diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers.json.j2 b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers.json.j2 new file mode 100644 index 000000000000..0b1cb2c541b6 --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers.json.j2 @@ -0,0 +1,2 @@ +{%- set default_topo = 't1' %} +{%- include 'buffers_config.j2' %} diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t0.j2 b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t0.j2 new file mode 100644 index 000000000000..3e39d411e8bf --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t0.j2 @@ -0,0 +1,47 @@ + +{%- set default_cable = '5m' %} + +{%- macro generate_port_lists(PORT_ALL) %} + {# Generate list of ports #} + {%- for port_idx in range(0,128,4) %} + {%- if PORT_ALL.append("Ethernet%d" % (port_idx)) %}{%- endif %} + {%- endfor %} +{%- endmacro %} + +{%- macro generate_buffer_pool_and_profiles() %} + "BUFFER_POOL": { + "ingress_lossless_pool": { + "size": "11213696", + "type": "ingress", + "mode": "dynamic", + "xoff": "3855488" + }, + "egress_lossy_pool": { + "size": "9532224", + "type": "egress", + "mode": "dynamic" + }, + "egress_lossless_pool": { + "size": "15982720", + "type": "egress", + "mode": "static" + } + }, + "BUFFER_PROFILE": { + "ingress_lossy_profile": { + "pool":"[BUFFER_POOL|ingress_lossless_pool]", + "size":"0", + "dynamic_th":"3" + }, + "egress_lossless_profile": { + "pool":"[BUFFER_POOL|egress_lossless_pool]", + "size":"1518", + "static_th":"3995680" + }, + "egress_lossy_profile": { + "pool":"[BUFFER_POOL|egress_lossy_pool]", + "size":"1518", + "dynamic_th":"3" + } + }, +{%- endmacro %} diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t1.j2 b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t1.j2 new file mode 100644 index 000000000000..d9f562f95624 --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/buffers_defaults_t1.j2 @@ -0,0 +1,47 @@ + +{%- set default_cable = '40m' %} + +{%- macro generate_port_lists(PORT_ALL) %} + {# Generate list of ports #} + {%- for port_idx in range(0,128,4) %} + {%- if PORT_ALL.append("Ethernet%d" % (port_idx)) %}{%- endif %} + {%- endfor %} +{%- endmacro %} + +{%- macro generate_buffer_pool_and_profiles() %} + "BUFFER_POOL": { + "ingress_lossless_pool": { + "size": "10443264", + "type": "ingress", + "mode": "dynamic", + "xoff": "4625920" + }, + "egress_lossy_pool": { + "size": "8877440", + "type": "egress", + "mode": "dynamic" + }, + "egress_lossless_pool": { + "size": "15982720", + "type": "egress", + "mode": "static" + } + }, + "BUFFER_PROFILE": { + "ingress_lossy_profile": { + "pool":"[BUFFER_POOL|ingress_lossless_pool]", + "size":"0", + "dynamic_th":"3" + }, + "egress_lossless_profile": { + "pool":"[BUFFER_POOL|egress_lossless_pool]", + "size":"1518", + "static_th":"3995680" + }, + "egress_lossy_profile": { + "pool":"[BUFFER_POOL|egress_lossy_pool]", + "size":"1518", + "dynamic_th":"3" + } + }, +{%- endmacro %} diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/pg_profile_lookup.ini b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/pg_profile_lookup.ini new file mode 100644 index 000000000000..3b2a417cebcd --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/pg_profile_lookup.ini @@ -0,0 +1,17 @@ +# PG lossless profiles. +# speed cable size xon xoff threshold xon_offset + 10000 5m 1248 2288 35776 -4 2288 + 25000 5m 1248 2288 53248 -4 2288 + 40000 5m 1248 2288 66560 -4 2288 + 50000 5m 1248 2288 90272 -4 2288 + 100000 5m 1248 2288 165568 -4 2288 + 10000 40m 1248 2288 37024 -4 2288 + 25000 40m 1248 2288 53248 -4 2288 + 40000 40m 1248 2288 71552 -4 2288 + 50000 40m 1248 2288 96096 -4 2288 + 100000 40m 1248 2288 177632 -4 2288 + 10000 300m 1248 2288 46176 -4 2288 + 25000 300m 1248 2288 79040 -4 2288 + 40000 300m 1248 2288 108160 -4 2288 + 50000 300m 1248 2288 141856 -4 2288 + 100000 300m 1248 2288 268736 -4 2288 diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/qos.json.j2 b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/qos.json.j2 new file mode 100644 index 000000000000..b724b48c2c23 --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/MiTAC-LY1200-B32H0-C3/qos.json.j2 @@ -0,0 +1,167 @@ +{ + "TC_TO_PRIORITY_GROUP_MAP": { + "AZURE": { + "0": "0", + "1": "1", + "2": "2", + "3": "3", + "4": "4", + "5": "5", + "6": "6", + "7": "7" + } + }, + "MAP_PFC_PRIORITY_TO_QUEUE": { + "AZURE": { + "0": "0", + "1": "1", + "2": "2", + "3": "3", + "4": "4", + "5": "5", + "6": "6", + "7": "7" + } + }, + "TC_TO_QUEUE_MAP": { + "AZURE": { + "0": "0", + "1": "1", + "2": "2", + "3": "3", + "4": "4", + "5": "5", + "6": "6", + "7": "7" + } + }, + "DSCP_TO_TC_MAP": { + "AZURE": { + "0":"0", + "1":"0", + "2":"0", + "3":"3", + "4":"4", + "5":"0", + "6":"0", + "7":"0", + "8":"1", + "9":"0", + "10":"0", + "11":"0", + "12":"0", + "13":"0", + "14":"0", + "15":"0", + "16":"0", + "17":"0", + "18":"0", + "19":"0", + "20":"0", + "21":"0", + "22":"0", + "23":"0", + "24":"0", + "25":"0", + "26":"0", + "27":"0", + "28":"0", + "29":"0", + "30":"0", + "31":"0", + "32":"0", + "33":"0", + "34":"0", + "35":"0", + "36":"0", + "37":"0", + "38":"0", + "39":"0", + "40":"0", + "41":"0", + "42":"0", + "43":"0", + "44":"0", + "45":"0", + "46":"0", + "47":"0", + "48":"0", + "49":"0", + "50":"0", + "51":"0", + "52":"0", + "53":"0", + "54":"0", + "55":"0", + "56":"0", + "57":"0", + "58":"0", + "59":"0", + "60":"0", + "61":"0", + "62":"0", + "63":"0" + } + }, + "SCHEDULER": { + "scheduler.0" : { + "type":"DWRR", + "weight": "25" + }, + "scheduler.1" : { + "type":"DWRR", + "weight": "30" + }, + "scheduler.2" : { + "type":"DWRR", + "weight": "20" + } + }, + "PORT_QOS_MAP": { + "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124": { + "dscp_to_tc_map" : "[DSCP_TO_TC_MAP|AZURE]", + "tc_to_queue_map" : "[TC_TO_QUEUE_MAP|AZURE]", + "tc_to_pg_map" : "[TC_TO_PRIORITY_GROUP_MAP|AZURE]", + "pfc_to_queue_map": "[MAP_PFC_PRIORITY_TO_QUEUE|AZURE]", + "pfc_enable": "3,4" + } + }, + "WRED_PROFILE": { + "AZURE_LOSSY" : { + "wred_green_enable":"true", + "wred_yellow_enable":"true", + "ecn":"ecn_all", + "red_max_threshold":"512000", + "red_min_threshold":"512000", + "yellow_max_threshold":"512000", + "yellow_min_threshold":"512000", + "green_max_threshold": "184320", + "green_min_threshold": "184320" + }, + "AZURE_LOSSLESS" : { + "wred_green_enable":"true", + "wred_yellow_enable":"true", + "ecn":"ecn_all", + "red_max_threshold":"512000", + "red_min_threshold":"512000", + "yellow_max_threshold":"512000", + "yellow_min_threshold":"512000", + "green_max_threshold": "184320", + "green_min_threshold": "184320" + } + }, + "QUEUE": { + "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|0-1" : { + "wred_profile" : "[WRED_PROFILE|AZURE_LOSSY]" + }, + "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|3-4" : { + "scheduler" : "[SCHEDULER|scheduler.0]" + }, + "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|0" : { + "scheduler" : "[SCHEDULER|scheduler.1]" + }, + "Ethernet0,Ethernet4,Ethernet8,Ethernet12,Ethernet16,Ethernet20,Ethernet24,Ethernet28,Ethernet32,Ethernet36,Ethernet40,Ethernet44,Ethernet48,Ethernet52,Ethernet56,Ethernet60,Ethernet64,Ethernet68,Ethernet72,Ethernet76,Ethernet80,Ethernet84,Ethernet88,Ethernet92,Ethernet96,Ethernet100,Ethernet104,Ethernet108,Ethernet112,Ethernet116,Ethernet120,Ethernet124|1" : { + "scheduler" : "[SCHEDULER|scheduler.2]" + } + } +} diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/installer.conf b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/installer.conf index 8d4683add468..cda2e2810cbf 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/installer.conf +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/installer.conf @@ -1,4 +1,4 @@ CONSOLE_PORT=0x3f8 CONSOLE_DEV=0 CONSOLE_SPEED=115200 -ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="acpi_enforce_resources=lax pcie_aspm=off irqpoll" +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="acpi_enforce_resources=lax pcie_aspm=off irqpoll modprobe.blacklist=i2c_ismt" diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/psuutil.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/psuutil.py new file mode 100644 index 000000000000..8fd9d3b1f349 --- /dev/null +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/psuutil.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +############################################################################# +# MiTAC +# +# Module contains an implementation of SONiC PSU Base API and +# provides the PSUs status which are available in the platform +# +############################################################################# + +import os.path + +try: + from sonic_psu.psu_base import PsuBase +except ImportError as e: + raise ImportError (str(e) + "- required module not found") + +class PsuUtil(PsuBase): + """Platform-specific PSUutil class""" + + def __init__(self): + PsuBase.__init__(self) + + self.psu_nums = 2 + self.psu_path = "/sys/bus/i2c/devices/1-0032/" + self.psu_presence = "ps{}_ps" + self.psu_oper_status = "ps{}_pg" + + def get_num_psus(self): + """ + Retrieves the number of PSUs available on the device + :return: An integer, the number of PSUs available on the device + """ + return self.psu_nums + + def get_psu_status(self, index): + """ + Retrieves the oprational status of power supply unit (PSU) defined + by 1-based index + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is operating properly, False if PSU is faulty + """ + if index is None: + return False + + status = 1 + try: + with open(self.psu_path + self.psu_oper_status.format(index), 'r') as power_status: + status = int(power_status.read(), 0) + except IOError: + return False + + return status == 0 + + def get_psu_presence(self, index): + """ + Retrieves the presence status of power supply unit (PSU) defined + by 1-based index + :param index: An integer, 1-based index of the PSU of which to query status + :return: Boolean, True if PSU is plugged, False if not + """ + if index is None: + return False + + status = 1 + try: + with open(self.psu_path + self.psu_presence.format(index), 'r') as presence_status: + status = int(presence_status.read(), 0) + except IOError: + return False + + return status == 0 diff --git a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py index 33e98016384a..a28bfecd9341 100644 --- a/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py +++ b/device/mitac/x86_64-mitac_ly1200_b32h0_c3-r0/plugins/sfputil.py @@ -4,6 +4,7 @@ # try: + import subprocess import time from sonic_sfp.sfputilbase import SfpUtilBase except ImportError as e: @@ -18,7 +19,10 @@ class SfpUtil(SfpUtilBase): PORTS_IN_BLOCK = 32 EEPROM_OFFSET = 10 + # time period (sec) for querying transceivers + QUERY_XCVR_PERIOD = 2 + pre_port_dict = {} _port_to_eeprom_mapping = {} @property @@ -37,6 +41,10 @@ def qsfp_ports(self): def port_to_eeprom_mapping(self): return self._port_to_eeprom_mapping + @property + def qry_xcvr_period(self): + return self.QUERY_XCVR_PERIOD + def __init__(self): eeprom_path = "/sys/class/i2c-adapter/i2c-{0}/{0}-0050/eeprom" @@ -50,27 +58,36 @@ def get_presence(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - if port_num > 16: + if port_num > 15: cpld_addr=33 + if port_num < 24: + port_id="_17_24" + else: + port_id="_25_32" else: cpld_addr=32 - - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_present" - + if port_num < 8: + port_id="_1_8" + else: + port_id="_9_16" + + file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + port_id + "_present" try: - reg_file = open("file_path") + reg_file = open(file_path) except IOError as e: print "Error: unable to open file: %s" % str(e) return False content = reg_file.readline().rstrip() - # content is a string containing the hex representation of the register reg_value = int(content, 16) + port_num = port_num % 8 + # Mask off the bit corresponding to our port + mask = (1 << port_num) # ModPrsL is active low - if reg_value == 0: + if reg_value & mask == 0: return True return False @@ -80,13 +97,20 @@ def get_low_power_mode(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - if port_num > 16: + if port_num > 15: cpld_addr=33 + if port_num < 24: + port_id="_17_24" + else: + port_id="_25_32" else: cpld_addr=32 - - - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + if port_num < 8: + port_id="_1_8" + else: + port_id="_9_16" + + file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + port_id + "_lpmode" try: reg_file = open(file_path) @@ -97,9 +121,13 @@ def get_low_power_mode(self, port_num): # content is a string containing the hex representation of the register reg_value = int(content, 16) + port_num = port_num % 8 + + # Mask off the bit corresponding to our por + mask = (1 << port_num) # LPMode is active high - if reg_value == 0: + if reg_value & mask == 0: return False return True @@ -109,24 +137,41 @@ def set_low_power_mode(self, port_num, lpmode): if port_num < self.port_start or port_num > self.port_end: return False - if port_num > 16: + if port_num > 15: cpld_addr=33 + if port_num < 24: + port_id="_17_24" + else: + port_id="_25_32" else: cpld_addr=32 - - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_lpmode" + if port_num < 8: + port_id="_1_8" + else: + port_id="_9_16" + + file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + port_id + "_lpmode" try: reg_file = open(file_path, "r+") except IOError as e: print "Error: unable to open file: %s" % str(e) return False + + + content = reg_file.readline().rstrip() + + # content is a string containing the hex representation of the register + reg_value = int(content,16) + + # Mask off the bit corresponding to our port + mask = (1 << (port_num % 8)) # LPMode is active high; set or clear the bit accordingly if lpmode is True: - reg_value = 1 + reg_value = reg_value | mask else: - reg_value = 0 + reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back content = hex(reg_value) @@ -143,12 +188,20 @@ def reset(self, port_num): if port_num < self.port_start or port_num > self.port_end: return False - if port_num > 16: + if port_num > 15: cpld_addr=33 + if port_num < 24: + port_id="_17_24" + else: + port_id="_25_32" else: cpld_addr=32 - - file_path="/sys/bus/i2c/devices/1-00" + str(cpld_num) + "/port" + str(port_num) + "/port" + str(port_num) + "_rst" + if port_num < 8: + port_id="_1_8" + else: + port_id="_9_16" + + file_path="/sys/bus/i2c/devices/1-00" + str(cpld_addr) + "/port" + port_id + "_rst" try: reg_file = open(file_path, "r+") @@ -156,35 +209,74 @@ def reset(self, port_num): print "Error: unable to open file: %s" % str(e) return False + content = reg_file.readline().rstrip() + + # content is a string containing the hex representation of the register + reg_value = int(content,16) + + # Mask off the bit corresponding to our port + mask = (1 << (port_num % 8)) + # ResetL is active low - reg_value = 0 + reg_value = reg_value & ~mask # Convert our register value back to a hex string and write back reg_file.seek(0) reg_file.write(hex(reg_value)) reg_file.close() - + # Sleep 1 second to allow it to settle time.sleep(1) # Flip the bit back high and write back to the register to take port out of reset try: - reg_file = open(QSFP_RESET_REGISTER_DEVICE_FILE, "w") + reg_file = open(file_path, "w+") except IOError as e: print "Error: unable to open file: %s" % str(e) return False - - reg_value = 1 + + reg_value = reg_value | mask reg_file.seek(0) reg_file.write(hex(reg_value)) reg_file.close() - + return True + def get_data_not_ready(self ,port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False + + port = str(10+port_num) + get_data_cmd = "sudo i2cget -f -y " +port+ " 0x50 0x02 b 2>/dev/null" + try: + get_data = subprocess.check_output(get_data_cmd, shell=True) + data_not_ready = int( bin(int(get_data,16))[-1] ) + except: + data_not_ready = 1 + + return data_not_ready + def get_transceiver_change_event(self): - """ - TODO: This function need to be implemented - when decide to support monitoring SFP(Xcvrd) - on this platform. - """ - raise NotImplementedError + + port_dict = {} + while True: + # Get the status of ports + for port in range(self.port_end + 1): + presence = self.get_presence(port) + not_rdy = self.get_data_not_ready(port) + + if presence is True and not_rdy == 0: + #qsfp is inserted + port_dict[port] = '1' + else: + #qsfp is removed + port_dict[port] = '0' + + if len(self.pre_port_dict) != 0: + if cmp (self.pre_port_dict,port_dict) != 0: + self.pre_port_dict = port_dict.copy() + return True, port_dict + + self.pre_port_dict = port_dict.copy() + time.sleep(self.qry_xcvr_period) diff --git a/platform/broadcom/rules.mk b/platform/broadcom/rules.mk index 85eb0df51870..aaed52f446f7 100644 --- a/platform/broadcom/rules.mk +++ b/platform/broadcom/rules.mk @@ -10,7 +10,7 @@ include $(PLATFORM_PATH)/platform-modules-inventec.mk include $(PLATFORM_PATH)/platform-modules-cel.mk include $(PLATFORM_PATH)/platform-modules-delta.mk include $(PLATFORM_PATH)/platform-modules-quanta.mk -#include $(PLATFORM_PATH)/platform-modules-mitac.mk +include $(PLATFORM_PATH)/platform-modules-mitac.mk include $(PLATFORM_PATH)/docker-orchagent-brcm.mk include $(PLATFORM_PATH)/docker-syncd-brcm.mk include $(PLATFORM_PATH)/docker-syncd-brcm-rpc.mk diff --git a/platform/broadcom/sonic-platform-modules-mitac/.gitignore b/platform/broadcom/sonic-platform-modules-mitac/.gitignore index 38e72f05332d..27d99ee51e1f 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/.gitignore +++ b/platform/broadcom/sonic-platform-modules-mitac/.gitignore @@ -7,6 +7,8 @@ ly1200-32x/modules/*.cmd ly1200-32x/modules/Module.symvers ly1200-32x/modules/modules.order ly1200-32x/modules/.tmp_versions +build/ +ly1200_32x.egg-info/ debian/sonic-platform-mitac-ly1200-32x/ debian/sonic-platform-mitac-ly1200-32x.debhelper.log @@ -15,3 +17,7 @@ debian/sonic-platform-mitac-ly1200-32x.postrm.debhelper debian/sonic-platform-mitac-ly1200-32x.prerm.debhelper debian/sonic-platform-mitac-ly1200-32x.substvars debian/files +debian/.debhelper +debian/debhelper-build-stamp + +ly1200-32x/classes/fan_ctrl_pkg/*.pyc diff --git a/platform/broadcom/sonic-platform-modules-mitac/README.md b/platform/broadcom/sonic-platform-modules-mitac/README.md index d7d47a58debf..ff88d76910f1 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/README.md +++ b/platform/broadcom/sonic-platform-modules-mitac/README.md @@ -1 +1,2 @@ -platform drivers of MiTAC products for the SONiC project +# sonic-platform-modules-mitac_stretch +platform drivers of MiTAC products for the SONiC project of Debian 9 diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/control b/platform/broadcom/sonic-platform-modules-mitac/debian/control index 8e20f8524d74..9776e1d64110 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/debian/control +++ b/platform/broadcom/sonic-platform-modules-mitac/debian/control @@ -1,12 +1,11 @@ Source: sonic-mitac-platform-modules Section: main Priority: extra -Maintainer: MiTAC network +Maintainer: MiTAC Computing Technology Build-Depends: debhelper (>= 8.0.0), bzip2 Standards-Version: 3.9.3 Package: sonic-platform-mitac-ly1200-32x Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 -Description: kernel modules for platform devices such as fan, led, sfp - +Depends: linux-image-4.9.0-7-amd64, bc +Description: kernel modules for platform devices such as fan, led, sfp \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/rules b/platform/broadcom/sonic-platform-modules-mitac/debian/rules index 7f9f99827d21..51b8b4ff8e70 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/debian/rules +++ b/platform/broadcom/sonic-platform-modules-mitac/debian/rules @@ -1,7 +1,11 @@ #!/usr/bin/make -f +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 export INSTALL_MOD_DIR:=extra +PYTHON ?= python2 + PACKAGE_PRE_NAME := sonic-platform-mitac KVERSION ?= $(shell uname -r) KERNEL_SRC := /lib/modules/$(KVERSION) @@ -14,21 +18,19 @@ MODULE_DIRS:= ly1200-32x override_dh_auto_build: (for mod in $(MODULE_DIRS); do \ make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules; \ + $(PYTHON) $${mod}/setup.py build; \ done) override_dh_auto_install: (for mod in $(MODULE_DIRS); do \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}\ + dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} \ $(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod}/usr/local/bin;\ cp $(MOD_SRC_DIR)/$${mod}/modules/*.ko \ debian/$(PACKAGE_PRE_NAME)-$${mod}/$(KERNEL_SRC)/$(INSTALL_MOD_DIR); \ - mkdir -p debian/$(PACKAGE_PRE_NAME)-$${mod}/opt; \ + dh_installdirs -p$(PACKAGE_PRE_NAME)-$${mod} /opt;\ + $(PYTHON) $${mod}/setup.py install --root=$(MOD_SRC_DIR)/debian/$(PACKAGE_PRE_NAME)-$${mod} --install-layout=deb; \ cp -rfL $(MOD_SRC_DIR)/$${mod}/opt/* \ debian/$(PACKAGE_PRE_NAME)-$${mod}/opt; \ - mkdir -p debian/$(PACKAGE_PRE_NAME)-$${mod}/etc/init.d; \ - cp -rfL $(MOD_SRC_DIR)/$${mod}/etc/* \ - debian/$(PACKAGE_PRE_NAME)-$${mod}/etc; \ done) override_dh_usrlocal: @@ -36,6 +38,5 @@ override_dh_usrlocal: override_dh_clean: dh_clean (for mod in $(MODULE_DIRS); do \ - make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \ + make -C $(KERNEL_SRC)/build M=$(MOD_SRC_DIR)/$${mod}/modules clean; \ done) - diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.init b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.init index d2f7dbf610ab..ee3fb2437df4 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.init +++ b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.init @@ -16,26 +16,34 @@ start) echo -n "Setting up board... " echo 0 > /proc/sys/kernel/perf_cpu_time_max_percent - - /etc/init.d/gpe start /etc/init.d/i2c_init start /etc/init.d/sys_polld start - /opt/script/start_watchdog.sh & - /opt/script/start_service.sh & + /etc/init.d/sys_servd start + echo 0 > /sys/bus/i2c/devices/1-0031/wd_en + echo "0x0" > /sys/bus/i2c/devices/1-0032/port_1_8_modsel + echo "0x0" > /sys/bus/i2c/devices/1-0032/port_9_16_modsel + echo "0x0" > /sys/bus/i2c/devices/1-0033/port_17_24_modsel + echo "0x0" > /sys/bus/i2c/devices/1-0033/port_25_32_modsel + echo "0x0" > /sys/bus/i2c/devices/1-0032/port_1_8_lpmode + echo "0x0" > /sys/bus/i2c/devices/1-0032/port_9_16_lpmode + echo "0x0" > /sys/bus/i2c/devices/1-0033/port_17_24_lpmode + echo "0x0" > /sys/bus/i2c/devices/1-0033/port_25_32_lpmode + echo "0xff" > /sys/bus/i2c/devices/1-0032/port_1_8_rst + echo "0xff" > /sys/bus/i2c/devices/1-0032/port_9_16_rst + echo "0xff" > /sys/bus/i2c/devices/1-0033/port_17_24_rst + echo "0xff" > /sys/bus/i2c/devices/1-0033/port_25_32_rst + echo "done." ;; stop) echo -n "cleaning... " - /etc/init.d/gpe stop /etc/init.d/i2c_init stop - /etc/init.d/xcvr_servd stop /etc/init.d/sys_servd stop /etc/init.d/sys_polld stop echo "done." - ;; force-reload|restart) @@ -43,7 +51,7 @@ force-reload|restart) ;; *) - echo "Usage: /etc/init.d/sonic-platform-mitac-ly1200-32x.init {start|stop}" + echo "Usage: /etc/init.d/sonic-platform-mitac-ly1200-32x {start|stop}" exit 1 ;; esac diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.install b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.install new file mode 100644 index 000000000000..c63dfd611e01 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.install @@ -0,0 +1,2 @@ +ly1200-32x/etc/init.d/* etc/init.d +ly1200-32x/systemd/sonic-platform-mitac-ly1200-32x.service lib/systemd/system diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.postinst b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.postinst new file mode 100644 index 000000000000..e53f80f95d04 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.postinst @@ -0,0 +1,3 @@ +depmod -a +systemctl enable sonic-platform-mitac-ly1200-32x.service +systemctl start sonic-platform-mitac-ly1200-32x.service diff --git a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.upstart b/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.upstart deleted file mode 100644 index 39533b8226af..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/debian/sonic-platform-mitac-ly1200-32x.upstart +++ /dev/null @@ -1,5 +0,0 @@ -description "SONiC platform service" - -respawn - -exec /etc/init.d/sonic-platform-mitac-ly1200-32x start diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/__init__.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/__main__.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/__main__.py new file mode 100644 index 000000000000..d4b4e6e6fdf3 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/__main__.py @@ -0,0 +1,48 @@ +#! /usr/bin/env python +# coding:utf-8 + +try: + import time + from .temperature_sensor import TemperatureSensor + from .fan_utility import * +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +def main(zone_conf, temp_conf, log_file, debug_mode, simulate_mode): + + fan_util = FanUtility(zone_conf, temp_conf, log_file, debug_mode, simulate_mode) + + fan_util.validate_configuration() + + fan_util.dump_runtime_info() + + INFO("Starting fan control service...") + + sensor_instance = [(TemperatureSensor(name, fan_util.fan_zone)) for name in fan_util.fan_zone['TEMP_LIST']] + + while True: + pwm = [] + temp = {} + + for instance in sensor_instance: + temp[instance.name] = instance.get_temp + pwm.append(instance.get_pwm(temp[instance.name], fan_util.fan_zone_thermal)) + + current_pwm = fan_util.pwm_value + new_pwm = max(pwm) + + apply_pwm = True + if new_pwm < current_pwm: + for instance in sensor_instance: + if not instance.hysteresis(current_pwm, temp[instance.name], fan_util.fan_zone_thermal): + apply_pwm = False + break + if apply_pwm: + fan_util.pwm_value = new_pwm + + elif new_pwm > current_pwm: + fan_util.pwm_value = new_pwm + + fan_util.dump_runtime_info(temp, new_pwm if apply_pwm else current_pwm) + time.sleep(fan_util.fan_zone['INTERVAL']) diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_ctrl_parser.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_ctrl_parser.py new file mode 100644 index 000000000000..c19ce226b9ed --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_ctrl_parser.py @@ -0,0 +1,54 @@ +#! /usr/bin/env python +# coding:utf-8 + +try: + import argparse + import os +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +def fan_ctrl_parser(base_dir): + # get the current path + config_dir = base_dir + "/conf_file/" + + parser = argparse.ArgumentParser(usage='./fan-ctrl [-h help] [-z zone_file] [-t thermal_file] [-o log_file] [-d] [-s]') + parser.add_argument('-z', '--zone-config', metavar='', help='Fan zone configuration file (default: conf_file/fan-zone.conf)') + parser.add_argument('-t', '--temp-config', metavar='', help='Fan zone thermal configuration file (default: conf_file/fan-zone-thermal.conf)') + parser.add_argument('-o', '--log-file', metavar='', help='Log file (default: /var/log/syslog)') + parser.add_argument('-d', '--debug', help='Debug mode (default: off)', action='store_true') + parser.add_argument('-s', '--simulate', help='Simulate mode (default: off)', action='store_true') + + args = parser.parse_args() + + if args.zone_config is None: + zone_conf = config_dir + "fan-zone.conf" + else: + zone_conf = args.zone_config + if not os.path.exists(zone_conf): + raise OSError('zone config \'%s\' is not exist' % (zone_conf)) + + if args.temp_config is None: + temp_conf = config_dir + "fan-zone-thermal.conf" + else: + temp_conf = args.temp_config + if not os.path.exists(temp_conf): + raise OSError('temp config \'%s\' is not exist' % (temp_conf)) + + if args.log_file is None: + log_file = "/var/log/syslog" + else: + log_file = args.log_file + + if args.debug is True: + # default debug mode (0: OFF, 1: ON) + debug_mode = args.debug + else: + debug_mode = False + + if args.simulate is True: + simulate_mode = args.simulate + else: + simulate_mode = False + + return zone_conf, temp_conf, log_file, debug_mode, simulate_mode diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_utility.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_utility.py new file mode 100644 index 000000000000..230a3262c76c --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/fan_utility.py @@ -0,0 +1,325 @@ +#! /usr/bin/env python +# coding:utf-8 + +try: + import subprocess + import logging + import socket + import os + import sys + import glob + import json + import ast +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +def DEBUG(arg): FanUtility.log_message(logging.DEBUG, arg) +def INFO(arg): FanUtility.log_message(logging.INFO, arg) +def WARN(arg): FanUtility.log_message(logging.WARNING, arg) +def ERR(arg): FanUtility.log_message(logging.ERROR, arg) +def CRITICAL(arg): FanUtility.log_message(logging.CRITICAL, arg) + + +class ReadonlyDict(dict): + def __setitem__(self, key, value): + raise TypeError("__setitem__ is not supported") + + def __delitem__(self, key): + raise TypeError("__delitem__ is not supported") + + +class FanUtility(object): + """ fan-ctrl FanUtility class """ + + _log_file = "/var/log/syslog" + + def __new__(cls, *args): + if len(args) != 5: + raise TypeError("it needs five arguments") + cls._log_file = args[2] + return object.__new__(cls) + + def __init__(self, *args): + """ The *args is list of [zone_conf, temp_conf, log_file, debug_mode, simulate_mode] """ + self.__debug_mode = args[3] + self.__simulate_mode = args[4] + _sim_zone_dict = self.__create_zone_dict(args[0]) + if self.__simulate_mode is True: + for name in _sim_zone_dict['TEMP_LIST']: + _sim_zone_dict[name]['cmd'] = 'cat /tmp/simulate' + name + '.txt' + with open('/tmp/simulate' + name + '.txt', 'w+') as f: + f.write('60.0') + + for i in range(len(_sim_zone_dict['FAN_CMD'])): + _sim_zone_dict['FAN_CMD'][i] = '/tmp/simulate_fan_pwm' + with open('/tmp/simulate_fan_pwm', 'w+') as f: + f.write('0') + + self.__fan_zone = ReadonlyDict(_sim_zone_dict) + self.__fan_zone_thermal = ReadonlyDict(self.__create_zone_thermal_dict(args[1])) + self.__current_pwm = 0 + + @property + def debug_mode(self): + return self.__debug_mode + + @property + def simulate_mode(self): + return self.__simulate_mode + + @property + def fan_zone(self): + return self.__fan_zone + + @property + def fan_zone_thermal(self): + return self.__fan_zone_thermal + + @property + def pwm_value(self): + return self.__current_pwm + + @pwm_value.setter + def pwm_value(self, current_pwm): + for file_path in self.fan_zone['FAN_CMD']: + file_path = glob.glob(file_path)[0] + try: + with open(file_path, 'w+') as f: + f.write(str(current_pwm)) + except EnvironmentError: + ERR("Open file fail. reason = " + file_path + " is not exist.") + + self.__current_pwm = current_pwm + + @classmethod + def log_message(cls, msg_lvl, msg): + """ Log wrappers """ + + hostname = socket.gethostname() + log_file = cls._log_file + date_fmt = '%b %_d %T' + msg_format = '%(asctime)s ' + hostname + ' %(filename)s[%(process)d]: <%(levelname)s>:%(message)s' + + logging.basicConfig(filename=log_file, format=msg_format, datefmt=date_fmt, level=logging.DEBUG) + + # DEBUG:10 INFO:20 WARNING:30 ERROR:40 + if msg_lvl >= logging.WARNING: + print(msg) + + if msg_lvl == logging.DEBUG: + logging.debug(msg) + elif msg_lvl == logging.INFO: + logging.info(msg) + elif msg_lvl == logging.WARNING: + logging.warning(msg) + elif msg_lvl == logging.ERROR: + logging.error(msg) + sys.exit(os.EX_USAGE) + elif msg_lvl == logging.CRITICAL: + logging.critical(msg) + sys.exit(os.EX_USAGE) + else: + raise ValueError("Unsupported message level" + str(msg_lvl)) + + def dump_runtime_info(self, *args): + """ Debug for showing system current fan level and PWM """ + if self.debug_mode is True: + if len(args) == 0: + print("********* Sensor Group *********") + for name in self.fan_zone['TEMP_LIST']: + print(name + '\t' + self.fan_zone[name]['cmd'] + '\t' + self.fan_zone[name]['max_temp']) + + print("********* Sensor Table *********") + for name in self.fan_zone_thermal['TEMP_LIST']: + sensor_list = '' + for pwm in self.fan_zone_thermal['PWM']: + sensor_list += str(self.fan_zone_thermal[str(pwm)][name]) + " " + print(name + '\t' + sensor_list) + else: + print("********* Sensor Reading *********") + temp = args[0] + current_pwm = args[1] + for name in self.fan_zone['TEMP_LIST']: + print(name + "\t" + str(temp[name])) + + current_level = self.fan_zone_thermal['PWM'].index(current_pwm) + 1 + # For human readable, the representation of fan level will start from 1. + print("Current Level" + "\t " + str(current_level) + ", PWM" + "\t " + str(current_pwm)) + + if self.simulate_mode is True: + print("********* Simulate mode *********") + print('please modify the contents of following files.') + for name in self.fan_zone['TEMP_LIST']: + print('/tmp/simulate' + name + '.txt') + + @staticmethod + def platform_init(conf_dir, zone_conf, temp_conf, simulate_mode): + """ Getting board type and create symbolic link """ + + file_path = conf_dir + "/conf_file" + + if os.path.basename(zone_conf).find("fan-zone.conf") == -1: + forward_sensor_conf = "ln -sf " + zone_conf + " " + file_path + "/fan-zone.conf" + reverse_sensor_conf = "ln -sf " + zone_conf + " " + file_path + "/fan-zone.conf" + else: + forward_sensor_conf = "ln -sf " + file_path + "/fan-zone_F2B.conf " + file_path + "/fan-zone.conf" + reverse_sensor_conf = "ln -sf " + file_path + "/fan-zone_B2F.conf " + file_path + "/fan-zone.conf" + + if os.path.basename(temp_conf).find("fan-zone-thermal.conf") == -1: + forward_pwm_conf = "ln -sf " + temp_conf + " " + file_path + "/fan-zone-thermal.conf" + reverse_pwn_conf = "ln -sf " + temp_conf + " " + file_path + "/fan-zone-thermal.conf" + else: + forward_pwm_conf = "ln -sf " + file_path + "/fan-zone-thermal_F2B.conf " + file_path + "/fan-zone-thermal" \ + ".conf " + reverse_pwn_conf = "ln -sf " + file_path + "/fan-zone-thermal_B2F.conf " + file_path + "/fan-zone-thermal" \ + ".conf " + + # board_type_cmd_dic + board_type_list1 = ("0x0", "0x2") + board_type_list2 = ("0x1", "0x3") + cmd_list1 = (forward_sensor_conf, forward_pwm_conf) + cmd_list2 = (reverse_sensor_conf, reverse_pwn_conf) + + # get board type + if simulate_mode is True: + board_type = "0x1" + else: + get_board_type_cmd = "cat /sys/bus/i2c/devices/1-0032/brd_type" + board_type = subprocess.check_output(["/bin/bash", "-c", get_board_type_cmd]).decode('utf8').strip() + + # create symbolic + if board_type in board_type_list1: + for cmd in cmd_list1: + subprocess.check_output(["/bin/bash", "-c", cmd]) + elif board_type in board_type_list2: + for cmd in cmd_list2: + subprocess.check_output(["/bin/bash", "-c", cmd]) + else: + print(board_type + "is not exist") + sys.exit(os.EX_DATAERR) + + @staticmethod + def __create_zone_dict(file_path): + """ Create zone dictionary """ + + zone_dic = {} + temp_grp = [] + fan_grp = [] + list1 = ('INTERVAL', 'HYTERESIS', 'MIN_PWM') + + # get temp list + cmd = "cat " + file_path + " | grep '^TEMP_'| awk -F ',' {'print$1'}" + temp_list = subprocess.check_output(["/bin/bash", "-c", cmd]).decode('utf8').split() + zone_dic['TEMP_LIST'] = temp_list + + # get sensor name cmd max_temp + for i in range(len(temp_list)): + # Processing ascii code for degree sign + cmd = "cat " + file_path + " | grep '^TEMP_' | awk NR==" + str(i + 1) + ">/tmp/fan_ctrl.BAK" + os.system(cmd) + cmd = "cat /tmp/fan_ctrl.BAK|sed 's/^+\|\\xc2\\xb0C//g'" + line = subprocess.check_output(["/bin/bash", "-c", cmd]).decode('utf8').strip() + items = line.split(', ') + temp_grp += [str(item).strip() for item in items] + + while len(temp_grp) > 0: + name, cmd, max_temp = temp_grp[:3] + cmd = cmd.strip('"') + zone_dic[name] = {'cmd': cmd, 'max_temp': max_temp} + del temp_grp[:3] + + # get default value INTERVAL:10, HYSTERESIS:2, MIN_PWM:39, ZONE_ID:0 + for list_name in list1: + cmd = "cat " + file_path + " | grep ^" + list_name + " | awk -F '=' {'print$2'} | tail" + value = subprocess.check_output(["/bin/bash", "-c", cmd]).strip() + if not value: + ERR("config: status = invalid. reason = no " + list_name + " defined.") + else: + try: + zone_dic[list_name] = int(value) if int(value) >= 0 else None + except TypeError: + ERR("config: status = invalid. reason = the value of " + list_name + " is not integer.") + + zone_dic['ZONE_ID'] = 0 + + # get fan command and fan numbers + cmd = "cat " + file_path + "| grep '^FAN_' | awk {'print$2'} | wc -l" + fan_num = subprocess.check_output(["/bin/bash", "-c", cmd]).strip() + + for i in range(int(fan_num)): + cmd = "cat " + file_path + " | grep '^FAN_' | awk NR==" + str(i + 1) + "{'print$2'}" + line = subprocess.check_output(["/bin/bash", "-c", cmd]).decode('utf8').strip('\n') + fan_grp += line.split(',') + + zone_dic['FAN_CMD'] = fan_grp + zone_dic = ast.literal_eval(json.dumps(zone_dic)) + return zone_dic + + @staticmethod + def __create_zone_thermal_dict(file_path): + """ Create zone thermal dictionary """ + + zone_thermal_dic = {} + sensor_temp = {} + + # get temp list + cmd = "cat " + file_path + " | grep '^TEMP_'| awk {'print$1'}" + temp_list = subprocess.check_output(["/bin/bash", "-c", cmd]).decode('utf8').split() + zone_thermal_dic['TEMP_LIST'] = temp_list + + # get fan_level_list + cmd = "cat " + file_path + "| grep '^PWM' | awk -F 'PWM' {'print$2'}" + pwm_list = list(map(int, subprocess.check_output(["/bin/bash", "-c", cmd]).split())) + zone_thermal_dic['PWM'] = pwm_list + + # get sensor fan level + for sensor_name in temp_list: + cmd = "cat " + file_path + "| grep ^" + sensor_name + "| awk -F " + sensor_name + " {'print$2'}" + s_fan_level_list = list(map(float, subprocess.check_output(["/bin/bash", "-c", cmd]).split())) + zone_thermal_dic[sensor_name] = list(zip(s_fan_level_list, pwm_list)) + sensor_temp[sensor_name] = s_fan_level_list + + # get pre_pwn + pre_pwm_list = pwm_list[0:len(pwm_list) - 1] + pre_pwm_list.insert(0, 0) + sensor_temp['PRE_PWM'] = pre_pwm_list + + for i in range(len(pwm_list)): + list1 = [] + name_list = [] + for name in sensor_temp: + list1.append(sensor_temp[name][i]) + name_list.append(name) + zone_thermal_dic[pwm_list[i]] = dict(zip(name_list, list1)) + + zone_thermal_dic = ast.literal_eval(json.dumps(zone_thermal_dic)) + return zone_thermal_dic + + def validate_configuration(self): + """ Initialization """ + + # validate zone config + if len(self.fan_zone['TEMP_LIST']) == 0: + ERR("config: status = invalid. reason = no TEMPERATURE SENSORS defined.") + + if len(self.fan_zone['FAN_CMD']) == 0: + ERR("config: status = invalid. reason = no FAN defined.") + + # validate thermal config + if len(self.fan_zone_thermal['PWM']) == 0: + ERR("config: status = invalid. reason = no FAN LEVELS defined.") + + if len(self.fan_zone_thermal['TEMP_LIST']) != len(self.fan_zone['TEMP_LIST']): + ERR("config: status = invalid. reason = the number of temperature sensors is inconsistent.") + + # compare temperature sensor name between configuration files + for i in range(len(self.fan_zone['TEMP_LIST'])): + if self.fan_zone['TEMP_LIST'][i] != self.fan_zone_thermal['TEMP_LIST'][i]: + ERR("config: status = invalid. reason = the name of temperature sensors is inconsistent.") + + # validate pwm values + for pwm in self.fan_zone_thermal['PWM']: + if pwm < self.fan_zone['MIN_PWM']: + ERR("config: status=invalid. reason=the value of fan level is less than MIN_PWM({0}).".format( + str(self.fan_zone["MIN_PWM"]))) diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor.py new file mode 100644 index 000000000000..c1985ea9cfe7 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor.py @@ -0,0 +1,55 @@ +#! /usr/bin/env python +# coding:utf-8 + +try: + import subprocess + from .temperature_sensor_base import TempSensorBase as Base + from .fan_utility import * +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + +class TemperatureSensor(Base): + """ TemperatureSensor class for fan utility """ + + def __init__(self, temp_name, fan_zone): + self.name = temp_name + self.get_temp_cmd = fan_zone[temp_name]['cmd'] + self.max_temp = fan_zone[temp_name]['max_temp'] + self.zone_id = fan_zone['ZONE_ID'] + self.status = 'GOOD' + + @property + def get_temp(self): + + msg_header = "[ZONE_%d] Sensor %s" % (self.zone_id, self.name) + cmd = self.get_temp_cmd + " 2>/dev/null" + try: + temperature = subprocess.check_output(["/bin/bash", "-c", cmd]).strip() + if self.status == 'FAULT': + WARN("%s: status=RECOVER. reason=temperature is %s deg C." % (msg_header, temperature)) + + self.status = 'GOOD' + return float(temperature) + except (ValueError, subprocess.CalledProcessError) as e: + if self.status == 'GOOD': + WARN("%s: status=ERROR. reason=read sensor failed." % msg_header) + + self.status = 'FAULT' + return float(self.max_temp) + + def get_pwm(self, temperature, fan_zone_thermal): + + pwm = max(fan_zone_thermal['PWM']) + for i in range(len(list(fan_zone_thermal[self.name]))): + if temperature < fan_zone_thermal[self.name][i][0]: + pwm = fan_zone_thermal[self.name][i][1] + break + return pwm + + def hysteresis(self, cur_pwm, temperature, fan_zone_thermal): + + pre_pwm = fan_zone_thermal[str(cur_pwm)]['PRE_PWM'] + if temperature <= (fan_zone_thermal[str(pre_pwm)][self.name] - 2): + return True + else: + return False diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor_base.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor_base.py new file mode 100644 index 000000000000..f75bb5d31d6d --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/fan_ctrl_pkg/temperature_sensor_base.py @@ -0,0 +1,30 @@ +#! /usr/bin/env python +# coding:utf-8 + +import abc + + +class TempSensorBase: + """ Base class for TemperatureSensor """ + + __metaclass__ = abc.ABCMeta + + name = " " + get_temp_cmd = " " + max_temp = 0 + + @abc.abstractmethod + def get_temp(self): + """ Get sensor temperature """ + pass + + @abc.abstractmethod + def get_pwm(self, temperature, fan_zone_thermal): + """ Get the fan speed """ + pass + + @abc.abstractmethod + def hysteresis(self, cur_pwm, fan_zone, fan_zone_thermal): + """ Determine whether the sensor temperature is lower than + the hysteresis temperature to reduce the fan speed. """ + pass diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/__init__.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/__init__.py new file mode 100755 index 000000000000..e69de29bb2d1 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/__main__.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/__main__.py new file mode 100755 index 000000000000..db0f115caa85 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/__main__.py @@ -0,0 +1,109 @@ +#!/usr/bin/python2 + +import json +import time +import signal +import sys +import threading +import socket +import select +import os +import logging +import getopt + +from fan_dev import FanDevMon +from psu_dev import PsuDevMon +from misc_dev import MiscDevMon +from commonlib import * +from config import * + +MIC_FEAT_SYS_INT = 0 +gpe_num = 0x1 +BMS_SYS_GPE_SYSFS = '/sys/firmware/acpi/interrupts/gpe{:02X}'.format(gpe_num) +SYS_GPE_INTR_TAG = 'bms_acpi PNP0C01:00 000000{:02X} 00000000'.format(gpe_num) +ACPI_SOCK_SYSFS = '/var/run/acpid.socket' + +if 0: + BMS_SYS_GPE_SYSFS = 'gpe{:02X}'.format(gpe_num) + ACPI_SOCK_SYSFS = './tt.d' + +def service_shutdown(signum, frame): + WARN('Caught signal {:2d}'.format(signum)) + raise Exception('System daemon service shutdown') + +def main_thread(dm_list, wait_time=2) : + if MIC_FEAT_SYS_INT: + sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + sock.connect( ACPI_SOCK_SYSFS ) + try: + while 1: + if MIC_FEAT_SYS_INT: + write_file(BMS_SYS_GPE_SYSFS,'enable') + buf = sock.recv(1024) + DEBUG( 'got acpi event data: [{}] tag[{}]'.format(buf, SYS_GPE_INTR_TAG) ) + if buf != SYS_GPE_INTR_TAG: + continue + write_file(BMS_SYS_GPE_SYSFS,'disable') + else: + time.sleep(wait_time) + + for dm in dm_list: + # intr == 0 and msk == 1 --> set intr event + intr = dm.get_intr_src() + msk = dm.get_intr_msk() + + for i in range(len(intr)): + if intr[i] == 0 and msk[i] == 1: + dm.set_intr_event() + break + #if 0 in intr: + # dm.set_intr_event() + finally: + if MIC_FEAT_SYS_INT: + sock.close() + +def main(): + #os.system( 'renice -20 {}'.format(os.getpid()) ) + config = None + try: + opts, args = getopt.gnu_getopt(sys.argv[1:],"d:",["log="]) + config = args[0] if len(args) > 0 else None + + for o, a in opts: + if o in ('--log', '-d'): + logging.getLogger(SYSLOG_IDENT).setLevel( eval('logging.{level}'.format(level=a.upper()) ) ) + except: + ERR('params error') + + signal.signal(signal.SIGTERM, service_shutdown) + signal.signal(signal.SIGINT, service_shutdown) + + if config == None: + data = config_data_ly1200 + else : + with open(config, 'r') as j_file: + data = json.load(j_file) + #DEBUG(json.dumps(data, indent=2)) + + BoardType(data["board_type_path"]) + PsuType(data['psu_type']) + + root_class = ( + FanDevMon, + PsuDevMon, + MiscDevMon, + ) + + dm_list = [m(data[m.__dict__['_config_key']]) for m in root_class if m.__dict__['_config_key'] in data] + + try: + [ dm.set_intr_msk(1) for dm in dm_list ] + [ dm.start_monitor() for dm in dm_list ] + main_thread(dm_list) + except Exception as e: + WARN(e) + finally: + [ dm.stop_monitor() for dm in dm_list ] + +if __name__ == '__main__': + main() diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/commonlib.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/commonlib.py new file mode 100755 index 000000000000..252c531b7c18 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/commonlib.py @@ -0,0 +1,258 @@ +import threading +import logging +import os +from logging.handlers import SysLogHandler + +SYSLOG_IDENT = 'sys-servd' + +class MitacLog(object) : + log = logging.getLogger(SYSLOG_IDENT) + log.setLevel(logging.DEBUG) + + #https://docs.python.org/2/library/logging.html + # DEBUG INFO WARNING ERROR CRITICAL + handler = logging.StreamHandler() + handler.setFormatter(logging.Formatter('%(asctime)s: %(levelname)-8s %(module)-9s %(funcName)-10s: %(message)s', '%y-%m-%d %H:%M:%S')) + handler.setFormatter(logging.Formatter('%(asctime)s: %(levelname)-8s %(message)s', '%y-%m-%d %H:%M:%S')) + log.addHandler(handler) + + handler = SysLogHandler(address = '/dev/log') + #handler.setLevel(logging.INFO) + handler.setFormatter( logging.Formatter('%(name)s: %(levelname)-8s %(message)s') ) + handler.setFormatter( logging.Formatter('%(name)s: %(message)s') ) + log.addHandler(handler) + +def DEBUG(arg): MitacLog.log.debug(arg) +def INFO(arg): MitacLog.log.info(arg) +def WARN(arg): MitacLog.log.warn(arg) +def ERR(arg): MitacLog.log.error(arg) +def CRITICAL(arg): MitacLog.log.critical(arg) + +class Led(object): + def __init__(self, *args): + self._node = args[0] + self._name = args[1] + self.ledmap = dict([ (k.upper(), v ) for k, v in args[2].items() ]) + self.val = None + def set_led(self, val): + val = val.upper() + if val == self.val : return + self.val = val + try : + v = self.ledmap[val] + except KeyError: + v = None + INFO( '{0.__class__.__name__}-{0._name}: {1}({2})'.format(self, val, v) ) + if v != None: write_file( self._node, v ) + +class State(object): + """ + We define a state object which provides some utility functions for the + individual states within the state machine. + """ + def __init__(self): + #print 'Processing current state:', str(self) + self.msg = self.__class__.__name__ + pass + def on_event(self, event): + pass + def __repr__(self): + return self.__str__() + def __str__(self): + return self.__class__.__name__ + def __eq__(self, other): + return self.__class__.__name__ == other.__class__.__name__ + +class Singleton(object): + _instance = None + def __new__(cls, *args, **kw): + if not cls._instance: + cls._instance = super(Singleton, cls).__new__(cls) + return cls._instance + +class BoardType(Singleton): + board_type = 0 + def __init__(self, node = None): + if(node == None): return + try: + self.board_type = cat_file(node, 16) + except: + self.board_type = 0 + +class PsuType(Singleton): + psu_type = None + def __init__(self, type = None): + if type == None: return + + try: + self.psu_type = type + except: + self.psu_type = None + +class CommonDev(object): + def __init__(self, param): + super(CommonDev, self).__init__() + + self.name = (param['name'] if 'name' in param else 'unknown_dev').upper() + self.present = 0 + + self.cpld_path = param['cpld_path'] if 'cpld_path' in param else None + + self.intr_src = param['intr_src'] + self.intr_msk = param['intr_msk'] + + def get_intr_src(self): + return cat_file( os.path.join(self.cpld_path, self.intr_src), 16) + + def get_intr_msk(self): + return cat_file( os.path.join(self.cpld_path, self.intr_msk), 16) + + def set_intr_msk(self, v): + write_file( os.path.join(self.cpld_path, self.intr_msk), v) + + @property + def get_present(self): + return self.present + + def event_handler(self): + pass + +class StateDev(CommonDev): + def __init__(self, param): + super(StateDev, self).__init__(param) + + self.state = State() + self.hwmon_path = param['hwmon_path'] if 'hwmon_path' in param else None + self.hwmon_ext_path = '' + if self.hwmon_path : + try: + listofdir = [f for f in os.listdir(self.hwmon_path) if os.path.isdir( os.path.join(self.hwmon_path,str(f)))] + if len(listofdir) : + self.hwmon_ext_path = listofdir[0] + except : + pass + def get_intr_src(self): return 1 + def get_intr_msk(self): return 0 + def set_intr_msk(self, v): pass + def refresh(self): + pass + def on_event(self, event): + pass + def update_state(self): + pass + def get_state(self): + return self.state + def dump_dev(self): + pass + +def _threaded(fn): + def wrapper(*args, **kwargs): + thread = threading.Thread(target=fn, args=args, kwargs=kwargs) + thread.setDaemon(True) + thread.start() + return thread + return wrapper + +class DevMon(object): + def __init__(self, *args): + super(DevMon, self).__init__() + data = args[0] + dev_class = args[1] + self.dev_list = [ dev_class(d) for d in data['devs'] ] + + self.delay_time = float(data['timeout'])/1000 if 'timeout' in data else None + self.tMonitor = None + self.shutdown_event = threading.Event() + self.intr_event = threading.Event() + self.handler_list = [self.intr_handler] + + def set_intr_event(self): + self.intr_event.set() + + def get_intr_src(self): + return [d.get_intr_src() for d in self.dev_list ] + + def set_intr_msk(self, v): + [d.set_intr_msk(v) for d in self.dev_list ] + + def get_intr_msk(self): + return [d.get_intr_msk() for d in self.dev_list ] + + def start_monitor(self): + if type(self.tMonitor) == type(None): + self.shutdown_event.clear() + self.tMonitor = self._dev_monitor_thread() + + def stop_monitor(self): + if type(self.tMonitor) != type(None): + self.shutdown_event.set() + self.intr_event.set() + self.tMonitor.join() + self.tMonitor = None + + def intr_handler(self, intr): + if intr: + for d in self.dev_list: + if d.get_intr_src() == 0: + d.event_handler() + d.set_intr_msk(0) + def shutdown_func(self): + pass + @_threaded + def _dev_monitor_thread(self): + while not self.shutdown_event.is_set(): + intr = self.intr_event.wait(self.delay_time) + + if self.shutdown_event.is_set(): break + + self.intr_event.clear() + [handler(intr) for handler in self.handler_list] + + self.shutdown_func() + DEBUG('{}: Exit monitoring thread'.format(self.__class__.__name__)) + +class StateMon(DevMon): + def __init__(self, *args): + super(StateMon, self).__init__(*args) + + self.handler_list.append(self.update_all_state) + def state_change(self): + pass + + def force_state_change(self) : + return False + + def get_state(self): + return [d.get_state() for d in self.dev_list ] + + def dump_devs(self): + [ d.dump_dev() for d in self.dev_list ] + + def update_all_state(self, intr): + old_state = self.get_state() + [d.update_state() for d in self.dev_list ] + + if old_state != self.get_state() or self.force_state_change() : + self.state_change() + +## common function +def cat_file(fstr, base=10): + try: + with open(fstr, 'r') as f: + return int(f.read(), base) + except IOError: + pass + +def cat_file_str(fstr): + try: + with open(fstr, 'r') as f: + return f.read() + except IOError: + pass + +def write_file(fstr, v): + try: + with open(fstr, 'r+') as f: + f.write(str(v)+'\n') + except IOError: + ERR('write {} to {} fail'.format(v, fstr)) diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/config.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/config.py new file mode 100755 index 000000000000..3731f46672f8 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/config.py @@ -0,0 +1,185 @@ + +config_data_ly1200 = { + 'board_type_path': '/sys/bus/i2c/devices/1-0032/brd_type', + 'psu_type1': ['SE047-180G', 'SE048-180G', 'SE050-180G', 'SE049-180G'], + 'psu_type': ['FSE047-180G','FSE048-180G','FSE050-180G','FSE049-180G'], + + 'mon_fan': { + 'devs': [ + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan1_fault', 'fan2_fault'], + 'fan_fault_mask': [ 'fan1_fault_mask', 'fan2_fault_mask'], + 'fan_input': ['fan1_input', 'fan2_input'], + 'fan_panel_led': 'fan_led', + 'fan_target': [ 'fan1_target', 'fan2_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0020/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan1', + 'present': 'fan_tray1_present', + 'pwm': ['pwm1', 'pwm2'], + 'pwm_enable': [ 'pwm1_enable', 'pwm2_enable'], + 'tray_led': 'fan_tray1_led', + 'type': 'fan_type1', + }, + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan3_fault', 'fan4_fault'], + 'fan_fault_mask': [ 'fan3_fault_mask','fan4_fault_mask'], + 'fan_input': ['fan3_input', 'fan4_input'], + 'fan_panel_led': 'fan_led', + 'fan_target': [ 'fan3_target','fan4_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0020/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan2', + 'present': 'fan_tray2_present', + 'pwm': ['pwm3', 'pwm4'], + 'pwm_enable': [ 'pwm3_enable','pwm4_enable'], + 'tray_led': 'fan_tray2_led', + 'type': 'fan_type2'}, + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan5_fault', 'fan6_fault'], + 'fan_fault_mask': [ 'fan5_fault_mask','fan6_fault_mask'], + 'fan_input': ['fan5_input', 'fan6_input'], + 'fan_panel_led': 'fan_led', + 'fan_target': [ 'fan5_target','fan6_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0020/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan3', + 'present': 'fan_tray3_present', + 'pwm': ['pwm5', 'pwm6'], + 'pwm_enable': [ 'pwm5_enable','pwm6_enable'], + 'tray_led': 'fan_tray3_led', + 'type': 'fan_type3' + }, + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan1_fault', 'fan2_fault'], + 'fan_fault_mask': [ 'fan1_fault_mask','fan2_fault_mask'], + 'fan_input': ['fan1_input', 'fan2_input'], + 'fan_target': [ 'fan1_target','fan2_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0023/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan4', + 'present': 'fan_tray4_present', + 'pwm': ['pwm1', 'pwm2'], + 'pwm_enable': [ 'pwm1_enable','pwm2_enable'], + 'tray_led': 'fan_tray4_led', + 'type': 'fan_type4'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan3_fault', 'fan4_fault'], + 'fan_fault_mask': [ 'fan3_fault_mask','fan4_fault_mask'], + 'fan_input': ['fan3_input', 'fan4_input'], + 'fan_target': [ 'fan3_target','fan4_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0023/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan5', + 'present': 'fan_tray5_present', + 'pwm': ['pwm3', 'pwm4'], + 'pwm_enable': [ 'pwm3_enable','pwm4_enable'], + 'tray_led': 'fan_tray5_led', + 'type': 'fan_type5'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'fan_fault': ['fan5_fault', 'fan6_fault'], + 'fan_fault_mask': [ 'fan5_fault_mask','fan6_fault_mask'], + 'fan_input': ['fan5_input', 'fan6_input'], + 'fan_target': [ 'fan5_target','fan6_target'], + "hwmon_path": "/sys/bus/i2c/devices/3-0023/hwmon", + 'intr_msk': 'fan_alert_int_msk', + 'intr_src': 'fan_alert_int', + 'name': 'Fan6', + 'present': 'fan_tray6_present', + 'pwm': ['pwm5', 'pwm6'], + 'pwm_enable': [ 'pwm5_enable','pwm6_enable'], + 'tray_led': 'fan_tray6_led', + 'type': 'fan_type6' + }], + 'start_smart_fan': '/etc/init.d/fan-ctrld start', + 'stop_smart_fan': '/etc/init.d/fan-ctrld stop', + 'timeout': 1000 }, + 'mon_misc': { + 'devs': [ + { + 'cpld_path': '/sys/bus/i2c/devices/1-0031', + 'intr_msk': 'vrhot_irq_en', + 'intr_src': 'vrhot_irq', + 'name': 'vrhot'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0031', + 'intr_msk': 'cpu_thermtrip_irq_en', + 'intr_src': 'cpu_thermtrip_irq', + 'name': 'cpu_temp'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0031', + 'intr_msk': 'temp_alert_irq_en', + 'intr_src': 'temp_alert_irq', + 'name': 'sys_temp'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'intr_msk': 'usb_fault_msk', + 'intr_src': 'usb_fault', + 'name': 'usb'}, + { 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'intr_msk': 'pcie_int_msk', + 'intr_src': 'pcie_int', + 'name': 'pcie'} + ], + #'timeout_': 1000, + }, + 'mon_psu': { + 'devs': [ + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'hwmon_path': '/sys/bus/i2c/devices/5-0058/hwmon', + 'intr_msk': 'ps1_int_msk', + 'intr_src': 'ps1_int', + 'model_reg': 'mfr_model', + 'name': 'Psu1', + 'pg_off': 6, + 'pg_ps_reg': 'psu_en_status_fld', + 'power_fault': 'ps1_pf', + 'power_good': 'ps1_pg', + 'present': 'ps1_ps', + 'ps_off': 7, + 'psu_intr_src': [ 'vout_ov_fault', + 'vout_uv_fault', + 'curr2_crit_alarm', + 'curr2_max_alarm', + 'ot_fault', + 'ot_warning', + 'vin_uv_warning', + 'vin_uv_fault', + 'fan1_fault', + 'fan1_alarm'], + 'psu_panel_led': 'power_led', + 'sysfs_cmd': "echo 'fse000 0x58' > /sys/bus/i2c/devices/i2c-5/new_device"}, + { + 'cpld_path': '/sys/bus/i2c/devices/1-0032', + 'hwmon_path': '/sys/bus/i2c/devices/5-0059/hwmon', + 'intr_msk': 'ps2_int_msk', + 'intr_src': 'ps2_int', + 'model_reg': 'mfr_model', + 'name': 'Psu2', + 'pg_off': 2, + 'pg_ps_reg': 'psu_en_status_fld', + 'power_fault': 'ps2_pf', + 'power_good': 'ps2_pg', + 'present': 'ps2_ps', + 'ps_off': 3, + 'psu_intr_src': [ 'vout_ov_fault', + 'vout_uv_fault', + 'curr2_crit_alarm', + 'curr2_max_alarm', + 'ot_fault', + 'ot_warning', + 'vin_uv_warning', + 'vin_uv_fault', + 'fan1_fault', + 'fan1_alarm'], + 'sysfs_cmd': "echo 'fse000 0x59' > /sys/bus/i2c/devices/i2c-5/new_device"}], + 'timeout': 1000}, +} + diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/fan_dev.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/fan_dev.py new file mode 100755 index 000000000000..fe23024d96a7 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/fan_dev.py @@ -0,0 +1,264 @@ +import time +import copy +import os + +from commonlib import * + +FAN_PRESENT = 0 + +PWM_MIN = 38 +PWM_MAX = 255 +INLET_MIN_SPEED_MIN = 2510 +INLET_MIN_SPEED_MAX = 3910 +INLET_MAX_SPEED_MIN = 19260 +INLET_MAX_SPEED_MAX = 23540 +INLET_MAX_SLOPE = ((INLET_MAX_SPEED_MAX - INLET_MIN_SPEED_MAX)/(PWM_MAX - PWM_MIN)) +INLET_MIN_SLOPE = ((INLET_MAX_SPEED_MIN - INLET_MIN_SPEED_MIN)/(PWM_MAX - PWM_MIN)) +INLET_MAX_SPEED = lambda _pwm : ((INLET_MAX_SLOPE * (_pwm - PWM_MIN)) + INLET_MIN_SPEED_MAX) +INLET_MIN_SPEED = lambda _pwm : ((INLET_MIN_SLOPE * (_pwm - PWM_MIN)) + INLET_MIN_SPEED_MIN) + +#/* if only one fan in a fan module, do not care below values */ +OUTLET_MIN_SPEED_MIN = 2615 +OUTLET_MIN_SPEED_MAX = 4015 +OUTLET_MAX_SPEED_MIN = 19890 +OUTLET_MAX_SPEED_MAX = 24310 +OUTLET_MAX_SLOPE = ((OUTLET_MAX_SPEED_MAX - OUTLET_MIN_SPEED_MAX)/(PWM_MAX - PWM_MIN)) +OUTLET_MIN_SLOPE = ((OUTLET_MAX_SPEED_MIN - OUTLET_MIN_SPEED_MIN)/(PWM_MAX - PWM_MIN)) +OUTLET_MAX_SPEED = lambda _pwm: ((OUTLET_MAX_SLOPE * (_pwm - PWM_MIN)) + OUTLET_MIN_SPEED_MAX) +OUTLET_MIN_SPEED = lambda _pwm: ((OUTLET_MIN_SLOPE * (_pwm - PWM_MIN)) + OUTLET_MIN_SPEED_MIN) + +EVT_UNPLUG = 'evt_unplug' +EVT_PLUG = 'evt_plug' +EVT_PWM = 'evt_pwm' +EVT_NORMAL = 'evt_normal' +EVT_FAIL = 'evt_fail' +EVT_RETRY = 'evt_retry' +EVT_POLL = 'evt_poll' + +FAN_INIT_RETRY = 5 +FAN_PWM_RETRY = 6 +FAN_FAILED_RETRY = 3 + +class UnplugState(State): + def __init__(self): + self.msg = 'Unplugged' + def on_event(self, event): + evtmap = { + EVT_PLUG: InitState(), + } + return evtmap[event] if event in evtmap else self + +class InitState(State): + def __init__(self): + self.msg = 'Plugged' + def on_event(self, event): + evtmap = { + EVT_UNPLUG: UnplugState(), + EVT_NORMAL: NormalState(), + EVT_FAIL : FailState(), + } + return evtmap[event] if event in evtmap else self + +class NormalState(State): + def __init__(self): + self.msg = 'Plugged and normal' + def on_event(self, event): + evtmap = { + EVT_UNPLUG: UnplugState(), + EVT_PWM : PwmState(), + EVT_RETRY : FailRetryState(), + } + return evtmap[event] if event in evtmap else self + +class PwmState(State): + def on_event(self, event): + evtmap = { + EVT_UNPLUG: UnplugState(), + EVT_NORMAL: NormalState(), + EVT_FAIL : FailState(), + } + return evtmap[event] if event in evtmap else self + +class FailState(State): + def __init__(self): + self.msg = 'Fail' + def on_event(self, event): + evtmap = { + EVT_UNPLUG : UnplugState(), + EVT_NORMAL : NormalState(), + } + return evtmap[event] if event in evtmap else self + +class FailRetryState(State): + def on_event(self, event): + evtmap = { + EVT_UNPLUG: UnplugState(), + EVT_NORMAL: NormalState(), + EVT_PWM : PwmState(), + EVT_FAIL : FailState(), + } + return evtmap[event] if event in evtmap else self + +_NUM_ROTOR = 2 +class FanDev(StateDev): + def __init__(self, param): + super(FanDev, self).__init__(param) + + self.fan_input = [param['fan_input'][i] for i in range(_NUM_ROTOR)] + self.pwms = [param['pwm'][i] for i in range(_NUM_ROTOR)] + self.pwm_enable= [param['pwm_enable'][i] for i in range(_NUM_ROTOR)] + self.present_node = param['present'] + self.type_node = param['type'] + + ledmap = { + 'OFF': 0, + 'GREEN': 1, + 'AMBER': 2 + } + self.led = Led( os.path.join(self.cpld_path, param['tray_led']), self.name, ledmap) + self.led.set_led('OFF') + + self.rpm = [0]*_NUM_ROTOR + self.pwm = [0]*_NUM_ROTOR + self.state = UnplugState() + self.type = None + self.retry_count = 0 + + [ write_file(os.path.join(self.hwmon_path, self.hwmon_ext_path, p), 1) for p in self.pwm_enable ] + + def refresh_rpm(self): + self.rpm = [ cat_file(os.path.join(self.hwmon_path, self.hwmon_ext_path, r)) for r in self.fan_input ] + + def refresh_pwm(self): + self.pwm = [ cat_file(os.path.join(self.hwmon_path, self.hwmon_ext_path, p)) for p in self.pwms ] + + def refresh_present(self): + v = cat_file( os.path.join(self.cpld_path, self.present_node), 16) + self.present = 1 if v == FAN_PRESENT else 0 + + def refresh(self): + self.refresh_present() + self.refresh_pwm() + self.refresh_rpm() + + def update_type(self): + self.type = cat_file( os.path.join(self.cpld_path, self.type_node), 16) if self.get_present else None + DEBUG('{0.name} type {0.type}:{0.check_fan_type}'.format(self)) + + def get_rpm(self, *args): + return copy.copy(self.rpm) + + def get_pwm(self, *args): + return copy.copy(self.pwm) + + def set_pwm(self, index, v): + write_file( os.path.join(self.hwmon_path, self.hwmon_ext_path, self.pwms[index]), v) + + def dump_dev(self): + DEBUG ('{0.name} present:{0.get_present:2} inlet({0.pwm[0]:3},{0.rpm[0]:5}) outlet({0.pwm[1]:3},{0.rpm[1]:5})'.format(self)) + + def check_fan(self): + ret = 0 + for id in range(_NUM_ROTOR): + max = INLET_MAX_SPEED(self.pwm[id]) if id==0 else OUTLET_MAX_SPEED(self.pwm[id]) + min = INLET_MIN_SPEED(self.pwm[id]) if id==0 else OUTLET_MIN_SPEED(self.pwm[id]) + #DEBUG('{}-{} pwm:{:3} rpm:{:5} ({:5} ~ {:5})'.format(self.name, id, self.pwm[id], self.rpm[id],min, max)) + if(self.rpm[id] > max or self.rpm[id] < min): + ret |= 1< {new}) {evt} retry:{0.retry_count}'.format( self, old=state, new=new_state, evt=event)) + show_msg = False + if self.state in [FailState(), UnplugState(), InitState()]: + show_msg = True + elif self.state == NormalState() and state not in [PwmState(), FailRetryState()]: + show_msg = True + if show_msg: + INFO('{0.name} : {msg}'.format( self, msg=new_state.msg)) + self.dump_dev() + + if self.state == NormalState() : + self.led.set_led('GREEN') + elif self.state == FailState() : + self.led.set_led('AMBER' if self.check_fan_type else 'OFF') + elif self.state == UnplugState() : + self.led.set_led('OFF') + + def update_state(self): + old_pwm = self.get_pwm() + old_present = self.get_present + + self.refresh() + + if old_present != self.get_present: + self.update_type() + if self.get_present: + self.retry_count = FAN_INIT_RETRY + self.on_event(EVT_PLUG) + else: + self.on_event(EVT_UNPLUG) + elif self.get_present: + if not self.check_fan_type: + self.on_event(EVT_FAIL) + elif self.check_fan() == 0 : + self.on_event(EVT_NORMAL) + elif old_pwm != self.get_pwm(): + self.retry_count = FAN_PWM_RETRY + self.on_event(EVT_PWM) + elif self.state == NormalState() : + self.retry_count = FAN_FAILED_RETRY + self.on_event(EVT_RETRY) + elif self.retry_count > 0 : + self.retry_count -= 1 + self.on_event(EVT_POLL) + else: + self.on_event(EVT_FAIL) + +class FanDevMon(StateMon): + _config_key = 'mon_fan' + def __init__(self, data): + super(FanDevMon, self).__init__( data, FanDev) + + self._fan_fail = None + ledmap = { + 'OFF' : 0, + 'AMBER': 1, + 'GREEN': 2, + 'BLINK': 3, + } + self.led = Led(os.path.join(self.dev_list[0].cpld_path, data['devs'][0]['fan_panel_led']) , 'FanPanel', ledmap ) + self.led.set_led('OFF') + self.start_smart_fan = data['start_smart_fan'] + self.stop_smart_fan = data['stop_smart_fan'] + + self.shutdown_func() + + def shutdown_func(self): + os.system(self.stop_smart_fan) + [d.set_pwm( j , PWM_MAX) for j in range(_NUM_ROTOR) for d in self.dev_list] + def state_change(self): + state = self.get_state() + fan_fail = bool( [ (isinstance(i, FailState) or isinstance(i, UnplugState) or isinstance(i, InitState)) for i in state].count(True) ) + + if fan_fail != self._fan_fail: + self._fan_fail = fan_fail + + self.led.set_led( 'BLINK' if fan_fail else 'GREEN' ) + smart_fan_cmd = self.stop_smart_fan if fan_fail else self.start_smart_fan + DEBUG( smart_fan_cmd ) + os.system(smart_fan_cmd) + if fan_fail: + DEBUG('set fan pwm to max') + [d.set_pwm( j , PWM_MAX) for j in range(_NUM_ROTOR) for d in self.dev_list] diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/misc_dev.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/misc_dev.py new file mode 100755 index 000000000000..988faf739060 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/misc_dev.py @@ -0,0 +1,14 @@ + +from commonlib import * + +class MiscDev(CommonDev): + def __init__(self, param): + super(MiscDev, self).__init__(param) + self.present = 1 + def event_handler(self): + WARN( '{0.name} event_handler'.format(self) ) + +class MiscDevMon(DevMon): + _config_key = 'mon_misc' + def __init__(self, data): + super(MiscDevMon, self).__init__(data, MiscDev) diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/psu_dev.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/psu_dev.py new file mode 100755 index 000000000000..9bdd3e2b59d2 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/classes/sys_serv_pkg/psu_dev.py @@ -0,0 +1,229 @@ +import os +import copy + +from commonlib import * + +PSU_POWER_GOOD = 0 +PSU_PRESENT = 0 +PSU_POWER_FAULT= 1 + +EVT_UNPLUG = 'evt_ps' +EVT_PLUG = 'evt_ps_n' +EVT_PG = 'evt_pg' +EVT_PG_N = 'evt_pg_n' +EVT_PF = 'evt_pf' +EVT_PF_N = 'evt_pf_n' + +PSU_MODEL_TYPE_INIT = 0xFF +PSU_MODEL_TYPE_NOT_FOUND = 0xFE + +class AbsentState(State): + def __init__(self): + self.msg = 'Absent' + def on_event(self, event): + evtmap = { + EVT_PLUG : PresentState(), + } + return evtmap[event] if event in evtmap else self + +class PresentState(State): + def __init__(self): + self.msg = 'Present but no power' + def on_event(self, event): + evtmap = { + EVT_UNPLUG : AbsentState(), + EVT_PG : NormalState(), + } + return evtmap[event] if event in evtmap else self + +class NormalState(State): + def __init__(self): + self.msg = 'Present and work normal' + def on_event(self, event): + evtmap = { + EVT_UNPLUG : AbsentState(), + EVT_PG_N : PresentState(), + EVT_PF : FaultState(), + } + return evtmap[event] if event in evtmap else self + +class FaultState(State): + def on_event(self, event): + evtmap = { + EVT_UNPLUG : AbsentState(), + EVT_PG_N : PresentState(), + EVT_PF_N : NormalState(), + } + return evtmap[event] if event in evtmap else self + +class PsuDev(StateDev): + + def __init__(self, param): + super(PsuDev, self).__init__(param) + + self.sysfs_cmd = param["sysfs_cmd"] + self.present_node = param['present'] + self.power_good_node = param['power_good'] + self.model_type_node = param['model_reg'] + + self.power_good = int(not PSU_POWER_GOOD) + self.power_fault = dict([( x, int(not PSU_POWER_FAULT) ) for x in param['psu_intr_src'] ]) + self.state = AbsentState() + self.model_type = None + self.model_type_index = PSU_MODEL_TYPE_INIT + + self.sysfs_init_flag = 0 + + self.present_changed = 1 + self.power_good_changed = 1 + self.power_fault_changed = 1 + + self.update_state() + + self._crate_hwmon_sysfs() + + def _crate_hwmon_sysfs(self): + #if self.sysfs_init_flag == 0 and self.power_good and self.present: + if self.sysfs_init_flag == 0 and self.present: + if not os.path.exists(self.hwmon_path) : + INFO('{0.name} : run command --> {0.sysfs_cmd}'.format(self)) + os.system(self.sysfs_cmd) + + self.sysfs_init_flag = 1 + if self.hwmon_path : + try: + listofdir = [f for f in os.listdir(self.hwmon_path) if os.path.isdir( os.path.join(self.hwmon_path,str(f)))] + if len(listofdir) : + self.hwmon_ext_path = listofdir[0] + except : + self.sysfs_init_flag = 0 + + def refresh_present(self): + v = cat_file( os.path.join(self.cpld_path, self.present_node), 16) + self.present = 1 if v == PSU_PRESENT else 0 + + def refresh_power_good(self): + v = cat_file( os.path.join(self.cpld_path, self.power_good_node), 16) + self.power_good = 1 if v == PSU_POWER_GOOD else 0 + + def refresh_power_fault(self): + if self.sysfs_init_flag == 0 : return + if not self.present: return + + for f in self.power_fault: + self.power_fault[f] = cat_file(os.path.join(self.hwmon_path, self.hwmon_ext_path ,f), 16) + + def refresh(self): + self.refresh_present() + self.refresh_power_good() + self.refresh_power_fault() + + def update_model_type(self): + if self.model_type_index == PSU_MODEL_TYPE_INIT : + if not self.present : return + + if self.sysfs_init_flag == 0 : + self.model_type = None + else: + self.model_type = cat_file_str(os.path.join(self.hwmon_path, self.hwmon_ext_path, self.model_type_node)).strip() + if self.model_type == None: + return + INFO( '{0.name} type : {0.model_type}'.format(self) ) + try: + self.model_type_index = PsuType().psu_type.index(self.model_type) + if self.model_type_index != BoardType().board_type : + pass + except ValueError: + self.model_type_index = PSU_MODEL_TYPE_NOT_FOUND + + def get_power_good(self): + return self.power_good + + def get_power_fault(self): + return copy.copy(self.power_fault) + + def dump_dev(self): + pass + + def on_event(self, event): + state = self.state + new_state = self.state.on_event(event) + self.state = new_state + + if state != new_state : + DEBUG("{0.name} state ({old} --> {new}) {evt} ".format( self, old=state, new=new_state, evt=event )) + INFO("{0.name} : {msg}".format( self, msg=new_state.msg)) + self.dump_dev() + if new_state == NormalState(): + self._crate_hwmon_sysfs() + + if event == EVT_UNPLUG: + self.model_type_index = PSU_MODEL_TYPE_INIT + for f in self.power_fault: self.power_fault[f] = 0 + elif event == EVT_PLUG: + self.power_good_changed = 1 + self.power_fault_changed = 1 + elif event == EVT_PG: + self.power_fault_changed = 1 + + def update_state(self): + old_present = self.get_present + old_power_good = self.get_power_good() + old_power_fault = self.get_power_fault() + + self.refresh() + + if old_present != self.get_present : self.present_changed = 1 + elif old_power_good != self.get_power_good(): self.power_good_changed = 1 + elif old_power_fault != self.get_power_fault(): self.power_fault_changed = 1 + + if self.present_changed: + self.present_changed = 0 + self.on_event(EVT_PLUG if self.get_present else EVT_UNPLUG ) + if self.power_good_changed: + self.power_good_changed = 0 + self.on_event(EVT_PG if self.get_power_good() else EVT_PG_N ) + if self.power_fault_changed: + self.power_fault_changed = 0 + + pf = self.get_power_fault().values() + self.on_event( EVT_PF if list(pf).count(1) else EVT_PF_N ) + + if old_power_fault != self.get_power_fault(): + diff = set(self.power_fault.items()) - set(old_power_fault.items()) + [INFO ('{0.name} {key:15}: {val}'.format(self, key=e[0], val=e[1]) ) for e in diff] + +class PsuDevMon(StateMon): + _config_key = 'mon_psu' + def __init__(self, data): + super(PsuDevMon, self).__init__(data, PsuDev) + + ledmap = { + 'OFF' : 0, + 'AMBER': 1, + 'GREEN': 2, + 'BLINK': 3, + } + self.led = Led(os.path.join(self.dev_list[0].cpld_path, data['devs'][0]['psu_panel_led']) , 'PsuPanel', ledmap ) + self.led.set_led('GREEN') + + def state_change(self): + fault = bool( [ (isinstance(i, FaultState) ) for i in self.get_state() ].count(True) ) + + brd_type_error = False + for d in self.dev_list : + if d.model_type_index != PSU_MODEL_TYPE_INIT and d.model_type_index != BoardType().board_type : + ERR( '{0.name} type error {0.model_type_index} : {type}'.format(d, type=BoardType().board_type) ) + brd_type_error = True + break + + self.led.set_led( 'AMBER' if fault or brd_type_error else 'GREEN' ) + + def force_state_change(self) : + for d in self.dev_list : + index = d.model_type_index + + d.update_model_type() + if index != d.model_type_index : + return True + return False diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/fan-ctrld b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/fan-ctrld index 936f01e8b640..a7ae13ecee8b 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/fan-ctrld +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/fan-ctrld @@ -3,7 +3,7 @@ # Provides: fan-ctrld # Required-Start: # Required-Stop: -# Default-Start: rc.local +# Default-Start: # Default-Stop: # Short-Description: Daemon fan-ctrld ### END INIT INFO diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/gpe b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/gpe deleted file mode 100755 index c326442db047..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/gpe +++ /dev/null @@ -1,39 +0,0 @@ -#! /bin/bash -### BEGIN INIT INFO -# Provides: gpe -# Required-Start: -# Required-Stop: -# Default-Start: rc.local -# Default-Stop: -# Short-Description: Daemon gpe -### END INIT INFO - -# Load kernel modules -load_module () { - if [ `lsmod | grep -c "gpe "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_gpe.ko - fi -} - -remove_module () { - rmmod mitac-ly1200-32x_gpe -} - -case "$1" in - start) - load_module - ;; - stop) - remove_module - ;; - reload|restart|force-reload) - remove_module - load_module - ;; - *) - echo "Usage: $N {start|stop|reload|restart|force-reload}" >&2 - exit 1 - ;; -esac - -exit 0 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/i2c_init b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/i2c_init index caddfce3325d..44006e5b5011 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/i2c_init +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/i2c_init @@ -1,16 +1,17 @@ #!/bin/bash ### BEGIN INIT INFO -# Provides: setup-board +# Provides: setup-board-i2c # Required-Start: # Required-Stop: # Should-Start: # Should-Stop: -# Default-Start: S -# Default-Stop: 0 6 +# Default-Start: +# Default-Stop: # Short-Description: Setup ly1200-32x board. ### END INIT INFO +I2C_BUS_RM_ALL=0 I2C_I801_RM_PRINT=0 I2C_ISMT_RM_PRINT=0 I2C_I801_INS_PRINT=0 @@ -47,134 +48,53 @@ function log_msg() { # Load kernel modules load_modules () { - #----------remove i801 start--------------------- - if [ `lsmod | grep -c "i2c_i801 "` -eq 1 ]; then - rmmod i2c_i801 - while [ `lsmod | grep -c "i2c_i801 "` -eq 1 ] - do - if [ $I2C_I801_RM_PRINT -eq 0 ]; then - I2C_I801_RM_PRINT=1 - log_msg "Wait for i2c_i801 remove." - fi - if [ $I2C_I801_RM_RETRY -lt $RETRY ];then - I2C_I801_RM_RETRY=$((I2C_I801_RM_RETRY + 1)) - else - break - fi - sleep 1 - done - if [ $I2C_I801_RM_PRINT -eq 1 ]; then - log_msg "i2c_i801 remove success." - fi - fi - #----------remove i801 end------------------------ - - - #----------remove ismt start---------------------- - if [ `lsmod | grep -c "i2c_ismt "` -eq 1 ]; then - rmmod i2c_ismt - while [ `lsmod | grep -c "i2c_ismt "` -eq 1 ] - do - if [ $I2C_ISMT_RM_PRINT -eq 0 ]; then - I2C_ISMT_RM_PRINT=1 - log_msg "Wait for i2c_ismt remove." - fi - if [ $I2C_ISMT_RM_RETRY -lt $RETRY ];then - I2C_ISMT_RM_RETRY=$((I2C_ISMT_RM_RETRY + 1)) - else - break - fi - sleep 1 - done - if [ $I2C_ISMT_RM_PRINT -eq 1 ]; then - log_msg "i2c_ismt remove success." - fi - fi - #----------remove ismt end------------------------ - - #----------insert i801 start---------------------- - insmod /lib/modules/`uname -r`/kernel/drivers/i2c/busses/i2c-i801.ko - while [ `lsmod | grep -c "i2c_i801 "` -eq 0 ] - do - if [ $I2C_I801_INS_PRINT -eq 0 ]; then - I2C_I801_INS_PRINT=1 - log_msg "Wait for i2c_i801 insert." - fi - if [ $I2C_I801_INS_RETRY -lt $RETRY ];then - I2C_I801_INS_RETRY=$((I2C_I801_INS_RETRY + 1)) - else - break - fi - sleep 1 - done - if [ $I2C_I801_INS_PRINT -eq 1 ]; then - log_msg "i2c_i801 insert success." - fi - #----------insert i801 end------------------------ - - #----------insert ismt start---------------------- - insmod /lib/modules/`uname -r`/kernel/drivers/i2c/busses/i2c-ismt.ko - while [ `lsmod | grep -c "i2c_ismt "` -eq 0 ] - do - if [ $I2C_ISMT_INS_PRINT -eq 0 ]; then - I2C_ISMT_INS_PRINT=1 - log_msg "Wait for i2c_ismt insert." - fi - if [ $I2C_ISMT_INS_RETRY -lt $RETRY ];then - I2C_ISMT_INS_RETRY=$((I2C_ISMT_INS_RETRY + 1)) - else - break - fi - sleep 1 - done - if [ $I2C_ISMT_INS_PRINT -eq 1 ]; then - log_msg "i2c_ismt insert success." - fi - #----------insert ismt start------------------------ + modprobe i2c_i801 + modprobe i2c_ismt + if [ `lsmod | grep -c "at24 "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/misc/eeprom/at24.ko + modprobe at24 fi if [ `lsmod | grep -c "i2c_mux "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/i2c/i2c-mux.ko + modprobe i2c_mux fi if [ `lsmod | grep -c "i2c_mux_pca954x "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/i2c/muxes/i2c-mux-pca954x.ko + modprobe i2c_mux_pca954x fi if [ `lsmod | grep -c "lm75 "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/hwmon/lm75.ko + modprobe lm75 fi if [ `lsmod | grep -c "max31790 "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/hwmon/max31790.ko + modprobe max31790 fi if [ `lsmod | grep -c "sff_8436_eeprom "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/kernel/drivers/misc/eeprom/sff_8436_eeprom.ko + modprobe sff_8436_eeprom fi if [ `lsmod | grep -c "mitac_ly1200_32x_fse000 "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_fse000.ko + modprobe mitac_ly1200_32x_fse000 fi if [ `lsmod | grep -c "mitac_ly1200_32x_system_cpld "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_system_cpld.ko + modprobe mitac_ly1200_32x_system_cpld fi if [ `lsmod | grep -c "mitac_ly1200_32x_master_cpld "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_master_cpld.ko + modprobe mitac_ly1200_32x_master_cpld fi if [ `lsmod | grep -c "mitac_ly1200_32x_slave_cpld "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_slave_cpld.ko + modprobe mitac_ly1200_32x_slave_cpld fi if [ `lsmod | grep -c "mitac_ly1200_32x_cb_i2c "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_cb_i2c.ko + modprobe mitac_ly1200_32x_cb_i2c fi if [ `lsmod | grep -c "mitac_ly1200_32x_sb_i2c "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_sb_i2c.ko + modprobe mitac_ly1200_32x_sb_i2c fi if [ `lsmod | grep -c "mitac_ly1200_32x_pb_i2c "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_pb_i2c.ko + modprobe mitac_ly1200_32x_pb_i2c fi if [ `lsmod | grep -c "mitac_ly1200_32x_fb_i2c "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_fb_i2c.ko + modprobe mitac_ly1200_32x_fb_i2c fi if [ `lsmod | grep -c "mitac_ly1200_32x_fb_module_i2c "` -eq 0 ]; then - insmod /lib/modules/`uname -r`/extra/mitac_ly1200_32x_fb_module_i2c.ko + modprobe mitac_ly1200_32x_fb_module_i2c fi } @@ -185,18 +105,24 @@ load_i2c_dev_modules () { fi } +# Load nvmem_core modules +load_nvmem_core_modules () { + if [ `lsmod | grep -c "nvmem_core "` -eq 0 ]; then + modprobe nvmem_core + fi +} + case "$1" in start) - echo -n "Setting up board... " + echo -n "Loading modules for board... " load_i2c_dev_modules + load_nvmem_core_modules load_modules echo "done." ;; stop) echo -n "cleaning... " - - echo "done." ;; diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_polld b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_polld index 1df43346f257..7918c836c628 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_polld +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_polld @@ -3,7 +3,7 @@ # Provides: sys-polld # Required-Start: # Required-Stop: -# Default-Start: rc.local +# Default-Start: # Default-Stop: # Short-Description: Daemon sys-polld ### END INIT INFO diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_servd index 09ee087d5db0..4a9b5fb4adb7 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_servd +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/sys_servd @@ -3,22 +3,25 @@ # Provides: sys-servd # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog -# Default-Start: rc.local -# Default-Stop: 0 1 6 +# Default-Start: +# Default-Stop: # Short-Description: Daemon sys-servd ### END INIT INFO # Author: Eddy Weng DESC="Service script for /opt/sys-serv/sys-servd" -DAEMON=/opt/sys-serv/sys-servd +DAEMON='/usr/bin/python -m /usr/lib/python2.7/dist-packages/sys_serv_pkg' +DAEMON_OPTS='-dinfo' + +PIDFILE=/var/run/sys-serv.pid case "$1" in start) - start-stop-daemon --start --exec $DAEMON + start-stop-daemon --start --make-pidfile --pidfile $PIDFILE --background -N-20 --exec $DAEMON -- $DAEMON_OPTS ;; stop) - start-stop-daemon --stop --name sys-servd + start-stop-daemon --stop --pidfile $PIDFILE ;; *) exit 1 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/xcvr_servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/xcvr_servd deleted file mode 100755 index 1558614fd43c..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/init.d/xcvr_servd +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -### BEGIN INIT INFO -# Provides: xcvr-servd -# Required-Start: $remote_fs $syslog -# Required-Stop: $remote_fs $syslog -# Default-Start: rc.local -# Default-Stop: 0 1 6 -# Short-Description: Daemon xcvr-servd -### END INIT INFO - -# Author: Yencheng Lin - -DESC="Service script for /opt/xcvr-serv/xcvr-servd" -DAEMON=/opt/xcvr-serv/xcvr-servd - -case "$1" in - start) - start-stop-daemon --start --exec $DAEMON - ;; - stop) - start-stop-daemon --stop --name xcvr-servd - ;; - *) - exit 1 - ;; -esac - -exit 0 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc0.d/K02xcvr_servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc0.d/K02xcvr_servd deleted file mode 120000 index d71f756d3deb..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc0.d/K02xcvr_servd +++ /dev/null @@ -1 +0,0 @@ -../init.d/xcvr_servd \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc1.d/K02xcvr_servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc1.d/K02xcvr_servd deleted file mode 120000 index d71f756d3deb..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc1.d/K02xcvr_servd +++ /dev/null @@ -1 +0,0 @@ -../init.d/xcvr_servd \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc6.d/K02xcvr_servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc6.d/K02xcvr_servd deleted file mode 120000 index d71f756d3deb..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/etc/rc6.d/K02xcvr_servd +++ /dev/null @@ -1 +0,0 @@ -../init.d/xcvr_servd \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/master_cpld_sysfs.h b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/master_cpld_sysfs.h index e851ca5fb487..cc256db58c9d 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/master_cpld_sysfs.h +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/master_cpld_sysfs.h @@ -8,7 +8,7 @@ struct device_attribute field \ #define SYSFS_RAW_RW_ATTR_DEF(field) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, master_cpld_##field##_raw_read, master_cpld_##field##_raw_write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, master_cpld_##field##_raw_read, master_cpld_##field##_raw_write); #define SYSFS_MISC_RO_ATTR_DEF(field, _read) \ struct device_attribute field \ @@ -16,7 +16,7 @@ struct device_attribute field \ #define SYSFS_MISC_RW_ATTR_DEF(field, _read, _write) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, _read, _write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, _read, _write); #define SYSFS_ATTR_PTR(field) \ &field.attr diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/mitac_ly1200_32x_system_cpld.c b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/mitac_ly1200_32x_system_cpld.c index e5af8b70bf9a..0900070a8d07 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/mitac_ly1200_32x_system_cpld.c +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/mitac_ly1200_32x_system_cpld.c @@ -5,7 +5,12 @@ #include "system_cpld_reg.h" #include "system_cpld_sysfs.h" -#ifdef CONFIG_DRV_SYSCPLD_WDT + +#define MIC_DEBUG_TAG " [mitac] " +#define MITAC_WDT_MINOR 135 +#define MITAC_WDT_NAME "watchdog5" + +#if CONFIG_DRV_SYSCPLD_WDT #include #include #include @@ -33,7 +38,6 @@ MODULE_DEVICE_TABLE(i2c, system_cpld_ids); static int system_cpld_raw_read(struct device *dev, struct device_attribute *attr, char *buf, int reg_offset, int reg_width, int fld_shift, int fld_width, int fld_mask, char* reg_name){ unsigned int reg_val = 0, fld_val; - static int debug_flag; struct system_cpld_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; int err; @@ -64,7 +68,6 @@ static int system_cpld_raw_write(struct device *dev, struct device_attribute *at int ret_code; unsigned int reg_val, fld_val; unsigned long val; - static int debug_flag; struct system_cpld_data *data = dev_get_drvdata(dev); struct i2c_client *client = data->client; if (reg_width != 8){ @@ -192,7 +195,7 @@ static const struct attribute_group system_cpld_group_misc = { .attrs = misc_attributes, }; -#ifdef CONFIG_DRV_SYSCPLD_WDT +#if CONFIG_DRV_SYSCPLD_WDT /* ***************************************************************************** * @@ -276,9 +279,9 @@ static void wdt_set_timeout(int index) { struct device *dev = &system_cpld->client->dev; struct device_attribute *fake_attr=NULL; - char buf[1]; + char buf[16]; if ( WD_TIMO_MAX_NUM == 16 ) { - sprintf(buf,"%x",index); + snprintf(buf, 16, "%x",index); system_cpld_wd_timer_raw_write(dev, fake_attr, buf, (size_t)0); } else @@ -390,7 +393,7 @@ static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd, */ static int wdt_open(struct inode *inode, struct file *file) { - if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { + if (MINOR(inode->i_rdev) == MITAC_WDT_MINOR) { if (test_and_set_bit(0, &wdt_is_open)) { return -EBUSY; } @@ -412,7 +415,7 @@ static int wdt_open(struct inode *inode, struct file *file) */ static int wdt_release(struct inode *inode, struct file *file) { - if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) + if (MINOR(inode->i_rdev) == MITAC_WDT_MINOR) clear_bit(0, &wdt_is_open); return 0; } @@ -447,8 +450,8 @@ static const struct file_operations wdt_fops = { }; static struct miscdevice wdt_dev = { - .minor = WATCHDOG_MINOR, - .name = "watchdog", + .minor = MITAC_WDT_MINOR, + .name = MITAC_WDT_NAME, .fops = &wdt_fops, }; @@ -459,6 +462,8 @@ static struct miscdevice wdt_dev = { static struct notifier_block wdt_notifier = { .notifier_call = wdt_notify_sys, }; +static struct notifier_block *p_wdt_notifier = NULL; + #endif /* CONFIG_DRV_SYSCPLD_WDT */ static int system_cpld_probe(struct i2c_client *client, const struct i2c_device_id *id) @@ -483,14 +488,22 @@ static int system_cpld_probe(struct i2c_client *client, const struct i2c_device_ printk(KERN_INFO "%s: System CPLD LCMXO3LF created.\n", __FUNCTION__); -#ifdef CONFIG_DRV_SYSCPLD_WDT +#if CONFIG_DRV_SYSCPLD_WDT + wdt_dev.minor = MITAC_WDT_MINOR; err = misc_register(&wdt_dev); - if (err) - return err; - err = register_reboot_notifier(&wdt_notifier); if (err) { - misc_deregister(&wdt_dev); - return err; + printk(MIC_DEBUG_TAG"%s-%d misc_register register watchdog (%s : %d) fail err=%d \n", __FUNCTION__, __LINE__, wdt_dev.name, wdt_dev.minor, err); + wdt_dev.minor = 0; + } + else { + p_wdt_notifier = &wdt_notifier; + err = register_reboot_notifier(p_wdt_notifier); + if (err) { + printk(MIC_DEBUG_TAG"%s-%d register_reboot_notifier fail err:%d \n", __FUNCTION__, __LINE__, err); + misc_deregister(&wdt_dev); + p_wdt_notifier = NULL; + wdt_dev.minor = 0; + } } printk(KERN_INFO "%s: System CPLD watchdog created.\n", __FUNCTION__); #endif @@ -501,9 +514,9 @@ static int system_cpld_probe(struct i2c_client *client, const struct i2c_device_ static int system_cpld_remove(struct i2c_client *client) { -#ifdef CONFIG_DRV_SYSCPLD_WDT - misc_deregister(&wdt_dev); - unregister_reboot_notifier(&wdt_notifier); +#if CONFIG_DRV_SYSCPLD_WDT + if(p_wdt_notifier) unregister_reboot_notifier(p_wdt_notifier); + if(wdt_dev.minor) misc_deregister(&wdt_dev); #endif sysfs_remove_group(&client->dev.kobj, &system_cpld_group_misc); diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/slave_cpld_sysfs.h b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/slave_cpld_sysfs.h index 92d00d29d493..a619f45388cb 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/slave_cpld_sysfs.h +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/slave_cpld_sysfs.h @@ -8,7 +8,7 @@ struct device_attribute field \ #define SYSFS_RAW_RW_ATTR_DEF(field) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, slave_cpld_##field##_raw_read, slave_cpld_##field##_raw_write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, slave_cpld_##field##_raw_read, slave_cpld_##field##_raw_write); #define SYSFS_MISC_RO_ATTR_DEF(field, _read) \ struct device_attribute field \ @@ -16,7 +16,7 @@ struct device_attribute field \ #define SYSFS_MISC_RW_ATTR_DEF(field, _read, _write) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, _read, _write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, _read, _write); #define SYSFS_ATTR_PTR(field) \ &field.attr diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/system_cpld_sysfs.h b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/system_cpld_sysfs.h index e6b03bd1bd0d..1dbe9b2819f9 100644 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/system_cpld_sysfs.h +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/modules/system_cpld_sysfs.h @@ -8,7 +8,7 @@ struct device_attribute field \ #define SYSFS_RAW_RW_ATTR_DEF(field) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, system_cpld_##field##_raw_read, system_cpld_##field##_raw_write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, system_cpld_##field##_raw_read, system_cpld_##field##_raw_write); #define SYSFS_MISC_RO_ATTR_DEF(field, _read) \ struct device_attribute field \ @@ -16,7 +16,7 @@ struct device_attribute field \ #define SYSFS_MISC_RW_ATTR_DEF(field, _read, _write) \ struct device_attribute field \ - = __ATTR(field, S_IRUGO | S_IWUGO, _read, _write); + = __ATTR(field, S_IRUGO | S_IWUSR | S_IWGRP, _read, _write); #define SYSFS_ATTR_PTR(field) \ &field.attr diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone-thermal_B2F.conf b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone-thermal_B2F.conf similarity index 100% rename from platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone-thermal_B2F.conf rename to platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone-thermal_B2F.conf diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone-thermal_F2B.conf b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone-thermal_F2B.conf similarity index 100% rename from platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone-thermal_F2B.conf rename to platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone-thermal_F2B.conf diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone_B2F.conf b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone_B2F.conf similarity index 100% rename from platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone_B2F.conf rename to platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone_B2F.conf diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone_F2B.conf b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone_F2B.conf similarity index 100% rename from platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-zone_F2B.conf rename to platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/conf_file/fan-zone_F2B.conf diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-ctrl b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-ctrl index 73ff759b6f45..b3a7b94f5ebb 100755 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-ctrl +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/fan-ctrl @@ -1,679 +1,16 @@ -#!/bin/bash -#/* -#********************************************************************** -#* -#* @filename fan-ctrl -#* -#* @purpose system daemon for controlling system fan pwm -#* -#* @create 2017/06/21 -#* -#* @author nixon.chu -#* -#* @history 2017/06/21: init version -#* -#********************************************************************** -#*/ - -DIR=$(dirname $0) - -# include files -source ${DIR}/funcs.sh - -#/* -#********************************************************************** -#* -#* CONSTANT VARIABLES -#* -#********************************************************************** -#*/ - -# process name/id -DAEMON_NAME=`basename $0` -DAEMON_PID="$$" - -# define symbol for fan/temperature type sensor -SYMBOL_TEMP="TEMP_" -SYMBOL_FAN="FAN_" - -# describe the structure of temperature sensor by id -STRUCT_TEMP_NAME=0 -STRUCT_TEMP_CMD=1 -STRUCT_TEMP_MAX=2 -STRUCT_TEMP_SIZE=$(( ${STRUCT_TEMP_MAX} + 1 )) - -# describe the structure of fan sensor by id -STRUCT_FAN_CMD=0 -STRUCT_FAN_SIZE=$(( ${STRUCT_FAN_CMD} + 1 )) - -# default fan zone configuration file -DEF_ZONE_CONF="${DIR}/fan-zone.conf" - -# default fan zone thermal configuration file -DEF_TEMP_CONF="${DIR}/fan-zone-thermal.conf" - -# default interval (sec) -DEF_INTERVAL=10 - -# default hysteresis (deg C) -DEF_HYSIS=3 - -# default debug mode (0: OFF, 1: ON) -DEF_DEBUG_MODE=0 - -# default log file -DEF_LOG_FILE="/var/log/syslog" - -# default fan level -DEF_FAN_LEVEL=0 - -# default minimum pwm (38.25=255x15%) -DEF_MIN_PWM=39 - -# default zone id -DEF_ZONE_ID=0 - -# error codes -E_STATUS_GOOD=0 -E_STATUS_FAULT=1 -E_INVALID_ARGS=11 -E_INVALID_CONF=12 - -# message levels -MSG_EMERG=0 -MSG_ALERT=1 -MSG_CRIT=2 -MSG_ERR=3 -MSG_WARNING=4 -MSG_NOTICE=5 -MSG_INFO=6 -MSG_DEBUG=7 - -# default message level -DEF_MSG_LEVEL=$MSG_WARNING - -#/* -#********************************************************************** -#* -#* GLOBAL VARIABLES -#* -#********************************************************************** -#*/ - -# temperature sensor group -GBL_TEMP_GRP=() -GBL_TEMP_NUM=${#GBL_TEMP_GRP[@]} - -# fan sensor group -GBL_FAN_GRP=() -GBL_FAN_NUM=${#GBL_FAN_GRP[@]} - -# fan level table -GBL_FAN_LEVEL=() -GBL_LEVEL_NUM=${#GBL_FAN_LEVEL[@]} - -# load defaults -GBL_ZONE_CONF=$DEF_ZONE_CONF -GBL_TEMP_CONF=$DEF_TEMP_CONF -GBL_INTERVAL=$DEF_INTERVAL -GBL_HYSIS=$DEF_HYSIS -GBL_DEBUG_MODE=$DEF_DEBUG_MODE -GBL_LOG_FILE=$DEF_LOG_FILE -GBL_CUR_LEVEL=$DEF_FAN_LEVEL -GBL_MIN_PWM=$DEF_MIN_PWM -GBL_ZONE_ID=$DEF_ZONE_ID -GBL_MSG_LEVEL=$DEF_MSG_LEVEL - -# temperature sensors' readings/statuses/properties (properties list have to be converted with fan level table) -GBL_TEMP_READINGS=() -GBL_TEMP_STATUSES=() -GBL_TEMP_PROPERTY=() - -#/* -#********************************************************************** -#* -#* FUNCTIONS -#* -#********************************************************************** -#*/ - -#/* -#* FEATURE: -#* usage -#* PURPOSE: -#* show the usage of this daemon -#* PARAMETERS: -#* -#* RETURNS: -#* success, this function returns @E_INVALID_ARGS. -#*/ -function usage() { - local dbg_mode - - [ $GBL_DEBUG_MODE -eq 0 ] && dbg_mode="off" || dbg_mode="on" - - echo -e "Usage: $0 [-z zone_file] [-t thermal_file] [-o log_file] [-d]" >&2 - echo -e "" >&2 - echo -e "Arguments:" >&2 - echo -e " -z, --zone-config Fan zone configuration file (default: $DEF_ZONE_CONF)" >&2 - echo -e " -t, --temp-config Fan zone thermal configuration file (default: $DEF_TEMP_CONF)" >&2 - echo -e " -o, --log-file Log file (default: $DEF_LOG_FILE)" >&2 - echo -e " -d, --debug Debug mode (default: $dbg_mode)" >&2 - exit ${E_INVALID_ARGS} -} - -#/* -#* FEATURE: -#* print_msg -#* PURPOSE: -#* print message by message level -#* PARAMETERS: -#* msg_lvl (IN) message level -#* msg (IN) message -#* RETURNS: -#* -#*/ -function print_msg() { - local msg_lvl=$1 - local msg=$2 - - [ $msg_lvl -le $GBL_MSG_LEVEL ] && echo "${msg}" >&2 -} - -#/* -#* FEATURE: -#* err_msg -#* PURPOSE: -#* log error message -#* PARAMETERS: -#* msg (IN) message -#* err_no (IN) error code -#* RETURNS: -#* success, this function returns non-zero error code. -#*/ -function err_msg() { - local msg=$1 - local err_no=$2 - - log_msg $MSG_ERROR "${msg}" - exit ${err_no} -} - -#/* -#* FEATURE: -#* log_msg -#* PURPOSE: -#* log message -#* PARAMETERS: -#* msg_lvl (IN) message level -#* msg (IN) message -#* RETURNS: -#* -#*/ -function log_msg() { - local msg_lvl=$1 - local msg=$2 - - if [ $GBL_LOG_FILE == $DEF_LOG_FILE ]; then - `logger -t $DAEMON_NAME -p $msg_lvl $msg` - else - echo -e "`date +"%b %_d %T"` `hostname` $DAEMON_NAME[$DAEMON_PID]: ${msg}" >> ${GBL_LOG_FILE} - fi - - print_msg $msg_lvl "${msg}" -} - -#/* -#* FEATURE: -#* debug_temp_grp -#* PURPOSE: -#* debug function for showing the temperature sensor group configs -#* @GBL_TEMP_GRP[]: store sensor group configs (sensor name, command, and max_temp) -#* PARAMETERS: -#* -#* RETURNS: -#* -#*/ -function debug_temp_grp() { - if [ $GBL_DEBUG_MODE -ne 0 ]; then - echo "********* Sensor Group *********" - for ((i=0; i<$GBL_TEMP_NUM; i++)) - do - echo -en "`fetch_temp_struct $i $STRUCT_TEMP_NAME`\t" - echo -en "`fetch_temp_struct $i $STRUCT_TEMP_CMD`\t" - echo "`fetch_temp_struct $i $STRUCT_TEMP_MAX`" - done - fi -} - -#/* -#* FEATURE: -#* debug_temp_readings -#* PURPOSE: -#* debug function for showing the temperature sensors' readings -#* @GBL_TEMP_READINGS[]: store current reading for temperature sensors -#* PARAMETERS: -#* -#* RETURNS: -#* -#*/ -function debug_temp_readings() { - if [ $GBL_DEBUG_MODE -ne 0 ]; then - echo "********* Sensor Reading *********" - for ((i=0; i<$GBL_TEMP_NUM; i++)) - do - echo -e "`fetch_temp_struct $i $STRUCT_TEMP_NAME`\t${GBL_TEMP_READINGS[$i]}" - done - fi -} - -#/* -#* FEATURE: -#* debug_temp_property -#* PURPOSE: -#* debug function for showing the temperature sensors' properties -#* @GBL_TEMP_PROPERTY[]: store temperature sensors' properties (asserted temperature for each fan levels) -#* PARAMETERS: -#* -#* RETURNS: -#* -#*/ -function debug_temp_property() { - local size base start_idx level - if [ $GBL_DEBUG_MODE -ne 0 ]; then - echo "********* Sensor Table *********" - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - # show array @GBL_TEMP_PROPERTY[]: format name(1) + fan levels(2-?) - size=$(( ${GBL_LEVEL_NUM}+1 )) - base=$i*${size} - start_idx=$(( $base+1 )) - level=${GBL_LEVEL_NUM} - echo -e "${GBL_TEMP_PROPERTY[$base]}\t\t${GBL_TEMP_PROPERTY[@]:$start_idx:$level}" - done - fi -} - -#/* -#* FEATURE: -#* fetch_temp_struct -#* PURPOSE: -#* fetch the member value of specific temperature sensor -#* PARAMETERS: -#* id (IN) sensor id -#* member_id (IN) member id -#* RETURNS: -#* success, returns member value -#*/ -function fetch_temp_struct() { - local id member_id index_base data - - id=$1 - member_id=$2 - - index_base=$(( $id * $STRUCT_TEMP_SIZE )) - data=${GBL_TEMP_GRP[$(($index_base+$member_id))]} - # remove unuseful characters, such as double quotes('"') and the start/end space(' ') of a string. - data=`echo $data | sed 's/^ *\| *$//g' | sed 's/^"\|\"$//g'` - echo $data -} - -#/* -#* FEATURE: -#* fetch_temp_property -#* PURPOSE: -#* fetch the properties of specific temperature sensor -#* PARAMETERS: -#* name (IN) sensor name -#* RETURNS: -#* success, returns an asserted temperature list -#*/ -function fetch_temp_property() { - local name size base start_idx length - - name=$1 - - size=$(( $GBL_LEVEL_NUM+1 )) - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - base=$i*${size} - # find sensor by name - if [ ${GBL_TEMP_PROPERTY[${base}]} == "${name}" ]; then - start_idx=$(( $base+1 )) - length=$GBL_LEVEL_NUM - echo ${GBL_TEMP_PROPERTY[@]:$start_idx:$length} - break - fi - done -} - -#/* -#* FEATURE: -#* debug_fan_speed -#* PURPOSE: -#* debug function for showing system current fan level and PWM -#* @GBL_CUR_LEVEL: system current/output fan level -#* PARAMETERS: -#* -#* RETURNS: -#* -#*/ -function debug_fan_speed() { - if [ $GBL_DEBUG_MODE -ne 0 ]; then - # For human readable, the representation of fan level will start from 1. - echo "Current Level: $(( $GBL_CUR_LEVEL+1 )), PWM: ${GBL_FAN_LEVEL[$GBL_CUR_LEVEL]}" - fi -} - -#/* -#* FEATURE: -#* arg_parse -#* PURPOSE: -#* parser for input arguments -#* PARAMETERS: -#* arg_lists[] (IN) argument list -#* RETURNS: -#* -#*/ -function arg_parse() { - while [[ $# -ge 1 ]] - do - key="$1" - case $key in - -z|--zone-config) - [ $# -lt 2 ] && usage - GBL_ZONE_CONF=$2 - [ ! -e $GBL_ZONE_CONF ] && usage - shift # past argument - ;; - -t|--temp-config) - [ $# -lt 2 ] && usage - GBL_TEMP_CONF=$2 - [ ! -e $GBL_TEMP_CONF ] && usage - shift # past argument - ;; - -o|--log-file) - [ $# -lt 2 ] && usage - GBL_LOG_FILE=$2 - shift # past argument - ;; - -d|--debug) - GBL_DEBUG_MODE=1 - ;; - *) - usage # unknown option - ;; - esac - shift # past argument or value - done -} - -#/* -#* FEATURE: -#* valid_conf -#* PURPOSE: -#* check if configuration files are valid -#* PARAMETERS: -#* -#* RETURNS: -#* success, this function returns nothing -#* fail, returns @E_INVALID_CONF -#*/ -function valid_conf() { - local list_1 list_2 match_num - - list_1=("${!1}") - list_2=("${!2}") - - # validate zone config - [ ${GBL_TEMP_NUM} -eq 0 ] && err_msg "config: status=invalid. reason=no TEMPERATURE SENSORS defined." "${E_INVALID_CONF}" - [ ${GBL_FAN_NUM} -eq 0 ] && err_msg "config: status=invalid. reason=no FAN defined." "${E_INVALID_CONF}" - - # validate thermal config - [ ${GBL_LEVEL_NUM} -eq 0 ] && err_msg "config: status=invalid. reason=no FAN LEVELS defined." "${E_INVALID_CONF}" - [ ${#list_2[@]} -ne ${GBL_TEMP_NUM} ] && err_msg "config: status=invalid. reason=the number of temperature sensors is inconsistent." "${E_INVALID_CONF}" - - # compare temperature sensor name between configuration files - match_num=0 - for i in ${!list_1[@]} - do - for j in ${!list_2[@]} - do - [ "${list_1[$i]}" == "${list_2[$j]}" ] && match_num=$(( $match_num+1 )) - done - done - [ $match_num -ne ${GBL_TEMP_NUM} ] && err_msg "config: status=invalid. reason=the name of temperature sensors is inconsistent." "${E_INVALID_CONF}" - - # validate pwm values - for pwm in ${GBL_FAN_LEVEL[@]} - do - expr $pwm + $GBL_MIN_PWM >/dev/null 2>&1 - [ $? -ne 0 ] && err_msg "config: status=invalid. reason=the value of pwm is not integer." "$E_INVALID_CONF" - [ $pwm -lt $GBL_MIN_PWM ] && err_msg "config: status=invalid. reason=the value of fan level is less than MIN_PWM($GBL_MIN_PWM)." "$E_INVALID_CONF" - done -} - -#/* -#* FEATURE: -#* initialize -#* PURPOSE: -#* load zone config and thermal config -#* PARAMETERS: -#* -#* RETURNS: -#* -#*/ -function initialize() { - local data conf_interval conf_hysis conf_min_pwm conf_zone_id conf_msg_level temp_list_1 temp_list_2 - - log_msg $MSG_INFO "Initializing fan control service..." - - # fetch temperature sensor name from configuration files - temp_list_1=(`cat ${GBL_ZONE_CONF} | grep "^${SYMBOL_TEMP}" | awk -F "," {'print $1'}`) - temp_list_2=(`cat ${GBL_TEMP_CONF} | grep "^${SYMBOL_TEMP}" | awk {'print $1'}`) - - # calculate the number of temperature/fan sensors - GBL_TEMP_NUM=${#temp_list_1[@]} - GBL_FAN_NUM=(`cat ${GBL_ZONE_CONF} | grep "^${SYMBOL_FAN}" | awk {'print $2'} | wc -l`) - - # calculate the number of fan levels - GBL_FAN_LEVEL=(`cat ${GBL_TEMP_CONF} | grep "^PWM" | awk -F "PWM" {'print $2'}`) - GBL_LEVEL_NUM=${#GBL_FAN_LEVEL[@]} - - # check if the interval/hyteresis should be updated. - conf_interval=`cat ${GBL_ZONE_CONF} | grep "^INTERVAL=" | awk -F "=" {'print $2'} | tail` - [ ! -z ${conf_interval} ] && GBL_INTERVAL=${conf_interval} - conf_hysis=`cat ${GBL_ZONE_CONF} | grep "^HYTERESIS=" | awk -F "=" {'print $2'} | tail` - [ ! -z ${conf_hysis} ] && GBL_HYSIS=${conf_hysis} - conf_min_pwm=`cat ${GBL_ZONE_CONF} | grep "^MIN_PWM=" | awk -F "=" {'print $2'} | tail` - [ ! -z ${conf_min_pwm} ] && GBL_MIN_PWM=${conf_min_pwm} - conf_zone_id=`cat ${GBL_ZONE_CONF} | grep "^ZONE_ID=" | awk -F "=" {'print $2'} | tail` - [ ! -z ${conf_zone_id} ] && GBL_ZONE_ID=${conf_zone_id} - conf_msg_level=`cat ${GBL_ZONE_CONF} | grep "^MSG_LEVEL=" | awk -F "=" {'print $2'} | tail` - [ ! -z ${conf_msg_level} ] && GBL_MSG_LEVEL=${conf_msg_level} - - # load zone config - for ((i=1; i<=${GBL_TEMP_NUM}; i++)) - do - GBL_TEMP_STATUSES+=($E_STATUS_GOOD) - data=`cat ${GBL_ZONE_CONF} | grep "^${SYMBOL_TEMP}" | awk NR==$i` - # FIXME - GBL_TEMP_GRP+=("`echo $data | awk -F ", " {'print $1'}`") - GBL_TEMP_GRP+=("`echo $data | awk -F ", " {'print $2'}`") - GBL_TEMP_GRP+=("`echo $data | awk -F ", " {'print $3'}`") - done - debug_temp_grp - - for ((i=1; i<=${GBL_FAN_NUM}; i++)) - do - data=`cat ${GBL_ZONE_CONF} | grep "^${SYMBOL_FAN}" | awk NR==$i{'print $2'}` - GBL_FAN_GRP+=("`echo $data`") - done - - # load thermal config - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - index=$(( $i * ${STRUCT_TEMP_SIZE} + ${STRUCT_TEMP_NAME} )) - sensor_name=${GBL_TEMP_GRP[$index]} - GBL_TEMP_PROPERTY+=(`cat ${GBL_TEMP_CONF} | grep "^${sensor_name}" | tail`) - done - debug_temp_property - - # check if the config files is valid - valid_conf temp_list_1[@] temp_list_2[@] -} - -#/* -#* FEATURE: -#* temperature_collection -#* PURPOSE: -#* collect all temperature sensor readlings -#* PARAMETERS: -#* -#* RETURNS: -#* success, returns a series of reading @GBL_TEMP_READINGS[] -#*/ -function temperature_collection() { - local name cmd max_temp reading status pre_status - - GBL_TEMP_READINGS=() - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - # read temperature sensor value & record sensor status - name=`fetch_temp_struct $i ${STRUCT_TEMP_NAME}` - cmd=`fetch_temp_struct $i ${STRUCT_TEMP_CMD}` - max_temp=`fetch_temp_struct $i ${STRUCT_TEMP_MAX}` - reading=`eval ${cmd} 2>/dev/null` - if [ $? -eq 0 ]; then - GBL_TEMP_READINGS+=($reading) - status=$E_STATUS_GOOD - else - GBL_TEMP_READINGS+=($max_temp) - status=$E_STATUS_FAULT - fi - - # Compare previous status of temperature sensor, then update it. - pre_status=${GBL_TEMP_STATUSES[$i]} - if [ $pre_status -eq $E_STATUS_GOOD ] && [ $status -eq $E_STATUS_FAULT ]; then - # Good -> Fault - log_msg $MSG_WARN "[ZONE_${GBL_ZONE_ID}] Sensor $name: status=ERROR. reason=read sensor failed." - elif [ $pre_status -eq $E_STATUS_FAULT ] && [ $status -eq $E_STATUS_GOOD ]; then - # Fault -> Good - log_msg $MSG_WARN "[ZONE_${GBL_ZONE_ID}] Sensor $name: status=RECOVER. reason=reading is $reading deg C" - fi - GBL_TEMP_STATUSES[$i]=$status - done - debug_temp_readings -} - -#/* -#* FEATURE: -#* fan_level_selection -#* PURPOSE: -#* select proper fan level by temperature sensor reading -#* PARAMETERS: -#* reading_list (IN) sensor reading list -#* RETURNS: -#* success, returns a fan level value -#*/ -function fan_level_selection() { - local reading_list name reading temp_list highest_level pre_level next_level hysis_temp res res1 - - reading_list=("${!1}") - highest_level=0 - pre_level=${GBL_CUR_LEVEL} - next_level=0 - - # search fan table by each temperature sensor reading - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - name=`fetch_temp_struct $i $STRUCT_TEMP_NAME` - reading=${reading_list[$i]} - temp_list=(`fetch_temp_property ${name}`) - for j in ${!temp_list[@]} - do - res=`echo $reading \<= ${temp_list[$j]} | bc -l` - if [ $res -eq 1 ] || [ $j -eq $((${#temp_list[@]}-1)) ]; then - if [ $j -gt $highest_level ]; then - highest_level=$j - fi - break - fi - done - done - - if [ $highest_level -lt $pre_level ]; then - # Determine if require decreasing current fan level @assert_level - local pass_num - pass_num=0 - for ((i=0; i<${GBL_TEMP_NUM}; i++)) - do - name=`fetch_temp_struct $i $STRUCT_TEMP_NAME` - reading=${reading_list[$i]} - temp_list=(`fetch_temp_property ${name}`) - assert_level=$(( $pre_level-1 )) - hysis_temp=`echo ${temp_list[$assert_level]} - $GBL_HYSIS | bc` - res=`echo $reading \<= $hysis_temp | bc -l` - if [ $res -eq 1 ]; then - pass_num=$(( $pass_num+1 )) - else - break - fi - done - if [ $pass_num -eq ${GBL_TEMP_NUM} ]; then - # Decrease fan pwm: All sensor reading should less than its own hysteresis temperature - next_level=${highest_level} - else - # Keep current fan pwm - next_level=${pre_level} - fi - else - # Increase fan pwm - next_level=${highest_level} - fi - GBL_CUR_LEVEL=${next_level} -} - -#/* -#* FEATURE: -#* apply_fan_level -#* PURPOSE: -#* convert given fan level to PWM, then output to fans -#* PARAMETERS: -#* fan_list (IN) fan devices list -#* fan_level (IN) fan level -#* RETURNS: -#* success, returns a pwm value -#*/ -function apply_fan_level() { - local fan_level fan_list - - fan_list=("${!1}") - fan_level=$2 - - for fan in ${fan_list[@]} - do - echo ${GBL_FAN_LEVEL[$fan_level]} > $fan - done - debug_fan_speed -} - -#/* -#********************************************************************** -#* -#* MAIN -#* -#********************************************************************** -#*/ -Platform_init -arg_parse $@ -initialize -log_msg $MSG_INFO "Starting fan control service..." -while [ true ]; do - temperature_collection - fan_level_selection GBL_TEMP_READINGS[@] - apply_fan_level GBL_FAN_GRP[@] ${GBL_CUR_LEVEL} - sleep $GBL_INTERVAL -done - -exit 0 +#! /usr/bin/env python +# coding:utf-8 + +try: + import os + from fan_ctrl_pkg.fan_utility import FanUtility + from fan_ctrl_pkg import fan_ctrl_parser as arg + from fan_ctrl_pkg import __main__ +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + +if __name__ == '__main__': + zone_conf, temp_conf, log_file, debug_mode, simulate_mode = arg.fan_ctrl_parser(os.path.dirname(os.path.abspath(__file__))) + FanUtility.platform_init(os.path.dirname(os.path.abspath(__file__)), zone_conf, temp_conf, simulate_mode) + __main__.main(zone_conf, temp_conf, log_file, debug_mode, simulate_mode) diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/funcs.sh b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/funcs.sh deleted file mode 100755 index 3e417f699543..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/funcs.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/bash -#/* -#********************************************************************** -#* -#* @filename funcs.sh -#* -#* @purpose api functions script for fan-ctrl -#* -#* @create 2017/08/09 -#* -#* @author nixon.chu -#* -#* @history 2017/08/09: init version -#* -#********************************************************************** -#*/ - -DIR=$(dirname $0) - -function Platform_init() { - ${DIR}/init.sh -} diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/init.sh b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/init.sh deleted file mode 100755 index 06df071fa147..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/fan-ctrl/init.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash -DIR=$(dirname $0) - -# board type -BOARD_TYPE=`cat /sys/bus/i2c/devices/1-0032/brd_type` - -# fan tables -FORWARD_SENSOR_CONF=${DIR}/fan-zone_F2B.conf -FORWARD_PWM_CONF=${DIR}/fan-zone-thermal_F2B.conf -REVERSE_SENSOR_CONF=${DIR}/fan-zone_B2F.conf -REVERSE_PWM_CONF=${DIR}/fan-zone-thermal_B2F.conf - -# Nixon: Please refer to "BMS CPLD Design Spec." -# board type : BRD_TYPE[3:0] -# 0x0 (0000b): BMS_AC_PSU_NORMAL_FAN, 0x2 (0010b): BMS_DC_PSU_NORMAL_FAN -# 0x1 (0001b): BMS_AC_PSU_REVERSE_FAN, 0x3 (0011b): BMS_DC_PSU_REVERSE_FAN -case $BOARD_TYPE in - 0x0|0x2) - ln -sf $FORWARD_SENSOR_CONF ${DIR}/fan-zone.conf - ln -sf $FORWARD_PWM_CONF ${DIR}/fan-zone-thermal.conf - ;; - 0x1|0x3) - ln -sf $REVERSE_SENSOR_CONF ${DIR}/fan-zone.conf - ln -sf $REVERSE_PWM_CONF ${DIR}/fan-zone-thermal.conf - ;; -esac diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/funcs.sh b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/funcs.sh deleted file mode 100755 index 4b0c4c35471f..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/funcs.sh +++ /dev/null @@ -1,23 +0,0 @@ -#/bin/bash - -# process name/id -DAEMON_NAME=`basename $0` -DAEMON_PID="$$" - -DEF_SEVERITY="INFO" - -#/* -#* FEATURE: -#* log_msg -#* PURPOSE: -#* log message -#* PARAMETERS: -#* msg (IN) message -#* RETURNS: -#* -#*/ -function log_msg() { - local msg=$1 - - `logger -t $DAEMON_NAME -p $DEF_SEVERITY $msg` -} diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_service.sh b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_service.sh deleted file mode 100755 index 2bc9589738d0..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_service.sh +++ /dev/null @@ -1,99 +0,0 @@ -#/bin/bash - -DIR=$(dirname $0) - -# include files -source ${DIR}/funcs.sh - -ACPI_INSTALL_PRINT=0 -ACPID_INSTALL_PRINT=0 -BC_INSTALL_PRINT=0 -ACPID_SOCKET_PRINT=0 -ACPI_PRINT=0 - - -while [ 1 ] -do - if [ `dpkg -l |grep -c "acpi "` -eq "0" ]; then - dpkg -i /opt/debs/acpi_1.7-1_amd64.deb - if [ "$?" -ne "0" ]; then - if [ $ACPI_INSTALL_PRINT -eq 0 ]; then - ACPI_INSTALL_PRINT=1 - log_msg "Wait for acpi package install." - fi - sleep 1 - continue - else - log_msg "Install acpi package success." - fi - fi - break -done - -while [ 1 ] -do - if [ `dpkg -l |grep -c "acpid "` -eq "0" ]; then - dpkg -i /opt/debs/acpid_2.0.23-2_amd64.deb - if [ "$?" -ne "0" ]; then - if [ $ACPID_INSTALL_PRINT -eq 0 ]; then - ACPID_INSTALL_PRINT=1 - log_msg "Wait for acpid package install." - fi - sleep 1 - continue - else - log_msg "Install acpid package success." - fi - fi - break -done - -while [ 1 ] -do - if [ `dpkg -l |grep -c " bc "` -eq "0" ]; then - dpkg -i /opt/debs/bc_1.06.95-9_amd64.deb - if [ "$?" -ne "0" ]; then - if [ $BC_INSTALL_PRINT -eq 0 ]; then - BC_INSTALL_PRINT=1 - log_msg "Wait for bc package install." - fi - sleep 1 - continue - else - log_msg "Install bc package success." - fi - fi - break -done - -while [ 1 ] -do - if [ ! -e "/sys/firmware/acpi/interrupts/gpe01" ]; then - if [ $ACPI_PRINT -eq 0 ]; then - ACPI_PRINT=1 - log_msg "Wait for acpi daemon start." - fi - sleep 1 - continue - fi - log_msg "The acpi daemon start." - break -done - -while [ 1 ] -do - if [ ! -e "/var/run/acpid.socket" ]; then - if [ $ACPID_SOCKET_PRINT -eq 0 ]; then - ACPID_SOCKET_PRINT=1 - log_msg "Wait for acipd daemon start." - fi - sleep 1 - continue - fi - log_msg "The acpid daemon start." - break -done - -/etc/init.d/xcvr_servd start -/etc/init.d/sys_servd start -exit 0; diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_watchdog.sh b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_watchdog.sh deleted file mode 100755 index 2268e5e0d16e..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/script/start_watchdog.sh +++ /dev/null @@ -1,32 +0,0 @@ -#/bin/bash - -DIR=$(dirname $0) - -# include files -source ${DIR}/funcs.sh - -WATCHDOG_PRINT=0 - -while [ 1 ] -do - if [ `dpkg -l |grep -c "watchdog "` -eq "0" ]; then - dpkg -i /opt/debs/watchdog_5.14-3_amd64.deb - if [ "$?" -ne "0" ]; then - if [ $WATCHDOG_PRINT -eq 0 ]; then - WATCHDOG_PRINT=1 - log_msg "Wait for watchdog package install." - fi - sleep 1 - continue - else - log_msg "Install watchdog package success." - fi - fi - break -done - -ln -sf /opt/watchdog/watchdog.conf /etc/watchdog.conf - -/usr/sbin/watchdog -c /etc/watchdog.conf - -exit 0; diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/sys-serv/sys-servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/sys-serv/sys-servd deleted file mode 100755 index a1b4f177897c..000000000000 Binary files a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/sys-serv/sys-servd and /dev/null differ diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/watchdog/watchdog.conf b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/watchdog/watchdog.conf deleted file mode 100644 index 81f0b7b819bf..000000000000 --- a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/watchdog/watchdog.conf +++ /dev/null @@ -1,45 +0,0 @@ -#ping = 172.31.14.1 -#ping = 172.26.1.255 -#interface = eth0 -#file = /var/log/messages -#change = 1407 - -# Uncomment to enable test. Setting one of these values to '0' disables it. -# These values will hopefully never reboot your machine during normal use -# (if your machine is really hung, the loadavg will go much higher than 25) -#max-load-1 = 24 -#max-load-5 = 18 -#max-load-15 = 12 - -# Note that this is the number of pages! -# To get the real size, check how large the pagesize is on your machine. -#min-memory = 1 -#allocatable-memory = 1 - -#repair-binary = /usr/sbin/repair -#repair-timeout = -#test-binary = -#test-timeout = - -watchdog-device = /dev/watchdog - -# Defaults compiled into the binary -#temperature-device = -#max-temperature = 120 - -# Defaults compiled into the binary -#admin = root -#interval = 1 -#logtick = 1 -#log-dir = /var/log/watchdog - -# This greatly decreases the chance that watchdog won't be scheduled before -# your machine is really loaded -realtime = yes -priority = 99 - -# Check if rsyslogd is still running by enabling the following line -#pidfile = /var/run/rsyslogd.pid - -# timeout : 15 , 30 , 60 , 90 , 120 , 180 , 240 sec -watchdog-timeout = 120 diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/xcvr-serv/xcvr-servd b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/xcvr-serv/xcvr-servd deleted file mode 100755 index c882ff8e335a..000000000000 Binary files a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/opt/xcvr-serv/xcvr-servd and /dev/null differ diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/setup.py b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/setup.py new file mode 100755 index 000000000000..f5fbe22c1f6c --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/setup.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import os +import sys +from setuptools import setup +os.listdir + +setup( + name='ly1200_32x', + version='1.0', + description='Module to initialize Mitac LY1200-32X platforms', + + packages=['sys_serv_pkg', 'fan_ctrl_pkg'], + package_dir={'sys_serv_pkg': 'ly1200-32x/classes/sys_serv_pkg', + 'fan_ctrl_pkg': 'ly1200-32x/classes/fan_ctrl_pkg'} +) + diff --git a/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/systemd/sonic-platform-mitac-ly1200-32x.service b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/systemd/sonic-platform-mitac-ly1200-32x.service new file mode 100644 index 000000000000..b6e319277819 --- /dev/null +++ b/platform/broadcom/sonic-platform-modules-mitac/ly1200-32x/systemd/sonic-platform-mitac-ly1200-32x.service @@ -0,0 +1,13 @@ +[Unit] +Description=MiTAC ly1200-32x platform modules +After=local-fs.target +Before=pmon.service + +[Service] +Type=oneshot +ExecStart=/etc/init.d/sonic-platform-mitac-ly1200-32x start +ExecStop=/etc/init.d/sonic-platform-mitac-ly1200-32x stop +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target