diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/buffers.json.j2 b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/buffers.json.j2 new file mode 100644 index 000000000000..08e21e428b6c --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/buffers.json.j2 @@ -0,0 +1,70 @@ +{# Default values which will be used if no actual configura available #} +{% set default_cable = '40m' %} +{% set default_ports_num = 54 -%} + +{# Port configuration to cable length look-up table #} +{# Each record describes mapping of DUT (DUT port) role and neighbor role to cable length #} +{# Roles described in the minigraph #} +{% set ports2cable = { + 'torrouter_server' : '5m', + 'leafrouter_torrouter' : '40m', + 'spinerouter_leafrouter' : '300m' + } +%} + +{%- macro cable_length(port_name) -%} + {%- set cable_len = [] -%} + {%- for local_port in DEVICE_NEIGHBOR -%} + {%- if local_port == port_name -%} + {%- if DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] -%} + {%- set neighbor = DEVICE_NEIGHBOR_METADATA[DEVICE_NEIGHBOR[local_port].name] -%} + {%- set neighbor_role = neighbor.type -%} + {%- set roles1 = switch_role + '_' + neighbor_role %} + {%- set roles2 = neighbor_role + '_' + switch_role -%} + {%- set roles1 = roles1 | lower -%} + {%- set roles2 = roles2 | lower -%} + {%- if roles1 in ports2cable -%} + {%- if cable_len.append(ports2cable[roles1]) -%}{%- endif -%} + {%- elif roles2 in ports2cable -%} + {%- if cable_len.append(ports2cable[roles2]) -%}{%- endif -%} + {%- endif -%} + {%- endif -%} + {%- endif -%} + {%- endfor -%} + {%- if cable_len -%} + {{ cable_len.0 }} + {%- else -%} + {{ default_cable }} + {%- endif -%} +{% endmacro %} + +{%- if DEVICE_METADATA is defined %} +{%- set switch_role = DEVICE_METADATA['localhost']['type'] %} +{%- endif -%} + +{# Generate list of ports if not defined #} +{% if PORT is not defined %} + {% set PORT = [] %} + {% for port_idx in range(1,default_ports_num+1) %} + {% if PORT.append("Ethernet%d" % (port_idx)) %}{% endif %} + {% endfor %} +{% endif -%} + +{% set port_names_list = [] %} +{% for port in PORT %} + {%- if port_names_list.append(port) %}{% endif %} +{% endfor %} +{% set port_names = port_names_list | join(',') -%} + +{ + "CABLE_LENGTH": { + "AZURE": { + {% for port in PORT %} + {% set cable = cable_length(port) -%} + "{{ port }}": "{{ cable }}"{%- if not loop.last -%},{% endif %} + + {% endfor %} + } + } +} + diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/pg_profile_lookup.ini b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/pg_profile_lookup.ini new file mode 100644 index 000000000000..a65244e69b5b --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/pg_profile_lookup.ini @@ -0,0 +1,21 @@ +# PG lossless profiles. +# speed cable size xon xoff threshold + 1000 5m 34816 18432 16384 0 + 10000 5m 34816 18432 16384 0 + 25000 5m 34816 18432 16384 0 + 40000 5m 34816 18432 16384 0 + 50000 5m 34816 18432 16384 0 + 100000 5m 36864 18432 18432 0 + 1000 40m 36864 18432 18432 0 + 10000 40m 36864 18432 18432 0 + 25000 40m 39936 18432 21504 0 + 40000 40m 41984 18432 23552 0 + 50000 40m 41984 18432 23552 0 + 100000 40m 54272 18432 35840 0 + 1000 300m 49152 18432 30720 0 + 10000 300m 49152 18432 30720 0 + 25000 300m 71680 18432 53248 0 + 40000 300m 94208 18432 75776 0 + 50000 300m 94208 18432 75776 0 + 100000 300m 184320 18432 165888 0 + diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/port_config.ini b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/port_config.ini new file mode 100644 index 000000000000..78a1df9f051d --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/port_config.ini @@ -0,0 +1,55 @@ +# name lanes alias speed +Ethernet1 75 eth-0-1 1000 +Ethernet2 73 eth-0-2 1000 +Ethernet3 72 eth-0-3 1000 +Ethernet4 70 eth-0-4 1000 +Ethernet5 69 eth-0-5 1000 +Ethernet6 67 eth-0-6 1000 +Ethernet7 66 eth-0-7 1000 +Ethernet8 64 eth-0-8 1000 +Ethernet9 63 eth-0-9 1000 +Ethernet10 61 eth-0-10 1000 +Ethernet11 60 eth-0-11 1000 +Ethernet12 58 eth-0-12 1000 +Ethernet13 57 eth-0-13 10000 +Ethernet14 56 eth-0-14 10000 +Ethernet15 55 eth-0-15 10000 +Ethernet16 53 eth-0-16 10000 +Ethernet17 52 eth-0-17 10000 +Ethernet18 50 eth-0-18 10000 +Ethernet19 49 eth-0-19 10000 +Ethernet20 48 eth-0-20 10000 +Ethernet21 0 eth-0-21 10000 +Ethernet22 1 eth-0-22 10000 +Ethernet23 3 eth-0-23 10000 +Ethernet24 2 eth-0-24 10000 +Ethernet25 4 eth-0-25 10000 +Ethernet26 5 eth-0-26 10000 +Ethernet27 6 eth-0-27 10000 +Ethernet28 7 eth-0-28 10000 +Ethernet29 8 eth-0-29 10000 +Ethernet30 9 eth-0-30 10000 +Ethernet31 10 eth-0-31 10000 +Ethernet32 12 eth-0-32 10000 +Ethernet33 13 eth-0-33 10000 +Ethernet34 15 eth-0-34 10000 +Ethernet35 16 eth-0-35 10000 +Ethernet36 18 eth-0-36 10000 +Ethernet37 19 eth-0-37 10000 +Ethernet38 21 eth-0-38 10000 +Ethernet39 22 eth-0-39 10000 +Ethernet40 24 eth-0-40 10000 +Ethernet41 25 eth-0-41 10000 +Ethernet42 27 eth-0-42 10000 +Ethernet43 28 eth-0-43 10000 +Ethernet44 30 eth-0-44 10000 +Ethernet45 31 eth-0-45 10000 +Ethernet46 33 eth-0-46 10000 +Ethernet47 34 eth-0-47 10000 +Ethernet48 36 eth-0-48 10000 +Ethernet49 42,41,43,40 eth-0-49 40000 +Ethernet50 45,46,44,47 eth-0-50 40000 +Ethernet51 94,93,95,92 eth-0-51 100000 +Ethernet52 89,90,88,91 eth-0-52 100000 +Ethernet53 85,86,84,87 eth-0-53 100000 +Ethernet54 81,82,80,83 eth-0-54 100000 diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/qos.json.j2 b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/qos.json.j2 new file mode 100644 index 000000000000..3e548325ea30 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/qos.json.j2 @@ -0,0 +1 @@ +{%- include 'qos_config.j2' %} diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/sai.profile b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/sai.profile new file mode 100644 index 000000000000..6139a61cf0cd --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/E582-48x2q4z/sai.profile @@ -0,0 +1,2 @@ +SAI_INIT_CONFIG_FILE=/etc/centec/E582-48x2q4z-chip-profile.txt +SAI_HW_PORT_PROFILE_ID_CONFIG_FILE=/etc/centec/E582-48x2q4z-datapath-cfg.txt diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/default_sku b/device/centec/x86_64-centec_e582_48x2q4z-r0/default_sku new file mode 100644 index 000000000000..89c83dc3d0e3 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/default_sku @@ -0,0 +1 @@ +E582-48x2q4z t1 diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/fancontrol b/device/centec/x86_64-centec_e582_48x2q4z-r0/fancontrol new file mode 100644 index 000000000000..5bcd0383896b --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/fancontrol @@ -0,0 +1,10 @@ +# Configuration file generated by pwmconfig, changes will be lost +INTERVAL=10 +DEVPATH=hwmon1=devices/platform/coretemp.0 hwmon5=devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-15/15-002f +DEVNAME=hwmon1=coretemp hwmon5=adt7470 +FCTEMPS=hwmon5/pwm4=hwmon1/temp1_input hwmon5/pwm3=hwmon1/temp1_input hwmon5/pwm2=hwmon1/temp1_input hwmon5/pwm1=hwmon1/temp1_input +FCFANS=hwmon5/pwm4=hwmon5/fan4_input hwmon5/pwm3=hwmon5/fan3_input hwmon5/pwm2=hwmon5/fan2_input hwmon5/pwm1=hwmon5/fan1_input +MINTEMP=hwmon5/pwm4=20 hwmon5/pwm3=20 hwmon5/pwm2=20 hwmon5/pwm1=20 +MAXTEMP=hwmon5/pwm4=60 hwmon5/pwm3=60 hwmon5/pwm2=60 hwmon5/pwm1=60 +MINSTART=hwmon5/pwm4=150 hwmon5/pwm3=150 hwmon5/pwm2=150 hwmon5/pwm1=150 +MINSTOP=hwmon5/pwm4=0 hwmon5/pwm3=0 hwmon5/pwm2=0 hwmon5/pwm1=100 diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/installer.conf b/device/centec/x86_64-centec_e582_48x2q4z-r0/installer.conf new file mode 100644 index 000000000000..7d60bf73d366 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/installer.conf @@ -0,0 +1,2 @@ +CONSOLE_SPEED=115200 +ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="acpi_enforce_resources=no" diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py new file mode 100644 index 000000000000..3fd55c63d8b7 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/eeprom.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +############################################################################# +# Centec E582-48X6Q +# +# Platform and model specific eeprom subclass, inherits from the base class, +# and provides the followings: +# - the eeprom format definition +# - specific encoder/decoder if there is special need +############################################################################# + +try: + import exceptions + import binascii + import time + import optparse + import warnings + import os + import sys + import subprocess + from sonic_eeprom import eeprom_base + from sonic_eeprom import eeprom_tlvinfo +except ImportError, e: + raise ImportError (str(e) + "- required module not found") + + +class board(eeprom_tlvinfo.TlvInfoDecoder): + + def __init__(self, name, path, cpld_root, ro): + self.eeprom_path = "/sys/class/i2c-adapter/i2c-0/0-0057/eeprom" + super(board, self).__init__(self.eeprom_path, 0, '', True) diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py new file mode 100644 index 000000000000..4459096cb011 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/led_control.py @@ -0,0 +1,153 @@ +#!/usr/bin/env python +# +# led_control.py +# +# Platform-specific LED control functionality for SONiC +# + +try: + from sonic_led.led_control_base import LedControlBase + import swsssdk + import threading + import os + import logging + import struct + import time + import syslog + from socket import * + from select import * +except ImportError, e: + raise ImportError(str(e) + " - required module not found") + + +def DBG_PRINT(str): + syslog.openlog("centec-led") + syslog.syslog(syslog.LOG_INFO, str) + syslog.closelog() + +class LedControl(LedControlBase): + """Platform specific LED control class""" + SONIC_PORT_NAME_PREFIX = "Ethernet" + LED_MODE_UP = [11, 1] + LED_MODE_DOWN = [7, 2] + + def _initSystemLed(self): + try: + with open(self.f_led.format("system"), 'w') as led_file: + led_file.write("5") + DBG_PRINT("init system led to normal") + with open(self.f_led.format("idn"), 'w') as led_file: + led_file.write("1") + DBG_PRINT("init idn led to off") + except IOError as e: + DBG_PRINT(str(e)) + + def _initPanelLed(self): + with open(self.f_led.format("port1"), 'r') as led_file: + shouldInit = (int(led_file.read()) == 0) + + if shouldInit == True: + for (port, ctlid, defmode) in self.led_mapping[1:59]: + data = struct.pack('=HHHBBH', 0, 7, 4, ctlid, defmode, port) + self.udpClient.sendto(data, ('localhost', 8101)) + + data = struct.pack('=HHHBB30B', 0, 3, 32, 30, 0, *[x[0] for x in self.led_mapping[21:51]]) + self.udpClient.sendto(data, ('localhost', 8101)) + data = struct.pack('=HHHBB28B', 0, 3, 30, 28, 1, *[x[0] for x in (self.led_mapping[1:21]+self.led_mapping[51:59])]) + self.udpClient.sendto(data, ('localhost', 8101)) + + data = struct.pack('=HHHB', 0, 5, 1, 1) + self.udpClient.sendto(data, ('localhost', 8101)) + + for idx in range(1, 55): + (port, ctlid, defmode) = self.led_mapping[idx] + with open(self.f_led.format("port{}".format(idx)), 'w') as led_file: + led_file.write(str(defmode)) + DBG_PRINT("init port{} led to mode={}".format(idx, defmode)) + + for idx in range(1, 55): + (port, ctlid, defmode) = self.led_mapping[idx] + with open(self.f_led.format("port{}".format(idx)), 'r') as led_file: + defmode = int(led_file.read()) + data = struct.pack('=HHHBBH', 0, 7, 4, ctlid, defmode, port) + self.udpClient.sendto(data, ('localhost', 8101)) + DBG_PRINT("init port{} led to mode={}".format(idx, defmode)) + + def _initDefaultConfig(self): + DBG_PRINT("start init led") + while True: + try: + r_sel = [self.udpClient] + echo_req = struct.pack('=HHH', 0, 1, 0) + self.udpClient.sendto(echo_req, ('localhost', 8101)) + result = select(r_sel, [], [], 1) + if self.udpClient in result[0]: + echo_rsp, srv_addr = self.udpClient.recvfrom(1024) + if echo_rsp: + break + DBG_PRINT("connect to sdk rpc server timeout, try again.") + except IOError as e: + DBG_PRINT(str(e)) + + DBG_PRINT("connect to sdk rpc server success.") + + self._initSystemLed() + self._initPanelLed() + + DBG_PRINT("init led done") + + + # Helper method to map SONiC port name to index + def _port_name_to_index(self, port_name): + # Strip "Ethernet" off port name + if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): + return -1 + + port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) + return port_idx + + def _port_state_to_mode(self, port_idx, state): + if state == "up": + return self.LED_MODE_UP[0] if (port_idx < 49) else self.LED_MODE_UP[1] + else: + return self.LED_MODE_DOWN[0] if (port_idx < 49) else self.LED_MODE_DOWN[1] + + def _port_led_mode_update(self, port_idx, ledMode): + with open(self.f_led.format("port{}".format(port_idx)), 'w') as led_file: + led_file.write(str(ledMode)) + (port, ctlid) = (self.led_mapping[port_idx][0], self.led_mapping[port_idx][1]) + data = struct.pack('=HHHBBH', 0, 7, 4, ctlid, ledMode, port) + self.udpClient.sendto(data, ('localhost', 8101)) + + # Concrete implementation of port_link_state_change() method + def port_link_state_change(self, portname, state): + port_idx = self._port_name_to_index(portname) + ledMode = self._port_state_to_mode(port_idx, state) + with open(self.f_led.format("port{}".format(port_idx)), 'r') as led_file: + saveMode = int(led_file.read()) + + if ledMode == saveMode: + return + + self._port_led_mode_update(port_idx, ledMode) + DBG_PRINT("update {} led mode from {} to {}".format(portname, saveMode, ledMode)) + + # Constructor + def __init__(self): + # [macid, ctlid, defaultmode] + self.led_mapping = [(0, 0, 0)] # resv + self.led_mapping.extend([(27, 1, 7), (25, 1, 7), (24, 1, 7), (22, 1, 7), (21, 1, 7), (19, 1, 7), (18, 1, 7), (16, 1, 7)]) # panel port 1~8 + self.led_mapping.extend([(15, 1, 7), (13, 1, 7), (12, 1, 7), (10, 1, 7), (9, 1, 7), (8, 1, 7), (7, 1, 7), (5, 1, 7)]) # panel port 9~16 + self.led_mapping.extend([(4, 1, 7), (2, 1, 7), (1, 1, 7), (0, 1, 7), (0, 0, 7), (1, 0, 7), (3, 0, 7), (2, 0, 7)]) # panel port 17~24 + self.led_mapping.extend([(4, 0, 7), (5, 0, 7), (6, 0, 7), (7, 0, 7), (8, 0, 7), (9, 0, 7), (10, 0, 7), (12, 0, 7)]) # panel port 25~32 + self.led_mapping.extend([(13, 0, 7), (15, 0, 7), (16, 0, 7), (18, 0, 7), (19, 0, 7), (21, 0, 7), (22, 0, 7), (24, 0, 7)]) # panel port 33~40 + self.led_mapping.extend([(25, 0, 7), (27, 0, 7), (28, 0, 7), (30, 0, 7), (31, 0, 7), (33, 0, 7), (34, 0, 7), (48, 0, 7)]) # panel port 41~48 + self.led_mapping.extend([(36, 0, 2), (52, 0, 2), (52, 1, 2), (36, 1, 2), (48, 1, 2), (32, 1, 2)]) # panel port 49~54 + self.led_mapping.extend([(11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2), (11, 1, 2)]) + + self.f_led = "/sys/class/leds/{}/brightness" + + self.udpClient = socket(AF_INET, SOCK_DGRAM) + + self._initDefaultConfig() + diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py new file mode 100644 index 000000000000..6505318ed948 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/psuutil.py @@ -0,0 +1,74 @@ +#!/usr/bin/env python + +############################################################################# +# Centec +# +# 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_path = "/sys/class/psu/psu{}/" + self.psu_presence = "psu_presence" + self.psu_oper_status = "psu_status" + + 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 2 + + 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 = 0 + try: + with open(self.psu_path.format(index) + self.psu_oper_status, 'r') as power_status: + status = int(power_status.read()) + 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 = 0 + try: + with open(self.psu_path.format(index) + self.psu_presence, 'r') as presence_status: + status = int(presence_status.read()) + except IOError: + return False + + return status == 0 diff --git a/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py new file mode 100644 index 000000000000..4d4b3f3e5558 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x2q4z-r0/plugins/sfputil.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python + +# sfputil.py +# +# Platform-specific SFP transceiver interface for SONiC +# + +try: + import time + import os + import logging + import struct + import syslog + from socket import * + from select import * + from sonic_sfp.sfputilbase import SfpUtilBase +except ImportError as e: + raise ImportError("%s - required module not found" % str(e)) + + + +def DBG_PRINT(str): + print str + "\n" + + +class SfpUtil(SfpUtilBase): + """Platform-specific SfpUtil class""" + SONIC_PORT_NAME_PREFIX = "Ethernet" + PORT_START = 1 + PORT_END = 54 + PORTS_IN_BLOCK = 54 + + @property + def port_start(self): + return self.PORT_START + + @property + def port_end(self): + return self.PORT_END + + @property + def qsfp_ports(self): + return range(49, self.PORTS_IN_BLOCK + 1) + + @property + def port_to_eeprom_mapping(self): + return self.eeprom_mapping + + def is_logical_port(self, port_name): + return True + + def get_logical_to_physical(self, port_name): + if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): + return None + + port_idx = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) + + return [port_idx] + + def get_eeprom_data(self, port): + (ctlid, devid) = self.fiber_mapping[port] + offset = (128 if port in self.qsfp_ports else 0) + r_sel = [self.udpClient] + req = struct.pack('=HHHBBHIBBBBI', + 0, 9, 16, # lchip/msgtype/msglen + ctlid, # uint8 ctl_id + devid, # uint8 slave_dev_id + 0x50, # uint16 dev_addr + (1< self.port_end: + return False + try: + with open(self.f_sfp_present.format(port_num), 'r') as sfp_file: + return 1 == int(sfp_file.read()) + except IOError as e: + DBG_PRINT(str(e)) + + return False + + def get_low_power_mode(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False + + return False + + def set_low_power_mode(self, port_num, lpmode): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False + + return False + + def reset(self, port_num): + # Check for invalid port_num + if port_num < self.port_start or port_num > self.port_end: + return False + + return False + + def get_transceiver_change_event(self, timeout=0): + return False, {} diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/port_config.ini b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/port_config.ini index 95190282b25d..efb24937cec1 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/port_config.ini +++ b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/port_config.ini @@ -1,55 +1,55 @@ -# name lanes -Ethernet1 4 -Ethernet2 5 -Ethernet3 6 -Ethernet4 8 -Ethernet5 9 -Ethernet6 10 -Ethernet7 12 -Ethernet8 13 -Ethernet9 14 -Ethernet10 16 -Ethernet11 17 -Ethernet12 18 -Ethernet13 20 -Ethernet14 21 -Ethernet15 22 -Ethernet16 24 -Ethernet17 25 -Ethernet18 26 -Ethernet19 28 -Ethernet20 30 -Ethernet21 31 -Ethernet22 32 -Ethernet23 34 -Ethernet24 35 -Ethernet25 40 -Ethernet26 41 -Ethernet27 43 -Ethernet28 36 -Ethernet29 37 -Ethernet30 39 -Ethernet31 44 -Ethernet32 45 -Ethernet33 46 -Ethernet34 47 -Ethernet35 80 -Ethernet36 81 -Ethernet37 82 -Ethernet38 88 -Ethernet39 89 -Ethernet40 90 -Ethernet41 84 -Ethernet42 85 -Ethernet43 86 -Ethernet44 87 -Ethernet45 92 -Ethernet46 93 -Ethernet47 94 -Ethernet48 95 -Ethernet49 52,53,54,55 -Ethernet50 56,57,58,59 -Ethernet51 60,61,62,63 -Ethernet52 68,69,70,71 -Ethernet53 72,73,74,75 -Ethernet54 76,77,78,79 +# name lanes alias speed +Ethernet1 4 eth-0-1 1000 +Ethernet2 5 eth-0-2 1000 +Ethernet3 6 eth-0-3 1000 +Ethernet4 8 eth-0-4 1000 +Ethernet5 9 eth-0-5 1000 +Ethernet6 10 eth-0-6 1000 +Ethernet7 12 eth-0-7 1000 +Ethernet8 13 eth-0-8 1000 +Ethernet9 14 eth-0-9 1000 +Ethernet10 16 eth-0-10 1000 +Ethernet11 17 eth-0-11 1000 +Ethernet12 18 eth-0-12 1000 +Ethernet13 20 eth-0-13 10000 +Ethernet14 21 eth-0-14 10000 +Ethernet15 22 eth-0-15 10000 +Ethernet16 24 eth-0-16 10000 +Ethernet17 25 eth-0-17 10000 +Ethernet18 26 eth-0-18 10000 +Ethernet19 28 eth-0-19 10000 +Ethernet20 30 eth-0-20 10000 +Ethernet21 31 eth-0-21 10000 +Ethernet22 32 eth-0-22 10000 +Ethernet23 34 eth-0-23 10000 +Ethernet24 35 eth-0-24 10000 +Ethernet25 36 eth-0-25 10000 +Ethernet26 37 eth-0-26 10000 +Ethernet27 39 eth-0-27 10000 +Ethernet28 40 eth-0-28 10000 +Ethernet29 41 eth-0-29 10000 +Ethernet30 43 eth-0-30 10000 +Ethernet31 47 eth-0-31 10000 +Ethernet32 46 eth-0-32 10000 +Ethernet33 45 eth-0-33 10000 +Ethernet34 44 eth-0-34 10000 +Ethernet35 92 eth-0-35 10000 +Ethernet36 93 eth-0-36 10000 +Ethernet37 94 eth-0-37 10000 +Ethernet38 95 eth-0-38 10000 +Ethernet39 90 eth-0-39 10000 +Ethernet40 89 eth-0-40 10000 +Ethernet41 88 eth-0-41 10000 +Ethernet42 87 eth-0-42 10000 +Ethernet43 86 eth-0-43 10000 +Ethernet44 85 eth-0-44 10000 +Ethernet45 84 eth-0-45 10000 +Ethernet46 82 eth-0-46 10000 +Ethernet47 81 eth-0-47 10000 +Ethernet48 80 eth-0-48 10000 +Ethernet49 77,78,76,79 eth-0-49 40000 +Ethernet50 73,74,72,75 eth-0-50 40000 +Ethernet51 70,71,69,68 eth-0-51 40000 +Ethernet52 61,63,60,62 eth-0-52 40000 +Ethernet53 59,57,58,56 eth-0-53 40000 +Ethernet54 53,55,54,52 eth-0-54 40000 diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json deleted file mode 100644 index b9dc80abb07f..000000000000 --- a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json +++ /dev/null @@ -1,133 +0,0 @@ -{ - "DSCP_TO_TC_MAP": { - "AZURE": { - "0":"0", - "1":"0", - "2":"0", - "3":"0", - "4":"0", - "5":"0", - "6":"0", - "7":"0", - "8":"1", - "9":"1", - "10":"1", - "11":"1", - "12":"1", - "13":"1", - "14":"1", - "15":"1", - "16":"2", - "17":"2", - "18":"2", - "19":"2", - "20":"2", - "21":"2", - "22":"2", - "23":"2", - "24":"3", - "25":"3", - "26":"3", - "27":"3", - "28":"3", - "29":"3", - "30":"3", - "31":"3", - "32":"4", - "33":"4", - "34":"4", - "35":"4", - "36":"4", - "37":"4", - "38":"4", - "39":"4", - "40":"5", - "41":"5", - "42":"5", - "43":"5", - "44":"5", - "45":"5", - "46":"5", - "47":"5", - "48":"6", - "49":"6", - "50":"6", - "51":"6", - "52":"6", - "53":"6", - "54":"6", - "55":"6", - "56":"7", - "57":"7", - "58":"7", - "59":"7", - "60":"7", - "61":"7", - "62":"7", - "63":"7" - } - }, - "SCHEDULER": { - "scheduler.0": { - "type":"DWRR", - "weight": "25" - }, - "scheduler.1": { - "type":"DWRR", - "weight": "30" - }, - "scheduler.2": { - "type":"DWRR", - "weight": "20" - } - }, - "PORT_QOS_MAP": { - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54": { - "dscp_to_tc_map" : "[DSCP_TO_TC_MAP|AZURE]", - "pfc_enable": "3,4" - } - }, - "WRED_PROFILE": { - "AZURE_LOSSY": { - "wred_green_enable":"true", - "wred_yellow_enable":"true", - "red_max_threshold":"32760", - "red_min_threshold":"4095", - "yellow_max_threshold":"32760", - "yellow_min_threshold":"4095", - "green_max_threshold": "32760", - "green_min_threshold": "4095" - }, - "AZURE_LOSSLESS": { - "wred_green_enable":"true", - "wred_yellow_enable":"true", - "red_max_threshold":"32760", - "red_min_threshold":"4095", - "yellow_max_threshold":"32760", - "yellow_min_threshold":"4095", - "green_max_threshold": "32760", - "green_min_threshold": "4095" - } - }, - "QUEUE": { - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|0-2": { - "scheduler" : "[SCHEDULER|scheduler.1]" - }, - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|5-7": { - "scheduler" : "[SCHEDULER|scheduler.2]" - }, - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|0-2": { - "wred_profile" : "[WRED_PROFILE|AZURE_LOSSY]" - }, - - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|5-7": { - "wred_profile" : "[WRED_PROFILE|AZURE_LOSSY]" - }, - "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|3-4": { - "scheduler" : "[SCHEDULER|scheduler.0]", - "wred_profile" : "[WRED_PROFILE|AZURE_LOSSLESS]" - } - } -} - - diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json.j2 b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json.j2 new file mode 100644 index 000000000000..3e548325ea30 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/qos.json.j2 @@ -0,0 +1 @@ +{%- include 'qos_config.j2' %} diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/sai.profile b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/sai.profile index 9842dcf57fac..c03fcf630c5a 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/sai.profile +++ b/device/centec/x86_64-centec_e582_48x6q-r0/E582-48x6q/sai.profile @@ -1,3 +1,2 @@ -BOARD_CONFIG_FILE_PATH=/etc/centec/E582-48x6q.json SAI_INIT_CONFIG_FILE=/etc/centec/E582-48x6q-chip-profile.txt SAI_HW_PORT_PROFILE_ID_CONFIG_FILE=/etc/centec/E582-48x6q-datapath-cfg.txt diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/default_sku b/device/centec/x86_64-centec_e582_48x6q-r0/default_sku new file mode 100644 index 000000000000..e0f7b24535b6 --- /dev/null +++ b/device/centec/x86_64-centec_e582_48x6q-r0/default_sku @@ -0,0 +1 @@ +E582-48x6q t1 diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/fancontrol b/device/centec/x86_64-centec_e582_48x6q-r0/fancontrol index 886a4bc6c030..5bcd0383896b 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/fancontrol +++ b/device/centec/x86_64-centec_e582_48x6q-r0/fancontrol @@ -1,11 +1,10 @@ # Configuration file generated by pwmconfig, changes will be lost INTERVAL=10 -DEVPATH=hwmon0= hwmon5=devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-15/15-002f -DEVNAME=hwmon0=acpitz hwmon5=adt7470 -FCTEMPS=hwmon5/device/pwm4=hwmon0/temp1_input hwmon5/device/pwm3=hwmon0/temp1_input hwmon5/device/pwm2=hwmon0/temp1_input hwmon5/device/pwm1=hwmon0/temp1_input -FCFANS=hwmon5/device/pwm4=hwmon5/device/fan4_input hwmon5/device/pwm3=hwmon5/device/fan3_input hwmon5/device/pwm2=hwmon5/device/fan2_input hwmon5/device/pwm1=hwmon5/device/fan1_input -MINTEMP=hwmon5/device/pwm4=20 hwmon5/device/pwm3=20 hwmon5/device/pwm2=20 hwmon5/device/pwm1=20 -MAXTEMP=hwmon5/device/pwm4=60 hwmon5/device/pwm3=60 hwmon5/device/pwm2=60 hwmon5/device/pwm1=60 -MINSTART=hwmon5/device/pwm4=150 hwmon5/device/pwm3=12 hwmon5/device/pwm2=12 hwmon5/device/pwm1=150 -MINSTOP=hwmon5/device/pwm4=0 hwmon5/device/pwm3=12 hwmon5/device/pwm2=12 hwmon5/device/pwm1=0 -MAXPWM= hwmon5/device/pwm4=150 +DEVPATH=hwmon1=devices/platform/coretemp.0 hwmon5=devices/pci0000:00/0000:00:1f.3/i2c-0/i2c-15/15-002f +DEVNAME=hwmon1=coretemp hwmon5=adt7470 +FCTEMPS=hwmon5/pwm4=hwmon1/temp1_input hwmon5/pwm3=hwmon1/temp1_input hwmon5/pwm2=hwmon1/temp1_input hwmon5/pwm1=hwmon1/temp1_input +FCFANS=hwmon5/pwm4=hwmon5/fan4_input hwmon5/pwm3=hwmon5/fan3_input hwmon5/pwm2=hwmon5/fan2_input hwmon5/pwm1=hwmon5/fan1_input +MINTEMP=hwmon5/pwm4=20 hwmon5/pwm3=20 hwmon5/pwm2=20 hwmon5/pwm1=20 +MAXTEMP=hwmon5/pwm4=60 hwmon5/pwm3=60 hwmon5/pwm2=60 hwmon5/pwm1=60 +MINSTART=hwmon5/pwm4=150 hwmon5/pwm3=150 hwmon5/pwm2=150 hwmon5/pwm1=150 +MINSTOP=hwmon5/pwm4=0 hwmon5/pwm3=0 hwmon5/pwm2=0 hwmon5/pwm1=100 diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py index 5f8ba030c1f0..6505318ed948 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/psuutil.py @@ -1,7 +1,7 @@ #!/usr/bin/env python ############################################################################# -# Mellanox +# Centec # # Module contains an implementation of SONiC PSU Base API and # provides the PSUs status which are available in the platform diff --git a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py index 2695957bd5e1..8d1281492d6c 100644 --- a/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py +++ b/device/centec/x86_64-centec_e582_48x6q-r0/plugins/sfputil.py @@ -158,11 +158,5 @@ def reset(self, port_num): return False - 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 - + def get_transceiver_change_event(self, timeout=0): + return False, {} diff --git a/device/centec/x86_64-ew_es6220_x48q2h4-r0/minigraph.xml b/device/centec/x86_64-ew_es6220_x48q2h4-r0/minigraph.xml deleted file mode 100644 index cb0e9d4e2b0a..000000000000 --- a/device/centec/x86_64-ew_es6220_x48q2h4-r0/minigraph.xml +++ /dev/null @@ -1,1049 +0,0 @@ - - - - - - ARISTA01T0 - 10.0.0.33 - sonic - 10.0.0.32 - 1 - 180 - 60 - - - sonic - 10.0.0.0 - ARISTA01T2 - 10.0.0.1 - 1 - 180 - 60 - - - ARISTA02T0 - 10.0.0.35 - sonic - 10.0.0.34 - 1 - 180 - 60 - - - sonic - 10.0.0.2 - ARISTA02T2 - 10.0.0.3 - 1 - 180 - 60 - - - ARISTA03T0 - 10.0.0.37 - sonic - 10.0.0.36 - 1 - 180 - 60 - - - sonic - 10.0.0.4 - ARISTA03T2 - 10.0.0.5 - 1 - 180 - 60 - - - ARISTA04T0 - 10.0.0.39 - sonic - 10.0.0.38 - 1 - 180 - 60 - - - sonic - 10.0.0.6 - ARISTA04T2 - 10.0.0.7 - 1 - 180 - 60 - - - ARISTA05T0 - 10.0.0.41 - sonic - 10.0.0.40 - 1 - 180 - 60 - - - sonic - 10.0.0.8 - ARISTA05T2 - 10.0.0.9 - 1 - 180 - 60 - - - ARISTA06T0 - 10.0.0.43 - sonic - 10.0.0.42 - 1 - 180 - 60 - - - sonic - 10.0.0.10 - ARISTA06T2 - 10.0.0.11 - 1 - 180 - 60 - - - ARISTA07T0 - 10.0.0.45 - sonic - 10.0.0.44 - 1 - 180 - 60 - - - sonic - 10.0.0.12 - ARISTA07T2 - 10.0.0.13 - 1 - 180 - 60 - - - ARISTA08T0 - 10.0.0.47 - sonic - 10.0.0.46 - 1 - 180 - 60 - - - sonic - 10.0.0.14 - ARISTA08T2 - 10.0.0.15 - 1 - 180 - 60 - - - ARISTA09T0 - 10.0.0.49 - sonic - 10.0.0.48 - 1 - 180 - 60 - - - sonic - 10.0.0.16 - ARISTA09T2 - 10.0.0.17 - 1 - 180 - 60 - - - ARISTA10T0 - 10.0.0.51 - sonic - 10.0.0.50 - 1 - 180 - 60 - - - sonic - 10.0.0.18 - ARISTA10T2 - 10.0.0.19 - 1 - 180 - 60 - - - ARISTA11T0 - 10.0.0.53 - sonic - 10.0.0.52 - 1 - 180 - 60 - - - sonic - 10.0.0.20 - ARISTA11T2 - 10.0.0.21 - 1 - 180 - 60 - - - ARISTA12T0 - 10.0.0.55 - sonic - 10.0.0.54 - 1 - 180 - 60 - - - sonic - 10.0.0.22 - ARISTA12T2 - 10.0.0.23 - 1 - 180 - 60 - - - ARISTA13T0 - 10.0.0.57 - sonic - 10.0.0.56 - 1 - 180 - 60 - - - sonic - 10.0.0.24 - ARISTA13T2 - 10.0.0.25 - 1 - 180 - 60 - - - ARISTA14T0 - 10.0.0.59 - sonic - 10.0.0.58 - 1 - 180 - 60 - - - sonic - 10.0.0.26 - ARISTA14T2 - 10.0.0.27 - 1 - 180 - 60 - - - ARISTA15T0 - 10.0.0.61 - sonic - 10.0.0.60 - 1 - 180 - 60 - - - sonic - 10.0.0.28 - ARISTA15T2 - 10.0.0.29 - 1 - 180 - 60 - - - ARISTA16T0 - 10.0.0.63 - sonic - 10.0.0.62 - 1 - 180 - 60 - - - sonic - 10.0.0.30 - ARISTA16T2 - 10.0.0.31 - 1 - 180 - 60 - - - - - 65100 - sonic - - -
10.0.0.33
- - -
- -
10.0.0.1
- - -
- -
10.0.0.35
- - -
- -
10.0.0.3
- - -
- -
10.0.0.37
- - -
- -
10.0.0.5
- - -
- -
10.0.0.39
- - -
- -
10.0.0.7
- - -
- -
10.0.0.41
- - -
- -
10.0.0.9
- - -
- -
10.0.0.43
- - -
- -
10.0.0.11
- - -
- -
10.0.0.45
- - -
- -
10.0.0.13
- - -
- -
10.0.0.47
- - -
- -
10.0.0.15
- - -
- -
10.0.0.49
- - -
- -
10.0.0.17
- - -
- -
10.0.0.51
- - -
- -
10.0.0.19
- - -
- -
10.0.0.53
- - -
- -
10.0.0.21
- - -
- -
10.0.0.55
- - -
- -
10.0.0.23
- - -
- -
10.0.0.57
- - -
- -
10.0.0.25
- - -
- -
10.0.0.59
- - -
- -
10.0.0.27
- - -
- -
10.0.0.61
- - -
- -
10.0.0.29
- - -
- -
10.0.0.63
- - -
- -
10.0.0.31
- - -
-
- -
- - 64001 - ARISTA01T0 - - - - 65200 - ARISTA01T2 - - - - 64002 - ARISTA02T0 - - - - 65200 - ARISTA02T2 - - - - 64003 - ARISTA03T0 - - - - 65200 - ARISTA03T2 - - - - 64004 - ARISTA04T0 - - - - 65200 - ARISTA04T2 - - - - 64005 - ARISTA05T0 - - - - 65200 - ARISTA05T2 - - - - 64006 - ARISTA06T0 - - - - 65200 - ARISTA06T2 - - - - 64007 - ARISTA07T0 - - - - 65200 - ARISTA07T2 - - - - 64008 - ARISTA08T0 - - - - 65200 - ARISTA08T2 - - - - 64009 - ARISTA09T0 - - - - 65200 - ARISTA09T2 - - - - 64010 - ARISTA10T0 - - - - 65200 - ARISTA10T2 - - - - 64011 - ARISTA11T0 - - - - 65200 - ARISTA11T2 - - - - 64012 - ARISTA12T0 - - - - 65200 - ARISTA12T2 - - - - 64013 - ARISTA13T0 - - - - 65200 - ARISTA13T2 - - - - 64014 - ARISTA14T0 - - - - 65200 - ARISTA14T2 - - - - 64015 - ARISTA15T0 - - - - 65200 - ARISTA15T2 - - - - 64016 - ARISTA16T0 - - - - 65200 - ARISTA16T2 - - -
-
- - - - - - HostIP - Loopback0 - - 10.1.0.32/32 - - 10.1.0.32/32 - - - - - - - - sonic - - - - - - Ethernet0 - 10.0.0.0/31 - - - - Ethernet4 - 10.0.0.2/31 - - - - Ethernet8 - 10.0.0.4/31 - - - - Ethernet12 - 10.0.0.6/31 - - - - Ethernet16 - 10.0.0.8/31 - - - - Ethernet20 - 10.0.0.10/31 - - - - Ethernet24 - 10.0.0.12/31 - - - - Ethernet28 - 10.0.0.14/31 - - - - Ethernet32 - 10.0.0.16/31 - - - - Ethernet36 - 10.0.0.18/31 - - - - Ethernet40 - 10.0.0.20/31 - - - - Ethernet44 - 10.0.0.22/31 - - - - Ethernet48 - 10.0.0.24/31 - - - - Ethernet52 - 10.0.0.26/31 - - - - Ethernet56 - 10.0.0.28/31 - - - - Ethernet60 - 10.0.0.30/31 - - - - Ethernet64 - 10.0.0.32/31 - - - - Ethernet68 - 10.0.0.34/31 - - - - Ethernet72 - 10.0.0.36/31 - - - - Ethernet76 - 10.0.0.38/31 - - - - Ethernet80 - 10.0.0.40/31 - - - - Ethernet84 - 10.0.0.42/31 - - - - Ethernet88 - 10.0.0.44/31 - - - - Ethernet92 - 10.0.0.46/31 - - - - Ethernet96 - 10.0.0.48/31 - - - - Ethernet100 - 10.0.0.50/31 - - - - Ethernet104 - 10.0.0.52/31 - - - - Ethernet108 - 10.0.0.54/31 - - - - Ethernet112 - 10.0.0.56/31 - - - - Ethernet116 - 10.0.0.58/31 - - - - Ethernet120 - 10.0.0.60/31 - - - - Ethernet124 - 10.0.0.62/31 - - - - - - - - - - - - DeviceInterfaceLink - sonic - Ethernet0 - ARISTA01T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet4 - ARISTA02T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet8 - ARISTA03T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet12 - ARISTA04T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet16 - ARISTA05T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet20 - ARISTA06T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet24 - ARISTA07T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet28 - ARISTA08T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet32 - ARISTA09T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet36 - ARISTA10T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet40 - ARISTA11T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet44 - ARISTA12T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet48 - ARISTA13T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet52 - ARISTA14T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet56 - ARISTA15T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet60 - ARISTA16T2 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet64 - ARISTA01T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet68 - ARISTA02T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet72 - ARISTA03T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet76 - ARISTA04T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet80 - ARISTA05T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet84 - ARISTA06T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet88 - ARISTA07T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet92 - ARISTA08T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet96 - ARISTA09T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet100 - ARISTA10T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet104 - ARISTA11T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet108 - ARISTA12T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet112 - ARISTA13T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet116 - ARISTA14T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet120 - ARISTA15T0 - Ethernet1 - - - DeviceInterfaceLink - sonic - Ethernet124 - ARISTA16T0 - Ethernet1 - - - - - sonic - ES6428A-X48Q2H4 - - - - sonic - ES6428A-X48Q2H4 -
diff --git a/platform/centec/libsaithrift-dev.mk b/platform/centec/libsaithrift-dev.mk index fc1fe398080e..b0e13fa02828 100644 --- a/platform/centec/libsaithrift-dev.mk +++ b/platform/centec/libsaithrift-dev.mk @@ -1,6 +1,6 @@ # libsaithrift-dev package -LIBSAITHRIFT_DEV_CENTEC = libsaithrift-dev_1.2.1_amd64.deb +LIBSAITHRIFT_DEV_CENTEC = libsaithrift-dev_1.3.5_amd64.deb $(LIBSAITHRIFT_DEV_CENTEC)_SRC_PATH = $(SRC_PATH)/sonic-sairedis/SAI $(LIBSAITHRIFT_DEV_CENTEC)_DEPENDS += $(LIBTHRIFT) $(LIBTHRIFT_DEV) $(THRIFT_COMPILER) $(CENTEC_SAI) $(LIBSAITHRIFT_DEV_CENTEC)_RDEPENDS += $(LIBTHRIFT) $(CENTEC_SAI) diff --git a/platform/centec/one-image.mk b/platform/centec/one-image.mk index 42e78ab4df34..ec8448433aaa 100644 --- a/platform/centec/one-image.mk +++ b/platform/centec/one-image.mk @@ -3,6 +3,7 @@ SONIC_ONE_IMAGE = sonic-centec.bin $(SONIC_ONE_IMAGE)_MACHINE = centec $(SONIC_ONE_IMAGE)_IMAGE_TYPE = onie -$(SONIC_ONE_IMAGE)_INSTALLS += $(CENTEC_E582_48X6Q_PLATFORM_MODULE) +$(SONIC_ONE_IMAGE)_LAZY_INSTALLS += $(CENTEC_E582_48X6Q_PLATFORM_MODULE) \ + $(CENTEC_E582_48X2Q4Z_PLATFORM_MODULE) $(SONIC_ONE_IMAGE)_DOCKERS += $(SONIC_INSTALL_DOCKER_IMAGES) SONIC_INSTALLERS += $(SONIC_ONE_IMAGE) diff --git a/platform/centec/platform-modules-centec-e582.mk b/platform/centec/platform-modules-centec-e582.mk index e86c428a7403..e22653075ecb 100644 --- a/platform/centec/platform-modules-centec-e582.mk +++ b/platform/centec/platform-modules-centec-e582.mk @@ -12,6 +12,7 @@ CENTEC_E582_48X6Q_PLATFORM_MODULE = platform-modules-e582-48x6q_$(CENTEC_E582_48 $(CENTEC_E582_48X6Q_PLATFORM_MODULE)_SRC_PATH = $(PLATFORM_PATH)/sonic-platform-modules-e582 $(CENTEC_E582_48X6Q_PLATFORM_MODULE)_DEPENDS += $(LINUX_HEADERS) $(LINUX_HEADERS_COMMON) $(CENTEC_E582_48X6Q_PLATFORM_MODULE)_PLATFORM = x86_64-centec_e582_48x6q-r0 +SONIC_STRETCH_DEBS += $(CENTEC_E582_48X6Q_PLATFORM_MODULE) SONIC_DPKG_DEBS += $(CENTEC_E582_48X6Q_PLATFORM_MODULE) CENTEC_E582_48X2Q4Z_PLATFORM_MODULE = platform-modules-e582-48x2q4z_$(CENTEC_E582_48X2Q4Z_PLATFORM_MODULE_VERSION)_amd64.deb diff --git a/platform/centec/python-saithrift.mk b/platform/centec/python-saithrift.mk index 30bd8715397b..b62beff89237 100644 --- a/platform/centec/python-saithrift.mk +++ b/platform/centec/python-saithrift.mk @@ -1,6 +1,6 @@ # python-saithrift package -PYTHON_SAITHRIFT_CENTEC = python-saithrift_1.2.1_amd64.deb +PYTHON_SAITHRIFT_CENTEC = python-saithrift_1.3.5_amd64.deb $(PYTHON_SAITHRIFT_CENTEC)_SRC_PATH = $(SRC_PATH)/sonic-sairedis/SAI $(PYTHON_SAITHRIFT_CENTEC)_DEPENDS += $(CENTEC_SAI) $(THRIFT_COMPILER) $(PYTHON_THRIFT) $(LIBTHRIFT_DEV) SONIC_DPKG_DEBS += $(PYTHON_SAITHRIFT_CENTEC) diff --git a/platform/centec/sdk.mk b/platform/centec/sdk.mk index ba2d1adbe6a8..c529762dafc8 100644 --- a/platform/centec/sdk.mk +++ b/platform/centec/sdk.mk @@ -1,5 +1,5 @@ # Centec SAI -CENTEC_SAI = libsai_1.2.4_amd64.deb -$(CENTEC_SAI)_URL = https://github.com/CentecNetworks/goldengate-sai/raw/master/lib/SONiC_1.2.4/libsai_1.2.4-1.0_amd64.deb +CENTEC_SAI = libsai_1.3.3_amd64.deb +$(CENTEC_SAI)_URL = https://github.com/CentecNetworks/goldengate-sai/raw/master/lib/SONiC_1.3.3/libsai_1.3.3-1.0_amd64.deb SONIC_ONLINE_DEBS += $(CENTEC_SAI) diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/48x2q4z-modules.conf b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/48x2q4z-modules.conf index 5becd702a716..7a7881c8c0d3 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/48x2q4z-modules.conf +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/48x2q4z-modules.conf @@ -12,6 +12,3 @@ i2c-mux-pca954x lm77 adt7470 tun -centec_e582_48x6q_platform -dal -centec_at24c64 diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db.json b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db.json new file mode 100644 index 000000000000..3a5c8ba914b5 --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db.json @@ -0,0 +1,302 @@ +{ + "DEVICE_METADATA": { + "localhost": { + "bgp_asn": 65100, + "deployment_id": null, + "hostname": "switch1", + "type": "LeafRouter", + "hwsku": "E582-48x6q" + + } + }, + "BGP_PEER_RANGE": {}, + "VLAN": {}, + "PORT": { + "Ethernet1": { + "alias": "eth-0-1", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet2": { + "alias": "eth-0-2", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet3": { + "alias": "eth-0-3", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet4": { + "alias": "eth-0-4", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet5": { + "alias": "eth-0-5", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet6": { + "alias": "eth-0-6", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet7": { + "alias": "eth-0-7", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet8": { + "alias": "eth-0-8", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet9": { + "alias": "eth-0-9", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet10": { + "alias": "eth-0-10", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet11": { + "alias": "eth-0-11", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet12": { + "alias": "eth-0-12", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet13": { + "alias": "eth-0-13", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet14": { + "alias": "eth-0-14", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet15": { + "alias": "eth-0-15", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet16": { + "alias": "eth-0-16", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet17": { + "alias": "eth-0-17", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet18": { + "alias": "eth-0-18", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet19": { + "alias": "eth-0-19", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet20": { + "alias": "eth-0-20", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet21": { + "alias": "eth-0-21", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet22": { + "alias": "eth-0-22", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet23": { + "alias": "eth-0-23", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet24": { + "alias": "eth-0-24", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet25": { + "alias": "eth-0-25", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet26": { + "alias": "eth-0-26", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet27": { + "alias": "eth-0-27", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet28": { + "alias": "eth-0-28", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet29": { + "alias": "eth-0-29", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet30": { + "alias": "eth-0-30", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet31": { + "alias": "eth-0-31", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet32": { + "alias": "eth-0-32", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet33": { + "alias": "eth-0-33", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet34": { + "alias": "eth-0-34", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet35": { + "alias": "eth-0-35", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet36": { + "alias": "eth-0-36", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet37": { + "alias": "eth-0-37", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet38": { + "alias": "eth-0-38", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet39": { + "alias": "eth-0-39", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet40": { + "alias": "eth-0-40", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet41": { + "alias": "eth-0-41", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet42": { + "alias": "eth-0-42", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet43": { + "alias": "eth-0-43", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet44": { + "alias": "eth-0-44", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet45": { + "alias": "eth-0-45", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet46": { + "alias": "eth-0-46", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet47": { + "alias": "eth-0-47", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet48": { + "alias": "eth-0-48", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet49": { + "alias": "eth-0-49", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet50": { + "alias": "eth-0-50", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet51": { + "alias": "eth-0-51", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet52": { + "alias": "eth-0-52", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet53": { + "alias": "eth-0-53", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet54": { + "alias": "eth-0-54", + "speed": "100000", + "mtu": "9100" + } + }, + "SYSLOG_SERVER": {}, + "VLAN_INTERFACE": {}, + "PORTCHANNEL_INTERFACE": {}, + "PORTCHANNEL": {}, + "MGMT_INTERFACE": {}, + "DHCP_SERVER": {}, + "LOOPBACK_INTERFACE": { + "Loopback0|127.0.0.1/8": {} + }, + "ACL_TABLE": {}, + "INTERFACE": { + "Ethernet1|192.168.1.1/24": {}, + "Ethernet2|192.168.2.1/24": {}, + "Ethernet3|192.168.3.1/24": {}, + "Ethernet4|192.168.4.1/24": {} + } +} diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db_l2l3.json b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db_l2l3.json new file mode 100644 index 000000000000..dd40332f9049 --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/cfg/config_db_l2l3.json @@ -0,0 +1,610 @@ +{ + "QUEUE": { + "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|0-2": { + "wred_profile": "[WRED_PROFILE|AZURE_LOSSY]" + }, + "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|3-4": { + "wred_profile": "[WRED_PROFILE|AZURE_LOSSLESS]", + "scheduler": "[SCHEDULER|scheduler.0]" + }, + "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54|5-7": { + "wred_profile": "[WRED_PROFILE|AZURE_LOSSY]" + } + }, + "WRED_PROFILE": { + "AZURE_LOSSLESS": { + "red_max_threshold": "32760", + "yellow_max_threshold": "32760", + "green_min_threshold": "4095", + "red_min_threshold": "4095", + "yellow_min_threshold": "4095", + "green_max_threshold": "32760", + "wred_yellow_enable": "true", + "wred_green_enable": "true" + }, + "AZURE_LOSSY": { + "red_max_threshold": "32760", + "yellow_max_threshold": "32760", + "green_min_threshold": "4095", + "red_min_threshold": "4095", + "yellow_min_threshold": "4095", + "green_max_threshold": "32760", + "wred_yellow_enable": "true", + "wred_green_enable": "true" + } + }, + "DSCP_TO_TC_MAP": { + "AZURE": { + "56": "7", + "54": "6", + "28": "3", + "48": "6", + "29": "3", + "60": "7", + "61": "7", + "62": "7", + "63": "7", + "49": "6", + "34": "4", + "24": "3", + "25": "3", + "26": "3", + "27": "3", + "20": "2", + "21": "2", + "22": "2", + "23": "2", + "46": "5", + "47": "5", + "44": "5", + "45": "5", + "42": "5", + "43": "5", + "40": "5", + "41": "5", + "1": "0", + "0": "0", + "3": "0", + "2": "0", + "5": "0", + "4": "0", + "7": "0", + "6": "0", + "9": "1", + "8": "1", + "35": "4", + "13": "1", + "12": "1", + "15": "1", + "58": "7", + "11": "1", + "10": "1", + "39": "4", + "38": "4", + "59": "7", + "14": "1", + "17": "2", + "16": "2", + "19": "2", + "18": "2", + "31": "3", + "30": "3", + "51": "6", + "36": "4", + "53": "6", + "52": "6", + "33": "4", + "55": "6", + "37": "4", + "32": "4", + "57": "7", + "50": "6" + } + }, + "DEVICE_METADATA": { + "localhost": { + "hwsku": "E582-48x6q", + "hostname": "switch1", + "bgp_asn": "None", + "deployment_id": "None", + "type": "LeafRouter" + } + }, + "PORT": { + "Ethernet1": { + "alias": "eth-0-1", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet2": { + "alias": "eth-0-2", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet3": { + "alias": "eth-0-3", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet4": { + "alias": "eth-0-4", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet5": { + "alias": "eth-0-5", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet6": { + "alias": "eth-0-6", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet7": { + "alias": "eth-0-7", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet8": { + "alias": "eth-0-8", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet9": { + "alias": "eth-0-9", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet10": { + "alias": "eth-0-10", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet11": { + "alias": "eth-0-11", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet12": { + "alias": "eth-0-12", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet13": { + "alias": "eth-0-13", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet14": { + "alias": "eth-0-14", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet15": { + "alias": "eth-0-15", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet16": { + "alias": "eth-0-16", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet17": { + "alias": "eth-0-17", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet18": { + "alias": "eth-0-18", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet19": { + "alias": "eth-0-19", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet20": { + "alias": "eth-0-20", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet21": { + "alias": "eth-0-21", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet22": { + "alias": "eth-0-22", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet23": { + "alias": "eth-0-23", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet24": { + "alias": "eth-0-24", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet25": { + "alias": "eth-0-25", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet26": { + "alias": "eth-0-26", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet27": { + "alias": "eth-0-27", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet28": { + "alias": "eth-0-28", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet29": { + "alias": "eth-0-29", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet30": { + "alias": "eth-0-30", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet31": { + "alias": "eth-0-31", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet32": { + "alias": "eth-0-32", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet33": { + "alias": "eth-0-33", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet34": { + "alias": "eth-0-34", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet35": { + "alias": "eth-0-35", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet36": { + "alias": "eth-0-36", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet37": { + "alias": "eth-0-37", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet38": { + "alias": "eth-0-38", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet39": { + "alias": "eth-0-39", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet40": { + "alias": "eth-0-40", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet41": { + "alias": "eth-0-41", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet42": { + "alias": "eth-0-42", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet43": { + "alias": "eth-0-43", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet44": { + "alias": "eth-0-44", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet45": { + "alias": "eth-0-45", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet46": { + "alias": "eth-0-46", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet47": { + "alias": "eth-0-47", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet48": { + "alias": "eth-0-48", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet49": { + "alias": "eth-0-49", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet50": { + "alias": "eth-0-50", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet51": { + "alias": "eth-0-51", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet52": { + "alias": "eth-0-52", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet53": { + "alias": "eth-0-53", + "speed": "100000", + "mtu": "9100" + }, + "Ethernet54": { + "alias": "eth-0-54", + "speed": "100000", + "mtu": "9100" + } + }, + "PORT_QOS_MAP": { + "Ethernet1,Ethernet2,Ethernet3,Ethernet4,Ethernet5,Ethernet6,Ethernet7,Ethernet8,Ethernet9,Ethernet10,Ethernet11,Ethernet12,Ethernet13,Ethernet14,Ethernet15,Ethernet16,Ethernet17,Ethernet18,Ethernet19,Ethernet20,Ethernet21,Ethernet22,Ethernet23,Ethernet24,Ethernet25,Ethernet26,Ethernet27,Ethernet28,Ethernet29,Ethernet30,Ethernet31,Ethernet32,Ethernet33,Ethernet34,Ethernet35,Ethernet36,Ethernet37,Ethernet38,Ethernet39,Ethernet40,Ethernet41,Ethernet42,Ethernet43,Ethernet44,Ethernet45,Ethernet46,Ethernet47,Ethernet48,Ethernet49,Ethernet50,Ethernet51,Ethernet52,Ethernet53,Ethernet54": { + "pfc_enable": "3,4", + "dscp_to_tc_map": "[DSCP_TO_TC_MAP|AZURE]" + } + }, + "SCHEDULER": { + "scheduler.0": { + "type": "DWRR", + "weight": "25" + }, + "scheduler.1": { + "type": "DWRR", + "weight": "30" + }, + "scheduler.2": { + "type": "DWRR", + "weight": "20" + } + }, + "VLAN": { + "Vlan500": { + "dhcp_servers": [ + "192.168.5.1", + "192.168.5.2", + "192.168.5.3", + "192.168.5.4" + ], + "members": [ + "Ethernet5", + "Ethernet6", + "Ethernet7", + "Ethernet8" + ], + "vlanid": "500" + }, + "Vlan600": { + "dhcp_servers": [ + "192.168.6.1", + "192.168.6.2", + "192.168.6.3", + "192.168.6.4" + ], + "members": [ + "Ethernet5", + "Ethernet6" + ], + "vlanid": "600" + }, + "Vlan700": { + "dhcp_servers": [ + "192.168.7.1", + "192.168.7.2", + "192.168.7.3", + "192.168.7.4" + ], + "members": [ + "Ethernet5", + "Ethernet7" + ], + "vlanid": "700" + }, + "Vlan800": { + "dhcp_servers": [ + "192.168.8.1", + "192.168.8.2", + "192.168.8.3", + "192.168.8.4" + ], + "members": [ + "Ethernet5", + "Ethernet8" + ], + "vlanid": "800" + } + }, + "VLAN_MEMBER": { + "Vlan500|Ethernet5": { + "tagging_mode": "tagged" + }, + "Vlan500|Ethernet6": { + "tagging_mode": "untagged" + }, + "Vlan500|Ethernet7": { + "tagging_mode": "untagged" + }, + "Vlan500|Ethernet8": { + "tagging_mode": "untagged" + }, + "Vlan600|Ethernet5": { + "tagging_mode": "tagged" + }, + "Vlan600|Ethernet6": { + "tagging_mode": "tagged" + }, + "Vlan700|Ethernet5": { + "tagging_mode": "tagged" + }, + "Vlan700|Ethernet7": { + "tagging_mode": "tagged" + }, + "Vlan800|Ethernet5": { + "tagging_mode": "tagged" + }, + "Vlan800|Ethernet8": { + "tagging_mode": "tagged" + } + }, + "INTERFACE": { + "Ethernet1|192.168.1.1/24": {}, + "Ethernet2|192.168.2.1/24": {}, + "Ethernet3|192.168.3.1/24": {}, + "Ethernet4|192.168.4.1/24": {} + }, + "VLAN_INTERFACE": { + "Vlan500|192.168.5.1/24": {}, + "Vlan600|192.168.6.1/24": {}, + "Vlan700|192.168.7.1/24": {}, + "Vlan800|192.168.8.1/24": {} + }, + "LOOPBACK_INTERFACE": { + "Loopback0|127.0.0.1/8": {} + }, + "CABLE_LENGTH": { + "AZURE": { + "Ethernet8": "40m", + "Ethernet9": "40m", + "Ethernet2": "40m", + "Ethernet3": "40m", + "Ethernet1": "40m", + "Ethernet6": "40m", + "Ethernet7": "40m", + "Ethernet4": "40m", + "Ethernet5": "40m", + "Ethernet22": "40m", + "Ethernet50": "40m", + "Ethernet51": "40m", + "Ethernet52": "40m", + "Ethernet53": "40m", + "Ethernet54": "40m", + "Ethernet38": "40m", + "Ethernet39": "40m", + "Ethernet18": "40m", + "Ethernet19": "40m", + "Ethernet14": "40m", + "Ethernet15": "40m", + "Ethernet16": "40m", + "Ethernet17": "40m", + "Ethernet10": "40m", + "Ethernet11": "40m", + "Ethernet12": "40m", + "Ethernet35": "40m", + "Ethernet37": "40m", + "Ethernet32": "40m", + "Ethernet33": "40m", + "Ethernet30": "40m", + "Ethernet31": "40m", + "Ethernet49": "40m", + "Ethernet48": "40m", + "Ethernet47": "40m", + "Ethernet36": "40m", + "Ethernet45": "40m", + "Ethernet44": "40m", + "Ethernet43": "40m", + "Ethernet42": "40m", + "Ethernet41": "40m", + "Ethernet40": "40m", + "Ethernet29": "40m", + "Ethernet28": "40m", + "Ethernet34": "40m", + "Ethernet46": "40m", + "Ethernet21": "40m", + "Ethernet20": "40m", + "Ethernet23": "40m", + "Ethernet13": "40m", + "Ethernet25": "40m", + "Ethernet24": "40m", + "Ethernet27": "40m", + "Ethernet26": "40m" + } + }, + "CRM": { + "Config": { + "acl_table_threshold_type": "percentage", + "nexthop_group_threshold_type": "percentage", + "fdb_entry_high_threshold": "85", + "acl_entry_threshold_type": "percentage", + "ipv6_neighbor_low_threshold": "70", + "nexthop_group_member_low_threshold": "70", + "acl_group_high_threshold": "85", + "ipv4_route_high_threshold": "85", + "acl_counter_high_threshold": "85", + "ipv4_route_low_threshold": "70", + "ipv4_route_threshold_type": "percentage", + "ipv4_neighbor_low_threshold": "70", + "acl_group_threshold_type": "percentage", + "ipv4_nexthop_high_threshold": "85", + "ipv6_route_threshold_type": "percentage", + "nexthop_group_low_threshold": "70", + "ipv4_neighbor_high_threshold": "85", + "ipv6_route_high_threshold": "85", + "ipv6_nexthop_threshold_type": "percentage", + "polling_interval": "300", + "ipv4_nexthop_threshold_type": "percentage", + "acl_group_low_threshold": "70", + "acl_entry_low_threshold": "70", + "nexthop_group_member_threshold_type": "percentage", + "ipv4_nexthop_low_threshold": "70", + "acl_counter_threshold_type": "percentage", + "ipv6_neighbor_high_threshold": "85", + "nexthop_group_member_high_threshold": "85", + "acl_table_low_threshold": "70", + "fdb_entry_threshold_type": "percentage", + "ipv6_neighbor_threshold_type": "percentage", + "acl_table_high_threshold": "85", + "ipv6_nexthop_low_threshold": "70", + "acl_counter_low_threshold": "70", + "ipv4_neighbor_threshold_type": "percentage", + "nexthop_group_high_threshold": "85", + "ipv6_route_low_threshold": "70", + "acl_entry_high_threshold": "85", + "fdb_entry_low_threshold": "70", + "ipv6_nexthop_high_threshold": "85" + } + } +} diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_at24c64.c b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_at24c64.c index 52b8d536d0e6..e1835df88625 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_at24c64.c +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_at24c64.c @@ -1,657 +1,602 @@ -/* - * at24.c - handle most I2C EEPROMs - * - * Copyright (C) 2005-2007 David Brownell - * Copyright (C) 2008 Wolfram Sang, Pengutronix - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. - * Differences between different vendor product lines (like Atmel AT24C or - * MicroChip 24LC, etc) won't much matter for typical read/write access. - * There are also I2C RAM chips, likewise interchangeable. One example - * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). - * - * However, misconfiguration can lose data. "Set 16-bit memory address" - * to a part with 8-bit addressing will overwrite data. Writing with too - * big a page size also loses data. And it's not safe to assume that the - * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC - * uses 0x51, for just one example. - * - * Accordingly, explicit board-specific configuration data should be used - * in almost all cases. (One partial exception is an SMBus used to access - * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) - * - * So this driver uses "new style" I2C driver binding, expecting to be - * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or - * similar kernel-resident tables; or, configuration data coming from - * a bootloader. - * - * Other than binding model, current differences from "eeprom" driver are - * that this one handles write access and isn't restricted to 24c02 devices. - * It also handles larger devices (32 kbit and up) with two-byte addresses, - * which won't work on pure SMBus systems. - */ - -struct at24_data { - struct at24_platform_data chip; - struct memory_accessor macc; - int use_smbus; - - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - struct bin_attribute bin; - - u8 *writebuf; - unsigned write_max; - unsigned num_addresses; - - /* - * Some chips tie up multiple I2C addresses; dummy devices reserve - * them for us, and we'll use them with SMBus calls. - */ - struct i2c_client *client[]; -}; - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned io_limit = 128; -module_param(io_limit, uint, 0); -MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); - -/* - * Specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned write_timeout = 25; -module_param(write_timeout, uint, 0); -MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); - -#define AT24_SIZE_BYTELEN 5 -#define AT24_SIZE_FLAGS 8 - -#define AT24_BITMASK(x) (BIT(x) - 1) - -/* create non-zero magic value for given eeprom parameters */ -#define AT24_DEVICE_MAGIC(_len, _flags) \ - ((1 << AT24_SIZE_FLAGS | (_flags)) \ - << AT24_SIZE_BYTELEN | ilog2(_len)) - -static const struct i2c_device_id at24_ctc_ids[] = { - { "24c64-ctc", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16 | AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(i2c, at24_ctc_ids); - -/*-------------------------------------------------------------------------*/ - -/* - * This routine supports chips which consume multiple I2C addresses. It - * computes the addressing information to be used for a given r/w request. - * Assumes that sanity checks for offset happened at sysfs-layer. - */ -static struct i2c_client *at24_translate_offset(struct at24_data *at24, - unsigned *offset) -{ - unsigned i; - - if (at24->chip.flags & AT24_FLAG_ADDR16) { - i = *offset >> 16; - *offset &= 0xffff; - } else { - i = *offset >> 8; - *offset &= 0xff; - } - - return at24->client[i]; -} - -static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - struct i2c_client *client; - unsigned long timeout, read_time; - int status; - - memset(msg, 0, sizeof(msg)); - - /* - * REVISIT some multi-address chips don't rollover page reads to - * the next slave address, so we may need to truncate the count. - * Those chips might need another quirk flag. - * - * If the real hardware used four adjacent 24c02 chips and that - * were misconfigured as one 24c08, that would be a similar effect: - * one "eeprom" file not four, but larger reads would fail when - * they crossed certain pages. - */ - - /* - * Slave address and byte offset derive from the offset. Always - * set the byte address; on a multi-master board, another master - * may have changed the chip's "current" address pointer. - */ - client = at24_translate_offset(at24, &offset); - - if (count > io_limit) - count = io_limit; - - count = 1; - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - status = i2c_smbus_write_byte_data(client, (offset >> 8) & 0x0ff, offset & 0x0ff ); - status = i2c_smbus_read_byte(client); - if (status >= 0) { - buf[0] = status; - status = count; - } - - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t at24_read(struct at24_data *at24, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) - return count; - - memset(buf, 0, count); - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - while (count) { - ssize_t status; - - status = at24_eeprom_read(at24, buf, off, count); - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - //printk(KERN_ALERT "at24_read buf = %s, retval = %zu\n", buf, retval); - - mutex_unlock(&at24->lock); - - return retval; -} - -static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct at24_data *at24; - - at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return at24_read(at24, buf, off, count); -} - - -/* - * Note that if the hardware write-protect pin is pulled high, the whole - * chip is normally write protected. But there are plenty of product - * variants here, including OTP fuses and partial chip protect. - * - * We only use page mode writes; the alternative is sloooow. This routine - * writes at most one page. - */ -static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, - unsigned offset, size_t count) -{ - struct i2c_client *client; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page; - - /* Get corresponding I2C address and adjust offset */ - client = at24_translate_offset(at24, &offset); - - /* write_max is at most a page */ - if (count > at24->write_max) - count = at24->write_max; - - /* Never roll over backwards, to the start of this page */ - next_page = roundup(offset + 1, at24->chip.page_size); - if (offset + count > next_page) - count = next_page - offset; - - /* - * Writes fail if the previous one didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - status = i2c_smbus_write_word_data(client, - (offset >> 8) & 0x0ff, (offset & 0xFF) | buf[0]); - if (status == 0) - status = count; - - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, - size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) - return count; - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - while (count) { - ssize_t status; - - status = at24_eeprom_write(at24, buf, off, 1); /* only one-byte to write; TODO page wirte */ - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&at24->lock); - - return retval; -} - -static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct at24_data *at24; - - if (unlikely(off >= attr->size)) - return -EFBIG; - - at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return at24_write(at24, buf, off, count); -} - -/*-------------------------------------------------------------------------*/ - -/* - * This lets other kernel code access the eeprom data. For example, it - * might hold a board's Ethernet address, or board-specific calibration - * data generated on the manufacturing floor. - */ - -static ssize_t at24_macc_read(struct memory_accessor *macc, char *buf, - off_t offset, size_t count) -{ - struct at24_data *at24 = container_of(macc, struct at24_data, macc); - - return at24_read(at24, buf, offset, count); -} - -static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf, - off_t offset, size_t count) -{ - struct at24_data *at24 = container_of(macc, struct at24_data, macc); - - return at24_write(at24, buf, offset, count); -} - -/*-------------------------------------------------------------------------*/ - -#ifdef CONFIG_OF -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ - const __be32 *val; - struct device_node *node = client->dev.of_node; - - if (node) { - if (of_get_property(node, "read-only", NULL)) - chip->flags |= AT24_FLAG_READONLY; - val = of_get_property(node, "pagesize", NULL); - if (val) - chip->page_size = be32_to_cpup(val); - } -} -#else -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ } -#endif /* CONFIG_OF */ - -static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) -{ - struct at24_platform_data chip; - bool writable; - int use_smbus = 0; - struct at24_data *at24; - int err; - unsigned i, num_addresses; - kernel_ulong_t magic; - - if (client->dev.platform_data) { - chip = *(struct at24_platform_data *)client->dev.platform_data; - } else { - if (!id->driver_data) - return -ENODEV; - - magic = id->driver_data; - chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); - magic >>= AT24_SIZE_BYTELEN; - chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); - - /* - * This is slow, but we can't know all eeproms, so we better - * play safe. Specifying custom eeprom-types via platform_data - * is recommended anyhow. - */ - chip.page_size = 1; - - /* update chipdata if OF is present */ - at24_get_ofdata(client, &chip); - - printk(KERN_ALERT "at24_probe chip.byte_len = 0x%x\n", chip.byte_len); - printk(KERN_ALERT "at24_probe chip.flags = 0x%x\n", chip.flags); - printk(KERN_ALERT "at24_probe chip.magic = 0x%lx\n", id->driver_data); - - chip.setup = NULL; - chip.context = NULL; - } - - if (!is_power_of_2(chip.byte_len)) - dev_warn(&client->dev, - "byte_len looks suspicious (no power of 2)!\n"); - if (!chip.page_size) { - dev_err(&client->dev, "page_size must not be 0!\n"); - return -EINVAL; - } - if (!is_power_of_2(chip.page_size)) - dev_warn(&client->dev, - "page_size looks suspicious (no power of 2)!\n"); - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - return -EPFNOSUPPORT; - } - use_smbus = I2C_SMBUS_BYTE_DATA; - printk(KERN_ALERT "at24_probe use_smbus --> %d\n", - use_smbus); - } - - if (chip.flags & AT24_FLAG_TAKE8ADDR) - num_addresses = 8; - else - num_addresses = DIV_ROUND_UP(chip.byte_len, - (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); - - at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + - num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); - if (!at24) - return -ENOMEM; - - mutex_init(&at24->lock); - at24->use_smbus = use_smbus; - at24->chip = chip; - at24->num_addresses = num_addresses; - - /* - * Export the EEPROM bytes through sysfs, since that's convenient. - * By default, only root should see the data (maybe passwords etc) - */ - sysfs_bin_attr_init(&at24->bin); - at24->bin.attr.name = "eeprom"; - at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; - at24->bin.read = at24_bin_read; - at24->bin.size = chip.byte_len; - - at24->macc.read = at24_macc_read; - - writable = !(chip.flags & AT24_FLAG_READONLY); - if (writable) { - if (!use_smbus || i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { - - unsigned write_max = chip.page_size; - - at24->macc.write = at24_macc_write; - - at24->bin.write = at24_bin_write; - at24->bin.attr.mode |= S_IWUSR; - - if (write_max > io_limit) - write_max = io_limit; - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - at24->write_max = write_max; - - /* buffer (data + address at the beginning) */ - at24->writebuf = devm_kzalloc(&client->dev, - write_max + 2, GFP_KERNEL); - if (!at24->writebuf) - return -ENOMEM; - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - } - - at24->client[0] = client; - - /* use dummy devices for multiple-address chips */ - for (i = 1; i < num_addresses; i++) { - at24->client[i] = i2c_new_dummy(client->adapter, - client->addr + i); - if (!at24->client[i]) { - dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); - err = -EADDRINUSE; - goto err_clients; - } - } - - err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin); - if (err) - goto err_clients; - - i2c_set_clientdata(client, at24); - - dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n", - at24->bin.size, client->name, - writable ? "writable" : "read-only", at24->write_max); - if (use_smbus == I2C_SMBUS_WORD_DATA || - use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } - - /* export data to kernel code */ - if (chip.setup) - chip.setup(&at24->macc, chip.context); - - return 0; - -err_clients: - for (i = 1; i < num_addresses; i++) - if (at24->client[i]) - i2c_unregister_device(at24->client[i]); - - return err; -} - -static int at24_remove(struct i2c_client *client) -{ - struct at24_data *at24; - int i; - - at24 = i2c_get_clientdata(client); - sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); - - for (i = 1; i < at24->num_addresses; i++) - i2c_unregister_device(at24->client[i]); - - return 0; -} - -/*-------------------------------------------------------------------------*/ - -static struct i2c_board_info i2c_devs = { - I2C_BOARD_INFO("24c64-ctc", 0x57), -}; - -static struct i2c_adapter *adapter = NULL; -static struct i2c_client *client = NULL; - -static int ctc_at24c64_init(void) -{ - printk(KERN_ALERT "ctc_at24c64_init\n"); - - adapter = i2c_get_adapter(0); - if(adapter == NULL){ - printk(KERN_ALERT "i2c_get_adapter == NULL\n"); - return -1; - } - - client = i2c_new_device(adapter, &i2c_devs); - if(client == NULL){ - printk(KERN_ALERT "i2c_new_device == NULL\n"); - i2c_put_adapter(adapter); - adapter = NULL; - return -1; - } - - return 0; -} - -static void ctc_at24c64_exit(void) -{ - printk(KERN_ALERT "ctc_at24c64_exit\n"); - if(client){ - i2c_unregister_device(client); - } - if(adapter){ - i2c_put_adapter(adapter); - } -} - -static struct i2c_driver at24_ctc_driver = { - .driver = { - .name = "at24-ctc", - .owner = THIS_MODULE, - }, - .probe = at24_probe, - .remove = at24_remove, - .id_table = at24_ctc_ids, -}; - -static int __init at24_ctc_init(void) -{ - if (!io_limit) { - pr_err("at24_ctc: io_limit must not be 0!\n"); - return -EINVAL; - } - - io_limit = rounddown_pow_of_two(io_limit); - - ctc_at24c64_init(); - - return i2c_add_driver(&at24_ctc_driver); -} -module_init(at24_ctc_init); - -static void __exit at24_ctc_exit(void) -{ - ctc_at24c64_exit(); - i2c_del_driver(&at24_ctc_driver); -} -module_exit(at24_ctc_exit); - -MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); -MODULE_AUTHOR("David Brownell and Wolfram Sang"); -MODULE_LICENSE("GPL"); +/* + * at24.c - handle most I2C EEPROMs + * + * Copyright (C) 2005-2007 David Brownell + * Copyright (C) 2008 Wolfram Sang, Pengutronix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. + * Differences between different vendor product lines (like Atmel AT24C or + * MicroChip 24LC, etc) won't much matter for typical read/write access. + * There are also I2C RAM chips, likewise interchangeable. One example + * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). + * + * However, misconfiguration can lose data. "Set 16-bit memory address" + * to a part with 8-bit addressing will overwrite data. Writing with too + * big a page size also loses data. And it's not safe to assume that the + * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC + * uses 0x51, for just one example. + * + * Accordingly, explicit board-specific configuration data should be used + * in almost all cases. (One partial exception is an SMBus used to access + * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) + * + * So this driver uses "new style" I2C driver binding, expecting to be + * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or + * similar kernel-resident tables; or, configuration data coming from + * a bootloader. + * + * Other than binding model, current differences from "eeprom" driver are + * that this one handles write access and isn't restricted to 24c02 devices. + * It also handles larger devices (32 kbit and up) with two-byte addresses, + * which won't work on pure SMBus systems. + */ + +struct at24_data { + struct at24_platform_data chip; + int use_smbus; + + /* + * Lock protects against activities from other Linux tasks, + * but not from changes by other I2C masters. + */ + struct mutex lock; + struct bin_attribute bin; + + u8 *writebuf; + unsigned write_max; + unsigned num_addresses; + + /* + * Some chips tie up multiple I2C addresses; dummy devices reserve + * them for us, and we'll use them with SMBus calls. + */ + struct i2c_client *client[]; +}; + +/* + * This parameter is to help this driver avoid blocking other drivers out + * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C + * clock, one 256 byte read takes about 1/43 second which is excessive; + * but the 1/170 second it takes at 400 kHz may be quite reasonable; and + * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. + * + * This value is forced to be a power of two so that writes align on pages. + */ +static unsigned io_limit = 128; +module_param(io_limit, uint, 0); +MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); + +/* + * Specs often allow 5 msec for a page write, sometimes 20 msec; + * it's important to recover from write timeouts. + */ +static unsigned write_timeout = 25; +module_param(write_timeout, uint, 0); +MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); + +#define AT24_SIZE_BYTELEN 5 +#define AT24_SIZE_FLAGS 8 + +#define AT24_BITMASK(x) (BIT(x) - 1) + +/* create non-zero magic value for given eeprom parameters */ +#define AT24_DEVICE_MAGIC(_len, _flags) \ + ((1 << AT24_SIZE_FLAGS | (_flags)) \ + << AT24_SIZE_BYTELEN | ilog2(_len)) + +static const struct i2c_device_id at24_ctc_ids[] = { + { "24c64-ctc", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16 | AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, + { /* END OF LIST */ } +}; +MODULE_DEVICE_TABLE(i2c, at24_ctc_ids); + +/*-------------------------------------------------------------------------*/ + +/* + * This routine supports chips which consume multiple I2C addresses. It + * computes the addressing information to be used for a given r/w request. + * Assumes that sanity checks for offset happened at sysfs-layer. + */ +static struct i2c_client *at24_translate_offset(struct at24_data *at24, + unsigned *offset) +{ + unsigned i = 0; + + if (at24->chip.flags & AT24_FLAG_ADDR16) { + i = *offset >> 16; + *offset &= 0xffff; + } else { + i = *offset >> 8; + *offset &= 0xff; + } + + return at24->client[i]; +} + +static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, + unsigned offset, size_t count) +{ + struct i2c_msg msg[2]; + struct i2c_client *client; + unsigned long timeout, read_time; + int status; + + memset(msg, 0, sizeof(msg)); + + /* + * REVISIT some multi-address chips don't rollover page reads to + * the next slave address, so we may need to truncate the count. + * Those chips might need another quirk flag. + * + * If the real hardware used four adjacent 24c02 chips and that + * were misconfigured as one 24c08, that would be a similar effect: + * one "eeprom" file not four, but larger reads would fail when + * they crossed certain pages. + */ + + /* + * Slave address and byte offset derive from the offset. Always + * set the byte address; on a multi-master board, another master + * may have changed the chip's "current" address pointer. + */ + client = at24_translate_offset(at24, &offset); + + if (count > io_limit) + count = io_limit; + + count = 1; + + /* + * Reads fail if the previous write didn't complete yet. We may + * loop a few times until this one succeeds, waiting at least + * long enough for one entire page write to work. + */ + timeout = jiffies + msecs_to_jiffies(write_timeout); + do { + read_time = jiffies; + + status = i2c_smbus_write_byte_data(client, (offset >> 8) & 0x0ff, offset & 0x0ff ); + status = i2c_smbus_read_byte(client); + if (status >= 0) { + buf[0] = status; + status = count; + } + + dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", count, offset, status, jiffies); + + if (status == count) + return count; + + /* REVISIT: at HZ=100, this is sloooow */ + msleep(1); + } while (time_before(read_time, timeout)); + + return -ETIMEDOUT; +} + +static ssize_t at24_read(struct at24_data *at24, + char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) + return count; + + memset(buf, 0, count); + + /* + * Read data from chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&at24->lock); + + while (count) { + ssize_t status; + + status = at24_eeprom_read(at24, buf, off, count); + if (status <= 0) { + if (retval == 0) + retval = status; + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&at24->lock); + + return retval; +} + +static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + struct at24_data *at24; + + at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); + return at24_read(at24, buf, off, count); +} + + +/* + * Note that if the hardware write-protect pin is pulled high, the whole + * chip is normally write protected. But there are plenty of product + * variants here, including OTP fuses and partial chip protect. + * + * We only use page mode writes; the alternative is sloooow. This routine + * writes at most one page. + */ +static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, + unsigned offset, size_t count) +{ + struct i2c_client *client; + ssize_t status; + unsigned long timeout, write_time; + unsigned next_page; + + /* Get corresponding I2C address and adjust offset */ + client = at24_translate_offset(at24, &offset); + + /* write_max is at most a page */ + if (count > at24->write_max) + count = at24->write_max; + + /* Never roll over backwards, to the start of this page */ + next_page = roundup(offset + 1, at24->chip.page_size); + if (offset + count > next_page) + count = next_page - offset; + + /* + * Writes fail if the previous one didn't complete yet. We may + * loop a few times until this one succeeds, waiting at least + * long enough for one entire page write to work. + */ + timeout = jiffies + msecs_to_jiffies(write_timeout); + do { + write_time = jiffies; + + status = i2c_smbus_write_word_data(client, (offset >> 8) & 0x0ff, (offset & 0xFF) | buf[0]); + if (status == 0) + status = count; + + dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", count, offset, status, jiffies); + + if (status == count) + return count; + + /* REVISIT: at HZ=100, this is sloooow */ + msleep(1); + } while (time_before(write_time, timeout)); + + return -ETIMEDOUT; +} + +static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, + size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) + return count; + + /* + * Write data to chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&at24->lock); + + while (count) { + ssize_t status; + + status = at24_eeprom_write(at24, buf, off, 1); /* only one-byte to write; TODO page wirte */ + if (status <= 0) { + if (retval == 0) + retval = status; + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&at24->lock); + + return retval; +} + +static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + struct at24_data *at24; + + if (unlikely(off >= attr->size)) + return -EFBIG; + + at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); + return at24_write(at24, buf, off, count); +} + +/*-------------------------------------------------------------------------*/ + +#ifdef CONFIG_OF +static void at24_get_ofdata(struct i2c_client *client, + struct at24_platform_data *chip) +{ + const __be32 *val; + struct device_node *node = client->dev.of_node; + + if (node) { + if (of_get_property(node, "read-only", NULL)) + chip->flags |= AT24_FLAG_READONLY; + val = of_get_property(node, "pagesize", NULL); + if (val) + chip->page_size = be32_to_cpup(val); + } +} +#else +static void at24_get_ofdata(struct i2c_client *client, + struct at24_platform_data *chip) +{ } +#endif /* CONFIG_OF */ + +static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct at24_platform_data chip; + bool writable; + int use_smbus = 0; + struct at24_data *at24; + int err; + unsigned i, num_addresses; + kernel_ulong_t magic; + + if (client->dev.platform_data) { + chip = *(struct at24_platform_data *)client->dev.platform_data; + } else { + if (!id->driver_data) + return -ENODEV; + + magic = id->driver_data; + chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); + magic >>= AT24_SIZE_BYTELEN; + chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); + + /* + * This is slow, but we can't know all eeproms, so we better + * play safe. Specifying custom eeprom-types via platform_data + * is recommended anyhow. + */ + chip.page_size = 1; + + /* update chipdata if OF is present */ + at24_get_ofdata(client, &chip); + + chip.setup = NULL; + chip.context = NULL; + } + + if (!is_power_of_2(chip.byte_len)) + dev_warn(&client->dev, + "byte_len looks suspicious (no power of 2)!\n"); + if (!chip.page_size) { + dev_err(&client->dev, "page_size must not be 0!\n"); + return -EINVAL; + } + if (!is_power_of_2(chip.page_size)) + dev_warn(&client->dev, + "page_size looks suspicious (no power of 2)!\n"); + + /* Use I2C operations unless we're stuck with SMBus extensions. */ + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) { + use_smbus = I2C_SMBUS_WORD_DATA; + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { + use_smbus = I2C_SMBUS_BYTE_DATA; + } else { + return -EPFNOSUPPORT; + } + use_smbus = I2C_SMBUS_BYTE_DATA; + } + + if (chip.flags & AT24_FLAG_TAKE8ADDR) + num_addresses = 8; + else + num_addresses = DIV_ROUND_UP(chip.byte_len, (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); + + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); + if (!at24) + return -ENOMEM; + + mutex_init(&at24->lock); + at24->use_smbus = use_smbus; + at24->chip = chip; + at24->num_addresses = num_addresses; + + printk(KERN_ALERT "at24_probe chip.byte_len = 0x%x\n", chip.byte_len); + printk(KERN_ALERT "at24_probe chip.flags = 0x%x\n", chip.flags); + printk(KERN_ALERT "at24_probe chip.magic = 0x%lx\n", id->driver_data); + printk(KERN_ALERT "at24_probe use_smbus = %d\n", at24->use_smbus); + printk(KERN_ALERT "at24_probe num_addresses = %d\n", at24->num_addresses); + + /* + * Export the EEPROM bytes through sysfs, since that's convenient. + * By default, only root should see the data (maybe passwords etc) + */ + sysfs_bin_attr_init(&at24->bin); + at24->bin.attr.name = "eeprom"; + at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; + at24->bin.read = at24_bin_read; + at24->bin.size = chip.byte_len; + + writable = !(chip.flags & AT24_FLAG_READONLY); + if (writable) { + if (!use_smbus || i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { + unsigned write_max = chip.page_size; + + at24->bin.write = at24_bin_write; + at24->bin.attr.mode |= S_IWUSR; + + if (write_max > io_limit) + write_max = io_limit; + if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) + write_max = I2C_SMBUS_BLOCK_MAX; + at24->write_max = write_max; + + /* buffer (data + address at the beginning) */ + at24->writebuf = devm_kzalloc(&client->dev, write_max + 2, GFP_KERNEL); + if (!at24->writebuf) + return -ENOMEM; + } else { + dev_warn(&client->dev, "cannot write due to controller restrictions."); + } + } + + at24->client[0] = client; + + /* use dummy devices for multiple-address chips */ + for (i = 1; i < num_addresses; i++) { + at24->client[i] = i2c_new_dummy(client->adapter, client->addr + i); + if (!at24->client[i]) { + dev_err(&client->dev, "address 0x%02x unavailable\n", client->addr + i); + err = -EADDRINUSE; + goto err_clients; + } + } + + err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin); + if (err) + goto err_clients; + + i2c_set_clientdata(client, at24); + + printk(KERN_ALERT "at24_probe %s done\n", client->name); + + return 0; + +err_clients: + for (i = 1; i < num_addresses; i++) + if (at24->client[i]) + i2c_unregister_device(at24->client[i]); + + return err; +} + +static int at24_remove(struct i2c_client *client) +{ + struct at24_data *at24; + int i; + + at24 = i2c_get_clientdata(client); + sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); + + for (i = 1; i < at24->num_addresses; i++) + i2c_unregister_device(at24->client[i]); + + return 0; +} + +/*-------------------------------------------------------------------------*/ + +static struct i2c_board_info i2c_devs = { + I2C_BOARD_INFO("24c64-ctc", 0x57), +}; + +static struct i2c_adapter *adapter = NULL; +static struct i2c_client *client = NULL; + +static int ctc_at24c64_init(void) +{ + printk(KERN_ALERT "ctc_at24c64_init\n"); + + adapter = i2c_get_adapter(0); + if(adapter == NULL){ + printk(KERN_ALERT "i2c_get_adapter == NULL\n"); + return -1; + } + + client = i2c_new_device(adapter, &i2c_devs); + if(client == NULL){ + printk(KERN_ALERT "i2c_new_device == NULL\n"); + i2c_put_adapter(adapter); + adapter = NULL; + return -1; + } + + return 0; +} + +static void ctc_at24c64_exit(void) +{ + printk(KERN_ALERT "ctc_at24c64_exit\n"); + if(client){ + i2c_unregister_device(client); + } + if(adapter){ + i2c_put_adapter(adapter); + } +} + +static struct i2c_driver at24_ctc_driver = { + .driver = { + .name = "at24-ctc", + .owner = THIS_MODULE, + }, + .probe = at24_probe, + .remove = at24_remove, + .id_table = at24_ctc_ids, +}; + +static int __init at24_ctc_init(void) +{ + if (!io_limit) { + pr_err("at24_ctc: io_limit must not be 0!\n"); + return -EINVAL; + } + + io_limit = rounddown_pow_of_two(io_limit); + + ctc_at24c64_init(); + + return i2c_add_driver(&at24_ctc_driver); +} +module_init(at24_ctc_init); + +static void __exit at24_ctc_exit(void) +{ + ctc_at24c64_exit(); + i2c_del_driver(&at24_ctc_driver); +} +module_exit(at24_ctc_exit); + +MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); +MODULE_AUTHOR("David Brownell and Wolfram Sang"); +MODULE_LICENSE("GPL"); +/* XXX */ + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_e582_48x2q4z_platform.c b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_e582_48x2q4z_platform.c index 003f9a80caf0..16bed86593b2 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_e582_48x2q4z_platform.c +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/centec_e582_48x2q4z_platform.c @@ -2,10 +2,52 @@ #include #include #include +#include +#include +#include +#define SEP(XXX) 1 +#define IS_INVALID_PTR(_PTR_) ((_PTR_ == NULL) || IS_ERR(_PTR_)) +#define IS_VALID_PTR(_PTR_) (!IS_INVALID_PTR(_PTR_)) + +#if SEP("defines") #define PCA9548_CHANNEL_NUM 8 #define PCA9548_ADAPT_ID_START 10 +#define SFP_NUM 48 +#define QSFP_NUM 6 +#define PORT_NUM (SFP_NUM+QSFP_NUM) +#endif + +#if SEP("i2c:master") +static struct i2c_adapter *i2c_adp_master = NULL; /* i2c-0-cpu */ + +static int e582_48x2q4z_init_i2c_master(void) +{ + /* find i2c-core master */ + i2c_adp_master = i2c_get_adapter(0); + if(IS_INVALID_PTR(i2c_adp_master)) + { + i2c_adp_master = NULL; + printk(KERN_CRIT "e582_48x2q4z_init_i2c_master can't find i2c-core bus\n"); + return -1; + } + + return 0; +} + +static int e582_48x2q4z_exit_i2c_master(void) +{ + /* uninstall i2c-core master */ + if(IS_VALID_PTR(i2c_adp_master)) { + i2c_put_adapter(i2c_adp_master); + i2c_adp_master = NULL; + } + + return 0; +} +#endif +#if SEP("i2c:pca9548") static struct pca954x_platform_mode i2c_dev_pca9548_platform_mode[PCA9548_CHANNEL_NUM] = { [0] = { .adap_id = PCA9548_ADAPT_ID_START, @@ -48,95 +90,1368 @@ static struct pca954x_platform_mode i2c_dev_pca9548_platform_mode[PCA9548_CHANNE .class = 0, } }; - static struct pca954x_platform_data i2c_dev_pca9548_platform_data = { .modes = i2c_dev_pca9548_platform_mode, .num_modes = PCA9548_CHANNEL_NUM, }; - static struct i2c_board_info i2c_dev_pca9548 = { I2C_BOARD_INFO("pca9548", 0x70), .platform_data = &i2c_dev_pca9548_platform_data, }; +static struct i2c_client *i2c_client_pca9548x = NULL; + +static int e582_48x2q4z_init_i2c_pca9548(void) +{ + if(IS_INVALID_PTR(i2c_adp_master)) + { + i2c_adp_master = NULL; + printk(KERN_CRIT "e582_48x2q4z_init_i2c_pca9548 can't find i2c-core bus\n"); + return -1; + } + + /* install i2c-mux */ + i2c_client_pca9548x = i2c_new_device(i2c_adp_master, &i2c_dev_pca9548); + if(IS_INVALID_PTR(i2c_client_pca9548x)) + { + i2c_client_pca9548x = NULL; + printk(KERN_CRIT "install e582_48x2q4z board pca9548 failed\n"); + return -1; + } + + return 0; +} + +static int e582_48x2q4z_exit_i2c_pca9548(void) +{ + /* uninstall i2c-core master */ + if(IS_VALID_PTR(i2c_client_pca9548x)) { + i2c_unregister_device(i2c_client_pca9548x); + i2c_client_pca9548x = NULL; + } + + return 0; +} +#endif -static struct i2c_board_info i2c_dev_adt7475 = { +#if SEP("i2c:adt7470") +static struct i2c_board_info i2c_dev_adt7470 = { I2C_BOARD_INFO("adt7470", 0x2F), }; +static struct i2c_adapter *i2c_adp_adt7470 = NULL; /* pca9548x-channel 4 */ +static struct i2c_client *i2c_client_adt7470 = NULL; -struct i2c_adapter *i2c_core_master = NULL; /* i2c-0-cpu */ -struct i2c_adapter *i2c_mux_channel_4 = NULL; /* pca9548x-channel 5 */ -struct i2c_client *i2c_client_pca9548x = NULL; -struct i2c_client *i2c_client_adt7475 = NULL; +static int e582_48x2q4z_init_i2c_adt7470(void) +{ + i2c_adp_adt7470 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 4); + if(IS_INVALID_PTR(i2c_adp_adt7470)) + { + i2c_adp_adt7470 = NULL; + printk(KERN_CRIT "install e582_48x2q4z board adt7470 failed\n"); + return -1; + } + + i2c_client_adt7470 = i2c_new_device(i2c_adp_adt7470, &i2c_dev_adt7470); + if(IS_INVALID_PTR(i2c_client_adt7470)){ + i2c_client_adt7470 = NULL; + printk(KERN_CRIT "install e582_48x2q4z board adt7470 failed\n"); + return -1; + } + + return 0; +} -static int e582_48x6q_init(void) +static int e582_48x2q4z_exit_i2c_adt7470(void) { - printk(KERN_INFO "install e582_48x6q board dirver...\n"); - - /* find i2c-core master */ - i2c_core_master = i2c_get_adapter(0); - if(i2c_core_master == NULL) + if(IS_VALID_PTR(i2c_client_adt7470)) { + i2c_unregister_device(i2c_client_adt7470); + i2c_client_adt7470 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_adt7470)) { + i2c_put_adapter(i2c_adp_adt7470); + i2c_adp_adt7470 = NULL; + } + + return 0; +} +#endif + +#if SEP("i2c:psu") +static struct i2c_adapter *i2c_adp_psu1 = NULL; /* psu1 channel 1 */ +static struct i2c_adapter *i2c_adp_psu2 = NULL; /* psu2 channel 0 */ +static struct i2c_board_info i2c_dev_psu1 = { + I2C_BOARD_INFO("i2c-psu1", 0x38), +}; +static struct i2c_board_info i2c_dev_psu2 = { + I2C_BOARD_INFO("i2c-psu2", 0x38), +}; +static struct i2c_client *i2c_client_psu1 = NULL; +static struct i2c_client *i2c_client_psu2 = NULL; + +static int e582_48x2q4z_init_i2c_psu(void) +{ + i2c_adp_psu1 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 1); + if(IS_INVALID_PTR(i2c_adp_psu1)) { - printk(KERN_CRIT "can't find i2c-core bus\n"); - goto err_i2c_core_master; + i2c_adp_psu1 = NULL; + printk(KERN_CRIT "get e582_48x2q4z psu1 i2c-adp failed\n"); + return -1; } - - /* install i2c-mux */ - i2c_client_pca9548x = i2c_new_device(i2c_core_master, &i2c_dev_pca9548); - if(i2c_client_pca9548x == NULL) + + i2c_adp_psu2 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 0); + if(IS_INVALID_PTR(i2c_adp_psu2)) + { + i2c_adp_psu2 = NULL; + printk(KERN_CRIT "get e582_48x2q4z psu2 i2c-adp failed\n"); + return -1; + } + + i2c_client_psu1 = i2c_new_device(i2c_adp_psu1, &i2c_dev_psu1); + if(IS_INVALID_PTR(i2c_client_psu1)){ + i2c_client_psu1 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client psu1 failed\n"); + return -1; + } + + i2c_client_psu2 = i2c_new_device(i2c_adp_psu2, &i2c_dev_psu2); + if(IS_INVALID_PTR(i2c_client_psu2)){ + i2c_client_psu2 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client psu2 failed\n"); + return -1; + } + + return 0; +} + +static int e582_48x2q4z_exit_i2c_psu(void) +{ + if(IS_VALID_PTR(i2c_client_psu1)) { + i2c_unregister_device(i2c_client_psu1); + i2c_client_psu1 = NULL; + } + + if(IS_VALID_PTR(i2c_client_psu2)) { + i2c_unregister_device(i2c_client_psu2); + i2c_client_psu2 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_psu1)) + { + i2c_put_adapter(i2c_adp_psu1); + i2c_adp_psu1 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_psu2)) + { + i2c_put_adapter(i2c_adp_psu2); + i2c_adp_psu2 = NULL; + } + + return 0; +} +#endif + +#if SEP("i2c:epld") +static struct i2c_board_info i2c_dev_epld = { + I2C_BOARD_INFO("i2c-epld", 0x58), +}; +static struct i2c_client *i2c_client_epld = NULL; + +static int e582_48x2q4z_init_i2c_epld(void) +{ + if (IS_INVALID_PTR(i2c_adp_master)) { - printk(KERN_INFO "install e582_48x6q board pca9548 failed\n"); - goto install_at24c64; + printk(KERN_CRIT "e582_48x2q4z_init_i2c_epld can't find i2c-core bus\n"); + return -1; } - /* install adt7475 */ - /* find i2c-mux-channel 15 */ - i2c_mux_channel_4 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 4); - if(i2c_mux_channel_4 == NULL) + i2c_client_epld = i2c_new_device(i2c_adp_master, &i2c_dev_epld); + if(IS_INVALID_PTR(i2c_client_epld)) { - printk(KERN_INFO "install e582_48x6q board adt7470 failed\n"); - goto install_at24c64; + i2c_client_epld = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client epld failed\n"); + return -1; + } + + return 0; +} + +static int e582_48x2q4z_exit_i2c_epld(void) +{ + if(IS_VALID_PTR(i2c_client_epld)) { + i2c_unregister_device(i2c_client_epld); + i2c_client_epld = NULL; } - i2c_client_adt7475 = i2c_new_device(i2c_mux_channel_4, &i2c_dev_adt7475); - if(i2c_client_adt7475 == NULL){ - printk(KERN_INFO "install e582_48x6q board adt7470 failed\n"); - goto install_at24c64; + return 0; +} +#endif + +#if SEP("i2c:gpio") +static struct i2c_adapter *i2c_adp_gpio0 = NULL; /* gpio0 channel 5 */ +static struct i2c_adapter *i2c_adp_gpio1 = NULL; /* gpio1 channel 5 */ +static struct i2c_adapter *i2c_adp_gpio2 = NULL; /* gpio2 channel 5 */ +static struct i2c_adapter *i2c_adp_gpio3 = NULL; /* gpio3 channel 6 */ +static struct i2c_adapter *i2c_adp_gpio4 = NULL; /* gpio4 channel 7 */ +static struct i2c_board_info i2c_dev_gpio0 = { + I2C_BOARD_INFO("i2c-gpio0", 0x21), +}; +static struct i2c_board_info i2c_dev_gpio1 = { + I2C_BOARD_INFO("i2c-gpio1", 0x22), +}; +static struct i2c_board_info i2c_dev_gpio2 = { + I2C_BOARD_INFO("i2c-gpio2", 0x23), +}; +static struct i2c_board_info i2c_dev_gpio3 = { + I2C_BOARD_INFO("i2c-gpio3", 0x21), +}; +static struct i2c_board_info i2c_dev_gpio4 = { + I2C_BOARD_INFO("i2c-gpio4", 0x22), +}; +static struct i2c_client *i2c_client_gpio0 = NULL; +static struct i2c_client *i2c_client_gpio1 = NULL; +static struct i2c_client *i2c_client_gpio2 = NULL; +static struct i2c_client *i2c_client_gpio3 = NULL; +static struct i2c_client *i2c_client_gpio4 = NULL; + +static int e582_48x2q4z_init_i2c_gpio(void) +{ + if (IS_INVALID_PTR(i2c_adp_master)) + { + printk(KERN_CRIT "e582_48x2q4z_init_i2c_gpio can't find i2c-core bus\n"); + return -1; + } + + i2c_adp_gpio0 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 5); + if(IS_INVALID_PTR(i2c_adp_gpio0)) + { + i2c_adp_gpio0 = NULL; + printk(KERN_CRIT "get e582_48x2q4z gpio0 i2c-adp failed\n"); + return -1; + } + + i2c_adp_gpio1 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 5); + if(IS_INVALID_PTR(i2c_adp_gpio1)) + { + i2c_adp_gpio1 = NULL; + printk(KERN_CRIT "get e582_48x2q4z gpio1 i2c-adp failed\n"); + return -1; + } + + i2c_adp_gpio2 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 5); + if(IS_INVALID_PTR(i2c_adp_gpio2)) + { + i2c_adp_gpio2 = NULL; + printk(KERN_CRIT "get e582_48x2q4z gpio2 i2c-adp failed\n"); + return -1; + } + + i2c_adp_gpio3 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 6); + if(IS_INVALID_PTR(i2c_adp_gpio3)) + { + i2c_adp_gpio3 = NULL; + printk(KERN_CRIT "get e582_48x2q4z gpio3 i2c-adp failed\n"); + return -1; + } + + i2c_adp_gpio4 = i2c_get_adapter(PCA9548_ADAPT_ID_START + 7); + if(IS_INVALID_PTR(i2c_adp_gpio4)) + { + i2c_adp_gpio4 = NULL; + printk(KERN_CRIT "get e582_48x2q4z gpio4 i2c-adp failed\n"); + return -1; } -install_at24c64: + i2c_client_gpio0 = i2c_new_device(i2c_adp_gpio0, &i2c_dev_gpio0); + if(IS_INVALID_PTR(i2c_client_gpio0)) + { + i2c_client_gpio0 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client gpio0 failed\n"); + return -1; + } + + i2c_client_gpio1 = i2c_new_device(i2c_adp_gpio1, &i2c_dev_gpio1); + if(IS_INVALID_PTR(i2c_client_gpio1)) + { + i2c_client_gpio1 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client gpio1 failed\n"); + return -1; + } + + i2c_client_gpio2 = i2c_new_device(i2c_adp_gpio2, &i2c_dev_gpio2); + if(IS_INVALID_PTR(i2c_client_gpio2)) + { + i2c_client_gpio2 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client gpio2 failed\n"); + return -1; + } + + i2c_client_gpio3 = i2c_new_device(i2c_adp_gpio3, &i2c_dev_gpio3); + if(IS_INVALID_PTR(i2c_client_gpio3)) + { + i2c_client_gpio3 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client gpio3 failed\n"); + return -1; + } + + i2c_client_gpio4 = i2c_new_device(i2c_adp_gpio4, &i2c_dev_gpio4); + if(IS_INVALID_PTR(i2c_client_gpio4)) + { + i2c_client_gpio4 = NULL; + printk(KERN_CRIT "create e582_48x2q4z board i2c client gpio4 failed\n"); + return -1; + } + + return 0; +} + +static int e582_48x2q4z_exit_i2c_gpio(void) +{ + if(IS_VALID_PTR(i2c_client_gpio0)) { + i2c_unregister_device(i2c_client_gpio0); + i2c_client_gpio0 = NULL; + } + + if(IS_VALID_PTR(i2c_client_gpio1)) { + i2c_unregister_device(i2c_client_gpio1); + i2c_client_gpio1 = NULL; + } + + if(IS_VALID_PTR(i2c_client_gpio2)) { + i2c_unregister_device(i2c_client_gpio2); + i2c_client_gpio2 = NULL; + } + + if(IS_VALID_PTR(i2c_client_gpio3)) { + i2c_unregister_device(i2c_client_gpio3); + i2c_client_gpio3 = NULL; + } + + if(IS_VALID_PTR(i2c_client_gpio4)) { + i2c_unregister_device(i2c_client_gpio4); + i2c_client_gpio4 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_gpio0)) + { + i2c_put_adapter(i2c_adp_gpio0); + i2c_adp_gpio0 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_gpio1)) + { + i2c_put_adapter(i2c_adp_gpio1); + i2c_adp_gpio1 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_gpio2)) + { + i2c_put_adapter(i2c_adp_gpio2); + i2c_adp_gpio2 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_gpio3)) + { + i2c_put_adapter(i2c_adp_gpio3); + i2c_adp_gpio3 = NULL; + } + + if(IS_VALID_PTR(i2c_adp_gpio4)) + { + i2c_put_adapter(i2c_adp_gpio4); + i2c_adp_gpio4 = NULL; + } - printk(KERN_INFO "install e582_48x6q board dirver...ok\n"); return 0; +} +#endif + +#if SEP("i2c:smbus") +static int e582_48x2q4z_smbus_read_reg(struct i2c_client *client, unsigned char reg, unsigned char* value) +{ + int ret = 0; + + if (IS_INVALID_PTR(client)) + { + printk(KERN_CRIT "invalid i2c client"); + return -1; + } -err_i2c_core_master: - return -1; + ret = i2c_smbus_read_byte_data(client, reg); + if (ret >= 0) { + *value = (unsigned char)ret; + } + else + { + *value = 0; + printk(KERN_CRIT "i2c_smbus op failed: ret=%d reg=%d\n",ret ,reg); + return ret; + } + + return 0; } -static void e582_48x6q_exit(void) +static int e582_48x2q4z_smbus_write_reg(struct i2c_client *client, unsigned char reg, unsigned char value) { - printk(KERN_INFO "uninstall e582_48x6q board dirver...\n"); + int ret = 0; - /* uninstall adt7475 master */ - if(i2c_client_adt7475) { - i2c_unregister_device(i2c_client_adt7475); + if (IS_INVALID_PTR(client)) + { + printk(KERN_CRIT "invalid i2c client"); + return -1; + } + + ret = i2c_smbus_write_byte_data(client, reg, value); + if (ret != 0) + { + printk(KERN_CRIT "i2c_smbus op failed: ret=%d reg=%d\n",ret ,reg); + return ret; + } + + return 0; +} +#endif + +#if SEP("drivers:psu") +static struct class* psu_class = NULL; +static struct device* psu_dev_psu1 = NULL; +static struct device* psu_dev_psu2 = NULL; + +static ssize_t e582_48x2q4z_psu_read_presence(struct device *dev, struct device_attribute *attr, char *buf) +{ + int ret = 0; + unsigned char present_no = 0; + unsigned char present = 0; + unsigned char value = 0; + struct i2c_client *i2c_psu_client = NULL; + + if (psu_dev_psu1 == dev) + { + i2c_psu_client = i2c_client_gpio2; + present_no = 30; + } + else if (psu_dev_psu2 == dev) + { + i2c_psu_client = i2c_client_gpio2; + present_no = 29; + } + else + { + return sprintf(buf, "Error: unknown psu device\n"); + } + + if (IS_INVALID_PTR(i2c_psu_client)) + { + return sprintf(buf, "Error: psu i2c-adapter invalid\n"); } - if(i2c_mux_channel_4) { - i2c_put_adapter(i2c_mux_channel_4); + + ret = e582_48x2q4z_smbus_read_reg(i2c_psu_client, present_no/8, &present); + if (ret != 0) + { + return sprintf(buf, "Error: read psu data:%s failed\n", attr->attr.name); } + + value = ((present & (1<<(present_no%8))) ? 1 : 0 ); - /* uninstall i2c-core master */ - if(i2c_client_pca9548x) { - i2c_unregister_device(i2c_client_pca9548x); + return sprintf(buf, "%d\n", value); +} + +static ssize_t e582_48x2q4z_psu_read_status(struct device *dev, struct device_attribute *attr, char *buf) +{ + int ret = 0; + unsigned char workstate_no = 0; + unsigned char workstate = 0; + unsigned char value = 0; + struct i2c_client *i2c_psu_client = NULL; + + if (psu_dev_psu1 == dev) + { + i2c_psu_client = i2c_client_gpio2; + workstate_no = 36; + } + else if (psu_dev_psu2 == dev) + { + i2c_psu_client = i2c_client_gpio2; + workstate_no = 35; + } + else + { + return sprintf(buf, "Error: unknown psu device\n"); + } + + if (IS_INVALID_PTR(i2c_psu_client)) + { + return sprintf(buf, "Error: psu i2c-adapter invalid\n"); + } + + ret = e582_48x2q4z_smbus_read_reg(i2c_psu_client, workstate_no/8, &workstate); + if (ret != 0) + { + return sprintf(buf, "Error: read psu data:%s failed\n", attr->attr.name); } + + if (ret != 0) + { + return sprintf(buf, "Error: read psu data:%s failed\n", attr->attr.name); + } + + value = ((workstate & (1<<(workstate_no%8))) ? 1 : 0 ); - /* uninstall i2c-core master */ - if(i2c_core_master) { - i2c_put_adapter(i2c_core_master); + return sprintf(buf, "%d\n", value); +} + +static DEVICE_ATTR(psu_presence, S_IRUGO, e582_48x2q4z_psu_read_presence, NULL); +static DEVICE_ATTR(psu_status, S_IRUGO, e582_48x2q4z_psu_read_status, NULL); + +static int e582_48x2q4z_init_psu(void) +{ + int ret = 0; + + psu_class = class_create(THIS_MODULE, "psu"); + if (IS_INVALID_PTR(psu_class)) + { + psu_class = NULL; + printk(KERN_CRIT "create e582_48x2q4z class psu failed\n"); + return -1; + } + + psu_dev_psu1 = device_create(psu_class, NULL, MKDEV(222,0), NULL, "psu1"); + if (IS_INVALID_PTR(psu_dev_psu1)) + { + psu_dev_psu1 = NULL; + printk(KERN_CRIT "create e582_48x2q4z psu1 device failed\n"); + return -1; + } + + psu_dev_psu2 = device_create(psu_class, NULL, MKDEV(222,1), NULL, "psu2"); + if (IS_INVALID_PTR(psu_dev_psu2)) + { + psu_dev_psu2 = NULL; + printk(KERN_CRIT "create e582_48x2q4z psu2 device failed\n"); + return -1; + } + + ret = device_create_file(psu_dev_psu1, &dev_attr_psu_presence); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z psu1 device attr:presence failed\n"); + return -1; + } + + ret = device_create_file(psu_dev_psu1, &dev_attr_psu_status); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z psu1 device attr:status failed\n"); + return -1; + } + + ret = device_create_file(psu_dev_psu2, &dev_attr_psu_presence); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z psu2 device attr:presence failed\n"); + return -1; + } + + ret = device_create_file(psu_dev_psu2, &dev_attr_psu_status); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z psu2 device attr:status failed\n"); + return -1; } + + return 0; } -MODULE_LICENSE("Dual BSD/GPL"); -MODULE_AUTHOR("xuwj centecNetworks, Inc"); -MODULE_DESCRIPTION("e582-48x6q board driver"); -module_init(e582_48x6q_init); -module_exit(e582_48x6q_exit); +static int e582_48x2q4z_exit_psu(void) +{ + if (IS_VALID_PTR(psu_dev_psu1)) + { + device_remove_file(psu_dev_psu1, &dev_attr_psu_presence); + device_remove_file(psu_dev_psu1, &dev_attr_psu_status); + device_destroy(psu_class, MKDEV(222,0)); + } + + if (IS_VALID_PTR(psu_dev_psu2)) + { + device_remove_file(psu_dev_psu2, &dev_attr_psu_presence); + device_remove_file(psu_dev_psu2, &dev_attr_psu_status); + device_destroy(psu_class, MKDEV(222,1)); + } + + if (IS_VALID_PTR(psu_class)) + { + class_destroy(psu_class); + psu_class = NULL; + } + + return 0; +} +#endif + +#if SEP("drivers:leds") +extern void e582_48x2q4z_led_set(struct led_classdev *led_cdev, enum led_brightness set_value); +extern enum led_brightness e582_48x2q4z_led_get(struct led_classdev *led_cdev); +extern void e582_48x2q4z_led_port_set(struct led_classdev *led_cdev, enum led_brightness set_value); +extern enum led_brightness e582_48x2q4z_led_port_get(struct led_classdev *led_cdev); + +static struct led_classdev led_dev_system = { + .name = "system", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_idn = { + .name = "idn", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_fan1 = { + .name = "fan1", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_fan2 = { + .name = "fan2", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_fan3 = { + .name = "fan3", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_fan4 = { + .name = "fan4", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_psu1 = { + .name = "psu1", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_psu2 = { + .name = "psu2", + .brightness_set = e582_48x2q4z_led_set, + .brightness_get = e582_48x2q4z_led_get, +}; +static struct led_classdev led_dev_port[PORT_NUM] = { +{ .name = "port1", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port2", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port3", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port4", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port5", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port6", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port7", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port8", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port9", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port10", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port11", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port12", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port13", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port14", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port15", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port16", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port17", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port18", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port19", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port20", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port21", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port22", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port23", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port24", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port25", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port26", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port27", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port28", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port29", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port30", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port31", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port32", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port33", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port34", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port35", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port36", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port37", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port38", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port39", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port40", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port41", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port42", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port43", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port44", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port45", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port46", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port47", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port48", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port49", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port50", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port51", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port52", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port53", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,}, +{ .name = "port54", .brightness_set = e582_48x2q4z_led_port_set, .brightness_get = e582_48x2q4z_led_port_get,} +}; +static unsigned char port_led_mode[PORT_NUM] = {0}; + +void e582_48x2q4z_led_set(struct led_classdev *led_cdev, enum led_brightness set_value) +{ + int ret = 0; + unsigned char reg = 0; + unsigned char mask = 0; + unsigned char shift = 0; + unsigned char led_value = 0; + struct i2c_client *i2c_led_client = i2c_client_epld; + + if (0 == strcmp(led_dev_system.name, led_cdev->name)) + { + reg = 0x2; + mask = 0x0F; + shift = 4; + } + else if (0 == strcmp(led_dev_idn.name, led_cdev->name)) + { + reg = 0x3; + mask = 0xFE; + shift = 0; + } + else if (0 == strcmp(led_dev_fan1.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan2.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan3.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan4.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_psu1.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_psu2.name, led_cdev->name)) + { + goto not_support; + } + else + { + goto not_support; + } + + ret = e582_48x2q4z_smbus_read_reg(i2c_led_client, reg, &led_value); + if (ret != 0) + { + printk(KERN_CRIT "Error: read %s led attr failed\n", led_cdev->name); + return; + } + + led_value = ((led_value & mask) | ((set_value << shift) & (~mask))); + + ret = e582_48x2q4z_smbus_write_reg(i2c_led_client, reg, led_value); + if (ret != 0) + { + printk(KERN_CRIT "Error: write %s led attr failed\n", led_cdev->name); + return; + } + + return; + +not_support: + + printk(KERN_INFO "Error: not support device:%s\n", led_cdev->name); + return; +} + +enum led_brightness e582_48x2q4z_led_get(struct led_classdev *led_cdev) +{ + int ret = 0; + unsigned char reg = 0; + unsigned char mask = 0; + unsigned char shift = 0; + unsigned char led_value = 0; + struct i2c_client *i2c_led_client = i2c_client_epld; + + if (0 == strcmp(led_dev_system.name, led_cdev->name)) + { + reg = 0x2; + mask = 0xF0; + shift = 4; + } + else if (0 == strcmp(led_dev_idn.name, led_cdev->name)) + { + reg = 0x3; + mask = 0x01; + shift = 0; + } + else if (0 == strcmp(led_dev_fan1.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan2.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan3.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_fan4.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_psu1.name, led_cdev->name)) + { + goto not_support; + } + else if (0 == strcmp(led_dev_psu2.name, led_cdev->name)) + { + goto not_support; + } + else + { + goto not_support; + } + + ret = e582_48x2q4z_smbus_read_reg(i2c_led_client, reg, &led_value); + if (ret != 0) + { + printk(KERN_CRIT "Error: read %s led attr failed\n", led_cdev->name); + return 0; + } + + led_value = ((led_value & mask) >> shift); + + return led_value; + +not_support: + + printk(KERN_INFO "Error: not support device:%s\n", led_cdev->name); + return 0; +} + +void e582_48x2q4z_led_port_set(struct led_classdev *led_cdev, enum led_brightness set_value) +{ + int portNum = 0; + + sscanf(led_cdev->name, "port%d", &portNum); + + port_led_mode[portNum-1] = set_value; + + return; +} + +enum led_brightness e582_48x2q4z_led_port_get(struct led_classdev *led_cdev) +{ + int portNum = 0; + + sscanf(led_cdev->name, "port%d", &portNum); + + return port_led_mode[portNum-1]; +} + +static int e582_48x2q4z_init_led(void) +{ + int ret = 0; + int i = 0; + + ret = led_classdev_register(NULL, &led_dev_system); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_system device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_idn); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_idn device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_fan1); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_fan1 device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_fan2); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_fan2 device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_fan3); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_fan3 device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_fan4); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_fan4 device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_psu1); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_psu1 device failed\n"); + return -1; + } + + ret = led_classdev_register(NULL, &led_dev_psu2); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z led_dev_psu2 device failed\n"); + return -1; + } + + for (i=0; i PORT_NUM)) + { + printk(KERN_CRIT "sfp read presence, invalid port number!\n"); + value = 0; + } + + if ((portNum >= 1) && (portNum <= 8)) + { + reg_no = portNum + 31;/*32-39*/ + i2c_sfp_client = i2c_client_gpio0; + } + else if ((portNum >= 9) && (portNum <= 16)) + { + reg_no = portNum - 9;/*0-7*/ + i2c_sfp_client = i2c_client_gpio1; + } + else if ((portNum >= 17) && (portNum <= 24)) + { + reg_no = portNum - 17;/*0-7*/ + i2c_sfp_client = i2c_client_gpio2; + } + else if ((portNum >= 25) && (portNum <= 32)) + { + reg_no = portNum - 17;/*8-15*/ + i2c_sfp_client = i2c_client_gpio2; + } + else if ((portNum >= 33) && (portNum <= 40)) + { + reg_no = portNum - 1;/*32-39*/ + i2c_sfp_client = i2c_client_gpio3; + } + else if ((portNum >= 41) && (portNum <= 48)) + { + reg_no = portNum - 41;/*0-7*/ + i2c_sfp_client = i2c_client_gpio4; + } + else if ((portNum >= 49) && (portNum <= 54)) + { + reg_no = portNum - 33;/*16-21*/ + i2c_sfp_client = i2c_client_gpio4; + } + + dir_bank = (reg_no/8) + 0x18; + ret = e582_48x2q4z_smbus_write_reg(i2c_sfp_client, dir_bank, 0xff); + if (ret != 0) + { + return sprintf(buf, "Error: read sfp data:%s set dir-ctl failed\n", attr->attr.name); + } + + input_bank = (reg_no/8) + 0x0; + ret = e582_48x2q4z_smbus_read_reg(i2c_sfp_client, input_bank, &value); + if (ret != 0) + { + return sprintf(buf, "Error: read sfp data:%s failed\n", attr->attr.name); + } + + value = ((value & (1<<(reg_no%8))) ? 0 : 1 );/*1:PRESENT 0:ABSENT*/ + + return sprintf(buf, "%d\n", value); +} + +static ssize_t e582_48x2q4z_sfp_read_enable(struct device *dev, struct device_attribute *attr, char *buf) +{ + int ret = 0; + unsigned char value = 0; + unsigned char reg_no = 0; + unsigned char dir_bank = 0; + unsigned char input_bank = 0; + int portNum = 0; + const char *name = dev_name(dev); + struct i2c_client *i2c_sfp_client = NULL; + + sscanf(name, "sfp%d", &portNum); + + if ((portNum < 1) || (portNum > PORT_NUM)) + { + printk(KERN_CRIT "sfp read presence, invalid port number!\n"); + value = 0; + } + + if ((portNum >= 1) && (portNum <= 8)) + { + reg_no = portNum - 1;/*0-7*/ + i2c_sfp_client = i2c_client_gpio0; + } + else if ((portNum >= 9) && (portNum <= 16)) + { + reg_no = portNum - 1;/*8-15*/ + i2c_sfp_client = i2c_client_gpio0; + } + else if ((portNum >= 17) && (portNum <= 24)) + { + reg_no = portNum - 9;/*8-15*/ + i2c_sfp_client = i2c_client_gpio1; + } + else if ((portNum >= 25) && (portNum <= 32)) + { + reg_no = portNum - 9;/*16-23*/ + i2c_sfp_client = i2c_client_gpio1; + } + else if ((portNum >= 33) && (portNum <= 40)) + { + reg_no = portNum - 33;/*0-7*/ + i2c_sfp_client = i2c_client_gpio3; + } + else if ((portNum >= 41) && (portNum <= 48)) + { + reg_no = portNum - 33;/*8-15*/ + i2c_sfp_client = i2c_client_gpio3; + } + else if ((portNum >= 49) && (portNum <= 54)) + { + printk(KERN_INFO "%s not supported!\n", name); + return sprintf(buf, "%d\n", 0); + } + + dir_bank = (reg_no/8) + 0x18; + ret = e582_48x2q4z_smbus_write_reg(i2c_sfp_client, dir_bank, 0xff); + if (ret != 0) + { + return sprintf(buf, "Error: read sfp data:%s set dir-ctl failed\n", attr->attr.name); + } + + input_bank = (reg_no/8) + 0x8; + ret = e582_48x2q4z_smbus_read_reg(i2c_sfp_client, input_bank, &value); + if (ret != 0) + { + return sprintf(buf, "Error: read sfp data:%s failed\n", attr->attr.name); + } + + value = ((value & (1<<(reg_no%8))) ? 0 : 1 ); + + return sprintf(buf, "%d\n", value); +} + +static ssize_t e582_48x2q4z_sfp_write_enable(struct device *dev, struct device_attribute *attr, const char *buf, size_t size) +{ + int ret = 0; + unsigned char value = 0; + unsigned char set_value = simple_strtol(buf, NULL, 10); + unsigned char reg_no = 0; + unsigned char dir_bank = 0; + unsigned char input_bank = 0; + unsigned char output_bank = 0; + int portNum = 0; + const char *name = dev_name(dev); + struct i2c_client *i2c_sfp_client = NULL; + + sscanf(name, "sfp%d", &portNum); + + if ((portNum < 1) || (portNum > PORT_NUM)) + { + printk(KERN_CRIT "sfp read presence, invalid port number!\n"); + return size; + } + + if ((portNum >= 1) && (portNum <= 8)) + { + reg_no = portNum - 1;/*0-7*/ + i2c_sfp_client = i2c_client_gpio0; + } + else if ((portNum >= 9) && (portNum <= 16)) + { + reg_no = portNum - 1;/*8-15*/ + i2c_sfp_client = i2c_client_gpio0; + } + else if ((portNum >= 17) && (portNum <= 24)) + { + reg_no = portNum - 9;/*8-15*/ + i2c_sfp_client = i2c_client_gpio1; + } + else if ((portNum >= 25) && (portNum <= 32)) + { + reg_no = portNum - 9;/*16-23*/ + i2c_sfp_client = i2c_client_gpio1; + } + else if ((portNum >= 33) && (portNum <= 40)) + { + reg_no = portNum - 33;/*0-7*/ + i2c_sfp_client = i2c_client_gpio3; + } + else if ((portNum >= 41) && (portNum <= 48)) + { + reg_no = portNum - 17;/*8-13*/ + i2c_sfp_client = i2c_client_gpio3; + } + else if ((portNum >= 49) && (portNum <= 54)) + { + printk(KERN_INFO "%s not supported!\n", name); + return size; + } + + set_value = ((set_value > 0) ? 0 : 1 ); + + dir_bank = (reg_no/8) + 0x18; + ret = e582_48x2q4z_smbus_write_reg(i2c_sfp_client, dir_bank, 0x0); + if (ret != 0) + { + printk(KERN_CRIT "Error: read sfp data:%s set dir-ctl failed\n", attr->attr.name); + return size; + } + + input_bank = (reg_no/8) + 0x8; + ret = e582_48x2q4z_smbus_read_reg(i2c_sfp_client, input_bank, &value); + if (ret != 0) + { + printk(KERN_CRIT "Error: read %s presence failed\n", name); + return size; + } + + if (set_value) + { + value = (value | (1<<(reg_no % 8))); + } + else + { + value = (value & (~(1<<(reg_no % 8)))); + } + + output_bank = (reg_no/8) + 0x8; + ret = e582_48x2q4z_smbus_write_reg(i2c_sfp_client, output_bank, value); + if (ret != 0) + { + printk(KERN_CRIT "Error: write %s presence failed\n", name); + return size; + } + + return size; +} + +static DEVICE_ATTR(sfp_presence, S_IRUGO, e582_48x2q4z_sfp_read_presence, NULL); +static DEVICE_ATTR(sfp_enable, S_IRUGO|S_IWUSR, e582_48x2q4z_sfp_read_enable, e582_48x2q4z_sfp_write_enable); +static int e582_48x2q4z_init_sfp(void) +{ + int ret = 0; + int i = 0; + + sfp_class = class_create(THIS_MODULE, "sfp"); + if (IS_INVALID_PTR(sfp_class)) + { + sfp_class = NULL; + printk(KERN_CRIT "create e582_48x2q4z class sfp failed\n"); + return -1; + } + + for (i=1; i<=PORT_NUM; i++) + { + sfp_dev[i] = device_create(sfp_class, NULL, MKDEV(223,i), NULL, "sfp%d", i); + if (IS_INVALID_PTR(sfp_dev[i])) + { + sfp_dev[i] = NULL; + printk(KERN_CRIT "create e582_48x2q4z sfp[%d] device failed\n", i); + continue; + } + + ret = device_create_file(sfp_dev[i], &dev_attr_sfp_presence); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z sfp[%d] device attr:presence failed\n", i); + continue; + } + + ret = device_create_file(sfp_dev[i], &dev_attr_sfp_enable); + if (ret != 0) + { + printk(KERN_CRIT "create e582_48x2q4z sfp[%d] device attr:enable failed\n", i); + continue; + } + } + + return ret; +} + +static int e582_48x2q4z_exit_sfp(void) +{ + int i = 0; + + for (i=1; i<=PORT_NUM; i++) + { + if (IS_VALID_PTR(sfp_dev[i])) + { + device_remove_file(sfp_dev[i], &dev_attr_sfp_presence); + device_remove_file(sfp_dev[i], &dev_attr_sfp_enable); + device_destroy(sfp_class, MKDEV(223,i)); + sfp_dev[i] = NULL; + } + } + + if (IS_VALID_PTR(sfp_class)) + { + class_destroy(sfp_class); + sfp_class = NULL; + } + + return 0; +} +#endif + +static int e582_48x2q4z_init(void) +{ + int ret = 0; + int failed = 0; + + printk(KERN_ALERT "install e582_48x2q4z board dirver...\n"); + + ret = e582_48x2q4z_init_i2c_master(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_i2c_pca9548(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_i2c_adt7470(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_i2c_psu(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_i2c_epld(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_i2c_gpio(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_psu(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_led(); + if (ret != 0) + { + failed = 1; + } + + ret = e582_48x2q4z_init_sfp(); + if (ret != 0) + { + failed = 1; + } + + if (failed) + printk(KERN_INFO "install e582_48x2q4z board driver failed\n"); + else + printk(KERN_ALERT "install e582_48x2q4z board dirver...ok\n"); + + return 0; +} + +static void e582_48x2q4z_exit(void) +{ + printk(KERN_INFO "uninstall e582_48x2q4z board dirver...\n"); + + e582_48x2q4z_exit_sfp(); + e582_48x2q4z_exit_led(); + e582_48x2q4z_exit_psu(); + e582_48x2q4z_exit_i2c_gpio(); + e582_48x2q4z_exit_i2c_epld(); + e582_48x2q4z_exit_i2c_psu(); + e582_48x2q4z_exit_i2c_adt7470(); + e582_48x2q4z_exit_i2c_pca9548(); + e582_48x2q4z_exit_i2c_master(); +} + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_AUTHOR("yangbs centecNetworks, Inc"); +MODULE_DESCRIPTION("e582-48x2q4z board driver"); +module_init(e582_48x2q4z_init); +module_exit(e582_48x2q4z_exit); + + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.c b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.c index 4c9a3da64e6e..32a38f842cfa 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.c +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.c @@ -25,7 +25,7 @@ #endif #include "dal_kernel.h" #include "dal_mpool.h" - +#include MODULE_AUTHOR("Centec Networks Inc."); MODULE_DESCRIPTION("DAL kernel module"); MODULE_LICENSE("GPL"); @@ -47,7 +47,9 @@ MODULE_PARM_DESC(dma_pool_size, #define CTC_VENDOR_VID 0xc001 #define CTC_HUMBER_DEVICE_ID 0x6048 -#define CTC_GOLDENGATE_DEVICE_ID 0xcb10 +#define CTC_GOLDENGATE_DEVICE_ID 0xc010 +#define CTC_PCIE_VENDOR_ID 0xcb10 +#define CTC_DUET2_DEVICE_ID 0x7148 #define MEM_MAP_RESERVE SetPageReserved #define MEM_MAP_UNRESERVE ClearPageReserved @@ -82,7 +84,7 @@ typedef struct dal_kernel_dev_s uintptr logic_address; /* Physical address */ - uintptr phys_address; + unsigned long long phys_address; } dal_kern_dev_t; typedef struct _dma_segment @@ -126,8 +128,8 @@ static unsigned int* dma_virt_base[DAL_MAX_CHIP_NUM]; #ifndef DMA_MEM_MODE_PLATFORM static unsigned int* dma_virt_base_tmp[DAL_MAX_CHIP_NUM]; #endif -static uintptr dma_phy_base[DAL_MAX_CHIP_NUM]; -static unsigned int dma_mem_size = 0x800000; +static unsigned long long dma_phy_base[DAL_MAX_CHIP_NUM]; +static unsigned int dma_mem_size = 0xc00000; static unsigned int msi_irq_base[DAL_MAX_CHIP_NUM]; static unsigned int msi_irq_num[DAL_MAX_CHIP_NUM]; static unsigned int msi_used = 0; @@ -141,7 +143,9 @@ MODULE_PARM_DESC(dal_debug, "Set debug level (default 0)"); static struct pci_device_id dal_id_table[] = { {PCI_DEVICE(CTC_VENDOR_VID, CTC_GREATBELT_DEVICE_ID)}, - {PCI_DEVICE(0xcb10, 0xc010)}, + {PCI_DEVICE(CTC_PCIE_VENDOR_ID, CTC_GOLDENGATE_DEVICE_ID)}, + {PCI_DEVICE((CTC_PCIE_VENDOR_ID+1), (CTC_GOLDENGATE_DEVICE_ID+1))}, + {PCI_DEVICE(CTC_PCIE_VENDOR_ID, CTC_DUET2_DEVICE_ID)}, {0, }, }; @@ -186,7 +190,11 @@ static struct file_operations dal_intr_fops[CTC_MAX_INTR_NUM] = .poll = linux_dal_poll7, }, }; - +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)) +#include +#define virt_to_bus virt_to_phys +#define bus_to_virt phys_to_virt +#endif /***************************************************************************** * macros *****************************************************************************/ @@ -450,9 +458,12 @@ dal_interrupt_register(unsigned int irq, int prio, void (* isr)(void*), void* da { if (irq == dal_isr[intr_num_tmp].irq) { - dal_isr[intr_num_tmp].count++; - printk("Interrupt irq %d register count %d.\n", irq, dal_isr[intr_num_tmp].count); - return 0; + if (0 == msi_used) + { + dal_isr[intr_num_tmp].count++; + printk("Interrupt irq %d register count %d.\n", irq, dal_isr[intr_num_tmp].count); + } + return 0; } if ((0 == dal_isr[intr_num_tmp].irq) && (CTC_MAX_INTR_NUM == intr_num)) { @@ -608,6 +619,7 @@ int dal_set_msi_cap(unsigned long arg) { int ret = 0; + int index = 0; dal_msi_info_t msi_info; if (copy_from_user(&msi_info, (void*)arg, sizeof(dal_msi_info_t))) @@ -618,8 +630,21 @@ dal_set_msi_cap(unsigned long arg) printk("####dal_set_msi_cap lchip %d base %d num:%d\n", msi_info.lchip, msi_info.irq_base, msi_info.irq_num); if (msi_info.irq_num > 0) { - msi_used = 1; - ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + if (0 == msi_used) + { + msi_used = 1; + ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + } + else if ((1 == msi_used) && (msi_info.irq_num != msi_irq_num[msi_info.lchip])) + { + for (index = 0; index < msi_irq_num[msi_info.lchip]; index++) + { + dal_interrupt_unregister(msi_irq_base[msi_info.lchip]+index); + } + _dal_set_msi_disable(msi_info.lchip); + msi_used = 1; + ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + } } else { @@ -1054,6 +1079,10 @@ int dal_create_irq_mapping(unsigned long arg) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) + +#ifndef NO_IRQ +#define NO_IRQ (-1) +#endif dal_irq_mapping_t irq_map; if (copy_from_user(&irq_map, (void*)arg, sizeof(dal_irq_mapping_t))) @@ -1086,7 +1115,7 @@ dal_pci_read(unsigned long arg) return -EFAULT; } - _dal_pci_read((unsigned char)cmdpara_chip.chip_id, (unsigned int)cmdpara_chip.reg_addr, + _dal_pci_read((unsigned char)cmdpara_chip.lchip, (unsigned int)cmdpara_chip.reg_addr, (unsigned int*)(&(cmdpara_chip.value))); if (copy_to_user((dal_chip_parm_t*)arg, (void*)&cmdpara_chip, sizeof(dal_chip_parm_t))) @@ -1119,7 +1148,7 @@ dal_pci_write(unsigned long arg) return -EFAULT; } - _dal_pci_write((unsigned char)cmdpara_chip.chip_id, (unsigned int)cmdpara_chip.reg_addr, + _dal_pci_write((unsigned char)cmdpara_chip.lchip, (unsigned int)cmdpara_chip.reg_addr, (unsigned int)cmdpara_chip.value); return 0; @@ -1158,7 +1187,7 @@ dal_user_read_pci_conf(unsigned long arg) return -EFAULT; } - if (dal_pci_conf_read(dal_cfg.chip_id, dal_cfg.offset, &dal_cfg.value)) + if (dal_pci_conf_read(dal_cfg.lchip, dal_cfg.offset, &dal_cfg.value)) { printk("dal_pci_conf_read failed.\n"); return -EFAULT; @@ -1182,14 +1211,14 @@ dal_user_write_pci_conf(unsigned long arg) return -EFAULT; } - return dal_pci_conf_write(dal_cfg.chip_id, dal_cfg.offset, dal_cfg.value); + return dal_pci_conf_write(dal_cfg.lchip, dal_cfg.offset, dal_cfg.value); } static int linux_get_device(unsigned long arg) { dal_user_dev_t user_dev; - int chip_id = 0; + int lchip = 0; if (copy_from_user(&user_dev, (void*)arg, sizeof(user_dev))) { @@ -1197,20 +1226,16 @@ linux_get_device(unsigned long arg) } user_dev.chip_num = dal_chip_num; - chip_id = user_dev.chip_id; + lchip = user_dev.lchip; - if (chip_id < dal_chip_num) + if (lchip < dal_chip_num) { - user_dev.phy_base0 = (unsigned int)dal_dev[chip_id].phys_address; - #ifdef PHYS_ADDR_IS_64BIT - user_dev.phy_base1 = (unsigned int)(dal_dev[chip_id].phys_address >> 32); - #else - user_dev.phy_base1 = 0; - #endif + user_dev.phy_base0 = (unsigned int)dal_dev[lchip].phys_address; + user_dev.phy_base1 = (unsigned int)(dal_dev[lchip].phys_address >> 32); - user_dev.bus_no = dal_dev[chip_id].pci_dev->bus->number; - user_dev.dev_no = dal_dev[chip_id].pci_dev->device; - user_dev.fun_no = dal_dev[chip_id].pci_dev->devfn; + user_dev.bus_no = dal_dev[lchip].pci_dev->bus->number; + user_dev.dev_no = dal_dev[lchip].pci_dev->device; + user_dev.fun_no = dal_dev[lchip].pci_dev->devfn; } if (copy_to_user((dal_user_dev_t*)arg, (void*)&user_dev, sizeof(user_dev))) @@ -1248,11 +1273,7 @@ linux_get_dma_info(unsigned long arg) } dma_para.phy_base = (unsigned int)dma_phy_base[dma_para.lchip]; - #ifdef PHYS_ADDR_IS_64BIT dma_para.phy_base_hi = dma_phy_base[dma_para.lchip] >> 32; - #else - dma_para.phy_base_hi = 0; - #endif dma_para.size = dma_mem_size; if (copy_to_user((dma_info_t*)arg, (void*)&dma_para, sizeof(dma_info_t))) @@ -1340,10 +1361,10 @@ dal_cache_inval(unsigned long arg) #if 0 dma_sync_single_for_cpu(NULL, intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); -#endif - dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); + dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); +#endif return 0; } @@ -1363,10 +1384,10 @@ dal_cache_flush(unsigned long arg) #if 0 dma_sync_single_for_cpu(NULL, intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); -#endif - dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); + dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); +#endif return 0; } @@ -1378,31 +1399,30 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) int ret = 0; unsigned int temp = 0; unsigned int lchip = 0; - unsigned int chip_id = 0; printk(KERN_WARNING "********found dal device*****\n"); - for (chip_id = 0; chip_id < DAL_MAX_CHIP_NUM; chip_id ++) + for (lchip = 0; lchip < DAL_MAX_CHIP_NUM; lchip ++) { - if (NULL == dal_dev[chip_id].pci_dev) + if (NULL == dal_dev[lchip].pci_dev) { break; } } - if (chip_id >= DAL_MAX_CHIP_NUM) + if (lchip >= DAL_MAX_CHIP_NUM) { printk("Exceed max local chip num\n"); return -1; } - dev = &dal_dev[chip_id]; + dev = &dal_dev[lchip]; if (NULL == dev) { printk("Cannot obtain PCI resources\n"); } - lchip = chip_id; + lchip = lchip; dal_chip_num += 1; dev->pci_dev = pdev; @@ -1446,7 +1466,6 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) if (dma_mem_size) { dal_alloc_dma_pool(lchip, dma_mem_size); - #ifdef PHYS_ADDR_IS_64BIT /*add check Dma memory pool cannot cross 4G space*/ if ((0==(dma_phy_base[lchip]>>32)) && (0!=((dma_phy_base[lchip]+dma_mem_size)>>32))) @@ -1454,7 +1473,6 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) printk("Dma malloc memory cross 4G space!!!!!! \n"); return -1; } - #endif } printk(KERN_WARNING "linux_dal_probe end*****\n"); @@ -1465,12 +1483,12 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) void linux_dal_remove(struct pci_dev* pdev) { - unsigned int chip_id = 0; + unsigned int lchip = 0; unsigned int flag = 0; - for (chip_id = 0; chip_id < DAL_MAX_CHIP_NUM; chip_id ++) + for (lchip = 0; lchip < DAL_MAX_CHIP_NUM; lchip ++) { - if (pdev == dal_dev[chip_id].pci_dev) + if (pdev == dal_dev[lchip].pci_dev) { flag = 1; break; @@ -1479,11 +1497,11 @@ linux_dal_remove(struct pci_dev* pdev) if (1 == flag) { - dal_free_dma_pool(chip_id); + dal_free_dma_pool(lchip); pci_release_regions(pdev); pci_disable_device(pdev); - dal_dev[chip_id].pci_dev = NULL; + dal_dev[lchip].pci_dev = NULL; dal_chip_num--; } @@ -1496,7 +1514,7 @@ linux_dal_ioctl(struct file* file, unsigned int cmd, unsigned long arg) #else -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 13)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) static int linux_dal_ioctl(struct file* file, unsigned int cmd, unsigned long arg) @@ -1812,3 +1830,4 @@ linux_dal_exit(void) module_init(linux_dal_init); module_exit(linux_dal_exit); + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.h b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.h index de39af67773b..850a4cffa731 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.h +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_kernel.h @@ -54,7 +54,7 @@ typedef unsigned int uintptr; #define DAL_ONE_MB (1024*1024) struct dal_chip_parm_s { - unsigned int chip_id; /*tmp should be uint8*/ + unsigned int lchip; /*tmp should be uint8*/ unsigned int fpga_id; /*tmp add*/ unsigned int reg_addr; unsigned int value; @@ -78,7 +78,7 @@ typedef struct dal_irq_mapping_s dal_irq_mapping_t; struct dal_user_dev_s { unsigned int chip_num; /*output: local chip number*/ - unsigned int chip_id; /*input: local chip id*/ + unsigned int lchip; /*input: local chip id*/ unsigned int phy_base0; /* low 32bits physical base address */ unsigned int phy_base1; /* high 32bits physical base address */ unsigned int bus_no; @@ -100,7 +100,7 @@ typedef struct dma_info_s dma_info_t; struct dal_pci_cfg_ioctl_s { - unsigned int chip_id; /* Device ID */ + unsigned int lchip; /* Device ID */ unsigned int offset; unsigned int value; }; @@ -168,3 +168,4 @@ typedef enum dal_version_e dal_version_t; #endif + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.c b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.c index 82d3b7a917a8..5aca222a138f 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.c +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.c @@ -1,4 +1,3 @@ - #include "dal_mpool.h" #ifdef __KERNEL__ @@ -27,6 +26,8 @@ static sal_mutex_t* dal_mpool_lock; #endif /* __KERNEL__ */ + + dal_mpool_mem_t* g_free_block_ptr = NULL; /* System cache line size */ @@ -34,8 +35,9 @@ dal_mpool_mem_t* g_free_block_ptr = NULL; #define DAL_CACHE_LINE_BYTES 256 #endif -static dal_mpool_mem_t* p_desc_pool = NULL; -static dal_mpool_mem_t* p_data_pool = NULL; +#define DAL_MAX_CHIP_NUM 32 +static dal_mpool_mem_t* p_desc_pool[DAL_MAX_CHIP_NUM] = {0}; +static dal_mpool_mem_t* p_data_pool[DAL_MAX_CHIP_NUM] = {0}; int dal_mpool_init(void) @@ -74,7 +76,7 @@ _dal_mpool_create(void* base, int size, int type) } dal_mpool_mem_t* -dal_mpool_create(void* base, int size) +dal_mpool_create(unsigned char lchip, void* base, int size) { dal_mpool_mem_t* head = NULL; int mod = (int)(((unsigned long)base) & (DAL_CACHE_LINE_BYTES - 1)); @@ -98,8 +100,8 @@ dal_mpool_create(void* base, int size) } /* init for desc linkptr */ - p_desc_pool = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC); - if (NULL == p_desc_pool) + p_desc_pool[lchip] = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC); + if (NULL == p_desc_pool[lchip]) { MPOOL_UNLOCK(); DAL_FREE(head->next); @@ -108,14 +110,14 @@ dal_mpool_create(void* base, int size) } /* init for data linkptr */ - p_data_pool = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA); - if (NULL == p_data_pool) + p_data_pool[lchip] = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA); + if (NULL == p_data_pool[lchip]) { MPOOL_UNLOCK(); DAL_FREE(head->next); DAL_FREE(head); - DAL_FREE(p_desc_pool->next); - DAL_FREE(p_desc_pool); + DAL_FREE(p_desc_pool[lchip]->next); + DAL_FREE(p_desc_pool[lchip]); return NULL; } @@ -160,7 +162,7 @@ _dal_mpool_alloc_comon(dal_mpool_mem_t* ptr, int size, int type) } void* -dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) +dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type) { dal_mpool_mem_t* ptr = NULL; dal_mpool_mem_t* new_ptr = NULL; @@ -186,7 +188,7 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } break; case DAL_MPOOL_TYPE_DESC: - ptr = p_desc_pool; + ptr = p_desc_pool[lchip]; new_ptr = _dal_mpool_alloc_comon(ptr, size, type); if (NULL == new_ptr) { @@ -195,7 +197,7 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } break; case DAL_MPOOL_TYPE_DATA: - ptr = p_data_pool; + ptr = p_data_pool[lchip]; new_ptr = _dal_mpool_alloc_comon(ptr, size, type); if (NULL == new_ptr) { @@ -210,6 +212,10 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } MPOOL_UNLOCK(); + if( NULL == new_ptr ) + { + return NULL; + } return new_ptr->address; } @@ -242,7 +248,7 @@ _dal_mpool_free(dal_mpool_mem_t* ptr, void* addr, int type) } void -dal_mpool_free(dal_mpool_mem_t* pool, void* addr) +dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr) { dal_mpool_mem_t* ptr = pool; @@ -255,11 +261,11 @@ dal_mpool_free(dal_mpool_mem_t* pool, void* addr) _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_USELESS); break; case DAL_MPOOL_TYPE_DESC: - ptr = p_desc_pool; + ptr = p_desc_pool[lchip]; _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DESC); break; case DAL_MPOOL_TYPE_DATA: - ptr = p_data_pool; + ptr = p_data_pool[lchip]; _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DATA); break; default: @@ -271,7 +277,7 @@ dal_mpool_free(dal_mpool_mem_t* pool, void* addr) } int -dal_mpool_destroy(dal_mpool_mem_t* pool) +dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool) { dal_mpool_mem_t* ptr, * next; @@ -283,13 +289,13 @@ dal_mpool_destroy(dal_mpool_mem_t* pool) DAL_FREE(ptr); } - for (ptr = p_desc_pool; ptr; ptr = next) + for (ptr = p_desc_pool[lchip]; ptr; ptr = next) { next = ptr->next; DAL_FREE(ptr); } - for (ptr = p_data_pool; ptr; ptr = next) + for (ptr = p_data_pool[lchip]; ptr; ptr = next) { next = ptr->next; DAL_FREE(ptr); @@ -341,3 +347,4 @@ dal_mpool_debug(dal_mpool_mem_t* pool) return 0; } + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.h b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.h index a1fa37d05f82..d93f88868136 100644 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.h +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/modules/dal_mpool.h @@ -47,16 +47,16 @@ extern int dal_mpool_init(void); extern dal_mpool_mem_t* -dal_mpool_create(void* base_ptr, int size); +dal_mpool_create(unsigned char lchip, void* base_ptr, int size); extern void* -dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type); +dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type); extern void -dal_mpool_free(dal_mpool_mem_t* pool, void* addr); +dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr); extern int -dal_mpool_destroy(dal_mpool_mem_t* pool); +dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool); extern int dal_mpool_usage(dal_mpool_mem_t* pool, int type); @@ -69,3 +69,4 @@ dal_mpool_debug(dal_mpool_mem_t* pool); #endif /* !_DMA_MPOOL_H */ + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform.sh b/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform.sh index 2caae94f03e7..2f6583bc487b 100755 --- a/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform.sh +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform.sh @@ -19,16 +19,58 @@ init_devnum() { init_devnum if [ "$1" == "init" ]; then + #install drivers and dependencies depmod -a + modprobe i2c-i801 modprobe i2c-dev + modprobe i2c-mux + modprobe i2c-smbus modprobe i2c-mux-pca954x force_deselect_on_exit=1 - modprobe centec_e582_48x2q4z_platform + i2cset -y 0 0x58 0x8 0x3f + modprobe lm77 + modprobe tun modprobe dal modprobe centec_at24c64 + modprobe centec_e582_48x2q4z_platform + i2cset -y 15 0x21 0x18 0x0 + i2cset -y 15 0x21 0x19 0x0 + i2cset -y 15 0x21 0x1a 0xff + i2cset -y 15 0x21 0x1b 0xff + i2cset -y 15 0x21 0x1c 0xff + i2cset -y 15 0x21 0x8 0x0 + i2cset -y 15 0x21 0x9 0x0 + i2cset -y 15 0x22 0x18 0xff + i2cset -y 15 0x22 0x19 0x0 + i2cset -y 15 0x22 0x1a 0x0 + i2cset -y 15 0x22 0x1b 0xff + i2cset -y 15 0x22 0x1c 0xff + i2cset -y 15 0x22 0x9 0x0 + i2cset -y 15 0x22 0xa 0x0 + i2cset -y 16 0x21 0x18 0x0 + i2cset -y 16 0x21 0x19 0x0 + i2cset -y 16 0x21 0x1a 0xff + i2cset -y 16 0x21 0x1b 0xff + i2cset -y 16 0x21 0x1c 0xff + i2cset -y 16 0x21 0x8 0x0 + i2cset -y 16 0x21 0x9 0x0 + i2cset -y 17 0x22 0x18 0xff + i2cset -y 17 0x22 0x19 0x0 + i2cset -y 17 0x22 0x1a 0xff + i2cset -y 17 0x22 0x1b 0x0 + i2cset -y 17 0x22 0x1c 0xff + i2cset -y 17 0x22 0x9 0x0 + i2cset -y 17 0x22 0xb 0x0c + + #start platform monitor + rm -rf /usr/bin/platform_monitor + ln -s /usr/bin/48x2q4z_platform_monitor.py /usr/bin/platform_monitor + python /usr/bin/platform_monitor & elif [ "$1" == "deinit" ]; then + kill -9 $(pidof platform_monitor) > /dev/null 2>&1 + rm -rf /usr/bin/platform_monitor + modprobe -r centec_e582_48x2q4z_platform modprobe -r centec_at24c64 modprobe -r dal - modprobe -r centec_e582_48x2q4z_platform modprobe -r i2c-mux-pca954x modprobe -r i2c-dev else diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform_monitor.py b/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform_monitor.py new file mode 100644 index 000000000000..2d8d2c440a8f --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/scripts/48x2q4z_platform_monitor.py @@ -0,0 +1,217 @@ +#!/usr/bin/env python + +############################################################################# +# Centec +# +# Module contains an implementation of sfp presence scan logic +# +############################################################################# + +try: + import os + import os.path + import threading + import time + import logging + import struct + import syslog + import swsssdk + from socket import * + from select import * +except ImportError, e: + raise ImportError(str(e) + " - required module not found") + + +def DBG_PRINT(str): + syslog.openlog("centec-pmon") + syslog.syslog(syslog.LOG_INFO, str) + syslog.closelog() + +PORT_NUMBER = (48+6) + +class PlatformMonitor: + + """init board platform default config""" + def __init__(self): + """[ctlid, slavedevid]""" + self.fiber_mapping = [(0, 0)] # res + self.fiber_mapping.extend([(1, 7), (1, 6), (1, 5), (1, 4), (1, 3), (1, 2), (1, 1), (1, 0)]) # panel port 1~8 + self.fiber_mapping.extend([(1, 15), (1, 14), (1, 13), (1, 12), (1, 11), (1, 10), (1, 9), (1, 8)]) # panel port 9~16 + self.fiber_mapping.extend([(1, 19), (1, 17), (1, 16), (1, 18), (0, 7), (0, 6), (0, 5), (0, 4)]) # panel port 17~24 + self.fiber_mapping.extend([(0, 3), (0, 2), (0, 1), (0, 0), (0, 15), (0, 14), (0, 13), (0, 12)]) # panel port 25~32 + self.fiber_mapping.extend([(0, 11), (0, 10), (0, 9), (0, 8), (0, 23), (0, 22), (0, 21), (0, 20)]) # panel port 33~40 + self.fiber_mapping.extend([(0, 19), (0, 18), (0, 17), (0, 16), (0, 31), (0, 26), (0, 29), (0, 27)]) # panel port 41~48 + self.fiber_mapping.extend([(0, 24), (0, 25), (1, 23), (1, 22), (1, 21), (1, 20)]) # panel port 49~54 + + self.udpClient = socket(AF_INET, SOCK_DGRAM) + self.sfp_present = [0]*(PORT_NUMBER+1) + self.sfp_enable = [0]*(PORT_NUMBER+1) + self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" + self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" + self.sfp_scan_timer = 0 + + def is_qsfp(self, port): + if port <= 48: + return False + else: + return True + + def get_sfp_present(self, port): + with open(self.f_sfp_present.format(port), 'r') as sfp_file: + return int(sfp_file.read()) + + def set_sfp_present(self, port, present): + self.sfp_present[port] = present + + def set_sfp_enable(self, port, enable): + if self.is_qsfp(port): + if enable: + with open(self.f_sfp_enable.format(port), 'w') as sfp_file: + sfp_file.write("1") + self.sfp_enable[port] = 1 + else: + with open(self.f_sfp_enable.format(port), 'w') as sfp_file: + sfp_file.write("0") + self.sfp_enable[port] = 0 + else: + (ctlid, devid) = self.fiber_mapping[port] + req = struct.pack('=HHHBBHIBBBBI', 0, 9, 16, ctlid, devid, 0x50, 0, 0x56, 1, 0xf, 0, 1) + self.udpClient.sendto(req, ('localhost', 8101)) + rsp, addr = self.udpClient.recvfrom(1024) + rsp_data = struct.unpack('=HHHBBHIBBBBIi512B', rsp) + enable_v = rsp_data[13] + if enable: + enable_v &= 0xf0 + else: + enable_v |= 0x0f + data = struct.pack('=HHHBBHBBBB', 0, 11, 8, ctlid, 0x56, 0x50, devid, enable_v, 0xf, 0) + self.udpClient.sendto(data, ('localhost', 8101)) + DBG_PRINT("set sfp{} to {}".format(port, ("enable" if enable else "disable"))) + + def initialize_configdb(self): + try: + f_mac = os.popen('ip link show eth0 | grep ether | awk \'{print $2}\'') + mac_addr = f_mac.read(17) + last_byte = mac_addr[-2:] + aligned_last_byte = format(int(int(str(last_byte), 16) + 1), '02x') + mac_addr = mac_addr[:-2] + aligned_last_byte + DBG_PRINT("start connect swss config-db to set device mac-address") + swss = swsssdk.SonicV2Connector() + swss.connect(swss.CONFIG_DB) + swss.set(swss.CONFIG_DB, "DEVICE_METADATA|localhost", 'mac', mac_addr) + mac_addr = swss.get(swss.CONFIG_DB, "DEVICE_METADATA|localhost", 'mac') + DBG_PRINT("set device mac-address: %s" % mac_addr) + except IOError as e: + DBG_PRINT(str(e)) + + def initialize_rpc(self): + while True: + try: + r_sel = [self.udpClient] + echo_req = struct.pack('=HHH', 0, 1, 0) + self.udpClient.sendto(echo_req, ('localhost', 8101)) + result = select(r_sel, [], [], 1) + if self.udpClient in result[0]: + echo_rsp, srv_addr = self.udpClient.recvfrom(1024) + if echo_rsp: + break + DBG_PRINT("connect to sdk rpc server timeout, try again.") + except IOError as e: + DBG_PRINT(str(e)) + + DBG_PRINT("connect to sdk rpc server success.") + + def initialize_gpio(self): + # set gpio 1,2,3,4,5,6,7,8 output mode + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 1, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 2, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 3, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 4, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 5, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 6, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 7, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 1, 8, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + # set gpio 1,2,3,4,5,6,7,8 output 0 to reset i2c bridge + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 1, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 2, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 3, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 4, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 5, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 6, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 7, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 8, 0) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + # set gpio 1,2,3,4,5,6,7,8 output 1 to release i2c bridge + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 1, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 2, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 3, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 4, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 5, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 6, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 7, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + gpio_init = struct.pack('=HHHBBB', 0, 13, 3, 2, 8, 1) + self.udpClient.sendto(gpio_init, ('localhost', 8101)) + DBG_PRINT("config ctc chip gpio done.") + + def initialize_sfp(self): + try: + for port in range(1, PORT_NUMBER+1): + if self.get_sfp_present(port): + self.set_sfp_present(port, 1) + self.set_sfp_enable(port, 1) + else: + self.set_sfp_present(port, 0) + self.set_sfp_enable(port, 0) + except IOError as e: + DBG_PRINT(str(e)) + + def initialize(self): + DBG_PRINT("start connect to sdk rpc server.") + + self.initialize_configdb() + self.initialize_rpc() + self.initialize_gpio() + self.initialize_sfp() + + def sfp_scan(self): + try: + for port in range(1, PORT_NUMBER+1): + cur_present = self.get_sfp_present(port) + if self.sfp_present[port] != cur_present: + self.set_sfp_present(port, cur_present) + self.set_sfp_enable(port, cur_present) + except IOError as e: + DBG_PRINT(str(e)) + + def start(self): + while True: + self.sfp_scan() + time.sleep(1) + +if __name__ == "__main__": + monitor = PlatformMonitor() + monitor.initialize() + monitor.start() + diff --git a/platform/centec/sonic-platform-modules-e582/48x2q4z/service/48x2q4z_platform.service b/platform/centec/sonic-platform-modules-e582/48x2q4z/service/48x2q4z_platform.service new file mode 100644 index 000000000000..008db145b110 --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/48x2q4z/service/48x2q4z_platform.service @@ -0,0 +1,13 @@ +[Unit] +Description=Centec e582 48x2q4z platform modules +After=local-fs.target +Before=pmon.service + +[Service] +Type=oneshot +ExecStart=-/etc/init.d/platform-modules-e582-48x2q4z start +ExecStop=-/etc/init.d/platform-modules-e582-48x2q4z stop +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db.json b/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db.json index c75eb1284f66..995ac0444b99 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db.json +++ b/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db.json @@ -13,274 +13,274 @@ "VLAN": {}, "PORT": { "Ethernet1": { - "alias": "Ethernet1", - "lanes": "4", - "speed": "1000" + "alias": "eth-0-1", + "speed": "1000", + "mtu": "9100" }, "Ethernet2": { - "alias": "Ethernet2", - "lanes": "5", - "speed": "1000" - }, - "Ethernet3": { - "alias": "Ethernet3", - "lanes": "6", - "speed": "1000" - }, - "Ethernet4": { - "alias": "Ethernet4", - "lanes": "8", - "speed": "1000" - }, - "Ethernet5": { - "alias": "Ethernet5", - "lanes": "9", - "speed": "1000" - }, - "Ethernet6": { - "alias": "Ethernet6", - "lanes": "10", - "speed": "1000" - }, - "Ethernet7": { - "alias": "Ethernet7", - "lanes": "12", - "speed": "1000" - }, - "Ethernet8": { - "alias": "Ethernet8", - "lanes": "13", - "speed": "1000" - }, - "Ethernet9": { - "alias": "Ethernet9", - "lanes": "14", - "speed": "1000" - }, - "Ethernet10": { - "alias": "Ethernet10", - "lanes": "16", - "speed": "1000" - }, - "Ethernet11": { - "alias": "Ethernet11", - "lanes": "17", - "speed": "1000" - }, - "Ethernet12": { - "alias": "Ethernet12", - "lanes": "18", - "speed": "1000" - }, - "Ethernet13": { - "alias": "Ethernet13", - "lanes": "20", - "speed": "10000" - }, - "Ethernet14": { - "alias": "Ethernet14", - "lanes": "21", - "speed": "10000" - }, - "Ethernet15": { - "alias": "Ethernet15", - "lanes": "22", - "speed": "10000" - }, - "Ethernet16": { - "alias": "Ethernet16", - "lanes": "24", - "speed": "10000" - }, - "Ethernet17": { - "alias": "Ethernet17", - "lanes": "25", - "speed": "10000" - }, - "Ethernet18": { - "alias": "Ethernet18", - "lanes": "26", - "speed": "10000" - }, - "Ethernet19": { - "alias": "Ethernet19", - "lanes": "28", - "speed": "10000" - }, - "Ethernet20": { - "alias": "Ethernet20", - "lanes": "30", - "speed": "10000" - }, - "Ethernet21": { - "alias": "Ethernet21", - "lanes": "31", - "speed": "10000" - }, - "Ethernet22": { - "alias": "Ethernet22", - "lanes": "32", - "speed": "10000" - }, - "Ethernet23": { - "alias": "Ethernet23", - "lanes": "34", - "speed": "10000" - }, - "Ethernet24": { - "alias": "Ethernet24", - "lanes": "35", - "speed": "10000" - }, - "Ethernet25": { - "alias": "Ethernet25", - "lanes": "40", - "speed": "10000" - }, - "Ethernet26": { - "alias": "Ethernet26", - "lanes": "41", - "speed": "10000" - }, - "Ethernet27": { - "alias": "Ethernet27", - "lanes": "43", - "speed": "10000" - }, - "Ethernet28": { - "alias": "Ethernet28", - "lanes": "36", - "speed": "10000" - }, - "Ethernet29": { - "alias": "Ethernet29", - "lanes": "37", - "speed": "10000" - }, - "Ethernet30": { - "alias": "Ethernet30", - "lanes": "39", - "speed": "10000" - }, - "Ethernet31": { - "alias": "Ethernet31", - "lanes": "44", - "speed": "10000" - }, - "Ethernet32": { - "alias": "Ethernet32", - "lanes": "45", - "speed": "10000" - }, - "Ethernet33": { - "alias": "Ethernet33", - "lanes": "46", - "speed": "10000" - }, - "Ethernet34": { - "alias": "Ethernet34", - "lanes": "47", - "speed": "10000" - }, - "Ethernet35": { - "alias": "Ethernet35", - "lanes": "80", - "speed": "10000" - }, - "Ethernet36": { - "alias": "Ethernet36", - "lanes": "81", - "speed": "10000" - }, - "Ethernet37": { - "alias": "Ethernet37", - "lanes": "82", - "speed": "10000" - }, - "Ethernet38": { - "alias": "Ethernet38", - "lanes": "88", - "speed": "10000" - }, - "Ethernet39": { - "alias": "Ethernet39", - "lanes": "89", - "speed": "10000" - }, - "Ethernet40": { - "alias": "Ethernet40", - "lanes": "90", - "speed": "10000" - }, - "Ethernet41": { - "alias": "Ethernet41", - "lanes": "84", - "speed": "10000" - }, - "Ethernet42": { - "alias": "Ethernet42", - "lanes": "85", - "speed": "10000" - }, - "Ethernet43": { - "alias": "Ethernet43", - "lanes": "86", - "speed": "10000" - }, - "Ethernet44": { - "alias": "Ethernet44", - "lanes": "87", - "speed": "10000" - }, - "Ethernet45": { - "alias": "Ethernet45", - "lanes": "92", - "speed": "10000" - }, - "Ethernet46": { - "alias": "Ethernet46", - "lanes": "93", - "speed": "10000" - }, - "Ethernet47": { - "alias": "Ethernet47", - "lanes": "94", - "speed": "10000" - }, - "Ethernet48": { - "alias": "Ethernet48", - "lanes": "95", - "speed": "10000" - }, - "Ethernet49": { - "alias": "Ethernet49", - "lanes": "52,53,54,55", - "speed": "40000" - }, - "Ethernet50": { - "alias": "Ethernet50", - "lanes": "56,57,58,59", - "speed": "40000" - }, - "Ethernet51": { - "alias": "Ethernet51", - "lanes": "60,61,62,63", - "speed": "40000" - }, - "Ethernet52": { - "alias": "Ethernet52", - "lanes": "68,69,70,71", - "speed": "40000" - }, - "Ethernet53": { - "alias": "Ethernet53", - "lanes": "72,73,74,75", - "speed": "40000" + "alias": "eth-0-2", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet3": { + "alias": "eth-0-3", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet4": { + "alias": "eth-0-4", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet5": { + "alias": "eth-0-5", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet6": { + "alias": "eth-0-6", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet7": { + "alias": "eth-0-7", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet8": { + "alias": "eth-0-8", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet9": { + "alias": "eth-0-9", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet10": { + "alias": "eth-0-10", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet11": { + "alias": "eth-0-11", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet12": { + "alias": "eth-0-12", + "speed": "1000", + "mtu": "9100" + }, + "Ethernet13": { + "alias": "eth-0-13", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet14": { + "alias": "eth-0-14", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet15": { + "alias": "eth-0-15", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet16": { + "alias": "eth-0-16", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet17": { + "alias": "eth-0-17", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet18": { + "alias": "eth-0-18", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet19": { + "alias": "eth-0-19", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet20": { + "alias": "eth-0-20", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet21": { + "alias": "eth-0-21", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet22": { + "alias": "eth-0-22", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet23": { + "alias": "eth-0-23", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet24": { + "alias": "eth-0-24", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet25": { + "alias": "eth-0-25", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet26": { + "alias": "eth-0-26", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet27": { + "alias": "eth-0-27", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet28": { + "alias": "eth-0-28", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet29": { + "alias": "eth-0-29", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet30": { + "alias": "eth-0-30", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet31": { + "alias": "eth-0-31", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet32": { + "alias": "eth-0-32", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet33": { + "alias": "eth-0-33", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet34": { + "alias": "eth-0-34", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet35": { + "alias": "eth-0-35", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet36": { + "alias": "eth-0-36", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet37": { + "alias": "eth-0-37", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet38": { + "alias": "eth-0-38", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet39": { + "alias": "eth-0-39", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet40": { + "alias": "eth-0-40", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet41": { + "alias": "eth-0-41", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet42": { + "alias": "eth-0-42", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet43": { + "alias": "eth-0-43", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet44": { + "alias": "eth-0-44", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet45": { + "alias": "eth-0-45", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet46": { + "alias": "eth-0-46", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet47": { + "alias": "eth-0-47", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet48": { + "alias": "eth-0-48", + "speed": "10000", + "mtu": "9100" + }, + "Ethernet49": { + "alias": "eth-0-49", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet50": { + "alias": "eth-0-50", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet51": { + "alias": "eth-0-51", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet52": { + "alias": "eth-0-52", + "speed": "40000", + "mtu": "9100" + }, + "Ethernet53": { + "alias": "eth-0-53", + "speed": "40000", + "mtu": "9100" }, "Ethernet54": { - "alias": "Ethernet54", - "lanes": "76,77,78,79", - "speed": "40000" + "alias": "eth-0-54", + "speed": "40000", + "mtu": "9100" } }, "SYSLOG_SERVER": {}, @@ -300,4 +300,3 @@ "Ethernet4|192.168.4.1/24": {} } } - diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db_l2l3.json b/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db_l2l3.json index e9d9a3bb5e4b..ce6909f3a200 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db_l2l3.json +++ b/platform/centec/sonic-platform-modules-e582/48x6q/cfg/config_db_l2l3.json @@ -112,274 +112,274 @@ }, "PORT": { "Ethernet1": { - "alias": "Ethernet1", - "lanes": "4", - "speed": "1000" + "alias": "eth-0-1", + "speed": "1000", + "mtu": "9100" }, "Ethernet2": { - "alias": "Ethernet2", - "lanes": "5", - "speed": "1000" + "alias": "eth-0-2", + "speed": "1000", + "mtu": "9100" }, "Ethernet3": { - "alias": "Ethernet3", - "lanes": "6", - "speed": "1000" + "alias": "eth-0-3", + "speed": "1000", + "mtu": "9100" }, "Ethernet4": { - "alias": "Ethernet4", - "lanes": "8", - "speed": "1000" + "alias": "eth-0-4", + "speed": "1000", + "mtu": "9100" }, "Ethernet5": { - "alias": "Ethernet5", - "lanes": "9", - "speed": "1000" + "alias": "eth-0-5", + "speed": "1000", + "mtu": "9100" }, "Ethernet6": { - "alias": "Ethernet6", - "lanes": "10", - "speed": "1000" + "alias": "eth-0-6", + "speed": "1000", + "mtu": "9100" }, "Ethernet7": { - "alias": "Ethernet7", - "lanes": "12", - "speed": "1000" + "alias": "eth-0-7", + "speed": "1000", + "mtu": "9100" }, "Ethernet8": { - "alias": "Ethernet8", - "lanes": "13", - "speed": "1000" + "alias": "eth-0-8", + "speed": "1000", + "mtu": "9100" }, "Ethernet9": { - "alias": "Ethernet9", - "lanes": "14", - "speed": "1000" + "alias": "eth-0-9", + "speed": "1000", + "mtu": "9100" }, "Ethernet10": { - "alias": "Ethernet10", - "lanes": "16", - "speed": "1000" + "alias": "eth-0-10", + "speed": "1000", + "mtu": "9100" }, "Ethernet11": { - "alias": "Ethernet11", - "lanes": "17", - "speed": "1000" + "alias": "eth-0-11", + "speed": "1000", + "mtu": "9100" }, "Ethernet12": { - "alias": "Ethernet12", - "lanes": "18", - "speed": "1000" + "alias": "eth-0-12", + "speed": "1000", + "mtu": "9100" }, "Ethernet13": { - "alias": "Ethernet13", - "lanes": "20", - "speed": "10000" + "alias": "eth-0-13", + "speed": "10000", + "mtu": "9100" }, "Ethernet14": { - "alias": "Ethernet14", - "lanes": "21", - "speed": "10000" + "alias": "eth-0-14", + "speed": "10000", + "mtu": "9100" }, "Ethernet15": { - "alias": "Ethernet15", - "lanes": "22", - "speed": "10000" + "alias": "eth-0-15", + "speed": "10000", + "mtu": "9100" }, "Ethernet16": { - "alias": "Ethernet16", - "lanes": "24", - "speed": "10000" + "alias": "eth-0-16", + "speed": "10000", + "mtu": "9100" }, "Ethernet17": { - "alias": "Ethernet17", - "lanes": "25", - "speed": "10000" + "alias": "eth-0-17", + "speed": "10000", + "mtu": "9100" }, "Ethernet18": { - "alias": "Ethernet18", - "lanes": "26", - "speed": "10000" + "alias": "eth-0-18", + "speed": "10000", + "mtu": "9100" }, "Ethernet19": { - "alias": "Ethernet19", - "lanes": "28", - "speed": "10000" + "alias": "eth-0-19", + "speed": "10000", + "mtu": "9100" }, "Ethernet20": { - "alias": "Ethernet20", - "lanes": "30", - "speed": "10000" + "alias": "eth-0-20", + "speed": "10000", + "mtu": "9100" }, "Ethernet21": { - "alias": "Ethernet21", - "lanes": "31", - "speed": "10000" + "alias": "eth-0-21", + "speed": "10000", + "mtu": "9100" }, "Ethernet22": { - "alias": "Ethernet22", - "lanes": "32", - "speed": "10000" + "alias": "eth-0-22", + "speed": "10000", + "mtu": "9100" }, "Ethernet23": { - "alias": "Ethernet23", - "lanes": "34", - "speed": "10000" + "alias": "eth-0-23", + "speed": "10000", + "mtu": "9100" }, "Ethernet24": { - "alias": "Ethernet24", - "lanes": "35", - "speed": "10000" + "alias": "eth-0-24", + "speed": "10000", + "mtu": "9100" }, "Ethernet25": { - "alias": "Ethernet25", - "lanes": "40", - "speed": "10000" + "alias": "eth-0-25", + "speed": "10000", + "mtu": "9100" }, "Ethernet26": { - "alias": "Ethernet26", - "lanes": "41", - "speed": "10000" + "alias": "eth-0-26", + "speed": "10000", + "mtu": "9100" }, "Ethernet27": { - "alias": "Ethernet27", - "lanes": "43", - "speed": "10000" + "alias": "eth-0-27", + "speed": "10000", + "mtu": "9100" }, "Ethernet28": { - "alias": "Ethernet28", - "lanes": "36", - "speed": "10000" + "alias": "eth-0-28", + "speed": "10000", + "mtu": "9100" }, "Ethernet29": { - "alias": "Ethernet29", - "lanes": "37", - "speed": "10000" + "alias": "eth-0-29", + "speed": "10000", + "mtu": "9100" }, "Ethernet30": { - "alias": "Ethernet30", - "lanes": "39", - "speed": "10000" + "alias": "eth-0-30", + "speed": "10000", + "mtu": "9100" }, "Ethernet31": { - "alias": "Ethernet31", - "lanes": "44", - "speed": "10000" + "alias": "eth-0-31", + "speed": "10000", + "mtu": "9100" }, "Ethernet32": { - "alias": "Ethernet32", - "lanes": "45", - "speed": "10000" + "alias": "eth-0-32", + "speed": "10000", + "mtu": "9100" }, "Ethernet33": { - "alias": "Ethernet33", - "lanes": "46", - "speed": "10000" + "alias": "eth-0-33", + "speed": "10000", + "mtu": "9100" }, "Ethernet34": { - "alias": "Ethernet34", - "lanes": "47", - "speed": "10000" + "alias": "eth-0-34", + "speed": "10000", + "mtu": "9100" }, "Ethernet35": { - "alias": "Ethernet35", - "lanes": "80", - "speed": "10000" + "alias": "eth-0-35", + "speed": "10000", + "mtu": "9100" }, "Ethernet36": { - "alias": "Ethernet36", - "lanes": "81", - "speed": "10000" + "alias": "eth-0-36", + "speed": "10000", + "mtu": "9100" }, "Ethernet37": { - "alias": "Ethernet37", - "lanes": "82", - "speed": "10000" + "alias": "eth-0-37", + "speed": "10000", + "mtu": "9100" }, "Ethernet38": { - "alias": "Ethernet38", - "lanes": "88", - "speed": "10000" + "alias": "eth-0-38", + "speed": "10000", + "mtu": "9100" }, "Ethernet39": { - "alias": "Ethernet39", - "lanes": "89", - "speed": "10000" + "alias": "eth-0-39", + "speed": "10000", + "mtu": "9100" }, "Ethernet40": { - "alias": "Ethernet40", - "lanes": "90", - "speed": "10000" + "alias": "eth-0-40", + "speed": "10000", + "mtu": "9100" }, "Ethernet41": { - "alias": "Ethernet41", - "lanes": "84", - "speed": "10000" + "alias": "eth-0-41", + "speed": "10000", + "mtu": "9100" }, "Ethernet42": { - "alias": "Ethernet42", - "lanes": "85", - "speed": "10000" + "alias": "eth-0-42", + "speed": "10000", + "mtu": "9100" }, "Ethernet43": { - "alias": "Ethernet43", - "lanes": "86", - "speed": "10000" + "alias": "eth-0-43", + "speed": "10000", + "mtu": "9100" }, "Ethernet44": { - "alias": "Ethernet44", - "lanes": "87", - "speed": "10000" + "alias": "eth-0-44", + "speed": "10000", + "mtu": "9100" }, "Ethernet45": { - "alias": "Ethernet45", - "lanes": "92", - "speed": "10000" + "alias": "eth-0-45", + "speed": "10000", + "mtu": "9100" }, "Ethernet46": { - "alias": "Ethernet46", - "lanes": "93", - "speed": "10000" + "alias": "eth-0-46", + "speed": "10000", + "mtu": "9100" }, "Ethernet47": { - "alias": "Ethernet47", - "lanes": "94", - "speed": "10000" + "alias": "eth-0-47", + "speed": "10000", + "mtu": "9100" }, "Ethernet48": { - "alias": "Ethernet48", - "lanes": "95", - "speed": "10000" + "alias": "eth-0-48", + "speed": "10000", + "mtu": "9100" }, "Ethernet49": { - "alias": "Ethernet49", - "lanes": "52,53,54,55", - "speed": "40000" + "alias": "eth-0-49", + "speed": "40000", + "mtu": "9100" }, "Ethernet50": { - "alias": "Ethernet50", - "lanes": "56,57,58,59", - "speed": "40000" + "alias": "eth-0-50", + "speed": "40000", + "mtu": "9100" }, "Ethernet51": { - "alias": "Ethernet51", - "lanes": "60,61,62,63", - "speed": "40000" + "alias": "eth-0-51", + "speed": "40000", + "mtu": "9100" }, "Ethernet52": { - "alias": "Ethernet52", - "lanes": "68,69,70,71", - "speed": "40000" + "alias": "eth-0-52", + "speed": "40000", + "mtu": "9100" }, "Ethernet53": { - "alias": "Ethernet53", - "lanes": "72,73,74,75", - "speed": "40000" + "alias": "eth-0-53", + "speed": "40000", + "mtu": "9100" }, "Ethernet54": { - "alias": "Ethernet54", - "lanes": "76,77,78,79", - "speed": "40000" + "alias": "eth-0-54", + "speed": "40000", + "mtu": "9100" } }, "PORT_QOS_MAP": { @@ -402,7 +402,7 @@ "weight": "20" } }, - "VLAN": { + "VLAN": { "Vlan500": { "dhcp_servers": [ "192.168.5.1", @@ -418,7 +418,7 @@ ], "vlanid": "500" }, - "Vlan600": { + "Vlan600": { "dhcp_servers": [ "192.168.6.1", "192.168.6.2", @@ -431,7 +431,7 @@ ], "vlanid": "600" }, - "Vlan700": { + "Vlan700": { "dhcp_servers": [ "192.168.7.1", "192.168.7.2", @@ -444,7 +444,7 @@ ], "vlanid": "700" }, - "Vlan800": { + "Vlan800": { "dhcp_servers": [ "192.168.8.1", "192.168.8.2", @@ -458,32 +458,32 @@ "vlanid": "800" } }, - "VLAN_MEMBER": { + "VLAN_MEMBER": { "Vlan500|Ethernet5": { "tagging_mode": "tagged" }, - "Vlan500|Ethernet6": { + "Vlan500|Ethernet6": { "tagging_mode": "untagged" }, - "Vlan500|Ethernet7": { + "Vlan500|Ethernet7": { "tagging_mode": "untagged" }, - "Vlan500|Ethernet8": { + "Vlan500|Ethernet8": { "tagging_mode": "untagged" }, "Vlan600|Ethernet5": { "tagging_mode": "tagged" }, - "Vlan600|Ethernet6": { + "Vlan600|Ethernet6": { "tagging_mode": "tagged" }, - "Vlan700|Ethernet5": { + "Vlan700|Ethernet5": { "tagging_mode": "tagged" }, - "Vlan700|Ethernet7": { + "Vlan700|Ethernet7": { "tagging_mode": "tagged" }, - "Vlan800|Ethernet5": { + "Vlan800|Ethernet5": { "tagging_mode": "tagged" }, "Vlan800|Ethernet8": { @@ -496,11 +496,11 @@ "Ethernet3|192.168.3.1/24": {}, "Ethernet4|192.168.4.1/24": {} }, - "VLAN_INTERFACE": { + "VLAN_INTERFACE": { "Vlan500|192.168.5.1/24": {}, - "Vlan600|192.168.6.1/24": {}, - "Vlan700|192.168.7.1/24": {}, - "Vlan800|192.168.8.1/24": {} + "Vlan600|192.168.6.1/24": {}, + "Vlan700|192.168.7.1/24": {}, + "Vlan800|192.168.8.1/24": {} }, "LOOPBACK_INTERFACE": { "Loopback0|127.0.0.1/8": {} diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/minigraph.xml b/platform/centec/sonic-platform-modules-e582/48x6q/cfg/minigraph.xml deleted file mode 100644 index fc313eb84635..000000000000 --- a/platform/centec/sonic-platform-modules-e582/48x6q/cfg/minigraph.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - switch1 - - - - - - - - - - - - - switch1 - E582-48x6q - - - - switch1 - E582-48x6q - - diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_at24c64.c b/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_at24c64.c index 7b551e71f79a..e1835df88625 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_at24c64.c +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_at24c64.c @@ -1,658 +1,602 @@ -/* - * at24.c - handle most I2C EEPROMs - * - * Copyright (C) 2005-2007 David Brownell - * Copyright (C) 2008 Wolfram Sang, Pengutronix - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. - * Differences between different vendor product lines (like Atmel AT24C or - * MicroChip 24LC, etc) won't much matter for typical read/write access. - * There are also I2C RAM chips, likewise interchangeable. One example - * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). - * - * However, misconfiguration can lose data. "Set 16-bit memory address" - * to a part with 8-bit addressing will overwrite data. Writing with too - * big a page size also loses data. And it's not safe to assume that the - * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC - * uses 0x51, for just one example. - * - * Accordingly, explicit board-specific configuration data should be used - * in almost all cases. (One partial exception is an SMBus used to access - * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) - * - * So this driver uses "new style" I2C driver binding, expecting to be - * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or - * similar kernel-resident tables; or, configuration data coming from - * a bootloader. - * - * Other than binding model, current differences from "eeprom" driver are - * that this one handles write access and isn't restricted to 24c02 devices. - * It also handles larger devices (32 kbit and up) with two-byte addresses, - * which won't work on pure SMBus systems. - */ - -struct at24_data { - struct at24_platform_data chip; - struct memory_accessor macc; - int use_smbus; - - /* - * Lock protects against activities from other Linux tasks, - * but not from changes by other I2C masters. - */ - struct mutex lock; - struct bin_attribute bin; - - u8 *writebuf; - unsigned write_max; - unsigned num_addresses; - - /* - * Some chips tie up multiple I2C addresses; dummy devices reserve - * them for us, and we'll use them with SMBus calls. - */ - struct i2c_client *client[]; -}; - -/* - * This parameter is to help this driver avoid blocking other drivers out - * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C - * clock, one 256 byte read takes about 1/43 second which is excessive; - * but the 1/170 second it takes at 400 kHz may be quite reasonable; and - * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. - * - * This value is forced to be a power of two so that writes align on pages. - */ -static unsigned io_limit = 128; -module_param(io_limit, uint, 0); -MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); - -/* - * Specs often allow 5 msec for a page write, sometimes 20 msec; - * it's important to recover from write timeouts. - */ -static unsigned write_timeout = 25; -module_param(write_timeout, uint, 0); -MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); - -#define AT24_SIZE_BYTELEN 5 -#define AT24_SIZE_FLAGS 8 - -#define AT24_BITMASK(x) (BIT(x) - 1) - -/* create non-zero magic value for given eeprom parameters */ -#define AT24_DEVICE_MAGIC(_len, _flags) \ - ((1 << AT24_SIZE_FLAGS | (_flags)) \ - << AT24_SIZE_BYTELEN | ilog2(_len)) - -static const struct i2c_device_id at24_ctc_ids[] = { - { "24c64-ctc", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16 | AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, - { /* END OF LIST */ } -}; -MODULE_DEVICE_TABLE(i2c, at24_ctc_ids); - -/*-------------------------------------------------------------------------*/ - -/* - * This routine supports chips which consume multiple I2C addresses. It - * computes the addressing information to be used for a given r/w request. - * Assumes that sanity checks for offset happened at sysfs-layer. - */ -static struct i2c_client *at24_translate_offset(struct at24_data *at24, - unsigned *offset) -{ - unsigned i; - - if (at24->chip.flags & AT24_FLAG_ADDR16) { - i = *offset >> 16; - *offset &= 0xffff; - } else { - i = *offset >> 8; - *offset &= 0xff; - } - - return at24->client[i]; -} - -static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - struct i2c_client *client; - unsigned long timeout, read_time; - int status; - - memset(msg, 0, sizeof(msg)); - - /* - * REVISIT some multi-address chips don't rollover page reads to - * the next slave address, so we may need to truncate the count. - * Those chips might need another quirk flag. - * - * If the real hardware used four adjacent 24c02 chips and that - * were misconfigured as one 24c08, that would be a similar effect: - * one "eeprom" file not four, but larger reads would fail when - * they crossed certain pages. - */ - - /* - * Slave address and byte offset derive from the offset. Always - * set the byte address; on a multi-master board, another master - * may have changed the chip's "current" address pointer. - */ - client = at24_translate_offset(at24, &offset); - - if (count > io_limit) - count = io_limit; - - count = 1; - - /* - * Reads fail if the previous write didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - read_time = jiffies; - - status = i2c_smbus_write_byte_data(client, (offset >> 8) & 0x0ff, offset & 0x0ff ); - status = i2c_smbus_read_byte(client); - if (status >= 0) { - buf[0] = status; - status = count; - } - - dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t at24_read(struct at24_data *at24, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) - return count; - - memset(buf, 0, count); - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - while (count) { - ssize_t status; - - status = at24_eeprom_read(at24, buf, off, count); - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - //printk(KERN_ALERT "at24_read buf = %s, retval = %zu\n", buf, retval); - - mutex_unlock(&at24->lock); - - return retval; -} - -static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct at24_data *at24; - - at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return at24_read(at24, buf, off, count); -} - - -/* - * Note that if the hardware write-protect pin is pulled high, the whole - * chip is normally write protected. But there are plenty of product - * variants here, including OTP fuses and partial chip protect. - * - * We only use page mode writes; the alternative is sloooow. This routine - * writes at most one page. - */ -static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, - unsigned offset, size_t count) -{ - struct i2c_client *client; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page; - - /* Get corresponding I2C address and adjust offset */ - client = at24_translate_offset(at24, &offset); - - /* write_max is at most a page */ - if (count > at24->write_max) - count = at24->write_max; - - /* Never roll over backwards, to the start of this page */ - next_page = roundup(offset + 1, at24->chip.page_size); - if (offset + count > next_page) - count = next_page - offset; - - /* - * Writes fail if the previous one didn't complete yet. We may - * loop a few times until this one succeeds, waiting at least - * long enough for one entire page write to work. - */ - timeout = jiffies + msecs_to_jiffies(write_timeout); - do { - write_time = jiffies; - - status = i2c_smbus_write_word_data(client, - (offset >> 8) & 0x0ff, (offset & 0xFF) | buf[0]); - if (status == 0) - status = count; - - dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", - count, offset, status, jiffies); - - if (status == count) - return count; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(write_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, - size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) - return count; - - /* - * Write data to chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&at24->lock); - - while (count) { - ssize_t status; - - status = at24_eeprom_write(at24, buf, off, 1); /* only one-byte to write; TODO page wirte */ - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&at24->lock); - - return retval; -} - -static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - struct at24_data *at24; - - if (unlikely(off >= attr->size)) - return -EFBIG; - - at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); - return at24_write(at24, buf, off, count); -} - -/*-------------------------------------------------------------------------*/ - -/* - * This lets other kernel code access the eeprom data. For example, it - * might hold a board's Ethernet address, or board-specific calibration - * data generated on the manufacturing floor. - */ - -static ssize_t at24_macc_read(struct memory_accessor *macc, char *buf, - off_t offset, size_t count) -{ - struct at24_data *at24 = container_of(macc, struct at24_data, macc); - - return at24_read(at24, buf, offset, count); -} - -static ssize_t at24_macc_write(struct memory_accessor *macc, const char *buf, - off_t offset, size_t count) -{ - struct at24_data *at24 = container_of(macc, struct at24_data, macc); - - return at24_write(at24, buf, offset, count); -} - -/*-------------------------------------------------------------------------*/ - -#ifdef CONFIG_OF -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ - const __be32 *val; - struct device_node *node = client->dev.of_node; - - if (node) { - if (of_get_property(node, "read-only", NULL)) - chip->flags |= AT24_FLAG_READONLY; - val = of_get_property(node, "pagesize", NULL); - if (val) - chip->page_size = be32_to_cpup(val); - } -} -#else -static void at24_get_ofdata(struct i2c_client *client, - struct at24_platform_data *chip) -{ } -#endif /* CONFIG_OF */ - -static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) -{ - struct at24_platform_data chip; - bool writable; - int use_smbus = 0; - struct at24_data *at24; - int err; - unsigned i, num_addresses; - kernel_ulong_t magic; - - if (client->dev.platform_data) { - chip = *(struct at24_platform_data *)client->dev.platform_data; - } else { - if (!id->driver_data) - return -ENODEV; - - magic = id->driver_data; - chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); - magic >>= AT24_SIZE_BYTELEN; - chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); - - /* - * This is slow, but we can't know all eeproms, so we better - * play safe. Specifying custom eeprom-types via platform_data - * is recommended anyhow. - */ - chip.page_size = 1; - - /* update chipdata if OF is present */ - at24_get_ofdata(client, &chip); - - printk(KERN_ALERT "at24_probe chip.byte_len = 0x%x\n", chip.byte_len); - printk(KERN_ALERT "at24_probe chip.flags = 0x%x\n", chip.flags); - printk(KERN_ALERT "at24_probe chip.magic = 0x%lx\n", id->driver_data); - - chip.setup = NULL; - chip.context = NULL; - } - - if (!is_power_of_2(chip.byte_len)) - dev_warn(&client->dev, - "byte_len looks suspicious (no power of 2)!\n"); - if (!chip.page_size) { - dev_err(&client->dev, "page_size must not be 0!\n"); - return -EINVAL; - } - if (!is_power_of_2(chip.page_size)) - dev_warn(&client->dev, - "page_size looks suspicious (no power of 2)!\n"); - - /* Use I2C operations unless we're stuck with SMBus extensions. */ - if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { - if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { - use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - return -EPFNOSUPPORT; - } - use_smbus = I2C_SMBUS_BYTE_DATA; - printk(KERN_ALERT "at24_probe use_smbus --> %d\n", - use_smbus); - } - - if (chip.flags & AT24_FLAG_TAKE8ADDR) - num_addresses = 8; - else - num_addresses = DIV_ROUND_UP(chip.byte_len, - (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); - - at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + - num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); - if (!at24) - return -ENOMEM; - - mutex_init(&at24->lock); - at24->use_smbus = use_smbus; - at24->chip = chip; - at24->num_addresses = num_addresses; - - /* - * Export the EEPROM bytes through sysfs, since that's convenient. - * By default, only root should see the data (maybe passwords etc) - */ - sysfs_bin_attr_init(&at24->bin); - at24->bin.attr.name = "eeprom"; - at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; - at24->bin.read = at24_bin_read; - at24->bin.size = chip.byte_len; - - at24->macc.read = at24_macc_read; - - writable = !(chip.flags & AT24_FLAG_READONLY); - if (writable) { - if (!use_smbus || i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { - - unsigned write_max = chip.page_size; - - at24->macc.write = at24_macc_write; - - at24->bin.write = at24_bin_write; - at24->bin.attr.mode |= S_IWUSR; - - if (write_max > io_limit) - write_max = io_limit; - if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - at24->write_max = write_max; - - /* buffer (data + address at the beginning) */ - at24->writebuf = devm_kzalloc(&client->dev, - write_max + 2, GFP_KERNEL); - if (!at24->writebuf) - return -ENOMEM; - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - } - - at24->client[0] = client; - - /* use dummy devices for multiple-address chips */ - for (i = 1; i < num_addresses; i++) { - at24->client[i] = i2c_new_dummy(client->adapter, - client->addr + i); - if (!at24->client[i]) { - dev_err(&client->dev, "address 0x%02x unavailable\n", - client->addr + i); - err = -EADDRINUSE; - goto err_clients; - } - } - - err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin); - if (err) - goto err_clients; - - i2c_set_clientdata(client, at24); - - dev_info(&client->dev, "%zu byte %s EEPROM, %s, %u bytes/write\n", - at24->bin.size, client->name, - writable ? "writable" : "read-only", at24->write_max); - if (use_smbus == I2C_SMBUS_WORD_DATA || - use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } - - /* export data to kernel code */ - if (chip.setup) - chip.setup(&at24->macc, chip.context); - - return 0; - -err_clients: - for (i = 1; i < num_addresses; i++) - if (at24->client[i]) - i2c_unregister_device(at24->client[i]); - - return err; -} - -static int at24_remove(struct i2c_client *client) -{ - struct at24_data *at24; - int i; - - at24 = i2c_get_clientdata(client); - sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); - - for (i = 1; i < at24->num_addresses; i++) - i2c_unregister_device(at24->client[i]); - - return 0; -} - -/*-------------------------------------------------------------------------*/ - -static struct i2c_board_info i2c_devs = { - I2C_BOARD_INFO("24c64-ctc", 0x57), -}; - -static struct i2c_adapter *adapter = NULL; -static struct i2c_client *client = NULL; - -static int ctc_at24c64_init(void) -{ - printk(KERN_ALERT "ctc_at24c64_init\n"); - - adapter = i2c_get_adapter(0); - if(adapter == NULL){ - printk(KERN_ALERT "i2c_get_adapter == NULL\n"); - return -1; - } - - client = i2c_new_device(adapter, &i2c_devs); - if(client == NULL){ - printk(KERN_ALERT "i2c_new_device == NULL\n"); - i2c_put_adapter(adapter); - adapter = NULL; - return -1; - } - - return 0; -} - -static void ctc_at24c64_exit(void) -{ - printk(KERN_ALERT "ctc_at24c64_exit\n"); - if(client){ - i2c_unregister_device(client); - } - if(adapter){ - i2c_put_adapter(adapter); - } -} - -static struct i2c_driver at24_ctc_driver = { - .driver = { - .name = "at24-ctc", - .owner = THIS_MODULE, - }, - .probe = at24_probe, - .remove = at24_remove, - .id_table = at24_ctc_ids, -}; - -static int __init at24_ctc_init(void) -{ - if (!io_limit) { - pr_err("at24_ctc: io_limit must not be 0!\n"); - return -EINVAL; - } - - io_limit = rounddown_pow_of_two(io_limit); - - ctc_at24c64_init(); - - return i2c_add_driver(&at24_ctc_driver); -} -module_init(at24_ctc_init); - -static void __exit at24_ctc_exit(void) -{ - ctc_at24c64_exit(); - i2c_del_driver(&at24_ctc_driver); -} -module_exit(at24_ctc_exit); - -MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); -MODULE_AUTHOR("David Brownell and Wolfram Sang"); -MODULE_LICENSE("GPL"); +/* + * at24.c - handle most I2C EEPROMs + * + * Copyright (C) 2005-2007 David Brownell + * Copyright (C) 2008 Wolfram Sang, Pengutronix + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* + * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable. + * Differences between different vendor product lines (like Atmel AT24C or + * MicroChip 24LC, etc) won't much matter for typical read/write access. + * There are also I2C RAM chips, likewise interchangeable. One example + * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes). + * + * However, misconfiguration can lose data. "Set 16-bit memory address" + * to a part with 8-bit addressing will overwrite data. Writing with too + * big a page size also loses data. And it's not safe to assume that the + * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC + * uses 0x51, for just one example. + * + * Accordingly, explicit board-specific configuration data should be used + * in almost all cases. (One partial exception is an SMBus used to access + * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.) + * + * So this driver uses "new style" I2C driver binding, expecting to be + * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or + * similar kernel-resident tables; or, configuration data coming from + * a bootloader. + * + * Other than binding model, current differences from "eeprom" driver are + * that this one handles write access and isn't restricted to 24c02 devices. + * It also handles larger devices (32 kbit and up) with two-byte addresses, + * which won't work on pure SMBus systems. + */ + +struct at24_data { + struct at24_platform_data chip; + int use_smbus; + + /* + * Lock protects against activities from other Linux tasks, + * but not from changes by other I2C masters. + */ + struct mutex lock; + struct bin_attribute bin; + + u8 *writebuf; + unsigned write_max; + unsigned num_addresses; + + /* + * Some chips tie up multiple I2C addresses; dummy devices reserve + * them for us, and we'll use them with SMBus calls. + */ + struct i2c_client *client[]; +}; + +/* + * This parameter is to help this driver avoid blocking other drivers out + * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C + * clock, one 256 byte read takes about 1/43 second which is excessive; + * but the 1/170 second it takes at 400 kHz may be quite reasonable; and + * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible. + * + * This value is forced to be a power of two so that writes align on pages. + */ +static unsigned io_limit = 128; +module_param(io_limit, uint, 0); +MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)"); + +/* + * Specs often allow 5 msec for a page write, sometimes 20 msec; + * it's important to recover from write timeouts. + */ +static unsigned write_timeout = 25; +module_param(write_timeout, uint, 0); +MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)"); + +#define AT24_SIZE_BYTELEN 5 +#define AT24_SIZE_FLAGS 8 + +#define AT24_BITMASK(x) (BIT(x) - 1) + +/* create non-zero magic value for given eeprom parameters */ +#define AT24_DEVICE_MAGIC(_len, _flags) \ + ((1 << AT24_SIZE_FLAGS | (_flags)) \ + << AT24_SIZE_BYTELEN | ilog2(_len)) + +static const struct i2c_device_id at24_ctc_ids[] = { + { "24c64-ctc", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16 | AT24_FLAG_READONLY | AT24_FLAG_IRUGO) }, + { /* END OF LIST */ } +}; +MODULE_DEVICE_TABLE(i2c, at24_ctc_ids); + +/*-------------------------------------------------------------------------*/ + +/* + * This routine supports chips which consume multiple I2C addresses. It + * computes the addressing information to be used for a given r/w request. + * Assumes that sanity checks for offset happened at sysfs-layer. + */ +static struct i2c_client *at24_translate_offset(struct at24_data *at24, + unsigned *offset) +{ + unsigned i = 0; + + if (at24->chip.flags & AT24_FLAG_ADDR16) { + i = *offset >> 16; + *offset &= 0xffff; + } else { + i = *offset >> 8; + *offset &= 0xff; + } + + return at24->client[i]; +} + +static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf, + unsigned offset, size_t count) +{ + struct i2c_msg msg[2]; + struct i2c_client *client; + unsigned long timeout, read_time; + int status; + + memset(msg, 0, sizeof(msg)); + + /* + * REVISIT some multi-address chips don't rollover page reads to + * the next slave address, so we may need to truncate the count. + * Those chips might need another quirk flag. + * + * If the real hardware used four adjacent 24c02 chips and that + * were misconfigured as one 24c08, that would be a similar effect: + * one "eeprom" file not four, but larger reads would fail when + * they crossed certain pages. + */ + + /* + * Slave address and byte offset derive from the offset. Always + * set the byte address; on a multi-master board, another master + * may have changed the chip's "current" address pointer. + */ + client = at24_translate_offset(at24, &offset); + + if (count > io_limit) + count = io_limit; + + count = 1; + + /* + * Reads fail if the previous write didn't complete yet. We may + * loop a few times until this one succeeds, waiting at least + * long enough for one entire page write to work. + */ + timeout = jiffies + msecs_to_jiffies(write_timeout); + do { + read_time = jiffies; + + status = i2c_smbus_write_byte_data(client, (offset >> 8) & 0x0ff, offset & 0x0ff ); + status = i2c_smbus_read_byte(client); + if (status >= 0) { + buf[0] = status; + status = count; + } + + dev_dbg(&client->dev, "read %zu@%d --> %d (%ld)\n", count, offset, status, jiffies); + + if (status == count) + return count; + + /* REVISIT: at HZ=100, this is sloooow */ + msleep(1); + } while (time_before(read_time, timeout)); + + return -ETIMEDOUT; +} + +static ssize_t at24_read(struct at24_data *at24, + char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) + return count; + + memset(buf, 0, count); + + /* + * Read data from chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&at24->lock); + + while (count) { + ssize_t status; + + status = at24_eeprom_read(at24, buf, off, count); + if (status <= 0) { + if (retval == 0) + retval = status; + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&at24->lock); + + return retval; +} + +static ssize_t at24_bin_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + struct at24_data *at24; + + at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); + return at24_read(at24, buf, off, count); +} + + +/* + * Note that if the hardware write-protect pin is pulled high, the whole + * chip is normally write protected. But there are plenty of product + * variants here, including OTP fuses and partial chip protect. + * + * We only use page mode writes; the alternative is sloooow. This routine + * writes at most one page. + */ +static ssize_t at24_eeprom_write(struct at24_data *at24, const char *buf, + unsigned offset, size_t count) +{ + struct i2c_client *client; + ssize_t status; + unsigned long timeout, write_time; + unsigned next_page; + + /* Get corresponding I2C address and adjust offset */ + client = at24_translate_offset(at24, &offset); + + /* write_max is at most a page */ + if (count > at24->write_max) + count = at24->write_max; + + /* Never roll over backwards, to the start of this page */ + next_page = roundup(offset + 1, at24->chip.page_size); + if (offset + count > next_page) + count = next_page - offset; + + /* + * Writes fail if the previous one didn't complete yet. We may + * loop a few times until this one succeeds, waiting at least + * long enough for one entire page write to work. + */ + timeout = jiffies + msecs_to_jiffies(write_timeout); + do { + write_time = jiffies; + + status = i2c_smbus_write_word_data(client, (offset >> 8) & 0x0ff, (offset & 0xFF) | buf[0]); + if (status == 0) + status = count; + + dev_dbg(&client->dev, "write %zu@%d --> %zd (%ld)\n", count, offset, status, jiffies); + + if (status == count) + return count; + + /* REVISIT: at HZ=100, this is sloooow */ + msleep(1); + } while (time_before(write_time, timeout)); + + return -ETIMEDOUT; +} + +static ssize_t at24_write(struct at24_data *at24, const char *buf, loff_t off, + size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) + return count; + + /* + * Write data to chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&at24->lock); + + while (count) { + ssize_t status; + + status = at24_eeprom_write(at24, buf, off, 1); /* only one-byte to write; TODO page wirte */ + if (status <= 0) { + if (retval == 0) + retval = status; + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&at24->lock); + + return retval; +} + +static ssize_t at24_bin_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + struct at24_data *at24; + + if (unlikely(off >= attr->size)) + return -EFBIG; + + at24 = dev_get_drvdata(container_of(kobj, struct device, kobj)); + return at24_write(at24, buf, off, count); +} + +/*-------------------------------------------------------------------------*/ + +#ifdef CONFIG_OF +static void at24_get_ofdata(struct i2c_client *client, + struct at24_platform_data *chip) +{ + const __be32 *val; + struct device_node *node = client->dev.of_node; + + if (node) { + if (of_get_property(node, "read-only", NULL)) + chip->flags |= AT24_FLAG_READONLY; + val = of_get_property(node, "pagesize", NULL); + if (val) + chip->page_size = be32_to_cpup(val); + } +} +#else +static void at24_get_ofdata(struct i2c_client *client, + struct at24_platform_data *chip) +{ } +#endif /* CONFIG_OF */ + +static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id) +{ + struct at24_platform_data chip; + bool writable; + int use_smbus = 0; + struct at24_data *at24; + int err; + unsigned i, num_addresses; + kernel_ulong_t magic; + + if (client->dev.platform_data) { + chip = *(struct at24_platform_data *)client->dev.platform_data; + } else { + if (!id->driver_data) + return -ENODEV; + + magic = id->driver_data; + chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN)); + magic >>= AT24_SIZE_BYTELEN; + chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS); + + /* + * This is slow, but we can't know all eeproms, so we better + * play safe. Specifying custom eeprom-types via platform_data + * is recommended anyhow. + */ + chip.page_size = 1; + + /* update chipdata if OF is present */ + at24_get_ofdata(client, &chip); + + chip.setup = NULL; + chip.context = NULL; + } + + if (!is_power_of_2(chip.byte_len)) + dev_warn(&client->dev, + "byte_len looks suspicious (no power of 2)!\n"); + if (!chip.page_size) { + dev_err(&client->dev, "page_size must not be 0!\n"); + return -EINVAL; + } + if (!is_power_of_2(chip.page_size)) + dev_warn(&client->dev, + "page_size looks suspicious (no power of 2)!\n"); + + /* Use I2C operations unless we're stuck with SMBus extensions. */ + if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { + if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { + use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)) { + use_smbus = I2C_SMBUS_WORD_DATA; + } else if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) { + use_smbus = I2C_SMBUS_BYTE_DATA; + } else { + return -EPFNOSUPPORT; + } + use_smbus = I2C_SMBUS_BYTE_DATA; + } + + if (chip.flags & AT24_FLAG_TAKE8ADDR) + num_addresses = 8; + else + num_addresses = DIV_ROUND_UP(chip.byte_len, (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256); + + at24 = devm_kzalloc(&client->dev, sizeof(struct at24_data) + num_addresses * sizeof(struct i2c_client *), GFP_KERNEL); + if (!at24) + return -ENOMEM; + + mutex_init(&at24->lock); + at24->use_smbus = use_smbus; + at24->chip = chip; + at24->num_addresses = num_addresses; + + printk(KERN_ALERT "at24_probe chip.byte_len = 0x%x\n", chip.byte_len); + printk(KERN_ALERT "at24_probe chip.flags = 0x%x\n", chip.flags); + printk(KERN_ALERT "at24_probe chip.magic = 0x%lx\n", id->driver_data); + printk(KERN_ALERT "at24_probe use_smbus = %d\n", at24->use_smbus); + printk(KERN_ALERT "at24_probe num_addresses = %d\n", at24->num_addresses); + + /* + * Export the EEPROM bytes through sysfs, since that's convenient. + * By default, only root should see the data (maybe passwords etc) + */ + sysfs_bin_attr_init(&at24->bin); + at24->bin.attr.name = "eeprom"; + at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR; + at24->bin.read = at24_bin_read; + at24->bin.size = chip.byte_len; + + writable = !(chip.flags & AT24_FLAG_READONLY); + if (writable) { + if (!use_smbus || i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) { + unsigned write_max = chip.page_size; + + at24->bin.write = at24_bin_write; + at24->bin.attr.mode |= S_IWUSR; + + if (write_max > io_limit) + write_max = io_limit; + if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) + write_max = I2C_SMBUS_BLOCK_MAX; + at24->write_max = write_max; + + /* buffer (data + address at the beginning) */ + at24->writebuf = devm_kzalloc(&client->dev, write_max + 2, GFP_KERNEL); + if (!at24->writebuf) + return -ENOMEM; + } else { + dev_warn(&client->dev, "cannot write due to controller restrictions."); + } + } + + at24->client[0] = client; + + /* use dummy devices for multiple-address chips */ + for (i = 1; i < num_addresses; i++) { + at24->client[i] = i2c_new_dummy(client->adapter, client->addr + i); + if (!at24->client[i]) { + dev_err(&client->dev, "address 0x%02x unavailable\n", client->addr + i); + err = -EADDRINUSE; + goto err_clients; + } + } + + err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin); + if (err) + goto err_clients; + + i2c_set_clientdata(client, at24); + + printk(KERN_ALERT "at24_probe %s done\n", client->name); + + return 0; + +err_clients: + for (i = 1; i < num_addresses; i++) + if (at24->client[i]) + i2c_unregister_device(at24->client[i]); + + return err; +} + +static int at24_remove(struct i2c_client *client) +{ + struct at24_data *at24; + int i; + + at24 = i2c_get_clientdata(client); + sysfs_remove_bin_file(&client->dev.kobj, &at24->bin); + + for (i = 1; i < at24->num_addresses; i++) + i2c_unregister_device(at24->client[i]); + + return 0; +} + +/*-------------------------------------------------------------------------*/ + +static struct i2c_board_info i2c_devs = { + I2C_BOARD_INFO("24c64-ctc", 0x57), +}; + +static struct i2c_adapter *adapter = NULL; +static struct i2c_client *client = NULL; + +static int ctc_at24c64_init(void) +{ + printk(KERN_ALERT "ctc_at24c64_init\n"); + + adapter = i2c_get_adapter(0); + if(adapter == NULL){ + printk(KERN_ALERT "i2c_get_adapter == NULL\n"); + return -1; + } + + client = i2c_new_device(adapter, &i2c_devs); + if(client == NULL){ + printk(KERN_ALERT "i2c_new_device == NULL\n"); + i2c_put_adapter(adapter); + adapter = NULL; + return -1; + } + + return 0; +} + +static void ctc_at24c64_exit(void) +{ + printk(KERN_ALERT "ctc_at24c64_exit\n"); + if(client){ + i2c_unregister_device(client); + } + if(adapter){ + i2c_put_adapter(adapter); + } +} + +static struct i2c_driver at24_ctc_driver = { + .driver = { + .name = "at24-ctc", + .owner = THIS_MODULE, + }, + .probe = at24_probe, + .remove = at24_remove, + .id_table = at24_ctc_ids, +}; + +static int __init at24_ctc_init(void) +{ + if (!io_limit) { + pr_err("at24_ctc: io_limit must not be 0!\n"); + return -EINVAL; + } + + io_limit = rounddown_pow_of_two(io_limit); + + ctc_at24c64_init(); + + return i2c_add_driver(&at24_ctc_driver); +} +module_init(at24_ctc_init); + +static void __exit at24_ctc_exit(void) +{ + ctc_at24c64_exit(); + i2c_del_driver(&at24_ctc_driver); +} +module_exit(at24_ctc_exit); + +MODULE_DESCRIPTION("Driver for most I2C EEPROMs"); +MODULE_AUTHOR("David Brownell and Wolfram Sang"); +MODULE_LICENSE("GPL"); /* XXX */ + diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_e582_48x6q_platform.c b/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_e582_48x6q_platform.c index 4837335872e4..6ef18ca62f41 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_e582_48x6q_platform.c +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/centec_e582_48x6q_platform.c @@ -845,7 +845,7 @@ enum led_brightness e582_48x6q_led_get(struct led_classdev *led_cdev) if (ret != 0) { printk(KERN_CRIT "Error: read %s led attr failed\n", led_cdev->name); - return; + return 0; } led_value = ((led_value & mask) >> shift); @@ -1189,7 +1189,8 @@ static ssize_t e582_48x6q_sfp_write_enable(struct device *dev, struct device_att ret = e582_48x6q_smbus_write_reg(i2c_sfp_client, dir_bank, 0x0); if (ret != 0) { - return sprintf(buf, "Error: read sfp data:%s set dir-ctl failed\n", attr->attr.name); + printk(KERN_CRIT "Error: read sfp data:%s set dir-ctl failed\n", attr->attr.name); + return size; } input_bank = (reg_no/8) + 0x8; @@ -1221,7 +1222,7 @@ static ssize_t e582_48x6q_sfp_write_enable(struct device *dev, struct device_att } static DEVICE_ATTR(sfp_presence, S_IRUGO, e582_48x6q_sfp_read_presence, NULL); -static DEVICE_ATTR(sfp_enable, S_IRUGO|S_IWUGO, e582_48x6q_sfp_read_enable, e582_48x6q_sfp_write_enable); +static DEVICE_ATTR(sfp_enable, S_IRUGO|S_IWUSR, e582_48x6q_sfp_read_enable, e582_48x6q_sfp_write_enable); static int e582_48x6q_init_sfp(void) { int ret = 0; diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.c b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.c index a1315a97159b..32a38f842cfa 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.c +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.c @@ -25,7 +25,7 @@ #endif #include "dal_kernel.h" #include "dal_mpool.h" - +#include MODULE_AUTHOR("Centec Networks Inc."); MODULE_DESCRIPTION("DAL kernel module"); MODULE_LICENSE("GPL"); @@ -47,7 +47,9 @@ MODULE_PARM_DESC(dma_pool_size, #define CTC_VENDOR_VID 0xc001 #define CTC_HUMBER_DEVICE_ID 0x6048 -#define CTC_GOLDENGATE_DEVICE_ID 0xcb10 +#define CTC_GOLDENGATE_DEVICE_ID 0xc010 +#define CTC_PCIE_VENDOR_ID 0xcb10 +#define CTC_DUET2_DEVICE_ID 0x7148 #define MEM_MAP_RESERVE SetPageReserved #define MEM_MAP_UNRESERVE ClearPageReserved @@ -82,7 +84,7 @@ typedef struct dal_kernel_dev_s uintptr logic_address; /* Physical address */ - uintptr phys_address; + unsigned long long phys_address; } dal_kern_dev_t; typedef struct _dma_segment @@ -126,8 +128,8 @@ static unsigned int* dma_virt_base[DAL_MAX_CHIP_NUM]; #ifndef DMA_MEM_MODE_PLATFORM static unsigned int* dma_virt_base_tmp[DAL_MAX_CHIP_NUM]; #endif -static uintptr dma_phy_base[DAL_MAX_CHIP_NUM]; -static unsigned int dma_mem_size = 0x800000; +static unsigned long long dma_phy_base[DAL_MAX_CHIP_NUM]; +static unsigned int dma_mem_size = 0xc00000; static unsigned int msi_irq_base[DAL_MAX_CHIP_NUM]; static unsigned int msi_irq_num[DAL_MAX_CHIP_NUM]; static unsigned int msi_used = 0; @@ -141,7 +143,9 @@ MODULE_PARM_DESC(dal_debug, "Set debug level (default 0)"); static struct pci_device_id dal_id_table[] = { {PCI_DEVICE(CTC_VENDOR_VID, CTC_GREATBELT_DEVICE_ID)}, - {PCI_DEVICE(0xcb10, 0xc010)}, + {PCI_DEVICE(CTC_PCIE_VENDOR_ID, CTC_GOLDENGATE_DEVICE_ID)}, + {PCI_DEVICE((CTC_PCIE_VENDOR_ID+1), (CTC_GOLDENGATE_DEVICE_ID+1))}, + {PCI_DEVICE(CTC_PCIE_VENDOR_ID, CTC_DUET2_DEVICE_ID)}, {0, }, }; @@ -186,7 +190,11 @@ static struct file_operations dal_intr_fops[CTC_MAX_INTR_NUM] = .poll = linux_dal_poll7, }, }; - +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0)) +#include +#define virt_to_bus virt_to_phys +#define bus_to_virt phys_to_virt +#endif /***************************************************************************** * macros *****************************************************************************/ @@ -450,9 +458,12 @@ dal_interrupt_register(unsigned int irq, int prio, void (* isr)(void*), void* da { if (irq == dal_isr[intr_num_tmp].irq) { - dal_isr[intr_num_tmp].count++; - printk("Interrupt irq %d register count %d.\n", irq, dal_isr[intr_num_tmp].count); - return 0; + if (0 == msi_used) + { + dal_isr[intr_num_tmp].count++; + printk("Interrupt irq %d register count %d.\n", irq, dal_isr[intr_num_tmp].count); + } + return 0; } if ((0 == dal_isr[intr_num_tmp].irq) && (CTC_MAX_INTR_NUM == intr_num)) { @@ -558,14 +569,6 @@ _dal_set_msi_enabe(unsigned int lchip, unsigned int irq_num) if (irq_num == 1) { - if (msi_irq_base[lchip]) - { - dal_interrupt_unregister(msi_irq_base[lchip]); - pci_disable_msi(dal_dev[lchip].pci_dev); - msi_used = 0; - msi_irq_base[lchip] = 0; - msi_irq_num[lchip] = 0; - } ret = pci_enable_msi(dal_dev[lchip].pci_dev); if (ret) { @@ -616,6 +619,7 @@ int dal_set_msi_cap(unsigned long arg) { int ret = 0; + int index = 0; dal_msi_info_t msi_info; if (copy_from_user(&msi_info, (void*)arg, sizeof(dal_msi_info_t))) @@ -626,8 +630,21 @@ dal_set_msi_cap(unsigned long arg) printk("####dal_set_msi_cap lchip %d base %d num:%d\n", msi_info.lchip, msi_info.irq_base, msi_info.irq_num); if (msi_info.irq_num > 0) { - msi_used = 1; - ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + if (0 == msi_used) + { + msi_used = 1; + ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + } + else if ((1 == msi_used) && (msi_info.irq_num != msi_irq_num[msi_info.lchip])) + { + for (index = 0; index < msi_irq_num[msi_info.lchip]; index++) + { + dal_interrupt_unregister(msi_irq_base[msi_info.lchip]+index); + } + _dal_set_msi_disable(msi_info.lchip); + msi_used = 1; + ret = _dal_set_msi_enabe(msi_info.lchip, msi_info.irq_num); + } } else { @@ -1062,6 +1079,10 @@ int dal_create_irq_mapping(unsigned long arg) { #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0)) + +#ifndef NO_IRQ +#define NO_IRQ (-1) +#endif dal_irq_mapping_t irq_map; if (copy_from_user(&irq_map, (void*)arg, sizeof(dal_irq_mapping_t))) @@ -1094,7 +1115,7 @@ dal_pci_read(unsigned long arg) return -EFAULT; } - _dal_pci_read((unsigned char)cmdpara_chip.chip_id, (unsigned int)cmdpara_chip.reg_addr, + _dal_pci_read((unsigned char)cmdpara_chip.lchip, (unsigned int)cmdpara_chip.reg_addr, (unsigned int*)(&(cmdpara_chip.value))); if (copy_to_user((dal_chip_parm_t*)arg, (void*)&cmdpara_chip, sizeof(dal_chip_parm_t))) @@ -1127,7 +1148,7 @@ dal_pci_write(unsigned long arg) return -EFAULT; } - _dal_pci_write((unsigned char)cmdpara_chip.chip_id, (unsigned int)cmdpara_chip.reg_addr, + _dal_pci_write((unsigned char)cmdpara_chip.lchip, (unsigned int)cmdpara_chip.reg_addr, (unsigned int)cmdpara_chip.value); return 0; @@ -1166,7 +1187,7 @@ dal_user_read_pci_conf(unsigned long arg) return -EFAULT; } - if (dal_pci_conf_read(dal_cfg.chip_id, dal_cfg.offset, &dal_cfg.value)) + if (dal_pci_conf_read(dal_cfg.lchip, dal_cfg.offset, &dal_cfg.value)) { printk("dal_pci_conf_read failed.\n"); return -EFAULT; @@ -1190,14 +1211,14 @@ dal_user_write_pci_conf(unsigned long arg) return -EFAULT; } - return dal_pci_conf_write(dal_cfg.chip_id, dal_cfg.offset, dal_cfg.value); + return dal_pci_conf_write(dal_cfg.lchip, dal_cfg.offset, dal_cfg.value); } static int linux_get_device(unsigned long arg) { dal_user_dev_t user_dev; - int chip_id = 0; + int lchip = 0; if (copy_from_user(&user_dev, (void*)arg, sizeof(user_dev))) { @@ -1205,20 +1226,16 @@ linux_get_device(unsigned long arg) } user_dev.chip_num = dal_chip_num; - chip_id = user_dev.chip_id; + lchip = user_dev.lchip; - if (chip_id < dal_chip_num) + if (lchip < dal_chip_num) { - user_dev.phy_base0 = (unsigned int)dal_dev[chip_id].phys_address; - #ifdef PHYS_ADDR_IS_64BIT - user_dev.phy_base1 = (unsigned int)(dal_dev[chip_id].phys_address >> 32); - #else - user_dev.phy_base1 = 0; - #endif + user_dev.phy_base0 = (unsigned int)dal_dev[lchip].phys_address; + user_dev.phy_base1 = (unsigned int)(dal_dev[lchip].phys_address >> 32); - user_dev.bus_no = dal_dev[chip_id].pci_dev->bus->number; - user_dev.dev_no = dal_dev[chip_id].pci_dev->device; - user_dev.fun_no = dal_dev[chip_id].pci_dev->devfn; + user_dev.bus_no = dal_dev[lchip].pci_dev->bus->number; + user_dev.dev_no = dal_dev[lchip].pci_dev->device; + user_dev.fun_no = dal_dev[lchip].pci_dev->devfn; } if (copy_to_user((dal_user_dev_t*)arg, (void*)&user_dev, sizeof(user_dev))) @@ -1256,11 +1273,7 @@ linux_get_dma_info(unsigned long arg) } dma_para.phy_base = (unsigned int)dma_phy_base[dma_para.lchip]; - #ifdef PHYS_ADDR_IS_64BIT dma_para.phy_base_hi = dma_phy_base[dma_para.lchip] >> 32; - #else - dma_para.phy_base_hi = 0; - #endif dma_para.size = dma_mem_size; if (copy_to_user((dma_info_t*)arg, (void*)&dma_para, sizeof(dma_info_t))) @@ -1348,10 +1361,10 @@ dal_cache_inval(unsigned long arg) #if 0 dma_sync_single_for_cpu(NULL, intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); -#endif - dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); + dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); +#endif return 0; } @@ -1371,10 +1384,10 @@ dal_cache_flush(unsigned long arg) #if 0 dma_sync_single_for_cpu(NULL, intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); -#endif - dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); + dma_cache_sync(NULL, (void*)intr_para.ptr, intr_para.length, DMA_BIDIRECTIONAL); +#endif return 0; } @@ -1386,31 +1399,30 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) int ret = 0; unsigned int temp = 0; unsigned int lchip = 0; - unsigned int chip_id = 0; printk(KERN_WARNING "********found dal device*****\n"); - for (chip_id = 0; chip_id < DAL_MAX_CHIP_NUM; chip_id ++) + for (lchip = 0; lchip < DAL_MAX_CHIP_NUM; lchip ++) { - if (NULL == dal_dev[chip_id].pci_dev) + if (NULL == dal_dev[lchip].pci_dev) { break; } } - if (chip_id >= DAL_MAX_CHIP_NUM) + if (lchip >= DAL_MAX_CHIP_NUM) { printk("Exceed max local chip num\n"); return -1; } - dev = &dal_dev[chip_id]; + dev = &dal_dev[lchip]; if (NULL == dev) { printk("Cannot obtain PCI resources\n"); } - lchip = chip_id; + lchip = lchip; dal_chip_num += 1; dev->pci_dev = pdev; @@ -1454,7 +1466,6 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) if (dma_mem_size) { dal_alloc_dma_pool(lchip, dma_mem_size); - #ifdef PHYS_ADDR_IS_64BIT /*add check Dma memory pool cannot cross 4G space*/ if ((0==(dma_phy_base[lchip]>>32)) && (0!=((dma_phy_base[lchip]+dma_mem_size)>>32))) @@ -1462,7 +1473,6 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) printk("Dma malloc memory cross 4G space!!!!!! \n"); return -1; } - #endif } printk(KERN_WARNING "linux_dal_probe end*****\n"); @@ -1473,12 +1483,12 @@ linux_dal_probe(struct pci_dev* pdev, const struct pci_device_id* id) void linux_dal_remove(struct pci_dev* pdev) { - unsigned int chip_id = 0; + unsigned int lchip = 0; unsigned int flag = 0; - for (chip_id = 0; chip_id < DAL_MAX_CHIP_NUM; chip_id ++) + for (lchip = 0; lchip < DAL_MAX_CHIP_NUM; lchip ++) { - if (pdev == dal_dev[chip_id].pci_dev) + if (pdev == dal_dev[lchip].pci_dev) { flag = 1; break; @@ -1487,11 +1497,11 @@ linux_dal_remove(struct pci_dev* pdev) if (1 == flag) { - dal_free_dma_pool(chip_id); + dal_free_dma_pool(lchip); pci_release_regions(pdev); pci_disable_device(pdev); - dal_dev[chip_id].pci_dev = NULL; + dal_dev[lchip].pci_dev = NULL; dal_chip_num--; } @@ -1504,7 +1514,7 @@ linux_dal_ioctl(struct file* file, unsigned int cmd, unsigned long arg) #else -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 8, 13)) +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)) static int linux_dal_ioctl(struct file* file, unsigned int cmd, unsigned long arg) @@ -1820,3 +1830,4 @@ linux_dal_exit(void) module_init(linux_dal_init); module_exit(linux_dal_exit); + diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.h b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.h index de39af67773b..850a4cffa731 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.h +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_kernel.h @@ -54,7 +54,7 @@ typedef unsigned int uintptr; #define DAL_ONE_MB (1024*1024) struct dal_chip_parm_s { - unsigned int chip_id; /*tmp should be uint8*/ + unsigned int lchip; /*tmp should be uint8*/ unsigned int fpga_id; /*tmp add*/ unsigned int reg_addr; unsigned int value; @@ -78,7 +78,7 @@ typedef struct dal_irq_mapping_s dal_irq_mapping_t; struct dal_user_dev_s { unsigned int chip_num; /*output: local chip number*/ - unsigned int chip_id; /*input: local chip id*/ + unsigned int lchip; /*input: local chip id*/ unsigned int phy_base0; /* low 32bits physical base address */ unsigned int phy_base1; /* high 32bits physical base address */ unsigned int bus_no; @@ -100,7 +100,7 @@ typedef struct dma_info_s dma_info_t; struct dal_pci_cfg_ioctl_s { - unsigned int chip_id; /* Device ID */ + unsigned int lchip; /* Device ID */ unsigned int offset; unsigned int value; }; @@ -168,3 +168,4 @@ typedef enum dal_version_e dal_version_t; #endif + diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.c b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.c index 82d3b7a917a8..5aca222a138f 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.c +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.c @@ -1,4 +1,3 @@ - #include "dal_mpool.h" #ifdef __KERNEL__ @@ -27,6 +26,8 @@ static sal_mutex_t* dal_mpool_lock; #endif /* __KERNEL__ */ + + dal_mpool_mem_t* g_free_block_ptr = NULL; /* System cache line size */ @@ -34,8 +35,9 @@ dal_mpool_mem_t* g_free_block_ptr = NULL; #define DAL_CACHE_LINE_BYTES 256 #endif -static dal_mpool_mem_t* p_desc_pool = NULL; -static dal_mpool_mem_t* p_data_pool = NULL; +#define DAL_MAX_CHIP_NUM 32 +static dal_mpool_mem_t* p_desc_pool[DAL_MAX_CHIP_NUM] = {0}; +static dal_mpool_mem_t* p_data_pool[DAL_MAX_CHIP_NUM] = {0}; int dal_mpool_init(void) @@ -74,7 +76,7 @@ _dal_mpool_create(void* base, int size, int type) } dal_mpool_mem_t* -dal_mpool_create(void* base, int size) +dal_mpool_create(unsigned char lchip, void* base, int size) { dal_mpool_mem_t* head = NULL; int mod = (int)(((unsigned long)base) & (DAL_CACHE_LINE_BYTES - 1)); @@ -98,8 +100,8 @@ dal_mpool_create(void* base, int size) } /* init for desc linkptr */ - p_desc_pool = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC); - if (NULL == p_desc_pool) + p_desc_pool[lchip] = _dal_mpool_create(base, DAL_MPOOL_MAX_DESX_SIZE, DAL_MPOOL_TYPE_DESC); + if (NULL == p_desc_pool[lchip]) { MPOOL_UNLOCK(); DAL_FREE(head->next); @@ -108,14 +110,14 @@ dal_mpool_create(void* base, int size) } /* init for data linkptr */ - p_data_pool = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA); - if (NULL == p_data_pool) + p_data_pool[lchip] = _dal_mpool_create(((char*)base+DAL_MPOOL_MAX_DESX_SIZE), (size - DAL_MPOOL_MAX_DESX_SIZE), DAL_MPOOL_TYPE_DATA); + if (NULL == p_data_pool[lchip]) { MPOOL_UNLOCK(); DAL_FREE(head->next); DAL_FREE(head); - DAL_FREE(p_desc_pool->next); - DAL_FREE(p_desc_pool); + DAL_FREE(p_desc_pool[lchip]->next); + DAL_FREE(p_desc_pool[lchip]); return NULL; } @@ -160,7 +162,7 @@ _dal_mpool_alloc_comon(dal_mpool_mem_t* ptr, int size, int type) } void* -dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) +dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type) { dal_mpool_mem_t* ptr = NULL; dal_mpool_mem_t* new_ptr = NULL; @@ -186,7 +188,7 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } break; case DAL_MPOOL_TYPE_DESC: - ptr = p_desc_pool; + ptr = p_desc_pool[lchip]; new_ptr = _dal_mpool_alloc_comon(ptr, size, type); if (NULL == new_ptr) { @@ -195,7 +197,7 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } break; case DAL_MPOOL_TYPE_DATA: - ptr = p_data_pool; + ptr = p_data_pool[lchip]; new_ptr = _dal_mpool_alloc_comon(ptr, size, type); if (NULL == new_ptr) { @@ -210,6 +212,10 @@ dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type) } MPOOL_UNLOCK(); + if( NULL == new_ptr ) + { + return NULL; + } return new_ptr->address; } @@ -242,7 +248,7 @@ _dal_mpool_free(dal_mpool_mem_t* ptr, void* addr, int type) } void -dal_mpool_free(dal_mpool_mem_t* pool, void* addr) +dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr) { dal_mpool_mem_t* ptr = pool; @@ -255,11 +261,11 @@ dal_mpool_free(dal_mpool_mem_t* pool, void* addr) _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_USELESS); break; case DAL_MPOOL_TYPE_DESC: - ptr = p_desc_pool; + ptr = p_desc_pool[lchip]; _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DESC); break; case DAL_MPOOL_TYPE_DATA: - ptr = p_data_pool; + ptr = p_data_pool[lchip]; _dal_mpool_free(ptr, addr, DAL_MPOOL_TYPE_DATA); break; default: @@ -271,7 +277,7 @@ dal_mpool_free(dal_mpool_mem_t* pool, void* addr) } int -dal_mpool_destroy(dal_mpool_mem_t* pool) +dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool) { dal_mpool_mem_t* ptr, * next; @@ -283,13 +289,13 @@ dal_mpool_destroy(dal_mpool_mem_t* pool) DAL_FREE(ptr); } - for (ptr = p_desc_pool; ptr; ptr = next) + for (ptr = p_desc_pool[lchip]; ptr; ptr = next) { next = ptr->next; DAL_FREE(ptr); } - for (ptr = p_data_pool; ptr; ptr = next) + for (ptr = p_data_pool[lchip]; ptr; ptr = next) { next = ptr->next; DAL_FREE(ptr); @@ -341,3 +347,4 @@ dal_mpool_debug(dal_mpool_mem_t* pool) return 0; } + diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.h b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.h index a1fa37d05f82..d93f88868136 100644 --- a/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.h +++ b/platform/centec/sonic-platform-modules-e582/48x6q/modules/dal_mpool.h @@ -47,16 +47,16 @@ extern int dal_mpool_init(void); extern dal_mpool_mem_t* -dal_mpool_create(void* base_ptr, int size); +dal_mpool_create(unsigned char lchip, void* base_ptr, int size); extern void* -dal_mpool_alloc(dal_mpool_mem_t* pool, int size, int type); +dal_mpool_alloc(unsigned char lchip, dal_mpool_mem_t* pool, int size, int type); extern void -dal_mpool_free(dal_mpool_mem_t* pool, void* addr); +dal_mpool_free(unsigned char lchip, dal_mpool_mem_t* pool, void* addr); extern int -dal_mpool_destroy(dal_mpool_mem_t* pool); +dal_mpool_destroy(unsigned char lchip, dal_mpool_mem_t* pool); extern int dal_mpool_usage(dal_mpool_mem_t* pool, int type); @@ -69,3 +69,4 @@ dal_mpool_debug(dal_mpool_mem_t* pool); #endif /* !_DMA_MPOOL_H */ + diff --git a/platform/centec/sonic-platform-modules-e582/48x6q/service/48x6q_platform.service b/platform/centec/sonic-platform-modules-e582/48x6q/service/48x6q_platform.service new file mode 100644 index 000000000000..ad9b1fb1b3a7 --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/48x6q/service/48x6q_platform.service @@ -0,0 +1,13 @@ +[Unit] +Description=Centec e582 48x6q platform modules +After=local-fs.target +Before=pmon.service + +[Service] +Type=oneshot +ExecStart=-/etc/init.d/platform-modules-e582-48x6q start +ExecStop=-/etc/init.d/platform-modules-e582-48x6q stop +RemainAfterExit=yes + +[Install] +WantedBy=multi-user.target diff --git a/platform/centec/sonic-platform-modules-e582/debian/changelog b/platform/centec/sonic-platform-modules-e582/debian/changelog index d6f8d9ed26d4..3f4ff89c1bee 100644 --- a/platform/centec/sonic-platform-modules-e582/debian/changelog +++ b/platform/centec/sonic-platform-modules-e582/debian/changelog @@ -2,10 +2,10 @@ sonic-centec-platform-modules (1.1) unstable; urgency=low * Add support for centec e582-48x2q4z - -- xuwj Thus, 25 Jan 2018 13:43:40 +0800 + -- yangbs Thu, 25 Jan 2018 13:43:40 +0800 sonic-centec-platform-modules (1.0) unstable; urgency=low * Initial release - -- xuwj Mon, 22 Jan 2018 13:43:40 +0800 + -- yangbs Mon, 22 Jan 2018 13:43:40 +0800 diff --git a/platform/centec/sonic-platform-modules-e582/debian/control b/platform/centec/sonic-platform-modules-e582/debian/control index 103b6eca242d..93939f7dad73 100644 --- a/platform/centec/sonic-platform-modules-e582/debian/control +++ b/platform/centec/sonic-platform-modules-e582/debian/control @@ -7,11 +7,11 @@ Standards-Version: 3.9.3 Package: platform-modules-e582-48x2q4z Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 +Depends: linux-image-4.9.0-7-amd64 Description: kernel modules for platform devices such as fan, led, sfp Package: platform-modules-e582-48x6q Architecture: amd64 -Depends: linux-image-3.16.0-5-amd64 +Depends: linux-image-4.9.0-7-amd64 Description: kernel modules for platform devices such as fan, led, sfp diff --git a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.install b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.install index 86569b323b1a..9bd1181e860f 100644 --- a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.install +++ b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.install @@ -1,2 +1,6 @@ 48x2q4z/cfg/48x2q4z-modules.conf etc/modules-load.d +48x2q4z/cfg/config_db.json etc/sonic +48x2q4z/cfg/config_db_l2l3.json etc/sonic 48x2q4z/scripts/48x2q4z_platform.sh usr/bin +48x2q4z/scripts/48x2q4z_platform_monitor.py usr/bin +48x2q4z/service/48x2q4z_platform.service lib/systemd/system diff --git a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.postinst b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.postinst new file mode 100644 index 000000000000..b4a1fcbe4e6c --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x2q4z.postinst @@ -0,0 +1,3 @@ +depmod -a +systemctl enable 48x2q4z_platform.service +systemctl start 48x2q4z_platform.service diff --git a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.install b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.install index 7ec21f33784d..a6d26ce329bc 100644 --- a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.install +++ b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.install @@ -1,6 +1,6 @@ 48x6q/cfg/48x6q-modules.conf etc/modules-load.d -48x6q/cfg/minigraph.xml etc/sonic 48x6q/cfg/config_db.json etc/sonic 48x6q/cfg/config_db_l2l3.json etc/sonic 48x6q/scripts/48x6q_platform.sh usr/bin 48x6q/scripts/48x6q_platform_monitor.py usr/bin +48x6q/service/48x6q_platform.service lib/systemd/system diff --git a/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.postinst b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.postinst new file mode 100644 index 000000000000..fea0c4eebda8 --- /dev/null +++ b/platform/centec/sonic-platform-modules-e582/debian/platform-modules-e582-48x6q.postinst @@ -0,0 +1,3 @@ +depmod -a +systemctl enable 48x6q_platform.service +systemctl start 48x6q_platform.service