From 65cd247a0acca7c14b7e320415da8f3665d73a69 Mon Sep 17 00:00:00 2001 From: "shaohua.xiong" Date: Fri, 23 Feb 2018 16:25:05 +0800 Subject: [PATCH 01/21] add platform support for ag6248c and ag6248c_poe --- .../loader-initrd-files/src/bin/swiget | 9 + .../loader-initrd-files/src/bin/swimount | 23 +- .../src/bootmodes/installed | 4 +- .../lib/platform-config-defaults-uboot.yml | 7 + .../src/python/onl/install/BaseInstall.py | 228 +- .../src/python/onl/install/InstallUtils.py | 57 + .../src/python/onl/mounts/__init__.py | 40 +- .../src/python/onl/platform/base.py | 4 + .../3.2-lts/configs/arm-iproc-all/Makefile | 2 +- .../arm-iproc-all/arm-iproc-all.config | 4 +- ...latform-delta-ag6248c-device-drivers.patch | 181 ++ .../configs/arm-iproc-all/patches/series | 1 + packages/platforms/delta/armel/Makefile | 1 + .../delta/armel/arm-delta-ag6248c/Makefile | 1 + .../delta/armel/arm-delta-ag6248c/README.md | 25 + .../arm-delta-ag6248c-poe/.gitignore | 1 + .../arm-delta-ag6248c-poe/Makefile | 1 + .../arm-delta-ag6248c-poe/modules/Makefile | 1 + .../arm-delta-ag6248c-poe/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 2 + .../modules/builds/Makefile | 6 + .../builds/arm-delta-ag6248c-poe-cpld-mux-1.c | 242 +++ .../builds/arm-delta-ag6248c-poe-cpld-mux-2.c | 243 +++ .../arm-delta-ag6248c-poe/onlp/Makefile | 1 + .../arm-delta-ag6248c-poe/onlp/PKG.yml | 1 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 44 + .../lib/libonlp-arm-delta-ag6248c-poe.mk | 10 + .../onlp/builds/onlpdump/Makefile | 45 + .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../r0/src/lib/arm-delta-ag6248c-poe-r0.yml | 42 + .../arm_delta_ag6248c_poe_r0/__init__.py | 21 + .../arm-delta-ag6248c/.gitignore | 2 + .../arm-delta-ag6248c/Makefile | 1 + .../arm-delta-ag6248c/modules/Makefile | 1 + .../arm-delta-ag6248c/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 2 + .../arm-delta-ag6248c/modules/builds/Makefile | 6 + .../builds/arm-delta-ag6248c-cpld-mux-1.c | 242 +++ .../builds/arm-delta-ag6248c-cpld-mux-2.c | 243 +++ .../arm-delta-ag6248c/onlp/Makefile | 1 + .../arm-delta-ag6248c/onlp/PKG.yml | 1 + .../arm-delta-ag6248c/onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 44 + .../builds/lib/libonlp-arm-delta-ag6248c.mk | 10 + .../onlp/builds/onlpdump/Makefile | 45 + .../platform-config/Makefile | 1 + .../platform-config/r0/Makefile | 1 + .../platform-config/r0/PKG.yml | 1 + .../r0/src/lib/arm-delta-ag6248c-r0.yml | 43 + .../python/arm_delta_ag6248c_r0/__init__.py | 23 + .../src/arm_delta_ag6248c/.gitignore | 2 + .../src/arm_delta_ag6248c/.module | 1 + .../src/arm_delta_ag6248c/Makefile | 28 + .../arm_delta_ag6248c/arm_delta_ag6248c.doxy | 1869 +++++++++++++++++ .../arm_delta_ag6248c/arm_delta_ag6248c.mk | 13 + .../module/auto/arm_delta_ag6248c.yml | 67 + .../src/arm_delta_ag6248c/module/auto/make.mk | 28 + .../inc/arm_delta_ag6248c/arm_delta_ag6248c.x | 34 + .../arm_delta_ag6248c_config.h | 162 ++ .../arm_delta_ag6248c/arm_delta_ag6248c_dox.h | 51 + .../arm_delta_ag6248c_porting.h | 132 ++ .../src/arm_delta_ag6248c/module/make.mk | 29 + .../src/arm_delta_ag6248c/module/src/Makefile | 30 + .../module/src/arm_delta_ag6248c_config.c | 101 + .../module/src/arm_delta_ag6248c_enums.c | 30 + .../module/src/arm_delta_ag6248c_int.h | 32 + .../module/src/arm_delta_ag6248c_log.c | 38 + .../module/src/arm_delta_ag6248c_log.h | 32 + .../module/src/arm_delta_ag6248c_module.c | 44 + .../module/src/arm_delta_ag6248c_ucli.c | 82 + .../module/src/arm_delta_i2c.c | 141 ++ .../module/src/arm_delta_i2c.h | 54 + .../src/arm_delta_ag6248c/module/src/fani.c | 470 +++++ .../src/arm_delta_ag6248c/module/src/ledi.c | 375 ++++ .../src/arm_delta_ag6248c/module/src/make.mk | 29 + .../module/src/platform_lib.c | 85 + .../module/src/platform_lib.h | 136 ++ .../src/arm_delta_ag6248c/module/src/psui.c | 381 ++++ .../src/arm_delta_ag6248c/module/src/sfpi.c | 364 ++++ .../src/arm_delta_ag6248c/module/src/sysi.c | 290 +++ .../arm_delta_ag6248c/module/src/thermali.c | 208 ++ .../platforms/delta/armel/modules/Makefile | 1 + .../platforms/delta/armel/modules/PKG.yml | 1 + 86 files changed, 7248 insertions(+), 15 deletions(-) create mode 100644 packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/platform-delta-ag6248c-device-drivers.patch create mode 100644 packages/platforms/delta/armel/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/README.md create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/.gitignore create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/PKG.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/.gitignore create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/PKG.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/libonlp-arm-delta-ag6248c-poe.mk create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/onlpdump/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/PKG.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/lib/arm-delta-ag6248c-poe-r0.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/python/arm_delta_ag6248c_poe_r0/__init__.py create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/.gitignore create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/PKG.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/.gitignore create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/Makefile create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/PKG.yml create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/libonlp-arm-delta-ag6248c.mk create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/PKG.yml create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/lib/arm-delta-ag6248c-r0.yml create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/python/arm_delta_ag6248c_r0/__init__.py create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.gitignore create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.module create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.doxy create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.mk create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/make.mk create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/make.mk create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/Makefile create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/ledi.c create mode 100644 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/make.mk create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.h create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/psui.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sfpi.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c create mode 100755 packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/thermali.c create mode 100644 packages/platforms/delta/armel/modules/Makefile create mode 100644 packages/platforms/delta/armel/modules/PKG.yml diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/swiget b/packages/base/all/initrds/loader-initrd-files/src/bin/swiget index 841ea130..3bee3891 100755 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/swiget +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/swiget @@ -19,6 +19,7 @@ import zipfile import onl.install.InstallUtils MountContext = onl.install.InstallUtils.MountContext BlkidParser = onl.install.InstallUtils.BlkidParser +UbinfoParser = onl.install.InstallUtils.UbinfoParser ProcMountsParser = onl.install.InstallUtils.ProcMountsParser import onl.mounts @@ -247,6 +248,14 @@ class Runner(onl.install.InstallUtils.SubprocessMixin): part = blkid[label] except IndexError: part = None + if part is None: + ubinfo = UbinfoParser(log=self.log) + part = {} + part = ubinfo[label] + device = "/dev/" + part['device'] + "_" + part['Volume ID'] + + return self.blockdevCopy(device, r, dir=mpt) + if part is not None: return self.blockdevCopy(part.device, r, dir=mpt) diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/swimount b/packages/base/all/initrds/loader-initrd-files/src/bin/swimount index b7ea1879..2741b5bd 100755 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/swimount +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/swimount @@ -11,6 +11,7 @@ import logging import onl.install.InstallUtils BlkidParser = onl.install.InstallUtils.BlkidParser +UbinfoParser = onl.install.InstallUtils.UbinfoParser import onl.mounts MountContext = onl.install.InstallUtils.MountContext @@ -26,6 +27,7 @@ class Runner(onl.install.InstallUtils.SubprocessMixin): self.log = log self.blkid = BlkidParser(log=self.log) + self.ubinfo = UbinfoParser(log=self.log) def mount(self, SWI): @@ -125,6 +127,13 @@ class Runner(onl.install.InstallUtils.SubprocessMixin): part = self.blkid[label] except IndexError: part = None + if part is None: + part = {} + part = self.ubinfo[label] + + device = "/dev/" + part['device'] + "_" + part['Volume ID'] + + return self.blockdevMount(device, path, dir=mpt) if part is not None: return self.blockdevMount(part.device, path, dir=mpt) @@ -141,7 +150,12 @@ class Runner(onl.install.InstallUtils.SubprocessMixin): if not os.path.exists(dst): self.log.error("missing SWI: %s", dst) return None - self.check_call(('mount', '-o', 'rw,remount', dst,)) + p = dev.find('ubi') + if p < 0: + self.check_call(('mount', '-o', 'rw,remount', dst,)) + else: + self.check_call(('mount', '-t', 'ubifs', '-o', 'rw,remount', dst,)) + return dst with MountContext(device=dev, log=self.log) as ctx: @@ -154,7 +168,12 @@ class Runner(onl.install.InstallUtils.SubprocessMixin): # move to its proper location as per mtab # XXX perms may not be right here if dir is not None: - self.check_call(('mount', '-o', 'rw,remount', ctx.dir,)) + p = dev.find('ubi') + if p < 0: + self.check_call(('mount', '-o', 'rw,remount', ctx.dir,)) + else: + self.check_call(('mount', '-t', 'ubifs', '-o', 'rw,remount', ctx.dir,)) + self.check_call(('mount', '--move', ctx.dir, dir,)) ctx.mounted = False dst = dir diff --git a/packages/base/all/initrds/loader-initrd-files/src/bootmodes/installed b/packages/base/all/initrds/loader-initrd-files/src/bootmodes/installed index 00aa3a41..dc0e887b 100755 --- a/packages/base/all/initrds/loader-initrd-files/src/bootmodes/installed +++ b/packages/base/all/initrds/loader-initrd-files/src/bootmodes/installed @@ -15,8 +15,8 @@ if [ ! -d /mnt/onl/data ]; then fi # make sure it's mounted as per mtab.yml -d1=$(stat -f -c '%d' /mnt/onl) -d2=$(stat -f -c '%d' /mnt/onl/data) +d1=$(stat -f -c '%b' /mnt/onl) +d2=$(stat -f -c '%b' /mnt/onl/data) if [ "$d1" -eq "$d2" ]; then msg_error "Unmounted /mnt/onl/data, disk boot cannot continue" exit 200 diff --git a/packages/base/all/vendor-config-onl/src/lib/platform-config-defaults-uboot.yml b/packages/base/all/vendor-config-onl/src/lib/platform-config-defaults-uboot.yml index 4ad068fb..6b66f8c6 100644 --- a/packages/base/all/vendor-config-onl/src/lib/platform-config-defaults-uboot.yml +++ b/packages/base/all/vendor-config-onl/src/lib/platform-config-defaults-uboot.yml @@ -129,6 +129,13 @@ default: - ext2load mmc 0:1 $onl_loadaddr $onl_itb - "bootm $onl_loadaddr#$onl_platform" + #ubifs to boot onl + flash_bootcmds: &flash_bootcmds + - ubi part open + - ubifsmount ONL-BOOT + - ubifsload $loadaddr $onl_itb + - "bootm $onl_loadaddr#$onl_platform" + nos_bootcmds: *ide_bootcmds # Configure the fw_env.config file, diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py index 10878bce..3290ec34 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/BaseInstall.py @@ -17,7 +17,7 @@ import imp import fnmatch, glob from InstallUtils import SubprocessMixin -from InstallUtils import MountContext, BlkidParser, PartedParser +from InstallUtils import MountContext, BlkidParser, PartedParser, UbinfoParser from InstallUtils import ProcMountsParser from InstallUtils import GdiskParser from InstallUtils import OnieSubprocess @@ -83,6 +83,7 @@ class Base: # keep track of next partition/next block self.blkidParts = [] + self.ubiParts = [] # current scan of partitions and labels self.partedDevice = None @@ -853,7 +854,203 @@ class GrubInstaller(SubprocessMixin, Base): def shutdown(self): Base.shutdown(self) -class UbootInstaller(SubprocessMixin, Base): +class UBIfsCreater(SubprocessMixin, Base): + + def __init__(self, *args, **kwargs): + Base.__init__(self, *args, **kwargs) + self.log = logging.getLogger("ubinfo -a") + self.device = self.im.getDevice() + self.ubiParts = None + """Set up an UBI file system.""" + + def ubifsinit(self): + UNITS = { + 'GiB' : 1024 * 1024 * 1024, + 'G' : 1000 * 1000 * 1000, + 'MiB' : 1024 * 1024, + 'M' : 1000 * 1000, + 'KiB' : 1024, + 'K' : 1000, + } + try: + code = 0 + if not code: + mtd_num = self.device[-1] + cmd = ('ubiformat', '/dev/mtd' + mtd_num) + self.check_call(cmd, vmode=self.V2) + cmd = ('ubiattach', '-m', mtd_num, '-d', '0', '/dev/ubi_ctrl',) + self.check_call(cmd, vmode=self.V2) + for part in self.im.platformConf['installer']: + label, partData = list(part.items())[0] + if type(partData) == dict: + sz, fmt = partData['='], partData.get('format', 'ubifs') + else: + sz, fmt = partData, 'ubifs' + cnt = None + for ul, ub in UNITS.items(): + if sz.endswith(ul): + cnt = int(sz[:-len(ul)], 10) * ub + break + if cnt is None: + self.log.error("invalid size (no units) for %s: %s",part, sz) + return 1 + label = label.strip() + cmd = ('ubimkvol', '/dev/ubi0', '-N', label, '-s', bytes(cnt),) + self.check_call(cmd, vmode=self.V2) + except Exception: + self.log.exception("cannot create UBI file systemfrom %s",self.device) + + return 0 + + def ubi_mount(self, dir, devpart): + + if devpart is None: + self.log.error("Mount failed.no given mount device part") + return 1 + if dir is None: + self.log.error("Mount failed.no given mount directory") + return 1 + if self.ubiParts is None: + try: + self.ubiParts = UbinfoParser(log=self.log.getChild("ubinfo -a")) + except Exception: + self.log.exception("Mount failed.No UBIfs") + return 1 + try: + dev = self.ubiParts[devpart] + except IndexError as ex: + self.log.error("Mount failed.cannot find %s partition", str(devpart)) + return 1 + self.makedirs(dir) + device = "/dev/" + dev['device'] + "_" + dev['Volume ID'] + if dev['fsType']: + cmd = ('mount', '-t', dev['fsType'], device, dir,) + else: + cmd = ('mount', device, dir,) + code = self.check_call(cmd, vmode=self.V2) + if code: + self.log.error("Mount failed.mount command exect failed") + return 1 + return 0 + + def ubi_unmount(self,dir=None): + + if dir is None: + self.log.error("Unmount failed.no given unmount directory") + return 1 + cmd = ('umount', dir) + code = self.check_call(cmd, vmode=self.V2) + if code: + self.log.error("Unmount failed.umount command exect failed") + return 1 + return 0 + + def ubi_getinfo(self): + try: + self.ubiParts = UbinfoParser(log=self.log.getChild("ubinfo -a")) + except Exception: + self.log.exception("UBI info get failed.No UBIfs") + return 1 + return 0 + + def ubi_installSwi(self): + + files = os.listdir(self.im.installerConf.installer_dir) + self.zf.namelist() + + swis = [x for x in files if x.endswith('.swi')] + + if not swis: + self.log.warn("No ONL Software Image available for ubi installation.") + self.log.warn("Post-install ZTN installation will be required.") + + if len(swis) > 1: + self.log.error("Multiple SWIs found in ubi installer: %s", " ".join(swis)) + return 1 + + base = swis[0] + + self.log.info("Installing ONL Software Image (%s)...", base) + dev = "ONL-IMAGES" + dstDir = "/tmp/ubifs" + code = self.ubi_mount(dstDir,dev) + if code : + return 1 + dst = os.path.join(dstDir, base) + self.installerCopy(base, dst) + self.log.info("syncing block devices(%s)...",dev) + self.check_call(('sync',)) + self.ubi_unmount(dstDir) + return 0 + + def ubi_installLoader(self): + + loaderBasename = None + for c in sysconfig.installer.fit: + if self.installerExists(c): + loaderBasename = c + break + if not loaderBasename: + self.log.error("The platform loader file is missing.") + return 1 + + self.log.info("Installing the ONL loader from %s...", loaderBasename) + dev = "ONL-BOOT" + dstDir = "/tmp/ubiloader" + code = self.ubi_mount(dstDir,dev) + if code : + return 1 + dst = os.path.join(dstDir, "%s.itb" % self.im.installerConf.installer_platform) + self.installerCopy(loaderBasename, dst) + self.log.info("syncing block devices(%s)...",dev) + self.check_call(('sync',)) + self.ubi_unmount(dstDir) + return 0 + + def ubi_installBootConfig(self): + + basename = 'boot-config' + + self.log.info("Installing boot-config to ONL-BOOT partion") + dev = "ONL-BOOT" + dstDir = "/tmp/ubibootcon" + code = self.ubi_mount(dstDir,dev) + if code : + return 1 + dst = os.path.join(dstDir, basename) + self.installerCopy(basename, dst, True) + with open(dst) as fd: + buf = fd.read() + ecf = buf.encode('base64', 'strict').strip() + if self.im.grub and self.im.grubEnv is not None: + setattr(self.im.grubEnv, 'boot_config_default', ecf) + if self.im.uboot and self.im.ubootEnv is not None: + setattr(self.im.ubootEnv, 'boot-config-default', ecf) + self.log.info("syncing block devices(%s)...",dev) + self.check_call(('sync',)) + self.ubi_unmount(dstDir) + return 0 + + def ubi_installOnlConfig(self): + + self.log.info("Installing onl-config to ONL-CONFIG partion") + dev = "ONL-CONFIG" + dstDir = "/tmp/ubionlconfig" + code = self.ubi_mount(dstDir,dev) + if code : + return 1 + for f in self.zf.namelist(): + d = 'config/' + if f.startswith(d) and f != d: + dst = os.path.join(dstDir, os.path.basename(f)) + if not os.path.exists(dst): + self.installerCopy(f, dst) + self.log.info("syncing block devices(%s)...",dev) + self.check_call(('sync',)) + self.ubi_unmount(dstDir) + return 0 + + +class UbootInstaller(SubprocessMixin, UBIfsCreater): class installmeta(Base.installmeta): @@ -874,13 +1071,16 @@ class UbootInstaller(SubprocessMixin, Base): cmds.append("setenv onl_itb %s" % itb) for item in self.platformConf['loader']['setenv']: k, v = list(item.items())[0] - cmds.append("setenv %s %s" % (k, v,)) + device = self.getDevice() + if "mtdblock" in device: + cmds.append("setenv %s %s ${platformargs} ubi.mtd=%s root=/dev/ram ethaddr=$ethaddr" % (k, v, device[-1],)) + else: + cmds.append("setenv %s %s" % (k, v,)) cmds.extend(self.platformConf['loader']['nos_bootcmds']) return "; ".join(cmds) def __init__(self, *args, **kwargs): - Base.__init__(self, *args, **kwargs) - + UBIfsCreater.__init__(self, *args, **kwargs) self.device = self.im.getDevice() self.rawLoaderDevice = None @@ -1014,6 +1214,24 @@ class UbootInstaller(SubprocessMixin, Base): code = self.assertUnmounted() if code: return code + + if "mtdblock" in self.device: + code = self.ubifsinit() + if code: return code + code = self.ubi_getinfo() + if code: return code + code = self.ubi_installSwi() + if code: return code + code = self.ubi_installLoader() + if code: return code + code = self.ubi_installBootConfig() + if code: return code + code = self.ubi_installOnlConfig() + if code: return code + code = self.runPlugins(Plugin.PLUGIN_POSTINSTALL) + if code: return code + code = self.installUbootEnv() + return code code = self.maybeCreateLabel() if code: return code diff --git a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py index ccb4615e..85fe2c01 100644 --- a/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/install/InstallUtils.py @@ -388,6 +388,63 @@ class BlkidParser(SubprocessMixin): def __len__(self): return len(self.parts) +class UbinfoParser(SubprocessMixin): + + def __init__(self, log=None): + self.log = log or logging.getLogger("ubinfo -a") + self.parse() + + def parse(self): + self.parts = [] + lines = '' + try: + cmd = ('ubinfo', '-a',) + lines = self.check_output(cmd).splitlines() + except Exception as ex: + return self + + dev = None + volId = None + name = None + attrs = {} + for line in lines: + line = line.strip() + + p = line.find(':') + if p < 0: continue + name, value = line[:p], line[p+1:].strip() + if 'Volume ID' in name: + p = value.find('(') + if p < 0: continue + volumeId = value[:p].strip() + attrs['Volume ID'] = volumeId + p = value.find('on') + if p < 0: continue + dev = value[p+2:-1].strip() + attrs['device'] = dev + + if 'Name' in name: + dev = "/dev/" + dev + "_" + volumeId + p = line.find(':') + if p < 0: continue + attrs['Name'] = line[p+1:].strip() + attrs['fsType'] = 'ubifs' + self.parts.append(attrs) + dev = None + volId = None + name = None + attrs = {} + + def __getitem__(self, idxOrName): + if type(idxOrName) == int: + return self.parts[idxOrName] + for part in self.parts: + if part['Name'] == idxOrName: return part + raise IndexError("cannot find partition %s" % repr(idxOrName)) + + def __len__(self): + return len(self.parts) + class ProcMtdEntry: def __init__(self, diff --git a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py index bf591df6..e6d24391 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/mounts/__init__.py @@ -63,7 +63,12 @@ class MountManager(object): self.logger.debug("%s not mounted @ %s. It will be mounted %s" % (device, directory, mode)) try: - cmd = "mount -o %s %s %s" % (','.join(mountargs), device, directory) + p = device.find('ubi') + if p < 0: + cmd = "mount -o %s %s %s" % (','.join(mountargs), device, directory) + else: + cmd = "mount -o %s -t %s %s %s" % (','.join(mountargs), 'ubifs', device, directory) + self.logger.debug("+ %s" % cmd) subprocess.check_call(cmd, shell=True) except subprocess.CalledProcessError, e: @@ -148,12 +153,39 @@ class OnlMountManager(object): def _discover(k): v = md[k] lbl = v.get('label', k) - + useUbiDev = False try: v['device'] = subprocess.check_output(('blkid', '-L', lbl,)).strip() except subprocess.CalledProcessError: - return False - + useUbiDev = True + if useUbiDev == True: + if k == 'EFI-BOOT': + return False + output = subprocess.check_output("ubinfo -d 0 -N %s" % k, shell=True).splitlines() + volumeId = None + device = None + for line in output: + line = line.strip() + p = line.find(':') + if p < 0: + self.logger.debug("Invaild ubinfo output %s" % line) + + name, value = line[:p], line[p+1:].strip() + if 'Volume ID' in name: + p = value.find('(') + if p < 0: + self.logger.debug("Invalid Volume ID %s" % value) + + volumeId = value[:p].strip() + p = value.find('on') + if p < 0: + self.logger.debug("Invalid ubi devicde %s" % value) + + device = value[p+2:-1].strip() + if 'Name' in name: + v['device'] = "/dev/" + device + "_" + volumeId + + if not os.path.isdir(v['dir']): self.logger.debug("Make directory '%s'...", v['dir']) os.makedirs(v['dir']) diff --git a/packages/base/all/vendor-config-onl/src/python/onl/platform/base.py b/packages/base/all/vendor-config-onl/src/python/onl/platform/base.py index b0849cf8..a2d00feb 100755 --- a/packages/base/all/vendor-config-onl/src/python/onl/platform/base.py +++ b/packages/base/all/vendor-config-onl/src/python/onl/platform/base.py @@ -477,6 +477,10 @@ class OnlPlatformPortConfig_48x1_4x10(object): PORT_COUNT=52 PORT_CONFIG="48x1 + 4x10" +class OnlPlatformPortConfig_48x1_2x10(object): + PORT_COUNT=50 + PORT_CONFIG="48x1 + 2x10" + class OnlPlatformPortConfig_48x10_4x40(object): PORT_COUNT=52 PORT_CONFIG="48x10 + 4x40" diff --git a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/Makefile b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/Makefile index b16fc9d4..49f02b06 100644 --- a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/Makefile +++ b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/Makefile @@ -38,6 +38,6 @@ K_COPY_DST := kernel-3.2-lts-arm-iproc-all.bin.gz endif export ARCH=arm -DTS_LIST := accton_as4610_54 +DTS_LIST := accton_as4610_54 delta_ag6248c include $(ONL)/make/kbuild.mk diff --git a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/arm-iproc-all.config b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/arm-iproc-all.config index 4df4b2f3..e70dd3b3 100644 --- a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/arm-iproc-all.config +++ b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/arm-iproc-all.config @@ -289,6 +289,7 @@ CONFIG_BCM_RAM_START_RESERVED_SIZE=0x200000 # CONFIG_MACH_GH is not set # CONFIG_MACH_DNI_3448P is not set CONFIG_MACH_ACCTON_AS4610_54=y +CONFIG_MACH_DELTA_AG6248C=y # CONFIG_MACH_IPROC_EMULATION is not set # @@ -1938,7 +1939,8 @@ CONFIG_IPROC_QSPI_SINGLE_MODE=y # CONFIG_IPROC_QSPI_DUAL_MODE is not set # CONFIG_IPROC_QSPI_QUAD_MODE is not set CONFIG_IPROC_QSPI_MAX_HZ=62500000 -# CONFIG_IPROC_MTD_NAND is not set +CONFIG_IPROC_MTD_NAND=y +# CONFIG_IPROC_MTD_NAND_USE_JFFS2 is not set # CONFIG_IPROC_PWM is not set CONFIG_IPROC_USB2H=y CONFIG_USB_EHCI_BCM=y diff --git a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/platform-delta-ag6248c-device-drivers.patch b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/platform-delta-ag6248c-device-drivers.patch new file mode 100644 index 00000000..6dd2774b --- /dev/null +++ b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/platform-delta-ag6248c-device-drivers.patch @@ -0,0 +1,181 @@ +diff --git a/arch/arm/boot/dts/delta_ag6248c.dts b/arch/arm/boot/dts/delta_ag6248c.dts +new file mode 100755 +index 0000000..f86c35b +--- /dev/null ++++ b/arch/arm/boot/dts/delta_ag6248c.dts +@@ -0,0 +1,78 @@ ++/* ++ * Delta Networks, Inc. AG6248C Device Tree Source ++ * ++ * Copyright 2015, Cumulus Networks, Inc. ++ * ++ * 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. ++ * ++ */ ++/dts-v1/; ++/include/ "helix4.dtsi" ++ ++/ { ++ model = "delta,ag6248c"; ++ compatible = "delta,ag6248c"; ++ ++ aliases { ++ serial0 = &uart0; ++ i2c-controller0 = &i2c0; ++ i2c-controller1 = &i2c1; ++ }; ++ ++ memory { ++ reg = <0x61000000 0x7f000000>; ++ }; ++ ++ cpus { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ cpu@0 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a9"; ++ next-level-cache = <&L2>; ++ reg = <0x00>; ++ }; ++ cpu@1 { ++ device_type = "cpu"; ++ compatible = "arm,cortex-a9"; ++ next-level-cache = <&L2>; ++ reg = <0x01>; ++ }; ++ }; ++ ++ localbus@1e000000{ ++ address-cells = <0x2>; ++ #size-cells = <0x1>; ++ compatible = "simple-bus"; ++ ranges = <0x0 0x0 0x1e000000 0x02000000>; ++ ++ }; ++ ++ i2c0: i2c@18038000 { ++ compatible = "iproc-smb"; ++ reg = <0x18038000 0x1000>; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ interrupts = < 127 >; ++ clock-frequency = <400000>; ++ rtc@68 { ++ compatible = "m41st85"; ++ reg = <0x68>; ++ }; ++ }; ++ ++ ++ i2c1: i2c@1803b000 { ++ compatible = "iproc-smb"; ++ reg = <0x1803b000 0x1000>; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ interrupts = < 128 >; ++ clock-frequency = <100000>; ++ ++ }; ++}; +diff --git a/arch/arm/mach-iproc/Kconfig b/arch/arm/mach-iproc/Kconfig +index c77208d..c6a87fc 100644 +--- a/arch/arm/mach-iproc/Kconfig ++++ b/arch/arm/mach-iproc/Kconfig +@@ -49,6 +49,12 @@ config MACH_ACCTON_AS4610_54 + help + Support for Accton AS4610-54 POE and non -POE board. + ++config MACH_DELTA_AG6248C ++ select ARM_L1_CACHE_SHIFT_6 ++ bool "Support Delta AG6248C board" ++ help ++ Support for Delta AG6248C board. ++ + config MACH_IPROC_P7 + bool "Support iProc Profile 7 architecture" + depends on MACH_GH +diff --git a/arch/arm/mach-iproc/board_bu.c b/arch/arm/mach-iproc/board_bu.c +index 7e07ed1..5479020 100644 +--- a/arch/arm/mach-iproc/board_bu.c ++++ b/arch/arm/mach-iproc/board_bu.c +@@ -1083,6 +1083,7 @@ MACHINE_END + static const char * helix4_dt_board_compat[] = { + "dni,dni_3448p", + "accton,as4610_54", ++ "delta,ag6248c", + NULL + }; + +diff --git a/arch/arm/mach-iproc/common.c b/arch/arm/mach-iproc/common.c +index b116ffc..e911a2b 100644 +--- a/arch/arm/mach-iproc/common.c ++++ b/arch/arm/mach-iproc/common.c +@@ -187,7 +187,8 @@ static struct platform_device wdt_device = + enum { + HX4_NONE = 0, + HX4_DNI_3448P, +- HX4_ACCTON_AS4610_54 ++ HX4_ACCTON_AS4610_54, ++ HX4_DELTA_AG6248C, + }; + + /* +@@ -212,6 +213,8 @@ int brcm_get_hx4_model(void) + return HX4_DNI_3448P; + else if (!strcmp(model, "accton,as4610_54")) + return HX4_ACCTON_AS4610_54; ++ else if (!strcmp(model, "delta,ag6248c")) ++ return HX4_DELTA_AG6248C; + + printk( KERN_ERR "Unknown Model %s\n", model ); + return HX4_NONE; +diff --git a/arch/arm/mach-iproc/include/mach/iproc_regs.h b/arch/arm/mach-iproc/include/mach/iproc_regs.h +index 460c436..50ea557 100644 +--- a/arch/arm/mach-iproc/include/mach/iproc_regs.h ++++ b/arch/arm/mach-iproc/include/mach/iproc_regs.h +@@ -364,7 +364,11 @@ + #define IPROC_GMAC3_INT 182 + #elif (defined(CONFIG_MACH_HX4) || defined(CONFIG_MACH_KT2) || defined(CONFIG_MACH_DNI_3448P) || \ + defined(CONFIG_MACH_ACCTON_AS4610_54)) ++#if defined(CONFIG_MACH_DELTA_AG6248C) ++#define IPROC_NUM_GMACS 1 ++#else + #define IPROC_NUM_GMACS 2 ++#endif + #define IPROC_GMAC0_REG_BASE (GMAC0_DEVCONTROL) //(0x18022000) + #define IPROC_GMAC1_REG_BASE (GMAC1_DEVCONTROL) //(0x18023000) + #define IPROC_GMAC2_REG_BASE (0) // n/a +diff --git a/drivers/bcmdrivers/gmac/src/shared/nvramstubs.c b/drivers/bcmdrivers/gmac/src/shared/nvramstubs.c +index d5b400d..a823697 100644 +--- a/drivers/bcmdrivers/gmac/src/shared/nvramstubs.c ++++ b/drivers/bcmdrivers/gmac/src/shared/nvramstubs.c +@@ -143,7 +143,8 @@ __setup("envaddr=", envaddr_setup); + enum { + HX4_NONE = 0, + HX4_DNI_3448P, +- HX4_ACCTON_AS4610_54 ++ HX4_ACCTON_AS4610_54, ++ HX4_DELTA_AG6248C + }; + + static void +@@ -158,7 +159,10 @@ setup_uboot_vars(void) { + } else if (modelnum == HX4_ACCTON_AS4610_54) { + env_offset = 0x000f0000; + uboot_vars_start = CONFIG_SPI_BASE + env_offset; +- } ++ }else if (modelnum == HX4_DELTA_AG6248C) { ++ env_offset = 0x00300000; ++ uboot_vars_start = CONFIG_NAND_BASE + env_offset; ++ } + } + + /* +-- +2.1.4 + diff --git a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/series b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/series index e2adb686..3028ed13 100644 --- a/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/series +++ b/packages/base/any/kernels/3.2-lts/configs/arm-iproc-all/patches/series @@ -506,3 +506,4 @@ scripts_package_Makefile.patch tools_include_tools_be_byteshift.h.patch tools_include_tools_le_byteshift.h.patch platform-accton-as4610-device-drivers.patch +platform-delta-ag6248c-device-drivers.patch diff --git a/packages/platforms/delta/armel/Makefile b/packages/platforms/delta/armel/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/README.md b/packages/platforms/delta/armel/arm-delta-ag6248c/README.md new file mode 100644 index 00000000..b49d2126 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/README.md @@ -0,0 +1,25 @@ +#How to run ONL in DELTA AG6248C board + +For the first step, it only support install the ONL to the USB and boot up. +It will be support to install the ONL to NandFlash next step. + +Build the ONL +-------------------------------------------------------------------------- +Please refer the $ONL/docs/Building.md + +Install the ONL through ONIE +-------------------------------------------------------------------------- +``` +ONIE:/ # onie-discovery-stop +discover: installer mode detected. +Stopping: discover... done. +ONIE:/ # +ONIE:/ # ifconfig eth0 192.168.1.1 #configure the DUT IP address +ONIE:/ # tftp -r ONL-2.*_ARMEL_INSTALLED_INSTALLER -g 192.168.1.99 -b 10240 +ONIE:/ # onie-nos-install ONL-2.*_ARMEL_INSTALLED_INSTALLER +``` +Boot the ONL +-------------------------------------------------------------------------- +Device will reboot automatically after install the ONL installer successfull. + +Now it will start the ONL boot progress. diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/.gitignore b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/.gitignore new file mode 100755 index 00000000..9f7b1342 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/.gitignore @@ -0,0 +1 @@ +onlpdump.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/PKG.yml new file mode 100755 index 00000000..4375c960 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml ARCH=armel VENDOR=delta BASENAME=arm-delta-ag6248c-poe KERNELS="onl-kernel-3.2-lts-arm-iproc-all:armel" diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/.gitignore b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/.gitignore new file mode 100755 index 00000000..a813c369 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/.gitignore @@ -0,0 +1,2 @@ +onlpdump.mk +lib diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/Makefile new file mode 100755 index 00000000..98c58425 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.2-lts-arm-iproc-all:armel +KMODULES := $(wildcard *.c) +VENDOR := delta +BASENAME := arm-delta-ag6248c-poe +ARCH := arm +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c new file mode 100755 index 00000000..29686679 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c @@ -0,0 +1,242 @@ +/* + * An I2C multiplexer dirver for delta as5812 CPLD + * + * Copyright (C) 2015 Delta Technology Corporation. + * Brandon Chuang + * + * This module supports the delta cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Delta ag7648c CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define CTRL_CPLD_BUS 0x0 +#define CTRL_CPLD_I2C_ADDR 0x28 +#define PARENT_CHAN 0x0 +#define NUM_OF_CPLD_CHANS 0x2 + +#define CPLD_CHANNEL_SELECT_REG 0x19 +#define CPLD_CHANNEL_SELECT_MASK 0x3 +#define CPLD_CHANNEL_SELECT_OFFSET 0x0 + +#define CPLD_DESELECT_CHANNEL 0xff + +#define CPLD_MUX_MAX_NCHANS 0x2 +enum cpld_mux_type { + delta_cpld_mux +}; + +struct delta_i2c_cpld_mux { + enum cpld_mux_type type; + struct i2c_adapter *virt_adaps[CPLD_MUX_MAX_NCHANS]; + u8 last_chan; /* last register value */ +}; + +struct chip_desc { + u8 nchans; + u8 deselectChan; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [delta_cpld_mux] = { + .nchans = NUM_OF_CPLD_CHANS, + .deselectChan = CPLD_DESELECT_CHANNEL, + } +}; + +static struct delta_i2c_cpld_mux *cpld_mux_data; + +static struct device dump_dev; + +/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() + for this as they will try to lock adapter a second time */ +static int delta_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 val) +{ + unsigned long orig_jiffies; + unsigned short flags; + union i2c_smbus_data data; + struct i2c_adapter *ctrl_adap; + int try; + s32 res = -EIO; + u8 reg_val = 0; + + data.byte = val; + flags = 0; + + ctrl_adap = i2c_get_adapter(CTRL_CPLD_BUS); + if (!ctrl_adap) + return res; + + // try to lock it + if (ctrl_adap->algo->smbus_xfer) { + /* Retry automatically on arbitration loss */ + orig_jiffies = jiffies; + for (res = 0, try = 0; try <= ctrl_adap->retries; try++) { + // read first + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_READ, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + + // modify the field we wanted + data.byte &= ~(CPLD_CHANNEL_SELECT_MASK << CPLD_CHANNEL_SELECT_OFFSET); + reg_val |= ((val & CPLD_CHANNEL_SELECT_MASK) << CPLD_CHANNEL_SELECT_OFFSET); + data.byte |= reg_val; + + // modify the register + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + if (time_after(jiffies, + orig_jiffies + ctrl_adap->timeout)) + break; + } + } + + return res; +} + +static int delta_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, + void *client, u32 chan) +{ + u8 regval; + int ret = 0; + regval = chan; + + /* Only select the channel if its different from the last channel */ + if (cpld_mux_data->last_chan != regval) { + ret = delta_i2c_cpld_mux_reg_write(NULL, NULL, regval); + cpld_mux_data->last_chan = regval; + } + + return ret; +} + +static int delta_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, + void *client, u32 chan) +{ + /* Deselect active channel */ + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; + + return delta_i2c_cpld_mux_reg_write(NULL, NULL, cpld_mux_data->last_chan); +} + +/* + * I2C init/probing/exit functions + */ +static int __delta_i2c_cpld_mux_init(void) +{ + struct i2c_adapter *adap = i2c_get_adapter(PARENT_CHAN); + int chan=0; + int ret = -ENODEV; + + memset (&dump_dev, 0, sizeof(dump_dev)); + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto err; + + if (!adap) + goto err; + + cpld_mux_data = kzalloc(sizeof(struct delta_i2c_cpld_mux), GFP_KERNEL); + if (!cpld_mux_data) { + ret = -ENOMEM; + goto err; + } + + cpld_mux_data->type = delta_cpld_mux; + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; /* force the first selection */ + + /* Now create an adapter for each channel */ + for (chan = 0; chan < NUM_OF_CPLD_CHANS; chan++) { + cpld_mux_data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &dump_dev, NULL, 0, + chan, + delta_i2c_cpld_mux_select_chan, + delta_i2c_cpld_mux_deselect_mux); + + if (cpld_mux_data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + printk("failed to register multiplexed adapter %d, parent %d\n", chan, PARENT_CHAN); + goto virt_reg_failed; + } + } + + printk("registered %d multiplexed busses for I2C mux bus %d\n", + chan, PARENT_CHAN); + + return 0; + +virt_reg_failed: + for (chan--; chan >= 0; chan--) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + } + + kfree(cpld_mux_data); +err: + return ret; +} + +static int __delta_i2c_cpld_mux_remove(void) +{ + const struct chip_desc *chip = &chips[cpld_mux_data->type]; + int chan; + + for (chan = 0; chan < chip->nchans; ++chan) { + if (cpld_mux_data->virt_adaps[chan]) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + cpld_mux_data->virt_adaps[chan] = NULL; + } + } + + kfree(cpld_mux_data); + + return 0; +} + +static int __init delta_i2c_cpld_mux_init(void) +{ + return __delta_i2c_cpld_mux_init (); +} + +static void __exit delta_i2c_cpld_mux_exit(void) +{ + __delta_i2c_cpld_mux_remove (); +} + +MODULE_AUTHOR("Dave Hu "); +MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); +MODULE_LICENSE("GPL"); + +module_init(delta_i2c_cpld_mux_init); +module_exit(delta_i2c_cpld_mux_exit); + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c new file mode 100755 index 00000000..c3354b89 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c @@ -0,0 +1,243 @@ +/* + * An I2C multiplexer dirver for delta as5812 CPLD + * + * Copyright (C) 2015 Delta Technology Corporation. + * Brandon Chuang + * + * This module supports the delta cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Delta ag7648c CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define CTRL_CPLD_BUS 0x0 +#define CTRL_CPLD_I2C_ADDR 0x28 +#define PARENT_CHAN 0x1 +#define NUM_OF_CPLD_CHANS 0x2 + +#define CPLD_CHANNEL_SELECT_REG 0x19 +#define CPLD_CHANNEL_SELECT_MASK 0x3 +#define CPLD_CHANNEL_SELECT_OFFSET 0x5 + +#define CPLD_DESELECT_CHANNEL 0xff + +#define CPLD_MUX_MAX_NCHANS 0x2 +enum cpld_mux_type { + delta_cpld_mux +}; + +struct delta_i2c_cpld_mux { + enum cpld_mux_type type; + struct i2c_adapter *virt_adaps[CPLD_MUX_MAX_NCHANS]; + u8 last_chan; /* last register value */ +}; + +struct chip_desc { + u8 nchans; + u8 deselectChan; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [delta_cpld_mux] = { + .nchans = NUM_OF_CPLD_CHANS, + .deselectChan = CPLD_DESELECT_CHANNEL, + } +}; + +static struct delta_i2c_cpld_mux *cpld_mux_data; + +static struct device dump_dev; + +/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() + for this as they will try to lock adapter a second time */ +static int delta_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 val) +{ + unsigned long orig_jiffies; + unsigned short flags; + union i2c_smbus_data data; + struct i2c_adapter *ctrl_adap; + int try; + s32 res = -EIO; + u8 reg_val = 0; + + data.byte = val; + flags = 0; + + ctrl_adap = i2c_get_adapter(CTRL_CPLD_BUS); + if (!ctrl_adap) + return res; + + + // try to lock it + if (ctrl_adap->algo->smbus_xfer) { + /* Retry automatically on arbitration loss */ + orig_jiffies = jiffies; + for (res = 0, try = 0; try <= ctrl_adap->retries; try++) { + // read first + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_READ, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + + // modify the field we wanted + data.byte &= ~(CPLD_CHANNEL_SELECT_MASK << CPLD_CHANNEL_SELECT_OFFSET); + reg_val |= ((val & CPLD_CHANNEL_SELECT_MASK) << CPLD_CHANNEL_SELECT_OFFSET); + data.byte |= reg_val; + + // modify the register + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res != -EAGAIN) + break; + if (time_after(jiffies, + orig_jiffies + ctrl_adap->timeout)) + break; + } + } + + return res; +} + +static int delta_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, + void *client, u32 chan) +{ + u8 regval; + int ret = 0; + regval = chan; + + /* Only select the channel if its different from the last channel */ + if (cpld_mux_data->last_chan != regval) { + ret = delta_i2c_cpld_mux_reg_write(NULL, NULL, regval); + cpld_mux_data->last_chan = regval; + } + + return ret; +} + +static int delta_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, + void *client, u32 chan) +{ + /* Deselect active channel */ + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; + + return delta_i2c_cpld_mux_reg_write(NULL, NULL, cpld_mux_data->last_chan); +} + +/* + * I2C init/probing/exit functions + */ +static int __delta_i2c_cpld_mux_init(void) +{ + struct i2c_adapter *adap = i2c_get_adapter(PARENT_CHAN); + int chan=0; + int ret = -ENODEV; + + memset (&dump_dev, 0, sizeof(dump_dev)); + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto err; + + if (!adap) + goto err; + + cpld_mux_data = kzalloc(sizeof(struct delta_i2c_cpld_mux), GFP_KERNEL); + if (!cpld_mux_data) { + ret = -ENOMEM; + goto err; + } + + cpld_mux_data->type = delta_cpld_mux; + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; /* force the first selection */ + + /* Now create an adapter for each channel */ + for (chan = 0; chan < NUM_OF_CPLD_CHANS; chan++) { + cpld_mux_data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &dump_dev, NULL, 0, + chan, + delta_i2c_cpld_mux_select_chan, + delta_i2c_cpld_mux_deselect_mux); + + if (cpld_mux_data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + printk("failed to register multiplexed adapter %d, parent %d\n", chan, PARENT_CHAN); + goto virt_reg_failed; + } + } + + printk("registered %d multiplexed busses for I2C mux bus %d\n", + chan, PARENT_CHAN); + + return 0; + +virt_reg_failed: + for (chan--; chan >= 0; chan--) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + } + + kfree(cpld_mux_data); +err: + return ret; +} + +static int __delta_i2c_cpld_mux_remove(void) +{ + const struct chip_desc *chip = &chips[cpld_mux_data->type]; + int chan; + + for (chan = 0; chan < chip->nchans; ++chan) { + if (cpld_mux_data->virt_adaps[chan]) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + cpld_mux_data->virt_adaps[chan] = NULL; + } + } + + kfree(cpld_mux_data); + + return 0; +} + +static int __init delta_i2c_cpld_mux_init(void) +{ + return __delta_i2c_cpld_mux_init (); +} + +static void __exit delta_i2c_cpld_mux_exit(void) +{ + __delta_i2c_cpld_mux_remove (); +} + +MODULE_AUTHOR("Dave Hu "); +MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); +MODULE_LICENSE("GPL"); + +module_init(delta_i2c_cpld_mux_init); +module_exit(delta_i2c_cpld_mux_exit); + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/PKG.yml new file mode 100755 index 00000000..0f9fdb5b --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=arm-delta-ag6248c-poe ARCH=armel TOOLCHAIN=arm-linux-gnueabi diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/Makefile new file mode 100755 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/Makefile new file mode 100755 index 00000000..8e449476 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/Makefile @@ -0,0 +1,44 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.armel.mk + +MODULE := libonlp-arm-delta-ag6248c-poe +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF arm_delta_ag6248c onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-arm-delta-ag6248c-poe.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/libonlp-arm-delta-ag6248c-poe.mk b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/libonlp-arm-delta-ag6248c-poe.mk new file mode 100755 index 00000000..9edfe87c --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/lib/libonlp-arm-delta-ag6248c-poe.mk @@ -0,0 +1,10 @@ + +############################################################################### +# +# Inclusive Makefile for the libonlp-arm-delta-ag6248c-poe module. +# +# Autogenerated 2016-07-20 18:27:47.344268 +# +############################################################################### +libonlp-arm-delta-ag6248c-poe_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/onlpdump/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/onlpdump/Makefile new file mode 100755 index 00000000..3fe979f3 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/onlp/builds/onlpdump/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.armel.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp arm_delta_ag6248c onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/Makefile new file mode 100755 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/PKG.yml new file mode 100755 index 00000000..d8c6ed4a --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=armel VENDOR=delta BASENAME=arm-delta-ag6248c-poe REVISION=r0 diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/lib/arm-delta-ag6248c-poe-r0.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/lib/arm-delta-ag6248c-poe-r0.yml new file mode 100755 index 00000000..ac3ed810 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/lib/arm-delta-ag6248c-poe-r0.yml @@ -0,0 +1,42 @@ +--- + +###################################################################### +# +# platform-config for AG6248C-POE +# +###################################################################### + +arm-delta-ag6248c-poe-r0: + flat_image_tree: + kernel: + <<: *arm-iproc-kernel + dtb: + =: delta_ag6248c.dtb + <<: *arm-iproc-kernel-package + itb: + <<: *arm-itb + + loader: + device: /dev/mtdblock4 + loadaddr: 0x70000000 + nos_bootcmds: *flash_bootcmds + + environment: + - device: /dev/mtd2 + env_offset: 0x00000000 + env_size: 0x00002000 + sector_size: 0x00010000 + + installer: + - ONL-BOOT: + =: 128MiB + format: ubifs + - ONL-CONFIG: + =: 128MiB + format: ubifs + - ONL-IMAGES: + =: 1024MiB + format: ubifs + - ONL-DATA: + =: 2048MiB + format: ubifs diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/python/arm_delta_ag6248c_poe_r0/__init__.py b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/python/arm_delta_ag6248c_poe_r0/__init__.py new file mode 100755 index 00000000..43045aec --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/platform-config/r0/src/python/arm_delta_ag6248c_poe_r0/__init__.py @@ -0,0 +1,21 @@ +from onl.platform.base import * +from onl.platform.delta import * + +class OnlPlatform_arm_delta_ag6248c_poe_r0(OnlPlatformDelta,OnlPlatformPortConfig_48x1_2x10): + PLATFORM='arm-delta-ag6248c-poe-r0' + MODEL="AG6248C-POE" + SYS_OBJECT_ID=".6248.1" + + def baseconfig(self): + self.insmod('arm-delta-ag6248c-poe-cpld-mux-1.ko') + self.insmod('arm-delta-ag6248c-poe-cpld-mux-2.ko') + + self.new_i2c_devices( + [ + # initiate lm75 + ('tmp75', 0x49, 0), + ('tmp75', 0x4a, 0), + + ] + ) + return True diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/.gitignore b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/.gitignore new file mode 100644 index 00000000..4d978b36 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/.gitignore @@ -0,0 +1,2 @@ +*x86*64*cel*redstone*xp*.mk +onlpdump.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/PKG.yml new file mode 100755 index 00000000..cb9893f5 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml ARCH=armel VENDOR=delta BASENAME=arm-delta-ag6248c KERNELS="onl-kernel-3.2-lts-arm-iproc-all:armel" diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/.gitignore b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/.gitignore new file mode 100755 index 00000000..a813c369 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/.gitignore @@ -0,0 +1,2 @@ +onlpdump.mk +lib diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/Makefile new file mode 100755 index 00000000..465902c8 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.2-lts-arm-iproc-all:armel +KMODULES := $(wildcard *.c) +VENDOR := delta +BASENAME := arm-delta-ag6248c +ARCH := arm +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c new file mode 100755 index 00000000..56d68b13 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c @@ -0,0 +1,242 @@ +/* + * An I2C multiplexer dirver for delta as5812 CPLD + * + * Copyright (C) 2017 Delta Networks, Inc. + * Brandon Chuang + * + * This module supports the delta cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Delta ag7648c CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define CTRL_CPLD_BUS 0x0 +#define CTRL_CPLD_I2C_ADDR 0x28 +#define PARENT_CHAN 0x0 +#define NUM_OF_CPLD_CHANS 0x2 + +#define CPLD_CHANNEL_SELECT_REG 0x19 +#define CPLD_CHANNEL_SELECT_MASK 0x3 +#define CPLD_CHANNEL_SELECT_OFFSET 0x0 + +#define CPLD_DESELECT_CHANNEL 0xff + +#define CPLD_MUX_MAX_NCHANS 0x2 +enum cpld_mux_type { + delta_cpld_mux +}; + +struct delta_i2c_cpld_mux { + enum cpld_mux_type type; + struct i2c_adapter *virt_adaps[CPLD_MUX_MAX_NCHANS]; + u8 last_chan; /* last register value */ +}; + +struct chip_desc { + u8 nchans; + u8 deselectChan; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [delta_cpld_mux] = { + .nchans = NUM_OF_CPLD_CHANS, + .deselectChan = CPLD_DESELECT_CHANNEL, + } +}; + +static struct delta_i2c_cpld_mux *cpld_mux_data; + +static struct device dump_dev; + +/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() + for this as they will try to lock adapter a second time */ +static int delta_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 val) +{ + unsigned long orig_jiffies; + unsigned short flags; + union i2c_smbus_data data; + struct i2c_adapter *ctrl_adap; + int try; + s32 res = -EIO; + u8 reg_val = 0; + + data.byte = val; + flags = 0; + + ctrl_adap = i2c_get_adapter(CTRL_CPLD_BUS); + if (!ctrl_adap) + return res; + + // try to lock it + if (ctrl_adap->algo->smbus_xfer) { + /* Retry automatically on arbitration loss */ + orig_jiffies = jiffies; + for (res = 0, try = 0; try <= ctrl_adap->retries; try++) { + // read first + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_READ, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + + // modify the field we wanted + data.byte &= ~(CPLD_CHANNEL_SELECT_MASK << CPLD_CHANNEL_SELECT_OFFSET); + reg_val |= ((val & CPLD_CHANNEL_SELECT_MASK) << CPLD_CHANNEL_SELECT_OFFSET); + data.byte |= reg_val; + + // modify the register + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + if (time_after(jiffies, + orig_jiffies + ctrl_adap->timeout)) + break; + } + } + + return res; +} + +static int delta_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, + void *client, u32 chan) +{ + u8 regval; + int ret = 0; + regval = chan; + + /* Only select the channel if its different from the last channel */ + if (cpld_mux_data->last_chan != regval) { + ret = delta_i2c_cpld_mux_reg_write(NULL, NULL, regval); + cpld_mux_data->last_chan = regval; + } + + return ret; +} + +static int delta_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, + void *client, u32 chan) +{ + /* Deselect active channel */ + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; + + return delta_i2c_cpld_mux_reg_write(NULL, NULL, cpld_mux_data->last_chan); +} + +/* + * I2C init/probing/exit functions + */ +static int __delta_i2c_cpld_mux_init(void) +{ + struct i2c_adapter *adap = i2c_get_adapter(PARENT_CHAN); + int chan=0; + int ret = -ENODEV; + + memset (&dump_dev, 0, sizeof(dump_dev)); + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto err; + + if (!adap) + goto err; + + cpld_mux_data = kzalloc(sizeof(struct delta_i2c_cpld_mux), GFP_KERNEL); + if (!cpld_mux_data) { + ret = -ENOMEM; + goto err; + } + + cpld_mux_data->type = delta_cpld_mux; + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; /* force the first selection */ + + /* Now create an adapter for each channel */ + for (chan = 0; chan < NUM_OF_CPLD_CHANS; chan++) { + cpld_mux_data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &dump_dev, NULL, 0, + chan, + delta_i2c_cpld_mux_select_chan, + delta_i2c_cpld_mux_deselect_mux); + + if (cpld_mux_data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + printk("failed to register multiplexed adapter %d, parent %d\n", chan, PARENT_CHAN); + goto virt_reg_failed; + } + } + + printk("registered %d multiplexed busses for I2C mux bus %d\n", + chan, PARENT_CHAN); + + return 0; + +virt_reg_failed: + for (chan--; chan >= 0; chan--) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + } + + kfree(cpld_mux_data); +err: + return ret; +} + +static int __delta_i2c_cpld_mux_remove(void) +{ + const struct chip_desc *chip = &chips[cpld_mux_data->type]; + int chan; + + for (chan = 0; chan < chip->nchans; ++chan) { + if (cpld_mux_data->virt_adaps[chan]) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + cpld_mux_data->virt_adaps[chan] = NULL; + } + } + + kfree(cpld_mux_data); + + return 0; +} + +static int __init delta_i2c_cpld_mux_init(void) +{ + return __delta_i2c_cpld_mux_init (); +} + +static void __exit delta_i2c_cpld_mux_exit(void) +{ + __delta_i2c_cpld_mux_remove (); +} + +MODULE_AUTHOR("Dave Hu "); +MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); +MODULE_LICENSE("GPL"); + +module_init(delta_i2c_cpld_mux_init); +module_exit(delta_i2c_cpld_mux_exit); + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c new file mode 100755 index 00000000..12b5fb38 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c @@ -0,0 +1,243 @@ +/* + * An I2C multiplexer dirver for delta as5812 CPLD + * + * Copyright (C) 2017 Delta Networks, Inc. + * Brandon Chuang + * + * This module supports the delta cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Delta ag7648c CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define CTRL_CPLD_BUS 0x0 +#define CTRL_CPLD_I2C_ADDR 0x28 +#define PARENT_CHAN 0x1 +#define NUM_OF_CPLD_CHANS 0x2 + +#define CPLD_CHANNEL_SELECT_REG 0x19 +#define CPLD_CHANNEL_SELECT_MASK 0x3 +#define CPLD_CHANNEL_SELECT_OFFSET 0x5 + +#define CPLD_DESELECT_CHANNEL 0xff + +#define CPLD_MUX_MAX_NCHANS 0x2 +enum cpld_mux_type { + delta_cpld_mux +}; + +struct delta_i2c_cpld_mux { + enum cpld_mux_type type; + struct i2c_adapter *virt_adaps[CPLD_MUX_MAX_NCHANS]; + u8 last_chan; /* last register value */ +}; + +struct chip_desc { + u8 nchans; + u8 deselectChan; +}; + +/* Provide specs for the PCA954x types we know about */ +static const struct chip_desc chips[] = { + [delta_cpld_mux] = { + .nchans = NUM_OF_CPLD_CHANS, + .deselectChan = CPLD_DESELECT_CHANNEL, + } +}; + +static struct delta_i2c_cpld_mux *cpld_mux_data; + +static struct device dump_dev; + +/* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() + for this as they will try to lock adapter a second time */ +static int delta_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 val) +{ + unsigned long orig_jiffies; + unsigned short flags; + union i2c_smbus_data data; + struct i2c_adapter *ctrl_adap; + int try; + s32 res = -EIO; + u8 reg_val = 0; + + data.byte = val; + flags = 0; + + ctrl_adap = i2c_get_adapter(CTRL_CPLD_BUS); + if (!ctrl_adap) + return res; + + + // try to lock it + if (ctrl_adap->algo->smbus_xfer) { + /* Retry automatically on arbitration loss */ + orig_jiffies = jiffies; + for (res = 0, try = 0; try <= ctrl_adap->retries; try++) { + // read first + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_READ, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res && res != -EAGAIN) + break; + + // modify the field we wanted + data.byte &= ~(CPLD_CHANNEL_SELECT_MASK << CPLD_CHANNEL_SELECT_OFFSET); + reg_val |= ((val & CPLD_CHANNEL_SELECT_MASK) << CPLD_CHANNEL_SELECT_OFFSET); + data.byte |= reg_val; + + // modify the register + res = ctrl_adap->algo->smbus_xfer(ctrl_adap, CTRL_CPLD_I2C_ADDR, flags, + I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); + if (res != -EAGAIN) + break; + if (time_after(jiffies, + orig_jiffies + ctrl_adap->timeout)) + break; + } + } + + return res; +} + +static int delta_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, + void *client, u32 chan) +{ + u8 regval; + int ret = 0; + regval = chan; + + /* Only select the channel if its different from the last channel */ + if (cpld_mux_data->last_chan != regval) { + ret = delta_i2c_cpld_mux_reg_write(NULL, NULL, regval); + cpld_mux_data->last_chan = regval; + } + + return ret; +} + +static int delta_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, + void *client, u32 chan) +{ + /* Deselect active channel */ + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; + + return delta_i2c_cpld_mux_reg_write(NULL, NULL, cpld_mux_data->last_chan); +} + +/* + * I2C init/probing/exit functions + */ +static int __delta_i2c_cpld_mux_init(void) +{ + struct i2c_adapter *adap = i2c_get_adapter(PARENT_CHAN); + int chan=0; + int ret = -ENODEV; + + memset (&dump_dev, 0, sizeof(dump_dev)); + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto err; + + if (!adap) + goto err; + + cpld_mux_data = kzalloc(sizeof(struct delta_i2c_cpld_mux), GFP_KERNEL); + if (!cpld_mux_data) { + ret = -ENOMEM; + goto err; + } + + cpld_mux_data->type = delta_cpld_mux; + cpld_mux_data->last_chan = chips[cpld_mux_data->type].deselectChan; /* force the first selection */ + + /* Now create an adapter for each channel */ + for (chan = 0; chan < NUM_OF_CPLD_CHANS; chan++) { + cpld_mux_data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &dump_dev, NULL, 0, + chan, + delta_i2c_cpld_mux_select_chan, + delta_i2c_cpld_mux_deselect_mux); + + if (cpld_mux_data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + printk("failed to register multiplexed adapter %d, parent %d\n", chan, PARENT_CHAN); + goto virt_reg_failed; + } + } + + printk("registered %d multiplexed busses for I2C mux bus %d\n", + chan, PARENT_CHAN); + + return 0; + +virt_reg_failed: + for (chan--; chan >= 0; chan--) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + } + + kfree(cpld_mux_data); +err: + return ret; +} + +static int __delta_i2c_cpld_mux_remove(void) +{ + const struct chip_desc *chip = &chips[cpld_mux_data->type]; + int chan; + + for (chan = 0; chan < chip->nchans; ++chan) { + if (cpld_mux_data->virt_adaps[chan]) { + i2c_del_mux_adapter(cpld_mux_data->virt_adaps[chan]); + cpld_mux_data->virt_adaps[chan] = NULL; + } + } + + kfree(cpld_mux_data); + + return 0; +} + +static int __init delta_i2c_cpld_mux_init(void) +{ + return __delta_i2c_cpld_mux_init (); +} + +static void __exit delta_i2c_cpld_mux_exit(void) +{ + __delta_i2c_cpld_mux_remove (); +} + +MODULE_AUTHOR("Dave Hu "); +MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); +MODULE_LICENSE("GPL"); + +module_init(delta_i2c_cpld_mux_init); +module_exit(delta_i2c_cpld_mux_exit); + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/PKG.yml new file mode 100644 index 00000000..63b56dc7 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=arm-delta-ag6248c ARCH=armel TOOLCHAIN=arm-linux-gnueabi diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/Makefile new file mode 100644 index 00000000..46fdfee8 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/Makefile @@ -0,0 +1,44 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.armel.mk + +MODULE := libonlp-arm-delta-ag6248c +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF arm_delta_ag6248c onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-arm-delta-ag6248c.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/libonlp-arm-delta-ag6248c.mk b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/libonlp-arm-delta-ag6248c.mk new file mode 100644 index 00000000..9cf2a027 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/lib/libonlp-arm-delta-ag6248c.mk @@ -0,0 +1,10 @@ + +############################################################################### +# +# Inclusive Makefile for the libonlp-arm-delta-ag6248c module. +# +# Autogenerated 2016-07-20 18:27:47.344268 +# +############################################################################### +libonlp-arm-delta-ag6248c_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/onlpdump/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..3fe979f3 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/onlp/builds/onlpdump/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.armel.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp arm_delta_ag6248c onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/PKG.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/PKG.yml new file mode 100644 index 00000000..16ff5c28 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=armel VENDOR=delta BASENAME=arm-delta-ag6248c REVISION=r0 diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/lib/arm-delta-ag6248c-r0.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/lib/arm-delta-ag6248c-r0.yml new file mode 100644 index 00000000..ba1cbec5 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/lib/arm-delta-ag6248c-r0.yml @@ -0,0 +1,43 @@ +--- + +###################################################################### +# +# platform-config for AG6248C +# +###################################################################### + +arm-delta-ag6248c-r0: + flat_image_tree: + kernel: + <<: *arm-iproc-kernel + dtb: + =: delta_ag6248c.dtb + <<: *arm-iproc-kernel-package + itb: + <<: *arm-itb + + loader: + device: /dev/mtdblock4 + loadaddr: 0x70000000 + nos_bootcmds: *flash_bootcmds + + environment: + - device: /dev/mtd2 + env_offset: 0x00000000 + env_size: 0x00002000 + sector_size: 0x00010000 + + installer: + - ONL-BOOT: + =: 128MiB + format: ubifs + - ONL-CONFIG: + =: 128MiB + format: ubifs + - ONL-IMAGES: + =: 1024MiB + format: ubifs + - ONL-DATA: + =: 2048MiB + format: ubifs + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/python/arm_delta_ag6248c_r0/__init__.py b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/python/arm_delta_ag6248c_r0/__init__.py new file mode 100755 index 00000000..7d7b97a1 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/platform-config/r0/src/python/arm_delta_ag6248c_r0/__init__.py @@ -0,0 +1,23 @@ +from onl.platform.base import * +from onl.platform.delta import * + +class OnlPlatform_arm_delta_ag6248c_r0(OnlPlatformDelta,OnlPlatformPortConfig_48x1_2x10): + PLATFORM='arm-delta-ag6248c-r0' + MODEL="AG6248C" + SYS_OBJECT_ID=".6248.2" + + def baseconfig(self): + self.insmod('arm-delta-ag6248c-cpld-mux-1.ko') + self.insmod('arm-delta-ag6248c-cpld-mux-2.ko') + + self.new_i2c_devices( + [ + # initiate lm75 + ('tmp75', 0x49, 0), + ('tmp75', 0x4a, 0), + + + + ] + ) + return True diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.gitignore b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.gitignore new file mode 100644 index 00000000..82fb1eaf --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.gitignore @@ -0,0 +1,2 @@ +/arm_delta_ag6248c_poe.mk +/doc diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.module b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.module new file mode 100644 index 00000000..1e18e32c --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/.module @@ -0,0 +1 @@ +name: arm_delta_ag6248c diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/Makefile new file mode 100644 index 00000000..bfc40983 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/Makefile @@ -0,0 +1,28 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.mk +MODULE := arm_delta_ag6248c +AUTOMODULE := arm_delta_ag6248c +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.doxy b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.doxy new file mode 100644 index 00000000..b13fcf5d --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.doxy @@ -0,0 +1,1869 @@ +# Doxyfile 1.8.3.1 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" "). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or sequence of words) that should +# identify the project. Note that if you do not use Doxywizard you need +# to put quotes around the project name if it contains spaces. + +PROJECT_NAME = "arm_delta_ag6248c" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer +# a quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = "Open Network Platform Linux Example Implementation." + +# With the PROJECT_LOGO tag one can specify an logo or icon that is +# included in the documentation. The maximum height of the logo should not +# exceed 55 pixels and the maximum width should not exceed 200 pixels. +# Doxygen will copy the logo to the output directory. + +PROJECT_LOGO = + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. Note that you specify absolute paths here, but also +# relative paths, which will be relative from the directory where doxygen is +# started. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful if your file system +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding +# "class=itcl::class" will allow you to use the command class in the +# itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, +# and language is one of the parsers supported by doxygen: IDL, Java, +# Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, +# C++. For instance to make doxygen treat .inc files as Fortran files (default +# is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note +# that for custom extensions you also need to set FILE_PATTERNS otherwise the +# files are not read by doxygen. + +EXTENSION_MAPPING = + +# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all +# comments according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you +# can mix doxygen, HTML, and XML commands with Markdown formatting. +# Disable only in case of backward compatibilities issues. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented classes, +# or namespaces to their corresponding documentation. Such a link can be +# prevented in individual cases by by putting a percent sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also makes the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES (the +# default) will make doxygen replace the get and set methods by a property in +# the documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and +# unions are shown inside the group in which they are included (e.g. using +# @ingroup) instead of on a separate page (for HTML and Man pages) or +# section (for LaTeX and RTF). + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and +# unions with only public data fields will be shown inline in the documentation +# of the scope in which they are defined (i.e. file, namespace, or group +# documentation), provided this scope is documented. If set to NO (the default), +# structs, classes, and unions are shown on a separate page (for HTML and Man +# pages) or section (for LaTeX and RTF). + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penalty. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will roughly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +SYMBOL_CACHE_SIZE = 0 + +# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be +# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given +# their name and scope. Since this can be an expensive process and often the +# same symbol appear multiple times in the code, doxygen keeps a cache of +# pre-resolved symbols. If the cache is too small doxygen will become slower. +# If the cache is too large, memory is wasted. The cache size is given by this +# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespaces are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to +# do proper type resolution of all parameters of a function it will reject a +# match between the prototype and the implementation of a member function even +# if there is only one candidate or it is obvious which candidate to choose +# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen +# will still accept a match between prototype and implementation in such cases. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if section-label ... \endif +# and \cond section-label ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or macro consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and macros in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. +# This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. +# You can optionally specify a file name after the option, if omitted +# DoxygenLayout.xml will be used as the name of the layout file. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files +# containing the references data. This must be a list of .bib files. The +# .bib extension is automatically appended if omitted. Using this command +# requires the bibtex tool to be installed. See also +# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style +# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this +# feature you need bibtex and perl available in the search path. Do not use +# file names with spaces, bibtex cannot handle them. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# The WARN_NO_PARAMDOC option can be enabled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = module/inc + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh +# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py +# *.f90 *.f *.for *.vhd *.vhdl + +FILE_PATTERNS = + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. +# If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. +# Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. +# The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty or if +# non of the patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) +# and it is also possible to disable source filtering for a specific pattern +# using *.ext= (so without naming a filter). This option only has effect when +# FILTER_SOURCE_FILES is enabled. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MD_FILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page (index.html). +# This can be useful if you have a project on for instance GitHub and want reuse +# the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C, C++ and Fortran comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. +# Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. Note that when using a custom header you are responsible +# for the proper inclusion of any scripts and style sheets that doxygen +# needs, which is dependent on the configuration options used. +# It is advised to generate a default header using "doxygen -w html +# header.html footer.html stylesheet.css YourConfigFile" and then modify +# that header. Note that the header is subject to change so you typically +# have to redo this when upgrading to a newer version of doxygen or when +# changing the value of configuration settings such as GENERATE_TREEVIEW! + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If left blank doxygen will +# generate a default style sheet. Note that it is recommended to use +# HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this +# tag will in the future become obsolete. + +HTML_STYLESHEET = + +# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional +# user-defined cascading style sheet that is included after the standard +# style sheets created by doxygen. Using this option one can overrule +# certain style aspects. This is preferred over using HTML_STYLESHEET +# since it does not replace the standard style sheet and is therefor more +# robust against future updates. Doxygen will copy the style sheet file to +# the output directory. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that +# the files will be copied as-is; there are no commands or markers available. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the style sheet and background images +# according to this color. Hue is specified as an angle on a colorwheel, +# see http://en.wikipedia.org/wiki/Hue for more information. +# For instance the value 0 represents red, 60 is yellow, 120 is green, +# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. +# The allowed range is 0 to 359. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of +# the colors in the HTML output. For a value of 0 the output will use +# grayscales only. A value of 255 will produce the most vivid colors. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to +# the luminance component of the colors in the HTML output. Values below +# 100 gradually make the output lighter, whereas values above 100 make +# the output darker. The value divided by 100 is the actual gamma applied, +# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, +# and 100 does not change the gamma. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of +# entries shown in the various tree structured indices initially; the user +# can expand and collapse entries dynamically later on. Doxygen will expand +# the tree to such a level that at most the specified number of entries are +# visible (unless a fully collapsed tree already exceeds this amount). +# So setting the number of entries 1 will produce a full collapsed tree by +# default. 0 is a special value representing an infinite number of entries +# and will result in a full expanded tree by default. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely +# identify the documentation publisher. This should be a reverse domain-name +# style string, e.g. com.mycompany.MyDocSet.documentation. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated +# that can be used as input for Qt's qhelpgenerator to generate a +# Qt Compressed Help (.qch) of the generated HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to +# add. For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see +# +# Qt Help Project / Custom Filters. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's +# filter section matches. +# +# Qt Help Project / Filter Attributes. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) +# at top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. Since the tabs have the same information as the +# navigation tree you can set this option to NO if you already set +# GENERATE_TREEVIEW to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. +# Since the tree basically has the same information as the tab index you +# could consider to set DISABLE_INDEX to NO when enabling this option. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values +# (range [0,1..20]) that doxygen will group on one line in the generated HTML +# documentation. Note that a value of 0 will completely suppress the enum +# values from appearing in the overview section. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open +# links to external symbols imported via tag files in a separate window. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are +# not supported properly for IE 6.0, but are supported on all modern browsers. +# Note that when changing this option you need to delete any form_*.png files +# in the HTML output before the changes have effect. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax +# (see http://www.mathjax.org) which uses client side Javascript for the +# rendering instead of using prerendered bitmaps. Use this if you do not +# have LaTeX installed or if you want to formulas look prettier in the HTML +# output. When enabled you may also need to install MathJax separately and +# configure the path to it using the MATHJAX_RELPATH option. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# thA MathJax output. Supported types are HTML-CSS, NativeMML (i.e. MathML) and +# SVG. The default value is HTML-CSS, which is slower, but has the best +# compatibility. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the +# HTML output directory using the MATHJAX_RELPATH option. The destination +# directory should contain the MathJax.js script. For instance, if the mathjax +# directory is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to +# the MathJax Content Delivery Network so you can quickly see the result without +# installing MathJax. +# However, it is strongly recommended to install a local +# copy of MathJax from http://www.mathjax.org before deployment. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension +# names that should be enabled during MathJax rendering. + +MATHJAX_EXTENSIONS = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a web server instead of a web client using Javascript. +# There are two flavours of web server based search depending on the +# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for +# searching and an index file used by the script. When EXTERNAL_SEARCH is +# enabled the indexing and searching needs to be provided by external tools. +# See the manual for details. + +SERVER_BASED_SEARCH = NO + +# When EXTERNAL_SEARCH is enabled doxygen will no longer generate the PHP +# script for searching. Instead the search results are written to an XML file +# which needs to be processed by an external indexer. Doxygen will invoke an +# external search engine pointed to by the SEARCHENGINE_URL option to obtain +# the search results. Doxygen ships with an example indexer (doxyindexer) and +# search engine (doxysearch.cgi) which are based on the open source search engine +# library Xapian. See the manual for configuration details. + +EXTERNAL_SEARCH = NO + +# The SEARCHENGINE_URL should point to a search engine hosted by a web server +# which will returned the search results when EXTERNAL_SEARCH is enabled. +# Doxygen ships with an example search engine (doxysearch) which is based on +# the open source search engine library Xapian. See the manual for configuration +# details. + +SEARCHENGINE_URL = + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed +# search data is written to a file for indexing by an external tool. With the +# SEARCHDATA_FILE tag the name of this file can be specified. + +SEARCHDATA_FILE = searchdata.xml + +# When SERVER_BASED_SEARCH AND EXTERNAL_SEARCH are both enabled the +# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is +# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple +# projects and redirect the results back to the right project. + +EXTERNAL_SEARCH_ID = + +# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen +# projects other than the one defined by this configuration file, but that are +# all added to the same external search index. Each project needs to have a +# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id +# of to a relative location where the documentation can be found. +# The format is: EXTRA_SEARCH_MAPPINGS = id1=loc1 id2=loc2 ... + +EXTRA_SEARCH_MAPPINGS = + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = YES + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4 + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for +# the generated latex document. The footer should contain everything after +# the last chapter. If it is left blank doxygen will generate a +# standard footer. Notice: only use this tag if you know what you are doing! + +LATEX_FOOTER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See +# http://en.wikipedia.org/wiki/BibTeX for more info. + +LATEX_BIB_STYLE = plain + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load style sheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. +# This is useful +# if you want to understand what is going on. +# On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# pointed to by INCLUDE_PATH will be searched when a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition that +# overrules the definition found in the source code. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all references to function-like macros +# that are alone on a line, have an all uppercase name, and do not end with a +# semicolon, because these will confuse the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. For each +# tag file the location of the external documentation should be added. The +# format of a tag file without this location is as follows: +# +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths +# or URLs. Note that each tag file must have a unique name (where the name does +# NOT include the path). If a tag file is not located in the directory in which +# doxygen is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option also works with HAVE_DOT disabled, but it is recommended to +# install and use dot, since it yields more powerful graphs. + +CLASS_DIAGRAMS = YES + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is +# allowed to run in parallel. When set to 0 (the default) doxygen will +# base this on the number of processors available in the system. You can set it +# explicitly to a value larger than 0 to get control over the balance +# between CPU load and processing speed. + +DOT_NUM_THREADS = 0 + +# By default doxygen will use the Helvetica font for all dot files that +# doxygen generates. When you want a differently looking font you can specify +# the font name using DOT_FONTNAME. You need to make sure dot is able to find +# the font, which can be done by putting it in a standard location or by setting +# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. + +DOT_FONTNAME = Helvetica + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the Helvetica font. +# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to +# set the path where dot can find it. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If the UML_LOOK tag is enabled, the fields and methods are shown inside +# the class node. If there are many fields or methods and many nodes the +# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS +# threshold limits the number of items for each type to make the size more +# managable. Set this to 0 for no limit. Note that the threshold may be +# exceeded by 50 percent before the limit is enforced. + +UML_LIMIT_NUM_FIELDS = 10 + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will generate a graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are svg, png, jpg, or gif. +# If left blank png will be used. If you choose svg you need to set +# HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible in IE 9+ (other browsers do not have this requirement). + +DOT_IMAGE_FORMAT = png + +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# Note that this requires a modern browser other than Internet Explorer. +# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you +# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible. Older versions of IE do not have SVG support. + +INTERACTIVE_SVG = NO + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the +# \mscfile command). + +MSCFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.mk b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.mk new file mode 100644 index 00000000..42ac4368 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/arm_delta_ag6248c.mk @@ -0,0 +1,13 @@ + +############################################################################### +# +# Inclusive Makefile for the arm_delta_ag6248c module. +# +# Autogenerated 2017-02-16 14:19:33.628446 +# +############################################################################### +arm_delta_ag6248c_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) +include $(arm_delta_ag6248c_BASEDIR)module/make.mk +include $(arm_delta_ag6248c_BASEDIR)module/auto/make.mk +include $(arm_delta_ag6248c_BASEDIR)module/src/make.mk + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml new file mode 100644 index 00000000..80f1a97d --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml @@ -0,0 +1,67 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ + +cdefs: &cdefs +- ONLPSIM_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- ONLPSIM_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- ONLPSIM_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: ONLPSIM_CONFIG_PORTING_STDLIB +- ONLPSIM_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- ONLPSIM_CONFIG_SFP_COUNT: + doc: "SFP Count." + default: 0 + +definitions: + cdefs: + ONLPSIM_CONFIG_HEADER: + defs: *cdefs + basename: arm_delta_ag6248c_config + + portingmacro: + ONLPSIM: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/make.mk b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/make.mk new file mode 100644 index 00000000..57889792 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/make.mk @@ -0,0 +1,28 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ + +arm_delta_ag6248c_AUTO_DEFS := module/auto/arm_delta_ag6248c.yml +arm_delta_ag6248c_AUTO_DIRS := module/inc/arm_delta_ag6248c module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x new file mode 100644 index 00000000..f15500cc --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x @@ -0,0 +1,34 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h new file mode 100644 index 00000000..68664185 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h @@ -0,0 +1,162 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +/**************************************************************************//** + * + * @file + * @brief arm_delta_ag6248c Configuration Header + * + * @addtogroup arm_delta_ag6248c-config + * @{ + * + *****************************************************************************/ +#ifndef __ONLPSIM_CONFIG_H__ +#define __ONLPSIM_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef ONLPSIM_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * ONLPSIM_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef ONLPSIM_CONFIG_INCLUDE_LOGGING +#define ONLPSIM_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT +#define ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * ONLPSIM_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef ONLPSIM_CONFIG_LOG_BITS_DEFAULT +#define ONLPSIM_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * ONLPSIM_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef ONLPSIM_CONFIG_PORTING_STDLIB +#define ONLPSIM_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS ONLPSIM_CONFIG_PORTING_STDLIB +#endif + +/** + * ONLPSIM_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef ONLPSIM_CONFIG_INCLUDE_UCLI +#define ONLPSIM_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * ONLPSIM_CONFIG_SFP_COUNT + * + * SFP Count. */ + + +#ifndef ONLPSIM_CONFIG_SFP_COUNT +#define ONLPSIM_CONFIG_SFP_COUNT 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct arm_delta_ag6248c_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} arm_delta_ag6248c_config_settings_t; + +/** Configuration settings table. */ +/** arm_delta_ag6248c_config_settings table. */ +extern arm_delta_ag6248c_config_settings_t arm_delta_ag6248c_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* arm_delta_ag6248c_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int arm_delta_ag6248c_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "arm_delta_ag6248c_porting.h" + +#endif /* __ONLPSIM_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h new file mode 100644 index 00000000..20f312ed --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h @@ -0,0 +1,51 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +/********************************************************//** + * + * arm_delta_ag6248c Doxygen Header + * + ***********************************************************/ +#ifndef __ONLPSIM_DOX_H__ +#define __ONLPSIM_DOX_H__ + +/** + * @defgroup arm_delta_ag6248c arm_delta_ag6248c - onlpsim Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup arm_delta_ag6248c-arm_delta_ag6248c Public Interface + * @defgroup arm_delta_ag6248c-config Compile Time Configuration + * @defgroup arm_delta_ag6248c-porting Porting Macros + * + * @} + * + */ + +#endif /* __ONLPSIM_DOX_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h new file mode 100644 index 00000000..19853401 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h @@ -0,0 +1,132 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +/********************************************************//** + * + * @file + * @brief arm_delta_ag6248c Porting Macros. + * + * @addtogroup arm_delta_ag6248c-porting + * @{ + * + ***********************************************************/ +#ifndef __ONLPSIM_PORTING_H__ +#define __ONLPSIM_PORTING_H__ + + +/* */ +#if ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef ONLPSIM_MALLOC + #if defined(GLOBAL_MALLOC) + #define ONLPSIM_MALLOC GLOBAL_MALLOC + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_MALLOC malloc + #else + #error The macro ONLPSIM_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_FREE + #if defined(GLOBAL_FREE) + #define ONLPSIM_FREE GLOBAL_FREE + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_FREE free + #else + #error The macro ONLPSIM_FREE is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_MEMSET + #if defined(GLOBAL_MEMSET) + #define ONLPSIM_MEMSET GLOBAL_MEMSET + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_MEMSET memset + #else + #error The macro ONLPSIM_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define ONLPSIM_MEMCPY GLOBAL_MEMCPY + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_MEMCPY memcpy + #else + #error The macro ONLPSIM_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define ONLPSIM_STRNCPY GLOBAL_STRNCPY + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_STRNCPY strncpy + #else + #error The macro ONLPSIM_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define ONLPSIM_VSNPRINTF GLOBAL_VSNPRINTF + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_VSNPRINTF vsnprintf + #else + #error The macro ONLPSIM_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define ONLPSIM_SNPRINTF GLOBAL_SNPRINTF + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_SNPRINTF snprintf + #else + #error The macro ONLPSIM_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef ONLPSIM_STRLEN + #if defined(GLOBAL_STRLEN) + #define ONLPSIM_STRLEN GLOBAL_STRLEN + #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 + #define ONLPSIM_STRLEN strlen + #else + #error The macro ONLPSIM_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __ONLPSIM_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/make.mk b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/make.mk new file mode 100644 index 00000000..29f7a9f3 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/make.mk @@ -0,0 +1,29 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +arm_delta_ag6248c_INCLUDES := -I $(THIS_DIR)inc +arm_delta_ag6248c_INTERNAL_INCLUDES := -I $(THIS_DIR)src +arm_delta_ag6248c_DEPENDMODULE_ENTRIES := init:arm_delta_ag6248c ucli:arm_delta_ag6248c + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/Makefile b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/Makefile new file mode 100644 index 00000000..94aa2ec9 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/Makefile @@ -0,0 +1,30 @@ +############################################################ +# +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# Local source generation targets. +# +############################################################ + +include ../../../../init.mk + +ucli: + $(SUBMODULE_BIGCODE)/tools/uclihandlers.py arm_delta_ag6248c_ucli.c + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c new file mode 100644 index 00000000..6447135c --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c @@ -0,0 +1,101 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* */ +#define __arm_delta_ag6248c_config_STRINGIFY_NAME(_x) #_x +#define __arm_delta_ag6248c_config_STRINGIFY_VALUE(_x) __arm_delta_ag6248c_config_STRINGIFY_NAME(_x) +arm_delta_ag6248c_config_settings_t arm_delta_ag6248c_config_settings[] = +{ +#ifdef ONLPSIM_CONFIG_INCLUDE_LOGGING + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_INCLUDE_LOGGING), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_INCLUDE_LOGGING) }, +#else +{ ONLPSIM_CONFIG_INCLUDE_LOGGING(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_LOG_BITS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ ONLPSIM_CONFIG_LOG_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_PORTING_STDLIB + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_PORTING_STDLIB), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_PORTING_STDLIB) }, +#else +{ ONLPSIM_CONFIG_PORTING_STDLIB(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_INCLUDE_UCLI + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_INCLUDE_UCLI), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_INCLUDE_UCLI) }, +#else +{ ONLPSIM_CONFIG_INCLUDE_UCLI(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef ONLPSIM_CONFIG_SFP_COUNT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_SFP_COUNT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_SFP_COUNT) }, +#else +{ ONLPSIM_CONFIG_SFP_COUNT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __arm_delta_ag6248c_config_STRINGIFY_VALUE +#undef __arm_delta_ag6248c_config_STRINGIFY_NAME + +const char* +arm_delta_ag6248c_config_lookup(const char* setting) +{ + int i; + for(i = 0; arm_delta_ag6248c_config_settings[i].name; i++) { + if(strcmp(arm_delta_ag6248c_config_settings[i].name, setting)) { + return arm_delta_ag6248c_config_settings[i].value; + } + } + return NULL; +} + +int +arm_delta_ag6248c_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; arm_delta_ag6248c_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", arm_delta_ag6248c_config_settings[i].name, arm_delta_ag6248c_config_settings[i].value); + } + return i; +} + +/* */ + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c new file mode 100644 index 00000000..2a14c2cc --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c @@ -0,0 +1,30 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h new file mode 100644 index 00000000..8dfd2c7c --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h @@ -0,0 +1,32 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __ONLPSIM_INT_H__ +#define __ONLPSIM_INT_H__ + +#include + + +#endif /* __ONLPSIM_INT_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c new file mode 100644 index 00000000..1941f294 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c @@ -0,0 +1,38 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#include "arm_delta_ag6248c_log.h" +/* + * arm_delta_ag6248c log struct. + */ +AIM_LOG_STRUCT_DEFINE( + ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT, + ONLPSIM_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h new file mode 100644 index 00000000..13d00bc5 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h @@ -0,0 +1,32 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#ifndef __ONLPSIM_LOG_H__ +#define __ONLPSIM_LOG_H__ + +#define AIM_LOG_MODULE_NAME arm_delta_ag6248c +#include + +#endif /* __ONLPSIM_LOG_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c new file mode 100644 index 00000000..fdb080f0 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c @@ -0,0 +1,44 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#include "arm_delta_ag6248c_log.h" + +static int +datatypes_init__(void) +{ +#define ONLPSIM_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __arm_delta_ag6248c_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c new file mode 100644 index 00000000..4dbeeed0 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c @@ -0,0 +1,82 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ + +#include + +#if ONLPSIM_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +arm_delta_ag6248c_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(arm_delta_ag6248c) +} + +/* */ +/****************************************************************************** + * + * These handler table(s) were autogenerated from the symbols in this + * source file. + * + *****************************************************************************/ +static ucli_command_handler_f arm_delta_ag6248c_ucli_ucli_handlers__[] = +{ + arm_delta_ag6248c_ucli_ucli__config__, + NULL +}; +/******************************************************************************/ +/* */ + +static ucli_module_t +arm_delta_ag6248c_ucli_module__ = + { + "arm_delta_ag6248c_ucli", + NULL, + arm_delta_ag6248c_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +arm_delta_ag6248c_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&arm_delta_ag6248c_ucli_module__); + n = ucli_node_create("arm_delta_ag6248c", NULL, &arm_delta_ag6248c_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("arm_delta_ag6248c")); + return n; +} + +#else +void* +arm_delta_ag6248c_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c new file mode 100755 index 00000000..a7a83e0e --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c @@ -0,0 +1,141 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "arm_delta_ag6248c_log.h" +#include "arm_delta_i2c.h" +#include + +struct i2c_device_info i2c_device_list[]={ + {"RTC",0X0,0X68}, + {"TMP1_CLOSE_TO_MAC",0X0,0X49}, + {"TMP2_CLOSE_TO_PHY",0X0,0X4a}, + {"CPLD",0X0,0X28}, + {"FAN_ON_BOARD",0X1,0X2C}, + {"CURT_MONTOR",0X1,0X40}, + {"SFP1",0X2,0X50}, + {"SFP2",0X3,0X50}, +// ------------------------- + {"PSU1_PMBUS",0X4,0X58}, + {"PSU2_PMBUS",0X5,0X59}, + {"PSU1_EEPROM",0X4,0X50}, + {"PSU2_EEPROM",0X5,0X51}, +// ------------------------- + {"PSU1_PMBUS_POE",0X4,0X58}, + {"PSU2_PMBUS_POE",0X5,0X58}, + {"PSU1_EEPROM_POE",0X4,0X52}, + {"PSU2_EEPROM_POE",0X5,0X52}, + {NULL, -1,-1}, +}; + + +uint32_t i2c_flag=ONLP_I2C_F_FORCE; + + +i2c_device_info_t *i2c_dev_find_by_name (char *name) +{ + i2c_device_info_t *i2c_dev = i2c_device_list; + + if (name == NULL) return NULL; + + while (i2c_dev->name) { + if (strcmp (name, i2c_dev->name) == 0) break; + ++ i2c_dev; + } + if (i2c_dev->name == NULL) return NULL; + + return i2c_dev; +} + +int i2c_devname_read_byte (char *name, int reg) +{ + int ret=-1; + i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name); + + if(i2c_dev==NULL) return -1; + + ret=onlp_i2c_readb (i2c_dev->i2cbus, i2c_dev->addr, reg, i2c_flag); + + return ret; +} + +int i2c_devname_write_byte (char *name, int reg, int value) +{ + int ret=-1; + i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name); + + if(i2c_dev==NULL) return -1; + + ret=onlp_i2c_writeb (i2c_dev->i2cbus, i2c_dev->addr, reg, value, i2c_flag); + + + return ret; +} + +int i2c_devname_read_word (char *name, int reg) +{ + int ret=-1; + i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name); + + if(i2c_dev==NULL) return -1; + + ret=onlp_i2c_readw (i2c_dev->i2cbus, i2c_dev->addr, reg, i2c_flag); + + return ret; +} + +int i2c_devname_write_word (char *name, int reg, int value) +{ + int ret=-1; + i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name); + + if(i2c_dev==NULL) return -1; + + ret=onlp_i2c_writew (i2c_dev->i2cbus, i2c_dev->addr, reg, value, i2c_flag); + + return ret; +} + +int i2c_devname_read_block (char *name, int reg, uint8_t *buff, int buff_size) +{ + int ret = -1; + + i2c_device_info_t *i2c_dev = i2c_dev_find_by_name (name); + + if(i2c_dev==NULL) return -1; + + ret = onlp_i2c_block_read (i2c_dev->i2cbus, i2c_dev->addr, reg, buff_size, buff, i2c_flag); + + return ret; + +} + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h new file mode 100755 index 00000000..76c35cbb --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h @@ -0,0 +1,54 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************/ +/* the i2c struct header*/ + +#ifndef __ARM_DELTA_I2C_H__ +#define __ARM_DELTA_I2C_H__ + +#include "arm_delta_ag6248c_log.h" + +struct i2c_device_info { + /*i2c device name*/ + char *name; + char i2cbus; + char addr; +}; + + +typedef struct i2c_device_info i2c_device_info_t; + +extern struct i2c_device_info i2c_device_list[]; + + +extern int i2c_devname_read_byte(char *name, int reg); + +extern int i2c_devname_write_byte(char *name, int reg, int value); + + +extern int i2c_devname_read_word(char *name, int reg); + +extern int i2c_devname_write_word(char *name, int reg, int value); + + +extern int i2c_devname_read_block (char *name, int reg, uint8_t *buff, int buff_size); + +#endif diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c new file mode 100755 index 00000000..b0c16526 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c @@ -0,0 +1,470 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include +#include "platform_lib.h" +#include "arm_delta_ag6248c_int.h" +#include "arm_delta_i2c.h" +#include + +#define MAX_FAN_SPEED 12000 +#define MAX_PSU_FAN_SPEED 23000 + +#define FILE_NAME_LEN 80 + +/* The MAX6639 registers, valid channel numbers: 0, 1 */ +#define MAX6639_REG_STATUS 0x02 +#define MAX6639_REG_FAN_CONFIG1(ch) (0x10 + 4*(ch-1)) +#define MAX6639_REG_FAN_CNT(ch) (0x20 + (ch-1)) +#define MAX6639_REG_TARGET_CNT(ch) (0x22 + (ch-1)) + +/*define the reg bit mask*/ +#define MAX6639_REG_FAN_STATUS_BIT(ch) (0X02>>(ch-1)) +#define MAX6639_FAN_CONFIG1_RPM_RANGE 0x03 +#define MAX6639_FAN_PRESENT_REG (0x0c) +#define MAX6639_FAN_PRESENT_BIT (0x2) +#define MAX6639_FAN_GOOD_BIT (0x1) +#define FAN_FROM_REG(val) ((480000.0) / (val)) + +static int fan_initd=0; + +enum onlp_fan_id +{ + FAN_RESERVED = 0, + FAN_1_ON_MAIN_BOARD, + FAN_2_ON_MAIN_BOARD, + FAN_1_ON_PSU1, + FAN_1_ON_PSU2 +}; + +#define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ + ONLP_FAN_STATUS_B2F | ONLP_FAN_STATUS_PRESENT, \ + (ONLP_FAN_CAPS_SET_PERCENTAGE |ONLP_FAN_CAPS_SET_RPM| ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + +#define MAKE_FAN_INFO_NODE_ON_PSU(psu_id, fan_id) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fan_id##_ON_PSU##psu_id), "Chassis PSU-"#psu_id " Fan "#fan_id, 0 }, \ + ONLP_FAN_STATUS_B2F | ONLP_FAN_STATUS_PRESENT, \ + (ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ + 0, \ + 0, \ + ONLP_FAN_MODE_INVALID, \ + } + +/* Static fan information */ +onlp_fan_info_t linfo[] = { + { }, /* Not used */ + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(1), + MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(2), + MAKE_FAN_INFO_NODE_ON_PSU(1,1), + MAKE_FAN_INFO_NODE_ON_PSU(2,1), +}; + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int + _onlp_psu_fan_val_to_rpm (int v) +{ + int lf = (v & 0xffff); + int y, n; + + y = lf & 0x7ff; + n = ((lf >> 11) & 0x1f); + + return (y * (1 << n)); +} + +static int +_onlp_fan_board_init(void) +{ + i2c_devname_write_byte("FAN_ON_BOARD", 0x03,0xfc); + i2c_devname_write_byte("FAN_ON_BOARD", 0x04,0x30); + + i2c_devname_write_byte("FAN_ON_BOARD", 0x10,0x23); + i2c_devname_write_byte("FAN_ON_BOARD", 0x11,0x00); + i2c_devname_write_byte("FAN_ON_BOARD", 0x12,0x00); + i2c_devname_write_byte("FAN_ON_BOARD", 0x13,0x21); + i2c_devname_write_byte("FAN_ON_BOARD", 0x24,0xe8); + + i2c_devname_write_byte("FAN_ON_BOARD", 0x14,0x23); + i2c_devname_write_byte("FAN_ON_BOARD", 0x15,0x00); + i2c_devname_write_byte("FAN_ON_BOARD", 0x16,0x00); + i2c_devname_write_byte("FAN_ON_BOARD", 0x17,0x21); + i2c_devname_write_byte("FAN_ON_BOARD", 0x25,0xe8); + + fan_initd=1; + + return ONLP_STATUS_OK; +} + +static int +_onlp_fani_info_get_fan(int local_id, onlp_fan_info_t* info) +{ + int r_data,fan_good,fan_present,fan_fault; + + /* init the fan on the board*/ + if(fan_initd==0) + _onlp_fan_board_init(); + /* get fan fault status (turn on when any one fails)*/ + r_data= i2c_devname_read_byte("CPLD",MAX6639_FAN_PRESENT_REG); + + if(r_data<0) + return ONLP_STATUS_E_INVALID; + + fan_present = r_data & MAX6639_FAN_PRESENT_BIT; + + if(!fan_present){ + + info->status |= ONLP_FAN_STATUS_PRESENT; + + fan_good=r_data&MAX6639_FAN_GOOD_BIT; + + if(fan_good) + info->status&=~ONLP_FAN_STATUS_FAILED; + else{ + r_data = i2c_devname_read_byte("FAN_ON_BOARD", MAX6639_REG_STATUS); + + if(r_data<0) + return ONLP_STATUS_E_INVALID; + + fan_fault=r_data & MAX6639_REG_FAN_STATUS_BIT(local_id); + + if(!fan_fault) + info->status &=~ ONLP_FAN_STATUS_FAILED; + else{ + info->status |=ONLP_FAN_STATUS_FAILED; + info->rpm=0; + info->percentage=0; + goto mode; + } + } + } + else{ + info->status &= ~ONLP_FAN_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + + /* get fan speed */ + r_data = i2c_devname_read_byte("FAN_ON_BOARD", MAX6639_REG_FAN_CNT(local_id)); + + if(r_data<0) + return ONLP_STATUS_E_INVALID; + + info->rpm = FAN_FROM_REG(r_data); + + /* get speed percentage from rpm */ + info->percentage = (info->rpm * 100.0) / MAX_FAN_SPEED; + +mode: + if(info->percentage>100) + strcpy(info->model,"ONLP_FAN_MODE_LAST"); + else if(info->percentage==100) + strcpy(info->model,"ONLP_FAN_MODE_MAX"); + else if(info->percentage>=75&&info->percentage<100) + strcpy(info->model,"ONLP_FAN_MODE_FAST"); + else if(info->percentage>=35&&info->percentage<75) + strcpy(info->model,"ONLP_FAN_MODE_NORMAL"); + else if(info->percentage>0&&info->percentage<35) + strcpy(info->model,"ONLP_FAN_MODE_SLOW"); + else if(info->percentage<=0) + strcpy(info->model,"ONLP_FAN_MODE_OFF"); + else{ } + + return ONLP_STATUS_OK; +} + +static int +_onlp_fani_info_get_fan_on_psu(int local_id, onlp_fan_info_t* info) +{ + int psu_id; + int r_data,fan_rpm; + int psu_present; + int psu_good; + psu_type_t psu_type; + + enum ag6248c_product_id pid = get_product_id(); + /* get fan fault status + */ + psu_id = (local_id - FAN_1_ON_PSU1) + 1; + DEBUG_PRINT("[Debug][%s][%d][psu_id: %d]\n", __FUNCTION__, __LINE__, psu_id); + + psu_type = get_psu_type(psu_id); /* psu_id = 1 , present PSU1. pus_id =2 , present PSU2 */ + DEBUG_PRINT("[Debug][%s][%d][psu_type: %d]\n", __FUNCTION__, __LINE__, psu_type); + psu_present=psu_status_info_get(psu_id, "present"); + psu_good=psu_status_info_get(psu_id, "good"); + if((psu_present<=0)||(psu_good<=0)){ + info->status &= ~ONLP_FAN_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_F2B); + break; + case PSU_TYPE_AC_B2F: + info->status |= (ONLP_FAN_STATUS_PRESENT | ONLP_FAN_STATUS_B2F); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* get fan speed*/ + if(pid == PID_AG6248C_48){ + if(psu_id==1) + r_data=i2c_devname_read_word("PSU1_PMBUS", 0x90); + else + r_data=i2c_devname_read_word("PSU2_PMBUS", 0x90); + } + else{ + if(psu_id==1) + r_data=i2c_devname_read_word("PSU1_PMBUS_POE", 0x90); + else + r_data=i2c_devname_read_word("PSU2_PMBUS_POE", 0x90); + } + + if(r_data<0) + return ONLP_STATUS_E_INVALID; + + fan_rpm=_onlp_psu_fan_val_to_rpm(r_data); + + info->rpm = fan_rpm; + + /* get speed percentage from rpm */ + info->percentage = (info->rpm * 100.0) / MAX_PSU_FAN_SPEED; + + if(info->percentage>100) + strcpy(info->model,"ONLP_FAN_MODE_LAST"); + else if(info->percentage==100) + strcpy(info->model,"ONLP_FAN_MODE_MAX"); + else if(info->percentage>=75&&info->percentage<100) + strcpy(info->model,"ONLP_FAN_MODE_FAST"); + else if(info->percentage>=35&&info->percentage<75) + strcpy(info->model,"ONLP_FAN_MODE_NORMAL"); + else if(info->percentage>0&&info->percentage<35) + strcpy(info->model,"ONLP_FAN_MODE_SLOW"); + else if(info->percentage<=0) + strcpy(info->model,"ONLP_FAN_MODE_OFF"); + else{} + + return ONLP_STATUS_OK; +} + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + int rc; + rc=_onlp_fan_board_init(); + return rc; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int local_id; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + if (chassis_fan_count() == 0) { + local_id += 1; + } + + *info = linfo[local_id]; + + switch (local_id) + { + case FAN_1_ON_PSU1: + case FAN_1_ON_PSU2: + rc = _onlp_fani_info_get_fan_on_psu(local_id, info); + break; + case FAN_1_ON_MAIN_BOARD: + case FAN_2_ON_MAIN_BOARD: + rc =_onlp_fani_info_get_fan(local_id, info); + break; + default: + rc = ONLP_STATUS_E_INVALID; + break; + } + + return rc; +} + +/* + * This function sets the speed of the given fan in RPM. + * + * This function will only be called if the fan supprots the RPM_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_rpm_set(onlp_oid_t id, int rpm) +{ /* + the rpm is the actual rpm/1000. so 16 represents the 16000(max spd) + */ + int fan_set_rpm_cont,rc; + int local_id; + int actual_rpm=rpm; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + if((local_id==FAN_1_ON_PSU1)||(local_id==FAN_1_ON_PSU2)) + return ONLP_STATUS_E_UNSUPPORTED; + + if (chassis_fan_count() == 0) { + return ONLP_STATUS_E_INVALID; + } + /* init the fan on the board*/ + if(fan_initd==0) + _onlp_fan_board_init(); + + /* reject rpm=0 (rpm=0, stop fan) */ + if (actual_rpm == 0) + return ONLP_STATUS_E_INVALID; + + /*get ret value for the speed set*/ + fan_set_rpm_cont=FAN_FROM_REG(actual_rpm); + + /*set the rpm speed */ + rc=i2c_devname_write_byte("FAN_ON_BOARD", MAX6639_REG_TARGET_CNT(local_id), fan_set_rpm_cont); + + if(rc<0) + return ONLP_STATUS_E_INVALID; + + return ONLP_STATUS_OK; +} +/*set the percentage for the psu fan*/ + + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int p) +{ + /* + p is between 0 and 100 ,p=100 represents 16000(max spd) + */ + int rpm_val,fan_set_rpm_cont,rc; + int local_id; + + VALIDATE(id); + + local_id = ONLP_OID_ID_GET(id); + + if((local_id==FAN_1_ON_PSU1)||(local_id==FAN_1_ON_PSU2)) + return ONLP_STATUS_E_UNSUPPORTED; + + if (chassis_fan_count() == 0) { + return ONLP_STATUS_E_INVALID; + } + + /* init the fan on the board*/ + if(fan_initd==0) + _onlp_fan_board_init(); + + /* reject p=0 (p=0, stop fan) */ + if (p == 0){ + return ONLP_STATUS_E_INVALID; + } + + rpm_val=p*(MAX_FAN_SPEED/100); + + /*get ret value for the speed set*/ + fan_set_rpm_cont=FAN_FROM_REG(rpm_val); + + /*set the rpm speed */ + rc=i2c_devname_write_byte("FAN_ON_BOARD", MAX6639_REG_TARGET_CNT(local_id), fan_set_rpm_cont); + + if(rc<0) + return ONLP_STATUS_E_INVALID; + + return ONLP_STATUS_OK; + + +} + + +/* + * This function sets the fan speed of the given OID as per + * the predefined ONLP fan speed modes: off, slow, normal, fast, max. + * + * Interpretation of these modes is up to the platform. + * + */ +int +onlp_fani_mode_set(onlp_oid_t id, onlp_fan_mode_t mode) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function sets the fan direction of the given OID. + * + * This function is only relevant if the fan OID supports both direction + * capabilities. + * + * This function is optional unless the functionality is available. + */ +int +onlp_fani_dir_set(onlp_oid_t id, onlp_fan_dir_t dir) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * Generic fan ioctl. Optional. + */ +int +onlp_fani_ioctl(onlp_oid_t id, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/ledi.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/ledi.c new file mode 100755 index 00000000..66443e10 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/ledi.c @@ -0,0 +1,375 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include + +#include +#include "platform_lib.h" +#include "arm_delta_ag6248c_int.h" +#include "arm_delta_i2c.h" +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + + +#define CPLD_LED_MODE_REG (0X0A) +#define CPLD_LED_MODE_TEMP_REG (0X0B) +#define CPLD_LED_MODE_REG_BIT(ch) (0x3<<2*((ch)-1)) +#define CPLD_LED_MODE_TEMP_REG_BIT (0x0C) +#define CPLD_LED_MODE_MASTER_REG_BIT (0x02) +#define CPLD_LED_MODE_REG_OFFSET(ch) (2*((ch)-1)) +#define CPLD_LED_MODE_TEMP_REG_OFFSET (2) +#define CPLD_LED_MODE_MASTER_REG_OFFSET (1) + + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_SYS), "sys", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_GREEN_BLINKING |ONLP_LED_CAPS_GREEN | + ONLP_LED_CAPS_RED_BLINKING | ONLP_LED_CAPS_RED , + }, + + { + { ONLP_LED_ID_CREATE(LED_FAN), "fan", 0 }, + ONLP_LED_STATUS_PRESENT, ONLP_LED_CAPS_ON_OFF | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_RED, + }, + + { + { ONLP_LED_ID_CREATE(LED_PSU2), "psu2", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN_BLINKING | + ONLP_LED_CAPS_GREEN , + }, + + { + { ONLP_LED_ID_CREATE(LED_PSU1), "psu1", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN_BLINKING | + ONLP_LED_CAPS_GREEN , + }, + + { + { ONLP_LED_ID_CREATE(LED_TEMP), "temp", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN | + ONLP_LED_CAPS_RED , + }, + + { + { ONLP_LED_ID_CREATE(LED_MASTER), "master", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_GREEN , + }, +}; + +static int conver_led_light_mode_to_onl(uint32_t id, int led_ligth_mode) +{ + switch (id) { + case LED_SYS: + switch (led_ligth_mode) { + case SYS_LED_MODE_GREEN_BLINKING: return ONLP_LED_MODE_GREEN_BLINKING; + case SYS_LED_MODE_GREEN: return ONLP_LED_MODE_GREEN; + case SYS_LED_MODE_RED: return ONLP_LED_MODE_RED; + case SYS_LED_MODE_RED_BLINKING: return ONLP_LED_MODE_RED_BLINKING; + default: return ONLP_LED_MODE_OFF; + } + case LED_PSU1: + case LED_PSU2: + switch (led_ligth_mode) { + case PSU_LED_MODE_OFF: return ONLP_LED_MODE_OFF; + case PSU_LED_MODE_GREEN: return ONLP_LED_MODE_GREEN; + case PSU_LED_MODE_GREEN_BLINKING: return ONLP_LED_MODE_GREEN_BLINKING; + default: return ONLP_LED_MODE_OFF; + } + case LED_FAN: + switch (led_ligth_mode) { + case FAN_LED_MODE_OFF: return ONLP_LED_MODE_OFF; + case FAN_LED_MODE_GREEN: return ONLP_LED_MODE_GREEN; + case FAN_LED_MODE_RED: return ONLP_LED_MODE_RED; + default: return ONLP_LED_MODE_OFF; + } + case LED_TEMP: + switch (led_ligth_mode) { + case TEMP_LED_MODE_OFF: return ONLP_LED_MODE_OFF; + case TEMP_LED_MODE_GREEN: return ONLP_LED_MODE_GREEN; + case TEMP_LED_MODE_RED: return ONLP_LED_MODE_RED; + default: return ONLP_LED_MODE_OFF; + } + case LED_MASTER: + switch (led_ligth_mode) { + case MASTER_LED_MODE_OFF: return ONLP_LED_MODE_OFF; + case MASTER_LED_MODE_GREEN: return ONLP_LED_MODE_GREEN; + default: return ONLP_LED_MODE_OFF; + } + } + + return ONLP_LED_MODE_OFF; +} + +static int conver_onlp_led_light_mode_to_driver(uint32_t id, int led_ligth_mode) +{ + switch (id) { + case LED_SYS: + switch (led_ligth_mode) { + case ONLP_LED_MODE_GREEN_BLINKING: return SYS_LED_MODE_GREEN_BLINKING; + case ONLP_LED_MODE_GREEN: return SYS_LED_MODE_GREEN; + case ONLP_LED_MODE_RED: return SYS_LED_MODE_RED ; + case ONLP_LED_MODE_RED_BLINKING: return SYS_LED_MODE_RED_BLINKING; + default: return SYS_LED_MODE_UNKNOWN; + } + case LED_PSU1: + case LED_PSU2: + switch (led_ligth_mode) { + case ONLP_LED_MODE_OFF: return PSU_LED_MODE_OFF; + case ONLP_LED_MODE_GREEN: return PSU_LED_MODE_GREEN; + case ONLP_LED_MODE_GREEN_BLINKING: return PSU_LED_MODE_GREEN_BLINKING; + default: return PSU_LED_MODE_UNKNOWN; + } + case LED_FAN: + switch (led_ligth_mode) { + case ONLP_LED_MODE_OFF: return FAN_LED_MODE_OFF; + case ONLP_LED_MODE_GREEN: return FAN_LED_MODE_GREEN ; + case ONLP_LED_MODE_RED: return FAN_LED_MODE_RED; + default: return FAN_LED_MODE_UNKNOWN; + } + case LED_TEMP: + switch (led_ligth_mode) { + case ONLP_LED_MODE_OFF: return TEMP_LED_MODE_OFF; + case ONLP_LED_MODE_GREEN: return TEMP_LED_MODE_GREEN; + case ONLP_LED_MODE_RED: return TEMP_LED_MODE_RED; + default: return TEMP_LED_MODE_UNKNOWN; + } + case LED_MASTER: + switch (led_ligth_mode) { + case ONLP_LED_MODE_OFF: return MASTER_LED_MODE_OFF; + case ONLP_LED_MODE_GREEN: return MASTER_LED_MODE_GREEN; + default: return TEMP_LED_MODE_UNKNOWN; + } + + } + + return ONLP_LED_MODE_OFF; +} + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +onlp_ledi_oid_to_internal_id(onlp_oid_t id) +{ + int lid = ONLP_OID_ID_GET(id); + + switch (lid) { + case 1: return LED_SYS; + case 2: return LED_FAN; + case 3: return LED_PSU2; + case 4: return LED_PSU1; + case 5: return LED_TEMP; + case 6: return LED_MASTER; + default : + return LED_UNKNOW; + } + + return LED_UNKNOW; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int r_data,m_data; + + VALIDATE(id); + + enum ag6248c_product_id pid = get_product_id(); + + int lid = onlp_ledi_oid_to_internal_id(id); + + if (pid == PID_AG6248C_48) { + if((lid >= LED_UNKNOW) || (lid < LED_SYS)) + return ONLP_STATUS_E_UNSUPPORTED; + } + else if (pid == PID_AG6248C_48P) { + if((lid >= LED_MASTER) || (lid < LED_SYS)) + return ONLP_STATUS_E_UNSUPPORTED; + } + else + return ONLP_STATUS_E_UNSUPPORTED; + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[lid]; + + if((lid==LED_TEMP)||(lid==LED_MASTER)) + r_data=i2c_devname_read_byte("CPLD",CPLD_LED_MODE_TEMP_REG); + else + r_data=i2c_devname_read_byte("CPLD",CPLD_LED_MODE_REG); + + if(r_data<0) + return ONLP_STATUS_E_INTERNAL; + + if(lid==LED_TEMP) + m_data=(r_data & CPLD_LED_MODE_TEMP_REG_BIT); + else if(lid==LED_MASTER) + m_data=(r_data & CPLD_LED_MODE_MASTER_REG_BIT); + else + m_data=(r_data & CPLD_LED_MODE_REG_BIT(lid)); + + if(lid==LED_TEMP) + m_data=(m_data>> CPLD_LED_MODE_TEMP_REG_OFFSET); + else if(lid==LED_MASTER) + m_data=(m_data>> CPLD_LED_MODE_MASTER_REG_OFFSET); + else + m_data=(m_data>>CPLD_LED_MODE_REG_OFFSET(lid)); + + info->mode = conver_led_light_mode_to_onl(lid, m_data); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) { + info->status |= ONLP_LED_STATUS_ON; + + } + + return ONLP_STATUS_OK; +} + +/* + * This function puts the LED into the given mode. It is a more functional + * interface for multimode LEDs. + * + * Only modes reported in the LED's capabilities will be attempted. + */ +int +onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int r_data,driver_mode, rc; + + VALIDATE(id); + + enum ag6248c_product_id pid = get_product_id(); + + int lid = onlp_ledi_oid_to_internal_id(id); + + if (pid == PID_AG6248C_48) { + if((lid >= LED_UNKNOW) || (lid < LED_SYS)) + return ONLP_STATUS_E_UNSUPPORTED; + } + else if (pid == PID_AG6248C_48P) { + if((lid >= LED_MASTER) || (lid < LED_SYS)) + return ONLP_STATUS_E_UNSUPPORTED; + } + else + return ONLP_STATUS_E_UNSUPPORTED; + + driver_mode = conver_onlp_led_light_mode_to_driver(lid, mode); + + if((driver_mode==SYS_LED_MODE_UNKNOWN)||(driver_mode==PSU_LED_MODE_UNKNOWN)||\ + (driver_mode==FAN_LED_MODE_UNKNOWN)||(driver_mode==TEMP_LED_MODE_UNKNOWN)||\ + (driver_mode==MASTER_LED_MODE_UNKNOWN)) + return ONLP_STATUS_E_UNSUPPORTED; + + if((lid==LED_TEMP)||(lid==LED_MASTER)) + r_data=i2c_devname_read_byte("CPLD",CPLD_LED_MODE_TEMP_REG); + else + r_data=i2c_devname_read_byte("CPLD",CPLD_LED_MODE_REG); + + if(r_data<0) + return ONLP_STATUS_E_INTERNAL; + + if(lid==LED_TEMP) + r_data=r_data&(~CPLD_LED_MODE_TEMP_REG_BIT); + else if(lid==LED_MASTER) + r_data=r_data&(~CPLD_LED_MODE_MASTER_REG_BIT); + else + r_data=r_data&(~CPLD_LED_MODE_REG_BIT(lid)); + + if(lid==LED_TEMP) + driver_mode=(driver_mode< +# +# Copyright 2014, 2015 Big Switch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ + +LIBRARY := arm_delta_ag6248c +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +#$(LIBRARY)_LAST := 1 +include $(BUILDER)/lib.mk diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c new file mode 100755 index 00000000..118cc437 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c @@ -0,0 +1,85 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" +#include "arm_delta_i2c.h" + + +psu_type_t get_psu_type(int id) +{ + if ((id == PSU1_ID)||(id == PSU2_ID)) + return PSU_TYPE_AC_B2F; + return PSU_TYPE_UNKNOWN; +} + +enum ag6248c_product_id get_product_id(void) +{ + int ret; + int pid = PID_UNKNOWN; + + ret = i2c_devname_read_byte("CPLD", 0X01); + + if(ret<0) + return PID_UNKNOWN; + + pid = ((ret&0xf0)>>4); + + + if (pid >= PID_UNKNOWN || pid < PID_AG6248C_48) { + return PID_UNKNOWN; + } + + return pid; +} + +int chassis_fan_count(void) +{ + enum ag6248c_product_id pid = get_product_id(); + + if ((pid == PID_AG6248C_48P)||(pid == PID_AG6248C_48)) { + return 4; + } + + return 0 ; +} + +int chassis_led_count(void) +{ + enum ag6248c_product_id pid = get_product_id(); + + if (pid == PID_AG6248C_48P) + return 5; + else if(pid == PID_AG6248C_48) + return 6; + else + return 0; +} diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.h new file mode 100755 index 00000000..7cd66a5f --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.h @@ -0,0 +1,136 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include "arm_delta_ag6248c_log.h" + +#define CHASSIS_THERMAL_COUNT 4 +#define CHASSIS_PSU_COUNT 2 + +#define PSU1_ID 1 +#define PSU2_ID 2 + + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id); + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(format, ...) printf(format, __VA_ARGS__) +#else + #define DEBUG_PRINT(format, ...) +#endif + +enum onlp_fan_duty_cycle_percentage +{ + FAN_IDLE_RPM = 5500, + FAN_LEVEL1_RPM = 7000, + FAN_LEVEL2_RPM = 9000, + FAN_LEVEL3_RPM = 12000, +}; + +enum ag6248c_product_id { + PID_AG6248C_48= 2, + PID_AG6248C_48P=4, + PID_UNKNOWN +}; +/* LED related data */ +enum sys_led_light_mode { + SYS_LED_MODE_GREEN_BLINKING = 0, + SYS_LED_MODE_GREEN, + SYS_LED_MODE_RED, + SYS_LED_MODE_RED_BLINKING, + SYS_LED_MODE_AUTO, + SYS_LED_MODE_UNKNOWN +}; + +enum fan_led_light_mode { + FAN_LED_MODE_OFF=0, + FAN_LED_MODE_GREEN, + FAN_LED_MODE_RED, + FAN_LED_MODE_RESERVERD, + FAN_LED_MODE_AUTO, + FAN_LED_MODE_UNKNOWN +}; + +enum psu_led_light_mode { + PSU_LED_MODE_OFF =0, + PSU_LED_MODE_GREEN, + PSU_LED_MODE_GREEN_BLINKING, + PSU_LED_MODE_RESERVERD, + PSU_LED_MODE_UNKNOWN +}; + +enum temp_led_light_mode { + TEMP_LED_MODE_OFF =0, + TEMP_LED_MODE_GREEN, + TEMP_LED_MODE_RED, + TEMP_LED_MODE_RESERVERD, + TEMP_LED_MODE_UNKNOWN +}; + +enum master_led_light_mode { + MASTER_LED_MODE_OFF =0, + MASTER_LED_MODE_GREEN, + MASTER_LED_MODE_OFF1, + MASTER_LED_MODE_RESERVERD, + MASTER_LED_MODE_UNKNOWN +}; + +typedef enum onlp_led_id +{ + LED_RESERVED = 0, + LED_SYS, + LED_FAN, + LED_PSU2, + LED_PSU1, + LED_TEMP, + LED_MASTER, + LED_UNKNOW +} onlp_led_id_t; + +enum ag6248c_product_id get_product_id(void); +int chassis_fan_count(void); +int chassis_led_count(void); + +typedef enum platform_id_e { + PLATFORM_ID_UNKNOWN, + PLATFORM_ID_POWERPC_DELTA_AG6248C_POE_R0, + PLATFORM_ID_POWERPC_DELTA_AG6248C_R0, +} platform_id_t; + +extern platform_id_t platform_id; + +extern int psu_status_info_get(int id, char *node); +#endif /* __PLATFORM_LIB_H__ */ + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/psui.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/psui.c new file mode 100755 index 00000000..3a0d8344 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/psui.c @@ -0,0 +1,381 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include "platform_lib.h" +#include "arm_delta_ag6248c_int.h" +#include "arm_delta_i2c.h" + +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 +#define PSU_STATUS_REG (0X08) +#define PSU_STATUS_PRESENT_BIT(ch) (0x8<<4*(ch-1)) +#define PSU_STATUS_GOOD_BIT(ch) (0x4<<4*(ch-1)) +#define PSU_STATUS_PRESENT_OFFSET(ch) (4*ch-1) +#define PSU_STATUS_GOOD_OFFSET(ch) (0x2+4*(ch-1)) +#define PSU_PNBUS_VIN_REG (0x88) +#define PSU_PNBUS_IIN_REG (0x89) +#define PSU_PNBUS_PIN_REG (0x97) +#define PSU_PNBUS_VOUT_REG (0x8b) +#define PSU_PNBUS_IOUT_REG (0x8c) +#define PSU_PNBUS_POUT_REG (0x96) +#define PSU_PNBUS_SERIAL_REG (0x39) +#define PSU_PNBUS_MODEL_REG (0xc) + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static long psu_data_convert(unsigned int d, int mult) +{ + long X, Y, N, n; + + Y = d & 0x07FF; + N = (d >> 11) & 0x0f; + n = d & 0x8000 ? 1 : 0; + + if (n) + X = (Y * mult) / ((1<<(((~N)&0xf)+1))) ; + else + X = (Y * mult) * (N=(1<<(N&0xf))); + + return X; +} + +static long psu_data_convert_16(unsigned int d, int mult) +{ + long X; + X = (d * mult) / (1 << 9); + return X; + +} + + +int +psu_status_info_get(int id, char *node) +{ + int ret; + int r_data; + ret=i2c_devname_read_byte("CPLD",PSU_STATUS_REG); + + if(ret<0) + return -1; + + if (PSU1_ID == id) { + if(!strcmp("present",node)) + r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); + else if(!strcmp("good",node)) + r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); + else + r_data=-1; + + } + else if (PSU2_ID == id) { + + if(!strcmp("present",node)) + r_data=!((ret& PSU_STATUS_PRESENT_BIT(id))>> PSU_STATUS_PRESENT_OFFSET(id)); + else if(!strcmp("good",node)) + r_data=((ret& PSU_STATUS_GOOD_BIT(id))>> PSU_STATUS_GOOD_OFFSET(id)); + else + r_data=-1; + } + else{ + r_data=-1; + } + + return r_data; +} + +static int +psu_value_info_get(int id, char *type) +{ + int ret; + char *dev_name; + int reg_offset; + + enum ag6248c_product_id pid = get_product_id(); + + if(pid == PID_AG6248C_48){ + if(PSU1_ID == id) + dev_name="PSU1_PMBUS"; + else + dev_name="PSU2_PMBUS"; + } + else{ + if(PSU1_ID == id) + dev_name="PSU1_PMBUS_POE"; + else + dev_name="PSU2_PMBUS_POE"; + } + + if(!strcmp(type,"vin")) + reg_offset=PSU_PNBUS_VIN_REG; + else if(!strcmp(type,"iin")) + reg_offset=PSU_PNBUS_IIN_REG; + else if(!strcmp(type,"pin")) + reg_offset=PSU_PNBUS_PIN_REG; + else if(!strcmp(type,"vout")) + reg_offset=PSU_PNBUS_VOUT_REG; + else if(!strcmp(type,"iout")) + reg_offset=PSU_PNBUS_IOUT_REG; + else + reg_offset=PSU_PNBUS_POUT_REG; + + ret=i2c_devname_read_word(dev_name,reg_offset); + + if(ret<0) + return -1; + + return ret; +} + + +static int +psu_serial_model_info_get(int id,char *type,char*data,int data_len) +{ + int i,r_data,re_cnt; + char *dev_name; + int reg_offset; + + enum ag6248c_product_id pid = get_product_id(); + + if(pid == PID_AG6248C_48){ + if(PSU1_ID == id) + dev_name="PSU1_EEPROM"; + else + dev_name="PSU2_EEPROM"; + } + else{ + if(PSU1_ID == id) + dev_name="PSU1_EEPROM_POE"; + else + dev_name="PSU2_EEPROM_POE"; + } + + if(!strcmp(type,"serial")) + reg_offset=PSU_PNBUS_SERIAL_REG; + else + reg_offset=PSU_PNBUS_MODEL_REG; + + for(i=0;istatus &= ~ONLP_PSU_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + info->status |= ONLP_PSU_STATUS_PRESENT; + + /* Get power good status */ + val=psu_status_info_get(index,"good"); + + if (val<0) { + AIM_LOG_INFO("Unable to read PSU %d good value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + return ONLP_STATUS_OK; + } + + /* Get PSU type + */ + psu_type = get_psu_type(index); + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + case PSU_TYPE_AC_B2F: + info->caps = ONLP_PSU_CAPS_AC; + ret = ONLP_STATUS_OK; + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + /* Get PSU vin,vout*/ + + r_data=psu_value_info_get(index,"vin"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Vin value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->mvin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"vout"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Vout value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->mvout=psu_data_convert_16(r_data,1000); + /* Get PSU iin, iout + */ + r_data=psu_value_info_get(index,"iin"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Iin value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->miin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"iout"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Iout value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->miout=psu_data_convert(r_data,1000); + + /* Get PSU pin, pout + */ + r_data=psu_value_info_get(index,"pin"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Pin value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->mpin=psu_data_convert(r_data,1000); + + r_data=psu_value_info_get(index,"pout"); + + if (r_data<0) { + AIM_LOG_INFO("Unable to read PSU %d Pout value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + info->mpout=psu_data_convert(r_data,1000); + /* Get PSU serial + */ + + ret=psu_serial_model_info_get(index,"serial",sn_data,14); + if (ret!=ONLP_STATUS_OK) { + AIM_LOG_INFO("Unable to read PSU %d SN value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + strcpy(info->serial,sn_data); + + /* Get PSU model + */ + ret=psu_serial_model_info_get(index,"model",model_data,16); + if (ret!=ONLP_STATUS_OK) { + AIM_LOG_INFO("Unable to read PSU %d model value)\r\n", index); + return ONLP_STATUS_E_INVALID; + } + + strcpy(info->model,model_data); + + return ONLP_STATUS_OK; +} + +int +onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sfpi.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sfpi.c new file mode 100755 index 00000000..4764bbe9 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sfpi.c @@ -0,0 +1,364 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include "platform_lib.h" + +#include +#include "arm_delta_ag6248c_log.h" +#include "arm_delta_i2c.h" + +#define SFP_PRESENT_REG (0X14) +#define SFP_RX_LOS_REG (0X11) +#define SFP_TX_DISABLE_REG (0X17) +#define SFP_PRESENT_PORT47_BIT (0X40) +#define SFP_PRESENT_PORT48_BIT (0X80) +#define SFP_PRESENT_PORT47_OFFSET (0X06) +#define SFP_PRESENT_PORT48_OFFSET (0X07) + + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + int p; + int start_port, end_port; + + if((platform_id == PLATFORM_ID_POWERPC_DELTA_AG6248C_POE_R0)|| + (platform_id ==PLATFORM_ID_POWERPC_DELTA_AG6248C_R0)) + { + start_port = 47; + end_port = 48; + } + else /*reserved*/ + { + AIM_LOG_ERROR("The platform id %d is invalid \r\n", platform_id); + return ONLP_STATUS_E_UNSUPPORTED; + } + + for(p = start_port; p <=end_port; p++) { + AIM_BITMAP_SET(bmap, p); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present,r_data; + + if((port==47)||(port==48)) + r_data=i2c_devname_read_byte("CPLD", SFP_PRESENT_REG); + else{ + AIM_LOG_ERROR("The port %d is invalid \r\n", port); + return ONLP_STATUS_E_UNSUPPORTED; + } + + if(r_data<0){ + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if(port==47){ + r_data&=SFP_PRESENT_PORT47_BIT; + present=!(r_data>>SFP_PRESENT_PORT47_OFFSET); + } + else{ + r_data&=SFP_PRESENT_PORT48_BIT; + present=!(r_data>>SFP_PRESENT_PORT48_OFFSET); + } + + return present; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + int status; + int port, i = 0; + uint64_t presence_all=0; + + AIM_BITMAP_CLR_ALL(dst); + + if((platform_id == PLATFORM_ID_POWERPC_DELTA_AG6248C_POE_R0)|| \ + (platform_id ==PLATFORM_ID_POWERPC_DELTA_AG6248C_R0)){ + + port=47; + + } + else{ + AIM_LOG_ERROR("The platform id %d is invalid \r\n", platform_id); + return ONLP_STATUS_E_UNSUPPORTED; + } + + status=i2c_devname_read_byte("CPLD", SFP_PRESENT_REG); + + if(status<0){ + AIM_LOG_ERROR("Unable to read the sfp_is_present_all value. \r\n"); + return ONLP_STATUS_E_INTERNAL; + } + status=~status; + + status>>=6; + + /* Convert to 64 bit integer in port order */ + + presence_all = status & 0x3; + + presence_all <<= port; + + /* Populate bitmap */ + for(i = 0; presence_all; i++) { + AIM_BITMAP_MOD(dst, i, (presence_all & 1)); + presence_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + int status; + int port,i = 0; + uint64_t rx_los_all = 0; + + AIM_BITMAP_CLR_ALL(dst); + + if((platform_id == PLATFORM_ID_POWERPC_DELTA_AG6248C_POE_R0)|| \ + (platform_id ==PLATFORM_ID_POWERPC_DELTA_AG6248C_R0)){ + + port=47; + + } + else{ + AIM_LOG_ERROR("The platform id %d is invalid \r\n", platform_id); + return ONLP_STATUS_E_UNSUPPORTED; + } + + status=i2c_devname_read_byte("CPLD", SFP_RX_LOS_REG); + + if(status<0){ + AIM_LOG_ERROR("Unable to read the rx loss reg value. \r\n"); + return ONLP_STATUS_E_INTERNAL; + } + + status>>=6; + + /* Convert to 64 bit integer in port order */ + rx_los_all = status & 0x3; + + rx_los_all <<= port; + + /* Populate bitmap */ + for(i = 0; rx_los_all; i++) { + AIM_BITMAP_MOD(dst, i, (rx_los_all & 1)); + rx_los_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + + int i, r_data, re_cnt; + char* sfp_name; + + memset(data, 0, 256); + + if(port==47) + sfp_name="SFP1"; + else + sfp_name="SFP2"; + + + for(i=0;i<256;i++){ + re_cnt=3; + while(re_cnt){ + r_data=i2c_devname_read_byte(sfp_name,i); + if(r_data<0){ + re_cnt--; + continue; + } + data[i]=r_data; + break; + } + if(re_cnt==0){ + AIM_LOG_ERROR("Unable to read the %d reg \r\n",i); + return ONLP_STATUS_E_INTERNAL; + } + + } + + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + + return onlp_sfpi_eeprom_read( port, data); +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + /*value is 1 if the tx disable + value is 0 if the tx enable + */ + + int rc,r_data,dis_value,present; + + present=onlp_sfpi_is_present(port); + + if(present==0){ + AIM_LOG_INFO("The port %d is not present and can not set tx disable\r\n",port); + return ONLP_STATUS_E_UNSUPPORTED; + } + + r_data=i2c_devname_read_byte("CPLD", SFP_TX_DISABLE_REG); + + if(r_data<0){ + AIM_LOG_INFO("Unable to read sfp tx disable reg value\r\n"); + return ONLP_STATUS_E_INTERNAL; + } + + if(port==47){ + r_data&=~(0x1<>SFP_PRESENT_PORT47_OFFSET); + } + else{ + r_data&=(0x1<>SFP_PRESENT_PORT48_OFFSET); + } + + return ONLP_STATUS_OK; +} + + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c new file mode 100755 index 00000000..b8b0adec --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c @@ -0,0 +1,290 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "arm_delta_ag6248c_int.h" +#include "arm_delta_ag6248c_log.h" + +#include "platform_lib.h" +#include "arm_delta_i2c.h" +platform_id_t platform_id = PLATFORM_ID_UNKNOWN; + +#define ONIE_PLATFORM_NAME "arm-delta-ag6248c-r0" + +const char* +onlp_sysi_platform_get(void) +{ + enum ag6248c_product_id pid = get_product_id(); + + if (pid == PID_AG6248C_48) + return "arm-delta-ag6248c"; + else if(pid == PID_AG6248C_48P) + return "arm-delta-ag6248c-poe"; + else + return "unknow"; +} + +int +onlp_sysi_platform_set(const char* platform) +{ + if(strstr(platform,"arm-delta-ag6248c-r0")) { + platform_id = PLATFORM_ID_POWERPC_DELTA_AG6248C_R0; + return ONLP_STATUS_OK; + } + if(strstr(platform,"arm-delta-ag6248c-poe-r0")) { + platform_id = PLATFORM_ID_POWERPC_DELTA_AG6248C_POE_R0; + return ONLP_STATUS_OK; + } + AIM_LOG_ERROR("No support for platform '%s'", platform); + return ONLP_STATUS_E_UNSUPPORTED; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int v; + + v = i2c_devname_read_byte("CPLD", 0X07); + + pi->cpld_versions = aim_fstrdup("%d", v); + + return 0; +} + +int +onlp_sysi_onie_data_get(uint8_t** data, int* size) +{ + uint8_t* rdata = aim_zmalloc(256); + int fd,rc_size; + char fullpath[20] = {0}; + + sprintf(fullpath, "/dev/mtd7"); + + fd=open(fullpath,O_RDWR); + + if(fd<0){ + aim_free(rdata); + return ONLP_STATUS_E_INTERNAL ; + } + + rc_size=read(fd,rdata,256); + + if(rc_size<0||rc_size!=256){ + aim_free(rdata); + return ONLP_STATUS_E_INTERNAL ; + } + + *data = rdata; + + return ONLP_STATUS_OK; + + +} + +void +onlp_sysi_onie_data_free(uint8_t* data) +{ + aim_free(data); +} + + + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + /* 1 Thermal sensors on the chassis */ + for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* LEDs on the chassis */ + for (i = 1; i <= chassis_led_count(); i++) { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* 1 Fans on the chassis */ + for (i = 1; i <= chassis_fan_count(); i++) { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + /* 2 PSUs on the chassis */ + for (i = 1; i <= CHASSIS_PSU_COUNT; i++) { + *e++ = ONLP_PSU_ID_CREATE(i); + } + + return 0; +} + +int +onlp_sysi_platform_manage_fans(void) +{ + + int rc; + onlp_thermal_info_t ti1; + onlp_thermal_info_t ti2; + int mtemp=0; + int new_rpm=0; + + if (chassis_fan_count() == 0) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + /* Get temperature */ + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &ti1); + + if (rc != ONLP_STATUS_OK) { + return rc; + } + + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(2), &ti2); + + if (rc != ONLP_STATUS_OK) { + return rc; + } + + mtemp=(ti1.mcelsius+ti2.mcelsius)/2; + /* Bring fan speed according the temp + */ + if(mtemp<50000) + new_rpm=FAN_IDLE_RPM; + else if((mtemp>=55000)&&(mtemp<60000)) + new_rpm=FAN_LEVEL1_RPM; + else if((mtemp>=65000)&&(mtemp<70000)) + new_rpm=FAN_LEVEL2_RPM; + else if(mtemp>=75000) + new_rpm=FAN_LEVEL3_RPM; + else{ + return ONLP_STATUS_OK; + } + + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(1),new_rpm); + onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(2),new_rpm); + + + return ONLP_STATUS_OK; +} + + +int +onlp_sysi_platform_manage_leds(void) +{ + int rc,rc1; + + onlp_fan_info_t info1,info2; + onlp_led_mode_t fan_new_mode; + onlp_thermal_info_t ti; + onlp_led_mode_t temp_new_mode; + onlp_psu_info_t psu1; + onlp_led_mode_t psu1_new_mode; + onlp_psu_info_t psu2; + onlp_led_mode_t psu2_new_mode; + onlp_led_mode_t sys_new_mode; + /*fan led */ + rc=onlp_fani_info_get(ONLP_FAN_ID_CREATE(1), &info1); + + rc1=onlp_fani_info_get(ONLP_FAN_ID_CREATE(2), &info2); + + if ((rc != ONLP_STATUS_OK)||(rc1 != ONLP_STATUS_OK)){ + fan_new_mode=ONLP_LED_MODE_RED; + goto temp_led; + } + if(((info1.status&0x3)==1)&&((info2.status&0x3)==1)) + fan_new_mode=ONLP_LED_MODE_GREEN; + else + fan_new_mode=ONLP_LED_MODE_RED; + +temp_led: + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_FAN),fan_new_mode); + + /*temperature led */ + + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &ti); + if (rc != ONLP_STATUS_OK) { + temp_new_mode=ONLP_LED_MODE_OFF; + goto psu1_led; + } + if(ti.mcelsius >= 75000) + temp_new_mode=ONLP_LED_MODE_RED; + else + temp_new_mode=ONLP_LED_MODE_GREEN; + +psu1_led: + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_TEMP),temp_new_mode); + + /*psu1 and psu2 led */ + rc=onlp_psui_info_get(ONLP_PSU_ID_CREATE(1),&psu1); + + if (rc != ONLP_STATUS_OK) { + psu1_new_mode=ONLP_LED_MODE_OFF; + goto psu2_led; + } + + if((psu1.status&0x1)&&!(psu1.status&0x2)) + psu1_new_mode=ONLP_LED_MODE_GREEN; + else + psu1_new_mode=ONLP_LED_MODE_OFF; +psu2_led: + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PSU1),psu1_new_mode); + //psu2 led ---------------- + rc=onlp_psui_info_get(ONLP_PSU_ID_CREATE(2),&psu2); + + if (rc != ONLP_STATUS_OK) { + psu2_new_mode=ONLP_LED_MODE_OFF; + goto sys_led; + } + + if((psu2.status&0x1)&&!(psu2.status&0x2)) + psu2_new_mode=ONLP_LED_MODE_GREEN; + else + psu2_new_mode=ONLP_LED_MODE_OFF; +sys_led : + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_PSU2),psu2_new_mode); + //sys led ---------------- + + if((fan_new_mode!=ONLP_LED_MODE_GREEN)||((psu2_new_mode!=ONLP_LED_MODE_GREEN)&& \ + (psu1_new_mode!=ONLP_LED_MODE_GREEN))) + sys_new_mode=ONLP_LED_MODE_RED_BLINKING; + else + sys_new_mode=ONLP_LED_MODE_GREEN; + + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_SYS),sys_new_mode); + + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/thermali.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/thermali.c new file mode 100755 index 00000000..807855c9 --- /dev/null +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/thermali.c @@ -0,0 +1,208 @@ +/************************************************************ + * + * + * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2016 Accton Technology Corporation. + * Copyright 2017 Delta Networks, Inc + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include +#include +#include +#include "platform_lib.h" +#include "arm_delta_ag6248c_log.h" +#include +#include "arm_delta_i2c.h" +#define prefix_path "/sys/bus/i2c/devices/" +#define LOCAL_DEBUG 0 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + + +enum onlp_thermal_id +{ + THERMAL_RESERVED = 0, + THERMAL_1_CLOSE_TO_MAC, + THERMAL_2_CLOSE_TO_PHY, + THERMAL_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +static char* last_path[] = /* must map with onlp_thermal_id */ +{ + "reserved", + "0-0049/temp1_input", + "0-004a/temp1_input", +}; + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_CLOSE_TO_MAC), "Thermal Sensor 1- close to mac", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_CLOSE_TO_PHY), "Thermal Sensor 2- close to phy", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(1)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(2)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; +static int +_onlp_psu_thermali_val_to_temperature (int v,int mult) +{ + long X, Y, N, n; + Y = v & 0x07FF; + N = (v >> 11) & 0x0f; + n = v & 0x8000 ? 1 : 0; + if (n) + X = (Y * mult) / ((1<<(((~N)&0xf)+1))) ; + else + X = Y * mult * (N=(1<<(N&0xf))); + return X; +} +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +static int +_onlp_thermali_info_get(int id, onlp_thermal_info_t* info) +{ + int len, nbytes = 10, temp_base=1, local_id; + uint8_t r_data[10] = {0}; + char fullpath[50] = {0}; + + local_id = id; + + DEBUG_PRINT("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); + + /* get fullpath */ + sprintf(fullpath, "%s%s", prefix_path, last_path[local_id]); + + onlp_file_read(r_data,nbytes,&len, fullpath); + + info->mcelsius =ONLPLIB_ATOI((char*)r_data) / temp_base; + + DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius); + + return ONLP_STATUS_OK; +} + +static int +_onlp_thermali_psu_info_get(int id, onlp_thermal_info_t* info) +{ + int psu_present,psu_good; + int psu_id,local_id; + int r_data,temperature_v; + enum ag6248c_product_id pid; + + local_id=id; + + DEBUG_PRINT("\n[Debug][%s][%d][local_id: %d]", __FUNCTION__, __LINE__, local_id); + + psu_id=(local_id-THERMAL_1_ON_PSU1)+1; + pid=get_product_id(); + //if the psu is not, directly to return + psu_present=psu_status_info_get(psu_id, "present"); + psu_good=psu_status_info_get(psu_id, "good"); + if((psu_present<=0)||(psu_good<=0)){ + info->status &= ~ONLP_THERMAL_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + //read the pus temperture register value + if(pid == PID_AG6248C_48){ + if(psu_id==1) + r_data=i2c_devname_read_word("PSU1_PMBUS", 0x8d); + else + r_data=i2c_devname_read_word("PSU2_PMBUS", 0x8d); + } + else{ + if(psu_id==1) + r_data=i2c_devname_read_word("PSU1_PMBUS_POE", 0x8d); + else + r_data=i2c_devname_read_word("PSU2_PMBUS_POE", 0x8d); + } + if(r_data<0) + return ONLP_STATUS_E_INVALID; + //get the real temperture value + temperature_v=_onlp_psu_thermali_val_to_temperature(r_data,1000); + + info->mcelsius=temperature_v; + + DEBUG_PRINT("\n[Debug][%s][%d][save data: %d]\n", __FUNCTION__, __LINE__, info->mcelsius); + + return ONLP_STATUS_OK; + +} + +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int rc; + int local_id; + + VALIDATE(id); + + local_id=ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[local_id]; + + if((local_id==THERMAL_1_CLOSE_TO_MAC) || (local_id==THERMAL_2_CLOSE_TO_PHY)) + rc= _onlp_thermali_info_get(local_id,info); + else if((local_id==THERMAL_1_ON_PSU1) || (local_id==THERMAL_1_ON_PSU2)) + rc=_onlp_thermali_psu_info_get(local_id,info); + else{ + rc=ONLP_STATUS_E_INVALID; + } + return rc; +} + + + diff --git a/packages/platforms/delta/armel/modules/Makefile b/packages/platforms/delta/armel/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/delta/armel/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/delta/armel/modules/PKG.yml b/packages/platforms/delta/armel/modules/PKG.yml new file mode 100644 index 00000000..e73b86da --- /dev/null +++ b/packages/platforms/delta/armel/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/no-arch-vendor-modules.yml ARCH=armel VENDOR=delta From b1eeddcc3186b27c5066977cfd3687c061bca952 Mon Sep 17 00:00:00 2001 From: "shaohua.xiong" Date: Mon, 26 Feb 2018 15:37:53 +0800 Subject: [PATCH 02/21] amended the comment fot the platform ag6248c and ag6248c_poe --- .../delta/armel/arm-delta-ag6248c/README.md | 5 +---- .../builds/arm-delta-ag6248c-poe-cpld-mux-1.c | 10 ++++------ .../builds/arm-delta-ag6248c-poe-cpld-mux-2.c | 12 +++++------- .../modules/builds/arm-delta-ag6248c-cpld-mux-1.c | 10 ++++------ .../modules/builds/arm-delta-ag6248c-cpld-mux-2.c | 12 +++++------- 5 files changed, 19 insertions(+), 30 deletions(-) diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/README.md b/packages/platforms/delta/armel/arm-delta-ag6248c/README.md index b49d2126..20a424e5 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/README.md +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/README.md @@ -1,7 +1,4 @@ -#How to run ONL in DELTA AG6248C board - -For the first step, it only support install the ONL to the USB and boot up. -It will be support to install the ONL to NandFlash next step. +#How to run ONL in DELTA AG6248C and AG6248C_POE board Build the ONL -------------------------------------------------------------------------- diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c index 29686679..08d3b805 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-1.c @@ -1,13 +1,11 @@ /* - * An I2C multiplexer dirver for delta as5812 CPLD + * An I2C multiplexer dirver for delta ag6248c_poe CPLD * - * Copyright (C) 2015 Delta Technology Corporation. - * Brandon Chuang + * Copyright (C) 2018 Delta Networks, Inc. + * Shaohua Xiong * * This module supports the delta cpld that hold the channel select * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Delta ag7648c CPLD1/CPLD2/CPLD3 * * Based on: * pca954x.c from Kumar Gala @@ -233,7 +231,7 @@ static void __exit delta_i2c_cpld_mux_exit(void) __delta_i2c_cpld_mux_remove (); } -MODULE_AUTHOR("Dave Hu "); +MODULE_AUTHOR("Shaohua Xiong "); MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c index c3354b89..8ed6f32e 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c-poe/modules/builds/arm-delta-ag6248c-poe-cpld-mux-2.c @@ -1,13 +1,11 @@ /* - * An I2C multiplexer dirver for delta as5812 CPLD + * An I2C multiplexer dirver for delta ag6248c_poe CPLD * - * Copyright (C) 2015 Delta Technology Corporation. - * Brandon Chuang + * Copyright (C) 2018 Delta Networks, Inc. + * Shaohua.xiong * * This module supports the delta cpld that hold the channel select - * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Delta ag7648c CPLD1/CPLD2/CPLD3 + * mechanism for other i2c slave devices, such as PSU. * * Based on: * pca954x.c from Kumar Gala @@ -234,7 +232,7 @@ static void __exit delta_i2c_cpld_mux_exit(void) __delta_i2c_cpld_mux_remove (); } -MODULE_AUTHOR("Dave Hu "); +MODULE_AUTHOR("Shaohua.xiong "); MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c index 56d68b13..23b07f51 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-1.c @@ -1,13 +1,11 @@ /* - * An I2C multiplexer dirver for delta as5812 CPLD + * An I2C multiplexer dirver for delta ag6248c CPLD * - * Copyright (C) 2017 Delta Networks, Inc. - * Brandon Chuang + * Copyright (C) 2018 Delta Networks, Inc. + * Shaohua Xiong * * This module supports the delta cpld that hold the channel select * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Delta ag7648c CPLD1/CPLD2/CPLD3 * * Based on: * pca954x.c from Kumar Gala @@ -233,7 +231,7 @@ static void __exit delta_i2c_cpld_mux_exit(void) __delta_i2c_cpld_mux_remove (); } -MODULE_AUTHOR("Dave Hu "); +MODULE_AUTHOR("Shaohua Xiong "); MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c index 12b5fb38..a133439e 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/arm-delta-ag6248c/modules/builds/arm-delta-ag6248c-cpld-mux-2.c @@ -1,13 +1,11 @@ /* - * An I2C multiplexer dirver for delta as5812 CPLD + * An I2C multiplexer dirver for delta ag6248c CPLD * - * Copyright (C) 2017 Delta Networks, Inc. - * Brandon Chuang + * Copyright (C) 2018 Delta Networks, Inc. + * Shaohua Xiong * * This module supports the delta cpld that hold the channel select - * mechanism for other i2c slave devices, such as SFP. - * This includes the: - * Delta ag7648c CPLD1/CPLD2/CPLD3 + * mechanism for other i2c slave devices, such as PSU. * * Based on: * pca954x.c from Kumar Gala @@ -234,7 +232,7 @@ static void __exit delta_i2c_cpld_mux_exit(void) __delta_i2c_cpld_mux_remove (); } -MODULE_AUTHOR("Dave Hu "); +MODULE_AUTHOR("Shaohua Xiong "); MODULE_DESCRIPTION("Delta I2C CPLD mux driver"); MODULE_LICENSE("GPL"); From 58d6801e57c36cc4d5fd1a324f40ea1df109ca7f Mon Sep 17 00:00:00 2001 From: "shaohua.xiong" Date: Tue, 27 Feb 2018 18:42:15 +0800 Subject: [PATCH 03/21] modified the comment and module name for ag6248c and ag6248c_poe --- .../module/auto/arm_delta_ag6248c.yml | 30 +++--- .../inc/arm_delta_ag6248c/arm_delta_ag6248c.x | 7 +- .../arm_delta_ag6248c_config.h | 70 +++++++------- .../arm_delta_ag6248c/arm_delta_ag6248c_dox.h | 13 +-- .../arm_delta_ag6248c_porting.h | 96 +++++++++---------- .../module/src/arm_delta_ag6248c_config.c | 59 ++++++------ .../module/src/arm_delta_ag6248c_enums.c | 7 +- .../module/src/arm_delta_ag6248c_int.h | 13 +-- .../module/src/arm_delta_ag6248c_log.c | 13 +-- .../module/src/arm_delta_ag6248c_log.h | 13 +-- .../module/src/arm_delta_ag6248c_module.c | 10 +- .../module/src/arm_delta_ag6248c_ucli.c | 10 +- .../module/src/arm_delta_i2c.c | 11 +-- .../module/src/arm_delta_i2c.h | 10 +- .../src/arm_delta_ag6248c/module/src/fani.c | 4 +- .../module/src/platform_lib.c | 2 +- .../src/arm_delta_ag6248c/module/src/sysi.c | 8 +- 17 files changed, 149 insertions(+), 227 deletions(-) diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml index 80f1a97d..c807d0c5 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/auto/arm_delta_ag6248c.yml @@ -1,13 +1,7 @@ ############################################################ # # -# Copyright 2014, 2015 Big Switch Networks, Inc. -# -# Licensed under the Eclipse Public License, Version 1.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.eclipse.org/legal/epl-v10.html +# Copyright 2018, Delta Networks, Inc. # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an @@ -23,39 +17,39 @@ ############################################################ cdefs: &cdefs -- ONLPSIM_CONFIG_INCLUDE_LOGGING: +- ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING: doc: "Include or exclude logging." default: 1 -- ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT: +- ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT: doc: "Default enabled log options." default: AIM_LOG_OPTIONS_DEFAULT -- ONLPSIM_CONFIG_LOG_BITS_DEFAULT: +- ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT: doc: "Default enabled log bits." default: AIM_LOG_BITS_DEFAULT -- ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT: +- ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT: doc: "Default enabled custom log bits." default: 0 -- ONLPSIM_CONFIG_PORTING_STDLIB: +- ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB: doc: "Default all porting macros to use the C standard libraries." default: 1 -- ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: +- ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: doc: "Include standard library headers for stdlib porting macros." - default: ONLPSIM_CONFIG_PORTING_STDLIB -- ONLPSIM_CONFIG_INCLUDE_UCLI: + default: ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB +- ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI: doc: "Include generic uCli support." default: 0 -- ONLPSIM_CONFIG_SFP_COUNT: +- ARM_DELTA_AG6248C_CONFIG_SFP_COUNT: doc: "SFP Count." default: 0 definitions: cdefs: - ONLPSIM_CONFIG_HEADER: + ARM_DELTA_AG6248C_CONFIG_HEADER: defs: *cdefs basename: arm_delta_ag6248c_config portingmacro: - ONLPSIM: + ARM_DELTA_AG6248C: macros: - malloc - free diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x index f15500cc..fe36b7c6 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c.x @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h index 68664185..33b217e1 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_config.h @@ -1,14 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html - * + * Copyright 2018, Delta Networks, Inc. + * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, @@ -32,96 +26,96 @@ * @{ * *****************************************************************************/ -#ifndef __ONLPSIM_CONFIG_H__ -#define __ONLPSIM_CONFIG_H__ +#ifndef __ARM_DELTA_AG6248C_CONFIG_H__ +#define __ARM_DELTA_AG6248C_CONFIG_H__ #ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG #include #endif -#ifdef ONLPSIM_INCLUDE_CUSTOM_CONFIG +#ifdef ARM_DELTA_AG6248C_INCLUDE_CUSTOM_CONFIG #include #endif -/* */ +/* */ #include /** - * ONLPSIM_CONFIG_INCLUDE_LOGGING + * ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING * * Include or exclude logging. */ -#ifndef ONLPSIM_CONFIG_INCLUDE_LOGGING -#define ONLPSIM_CONFIG_INCLUDE_LOGGING 1 +#ifndef ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING +#define ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING 1 #endif /** - * ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT + * ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT * * Default enabled log options. */ -#ifndef ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT -#define ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#ifndef ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT +#define ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT #endif /** - * ONLPSIM_CONFIG_LOG_BITS_DEFAULT + * ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT * * Default enabled log bits. */ -#ifndef ONLPSIM_CONFIG_LOG_BITS_DEFAULT -#define ONLPSIM_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#ifndef ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT +#define ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT #endif /** - * ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT * * Default enabled custom log bits. */ -#ifndef ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT -#define ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#ifndef ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 #endif /** - * ONLPSIM_CONFIG_PORTING_STDLIB + * ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB * * Default all porting macros to use the C standard libraries. */ -#ifndef ONLPSIM_CONFIG_PORTING_STDLIB -#define ONLPSIM_CONFIG_PORTING_STDLIB 1 +#ifndef ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB +#define ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB 1 #endif /** - * ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS * * Include standard library headers for stdlib porting macros. */ -#ifndef ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS -#define ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS ONLPSIM_CONFIG_PORTING_STDLIB +#ifndef ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB #endif /** - * ONLPSIM_CONFIG_INCLUDE_UCLI + * ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI * * Include generic uCli support. */ -#ifndef ONLPSIM_CONFIG_INCLUDE_UCLI -#define ONLPSIM_CONFIG_INCLUDE_UCLI 0 +#ifndef ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI +#define ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI 0 #endif /** - * ONLPSIM_CONFIG_SFP_COUNT + * ARM_DELTA_AG6248C_CONFIG_SFP_COUNT * * SFP Count. */ -#ifndef ONLPSIM_CONFIG_SFP_COUNT -#define ONLPSIM_CONFIG_SFP_COUNT 0 +#ifndef ARM_DELTA_AG6248C_CONFIG_SFP_COUNT +#define ARM_DELTA_AG6248C_CONFIG_SFP_COUNT 0 #endif @@ -154,9 +148,9 @@ const char* arm_delta_ag6248c_config_lookup(const char* setting); */ int arm_delta_ag6248c_config_show(struct aim_pvs_s* pvs); -/* */ +/* */ #include "arm_delta_ag6248c_porting.h" -#endif /* __ONLPSIM_CONFIG_H__ */ +#endif /* __ARM_DELTA_AG6248C_CONFIG_H__ */ /* @} */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h index 20f312ed..bc2e4f7a 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_dox.h @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -28,8 +23,8 @@ * arm_delta_ag6248c Doxygen Header * ***********************************************************/ -#ifndef __ONLPSIM_DOX_H__ -#define __ONLPSIM_DOX_H__ +#ifndef __ARM_DELTA_AG6248C_DOX_H__ +#define __ARM_DELTA_AG6248C_DOX_H__ /** * @defgroup arm_delta_ag6248c arm_delta_ag6248c - onlpsim Description @@ -48,4 +43,4 @@ The documentation overview for this module should go here. * */ -#endif /* __ONLPSIM_DOX_H__ */ +#endif /* __ARM_DELTA_AG6248C_DOX_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h index 19853401..15f715f3 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/inc/arm_delta_ag6248c/arm_delta_ag6248c_porting.h @@ -1,13 +1,7 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html + * Copyright 2018, Delta Networks, Inc. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -32,12 +26,12 @@ * @{ * ***********************************************************/ -#ifndef __ONLPSIM_PORTING_H__ -#define __ONLPSIM_PORTING_H__ +#ifndef __ARM_DELTA_AG6248C_PORTING_H__ +#define __ARM_DELTA_AG6248C_PORTING_H__ /* */ -#if ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#if ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 #include #include #include @@ -45,88 +39,88 @@ #include #endif -#ifndef ONLPSIM_MALLOC +#ifndef ARM_DELTA_AG6248C_MALLOC #if defined(GLOBAL_MALLOC) - #define ONLPSIM_MALLOC GLOBAL_MALLOC - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_MALLOC malloc + #define ARM_DELTA_AG6248C_MALLOC GLOBAL_MALLOC + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_MALLOC malloc #else - #error The macro ONLPSIM_MALLOC is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_MALLOC is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_FREE +#ifndef ARM_DELTA_AG6248C_FREE #if defined(GLOBAL_FREE) - #define ONLPSIM_FREE GLOBAL_FREE - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_FREE free + #define ARM_DELTA_AG6248C_FREE GLOBAL_FREE + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_FREE free #else - #error The macro ONLPSIM_FREE is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_FREE is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_MEMSET +#ifndef ARM_DELTA_AG6248C_MEMSET #if defined(GLOBAL_MEMSET) - #define ONLPSIM_MEMSET GLOBAL_MEMSET - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_MEMSET memset + #define ARM_DELTA_AG6248C_MEMSET GLOBAL_MEMSET + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_MEMSET memset #else - #error The macro ONLPSIM_MEMSET is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_MEMSET is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_MEMCPY +#ifndef ARM_DELTA_AG6248C_MEMCPY #if defined(GLOBAL_MEMCPY) - #define ONLPSIM_MEMCPY GLOBAL_MEMCPY - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_MEMCPY memcpy + #define ARM_DELTA_AG6248C_MEMCPY GLOBAL_MEMCPY + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_MEMCPY memcpy #else - #error The macro ONLPSIM_MEMCPY is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_MEMCPY is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_STRNCPY +#ifndef ARM_DELTA_AG6248C_STRNCPY #if defined(GLOBAL_STRNCPY) - #define ONLPSIM_STRNCPY GLOBAL_STRNCPY - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_STRNCPY strncpy + #define ARM_DELTA_AG6248C_STRNCPY GLOBAL_STRNCPY + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_STRNCPY strncpy #else - #error The macro ONLPSIM_STRNCPY is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_STRNCPY is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_VSNPRINTF +#ifndef ARM_DELTA_AG6248C_VSNPRINTF #if defined(GLOBAL_VSNPRINTF) - #define ONLPSIM_VSNPRINTF GLOBAL_VSNPRINTF - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_VSNPRINTF vsnprintf + #define ARM_DELTA_AG6248C_VSNPRINTF GLOBAL_VSNPRINTF + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_VSNPRINTF vsnprintf #else - #error The macro ONLPSIM_VSNPRINTF is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_VSNPRINTF is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_SNPRINTF +#ifndef ARM_DELTA_AG6248C_SNPRINTF #if defined(GLOBAL_SNPRINTF) - #define ONLPSIM_SNPRINTF GLOBAL_SNPRINTF - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_SNPRINTF snprintf + #define ARM_DELTA_AG6248C_SNPRINTF GLOBAL_SNPRINTF + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_SNPRINTF snprintf #else - #error The macro ONLPSIM_SNPRINTF is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_SNPRINTF is required but cannot be defined. #endif #endif -#ifndef ONLPSIM_STRLEN +#ifndef ARM_DELTA_AG6248C_STRLEN #if defined(GLOBAL_STRLEN) - #define ONLPSIM_STRLEN GLOBAL_STRLEN - #elif ONLPSIM_CONFIG_PORTING_STDLIB == 1 - #define ONLPSIM_STRLEN strlen + #define ARM_DELTA_AG6248C_STRLEN GLOBAL_STRLEN + #elif ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB == 1 + #define ARM_DELTA_AG6248C_STRLEN strlen #else - #error The macro ONLPSIM_STRLEN is required but cannot be defined. + #error The macro ARM_DELTA_AG6248C_STRLEN is required but cannot be defined. #endif #endif /* */ -#endif /* __ONLPSIM_PORTING_H__ */ +#endif /* __ARM_DELTA_AG6248C_PORTING_H__ */ /* @} */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c index 6447135c..e116934f 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_config.c @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -25,50 +20,50 @@ #include -/* */ +/* */ #define __arm_delta_ag6248c_config_STRINGIFY_NAME(_x) #_x #define __arm_delta_ag6248c_config_STRINGIFY_VALUE(_x) __arm_delta_ag6248c_config_STRINGIFY_NAME(_x) arm_delta_ag6248c_config_settings_t arm_delta_ag6248c_config_settings[] = { -#ifdef ONLPSIM_CONFIG_INCLUDE_LOGGING - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_INCLUDE_LOGGING), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_INCLUDE_LOGGING) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING) }, #else -{ ONLPSIM_CONFIG_INCLUDE_LOGGING(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_INCLUDE_LOGGING(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT) }, #else -{ ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_LOG_BITS_DEFAULT - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_BITS_DEFAULT) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT) }, #else -{ ONLPSIM_CONFIG_LOG_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, #else -{ ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_PORTING_STDLIB - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_PORTING_STDLIB), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_PORTING_STDLIB) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB) }, #else -{ ONLPSIM_CONFIG_PORTING_STDLIB(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_PORTING_STDLIB(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, #else -{ ONLPSIM_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_INCLUDE_UCLI - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_INCLUDE_UCLI), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_INCLUDE_UCLI) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI) }, #else -{ ONLPSIM_CONFIG_INCLUDE_UCLI(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef ONLPSIM_CONFIG_SFP_COUNT - { __arm_delta_ag6248c_config_STRINGIFY_NAME(ONLPSIM_CONFIG_SFP_COUNT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ONLPSIM_CONFIG_SFP_COUNT) }, +#ifdef ARM_DELTA_AG6248C_CONFIG_SFP_COUNT + { __arm_delta_ag6248c_config_STRINGIFY_NAME(ARM_DELTA_AG6248C_CONFIG_SFP_COUNT), __arm_delta_ag6248c_config_STRINGIFY_VALUE(ARM_DELTA_AG6248C_CONFIG_SFP_COUNT) }, #else -{ ONLPSIM_CONFIG_SFP_COUNT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, +{ ARM_DELTA_AG6248C_CONFIG_SFP_COUNT(__arm_delta_ag6248c_config_STRINGIFY_NAME), "__undefined__" }, #endif { NULL, NULL } }; @@ -97,5 +92,5 @@ arm_delta_ag6248c_config_show(struct aim_pvs_s* pvs) return i; } -/* */ +/* */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c index 2a14c2cc..f8b2d375 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_enums.c @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h index 8dfd2c7c..d87656ee 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_int.h @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -23,10 +18,10 @@ * ***********************************************************/ -#ifndef __ONLPSIM_INT_H__ -#define __ONLPSIM_INT_H__ +#ifndef __ARM_DELTA_AG6248C_INT_H__ +#define __ARM_DELTA_AG6248C_INT_H__ #include -#endif /* __ONLPSIM_INT_H__ */ +#endif /* __ARM_DELTA_AG6248C_INT_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c index 1941f294..772566b5 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.c @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -30,9 +25,9 @@ * arm_delta_ag6248c log struct. */ AIM_LOG_STRUCT_DEFINE( - ONLPSIM_CONFIG_LOG_OPTIONS_DEFAULT, - ONLPSIM_CONFIG_LOG_BITS_DEFAULT, + ARM_DELTA_AG6248C_CONFIG_LOG_OPTIONS_DEFAULT, + ARM_DELTA_AG6248C_CONFIG_LOG_BITS_DEFAULT, NULL, /* Custom log map */ - ONLPSIM_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ARM_DELTA_AG6248C_CONFIG_LOG_CUSTOM_BITS_DEFAULT ); diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h index 13d00bc5..3d5d1e79 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_log.h @@ -1,13 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. + * Copyright 2018, Delta Networks, Inc. * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -23,10 +18,10 @@ * ***********************************************************/ -#ifndef __ONLPSIM_LOG_H__ -#define __ONLPSIM_LOG_H__ +#ifndef __ARM_DELTA_AG6248C_LOG_H__ +#define __ARM_DELTA_AG6248C_LOG_H__ #define AIM_LOG_MODULE_NAME arm_delta_ag6248c #include -#endif /* __ONLPSIM_LOG_H__ */ +#endif /* __ARM_DELTA_AG6248C_LOG_H__ */ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c index fdb080f0..c2e8bad5 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_module.c @@ -1,13 +1,7 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html + * Copyright 2018, Delta Networks, Inc. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -30,7 +24,7 @@ static int datatypes_init__(void) { -#define ONLPSIM_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#define ARM_DELTA_AG6248C_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); #include return 0; } diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c index 4dbeeed0..b99ca825 100644 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_ag6248c_ucli.c @@ -1,13 +1,7 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html + * Copyright 2018, Delta Networks, Inc. * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an @@ -25,7 +19,7 @@ #include -#if ONLPSIM_CONFIG_INCLUDE_UCLI == 1 +#if ARM_DELTA_AG6248C_CONFIG_INCLUDE_UCLI == 1 #include #include diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c index a7a83e0e..6a280e65 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.c @@ -1,15 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * Copyright 2016 Accton Technology Corporation. - * Copyright 2017 Delta Networks, Inc - * Copyright 2017 Delta Networks, Inc - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html + * Copyright 2018 Delta Technology Corporation. + * Copyright 2018 Delta Networks, Inc * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h index 76c35cbb..5b24b76d 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/arm_delta_i2c.h @@ -1,14 +1,8 @@ /************************************************************ * * - * Copyright 2014, 2015 Big Switch Networks, Inc. - * Copyright 2016 Accton Technology Corporation. - * Copyright 2017 Delta Networks, Inc - * Licensed under the Eclipse Public License, Version 1.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.eclipse.org/legal/epl-v10.html + * Copyright 2018 Delta Technology Corporation. + * Copyright 2018 Delta Networks, Inc * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c index b0c16526..e511eca6 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/fani.c @@ -64,7 +64,7 @@ enum onlp_fan_id #define MAKE_FAN_INFO_NODE_ON_MAIN_BOARD(id) \ { \ { ONLP_FAN_ID_CREATE(FAN_##id##_ON_MAIN_BOARD), "Chassis Fan "#id, 0 }, \ - ONLP_FAN_STATUS_B2F | ONLP_FAN_STATUS_PRESENT, \ + ONLP_FAN_STATUS_F2B | ONLP_FAN_STATUS_PRESENT, \ (ONLP_FAN_CAPS_SET_PERCENTAGE |ONLP_FAN_CAPS_SET_RPM| ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ 0, \ 0, \ @@ -74,7 +74,7 @@ enum onlp_fan_id #define MAKE_FAN_INFO_NODE_ON_PSU(psu_id, fan_id) \ { \ { ONLP_FAN_ID_CREATE(FAN_##fan_id##_ON_PSU##psu_id), "Chassis PSU-"#psu_id " Fan "#fan_id, 0 }, \ - ONLP_FAN_STATUS_B2F | ONLP_FAN_STATUS_PRESENT, \ + ONLP_FAN_STATUS_F2B | ONLP_FAN_STATUS_PRESENT, \ (ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE), \ 0, \ 0, \ diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c index 118cc437..a5b27735 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/platform_lib.c @@ -37,7 +37,7 @@ psu_type_t get_psu_type(int id) { if ((id == PSU1_ID)||(id == PSU2_ID)) - return PSU_TYPE_AC_B2F; + return PSU_TYPE_AC_F2B; return PSU_TYPE_UNKNOWN; } diff --git a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c index b8b0adec..649a4e04 100755 --- a/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c +++ b/packages/platforms/delta/armel/arm-delta-ag6248c/src/arm_delta_ag6248c/module/src/sysi.c @@ -165,13 +165,13 @@ onlp_sysi_platform_manage_fans(void) } /* Get temperature */ - rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(1), &ti1); + rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(1), &ti1); if (rc != ONLP_STATUS_OK) { return rc; } - rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(2), &ti2); + rc = onlp_thermal_info_get(ONLP_THERMAL_ID_CREATE(2), &ti2); if (rc != ONLP_STATUS_OK) { return rc; @@ -192,8 +192,8 @@ onlp_sysi_platform_manage_fans(void) return ONLP_STATUS_OK; } - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(1),new_rpm); - onlp_fani_rpm_set(ONLP_FAN_ID_CREATE(2),new_rpm); + onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(1),new_rpm); + onlp_fan_rpm_set(ONLP_FAN_ID_CREATE(2),new_rpm); return ONLP_STATUS_OK; From eafbd5c95e028873adbd728206567cf3e6084a35 Mon Sep 17 00:00:00 2001 From: roylee123 Date: Wed, 7 Mar 2018 04:02:47 +0000 Subject: [PATCH 04/21] [accton] add new platform x86-64-accton-as5916-54xk. Signed-off-by: roylee123 --- .../x86-64-accton-as5916-54xk/.gitignore | 2 + .../x86-64/x86-64-accton-as5916-54xk/Makefile | 1 + .../modules/Makefile | 1 + .../x86-64-accton-as5916-54xk/modules/PKG.yml | 1 + .../modules/builds/.gitignore | 1 + .../modules/builds/Makefile | 6 + .../builds/x86-64-accton-as5916-54xk-fan.c | 485 ++++++ .../builds/x86-64-accton-as5916-54xk-leds.c | 386 +++++ .../builds/x86-64-accton-as5916-54xk-psu.c | 288 ++++ .../builds/x86-64-accton-as5916-54xk-sfp.c | 1315 +++++++++++++++++ .../x86-64-accton-as5916-54xk/onlp/Makefile | 1 + .../x86-64-accton-as5916-54xk/onlp/PKG.yml | 1 + .../onlp/builds/Makefile | 2 + .../onlp/builds/lib/Makefile | 45 + .../onlp/builds/onlpdump/Makefile | 46 + .../onlp/builds/src/.module | 1 + .../onlp/builds/src/Makefile | 9 + .../onlp/builds/src/README | 6 + .../onlp/builds/src/module/auto/make.mk | 9 + .../module/auto/x86_64_accton_as5916_54xk.yml | 50 + .../x86_64_accton_as5916_54xk.x | 14 + .../x86_64_accton_as5916_54xk_config.h | 137 ++ .../x86_64_accton_as5916_54xk_dox.h | 26 + .../x86_64_accton_as5916_54xk_porting.h | 107 ++ .../onlp/builds/src/module/make.mk | 10 + .../onlp/builds/src/module/src/Makefile | 9 + .../onlp/builds/src/module/src/fani.c | 303 ++++ .../onlp/builds/src/module/src/ledi.c | 247 ++++ .../onlp/builds/src/module/src/make.mk | 9 + .../onlp/builds/src/module/src/platform_lib.c | 124 ++ .../onlp/builds/src/module/src/platform_lib.h | 89 ++ .../onlp/builds/src/module/src/psui.c | 177 +++ .../onlp/builds/src/module/src/sfpi.c | 287 ++++ .../onlp/builds/src/module/src/sysi.c | 339 +++++ .../onlp/builds/src/module/src/thermali.c | 128 ++ .../src/x86_64_accton_as5916_54xk_config.c | 80 + .../src/x86_64_accton_as5916_54xk_enums.c | 10 + .../src/x86_64_accton_as5916_54xk_int.h | 12 + .../src/x86_64_accton_as5916_54xk_log.c | 18 + .../src/x86_64_accton_as5916_54xk_log.h | 12 + .../src/x86_64_accton_as5916_54xk_module.c | 24 + .../src/x86_64_accton_as5916_54xk_ucli.c | 50 + .../platform-config/Makefile | 1 + .../platform-config/r1/Makefile | 1 + .../platform-config/r1/PKG.yml | 1 + .../src/lib/x86-64-accton-as5916-54xk-r1.yml | 33 + .../x86_64_accton_as5916_54xk_r1/__init__.py | 72 + 47 files changed, 4976 insertions(+) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/.gitignore create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/fani.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/psui.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/thermali.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/Makefile create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore new file mode 100644 index 00000000..2e2944b3 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore @@ -0,0 +1,2 @@ +*x86*64*accton*as5916*54x*.mk +onlpdump.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml new file mode 100644 index 00000000..b6c16c5e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5916-54x ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/.gitignore new file mode 100644 index 00000000..a65b4177 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/.gitignore @@ -0,0 +1 @@ +lib diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile new file mode 100644 index 00000000..0ae14eaa --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile @@ -0,0 +1,6 @@ +KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 +KMODULES := $(wildcard *.c) +VENDOR := accton +BASENAME := x86-64-accton-as5916-54x +ARCH := x86_64 +include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c new file mode 100644 index 00000000..e69660e4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c @@ -0,0 +1,485 @@ +/* + * A hwmon driver for the Accton as5916 54x fan + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRVNAME "as5916_54x_fan" +#define MAX_FAN_SPEED_RPM 25500 + +static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *dev); +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); + +/* fan related data, the index should match sysfs_fan_attributes + */ +static const u8 fan_reg[] = { + 0x0F, /* fan 1-6 present status */ + 0x10, /* fan 1-6 direction(0:B2F 1:F2B) */ + 0x11, /* fan PWM(for all fan) */ + 0x12, /* front fan 1 speed(rpm) */ + 0x13, /* front fan 2 speed(rpm) */ + 0x14, /* front fan 3 speed(rpm) */ + 0x15, /* front fan 4 speed(rpm) */ + 0x16, /* front fan 5 speed(rpm) */ + 0x17, /* front fan 6 speed(rpm) */ + 0x22, /* rear fan 1 speed(rpm) */ + 0x23, /* rear fan 2 speed(rpm) */ + 0x24, /* rear fan 3 speed(rpm) */ + 0x25, /* rear fan 4 speed(rpm) */ + 0x26, /* rear fan 5 speed(rpm) */ + 0x27, /* rear fan 6 speed(rpm) */ +}; + +/* Each client has this additional data */ +struct as5916_54x_fan_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[ARRAY_SIZE(fan_reg)]; /* Register value */ +}; + +enum fan_id { + FAN1_ID, + FAN2_ID, + FAN3_ID, + FAN4_ID, + FAN5_ID, + FAN6_ID +}; + +enum sysfs_fan_attributes { + FAN_PRESENT_REG, + FAN_DIRECTION_REG, + FAN_DUTY_CYCLE_PERCENTAGE, /* Only one CPLD register to control duty cycle for all fans */ + FAN1_FRONT_SPEED_RPM, + FAN2_FRONT_SPEED_RPM, + FAN3_FRONT_SPEED_RPM, + FAN4_FRONT_SPEED_RPM, + FAN5_FRONT_SPEED_RPM, + FAN6_FRONT_SPEED_RPM, + FAN1_REAR_SPEED_RPM, + FAN2_REAR_SPEED_RPM, + FAN3_REAR_SPEED_RPM, + FAN4_REAR_SPEED_RPM, + FAN5_REAR_SPEED_RPM, + FAN6_REAR_SPEED_RPM, + FAN1_DIRECTION, + FAN2_DIRECTION, + FAN3_DIRECTION, + FAN4_DIRECTION, + FAN5_DIRECTION, + FAN6_DIRECTION, + FAN1_PRESENT, + FAN2_PRESENT, + FAN3_PRESENT, + FAN4_PRESENT, + FAN5_PRESENT, + FAN6_PRESENT, + FAN1_FAULT, + FAN2_FAULT, + FAN3_FAULT, + FAN4_FAULT, + FAN5_FAULT, + FAN6_FAULT, + FAN_MAX_RPM +}; + +/* Define attributes + */ +#define DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_fault, S_IRUGO, fan_show_value, NULL, FAN##index##_FAULT) +#define DECLARE_FAN_FAULT_ATTR(index) &sensor_dev_attr_fan##index##_fault.dev_attr.attr + +#define DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_direction, S_IRUGO, fan_show_value, NULL, FAN##index##_DIRECTION) +#define DECLARE_FAN_DIRECTION_ATTR(index) &sensor_dev_attr_fan##index##_direction.dev_attr.attr + +#define DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_duty_cycle_percentage, S_IWUSR | S_IRUGO, fan_show_value, set_duty_cycle, FAN##index##_DUTY_CYCLE_PERCENTAGE) +#define DECLARE_FAN_DUTY_CYCLE_ATTR(index) &sensor_dev_attr_fan##index##_duty_cycle_percentage.dev_attr.attr + +#define DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_present, S_IRUGO, fan_show_value, NULL, FAN##index##_PRESENT) +#define DECLARE_FAN_PRESENT_ATTR(index) &sensor_dev_attr_fan##index##_present.dev_attr.attr + +#define DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(index) \ + static SENSOR_DEVICE_ATTR(fan##index##_front_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_FRONT_SPEED_RPM);\ + static SENSOR_DEVICE_ATTR(fan##index##_rear_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN##index##_REAR_SPEED_RPM) +#define DECLARE_FAN_SPEED_RPM_ATTR(index) &sensor_dev_attr_fan##index##_front_speed_rpm.dev_attr.attr, \ + &sensor_dev_attr_fan##index##_rear_speed_rpm.dev_attr.attr + +static SENSOR_DEVICE_ATTR(fan_max_speed_rpm, S_IRUGO, fan_show_value, NULL, FAN_MAX_RPM); +#define DECLARE_FAN_MAX_RPM_ATTR(index) &sensor_dev_attr_fan_max_speed_rpm.dev_attr.attr + +/* 6 fan fault attributes in this platform */ +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(1); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(2); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(3); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(4); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(5); +DECLARE_FAN_FAULT_SENSOR_DEV_ATTR(6); +/* 6 fan speed(rpm) attributes in this platform */ +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(1); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(2); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(3); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(4); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(5); +DECLARE_FAN_SPEED_RPM_SENSOR_DEV_ATTR(6); +/* 6 fan present attributes in this platform */ +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(1); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(2); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(3); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(4); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(5); +DECLARE_FAN_PRESENT_SENSOR_DEV_ATTR(6); +/* 6 fan direction attribute in this platform */ +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(1); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(2); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(3); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(4); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(5); +DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); +/* 1 fan duty cycle attribute in this platform */ +DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(); + +static struct attribute *as5916_54x_fan_attributes[] = { + /* fan related attributes */ + DECLARE_FAN_FAULT_ATTR(1), + DECLARE_FAN_FAULT_ATTR(2), + DECLARE_FAN_FAULT_ATTR(3), + DECLARE_FAN_FAULT_ATTR(4), + DECLARE_FAN_FAULT_ATTR(5), + DECLARE_FAN_FAULT_ATTR(6), + DECLARE_FAN_SPEED_RPM_ATTR(1), + DECLARE_FAN_SPEED_RPM_ATTR(2), + DECLARE_FAN_SPEED_RPM_ATTR(3), + DECLARE_FAN_SPEED_RPM_ATTR(4), + DECLARE_FAN_SPEED_RPM_ATTR(5), + DECLARE_FAN_SPEED_RPM_ATTR(6), + DECLARE_FAN_PRESENT_ATTR(1), + DECLARE_FAN_PRESENT_ATTR(2), + DECLARE_FAN_PRESENT_ATTR(3), + DECLARE_FAN_PRESENT_ATTR(4), + DECLARE_FAN_PRESENT_ATTR(5), + DECLARE_FAN_PRESENT_ATTR(6), + DECLARE_FAN_DIRECTION_ATTR(1), + DECLARE_FAN_DIRECTION_ATTR(2), + DECLARE_FAN_DIRECTION_ATTR(3), + DECLARE_FAN_DIRECTION_ATTR(4), + DECLARE_FAN_DIRECTION_ATTR(5), + DECLARE_FAN_DIRECTION_ATTR(6), + DECLARE_FAN_DUTY_CYCLE_ATTR(), + DECLARE_FAN_MAX_RPM_ATTR(), + NULL +}; + +#define FAN_DUTY_CYCLE_REG_MASK 0xF +#define FAN_MAX_DUTY_CYCLE 100 +#define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 + +static int as5916_54x_fan_read_value(struct i2c_client *client, u8 reg) +{ + return i2c_smbus_read_byte_data(client, reg); +} + +static int as5916_54x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) +{ + return i2c_smbus_write_byte_data(client, reg, value); +} + +/* fan utility functions + */ +static u32 reg_val_to_duty_cycle(u8 reg_val) +{ + reg_val &= FAN_DUTY_CYCLE_REG_MASK; + return ((u32)(reg_val+1) * 625 + 75)/ 100; +} + +static u8 duty_cycle_to_reg_val(u8 duty_cycle) +{ + return ((u32)duty_cycle * 100 / 625) - 1; +} + +static u32 reg_val_to_speed_rpm(u8 reg_val) +{ + return (u32)reg_val * FAN_REG_VAL_TO_SPEED_RPM_STEP; +} + +static u8 reg_val_to_direction(u8 reg_val, enum fan_id id) +{ + return !!(reg_val & BIT(id)); +} + +static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) +{ + return !(reg_val & BIT(id)); +} + +static u8 is_fan_fault(struct as5916_54x_fan_data *data, enum fan_id id) +{ + u8 ret = 1; + int front_fan_index = FAN1_FRONT_SPEED_RPM + id; + int rear_fan_index = FAN1_REAR_SPEED_RPM + id; + + /* Check if the speed of front or rear fan is ZERO, + */ + if (reg_val_to_speed_rpm(data->reg_val[front_fan_index]) && + reg_val_to_speed_rpm(data->reg_val[rear_fan_index])) { + ret = 0; + } + + return ret; +} + +static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int error, value; + struct i2c_client *client = to_i2c_client(dev); + + error = kstrtoint(buf, 10, &value); + if (error) + return error; + + if (value < 0 || value > FAN_MAX_DUTY_CYCLE) + return -EINVAL; + + as5916_54x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ + as5916_54x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); + return count; +} + +static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5916_54x_fan_data *data = as5916_54x_fan_update_device(dev); + ssize_t ret = 0; + + if (data->valid) { + switch (attr->index) { + case FAN_DUTY_CYCLE_PERCENTAGE: + { + u32 duty_cycle = reg_val_to_duty_cycle(data->reg_val[FAN_DUTY_CYCLE_PERCENTAGE]); + ret = sprintf(buf, "%u\n", duty_cycle); + break; + } + case FAN1_FRONT_SPEED_RPM: + case FAN2_FRONT_SPEED_RPM: + case FAN3_FRONT_SPEED_RPM: + case FAN4_FRONT_SPEED_RPM: + case FAN5_FRONT_SPEED_RPM: + case FAN6_FRONT_SPEED_RPM: + case FAN1_REAR_SPEED_RPM: + case FAN2_REAR_SPEED_RPM: + case FAN3_REAR_SPEED_RPM: + case FAN4_REAR_SPEED_RPM: + case FAN5_REAR_SPEED_RPM: + case FAN6_REAR_SPEED_RPM: + ret = sprintf(buf, "%u\n", reg_val_to_speed_rpm(data->reg_val[attr->index])); + break; + case FAN1_PRESENT: + case FAN2_PRESENT: + case FAN3_PRESENT: + case FAN4_PRESENT: + case FAN5_PRESENT: + case FAN6_PRESENT: + ret = sprintf(buf, "%d\n", + reg_val_to_is_present(data->reg_val[FAN_PRESENT_REG], + attr->index - FAN1_PRESENT)); + break; + case FAN1_FAULT: + case FAN2_FAULT: + case FAN3_FAULT: + case FAN4_FAULT: + case FAN5_FAULT: + case FAN6_FAULT: + ret = sprintf(buf, "%d\n", is_fan_fault(data, attr->index - FAN1_FAULT)); + break; + case FAN1_DIRECTION: + case FAN2_DIRECTION: + case FAN3_DIRECTION: + case FAN4_DIRECTION: + case FAN5_DIRECTION: + case FAN6_DIRECTION: + ret = sprintf(buf, "%d\n", + reg_val_to_direction(data->reg_val[FAN_DIRECTION_REG], + attr->index - FAN1_DIRECTION)); + break; + case FAN_MAX_RPM: + ret = sprintf(buf, "%d\n", MAX_FAN_SPEED_RPM); + default: + break; + } + } + + return ret; +} + +static const struct attribute_group as5916_54x_fan_group = { + .attrs = as5916_54x_fan_attributes, +}; + +static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) || + !data->valid) { + int i; + + dev_dbg(&client->dev, "Starting as5916_54x_fan update\n"); + data->valid = 0; + + /* Update fan data + */ + for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { + int status = as5916_54x_fan_read_value(client, fan_reg[i]); + + if (status < 0) { + data->valid = 0; + mutex_unlock(&data->update_lock); + dev_dbg(&client->dev, "reg %d, err %d\n", fan_reg[i], status); + return data; + } + else { + data->reg_val[i] = status; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int as5916_54x_fan_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5916_54x_fan_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5916_54x_fan_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + data->valid = 0; + mutex_init(&data->update_lock); + + dev_info(&client->dev, "chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as5916_54x_fan_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + dev_info(&client->dev, "%s: fan '%s'\n", + dev_name(data->hwmon_dev), client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &as5916_54x_fan_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5916_54x_fan_remove(struct i2c_client *client) +{ + struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5916_54x_fan_group); + + return 0; +} + +/* Addresses to scan */ +static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; + +static const struct i2c_device_id as5916_54x_fan_id[] = { + { "as5916_54x_fan", 0 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5916_54x_fan_id); + +static struct i2c_driver as5916_54x_fan_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = DRVNAME, + }, + .probe = as5916_54x_fan_probe, + .remove = as5916_54x_fan_remove, + .id_table = as5916_54x_fan_id, + .address_list = normal_i2c, +}; + +static int __init as5916_54x_fan_init(void) +{ + return i2c_add_driver(&as5916_54x_fan_driver); +} + +static void __exit as5916_54x_fan_exit(void) +{ + i2c_del_driver(&as5916_54x_fan_driver); +} + +module_init(as5916_54x_fan_init); +module_exit(as5916_54x_fan_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5916_54x_fan driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c new file mode 100644 index 00000000..7f55dae7 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c @@ -0,0 +1,386 @@ +/* + * A LED driver for the accton_as5916_54x_led + * + * Copyright (C) 2016 Accton Technology Corporation. + * Brandon Chuang + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include + +#define DRVNAME "accton_as5916_54x_led" + +#define DEBUG_MODE 1 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +struct accton_as5916_54x_led_data { + struct platform_device *pdev; + struct mutex update_lock; + char valid; /* != 0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 reg_val[2]; /* Register value, 0 = RELEASE/DIAG LED, + 1 = FAN/PSU LED, + 2 ~ 4 = SYSTEM LED */ +}; + +static struct accton_as5916_54x_led_data *ledctl = NULL; + +#define LED_CNTRLER_I2C_ADDRESS (0x60) + +#define LED_TYPE_DIAG_REG_MASK (0x0C) +#define LED_MODE_DIAG_GREEN_VALUE (0x04) +#define LED_MODE_DIAG_ORANGE_VALUE (0x08) +#define LED_MODE_DIAG_OFF_VALUE (0x0C) + + +#define LED_TYPE_LOC_REG_MASK (0x10) +#define LED_MODE_LOC_ORANGE_VALUE (0x00) +#define LED_MODE_LOC_OFF_VALUE (0x10) + +static const u8 led_reg[] = { + 0x65, /* LOC/DIAG/FAN LED */ + 0x66, /* PSU LED */ +}; + +enum led_type { + LED_TYPE_DIAG, + LED_TYPE_LOC, + LED_TYPE_FAN, + LED_TYPE_PSU1, + LED_TYPE_PSU2 +}; + +/* FAN/PSU/DIAG/RELEASE led mode */ +enum led_light_mode { + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 +}; + +struct led_type_mode { + enum led_type type; + enum led_light_mode mode; + int type_mask; + int mode_value; +}; + +static struct led_type_mode led_type_mode_data[] = { +{LED_TYPE_LOC, LED_MODE_OFF, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_OFF_VALUE}, +{LED_TYPE_LOC, LED_MODE_ORANGE, LED_TYPE_LOC_REG_MASK, LED_MODE_LOC_ORANGE_VALUE}, +{LED_TYPE_DIAG, LED_MODE_OFF, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_OFF_VALUE}, +{LED_TYPE_DIAG, LED_MODE_GREEN, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_GREEN_VALUE}, +{LED_TYPE_DIAG, LED_MODE_ORANGE, LED_TYPE_DIAG_REG_MASK, LED_MODE_DIAG_ORANGE_VALUE}, +}; + +static int led_reg_val_to_light_mode(enum led_type type, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + if (type != led_type_mode_data[i].type) { + continue; + } + + if ((led_type_mode_data[i].type_mask & reg_val) == + led_type_mode_data[i].mode_value) { + return led_type_mode_data[i].mode; + } + } + + return LED_MODE_UNKNOWN; +} + +static u8 led_light_mode_to_reg_val(enum led_type type, + enum led_light_mode mode, u8 reg_val) { + int i; + + for (i = 0; i < ARRAY_SIZE(led_type_mode_data); i++) { + int type_mask, mode_value; + + if (type != led_type_mode_data[i].type) + continue; + + if (mode != led_type_mode_data[i].mode) + continue; + + type_mask = led_type_mode_data[i].type_mask; + mode_value = led_type_mode_data[i].mode_value; + reg_val = (reg_val & ~type_mask) | mode_value; + } + + return reg_val; +} + +static int accton_as5916_54x_led_read_value(u8 reg) +{ + return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); +} + +static int accton_as5916_54x_led_write_value(u8 reg, u8 value) +{ + return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); +} + +static void accton_as5916_54x_led_update(void) +{ + mutex_lock(&ledctl->update_lock); + + if (time_after(jiffies, ledctl->last_updated + HZ + HZ / 2) + || !ledctl->valid) { + int i; + + dev_dbg(&ledctl->pdev->dev, "Starting accton_as5916_54x_led update\n"); + ledctl->valid = 0; + + /* Update LED data + */ + for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { + int status = accton_as5916_54x_led_read_value(led_reg[i]); + + if (status < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], status); + goto exit; + } + else + ledctl->reg_val[i] = status; + } + + ledctl->last_updated = jiffies; + ledctl->valid = 1; + } + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as5916_54x_led_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode, + u8 reg, enum led_type type) +{ + int reg_val; + + mutex_lock(&ledctl->update_lock); + reg_val = accton_as5916_54x_led_read_value(reg); + + if (reg_val < 0) { + dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); + goto exit; + } + + reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); + accton_as5916_54x_led_write_value(reg, reg_val); + ledctl->valid = 0; + +exit: + mutex_unlock(&ledctl->update_lock); +} + +static void accton_as7312_54x_led_auto_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ +} + +static enum led_brightness accton_as7312_54x_led_auto_get(struct led_classdev *cdev) +{ + return LED_MODE_AUTO; +} + +static void accton_as5916_54x_led_diag_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); +} + +static enum led_brightness accton_as5916_54x_led_diag_get(struct led_classdev *cdev) +{ + accton_as5916_54x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); +} + +static enum led_brightness accton_as5916_54x_led_loc_get(struct led_classdev *cdev) +{ + accton_as5916_54x_led_update(); + return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); +} + +static void accton_as5916_54x_led_loc_set(struct led_classdev *led_cdev, + enum led_brightness led_light_mode) +{ + accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); +} + +static struct led_classdev accton_as5916_54x_leds[] = { + [LED_TYPE_LOC] = { + .name = "accton_as5916_54x_led::loc", + .default_trigger = "unused", + .brightness_set = accton_as5916_54x_led_loc_set, + .brightness_get = accton_as5916_54x_led_loc_get, + .max_brightness = LED_MODE_ORANGE, + }, + [LED_TYPE_DIAG] = { + .name = "accton_as5916_54x_led::diag", + .default_trigger = "unused", + .brightness_set = accton_as5916_54x_led_diag_set, + .brightness_get = accton_as5916_54x_led_diag_get, + .max_brightness = LED_MODE_GREEN, + }, + [LED_TYPE_PSU1] = { + .name = "accton_as5916_54x_led::psu1", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_PSU2] = { + .name = "accton_as5916_54x_led::psu2", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, + [LED_TYPE_FAN] = { + .name = "accton_as5916_54x_led::fan", + .default_trigger = "unused", + .brightness_set = accton_as7312_54x_led_auto_set, + .brightness_get = accton_as7312_54x_led_auto_get, + .max_brightness = LED_MODE_AUTO, + }, +}; + +static int accton_as5916_54x_led_probe(struct platform_device *pdev) +{ + int ret, i; + + for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { + ret = led_classdev_register(&pdev->dev, &accton_as5916_54x_leds[i]); + + if (ret < 0) { + break; + } + } + + /* Check if all LEDs were successfully registered */ + if (i != ARRAY_SIZE(accton_as5916_54x_leds)){ + int j; + + /* only unregister the LEDs that were successfully registered */ + for (j = 0; j < i; j++) { + led_classdev_unregister(&accton_as5916_54x_leds[i]); + } + } + + return ret; +} + +static int accton_as5916_54x_led_remove(struct platform_device *pdev) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { + led_classdev_unregister(&accton_as5916_54x_leds[i]); + } + + return 0; +} + +static struct platform_driver accton_as5916_54x_led_driver = { + .probe = accton_as5916_54x_led_probe, + .remove = accton_as5916_54x_led_remove, + .driver = { + .name = DRVNAME, + .owner = THIS_MODULE, + }, +}; + +static int __init accton_as5916_54x_led_init(void) +{ + int ret; + + ret = platform_driver_register(&accton_as5916_54x_led_driver); + if (ret < 0) { + goto exit; + } + + ledctl = kzalloc(sizeof(struct accton_as5916_54x_led_data), GFP_KERNEL); + if (!ledctl) { + ret = -ENOMEM; + goto exit_driver; + } + + mutex_init(&ledctl->update_lock); + + ledctl->pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0); + if (IS_ERR(ledctl->pdev)) { + ret = PTR_ERR(ledctl->pdev); + goto exit_free; + } + + return 0; + +exit_free: + kfree(ledctl); +exit_driver: + platform_driver_unregister(&accton_as5916_54x_led_driver); +exit: + return ret; +} + +static void __exit accton_as5916_54x_led_exit(void) +{ + platform_device_unregister(ledctl->pdev); + platform_driver_unregister(&accton_as5916_54x_led_driver); + kfree(ledctl); +} + +late_initcall(accton_as5916_54x_led_init); +module_exit(accton_as5916_54x_led_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton_as5916_54x_led driver"); +MODULE_LICENSE("GPL"); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c new file mode 100644 index 00000000..4627df9c --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c @@ -0,0 +1,288 @@ +/* + * An hwmon driver for accton as5916_54x Power Module + * + * Copyright (C) 2014 Accton Technology Corporation. + * Brandon Chuang + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); +static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +/* Each client has this additional data + */ +struct as5916_54x_psu_data { + struct device *hwmon_dev; + struct mutex update_lock; + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 index; /* PSU index */ + u8 status; /* Status(present/power_good) register read from CPLD */ + char model_name[9]; /* Model name, read from eeprom */ +}; + +static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev); + +enum as5916_54x_psu_sysfs_attributes { + PSU_PRESENT, + PSU_MODEL_NAME, + PSU_POWER_GOOD +}; + +/* sysfs attributes for hwmon + */ +static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); +static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); +static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); + +static struct attribute *as5916_54x_psu_attributes[] = { + &sensor_dev_attr_psu_present.dev_attr.attr, + &sensor_dev_attr_psu_model_name.dev_attr.attr, + &sensor_dev_attr_psu_power_good.dev_attr.attr, + NULL +}; + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + u8 status = 0; + + if (attr->index == PSU_PRESENT) { + status = !(data->status & BIT(1 - data->index));; + } + else { /* PSU_POWER_GOOD */ + status = !!(data->status & BIT(3 - data->index)); + } + + return sprintf(buf, "%d\n", status); +} + +static ssize_t show_model_name(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + + return sprintf(buf, "%s\n", data->model_name); +} + +static const struct attribute_group as5916_54x_psu_group = { + .attrs = as5916_54x_psu_attributes, +}; + +static int as5916_54x_psu_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct as5916_54x_psu_data *data; + int status; + + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { + status = -EIO; + goto exit; + } + + data = kzalloc(sizeof(struct as5916_54x_psu_data), GFP_KERNEL); + if (!data) { + status = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + data->valid = 0; + data->index = dev_id->driver_data; + mutex_init(&data->update_lock); + + dev_info(&client->dev, "chip found\n"); + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &as5916_54x_psu_group); + if (status) { + goto exit_free; + } + + data->hwmon_dev = hwmon_device_register(&client->dev); + if (IS_ERR(data->hwmon_dev)) { + status = PTR_ERR(data->hwmon_dev); + goto exit_remove; + } + + dev_info(&client->dev, "%s: psu '%s'\n", + dev_name(data->hwmon_dev), client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &as5916_54x_psu_group); +exit_free: + kfree(data); +exit: + + return status; +} + +static int as5916_54x_psu_remove(struct i2c_client *client) +{ + struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + + hwmon_device_unregister(data->hwmon_dev); + sysfs_remove_group(&client->dev.kobj, &as5916_54x_psu_group); + kfree(data); + + return 0; +} + +enum psu_index +{ + as5916_54x_psu1, + as5916_54x_psu2 +}; + +static const struct i2c_device_id as5916_54x_psu_id[] = { + { "as5916_54x_psu1", as5916_54x_psu1 }, + { "as5916_54x_psu2", as5916_54x_psu2 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, as5916_54x_psu_id); + +static struct i2c_driver as5916_54x_psu_driver = { + .class = I2C_CLASS_HWMON, + .driver = { + .name = "as5916_54x_psu", + }, + .probe = as5916_54x_psu_probe, + .remove = as5916_54x_psu_remove, + .id_table = as5916_54x_psu_id, + .address_list = normal_i2c, +}; + +static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, + int data_len) +{ + int result = 0; + int retry_count = 5; + + while (retry_count) { + retry_count--; + + result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + + if (unlikely(result < 0)) { + msleep(10); + continue; + } + + if (unlikely(result != data_len)) { + result = -EIO; + msleep(10); + continue; + } + + result = 0; + break; + } + + return result; +} + +static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + if (time_after(jiffies, data->last_updated + HZ + HZ / 2) + || !data->valid) { + int status; + int power_good = 0; + + dev_dbg(&client->dev, "Starting as5916_54x update\n"); + + /* Read psu status */ + status = accton_i2c_cpld_read(0x60, 0x2); + + if (status < 0) { + dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); + } + else { + data->status = status; + } + + /* Read model name */ + memset(data->model_name, 0, sizeof(data->model_name)); + power_good = data->status & BIT(3 - data->index); + + if (power_good) { + status = as5916_54x_psu_read_block(client, 0x20, data->model_name, + ARRAY_SIZE(data->model_name)-1); + + if (status < 0) { + data->model_name[0] = '\0'; + dev_dbg(&client->dev, "unable to read model name from (0x%x)\n", client->addr); + } + else { + data->model_name[ARRAY_SIZE(data->model_name)-1] = '\0'; + } + } + + data->last_updated = jiffies; + data->valid = 1; + } + + mutex_unlock(&data->update_lock); + + return data; +} + +static int __init as5916_54x_psu_init(void) +{ + return i2c_add_driver(&as5916_54x_psu_driver); +} + +static void __exit as5916_54x_psu_exit(void) +{ + i2c_del_driver(&as5916_54x_psu_driver); +} + +module_init(as5916_54x_psu_init); +module_exit(as5916_54x_psu_exit); + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("as5916_54x_psu driver"); +MODULE_LICENSE("GPL"); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c new file mode 100644 index 00000000..c924772b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c @@ -0,0 +1,1315 @@ +/* + * SFP driver for accton as5916_54x sfp + * + * Copyright (C) Brandon Chuang + * + * Based on ad7414.c + * Copyright 2006 Stefan Roese , DENX Software Engineering + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRIVER_NAME "as5916_54x_sfp" /* Platform dependent */ + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#define NUM_OF_SFP_PORT 54 +#define EEPROM_NAME "sfp_eeprom" +#define EEPROM_SIZE 256 /* 256 byte eeprom */ +#define BIT_INDEX(i) (1ULL << (i)) +#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ +#define I2C_RW_RETRY_COUNT 3 +#define I2C_RW_RETRY_INTERVAL 100 /* ms */ + +#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) +#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) + +#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 +#define SFF8024_DEVICE_ID_SFP 0x3 +#define SFF8024_DEVICE_ID_QSFP 0xC +#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD +#define SFF8024_DEVICE_ID_QSFP28 0x11 + +#define SFF8472_DIAG_MON_TYPE_ADDR 92 +#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 +#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 +#define SFF8472_10G_BASE_MASK 0xF0 + +#define SFF8436_RX_LOS_ADDR 3 +#define SFF8436_TX_FAULT_ADDR 4 +#define SFF8436_TX_DISABLE_ADDR 86 + +/* Platform dependent +++ */ +#define I2C_ADDR_CPLD1 0x60 +#define I2C_ADDR_CPLD2 0x62 +/* Platform dependent --- */ + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); +static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); +static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); +extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); + +enum sfp_sysfs_attributes { + PRESENT, + PRESENT_ALL, + PORT_NUMBER, + PORT_TYPE, + DDM_IMPLEMENTED, + TX_FAULT, + TX_FAULT1, + TX_FAULT2, + TX_FAULT3, + TX_FAULT4, + TX_DISABLE, + TX_DISABLE1, + TX_DISABLE2, + TX_DISABLE3, + TX_DISABLE4, + RX_LOS, + RX_LOS1, + RX_LOS2, + RX_LOS3, + RX_LOS4, + RX_LOS_ALL +}; + +/* SFP/QSFP common attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); +static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); +static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); +static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); +static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); +static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); +static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); + +/* QSFP attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); +static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); +static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); +static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); +static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); +static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); +static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); +static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); +static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); +static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); +static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); +static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); +static struct attribute *qsfp_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, + NULL +}; + +/* SFP msa attributes for sysfs */ +static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); +static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); +static struct attribute *sfp_msa_attributes[] = { + &sensor_dev_attr_sfp_port_number.dev_attr.attr, + &sensor_dev_attr_sfp_port_type.dev_attr.attr, + &sensor_dev_attr_sfp_is_present.dev_attr.attr, + &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, + &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, + &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los.dev_attr.attr, + &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, + &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, + NULL +}; + +/* SFP ddm attributes for sysfs */ +static struct attribute *sfp_ddm_attributes[] = { + NULL +}; + +/* Platform dependent +++ */ +#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) + +enum port_numbers { +as5916_54x_sfp1, as5916_54x_sfp2, as5916_54x_sfp3, as5916_54x_sfp4, as5916_54x_sfp5, as5916_54x_sfp6, as5916_54x_sfp7, as5916_54x_sfp8, +as5916_54x_sfp9, as5916_54x_sfp10, as5916_54x_sfp11, as5916_54x_sfp12, as5916_54x_sfp13, as5916_54x_sfp14, as5916_54x_sfp15, as5916_54x_sfp16, +as5916_54x_sfp17, as5916_54x_sfp18, as5916_54x_sfp19, as5916_54x_sfp20, as5916_54x_sfp21, as5916_54x_sfp22, as5916_54x_sfp23, as5916_54x_sfp24, +as5916_54x_sfp25, as5916_54x_sfp26, as5916_54x_sfp27, as5916_54x_sfp28, as5916_54x_sfp29, as5916_54x_sfp30, as5916_54x_sfp31, as5916_54x_sfp32, +as5916_54x_sfp33, as5916_54x_sfp34, as5916_54x_sfp35, as5916_54x_sfp36, as5916_54x_sfp37, as5916_54x_sfp38, as5916_54x_sfp39, as5916_54x_sfp40, +as5916_54x_sfp41, as5916_54x_sfp42, as5916_54x_sfp43, as5916_54x_sfp44, as5916_54x_sfp45, as5916_54x_sfp46, as5916_54x_sfp47, as5916_54x_sfp48, +as5916_54x_sfp49, as5916_54x_sfp50, as5916_54x_sfp51, as5916_54x_sfp52, as5916_54x_sfp53, as5916_54x_sfp54 +}; + +static const struct i2c_device_id sfp_device_id[] = { +{ "as5916_54x_sfp1", as5916_54x_sfp1 }, { "as5916_54x_sfp2", as5916_54x_sfp2 }, { "as5916_54x_sfp3", as5916_54x_sfp3 }, { "as5916_54x_sfp4", as5916_54x_sfp4 }, +{ "as5916_54x_sfp5", as5916_54x_sfp5 }, { "as5916_54x_sfp6", as5916_54x_sfp6 }, { "as5916_54x_sfp7", as5916_54x_sfp7 }, { "as5916_54x_sfp8", as5916_54x_sfp8 }, +{ "as5916_54x_sfp9", as5916_54x_sfp9 }, { "as5916_54x_sfp10", as5916_54x_sfp10 }, { "as5916_54x_sfp11", as5916_54x_sfp11 }, { "as5916_54x_sfp12", as5916_54x_sfp12 }, +{ "as5916_54x_sfp13", as5916_54x_sfp13 }, { "as5916_54x_sfp14", as5916_54x_sfp14 }, { "as5916_54x_sfp15", as5916_54x_sfp15 }, { "as5916_54x_sfp16", as5916_54x_sfp16 }, +{ "as5916_54x_sfp17", as5916_54x_sfp17 }, { "as5916_54x_sfp18", as5916_54x_sfp18 }, { "as5916_54x_sfp19", as5916_54x_sfp19 }, { "as5916_54x_sfp20", as5916_54x_sfp20 }, +{ "as5916_54x_sfp21", as5916_54x_sfp21 }, { "as5916_54x_sfp22", as5916_54x_sfp22 }, { "as5916_54x_sfp23", as5916_54x_sfp23 }, { "as5916_54x_sfp24", as5916_54x_sfp24 }, +{ "as5916_54x_sfp25", as5916_54x_sfp25 }, { "as5916_54x_sfp26", as5916_54x_sfp26 }, { "as5916_54x_sfp27", as5916_54x_sfp27 }, { "as5916_54x_sfp28", as5916_54x_sfp28 }, +{ "as5916_54x_sfp29", as5916_54x_sfp29 }, { "as5916_54x_sfp30", as5916_54x_sfp30 }, { "as5916_54x_sfp31", as5916_54x_sfp31 }, { "as5916_54x_sfp32", as5916_54x_sfp32 }, +{ "as5916_54x_sfp33", as5916_54x_sfp33 }, { "as5916_54x_sfp34", as5916_54x_sfp34 }, { "as5916_54x_sfp35", as5916_54x_sfp35 }, { "as5916_54x_sfp36", as5916_54x_sfp36 }, +{ "as5916_54x_sfp37", as5916_54x_sfp37 }, { "as5916_54x_sfp38", as5916_54x_sfp38 }, { "as5916_54x_sfp39", as5916_54x_sfp39 }, { "as5916_54x_sfp40", as5916_54x_sfp40 }, +{ "as5916_54x_sfp41", as5916_54x_sfp41 }, { "as5916_54x_sfp42", as5916_54x_sfp42 }, { "as5916_54x_sfp43", as5916_54x_sfp43 }, { "as5916_54x_sfp44", as5916_54x_sfp44 }, +{ "as5916_54x_sfp45", as5916_54x_sfp45 }, { "as5916_54x_sfp46", as5916_54x_sfp46 }, { "as5916_54x_sfp47", as5916_54x_sfp47 }, { "as5916_54x_sfp48", as5916_54x_sfp48 }, +{ "as5916_54x_sfp49", as5916_54x_sfp49 }, { "as5916_54x_sfp50", as5916_54x_sfp50 }, { "as5916_54x_sfp51", as5916_54x_sfp51 }, { "as5916_54x_sfp52", as5916_54x_sfp52 }, +{ "as5916_54x_sfp53", as5916_54x_sfp53 }, { "as5916_54x_sfp54", as5916_54x_sfp54 }, +{ /* LIST END */ } +}; +MODULE_DEVICE_TABLE(i2c, sfp_device_id); +/* Platform dependent --- */ + +/* + * list of valid port types + * note OOM_PORT_TYPE_NOT_PRESENT to indicate no + * module is present in this port + */ +typedef enum oom_driver_port_type_e { + OOM_DRIVER_PORT_TYPE_INVALID, + OOM_DRIVER_PORT_TYPE_NOT_PRESENT, + OOM_DRIVER_PORT_TYPE_SFP, + OOM_DRIVER_PORT_TYPE_SFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP, + OOM_DRIVER_PORT_TYPE_QSFP_PLUS, + OOM_DRIVER_PORT_TYPE_QSFP28 +} oom_driver_port_type_t; + +enum driver_type_e { + DRIVER_TYPE_SFP_MSA, + DRIVER_TYPE_SFP_DDM, + DRIVER_TYPE_QSFP +}; + +/* Each client has this additional data + */ +struct eeprom_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + struct bin_attribute bin; /* eeprom data */ +}; + +struct sfp_msa_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u64 status[6]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss + 3 => device id + 4 => 10G Ethernet Compliance Codes + to distinguish SFP or SFP+ + 5 => DIAGNOSTIC MONITORING TYPE */ + struct eeprom_data eeprom; +}; + +struct sfp_ddm_data { + struct eeprom_data eeprom; +}; + +struct qsfp_data { + char valid; /* !=0 if registers are valid */ + unsigned long last_updated; /* In jiffies */ + u8 status[3]; /* bit0:port0, bit1:port1 and so on */ + /* index 0 => tx_fail + 1 => tx_disable + 2 => rx_loss */ + + u8 device_id; + struct eeprom_data eeprom; +}; + +struct sfp_port_data { + struct mutex update_lock; + enum driver_type_e driver_type; + int port; /* CPLD port index */ + oom_driver_port_type_t port_type; + u64 present; /* present status, bit0:port0, bit1:port1 and so on */ + + struct sfp_msa_data *msa; + struct sfp_ddm_data *ddm; + struct qsfp_data *qsfp; + + struct i2c_client *client; +}; + +static ssize_t show_port_number(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); +} + +/* Platform dependent +++ */ +static struct sfp_port_data *sfp_update_present(struct i2c_client *client) +{ + int i = 0, j = 0, status = -1; + u8 reg; + unsigned short cpld_addr; + struct sfp_port_data *data = i2c_get_clientdata(client); + + DEBUG_PRINT("Starting sfp present status update"); + mutex_lock(&data->update_lock); + data->present = 0; + + /* Read present status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < 3; j++) { + cpld_addr = I2C_ADDR_CPLD1 + i*2; + reg = 0x10+j; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + + DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); + data->present |= (u64)status << ((i*24) + (j%3)*8); + } + } + + /* Read present status of port 49-52(QSFP port) */ + cpld_addr = I2C_ADDR_CPLD2; + reg = 0x52; + status = accton_i2c_cpld_read(cpld_addr, reg); + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); + goto exit; + } + else { + data->present |= (u64)(status & 0x3F) << 48; + } + + DEBUG_PRINT("Present status = 0x%lx", data->present); +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i = 0, j = 0; + int status = -1; + u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; + + if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { + return data; + } + + DEBUG_PRINT("Starting as5916_54x sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->msa->valid = 0; + memset(data->msa->status, 0, sizeof(data->msa->status)); + + /* Read status of port 1~48(SFP port) */ + for (i = 0; i < 2; i++) { + for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { + unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; + + status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); + goto exit; + } + + data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); + } + } + + data->msa->valid = 1; + data->msa->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + unsigned short cpld_addr = 0; + u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; + long disable; + int error; + u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_set_tx_disable(dev, da, buf, count); + } + + error = kstrtol(buf, 10, &disable); + if (error) { + return error; + } + + mutex_lock(&data->update_lock); + + if(data->port < 24) { + cpld_addr = I2C_ADDR_CPLD1; + cpld_reg = tx_disable_regs[data->port / 8]; + cpld_bit = 1 << (data->port % 8); + } + else { /* port 24 ~ 48 */ + cpld_addr = I2C_ADDR_CPLD2; + cpld_reg = tx_disable_regs[(data->port - 24) / 8]; + cpld_bit = 1 << (data->port % 8); + } + + /* Read current status */ + cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); + + /* Update tx_disable status */ + if (disable) { + data->msa->status[1] |= BIT_INDEX(data->port); + cpld_val |= cpld_bit; + } + else { + data->msa->status[1] &= ~BIT_INDEX(data->port); + cpld_val &= ~cpld_bit; + } + + accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); + mutex_unlock(&data->update_lock); + return count; +} + +static int sfp_is_port_present(struct i2c_client *client, int port) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + data = sfp_update_present(client); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ +} + +static ssize_t show_present(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + + if (PRESENT_ALL == attr->index) { + int i; + u8 values[7] = {0}; + struct sfp_port_data *data = sfp_update_present(client); + + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = ~(u8)(data->present >> (i * 8)); + } + + /* Return values 1 -> 54 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5], + values[6] & 0x3F); + } + else { + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + /* PRESENT */ + return sprintf(buf, "%d\n", present); + } +} +/* Platform dependent --- */ + +static struct sfp_port_data *sfp_update_port_type(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + u8 buf = 0; + int status; + + mutex_lock(&data->update_lock); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + if (buf != SFF8024_DEVICE_ID_SFP) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); + data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; + break; + } + case DRIVER_TYPE_QSFP: + { + status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); + if (unlikely(status < 0)) { + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); + switch (buf) { + case SFF8024_DEVICE_ID_QSFP: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; + break; + case SFF8024_DEVICE_ID_QSFP_PLUS: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + case SFF8024_DEVICE_ID_QSFP28: + data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; + break; + default: + data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; + break; + } + + break; + } + default: + break; + } + + mutex_unlock(&data->update_lock); + return data; +} + +static ssize_t show_port_type(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int present = sfp_is_port_present(client, data->port); + + if (IS_ERR_VALUE(present)) { + return present; + } + + if (!present) { + return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); + } + + sfp_update_port_type(dev); + return sprintf(buf, "%d\n", data->port_type); +} + +static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) +{ + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + int i, status = -1; + u8 buf = 0; + u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; + + if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { + return data; + } + + DEBUG_PRINT("Starting sfp tx rx status update"); + mutex_lock(&data->update_lock); + data->qsfp->valid = 0; + memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); + + /* Notify device to update tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + } + msleep(200); + + /* Read actual tx fault/ tx disable/ rx los status */ + for (i = 0; i < ARRAY_SIZE(reg); i++) { + status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); + if (unlikely(status < 0)) { + goto exit; + } + + DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); + data->qsfp->status[i] = (buf & 0xF); + } + + data->qsfp->valid = 1; + data->qsfp->last_updated = jiffies; + +exit: + mutex_unlock(&data->update_lock); + return (status < 0) ? ERR_PTR(status) : data; +} + +static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + int present; + u8 val = 0; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + present = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENXIO; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + switch (attr->index) { + case TX_FAULT: + val = !!(data->qsfp->status[2] & 0xF); + break; + case TX_FAULT1: + case TX_FAULT2: + case TX_FAULT3: + case TX_FAULT4: + val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); + break; + case TX_DISABLE: + val = data->qsfp->status[1] & 0xF; + break; + case TX_DISABLE1: + case TX_DISABLE2: + case TX_DISABLE3: + case TX_DISABLE4: + val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); + break; + case RX_LOS: + val = !!(data->qsfp->status[0] & 0xF); + break; + case RX_LOS1: + case RX_LOS2: + case RX_LOS3: + case RX_LOS4: + val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); + break; + default: + break; + } + + return sprintf(buf, "%d\n", val); +} + +static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + long disable; + int status; + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (!status) { + /* port is not present */ + return -ENXIO; + } + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + data = qsfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + mutex_lock(&data->update_lock); + + if (attr->index == TX_DISABLE) { + data->qsfp->status[1] = disable & 0xF; + } + else {/* TX_DISABLE1 ~ TX_DISABLE4*/ + if (disable) { + data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); + } + else { + data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); + } + } + + DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); + status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); + if (unlikely(status < 0)) { + count = status; + } + + mutex_unlock(&data->update_lock); + return count; +} + +static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, + char *buf) +{ + int status; + char ddm; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + + status = sfp_is_port_present(client, data->port); + if (IS_ERR_VALUE(status)) { + return status; + } + + if (status == 0) { + /* port is not present */ + return -ENODEV; + } + + status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); + if (unlikely(status < 0)) { + return status; + } + + return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); +} + +/* Platform dependent +++ */ +static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + u8 val = 0, index = 0; + struct i2c_client *client = to_i2c_client(dev); + struct sfp_port_data *data = i2c_get_clientdata(client); + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + + if (data->driver_type == DRIVER_TYPE_QSFP) { + return qsfp_show_tx_rx_status(dev, da, buf); + } + + data = sfp_update_tx_rx_status(dev); + if (IS_ERR(data)) { + return PTR_ERR(data); + } + + if(attr->index == RX_LOS_ALL) { + int i = 0; + u8 values[6] = {0}; + + for (i = 0; i < ARRAY_SIZE(values); i++) { + values[i] = (u8)(data->msa->status[2] >> (i * 8)); + } + + /** Return values 1 -> 48 in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], + values[3], values[4], values[5]); + } + + switch (attr->index) { + case TX_FAULT: + index = 0; + break; + case TX_DISABLE: + index = 1; + break; + case RX_LOS: + index = 2; + break; + default: + return 0; + } + + val = !!(data->msa->status[index] & BIT_INDEX(data->port)); + return sprintf(buf, "%d\n", val); +} +/* Platform dependent --- */ +static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return data_len; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, command, *data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + return status; + } + + return 1; +#endif + + +} + +static ssize_t sfp_port_write(struct sfp_port_data *data, + 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(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_write(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; +} + + +static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_write(data, buf, off, count); +} + +static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, + int data_len) +{ +#if USE_I2C_BLOCK_READ + int status, retry = I2C_RW_RETRY_COUNT; + + if (data_len > I2C_SMBUS_BLOCK_MAX) { + data_len = I2C_SMBUS_BLOCK_MAX; + } + + while (retry) { + status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + goto abort; + } + if (unlikely(status != data_len)) { + status = -EIO; + goto abort; + } + + //result = data_len; + +abort: + return status; +#else + int status, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, command); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + if (unlikely(status < 0)) { + dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); + goto abort; + } + + *data = (u8)status; + status = 1; + +abort: + return status; +#endif +} + +static ssize_t sfp_port_read(struct sfp_port_data *data, + char *buf, loff_t off, size_t count) +{ + ssize_t retval = 0; + + if (unlikely(!count)) { + DEBUG_PRINT("Count = 0, return"); + return count; + } + + /* + * Read data from chip, protecting against concurrent updates + * from this host, but not from other I2C masters. + */ + mutex_lock(&data->update_lock); + + while (count) { + ssize_t status; + + status = sfp_eeprom_read(data->client, off, buf, count); + if (status <= 0) { + if (retval == 0) { + retval = status; + } + break; + } + + buf += status; + off += status; + count -= status; + retval += status; + } + + mutex_unlock(&data->update_lock); + return retval; + +} + +static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, + struct bin_attribute *attr, + char *buf, loff_t off, size_t count) +{ + int present; + struct sfp_port_data *data; + DEBUG_PRINT("offset = (%d), count = (%d)", off, count); + data = dev_get_drvdata(container_of(kobj, struct device, kobj)); + + present = sfp_is_port_present(data->client, data->port); + if (IS_ERR_VALUE(present)) { + return present; + } + + if (present == 0) { + /* port is not present */ + return -ENODEV; + } + + return sfp_port_read(data, buf, off, count); +} + +static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) +{ + int err; + + sysfs_bin_attr_init(eeprom); + eeprom->attr.name = EEPROM_NAME; + eeprom->attr.mode = S_IWUSR | S_IRUGO; + eeprom->read = sfp_bin_read; + eeprom->write = sfp_bin_write; + eeprom->size = EEPROM_SIZE; + + /* Create eeprom file */ + err = sysfs_create_bin_file(kobj, eeprom); + if (err) { + return err; + } + + return 0; +} + +static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) +{ + sysfs_remove_bin_file(kobj, eeprom); + return 0; +} + +static const struct attribute_group sfp_msa_group = { + .attrs = sfp_msa_attributes, +}; + +static int sfp_i2c_check_functionality(struct i2c_client *client) +{ +#if USE_I2C_BLOCK_READ + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); +#else + return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); +#endif +} + +static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_msa_data **data) +{ + int status; + struct sfp_msa_data *msa; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); + if (!msa) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = msa; + dev_info(&client->dev, "sfp msa '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); +exit_free: + kfree(msa); +exit: + + return status; +} + +static const struct attribute_group sfp_ddm_group = { + .attrs = sfp_ddm_attributes, +}; + +static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct sfp_ddm_data **data) +{ + int status; + struct sfp_ddm_data *ddm; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); + if (!ddm) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = ddm; + dev_info(&client->dev, "sfp ddm '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); +exit_free: + kfree(ddm); +exit: + + return status; +} + +static const struct attribute_group qsfp_group = { + .attrs = qsfp_attributes, +}; + +static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, + struct qsfp_data **data) +{ + int status; + struct qsfp_data *qsfp; + + if (!sfp_i2c_check_functionality(client)) { + status = -EIO; + goto exit; + } + + qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); + if (!qsfp) { + status = -ENOMEM; + goto exit; + } + + /* Register sysfs hooks */ + status = sysfs_create_group(&client->dev.kobj, &qsfp_group); + if (status) { + goto exit_free; + } + + /* init eeprom */ + status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); + if (status) { + goto exit_remove; + } + + *data = qsfp; + dev_info(&client->dev, "qsfp '%s'\n", client->name); + + return 0; + +exit_remove: + sysfs_remove_group(&client->dev.kobj, &qsfp_group); +exit_free: + kfree(qsfp); +exit: + + return status; +} + +/* Platform dependent +++ */ +static int sfp_device_probe(struct i2c_client *client, + const struct i2c_device_id *dev_id) +{ + struct sfp_port_data *data = NULL; + + data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); + if (!data) { + return -ENOMEM; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->port = dev_id->driver_data; + data->client = client; + + if (dev_id->driver_data >= as5916_54x_sfp1 && dev_id->driver_data <= as5916_54x_sfp48) { + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_MSA; + return sfp_msa_probe(client, dev_id, &data->msa); + } + else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_SFP_DDM; + return sfp_ddm_probe(client, dev_id, &data->ddm); + } + } + else { /* as5916_54x_sfp49 ~ as5916_54x_sfp54 */ + if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { + data->driver_type = DRIVER_TYPE_QSFP; + return qsfp_probe(client, dev_id, &data->qsfp); + } + } + + return -ENODEV; +} +/* Platform dependent --- */ + +static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); + kfree(data); + return 0; +} + +static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); + kfree(data); + return 0; +} + +static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) +{ + sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); + sysfs_remove_group(&client->dev.kobj, &qsfp_group); + kfree(data); + return 0; +} + +static int sfp_device_remove(struct i2c_client *client) +{ + struct sfp_port_data *data = i2c_get_clientdata(client); + + switch (data->driver_type) { + case DRIVER_TYPE_SFP_MSA: + return sfp_msa_remove(client, data->msa); + case DRIVER_TYPE_SFP_DDM: + return sfp_ddm_remove(client, data->ddm); + case DRIVER_TYPE_QSFP: + return qfp_remove(client, data->qsfp); + } + + return 0; +} + +/* Addresses scanned + */ +static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; + +static struct i2c_driver sfp_driver = { + .driver = { + .name = DRIVER_NAME, + }, + .probe = sfp_device_probe, + .remove = sfp_device_remove, + .id_table = sfp_device_id, + .address_list = normal_i2c, +}; + +static int __init sfp_init(void) +{ + return i2c_add_driver(&sfp_driver); +} + +static void __exit sfp_exit(void) +{ + i2c_del_driver(&sfp_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("accton as5916_54x_sfp driver"); +MODULE_LICENSE("GPL"); + +late_initcall(sfp_init); +module_exit(sfp_exit); + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml new file mode 100644 index 00000000..ee1812ff --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/onlp-platform-revision.yml PLATFORM=x86-64-accton-as5916-54x ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu REVISION=r1 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/Makefile new file mode 100644 index 00000000..e7437cb2 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/Makefile @@ -0,0 +1,2 @@ +FILTER=src +include $(ONL)/make/subdirs.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile new file mode 100644 index 00000000..1f155bfc --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile @@ -0,0 +1,45 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +MODULE := libonlp-x86-64-accton-as5916-54x +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF x86_64_accton_as5916_54x onlplib +DEPENDMODULE_HEADERS := sff + +include $(BUILDER)/dependmodules.mk + +SHAREDLIB := libonlp-x86-64-accton-as5916-54x.so +$(SHAREDLIB)_TARGETS := $(ALL_TARGETS) +include $(BUILDER)/so.mk +.DEFAULT_GOAL := $(SHAREDLIB) + +GLOBAL_CFLAGS += -I$(onlp_BASEDIR)/module/inc +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -fPIC +GLOBAL_LINK_LIBS += -lpthread + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile new file mode 100644 index 00000000..0c41fbc0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile @@ -0,0 +1,46 @@ +############################################################ +# +# +# Copyright 2014 BigSwitch Networks, Inc. +# +# Licensed under the Eclipse Public License, Version 1.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.eclipse.org/legal/epl-v10.html +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, +# either express or implied. See the License for the specific +# language governing permissions and limitations under the +# License. +# +# +############################################################ +# +# +# +############################################################ +include $(ONL)/make/config.amd64.mk + +.DEFAULT_GOAL := onlpdump + +MODULE := onlpdump +include $(BUILDER)/standardinit.mk + +DEPENDMODULES := AIM IOF onlp x86_64_accton_as5916_54x onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS + +include $(BUILDER)/dependmodules.mk + +BINARY := onlpdump +$(BINARY)_LIBRARIES := $(LIBRARY_TARGETS) +include $(BUILDER)/bin.mk + +GLOBAL_CFLAGS += -DAIM_CONFIG_AIM_MAIN_FUNCTION=onlpdump_main +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MODULES_INIT=1 +GLOBAL_CFLAGS += -DAIM_CONFIG_INCLUDE_MAIN=1 +GLOBAL_LINK_LIBS += -lpthread -lm + +include $(BUILDER)/targets.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module new file mode 100644 index 00000000..b7e5840e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module @@ -0,0 +1 @@ +name: x86_64_accton_as5916_54x diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile new file mode 100644 index 00000000..10f71d72 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### +include ../../init.mk +MODULE := x86_64_accton_as5916_54x +AUTOMODULE := x86_64_accton_as5916_54x +include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README new file mode 100644 index 00000000..64864843 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README @@ -0,0 +1,6 @@ +############################################################################### +# +# x86_64_accton_as5916_54x README +# +############################################################################### + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk new file mode 100644 index 00000000..9db4a259 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# x86_64_accton_as5916_54x Autogeneration +# +############################################################################### +x86_64_accton_as5916_54x_AUTO_DEFS := module/auto/x86_64_accton_as5916_54x.yml +x86_64_accton_as5916_54x_AUTO_DIRS := module/inc/x86_64_accton_as5916_54x module/src +include $(BUILDER)/auto.mk + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml new file mode 100644 index 00000000..987f682f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml @@ -0,0 +1,50 @@ +############################################################################### +# +# x86_64_accton_as5916_54x Autogeneration Definitions. +# +############################################################################### + +cdefs: &cdefs +- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING: + doc: "Include or exclude logging." + default: 1 +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT: + doc: "Default enabled log options." + default: AIM_LOG_OPTIONS_DEFAULT +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT: + doc: "Default enabled log bits." + default: AIM_LOG_BITS_DEFAULT +- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT: + doc: "Default enabled custom log bits." + default: 0 +- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB: + doc: "Default all porting macros to use the C standard libraries." + default: 1 +- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: + doc: "Include standard library headers for stdlib porting macros." + default: X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI: + doc: "Include generic uCli support." + default: 0 +- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: + doc: "Assume chassis fan direction is the same as the PSU fan direction." + default: 0 + + +definitions: + cdefs: + X86_64_ACCTON_AS5916_54X_CONFIG_HEADER: + defs: *cdefs + basename: x86_64_accton_as5916_54x_config + + portingmacro: + x86_64_accton_as5916_54x: + macros: + - malloc + - free + - memset + - memcpy + - strncpy + - vsnprintf + - snprintf + - strlen diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x new file mode 100644 index 00000000..7776b59e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x @@ -0,0 +1,14 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.xmacro(ALL).define> */ +/* */ + +/* <--auto.start.xenum(ALL).define> */ +/* */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h new file mode 100644 index 00000000..43572880 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h @@ -0,0 +1,137 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5916_54x Configuration Header + * + * @addtogroup x86_64_accton_as5916_54x-config + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS5916_54X_CONFIG_H__ +#define __X86_64_ACCTON_AS5916_54X_CONFIG_H__ + +#ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG +#include +#endif +#ifdef X86_64_ACCTON_AS5916_54X_INCLUDE_CUSTOM_CONFIG +#include +#endif + +/* */ +#include +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING + * + * Include or exclude logging. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING 1 +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT + * + * Default enabled log options. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT + * + * Default enabled log bits. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * + * Default enabled custom log bits. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB + * + * Default all porting macros to use the C standard libraries. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB 1 +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * + * Include standard library headers for stdlib porting macros. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI + * + * Include generic uCli support. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI 0 +#endif + +/** + * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * + * Assume chassis fan direction is the same as the PSU fan direction. */ + + +#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#endif + + + +/** + * All compile time options can be queried or displayed + */ + +/** Configuration settings structure. */ +typedef struct x86_64_accton_as5916_54x_config_settings_s { + /** name */ + const char* name; + /** value */ + const char* value; +} x86_64_accton_as5916_54x_config_settings_t; + +/** Configuration settings table. */ +/** x86_64_accton_as5916_54x_config_settings table. */ +extern x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[]; + +/** + * @brief Lookup a configuration setting. + * @param setting The name of the configuration option to lookup. + */ +const char* x86_64_accton_as5916_54x_config_lookup(const char* setting); + +/** + * @brief Show the compile-time configuration. + * @param pvs The output stream. + */ +int x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs); + +/* */ + +#include "x86_64_accton_as5916_54x_porting.h" + +#endif /* __X86_64_ACCTON_AS5916_54X_CONFIG_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h new file mode 100644 index 00000000..67e69645 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h @@ -0,0 +1,26 @@ +/**************************************************************************//** + * + * x86_64_accton_as5916_54x Doxygen Header + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS5916_54X_DOX_H__ +#define __X86_64_ACCTON_AS5916_54X_DOX_H__ + +/** + * @defgroup x86_64_accton_as5916_54x x86_64_accton_as5916_54x - x86_64_accton_as5916_54x Description + * + +The documentation overview for this module should go here. + + * + * @{ + * + * @defgroup x86_64_accton_as5916_54x-x86_64_accton_as5916_54x Public Interface + * @defgroup x86_64_accton_as5916_54x-config Compile Time Configuration + * @defgroup x86_64_accton_as5916_54x-porting Porting Macros + * + * @} + * + */ + +#endif /* __X86_64_ACCTON_AS5916_54X_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h new file mode 100644 index 00000000..e7dcddc8 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h @@ -0,0 +1,107 @@ +/**************************************************************************//** + * + * @file + * @brief x86_64_accton_as5916_54x Porting Macros. + * + * @addtogroup x86_64_accton_as5916_54x-porting + * @{ + * + *****************************************************************************/ +#ifndef __X86_64_ACCTON_AS5916_54X_PORTING_H__ +#define __X86_64_ACCTON_AS5916_54X_PORTING_H__ + + +/* */ +#if X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#include +#include +#include +#include +#include +#endif + +#ifndef x86_64_accton_as5916_54x_MALLOC + #if defined(GLOBAL_MALLOC) + #define x86_64_accton_as5916_54x_MALLOC GLOBAL_MALLOC + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MALLOC malloc + #else + #error The macro x86_64_accton_as5916_54x_MALLOC is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_FREE + #if defined(GLOBAL_FREE) + #define x86_64_accton_as5916_54x_FREE GLOBAL_FREE + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_FREE free + #else + #error The macro x86_64_accton_as5916_54x_FREE is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_MEMSET + #if defined(GLOBAL_MEMSET) + #define x86_64_accton_as5916_54x_MEMSET GLOBAL_MEMSET + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MEMSET memset + #else + #error The macro x86_64_accton_as5916_54x_MEMSET is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_MEMCPY + #if defined(GLOBAL_MEMCPY) + #define x86_64_accton_as5916_54x_MEMCPY GLOBAL_MEMCPY + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_MEMCPY memcpy + #else + #error The macro x86_64_accton_as5916_54x_MEMCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_STRNCPY + #if defined(GLOBAL_STRNCPY) + #define x86_64_accton_as5916_54x_STRNCPY GLOBAL_STRNCPY + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_STRNCPY strncpy + #else + #error The macro x86_64_accton_as5916_54x_STRNCPY is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_VSNPRINTF + #if defined(GLOBAL_VSNPRINTF) + #define x86_64_accton_as5916_54x_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_VSNPRINTF vsnprintf + #else + #error The macro x86_64_accton_as5916_54x_VSNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_SNPRINTF + #if defined(GLOBAL_SNPRINTF) + #define x86_64_accton_as5916_54x_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_SNPRINTF snprintf + #else + #error The macro x86_64_accton_as5916_54x_SNPRINTF is required but cannot be defined. + #endif +#endif + +#ifndef x86_64_accton_as5916_54x_STRLEN + #if defined(GLOBAL_STRLEN) + #define x86_64_accton_as5916_54x_STRLEN GLOBAL_STRLEN + #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54x_STRLEN strlen + #else + #error The macro x86_64_accton_as5916_54x_STRLEN is required but cannot be defined. + #endif +#endif + +/* */ + + +#endif /* __X86_64_ACCTON_AS5916_54X_PORTING_H__ */ +/* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk new file mode 100644 index 00000000..568066a4 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk @@ -0,0 +1,10 @@ +############################################################################### +# +# +# +############################################################################### +THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) +x86_64_accton_as5916_54x_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5916_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5916_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54x ucli:x86_64_accton_as5916_54x + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile new file mode 100644 index 00000000..04d2f92b --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile @@ -0,0 +1,9 @@ +############################################################################### +# +# Local source generation targets. +# +############################################################################### + +ucli: + @../../../../tools/uclihandlers.py x86_64_accton_as5916_54x_ucli.c + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/fani.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/fani.c new file mode 100644 index 00000000..6e990cfd --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/fani.c @@ -0,0 +1,303 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Fan Platform Implementation Defaults. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +enum fan_id { + FAN_1_ON_FAN_BOARD = 1, + FAN_2_ON_FAN_BOARD, + FAN_3_ON_FAN_BOARD, + FAN_4_ON_FAN_BOARD, + FAN_5_ON_FAN_BOARD, + FAN_6_ON_FAN_BOARD, + FAN_1_ON_PSU_1, + FAN_1_ON_PSU_2, +}; + +#define MAX_FAN_SPEED 25500 +#define MAX_PSU_FAN_SPEED 25500 + +#define CHASSIS_FAN_INFO(fid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_FAN_BOARD), "Chassis Fan - "#fid, 0 },\ + 0x0,\ + ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +#define PSU_FAN_INFO(pid, fid) \ + { \ + { ONLP_FAN_ID_CREATE(FAN_##fid##_ON_PSU_##pid), "PSU "#pid" - Fan "#fid, 0 },\ + 0x0,\ + ONLP_FAN_CAPS_SET_PERCENTAGE | ONLP_FAN_CAPS_GET_RPM | ONLP_FAN_CAPS_GET_PERCENTAGE,\ + 0,\ + 0,\ + ONLP_FAN_MODE_INVALID,\ + } + +/* Static fan information */ +onlp_fan_info_t finfo[] = { + { }, /* Not used */ + CHASSIS_FAN_INFO(1), + CHASSIS_FAN_INFO(2), + CHASSIS_FAN_INFO(3), + CHASSIS_FAN_INFO(4), + CHASSIS_FAN_INFO(5), + CHASSIS_FAN_INFO(6), + PSU_FAN_INFO(1, 1), + PSU_FAN_INFO(2, 1) +}; + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_FAN(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +_onlp_fani_info_get_fan(int fid, onlp_fan_info_t* info) +{ + int value, ret; + + /* get fan present status + */ + ret = onlp_file_read_int(&value, "%s""fan%d_present", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + if (value == 0) { + return ONLP_STATUS_OK; /* fan is not present */ + } + info->status |= ONLP_FAN_STATUS_PRESENT; + + + /* get fan fault status (turn on when any one fails) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_fault", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + if (value > 0) { + info->status |= ONLP_FAN_STATUS_FAILED; + } + + + /* get fan direction (both : the same) + */ + ret = onlp_file_read_int(&value, "%s""fan%d_direction", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + info->status |= value ? ONLP_FAN_STATUS_F2B : ONLP_FAN_STATUS_B2F; + + + /* get front fan speed + */ + ret = onlp_file_read_int(&value, "%s""fan%d_front_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + info->rpm = value; + + /* get rear fan speed + */ + ret = onlp_file_read_int(&value, "%s""fan%d_rear_speed_rpm", FAN_BOARD_PATH, fid); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + /* take the min value from front/rear fan speed + */ + if (info->rpm > value) { + info->rpm = value; + } + + /* get speed percentage from rpm + */ + ret = onlp_file_read_int(&value, "%s""fan_max_speed_rpm", FAN_BOARD_PATH); + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from (%s)\r\n", FAN_BOARD_PATH); + return ONLP_STATUS_E_INTERNAL; + } + + info->percentage = (info->rpm * 100)/value; + + return ONLP_STATUS_OK; +} + +static uint32_t +_onlp_get_fan_direction_on_psu(void) +{ + /* Try to read direction from PSU1. + * If PSU1 is not valid, read from PSU2 + */ + int i = 0; + + for (i = PSU1_ID; i <= PSU2_ID; i++) { + psu_type_t psu_type; + psu_type = get_psu_type(i, NULL, 0); + + if (psu_type == PSU_TYPE_UNKNOWN) { + continue; + } + + if (PSU_TYPE_AC_F2B == psu_type) { + return ONLP_FAN_STATUS_F2B; + } + else { + return ONLP_FAN_STATUS_B2F; + } + } + + return 0; +} + +static int +_onlp_fani_info_get_fan_on_psu(int pid, onlp_fan_info_t* info) +{ + int val = 0; + + info->status |= ONLP_FAN_STATUS_PRESENT; + + /* get fan direction + */ + info->status |= _onlp_get_fan_direction_on_psu(); + + /* get fan speed + */ + if (psu_ym2651y_pmbus_info_get(pid, "psu_fan1_speed_rpm", &val) == ONLP_STATUS_OK) { + info->rpm = val; + info->percentage = (info->rpm * 100) / MAX_PSU_FAN_SPEED; + info->status |= (val == 0) ? ONLP_FAN_STATUS_FAILED : 0; + } + + return ONLP_STATUS_OK; +} + +/* + * This function will be called prior to all of onlp_fani_* functions. + */ +int +onlp_fani_init(void) +{ + return ONLP_STATUS_OK; +} + +int +onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* info) +{ + int rc = 0; + int fid; + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + *info = finfo[fid]; + + switch (fid) + { + case FAN_1_ON_PSU_1: + rc = _onlp_fani_info_get_fan_on_psu(PSU1_ID, info); + break; + case FAN_1_ON_PSU_2: + rc = _onlp_fani_info_get_fan_on_psu(PSU2_ID, info); + break; + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + rc =_onlp_fani_info_get_fan(fid, info); + break; + default: + rc = ONLP_STATUS_E_INVALID; + break; + } + + return rc; +} + +/* + * This function sets the fan speed of the given OID as a percentage. + * + * This will only be called if the OID has the PERCENTAGE_SET + * capability. + * + * It is optional if you have no fans at all with this feature. + */ +int +onlp_fani_percentage_set(onlp_oid_t id, int p) +{ + int fid; + char *path = NULL; + + VALIDATE(id); + + fid = ONLP_OID_ID_GET(id); + + /* reject p=0 (p=0, stop fan) */ + if (p == 0){ + return ONLP_STATUS_E_INVALID; + } + + switch (fid) + { + case FAN_1_ON_PSU_1: + return psu_ym2651y_pmbus_info_set(PSU1_ID, "psu_fan1_duty_cycle_percentage", p); + case FAN_1_ON_PSU_2: + return psu_ym2651y_pmbus_info_set(PSU2_ID, "psu_fan1_duty_cycle_percentage", p); + case FAN_1_ON_FAN_BOARD: + case FAN_2_ON_FAN_BOARD: + case FAN_3_ON_FAN_BOARD: + case FAN_4_ON_FAN_BOARD: + case FAN_5_ON_FAN_BOARD: + case FAN_6_ON_FAN_BOARD: + path = FAN_NODE(fan_duty_cycle_percentage); + break; + default: + return ONLP_STATUS_E_INVALID; + } + + if (onlp_file_write_int(p, path) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c new file mode 100644 index 00000000..4cb41893 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c @@ -0,0 +1,247 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define LED_FORMAT "/sys/class/leds/accton_as5916_54x_led::%s/brightness" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_LED(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +/* LED related data + */ +enum onlp_led_id +{ + LED_RESERVED = 0, + LED_LOC, + LED_DIAG, + LED_PSU1, + LED_PSU2, + LED_FAN, +}; + +enum led_light_mode { + LED_MODE_OFF, + LED_MODE_RED = 10, + LED_MODE_RED_BLINKING = 11, + LED_MODE_ORANGE = 12, + LED_MODE_ORANGE_BLINKING = 13, + LED_MODE_YELLOW = 14, + LED_MODE_YELLOW_BLINKING = 15, + LED_MODE_GREEN = 16, + LED_MODE_GREEN_BLINKING = 17, + LED_MODE_BLUE = 18, + LED_MODE_BLUE_BLINKING = 19, + LED_MODE_PURPLE = 20, + LED_MODE_PURPLE_BLINKING = 21, + LED_MODE_AUTO = 22, + LED_MODE_AUTO_BLINKING = 23, + LED_MODE_WHITE = 24, + LED_MODE_WHITE_BLINKING = 25, + LED_MODE_CYAN = 26, + LED_MODE_CYAN_BLINKING = 27, + LED_MODE_UNKNOWN = 99 +}; + +typedef struct led_light_mode_map { + enum onlp_led_id id; + enum led_light_mode driver_led_mode; + enum onlp_led_mode_e onlp_led_mode; +} led_light_mode_map_t; + +led_light_mode_map_t led_map[] = { +{LED_LOC, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_LOC, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{LED_DIAG, LED_MODE_OFF, ONLP_LED_MODE_OFF}, +{LED_DIAG, LED_MODE_GREEN, ONLP_LED_MODE_GREEN}, +{LED_DIAG, LED_MODE_ORANGE, ONLP_LED_MODE_ORANGE}, +{LED_FAN, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_PSU1, LED_MODE_AUTO, ONLP_LED_MODE_AUTO}, +{LED_PSU2, LED_MODE_AUTO, ONLP_LED_MODE_AUTO} +}; + +static char *leds[] = /* must map with onlp_led_id */ +{ + NULL, + "loc", + "diag", + "psu1", + "psu2", + "fan" +}; + +/* + * Get the information for the given LED OID. + */ +static onlp_led_info_t linfo[] = +{ + { }, /* Not used */ + { + { ONLP_LED_ID_CREATE(LED_LOC), "Chassis LED 1 (LOC LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE, + }, + { + { ONLP_LED_ID_CREATE(LED_DIAG), "Chassis LED 2 (DIAG LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU1), "Chassis LED 3 (PSU1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_PSU2), "Chassis LED 4 (PSU2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, + { + { ONLP_LED_ID_CREATE(LED_FAN), "Chassis LED 5 (FAN LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_AUTO, + }, +}; + +static int driver_to_onlp_led_mode(enum onlp_led_id id, enum led_light_mode driver_led_mode) +{ + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + for (i = 0; i < nsize; i++) + { + if (id == led_map[i].id && driver_led_mode == led_map[i].driver_led_mode) + { + return led_map[i].onlp_led_mode; + } + } + + return 0; +} + +static int onlp_to_driver_led_mode(enum onlp_led_id id, onlp_led_mode_t onlp_led_mode) +{ + int i, nsize = sizeof(led_map)/sizeof(led_map[0]); + + for(i = 0; i < nsize; i++) + { + if (id == led_map[i].id && onlp_led_mode == led_map[i].onlp_led_mode) + { + return led_map[i].driver_led_mode; + } + } + + return 0; +} + +/* + * This function will be called prior to any other onlp_ledi_* functions. + */ +int +onlp_ledi_init(void) +{ + /* + * Turn off the LOCATION and DIAG LEDs at startup + */ + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_DIAG), ONLP_LED_MODE_OFF); + onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_LOC), ONLP_LED_MODE_OFF); + + return ONLP_STATUS_OK; +} + +int +onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) +{ + int lid, value; + + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[ONLP_OID_ID_GET(id)]; + + /* Get LED mode */ + if (onlp_file_read_int(&value, LED_FORMAT, leds[lid]) < 0) { + DEBUG_PRINT("Unable to read status from file "LED_FORMAT, leds[lid]); + return ONLP_STATUS_E_INTERNAL; + } + + info->mode = driver_to_onlp_led_mode(lid, value); + + /* Set the on/off status */ + if (info->mode != ONLP_LED_MODE_OFF) { + info->status |= ONLP_LED_STATUS_ON; + } + + return ONLP_STATUS_OK; +} + +/* + * Turn an LED on or off. + * + * This function will only be called if the LED OID supports the ONOFF + * capability. + * + * What 'on' means in terms of colors or modes for multimode LEDs is + * up to the platform to decide. This is intended as baseline toggle mechanism. + */ +int +onlp_ledi_set(onlp_oid_t id, int on_or_off) +{ + VALIDATE(id); + + if (!on_or_off) { + return onlp_ledi_mode_set(id, ONLP_LED_MODE_OFF); + } + + return ONLP_STATUS_E_UNSUPPORTED; +} + +/* + * This function puts the LED into the given mode. It is a more functional + * interface for multimode LEDs. + * + * Only modes reported in the LED's capabilities will be attempted. + */ +int +onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int lid; + VALIDATE(id); + + lid = ONLP_OID_ID_GET(id); + if (onlp_file_write_int(onlp_to_driver_led_mode(lid , mode), LED_FORMAT, leds[lid]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk new file mode 100644 index 00000000..b3aafcb3 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk @@ -0,0 +1,9 @@ +############################################################################### +# +# +# +############################################################################### + +LIBRARY := x86_64_accton_as5916_54x +$(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) +include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.c new file mode 100644 index 00000000..1837a772 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.c @@ -0,0 +1,124 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2013 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include +#include +#include "platform_lib.h" + +#define PSU_NODE_MAX_PATH_LEN 64 +#define PSU_MODEL_NAME_LEN 9 +#define PSU_FAN_DIR_LEN 3 + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len) +{ + int ret = 0, value = 0; + char model[PSU_MODEL_NAME_LEN + 1] = {0}; + char fan_dir[PSU_FAN_DIR_LEN + 1] = {0}; + char *path = NULL; + + if (modelname && modelname_len < PSU_MODEL_NAME_LEN) { + return PSU_TYPE_UNKNOWN; + } + + /* Check AC model name */ + path = (id == PSU1_ID) ? PSU1_AC_EEPROM_NODE(psu_model_name) : PSU2_AC_EEPROM_NODE(psu_model_name); + ret = onlp_file_read((uint8_t*)model, PSU_MODEL_NAME_LEN, &value, path); + if (ret != ONLP_STATUS_OK || value != PSU_MODEL_NAME_LEN) { + return PSU_TYPE_UNKNOWN; + + } + + if (strncmp(model, "YM-2651Y", strlen("YM-2651Y")) != 0) { + return PSU_TYPE_UNKNOWN; + } + + if (modelname) { + strncpy(modelname, model, modelname_len-1); + } + + path = (id == PSU1_ID) ? PSU1_AC_PMBUS_NODE(psu_fan_dir) : PSU2_AC_PMBUS_NODE(psu_fan_dir); + ret = onlp_file_read((uint8_t*)fan_dir, sizeof(fan_dir), &value, path); + if (ret != ONLP_STATUS_OK) { + return PSU_TYPE_UNKNOWN; + } + + if (strncmp(fan_dir, "F2B", strlen("F2B")) == 0) { + return PSU_TYPE_AC_F2B; + } + + if (strncmp(fan_dir, "B2F", strlen("B2F")) == 0) { + return PSU_TYPE_AC_B2F; + } + + return PSU_TYPE_UNKNOWN; +} + +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value) +{ + int ret = 0; + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + *value = 0; + + if (PSU1_ID == id) { + ret = onlp_file_read_int(value, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + } + else { + ret = onlp_file_read_int(value, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + } + + if (ret < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ret; +} + +int psu_ym2651y_pmbus_info_set(int id, char *node, int value) +{ + char path[PSU_NODE_MAX_PATH_LEN] = {0}; + + switch (id) { + case PSU1_ID: + sprintf(path, "%s%s", PSU1_AC_PMBUS_PREFIX, node); + break; + case PSU2_ID: + sprintf(path, "%s%s", PSU2_AC_PMBUS_PREFIX, node); + break; + default: + return ONLP_STATUS_E_UNSUPPORTED; + }; + + if (onlp_file_write_int(value, path) < 0) { + AIM_LOG_ERROR("Unable to write data to file (%s)\r\n", path); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h new file mode 100644 index 00000000..f00d5d41 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h @@ -0,0 +1,89 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#ifndef __PLATFORM_LIB_H__ +#define __PLATFORM_LIB_H__ + +#include "x86_64_accton_as5916_54x_log.h" + +#define CHASSIS_FAN_COUNT 6 +#define CHASSIS_THERMAL_COUNT 5 +#define CHASSIS_LED_COUNT 5 +#define CHASSIS_PSU_COUNT 2 + +#define PSU1_ID 1 +#define PSU2_ID 2 + +#define PSU1_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/18-005b/" +#define PSU2_AC_PMBUS_PREFIX "/sys/bus/i2c/devices/17-0058/" + +#define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node +#define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node + +#define PSU1_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/18-0053/" +#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/17-0050/" + +#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node +#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node + +#define FAN_BOARD_PATH "/sys/bus/i2c/devices/9-0066/" +#define FAN_NODE(node) FAN_BOARD_PATH#node + +#define IDPROM_PATH "/sys/bus/i2c/devices/0-0054/eeprom" + +enum onlp_thermal_id +{ + THERMAL_RESERVED = 0, + THERMAL_CPU_CORE, + THERMAL_1_ON_MAIN_BROAD, + THERMAL_2_ON_MAIN_BROAD, + THERMAL_3_ON_MAIN_BROAD, + THERMAL_4_ON_MAIN_BROAD, + THERMAL_1_ON_PSU1, + THERMAL_1_ON_PSU2, +}; + +typedef enum psu_type { + PSU_TYPE_UNKNOWN, + PSU_TYPE_AC_F2B, + PSU_TYPE_AC_B2F +} psu_type_t; + +psu_type_t get_psu_type(int id, char* modelname, int modelname_len); +int psu_ym2651y_pmbus_info_get(int id, char *node, int *value); +int psu_ym2651y_pmbus_info_set(int id, char *node, int value); + +#define DEBUG_MODE 0 + +#if (DEBUG_MODE == 1) + #define DEBUG_PRINT(fmt, args...) \ + printf("%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) +#else + #define DEBUG_PRINT(fmt, args...) +#endif + +#endif /* __PLATFORM_LIB_H__ */ + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/psui.c new file mode 100644 index 00000000..f7f64f0e --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/psui.c @@ -0,0 +1,177 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define PSU_STATUS_PRESENT 1 +#define PSU_STATUS_POWER_GOOD 1 +#define PSU_NODE_MAX_PATH_LEN 64 + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_PSU(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static int +psu_status_info_get(int id, char *node, int *value) +{ + char *prefix = NULL; + + *value = 0; + + prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX; + if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { + AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); + return ONLP_STATUS_E_INTERNAL; + } + + return 0; +} + +int +onlp_psui_init(void) +{ + return ONLP_STATUS_OK; +} + +static int +psu_ym2651y_info_get(onlp_psu_info_t* info) +{ + int val = 0; + int index = ONLP_OID_ID_GET(info->hdr.id); + + /* Set capability + */ + info->caps = ONLP_PSU_CAPS_AC; + + if (info->status & ONLP_PSU_STATUS_FAILED) { + return ONLP_STATUS_OK; + } + + /* Set the associated oid_table */ + info->hdr.coids[0] = ONLP_FAN_ID_CREATE(index + CHASSIS_FAN_COUNT); + info->hdr.coids[1] = ONLP_THERMAL_ID_CREATE(index + CHASSIS_THERMAL_COUNT); + + /* Read voltage, current and power */ + if (psu_ym2651y_pmbus_info_get(index, "psu_v_out", &val) == 0) { + info->mvout = val; + info->caps |= ONLP_PSU_CAPS_VOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_i_out", &val) == 0) { + info->miout = val; + info->caps |= ONLP_PSU_CAPS_IOUT; + } + + if (psu_ym2651y_pmbus_info_get(index, "psu_p_out", &val) == 0) { + info->mpout = val; + info->caps |= ONLP_PSU_CAPS_POUT; + } + + return ONLP_STATUS_OK; +} + +/* + * Get all information about the given PSU oid. + */ +static onlp_psu_info_t pinfo[] = +{ + { }, /* Not used */ + { + { ONLP_PSU_ID_CREATE(PSU1_ID), "PSU-1", 0 }, + }, + { + { ONLP_PSU_ID_CREATE(PSU2_ID), "PSU-2", 0 }, + } +}; + +int +onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) +{ + int val = 0; + int ret = ONLP_STATUS_OK; + int index = ONLP_OID_ID_GET(id); + psu_type_t psu_type; + + VALIDATE(id); + + memset(info, 0, sizeof(onlp_psu_info_t)); + *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ + + /* Get the present state */ + if (psu_status_info_get(index, "psu_present", &val) != 0) { + printf("Unable to read PSU(%d) node(psu_present)\r\n", index); + } + + if (val != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_PSU_STATUS_PRESENT; + return ONLP_STATUS_OK; + } + info->status |= ONLP_PSU_STATUS_PRESENT; + + + /* Get power good status */ + if (psu_status_info_get(index, "psu_power_good", &val) != 0) { + printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + } + + if (val != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_PSU_STATUS_FAILED; + } + + + /* Get PSU type + */ + psu_type = get_psu_type(index, info->model, sizeof(info->model)); + + switch (psu_type) { + case PSU_TYPE_AC_F2B: + case PSU_TYPE_AC_B2F: + ret = psu_ym2651y_info_get(info); + break; + case PSU_TYPE_UNKNOWN: /* User insert a unknown PSU or unplugged.*/ + info->status |= ONLP_PSU_STATUS_UNPLUGGED; + info->status &= ~ONLP_PSU_STATUS_FAILED; + ret = ONLP_STATUS_OK; + break; + default: + ret = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return ret; +} + +int +onlp_psui_ioctl(onlp_oid_t pid, va_list vargs) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c new file mode 100644 index 00000000..d1606f47 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c @@ -0,0 +1,287 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2017 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#include "x86_64_accton_as5916_54x_log.h" + +#define NUM_OF_SFP_PORT 54 +#define MAX_PORT_PATH 64 + +#define SFP_PORT_FORMAT "/sys/bus/i2c/devices/%d-0050/%s" +#define SFP_PORT_DOM_FORMAT "/sys/bus/i2c/devices/%d-0051/%s" +#define SFP_BUS_INDEX(port) (port+33) + +/************************************************************ + * + * SFPI Entry Points + * + ***********************************************************/ +int +onlp_sfpi_init(void) +{ + /* Called at initialization time */ + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) +{ + /* + * Ports {0, 54} + */ + int p; + + for(p = 0; p < NUM_OF_SFP_PORT; p++) { + AIM_BITMAP_SET(bmap, p); + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_is_present(int port) +{ + /* + * Return 1 if present. + * Return 0 if not present. + * Return < 0 if error. + */ + int present; + if (onlp_file_read_int(&present, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_is_present") < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return present; +} + +int +onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[7]; + char path[MAX_PORT_PATH] = {0}; + FILE* fp; + + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_is_present_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5, + bytes+6 + ); + fclose(fp); + if(count != AIM_ARRAYSIZE(bytes)) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Mask out non-existant QSFP ports */ + bytes[6] &= 0x3F; + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t presence_all = 0 ; + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + presence_all <<= 8; + presence_all |= bytes[i]; + } + + /* Populate bitmap */ + for(i = 0; presence_all; i++) { + AIM_BITMAP_MOD(dst, i, (presence_all & 1)); + presence_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + int size = 0; + if(onlp_file_read(data, 256, &size, SFP_PORT_DOM_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { + if(size == 256) { + return ONLP_STATUS_OK; + } + } + + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) +{ + uint32_t bytes[6]; + char path[MAX_PORT_PATH] = {0}; + FILE* fp; + + sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_rx_los_all"); + fp = fopen(path, "r"); + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + int count = fscanf(fp, "%x %x %x %x %x %x", + bytes+0, + bytes+1, + bytes+2, + bytes+3, + bytes+4, + bytes+5 + ); + fclose(fp); + if(count != 6) { + AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Convert to 64 bit integer in port order */ + int i = 0; + uint64_t rx_los_all = 0 ; + for(i = 5; i >= 0; i--) { + rx_los_all <<= 8; + rx_los_all |= bytes[i]; + } + + /* Populate bitmap */ + for(i = 0; rx_los_all; i++) { + AIM_BITMAP_MOD(dst, i, (rx_los_all & 1)); + rx_los_all >>= 1; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) +{ + int rv; + + switch(control) + { + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (onlp_file_write_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") != 0) { + AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + break; + } + + return rv; +} + +int +onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) +{ + int rv; + + switch(control) + { + case ONLP_SFP_CONTROL_RX_LOS: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_rx_los") < 0) { + AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_FAULT: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_fault") < 0) { + AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + case ONLP_SFP_CONTROL_TX_DISABLE: + { + if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") < 0) { + AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); + rv = ONLP_STATUS_E_INTERNAL; + } + else { + rv = ONLP_STATUS_OK; + } + break; + } + + default: + rv = ONLP_STATUS_E_UNSUPPORTED; + } + + return rv; +} + + +int +onlp_sfpi_denit(void) +{ + return ONLP_STATUS_OK; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c new file mode 100644 index 00000000..44bf47a1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c @@ -0,0 +1,339 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2017 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * + * + ***********************************************************/ +#include +#include + +#include +#include +#include +#include +#include +#include +#include "platform_lib.h" + +#include "x86_64_accton_as5916_54x_int.h" +#include "x86_64_accton_as5916_54x_log.h" + +#define CPLD_VERSION_FORMAT "/sys/bus/i2c/devices/%s/version" +#define NUM_OF_CPLD 2 + +static char* cpld_path[NUM_OF_CPLD] = +{ + "11-0060", + "12-0062" +}; + +const char* +onlp_sysi_platform_get(void) +{ + return "x86-64-accton-as5916-54x-r1"; +} + +int +onlp_sysi_onie_data_get(uint8_t** data, int* size) +{ + uint8_t* rdata = aim_zmalloc(256); + if(onlp_file_read(rdata, 256, size, IDPROM_PATH) == ONLP_STATUS_OK) { + if(*size == 256) { + *data = rdata; + return ONLP_STATUS_OK; + } + } + + aim_free(rdata); + *size = 0; + return ONLP_STATUS_E_INTERNAL; +} + +int +onlp_sysi_oids_get(onlp_oid_t* table, int max) +{ + int i; + onlp_oid_t* e = table; + memset(table, 0, max*sizeof(onlp_oid_t)); + + /* 5 Thermal sensors on the chassis */ + for (i = 1; i <= CHASSIS_THERMAL_COUNT; i++) { + *e++ = ONLP_THERMAL_ID_CREATE(i); + } + + /* 5 LEDs on the chassis */ + for (i = 1; i <= CHASSIS_LED_COUNT; i++) { + *e++ = ONLP_LED_ID_CREATE(i); + } + + /* 2 PSUs on the chassis */ + for (i = 1; i <= CHASSIS_PSU_COUNT; i++) { + *e++ = ONLP_PSU_ID_CREATE(i); + } + + /* 6 Fans on the chassis */ + for (i = 1; i <= CHASSIS_FAN_COUNT; i++) { + *e++ = ONLP_FAN_ID_CREATE(i); + } + + return 0; +} + +int +onlp_sysi_platform_info_get(onlp_platform_info_t* pi) +{ + int i, v[NUM_OF_CPLD] = {0}; + + for (i = 0; i < AIM_ARRAYSIZE(cpld_path); i++) { + v[i] = 0; + + if(onlp_file_read_int(v+i, CPLD_VERSION_FORMAT , cpld_path[i]) < 0) { + return ONLP_STATUS_E_INTERNAL; + } + } + + pi->cpld_versions = aim_fstrdup("%d.%d", v[0], v[1]); + return ONLP_STATUS_OK; +} + +void +onlp_sysi_platform_info_free(onlp_platform_info_t* pi) +{ + aim_free(pi->cpld_versions); +} + +#define FAN_DUTY_MAX (100) +#define FAN_DUTY_MID (69) +#define FAN_DUTY_MIN (38) + +#define FANCTRL_DIR_FACTOR (ONLP_FAN_STATUS_B2F) +#define FANCTRL_DIR_FACTOR_DUTY_ADDON (6) + +static int +sysi_fanctrl_fan_fault_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if any fan is not operational */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (!(fi[i].status & ONLP_FAN_STATUS_FAILED)) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_absent_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* Bring fan speed to FAN_DUTY_MAX if fan is not present */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + if (fi[i].status & ONLP_FAN_STATUS_PRESENT) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_fan_unknown_speed_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty; + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + if (onlp_file_read_int(&fanduty, FAN_NODE(fan_duty_cycle_percentage)) < 0) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* Bring fan speed to max if current speed is not expected + */ + if (fanduty != fanduty_min && fanduty != fanduty_mid && fanduty != FAN_DUTY_MAX) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_single_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int i; + *adjusted = 0; + + /* When anyone higher than 50 degrees, all fans run with duty 100%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 50000) { + continue; + } + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + + /* When anyone higher than 45 degrees, all fans run with duty 62.5%. + */ + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + if (ti[i-1].mcelsius < 45000) { + continue; + } + + int fanduty_mid = FAN_DUTY_MID; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + + return ONLP_STATUS_OK; +} + +static int +sysi_fanctrl_overall_thermal_sensor_policy(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted) +{ + int fanduty_min = FAN_DUTY_MIN; + int fanduty_mid = FAN_DUTY_MID; + int i, num_of_sensor = 0, temp_avg = 0; + + *adjusted = 0; + fanduty_min += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + fanduty_mid += (fi[0].status & FANCTRL_DIR_FACTOR) ? FANCTRL_DIR_FACTOR_DUTY_ADDON : 0; + + for (i = (THERMAL_1_ON_MAIN_BROAD); i <= (THERMAL_3_ON_MAIN_BROAD); i++) { + num_of_sensor++; + temp_avg += ti[i-1].mcelsius; + } + + temp_avg /= num_of_sensor; + + if (temp_avg >= 45000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + } + else if (temp_avg >= 40000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_mid); + } + else if (temp_avg < 35000) { + *adjusted = 1; + return onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), fanduty_min); + } + + return ONLP_STATUS_OK; +} + +typedef int (*fan_control_policy)(onlp_fan_info_t fi[CHASSIS_FAN_COUNT], + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT], + int *adjusted); + +fan_control_policy fan_control_policies[] = { +sysi_fanctrl_fan_fault_policy, +sysi_fanctrl_fan_absent_policy, +sysi_fanctrl_fan_unknown_speed_policy, +sysi_fanctrl_single_thermal_sensor_policy, +sysi_fanctrl_overall_thermal_sensor_policy, +}; + +int +onlp_sysi_platform_manage_fans(void) +{ + int i, rc; + onlp_fan_info_t fi[CHASSIS_FAN_COUNT]; + onlp_thermal_info_t ti[CHASSIS_THERMAL_COUNT]; + + memset(fi, 0, sizeof(fi)); + memset(ti, 0, sizeof(ti)); + + /* Get fan status + */ + for (i = 0; i < CHASSIS_FAN_COUNT; i++) { + rc = onlp_fani_info_get(ONLP_FAN_ID_CREATE(i+1), &fi[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Get thermal sensor status + */ + for (i = 0; i < CHASSIS_THERMAL_COUNT; i++) { + rc = onlp_thermali_info_get(ONLP_THERMAL_ID_CREATE(i+1), &ti[i]); + + if (rc != ONLP_STATUS_OK) { + onlp_fani_percentage_set(ONLP_FAN_ID_CREATE(1), FAN_DUTY_MAX); + return ONLP_STATUS_E_INTERNAL; + } + } + + /* Apply thermal policy according the policy list, + * If fan duty is adjusted by one of the policies, skip the others + */ + for (i = 0; i < AIM_ARRAYSIZE(fan_control_policies); i++) { + int adjusted = 0; + + rc = fan_control_policies[i](fi, ti, &adjusted); + if (!adjusted) { + continue; + } + + return rc; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sysi_platform_manage_leds(void) +{ + return ONLP_STATUS_E_UNSUPPORTED; +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/thermali.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/thermali.c new file mode 100644 index 00000000..742a4dd1 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/thermali.c @@ -0,0 +1,128 @@ +/************************************************************ + * + * + * Copyright 2014 Big Switch Networks, Inc. + * Copyright 2014 Accton Technology Corporation. + * + * Licensed under the Eclipse Public License, Version 1.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.eclipse.org/legal/epl-v10.html + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the + * License. + * + * + ************************************************************ + * + * Thermal Sensor Platform Implementation. + * + ***********************************************************/ +#include +#include +#include "platform_lib.h" + +#define VALIDATE(_id) \ + do { \ + if(!ONLP_OID_IS_THERMAL(_id)) { \ + return ONLP_STATUS_E_INVALID; \ + } \ + } while(0) + +static char* devfiles__[] = /* must map with onlp_thermal_id */ +{ + NULL, + NULL, /* CPU_CORE files */ + "/sys/bus/i2c/devices/10-0048*temp1_input", + "/sys/bus/i2c/devices/10-0049*temp1_input", + "/sys/bus/i2c/devices/10-004a*temp1_input", + "/sys/bus/i2c/devices/10-004b*temp1_input", + "/sys/bus/i2c/devices/18-005b*psu_temp1_input", + "/sys/bus/i2c/devices/17-0058*psu_temp1_input", +}; + +static char* cpu_coretemp_files[] = + { + "/sys/devices/platform/coretemp.0*temp2_input", + "/sys/devices/platform/coretemp.0*temp3_input", + "/sys/devices/platform/coretemp.0*temp4_input", + "/sys/devices/platform/coretemp.0*temp5_input", + NULL, + }; + +/* Static values */ +static onlp_thermal_info_t linfo[] = { + { }, /* Not used */ + { { ONLP_THERMAL_ID_CREATE(THERMAL_CPU_CORE), "CPU Core", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_MAIN_BROAD), "LM75-1-48", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_2_ON_MAIN_BROAD), "LM75-2-49", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_3_ON_MAIN_BROAD), "LM75-3-4A", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_4_ON_MAIN_BROAD), "LM75-3-4B", 0}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU1), "PSU-1 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU1_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + }, + { { ONLP_THERMAL_ID_CREATE(THERMAL_1_ON_PSU2), "PSU-2 Thermal Sensor 1", ONLP_PSU_ID_CREATE(PSU2_ID)}, + ONLP_THERMAL_STATUS_PRESENT, + ONLP_THERMAL_CAPS_ALL, 0, ONLP_THERMAL_THRESHOLD_INIT_DEFAULTS + } +}; + +/* + * This will be called to intiialize the thermali subsystem. + */ +int +onlp_thermali_init(void) +{ + return ONLP_STATUS_OK; +} + +/* + * Retrieve the information structure for the given thermal OID. + * + * If the OID is invalid, return ONLP_E_STATUS_INVALID. + * If an unexpected error occurs, return ONLP_E_STATUS_INTERNAL. + * Otherwise, return ONLP_STATUS_OK with the OID's information. + * + * Note -- it is expected that you fill out the information + * structure even if the sensor described by the OID is not present. + */ +int +onlp_thermali_info_get(onlp_oid_t id, onlp_thermal_info_t* info) +{ + int tid; + VALIDATE(id); + + tid = ONLP_OID_ID_GET(id); + + /* Set the onlp_oid_hdr_t and capabilities */ + *info = linfo[tid]; + + if(tid == THERMAL_CPU_CORE) { + int rv = onlp_file_read_int_max(&info->mcelsius, cpu_coretemp_files); + return rv; + } + + return onlp_file_read_int(&info->mcelsius, devfiles__[tid]); +} + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c new file mode 100644 index 00000000..3579a89f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c @@ -0,0 +1,80 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* */ +#define __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) +x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[] = +{ +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif +#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#else +{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +#endif + { NULL, NULL } +}; +#undef __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5916_54x_config_STRINGIFY_NAME + +const char* +x86_64_accton_as5916_54x_config_lookup(const char* setting) +{ + int i; + for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { + if(strcmp(x86_64_accton_as5916_54x_config_settings[i].name, setting)) { + return x86_64_accton_as5916_54x_config_settings[i].value; + } + } + return NULL; +} + +int +x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs) +{ + int i; + for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5916_54x_config_settings[i].name, x86_64_accton_as5916_54x_config_settings[i].value); + } + return i; +} + +/* */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c new file mode 100644 index 00000000..b2b98d07 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c @@ -0,0 +1,10 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +/* <--auto.start.enum(ALL).source> */ +/* */ + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h new file mode 100644 index 00000000..4543ef58 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * x86_64_accton_as5916_54x Internal Header + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_INT_H__ +#define __x86_64_accton_as5916_54x_INT_H__ + +#include + + +#endif /* __x86_64_accton_as5916_54x_INT_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c new file mode 100644 index 00000000..1537e358 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c @@ -0,0 +1,18 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5916_54x_log.h" +/* + * x86_64_accton_as5916_54x log struct. + */ +AIM_LOG_STRUCT_DEFINE( + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT, + NULL, /* Custom log map */ + X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + ); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h new file mode 100644 index 00000000..5e6ad4d0 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h @@ -0,0 +1,12 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#ifndef __x86_64_accton_as5916_54x_LOG_H__ +#define __x86_64_accton_as5916_54x_LOG_H__ + +#define AIM_LOG_MODULE_NAME x86_64_accton_as5916_54x +#include + +#endif /* __x86_64_accton_as5916_54x_LOG_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c new file mode 100644 index 00000000..efd313db --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c @@ -0,0 +1,24 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#include "x86_64_accton_as5916_54x_log.h" + +static int +datatypes_init__(void) +{ +#define x86_64_accton_as5916_54x_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include + return 0; +} + +void __x86_64_accton_as5916_54x_module_init__(void) +{ + AIM_LOG_STRUCT_REGISTER(); + datatypes_init__(); +} + +int __onlp_platform_version__ = 1; \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c new file mode 100644 index 00000000..fe6e423f --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c @@ -0,0 +1,50 @@ +/**************************************************************************//** + * + * + * + *****************************************************************************/ +#include + +#if x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI == 1 + +#include +#include +#include + +static ucli_status_t +x86_64_accton_as5916_54x_ucli_ucli__config__(ucli_context_t* uc) +{ + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5916_54x) +} + +/* */ +/* */ + +static ucli_module_t +x86_64_accton_as5916_54x_ucli_module__ = + { + "x86_64_accton_as5916_54x_ucli", + NULL, + x86_64_accton_as5916_54x_ucli_ucli_handlers__, + NULL, + NULL, + }; + +ucli_node_t* +x86_64_accton_as5916_54x_ucli_node_create(void) +{ + ucli_node_t* n; + ucli_module_init(&x86_64_accton_as5916_54x_ucli_module__); + n = ucli_node_create("x86_64_accton_as5916_54x", NULL, &x86_64_accton_as5916_54x_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5916_54x")); + return n; +} + +#else +void* +x86_64_accton_as5916_54x_ucli_node_create(void) +{ + return NULL; +} +#endif + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/Makefile new file mode 100644 index 00000000..003238cf --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/Makefile @@ -0,0 +1 @@ +include $(ONL)/make/pkg.mk \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml new file mode 100644 index 00000000..caedb664 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml @@ -0,0 +1 @@ +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5916-54x REVISION=r1 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml new file mode 100644 index 00000000..42278b23 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml @@ -0,0 +1,33 @@ +--- + +###################################################################### +# +# platform-config for AS5916 +# +###################################################################### + +x86-64-accton-as5916-54x-r1: + + grub: + + serial: >- + --port=0x3f8 + --speed=115200 + --word=8 + --parity=no + --stop=1 + + kernel: + <<: *kernel-3-16 + + args: >- + nopat + console=ttyS0,115200n8 + tg3.short_preamble=1 + tg3.bcm5718s_reset=1 + + ##network: + ## interfaces: + ## ma1: + ## name: ~ + ## syspath: pci0000:00/0000:00:1c.0/0000:0a:00.0 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py new file mode 100644 index 00000000..171b3c20 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py @@ -0,0 +1,72 @@ +from onl.platform.base import * +from onl.platform.accton import * + +class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, + OnlPlatformPortConfig_48x10_6x40): + PLATFORM='x86-64-accton-as5916-54x-r1' + MODEL="AS5916-54X" + SYS_OBJECT_ID=".5916.54" + + def baseconfig(self): + self.insmod("accton_i2c_cpld") + self.insmod("ym2651y") + for m in [ "sfp", "psu", "fan", "leds" ]: + self.insmod("x86-64-accton-as5916-54x-%s" % m) + + ########### initialize I2C bus 0 ########### + self.new_i2c_devices( + [ + # initialize multiplexer (PCA9548) + ('pca9548', 0x77, 0), + ('pca9548', 0x76, 1), + + # initiate chassis fan + ('as5916_54x_fan', 0x66, 9), + + # inititate LM75 + ('lm75', 0x48, 10), + ('lm75', 0x49, 10), + ('lm75', 0x4a, 10), + ('lm75', 0x4b, 10), + + # initialize CPLDs + ('accton_i2c_cpld', 0x60, 11), + ('accton_i2c_cpld', 0x62, 12), + + # initialize multiplexer (PCA9548) + ('pca9548', 0x74, 2), + + # initiate PSU-1 AC Power + ('as5916_54x_psu1', 0x53, 18), + ('ym2651', 0x5b, 18), + + # initiate PSU-2 AC Power + ('as5916_54x_psu2', 0x50, 17), + ('ym2651', 0x58, 17), + + # initialize multiplexer (PCA9548) + ('pca9548', 0x72, 2), + ('pca9548', 0x75, 25), + ('pca9548', 0x75, 26), + ('pca9548', 0x75, 27), + ('pca9548', 0x75, 28), + ('pca9548', 0x75, 29), + ('pca9548', 0x75, 30), + ('pca9548', 0x75, 31), + + # initiate IDPROM + ('24c02', 0x54, 0), + ] + ) + + # initialize SFP devices + for port in range(1, 49): + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x51, port+32) + + # initialize QSFP devices + for port in range(49, 55): + self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + + return True + From 8cb1b5b6303fee9bce1d7d05ade45af88e751e16 Mon Sep 17 00:00:00 2001 From: roy_lee Date: Fri, 9 Mar 2018 10:44:08 +0800 Subject: [PATCH 05/21] 1. Rename 54x to be 54xk. 2. IDPROM changes to I2C address 0x56 instead of 0x54. Signed-off-by: roy_lee --- .../x86-64-accton-as5916-54xk/.gitignore | 2 +- .../x86-64-accton-as5916-54xk/modules/PKG.yml | 2 +- .../modules/builds/Makefile | 2 +- .../builds/x86-64-accton-as5916-54xk-fan.c | 78 ++++++------ .../builds/x86-64-accton-as5916-54xk-leds.c | 116 +++++++++--------- .../builds/x86-64-accton-as5916-54xk-psu.c | 82 ++++++------- .../builds/x86-64-accton-as5916-54xk-sfp.c | 54 ++++---- .../x86-64-accton-as5916-54xk/onlp/PKG.yml | 2 +- .../onlp/builds/lib/Makefile | 6 +- .../onlp/builds/onlpdump/Makefile | 2 +- .../onlp/builds/src/.module | 2 +- .../onlp/builds/src/Makefile | 4 +- .../onlp/builds/src/README | 2 +- .../onlp/builds/src/module/auto/make.mk | 6 +- .../module/auto/x86_64_accton_as5916_54xk.yml | 26 ++-- .../x86_64_accton_as5916_54xk.x | 2 +- .../x86_64_accton_as5916_54xk_config.h | 80 ++++++------ .../x86_64_accton_as5916_54xk_dox.h | 16 +-- .../x86_64_accton_as5916_54xk_porting.h | 92 +++++++------- .../onlp/builds/src/module/make.mk | 6 +- .../onlp/builds/src/module/src/Makefile | 2 +- .../onlp/builds/src/module/src/ledi.c | 2 +- .../onlp/builds/src/module/src/make.mk | 2 +- .../onlp/builds/src/module/src/platform_lib.h | 4 +- .../onlp/builds/src/module/src/sfpi.c | 2 +- .../onlp/builds/src/module/src/sysi.c | 6 +- .../src/x86_64_accton_as5916_54xk_config.c | 78 ++++++------ .../src/x86_64_accton_as5916_54xk_enums.c | 2 +- .../src/x86_64_accton_as5916_54xk_int.h | 10 +- .../src/x86_64_accton_as5916_54xk_log.c | 12 +- .../src/x86_64_accton_as5916_54xk_log.h | 8 +- .../src/x86_64_accton_as5916_54xk_module.c | 10 +- .../src/x86_64_accton_as5916_54xk_ucli.c | 24 ++-- .../platform-config/r1/PKG.yml | 2 +- .../src/lib/x86-64-accton-as5916-54xk-r1.yml | 2 +- .../x86_64_accton_as5916_54xk_r1/__init__.py | 22 ++-- 36 files changed, 385 insertions(+), 385 deletions(-) mode change 100644 => 100755 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h mode change 100644 => 100755 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore index 2e2944b3..0e4c79d6 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/.gitignore @@ -1,2 +1,2 @@ -*x86*64*accton*as5916*54x*.mk +*x86*64*accton*as5916*54xk*.mk onlpdump.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml index b6c16c5e..2506401a 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/PKG.yml @@ -1 +1 @@ -!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5916-54x ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" +!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5916-54xk ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64" diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile index 0ae14eaa..12f05c94 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/Makefile @@ -1,6 +1,6 @@ KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64 KMODULES := $(wildcard *.c) VENDOR := accton -BASENAME := x86-64-accton-as5916-54x +BASENAME := x86-64-accton-as5916-54xk ARCH := x86_64 include $(ONL)/make/kmodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c index e69660e4..4eb38682 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-fan.c @@ -1,5 +1,5 @@ /* - * A hwmon driver for the Accton as5916 54x fan + * A hwmon driver for the Accton as5916 54xk fan * * Copyright (C) 2016 Accton Technology Corporation. * Brandon Chuang @@ -30,10 +30,10 @@ #include #include -#define DRVNAME "as5916_54x_fan" +#define DRVNAME "as5916_54xk_fan" #define MAX_FAN_SPEED_RPM 25500 -static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *dev); +static struct as5916_54xk_fan_data *as5916_54xk_fan_update_device(struct device *dev); static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); @@ -59,7 +59,7 @@ static const u8 fan_reg[] = { }; /* Each client has this additional data */ -struct as5916_54x_fan_data { +struct as5916_54xk_fan_data { struct device *hwmon_dev; struct mutex update_lock; char valid; /* != 0 if registers are valid */ @@ -171,7 +171,7 @@ DECLARE_FAN_DIRECTION_SENSOR_DEV_ATTR(6); /* 1 fan duty cycle attribute in this platform */ DECLARE_FAN_DUTY_CYCLE_SENSOR_DEV_ATTR(); -static struct attribute *as5916_54x_fan_attributes[] = { +static struct attribute *as5916_54xk_fan_attributes[] = { /* fan related attributes */ DECLARE_FAN_FAULT_ATTR(1), DECLARE_FAN_FAULT_ATTR(2), @@ -206,12 +206,12 @@ static struct attribute *as5916_54x_fan_attributes[] = { #define FAN_MAX_DUTY_CYCLE 100 #define FAN_REG_VAL_TO_SPEED_RPM_STEP 100 -static int as5916_54x_fan_read_value(struct i2c_client *client, u8 reg) +static int as5916_54xk_fan_read_value(struct i2c_client *client, u8 reg) { return i2c_smbus_read_byte_data(client, reg); } -static int as5916_54x_fan_write_value(struct i2c_client *client, u8 reg, u8 value) +static int as5916_54xk_fan_write_value(struct i2c_client *client, u8 reg, u8 value) { return i2c_smbus_write_byte_data(client, reg, value); } @@ -244,7 +244,7 @@ static u8 reg_val_to_is_present(u8 reg_val, enum fan_id id) return !(reg_val & BIT(id)); } -static u8 is_fan_fault(struct as5916_54x_fan_data *data, enum fan_id id) +static u8 is_fan_fault(struct as5916_54xk_fan_data *data, enum fan_id id) { u8 ret = 1; int front_fan_index = FAN1_FRONT_SPEED_RPM + id; @@ -273,8 +273,8 @@ static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, if (value < 0 || value > FAN_MAX_DUTY_CYCLE) return -EINVAL; - as5916_54x_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ - as5916_54x_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); + as5916_54xk_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */ + as5916_54xk_fan_write_value(client, fan_reg[FAN_DUTY_CYCLE_PERCENTAGE], duty_cycle_to_reg_val(value)); return count; } @@ -282,7 +282,7 @@ static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5916_54x_fan_data *data = as5916_54x_fan_update_device(dev); + struct as5916_54xk_fan_data *data = as5916_54xk_fan_update_device(dev); ssize_t ret = 0; if (data->valid) { @@ -345,14 +345,14 @@ static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, return ret; } -static const struct attribute_group as5916_54x_fan_group = { - .attrs = as5916_54x_fan_attributes, +static const struct attribute_group as5916_54xk_fan_group = { + .attrs = as5916_54xk_fan_attributes, }; -static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *dev) +static struct as5916_54xk_fan_data *as5916_54xk_fan_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + struct as5916_54xk_fan_data *data = i2c_get_clientdata(client); mutex_lock(&data->update_lock); @@ -360,13 +360,13 @@ static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *d !data->valid) { int i; - dev_dbg(&client->dev, "Starting as5916_54x_fan update\n"); + dev_dbg(&client->dev, "Starting as5916_54xk_fan update\n"); data->valid = 0; /* Update fan data */ for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) { - int status = as5916_54x_fan_read_value(client, fan_reg[i]); + int status = as5916_54xk_fan_read_value(client, fan_reg[i]); if (status < 0) { data->valid = 0; @@ -388,10 +388,10 @@ static struct as5916_54x_fan_data *as5916_54x_fan_update_device(struct device *d return data; } -static int as5916_54x_fan_probe(struct i2c_client *client, +static int as5916_54xk_fan_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { - struct as5916_54x_fan_data *data; + struct as5916_54xk_fan_data *data; int status; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { @@ -399,7 +399,7 @@ static int as5916_54x_fan_probe(struct i2c_client *client, goto exit; } - data = kzalloc(sizeof(struct as5916_54x_fan_data), GFP_KERNEL); + data = kzalloc(sizeof(struct as5916_54xk_fan_data), GFP_KERNEL); if (!data) { status = -ENOMEM; goto exit; @@ -412,7 +412,7 @@ static int as5916_54x_fan_probe(struct i2c_client *client, dev_info(&client->dev, "chip found\n"); /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5916_54x_fan_group); + status = sysfs_create_group(&client->dev.kobj, &as5916_54xk_fan_group); if (status) { goto exit_free; } @@ -429,7 +429,7 @@ static int as5916_54x_fan_probe(struct i2c_client *client, return 0; exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5916_54x_fan_group); + sysfs_remove_group(&client->dev.kobj, &as5916_54xk_fan_group); exit_free: kfree(data); exit: @@ -437,11 +437,11 @@ exit: return status; } -static int as5916_54x_fan_remove(struct i2c_client *client) +static int as5916_54xk_fan_remove(struct i2c_client *client) { - struct as5916_54x_fan_data *data = i2c_get_clientdata(client); + struct as5916_54xk_fan_data *data = i2c_get_clientdata(client); hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5916_54x_fan_group); + sysfs_remove_group(&client->dev.kobj, &as5916_54xk_fan_group); return 0; } @@ -449,37 +449,37 @@ static int as5916_54x_fan_remove(struct i2c_client *client) /* Addresses to scan */ static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END }; -static const struct i2c_device_id as5916_54x_fan_id[] = { - { "as5916_54x_fan", 0 }, +static const struct i2c_device_id as5916_54xk_fan_id[] = { + { "as5916_54xk_fan", 0 }, {} }; -MODULE_DEVICE_TABLE(i2c, as5916_54x_fan_id); +MODULE_DEVICE_TABLE(i2c, as5916_54xk_fan_id); -static struct i2c_driver as5916_54x_fan_driver = { +static struct i2c_driver as5916_54xk_fan_driver = { .class = I2C_CLASS_HWMON, .driver = { .name = DRVNAME, }, - .probe = as5916_54x_fan_probe, - .remove = as5916_54x_fan_remove, - .id_table = as5916_54x_fan_id, + .probe = as5916_54xk_fan_probe, + .remove = as5916_54xk_fan_remove, + .id_table = as5916_54xk_fan_id, .address_list = normal_i2c, }; -static int __init as5916_54x_fan_init(void) +static int __init as5916_54xk_fan_init(void) { - return i2c_add_driver(&as5916_54x_fan_driver); + return i2c_add_driver(&as5916_54xk_fan_driver); } -static void __exit as5916_54x_fan_exit(void) +static void __exit as5916_54xk_fan_exit(void) { - i2c_del_driver(&as5916_54x_fan_driver); + i2c_del_driver(&as5916_54xk_fan_driver); } -module_init(as5916_54x_fan_init); -module_exit(as5916_54x_fan_exit); +module_init(as5916_54xk_fan_init); +module_exit(as5916_54xk_fan_exit); MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as5916_54x_fan driver"); +MODULE_DESCRIPTION("as5916_54xk_fan driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c index 7f55dae7..f155e970 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-leds.c @@ -1,5 +1,5 @@ /* - * A LED driver for the accton_as5916_54x_led + * A LED driver for the accton_as5916_54xk_led * * Copyright (C) 2016 Accton Technology Corporation. * Brandon Chuang @@ -27,7 +27,7 @@ #include #include -#define DRVNAME "accton_as5916_54x_led" +#define DRVNAME "accton_as5916_54xk_led" #define DEBUG_MODE 1 @@ -41,7 +41,7 @@ extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); -struct accton_as5916_54x_led_data { +struct accton_as5916_54xk_led_data { struct platform_device *pdev; struct mutex update_lock; char valid; /* != 0 if registers are valid */ @@ -51,7 +51,7 @@ struct accton_as5916_54x_led_data { 2 ~ 4 = SYSTEM LED */ }; -static struct accton_as5916_54x_led_data *ledctl = NULL; +static struct accton_as5916_54xk_led_data *ledctl = NULL; #define LED_CNTRLER_I2C_ADDRESS (0x60) @@ -155,17 +155,17 @@ static u8 led_light_mode_to_reg_val(enum led_type type, return reg_val; } -static int accton_as5916_54x_led_read_value(u8 reg) +static int accton_as5916_54xk_led_read_value(u8 reg) { return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } -static int accton_as5916_54x_led_write_value(u8 reg, u8 value) +static int accton_as5916_54xk_led_write_value(u8 reg, u8 value) { return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } -static void accton_as5916_54x_led_update(void) +static void accton_as5916_54xk_led_update(void) { mutex_lock(&ledctl->update_lock); @@ -173,13 +173,13 @@ static void accton_as5916_54x_led_update(void) || !ledctl->valid) { int i; - dev_dbg(&ledctl->pdev->dev, "Starting accton_as5916_54x_led update\n"); + dev_dbg(&ledctl->pdev->dev, "Starting accton_as5916_54xk_led update\n"); ledctl->valid = 0; /* Update LED data */ for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) { - int status = accton_as5916_54x_led_read_value(led_reg[i]); + int status = accton_as5916_54xk_led_read_value(led_reg[i]); if (status < 0) { dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", led_reg[i], status); @@ -197,14 +197,14 @@ exit: mutex_unlock(&ledctl->update_lock); } -static void accton_as5916_54x_led_set(struct led_classdev *led_cdev, +static void accton_as5916_54xk_led_set(struct led_classdev *led_cdev, enum led_brightness led_light_mode, u8 reg, enum led_type type) { int reg_val; mutex_lock(&ledctl->update_lock); - reg_val = accton_as5916_54x_led_read_value(reg); + reg_val = accton_as5916_54xk_led_read_value(reg); if (reg_val < 0) { dev_dbg(&ledctl->pdev->dev, "reg %d, err %d\n", reg, reg_val); @@ -212,91 +212,91 @@ static void accton_as5916_54x_led_set(struct led_classdev *led_cdev, } reg_val = led_light_mode_to_reg_val(type, led_light_mode, reg_val); - accton_as5916_54x_led_write_value(reg, reg_val); + accton_as5916_54xk_led_write_value(reg, reg_val); ledctl->valid = 0; exit: mutex_unlock(&ledctl->update_lock); } -static void accton_as7312_54x_led_auto_set(struct led_classdev *led_cdev, +static void accton_as7312_54xk_led_auto_set(struct led_classdev *led_cdev, enum led_brightness led_light_mode) { } -static enum led_brightness accton_as7312_54x_led_auto_get(struct led_classdev *cdev) +static enum led_brightness accton_as7312_54xk_led_auto_get(struct led_classdev *cdev) { return LED_MODE_AUTO; } -static void accton_as5916_54x_led_diag_set(struct led_classdev *led_cdev, +static void accton_as5916_54xk_led_diag_set(struct led_classdev *led_cdev, enum led_brightness led_light_mode) { - accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); + accton_as5916_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG); } -static enum led_brightness accton_as5916_54x_led_diag_get(struct led_classdev *cdev) +static enum led_brightness accton_as5916_54xk_led_diag_get(struct led_classdev *cdev) { - accton_as5916_54x_led_update(); + accton_as5916_54xk_led_update(); return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]); } -static enum led_brightness accton_as5916_54x_led_loc_get(struct led_classdev *cdev) +static enum led_brightness accton_as5916_54xk_led_loc_get(struct led_classdev *cdev) { - accton_as5916_54x_led_update(); + accton_as5916_54xk_led_update(); return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]); } -static void accton_as5916_54x_led_loc_set(struct led_classdev *led_cdev, +static void accton_as5916_54xk_led_loc_set(struct led_classdev *led_cdev, enum led_brightness led_light_mode) { - accton_as5916_54x_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); + accton_as5916_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC); } -static struct led_classdev accton_as5916_54x_leds[] = { +static struct led_classdev accton_as5916_54xk_leds[] = { [LED_TYPE_LOC] = { - .name = "accton_as5916_54x_led::loc", + .name = "accton_as5916_54xk_led::loc", .default_trigger = "unused", - .brightness_set = accton_as5916_54x_led_loc_set, - .brightness_get = accton_as5916_54x_led_loc_get, + .brightness_set = accton_as5916_54xk_led_loc_set, + .brightness_get = accton_as5916_54xk_led_loc_get, .max_brightness = LED_MODE_ORANGE, }, [LED_TYPE_DIAG] = { - .name = "accton_as5916_54x_led::diag", + .name = "accton_as5916_54xk_led::diag", .default_trigger = "unused", - .brightness_set = accton_as5916_54x_led_diag_set, - .brightness_get = accton_as5916_54x_led_diag_get, + .brightness_set = accton_as5916_54xk_led_diag_set, + .brightness_get = accton_as5916_54xk_led_diag_get, .max_brightness = LED_MODE_GREEN, }, [LED_TYPE_PSU1] = { - .name = "accton_as5916_54x_led::psu1", + .name = "accton_as5916_54xk_led::psu1", .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, .max_brightness = LED_MODE_AUTO, }, [LED_TYPE_PSU2] = { - .name = "accton_as5916_54x_led::psu2", + .name = "accton_as5916_54xk_led::psu2", .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, .max_brightness = LED_MODE_AUTO, }, [LED_TYPE_FAN] = { - .name = "accton_as5916_54x_led::fan", + .name = "accton_as5916_54xk_led::fan", .default_trigger = "unused", - .brightness_set = accton_as7312_54x_led_auto_set, - .brightness_get = accton_as7312_54x_led_auto_get, + .brightness_set = accton_as7312_54xk_led_auto_set, + .brightness_get = accton_as7312_54xk_led_auto_get, .max_brightness = LED_MODE_AUTO, }, }; -static int accton_as5916_54x_led_probe(struct platform_device *pdev) +static int accton_as5916_54xk_led_probe(struct platform_device *pdev) { int ret, i; - for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { - ret = led_classdev_register(&pdev->dev, &accton_as5916_54x_leds[i]); + for (i = 0; i < ARRAY_SIZE(accton_as5916_54xk_leds); i++) { + ret = led_classdev_register(&pdev->dev, &accton_as5916_54xk_leds[i]); if (ret < 0) { break; @@ -304,48 +304,48 @@ static int accton_as5916_54x_led_probe(struct platform_device *pdev) } /* Check if all LEDs were successfully registered */ - if (i != ARRAY_SIZE(accton_as5916_54x_leds)){ + if (i != ARRAY_SIZE(accton_as5916_54xk_leds)){ int j; /* only unregister the LEDs that were successfully registered */ for (j = 0; j < i; j++) { - led_classdev_unregister(&accton_as5916_54x_leds[i]); + led_classdev_unregister(&accton_as5916_54xk_leds[i]); } } return ret; } -static int accton_as5916_54x_led_remove(struct platform_device *pdev) +static int accton_as5916_54xk_led_remove(struct platform_device *pdev) { int i; - for (i = 0; i < ARRAY_SIZE(accton_as5916_54x_leds); i++) { - led_classdev_unregister(&accton_as5916_54x_leds[i]); + for (i = 0; i < ARRAY_SIZE(accton_as5916_54xk_leds); i++) { + led_classdev_unregister(&accton_as5916_54xk_leds[i]); } return 0; } -static struct platform_driver accton_as5916_54x_led_driver = { - .probe = accton_as5916_54x_led_probe, - .remove = accton_as5916_54x_led_remove, +static struct platform_driver accton_as5916_54xk_led_driver = { + .probe = accton_as5916_54xk_led_probe, + .remove = accton_as5916_54xk_led_remove, .driver = { .name = DRVNAME, .owner = THIS_MODULE, }, }; -static int __init accton_as5916_54x_led_init(void) +static int __init accton_as5916_54xk_led_init(void) { int ret; - ret = platform_driver_register(&accton_as5916_54x_led_driver); + ret = platform_driver_register(&accton_as5916_54xk_led_driver); if (ret < 0) { goto exit; } - ledctl = kzalloc(sizeof(struct accton_as5916_54x_led_data), GFP_KERNEL); + ledctl = kzalloc(sizeof(struct accton_as5916_54xk_led_data), GFP_KERNEL); if (!ledctl) { ret = -ENOMEM; goto exit_driver; @@ -364,23 +364,23 @@ static int __init accton_as5916_54x_led_init(void) exit_free: kfree(ledctl); exit_driver: - platform_driver_unregister(&accton_as5916_54x_led_driver); + platform_driver_unregister(&accton_as5916_54xk_led_driver); exit: return ret; } -static void __exit accton_as5916_54x_led_exit(void) +static void __exit accton_as5916_54xk_led_exit(void) { platform_device_unregister(ledctl->pdev); - platform_driver_unregister(&accton_as5916_54x_led_driver); + platform_driver_unregister(&accton_as5916_54xk_led_driver); kfree(ledctl); } -late_initcall(accton_as5916_54x_led_init); -module_exit(accton_as5916_54x_led_exit); +late_initcall(accton_as5916_54xk_led_init); +module_exit(accton_as5916_54xk_led_exit); MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton_as5916_54x_led driver"); +MODULE_DESCRIPTION("accton_as5916_54xk_led driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c index 4627df9c..a2737499 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-psu.c @@ -1,5 +1,5 @@ /* - * An hwmon driver for accton as5916_54x Power Module + * An hwmon driver for accton as5916_54xk Power Module * * Copyright (C) 2014 Accton Technology Corporation. * Brandon Chuang @@ -36,7 +36,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); -static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); +static int as5916_54xk_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned @@ -45,7 +45,7 @@ static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; /* Each client has this additional data */ -struct as5916_54x_psu_data { +struct as5916_54xk_psu_data { struct device *hwmon_dev; struct mutex update_lock; char valid; /* !=0 if registers are valid */ @@ -55,9 +55,9 @@ struct as5916_54x_psu_data { char model_name[9]; /* Model name, read from eeprom */ }; -static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev); +static struct as5916_54xk_psu_data *as5916_54xk_psu_update_device(struct device *dev); -enum as5916_54x_psu_sysfs_attributes { +enum as5916_54xk_psu_sysfs_attributes { PSU_PRESENT, PSU_MODEL_NAME, PSU_POWER_GOOD @@ -69,7 +69,7 @@ static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRE static SENSOR_DEVICE_ATTR(psu_model_name, S_IRUGO, show_model_name,NULL, PSU_MODEL_NAME); static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); -static struct attribute *as5916_54x_psu_attributes[] = { +static struct attribute *as5916_54xk_psu_attributes[] = { &sensor_dev_attr_psu_present.dev_attr.attr, &sensor_dev_attr_psu_model_name.dev_attr.attr, &sensor_dev_attr_psu_power_good.dev_attr.attr, @@ -80,7 +80,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf) { struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + struct as5916_54xk_psu_data *data = as5916_54xk_psu_update_device(dev); u8 status = 0; if (attr->index == PSU_PRESENT) { @@ -96,19 +96,19 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf) { - struct as5916_54x_psu_data *data = as5916_54x_psu_update_device(dev); + struct as5916_54xk_psu_data *data = as5916_54xk_psu_update_device(dev); return sprintf(buf, "%s\n", data->model_name); } -static const struct attribute_group as5916_54x_psu_group = { - .attrs = as5916_54x_psu_attributes, +static const struct attribute_group as5916_54xk_psu_group = { + .attrs = as5916_54xk_psu_attributes, }; -static int as5916_54x_psu_probe(struct i2c_client *client, +static int as5916_54xk_psu_probe(struct i2c_client *client, const struct i2c_device_id *dev_id) { - struct as5916_54x_psu_data *data; + struct as5916_54xk_psu_data *data; int status; if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { @@ -116,7 +116,7 @@ static int as5916_54x_psu_probe(struct i2c_client *client, goto exit; } - data = kzalloc(sizeof(struct as5916_54x_psu_data), GFP_KERNEL); + data = kzalloc(sizeof(struct as5916_54xk_psu_data), GFP_KERNEL); if (!data) { status = -ENOMEM; goto exit; @@ -130,7 +130,7 @@ static int as5916_54x_psu_probe(struct i2c_client *client, dev_info(&client->dev, "chip found\n"); /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5916_54x_psu_group); + status = sysfs_create_group(&client->dev.kobj, &as5916_54xk_psu_group); if (status) { goto exit_free; } @@ -147,7 +147,7 @@ static int as5916_54x_psu_probe(struct i2c_client *client, return 0; exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5916_54x_psu_group); + sysfs_remove_group(&client->dev.kobj, &as5916_54xk_psu_group); exit_free: kfree(data); exit: @@ -155,12 +155,12 @@ exit: return status; } -static int as5916_54x_psu_remove(struct i2c_client *client) +static int as5916_54xk_psu_remove(struct i2c_client *client) { - struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + struct as5916_54xk_psu_data *data = i2c_get_clientdata(client); hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5916_54x_psu_group); + sysfs_remove_group(&client->dev.kobj, &as5916_54xk_psu_group); kfree(data); return 0; @@ -168,29 +168,29 @@ static int as5916_54x_psu_remove(struct i2c_client *client) enum psu_index { - as5916_54x_psu1, - as5916_54x_psu2 + as5916_54xk_psu1, + as5916_54xk_psu2 }; -static const struct i2c_device_id as5916_54x_psu_id[] = { - { "as5916_54x_psu1", as5916_54x_psu1 }, - { "as5916_54x_psu2", as5916_54x_psu2 }, +static const struct i2c_device_id as5916_54xk_psu_id[] = { + { "as5916_54xk_psu1", as5916_54xk_psu1 }, + { "as5916_54xk_psu2", as5916_54xk_psu2 }, {} }; -MODULE_DEVICE_TABLE(i2c, as5916_54x_psu_id); +MODULE_DEVICE_TABLE(i2c, as5916_54xk_psu_id); -static struct i2c_driver as5916_54x_psu_driver = { +static struct i2c_driver as5916_54xk_psu_driver = { .class = I2C_CLASS_HWMON, .driver = { - .name = "as5916_54x_psu", + .name = "as5916_54xk_psu", }, - .probe = as5916_54x_psu_probe, - .remove = as5916_54x_psu_remove, - .id_table = as5916_54x_psu_id, + .probe = as5916_54xk_psu_probe, + .remove = as5916_54xk_psu_remove, + .id_table = as5916_54xk_psu_id, .address_list = normal_i2c, }; -static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data, +static int as5916_54xk_psu_read_block(struct i2c_client *client, u8 command, u8 *data, int data_len) { int result = 0; @@ -219,10 +219,10 @@ static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 * return result; } -static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *dev) +static struct as5916_54xk_psu_data *as5916_54xk_psu_update_device(struct device *dev) { struct i2c_client *client = to_i2c_client(dev); - struct as5916_54x_psu_data *data = i2c_get_clientdata(client); + struct as5916_54xk_psu_data *data = i2c_get_clientdata(client); mutex_lock(&data->update_lock); @@ -231,7 +231,7 @@ static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *d int status; int power_good = 0; - dev_dbg(&client->dev, "Starting as5916_54x update\n"); + dev_dbg(&client->dev, "Starting as5916_54xk update\n"); /* Read psu status */ status = accton_i2c_cpld_read(0x60, 0x2); @@ -248,7 +248,7 @@ static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *d power_good = data->status & BIT(3 - data->index); if (power_good) { - status = as5916_54x_psu_read_block(client, 0x20, data->model_name, + status = as5916_54xk_psu_read_block(client, 0x20, data->model_name, ARRAY_SIZE(data->model_name)-1); if (status < 0) { @@ -269,20 +269,20 @@ static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *d return data; } -static int __init as5916_54x_psu_init(void) +static int __init as5916_54xk_psu_init(void) { - return i2c_add_driver(&as5916_54x_psu_driver); + return i2c_add_driver(&as5916_54xk_psu_driver); } -static void __exit as5916_54x_psu_exit(void) +static void __exit as5916_54xk_psu_exit(void) { - i2c_del_driver(&as5916_54x_psu_driver); + i2c_del_driver(&as5916_54xk_psu_driver); } -module_init(as5916_54x_psu_init); -module_exit(as5916_54x_psu_exit); +module_init(as5916_54xk_psu_init); +module_exit(as5916_54xk_psu_exit); MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as5916_54x_psu driver"); +MODULE_DESCRIPTION("as5916_54xk_psu driver"); MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c index c924772b..c606e5c2 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/modules/builds/x86-64-accton-as5916-54xk-sfp.c @@ -1,5 +1,5 @@ /* - * SFP driver for accton as5916_54x sfp + * SFP driver for accton as5916_54xk sfp * * Copyright (C) Brandon Chuang * @@ -32,7 +32,7 @@ #include #include -#define DRIVER_NAME "as5916_54x_sfp" /* Platform dependent */ +#define DRIVER_NAME "as5916_54xk_sfp" /* Platform dependent */ #define DEBUG_MODE 0 @@ -181,30 +181,30 @@ static struct attribute *sfp_ddm_attributes[] = { #define CPLD_PORT_TO_FRONT_PORT(port) (port+1) enum port_numbers { -as5916_54x_sfp1, as5916_54x_sfp2, as5916_54x_sfp3, as5916_54x_sfp4, as5916_54x_sfp5, as5916_54x_sfp6, as5916_54x_sfp7, as5916_54x_sfp8, -as5916_54x_sfp9, as5916_54x_sfp10, as5916_54x_sfp11, as5916_54x_sfp12, as5916_54x_sfp13, as5916_54x_sfp14, as5916_54x_sfp15, as5916_54x_sfp16, -as5916_54x_sfp17, as5916_54x_sfp18, as5916_54x_sfp19, as5916_54x_sfp20, as5916_54x_sfp21, as5916_54x_sfp22, as5916_54x_sfp23, as5916_54x_sfp24, -as5916_54x_sfp25, as5916_54x_sfp26, as5916_54x_sfp27, as5916_54x_sfp28, as5916_54x_sfp29, as5916_54x_sfp30, as5916_54x_sfp31, as5916_54x_sfp32, -as5916_54x_sfp33, as5916_54x_sfp34, as5916_54x_sfp35, as5916_54x_sfp36, as5916_54x_sfp37, as5916_54x_sfp38, as5916_54x_sfp39, as5916_54x_sfp40, -as5916_54x_sfp41, as5916_54x_sfp42, as5916_54x_sfp43, as5916_54x_sfp44, as5916_54x_sfp45, as5916_54x_sfp46, as5916_54x_sfp47, as5916_54x_sfp48, -as5916_54x_sfp49, as5916_54x_sfp50, as5916_54x_sfp51, as5916_54x_sfp52, as5916_54x_sfp53, as5916_54x_sfp54 +as5916_54xk_sfp1, as5916_54xk_sfp2, as5916_54xk_sfp3, as5916_54xk_sfp4, as5916_54xk_sfp5, as5916_54xk_sfp6, as5916_54xk_sfp7, as5916_54xk_sfp8, +as5916_54xk_sfp9, as5916_54xk_sfp10, as5916_54xk_sfp11, as5916_54xk_sfp12, as5916_54xk_sfp13, as5916_54xk_sfp14, as5916_54xk_sfp15, as5916_54xk_sfp16, +as5916_54xk_sfp17, as5916_54xk_sfp18, as5916_54xk_sfp19, as5916_54xk_sfp20, as5916_54xk_sfp21, as5916_54xk_sfp22, as5916_54xk_sfp23, as5916_54xk_sfp24, +as5916_54xk_sfp25, as5916_54xk_sfp26, as5916_54xk_sfp27, as5916_54xk_sfp28, as5916_54xk_sfp29, as5916_54xk_sfp30, as5916_54xk_sfp31, as5916_54xk_sfp32, +as5916_54xk_sfp33, as5916_54xk_sfp34, as5916_54xk_sfp35, as5916_54xk_sfp36, as5916_54xk_sfp37, as5916_54xk_sfp38, as5916_54xk_sfp39, as5916_54xk_sfp40, +as5916_54xk_sfp41, as5916_54xk_sfp42, as5916_54xk_sfp43, as5916_54xk_sfp44, as5916_54xk_sfp45, as5916_54xk_sfp46, as5916_54xk_sfp47, as5916_54xk_sfp48, +as5916_54xk_sfp49, as5916_54xk_sfp50, as5916_54xk_sfp51, as5916_54xk_sfp52, as5916_54xk_sfp53, as5916_54xk_sfp54 }; static const struct i2c_device_id sfp_device_id[] = { -{ "as5916_54x_sfp1", as5916_54x_sfp1 }, { "as5916_54x_sfp2", as5916_54x_sfp2 }, { "as5916_54x_sfp3", as5916_54x_sfp3 }, { "as5916_54x_sfp4", as5916_54x_sfp4 }, -{ "as5916_54x_sfp5", as5916_54x_sfp5 }, { "as5916_54x_sfp6", as5916_54x_sfp6 }, { "as5916_54x_sfp7", as5916_54x_sfp7 }, { "as5916_54x_sfp8", as5916_54x_sfp8 }, -{ "as5916_54x_sfp9", as5916_54x_sfp9 }, { "as5916_54x_sfp10", as5916_54x_sfp10 }, { "as5916_54x_sfp11", as5916_54x_sfp11 }, { "as5916_54x_sfp12", as5916_54x_sfp12 }, -{ "as5916_54x_sfp13", as5916_54x_sfp13 }, { "as5916_54x_sfp14", as5916_54x_sfp14 }, { "as5916_54x_sfp15", as5916_54x_sfp15 }, { "as5916_54x_sfp16", as5916_54x_sfp16 }, -{ "as5916_54x_sfp17", as5916_54x_sfp17 }, { "as5916_54x_sfp18", as5916_54x_sfp18 }, { "as5916_54x_sfp19", as5916_54x_sfp19 }, { "as5916_54x_sfp20", as5916_54x_sfp20 }, -{ "as5916_54x_sfp21", as5916_54x_sfp21 }, { "as5916_54x_sfp22", as5916_54x_sfp22 }, { "as5916_54x_sfp23", as5916_54x_sfp23 }, { "as5916_54x_sfp24", as5916_54x_sfp24 }, -{ "as5916_54x_sfp25", as5916_54x_sfp25 }, { "as5916_54x_sfp26", as5916_54x_sfp26 }, { "as5916_54x_sfp27", as5916_54x_sfp27 }, { "as5916_54x_sfp28", as5916_54x_sfp28 }, -{ "as5916_54x_sfp29", as5916_54x_sfp29 }, { "as5916_54x_sfp30", as5916_54x_sfp30 }, { "as5916_54x_sfp31", as5916_54x_sfp31 }, { "as5916_54x_sfp32", as5916_54x_sfp32 }, -{ "as5916_54x_sfp33", as5916_54x_sfp33 }, { "as5916_54x_sfp34", as5916_54x_sfp34 }, { "as5916_54x_sfp35", as5916_54x_sfp35 }, { "as5916_54x_sfp36", as5916_54x_sfp36 }, -{ "as5916_54x_sfp37", as5916_54x_sfp37 }, { "as5916_54x_sfp38", as5916_54x_sfp38 }, { "as5916_54x_sfp39", as5916_54x_sfp39 }, { "as5916_54x_sfp40", as5916_54x_sfp40 }, -{ "as5916_54x_sfp41", as5916_54x_sfp41 }, { "as5916_54x_sfp42", as5916_54x_sfp42 }, { "as5916_54x_sfp43", as5916_54x_sfp43 }, { "as5916_54x_sfp44", as5916_54x_sfp44 }, -{ "as5916_54x_sfp45", as5916_54x_sfp45 }, { "as5916_54x_sfp46", as5916_54x_sfp46 }, { "as5916_54x_sfp47", as5916_54x_sfp47 }, { "as5916_54x_sfp48", as5916_54x_sfp48 }, -{ "as5916_54x_sfp49", as5916_54x_sfp49 }, { "as5916_54x_sfp50", as5916_54x_sfp50 }, { "as5916_54x_sfp51", as5916_54x_sfp51 }, { "as5916_54x_sfp52", as5916_54x_sfp52 }, -{ "as5916_54x_sfp53", as5916_54x_sfp53 }, { "as5916_54x_sfp54", as5916_54x_sfp54 }, +{ "as5916_54xk_sfp1", as5916_54xk_sfp1 }, { "as5916_54xk_sfp2", as5916_54xk_sfp2 }, { "as5916_54xk_sfp3", as5916_54xk_sfp3 }, { "as5916_54xk_sfp4", as5916_54xk_sfp4 }, +{ "as5916_54xk_sfp5", as5916_54xk_sfp5 }, { "as5916_54xk_sfp6", as5916_54xk_sfp6 }, { "as5916_54xk_sfp7", as5916_54xk_sfp7 }, { "as5916_54xk_sfp8", as5916_54xk_sfp8 }, +{ "as5916_54xk_sfp9", as5916_54xk_sfp9 }, { "as5916_54xk_sfp10", as5916_54xk_sfp10 }, { "as5916_54xk_sfp11", as5916_54xk_sfp11 }, { "as5916_54xk_sfp12", as5916_54xk_sfp12 }, +{ "as5916_54xk_sfp13", as5916_54xk_sfp13 }, { "as5916_54xk_sfp14", as5916_54xk_sfp14 }, { "as5916_54xk_sfp15", as5916_54xk_sfp15 }, { "as5916_54xk_sfp16", as5916_54xk_sfp16 }, +{ "as5916_54xk_sfp17", as5916_54xk_sfp17 }, { "as5916_54xk_sfp18", as5916_54xk_sfp18 }, { "as5916_54xk_sfp19", as5916_54xk_sfp19 }, { "as5916_54xk_sfp20", as5916_54xk_sfp20 }, +{ "as5916_54xk_sfp21", as5916_54xk_sfp21 }, { "as5916_54xk_sfp22", as5916_54xk_sfp22 }, { "as5916_54xk_sfp23", as5916_54xk_sfp23 }, { "as5916_54xk_sfp24", as5916_54xk_sfp24 }, +{ "as5916_54xk_sfp25", as5916_54xk_sfp25 }, { "as5916_54xk_sfp26", as5916_54xk_sfp26 }, { "as5916_54xk_sfp27", as5916_54xk_sfp27 }, { "as5916_54xk_sfp28", as5916_54xk_sfp28 }, +{ "as5916_54xk_sfp29", as5916_54xk_sfp29 }, { "as5916_54xk_sfp30", as5916_54xk_sfp30 }, { "as5916_54xk_sfp31", as5916_54xk_sfp31 }, { "as5916_54xk_sfp32", as5916_54xk_sfp32 }, +{ "as5916_54xk_sfp33", as5916_54xk_sfp33 }, { "as5916_54xk_sfp34", as5916_54xk_sfp34 }, { "as5916_54xk_sfp35", as5916_54xk_sfp35 }, { "as5916_54xk_sfp36", as5916_54xk_sfp36 }, +{ "as5916_54xk_sfp37", as5916_54xk_sfp37 }, { "as5916_54xk_sfp38", as5916_54xk_sfp38 }, { "as5916_54xk_sfp39", as5916_54xk_sfp39 }, { "as5916_54xk_sfp40", as5916_54xk_sfp40 }, +{ "as5916_54xk_sfp41", as5916_54xk_sfp41 }, { "as5916_54xk_sfp42", as5916_54xk_sfp42 }, { "as5916_54xk_sfp43", as5916_54xk_sfp43 }, { "as5916_54xk_sfp44", as5916_54xk_sfp44 }, +{ "as5916_54xk_sfp45", as5916_54xk_sfp45 }, { "as5916_54xk_sfp46", as5916_54xk_sfp46 }, { "as5916_54xk_sfp47", as5916_54xk_sfp47 }, { "as5916_54xk_sfp48", as5916_54xk_sfp48 }, +{ "as5916_54xk_sfp49", as5916_54xk_sfp49 }, { "as5916_54xk_sfp50", as5916_54xk_sfp50 }, { "as5916_54xk_sfp51", as5916_54xk_sfp51 }, { "as5916_54xk_sfp52", as5916_54xk_sfp52 }, +{ "as5916_54xk_sfp53", as5916_54xk_sfp53 }, { "as5916_54xk_sfp54", as5916_54xk_sfp54 }, { /* LIST END */ } }; MODULE_DEVICE_TABLE(i2c, sfp_device_id); @@ -351,7 +351,7 @@ static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) return data; } - DEBUG_PRINT("Starting as5916_54x sfp tx rx status update"); + DEBUG_PRINT("Starting as5916_54xk sfp tx rx status update"); mutex_lock(&data->update_lock); data->msa->valid = 0; memset(data->msa->status, 0, sizeof(data->msa->status)); @@ -1220,7 +1220,7 @@ static int sfp_device_probe(struct i2c_client *client, data->port = dev_id->driver_data; data->client = client; - if (dev_id->driver_data >= as5916_54x_sfp1 && dev_id->driver_data <= as5916_54x_sfp48) { + if (dev_id->driver_data >= as5916_54xk_sfp1 && dev_id->driver_data <= as5916_54xk_sfp48) { if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { data->driver_type = DRIVER_TYPE_SFP_MSA; return sfp_msa_probe(client, dev_id, &data->msa); @@ -1230,7 +1230,7 @@ static int sfp_device_probe(struct i2c_client *client, return sfp_ddm_probe(client, dev_id, &data->ddm); } } - else { /* as5916_54x_sfp49 ~ as5916_54x_sfp54 */ + else { /* as5916_54xk_sfp49 ~ as5916_54xk_sfp54 */ if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { data->driver_type = DRIVER_TYPE_QSFP; return qsfp_probe(client, dev_id, &data->qsfp); @@ -1306,7 +1306,7 @@ static void __exit sfp_exit(void) } MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5916_54x_sfp driver"); +MODULE_DESCRIPTION("accton as5916_54xk_sfp driver"); MODULE_LICENSE("GPL"); late_initcall(sfp_init); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml index ee1812ff..e9a7c297 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/PKG.yml @@ -1 +1 @@ -!include $ONL_TEMPLATES/onlp-platform-revision.yml PLATFORM=x86-64-accton-as5916-54x ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu REVISION=r1 +!include $ONL_TEMPLATES/onlp-platform-revision.yml PLATFORM=x86-64-accton-as5916-54xk ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu REVISION=r1 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile index 1f155bfc..dad1416d 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/lib/Makefile @@ -23,15 +23,15 @@ ############################################################ include $(ONL)/make/config.amd64.mk -MODULE := libonlp-x86-64-accton-as5916-54x +MODULE := libonlp-x86-64-accton-as5916-54xk include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF x86_64_accton_as5916_54x onlplib +DEPENDMODULES := AIM IOF x86_64_accton_as5916_54xk onlplib DEPENDMODULE_HEADERS := sff include $(BUILDER)/dependmodules.mk -SHAREDLIB := libonlp-x86-64-accton-as5916-54x.so +SHAREDLIB := libonlp-x86-64-accton-as5916-54xk.so $(SHAREDLIB)_TARGETS := $(ALL_TARGETS) include $(BUILDER)/so.mk .DEFAULT_GOAL := $(SHAREDLIB) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile index 0c41fbc0..d746bb0f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/onlpdump/Makefile @@ -29,7 +29,7 @@ include $(ONL)/make/config.amd64.mk MODULE := onlpdump include $(BUILDER)/standardinit.mk -DEPENDMODULES := AIM IOF onlp x86_64_accton_as5916_54x onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS +DEPENDMODULES := AIM IOF onlp x86_64_accton_as5916_54xk onlplib onlp_platform_defaults sff cjson cjson_util timer_wheel OS include $(BUILDER)/dependmodules.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module index b7e5840e..c5e14119 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/.module @@ -1 +1 @@ -name: x86_64_accton_as5916_54x +name: x86_64_accton_as5916_54xk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile index 10f71d72..24ddaca8 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/Makefile @@ -4,6 +4,6 @@ # ############################################################################### include ../../init.mk -MODULE := x86_64_accton_as5916_54x -AUTOMODULE := x86_64_accton_as5916_54x +MODULE := x86_64_accton_as5916_54xk +AUTOMODULE := x86_64_accton_as5916_54xk include $(BUILDER)/definemodule.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README index 64864843..10ac657c 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/README @@ -1,6 +1,6 @@ ############################################################################### # -# x86_64_accton_as5916_54x README +# x86_64_accton_as5916_54xk README # ############################################################################### diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk index 9db4a259..15148435 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/make.mk @@ -1,9 +1,9 @@ ############################################################################### # -# x86_64_accton_as5916_54x Autogeneration +# x86_64_accton_as5916_54xk Autogeneration # ############################################################################### -x86_64_accton_as5916_54x_AUTO_DEFS := module/auto/x86_64_accton_as5916_54x.yml -x86_64_accton_as5916_54x_AUTO_DIRS := module/inc/x86_64_accton_as5916_54x module/src +x86_64_accton_as5916_54xk_AUTO_DEFS := module/auto/x86_64_accton_as5916_54xk.yml +x86_64_accton_as5916_54xk_AUTO_DIRS := module/inc/x86_64_accton_as5916_54xk module/src include $(BUILDER)/auto.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml index 987f682f..9efc6401 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/auto/x86_64_accton_as5916_54xk.yml @@ -1,44 +1,44 @@ ############################################################################### # -# x86_64_accton_as5916_54x Autogeneration Definitions. +# x86_64_accton_as5916_54xk Autogeneration Definitions. # ############################################################################### cdefs: &cdefs -- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING: +- X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING: doc: "Include or exclude logging." default: 1 -- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT: +- X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT: doc: "Default enabled log options." default: AIM_LOG_OPTIONS_DEFAULT -- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT: +- X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT: doc: "Default enabled log bits." default: AIM_LOG_BITS_DEFAULT -- X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT: +- X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT: doc: "Default enabled custom log bits." default: 0 -- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB: +- X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB: doc: "Default all porting macros to use the C standard libraries." default: 1 -- X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: +- X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS: doc: "Include standard library headers for stdlib porting macros." - default: X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB -- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI: + default: X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB +- X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI: doc: "Include generic uCli support." default: 0 -- X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: +- X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION: doc: "Assume chassis fan direction is the same as the PSU fan direction." default: 0 definitions: cdefs: - X86_64_ACCTON_AS5916_54X_CONFIG_HEADER: + X86_64_ACCTON_AS5916_54XK_CONFIG_HEADER: defs: *cdefs - basename: x86_64_accton_as5916_54x_config + basename: x86_64_accton_as5916_54xk_config portingmacro: - x86_64_accton_as5916_54x: + x86_64_accton_as5916_54xk: macros: - malloc - free diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x index 7776b59e..33e59762 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk.x @@ -3,7 +3,7 @@ * * *****************************************************************************/ -#include +#include /* <--auto.start.xmacro(ALL).define> */ /* */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h index 43572880..427e6b26 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_config.h @@ -1,102 +1,102 @@ /**************************************************************************//** * * @file - * @brief x86_64_accton_as5916_54x Configuration Header + * @brief x86_64_accton_as5916_54xk Configuration Header * - * @addtogroup x86_64_accton_as5916_54x-config + * @addtogroup x86_64_accton_as5916_54xk-config * @{ * *****************************************************************************/ -#ifndef __X86_64_ACCTON_AS5916_54X_CONFIG_H__ -#define __X86_64_ACCTON_AS5916_54X_CONFIG_H__ +#ifndef __X86_64_ACCTON_AS5916_54XK_CONFIG_H__ +#define __X86_64_ACCTON_AS5916_54XK_CONFIG_H__ #ifdef GLOBAL_INCLUDE_CUSTOM_CONFIG #include #endif -#ifdef X86_64_ACCTON_AS5916_54X_INCLUDE_CUSTOM_CONFIG -#include +#ifdef X86_64_ACCTON_AS5916_54XK_INCLUDE_CUSTOM_CONFIG +#include #endif -/* */ +/* */ #include /** - * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING + * X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING * * Include or exclude logging. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING -#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING 1 +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING +#define X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING 1 #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT + * X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT * * Default enabled log options. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT -#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT +#define X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT AIM_LOG_OPTIONS_DEFAULT #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT + * X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT * * Default enabled log bits. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT -#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT AIM_LOG_BITS_DEFAULT #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + * X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT * * Default enabled custom log bits. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT -#define X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT +#define X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT 0 #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB + * X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB * * Default all porting macros to use the C standard libraries. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB -#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB 1 +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB +#define X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB 1 #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + * X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS * * Include standard library headers for stdlib porting macros. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS -#define X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS +#define X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI + * X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI * * Include generic uCli support. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI -#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI 0 +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI +#define X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI 0 #endif /** - * X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + * X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION * * Assume chassis fan direction is the same as the PSU fan direction. */ -#ifndef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION -#define X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 +#ifndef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION +#define X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION 0 #endif @@ -106,32 +106,32 @@ */ /** Configuration settings structure. */ -typedef struct x86_64_accton_as5916_54x_config_settings_s { +typedef struct x86_64_accton_as5916_54xk_config_settings_s { /** name */ const char* name; /** value */ const char* value; -} x86_64_accton_as5916_54x_config_settings_t; +} x86_64_accton_as5916_54xk_config_settings_t; /** Configuration settings table. */ -/** x86_64_accton_as5916_54x_config_settings table. */ -extern x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[]; +/** x86_64_accton_as5916_54xk_config_settings table. */ +extern x86_64_accton_as5916_54xk_config_settings_t x86_64_accton_as5916_54xk_config_settings[]; /** * @brief Lookup a configuration setting. * @param setting The name of the configuration option to lookup. */ -const char* x86_64_accton_as5916_54x_config_lookup(const char* setting); +const char* x86_64_accton_as5916_54xk_config_lookup(const char* setting); /** * @brief Show the compile-time configuration. * @param pvs The output stream. */ -int x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs); +int x86_64_accton_as5916_54xk_config_show(struct aim_pvs_s* pvs); -/* */ +/* */ -#include "x86_64_accton_as5916_54x_porting.h" +#include "x86_64_accton_as5916_54xk_porting.h" -#endif /* __X86_64_ACCTON_AS5916_54X_CONFIG_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54XK_CONFIG_H__ */ /* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h index 67e69645..af4fa451 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_dox.h @@ -1,13 +1,13 @@ /**************************************************************************//** * - * x86_64_accton_as5916_54x Doxygen Header + * x86_64_accton_as5916_54xk Doxygen Header * *****************************************************************************/ -#ifndef __X86_64_ACCTON_AS5916_54X_DOX_H__ -#define __X86_64_ACCTON_AS5916_54X_DOX_H__ +#ifndef __X86_64_ACCTON_AS5916_54XK_DOX_H__ +#define __X86_64_ACCTON_AS5916_54XK_DOX_H__ /** - * @defgroup x86_64_accton_as5916_54x x86_64_accton_as5916_54x - x86_64_accton_as5916_54x Description + * @defgroup x86_64_accton_as5916_54xk x86_64_accton_as5916_54xk - x86_64_accton_as5916_54xk Description * The documentation overview for this module should go here. @@ -15,12 +15,12 @@ The documentation overview for this module should go here. * * @{ * - * @defgroup x86_64_accton_as5916_54x-x86_64_accton_as5916_54x Public Interface - * @defgroup x86_64_accton_as5916_54x-config Compile Time Configuration - * @defgroup x86_64_accton_as5916_54x-porting Porting Macros + * @defgroup x86_64_accton_as5916_54xk-x86_64_accton_as5916_54xk Public Interface + * @defgroup x86_64_accton_as5916_54xk-config Compile Time Configuration + * @defgroup x86_64_accton_as5916_54xk-porting Porting Macros * * @} * */ -#endif /* __X86_64_ACCTON_AS5916_54X_DOX_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54XK_DOX_H__ */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h index e7dcddc8..bcfbee39 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/inc/x86_64_accton_as5916_54xk/x86_64_accton_as5916_54xk_porting.h @@ -1,18 +1,18 @@ /**************************************************************************//** * * @file - * @brief x86_64_accton_as5916_54x Porting Macros. + * @brief x86_64_accton_as5916_54xk Porting Macros. * - * @addtogroup x86_64_accton_as5916_54x-porting + * @addtogroup x86_64_accton_as5916_54xk-porting * @{ * *****************************************************************************/ -#ifndef __X86_64_ACCTON_AS5916_54X_PORTING_H__ -#define __X86_64_ACCTON_AS5916_54X_PORTING_H__ +#ifndef __X86_64_ACCTON_AS5916_54XK_PORTING_H__ +#define __X86_64_ACCTON_AS5916_54XK_PORTING_H__ /* */ -#if X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 +#if X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS == 1 #include #include #include @@ -20,88 +20,88 @@ #include #endif -#ifndef x86_64_accton_as5916_54x_MALLOC +#ifndef x86_64_accton_as5916_54xk_MALLOC #if defined(GLOBAL_MALLOC) - #define x86_64_accton_as5916_54x_MALLOC GLOBAL_MALLOC - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_MALLOC malloc + #define x86_64_accton_as5916_54xk_MALLOC GLOBAL_MALLOC + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_MALLOC malloc #else - #error The macro x86_64_accton_as5916_54x_MALLOC is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_MALLOC is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_FREE +#ifndef x86_64_accton_as5916_54xk_FREE #if defined(GLOBAL_FREE) - #define x86_64_accton_as5916_54x_FREE GLOBAL_FREE - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_FREE free + #define x86_64_accton_as5916_54xk_FREE GLOBAL_FREE + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_FREE free #else - #error The macro x86_64_accton_as5916_54x_FREE is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_FREE is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_MEMSET +#ifndef x86_64_accton_as5916_54xk_MEMSET #if defined(GLOBAL_MEMSET) - #define x86_64_accton_as5916_54x_MEMSET GLOBAL_MEMSET - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_MEMSET memset + #define x86_64_accton_as5916_54xk_MEMSET GLOBAL_MEMSET + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_MEMSET memset #else - #error The macro x86_64_accton_as5916_54x_MEMSET is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_MEMSET is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_MEMCPY +#ifndef x86_64_accton_as5916_54xk_MEMCPY #if defined(GLOBAL_MEMCPY) - #define x86_64_accton_as5916_54x_MEMCPY GLOBAL_MEMCPY - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_MEMCPY memcpy + #define x86_64_accton_as5916_54xk_MEMCPY GLOBAL_MEMCPY + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_MEMCPY memcpy #else - #error The macro x86_64_accton_as5916_54x_MEMCPY is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_MEMCPY is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_STRNCPY +#ifndef x86_64_accton_as5916_54xk_STRNCPY #if defined(GLOBAL_STRNCPY) - #define x86_64_accton_as5916_54x_STRNCPY GLOBAL_STRNCPY - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_STRNCPY strncpy + #define x86_64_accton_as5916_54xk_STRNCPY GLOBAL_STRNCPY + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_STRNCPY strncpy #else - #error The macro x86_64_accton_as5916_54x_STRNCPY is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_STRNCPY is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_VSNPRINTF +#ifndef x86_64_accton_as5916_54xk_VSNPRINTF #if defined(GLOBAL_VSNPRINTF) - #define x86_64_accton_as5916_54x_VSNPRINTF GLOBAL_VSNPRINTF - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_VSNPRINTF vsnprintf + #define x86_64_accton_as5916_54xk_VSNPRINTF GLOBAL_VSNPRINTF + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_VSNPRINTF vsnprintf #else - #error The macro x86_64_accton_as5916_54x_VSNPRINTF is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_VSNPRINTF is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_SNPRINTF +#ifndef x86_64_accton_as5916_54xk_SNPRINTF #if defined(GLOBAL_SNPRINTF) - #define x86_64_accton_as5916_54x_SNPRINTF GLOBAL_SNPRINTF - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_SNPRINTF snprintf + #define x86_64_accton_as5916_54xk_SNPRINTF GLOBAL_SNPRINTF + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_SNPRINTF snprintf #else - #error The macro x86_64_accton_as5916_54x_SNPRINTF is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_SNPRINTF is required but cannot be defined. #endif #endif -#ifndef x86_64_accton_as5916_54x_STRLEN +#ifndef x86_64_accton_as5916_54xk_STRLEN #if defined(GLOBAL_STRLEN) - #define x86_64_accton_as5916_54x_STRLEN GLOBAL_STRLEN - #elif X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB == 1 - #define x86_64_accton_as5916_54x_STRLEN strlen + #define x86_64_accton_as5916_54xk_STRLEN GLOBAL_STRLEN + #elif X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB == 1 + #define x86_64_accton_as5916_54xk_STRLEN strlen #else - #error The macro x86_64_accton_as5916_54x_STRLEN is required but cannot be defined. + #error The macro x86_64_accton_as5916_54xk_STRLEN is required but cannot be defined. #endif #endif /* */ -#endif /* __X86_64_ACCTON_AS5916_54X_PORTING_H__ */ +#endif /* __X86_64_ACCTON_AS5916_54XK_PORTING_H__ */ /* @} */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk index 568066a4..da8a50de 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/make.mk @@ -4,7 +4,7 @@ # ############################################################################### THIS_DIR := $(dir $(lastword $(MAKEFILE_LIST))) -x86_64_accton_as5916_54x_INCLUDES := -I $(THIS_DIR)inc -x86_64_accton_as5916_54x_INTERNAL_INCLUDES := -I $(THIS_DIR)src -x86_64_accton_as5916_54x_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54x ucli:x86_64_accton_as5916_54x +x86_64_accton_as5916_54xk_INCLUDES := -I $(THIS_DIR)inc +x86_64_accton_as5916_54xk_INTERNAL_INCLUDES := -I $(THIS_DIR)src +x86_64_accton_as5916_54xk_DEPENDMODULE_ENTRIES := init:x86_64_accton_as5916_54xk ucli:x86_64_accton_as5916_54xk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile index 04d2f92b..86833365 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/Makefile @@ -5,5 +5,5 @@ ############################################################################### ucli: - @../../../../tools/uclihandlers.py x86_64_accton_as5916_54x_ucli.c + @../../../../tools/uclihandlers.py x86_64_accton_as5916_54xk_ucli.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c index 4cb41893..26e36736 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/ledi.c @@ -27,7 +27,7 @@ #include #include "platform_lib.h" -#define LED_FORMAT "/sys/class/leds/accton_as5916_54x_led::%s/brightness" +#define LED_FORMAT "/sys/class/leds/accton_as5916_54xk_led::%s/brightness" #define VALIDATE(_id) \ do { \ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk index b3aafcb3..79448f2c 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/make.mk @@ -4,6 +4,6 @@ # ############################################################################### -LIBRARY := x86_64_accton_as5916_54x +LIBRARY := x86_64_accton_as5916_54xk $(LIBRARY)_SUBDIR := $(dir $(lastword $(MAKEFILE_LIST))) include $(BUILDER)/lib.mk diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h old mode 100644 new mode 100755 index f00d5d41..bd8a6ea5 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/platform_lib.h @@ -26,7 +26,7 @@ #ifndef __PLATFORM_LIB_H__ #define __PLATFORM_LIB_H__ -#include "x86_64_accton_as5916_54x_log.h" +#include "x86_64_accton_as5916_54xk_log.h" #define CHASSIS_FAN_COUNT 6 #define CHASSIS_THERMAL_COUNT 5 @@ -51,7 +51,7 @@ #define FAN_BOARD_PATH "/sys/bus/i2c/devices/9-0066/" #define FAN_NODE(node) FAN_BOARD_PATH#node -#define IDPROM_PATH "/sys/bus/i2c/devices/0-0054/eeprom" +#define IDPROM_PATH "/sys/bus/i2c/devices/0-0056/eeprom" enum onlp_thermal_id { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c index d1606f47..f4d29904 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sfpi.c @@ -27,7 +27,7 @@ #include #include "platform_lib.h" -#include "x86_64_accton_as5916_54x_log.h" +#include "x86_64_accton_as5916_54xk_log.h" #define NUM_OF_SFP_PORT 54 #define MAX_PORT_PATH 64 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c index 44bf47a1..0b55c57a 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/sysi.c @@ -34,8 +34,8 @@ #include #include "platform_lib.h" -#include "x86_64_accton_as5916_54x_int.h" -#include "x86_64_accton_as5916_54x_log.h" +#include "x86_64_accton_as5916_54xk_int.h" +#include "x86_64_accton_as5916_54xk_log.h" #define CPLD_VERSION_FORMAT "/sys/bus/i2c/devices/%s/version" #define NUM_OF_CPLD 2 @@ -49,7 +49,7 @@ static char* cpld_path[NUM_OF_CPLD] = const char* onlp_sysi_platform_get(void) { - return "x86-64-accton-as5916-54x-r1"; + return "x86-64-accton-as5916-54xk-r1"; } int diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c index 3579a89f..6596013d 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_config.c @@ -3,78 +3,78 @@ * * *****************************************************************************/ -#include +#include -/* */ -#define __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) #_x -#define __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(_x) -x86_64_accton_as5916_54x_config_settings_t x86_64_accton_as5916_54x_config_settings[] = +/* */ +#define __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(_x) #_x +#define __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(_x) __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(_x) +x86_64_accton_as5916_54xk_config_settings_t x86_64_accton_as5916_54xk_config_settings[] = { -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_LOGGING(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_STDLIB(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_UCLI(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif -#ifdef X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION - { __x86_64_accton_as5916_54x_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, +#ifdef X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION + { __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION), __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE(X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION) }, #else -{ X86_64_ACCTON_AS5916_54X_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54x_config_STRINGIFY_NAME), "__undefined__" }, +{ X86_64_ACCTON_AS5916_54XK_CONFIG_INCLUDE_DEFAULT_FAN_DIRECTION(__x86_64_accton_as5916_54xk_config_STRINGIFY_NAME), "__undefined__" }, #endif { NULL, NULL } }; -#undef __x86_64_accton_as5916_54x_config_STRINGIFY_VALUE -#undef __x86_64_accton_as5916_54x_config_STRINGIFY_NAME +#undef __x86_64_accton_as5916_54xk_config_STRINGIFY_VALUE +#undef __x86_64_accton_as5916_54xk_config_STRINGIFY_NAME const char* -x86_64_accton_as5916_54x_config_lookup(const char* setting) +x86_64_accton_as5916_54xk_config_lookup(const char* setting) { int i; - for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { - if(strcmp(x86_64_accton_as5916_54x_config_settings[i].name, setting)) { - return x86_64_accton_as5916_54x_config_settings[i].value; + for(i = 0; x86_64_accton_as5916_54xk_config_settings[i].name; i++) { + if(strcmp(x86_64_accton_as5916_54xk_config_settings[i].name, setting)) { + return x86_64_accton_as5916_54xk_config_settings[i].value; } } return NULL; } int -x86_64_accton_as5916_54x_config_show(struct aim_pvs_s* pvs) +x86_64_accton_as5916_54xk_config_show(struct aim_pvs_s* pvs) { int i; - for(i = 0; x86_64_accton_as5916_54x_config_settings[i].name; i++) { - aim_printf(pvs, "%s = %s\n", x86_64_accton_as5916_54x_config_settings[i].name, x86_64_accton_as5916_54x_config_settings[i].value); + for(i = 0; x86_64_accton_as5916_54xk_config_settings[i].name; i++) { + aim_printf(pvs, "%s = %s\n", x86_64_accton_as5916_54xk_config_settings[i].name, x86_64_accton_as5916_54xk_config_settings[i].value); } return i; } -/* */ \ No newline at end of file +/* */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c index b2b98d07..7c1101b0 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_enums.c @@ -3,7 +3,7 @@ * * *****************************************************************************/ -#include +#include /* <--auto.start.enum(ALL).source> */ /* */ diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h index 4543ef58..811a0b8b 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_int.h @@ -1,12 +1,12 @@ /**************************************************************************//** * - * x86_64_accton_as5916_54x Internal Header + * x86_64_accton_as5916_54xk Internal Header * *****************************************************************************/ -#ifndef __x86_64_accton_as5916_54x_INT_H__ -#define __x86_64_accton_as5916_54x_INT_H__ +#ifndef __x86_64_accton_as5916_54xk_INT_H__ +#define __x86_64_accton_as5916_54xk_INT_H__ -#include +#include -#endif /* __x86_64_accton_as5916_54x_INT_H__ */ \ No newline at end of file +#endif /* __x86_64_accton_as5916_54xk_INT_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c index 1537e358..465717fc 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.c @@ -3,16 +3,16 @@ * * *****************************************************************************/ -#include +#include -#include "x86_64_accton_as5916_54x_log.h" +#include "x86_64_accton_as5916_54xk_log.h" /* - * x86_64_accton_as5916_54x log struct. + * x86_64_accton_as5916_54xk log struct. */ AIM_LOG_STRUCT_DEFINE( - X86_64_ACCTON_AS5916_54X_CONFIG_LOG_OPTIONS_DEFAULT, - X86_64_ACCTON_AS5916_54X_CONFIG_LOG_BITS_DEFAULT, + X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_OPTIONS_DEFAULT, + X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_BITS_DEFAULT, NULL, /* Custom log map */ - X86_64_ACCTON_AS5916_54X_CONFIG_LOG_CUSTOM_BITS_DEFAULT + X86_64_ACCTON_AS5916_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT ); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h index 5e6ad4d0..8ccc0eb4 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_log.h @@ -3,10 +3,10 @@ * * *****************************************************************************/ -#ifndef __x86_64_accton_as5916_54x_LOG_H__ -#define __x86_64_accton_as5916_54x_LOG_H__ +#ifndef __x86_64_accton_as5916_54xk_LOG_H__ +#define __x86_64_accton_as5916_54xk_LOG_H__ -#define AIM_LOG_MODULE_NAME x86_64_accton_as5916_54x +#define AIM_LOG_MODULE_NAME x86_64_accton_as5916_54xk #include -#endif /* __x86_64_accton_as5916_54x_LOG_H__ */ \ No newline at end of file +#endif /* __x86_64_accton_as5916_54xk_LOG_H__ */ \ No newline at end of file diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c index efd313db..f29eef98 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_module.c @@ -3,19 +3,19 @@ * * *****************************************************************************/ -#include +#include -#include "x86_64_accton_as5916_54x_log.h" +#include "x86_64_accton_as5916_54xk_log.h" static int datatypes_init__(void) { -#define x86_64_accton_as5916_54x_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); -#include +#define x86_64_accton_as5916_54xk_ENUMERATION_ENTRY(_enum_name, _desc) AIM_DATATYPE_MAP_REGISTER(_enum_name, _enum_name##_map, _desc, AIM_LOG_INTERNAL); +#include return 0; } -void __x86_64_accton_as5916_54x_module_init__(void) +void __x86_64_accton_as5916_54xk_module_init__(void) { AIM_LOG_STRUCT_REGISTER(); datatypes_init__(); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c index fe6e423f..22ed3740 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/onlp/builds/src/module/src/x86_64_accton_as5916_54xk_ucli.c @@ -3,46 +3,46 @@ * * *****************************************************************************/ -#include +#include -#if x86_64_accton_as5916_54x_CONFIG_INCLUDE_UCLI == 1 +#if x86_64_accton_as5916_54xk_CONFIG_INCLUDE_UCLI == 1 #include #include #include static ucli_status_t -x86_64_accton_as5916_54x_ucli_ucli__config__(ucli_context_t* uc) +x86_64_accton_as5916_54xk_ucli_ucli__config__(ucli_context_t* uc) { - UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5916_54x) + UCLI_HANDLER_MACRO_MODULE_CONFIG(x86_64_accton_as5916_54xk) } /* */ /* */ static ucli_module_t -x86_64_accton_as5916_54x_ucli_module__ = +x86_64_accton_as5916_54xk_ucli_module__ = { - "x86_64_accton_as5916_54x_ucli", + "x86_64_accton_as5916_54xk_ucli", NULL, - x86_64_accton_as5916_54x_ucli_ucli_handlers__, + x86_64_accton_as5916_54xk_ucli_ucli_handlers__, NULL, NULL, }; ucli_node_t* -x86_64_accton_as5916_54x_ucli_node_create(void) +x86_64_accton_as5916_54xk_ucli_node_create(void) { ucli_node_t* n; - ucli_module_init(&x86_64_accton_as5916_54x_ucli_module__); - n = ucli_node_create("x86_64_accton_as5916_54x", NULL, &x86_64_accton_as5916_54x_ucli_module__); - ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5916_54x")); + ucli_module_init(&x86_64_accton_as5916_54xk_ucli_module__); + n = ucli_node_create("x86_64_accton_as5916_54xk", NULL, &x86_64_accton_as5916_54xk_ucli_module__); + ucli_node_subnode_add(n, ucli_module_log_node_create("x86_64_accton_as5916_54xk")); return n; } #else void* -x86_64_accton_as5916_54x_ucli_node_create(void) +x86_64_accton_as5916_54xk_ucli_node_create(void) { return NULL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml index caedb664..e153db0f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/PKG.yml @@ -1 +1 @@ -!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5916-54x REVISION=r1 +!include $ONL_TEMPLATES/platform-config-platform.yml ARCH=amd64 VENDOR=accton BASENAME=x86-64-accton-as5916-54xk REVISION=r1 diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml index 42278b23..40659850 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/lib/x86-64-accton-as5916-54xk-r1.yml @@ -6,7 +6,7 @@ # ###################################################################### -x86-64-accton-as5916-54x-r1: +x86-64-accton-as5916-54xk-r1: grub: diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py old mode 100644 new mode 100755 index 171b3c20..da17b4ea --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xk/platform-config/r1/src/python/x86_64_accton_as5916_54xk_r1/__init__.py @@ -1,17 +1,17 @@ from onl.platform.base import * from onl.platform.accton import * -class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, +class OnlPlatform_x86_64_accton_as5916_54xk_r1(OnlPlatformAccton, OnlPlatformPortConfig_48x10_6x40): - PLATFORM='x86-64-accton-as5916-54x-r1' - MODEL="AS5916-54X" + PLATFORM='x86-64-accton-as5916-54xk-r1' + MODEL="AS5916-54XK" SYS_OBJECT_ID=".5916.54" def baseconfig(self): self.insmod("accton_i2c_cpld") self.insmod("ym2651y") for m in [ "sfp", "psu", "fan", "leds" ]: - self.insmod("x86-64-accton-as5916-54x-%s" % m) + self.insmod("x86-64-accton-as5916-54xk-%s" % m) ########### initialize I2C bus 0 ########### self.new_i2c_devices( @@ -21,7 +21,7 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, ('pca9548', 0x76, 1), # initiate chassis fan - ('as5916_54x_fan', 0x66, 9), + ('as5916_54xk_fan', 0x66, 9), # inititate LM75 ('lm75', 0x48, 10), @@ -37,11 +37,11 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, ('pca9548', 0x74, 2), # initiate PSU-1 AC Power - ('as5916_54x_psu1', 0x53, 18), + ('as5916_54xk_psu1', 0x53, 18), ('ym2651', 0x5b, 18), # initiate PSU-2 AC Power - ('as5916_54x_psu2', 0x50, 17), + ('as5916_54xk_psu2', 0x50, 17), ('ym2651', 0x58, 17), # initialize multiplexer (PCA9548) @@ -55,18 +55,18 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, ('pca9548', 0x75, 31), # initiate IDPROM - ('24c02', 0x54, 0), + ('24c02', 0x56, 0), ] ) # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x51, port+32) + self.new_i2c_device('as5916_54xk_sfp%d' % port, 0x50, port+32) + self.new_i2c_device('as5916_54xk_sfp%d' % port, 0x51, port+32) # initialize QSFP devices for port in range(49, 55): - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + self.new_i2c_device('as5916_54xk_sfp%d' % port, 0x50, port+32) return True From e8b177c1df2edf4f13c699a1175cf410808ed0b1 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Thu, 15 Mar 2018 17:39:35 +0800 Subject: [PATCH 06/21] [as5912-54xk] Add support for OOM driver --- .../builds/x86-64-accton-as5912-54xk-cpld.c | 1098 ++++++++++++++ .../builds/x86-64-accton-as5912-54xk-leds.c | 8 +- .../builds/x86-64-accton-as5912-54xk-psu.c | 4 +- .../builds/x86-64-accton-as5912-54xk-sfp.c | 1315 ----------------- .../onlp/builds/src/module/src/sfpi.c | 240 +-- .../x86_64_accton_as5912_54xk_r0/__init__.py | 16 +- 6 files changed, 1268 insertions(+), 1413 deletions(-) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-cpld.c delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-cpld.c new file mode 100644 index 00000000..aba70271 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-cpld.c @@ -0,0 +1,1098 @@ +/* + * Copyright (C) Brandon Chuang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as5912_54x CPLD1/CPLD2 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as5912_54xk_cpld1, + as5912_54xk_cpld2 +}; + +struct as5912_54xk_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as5912_54xk_cpld_id[] = { + { "as5912_54xk_cpld1", as5912_54xk_cpld1 }, + { "as5912_54xk_cpld2", as5912_54xk_cpld2 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5912_54xk_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as5912_54xk_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_PRESENT_ATTR_ID(35), + TRANSCEIVER_PRESENT_ATTR_ID(36), + TRANSCEIVER_PRESENT_ATTR_ID(37), + TRANSCEIVER_PRESENT_ATTR_ID(38), + TRANSCEIVER_PRESENT_ATTR_ID(39), + TRANSCEIVER_PRESENT_ATTR_ID(40), + TRANSCEIVER_PRESENT_ATTR_ID(41), + TRANSCEIVER_PRESENT_ATTR_ID(42), + TRANSCEIVER_PRESENT_ATTR_ID(43), + TRANSCEIVER_PRESENT_ATTR_ID(44), + TRANSCEIVER_PRESENT_ATTR_ID(45), + TRANSCEIVER_PRESENT_ATTR_ID(46), + TRANSCEIVER_PRESENT_ATTR_ID(47), + TRANSCEIVER_PRESENT_ATTR_ID(48), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(1), + TRANSCEIVER_TXDISABLE_ATTR_ID(2), + TRANSCEIVER_TXDISABLE_ATTR_ID(3), + TRANSCEIVER_TXDISABLE_ATTR_ID(4), + TRANSCEIVER_TXDISABLE_ATTR_ID(5), + TRANSCEIVER_TXDISABLE_ATTR_ID(6), + TRANSCEIVER_TXDISABLE_ATTR_ID(7), + TRANSCEIVER_TXDISABLE_ATTR_ID(8), + TRANSCEIVER_TXDISABLE_ATTR_ID(9), + TRANSCEIVER_TXDISABLE_ATTR_ID(10), + TRANSCEIVER_TXDISABLE_ATTR_ID(11), + TRANSCEIVER_TXDISABLE_ATTR_ID(12), + TRANSCEIVER_TXDISABLE_ATTR_ID(13), + TRANSCEIVER_TXDISABLE_ATTR_ID(14), + TRANSCEIVER_TXDISABLE_ATTR_ID(15), + TRANSCEIVER_TXDISABLE_ATTR_ID(16), + TRANSCEIVER_TXDISABLE_ATTR_ID(17), + TRANSCEIVER_TXDISABLE_ATTR_ID(18), + TRANSCEIVER_TXDISABLE_ATTR_ID(19), + TRANSCEIVER_TXDISABLE_ATTR_ID(20), + TRANSCEIVER_TXDISABLE_ATTR_ID(21), + TRANSCEIVER_TXDISABLE_ATTR_ID(22), + TRANSCEIVER_TXDISABLE_ATTR_ID(23), + TRANSCEIVER_TXDISABLE_ATTR_ID(24), + TRANSCEIVER_TXDISABLE_ATTR_ID(25), + TRANSCEIVER_TXDISABLE_ATTR_ID(26), + TRANSCEIVER_TXDISABLE_ATTR_ID(27), + TRANSCEIVER_TXDISABLE_ATTR_ID(28), + TRANSCEIVER_TXDISABLE_ATTR_ID(29), + TRANSCEIVER_TXDISABLE_ATTR_ID(30), + TRANSCEIVER_TXDISABLE_ATTR_ID(31), + TRANSCEIVER_TXDISABLE_ATTR_ID(32), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(35), + TRANSCEIVER_TXDISABLE_ATTR_ID(36), + TRANSCEIVER_TXDISABLE_ATTR_ID(37), + TRANSCEIVER_TXDISABLE_ATTR_ID(38), + TRANSCEIVER_TXDISABLE_ATTR_ID(39), + TRANSCEIVER_TXDISABLE_ATTR_ID(40), + TRANSCEIVER_TXDISABLE_ATTR_ID(41), + TRANSCEIVER_TXDISABLE_ATTR_ID(42), + TRANSCEIVER_TXDISABLE_ATTR_ID(43), + TRANSCEIVER_TXDISABLE_ATTR_ID(44), + TRANSCEIVER_TXDISABLE_ATTR_ID(45), + TRANSCEIVER_TXDISABLE_ATTR_ID(46), + TRANSCEIVER_TXDISABLE_ATTR_ID(47), + TRANSCEIVER_TXDISABLE_ATTR_ID(48), + TRANSCEIVER_RXLOS_ATTR_ID(1), + TRANSCEIVER_RXLOS_ATTR_ID(2), + TRANSCEIVER_RXLOS_ATTR_ID(3), + TRANSCEIVER_RXLOS_ATTR_ID(4), + TRANSCEIVER_RXLOS_ATTR_ID(5), + TRANSCEIVER_RXLOS_ATTR_ID(6), + TRANSCEIVER_RXLOS_ATTR_ID(7), + TRANSCEIVER_RXLOS_ATTR_ID(8), + TRANSCEIVER_RXLOS_ATTR_ID(9), + TRANSCEIVER_RXLOS_ATTR_ID(10), + TRANSCEIVER_RXLOS_ATTR_ID(11), + TRANSCEIVER_RXLOS_ATTR_ID(12), + TRANSCEIVER_RXLOS_ATTR_ID(13), + TRANSCEIVER_RXLOS_ATTR_ID(14), + TRANSCEIVER_RXLOS_ATTR_ID(15), + TRANSCEIVER_RXLOS_ATTR_ID(16), + TRANSCEIVER_RXLOS_ATTR_ID(17), + TRANSCEIVER_RXLOS_ATTR_ID(18), + TRANSCEIVER_RXLOS_ATTR_ID(19), + TRANSCEIVER_RXLOS_ATTR_ID(20), + TRANSCEIVER_RXLOS_ATTR_ID(21), + TRANSCEIVER_RXLOS_ATTR_ID(22), + TRANSCEIVER_RXLOS_ATTR_ID(23), + TRANSCEIVER_RXLOS_ATTR_ID(24), + TRANSCEIVER_RXLOS_ATTR_ID(25), + TRANSCEIVER_RXLOS_ATTR_ID(26), + TRANSCEIVER_RXLOS_ATTR_ID(27), + TRANSCEIVER_RXLOS_ATTR_ID(28), + TRANSCEIVER_RXLOS_ATTR_ID(29), + TRANSCEIVER_RXLOS_ATTR_ID(30), + TRANSCEIVER_RXLOS_ATTR_ID(31), + TRANSCEIVER_RXLOS_ATTR_ID(32), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(35), + TRANSCEIVER_RXLOS_ATTR_ID(36), + TRANSCEIVER_RXLOS_ATTR_ID(37), + TRANSCEIVER_RXLOS_ATTR_ID(38), + TRANSCEIVER_RXLOS_ATTR_ID(39), + TRANSCEIVER_RXLOS_ATTR_ID(40), + TRANSCEIVER_RXLOS_ATTR_ID(41), + TRANSCEIVER_RXLOS_ATTR_ID(42), + TRANSCEIVER_RXLOS_ATTR_ID(43), + TRANSCEIVER_RXLOS_ATTR_ID(44), + TRANSCEIVER_RXLOS_ATTR_ID(45), + TRANSCEIVER_RXLOS_ATTR_ID(46), + TRANSCEIVER_RXLOS_ATTR_ID(47), + TRANSCEIVER_RXLOS_ATTR_ID(48), + TRANSCEIVER_TXFAULT_ATTR_ID(1), + TRANSCEIVER_TXFAULT_ATTR_ID(2), + TRANSCEIVER_TXFAULT_ATTR_ID(3), + TRANSCEIVER_TXFAULT_ATTR_ID(4), + TRANSCEIVER_TXFAULT_ATTR_ID(5), + TRANSCEIVER_TXFAULT_ATTR_ID(6), + TRANSCEIVER_TXFAULT_ATTR_ID(7), + TRANSCEIVER_TXFAULT_ATTR_ID(8), + TRANSCEIVER_TXFAULT_ATTR_ID(9), + TRANSCEIVER_TXFAULT_ATTR_ID(10), + TRANSCEIVER_TXFAULT_ATTR_ID(11), + TRANSCEIVER_TXFAULT_ATTR_ID(12), + TRANSCEIVER_TXFAULT_ATTR_ID(13), + TRANSCEIVER_TXFAULT_ATTR_ID(14), + TRANSCEIVER_TXFAULT_ATTR_ID(15), + TRANSCEIVER_TXFAULT_ATTR_ID(16), + TRANSCEIVER_TXFAULT_ATTR_ID(17), + TRANSCEIVER_TXFAULT_ATTR_ID(18), + TRANSCEIVER_TXFAULT_ATTR_ID(19), + TRANSCEIVER_TXFAULT_ATTR_ID(20), + TRANSCEIVER_TXFAULT_ATTR_ID(21), + TRANSCEIVER_TXFAULT_ATTR_ID(22), + TRANSCEIVER_TXFAULT_ATTR_ID(23), + TRANSCEIVER_TXFAULT_ATTR_ID(24), + TRANSCEIVER_TXFAULT_ATTR_ID(25), + TRANSCEIVER_TXFAULT_ATTR_ID(26), + TRANSCEIVER_TXFAULT_ATTR_ID(27), + TRANSCEIVER_TXFAULT_ATTR_ID(28), + TRANSCEIVER_TXFAULT_ATTR_ID(29), + TRANSCEIVER_TXFAULT_ATTR_ID(30), + TRANSCEIVER_TXFAULT_ATTR_ID(31), + TRANSCEIVER_TXFAULT_ATTR_ID(32), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(35), + TRANSCEIVER_TXFAULT_ATTR_ID(36), + TRANSCEIVER_TXFAULT_ATTR_ID(37), + TRANSCEIVER_TXFAULT_ATTR_ID(38), + TRANSCEIVER_TXFAULT_ATTR_ID(39), + TRANSCEIVER_TXFAULT_ATTR_ID(40), + TRANSCEIVER_TXFAULT_ATTR_ID(41), + TRANSCEIVER_TXFAULT_ATTR_ID(42), + TRANSCEIVER_TXFAULT_ATTR_ID(43), + TRANSCEIVER_TXFAULT_ATTR_ID(44), + TRANSCEIVER_TXFAULT_ATTR_ID(45), + TRANSCEIVER_TXFAULT_ATTR_ID(46), + TRANSCEIVER_TXFAULT_ATTR_ID(47), + TRANSCEIVER_TXFAULT_ATTR_ID(48), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as5912_54xk_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5912_54xk_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); + +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); + +static struct attribute *as5912_54xk_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_SFP_TRANSCEIVER_ATTR(1), + DECLARE_SFP_TRANSCEIVER_ATTR(2), + DECLARE_SFP_TRANSCEIVER_ATTR(3), + DECLARE_SFP_TRANSCEIVER_ATTR(4), + DECLARE_SFP_TRANSCEIVER_ATTR(5), + DECLARE_SFP_TRANSCEIVER_ATTR(6), + DECLARE_SFP_TRANSCEIVER_ATTR(7), + DECLARE_SFP_TRANSCEIVER_ATTR(8), + DECLARE_SFP_TRANSCEIVER_ATTR(9), + DECLARE_SFP_TRANSCEIVER_ATTR(10), + DECLARE_SFP_TRANSCEIVER_ATTR(11), + DECLARE_SFP_TRANSCEIVER_ATTR(12), + DECLARE_SFP_TRANSCEIVER_ATTR(13), + DECLARE_SFP_TRANSCEIVER_ATTR(14), + DECLARE_SFP_TRANSCEIVER_ATTR(15), + DECLARE_SFP_TRANSCEIVER_ATTR(16), + DECLARE_SFP_TRANSCEIVER_ATTR(17), + DECLARE_SFP_TRANSCEIVER_ATTR(18), + DECLARE_SFP_TRANSCEIVER_ATTR(19), + DECLARE_SFP_TRANSCEIVER_ATTR(20), + DECLARE_SFP_TRANSCEIVER_ATTR(21), + DECLARE_SFP_TRANSCEIVER_ATTR(22), + DECLARE_SFP_TRANSCEIVER_ATTR(23), + DECLARE_SFP_TRANSCEIVER_ATTR(24), + NULL +}; + +static const struct attribute_group as5912_54xk_cpld1_group = { + .attrs = as5912_54xk_cpld1_attributes, +}; + +static struct attribute *as5912_54xk_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_TRANSCEIVER_PRESENT_ATTR(33), + DECLARE_TRANSCEIVER_PRESENT_ATTR(34), + DECLARE_TRANSCEIVER_PRESENT_ATTR(35), + DECLARE_TRANSCEIVER_PRESENT_ATTR(36), + DECLARE_TRANSCEIVER_PRESENT_ATTR(37), + DECLARE_TRANSCEIVER_PRESENT_ATTR(38), + DECLARE_TRANSCEIVER_PRESENT_ATTR(39), + DECLARE_TRANSCEIVER_PRESENT_ATTR(40), + DECLARE_TRANSCEIVER_PRESENT_ATTR(41), + DECLARE_TRANSCEIVER_PRESENT_ATTR(42), + DECLARE_TRANSCEIVER_PRESENT_ATTR(43), + DECLARE_TRANSCEIVER_PRESENT_ATTR(44), + DECLARE_TRANSCEIVER_PRESENT_ATTR(45), + DECLARE_TRANSCEIVER_PRESENT_ATTR(46), + DECLARE_TRANSCEIVER_PRESENT_ATTR(47), + DECLARE_TRANSCEIVER_PRESENT_ATTR(48), + DECLARE_TRANSCEIVER_PRESENT_ATTR(49), + DECLARE_TRANSCEIVER_PRESENT_ATTR(50), + DECLARE_TRANSCEIVER_PRESENT_ATTR(51), + DECLARE_TRANSCEIVER_PRESENT_ATTR(52), + DECLARE_TRANSCEIVER_PRESENT_ATTR(53), + DECLARE_TRANSCEIVER_PRESENT_ATTR(54), + DECLARE_SFP_TRANSCEIVER_ATTR(25), + DECLARE_SFP_TRANSCEIVER_ATTR(26), + DECLARE_SFP_TRANSCEIVER_ATTR(27), + DECLARE_SFP_TRANSCEIVER_ATTR(28), + DECLARE_SFP_TRANSCEIVER_ATTR(29), + DECLARE_SFP_TRANSCEIVER_ATTR(30), + DECLARE_SFP_TRANSCEIVER_ATTR(31), + DECLARE_SFP_TRANSCEIVER_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + DECLARE_SFP_TRANSCEIVER_ATTR(35), + DECLARE_SFP_TRANSCEIVER_ATTR(36), + DECLARE_SFP_TRANSCEIVER_ATTR(37), + DECLARE_SFP_TRANSCEIVER_ATTR(38), + DECLARE_SFP_TRANSCEIVER_ATTR(39), + DECLARE_SFP_TRANSCEIVER_ATTR(40), + DECLARE_SFP_TRANSCEIVER_ATTR(41), + DECLARE_SFP_TRANSCEIVER_ATTR(42), + DECLARE_SFP_TRANSCEIVER_ATTR(43), + DECLARE_SFP_TRANSCEIVER_ATTR(44), + DECLARE_SFP_TRANSCEIVER_ATTR(45), + DECLARE_SFP_TRANSCEIVER_ATTR(46), + DECLARE_SFP_TRANSCEIVER_ATTR(47), + DECLARE_SFP_TRANSCEIVER_ATTR(48), + NULL +}; + +static const struct attribute_group as5912_54xk_cpld2_group = { + .attrs = as5912_54xk_cpld2_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status, num_regs = 0; + u8 values[4] = {0}; + u8 regs[] = {0x10, 0x11, 0x12, 0x52}; + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + num_regs = (data->type == as5912_54xk_cpld1) ? 3 : 4; + + for (i = 0; i < num_regs; i++) { + status = as5912_54xk_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + if (data->type == as5912_54xk_cpld1) { + status = sprintf(buf, "%.2x %.2x %.2x\n", + values[0], values[1], values[2]); + } + else { /* as5912_54xk_cpld2 */ + values[3] &= 0x3F; + status = sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + } + + return status; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[3] = {0}; + u8 regs[] = {0x30, 0x32, 0x34}; + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as5912_54xk_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 24 in order */ + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_33 ... MODULE_PRESENT_40: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_33); + break; + case MODULE_PRESENT_41 ... MODULE_PRESENT_48: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_41); + break; + case MODULE_PRESENT_49 ... MODULE_PRESENT_54: + reg = 0x52; + mask = 0x1 << (attr->index - MODULE_PRESENT_49); + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1); + break; + case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_9); + break; + case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_17); + break; + case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_25); + break; + case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_33); + break; + case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_41); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_8: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_1); + break; + case MODULE_RXLOS_9 ... MODULE_RXLOS_16: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_9); + break; + case MODULE_RXLOS_17 ... MODULE_RXLOS_24: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_17); + break; + case MODULE_RXLOS_25 ... MODULE_RXLOS_32: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_25); + break; + case MODULE_RXLOS_33 ... MODULE_RXLOS_40: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_33); + break; + case MODULE_RXLOS_41 ... MODULE_RXLOS_48: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_41); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as5912_54xk_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5912_54xk_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5912_54xk_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as5912_54xk_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as5912_54xk_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as5912_54xk_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5912_54xk_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as5912_54xk_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as5912_54xk_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as5912_54xk_cpld1: + group = &as5912_54xk_cpld1_group; + break; + case as5912_54xk_cpld2: + group = &as5912_54xk_cpld2_group; + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as5912_54xk_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as5912_54xk_cpld_remove(struct i2c_client *client) +{ + struct as5912_54xk_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as5912_54xk_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as5912_54xk_cpld1: + group = &as5912_54xk_cpld1_group; + break; + case as5912_54xk_cpld2: + group = &as5912_54xk_cpld2_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as5912_54xk_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as5912_54xk_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as5912_54xk_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5912_54xk_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5912_54xk_cpld_read); + +int as5912_54xk_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5912_54xk_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5912_54xk_cpld_write); + +static struct i2c_driver as5912_54xk_cpld_driver = { + .driver = { + .name = "as5912_54xk_cpld", + .owner = THIS_MODULE, + }, + .probe = as5912_54xk_cpld_probe, + .remove = as5912_54xk_cpld_remove, + .id_table = as5912_54xk_cpld_id, +}; + +static int __init as5912_54xk_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5912_54xk_cpld_driver); +} + +static void __exit as5912_54xk_cpld_exit(void) +{ + i2c_del_driver(&as5912_54xk_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as5912_54xk_cpld_init); +module_exit(as5912_54xk_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c index b81cef4d..f7b3ca43 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-leds.c @@ -38,8 +38,8 @@ #define DEBUG_PRINT(fmt, args...) #endif -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5912_54xk_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5912_54xk_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); struct accton_as5912_54xk_led_data { struct platform_device *pdev; @@ -157,12 +157,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as5912_54xk_led_read_value(u8 reg) { - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); + return as5912_54xk_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } static int accton_as5912_54xk_led_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); + return as5912_54xk_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } static void accton_as5912_54xk_led_update(void) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c index da4ea68b..964838a6 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-psu.c @@ -37,7 +37,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static int as5912_54xk_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5912_54xk_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned */ @@ -234,7 +234,7 @@ static struct as5912_54xk_psu_data *as5912_54xk_psu_update_device(struct device dev_dbg(&client->dev, "Starting as5912_54xk update\n"); /* Read psu status */ - status = accton_i2c_cpld_read(0x60, 0x2); + status = as5912_54xk_cpld_read(0x60, 0x2); if (status < 0) { dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c deleted file mode 100644 index 14771b1b..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/modules/builds/x86-64-accton-as5912-54xk-sfp.c +++ /dev/null @@ -1,1315 +0,0 @@ -/* - * SFP driver for accton as5912_54xk sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as5912_54xk_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 54 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 3 -#define I2C_RW_RETRY_INTERVAL 100 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) -#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 -#define SFF8472_10G_BASE_MASK 0xF0 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -/* Platform dependent +++ */ -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -/* Platform dependent --- */ - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - NULL -}; - -/* SFP ddm attributes for sysfs */ -static struct attribute *sfp_ddm_attributes[] = { - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as5912_54xk_sfp1, as5912_54xk_sfp2, as5912_54xk_sfp3, as5912_54xk_sfp4, as5912_54xk_sfp5, as5912_54xk_sfp6, as5912_54xk_sfp7, as5912_54xk_sfp8, -as5912_54xk_sfp9, as5912_54xk_sfp10, as5912_54xk_sfp11, as5912_54xk_sfp12, as5912_54xk_sfp13, as5912_54xk_sfp14, as5912_54xk_sfp15, as5912_54xk_sfp16, -as5912_54xk_sfp17, as5912_54xk_sfp18, as5912_54xk_sfp19, as5912_54xk_sfp20, as5912_54xk_sfp21, as5912_54xk_sfp22, as5912_54xk_sfp23, as5912_54xk_sfp24, -as5912_54xk_sfp25, as5912_54xk_sfp26, as5912_54xk_sfp27, as5912_54xk_sfp28, as5912_54xk_sfp29, as5912_54xk_sfp30, as5912_54xk_sfp31, as5912_54xk_sfp32, -as5912_54xk_sfp33, as5912_54xk_sfp34, as5912_54xk_sfp35, as5912_54xk_sfp36, as5912_54xk_sfp37, as5912_54xk_sfp38, as5912_54xk_sfp39, as5912_54xk_sfp40, -as5912_54xk_sfp41, as5912_54xk_sfp42, as5912_54xk_sfp43, as5912_54xk_sfp44, as5912_54xk_sfp45, as5912_54xk_sfp46, as5912_54xk_sfp47, as5912_54xk_sfp48, -as5912_54xk_sfp49, as5912_54xk_sfp50, as5912_54xk_sfp51, as5912_54xk_sfp52, as5912_54xk_sfp53, as5912_54xk_sfp54 -}; - -static const struct i2c_device_id sfp_device_id[] = { -{ "as5912_54xk_sfp1", as5912_54xk_sfp1 }, { "as5912_54xk_sfp2", as5912_54xk_sfp2 }, { "as5912_54xk_sfp3", as5912_54xk_sfp3 }, { "as5912_54xk_sfp4", as5912_54xk_sfp4 }, -{ "as5912_54xk_sfp5", as5912_54xk_sfp5 }, { "as5912_54xk_sfp6", as5912_54xk_sfp6 }, { "as5912_54xk_sfp7", as5912_54xk_sfp7 }, { "as5912_54xk_sfp8", as5912_54xk_sfp8 }, -{ "as5912_54xk_sfp9", as5912_54xk_sfp9 }, { "as5912_54xk_sfp10", as5912_54xk_sfp10 }, { "as5912_54xk_sfp11", as5912_54xk_sfp11 }, { "as5912_54xk_sfp12", as5912_54xk_sfp12 }, -{ "as5912_54xk_sfp13", as5912_54xk_sfp13 }, { "as5912_54xk_sfp14", as5912_54xk_sfp14 }, { "as5912_54xk_sfp15", as5912_54xk_sfp15 }, { "as5912_54xk_sfp16", as5912_54xk_sfp16 }, -{ "as5912_54xk_sfp17", as5912_54xk_sfp17 }, { "as5912_54xk_sfp18", as5912_54xk_sfp18 }, { "as5912_54xk_sfp19", as5912_54xk_sfp19 }, { "as5912_54xk_sfp20", as5912_54xk_sfp20 }, -{ "as5912_54xk_sfp21", as5912_54xk_sfp21 }, { "as5912_54xk_sfp22", as5912_54xk_sfp22 }, { "as5912_54xk_sfp23", as5912_54xk_sfp23 }, { "as5912_54xk_sfp24", as5912_54xk_sfp24 }, -{ "as5912_54xk_sfp25", as5912_54xk_sfp25 }, { "as5912_54xk_sfp26", as5912_54xk_sfp26 }, { "as5912_54xk_sfp27", as5912_54xk_sfp27 }, { "as5912_54xk_sfp28", as5912_54xk_sfp28 }, -{ "as5912_54xk_sfp29", as5912_54xk_sfp29 }, { "as5912_54xk_sfp30", as5912_54xk_sfp30 }, { "as5912_54xk_sfp31", as5912_54xk_sfp31 }, { "as5912_54xk_sfp32", as5912_54xk_sfp32 }, -{ "as5912_54xk_sfp33", as5912_54xk_sfp33 }, { "as5912_54xk_sfp34", as5912_54xk_sfp34 }, { "as5912_54xk_sfp35", as5912_54xk_sfp35 }, { "as5912_54xk_sfp36", as5912_54xk_sfp36 }, -{ "as5912_54xk_sfp37", as5912_54xk_sfp37 }, { "as5912_54xk_sfp38", as5912_54xk_sfp38 }, { "as5912_54xk_sfp39", as5912_54xk_sfp39 }, { "as5912_54xk_sfp40", as5912_54xk_sfp40 }, -{ "as5912_54xk_sfp41", as5912_54xk_sfp41 }, { "as5912_54xk_sfp42", as5912_54xk_sfp42 }, { "as5912_54xk_sfp43", as5912_54xk_sfp43 }, { "as5912_54xk_sfp44", as5912_54xk_sfp44 }, -{ "as5912_54xk_sfp45", as5912_54xk_sfp45 }, { "as5912_54xk_sfp46", as5912_54xk_sfp46 }, { "as5912_54xk_sfp47", as5912_54xk_sfp47 }, { "as5912_54xk_sfp48", as5912_54xk_sfp48 }, -{ "as5912_54xk_sfp49", as5912_54xk_sfp49 }, { "as5912_54xk_sfp50", as5912_54xk_sfp50 }, { "as5912_54xk_sfp51", as5912_54xk_sfp51 }, { "as5912_54xk_sfp52", as5912_54xk_sfp52 }, -{ "as5912_54xk_sfp53", as5912_54xk_sfp53 }, { "as5912_54xk_sfp54", as5912_54xk_sfp54 }, -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -/* - * list of valid port types - * note OOM_PORT_TYPE_NOT_PRESENT to indicate no - * module is present in this port - */ -typedef enum oom_driver_port_type_e { - OOM_DRIVER_PORT_TYPE_INVALID, - OOM_DRIVER_PORT_TYPE_NOT_PRESENT, - OOM_DRIVER_PORT_TYPE_SFP, - OOM_DRIVER_PORT_TYPE_SFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP, - OOM_DRIVER_PORT_TYPE_QSFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP28 -} oom_driver_port_type_t; - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[6]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss - 3 => device id - 4 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 5 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -}; - -struct sfp_ddm_data { - struct eeprom_data eeprom; -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - oom_driver_port_type_t port_type; - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct sfp_ddm_data *ddm; - struct qsfp_data *qsfp; - - struct i2c_client *client; -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - int i = 0, j = 0, status = -1; - u8 reg; - unsigned short cpld_addr; - struct sfp_port_data *data = i2c_get_clientdata(client); - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - data->present = 0; - - /* Read present status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) { - cpld_addr = I2C_ADDR_CPLD1 + i*2; - reg = 0x10+j; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); - data->present |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* Read present status of port 49-52(QSFP port) */ - cpld_addr = I2C_ADDR_CPLD2; - reg = 0x52; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - else { - data->present |= (u64)(status & 0x3F) << 48; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; - - if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { - return data; - } - - DEBUG_PRINT("Starting as5912_54xk sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->msa->valid = 0; - memset(data->msa->status, 0, sizeof(data->msa->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { - unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; - - status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); - goto exit; - } - - data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - data->msa->valid = 1; - data->msa->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_set_tx_disable(dev, da, buf, count); - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = I2C_ADDR_CPLD1; - cpld_reg = tx_disable_regs[data->port / 8]; - cpld_bit = 1 << (data->port % 8); - } - else { /* port 24 ~ 48 */ - cpld_addr = I2C_ADDR_CPLD2; - cpld_reg = tx_disable_regs[(data->port - 24) / 8]; - cpld_bit = 1 << (data->port % 8); - } - - /* Read current status */ - cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->msa->status[1] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->msa->status[1] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - mutex_unlock(&data->update_lock); - return count; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ -} - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[7] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *sfp_update_port_type(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 buf = 0; - int status; - - mutex_lock(&data->update_lock); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - if (buf != SFF8024_DEVICE_ID_SFP) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); - data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; - break; - } - case DRIVER_TYPE_QSFP: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); - switch (buf) { - case SFF8024_DEVICE_ID_QSFP: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; - break; - case SFF8024_DEVICE_ID_QSFP_PLUS: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - case SFF8024_DEVICE_ID_QSFP28: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - default: - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - break; - } - default: - break; - } - - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - if (!present) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_type(dev); - return sprintf(buf, "%d\n", data->port_type); -} - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - data->qsfp->status[1] = disable & 0xF; - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, - char *buf) -{ - int status; - char ddm; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (status == 0) { - /* port is not present */ - return -ENODEV; - } - - status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); - if (unlikely(status < 0)) { - return status; - } - - return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); -} - -/* Platform dependent +++ */ -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_show_tx_rx_status(dev, da, buf); - } - - data = sfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - if(attr->index == RX_LOS_ALL) { - int i = 0; - u8 values[6] = {0}; - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = (u8)(data->msa->status[2] >> (i * 8)); - } - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - return 0; - } - - val = !!(data->msa->status[index] & BIT_INDEX(data->port)); - return sprintf(buf, "%d\n", val); -} -/* Platform dependent --- */ -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -static ssize_t sfp_port_write(struct sfp_port_data *data, - 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(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} - - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_write(data, buf, off, count); -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_read(data, buf, off, count); -} - -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; - eeprom->size = EEPROM_SIZE; - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group sfp_ddm_group = { - .attrs = sfp_ddm_attributes, -}; - -static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_ddm_data **data) -{ - int status; - struct sfp_ddm_data *ddm; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); - if (!ddm) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = ddm; - dev_info(&client->dev, "sfp ddm '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); -exit_free: - kfree(ddm); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct sfp_port_data *data = NULL; - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (dev_id->driver_data >= as5912_54xk_sfp1 && dev_id->driver_data <= as5912_54xk_sfp48) { - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_MSA; - return sfp_msa_probe(client, dev_id, &data->msa); - } - else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_DDM; - return sfp_ddm_probe(client, dev_id, &data->ddm); - } - } - else { /* as5912_54xk_sfp49 ~ as5912_54xk_sfp54 */ - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_QSFP; - return qsfp_probe(client, dev_id, &data->qsfp); - } - } - - return -ENODEV; -} -/* Platform dependent --- */ - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_SFP_DDM: - return sfp_ddm_remove(client, data->ddm); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - - return 0; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5912_54xk_sfp driver"); -MODULE_LICENSE("GPL"); - -late_initcall(sfp_init); -module_exit(sfp_exit); - - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c index a24a5b96..51b5fbfc 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/onlp/builds/src/module/src/sfpi.c @@ -24,17 +24,21 @@ * ***********************************************************/ #include +#include #include -#include "platform_lib.h" - +#include "x86_64_accton_as5912_54xk_int.h" #include "x86_64_accton_as5912_54xk_log.h" -#define NUM_OF_SFP_PORT 54 -#define MAX_PORT_PATH 64 +#define PORT_BUS_INDEX(port) (port+26) -#define SFP_PORT_FORMAT "/sys/bus/i2c/devices/%d-0050/%s" -#define SFP_PORT_DOM_FORMAT "/sys/bus/i2c/devices/%d-0051/%s" -#define SFP_BUS_INDEX(port) (port+26) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD1 "/sys/bus/i2c/devices/4-0060/module_rx_los_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/5-0062/module_rx_los_all" /************************************************************ * @@ -55,8 +59,8 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) * Ports {0, 54} */ int p; - - for(p = 0; p < NUM_OF_SFP_PORT; p++) { + + for(p = 0; p < 54; p++) { AIM_BITMAP_SET(bmap, p); } @@ -72,7 +76,12 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - if (onlp_file_read_int(&present, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_is_present") < 0) { + int bus, addr; + + addr = (port < 24) ? 60 : 62; + bus = (addr == 60) ? 4 : 5; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -83,31 +92,45 @@ onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[7]; - char path[MAX_PORT_PATH] = {0}; + uint32_t bytes[7], *ptr = NULL; FILE* fp; + int addr; - sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_is_present_all"); - fp = fopen(path, "r"); + ptr = bytes; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5, - bytes+6 - ); - fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { - /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 60; addr <= 62; addr+=2) { + /* Read present status of port 0~53 */ + int count = 0; + char file[64] = {0}; + int bus = (addr == 60) ? 4 : 5; + + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + + if (addr == 60) { /* CPLD1 */ + count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + else { /* CPLD2 */ + count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + + ptr += count; } /* Mask out non-existant QSFP ports */ @@ -130,64 +153,44 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) -{ - int size = 0; - if(onlp_file_read(data, 256, &size, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { - if(size == 256) { - return ONLP_STATUS_OK; - } - } - - return ONLP_STATUS_E_INTERNAL; -} - -int -onlp_sfpi_dom_read(int port, uint8_t data[256]) -{ - int size = 0; - if(onlp_file_read(data, 256, &size, SFP_PORT_DOM_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { - if(size == 256) { - return ONLP_STATUS_OK; - } - } - - return ONLP_STATUS_E_INTERNAL; -} - int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[6]; - char path[MAX_PORT_PATH] = {0}; + uint32_t *ptr = bytes; FILE* fp; - sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_rx_los_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~23 */ + int addr, i = 0; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5 - ); - fclose(fp); - if(count != 6) { - AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 60; addr <= 62; addr+=2) { + if (addr == 60) { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r"); + } + else { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Convert to 64 bit integer in port order */ - int i = 0; + i = 0; uint64_t rx_los_all = 0 ; - for(i = 5; i >= 0; i--) { + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { rx_los_all <<= 8; rx_los_all |= bytes[i]; } @@ -201,16 +204,77 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + int size = 0; + memset(data, 0, 256); + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 4 : 5; + switch(control) { case ONLP_SFP_CONTROL_TX_DISABLE: { - if (onlp_file_write_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") != 0) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -233,12 +297,19 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 4 : 5; + switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_rx_los") < 0) { - AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -249,7 +320,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_fault") < 0) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -261,7 +332,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") < 0) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -278,7 +349,6 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) return rv; } - int onlp_sfpi_denit(void) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py index 9922d621..dfbb7551 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5912-54xk/platform-config/r0/src/python/x86_64_accton_as5912_54xk_r0/__init__.py @@ -8,9 +8,9 @@ class OnlPlatform_x86_64_accton_as5912_54xk_r0(OnlPlatformAccton, SYS_OBJECT_ID=".5912.54" def baseconfig(self): - self.insmod("accton_i2c_cpld") + self.insmod('optoe') self.insmod("ym2651y") - for m in [ "sfp", "psu", "fan", "leds" ]: + for m in [ "cpld", "psu", "fan", "leds" ]: self.insmod("x86-64-accton-as5912-54xk-%s" % m) ########### initialize I2C bus 0 ########### @@ -29,8 +29,8 @@ class OnlPlatform_x86_64_accton_as5912_54xk_r0(OnlPlatformAccton, ('lm75', 0x4b, 3), # initialize CPLDs - ('accton_i2c_cpld', 0x60, 4), - ('accton_i2c_cpld', 0x62, 5), + ('as5912_54xk_cpld1', 0x60, 4), + ('as5912_54xk_cpld2', 0x62, 5), ] ) @@ -69,12 +69,14 @@ class OnlPlatform_x86_64_accton_as5912_54xk_r0(OnlPlatformAccton, # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x50, port+25) - self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x51, port+25) + self.new_i2c_device('optoe2', 0x50, port+25) # initialize QSFP devices for port in range(49, 55): - self.new_i2c_device('as5912_54xk_sfp%d' % port, 0x50, port+25) + self.new_i2c_device('optoe1', 0x50, port+25) + + for port in range(1, 55): + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+25), shell=True) return True From ae59d5cf5cf8a3695d4a0541445f03cb115b57f3 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Tue, 20 Mar 2018 11:27:15 +0800 Subject: [PATCH 07/21] [as5812-54x] Add support for OOM --- .../builds/x86-64-accton-as5812-54x-cpld.c | 1089 +++++++++++++++-- .../builds/x86-64-accton-as5812-54x-fan.c | 10 +- .../builds/x86-64-accton-as5812-54x-leds.c | 8 +- .../builds/x86-64-accton-as5812-54x-psu.c | 17 +- .../builds/x86-64-accton-as5812-54x-sfp.c | 508 -------- .../onlp/builds/src/module/src/sfpi.c | 214 ++-- .../x86_64_accton_as5812_54x_r0/__init__.py | 21 +- 7 files changed, 1111 insertions(+), 756 deletions(-) delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-cpld.c index 14e1d860..5b9a5582 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-cpld.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-cpld.c @@ -33,31 +33,13 @@ #include #include #include -#include #include +#include +#include +#include -static struct dmi_system_id as5812_54x_dmi_table[] = { - { - .ident = "Accton AS5812-54X", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5812-54X"), - }, - }, - { - .ident = "Accton AS5812-54X", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS5812-54X"), - }, - }, -}; - -int platform_accton_as5812_54x(void) -{ - return dmi_check_system(as5812_54x_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as5812_54x); +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ #define NUM_OF_CPLD1_CHANS 0x0 #define NUM_OF_CPLD2_CHANS 0x18 @@ -81,10 +63,13 @@ enum cpld_mux_type { as5812_54x_cpld1 }; -struct accton_i2c_cpld_mux { +struct as5812_54x_cpld_data { enum cpld_mux_type type; struct i2c_adapter *virt_adaps[ACCTON_I2C_CPLD_MUX_MAX_NCHANS]; u8 last_chan; /* last register value */ + + struct device *hwmon_dev; + struct mutex update_lock; }; struct chip_desc { @@ -108,17 +93,833 @@ static const struct chip_desc chips[] = { } }; -static const struct i2c_device_id accton_i2c_cpld_mux_id[] = { +static const struct i2c_device_id as5812_54x_cpld_mux_id[] = { { "as5812_54x_cpld1", as5812_54x_cpld1 }, { "as5812_54x_cpld2", as5812_54x_cpld2 }, { "as5812_54x_cpld3", as5812_54x_cpld3 }, { } }; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_mux_id); +MODULE_DEVICE_TABLE(i2c, as5812_54x_cpld_mux_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as5812_54x_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_PRESENT_ATTR_ID(35), + TRANSCEIVER_PRESENT_ATTR_ID(36), + TRANSCEIVER_PRESENT_ATTR_ID(37), + TRANSCEIVER_PRESENT_ATTR_ID(38), + TRANSCEIVER_PRESENT_ATTR_ID(39), + TRANSCEIVER_PRESENT_ATTR_ID(40), + TRANSCEIVER_PRESENT_ATTR_ID(41), + TRANSCEIVER_PRESENT_ATTR_ID(42), + TRANSCEIVER_PRESENT_ATTR_ID(43), + TRANSCEIVER_PRESENT_ATTR_ID(44), + TRANSCEIVER_PRESENT_ATTR_ID(45), + TRANSCEIVER_PRESENT_ATTR_ID(46), + TRANSCEIVER_PRESENT_ATTR_ID(47), + TRANSCEIVER_PRESENT_ATTR_ID(48), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(1), + TRANSCEIVER_TXDISABLE_ATTR_ID(2), + TRANSCEIVER_TXDISABLE_ATTR_ID(3), + TRANSCEIVER_TXDISABLE_ATTR_ID(4), + TRANSCEIVER_TXDISABLE_ATTR_ID(5), + TRANSCEIVER_TXDISABLE_ATTR_ID(6), + TRANSCEIVER_TXDISABLE_ATTR_ID(7), + TRANSCEIVER_TXDISABLE_ATTR_ID(8), + TRANSCEIVER_TXDISABLE_ATTR_ID(9), + TRANSCEIVER_TXDISABLE_ATTR_ID(10), + TRANSCEIVER_TXDISABLE_ATTR_ID(11), + TRANSCEIVER_TXDISABLE_ATTR_ID(12), + TRANSCEIVER_TXDISABLE_ATTR_ID(13), + TRANSCEIVER_TXDISABLE_ATTR_ID(14), + TRANSCEIVER_TXDISABLE_ATTR_ID(15), + TRANSCEIVER_TXDISABLE_ATTR_ID(16), + TRANSCEIVER_TXDISABLE_ATTR_ID(17), + TRANSCEIVER_TXDISABLE_ATTR_ID(18), + TRANSCEIVER_TXDISABLE_ATTR_ID(19), + TRANSCEIVER_TXDISABLE_ATTR_ID(20), + TRANSCEIVER_TXDISABLE_ATTR_ID(21), + TRANSCEIVER_TXDISABLE_ATTR_ID(22), + TRANSCEIVER_TXDISABLE_ATTR_ID(23), + TRANSCEIVER_TXDISABLE_ATTR_ID(24), + TRANSCEIVER_TXDISABLE_ATTR_ID(25), + TRANSCEIVER_TXDISABLE_ATTR_ID(26), + TRANSCEIVER_TXDISABLE_ATTR_ID(27), + TRANSCEIVER_TXDISABLE_ATTR_ID(28), + TRANSCEIVER_TXDISABLE_ATTR_ID(29), + TRANSCEIVER_TXDISABLE_ATTR_ID(30), + TRANSCEIVER_TXDISABLE_ATTR_ID(31), + TRANSCEIVER_TXDISABLE_ATTR_ID(32), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(35), + TRANSCEIVER_TXDISABLE_ATTR_ID(36), + TRANSCEIVER_TXDISABLE_ATTR_ID(37), + TRANSCEIVER_TXDISABLE_ATTR_ID(38), + TRANSCEIVER_TXDISABLE_ATTR_ID(39), + TRANSCEIVER_TXDISABLE_ATTR_ID(40), + TRANSCEIVER_TXDISABLE_ATTR_ID(41), + TRANSCEIVER_TXDISABLE_ATTR_ID(42), + TRANSCEIVER_TXDISABLE_ATTR_ID(43), + TRANSCEIVER_TXDISABLE_ATTR_ID(44), + TRANSCEIVER_TXDISABLE_ATTR_ID(45), + TRANSCEIVER_TXDISABLE_ATTR_ID(46), + TRANSCEIVER_TXDISABLE_ATTR_ID(47), + TRANSCEIVER_TXDISABLE_ATTR_ID(48), + TRANSCEIVER_RXLOS_ATTR_ID(1), + TRANSCEIVER_RXLOS_ATTR_ID(2), + TRANSCEIVER_RXLOS_ATTR_ID(3), + TRANSCEIVER_RXLOS_ATTR_ID(4), + TRANSCEIVER_RXLOS_ATTR_ID(5), + TRANSCEIVER_RXLOS_ATTR_ID(6), + TRANSCEIVER_RXLOS_ATTR_ID(7), + TRANSCEIVER_RXLOS_ATTR_ID(8), + TRANSCEIVER_RXLOS_ATTR_ID(9), + TRANSCEIVER_RXLOS_ATTR_ID(10), + TRANSCEIVER_RXLOS_ATTR_ID(11), + TRANSCEIVER_RXLOS_ATTR_ID(12), + TRANSCEIVER_RXLOS_ATTR_ID(13), + TRANSCEIVER_RXLOS_ATTR_ID(14), + TRANSCEIVER_RXLOS_ATTR_ID(15), + TRANSCEIVER_RXLOS_ATTR_ID(16), + TRANSCEIVER_RXLOS_ATTR_ID(17), + TRANSCEIVER_RXLOS_ATTR_ID(18), + TRANSCEIVER_RXLOS_ATTR_ID(19), + TRANSCEIVER_RXLOS_ATTR_ID(20), + TRANSCEIVER_RXLOS_ATTR_ID(21), + TRANSCEIVER_RXLOS_ATTR_ID(22), + TRANSCEIVER_RXLOS_ATTR_ID(23), + TRANSCEIVER_RXLOS_ATTR_ID(24), + TRANSCEIVER_RXLOS_ATTR_ID(25), + TRANSCEIVER_RXLOS_ATTR_ID(26), + TRANSCEIVER_RXLOS_ATTR_ID(27), + TRANSCEIVER_RXLOS_ATTR_ID(28), + TRANSCEIVER_RXLOS_ATTR_ID(29), + TRANSCEIVER_RXLOS_ATTR_ID(30), + TRANSCEIVER_RXLOS_ATTR_ID(31), + TRANSCEIVER_RXLOS_ATTR_ID(32), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(35), + TRANSCEIVER_RXLOS_ATTR_ID(36), + TRANSCEIVER_RXLOS_ATTR_ID(37), + TRANSCEIVER_RXLOS_ATTR_ID(38), + TRANSCEIVER_RXLOS_ATTR_ID(39), + TRANSCEIVER_RXLOS_ATTR_ID(40), + TRANSCEIVER_RXLOS_ATTR_ID(41), + TRANSCEIVER_RXLOS_ATTR_ID(42), + TRANSCEIVER_RXLOS_ATTR_ID(43), + TRANSCEIVER_RXLOS_ATTR_ID(44), + TRANSCEIVER_RXLOS_ATTR_ID(45), + TRANSCEIVER_RXLOS_ATTR_ID(46), + TRANSCEIVER_RXLOS_ATTR_ID(47), + TRANSCEIVER_RXLOS_ATTR_ID(48), + TRANSCEIVER_TXFAULT_ATTR_ID(1), + TRANSCEIVER_TXFAULT_ATTR_ID(2), + TRANSCEIVER_TXFAULT_ATTR_ID(3), + TRANSCEIVER_TXFAULT_ATTR_ID(4), + TRANSCEIVER_TXFAULT_ATTR_ID(5), + TRANSCEIVER_TXFAULT_ATTR_ID(6), + TRANSCEIVER_TXFAULT_ATTR_ID(7), + TRANSCEIVER_TXFAULT_ATTR_ID(8), + TRANSCEIVER_TXFAULT_ATTR_ID(9), + TRANSCEIVER_TXFAULT_ATTR_ID(10), + TRANSCEIVER_TXFAULT_ATTR_ID(11), + TRANSCEIVER_TXFAULT_ATTR_ID(12), + TRANSCEIVER_TXFAULT_ATTR_ID(13), + TRANSCEIVER_TXFAULT_ATTR_ID(14), + TRANSCEIVER_TXFAULT_ATTR_ID(15), + TRANSCEIVER_TXFAULT_ATTR_ID(16), + TRANSCEIVER_TXFAULT_ATTR_ID(17), + TRANSCEIVER_TXFAULT_ATTR_ID(18), + TRANSCEIVER_TXFAULT_ATTR_ID(19), + TRANSCEIVER_TXFAULT_ATTR_ID(20), + TRANSCEIVER_TXFAULT_ATTR_ID(21), + TRANSCEIVER_TXFAULT_ATTR_ID(22), + TRANSCEIVER_TXFAULT_ATTR_ID(23), + TRANSCEIVER_TXFAULT_ATTR_ID(24), + TRANSCEIVER_TXFAULT_ATTR_ID(25), + TRANSCEIVER_TXFAULT_ATTR_ID(26), + TRANSCEIVER_TXFAULT_ATTR_ID(27), + TRANSCEIVER_TXFAULT_ATTR_ID(28), + TRANSCEIVER_TXFAULT_ATTR_ID(29), + TRANSCEIVER_TXFAULT_ATTR_ID(30), + TRANSCEIVER_TXFAULT_ATTR_ID(31), + TRANSCEIVER_TXFAULT_ATTR_ID(32), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(35), + TRANSCEIVER_TXFAULT_ATTR_ID(36), + TRANSCEIVER_TXFAULT_ATTR_ID(37), + TRANSCEIVER_TXFAULT_ATTR_ID(38), + TRANSCEIVER_TXFAULT_ATTR_ID(39), + TRANSCEIVER_TXFAULT_ATTR_ID(40), + TRANSCEIVER_TXFAULT_ATTR_ID(41), + TRANSCEIVER_TXFAULT_ATTR_ID(42), + TRANSCEIVER_TXFAULT_ATTR_ID(43), + TRANSCEIVER_TXFAULT_ATTR_ID(44), + TRANSCEIVER_TXFAULT_ATTR_ID(45), + TRANSCEIVER_TXFAULT_ATTR_ID(46), + TRANSCEIVER_TXFAULT_ATTR_ID(47), + TRANSCEIVER_TXFAULT_ATTR_ID(48), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as5812_54x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5812_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); + +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); + +static struct attribute *as5812_54x_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as5812_54x_cpld1_group = { + .attrs = as5812_54x_cpld1_attributes, +}; + +static struct attribute *as5812_54x_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_SFP_TRANSCEIVER_ATTR(1), + DECLARE_SFP_TRANSCEIVER_ATTR(2), + DECLARE_SFP_TRANSCEIVER_ATTR(3), + DECLARE_SFP_TRANSCEIVER_ATTR(4), + DECLARE_SFP_TRANSCEIVER_ATTR(5), + DECLARE_SFP_TRANSCEIVER_ATTR(6), + DECLARE_SFP_TRANSCEIVER_ATTR(7), + DECLARE_SFP_TRANSCEIVER_ATTR(8), + DECLARE_SFP_TRANSCEIVER_ATTR(9), + DECLARE_SFP_TRANSCEIVER_ATTR(10), + DECLARE_SFP_TRANSCEIVER_ATTR(11), + DECLARE_SFP_TRANSCEIVER_ATTR(12), + DECLARE_SFP_TRANSCEIVER_ATTR(13), + DECLARE_SFP_TRANSCEIVER_ATTR(14), + DECLARE_SFP_TRANSCEIVER_ATTR(15), + DECLARE_SFP_TRANSCEIVER_ATTR(16), + DECLARE_SFP_TRANSCEIVER_ATTR(17), + DECLARE_SFP_TRANSCEIVER_ATTR(18), + DECLARE_SFP_TRANSCEIVER_ATTR(19), + DECLARE_SFP_TRANSCEIVER_ATTR(20), + DECLARE_SFP_TRANSCEIVER_ATTR(21), + DECLARE_SFP_TRANSCEIVER_ATTR(22), + DECLARE_SFP_TRANSCEIVER_ATTR(23), + DECLARE_SFP_TRANSCEIVER_ATTR(24), + NULL +}; + +static const struct attribute_group as5812_54x_cpld2_group = { + .attrs = as5812_54x_cpld2_attributes, +}; + +static struct attribute *as5812_54x_cpld3_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_TRANSCEIVER_PRESENT_ATTR(33), + DECLARE_TRANSCEIVER_PRESENT_ATTR(34), + DECLARE_TRANSCEIVER_PRESENT_ATTR(35), + DECLARE_TRANSCEIVER_PRESENT_ATTR(36), + DECLARE_TRANSCEIVER_PRESENT_ATTR(37), + DECLARE_TRANSCEIVER_PRESENT_ATTR(38), + DECLARE_TRANSCEIVER_PRESENT_ATTR(39), + DECLARE_TRANSCEIVER_PRESENT_ATTR(40), + DECLARE_TRANSCEIVER_PRESENT_ATTR(41), + DECLARE_TRANSCEIVER_PRESENT_ATTR(42), + DECLARE_TRANSCEIVER_PRESENT_ATTR(43), + DECLARE_TRANSCEIVER_PRESENT_ATTR(44), + DECLARE_TRANSCEIVER_PRESENT_ATTR(45), + DECLARE_TRANSCEIVER_PRESENT_ATTR(46), + DECLARE_TRANSCEIVER_PRESENT_ATTR(47), + DECLARE_TRANSCEIVER_PRESENT_ATTR(48), + DECLARE_TRANSCEIVER_PRESENT_ATTR(49), + DECLARE_TRANSCEIVER_PRESENT_ATTR(50), + DECLARE_TRANSCEIVER_PRESENT_ATTR(51), + DECLARE_TRANSCEIVER_PRESENT_ATTR(52), + DECLARE_TRANSCEIVER_PRESENT_ATTR(53), + DECLARE_TRANSCEIVER_PRESENT_ATTR(54), + DECLARE_SFP_TRANSCEIVER_ATTR(25), + DECLARE_SFP_TRANSCEIVER_ATTR(26), + DECLARE_SFP_TRANSCEIVER_ATTR(27), + DECLARE_SFP_TRANSCEIVER_ATTR(28), + DECLARE_SFP_TRANSCEIVER_ATTR(29), + DECLARE_SFP_TRANSCEIVER_ATTR(30), + DECLARE_SFP_TRANSCEIVER_ATTR(31), + DECLARE_SFP_TRANSCEIVER_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + DECLARE_SFP_TRANSCEIVER_ATTR(35), + DECLARE_SFP_TRANSCEIVER_ATTR(36), + DECLARE_SFP_TRANSCEIVER_ATTR(37), + DECLARE_SFP_TRANSCEIVER_ATTR(38), + DECLARE_SFP_TRANSCEIVER_ATTR(39), + DECLARE_SFP_TRANSCEIVER_ATTR(40), + DECLARE_SFP_TRANSCEIVER_ATTR(41), + DECLARE_SFP_TRANSCEIVER_ATTR(42), + DECLARE_SFP_TRANSCEIVER_ATTR(43), + DECLARE_SFP_TRANSCEIVER_ATTR(44), + DECLARE_SFP_TRANSCEIVER_ATTR(45), + DECLARE_SFP_TRANSCEIVER_ATTR(46), + DECLARE_SFP_TRANSCEIVER_ATTR(47), + DECLARE_SFP_TRANSCEIVER_ATTR(48), + NULL +}; + +static const struct attribute_group as5812_54x_cpld3_group = { + .attrs = as5812_54x_cpld3_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status, num_regs = 0; + u8 values[4] = {0}; + u8 regs[] = {0x6, 0x7, 0x8, 0x14}; + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + num_regs = (data->type == as5812_54x_cpld2) ? 3 : 4; + + for (i = 0; i < num_regs; i++) { + status = as5812_54x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 54 in order */ + if (data->type == as5812_54x_cpld2) { + status = sprintf(buf, "%.2x %.2x %.2x\n", + values[0], values[1], values[2]); + } + else { /* as5812_54x_cpld3 */ + values[3] &= 0x3F; + status = sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + } + + return status; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[3] = {0}; + u8 regs[] = {0xF, 0x10, 0x11}; + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as5812_54x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 24 in order */ + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x6; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x7; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x8; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x6; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_33 ... MODULE_PRESENT_40: + reg = 0x7; + mask = 0x1 << (attr->index - MODULE_PRESENT_33); + break; + case MODULE_PRESENT_41 ... MODULE_PRESENT_48: + reg = 0x8; + mask = 0x1 << (attr->index - MODULE_PRESENT_41); + break; + case MODULE_PRESENT_49: + reg = 0x14; + mask = 0x1; + break; + case MODULE_PRESENT_50: + reg = 0x14; + mask = 0x4; + break; + case MODULE_PRESENT_51: + reg = 0x14; + mask = 0x10; + break; + case MODULE_PRESENT_52: + reg = 0x14; + mask = 0x2; + break; + case MODULE_PRESENT_53: + reg = 0x14; + mask = 0x8; + break; + case MODULE_PRESENT_54: + reg = 0x14; + mask = 0x20; + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: + reg = 0x9; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1); + break; + case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_TXFAULT_9); + break; + case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXFAULT_17); + break; + case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: + reg = 0x9; + mask = 0x1 << (attr->index - MODULE_TXFAULT_25); + break; + case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_TXFAULT_33); + break; + case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXFAULT_41); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_8: + reg = 0xF; + mask = 0x1 << (attr->index - MODULE_RXLOS_1); + break; + case MODULE_RXLOS_9 ... MODULE_RXLOS_16: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_RXLOS_9); + break; + case MODULE_RXLOS_17 ... MODULE_RXLOS_24: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_RXLOS_17); + break; + case MODULE_RXLOS_25 ... MODULE_RXLOS_32: + reg = 0xF; + mask = 0x1 << (attr->index - MODULE_RXLOS_25); + break; + case MODULE_RXLOS_33 ... MODULE_RXLOS_40: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_RXLOS_33); + break; + case MODULE_RXLOS_41 ... MODULE_RXLOS_48: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_RXLOS_41); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as5812_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5812_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5812_54x_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as5812_54x_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} /* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() for this as they will try to lock adapter a second time */ -static int accton_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, +static int as5812_54x_cpld_mux_reg_write(struct i2c_adapter *adap, struct i2c_client *client, u8 val) { unsigned long orig_jiffies; @@ -149,35 +950,35 @@ static int accton_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, return res; } -static int accton_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, +static int as5812_54x_cpld_mux_select_chan(struct i2c_adapter *adap, void *client, u32 chan) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); u8 regval; int ret = 0; regval = chan; /* Only select the channel if its different from the last channel */ if (data->last_chan != regval) { - ret = accton_i2c_cpld_mux_reg_write(adap, client, regval); + ret = as5812_54x_cpld_mux_reg_write(adap, client, regval); data->last_chan = regval; } return ret; } -static int accton_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, +static int as5812_54x_cpld_mux_deselect_mux(struct i2c_adapter *adap, void *client, u32 chan) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); /* Deselect active channel */ data->last_chan = chips[data->type].deselectChan; - return accton_i2c_cpld_mux_reg_write(adap, client, data->last_chan); + return as5812_54x_cpld_mux_reg_write(adap, client, data->last_chan); } -static void accton_i2c_cpld_add_client(struct i2c_client *client) +static void as5812_54x_cpld_add_client(struct i2c_client *client) { struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); @@ -193,7 +994,7 @@ static void accton_i2c_cpld_add_client(struct i2c_client *client) mutex_unlock(&list_lock); } -static void accton_i2c_cpld_remove_client(struct i2c_client *client) +static void as5812_54x_cpld_remove_client(struct i2c_client *client) { struct list_head *list_node = NULL; struct cpld_client_node *cpld_node = NULL; @@ -219,107 +1020,178 @@ static void accton_i2c_cpld_remove_client(struct i2c_client *client) mutex_unlock(&list_lock); } -static ssize_t show_cpld_version(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) { - u8 reg = 0x1; - struct i2c_client *client; - int len; + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); - client = to_i2c_client(dev); - len = sprintf(buf, "%d", i2c_smbus_read_byte_data(client, reg)); - - return len; + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); } -static struct device_attribute ver = __ATTR(version, 0600, show_cpld_version, NULL); - /* * I2C init/probing/exit functions */ -static int accton_i2c_cpld_mux_probe(struct i2c_client *client, +static int as5812_54x_cpld_mux_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); int chan=0; - struct accton_i2c_cpld_mux *data; + struct as5812_54x_cpld_data *data; int ret = -ENODEV; + const struct attribute_group *group = NULL; if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - goto err; + goto exit; - data = kzalloc(sizeof(struct accton_i2c_cpld_mux), GFP_KERNEL); + data = kzalloc(sizeof(struct as5812_54x_cpld_data), GFP_KERNEL); if (!data) { ret = -ENOMEM; - goto err; + goto exit; } i2c_set_clientdata(client, data); - + mutex_init(&data->update_lock); data->type = id->driver_data; if (data->type == as5812_54x_cpld2 || data->type == as5812_54x_cpld3) { data->last_chan = chips[data->type].deselectChan; /* force the first selection */ - /* Now create an adapter for each channel */ - for (chan = 0; chan < chips[data->type].nchans; chan++) { - data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &client->dev, client, 0, chan, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) - I2C_CLASS_HWMON | I2C_CLASS_SPD, -#endif - accton_i2c_cpld_mux_select_chan, - accton_i2c_cpld_mux_deselect_mux); + /* Now create an adapter for each channel */ + for (chan = 0; chan < chips[data->type].nchans; chan++) { + data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &client->dev, client, 0, chan, 0, + as5812_54x_cpld_mux_select_chan, + as5812_54x_cpld_mux_deselect_mux); - if (data->virt_adaps[chan] == NULL) { - ret = -ENODEV; - dev_err(&client->dev, "failed to register multiplexed adapter %d\n", chan); - goto virt_reg_failed; + if (data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + dev_err(&client->dev, "failed to register multiplexed adapter %d\n", chan); + goto exit_mux_register; + } + } + + dev_info(&client->dev, "registered %d multiplexed busses for I2C mux %s\n", + chan, client->name); + } + + /* Register sysfs hooks */ + switch (data->type) { + case as5812_54x_cpld1: + group = &as5812_54x_cpld1_group; + break; + case as5812_54x_cpld2: + group = &as5812_54x_cpld2_group; + break; + case as5812_54x_cpld3: + group = &as5812_54x_cpld3_group; + break; + default: + break; + } + + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_mux_register; } } - dev_info(&client->dev, "registered %d multiplexed busses for I2C mux %s\n", - chan, client->name); - } - - accton_i2c_cpld_add_client(client); - - ret = sysfs_create_file(&client->dev.kobj, &ver.attr); - if (ret) - goto virt_reg_failed; + as5812_54x_cpld_add_client(client); return 0; -virt_reg_failed: +exit_mux_register: for (chan--; chan >= 0; chan--) { i2c_del_mux_adapter(data->virt_adaps[chan]); } - - kfree(data); -err: + kfree(data); +exit: return ret; } -static int accton_i2c_cpld_mux_remove(struct i2c_client *client) +static int as5812_54x_cpld_mux_remove(struct i2c_client *client) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); + struct as5812_54x_cpld_data *data = i2c_get_clientdata(client); const struct chip_desc *chip = &chips[data->type]; int chan; + const struct attribute_group *group = NULL; - sysfs_remove_file(&client->dev.kobj, &ver.attr); + as5812_54x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as5812_54x_cpld1: + group = &as5812_54x_cpld1_group; + break; + case as5812_54x_cpld2: + group = &as5812_54x_cpld2_group; + break; + case as5812_54x_cpld3: + group = &as5812_54x_cpld3_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } for (chan = 0; chan < chip->nchans; ++chan) { - if (data->virt_adaps[chan]) { - i2c_del_mux_adapter(data->virt_adaps[chan]); - data->virt_adaps[chan] = NULL; - } + if (data->virt_adaps[chan]) { + i2c_del_mux_adapter(data->virt_adaps[chan]); + data->virt_adaps[chan] = NULL; + } } kfree(data); - accton_i2c_cpld_remove_client(client); return 0; } -int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg) +static int as5812_54x_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as5812_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as5812_54x_cpld_read(unsigned short cpld_addr, u8 reg) { struct list_head *list_node = NULL; struct cpld_client_node *cpld_node = NULL; @@ -329,21 +1201,21 @@ int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg) list_for_each(list_node, &cpld_client_list) { - cpld_node = list_entry(list_node, struct cpld_client_node, list); + cpld_node = list_entry(list_node, struct cpld_client_node, list); - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; - } + if (cpld_node->client->addr == cpld_addr) { + ret = as5812_54x_cpld_read_internal(cpld_node->client, reg); + break; + } } mutex_unlock(&list_lock); return ret; } -EXPORT_SYMBOL(as5812_54x_i2c_cpld_read); +EXPORT_SYMBOL(as5812_54x_cpld_read); -int as5812_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +int as5812_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) { struct list_head *list_node = NULL; struct cpld_client_node *cpld_node = NULL; @@ -353,44 +1225,45 @@ int as5812_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) list_for_each(list_node, &cpld_client_list) { - cpld_node = list_entry(list_node, struct cpld_client_node, list); + cpld_node = list_entry(list_node, struct cpld_client_node, list); - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } + if (cpld_node->client->addr == cpld_addr) { + ret = as5812_54x_cpld_write_internal(cpld_node->client, reg, value); + break; + } } mutex_unlock(&list_lock); return ret; } -EXPORT_SYMBOL(as5812_54x_i2c_cpld_write); +EXPORT_SYMBOL(as5812_54x_cpld_write); -static struct i2c_driver accton_i2c_cpld_mux_driver = { +static struct i2c_driver as5812_54x_cpld_mux_driver = { .driver = { .name = "as5812_54x_cpld", .owner = THIS_MODULE, }, - .probe = accton_i2c_cpld_mux_probe, - .remove = accton_i2c_cpld_mux_remove, - .id_table = accton_i2c_cpld_mux_id, + .probe = as5812_54x_cpld_mux_probe, + .remove = as5812_54x_cpld_mux_remove, + .id_table = as5812_54x_cpld_mux_id, }; -static int __init accton_i2c_cpld_mux_init(void) +static int __init as5812_54x_cpld_mux_init(void) { mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_mux_driver); + return i2c_add_driver(&as5812_54x_cpld_mux_driver); } -static void __exit accton_i2c_cpld_mux_exit(void) +static void __exit as5812_54x_cpld_mux_exit(void) { - i2c_del_driver(&accton_i2c_cpld_mux_driver); + i2c_del_driver(&as5812_54x_cpld_mux_driver); } MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("Accton I2C CPLD mux driver"); MODULE_LICENSE("GPL"); -module_init(accton_i2c_cpld_mux_init); -module_exit(accton_i2c_cpld_mux_exit); +module_init(as5812_54x_cpld_mux_init); +module_exit(as5812_54x_cpld_mux_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c index 4c3cdeab..2521a469 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-fan.c @@ -131,8 +131,8 @@ static ssize_t fan_set_duty_cycle(struct device *dev, static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -extern int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as5812_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5812_54x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5812_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); /*******************/ @@ -258,12 +258,12 @@ static const struct attribute_group accton_as5812_54x_fan_group = { static int accton_as5812_54x_fan_read_value(u8 reg) { - return as5812_54x_i2c_cpld_read(0x60, reg); + return as5812_54x_cpld_read(0x60, reg); } static int accton_as5812_54x_fan_write_value(u8 reg, u8 value) { - return as5812_54x_i2c_cpld_write(0x60, reg, value); + return as5812_54x_cpld_write(0x60, reg, value); } static void accton_as5812_54x_fan_update_device(struct device *dev) @@ -393,7 +393,7 @@ static struct platform_driver accton_as5812_54x_fan_driver = { static int __init accton_as5812_54x_fan_init(void) { int ret; - + ret = platform_driver_register(&accton_as5812_54x_fan_driver); if (ret < 0) { goto exit; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c index f196f22c..0b8e46c4 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-leds.c @@ -29,8 +29,8 @@ #include #include -extern int as5812_54x_i2c_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as5812_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5812_54x_cpld_read (unsigned short cpld_addr, u8 reg); +extern int as5812_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); extern void led_classdev_unregister(struct led_classdev *led_cdev); extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); @@ -220,12 +220,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as5812_54x_led_read_value(u8 reg) { - return as5812_54x_i2c_cpld_read(0x60, reg); + return as5812_54x_cpld_read(0x60, reg); } static int accton_as5812_54x_led_write_value(u8 reg, u8 value) { - return as5812_54x_i2c_cpld_write(0x60, reg, value); + return as5812_54x_cpld_write(0x60, reg, value); } static void accton_as5812_54x_led_update(void) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c index 2703897f..9d52e544 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-psu.c @@ -44,7 +44,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_serial_number(struct device *dev, struct device_attribute *da,char *buf); static int as5812_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5812_54x_cpld_read(unsigned short cpld_addr, u8 reg); static int as5812_54x_psu_model_name_get(struct device *dev , int get_serial); /* Addresses scanned @@ -406,7 +406,7 @@ static struct as5812_54x_psu_data *as5812_54x_psu_update_device(struct device *d /* Read psu status */ - status = as5812_54x_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); + status = as5812_54x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); if (status < 0) { dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); @@ -426,20 +426,9 @@ exit: return data; } -static int __init as5812_54x_psu_init(void) -{ - return i2c_add_driver(&as5812_54x_psu_driver); -} - -static void __exit as5812_54x_psu_exit(void) -{ - i2c_del_driver(&as5812_54x_psu_driver); -} +module_i2c_driver(as5812_54x_psu_driver); MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("accton as5812_54x_psu driver"); MODULE_LICENSE("GPL"); -module_init(as5812_54x_psu_init); -module_exit(as5812_54x_psu_exit); - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-sfp.c deleted file mode 100644 index 44727e22..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/modules/builds/x86-64-accton-as5812-54x-sfp.c +++ /dev/null @@ -1,508 +0,0 @@ -/* - * An hwmon driver for accton as5812_54x sfp - * - * Copyright (C) 2015 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NUM_OF_SFP_PORT 54 -#define BIT_INDEX(i) (1ULL << (i)) - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as5812_54x_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u64 status[4]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => is_present - 1 => tx_fail - 2 => tx_disable - 3 => rx_loss */ -}; - -/* The table maps active port to cpld port. - * Array index 0 is for active port 1, - * index 1 for active port 2, and so on. - * The array content implies cpld port index. - */ -static const u8 cpld_to_front_port_table[] = -{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, - 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, - 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, - 49, 52, 50, 53, 51, 54}; - -#define CPLD_PORT_TO_FRONT_PORT(port) (cpld_to_front_port_table[port]) - -static struct as5812_54x_sfp_data *as5812_54x_sfp_update_device(struct device *dev, int update_eeprom); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count); -extern int as5812_54x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as5812_54x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as5812_54x_sfp_sysfs_attributes { - SFP_IS_PRESENT, - SFP_TX_FAULT, - SFP_TX_DISABLE, - SFP_RX_LOSS, - SFP_PORT_NUMBER, - SFP_EEPROM, - SFP_RX_LOS_ALL, - SFP_IS_PRESENT_ALL, -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_status, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, show_status, NULL, SFP_TX_FAULT); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, show_status, set_tx_disable, SFP_TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_rx_loss, S_IRUGO, show_status,NULL, SFP_RX_LOSS); -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, show_status,NULL, SFP_RX_LOS_ALL); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_status,NULL, SFP_IS_PRESENT_ALL); - -static struct attribute *as5812_54x_sfp_attributes[] = { - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_loss.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54x_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as5812_54x_sfp_data *data; - u8 val; - int values[7]; - - /* Error-check the CPLD read results. */ -#define VALIDATED_READ(_buf, _rv, _read_expr, _invert) \ - do { \ - _rv = (_read_expr); \ - if(_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if(_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ - } while(0) - - if(attr->index == SFP_RX_LOS_ALL) { - /* - * Report the RX_LOS status for all ports. - * This does not depend on the currently active SFP selector. - */ - - /* RX_LOS Ports 1-8 */ - VALIDATED_READ(buf, values[0], as5812_54x_i2c_cpld_read(0x61, 0x0F), 0); - /* RX_LOS Ports 9-16 */ - VALIDATED_READ(buf, values[1], as5812_54x_i2c_cpld_read(0x61, 0x10), 0); - /* RX_LOS Ports 17-24 */ - VALIDATED_READ(buf, values[2], as5812_54x_i2c_cpld_read(0x61, 0x11), 0); - /* RX_LOS Ports 25-32 */ - VALIDATED_READ(buf, values[3], as5812_54x_i2c_cpld_read(0x62, 0x0F), 0); - /* RX_LOS Ports 33-40 */ - VALIDATED_READ(buf, values[4], as5812_54x_i2c_cpld_read(0x62, 0x10), 0); - /* RX_LOS Ports 41-48 */ - VALIDATED_READ(buf, values[5], as5812_54x_i2c_cpld_read(0x62, 0x11), 0); - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - if(attr->index == SFP_IS_PRESENT_ALL) { - /* - * Report the SFP_PRESENCE status for all ports. - * This does not depend on the currently active SFP selector. - */ - - /* SFP_PRESENT Ports 1-8 */ - VALIDATED_READ(buf, values[0], as5812_54x_i2c_cpld_read(0x61, 0x6), 1); - /* SFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], as5812_54x_i2c_cpld_read(0x61, 0x7), 1); - /* SFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], as5812_54x_i2c_cpld_read(0x61, 0x8), 1); - /* SFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], as5812_54x_i2c_cpld_read(0x62, 0x6), 1); - /* SFP_PRESENT Ports 33-40 */ - VALIDATED_READ(buf, values[4], as5812_54x_i2c_cpld_read(0x62, 0x7), 1); - /* SFP_PRESENT Ports 41-48 */ - VALIDATED_READ(buf, values[5], as5812_54x_i2c_cpld_read(0x62, 0x8), 1); - /* QSFP_PRESENT Ports 49-54 */ - VALIDATED_READ(buf, values[6], as5812_54x_i2c_cpld_read(0x62, 0x14), 1); - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - /* - * The remaining attributes are gathered on a per-selected-sfp basis. - */ - data = as5812_54x_sfp_update_device(dev, 0); - if (attr->index == SFP_IS_PRESENT) { - val = (data->status[attr->index] & BIT_INDEX(data->port)) ? 0 : 1; - } - else { - val = (data->status[attr->index] & BIT_INDEX(data->port)) ? 1 : 0; - } - - return sprintf(buf, "%d", val); -} - -static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54x_sfp_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - - /* Tx disable is not supported for QSFP ports(49-54) */ - if (data->port >= 48) { - return -EINVAL; - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = 0x61; - cpld_reg = 0xC + data->port / 8; - cpld_bit = 1 << (data->port % 8); - } - else { - cpld_addr = 0x62; - cpld_reg = 0xC + (data->port - 24) / 8; - cpld_bit = 1 << (data->port % 8); - } - - cpld_val = as5812_54x_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->status[SFP_TX_DISABLE] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->status[SFP_TX_DISABLE] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - as5812_54x_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - - mutex_unlock(&data->update_lock); - - return count; -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as5812_54x_sfp_data *data = as5812_54x_sfp_update_device(dev, 1); - - if (!data->valid) { - return 0; - } - - if ((data->status[SFP_IS_PRESENT] & BIT_INDEX(data->port)) != 0) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as5812_54x_sfp_group = { - .attrs = as5812_54x_sfp_attributes, -}; - -static int as5812_54x_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as5812_54x_sfp_data *data; - int status; - - extern int platform_accton_as5812_54x(void); - if(!platform_accton_as5812_54x()) { - return -ENODEV; - } - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as5812_54x_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as5812_54x_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as5812_54x_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as5812_54x_sfp_remove(struct i2c_client *client) -{ - struct as5812_54x_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as5812_54x_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as5812_54x_sfp1, as5812_54x_sfp2, as5812_54x_sfp3, as5812_54x_sfp4, -as5812_54x_sfp5, as5812_54x_sfp6, as5812_54x_sfp7, as5812_54x_sfp8, -as5812_54x_sfp9, as5812_54x_sfp10, as5812_54x_sfp11,as5812_54x_sfp12, -as5812_54x_sfp13, as5812_54x_sfp14, as5812_54x_sfp15,as5812_54x_sfp16, -as5812_54x_sfp17, as5812_54x_sfp18, as5812_54x_sfp19,as5812_54x_sfp20, -as5812_54x_sfp21, as5812_54x_sfp22, as5812_54x_sfp23,as5812_54x_sfp24, -as5812_54x_sfp25, as5812_54x_sfp26, as5812_54x_sfp27,as5812_54x_sfp28, -as5812_54x_sfp29, as5812_54x_sfp30, as5812_54x_sfp31,as5812_54x_sfp32, -as5812_54x_sfp33, as5812_54x_sfp34, as5812_54x_sfp35,as5812_54x_sfp36, -as5812_54x_sfp37, as5812_54x_sfp38, as5812_54x_sfp39,as5812_54x_sfp40, -as5812_54x_sfp41, as5812_54x_sfp42, as5812_54x_sfp43,as5812_54x_sfp44, -as5812_54x_sfp45, as5812_54x_sfp46, as5812_54x_sfp47,as5812_54x_sfp48, -as5812_54x_sfp49, as5812_54x_sfp52, as5812_54x_sfp50,as5812_54x_sfp53, -as5812_54x_sfp51, as5812_54x_sfp54 -}; - -static const struct i2c_device_id as5812_54x_sfp_id[] = { -{ "as5812_54x_sfp1", as5812_54x_sfp1 }, { "as5812_54x_sfp2", as5812_54x_sfp2 }, -{ "as5812_54x_sfp3", as5812_54x_sfp3 }, { "as5812_54x_sfp4", as5812_54x_sfp4 }, -{ "as5812_54x_sfp5", as5812_54x_sfp5 }, { "as5812_54x_sfp6", as5812_54x_sfp6 }, -{ "as5812_54x_sfp7", as5812_54x_sfp7 }, { "as5812_54x_sfp8", as5812_54x_sfp8 }, -{ "as5812_54x_sfp9", as5812_54x_sfp9 }, { "as5812_54x_sfp10", as5812_54x_sfp10 }, -{ "as5812_54x_sfp11", as5812_54x_sfp11 }, { "as5812_54x_sfp12", as5812_54x_sfp12 }, -{ "as5812_54x_sfp13", as5812_54x_sfp13 }, { "as5812_54x_sfp14", as5812_54x_sfp14 }, -{ "as5812_54x_sfp15", as5812_54x_sfp15 }, { "as5812_54x_sfp16", as5812_54x_sfp16 }, -{ "as5812_54x_sfp17", as5812_54x_sfp17 }, { "as5812_54x_sfp18", as5812_54x_sfp18 }, -{ "as5812_54x_sfp19", as5812_54x_sfp19 }, { "as5812_54x_sfp20", as5812_54x_sfp20 }, -{ "as5812_54x_sfp21", as5812_54x_sfp21 }, { "as5812_54x_sfp22", as5812_54x_sfp22 }, -{ "as5812_54x_sfp23", as5812_54x_sfp23 }, { "as5812_54x_sfp24", as5812_54x_sfp24 }, -{ "as5812_54x_sfp25", as5812_54x_sfp25 }, { "as5812_54x_sfp26", as5812_54x_sfp26 }, -{ "as5812_54x_sfp27", as5812_54x_sfp27 }, { "as5812_54x_sfp28", as5812_54x_sfp28 }, -{ "as5812_54x_sfp29", as5812_54x_sfp29 }, { "as5812_54x_sfp30", as5812_54x_sfp30 }, -{ "as5812_54x_sfp31", as5812_54x_sfp31 }, { "as5812_54x_sfp32", as5812_54x_sfp32 }, -{ "as5812_54x_sfp33", as5812_54x_sfp33 }, { "as5812_54x_sfp34", as5812_54x_sfp34 }, -{ "as5812_54x_sfp35", as5812_54x_sfp35 }, { "as5812_54x_sfp36", as5812_54x_sfp36 }, -{ "as5812_54x_sfp37", as5812_54x_sfp37 }, { "as5812_54x_sfp38", as5812_54x_sfp38 }, -{ "as5812_54x_sfp39", as5812_54x_sfp39 }, { "as5812_54x_sfp40", as5812_54x_sfp40 }, -{ "as5812_54x_sfp41", as5812_54x_sfp41 }, { "as5812_54x_sfp42", as5812_54x_sfp42 }, -{ "as5812_54x_sfp43", as5812_54x_sfp43 }, { "as5812_54x_sfp44", as5812_54x_sfp44 }, -{ "as5812_54x_sfp45", as5812_54x_sfp45 }, { "as5812_54x_sfp46", as5812_54x_sfp46 }, -{ "as5812_54x_sfp47", as5812_54x_sfp47 }, { "as5812_54x_sfp48", as5812_54x_sfp48 }, -{ "as5812_54x_sfp49", as5812_54x_sfp49 }, { "as5812_54x_sfp50", as5812_54x_sfp50 }, -{ "as5812_54x_sfp51", as5812_54x_sfp51 }, { "as5812_54x_sfp52", as5812_54x_sfp52 }, -{ "as5812_54x_sfp53", as5812_54x_sfp53 }, { "as5812_54x_sfp54", as5812_54x_sfp54 }, - -{} -}; -MODULE_DEVICE_TABLE(i2c, as5812_54x_sfp_id); - -static struct i2c_driver as5812_54x_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as5812_54x_sfp", - }, - .probe = as5812_54x_sfp_probe, - .remove = as5812_54x_sfp_remove, - .id_table = as5812_54x_sfp_id, - .address_list = normal_i2c, -}; - -static int as5812_54x_sfp_read_byte(struct i2c_client *client, u8 command, u8 *data) -{ - int result = i2c_smbus_read_byte_data(client, command); - - if (unlikely(result < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, result); - goto abort; - } - - *data = (u8)result; - result = 0; - -abort: - return result; -} - -#define ALWAYS_UPDATE_DEVICE 1 - -static struct as5812_54x_sfp_data *as5812_54x_sfp_update_device(struct device *dev, int update_eeprom) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as5812_54x_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (ALWAYS_UPDATE_DEVICE || time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - int i = 0, j = 0; - - data->valid = 0; - //dev_dbg(&client->dev, "Starting as5812_54x sfp status update\n"); - memset(data->status, 0, sizeof(data->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 12; j++) { - status = as5812_54x_i2c_cpld_read(0x61+i, 0x6+j); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", 0x61+i, 0x6+j, status); - goto exit; - } - - data->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* - * Bring QSFPs out of reset, - * This is a temporary fix until the QSFP+_MOD_RST register - * can be exposed through the driver. - */ - as5812_54x_i2c_cpld_write(0x62, 0x15, 0x3F); - - /* Read present status of port 49-54(QSFP port) */ - status = as5812_54x_i2c_cpld_read(0x62, 0x14); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", 0x61+i, 0x6+j, status); - } - else { - data->status[SFP_IS_PRESENT] |= (u64)status << 48; - } - - if (update_eeprom) { - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if ((data->status[SFP_IS_PRESENT] & BIT_INDEX(data->port)) == 0) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom); i++) { - status = as5812_54x_sfp_read_byte(client, i, data->eeprom + i); - - if (status < 0) { - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", - CPLD_PORT_TO_FRONT_PORT(data->port)); - goto exit; - } - } - } - } - - data->valid = 1; - data->last_updated = jiffies; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -module_i2c_driver(as5812_54x_sfp_driver); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5812_54x_sfp driver"); -MODULE_LICENSE("GPL"); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/sfpi.c index 6cfa29a9..f731e0d3 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/onlp/builds/src/module/src/sfpi.c @@ -24,20 +24,24 @@ * ***********************************************************/ #include - -#include /* For O_RDWR && open */ -#include -#include -#include -#include #include -#include "platform_lib.h" +#include +#include "x86_64_accton_as5812_54x_int.h" +#include "x86_64_accton_as5812_54x_log.h" -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; #define CPLD_MUX_BUS_START_INDEX 2 -static int front_port_to_cpld_mux_index(int port) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/0-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/0-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/0-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/0-00%d/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/0-0061/module_present_all" +#define MODULE_PRESENT_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/0-0062/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/0-0061/module_rx_los_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/0-0062/module_rx_los_all" + +static int front_port_bus_index(int port) { int rport = 0; @@ -63,38 +67,6 @@ static int front_port_to_cpld_mux_index(int port) return (rport + CPLD_MUX_BUS_START_INDEX); } -static int -as5812_54x_sfp_node_read_int(char *node_path, int *value, int data_len) -{ - int ret = 0; - char buf[8] = {0}; - *value = 0; - - ret = deviceNodeReadString(node_path, buf, sizeof(buf), data_len); - - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -static char* -as5812_54x_sfp_get_port_path_addr(int port, int addr, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s", - front_port_to_cpld_mux_index(port), addr, - node_name); - return sfp_node_path; -} - -static char* -as5812_54x_sfp_get_port_path(int port, char *node_name) -{ - return as5812_54x_sfp_get_port_path_addr(port, 50, node_name); -} - - /************************************************************ * * SFPI Entry Points @@ -203,10 +175,10 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char* path = as5812_54x_sfp_get_port_path(port, "sfp_is_present"); - - if (as5812_54x_sfp_node_read_int(path, &present, 1) != 0) { - AIM_LOG_INFO("Unable to read present status from port(%d)\r\n", port); + int addr = (port < 24) ? 61 : 62; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -217,29 +189,35 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[7]; - char* path; FILE* fp; - path = as5812_54x_sfp_get_port_path(0, "sfp_is_present_all"); - fp = fopen(path, "r"); - + /* Read present status of port 0~23 */ + fp = fopen(MODULE_PRESENT_ALL_ATTR_CPLD2, "r"); if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD2."); return ONLP_STATUS_E_INTERNAL; } - int count = fscanf(fp, "%x %x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5, - bytes+6 - ); + + int count = fscanf(fp, "%x %x %x", bytes+0, bytes+1, bytes+2); fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { + if(count != 3) { /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD2."); + return ONLP_STATUS_E_INTERNAL; + } + + /* Read present status of port 24~53 */ + fp = fopen(MODULE_PRESENT_ALL_ATTR_CPLD3, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD3."); + return ONLP_STATUS_E_INTERNAL; + } + + count = fscanf(fp, "%x %x %x %x", bytes+3, bytes+4, bytes+5, bytes+6); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD3."); return ONLP_STATUS_E_INTERNAL; } @@ -268,33 +246,39 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[7]; - char* path; + uint32_t bytes[6]; + uint32_t *ptr = bytes; FILE* fp; - path = as5812_54x_sfp_get_port_path(0, "sfp_rx_los_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~23 */ + int addr, i = 0; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5 - ); - fclose(fp); - if(count != 6) { - AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 61; addr <= 62; addr++) { + if (addr == 61) { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r"); + } + else { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD3, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Convert to 64 bit integer in port order */ - int i = 0; + i = 0; uint64_t rx_los_all = 0 ; for(i = 5; i >= 0; i--) { rx_los_all <<= 8; @@ -315,18 +299,22 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = as5812_54x_sfp_get_port_path(port, "sfp_eeprom"); - /* * Read the SFP eeprom into data[] * * Return MISSING if SFP is missing. * Return OK if eeprom is read */ + int size = 0; memset(data, 0, 256); - if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, front_port_bus_index(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -336,11 +324,26 @@ onlp_sfpi_eeprom_read(int port, uint8_t data[256]) int onlp_sfpi_dom_read(int port, uint8_t data[256]) { - char* path = as5812_54x_sfp_get_port_path_addr(port, 51, "sfp_eeprom"); - memset(data, 0, 256); + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, front_port_bus_index(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } - if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -350,28 +353,28 @@ onlp_sfpi_dom_read(int port, uint8_t data[256]) int onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) { - int bus = front_port_to_cpld_mux_index(port); + int bus = front_port_bus_index(port); return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) { - int bus = front_port_to_cpld_mux_index(port); + int bus = front_port_bus_index(port); return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); } int onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) { - int bus = front_port_to_cpld_mux_index(port); + int bus = front_port_bus_index(port); return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); } int onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) { - int bus = front_port_to_cpld_mux_index(port); + int bus = front_port_bus_index(port); return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); } @@ -384,13 +387,13 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) return ONLP_STATUS_E_UNSUPPORTED; } + int addr = (port < 24) ? 61 : 62; + switch(control) { case ONLP_SFP_CONTROL_TX_DISABLE: { - char* path = as5812_54x_sfp_get_port_path(port, "sfp_tx_disable"); - - if (deviceNodeWriteInt(path, value, 0) != 0) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -412,19 +415,18 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; - char* path = NULL; if (port < 0 || port >= 48) { return ONLP_STATUS_E_UNSUPPORTED; } + int addr = (port < 24) ? 61 : 62; + switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - path = as5812_54x_sfp_get_port_path(port, "sfp_rx_loss"); - - if (as5812_54x_sfp_node_read_int(path, value, 1) != 0) { + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -436,9 +438,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - path = as5812_54x_sfp_get_port_path(port, "sfp_tx_fault"); - - if (as5812_54x_sfp_node_read_int(path, value, 1) != 0) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -450,9 +450,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - path = as5812_54x_sfp_get_port_path(port, "sfp_tx_disable"); - - if (as5812_54x_sfp_node_read_int(path, value, 0) != 0) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py index 5eee6748..b6505028 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5812-54x/platform-config/r0/src/python/x86_64_accton_as5812_54x_r0/__init__.py @@ -9,9 +9,10 @@ class OnlPlatform_x86_64_accton_as5812_54x_r0(OnlPlatformAccton, SYS_OBJECT_ID=".5812.54.1" def baseconfig(self): + self.insmod('optoe') self.insmod('cpr_4011_4mxx') self.insmod("ym2651y") - for m in [ 'cpld', 'fan', 'psu', 'leds', 'sfp' ]: + for m in [ 'cpld', 'fan', 'psu', 'leds' ]: self.insmod("x86-64-accton-as5812-54x-%s.ko" % m) ########### initialize I2C bus 0 ########### @@ -26,16 +27,18 @@ class OnlPlatform_x86_64_accton_as5812_54x_r0(OnlPlatformAccton, ) # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5812_54x_sfp%d' % port, 0x50, port+1) - self.new_i2c_device('as5812_54x_sfp%d' % port, 0x51, port+1) + self.new_i2c_device('optoe2', 0x50, port+1) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+1), shell=True) # Initialize QSFP devices - self.new_i2c_device('as5812_54x_sfp49', 0x50, 50) - self.new_i2c_device('as5812_54x_sfp52', 0x50, 51) - self.new_i2c_device('as5812_54x_sfp50', 0x50, 52) - self.new_i2c_device('as5812_54x_sfp53', 0x50, 53) - self.new_i2c_device('as5812_54x_sfp51', 0x50, 54) - self.new_i2c_device('as5812_54x_sfp54', 0x50, 55) + for port in range(49, 55): + self.new_i2c_device('optoe1', 0x50, port+1) + subprocess.call('echo port49 > /sys/bus/i2c/devices/50-0050/port_name', shell=True) + subprocess.call('echo port52 > /sys/bus/i2c/devices/51-0050/port_name', shell=True) + subprocess.call('echo port50 > /sys/bus/i2c/devices/52-0050/port_name', shell=True) + subprocess.call('echo port53 > /sys/bus/i2c/devices/53-0050/port_name', shell=True) + subprocess.call('echo port51 > /sys/bus/i2c/devices/54-0050/port_name', shell=True) + subprocess.call('echo port54 > /sys/bus/i2c/devices/55-0050/port_name', shell=True) ########### initialize I2C bus 1 ########### self.new_i2c_devices( From f258852eb425bafb873122163090fb78f571524a Mon Sep 17 00:00:00 2001 From: cytsai0409 Date: Tue, 20 Mar 2018 11:39:07 +0800 Subject: [PATCH 08/21] [ingrasys s9100] platform driver update --- .../x86_64_ingrasys_s9100/module/src/fani.c | 75 +++++++++++++---- .../x86_64_ingrasys_s9100/module/src/ledi.c | 82 ++++++++++++++++++- .../module/src/platform_lib.c | 70 +++++++++++++++- .../module/src/platform_lib.h | 19 +++++ .../x86_64_ingrasys_s9100/module/src/psui.c | 4 +- .../x86_64_ingrasys_s9100/module/src/sysi.c | 74 ++++++++++++++--- .../x86_64_ingrasys_s9100_r0/__init__.py | 75 +++++++++++++++++ 7 files changed, 365 insertions(+), 34 deletions(-) diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c index 921b3ffa..66f33b16 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/fani.c @@ -25,6 +25,7 @@ #include #include "x86_64_ingrasys_s9100_int.h" #include +#include #include "platform_lib.h" onlp_fan_info_t fan_info[] = { @@ -111,12 +112,67 @@ onlp_fani_init(void) return ONLP_STATUS_OK; } +/* get fan present status*/ +int sys_fan_present_get(onlp_fan_info_t* info, int id) +{ + int rv, fan_presence, i2c_bus, offset, fan_reg_mask; + + /* get fan presence*/ + i2c_bus = I2C_BUS_9; + switch (id) + { + case FAN_ID_FAN1: + case FAN_ID_FAN2: + offset = 0; + fan_reg_mask = FAN_1_2_PRESENT_MASK; + break; + case FAN_ID_FAN3: + case FAN_ID_FAN4: + offset = 0; + fan_reg_mask = FAN_3_4_PRESENT_MASK; + break; + case FAN_ID_FAN5: + case FAN_ID_FAN6: + offset = 1; + fan_reg_mask = FAN_5_6_PRESENT_MASK; + break; + case FAN_ID_FAN7: + case FAN_ID_FAN8: + offset = 1; + fan_reg_mask = FAN_7_8_PRESENT_MASK; + break; + default: + return ONLP_STATUS_E_INVALID; + } + + rv = onlp_i2c_readb(i2c_bus, FAN_REG, offset, ONLP_I2C_F_FORCE); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + fan_presence = (rv & fan_reg_mask) ? 0 : 1; + + if (!fan_presence) { + info->status &= ~ONLP_FAN_STATUS_PRESENT; + } else { + info->status |= ONLP_FAN_STATUS_PRESENT; + } + + return ONLP_STATUS_OK; +} + int sys_fan_info_get(onlp_fan_info_t* info, int id) { int rv, fan_status, fan_rpm, perc_val, percentage; + int max_fan_speed = 16000; fan_status = 0; fan_rpm = 0; + + rv = sys_fan_present_get(info, id); + if (rv < 0) { + return ONLP_STATUS_E_INTERNAL; + } rv = onlp_file_read_int(&fan_status, SYS_FAN_PREFIX "fan%d_alarm", id); if (rv < 0) { @@ -157,21 +213,8 @@ sys_fan_info_get(onlp_fan_info_t* info, int id) return ONLP_STATUS_E_INTERNAL; } - /* - Get fan speed, converting driver value to percnet. - Value 128 is 50%. - Value 200 is 80%. - Value 255 is 100%. - */ - if (perc_val == 255) { - percentage = 100; - } else if (perc_val == 200) { - percentage = 80; - } else if (perc_val == 128) { - percentage = 50; - } else { - return ONLP_STATUS_E_INTERNAL; - } + percentage = (info->rpm*100)/max_fan_speed; + info->percentage = percentage; return ONLP_STATUS_OK; @@ -280,4 +323,4 @@ onlp_fani_info_get(onlp_oid_t id, onlp_fan_info_t* rv) return rc; } - \ No newline at end of file + diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c index 306ab37b..b694ca2e 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/ledi.c @@ -55,9 +55,36 @@ static onlp_led_info_t led_info[] = { LED_OID_PSU2, "Chassis LED 4 (PSU2 LED)", 0 }, ONLP_LED_STATUS_PRESENT, ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_FAN_TRAY1, "Rear LED 1 (FAN TRAY1 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_FAN_TRAY2, "Rear LED 2 (FAN TRAY2 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_FAN_TRAY3, "Rear LED 3 (FAN TRAY3 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, + }, + { + { LED_OID_FAN_TRAY4, "Rear LED 4 (FAN TRAY4 LED)", 0 }, + ONLP_LED_STATUS_PRESENT, + ONLP_LED_CAPS_ON_OFF | ONLP_LED_CAPS_ORANGE | + ONLP_LED_CAPS_GREEN | ONLP_LED_CAPS_AUTO, } + }; +extern int sys_fan_info_get(onlp_fan_info_t* info, int id); + /* * This function will be called prior to any other onlp_ledi_* functions. */ @@ -70,13 +97,56 @@ onlp_ledi_init(void) int onlp_ledi_info_get(onlp_oid_t id, onlp_led_info_t* info) { - int led_id; + int led_id, pw_exist, pw_good, rc, psu_mask, fan_id; + onlp_fan_info_t fan_info; + memset(&fan_info, 0, sizeof(onlp_fan_info_t)); led_id = ONLP_OID_ID_GET(id); *info = led_info[led_id]; - info->status |= ONLP_LED_STATUS_ON; - info->mode |= ONLP_LED_MODE_ON; + + if (id == LED_OID_PSU1 || id == LED_OID_PSU2) { + if (id == LED_OID_PSU1) { + psu_mask = PSU1_MUX_MASK; + } else { + psu_mask = PSU2_MUX_MASK; + } + /* check psu status */ + if ((rc = psu_present_get(&pw_exist, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + if ((rc = psu_pwgood_get(&pw_good, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { + return ONLP_STATUS_E_INTERNAL; + } + /* psu not present */ + if (pw_exist != PSU_STATUS_PRESENT) { + info->status &= ~ONLP_LED_STATUS_ON; + info->mode = ONLP_LED_MODE_OFF; + } else if (pw_good != PSU_STATUS_POWER_GOOD) { + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_ORANGE; + } else { + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_GREEN; + } + } else if (id == LED_OID_FAN) { + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_GREEN; + for (fan_id=FAN_ID_FAN1; fan_id<=FAN_ID_FAN8; ++fan_id) { + rc = sys_fan_info_get(&fan_info, fan_id); + if (rc != ONLP_STATUS_OK || fan_info.status & ONLP_FAN_STATUS_FAILED) { + info->mode &= ~ONLP_LED_MODE_GREEN; + info->mode |= ONLP_LED_MODE_ORANGE; + break; + } + } + } else if (id == LED_OID_SYSTEM) { + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_GREEN; + } else { + info->status |= ONLP_LED_STATUS_ON; + info->mode |= ONLP_LED_MODE_ON; + } return ONLP_STATUS_OK; } @@ -125,6 +195,12 @@ onlp_ledi_mode_set(onlp_oid_t id, onlp_led_mode_t mode) case LED_PSU2_LED: rc = psu2_led_set(mode); break; + case LED_FAN_TRAY1: + case LED_FAN_TRAY2: + case LED_FAN_TRAY3: + case LED_FAN_TRAY4: + rc = fan_tray_led_set(id, mode); + break; default: return ONLP_STATUS_E_INTERNAL; break; diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c index 172b7f13..43d2b965 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.c @@ -70,8 +70,11 @@ psu_thermal_get(onlp_thermal_info_t* info, int thermal_id) if (pw_exist != PSU_STATUS_PRESENT) { info->mcelsius = 0; + info->status &= ~ONLP_THERMAL_STATUS_PRESENT; return ONLP_STATUS_OK; - } + } else { + info->status |= ONLP_THERMAL_STATUS_PRESENT; + } if ((rc = psu_pwgood_get(&pw_good, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { return ONLP_STATUS_E_INTERNAL; @@ -126,7 +129,10 @@ psu_fan_info_get(onlp_fan_info_t* info, int id) if (pw_exist != PSU_STATUS_PRESENT) { info->rpm = 0; + info->status &= ~ONLP_FAN_STATUS_PRESENT; return ONLP_STATUS_OK; + } else { + info->status |= ONLP_FAN_STATUS_PRESENT; } if ((rc = psu_pwgood_get(&pw_good, I2C_BUS_0, psu_mask)) != ONLP_STATUS_OK) { @@ -472,6 +478,10 @@ psu1_led_set(onlp_led_mode_t mode) rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_PSU1_AND_MASK, LED_PSU1_YMASK, ONLP_I2C_F_FORCE); + } else if(mode == ONLP_LED_MODE_OFF) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU1_AND_MASK, LED_PSU1_OFFMASK, + ONLP_I2C_F_FORCE); } else { return ONLP_STATUS_E_INTERNAL; } @@ -495,6 +505,10 @@ psu2_led_set(onlp_led_mode_t mode) rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, LED_PSU2_AND_MASK, LED_PSU2_YMASK, ONLP_I2C_F_FORCE); + } else if(mode == ONLP_LED_MODE_OFF) { + rc = onlp_i2c_modifyb(I2C_BUS_9, LED_REG, LED_OFFSET, + LED_PSU2_AND_MASK, LED_PSU2_OFFMASK, + ONLP_I2C_F_FORCE); } else { return ONLP_STATUS_E_INTERNAL; } @@ -507,6 +521,60 @@ psu2_led_set(onlp_led_mode_t mode) return ONLP_STATUS_OK; } +int +fan_tray_led_set(onlp_oid_t id, onlp_led_mode_t mode) +{ + int rc, temp_id; + int fan_tray_id, offset; +char cmd[256]; +memset(cmd, 0, sizeof(cmd)); + + temp_id = ONLP_OID_ID_GET(id); + switch (temp_id) { + case 5: + fan_tray_id = 1; + offset = 2; + break; + case 6: + fan_tray_id = 2; + offset = 2; + break; + case 7: + fan_tray_id = 3; + offset = 3; + break; + case 8: + fan_tray_id = 4; + offset = 3; + break; + default: + return ONLP_STATUS_E_INTERNAL; + break; + } + if (fan_tray_id == 1 || fan_tray_id == 3) { + if (mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, FAN_REG, offset, 0xFC, + 0x01, ONLP_I2C_F_FORCE); + } else if (mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, FAN_REG, offset, 0xFC, + 0x02, ONLP_I2C_F_FORCE); + } + } else if (fan_tray_id == 2 || fan_tray_id == 4) { + if (mode == ONLP_LED_MODE_GREEN) { + rc = onlp_i2c_modifyb(I2C_BUS_9, FAN_REG, offset, 0xCF, + 0x10, ONLP_I2C_F_FORCE); + } else if (mode == ONLP_LED_MODE_ORANGE) { + rc = onlp_i2c_modifyb(I2C_BUS_9, FAN_REG, offset, 0xCF, + 0x20, ONLP_I2C_F_FORCE); + } + } + if (rc < 0) { + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + int sysi_platform_info_get(onlp_platform_info_t* pi) { diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h index c06d2de9..e9f44ed6 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/platform_lib.h @@ -111,9 +111,11 @@ #define LED_PSU1_AND_MASK 0xFC #define LED_PSU1_GMASK 0x01 #define LED_PSU1_YMASK 0x02 +#define LED_PSU1_OFFMASK 0x03 #define LED_PSU2_AND_MASK 0xCF #define LED_PSU2_GMASK 0x10 #define LED_PSU2_YMASK 0x20 +#define LED_PSU2_OFFMASK 0x30 /* SYS */ #define CPLD_REG 0x33 @@ -125,12 +127,23 @@ #define QSFP_PRES_OFFSET1 0x00 #define QSFP_PRES_OFFSET2 0x01 +/* FAN */ +#define FAN_REG 0x20 +#define FAN_1_2_PRESENT_MASK 0x04 +#define FAN_3_4_PRESENT_MASK 0x40 +#define FAN_5_6_PRESENT_MASK 0x04 +#define FAN_7_8_PRESENT_MASK 0x40 + /** led_oid */ typedef enum led_oid_e { LED_OID_SYSTEM = ONLP_LED_ID_CREATE(1), LED_OID_FAN = ONLP_LED_ID_CREATE(2), LED_OID_PSU1 = ONLP_LED_ID_CREATE(3), LED_OID_PSU2 = ONLP_LED_ID_CREATE(4), + LED_OID_FAN_TRAY1 = ONLP_LED_ID_CREATE(5), + LED_OID_FAN_TRAY2 = ONLP_LED_ID_CREATE(6), + LED_OID_FAN_TRAY3 = ONLP_LED_ID_CREATE(7), + LED_OID_FAN_TRAY4 = ONLP_LED_ID_CREATE(8), } led_oid_t; /** led_id */ @@ -139,6 +152,10 @@ typedef enum led_id_e { LED_FAN_LED = 2, LED_PSU1_LED = 3, LED_PSU2_LED = 4, + LED_FAN_TRAY1 = 5, + LED_FAN_TRAY2 = 6, + LED_FAN_TRAY3 = 7, + LED_FAN_TRAY4 = 8, } led_id_t; /** Thermal_oid */ @@ -241,6 +258,8 @@ int fan_led_set(onlp_led_mode_t mode); int system_led_set(onlp_led_mode_t mode); +int fan_tray_led_set(onlp_oid_t id, onlp_led_mode_t mode); + int sysi_platform_info_get(onlp_platform_info_t* pi); int qsfp_present_get(int port, int *pres_val); diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c index 496bc1ea..52f0d92f 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/psui.c @@ -93,6 +93,8 @@ psu_status_info_get(int id, onlp_psu_info_t *info) if (pw_good != PSU_STATUS_POWER_GOOD) { info->status |= ONLP_PSU_STATUS_UNPLUGGED; return ONLP_STATUS_OK; + } else { + info->status &= ~ONLP_PSU_STATUS_UNPLUGGED; } /* Get power eeprom status */ @@ -147,4 +149,4 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) return ONLP_STATUS_OK; -} \ No newline at end of file +} diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c index 20c65b24..f748eb9c 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/onlp/builds/src/x86_64_ingrasys_s9100/module/src/sysi.c @@ -197,13 +197,18 @@ _EXIT : int onlp_sysi_platform_manage_leds(void) { - int psu1_status, psu2_status, rc, i, tmp_fan_status; + int psu1_status, psu2_status, rc, i; + int fan_tray_id, sum, total = 0; static int pre_psu1_status = 0, pre_psu2_status = 0, pre_fan_status = 0; + static int pre_fan_tray_status[4] = {0}; onlp_psu_info_t psu_info; onlp_fan_info_t fan_info; + onlp_led_status_t fan_tray_status[SYS_FAN_NUM]; + memset(&psu_info, 0, sizeof(onlp_psu_info_t)); memset(&fan_info, 0, sizeof(onlp_fan_info_t)); + memset(&fan_tray_status, 0, sizeof(fan_tray_status)); uint32_t fan_arr[] = { FAN_OID_FAN1, FAN_OID_FAN2, FAN_OID_FAN3, @@ -213,6 +218,7 @@ onlp_sysi_platform_manage_leds(void) FAN_OID_FAN7, FAN_OID_FAN8, }; + /* PSU LED CTRL */ if ((rc = onlp_psui_info_get(PSU_OID_PSU1, &psu_info)) != ONLP_STATUS_OK) { goto _EXIT; @@ -220,7 +226,10 @@ onlp_sysi_platform_manage_leds(void) psu1_status = psu_info.status; if (psu1_status != pre_psu1_status) { - if(psu1_status != ONLP_PSU_STATUS_PRESENT) { + if((psu1_status & ONLP_PSU_STATUS_PRESENT) == 0) { + rc = onlp_ledi_mode_set(LED_OID_PSU1, ONLP_LED_MODE_OFF); + } + else if(psu1_status != ONLP_PSU_STATUS_PRESENT) { rc = onlp_ledi_mode_set(LED_OID_PSU1, ONLP_LED_MODE_ORANGE); } else { rc = onlp_ledi_mode_set(LED_OID_PSU1, ONLP_LED_MODE_GREEN); @@ -238,7 +247,10 @@ onlp_sysi_platform_manage_leds(void) psu2_status = psu_info.status; if( psu2_status != pre_psu2_status) { - if(psu2_status != ONLP_PSU_STATUS_PRESENT) { + if((psu2_status & ONLP_PSU_STATUS_PRESENT) == 0) { + rc = onlp_ledi_mode_set(LED_OID_PSU2, ONLP_LED_MODE_OFF); + } + else if(psu2_status != ONLP_PSU_STATUS_PRESENT) { rc = onlp_ledi_mode_set(LED_OID_PSU2, ONLP_LED_MODE_ORANGE); } else { rc = onlp_ledi_mode_set(LED_OID_PSU2, ONLP_LED_MODE_GREEN); @@ -251,29 +263,65 @@ onlp_sysi_platform_manage_leds(void) } /* FAN LED CTRL */ - tmp_fan_status = ONLP_LED_STATUS_PRESENT; + for (i=0; i ONLP_LED_STATUS_FAILED) { + rc = onlp_ledi_mode_set(fan_tray_id, ONLP_LED_MODE_ORANGE); + } else { + rc = onlp_ledi_mode_set(fan_tray_id, ONLP_LED_MODE_GREEN); + } - if(fan_info.status != ONLP_LED_STATUS_PRESENT) { - tmp_fan_status = fan_info.status; + if (rc != ONLP_STATUS_OK) { + goto _EXIT; + } + + pre_fan_tray_status[fan_tray_id - 5] = sum; + } } - } + } - if (tmp_fan_status != pre_fan_status) { - if (tmp_fan_status != ONLP_LED_STATUS_PRESENT) { - rc = onlp_ledi_mode_set(LED_OID_FAN, ONLP_LED_MODE_ORANGE); - } else { + if (total != pre_fan_status) { + if (total == (ONLP_LED_STATUS_PRESENT * 8)) { rc = onlp_ledi_mode_set(LED_OID_FAN, ONLP_LED_MODE_GREEN); + } else { + rc = onlp_ledi_mode_set(LED_OID_FAN, ONLP_LED_MODE_ORANGE); } - + if (rc != ONLP_STATUS_OK) { goto _EXIT; } + + pre_fan_status = total; } - pre_fan_status = fan_info.status; _EXIT : return rc; diff --git a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py index cba0b0fe..3a808108 100755 --- a/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py +++ b/packages/platforms/ingrasys/x86-64/x86-64-ingrasys-s9100/platform-config/r0/src/python/x86_64_ingrasys_s9100_r0/__init__.py @@ -365,6 +365,38 @@ class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformIngrasys): os.system("echo out > /sys/class/gpio/gpio413/direction") os.system("echo out > /sys/class/gpio/gpio414/direction") os.system("echo out > /sys/class/gpio/gpio415/direction") + os.system("echo 1 > /sys/class/gpio/gpio400/active_low") + os.system("echo 1 > /sys/class/gpio/gpio401/active_low") + os.system("echo 1 > /sys/class/gpio/gpio402/active_low") + os.system("echo 1 > /sys/class/gpio/gpio403/active_low") + os.system("echo 1 > /sys/class/gpio/gpio404/active_low") + os.system("echo 1 > /sys/class/gpio/gpio405/active_low") + os.system("echo 1 > /sys/class/gpio/gpio406/active_low") + os.system("echo 1 > /sys/class/gpio/gpio407/active_low") + os.system("echo 1 > /sys/class/gpio/gpio408/active_low") + os.system("echo 1 > /sys/class/gpio/gpio409/active_low") + os.system("echo 1 > /sys/class/gpio/gpio410/active_low") + os.system("echo 1 > /sys/class/gpio/gpio411/active_low") + os.system("echo 1 > /sys/class/gpio/gpio412/active_low") + os.system("echo 1 > /sys/class/gpio/gpio413/active_low") + os.system("echo 1 > /sys/class/gpio/gpio414/active_low") + os.system("echo 1 > /sys/class/gpio/gpio415/active_low") + os.system("echo 0 > /sys/class/gpio/gpio400/value") + os.system("echo 0 > /sys/class/gpio/gpio401/value") + os.system("echo 0 > /sys/class/gpio/gpio402/value") + os.system("echo 0 > /sys/class/gpio/gpio403/value") + os.system("echo 0 > /sys/class/gpio/gpio404/value") + os.system("echo 0 > /sys/class/gpio/gpio405/value") + os.system("echo 0 > /sys/class/gpio/gpio406/value") + os.system("echo 0 > /sys/class/gpio/gpio407/value") + os.system("echo 0 > /sys/class/gpio/gpio408/value") + os.system("echo 0 > /sys/class/gpio/gpio409/value") + os.system("echo 0 > /sys/class/gpio/gpio410/value") + os.system("echo 0 > /sys/class/gpio/gpio411/value") + os.system("echo 0 > /sys/class/gpio/gpio412/value") + os.system("echo 0 > /sys/class/gpio/gpio413/value") + os.system("echo 0 > /sys/class/gpio/gpio414/value") + os.system("echo 0 > /sys/class/gpio/gpio415/value") # initialize RST Port 16-31 self.new_i2c_device('pca9535', 0x23, 7) @@ -400,6 +432,38 @@ class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformIngrasys): os.system("echo out > /sys/class/gpio/gpio397/direction") os.system("echo out > /sys/class/gpio/gpio398/direction") os.system("echo out > /sys/class/gpio/gpio399/direction") + os.system("echo 1 > /sys/class/gpio/gpio384/active_low") + os.system("echo 1 > /sys/class/gpio/gpio385/active_low") + os.system("echo 1 > /sys/class/gpio/gpio386/active_low") + os.system("echo 1 > /sys/class/gpio/gpio387/active_low") + os.system("echo 1 > /sys/class/gpio/gpio388/active_low") + os.system("echo 1 > /sys/class/gpio/gpio389/active_low") + os.system("echo 1 > /sys/class/gpio/gpio390/active_low") + os.system("echo 1 > /sys/class/gpio/gpio391/active_low") + os.system("echo 1 > /sys/class/gpio/gpio392/active_low") + os.system("echo 1 > /sys/class/gpio/gpio393/active_low") + os.system("echo 1 > /sys/class/gpio/gpio394/active_low") + os.system("echo 1 > /sys/class/gpio/gpio395/active_low") + os.system("echo 1 > /sys/class/gpio/gpio396/active_low") + os.system("echo 1 > /sys/class/gpio/gpio397/active_low") + os.system("echo 1 > /sys/class/gpio/gpio398/active_low") + os.system("echo 1 > /sys/class/gpio/gpio399/active_low") + os.system("echo 0 > /sys/class/gpio/gpio384/value") + os.system("echo 0 > /sys/class/gpio/gpio385/value") + os.system("echo 0 > /sys/class/gpio/gpio386/value") + os.system("echo 0 > /sys/class/gpio/gpio387/value") + os.system("echo 0 > /sys/class/gpio/gpio388/value") + os.system("echo 0 > /sys/class/gpio/gpio389/value") + os.system("echo 0 > /sys/class/gpio/gpio390/value") + os.system("echo 0 > /sys/class/gpio/gpio391/value") + os.system("echo 0 > /sys/class/gpio/gpio392/value") + os.system("echo 0 > /sys/class/gpio/gpio393/value") + os.system("echo 0 > /sys/class/gpio/gpio394/value") + os.system("echo 0 > /sys/class/gpio/gpio395/value") + os.system("echo 0 > /sys/class/gpio/gpio396/value") + os.system("echo 0 > /sys/class/gpio/gpio397/value") + os.system("echo 0 > /sys/class/gpio/gpio398/value") + os.system("echo 0 > /sys/class/gpio/gpio399/value") # initialize MODSEL Port 0-15 self.new_i2c_device('pca9535', 0x24, 7) @@ -491,6 +555,17 @@ class OnlPlatform_x86_64_ingrasys_s9100_r0(OnlPlatformIngrasys): os.system("i2cset -m 0x40 -y -r 9 0x22 2 0xFF") os.system("i2cset -m 0x80 -y -r 9 0x22 2 0x00") + # init CPLD LED_CLR Register (Switch Port LED) + os.system("i2cset -y 0 0x33 0x34 0x10") + + # init Fan I/O Exanpler + os.system("i2cset -y -r 9 0x20 4 0x00") + os.system("i2cset -y -r 9 0x20 5 0x00") + os.system("i2cset -y -r 9 0x20 2 0x00") + os.system("i2cset -y -r 9 0x20 3 0x00") + os.system("i2cset -y -r 9 0x20 6 0xCC") + os.system("i2cset -y -r 9 0x20 7 0xCC") + return True From f24caec55af1cd2d2ae71126b20ec23e464a5c87 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Tue, 20 Mar 2018 11:43:44 +0800 Subject: [PATCH 09/21] [as6812-32x] Add support for OOM --- .../builds/x86-64-accton-as6812-32x-cpld.c | 621 +++++-- .../builds/x86-64-accton-as6812-32x-fan.c | 13 +- .../builds/x86-64-accton-as6812-32x-leds.c | 13 +- .../builds/x86-64-accton-as6812-32x-psu.c | 16 +- .../builds/x86-64-accton-as6812-32x-sfp.c | 1532 ----------------- .../onlp/builds/src/module/src/sfpi.c | 95 +- .../x86_64_accton_as6812_32x_r0/__init__.py | 8 +- 7 files changed, 536 insertions(+), 1762 deletions(-) delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-cpld.c index 6c146767..b42e5c2a 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-cpld.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-cpld.c @@ -33,44 +33,28 @@ #include #include #include -#include #include +#include +#include +#include -static struct dmi_system_id as6812_dmi_table[] = { - { - .ident = "Accton AS6812", - .matches = { - DMI_MATCH(DMI_BOARD_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS6812"), - }, - }, - { - .ident = "Accton AS6812", - .matches = { - DMI_MATCH(DMI_SYS_VENDOR, "Accton"), - DMI_MATCH(DMI_PRODUCT_NAME, "AS6812"), - }, - }, -}; - -int platform_accton_as6812_32x(void) -{ - return dmi_check_system(as6812_dmi_table); -} -EXPORT_SYMBOL(platform_accton_as6812_32x); +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ #define NUM_OF_CPLD1_CHANS 0x0 #define NUM_OF_CPLD2_CHANS 0x10 #define NUM_OF_CPLD3_CHANS 0x10 -#define NUM_OF_ALL_CPLD_CHANS (NUM_OF_CPLD2_CHANS + NUM_OF_CPLD3_CHANS) -#define ACCTON_I2C_CPLD_MUX_MAX_NCHANS NUM_OF_CPLD3_CHANS +#define CPLD_CHANNEL_SELECT_REG 0x2 +#define CPLD_DESELECT_CHANNEL 0xFF + +#define ACCTON_I2C_CPLD_MUX_MAX_NCHANS NUM_OF_CPLD3_CHANS static LIST_HEAD(cpld_client_list); -static struct mutex list_lock; +static struct mutex list_lock; struct cpld_client_node { - struct i2c_client *client; - struct list_head list; + struct i2c_client *client; + struct list_head list; }; enum cpld_mux_type { @@ -79,10 +63,13 @@ enum cpld_mux_type { as6812_32x_cpld1 }; -struct accton_i2c_cpld_mux { - enum cpld_mux_type type; - struct i2c_adapter *virt_adaps[ACCTON_I2C_CPLD_MUX_MAX_NCHANS]; - u8 last_chan; /* last register value */ +struct as6812_32x_cpld_data { + enum cpld_mux_type type; + struct i2c_adapter *virt_adaps[ACCTON_I2C_CPLD_MUX_MAX_NCHANS]; + u8 last_chan; /* last register value */ + + struct device *hwmon_dev; + struct mutex update_lock; }; struct chip_desc { @@ -106,18 +93,289 @@ static const struct chip_desc chips[] = { } }; -static const struct i2c_device_id accton_i2c_cpld_mux_id[] = { +static const struct i2c_device_id as6812_32x_cpld_mux_id[] = { { "as6812_32x_cpld1", as6812_32x_cpld1 }, { "as6812_32x_cpld2", as6812_32x_cpld2 }, { "as6812_32x_cpld3", as6812_32x_cpld3 }, { } }; -MODULE_DEVICE_TABLE(i2c, accton_i2c_cpld_mux_id); +MODULE_DEVICE_TABLE(i2c, as6812_32x_cpld_mux_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as6812_32x_cpld_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as6812_32x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as6812_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); + +static struct attribute *as6812_32x_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as6812_32x_cpld1_group = { + .attrs = as6812_32x_cpld1_attributes, +}; + +static struct attribute *as6812_32x_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + NULL +}; + +static const struct attribute_group as6812_32x_cpld2_group = { + .attrs = as6812_32x_cpld2_attributes, +}; + +static struct attribute *as6812_32x_cpld3_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + NULL +}; + +static const struct attribute_group as6812_32x_cpld3_group = { + .attrs = as6812_32x_cpld3_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[2] = {0}; + u8 regs[] = {0xA, 0xB}; + struct i2c_client *client = to_i2c_client(dev); + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as6812_32x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 32 in order */ + return sprintf(buf, "%.2x %.2x\n", values[0], values[1]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + default: + return 0; + } + + mutex_lock(&data->update_lock); + status = as6812_32x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", !(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as6812_32x_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} /* Write to mux register. Don't use i2c_transfer()/i2c_smbus_xfer() for this as they will try to lock adapter a second time */ -static int accton_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, - struct i2c_client *client, u8 val) +static int as6812_32x_cpld_mux_reg_write(struct i2c_adapter *adap, + struct i2c_client *client, u8 val) { unsigned long orig_jiffies; unsigned short flags; @@ -134,8 +392,8 @@ static int accton_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, orig_jiffies = jiffies; for (res = 0, try = 0; try <= adap->retries; try++) { res = adap->algo->smbus_xfer(adap, client->addr, flags, - I2C_SMBUS_WRITE, 0x2, - I2C_SMBUS_BYTE_DATA, &data); + I2C_SMBUS_WRITE, CPLD_CHANNEL_SELECT_REG, + I2C_SMBUS_BYTE_DATA, &data); if (res != -EAGAIN) break; if (time_after(jiffies, @@ -147,35 +405,35 @@ static int accton_i2c_cpld_mux_reg_write(struct i2c_adapter *adap, return res; } -static int accton_i2c_cpld_mux_select_chan(struct i2c_adapter *adap, - void *client, u32 chan) +static int as6812_32x_cpld_mux_select_chan(struct i2c_adapter *adap, + void *client, u32 chan) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); u8 regval; int ret = 0; regval = chan; /* Only select the channel if its different from the last channel */ if (data->last_chan != regval) { - ret = accton_i2c_cpld_mux_reg_write(adap, client, regval); + ret = as6812_32x_cpld_mux_reg_write(adap, client, regval); data->last_chan = regval; } return ret; } -static int accton_i2c_cpld_mux_deselect_mux(struct i2c_adapter *adap, +static int as6812_32x_cpld_mux_deselect_mux(struct i2c_adapter *adap, void *client, u32 chan) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); /* Deselect active channel */ data->last_chan = chips[data->type].deselectChan; - return accton_i2c_cpld_mux_reg_write(adap, client, data->last_chan); + return as6812_32x_cpld_mux_reg_write(adap, client, data->last_chan); } -static void accton_i2c_cpld_add_client(struct i2c_client *client) +static void as6812_32x_cpld_add_client(struct i2c_client *client) { struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); @@ -191,7 +449,7 @@ static void accton_i2c_cpld_add_client(struct i2c_client *client) mutex_unlock(&list_lock); } -static void accton_i2c_cpld_remove_client(struct i2c_client *client) +static void as6812_32x_cpld_remove_client(struct i2c_client *client) { struct list_head *list_node = NULL; struct cpld_client_node *cpld_node = NULL; @@ -217,177 +475,250 @@ static void accton_i2c_cpld_remove_client(struct i2c_client *client) mutex_unlock(&list_lock); } -static ssize_t show_cpld_version(struct device *dev, struct device_attribute *attr, char *buf) +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) { - u8 reg = 0x1; - struct i2c_client *client; - int len; + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); - client = to_i2c_client(dev); - len = sprintf(buf, "%d", i2c_smbus_read_byte_data(client, reg)); - - return len; + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); } -static struct device_attribute ver = __ATTR(version, 0600, show_cpld_version, NULL); - /* * I2C init/probing/exit functions */ -static int accton_i2c_cpld_mux_probe(struct i2c_client *client, +static int as6812_32x_cpld_mux_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); int chan=0; - struct accton_i2c_cpld_mux *data; + struct as6812_32x_cpld_data *data; int ret = -ENODEV; + const struct attribute_group *group = NULL; if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) - goto err; + goto exit; - data = kzalloc(sizeof(struct accton_i2c_cpld_mux), GFP_KERNEL); + data = kzalloc(sizeof(struct as6812_32x_cpld_data), GFP_KERNEL); if (!data) { ret = -ENOMEM; - goto err; + goto exit; } i2c_set_clientdata(client, data); - + mutex_init(&data->update_lock); data->type = id->driver_data; - if (data->type == as6812_32x_cpld2 || data->type == as6812_32x_cpld3) { - data->last_chan = chips[data->type].deselectChan; /* force the first selection */ + if (data->type == as6812_32x_cpld2 || data->type == as6812_32x_cpld3) { + data->last_chan = chips[data->type].deselectChan; /* force the first selection */ - /* Now create an adapter for each channel */ - for (chan = 0; chan < chips[data->type].nchans; chan++) { - data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &client->dev, client, 0, chan, -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,7,0) - I2C_CLASS_HWMON | I2C_CLASS_SPD, -#endif - accton_i2c_cpld_mux_select_chan, - accton_i2c_cpld_mux_deselect_mux); + /* Now create an adapter for each channel */ + for (chan = 0; chan < chips[data->type].nchans; chan++) { + data->virt_adaps[chan] = i2c_add_mux_adapter(adap, &client->dev, client, 0, chan, 0, + as6812_32x_cpld_mux_select_chan, + as6812_32x_cpld_mux_deselect_mux); - if (data->virt_adaps[chan] == NULL) { - ret = -ENODEV; - dev_err(&client->dev, "failed to register multiplexed adapter %d\n", chan); - goto virt_reg_failed; - } - } + if (data->virt_adaps[chan] == NULL) { + ret = -ENODEV; + dev_err(&client->dev, "failed to register multiplexed adapter %d\n", chan); + goto exit_mux_register; + } + } - dev_info(&client->dev, "registered %d multiplexed busses for I2C mux %s\n", - chan, client->name); - } + dev_info(&client->dev, "registered %d multiplexed busses for I2C mux %s\n", + chan, client->name); + } - accton_i2c_cpld_add_client(client); + /* Register sysfs hooks */ + switch (data->type) { + case as6812_32x_cpld1: + group = &as6812_32x_cpld1_group; + break; + case as6812_32x_cpld2: + group = &as6812_32x_cpld2_group; + break; + case as6812_32x_cpld3: + group = &as6812_32x_cpld3_group; + break; + default: + break; + } - ret = sysfs_create_file(&client->dev.kobj, &ver.attr); - if (ret) - goto virt_reg_failed; + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_mux_register; + } + } - return 0; + as6812_32x_cpld_add_client(client); -virt_reg_failed: + return 0; + +exit_mux_register: for (chan--; chan >= 0; chan--) { i2c_del_mux_adapter(data->virt_adaps[chan]); - } - kfree(data); -err: + } + kfree(data); +exit: return ret; +} + +static int as6812_32x_cpld_mux_remove(struct i2c_client *client) +{ + struct as6812_32x_cpld_data *data = i2c_get_clientdata(client); + const struct chip_desc *chip = &chips[data->type]; + int chan; + const struct attribute_group *group = NULL; + + as6812_32x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as6812_32x_cpld1: + group = &as6812_32x_cpld1_group; + break; + case as6812_32x_cpld2: + group = &as6812_32x_cpld2_group; + break; + case as6812_32x_cpld3: + group = &as6812_32x_cpld3_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + for (chan = 0; chan < chip->nchans; ++chan) { + if (data->virt_adaps[chan]) { + i2c_del_mux_adapter(data->virt_adaps[chan]); + data->virt_adaps[chan] = NULL; + } + } + + kfree(data); + + return 0; } -static int accton_i2c_cpld_mux_remove(struct i2c_client *client) +static int as6812_32x_cpld_read_internal(struct i2c_client *client, u8 reg) { - struct accton_i2c_cpld_mux *data = i2c_get_clientdata(client); - const struct chip_desc *chip = &chips[data->type]; - int chan; + int status = 0, retry = I2C_RW_RETRY_COUNT; - sysfs_remove_file(&client->dev.kobj, &ver.attr); - - for (chan = 0; chan < chip->nchans; ++chan) { - if (data->virt_adaps[chan]) { - i2c_del_mux_adapter(data->virt_adaps[chan]); - data->virt_adaps[chan] = NULL; + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; } + + break; } - kfree(data); - accton_i2c_cpld_remove_client(client); - - return 0; + return status; } -int as6812_32x_i2c_cpld_read(unsigned short cpld_addr, u8 reg) +static int as6812_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) { - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EPERM; + int status = 0, retry = I2C_RW_RETRY_COUNT; - mutex_lock(&list_lock); - - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); - - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_read_byte_data(cpld_node->client, reg); - break; + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; } + + break; } + return status; +} + +int as6812_32x_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as6812_32x_cpld_read_internal(cpld_node->client, reg); + break; + } + } + mutex_unlock(&list_lock); - return ret; + return ret; } -EXPORT_SYMBOL(as6812_32x_i2c_cpld_read); +EXPORT_SYMBOL(as6812_32x_cpld_read); -int as6812_32x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +int as6812_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) { - struct list_head *list_node = NULL; - struct cpld_client_node *cpld_node = NULL; - int ret = -EIO; + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; mutex_lock(&list_lock); - list_for_each(list_node, &cpld_client_list) - { - cpld_node = list_entry(list_node, struct cpld_client_node, list); + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); - if (cpld_node->client->addr == cpld_addr) { - ret = i2c_smbus_write_byte_data(cpld_node->client, reg, value); - break; - } - } + if (cpld_node->client->addr == cpld_addr) { + ret = as6812_32x_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } mutex_unlock(&list_lock); - return ret; + return ret; } -EXPORT_SYMBOL(as6812_32x_i2c_cpld_write); +EXPORT_SYMBOL(as6812_32x_cpld_write); -static struct i2c_driver accton_i2c_cpld_mux_driver = { +static struct i2c_driver as6812_32x_cpld_mux_driver = { .driver = { .name = "as6812_32x_cpld", .owner = THIS_MODULE, }, - .probe = accton_i2c_cpld_mux_probe, - .remove = accton_i2c_cpld_mux_remove, - .id_table = accton_i2c_cpld_mux_id, + .probe = as6812_32x_cpld_mux_probe, + .remove = as6812_32x_cpld_mux_remove, + .id_table = as6812_32x_cpld_mux_id, }; -static int __init accton_i2c_cpld_mux_init(void) +static int __init as6812_32x_cpld_mux_init(void) { - mutex_init(&list_lock); - return i2c_add_driver(&accton_i2c_cpld_mux_driver); + mutex_init(&list_lock); + return i2c_add_driver(&as6812_32x_cpld_mux_driver); } -static void __exit accton_i2c_cpld_mux_exit(void) +static void __exit as6812_32x_cpld_mux_exit(void) { - i2c_del_driver(&accton_i2c_cpld_mux_driver); + i2c_del_driver(&as6812_32x_cpld_mux_driver); } MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("Accton I2C CPLD mux driver"); MODULE_LICENSE("GPL"); -module_init(accton_i2c_cpld_mux_init); -module_exit(accton_i2c_cpld_mux_exit); +module_init(as6812_32x_cpld_mux_init); +module_exit(as6812_32x_cpld_mux_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-fan.c index f0555674..7e5567df 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-fan.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-fan.c @@ -137,8 +137,8 @@ static ssize_t fan_set_duty_cycle(struct device *dev, static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); -extern int as6812_32x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int as6812_32x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as6812_32x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as6812_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); /*******************/ @@ -257,12 +257,12 @@ static const struct attribute_group accton_as6812_32x_fan_group = { static int accton_as6812_32x_fan_read_value(u8 reg) { - return as6812_32x_i2c_cpld_read(0x60, reg); + return as6812_32x_cpld_read(0x60, reg); } static int accton_as6812_32x_fan_write_value(u8 reg, u8 value) { - return as6812_32x_i2c_cpld_write(0x60, reg, value); + return as6812_32x_cpld_write(0x60, reg, value); } static void accton_as6812_32x_fan_update_device(struct device *dev) @@ -385,11 +385,6 @@ static struct platform_driver accton_as6812_32x_fan_driver = { static int __init accton_as6812_32x_fan_init(void) { int ret; - - extern int platform_accton_as6812_32x(void); - if(!platform_accton_as6812_32x()) { - return -ENODEV; - } ret = platform_driver_register(&accton_as6812_32x_fan_driver); if (ret < 0) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-leds.c index fd54ce06..691af597 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-leds.c @@ -29,8 +29,8 @@ #include #include -extern int as6812_32x_i2c_cpld_read (unsigned short cpld_addr, u8 reg); -extern int as6812_32x_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as6812_32x_cpld_read (unsigned short cpld_addr, u8 reg); +extern int as6812_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); extern void led_classdev_unregister(struct led_classdev *led_cdev); extern int led_classdev_register(struct device *parent, struct led_classdev *led_cdev); @@ -239,12 +239,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as6812_32x_led_read_value(u8 reg) { - return as6812_32x_i2c_cpld_read(0x60, reg); + return as6812_32x_cpld_read(0x60, reg); } static int accton_as6812_32x_led_write_value(u8 reg, u8 value) { - return as6812_32x_i2c_cpld_write(0x60, reg, value); + return as6812_32x_cpld_write(0x60, reg, value); } static void accton_as6812_32x_led_update(void) @@ -571,11 +571,6 @@ static int __init accton_as6812_32x_led_init(void) { int ret; - extern int platform_accton_as6812_32x(void); - if(!platform_accton_as6812_32x()) { - return -ENODEV; - } - ret = platform_driver_register(&accton_as6812_32x_led_driver); if (ret < 0) { goto exit; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-psu.c index a782870e..40d86b1c 100755 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-psu.c @@ -44,7 +44,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_serial_number(struct device *dev, struct device_attribute *da,char *buf); static int as6812_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int as6812_32x_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as6812_32x_cpld_read(unsigned short cpld_addr, u8 reg); static int as6812_32x_psu_model_name_get(struct device *dev, int get_serial); /* Addresses scanned @@ -415,7 +415,7 @@ static struct as6812_32x_psu_data *as6812_32x_psu_update_device(struct device *d data->valid = 0; /* Read psu status */ - status = as6812_32x_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); + status = as6812_32x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); if (status < 0) { dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); @@ -435,19 +435,9 @@ exit: return data; } -static int __init as6812_32x_psu_init(void) -{ - return i2c_add_driver(&as6812_32x_psu_driver); -} - -static void __exit as6812_32x_psu_exit(void) -{ - i2c_del_driver(&as6812_32x_psu_driver); -} +module_i2c_driver(as6812_32x_psu_driver); MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("as6812_32x_psu driver"); MODULE_LICENSE("GPL"); -module_init(as6812_32x_psu_init); -module_exit(as6812_32x_psu_exit); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-sfp.c deleted file mode 100644 index 362d87db..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/modules/builds/x86-64-accton-as6812-32x-sfp.c +++ /dev/null @@ -1,1532 +0,0 @@ -/* - * SFP driver for accton as6812_32x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as6812_32x_sfp" - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 32 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 10 -#define I2C_RW_RETRY_INTERVAL 60 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -#define MULTIPAGE_SUPPORT 1 - -#if (MULTIPAGE_SUPPORT == 1) -/* fundamental unit of addressing for SFF_8472/SFF_8436 */ -#define SFF_8436_PAGE_SIZE 128 -/* - * The current 8436 (QSFP) spec provides for only 4 supported - * pages (pages 0-3). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8436_SPECED_PAGES 4 -#define SFF_8436_EEPROM_SIZE ((1 + SFF_8436_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8436_EEPROM_UNPAGED_SIZE (2 * SFF_8436_PAGE_SIZE) -/* - * The current 8472 (SFP) spec provides for only 3 supported - * pages (pages 0-2). - * This driver is prepared to support more, but needs a register in the - * EEPROM to indicate how many pages are supported before it is safe - * to implement more pages in the driver. - */ -#define SFF_8472_SPECED_PAGES 3 -#define SFF_8472_EEPROM_SIZE ((3 + SFF_8472_SPECED_PAGES) * SFF_8436_PAGE_SIZE) -#define SFF_8472_EEPROM_UNPAGED_SIZE (4 * SFF_8436_PAGE_SIZE) - -/* a few constants to find our way around the EEPROM */ -#define SFF_8436_PAGE_SELECT_REG 0x7F -#define SFF_8436_PAGEABLE_REG 0x02 -#define SFF_8436_NOT_PAGEABLE (1<<2) -#define SFF_8472_PAGEABLE_REG 0x40 -#define SFF_8472_PAGEABLE (1<<4) - -/* - * 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 = SFF_8436_PAGE_SIZE; - -/* - * 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; - -typedef enum qsfp_opcode { - QSFP_READ_OP = 0, - QSFP_WRITE_OP = 1 -} qsfp_opcode_e; -#endif - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int as6812_32x_i2c_cpld_read (unsigned short cpld_addr, u8 reg); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as6812_32x_port1, as6812_32x_port2, as6812_32x_port3, as6812_32x_port4, as6812_32x_port5, as6812_32x_port6, as6812_32x_port7, as6812_32x_port8, -as6812_32x_port9, as6812_32x_port10, as6812_32x_port11, as6812_32x_port12, as6812_32x_port13, as6812_32x_port14, as6812_32x_port15, as6812_32x_port16, -as6812_32x_port17, as6812_32x_port18, as6812_32x_port19, as6812_32x_port20, as6812_32x_port21, as6812_32x_port22, as6812_32x_port23, as6812_32x_port24, -as6812_32x_port25, as6812_32x_port26, as6812_32x_port27, as6812_32x_port28, as6812_32x_port29, as6812_32x_port30, as6812_32x_port31, as6812_32x_port32 -}; - -#define I2C_DEV_ID(x) { #x, x} - -static const struct i2c_device_id sfp_device_id[] = { -I2C_DEV_ID(as6812_32x_port1), -I2C_DEV_ID(as6812_32x_port2), -I2C_DEV_ID(as6812_32x_port3), -I2C_DEV_ID(as6812_32x_port4), -I2C_DEV_ID(as6812_32x_port5), -I2C_DEV_ID(as6812_32x_port6), -I2C_DEV_ID(as6812_32x_port7), -I2C_DEV_ID(as6812_32x_port8), -I2C_DEV_ID(as6812_32x_port9), -I2C_DEV_ID(as6812_32x_port10), -I2C_DEV_ID(as6812_32x_port11), -I2C_DEV_ID(as6812_32x_port12), -I2C_DEV_ID(as6812_32x_port13), -I2C_DEV_ID(as6812_32x_port14), -I2C_DEV_ID(as6812_32x_port15), -I2C_DEV_ID(as6812_32x_port16), -I2C_DEV_ID(as6812_32x_port17), -I2C_DEV_ID(as6812_32x_port18), -I2C_DEV_ID(as6812_32x_port19), -I2C_DEV_ID(as6812_32x_port20), -I2C_DEV_ID(as6812_32x_port21), -I2C_DEV_ID(as6812_32x_port22), -I2C_DEV_ID(as6812_32x_port23), -I2C_DEV_ID(as6812_32x_port24), -I2C_DEV_ID(as6812_32x_port25), -I2C_DEV_ID(as6812_32x_port26), -I2C_DEV_ID(as6812_32x_port27), -I2C_DEV_ID(as6812_32x_port28), -I2C_DEV_ID(as6812_32x_port29), -I2C_DEV_ID(as6812_32x_port30), -I2C_DEV_ID(as6812_32x_port31), -I2C_DEV_ID(as6812_32x_port32), -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct qsfp_data *qsfp; - - struct i2c_client *client; -#if (MULTIPAGE_SUPPORT == 1) - int use_smbus; - u8 *writebuf; - unsigned write_max; -#endif -}; - -#if (MULTIPAGE_SUPPORT == 1) -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode); -#endif -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - - /* Read present status of port 1~32 */ - data->present = 0; - - for (i = 0; i < 2; i++) { - for (j = 0; j < 2; j++) { - status = as6812_32x_i2c_cpld_read(0x62+i*2, 0xA+j); - - if (status < 0) { - DEBUG_PRINT("cpld(0x%x) reg(0x%x) err %d", 0x62+i*2, 0xA+j, status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); - data->present |= (u64)status << ((i*16) + (j*8)); - } - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -/* Platform dependent --- */ - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return (data->present & BIT_INDEX(data->port)) ? 0 : 1; /* Platform dependent */ -} - -/* Platform dependent +++ */ -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[4] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3]); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - if (disable) { - data->qsfp->status[1] |= 0xF; - } - else { - data->qsfp->status[1] &= ~0xF; - } - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -#if (MULTIPAGE_SUPPORT == 0) -static ssize_t sfp_port_write(struct sfp_port_data *data, - 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(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} -#endif - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_WRITE_OP); -#else - return sfp_port_write(data, buf, off, count); -#endif -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -/*-------------------------------------------------------------------------*/ -/* - * This routine computes the addressing information to be used for - * a given r/w request. - * - * Task is to calculate the client (0 = i2c addr 50, 1 = i2c addr 51), - * the page, and the offset. - * - * Handles both SFP and QSFP. - * For SFP, offset 0-255 are on client[0], >255 is on client[1] - * Offset 256-383 are on the lower half of client[1] - * Pages are accessible on the upper half of client[1]. - * Offset >383 are in 128 byte pages mapped into the upper half - * - * For QSFP, all offsets are on client[0] - * offset 0-127 are on the lower half of client[0] (no paging) - * Pages are accessible on the upper half of client[1]. - * Offset >127 are in 128 byte pages mapped into the upper half - * - * Callers must not read/write beyond the end of a client or a page - * without recomputing the client/page. Hence offset (within page) - * plus length must be less than or equal to 128. (Note that this - * routine does not have access to the length of the call, hence - * cannot do the validity check.) - * - * Offset within Lower Page 00h and Upper Page 00h are not recomputed - */ -static uint8_t sff_8436_translate_offset(struct sfp_port_data *port_data, - loff_t *offset, struct i2c_client **client) -{ - unsigned page = 0; - - *client = port_data->client; - - /* - * if offset is in the range 0-128... - * page doesn't matter (using lower half), return 0. - * offset is already correct (don't add 128 to get to paged area) - */ - if (*offset < SFF_8436_PAGE_SIZE) - return page; - - /* note, page will always be positive since *offset >= 128 */ - page = (*offset >> 7)-1; - /* 0x80 places the offset in the top half, offset is last 7 bits */ - *offset = SFF_8436_PAGE_SIZE + (*offset & 0x7f); - - return page; /* note also returning client and offset */ -} - -static ssize_t sff_8436_eeprom_read(struct sfp_port_data *port_data, - struct i2c_client *client, - char *buf, unsigned offset, size_t count) -{ - struct i2c_msg msg[2]; - u8 msgbuf[2]; - unsigned long timeout, read_time; - int status, i; - - memset(msg, 0, sizeof(msg)); - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* - * When we have a better choice than SMBus calls, use a - * combined I2C message. Write address; then read up to - * io_limit data bytes. msgbuf is u8 and will cast to our - * needs. - */ - i = 0; - msgbuf[i++] = offset; - - msg[0].addr = client->addr; - msg[0].buf = msgbuf; - msg[0].len = i; - - msg[1].addr = client->addr; - msg[1].flags = I2C_M_RD; - msg[1].buf = buf; - msg[1].len = count; - } - - /* - * 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; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_read_i2c_block_data(client, offset, - count, buf); - break; - case I2C_SMBUS_WORD_DATA: - status = i2c_smbus_read_word_data(client, offset); - if (status >= 0) { - buf[0] = status & 0xff; - if (count == 2) - buf[1] = status >> 8; - status = count; - } - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_read_byte_data(client, offset); - if (status >= 0) { - buf[0] = status; - status = count; - } - break; - default: - status = i2c_transfer(client->adapter, msg, 2); - if (status == 2) - status = count; - } - - dev_dbg(&client->dev, "eeprom read %zu@%d --> %d (%ld)\n", - count, offset, status, jiffies); - - if (status == count) /* happy path */ - return count; - - if (status == -ENXIO) /* no module present */ - return status; - - /* REVISIT: at HZ=100, this is sloooow */ - msleep(1); - } while (time_before(read_time, timeout)); - - return -ETIMEDOUT; -} - -static ssize_t sff_8436_eeprom_write(struct sfp_port_data *port_data, - struct i2c_client *client, - const char *buf, - unsigned offset, size_t count) -{ - struct i2c_msg msg; - ssize_t status; - unsigned long timeout, write_time; - unsigned next_page_start; - int i = 0; - - /* write max is at most a page - * (In this driver, write_max is actually one byte!) - */ - if (count > port_data->write_max) - count = port_data->write_max; - - /* shorten count if necessary to avoid crossing page boundary */ - next_page_start = roundup(offset + 1, SFF_8436_PAGE_SIZE); - if (offset + count > next_page_start) - count = next_page_start - offset; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - /*smaller eeproms can work given some SMBus extension calls */ - if (count > I2C_SMBUS_BLOCK_MAX) - count = I2C_SMBUS_BLOCK_MAX; - break; - case I2C_SMBUS_WORD_DATA: - /* Check for odd length transaction */ - count = (count == 1) ? 1 : 2; - break; - case I2C_SMBUS_BYTE_DATA: - count = 1; - break; - default: - /* If we'll use I2C calls for I/O, set up the message */ - msg.addr = client->addr; - msg.flags = 0; - - /* msg.buf is u8 and casts will mask the values */ - msg.buf = port_data->writebuf; - - msg.buf[i++] = offset; - memcpy(&msg.buf[i], buf, count); - msg.len = i + count; - break; - } - - /* - * 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 { - write_time = jiffies; - - switch (port_data->use_smbus) { - case I2C_SMBUS_I2C_BLOCK_DATA: - status = i2c_smbus_write_i2c_block_data(client, - offset, count, buf); - if (status == 0) - status = count; - break; - case I2C_SMBUS_WORD_DATA: - if (count == 2) { - status = i2c_smbus_write_word_data(client, - offset, (u16)((buf[0])|(buf[1] << 8))); - } else { - /* count = 1 */ - status = i2c_smbus_write_byte_data(client, - offset, buf[0]); - } - if (status == 0) - status = count; - break; - case I2C_SMBUS_BYTE_DATA: - status = i2c_smbus_write_byte_data(client, offset, - buf[0]); - if (status == 0) - status = count; - break; - default: - status = i2c_transfer(client->adapter, &msg, 1); - if (status == 1) - status = count; - break; - } - - dev_dbg(&client->dev, "eeprom write %zu@%d --> %ld (%lu)\n", - count, offset, (long int) 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 sff_8436_eeprom_update_client(struct sfp_port_data *port_data, - char *buf, loff_t off, - size_t count, qsfp_opcode_e opcode) -{ - struct i2c_client *client; - ssize_t retval = 0; - u8 page = 0; - loff_t phy_offset = off; - int ret = 0; - - page = sff_8436_translate_offset(port_data, &phy_offset, &client); - - dev_dbg(&client->dev, - "sff_8436_eeprom_update_client off %lld page:%d phy_offset:%lld, count:%ld, opcode:%d\n", - off, page, phy_offset, (long int) count, opcode); - if (page > 0) { - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_dbg(&client->dev, - "Write page register for page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - - while (count) { - ssize_t status; - - if (opcode == QSFP_READ_OP) { - status = sff_8436_eeprom_read(port_data, client, - buf, phy_offset, count); - } else { - status = sff_8436_eeprom_write(port_data, client, - buf, phy_offset, count); - } - if (status <= 0) { - if (retval == 0) - retval = status; - break; - } - buf += status; - phy_offset += status; - count -= status; - retval += status; - } - - - if (page > 0) { - /* return the page register to page 0 (why?) */ - page = 0; - ret = sff_8436_eeprom_write(port_data, client, &page, - SFF_8436_PAGE_SELECT_REG, 1); - if (ret < 0) { - dev_err(&client->dev, - "Restore page register to page %d failed ret:%d!\n", - page, ret); - return ret; - } - } - return retval; -} - - -/* - * Figure out if this access is within the range of supported pages. - * Note this is called on every access because we don't know if the - * module has been replaced since the last call. - * If/when modules support more pages, this is the routine to update - * to validate and allow access to additional pages. - * - * Returns updated len for this access: - * - entire access is legal, original len is returned. - * - access begins legal but is too long, len is truncated to fit. - * - initial offset exceeds supported pages, return -EINVAL - */ -static ssize_t sff_8436_page_legal(struct sfp_port_data *port_data, - loff_t off, size_t len) -{ - struct i2c_client *client = port_data->client; - u8 regval; - int status; - size_t maxlen; - - if (off < 0) return -EINVAL; - if (port_data->driver_type == DRIVER_TYPE_SFP_MSA) { - /* SFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= SFF_8472_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8472_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8472_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8472_PAGEABLE) { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8472_EEPROM_SIZE - off; - } else { - /* pages not supported, trim len to unpaged size */ - maxlen = SFF_8472_EEPROM_UNPAGED_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, SFP, off %lld len %ld\n", - off, (long int) len); - } - else if (port_data->driver_type == DRIVER_TYPE_QSFP) { - /* QSFP case */ - /* if no pages needed, we're good */ - if ((off + len) <= SFF_8436_EEPROM_UNPAGED_SIZE) return len; - /* if offset exceeds possible pages, we're not good */ - if (off >= SFF_8436_EEPROM_SIZE) return -EINVAL; - /* in between, are pages supported? */ - status = sff_8436_eeprom_read(port_data, client, ®val, - SFF_8436_PAGEABLE_REG, 1); - if (status < 0) return status; /* error out (no module?) */ - if (regval & SFF_8436_NOT_PAGEABLE) { - /* pages not supported, trim len to unpaged size */ - maxlen = SFF_8436_EEPROM_UNPAGED_SIZE - off; - } else { - /* Pages supported, trim len to the end of pages */ - maxlen = SFF_8436_EEPROM_SIZE - off; - } - len = (len > maxlen) ? maxlen : len; - dev_dbg(&client->dev, - "page_legal, QSFP, off %lld len %ld\n", - off, (long int) len); - } - else { - return -EINVAL; - } - return len; -} - - -static ssize_t sfp_port_read_write(struct sfp_port_data *port_data, - char *buf, loff_t off, size_t len, qsfp_opcode_e opcode) -{ - struct i2c_client *client = port_data->client; - int chunk; - int status = 0; - ssize_t retval; - size_t pending_len = 0, chunk_len = 0; - loff_t chunk_offset = 0, chunk_start_offset = 0; - - if (unlikely(!len)) - return len; - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&port_data->update_lock); - - /* - * Confirm this access fits within the device suppored addr range - */ - len = sff_8436_page_legal(port_data, off, len); - if (len < 0) { - status = len; - goto err; - } - - /* - * For each (128 byte) chunk involved in this request, issue a - * separate call to sff_eeprom_update_client(), to - * ensure that each access recalculates the client/page - * and writes the page register as needed. - * Note that chunk to page mapping is confusing, is different for - * QSFP and SFP, and never needs to be done. Don't try! - */ - pending_len = len; /* amount remaining to transfer */ - retval = 0; /* amount transferred */ - for (chunk = off >> 7; chunk <= (off + len - 1) >> 7; chunk++) { - - /* - * Compute the offset and number of bytes to be read/write - * - * 1. start at offset 0 (within the chunk), and read/write - * the entire chunk - * 2. start at offset 0 (within the chunk) and read/write less - * than entire chunk - * 3. start at an offset not equal to 0 and read/write the rest - * of the chunk - * 4. start at an offset not equal to 0 and read/write less than - * (end of chunk - offset) - */ - chunk_start_offset = chunk * SFF_8436_PAGE_SIZE; - - if (chunk_start_offset < off) { - chunk_offset = off; - if ((off + pending_len) < (chunk_start_offset + - SFF_8436_PAGE_SIZE)) - chunk_len = pending_len; - else - chunk_len = (chunk+1)*SFF_8436_PAGE_SIZE - off;/*SFF_8436_PAGE_SIZE - off;*/ - } else { - chunk_offset = chunk_start_offset; - if (pending_len > SFF_8436_PAGE_SIZE) - chunk_len = SFF_8436_PAGE_SIZE; - else - chunk_len = pending_len; - } - - dev_dbg(&client->dev, - "sff_r/w: off %lld, len %ld, chunk_start_offset %lld, chunk_offset %lld, chunk_len %ld, pending_len %ld\n", - off, (long int) len, chunk_start_offset, chunk_offset, - (long int) chunk_len, (long int) pending_len); - - /* - * note: chunk_offset is from the start of the EEPROM, - * not the start of the chunk - */ - status = sff_8436_eeprom_update_client(port_data, buf, - chunk_offset, chunk_len, opcode); - if (status != chunk_len) { - /* This is another 'no device present' path */ - dev_dbg(&client->dev, - "sff_8436_update_client for chunk %d chunk_offset %lld chunk_len %ld failed %d!\n", - chunk, chunk_offset, (long int) chunk_len, status); - goto err; - } - buf += status; - pending_len -= status; - retval += status; - } - mutex_unlock(&port_data->update_lock); - - return retval; - -err: - mutex_unlock(&port_data->update_lock); - - return status; -} - -#else -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} -#endif - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - -#if (MULTIPAGE_SUPPORT == 1) - return sfp_port_read_write(data, buf, off, count, QSFP_READ_OP); -#else - return sfp_port_read(data, buf, off, count); -#endif -} - -#if (MULTIPAGE_SUPPORT == 1) -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom, size_t size) -#else -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -#endif -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; -#if (MULTIPAGE_SUPPORT == 1) - eeprom->size = size; -#else - eeprom->size = EEPROM_SIZE; -#endif - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - - -#if (MULTIPAGE_SUPPORT == 0) -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} -#endif - - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - -#if (MULTIPAGE_SUPPORT == 0) - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } -#endif - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ -#if (MULTIPAGE_SUPPORT == 1) - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin, SFF_8436_EEPROM_SIZE); -#else - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); -#endif - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - int ret = 0; - struct sfp_port_data *data = NULL; - - if (client->addr != SFP_EEPROM_A0_I2C_ADDR) { - return -ENODEV; - } - - if (dev_id->driver_data < as6812_32x_port1 || dev_id->driver_data > as6812_32x_port32) { - return -ENXIO; - } - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - -#if (MULTIPAGE_SUPPORT == 1) - data->use_smbus = 0; - - /* 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)) { - data->use_smbus = I2C_SMBUS_I2C_BLOCK_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_WORD_DATA)) { - data->use_smbus = I2C_SMBUS_WORD_DATA; - } else if (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_READ_BYTE_DATA)) { - data->use_smbus = I2C_SMBUS_BYTE_DATA; - } else { - ret = -EPFNOSUPPORT; - goto exit_kfree; - } - } - - if (!data->use_smbus || - (i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_WORD_DATA) || - i2c_check_functionality(client->adapter, - I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) { - /* - * NOTE: AN-2079 - * Finisar recommends that the host implement 1 byte writes - * only since this module only supports 32 byte page boundaries. - * 2 byte writes are acceptable for PE and Vout changes per - * Application Note AN-2071. - */ - unsigned write_max = 1; - - if (write_max > io_limit) - write_max = io_limit; - if (data->use_smbus && write_max > I2C_SMBUS_BLOCK_MAX) - write_max = I2C_SMBUS_BLOCK_MAX; - data->write_max = write_max; - - /* buffer (data + address at the beginning) */ - data->writebuf = kmalloc(write_max + 2, GFP_KERNEL); - if (!data->writebuf) { - ret = -ENOMEM; - goto exit_kfree; - } - } else { - dev_warn(&client->dev, - "cannot write due to controller restrictions."); - } - - if (data->use_smbus == I2C_SMBUS_WORD_DATA || - data->use_smbus == I2C_SMBUS_BYTE_DATA) { - dev_notice(&client->dev, "Falling back to %s reads, " - "performance will suffer\n", data->use_smbus == - I2C_SMBUS_WORD_DATA ? "word" : "byte"); - } -#endif - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - data->driver_type = DRIVER_TYPE_QSFP; - - ret = qsfp_probe(client, dev_id, &data->qsfp); - if (ret < 0) { - goto exit_kfree_buf; - } - - return ret; - -exit_kfree_buf: -#if (MULTIPAGE_SUPPORT == 1) - if (data->writebuf) kfree(data->writebuf); -#endif - -exit_kfree: - kfree(data); - return ret; -} -/* Platform dependent --- */ - -static int qsfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - int ret = 0; - struct sfp_port_data *data = i2c_get_clientdata(client); -#if (MULTIPAGE_SUPPORT == 1) - kfree(data->writebuf); -#endif - - if (data->driver_type == DRIVER_TYPE_QSFP) { - ret = qsfp_remove(client, data->qsfp); - } - - kfree(data); - return ret; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as6812_32x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(sfp_init); -module_exit(sfp_exit); - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c index 10288992..20a5a884 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/onlp/builds/src/module/src/sfpi.c @@ -24,35 +24,17 @@ * ***********************************************************/ #include - -#include /* For O_RDWR && open */ -#include -#include -#include -#include - -#include "platform_lib.h" +#include #include +#include "x86_64_accton_as6812_32x_int.h" +#include "x86_64_accton_as6812_32x_log.h" -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define FRONT_PORT_TO_CPLD_MUX_INDEX(port) (port+2) +#define PORT_BUS_INDEX(port) (port+2) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/0-00%d/module_present_%d" +#define MODULE_PRESENT_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/0-0062/module_present_all" +#define MODULE_PRESENT_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/0-0064/module_present_all" -static int -as6812_32x_sfp_node_read_int(char *node_path, int *value, int data_len) -{ - return onlp_file_read_int(value, node_path); -} - -static char* -as6812_32x_sfp_get_port_path(int port, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-0050/%s", - FRONT_PORT_TO_CPLD_MUX_INDEX(port), - node_name); - - return sfp_node_path; -} /************************************************************ * @@ -91,12 +73,13 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char* path = as6812_32x_sfp_get_port_path(port, "sfp_is_present"); - - if (as6812_32x_sfp_node_read_int(path, &present, 1) != 0) { + int addr = (port < 16) ? 62 : 64; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } + return present; } @@ -104,27 +87,34 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[4]; - char* path; + uint32_t *ptr = bytes; FILE* fp; - path = as6812_32x_sfp_get_port_path(0, "sfp_is_present_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~31 */ + int addr; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3 - ); - fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { - /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 62; addr <= 64; addr+=2) { + if (addr == 62) { + fp = fopen(MODULE_PRESENT_ALL_ATTR_CPLD2, "r"); + } + else { + fp = fopen(MODULE_PRESENT_ALL_ATTR_CPLD3, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x", ptr+0, ptr+1); + fclose(fp); + if(count != 2) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_present_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Convert to 64 bit integer in port order */ @@ -153,21 +143,25 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = as6812_32x_sfp_get_port_path(port, "sfp_eeprom"); - /* * Read the SFP eeprom into data[] * * Return MISSING if SFP is missing. * Return OK if eeprom is read */ + int size = 0; memset(data, 0, 256); - if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) { + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; } @@ -176,3 +170,4 @@ onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/platform-config/r0/src/python/x86_64_accton_as6812_32x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/platform-config/r0/src/python/x86_64_accton_as6812_32x_r0/__init__.py index 43c9b7d8..115f08b9 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/platform-config/r0/src/python/x86_64_accton_as6812_32x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as6812-32x/platform-config/r0/src/python/x86_64_accton_as6812_32x_r0/__init__.py @@ -8,9 +8,10 @@ class OnlPlatform_x86_64_accton_as6812_32x_r0(OnlPlatformAccton, SYS_OBJECT_ID=".6812.32" def baseconfig(self): + self.insmod('optoe') self.insmod('cpr_4011_4mxx') self.insmod("ym2651y") - for m in [ 'cpld', 'fan', 'psu', 'leds', 'sfp' ]: + for m in [ 'cpld', 'fan', 'psu', 'leds' ]: self.insmod("x86-64-accton-as6812-32x-%s.ko" % m) ########### initialize I2C bus 0 ########### @@ -25,9 +26,8 @@ class OnlPlatform_x86_64_accton_as6812_32x_r0(OnlPlatformAccton, # initialize QSFP port 1~32 for port in range(1, 33): - self.new_i2c_device('as6812_32x_port%d' % port, - 0x50, - port+1) + self.new_i2c_device('optoe1', 0x50, port+1) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+1), shell=True) ########### initialize I2C bus 1 ########### self.new_i2c_devices( From c3fb9e5abe94cecf4d492419ccbb5f6bf31a48a2 Mon Sep 17 00:00:00 2001 From: Steven Noble Date: Tue, 20 Mar 2018 05:39:51 +0000 Subject: [PATCH 10/21] Updating SupportedHardware.md to match new HCL --- docs/SupportedHardware.md | 183 ++++++++++++++++++++------------------ 1 file changed, 95 insertions(+), 88 deletions(-) diff --git a/docs/SupportedHardware.md b/docs/SupportedHardware.md index 4e0e2b0f..658ee98b 100644 --- a/docs/SupportedHardware.md +++ b/docs/SupportedHardware.md @@ -1,107 +1,114 @@ Hardware Support ================ -Because of the HTML formatting, this page may be best viewed from - - - -Quanta ------- - - - - - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab OF-DPA OpenNSL SAI
QuantaMesh T1048-LB9 48x1G + 4x10G FreeScale P2020 Broadcom BCM56534 (Firebolt3) Yes Yes No No No
QuantaMesh T3048-LY2 48x10G + 4x40G FreeScale P2020 Broadcom BCM56846 (Trident+) Yes Yes No No No
QuantaMesh T3048-LY8 48x10G + 6x40G Intel Rangeley C2758 x86 Broadcom BCM56854 (Trident2) Yes Yes No No No
QuantaMesh T5032-LY6 32x40G Intel Rangeley C2758 x86 Broadcom BCM56850 (Trident2) Yes Yes No No No
QuantaMesh T3048-LY9 48x10GT + 6x40G Intel Rangeley C2758 x86 Broadcom BCM56850 (Trident2) Yes Yes No No No
- Accton/Edge-Core ------ - - - - - - - - - - - - - - - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab OF-DPA OpenNSL SAI
Accton AS4600-54T 48x1G + 4x10G FreeScale P2020 Broadcom BCM56540 (Apollo2) Yes Yes Yes*** Yes*** No
Accton AS4610-54P 48x1G + 4x10G + 2x20G Dual-core ARM Cortex A9 1GHz Broadcom BCM56340 (Helix4) Yes Yes No No No
Accton AS5610-52X 48x10G + 4x40G FreeScale P2020 Broadcom BCM56846 (Trident+) Yes Yes No No No
Accton AS5710-54X 48x10G + 6x40G FreeScale P2041 Broadcom BCM56854 (Trident2) Yes Yes Yes*** Yes*** No
Accton AS6700-32X 32x40G FreeScale P2041 Broadcom BCM56850 (Trident2) Yes Yes No No No
Accton AS5512-54X 48x10G + 6x40G Intel Rangeley C2538 x86 MediaTek/Nephos MT3258 Yes Yes No No No
Accton AS5712-54X 48x10G + 6x40G Intel Rangeley C2538 x86 Broadcom BCM56854 (Trident2) Yes Yes Yes*** Yes*** No
Accton AS6712-32X 32x40G Intel Rangeley C2538 x86 Broadcom BCM56850 (Trident2) Yes Yes Yes*** Yes*** No
Accton AS5812-54T 48x10G + 6x40G Intel Rangeley C2538 x86 Broadcom BCM56864 (Trident2+) Yes Yes No No No
Accton AS5812-54X 48x10G + 6x40G Intel Rangeley C2538 x86 Broadcom BCM56864 (Trident2+) Yes Yes Yes*** Yes*** No
Accton AS6812-32X 32x40G Intel Rangeley C2538 x86 Broadcom BCM56864 (Trident2+) Yes Yes Yes*** Yes*** No
Accton AS7712-32X 32x100G Intel Rangeley C2538 x86 Broadcom BCM56960 (Tomahawk) Yes Yes Yes*** Yes*** No
Accton AS7716-32X 32x100G Intel Xeon D-1518 x86 Broadcom BCM56960 (Tomahawk) Yes Yes Yes*** Yes*** No
Accton Wedge-16X 16x40G Intel Rangeley C2550 x86 Broadcom BCM56864 (Trident2+) Work In Progress** Yes No Yes No
Accton (FB) Wedge 100 32x100G Intel Bay Trail E3845 x86 Broadcom BCM56960 (Tomahawk) Work In Progress** Yes No Yes No
+Device Ports CPU Forwarding In Lab +Accton AS4600-54T 48x1G + 4x10G FreeScale P2020 Broadcom BCM56540 (Apollo2) Yes +Accton AS4610-54P 48x1G + 4x10G + 2x20G Dual-core ARM Cortex A9 Broadcom BCM56340 (Helix4) Yes +Accton AS5512-54X 48x10G + 6x40G Intel C2538 MediaTek/Nephos MT3258 Yes +Accton AS5610-52X 48x10G + 4x40G FreeScale P2020 Broadcom BCM56846 (Trident+) Yes +Accton AS5710-54X 48x10G + 6x40G FreeScale P2041 Broadcom BCM56854 (Trident2) Yes +Accton AS5712-54X 48x10G + 6x40G Intel C2538 Broadcom BCM56854 (Trident2) Yes +Accton AS5812-54T 48x10G + 6x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Accton AS5812-54X 48x10G + 6x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Accton AS5822-32X 48x10G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) Yes +Accton AS5912-54X 48x10G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) Yes +Accton AS5912-54XK 48x10G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) Yes +Accton AS5916-54XM 48x10G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) No +Accton AS5916-54X 48x10G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) No +Accton AS6700-32X 32x40G FreeScale P2041 Broadcom BCM56850 (Trident2) Yes +Accton AS6712-32X 32x40G Intel C2538 Broadcom BCM56850 (Trident2) Yes +Accton AS6812-32X 32x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Accton AS7312-54X 48x25G + 6x100G Intel C2558 Broadcom BCM88375 (Qumran) Yes +Accton AS7712-32X 32x100G Intel C2538 Broadcom BCM56960 (Tomahawk) Yes +Accton AS7716-32X 32x100G Intel Xeon D-1518 Broadcom BCM56960 (Tomahawk) Yes +Accton AS7816-64X 64x100 Intel C2558 Broadcom BCM56970 (Tomahawk II) Yes +Accton Wedge-16X 16x40G Intel C2550 Broadcom BCM56864 (Trident2+) Yes +Accton Wedge 100-32X 32x100G Intel E3845 Broadcom BCM56960 (Tomahawk) Yes +Accton Wedge 100S-32X 32x100G Intel D1508 Broadcom BCM56960 (Tomahawk) Yes + +Alpha Networks +--- +Device Ports CPU Forwarding In Lab +SNX-60A0-486F 48x10G + 6x40G Intel C2558 Broadcom BCM56850 (Trident2) Yes + +Celestica +--- +Device Ports CPU Forwarding In Lab +Redstone-XP 48x10G + 6x40G Intel C2558 Broadcom BCM56854 (Trident2) Yes +Seastone 32x100G Intel C2558 Broadcom BCM56960 (Tomahawk) No DNI/Agema --- - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab OF-DPA OpenNSL SAI
AG-7448CU 48x10G + 4x40G FreeScale P2020 Broadcom BCM56845 (Trident) Yes Yes No No No
+Device Ports CPU Forwarding In Lab +AG-7448CU 48x10G + 4x40G FreeScale P2020 Broadcom BCM56845 (Trident) Yes +AG-5648 48x25G + 6x100G Intel D1548 Broadcom BCM56960 (Tomahawk) No +AG-5648v1 48x25G + 6x100G Intel D1548 Broadcom BCM56963 (Tomahawk+) No +AG-7648 48x10G + 6x40G Intel D1548 Broadcom BCM56854 (Trident2) Yes +AG-9032v1 32x100G Intel D1548 Broadcom BCM56960 (Tomahawk) Yes +AG-9032v2 32x100G Intel D1548 Broadcom BCM56963 (Tomahawk+) No +AG-9064 64x100G Intel D1547 Broadcom BCM56970 (Tomahawk II) No +AGC-5648S 48x25G + 6x100G Intel D1548 Broadcom BCM88680 (Jericho+) No +AGC-7648A 48x10G + 6x100G Intel D1548 Broadcom BCM88370 (Qumran MX) No +WB-2448 48x1GT + 4x10G Intel E3805 Broadcom BCM56150 (Hurricane2) No +AG-6248C 48x1GT + 2x10G ARM A9 1GHz Broadcom BCM56340 (Helix4) Yes Dell --- - - - - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab OF-DPA OpenNSL SAI
S4810-ON 48x10G + 4x40G FreeScale P2020 Broadcom BCM56845 (Trident) Yes Yes No No No
S4048-ON 48x10G + 6x40G Intel Atom C2338 Broadcom BCM56854 (Trident2) Yes Yes No No No
S6000-ON 32x40G Intel Atom S1220 Broadcom BCM56850 (Trident2) Yes Yes No No No
Z9100-ON 32x100G Intel Atom C2538 Broadcom BCM56960 (Tomahawk) Yes Yes No No No
+Device Ports CPU Forwarding In Lab +S4000-ON 48x10G + 6x40G Intel C2338 Broadcom BCM56854 (Trident2) Yes +S4810-ON 48x10G + 4x40G FreeScale P2020 Broadcom BCM56845 (Trident) Yes +S4048-ON 48x10G + 6x40G Intel C2338 Broadcom BCM56854 (Trident2) Yes +S6000-ON 32x40G Intel S1220 Broadcom BCM56850 (Trident2) Yes +S6010-ON 32x40G Intel S1220 Broadcom BCM56850 (Trident2) Yes +S6100-ON 64x50G/128x25G Intel C2538 Broadcom BCM56960 (Tomahawk) Yes +Z9100-ON 32x100G Intel C2538 Broadcom BCM56960 (Tomahawk) Yes -Interface Masters Technologies, Inc. +HPE --- - - - - - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab OF-DPA OpenNSL SAI
Niagara 2948X12XLm 48x10G + 12x40G Intel/AMD x86 Broadcom BCM56850 (Trident2) Work In Progress** No Yes*** Yes*** No
Niagara 2960X6XLm 60x10G + 6x40G Intel/AMD x86 Broadcom BCM56850 (Trident2) Work In Progress** No Yes*** Yes*** No
Niagara 2972Xm 72x10G Intel/AMD x86 Broadcom BCM56850 (Trident2) Work In Progress** Yes Yes*** Yes*** No
Niagara 2932XL 32x40G Intel/AMD x86 Broadcom BCM56850 (Trident2) Work In Progress** No Yes*** Yes*** No
Niagara 2948X6XL 48x10G + 6x40G Intel/AMD x86 Broadcom BCM56850 (Trident2) Work In Progress** No Yes*** Yes No
+Device Ports CPU Forwarding In Lab +Altoline 6921 48x10G + 6x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Altoline 6921T 48x10G + 6x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Altoline 6941 32x40G Intel C2538 Broadcom BCM56864 (Trident2+) Yes +Altoline 6960 32x100G Intel C2538 Broadcom BCM56960 (Tomahawk) Yes + +Ingrasys +--- +Device Ports CPU Forwarding In Lab +S9100-32X 32x100G Intel Broadcom BCM56960 (Tomahawk) No + +Inventec +--- +Device Ports CPU Forwarding In Lab +D7032Q28B 32x100G Intel No Mellanox --- - - - - - - - - - - - -
Device Ports CPU Forwarding ONL Certified In Lab SAI
SN2100 16x100G Intel Rangeley C2558 Mellanox Spectrum Yes Yes Yes
SN2100B 16x40G Intel Rangeley C2558 Mellanox Spectrum Yes No Yes
SN2410 48x25G + 8x100G Intel Ivybridge 1047UE Mellanox Spectrum Yes Yes Yes
SN2410B 48x10G + 8x100G Intel Ivybridge 1047UE Mellanox Spectrum Yes No Yes
SN2700 32x100G Intel Ivybridge 1047UE Mellanox Spectrum Yes Yes Yes
SN2700B 32x40G Intel Ivybridge 1047UE Mellanox Spectrum Yes No Yes
+Device Ports CPU Forwarding In Lab +SN2100 16x100G Intel C2558 Mellanox Spectrum Yes +SN2100B 16x40G Intel C2558 Mellanox Spectrum No +SN2410 48x25G + 8x100G Intel 1047UE Mellanox Spectrum Yes +SN2410B 48x10G + 8x100G Intel 1047UE Mellanox Spectrum No +SN2700 32x100G Intel 1047UE Mellanox Spectrum Yes +SN2700B 32x40G Intel 1047UE Mellanox Spectrum No -Notes: +Netberg --- +Device Ports CPU Forwarding In Lab +Aurora 620 32x100G Intel C2558 Broadcom BCM56960 (Tomahawk) Yes +Aurora 720 48x10/25G + 6x40/100G Intel C2558 Broadcom BCM56960 (Tomahawk) Yes -ONL Certified means that the system runs ONIE, is able to install a generic version of ONL and has the ONL Platform drivers necessary to manage the system. - -\* Systems no longer in the lab cannot be certified post removal - -\** Developing ONL Platform Drivers - -\*** Vendor provided +Quanta +------ +Device Ports CPU Forwarding In Lab +QuantaMesh T1048-LB9 48x1G + 4x10G FreeScale P2020 Broadcom BCM56534 (Firebolt3) Yes +QuantaMesh T3048-LY2 48x10G + 4x40G FreeScale P2020 Broadcom BCM56846 (Trident+) Yes +QuantaMesh T5032-LY6 32x40G Intel C2758 Broadcom BCM56850 (Trident2) Yes +QuantaMesh T3048-LY7 48x10G + 4x100G Intel C2558 Broadcom BCM56768 (Maverick) Yes +QuantaMesh T3048-LY8 48x10G + 6x40G Intel C2758 Broadcom BCM56854 (Trident2) Yes +QuantaMesh T3048-LY9 48x10GT + 6x40G Intel C2758 Broadcom BCM56850 (Trident2) Yes +QuantaMesh T7032-IX1 32x100G Intel C2758 Broadcom BCM56960 (Tomahawk) Yes +QuantaMesh T7032-IX1B 32x100G Intel C2758 Broadcom BCM56960 (Tomahawk) Yes +QuantaMesh T4048-IX2 48xSFP28 + 8xQSFP28 Intel C2758 Broadcom BCM56960 (Tomahawk) Yes +QuantaMesh T4048-IX8 48x10G + 8x100G Intel Broadcom BCM56870 (Trident 3) Yes From 7a55f96744d858b95de4a33092ec86a81137f361 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Wed, 28 Mar 2018 16:01:17 +0800 Subject: [PATCH 11/21] [as5822-54x] Add support for OOM --- .../builds/x86-64-accton-as5822-54x-cpld.c | 1148 ++++++++++++++ .../builds/x86-64-accton-as5822-54x-fan.c | 8 +- .../builds/x86-64-accton-as5822-54x-leds.c | 8 +- .../builds/x86-64-accton-as5822-54x-psu.c | 17 +- .../builds/x86-64-accton-as5822-54x-sfp.c | 1376 ----------------- .../onlp/builds/src/module/src/sfpi.c | 269 ++-- .../x86_64_accton_as5822_54x_r0/__init__.py | 18 +- 7 files changed, 1346 insertions(+), 1498 deletions(-) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-cpld.c delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-cpld.c new file mode 100644 index 00000000..455614ef --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-cpld.c @@ -0,0 +1,1148 @@ +/* + * Copyright (C) Brandon Chuang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as5822_54x CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as5822_54x_cpld1, + as5822_54x_cpld2, + as5822_54x_cpld3 +}; + +struct as5822_54x_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as5822_54x_cpld_id[] = { + { "as5822_54x_cpld1", as5822_54x_cpld1 }, + { "as5822_54x_cpld2", as5822_54x_cpld2 }, + { "as5822_54x_cpld3", as5822_54x_cpld3 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5822_54x_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as5822_54x_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_PRESENT_ATTR_ID(35), + TRANSCEIVER_PRESENT_ATTR_ID(36), + TRANSCEIVER_PRESENT_ATTR_ID(37), + TRANSCEIVER_PRESENT_ATTR_ID(38), + TRANSCEIVER_PRESENT_ATTR_ID(39), + TRANSCEIVER_PRESENT_ATTR_ID(40), + TRANSCEIVER_PRESENT_ATTR_ID(41), + TRANSCEIVER_PRESENT_ATTR_ID(42), + TRANSCEIVER_PRESENT_ATTR_ID(43), + TRANSCEIVER_PRESENT_ATTR_ID(44), + TRANSCEIVER_PRESENT_ATTR_ID(45), + TRANSCEIVER_PRESENT_ATTR_ID(46), + TRANSCEIVER_PRESENT_ATTR_ID(47), + TRANSCEIVER_PRESENT_ATTR_ID(48), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(1), + TRANSCEIVER_TXDISABLE_ATTR_ID(2), + TRANSCEIVER_TXDISABLE_ATTR_ID(3), + TRANSCEIVER_TXDISABLE_ATTR_ID(4), + TRANSCEIVER_TXDISABLE_ATTR_ID(5), + TRANSCEIVER_TXDISABLE_ATTR_ID(6), + TRANSCEIVER_TXDISABLE_ATTR_ID(7), + TRANSCEIVER_TXDISABLE_ATTR_ID(8), + TRANSCEIVER_TXDISABLE_ATTR_ID(9), + TRANSCEIVER_TXDISABLE_ATTR_ID(10), + TRANSCEIVER_TXDISABLE_ATTR_ID(11), + TRANSCEIVER_TXDISABLE_ATTR_ID(12), + TRANSCEIVER_TXDISABLE_ATTR_ID(13), + TRANSCEIVER_TXDISABLE_ATTR_ID(14), + TRANSCEIVER_TXDISABLE_ATTR_ID(15), + TRANSCEIVER_TXDISABLE_ATTR_ID(16), + TRANSCEIVER_TXDISABLE_ATTR_ID(17), + TRANSCEIVER_TXDISABLE_ATTR_ID(18), + TRANSCEIVER_TXDISABLE_ATTR_ID(19), + TRANSCEIVER_TXDISABLE_ATTR_ID(20), + TRANSCEIVER_TXDISABLE_ATTR_ID(21), + TRANSCEIVER_TXDISABLE_ATTR_ID(22), + TRANSCEIVER_TXDISABLE_ATTR_ID(23), + TRANSCEIVER_TXDISABLE_ATTR_ID(24), + TRANSCEIVER_TXDISABLE_ATTR_ID(25), + TRANSCEIVER_TXDISABLE_ATTR_ID(26), + TRANSCEIVER_TXDISABLE_ATTR_ID(27), + TRANSCEIVER_TXDISABLE_ATTR_ID(28), + TRANSCEIVER_TXDISABLE_ATTR_ID(29), + TRANSCEIVER_TXDISABLE_ATTR_ID(30), + TRANSCEIVER_TXDISABLE_ATTR_ID(31), + TRANSCEIVER_TXDISABLE_ATTR_ID(32), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(35), + TRANSCEIVER_TXDISABLE_ATTR_ID(36), + TRANSCEIVER_TXDISABLE_ATTR_ID(37), + TRANSCEIVER_TXDISABLE_ATTR_ID(38), + TRANSCEIVER_TXDISABLE_ATTR_ID(39), + TRANSCEIVER_TXDISABLE_ATTR_ID(40), + TRANSCEIVER_TXDISABLE_ATTR_ID(41), + TRANSCEIVER_TXDISABLE_ATTR_ID(42), + TRANSCEIVER_TXDISABLE_ATTR_ID(43), + TRANSCEIVER_TXDISABLE_ATTR_ID(44), + TRANSCEIVER_TXDISABLE_ATTR_ID(45), + TRANSCEIVER_TXDISABLE_ATTR_ID(46), + TRANSCEIVER_TXDISABLE_ATTR_ID(47), + TRANSCEIVER_TXDISABLE_ATTR_ID(48), + TRANSCEIVER_RXLOS_ATTR_ID(1), + TRANSCEIVER_RXLOS_ATTR_ID(2), + TRANSCEIVER_RXLOS_ATTR_ID(3), + TRANSCEIVER_RXLOS_ATTR_ID(4), + TRANSCEIVER_RXLOS_ATTR_ID(5), + TRANSCEIVER_RXLOS_ATTR_ID(6), + TRANSCEIVER_RXLOS_ATTR_ID(7), + TRANSCEIVER_RXLOS_ATTR_ID(8), + TRANSCEIVER_RXLOS_ATTR_ID(9), + TRANSCEIVER_RXLOS_ATTR_ID(10), + TRANSCEIVER_RXLOS_ATTR_ID(11), + TRANSCEIVER_RXLOS_ATTR_ID(12), + TRANSCEIVER_RXLOS_ATTR_ID(13), + TRANSCEIVER_RXLOS_ATTR_ID(14), + TRANSCEIVER_RXLOS_ATTR_ID(15), + TRANSCEIVER_RXLOS_ATTR_ID(16), + TRANSCEIVER_RXLOS_ATTR_ID(17), + TRANSCEIVER_RXLOS_ATTR_ID(18), + TRANSCEIVER_RXLOS_ATTR_ID(19), + TRANSCEIVER_RXLOS_ATTR_ID(20), + TRANSCEIVER_RXLOS_ATTR_ID(21), + TRANSCEIVER_RXLOS_ATTR_ID(22), + TRANSCEIVER_RXLOS_ATTR_ID(23), + TRANSCEIVER_RXLOS_ATTR_ID(24), + TRANSCEIVER_RXLOS_ATTR_ID(25), + TRANSCEIVER_RXLOS_ATTR_ID(26), + TRANSCEIVER_RXLOS_ATTR_ID(27), + TRANSCEIVER_RXLOS_ATTR_ID(28), + TRANSCEIVER_RXLOS_ATTR_ID(29), + TRANSCEIVER_RXLOS_ATTR_ID(30), + TRANSCEIVER_RXLOS_ATTR_ID(31), + TRANSCEIVER_RXLOS_ATTR_ID(32), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(35), + TRANSCEIVER_RXLOS_ATTR_ID(36), + TRANSCEIVER_RXLOS_ATTR_ID(37), + TRANSCEIVER_RXLOS_ATTR_ID(38), + TRANSCEIVER_RXLOS_ATTR_ID(39), + TRANSCEIVER_RXLOS_ATTR_ID(40), + TRANSCEIVER_RXLOS_ATTR_ID(41), + TRANSCEIVER_RXLOS_ATTR_ID(42), + TRANSCEIVER_RXLOS_ATTR_ID(43), + TRANSCEIVER_RXLOS_ATTR_ID(44), + TRANSCEIVER_RXLOS_ATTR_ID(45), + TRANSCEIVER_RXLOS_ATTR_ID(46), + TRANSCEIVER_RXLOS_ATTR_ID(47), + TRANSCEIVER_RXLOS_ATTR_ID(48), + TRANSCEIVER_TXFAULT_ATTR_ID(1), + TRANSCEIVER_TXFAULT_ATTR_ID(2), + TRANSCEIVER_TXFAULT_ATTR_ID(3), + TRANSCEIVER_TXFAULT_ATTR_ID(4), + TRANSCEIVER_TXFAULT_ATTR_ID(5), + TRANSCEIVER_TXFAULT_ATTR_ID(6), + TRANSCEIVER_TXFAULT_ATTR_ID(7), + TRANSCEIVER_TXFAULT_ATTR_ID(8), + TRANSCEIVER_TXFAULT_ATTR_ID(9), + TRANSCEIVER_TXFAULT_ATTR_ID(10), + TRANSCEIVER_TXFAULT_ATTR_ID(11), + TRANSCEIVER_TXFAULT_ATTR_ID(12), + TRANSCEIVER_TXFAULT_ATTR_ID(13), + TRANSCEIVER_TXFAULT_ATTR_ID(14), + TRANSCEIVER_TXFAULT_ATTR_ID(15), + TRANSCEIVER_TXFAULT_ATTR_ID(16), + TRANSCEIVER_TXFAULT_ATTR_ID(17), + TRANSCEIVER_TXFAULT_ATTR_ID(18), + TRANSCEIVER_TXFAULT_ATTR_ID(19), + TRANSCEIVER_TXFAULT_ATTR_ID(20), + TRANSCEIVER_TXFAULT_ATTR_ID(21), + TRANSCEIVER_TXFAULT_ATTR_ID(22), + TRANSCEIVER_TXFAULT_ATTR_ID(23), + TRANSCEIVER_TXFAULT_ATTR_ID(24), + TRANSCEIVER_TXFAULT_ATTR_ID(25), + TRANSCEIVER_TXFAULT_ATTR_ID(26), + TRANSCEIVER_TXFAULT_ATTR_ID(27), + TRANSCEIVER_TXFAULT_ATTR_ID(28), + TRANSCEIVER_TXFAULT_ATTR_ID(29), + TRANSCEIVER_TXFAULT_ATTR_ID(30), + TRANSCEIVER_TXFAULT_ATTR_ID(31), + TRANSCEIVER_TXFAULT_ATTR_ID(32), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(35), + TRANSCEIVER_TXFAULT_ATTR_ID(36), + TRANSCEIVER_TXFAULT_ATTR_ID(37), + TRANSCEIVER_TXFAULT_ATTR_ID(38), + TRANSCEIVER_TXFAULT_ATTR_ID(39), + TRANSCEIVER_TXFAULT_ATTR_ID(40), + TRANSCEIVER_TXFAULT_ATTR_ID(41), + TRANSCEIVER_TXFAULT_ATTR_ID(42), + TRANSCEIVER_TXFAULT_ATTR_ID(43), + TRANSCEIVER_TXFAULT_ATTR_ID(44), + TRANSCEIVER_TXFAULT_ATTR_ID(45), + TRANSCEIVER_TXFAULT_ATTR_ID(46), + TRANSCEIVER_TXFAULT_ATTR_ID(47), + TRANSCEIVER_TXFAULT_ATTR_ID(48), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as5822_54x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5822_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); + +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); + +static struct attribute *as5822_54x_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as5822_54x_cpld1_group = { + .attrs = as5822_54x_cpld1_attributes, +}; + +static struct attribute *as5822_54x_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_SFP_TRANSCEIVER_ATTR(1), + DECLARE_SFP_TRANSCEIVER_ATTR(2), + DECLARE_SFP_TRANSCEIVER_ATTR(3), + DECLARE_SFP_TRANSCEIVER_ATTR(4), + DECLARE_SFP_TRANSCEIVER_ATTR(5), + DECLARE_SFP_TRANSCEIVER_ATTR(6), + DECLARE_SFP_TRANSCEIVER_ATTR(7), + DECLARE_SFP_TRANSCEIVER_ATTR(8), + DECLARE_SFP_TRANSCEIVER_ATTR(9), + DECLARE_SFP_TRANSCEIVER_ATTR(10), + DECLARE_SFP_TRANSCEIVER_ATTR(11), + DECLARE_SFP_TRANSCEIVER_ATTR(12), + DECLARE_SFP_TRANSCEIVER_ATTR(13), + DECLARE_SFP_TRANSCEIVER_ATTR(14), + DECLARE_SFP_TRANSCEIVER_ATTR(15), + DECLARE_SFP_TRANSCEIVER_ATTR(16), + DECLARE_SFP_TRANSCEIVER_ATTR(17), + DECLARE_SFP_TRANSCEIVER_ATTR(18), + DECLARE_SFP_TRANSCEIVER_ATTR(19), + DECLARE_SFP_TRANSCEIVER_ATTR(20), + DECLARE_SFP_TRANSCEIVER_ATTR(21), + DECLARE_SFP_TRANSCEIVER_ATTR(22), + DECLARE_SFP_TRANSCEIVER_ATTR(23), + DECLARE_SFP_TRANSCEIVER_ATTR(24), + DECLARE_SFP_TRANSCEIVER_ATTR(25), + DECLARE_SFP_TRANSCEIVER_ATTR(26), + DECLARE_SFP_TRANSCEIVER_ATTR(27), + DECLARE_SFP_TRANSCEIVER_ATTR(28), + DECLARE_SFP_TRANSCEIVER_ATTR(29), + NULL +}; + +static const struct attribute_group as5822_54x_cpld2_group = { + .attrs = as5822_54x_cpld2_attributes, +}; + +static struct attribute *as5822_54x_cpld3_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_TRANSCEIVER_PRESENT_ATTR(33), + DECLARE_TRANSCEIVER_PRESENT_ATTR(34), + DECLARE_TRANSCEIVER_PRESENT_ATTR(35), + DECLARE_TRANSCEIVER_PRESENT_ATTR(36), + DECLARE_TRANSCEIVER_PRESENT_ATTR(37), + DECLARE_TRANSCEIVER_PRESENT_ATTR(38), + DECLARE_TRANSCEIVER_PRESENT_ATTR(39), + DECLARE_TRANSCEIVER_PRESENT_ATTR(40), + DECLARE_TRANSCEIVER_PRESENT_ATTR(41), + DECLARE_TRANSCEIVER_PRESENT_ATTR(42), + DECLARE_TRANSCEIVER_PRESENT_ATTR(43), + DECLARE_TRANSCEIVER_PRESENT_ATTR(44), + DECLARE_TRANSCEIVER_PRESENT_ATTR(45), + DECLARE_TRANSCEIVER_PRESENT_ATTR(46), + DECLARE_TRANSCEIVER_PRESENT_ATTR(47), + DECLARE_TRANSCEIVER_PRESENT_ATTR(48), + DECLARE_TRANSCEIVER_PRESENT_ATTR(49), + DECLARE_TRANSCEIVER_PRESENT_ATTR(50), + DECLARE_TRANSCEIVER_PRESENT_ATTR(51), + DECLARE_TRANSCEIVER_PRESENT_ATTR(52), + DECLARE_TRANSCEIVER_PRESENT_ATTR(53), + DECLARE_TRANSCEIVER_PRESENT_ATTR(54), + DECLARE_SFP_TRANSCEIVER_ATTR(30), + DECLARE_SFP_TRANSCEIVER_ATTR(31), + DECLARE_SFP_TRANSCEIVER_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + DECLARE_SFP_TRANSCEIVER_ATTR(35), + DECLARE_SFP_TRANSCEIVER_ATTR(36), + DECLARE_SFP_TRANSCEIVER_ATTR(37), + DECLARE_SFP_TRANSCEIVER_ATTR(38), + DECLARE_SFP_TRANSCEIVER_ATTR(39), + DECLARE_SFP_TRANSCEIVER_ATTR(40), + DECLARE_SFP_TRANSCEIVER_ATTR(41), + DECLARE_SFP_TRANSCEIVER_ATTR(42), + DECLARE_SFP_TRANSCEIVER_ATTR(43), + DECLARE_SFP_TRANSCEIVER_ATTR(44), + DECLARE_SFP_TRANSCEIVER_ATTR(45), + DECLARE_SFP_TRANSCEIVER_ATTR(46), + DECLARE_SFP_TRANSCEIVER_ATTR(47), + DECLARE_SFP_TRANSCEIVER_ATTR(48), + NULL +}; + +static const struct attribute_group as5822_54x_cpld3_group = { + .attrs = as5822_54x_cpld3_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[4] = {0}; + u8 regs[] = {0x3, 0x4, 0x5, 0x6}; + struct i2c_client *client = to_i2c_client(dev); + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as5822_54x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 54 in order */ + if (data->type == as5822_54x_cpld2) { + values[3] &= 0x1F; + } + else { /* as5822_54x_cpld3 */ + values[2] &= 0x7; + values[3] &= 0x3F; + values[2] |= (values[3] & 0x1F) << 3; + values[3] >>= 5; /* shift out port 49-53 */ + } + + return sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[4] = {0}; + u8 regs_cpld2[] = {0xF, 0x10, 0x11, 0x12}; + u8 regs_cpld3[] = {0xD, 0xE, 0xF}; + u8 *regs[] = {NULL, regs_cpld2, regs_cpld3}; + u8 size[] = {0, ARRAY_SIZE(regs_cpld2), ARRAY_SIZE(regs_cpld3)}; + struct i2c_client *client = to_i2c_client(dev); + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < size[data->type]; i++) { + status = as5822_54x_cpld_read_internal(client, regs[data->type][i]); + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + if (data->type == as5822_54x_cpld2) { + values[3] &= 0x1F; + + /* Return values in order */ + return sprintf(buf, "%.2x %.2x %.2x %.2x\n", values[0], values[1], values[2], values[3]); + } + else { /* as5822_54x_cpld3 */ + values[2] &= 0x7; + + /* Return values in order */ + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); + } + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x3; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x4; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x5; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_29: + reg = 0x6; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_30 ... MODULE_PRESENT_37: + reg = 0x3; + mask = 0x1 << (attr->index - MODULE_PRESENT_30); + break; + case MODULE_PRESENT_38 ... MODULE_PRESENT_45: + reg = 0x4; + mask = 0x1 << (attr->index - MODULE_PRESENT_38); + break; + case MODULE_PRESENT_46 ... MODULE_PRESENT_48: + reg = 0x5; + mask = 0x1 << (attr->index - MODULE_PRESENT_46); + break; + case MODULE_PRESENT_49 ... MODULE_PRESENT_54: + reg = 0x6; + mask = 0x1 << (attr->index - MODULE_PRESENT_49); + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: + reg = 0x7; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1); + break; + case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: + reg = 0x8; + mask = 0x1 << (attr->index - MODULE_TXFAULT_9); + break; + case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: + reg = 0x9; + mask = 0x1 << (attr->index - MODULE_TXFAULT_17); + break; + case MODULE_TXFAULT_25 ... MODULE_TXFAULT_29: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_TXFAULT_25); + break; + case MODULE_TXFAULT_30 ... MODULE_TXFAULT_37: + reg = 0x7; + mask = 0x1 << (attr->index - MODULE_TXFAULT_30); + break; + case MODULE_TXFAULT_38 ... MODULE_TXFAULT_45: + reg = 0x8; + mask = 0x1 << (attr->index - MODULE_TXFAULT_38); + break; + case MODULE_TXFAULT_46 ... MODULE_TXFAULT_48: + reg = 0x9; + mask = 0x1 << (attr->index - MODULE_TXFAULT_46); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_29: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_30 ... MODULE_TXDISABLE_37: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_30); + break; + case MODULE_TXDISABLE_38 ... MODULE_TXDISABLE_45: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_38); + break; + case MODULE_TXDISABLE_46 ... MODULE_TXDISABLE_48: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_46); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_8: + reg = 0xF; + mask = 0x1 << (attr->index - MODULE_RXLOS_1); + break; + case MODULE_RXLOS_9 ... MODULE_RXLOS_16: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_RXLOS_9); + break; + case MODULE_RXLOS_17 ... MODULE_RXLOS_24: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_RXLOS_17); + break; + case MODULE_RXLOS_25 ... MODULE_RXLOS_29: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_RXLOS_25); + break; + case MODULE_RXLOS_30 ... MODULE_RXLOS_37: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_RXLOS_30); + break; + case MODULE_RXLOS_38 ... MODULE_RXLOS_45: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_RXLOS_38); + break; + case MODULE_RXLOS_46 ... MODULE_RXLOS_48: + reg = 0xF; + mask = 0x1 << (attr->index - MODULE_RXLOS_46); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as5822_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0xD; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_29: + reg = 0xE; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_30 ... MODULE_TXDISABLE_37: + reg = 0xA; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_30); + break; + case MODULE_TXDISABLE_38 ... MODULE_TXDISABLE_45: + reg = 0xB; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_38); + break; + case MODULE_TXDISABLE_46 ... MODULE_TXDISABLE_48: + reg = 0xC; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_46); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5822_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5822_54x_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as5822_54x_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as5822_54x_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as5822_54x_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5822_54x_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as5822_54x_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as5822_54x_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as5822_54x_cpld1: + group = &as5822_54x_cpld1_group; + break; + case as5822_54x_cpld2: + group = &as5822_54x_cpld2_group; + break; + case as5822_54x_cpld3: + group = &as5822_54x_cpld3_group; + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as5822_54x_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as5822_54x_cpld_remove(struct i2c_client *client) +{ + struct as5822_54x_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as5822_54x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as5822_54x_cpld1: + group = &as5822_54x_cpld1_group; + break; + case as5822_54x_cpld2: + group = &as5822_54x_cpld2_group; + break; + case as5822_54x_cpld3: + group = &as5822_54x_cpld3_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as5822_54x_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as5822_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5822_54x_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5822_54x_cpld_read); + +int as5822_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5822_54x_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5822_54x_cpld_write); + +static struct i2c_driver as5822_54x_cpld_driver = { + .driver = { + .name = "as5822_54x_cpld", + .owner = THIS_MODULE, + }, + .probe = as5822_54x_cpld_probe, + .remove = as5822_54x_cpld_remove, + .id_table = as5822_54x_cpld_id, +}; + +static int __init as5822_54x_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5822_54x_cpld_driver); +} + +static void __exit as5822_54x_cpld_exit(void) +{ + i2c_del_driver(&as5822_54x_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as5822_54x_cpld_init); +module_exit(as5822_54x_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-fan.c index 52b55612..2149b4f4 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-fan.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-fan.c @@ -39,8 +39,8 @@ static struct as5822_54x_fan_data *as5822_54x_fan_update_device(struct device *d static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5822_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); /* fan related data, the index should match sysfs_fan_attributes */ @@ -199,12 +199,12 @@ static struct attribute *as5822_54x_fan_attributes[] = { static int as5822_54x_fan_read_value(u8 reg) { - return accton_i2c_cpld_read(FAN_STATUS_I2C_ADDR, reg); + return as5822_54x_cpld_read(FAN_STATUS_I2C_ADDR, reg); } static int as5822_54x_fan_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(FAN_STATUS_I2C_ADDR, reg, value); + return as5822_54x_cpld_write(FAN_STATUS_I2C_ADDR, reg, value); } /* fan utility functions diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-leds.c index 2795da57..52d70db4 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-leds.c @@ -38,8 +38,8 @@ #define DEBUG_PRINT(fmt, args...) #endif -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5822_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); struct accton_as5822_54x_led_data { struct platform_device *pdev; @@ -147,12 +147,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as5822_54x_led_read_value(u8 reg) { - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); + return as5822_54x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } static int accton_as5822_54x_led_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); + return as5822_54x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } static void accton_as5822_54x_led_update(void) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-psu.c index 4d2e8a28..7e0c08ca 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-psu.c @@ -50,7 +50,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_string(struct device *dev, struct device_attribute *da, char *buf); static int as5822_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5822_54x_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned */ @@ -317,7 +317,7 @@ static struct as5822_54x_psu_data *as5822_54x_psu_update_device(struct device *d data->valid = 0; /* Read psu status */ - status = accton_i2c_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); + status = as5822_54x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); if (status < 0) { dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); @@ -372,18 +372,7 @@ exit: return data; } -static int __init as5822_54x_psu_init(void) -{ - return i2c_add_driver(&as5822_54x_psu_driver); -} - -static void __exit as5822_54x_psu_exit(void) -{ - i2c_del_driver(&as5822_54x_psu_driver); -} - -module_init(as5822_54x_psu_init); -module_exit(as5822_54x_psu_exit); +module_i2c_driver(as5822_54x_psu_driver); MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("as5822_54x_psu driver"); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-sfp.c deleted file mode 100644 index 5124e494..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/modules/builds/x86-64-accton-as5822-54x-sfp.c +++ /dev/null @@ -1,1376 +0,0 @@ -/* - * SFP driver for accton as5822_54x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as5822_54x_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 54 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 3 -#define I2C_RW_RETRY_INTERVAL 100 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) -#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 -#define SFF8472_10G_BASE_MASK 0xF0 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -/* Platform dependent +++ */ -enum CPLD_ID{ - SFP_CPLD1, - SFP_CPLD2, - NUM_OF_CPLD -}; - -int cplds[NUM_OF_CPLD] = {0x61, 0x62}; - -/* Platform dependent --- */ - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_FAULT_ALL, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - TX_DISABLE_ALL, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); -static SENSOR_DEVICE_ATTR(sfp_tx_fault_all, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT_ALL); -static SENSOR_DEVICE_ATTR(sfp_tx_disable_all, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_DISABLE_ALL); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable_all.dev_attr.attr, - NULL -}; - -/* SFP ddm attributes for sysfs */ -static struct attribute *sfp_ddm_attributes[] = { - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as5822_54x_sfp1, as5822_54x_sfp2, as5822_54x_sfp3, as5822_54x_sfp4, as5822_54x_sfp5, as5822_54x_sfp6, as5822_54x_sfp7, as5822_54x_sfp8, -as5822_54x_sfp9, as5822_54x_sfp10, as5822_54x_sfp11, as5822_54x_sfp12, as5822_54x_sfp13, as5822_54x_sfp14, as5822_54x_sfp15, as5822_54x_sfp16, -as5822_54x_sfp17, as5822_54x_sfp18, as5822_54x_sfp19, as5822_54x_sfp20, as5822_54x_sfp21, as5822_54x_sfp22, as5822_54x_sfp23, as5822_54x_sfp24, -as5822_54x_sfp25, as5822_54x_sfp26, as5822_54x_sfp27, as5822_54x_sfp28, as5822_54x_sfp29, as5822_54x_sfp30, as5822_54x_sfp31, as5822_54x_sfp32, -as5822_54x_sfp33, as5822_54x_sfp34, as5822_54x_sfp35, as5822_54x_sfp36, as5822_54x_sfp37, as5822_54x_sfp38, as5822_54x_sfp39, as5822_54x_sfp40, -as5822_54x_sfp41, as5822_54x_sfp42, as5822_54x_sfp43, as5822_54x_sfp44, as5822_54x_sfp45, as5822_54x_sfp46, as5822_54x_sfp47, as5822_54x_sfp48, -as5822_54x_sfp49, as5822_54x_sfp50, as5822_54x_sfp51, as5822_54x_sfp52, as5822_54x_sfp53, as5822_54x_sfp54 -}; - -static const struct i2c_device_id sfp_device_id[] = { -{ "as5822_54x_sfp1", as5822_54x_sfp1 }, { "as5822_54x_sfp2", as5822_54x_sfp2 }, { "as5822_54x_sfp3", as5822_54x_sfp3 }, { "as5822_54x_sfp4", as5822_54x_sfp4 }, -{ "as5822_54x_sfp5", as5822_54x_sfp5 }, { "as5822_54x_sfp6", as5822_54x_sfp6 }, { "as5822_54x_sfp7", as5822_54x_sfp7 }, { "as5822_54x_sfp8", as5822_54x_sfp8 }, -{ "as5822_54x_sfp9", as5822_54x_sfp9 }, { "as5822_54x_sfp10", as5822_54x_sfp10 }, { "as5822_54x_sfp11", as5822_54x_sfp11 }, { "as5822_54x_sfp12", as5822_54x_sfp12 }, -{ "as5822_54x_sfp13", as5822_54x_sfp13 }, { "as5822_54x_sfp14", as5822_54x_sfp14 }, { "as5822_54x_sfp15", as5822_54x_sfp15 }, { "as5822_54x_sfp16", as5822_54x_sfp16 }, -{ "as5822_54x_sfp17", as5822_54x_sfp17 }, { "as5822_54x_sfp18", as5822_54x_sfp18 }, { "as5822_54x_sfp19", as5822_54x_sfp19 }, { "as5822_54x_sfp20", as5822_54x_sfp20 }, -{ "as5822_54x_sfp21", as5822_54x_sfp21 }, { "as5822_54x_sfp22", as5822_54x_sfp22 }, { "as5822_54x_sfp23", as5822_54x_sfp23 }, { "as5822_54x_sfp24", as5822_54x_sfp24 }, -{ "as5822_54x_sfp25", as5822_54x_sfp25 }, { "as5822_54x_sfp26", as5822_54x_sfp26 }, { "as5822_54x_sfp27", as5822_54x_sfp27 }, { "as5822_54x_sfp28", as5822_54x_sfp28 }, -{ "as5822_54x_sfp29", as5822_54x_sfp29 }, { "as5822_54x_sfp30", as5822_54x_sfp30 }, { "as5822_54x_sfp31", as5822_54x_sfp31 }, { "as5822_54x_sfp32", as5822_54x_sfp32 }, -{ "as5822_54x_sfp33", as5822_54x_sfp33 }, { "as5822_54x_sfp34", as5822_54x_sfp34 }, { "as5822_54x_sfp35", as5822_54x_sfp35 }, { "as5822_54x_sfp36", as5822_54x_sfp36 }, -{ "as5822_54x_sfp37", as5822_54x_sfp37 }, { "as5822_54x_sfp38", as5822_54x_sfp38 }, { "as5822_54x_sfp39", as5822_54x_sfp39 }, { "as5822_54x_sfp40", as5822_54x_sfp40 }, -{ "as5822_54x_sfp41", as5822_54x_sfp41 }, { "as5822_54x_sfp42", as5822_54x_sfp42 }, { "as5822_54x_sfp43", as5822_54x_sfp43 }, { "as5822_54x_sfp44", as5822_54x_sfp44 }, -{ "as5822_54x_sfp45", as5822_54x_sfp45 }, { "as5822_54x_sfp46", as5822_54x_sfp46 }, { "as5822_54x_sfp47", as5822_54x_sfp47 }, { "as5822_54x_sfp48", as5822_54x_sfp48 }, -{ "as5822_54x_sfp49", as5822_54x_sfp49 }, { "as5822_54x_sfp50", as5822_54x_sfp50 }, { "as5822_54x_sfp51", as5822_54x_sfp51 }, { "as5822_54x_sfp52", as5822_54x_sfp52 }, -{ "as5822_54x_sfp53", as5822_54x_sfp53 }, { "as5822_54x_sfp54", as5822_54x_sfp54 }, -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -/* - * list of valid port types - * note OOM_PORT_TYPE_NOT_PRESENT to indicate no - * module is present in this port - */ -typedef enum oom_driver_port_type_e { - OOM_DRIVER_PORT_TYPE_INVALID, - OOM_DRIVER_PORT_TYPE_NOT_PRESENT, - OOM_DRIVER_PORT_TYPE_SFP, - OOM_DRIVER_PORT_TYPE_SFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP, - OOM_DRIVER_PORT_TYPE_QSFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP28 -} oom_driver_port_type_t; - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[6]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss - 3 => device id - 4 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 5 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -}; - -struct sfp_ddm_data { - struct eeprom_data eeprom; -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - oom_driver_port_type_t port_type; - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct sfp_ddm_data *ddm; - struct qsfp_data *qsfp; - - struct i2c_client *client; -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - int i = 0, j = 0, status = -1; - u8 reg; - struct sfp_port_data *data = i2c_get_clientdata(client); - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - data->present = 0; - - /* Read present status of port 1~48(SFP port) */ - for (i = 0; i < ARRAY_SIZE(cplds); i++) { - for (j = 0; j < 4; j++) { - reg = 0x3+j; - status = accton_i2c_cpld_read(cplds[i], reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cplds[i], reg, status); - goto exit; - } - - if (i == SFP_CPLD1) { /* SFP_CPLD1 */ - data->present |= (u64)status << j*8; - } - else if (i == SFP_CPLD2) { /* SFP_CPLD2 */ - switch (j) { - case 0: - case 1: - data->present |= (u64)status << (j*8 + 29); - break; - case 2: - data->present |= ((u64)status & 0x7) << 45; - break; - case 3: - data->present |= ((u64)status & 0x3F) << 48; - break; - default: - break; - }; - } - } - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -struct i2c_info { - enum CPLD_ID cid; - int reg; -}; - -static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - struct i2c_info tx_fault[] = {{SFP_CPLD1, 0x7}, {SFP_CPLD1, 0x8}, - {SFP_CPLD1, 0x9}, {SFP_CPLD1, 0xa}, - {SFP_CPLD2, 0x7}, {SFP_CPLD2, 0x8}, - {SFP_CPLD2, 0x9}}; - struct i2c_info tx_disable[] = {{SFP_CPLD1, 0xb}, {SFP_CPLD1, 0xc}, - {SFP_CPLD1, 0xd}, {SFP_CPLD1, 0xe}, - {SFP_CPLD2, 0xa}, {SFP_CPLD2, 0xb}, - {SFP_CPLD2, 0xc}}; - struct i2c_info rx_los[] = {{SFP_CPLD1, 0xf}, {SFP_CPLD1, 0x10}, - {SFP_CPLD1, 0x11},{SFP_CPLD1, 0x12}, - {SFP_CPLD2, 0xd}, {SFP_CPLD2, 0xe}, - {SFP_CPLD2, 0xf}}; - struct i2c_info *tx_rx_data[] = {tx_fault, tx_disable, rx_los}; - - if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { - return data; - } - - DEBUG_PRINT("Starting as5822_54x sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->msa->valid = 0; - memset(data->msa->status, 0, sizeof(data->msa->status)); - - for (i = 0; i < ARRAY_SIZE(tx_rx_data); i++) { - for (j = 0; j < ARRAY_SIZE(tx_fault); j++) { - int cid = tx_rx_data[i][j].cid; - int reg = tx_rx_data[i][j].reg; - - status = accton_i2c_cpld_read(cplds[cid], reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cplds[cid], reg, status); - goto exit; - } - - switch (j) { - case 0 ... 2: - data->msa->status[i] |= (u64)status << j*8; - break; - case 3: - data->msa->status[i] |= ((u64)status & 0x1F) << j*8; - break; - case 4 ... 5: - data->msa->status[i] |= (u64)status << ((j-4)*8 + 29); - break; - case 6: - data->msa->status[i] |= ((u64)status & 0x7) << 45; - break; - default: - break; - }; - } - } - - data->msa->valid = 1; - data->msa->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - unsigned short cpld_id = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - u8 tx_disable_regs[] = {0xb, 0xc, 0xd, 0xe, 0xa, 0xb, 0xc}; - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_set_tx_disable(dev, da, buf, count); - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < as5822_54x_sfp29) { - cpld_id = SFP_CPLD1; - cpld_reg = tx_disable_regs[data->port / 8]; - cpld_bit = 1 << (data->port % 8); - } - else { /* port 30 ~ 48 */ - cpld_id = SFP_CPLD2; - cpld_reg = tx_disable_regs[(data->port - as5822_54x_sfp29) / 8 + 4]; - cpld_bit = 1 << ((data->port - as5822_54x_sfp30) % 8); - } - - /* Read current status */ - cpld_val = accton_i2c_cpld_read(cplds[cpld_id], cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->msa->status[1] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->msa->status[1] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - DEBUG_PRINT("Write to CPLD(0x%x), REG(0x%x), VAL(0x%x)", cplds[cpld_id], cpld_reg, cpld_val); - accton_i2c_cpld_write(cplds[cpld_id], cpld_reg, cpld_val); - mutex_unlock(&data->update_lock); - return count; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ -} - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[7] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *sfp_update_port_type(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 buf = 0; - int status; - - mutex_lock(&data->update_lock); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - if (buf != SFF8024_DEVICE_ID_SFP) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); - data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; - break; - } - case DRIVER_TYPE_QSFP: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); - switch (buf) { - case SFF8024_DEVICE_ID_QSFP: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; - break; - case SFF8024_DEVICE_ID_QSFP_PLUS: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - case SFF8024_DEVICE_ID_QSFP28: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - default: - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - break; - } - default: - break; - } - - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - if (!present) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_type(dev); - return sprintf(buf, "%d\n", data->port_type); -} - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - data->qsfp->status[1] = disable & 0xF; - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, - char *buf) -{ - int status; - char ddm; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (status == 0) { - /* port is not present */ - return -ENODEV; - } - - status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); - if (unlikely(status < 0)) { - return status; - } - - return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); -} - -/* Platform dependent +++ */ -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_show_tx_rx_status(dev, da, buf); - } - - data = sfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - if(attr->index == RX_LOS_ALL || attr->index == TX_FAULT_ALL || - attr->index == TX_DISABLE_ALL) { - int i = 0, index = 0; - u8 values[6] = {0}; - - switch (attr->index) { - case TX_FAULT_ALL: - index = 0; - break; - case TX_DISABLE_ALL: - index = 1; - break; - case RX_LOS_ALL: - index = 2; - break; - default: - break; - }; - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = (u8)(data->msa->status[index] >> (i * 8)); - } - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - return 0; - } - - val = !!(data->msa->status[index] & BIT_INDEX(data->port)); - return sprintf(buf, "%d\n", val); -} -/* Platform dependent --- */ -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -static ssize_t sfp_port_write(struct sfp_port_data *data, - 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(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} - - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_write(data, buf, off, count); -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_read(data, buf, off, count); -} - -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; - eeprom->size = EEPROM_SIZE; - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group sfp_ddm_group = { - .attrs = sfp_ddm_attributes, -}; - -static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_ddm_data **data) -{ - int status; - struct sfp_ddm_data *ddm; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); - if (!ddm) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = ddm; - dev_info(&client->dev, "sfp ddm '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); -exit_free: - kfree(ddm); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct sfp_port_data *data = NULL; - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (dev_id->driver_data >= as5822_54x_sfp1 && dev_id->driver_data <= as5822_54x_sfp48) { - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_MSA; - return sfp_msa_probe(client, dev_id, &data->msa); - } - else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_DDM; - return sfp_ddm_probe(client, dev_id, &data->ddm); - } - } - else { /* as5822_54x_sfp49 ~ as5822_54x_sfp54 */ - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_QSFP; - return qsfp_probe(client, dev_id, &data->qsfp); - } - } - - return -ENODEV; -} - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_SFP_DDM: - return sfp_ddm_remove(client, data->ddm); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - - return 0; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5822_54x_sfp driver"); -MODULE_LICENSE("GPL"); - -late_initcall(sfp_init); -module_exit(sfp_exit); - - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/sfpi.c index 47e39ee2..a2e1bb45 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/onlp/builds/src/module/src/sfpi.c @@ -2,7 +2,7 @@ * * * Copyright 2014 Big Switch Networks, Inc. - * Copyright 2016 Accton Technology Corporation. + * Copyright 2013 Accton Technology Corporation. * * Licensed under the Eclipse Public License, Version 1.0 (the * "License"); you may not use this file except in compliance @@ -24,29 +24,21 @@ * ***********************************************************/ #include +#include #include -#include "platform_lib.h" - +#include "x86_64_accton_as5822_54x_int.h" #include "x86_64_accton_as5822_54x_log.h" -#define NUM_OF_SFP_PORT 54 -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define FRONT_PORT_BUS_INDEX(port) (port+18) +#define PORT_BUS_INDEX(port) (port+18) -static char* -sfp_get_port_path_addr(int port, int addr, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s", - FRONT_PORT_BUS_INDEX(port), addr, node_name); - return sfp_node_path; -} - -static char* -sfp_get_port_path(int port, char *node_name) -{ - return sfp_get_port_path_addr(port, 50, node_name); -} +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/10-0061/module_rx_los_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD3 "/sys/bus/i2c/devices/11-0062/module_rx_los_all" /************************************************************ * @@ -68,7 +60,7 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) */ int p; - for(p = 0; p < NUM_OF_SFP_PORT; p++) { + for(p = 0; p < 54; p++) { AIM_BITMAP_SET(bmap, p); } @@ -84,9 +76,12 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char *path = sfp_get_port_path(port, "sfp_is_present"); + int bus, addr; - if (onlp_file_read_int(&present, path) < 0) { + addr = (port < 29) ? 61 : 62; + bus = (addr == 61) ? 10 : 11; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -97,42 +92,51 @@ onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[7]; - char* path; + uint32_t bytes[8], *ptr = NULL; FILE* fp; + int addr; - AIM_BITMAP_CLR_ALL(dst); + ptr = bytes; - path = sfp_get_port_path(0, "sfp_is_present_all"); - fp = fopen(path, "r"); + for (addr = 61; addr <= 62; addr++) { + /* Read present status of port 0~53 */ + char file[64] = {0}; + int bus = (addr == 61) ? 10 : 11; + + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD."); + return ONLP_STATUS_E_INTERNAL; + } - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5, - bytes+6 - ); - fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { - /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; + int count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD."); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Mask out non-existant QSFP ports */ - bytes[6] &= 0x3F; + bytes[3] &= 0x1F; + bytes[7] &= 0x1; /* Convert to 64 bit integer in port order */ int i = 0; uint64_t presence_all = 0 ; - for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { + for(i = 7; i >= 4; i--) { + presence_all <<= 8; + presence_all |= bytes[i]; + } + + presence_all <<= 5; + presence_all |= bytes[3]; + + for(i = 2; i >= 0; i--) { presence_all <<= 8; presence_all |= bytes[i]; } @@ -149,39 +153,68 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[6]; - char* path; + uint32_t bytes[7]; + uint32_t *ptr = bytes; FILE* fp; - path = sfp_get_port_path(0, "sfp_rx_los_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~23 */ + int addr, i = 0; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5 - ); - fclose(fp); - if(count != 6) { - AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 61; addr <= 62; addr++) { + int count; + + if (addr == 61) { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r"); + } + else { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD3, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + if (addr == 61) { + count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + else { + count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + + ptr += count; } /* Convert to 64 bit integer in port order */ - int i = 0; uint64_t rx_los_all = 0 ; - for(i = 5; i >= 0; i--) { + bytes[3] &= 0x1F; + bytes[6] &= 0x7; + for(i = 6; i >= 4; i--) { rx_los_all <<= 8; rx_los_all |= bytes[i]; } + rx_los_all <<= 5; + rx_los_all |= bytes[3]; + + for(i = 2; i >= 0; i--) { + rx_los_all <<= 8; + rx_los_all |= bytes[i]; + } + + /* Populate bitmap */ for(i = 0; rx_los_all; i++) { AIM_BITMAP_MOD(dst, i, (rx_los_all & 1)); @@ -194,50 +227,102 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = sfp_get_port_path(port, "sfp_eeprom"); - /* * Read the SFP eeprom into data[] * * Return MISSING if SFP is missing. * Return OK if eeprom is read */ + int size = 0; memset(data, 0, 256); - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; } int onlp_sfpi_dom_read(int port, uint8_t data[256]) { - char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom"); - memset(data, 0, 256); + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } return ONLP_STATUS_OK; } +int +onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 29) ? 61 : 62; + int bus = (addr == 61) ? 10 : 11; + switch(control) { case ONLP_SFP_CONTROL_TX_DISABLE: { - char* path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_write_integer(path, value) != 0) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -259,16 +344,20 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; - char* path = NULL; + + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 29) ? 61 : 62; + int bus = (addr == 61) ? 10 : 11; switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - path = sfp_get_port_path(port, "sfp_rx_los"); - - if (onlp_file_read_int(value, path) < 0) { - AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -279,9 +368,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - path = sfp_get_port_path(port, "sfp_tx_fault"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -293,9 +380,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -312,9 +397,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) return rv; } - int onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/platform-config/r0/src/python/x86_64_accton_as5822_54x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/platform-config/r0/src/python/x86_64_accton_as5822_54x_r0/__init__.py index dff6590e..88005cae 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/platform-config/r0/src/python/x86_64_accton_as5822_54x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5822-54x/platform-config/r0/src/python/x86_64_accton_as5822_54x_r0/__init__.py @@ -8,9 +8,9 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton, SYS_OBJECT_ID=".5822.54" def baseconfig(self): - self.insmod("accton_i2c_cpld") + self.insmod('optoe') self.insmod("ym2651y") - for m in [ "sfp", "psu", "fan", "leds" ]: + for m in [ 'cpld', 'fan', 'psu', 'leds' ]: self.insmod("x86-64-accton-as5822-54x-%s" % m) ########### initialize I2C bus 0 ########### @@ -20,7 +20,7 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton, ('pca9548', 0x72, 0), # initialize CPLD - ('accton_i2c_cpld', 0x60, 6), + ('as5822_54x_cpld1', 0x60, 6), # initiate PSU-1 AC Power ('as5822_54x_psu1', 0x50, 3), @@ -45,8 +45,8 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton, ('pca9548', 0x70, 1), # initialize CPLD - ('accton_i2c_cpld', 0x61, 10), - ('accton_i2c_cpld', 0x62, 11), + ('as5822_54x_cpld2', 0x61, 10), + ('as5822_54x_cpld3', 0x62, 11), # initialize multiplexer (PCA9548) ('pca9548', 0x71, 12), @@ -64,11 +64,13 @@ class OnlPlatform_x86_64_accton_as5822_54x_r0(OnlPlatformAccton, # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5822_54x_sfp%d' % port, 0x50, port+17) - self.new_i2c_device('as5822_54x_sfp%d' % port, 0x51, port+17) + self.new_i2c_device('optoe2', 0x50, port+17) # initialize QSFP devices for port in range(49, 55): - self.new_i2c_device('as5822_54x_sfp%d' % port, 0x50, port+17) + self.new_i2c_device('optoe1', 0x50, port+17) + + for port in range(1, 55): + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+17), shell=True) return True From 721c3827c8f0729bfbb7e425393e57fa31bdd628 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Wed, 28 Mar 2018 16:53:47 +0800 Subject: [PATCH 12/21] [as5916-54xm] Add support for OOM --- .../builds/x86-64-accton-as5916-54xm-cpld.c | 1098 ++++++++++++++ .../builds/x86-64-accton-as5916-54xm-leds.c | 8 +- .../builds/x86-64-accton-as5916-54xm-psu.c | 4 +- .../builds/x86-64-accton-as5916-54xm-sfp.c | 1315 ----------------- .../onlp/builds/src/module/src/sfpi.c | 218 +-- .../x86_64_accton_as5916_54xm_r0/__init__.py | 16 +- 6 files changed, 1238 insertions(+), 1421 deletions(-) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-cpld.c delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-cpld.c new file mode 100644 index 00000000..d7074786 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-cpld.c @@ -0,0 +1,1098 @@ +/* + * Copyright (C) Brandon Chuang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as5916_54x CPLD1/CPLD2 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as5916_54xm_cpld1, + as5916_54xm_cpld2 +}; + +struct as5916_54xm_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as5916_54xm_cpld_id[] = { + { "as5916_54xm_cpld1", as5916_54xm_cpld1 }, + { "as5916_54xm_cpld2", as5916_54xm_cpld2 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5916_54xm_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as5916_54xm_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_PRESENT_ATTR_ID(35), + TRANSCEIVER_PRESENT_ATTR_ID(36), + TRANSCEIVER_PRESENT_ATTR_ID(37), + TRANSCEIVER_PRESENT_ATTR_ID(38), + TRANSCEIVER_PRESENT_ATTR_ID(39), + TRANSCEIVER_PRESENT_ATTR_ID(40), + TRANSCEIVER_PRESENT_ATTR_ID(41), + TRANSCEIVER_PRESENT_ATTR_ID(42), + TRANSCEIVER_PRESENT_ATTR_ID(43), + TRANSCEIVER_PRESENT_ATTR_ID(44), + TRANSCEIVER_PRESENT_ATTR_ID(45), + TRANSCEIVER_PRESENT_ATTR_ID(46), + TRANSCEIVER_PRESENT_ATTR_ID(47), + TRANSCEIVER_PRESENT_ATTR_ID(48), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(1), + TRANSCEIVER_TXDISABLE_ATTR_ID(2), + TRANSCEIVER_TXDISABLE_ATTR_ID(3), + TRANSCEIVER_TXDISABLE_ATTR_ID(4), + TRANSCEIVER_TXDISABLE_ATTR_ID(5), + TRANSCEIVER_TXDISABLE_ATTR_ID(6), + TRANSCEIVER_TXDISABLE_ATTR_ID(7), + TRANSCEIVER_TXDISABLE_ATTR_ID(8), + TRANSCEIVER_TXDISABLE_ATTR_ID(9), + TRANSCEIVER_TXDISABLE_ATTR_ID(10), + TRANSCEIVER_TXDISABLE_ATTR_ID(11), + TRANSCEIVER_TXDISABLE_ATTR_ID(12), + TRANSCEIVER_TXDISABLE_ATTR_ID(13), + TRANSCEIVER_TXDISABLE_ATTR_ID(14), + TRANSCEIVER_TXDISABLE_ATTR_ID(15), + TRANSCEIVER_TXDISABLE_ATTR_ID(16), + TRANSCEIVER_TXDISABLE_ATTR_ID(17), + TRANSCEIVER_TXDISABLE_ATTR_ID(18), + TRANSCEIVER_TXDISABLE_ATTR_ID(19), + TRANSCEIVER_TXDISABLE_ATTR_ID(20), + TRANSCEIVER_TXDISABLE_ATTR_ID(21), + TRANSCEIVER_TXDISABLE_ATTR_ID(22), + TRANSCEIVER_TXDISABLE_ATTR_ID(23), + TRANSCEIVER_TXDISABLE_ATTR_ID(24), + TRANSCEIVER_TXDISABLE_ATTR_ID(25), + TRANSCEIVER_TXDISABLE_ATTR_ID(26), + TRANSCEIVER_TXDISABLE_ATTR_ID(27), + TRANSCEIVER_TXDISABLE_ATTR_ID(28), + TRANSCEIVER_TXDISABLE_ATTR_ID(29), + TRANSCEIVER_TXDISABLE_ATTR_ID(30), + TRANSCEIVER_TXDISABLE_ATTR_ID(31), + TRANSCEIVER_TXDISABLE_ATTR_ID(32), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(35), + TRANSCEIVER_TXDISABLE_ATTR_ID(36), + TRANSCEIVER_TXDISABLE_ATTR_ID(37), + TRANSCEIVER_TXDISABLE_ATTR_ID(38), + TRANSCEIVER_TXDISABLE_ATTR_ID(39), + TRANSCEIVER_TXDISABLE_ATTR_ID(40), + TRANSCEIVER_TXDISABLE_ATTR_ID(41), + TRANSCEIVER_TXDISABLE_ATTR_ID(42), + TRANSCEIVER_TXDISABLE_ATTR_ID(43), + TRANSCEIVER_TXDISABLE_ATTR_ID(44), + TRANSCEIVER_TXDISABLE_ATTR_ID(45), + TRANSCEIVER_TXDISABLE_ATTR_ID(46), + TRANSCEIVER_TXDISABLE_ATTR_ID(47), + TRANSCEIVER_TXDISABLE_ATTR_ID(48), + TRANSCEIVER_RXLOS_ATTR_ID(1), + TRANSCEIVER_RXLOS_ATTR_ID(2), + TRANSCEIVER_RXLOS_ATTR_ID(3), + TRANSCEIVER_RXLOS_ATTR_ID(4), + TRANSCEIVER_RXLOS_ATTR_ID(5), + TRANSCEIVER_RXLOS_ATTR_ID(6), + TRANSCEIVER_RXLOS_ATTR_ID(7), + TRANSCEIVER_RXLOS_ATTR_ID(8), + TRANSCEIVER_RXLOS_ATTR_ID(9), + TRANSCEIVER_RXLOS_ATTR_ID(10), + TRANSCEIVER_RXLOS_ATTR_ID(11), + TRANSCEIVER_RXLOS_ATTR_ID(12), + TRANSCEIVER_RXLOS_ATTR_ID(13), + TRANSCEIVER_RXLOS_ATTR_ID(14), + TRANSCEIVER_RXLOS_ATTR_ID(15), + TRANSCEIVER_RXLOS_ATTR_ID(16), + TRANSCEIVER_RXLOS_ATTR_ID(17), + TRANSCEIVER_RXLOS_ATTR_ID(18), + TRANSCEIVER_RXLOS_ATTR_ID(19), + TRANSCEIVER_RXLOS_ATTR_ID(20), + TRANSCEIVER_RXLOS_ATTR_ID(21), + TRANSCEIVER_RXLOS_ATTR_ID(22), + TRANSCEIVER_RXLOS_ATTR_ID(23), + TRANSCEIVER_RXLOS_ATTR_ID(24), + TRANSCEIVER_RXLOS_ATTR_ID(25), + TRANSCEIVER_RXLOS_ATTR_ID(26), + TRANSCEIVER_RXLOS_ATTR_ID(27), + TRANSCEIVER_RXLOS_ATTR_ID(28), + TRANSCEIVER_RXLOS_ATTR_ID(29), + TRANSCEIVER_RXLOS_ATTR_ID(30), + TRANSCEIVER_RXLOS_ATTR_ID(31), + TRANSCEIVER_RXLOS_ATTR_ID(32), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(35), + TRANSCEIVER_RXLOS_ATTR_ID(36), + TRANSCEIVER_RXLOS_ATTR_ID(37), + TRANSCEIVER_RXLOS_ATTR_ID(38), + TRANSCEIVER_RXLOS_ATTR_ID(39), + TRANSCEIVER_RXLOS_ATTR_ID(40), + TRANSCEIVER_RXLOS_ATTR_ID(41), + TRANSCEIVER_RXLOS_ATTR_ID(42), + TRANSCEIVER_RXLOS_ATTR_ID(43), + TRANSCEIVER_RXLOS_ATTR_ID(44), + TRANSCEIVER_RXLOS_ATTR_ID(45), + TRANSCEIVER_RXLOS_ATTR_ID(46), + TRANSCEIVER_RXLOS_ATTR_ID(47), + TRANSCEIVER_RXLOS_ATTR_ID(48), + TRANSCEIVER_TXFAULT_ATTR_ID(1), + TRANSCEIVER_TXFAULT_ATTR_ID(2), + TRANSCEIVER_TXFAULT_ATTR_ID(3), + TRANSCEIVER_TXFAULT_ATTR_ID(4), + TRANSCEIVER_TXFAULT_ATTR_ID(5), + TRANSCEIVER_TXFAULT_ATTR_ID(6), + TRANSCEIVER_TXFAULT_ATTR_ID(7), + TRANSCEIVER_TXFAULT_ATTR_ID(8), + TRANSCEIVER_TXFAULT_ATTR_ID(9), + TRANSCEIVER_TXFAULT_ATTR_ID(10), + TRANSCEIVER_TXFAULT_ATTR_ID(11), + TRANSCEIVER_TXFAULT_ATTR_ID(12), + TRANSCEIVER_TXFAULT_ATTR_ID(13), + TRANSCEIVER_TXFAULT_ATTR_ID(14), + TRANSCEIVER_TXFAULT_ATTR_ID(15), + TRANSCEIVER_TXFAULT_ATTR_ID(16), + TRANSCEIVER_TXFAULT_ATTR_ID(17), + TRANSCEIVER_TXFAULT_ATTR_ID(18), + TRANSCEIVER_TXFAULT_ATTR_ID(19), + TRANSCEIVER_TXFAULT_ATTR_ID(20), + TRANSCEIVER_TXFAULT_ATTR_ID(21), + TRANSCEIVER_TXFAULT_ATTR_ID(22), + TRANSCEIVER_TXFAULT_ATTR_ID(23), + TRANSCEIVER_TXFAULT_ATTR_ID(24), + TRANSCEIVER_TXFAULT_ATTR_ID(25), + TRANSCEIVER_TXFAULT_ATTR_ID(26), + TRANSCEIVER_TXFAULT_ATTR_ID(27), + TRANSCEIVER_TXFAULT_ATTR_ID(28), + TRANSCEIVER_TXFAULT_ATTR_ID(29), + TRANSCEIVER_TXFAULT_ATTR_ID(30), + TRANSCEIVER_TXFAULT_ATTR_ID(31), + TRANSCEIVER_TXFAULT_ATTR_ID(32), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(35), + TRANSCEIVER_TXFAULT_ATTR_ID(36), + TRANSCEIVER_TXFAULT_ATTR_ID(37), + TRANSCEIVER_TXFAULT_ATTR_ID(38), + TRANSCEIVER_TXFAULT_ATTR_ID(39), + TRANSCEIVER_TXFAULT_ATTR_ID(40), + TRANSCEIVER_TXFAULT_ATTR_ID(41), + TRANSCEIVER_TXFAULT_ATTR_ID(42), + TRANSCEIVER_TXFAULT_ATTR_ID(43), + TRANSCEIVER_TXFAULT_ATTR_ID(44), + TRANSCEIVER_TXFAULT_ATTR_ID(45), + TRANSCEIVER_TXFAULT_ATTR_ID(46), + TRANSCEIVER_TXFAULT_ATTR_ID(47), + TRANSCEIVER_TXFAULT_ATTR_ID(48), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as5916_54xm_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5916_54xm_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); + +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); + +static struct attribute *as5916_54xm_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_SFP_TRANSCEIVER_ATTR(1), + DECLARE_SFP_TRANSCEIVER_ATTR(2), + DECLARE_SFP_TRANSCEIVER_ATTR(3), + DECLARE_SFP_TRANSCEIVER_ATTR(4), + DECLARE_SFP_TRANSCEIVER_ATTR(5), + DECLARE_SFP_TRANSCEIVER_ATTR(6), + DECLARE_SFP_TRANSCEIVER_ATTR(7), + DECLARE_SFP_TRANSCEIVER_ATTR(8), + DECLARE_SFP_TRANSCEIVER_ATTR(9), + DECLARE_SFP_TRANSCEIVER_ATTR(10), + DECLARE_SFP_TRANSCEIVER_ATTR(11), + DECLARE_SFP_TRANSCEIVER_ATTR(12), + DECLARE_SFP_TRANSCEIVER_ATTR(13), + DECLARE_SFP_TRANSCEIVER_ATTR(14), + DECLARE_SFP_TRANSCEIVER_ATTR(15), + DECLARE_SFP_TRANSCEIVER_ATTR(16), + DECLARE_SFP_TRANSCEIVER_ATTR(17), + DECLARE_SFP_TRANSCEIVER_ATTR(18), + DECLARE_SFP_TRANSCEIVER_ATTR(19), + DECLARE_SFP_TRANSCEIVER_ATTR(20), + DECLARE_SFP_TRANSCEIVER_ATTR(21), + DECLARE_SFP_TRANSCEIVER_ATTR(22), + DECLARE_SFP_TRANSCEIVER_ATTR(23), + DECLARE_SFP_TRANSCEIVER_ATTR(24), + NULL +}; + +static const struct attribute_group as5916_54xm_cpld1_group = { + .attrs = as5916_54xm_cpld1_attributes, +}; + +static struct attribute *as5916_54xm_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_TRANSCEIVER_PRESENT_ATTR(33), + DECLARE_TRANSCEIVER_PRESENT_ATTR(34), + DECLARE_TRANSCEIVER_PRESENT_ATTR(35), + DECLARE_TRANSCEIVER_PRESENT_ATTR(36), + DECLARE_TRANSCEIVER_PRESENT_ATTR(37), + DECLARE_TRANSCEIVER_PRESENT_ATTR(38), + DECLARE_TRANSCEIVER_PRESENT_ATTR(39), + DECLARE_TRANSCEIVER_PRESENT_ATTR(40), + DECLARE_TRANSCEIVER_PRESENT_ATTR(41), + DECLARE_TRANSCEIVER_PRESENT_ATTR(42), + DECLARE_TRANSCEIVER_PRESENT_ATTR(43), + DECLARE_TRANSCEIVER_PRESENT_ATTR(44), + DECLARE_TRANSCEIVER_PRESENT_ATTR(45), + DECLARE_TRANSCEIVER_PRESENT_ATTR(46), + DECLARE_TRANSCEIVER_PRESENT_ATTR(47), + DECLARE_TRANSCEIVER_PRESENT_ATTR(48), + DECLARE_TRANSCEIVER_PRESENT_ATTR(49), + DECLARE_TRANSCEIVER_PRESENT_ATTR(50), + DECLARE_TRANSCEIVER_PRESENT_ATTR(51), + DECLARE_TRANSCEIVER_PRESENT_ATTR(52), + DECLARE_TRANSCEIVER_PRESENT_ATTR(53), + DECLARE_TRANSCEIVER_PRESENT_ATTR(54), + DECLARE_SFP_TRANSCEIVER_ATTR(25), + DECLARE_SFP_TRANSCEIVER_ATTR(26), + DECLARE_SFP_TRANSCEIVER_ATTR(27), + DECLARE_SFP_TRANSCEIVER_ATTR(28), + DECLARE_SFP_TRANSCEIVER_ATTR(29), + DECLARE_SFP_TRANSCEIVER_ATTR(30), + DECLARE_SFP_TRANSCEIVER_ATTR(31), + DECLARE_SFP_TRANSCEIVER_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + DECLARE_SFP_TRANSCEIVER_ATTR(35), + DECLARE_SFP_TRANSCEIVER_ATTR(36), + DECLARE_SFP_TRANSCEIVER_ATTR(37), + DECLARE_SFP_TRANSCEIVER_ATTR(38), + DECLARE_SFP_TRANSCEIVER_ATTR(39), + DECLARE_SFP_TRANSCEIVER_ATTR(40), + DECLARE_SFP_TRANSCEIVER_ATTR(41), + DECLARE_SFP_TRANSCEIVER_ATTR(42), + DECLARE_SFP_TRANSCEIVER_ATTR(43), + DECLARE_SFP_TRANSCEIVER_ATTR(44), + DECLARE_SFP_TRANSCEIVER_ATTR(45), + DECLARE_SFP_TRANSCEIVER_ATTR(46), + DECLARE_SFP_TRANSCEIVER_ATTR(47), + DECLARE_SFP_TRANSCEIVER_ATTR(48), + NULL +}; + +static const struct attribute_group as5916_54xm_cpld2_group = { + .attrs = as5916_54xm_cpld2_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status, num_regs = 0; + u8 values[4] = {0}; + u8 regs[] = {0x10, 0x11, 0x12, 0x52}; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + num_regs = (data->type == as5916_54xm_cpld1) ? 3 : 4; + + for (i = 0; i < num_regs; i++) { + status = as5916_54xm_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + if (data->type == as5916_54xm_cpld1) { + status = sprintf(buf, "%.2x %.2x %.2x\n", + values[0], values[1], values[2]); + } + else { /* as5916_54xm_cpld2 */ + values[3] &= 0x3F; + status = sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + } + + return status; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[3] = {0}; + u8 regs[] = {0x30, 0x32, 0x34}; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as5916_54xm_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 24 in order */ + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_33 ... MODULE_PRESENT_40: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_33); + break; + case MODULE_PRESENT_41 ... MODULE_PRESENT_48: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_41); + break; + case MODULE_PRESENT_49 ... MODULE_PRESENT_54: + reg = 0x52; + mask = 0x1 << (attr->index - MODULE_PRESENT_49); + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1); + break; + case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_9); + break; + case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_17); + break; + case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_25); + break; + case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_33); + break; + case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_41); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_8: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_1); + break; + case MODULE_RXLOS_9 ... MODULE_RXLOS_16: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_9); + break; + case MODULE_RXLOS_17 ... MODULE_RXLOS_24: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_17); + break; + case MODULE_RXLOS_25 ... MODULE_RXLOS_32: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_25); + break; + case MODULE_RXLOS_33 ... MODULE_RXLOS_40: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_33); + break; + case MODULE_RXLOS_41 ... MODULE_RXLOS_48: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_41); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as5916_54xm_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5916_54xm_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5916_54xm_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as5916_54xm_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as5916_54xm_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as5916_54xm_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5916_54xm_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as5916_54xm_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as5916_54xm_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as5916_54xm_cpld1: + group = &as5916_54xm_cpld1_group; + break; + case as5916_54xm_cpld2: + group = &as5916_54xm_cpld2_group; + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as5916_54xm_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as5916_54xm_cpld_remove(struct i2c_client *client) +{ + struct as5916_54xm_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as5916_54xm_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as5916_54xm_cpld1: + group = &as5916_54xm_cpld1_group; + break; + case as5916_54xm_cpld2: + group = &as5916_54xm_cpld2_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as5916_54xm_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as5916_54xm_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as5916_54xm_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5916_54xm_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5916_54xm_cpld_read); + +int as5916_54xm_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5916_54xm_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5916_54xm_cpld_write); + +static struct i2c_driver as5916_54xm_cpld_driver = { + .driver = { + .name = "as5916_54xm_cpld", + .owner = THIS_MODULE, + }, + .probe = as5916_54xm_cpld_probe, + .remove = as5916_54xm_cpld_remove, + .id_table = as5916_54xm_cpld_id, +}; + +static int __init as5916_54xm_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5916_54xm_cpld_driver); +} + +static void __exit as5916_54xm_cpld_exit(void) +{ + i2c_del_driver(&as5916_54xm_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as5916_54xm_cpld_init); +module_exit(as5916_54xm_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-leds.c index a0c31b13..04f39260 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-leds.c @@ -38,8 +38,8 @@ #define DEBUG_PRINT(fmt, args...) #endif -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5916_54xm_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5916_54xm_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); struct accton_as5916_54xm_led_data { struct platform_device *pdev; @@ -148,12 +148,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as5916_54xm_led_read_value(u8 reg) { - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); + return as5916_54xm_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } static int accton_as5916_54xm_led_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); + return as5916_54xm_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } static void accton_as5916_54xm_led_update(void) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-psu.c index 90f44103..05b9a86a 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-psu.c @@ -37,7 +37,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static int as5916_54xm_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5916_54xm_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned */ @@ -234,7 +234,7 @@ static struct as5916_54xm_psu_data *as5916_54xm_psu_update_device(struct device dev_dbg(&client->dev, "Starting as5916_54xm update\n"); /* Read psu status */ - status = accton_i2c_cpld_read(0x60, 0x2); + status = as5916_54xm_cpld_read(0x60, 0x2); if (status < 0) { dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-sfp.c deleted file mode 100644 index de1ed9bc..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/modules/builds/x86-64-accton-as5916-54xm-sfp.c +++ /dev/null @@ -1,1315 +0,0 @@ -/* - * SFP driver for accton as5916_54xm sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as5916_54xm_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 54 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 3 -#define I2C_RW_RETRY_INTERVAL 100 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) -#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 -#define SFF8472_10G_BASE_MASK 0xF0 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -/* Platform dependent +++ */ -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -/* Platform dependent --- */ - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - NULL -}; - -/* SFP ddm attributes for sysfs */ -static struct attribute *sfp_ddm_attributes[] = { - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as5916_54xm_sfp1, as5916_54xm_sfp2, as5916_54xm_sfp3, as5916_54xm_sfp4, as5916_54xm_sfp5, as5916_54xm_sfp6, as5916_54xm_sfp7, as5916_54xm_sfp8, -as5916_54xm_sfp9, as5916_54xm_sfp10, as5916_54xm_sfp11, as5916_54xm_sfp12, as5916_54xm_sfp13, as5916_54xm_sfp14, as5916_54xm_sfp15, as5916_54xm_sfp16, -as5916_54xm_sfp17, as5916_54xm_sfp18, as5916_54xm_sfp19, as5916_54xm_sfp20, as5916_54xm_sfp21, as5916_54xm_sfp22, as5916_54xm_sfp23, as5916_54xm_sfp24, -as5916_54xm_sfp25, as5916_54xm_sfp26, as5916_54xm_sfp27, as5916_54xm_sfp28, as5916_54xm_sfp29, as5916_54xm_sfp30, as5916_54xm_sfp31, as5916_54xm_sfp32, -as5916_54xm_sfp33, as5916_54xm_sfp34, as5916_54xm_sfp35, as5916_54xm_sfp36, as5916_54xm_sfp37, as5916_54xm_sfp38, as5916_54xm_sfp39, as5916_54xm_sfp40, -as5916_54xm_sfp41, as5916_54xm_sfp42, as5916_54xm_sfp43, as5916_54xm_sfp44, as5916_54xm_sfp45, as5916_54xm_sfp46, as5916_54xm_sfp47, as5916_54xm_sfp48, -as5916_54xm_sfp49, as5916_54xm_sfp50, as5916_54xm_sfp51, as5916_54xm_sfp52, as5916_54xm_sfp53, as5916_54xm_sfp54 -}; - -static const struct i2c_device_id sfp_device_id[] = { -{ "as5916_54xm_sfp1", as5916_54xm_sfp1 }, { "as5916_54xm_sfp2", as5916_54xm_sfp2 }, { "as5916_54xm_sfp3", as5916_54xm_sfp3 }, { "as5916_54xm_sfp4", as5916_54xm_sfp4 }, -{ "as5916_54xm_sfp5", as5916_54xm_sfp5 }, { "as5916_54xm_sfp6", as5916_54xm_sfp6 }, { "as5916_54xm_sfp7", as5916_54xm_sfp7 }, { "as5916_54xm_sfp8", as5916_54xm_sfp8 }, -{ "as5916_54xm_sfp9", as5916_54xm_sfp9 }, { "as5916_54xm_sfp10", as5916_54xm_sfp10 }, { "as5916_54xm_sfp11", as5916_54xm_sfp11 }, { "as5916_54xm_sfp12", as5916_54xm_sfp12 }, -{ "as5916_54xm_sfp13", as5916_54xm_sfp13 }, { "as5916_54xm_sfp14", as5916_54xm_sfp14 }, { "as5916_54xm_sfp15", as5916_54xm_sfp15 }, { "as5916_54xm_sfp16", as5916_54xm_sfp16 }, -{ "as5916_54xm_sfp17", as5916_54xm_sfp17 }, { "as5916_54xm_sfp18", as5916_54xm_sfp18 }, { "as5916_54xm_sfp19", as5916_54xm_sfp19 }, { "as5916_54xm_sfp20", as5916_54xm_sfp20 }, -{ "as5916_54xm_sfp21", as5916_54xm_sfp21 }, { "as5916_54xm_sfp22", as5916_54xm_sfp22 }, { "as5916_54xm_sfp23", as5916_54xm_sfp23 }, { "as5916_54xm_sfp24", as5916_54xm_sfp24 }, -{ "as5916_54xm_sfp25", as5916_54xm_sfp25 }, { "as5916_54xm_sfp26", as5916_54xm_sfp26 }, { "as5916_54xm_sfp27", as5916_54xm_sfp27 }, { "as5916_54xm_sfp28", as5916_54xm_sfp28 }, -{ "as5916_54xm_sfp29", as5916_54xm_sfp29 }, { "as5916_54xm_sfp30", as5916_54xm_sfp30 }, { "as5916_54xm_sfp31", as5916_54xm_sfp31 }, { "as5916_54xm_sfp32", as5916_54xm_sfp32 }, -{ "as5916_54xm_sfp33", as5916_54xm_sfp33 }, { "as5916_54xm_sfp34", as5916_54xm_sfp34 }, { "as5916_54xm_sfp35", as5916_54xm_sfp35 }, { "as5916_54xm_sfp36", as5916_54xm_sfp36 }, -{ "as5916_54xm_sfp37", as5916_54xm_sfp37 }, { "as5916_54xm_sfp38", as5916_54xm_sfp38 }, { "as5916_54xm_sfp39", as5916_54xm_sfp39 }, { "as5916_54xm_sfp40", as5916_54xm_sfp40 }, -{ "as5916_54xm_sfp41", as5916_54xm_sfp41 }, { "as5916_54xm_sfp42", as5916_54xm_sfp42 }, { "as5916_54xm_sfp43", as5916_54xm_sfp43 }, { "as5916_54xm_sfp44", as5916_54xm_sfp44 }, -{ "as5916_54xm_sfp45", as5916_54xm_sfp45 }, { "as5916_54xm_sfp46", as5916_54xm_sfp46 }, { "as5916_54xm_sfp47", as5916_54xm_sfp47 }, { "as5916_54xm_sfp48", as5916_54xm_sfp48 }, -{ "as5916_54xm_sfp49", as5916_54xm_sfp49 }, { "as5916_54xm_sfp50", as5916_54xm_sfp50 }, { "as5916_54xm_sfp51", as5916_54xm_sfp51 }, { "as5916_54xm_sfp52", as5916_54xm_sfp52 }, -{ "as5916_54xm_sfp53", as5916_54xm_sfp53 }, { "as5916_54xm_sfp54", as5916_54xm_sfp54 }, -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -/* - * list of valid port types - * note OOM_PORT_TYPE_NOT_PRESENT to indicate no - * module is present in this port - */ -typedef enum oom_driver_port_type_e { - OOM_DRIVER_PORT_TYPE_INVALID, - OOM_DRIVER_PORT_TYPE_NOT_PRESENT, - OOM_DRIVER_PORT_TYPE_SFP, - OOM_DRIVER_PORT_TYPE_SFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP, - OOM_DRIVER_PORT_TYPE_QSFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP28 -} oom_driver_port_type_t; - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[6]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss - 3 => device id - 4 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 5 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -}; - -struct sfp_ddm_data { - struct eeprom_data eeprom; -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - oom_driver_port_type_t port_type; - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct sfp_ddm_data *ddm; - struct qsfp_data *qsfp; - - struct i2c_client *client; -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - int i = 0, j = 0, status = -1; - u8 reg; - unsigned short cpld_addr; - struct sfp_port_data *data = i2c_get_clientdata(client); - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - data->present = 0; - - /* Read present status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) { - cpld_addr = I2C_ADDR_CPLD1 + i*2; - reg = 0x10+j; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); - data->present |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* Read present status of port 49-52(QSFP port) */ - cpld_addr = I2C_ADDR_CPLD2; - reg = 0x52; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - else { - data->present |= (u64)(status & 0x3F) << 48; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; - - if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { - return data; - } - - DEBUG_PRINT("Starting as5916_54xm sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->msa->valid = 0; - memset(data->msa->status, 0, sizeof(data->msa->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { - unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; - - status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); - goto exit; - } - - data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - data->msa->valid = 1; - data->msa->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_set_tx_disable(dev, da, buf, count); - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = I2C_ADDR_CPLD1; - cpld_reg = tx_disable_regs[data->port / 8]; - cpld_bit = 1 << (data->port % 8); - } - else { /* port 24 ~ 48 */ - cpld_addr = I2C_ADDR_CPLD2; - cpld_reg = tx_disable_regs[(data->port - 24) / 8]; - cpld_bit = 1 << (data->port % 8); - } - - /* Read current status */ - cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->msa->status[1] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->msa->status[1] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - mutex_unlock(&data->update_lock); - return count; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ -} - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[7] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *sfp_update_port_type(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 buf = 0; - int status; - - mutex_lock(&data->update_lock); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - if (buf != SFF8024_DEVICE_ID_SFP) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); - data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; - break; - } - case DRIVER_TYPE_QSFP: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); - switch (buf) { - case SFF8024_DEVICE_ID_QSFP: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; - break; - case SFF8024_DEVICE_ID_QSFP_PLUS: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - case SFF8024_DEVICE_ID_QSFP28: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - default: - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - break; - } - default: - break; - } - - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - if (!present) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_type(dev); - return sprintf(buf, "%d\n", data->port_type); -} - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - data->qsfp->status[1] = disable & 0xF; - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, - char *buf) -{ - int status; - char ddm; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (status == 0) { - /* port is not present */ - return -ENODEV; - } - - status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); - if (unlikely(status < 0)) { - return status; - } - - return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); -} - -/* Platform dependent +++ */ -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_show_tx_rx_status(dev, da, buf); - } - - data = sfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - if(attr->index == RX_LOS_ALL) { - int i = 0; - u8 values[6] = {0}; - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = (u8)(data->msa->status[2] >> (i * 8)); - } - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - return 0; - } - - val = !!(data->msa->status[index] & BIT_INDEX(data->port)); - return sprintf(buf, "%d\n", val); -} -/* Platform dependent --- */ -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -static ssize_t sfp_port_write(struct sfp_port_data *data, - 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(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} - - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_write(data, buf, off, count); -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_read(data, buf, off, count); -} - -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; - eeprom->size = EEPROM_SIZE; - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group sfp_ddm_group = { - .attrs = sfp_ddm_attributes, -}; - -static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_ddm_data **data) -{ - int status; - struct sfp_ddm_data *ddm; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); - if (!ddm) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = ddm; - dev_info(&client->dev, "sfp ddm '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); -exit_free: - kfree(ddm); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct sfp_port_data *data = NULL; - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (dev_id->driver_data >= as5916_54xm_sfp1 && dev_id->driver_data <= as5916_54xm_sfp48) { - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_MSA; - return sfp_msa_probe(client, dev_id, &data->msa); - } - else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_DDM; - return sfp_ddm_probe(client, dev_id, &data->ddm); - } - } - else { /* as5916_54xm_sfp49 ~ as5916_54xm_sfp54 */ - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_QSFP; - return qsfp_probe(client, dev_id, &data->qsfp); - } - } - - return -ENODEV; -} -/* Platform dependent --- */ - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_SFP_DDM: - return sfp_ddm_remove(client, data->ddm); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - - return 0; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5916_54xm_sfp driver"); -MODULE_LICENSE("GPL"); - -late_initcall(sfp_init); -module_exit(sfp_exit); - - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/onlp/builds/src/module/src/sfpi.c index 965c08d4..26939c81 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/onlp/builds/src/module/src/sfpi.c @@ -24,29 +24,21 @@ * ***********************************************************/ #include +#include #include -#include "platform_lib.h" - +#include "x86_64_accton_as5916_54xm_int.h" #include "x86_64_accton_as5916_54xm_log.h" -#define NUM_OF_SFP_PORT 54 -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define FRONT_PORT_BUS_INDEX(port) ((port <48)? (port+41):(port-23)) +#define PORT_BUS_INDEX(port) ((port <48)? (port+41):(port-23)) -static char* -sfp_get_port_path_addr(int port, int addr, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-00%d/%s", - FRONT_PORT_BUS_INDEX(port), addr, node_name); - return sfp_node_path; -} - -static char* -sfp_get_port_path(int port, char *node_name) -{ - return sfp_get_port_path_addr(port, 50, node_name); -} +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD1 "/sys/bus/i2c/devices/11-0060/module_rx_los_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/12-0062/module_rx_los_all" /************************************************************ * @@ -67,8 +59,8 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) * Ports {0, 54} */ int p; - - for(p = 0; p < NUM_OF_SFP_PORT; p++) { + + for(p = 0; p < 54; p++) { AIM_BITMAP_SET(bmap, p); } @@ -84,9 +76,12 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char *path = sfp_get_port_path(port, "sfp_is_present"); + int bus, addr; - if (onlp_file_read_int(&present, path) < 0) { + addr = (port < 24) ? 60 : 62; + bus = (addr == 60) ? 11 : 12; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -97,33 +92,45 @@ onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[7]; - char* path; + uint32_t bytes[7], *ptr = NULL; FILE* fp; + int addr; - AIM_BITMAP_CLR_ALL(dst); + ptr = bytes; - path = sfp_get_port_path(0, "sfp_is_present_all"); - fp = fopen(path, "r"); + for (addr = 60; addr <= 62; addr+=2) { + /* Read present status of port 0~53 */ + int count = 0; + char file[64] = {0}; + int bus = (addr == 60) ? 11 : 12; + + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5, - bytes+6 - ); - fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { - /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; + if (addr == 60) { /* CPLD1 */ + count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + else { /* CPLD2 */ + count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + + ptr += count; } /* Mask out non-existant QSFP ports */ @@ -150,34 +157,40 @@ int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[6]; - char* path; + uint32_t *ptr = bytes; FILE* fp; - path = sfp_get_port_path(0, "sfp_rx_los_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~23 */ + int addr, i = 0; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5 - ); - fclose(fp); - if(count != 6) { - AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 60; addr <= 62; addr+=2) { + if (addr == 60) { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r"); + } + else { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Convert to 64 bit integer in port order */ - int i = 0; + i = 0; uint64_t rx_los_all = 0 ; - for(i = 5; i >= 0; i--) { + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { rx_los_all <<= 8; rx_los_all |= bytes[i]; } @@ -194,32 +207,51 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = sfp_get_port_path(port, "sfp_eeprom"); - /* * Read the SFP eeprom into data[] * * Return MISSING if SFP is missing. * Return OK if eeprom is read */ + int size = 0; memset(data, 0, 256); - - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; } int onlp_sfpi_dom_read(int port, uint8_t data[256]) { - char* path = sfp_get_port_path_addr(port, 51, "sfp_eeprom"); - memset(data, 0, 256); + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } - if (onlp_file_read_binary(path, (char*)data, 256, 256) != 0) { - AIM_LOG_INFO("Unable to read eeprom from port(%d)\r\n", port); + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); return ONLP_STATUS_E_INTERNAL; } @@ -231,13 +263,18 @@ onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 11 : 12; + switch(control) { case ONLP_SFP_CONTROL_TX_DISABLE: { - char* path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_write_integer(path, value) != 0) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -259,16 +296,20 @@ int onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; - char* path = NULL; + + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 11 : 12; switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - path = sfp_get_port_path(port, "sfp_rx_los"); - - if (onlp_file_read_int(value, path) < 0) { - AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -279,9 +320,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - path = sfp_get_port_path(port, "sfp_tx_fault"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -293,9 +332,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - path = sfp_get_port_path(port, "sfp_tx_disable"); - - if (onlp_file_read_int(value, path) < 0) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -312,12 +349,9 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) return rv; } - int onlp_sfpi_denit(void) { return ONLP_STATUS_OK; } - - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/platform-config/r0/src/python/x86_64_accton_as5916_54xm_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/platform-config/r0/src/python/x86_64_accton_as5916_54xm_r0/__init__.py index 454c3122..11dd6fed 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/platform-config/r0/src/python/x86_64_accton_as5916_54xm_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54xm/platform-config/r0/src/python/x86_64_accton_as5916_54xm_r0/__init__.py @@ -8,9 +8,9 @@ class OnlPlatform_x86_64_accton_as5916_54xm_r0(OnlPlatformAccton, SYS_OBJECT_ID=".5916.54" def baseconfig(self): - self.insmod("accton_i2c_cpld") + self.insmod('optoe') self.insmod("ym2651y") - for m in [ "sfp", "psu", "fan", "leds" ]: + for m in [ "cpld", "psu", "fan", "leds" ]: self.insmod("x86-64-accton-as5916-54xm-%s" % m) ########### initialize I2C bus 0 ########### @@ -36,8 +36,8 @@ class OnlPlatform_x86_64_accton_as5916_54xm_r0(OnlPlatformAccton, ('lm75', 0x4b, 10), # initialize CPLDs - ('accton_i2c_cpld', 0x60, 11), - ('accton_i2c_cpld', 0x62, 12), + ('as5916_54xm_cpld1', 0x60, 11), + ('as5916_54xm_cpld2', 0x62, 12), ] ) @@ -65,8 +65,8 @@ class OnlPlatform_x86_64_accton_as5916_54xm_r0(OnlPlatformAccton, ) # initialize QSFP devices for port in range(49, 55): - self.new_i2c_device('as5916_54xm_sfp%d' % port, 0x50, port-24) - + self.new_i2c_device('optoe1', 0x50, port-24) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port-24), shell=True) ########### initialize I2C bus 1 ########### @@ -85,8 +85,8 @@ class OnlPlatform_x86_64_accton_as5916_54xm_r0(OnlPlatformAccton, # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5916_54xm_sfp%d' % port, 0x50, port+40) - self.new_i2c_device('as5916_54xm_sfp%d' % port, 0x51, port+40) + self.new_i2c_device('optoe2', 0x50, port+40) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+40), shell=True) return True From c0423e08ed48111d3b576a0dc225849f33eb6d0f Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Wed, 28 Mar 2018 16:57:10 +0800 Subject: [PATCH 13/21] [as7512-32x] Add support for OOM --- .../builds/x86-64-accton-as7512-32x-cpld.c | 593 ++++++++++++++++++ .../builds/x86-64-accton-as7512-32x-fan.c | 19 +- .../builds/x86-64-accton-as7512-32x-leds.c | 13 +- .../builds/x86-64-accton-as7512-32x-psu.c | 21 +- .../builds/x86-64-accton-as7512-32x-sfp.c | 356 ----------- .../onlp/builds/src/module/src/sfpi.c | 96 ++- .../x86_64_accton_as7512_32x_r0/__init__.py | 18 +- 7 files changed, 657 insertions(+), 459 deletions(-) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-cpld.c delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-cpld.c new file mode 100644 index 00000000..bc105f3d --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-cpld.c @@ -0,0 +1,593 @@ +/* + * Copyright (C) Brandon Chuang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as7512_32x CPLD1/CPLD2/CPLD3 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as7512_32x_cpld1, + as7512_32x_cpld2, + as7512_32x_cpld3 +}; + +struct as7512_32x_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as7512_32x_cpld_id[] = { + { "as7512_32x_cpld1", as7512_32x_cpld1 }, + { "as7512_32x_cpld2", as7512_32x_cpld2 }, + { "as7512_32x_cpld3", as7512_32x_cpld3 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as7512_32x_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as7512_32x_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as7512_32x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as7512_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); + +static struct attribute *as7512_32x_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + NULL +}; + +static const struct attribute_group as7512_32x_cpld1_group = { + .attrs = as7512_32x_cpld1_attributes, +}; + +static struct attribute *as7512_32x_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as7512_32x_cpld2_group = { + .attrs = as7512_32x_cpld2_attributes, +}; + +static struct attribute *as7512_32x_cpld3_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + NULL +}; + +static const struct attribute_group as7512_32x_cpld3_group = { + .attrs = as7512_32x_cpld3_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[4] = {0}; + u8 regs[] = {0x30, 0x31, 0x32, 0x33}; + struct i2c_client *client = to_i2c_client(dev); + struct as7512_32x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as7512_32x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as7512_32x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x31; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x33; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_32) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as7512_32x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as7512_32x_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as7512_32x_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as7512_32x_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as7512_32x_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as7512_32x_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as7512_32x_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as7512_32x_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as7512_32x_cpld1: + group = &as7512_32x_cpld1_group; + break; + case as7512_32x_cpld2: + group = &as7512_32x_cpld2_group; + break; + case as7512_32x_cpld3: + group = &as7512_32x_cpld3_group; + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as7512_32x_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as7512_32x_cpld_remove(struct i2c_client *client) +{ + struct as7512_32x_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as7512_32x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as7512_32x_cpld1: + group = &as7512_32x_cpld1_group; + break; + case as7512_32x_cpld2: + group = &as7512_32x_cpld2_group; + break; + case as7512_32x_cpld3: + group = &as7512_32x_cpld3_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as7512_32x_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as7512_32x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as7512_32x_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as7512_32x_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as7512_32x_cpld_read); + +int as7512_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as7512_32x_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as7512_32x_cpld_write); + +static struct i2c_driver as7512_32x_cpld_driver = { + .driver = { + .name = "as7512_32x_cpld", + .owner = THIS_MODULE, + }, + .probe = as7512_32x_cpld_probe, + .remove = as7512_32x_cpld_remove, + .id_table = as7512_32x_cpld_id, +}; + +static int __init as7512_32x_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as7512_32x_cpld_driver); +} + +static void __exit as7512_32x_cpld_exit(void) +{ + i2c_del_driver(&as7512_32x_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as7512_32x_cpld_init); +module_exit(as7512_32x_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-fan.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-fan.c index 6dfa74f8..cfc9630f 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-fan.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-fan.c @@ -36,8 +36,6 @@ static struct as7512_32x_fan_data *as7512_32x_fan_update_device(struct device *d static ssize_t fan_show_value(struct device *dev, struct device_attribute *da, char *buf); static ssize_t set_duty_cycle(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); /* fan related data, the index should match sysfs_fan_attributes */ @@ -487,24 +485,9 @@ static struct i2c_driver as7512_32x_fan_driver = { .address_list = normal_i2c, }; -static int __init as7512_32x_fan_init(void) -{ - extern int platform_accton_as7512_32x(void); - if (!platform_accton_as7512_32x()) { - return -ENODEV; - } - - return i2c_add_driver(&as7512_32x_fan_driver); -} - -static void __exit as7512_32x_fan_exit(void) -{ - i2c_del_driver(&as7512_32x_fan_driver); -} +module_i2c_driver(as7512_32x_fan_driver); MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("as7512_32x_fan driver"); MODULE_LICENSE("GPL"); -module_init(as7512_32x_fan_init); -module_exit(as7512_32x_fan_exit); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-leds.c index 3dc5def5..ee771701 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-leds.c @@ -30,8 +30,8 @@ #include #include -extern int accton_i2c_cpld_read (unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as7512_32x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as7512_32x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); #define DRVNAME "as7512_32x_led" #define NUM_OF_LED_REG 5 @@ -191,12 +191,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as7512_32x_led_read_value(u8 reg) { - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); + return as7512_32x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } static int accton_as7512_32x_led_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); + return as7512_32x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } static void accton_as7512_32x_led_update(void) @@ -457,11 +457,6 @@ static int __init accton_as7512_32x_led_init(void) { int ret; - extern int platform_accton_as7512_32x(void); - if (!platform_accton_as7512_32x()) { - return -ENODEV; - } - ret = platform_driver_register(&accton_as7512_32x_led_driver); if (ret < 0) { goto exit; diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-psu.c index 3ab19698..3e4e4608 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-psu.c @@ -36,7 +36,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static int as7512_32x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as7512_32x_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned */ @@ -238,7 +238,7 @@ static struct as7512_32x_psu_data *as7512_32x_psu_update_device(struct device *d dev_dbg(&client->dev, "Starting as7512_32x update\n"); /* Read psu status */ - status = accton_i2c_cpld_read(0x60, 0x2); + status = as7512_32x_cpld_read(0x60, 0x2); if (status < 0) { dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); @@ -276,24 +276,9 @@ exit: return data; } -static int __init as7512_32x_psu_init(void) -{ - extern int platform_accton_as7512_32x(void); - if (!platform_accton_as7512_32x()) { - return -ENODEV; - } - - return i2c_add_driver(&as7512_32x_psu_driver); -} - -static void __exit as7512_32x_psu_exit(void) -{ - i2c_del_driver(&as7512_32x_psu_driver); -} +module_i2c_driver(as7512_32x_psu_driver); MODULE_AUTHOR("Brandon Chuang "); MODULE_DESCRIPTION("as7512_32x_psu driver"); MODULE_LICENSE("GPL"); -module_init(as7512_32x_psu_init); -module_exit(as7512_32x_psu_exit); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-sfp.c deleted file mode 100644 index f7560fb6..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/modules/builds/x86-64-accton-as7512-32x-sfp.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * An hwmon driver for accton as7512_32x sfp - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BIT_INDEX(i) (1UL << (i)) - - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { 0x50, I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7512_32x_sfp_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - int port; /* Front port index */ - char eeprom[256]; /* eeprom data */ - u32 is_present; /* present status */ -}; - -static struct as7512_32x_sfp_data *as7512_32x_sfp_update_device(struct device *dev); -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da,char *buf); -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, char *buf); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum as7512_32x_sfp_sysfs_attributes { - SFP_PORT_NUMBER, - SFP_IS_PRESENT, - SFP_IS_PRESENT_ALL, - SFP_EEPROM -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, SFP_PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, SFP_IS_PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, SFP_IS_PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_eeprom, S_IRUGO, show_eeprom, NULL, SFP_EEPROM); - -static struct attribute *as7512_32x_sfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_eeprom.dev_attr.attr, - NULL -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7512_32x_sfp_data *data = i2c_get_clientdata(client); - - return sprintf(buf, "%d\n", data->port+1); -} - -/* Error-check the CPLD read results. */ -#define VALIDATED_READ(_buf, _rv, _read_expr, _invert) \ -do { \ - _rv = (_read_expr); \ - if(_rv < 0) { \ - return sprintf(_buf, "READ ERROR\n"); \ - } \ - if(_invert) { \ - _rv = ~_rv; \ - } \ - _rv &= 0xFF; \ -} while(0) - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if(attr->index == SFP_IS_PRESENT_ALL) { - int values[4]; - /* - * Report the SFP_PRESENCE status for all ports. - */ - - /* SFP_PRESENT Ports 1-8 */ - VALIDATED_READ(buf, values[0], accton_i2c_cpld_read(0x60, 0x30), 1); - /* SFP_PRESENT Ports 9-16 */ - VALIDATED_READ(buf, values[1], accton_i2c_cpld_read(0x60, 0x31), 1); - /* SFP_PRESENT Ports 17-24 */ - VALIDATED_READ(buf, values[2], accton_i2c_cpld_read(0x60, 0x32), 1); - /* SFP_PRESENT Ports 25-32 */ - VALIDATED_READ(buf, values[3], accton_i2c_cpld_read(0x60, 0x33), 1); - - /* Return values 1 -> 32 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], values[3]); - } - else { /* SFP_IS_PRESENT */ - struct as7512_32x_sfp_data *data = as7512_32x_sfp_update_device(dev); - - if (!data->valid) { - return -EIO; - } - - return sprintf(buf, "%d\n", data->is_present); - } -} - -static ssize_t show_eeprom(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct as7512_32x_sfp_data *data = as7512_32x_sfp_update_device(dev); - - if (!data->valid) { - return 0; - } - - if (!data->is_present) { - return 0; - } - - memcpy(buf, data->eeprom, sizeof(data->eeprom)); - - return sizeof(data->eeprom); -} - -static const struct attribute_group as7512_32x_sfp_group = { - .attrs = as7512_32x_sfp_attributes, -}; - -static int as7512_32x_sfp_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7512_32x_sfp_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7512_32x_sfp_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - i2c_set_clientdata(client, data); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7512_32x_sfp_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: sfp '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7512_32x_sfp_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7512_32x_sfp_remove(struct i2c_client *client) -{ - struct as7512_32x_sfp_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7512_32x_sfp_group); - kfree(data); - - return 0; -} - -enum port_numbers { -as7512_32x_sfp1, as7512_32x_sfp2, as7512_32x_sfp3, as7512_32x_sfp4, -as7512_32x_sfp5, as7512_32x_sfp6, as7512_32x_sfp7, as7512_32x_sfp8, -as7512_32x_sfp9, as7512_32x_sfp10,as7512_32x_sfp11,as7512_32x_sfp12, -as7512_32x_sfp13,as7512_32x_sfp14,as7512_32x_sfp15,as7512_32x_sfp16, -as7512_32x_sfp17,as7512_32x_sfp18,as7512_32x_sfp19,as7512_32x_sfp20, -as7512_32x_sfp21,as7512_32x_sfp22,as7512_32x_sfp23,as7512_32x_sfp24, -as7512_32x_sfp25,as7512_32x_sfp26,as7512_32x_sfp27,as7512_32x_sfp28, -as7512_32x_sfp29,as7512_32x_sfp30,as7512_32x_sfp31,as7512_32x_sfp32 -}; - -static const struct i2c_device_id as7512_32x_sfp_id[] = { -{ "as7512_32x_sfp1", as7512_32x_sfp1 }, { "as7512_32x_sfp2", as7512_32x_sfp2 }, -{ "as7512_32x_sfp3", as7512_32x_sfp3 }, { "as7512_32x_sfp4", as7512_32x_sfp4 }, -{ "as7512_32x_sfp5", as7512_32x_sfp5 }, { "as7512_32x_sfp6", as7512_32x_sfp6 }, -{ "as7512_32x_sfp7", as7512_32x_sfp7 }, { "as7512_32x_sfp8", as7512_32x_sfp8 }, -{ "as7512_32x_sfp9", as7512_32x_sfp9 }, { "as7512_32x_sfp10", as7512_32x_sfp10 }, -{ "as7512_32x_sfp11", as7512_32x_sfp11 }, { "as7512_32x_sfp12", as7512_32x_sfp12 }, -{ "as7512_32x_sfp13", as7512_32x_sfp13 }, { "as7512_32x_sfp14", as7512_32x_sfp14 }, -{ "as7512_32x_sfp15", as7512_32x_sfp15 }, { "as7512_32x_sfp16", as7512_32x_sfp16 }, -{ "as7512_32x_sfp17", as7512_32x_sfp17 }, { "as7512_32x_sfp18", as7512_32x_sfp18 }, -{ "as7512_32x_sfp19", as7512_32x_sfp19 }, { "as7512_32x_sfp20", as7512_32x_sfp20 }, -{ "as7512_32x_sfp21", as7512_32x_sfp21 }, { "as7512_32x_sfp22", as7512_32x_sfp22 }, -{ "as7512_32x_sfp23", as7512_32x_sfp23 }, { "as7512_32x_sfp24", as7512_32x_sfp24 }, -{ "as7512_32x_sfp25", as7512_32x_sfp25 }, { "as7512_32x_sfp26", as7512_32x_sfp26 }, -{ "as7512_32x_sfp27", as7512_32x_sfp27 }, { "as7512_32x_sfp28", as7512_32x_sfp28 }, -{ "as7512_32x_sfp29", as7512_32x_sfp29 }, { "as7512_32x_sfp30", as7512_32x_sfp30 }, -{ "as7512_32x_sfp31", as7512_32x_sfp31 }, { "as7512_32x_sfp32", as7512_32x_sfp32 }, -{} -}; -MODULE_DEVICE_TABLE(i2c, as7512_32x_sfp_id); - -static struct i2c_driver as7512_32x_sfp_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7512_32x_sfp", - }, - .probe = as7512_32x_sfp_probe, - .remove = as7512_32x_sfp_remove, - .id_table = as7512_32x_sfp_id, - .address_list = normal_i2c, -}; - -static int as7512_32x_sfp_read_block(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ - int result = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - - if (unlikely(result < 0)) - goto abort; - if (unlikely(result != data_len)) { - result = -EIO; - goto abort; - } - - result = 0; - -abort: - return result; -} - -static struct as7512_32x_sfp_data *as7512_32x_sfp_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7512_32x_sfp_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status = -1; - int i = 0; - u8 cpld_reg = 0x30 + (data->port/8); - - data->valid = 0; - - /* Read present status of the specified port number */ - data->is_present = 0; - status = accton_i2c_cpld_read(0x60, cpld_reg); - - if (status < 0) { - dev_dbg(&client->dev, "cpld(0x60) reg(0x%x) err %d\n", cpld_reg, status); - goto exit; - } - - data->is_present = (status & (1 << (data->port % 8))) ? 0 : 1; - - /* Read eeprom data based on port number */ - memset(data->eeprom, 0, sizeof(data->eeprom)); - - /* Check if the port is present */ - if (data->is_present) { - /* read eeprom */ - for (i = 0; i < sizeof(data->eeprom)/I2C_SMBUS_BLOCK_MAX; i++) { - status = as7512_32x_sfp_read_block(client, i*I2C_SMBUS_BLOCK_MAX, - data->eeprom+(i*I2C_SMBUS_BLOCK_MAX), - I2C_SMBUS_BLOCK_MAX); - if (status < 0) { - dev_dbg(&client->dev, "unable to read eeprom from port(%d)\n", data->port); - goto exit; - } - } - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7512_32x_sfp_init(void) -{ - extern int platform_accton_as7512_32x(void); - if (!platform_accton_as7512_32x()) { - return -ENODEV; - } - - return i2c_add_driver(&as7512_32x_sfp_driver); -} - -static void __exit as7512_32x_sfp_exit(void) -{ - i2c_del_driver(&as7512_32x_sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as7512_32x_sfp driver"); -MODULE_LICENSE("GPL"); - -module_init(as7512_32x_sfp_init); -module_exit(as7512_32x_sfp_exit); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/sfpi.c index c478ecaa..b076631c 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/onlp/builds/src/module/src/sfpi.c @@ -25,43 +25,16 @@ ***********************************************************/ #include -#include /* For O_RDWR && open */ -#include -#include -#include -#include - +#include +#include #include "platform_lib.h" -#define MAX_SFP_PATH 64 -static char sfp_node_path[MAX_SFP_PATH] = {0}; -#define FRONT_PORT_TO_CPLD_MUX_INDEX(port) (port+18) -static int -as7512_32x_sfp_node_read_int(char *node_path, int *value, int data_len) -{ - int ret = 0; - char buf[8]; - *value = 0; +#define PORT_BUS_INDEX(port) (port+18) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" - ret = deviceNodeReadString(node_path, buf, sizeof(buf), data_len); - - if (ret == 0) { - *value = atoi(buf); - } - - return ret; -} - -static char* -as7512_32x_sfp_get_port_path(int port, char *node_name) -{ - sprintf(sfp_node_path, "/sys/bus/i2c/devices/%d-0050/%s", - FRONT_PORT_TO_CPLD_MUX_INDEX(port), - node_name); - - return sfp_node_path; -} +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/4-0060/module_present_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/4-0060/module_present_all" /************************************************************ * @@ -100,13 +73,12 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - char* path = as7512_32x_sfp_get_port_path(port, "sfp_is_present"); - if (as7512_32x_sfp_node_read_int(path, &present, 0) != 0) { + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } - + return present; } @@ -114,12 +86,10 @@ int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[4]; - char* path; FILE* fp; - path = as7512_32x_sfp_get_port_path(0, "sfp_is_present_all"); - fp = fopen(path, "r"); - + fp = fopen(MODULE_PRESENT_ALL_ATTR, "r"); + if(fp == NULL) { AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); return ONLP_STATUS_E_INTERNAL; @@ -154,33 +124,59 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } -int -onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) -{ - return ONLP_STATUS_OK; -} - int onlp_sfpi_eeprom_read(int port, uint8_t data[256]) { - char* path = as7512_32x_sfp_get_port_path(port, "sfp_eeprom"); - /* * Read the SFP eeprom into data[] * * Return MISSING if SFP is missing. * Return OK if eeprom is read */ + int size = 0; memset(data, 0, 256); - - if (deviceNodeReadBinary(path, (char*)data, 256, 256) != 0) { + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + return ONLP_STATUS_OK; } +int +onlp_sfpi_dev_readb(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readb(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writeb(int port, uint8_t devaddr, uint8_t addr, uint8_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writeb(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_readw(int port, uint8_t devaddr, uint8_t addr) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_readw(bus, devaddr, addr, ONLP_I2C_F_FORCE); +} + +int +onlp_sfpi_dev_writew(int port, uint8_t devaddr, uint8_t addr, uint16_t value) +{ + int bus = PORT_BUS_INDEX(port); + return onlp_i2c_writew(bus, devaddr, addr, value, ONLP_I2C_F_FORCE); +} + int onlp_sfpi_denit(void) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/platform-config/r0/src/python/x86_64_accton_as7512_32x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/platform-config/r0/src/python/x86_64_accton_as7512_32x_r0/__init__.py index e6b0e804..3cadb818 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/platform-config/r0/src/python/x86_64_accton_as7512_32x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7512-32x/platform-config/r0/src/python/x86_64_accton_as7512_32x_r0/__init__.py @@ -8,10 +8,10 @@ class OnlPlatform_x86_64_accton_as7512_32x_r0(OnlPlatformAccton, SYS_OBJECT_ID=".7512.32" def baseconfig(self): - + self.insmod('optoe') self.insmod("ym2651y") - self.insmod("accton_i2c_cpld") - self.insmod_platform() + for m in [ 'cpld', 'fan', 'psu', 'leds' ]: + self.insmod("x86-64-accton-as7512-32x-%s" % m) ########### initialize I2C bus 0 ########### # initialize multiplexer (PCA9548) @@ -31,9 +31,9 @@ class OnlPlatform_x86_64_accton_as7512_32x_r0(OnlPlatformAccton, # initialize CPLD self.new_i2c_devices( [ - ('accton_i2c_cpld', 0x60, 4), - ('accton_i2c_cpld', 0x62, 5), - ('accton_i2c_cpld', 0x64, 6), + ('as7512_32x_cpld1', 0x60, 4), + ('as7512_32x_cpld2', 0x62, 5), + ('as7512_32x_cpld3', 0x64, 6), ] ) ########### initialize I2C bus 1 ########### @@ -65,7 +65,9 @@ class OnlPlatform_x86_64_accton_as7512_32x_r0(OnlPlatformAccton, ) # initialize QSFP port 1~32 - for p in range(1,33): - self.new_i2c_device('as7512_32x_sfp%d' % p, 0x50, 17+p) + # initialize QSFP devices + for port in range(1, 33): + self.new_i2c_device('optoe1', 0x50, port+17) + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+17), shell=True) return True From 9a11cd02818abd994fc671b6bdd5c414bca9dc20 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Thu, 29 Mar 2018 11:41:07 +0800 Subject: [PATCH 14/21] [as7816-64x] Replace psu driver with at24 --- .../builds/x86-64-accton-as7816-64x-cpld1.c | 62 +++++ .../builds/x86-64-accton-as7816-64x-psu.c | 239 ------------------ .../onlp/builds/src/module/src/platform_lib.c | 5 +- .../onlp/builds/src/module/src/platform_lib.h | 7 +- .../onlp/builds/src/module/src/psui.c | 26 +- .../x86_64_accton_as7816_64x_r0/__init__.py | 6 +- 6 files changed, 75 insertions(+), 270 deletions(-) delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-psu.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c index 1dcd3395..16474804 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-cpld1.c @@ -45,6 +45,8 @@ struct cpld_client_node { #define I2C_RW_RETRY_COUNT 10 #define I2C_RW_RETRY_INTERVAL 60 /* ms */ +static ssize_t show_psu(struct device *dev, struct device_attribute *da, + char *buf); static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_present_all(struct device *dev, struct device_attribute *da, @@ -66,6 +68,8 @@ struct as7816_64x_cpld_data { static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; #define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define PSU_PRESENT_ATTR_ID(index) PSU##index##_PRESENT +#define PSU_POWERGOOD_ATTR_ID(index) PSU##index##_POWER_GOOD enum as7816_64x_cpld_sysfs_attributes { CPLD_VERSION, @@ -136,6 +140,12 @@ enum as7816_64x_cpld_sysfs_attributes { TRANSCEIVER_PRESENT_ATTR_ID(62), TRANSCEIVER_PRESENT_ATTR_ID(63), TRANSCEIVER_PRESENT_ATTR_ID(64), + + /* psu attributes */ + PSU_PRESENT_ATTR_ID(1), + PSU_PRESENT_ATTR_ID(2), + PSU_POWERGOOD_ATTR_ID(1), + PSU_POWERGOOD_ATTR_ID(2), }; /* sysfs attributes for hwmon @@ -146,6 +156,14 @@ enum as7816_64x_cpld_sysfs_attributes { static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_present, NULL, MODULE_PRESENT_##index) #define DECLARE_TRANSCEIVER_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr +/* psu attributes */ +#define DECLARE_PSU_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(psu##index##_present, S_IRUGO, show_psu, NULL, PSU##index##_PRESENT); \ + static SENSOR_DEVICE_ATTR(psu##index##_power_good, S_IRUGO, show_psu, NULL, PSU##index##_POWER_GOOD); +#define DECLARE_PSU_ATTR(index) \ + &sensor_dev_attr_psu##index##_present.dev_attr.attr, \ + &sensor_dev_attr_psu##index##_power_good.dev_attr.attr + static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); /* transceiver attributes */ @@ -215,6 +233,10 @@ DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(62); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(63); DECLARE_TRANSCEIVER_SENSOR_DEVICE_ATTR(64); +/* psu attributes*/ +DECLARE_PSU_SENSOR_DEVICE_ATTR(1); +DECLARE_PSU_SENSOR_DEVICE_ATTR(2); + static struct attribute *as7816_64x_cpld_attributes[] = { &sensor_dev_attr_version.dev_attr.attr, &sensor_dev_attr_access.dev_attr.attr, @@ -284,6 +306,10 @@ static struct attribute *as7816_64x_cpld_attributes[] = { DECLARE_TRANSCEIVER_ATTR(62), DECLARE_TRANSCEIVER_ATTR(63), DECLARE_TRANSCEIVER_ATTR(64), + + /* psu attributes*/ + DECLARE_PSU_ATTR(1), + DECLARE_PSU_ATTR(2), NULL }; @@ -291,6 +317,42 @@ static const struct attribute_group as7816_64x_cpld_group = { .attrs = as7816_64x_cpld_attributes, }; +static ssize_t show_psu(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as7816_64x_cpld_data *data = i2c_get_clientdata(client); + int status = 0, value = 0; + + mutex_lock(&data->update_lock); + status = as7816_64x_cpld_read_internal(client, 0x03); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + switch (attr->index) { + case PSU1_PRESENT: + case PSU2_PRESENT: + value = !(status & BIT(attr->index - PSU1_PRESENT)); + break; + case PSU1_POWER_GOOD: + case PSU2_POWER_GOOD: + value = !!(status & BIT(attr->index - PSU1_POWER_GOOD + 2)); + break; + default: + return 0; + } + + + return sprintf(buf, "%d\n", value); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + static ssize_t show_present_all(struct device *dev, struct device_attribute *da, char *buf) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-psu.c deleted file mode 100644 index a2703aa9..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/modules/builds/x86-64-accton-as7816-64x-psu.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - * An hwmon driver for accton as7816_64x Power Module - * - * Copyright (C) 2014 Accton Technology Corporation. - * Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define PSU_STATUS_I2C_ADDR 0x60 -#define PSU_STATUS_I2C_REG_OFFSET 0x03 - -#define IS_POWER_GOOD(id, value) (!!(value & BIT(2+id))) -#define IS_PRESENT(id, value) (!(value & BIT(id))) - -static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); -static struct as7816_64x_psu_data *as7816_64x_psu_update_device(struct device *dev); -extern int as7816_64x_cpld_read (unsigned short cpld_addr, u8 reg); - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -/* Each client has this additional data - */ -struct as7816_64x_psu_data { - struct device *hwmon_dev; - struct mutex update_lock; - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 index; /* PSU index */ - u8 status; /* Status(present/power_good) register read from CPLD */ -}; - -enum as7816_64x_psu_sysfs_attributes { - PSU_PRESENT, - PSU_POWER_GOOD -}; - -/* sysfs attributes for hwmon - */ -static SENSOR_DEVICE_ATTR(psu_present, S_IRUGO, show_status, NULL, PSU_PRESENT); -static SENSOR_DEVICE_ATTR(psu_power_good, S_IRUGO, show_status, NULL, PSU_POWER_GOOD); - -static struct attribute *as7816_64x_psu_attributes[] = { - &sensor_dev_attr_psu_present.dev_attr.attr, - &sensor_dev_attr_psu_power_good.dev_attr.attr, - NULL -}; - -static ssize_t show_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct as7816_64x_psu_data *data = as7816_64x_psu_update_device(dev); - u8 status = 0; - - if (!data->valid) { - return -EIO; - } - - if (attr->index == PSU_PRESENT) { - status = IS_PRESENT(data->index, data->status); - } - else { /* PSU_POWER_GOOD */ - status = IS_POWER_GOOD(data->index, data->status); - } - - return sprintf(buf, "%d\n", status); -} - -static const struct attribute_group as7816_64x_psu_group = { - .attrs = as7816_64x_psu_attributes, -}; - -static int as7816_64x_psu_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct as7816_64x_psu_data *data; - int status; - - if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { - status = -EIO; - goto exit; - } - - data = kzalloc(sizeof(struct as7816_64x_psu_data), GFP_KERNEL); - if (!data) { - status = -ENOMEM; - goto exit; - } - - i2c_set_clientdata(client, data); - data->valid = 0; - data->index = dev_id->driver_data; - mutex_init(&data->update_lock); - - dev_info(&client->dev, "chip found\n"); - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &as7816_64x_psu_group); - if (status) { - goto exit_free; - } - - data->hwmon_dev = hwmon_device_register(&client->dev); - if (IS_ERR(data->hwmon_dev)) { - status = PTR_ERR(data->hwmon_dev); - goto exit_remove; - } - - dev_info(&client->dev, "%s: psu '%s'\n", - dev_name(data->hwmon_dev), client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &as7816_64x_psu_group); -exit_free: - kfree(data); -exit: - - return status; -} - -static int as7816_64x_psu_remove(struct i2c_client *client) -{ - struct as7816_64x_psu_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - sysfs_remove_group(&client->dev.kobj, &as7816_64x_psu_group); - kfree(data); - - return 0; -} - -enum psu_index -{ - as7816_64x_psu1, - as7816_64x_psu2 -}; - -static const struct i2c_device_id as7816_64x_psu_id[] = { - { "as7816_64x_psu1", as7816_64x_psu1 }, - { "as7816_64x_psu2", as7816_64x_psu2 }, - {} -}; -MODULE_DEVICE_TABLE(i2c, as7816_64x_psu_id); - -static struct i2c_driver as7816_64x_psu_driver = { - .class = I2C_CLASS_HWMON, - .driver = { - .name = "as7816_64x_psu", - }, - .probe = as7816_64x_psu_probe, - .remove = as7816_64x_psu_remove, - .id_table = as7816_64x_psu_id, - .address_list = normal_i2c, -}; - -static struct as7816_64x_psu_data *as7816_64x_psu_update_device(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct as7816_64x_psu_data *data = i2c_get_clientdata(client); - - mutex_lock(&data->update_lock); - - if (time_after(jiffies, data->last_updated + HZ + HZ / 2) - || !data->valid) { - int status; - - data->valid = 0; - dev_dbg(&client->dev, "Starting as7816_64x update\n"); - - /* Read psu status */ - status = as7816_64x_cpld_read(PSU_STATUS_I2C_ADDR, PSU_STATUS_I2C_REG_OFFSET); - - if (status < 0) { - dev_dbg(&client->dev, "cpld reg (0x%x) err %d\n", PSU_STATUS_I2C_ADDR, status); - goto exit; - } - else { - data->status = status; - } - - data->last_updated = jiffies; - data->valid = 1; - } - -exit: - mutex_unlock(&data->update_lock); - - return data; -} - -static int __init as7816_64x_psu_init(void) -{ - return i2c_add_driver(&as7816_64x_psu_driver); -} - -static void __exit as7816_64x_psu_exit(void) -{ - i2c_del_driver(&as7816_64x_psu_driver); -} - -module_init(as7816_64x_psu_init); -module_exit(as7816_64x_psu_exit); - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("as7816_64x_psu driver"); -MODULE_LICENSE("GPL"); - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c index d589fa93..dffc3c46 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.c @@ -68,9 +68,8 @@ psu_type_t psu_type_get(int id, char* modelname, int modelname_len) /* Check if the psu is power good */ - prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX; - if (onlp_file_read_int(&value, "%s%s", prefix, "psu_power_good") < 0) { - AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, "psu_power_good"); + if (onlp_file_read_int(&value, PSU_POWERGOOD_FORMAT, id) < 0) { + AIM_LOG_ERROR("Unable to read present status from PSU(%d)\r\n", index); return ONLP_STATUS_E_INTERNAL; } diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h index 54d03dd4..3a37a536 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/platform_lib.h @@ -42,11 +42,8 @@ #define PSU1_AC_PMBUS_NODE(node) PSU1_AC_PMBUS_PREFIX#node #define PSU2_AC_PMBUS_NODE(node) PSU2_AC_PMBUS_PREFIX#node -#define PSU1_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/10-0053/" -#define PSU2_AC_EEPROM_PREFIX "/sys/bus/i2c/devices/9-0050/" - -#define PSU1_AC_EEPROM_NODE(node) PSU1_AC_EEPROM_PREFIX#node -#define PSU2_AC_EEPROM_NODE(node) PSU2_AC_EEPROM_PREFIX#node +#define PSU_PRESENT_FORMAT "/sys/bus/i2c/devices/19-0060/psu%d_present" +#define PSU_POWERGOOD_FORMAT "/sys/bus/i2c/devices/19-0060/psu%d_power_good" #define FAN_BOARD_PATH "/sys/bus/i2c/devices/17-0068/" #define FAN_NODE(node) FAN_BOARD_PATH#node diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/psui.c b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/psui.c index a80b5627..6e347b6e 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/psui.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/onlp/builds/src/module/src/psui.c @@ -37,21 +37,6 @@ } \ } while(0) -static int -psu_status_info_get(int id, char *node, int *value) -{ - char *prefix = NULL; - *value = 0; - - prefix = (id == PSU1_ID) ? PSU1_AC_EEPROM_PREFIX : PSU2_AC_EEPROM_PREFIX; - if (onlp_file_read_int(value, "%s%s", prefix, node) < 0) { - AIM_LOG_ERROR("Unable to read status from file(%s%s)\r\n", prefix, node); - return ONLP_STATUS_E_INTERNAL; - } - - return 0; -} - int onlp_psui_init(void) { @@ -124,9 +109,9 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) memset(info, 0, sizeof(onlp_psu_info_t)); *info = pinfo[index]; /* Set the onlp_oid_hdr_t */ - /* Get the present state */ - if (psu_status_info_get(index, "psu_present", &val) != 0) { - printf("Unable to read PSU(%d) node(psu_present)\r\n", index); + if (onlp_file_read_int(&val, PSU_PRESENT_FORMAT, index) < 0) { + AIM_LOG_ERROR("Unable to read present status from PSU(%d)\r\n", index); + return ONLP_STATUS_E_INTERNAL; } if (val != PSU_STATUS_PRESENT) { @@ -137,8 +122,9 @@ onlp_psui_info_get(onlp_oid_t id, onlp_psu_info_t* info) /* Get power good status */ - if (psu_status_info_get(index, "psu_power_good", &val) != 0) { - printf("Unable to read PSU(%d) node(psu_power_good)\r\n", index); + if (onlp_file_read_int(&val, PSU_POWERGOOD_FORMAT, index) < 0) { + AIM_LOG_ERROR("Unable to read power status from PSU(%d)\r\n", index); + return ONLP_STATUS_E_INTERNAL; } if (val != PSU_STATUS_POWER_GOOD) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/platform-config/r0/src/python/x86_64_accton_as7816_64x_r0/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/platform-config/r0/src/python/x86_64_accton_as7816_64x_r0/__init__.py index 0f79ec54..163f3991 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/platform-config/r0/src/python/x86_64_accton_as7816_64x_r0/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as7816-64x/platform-config/r0/src/python/x86_64_accton_as7816_64x_r0/__init__.py @@ -11,7 +11,7 @@ class OnlPlatform_x86_64_accton_as7816_64x_r0(OnlPlatformAccton, self.insmod('optoe') self.insmod('ym2651y') self.insmod('accton_i2c_cpld') - for m in [ 'fan', 'cpld1', 'psu', 'leds' ]: + for m in [ 'fan', 'cpld1', 'leds' ]: self.insmod("x86-64-accton-as7816-64x-%s.ko" % m) ########### initialize I2C bus 0 ########### @@ -25,11 +25,11 @@ class OnlPlatform_x86_64_accton_as7816_64x_r0(OnlPlatformAccton, ('pca9548', 0x73, 1), # initiate PSU-1 - ('as7816_64x_psu1', 0x53, 10), + ('24c02', 0x53, 10), ('ym2851', 0x5b, 10), # initiate PSU-2 - ('as7816_64x_psu2', 0x50, 9), + ('24c02', 0x50, 9), ('ym2851', 0x58, 9), # initiate chassis fan From be9cdca9d586075b055183e1b8e5b6ebe4241729 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 29 Mar 2018 18:18:27 +0000 Subject: [PATCH 15/21] Manufecturer field missing from JSON output. --- packages/base/any/onlp/src/onlplib/module/src/onie.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/base/any/onlp/src/onlplib/module/src/onie.c b/packages/base/any/onlp/src/onlplib/module/src/onie.c index 2060e2e3..62663ce9 100644 --- a/packages/base/any/onlp/src/onlplib/module/src/onie.c +++ b/packages/base/any/onlp/src/onlplib/module/src/onie.c @@ -111,7 +111,7 @@ decode_tlv__(onlp_onie_info_t* info, tlvinfo_tlv_t * tlv) } \ _info -> _member = aim_zmalloc(_tlv->length + 1); \ memcpy((void*) _info -> _member, _tlv->value, _tlv->length); \ - break; \ + break; \ } CASE_TLV_STRING(info, product_name, PRODUCT_NAME, tlv); @@ -425,6 +425,7 @@ onlp_onie_show_json(onlp_onie_info_t* info, aim_pvs_t* pvs) cJSON_AddStringToObject(cj, "MAC", mac); aim_free(mac); } + _S(Manufacturer, manufacturer); _S(Manufacture Date,manufacture_date); _S(Vendor,vendor); _S(Platform Name,platform_name); @@ -522,8 +523,3 @@ onlp_onie_read_json(onlp_onie_info_t* info, const char* fname) cJSON_Delete(cj); return 0; } - - - - - From c6d880505fb27338b799e3e0822c6978adcc2a47 Mon Sep 17 00:00:00 2001 From: Brandon Chuang Date: Fri, 30 Mar 2018 10:51:30 +0800 Subject: [PATCH 16/21] [as5916-54x] Add support for OOM --- .../builds/x86-64-accton-as5916-54x-cpld.c | 1098 ++++++++++++++ .../builds/x86-64-accton-as5916-54x-leds.c | 8 +- .../builds/x86-64-accton-as5916-54x-psu.c | 4 +- .../builds/x86-64-accton-as5916-54x-sfp.c | 1315 ----------------- .../onlp/builds/src/module/src/sfpi.c | 238 +-- .../x86_64_accton_as5916_54x_r1/__init__.py | 16 +- 6 files changed, 1267 insertions(+), 1412 deletions(-) create mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-cpld.c delete mode 100644 packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-cpld.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-cpld.c new file mode 100644 index 00000000..646cb025 --- /dev/null +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-cpld.c @@ -0,0 +1,1098 @@ +/* + * Copyright (C) Brandon Chuang + * + * This module supports the accton cpld that hold the channel select + * mechanism for other i2c slave devices, such as SFP. + * This includes the: + * Accton as5916_54x CPLD1/CPLD2 + * + * Based on: + * pca954x.c from Kumar Gala + * Copyright (C) 2006 + * + * Based on: + * pca954x.c from Ken Harrenstien + * Copyright (C) 2004 Google, Inc. (Ken Harrenstien) + * + * Based on: + * i2c-virtual_cb.c from Brian Kuschak + * and + * pca9540.c from Jean Delvare . + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define I2C_RW_RETRY_COUNT 10 +#define I2C_RW_RETRY_INTERVAL 60 /* ms */ + +static LIST_HEAD(cpld_client_list); +static struct mutex list_lock; + +struct cpld_client_node { + struct i2c_client *client; + struct list_head list; +}; + +enum cpld_type { + as5916_54x_cpld1, + as5916_54x_cpld2 +}; + +struct as5916_54x_cpld_data { + enum cpld_type type; + struct device *hwmon_dev; + struct mutex update_lock; +}; + +static const struct i2c_device_id as5916_54x_cpld_id[] = { + { "as5916_54x_cpld1", as5916_54x_cpld1 }, + { "as5916_54x_cpld2", as5916_54x_cpld2 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, as5916_54x_cpld_id); + +#define TRANSCEIVER_PRESENT_ATTR_ID(index) MODULE_PRESENT_##index +#define TRANSCEIVER_TXDISABLE_ATTR_ID(index) MODULE_TXDISABLE_##index +#define TRANSCEIVER_RXLOS_ATTR_ID(index) MODULE_RXLOS_##index +#define TRANSCEIVER_TXFAULT_ATTR_ID(index) MODULE_TXFAULT_##index + +enum as5916_54x_cpld1_sysfs_attributes { + CPLD_VERSION, + ACCESS, + MODULE_PRESENT_ALL, + MODULE_RXLOS_ALL, + /* transceiver attributes */ + TRANSCEIVER_PRESENT_ATTR_ID(1), + TRANSCEIVER_PRESENT_ATTR_ID(2), + TRANSCEIVER_PRESENT_ATTR_ID(3), + TRANSCEIVER_PRESENT_ATTR_ID(4), + TRANSCEIVER_PRESENT_ATTR_ID(5), + TRANSCEIVER_PRESENT_ATTR_ID(6), + TRANSCEIVER_PRESENT_ATTR_ID(7), + TRANSCEIVER_PRESENT_ATTR_ID(8), + TRANSCEIVER_PRESENT_ATTR_ID(9), + TRANSCEIVER_PRESENT_ATTR_ID(10), + TRANSCEIVER_PRESENT_ATTR_ID(11), + TRANSCEIVER_PRESENT_ATTR_ID(12), + TRANSCEIVER_PRESENT_ATTR_ID(13), + TRANSCEIVER_PRESENT_ATTR_ID(14), + TRANSCEIVER_PRESENT_ATTR_ID(15), + TRANSCEIVER_PRESENT_ATTR_ID(16), + TRANSCEIVER_PRESENT_ATTR_ID(17), + TRANSCEIVER_PRESENT_ATTR_ID(18), + TRANSCEIVER_PRESENT_ATTR_ID(19), + TRANSCEIVER_PRESENT_ATTR_ID(20), + TRANSCEIVER_PRESENT_ATTR_ID(21), + TRANSCEIVER_PRESENT_ATTR_ID(22), + TRANSCEIVER_PRESENT_ATTR_ID(23), + TRANSCEIVER_PRESENT_ATTR_ID(24), + TRANSCEIVER_PRESENT_ATTR_ID(25), + TRANSCEIVER_PRESENT_ATTR_ID(26), + TRANSCEIVER_PRESENT_ATTR_ID(27), + TRANSCEIVER_PRESENT_ATTR_ID(28), + TRANSCEIVER_PRESENT_ATTR_ID(29), + TRANSCEIVER_PRESENT_ATTR_ID(30), + TRANSCEIVER_PRESENT_ATTR_ID(31), + TRANSCEIVER_PRESENT_ATTR_ID(32), + TRANSCEIVER_PRESENT_ATTR_ID(33), + TRANSCEIVER_PRESENT_ATTR_ID(34), + TRANSCEIVER_PRESENT_ATTR_ID(35), + TRANSCEIVER_PRESENT_ATTR_ID(36), + TRANSCEIVER_PRESENT_ATTR_ID(37), + TRANSCEIVER_PRESENT_ATTR_ID(38), + TRANSCEIVER_PRESENT_ATTR_ID(39), + TRANSCEIVER_PRESENT_ATTR_ID(40), + TRANSCEIVER_PRESENT_ATTR_ID(41), + TRANSCEIVER_PRESENT_ATTR_ID(42), + TRANSCEIVER_PRESENT_ATTR_ID(43), + TRANSCEIVER_PRESENT_ATTR_ID(44), + TRANSCEIVER_PRESENT_ATTR_ID(45), + TRANSCEIVER_PRESENT_ATTR_ID(46), + TRANSCEIVER_PRESENT_ATTR_ID(47), + TRANSCEIVER_PRESENT_ATTR_ID(48), + TRANSCEIVER_PRESENT_ATTR_ID(49), + TRANSCEIVER_PRESENT_ATTR_ID(50), + TRANSCEIVER_PRESENT_ATTR_ID(51), + TRANSCEIVER_PRESENT_ATTR_ID(52), + TRANSCEIVER_PRESENT_ATTR_ID(53), + TRANSCEIVER_PRESENT_ATTR_ID(54), + TRANSCEIVER_TXDISABLE_ATTR_ID(1), + TRANSCEIVER_TXDISABLE_ATTR_ID(2), + TRANSCEIVER_TXDISABLE_ATTR_ID(3), + TRANSCEIVER_TXDISABLE_ATTR_ID(4), + TRANSCEIVER_TXDISABLE_ATTR_ID(5), + TRANSCEIVER_TXDISABLE_ATTR_ID(6), + TRANSCEIVER_TXDISABLE_ATTR_ID(7), + TRANSCEIVER_TXDISABLE_ATTR_ID(8), + TRANSCEIVER_TXDISABLE_ATTR_ID(9), + TRANSCEIVER_TXDISABLE_ATTR_ID(10), + TRANSCEIVER_TXDISABLE_ATTR_ID(11), + TRANSCEIVER_TXDISABLE_ATTR_ID(12), + TRANSCEIVER_TXDISABLE_ATTR_ID(13), + TRANSCEIVER_TXDISABLE_ATTR_ID(14), + TRANSCEIVER_TXDISABLE_ATTR_ID(15), + TRANSCEIVER_TXDISABLE_ATTR_ID(16), + TRANSCEIVER_TXDISABLE_ATTR_ID(17), + TRANSCEIVER_TXDISABLE_ATTR_ID(18), + TRANSCEIVER_TXDISABLE_ATTR_ID(19), + TRANSCEIVER_TXDISABLE_ATTR_ID(20), + TRANSCEIVER_TXDISABLE_ATTR_ID(21), + TRANSCEIVER_TXDISABLE_ATTR_ID(22), + TRANSCEIVER_TXDISABLE_ATTR_ID(23), + TRANSCEIVER_TXDISABLE_ATTR_ID(24), + TRANSCEIVER_TXDISABLE_ATTR_ID(25), + TRANSCEIVER_TXDISABLE_ATTR_ID(26), + TRANSCEIVER_TXDISABLE_ATTR_ID(27), + TRANSCEIVER_TXDISABLE_ATTR_ID(28), + TRANSCEIVER_TXDISABLE_ATTR_ID(29), + TRANSCEIVER_TXDISABLE_ATTR_ID(30), + TRANSCEIVER_TXDISABLE_ATTR_ID(31), + TRANSCEIVER_TXDISABLE_ATTR_ID(32), + TRANSCEIVER_TXDISABLE_ATTR_ID(33), + TRANSCEIVER_TXDISABLE_ATTR_ID(34), + TRANSCEIVER_TXDISABLE_ATTR_ID(35), + TRANSCEIVER_TXDISABLE_ATTR_ID(36), + TRANSCEIVER_TXDISABLE_ATTR_ID(37), + TRANSCEIVER_TXDISABLE_ATTR_ID(38), + TRANSCEIVER_TXDISABLE_ATTR_ID(39), + TRANSCEIVER_TXDISABLE_ATTR_ID(40), + TRANSCEIVER_TXDISABLE_ATTR_ID(41), + TRANSCEIVER_TXDISABLE_ATTR_ID(42), + TRANSCEIVER_TXDISABLE_ATTR_ID(43), + TRANSCEIVER_TXDISABLE_ATTR_ID(44), + TRANSCEIVER_TXDISABLE_ATTR_ID(45), + TRANSCEIVER_TXDISABLE_ATTR_ID(46), + TRANSCEIVER_TXDISABLE_ATTR_ID(47), + TRANSCEIVER_TXDISABLE_ATTR_ID(48), + TRANSCEIVER_RXLOS_ATTR_ID(1), + TRANSCEIVER_RXLOS_ATTR_ID(2), + TRANSCEIVER_RXLOS_ATTR_ID(3), + TRANSCEIVER_RXLOS_ATTR_ID(4), + TRANSCEIVER_RXLOS_ATTR_ID(5), + TRANSCEIVER_RXLOS_ATTR_ID(6), + TRANSCEIVER_RXLOS_ATTR_ID(7), + TRANSCEIVER_RXLOS_ATTR_ID(8), + TRANSCEIVER_RXLOS_ATTR_ID(9), + TRANSCEIVER_RXLOS_ATTR_ID(10), + TRANSCEIVER_RXLOS_ATTR_ID(11), + TRANSCEIVER_RXLOS_ATTR_ID(12), + TRANSCEIVER_RXLOS_ATTR_ID(13), + TRANSCEIVER_RXLOS_ATTR_ID(14), + TRANSCEIVER_RXLOS_ATTR_ID(15), + TRANSCEIVER_RXLOS_ATTR_ID(16), + TRANSCEIVER_RXLOS_ATTR_ID(17), + TRANSCEIVER_RXLOS_ATTR_ID(18), + TRANSCEIVER_RXLOS_ATTR_ID(19), + TRANSCEIVER_RXLOS_ATTR_ID(20), + TRANSCEIVER_RXLOS_ATTR_ID(21), + TRANSCEIVER_RXLOS_ATTR_ID(22), + TRANSCEIVER_RXLOS_ATTR_ID(23), + TRANSCEIVER_RXLOS_ATTR_ID(24), + TRANSCEIVER_RXLOS_ATTR_ID(25), + TRANSCEIVER_RXLOS_ATTR_ID(26), + TRANSCEIVER_RXLOS_ATTR_ID(27), + TRANSCEIVER_RXLOS_ATTR_ID(28), + TRANSCEIVER_RXLOS_ATTR_ID(29), + TRANSCEIVER_RXLOS_ATTR_ID(30), + TRANSCEIVER_RXLOS_ATTR_ID(31), + TRANSCEIVER_RXLOS_ATTR_ID(32), + TRANSCEIVER_RXLOS_ATTR_ID(33), + TRANSCEIVER_RXLOS_ATTR_ID(34), + TRANSCEIVER_RXLOS_ATTR_ID(35), + TRANSCEIVER_RXLOS_ATTR_ID(36), + TRANSCEIVER_RXLOS_ATTR_ID(37), + TRANSCEIVER_RXLOS_ATTR_ID(38), + TRANSCEIVER_RXLOS_ATTR_ID(39), + TRANSCEIVER_RXLOS_ATTR_ID(40), + TRANSCEIVER_RXLOS_ATTR_ID(41), + TRANSCEIVER_RXLOS_ATTR_ID(42), + TRANSCEIVER_RXLOS_ATTR_ID(43), + TRANSCEIVER_RXLOS_ATTR_ID(44), + TRANSCEIVER_RXLOS_ATTR_ID(45), + TRANSCEIVER_RXLOS_ATTR_ID(46), + TRANSCEIVER_RXLOS_ATTR_ID(47), + TRANSCEIVER_RXLOS_ATTR_ID(48), + TRANSCEIVER_TXFAULT_ATTR_ID(1), + TRANSCEIVER_TXFAULT_ATTR_ID(2), + TRANSCEIVER_TXFAULT_ATTR_ID(3), + TRANSCEIVER_TXFAULT_ATTR_ID(4), + TRANSCEIVER_TXFAULT_ATTR_ID(5), + TRANSCEIVER_TXFAULT_ATTR_ID(6), + TRANSCEIVER_TXFAULT_ATTR_ID(7), + TRANSCEIVER_TXFAULT_ATTR_ID(8), + TRANSCEIVER_TXFAULT_ATTR_ID(9), + TRANSCEIVER_TXFAULT_ATTR_ID(10), + TRANSCEIVER_TXFAULT_ATTR_ID(11), + TRANSCEIVER_TXFAULT_ATTR_ID(12), + TRANSCEIVER_TXFAULT_ATTR_ID(13), + TRANSCEIVER_TXFAULT_ATTR_ID(14), + TRANSCEIVER_TXFAULT_ATTR_ID(15), + TRANSCEIVER_TXFAULT_ATTR_ID(16), + TRANSCEIVER_TXFAULT_ATTR_ID(17), + TRANSCEIVER_TXFAULT_ATTR_ID(18), + TRANSCEIVER_TXFAULT_ATTR_ID(19), + TRANSCEIVER_TXFAULT_ATTR_ID(20), + TRANSCEIVER_TXFAULT_ATTR_ID(21), + TRANSCEIVER_TXFAULT_ATTR_ID(22), + TRANSCEIVER_TXFAULT_ATTR_ID(23), + TRANSCEIVER_TXFAULT_ATTR_ID(24), + TRANSCEIVER_TXFAULT_ATTR_ID(25), + TRANSCEIVER_TXFAULT_ATTR_ID(26), + TRANSCEIVER_TXFAULT_ATTR_ID(27), + TRANSCEIVER_TXFAULT_ATTR_ID(28), + TRANSCEIVER_TXFAULT_ATTR_ID(29), + TRANSCEIVER_TXFAULT_ATTR_ID(30), + TRANSCEIVER_TXFAULT_ATTR_ID(31), + TRANSCEIVER_TXFAULT_ATTR_ID(32), + TRANSCEIVER_TXFAULT_ATTR_ID(33), + TRANSCEIVER_TXFAULT_ATTR_ID(34), + TRANSCEIVER_TXFAULT_ATTR_ID(35), + TRANSCEIVER_TXFAULT_ATTR_ID(36), + TRANSCEIVER_TXFAULT_ATTR_ID(37), + TRANSCEIVER_TXFAULT_ATTR_ID(38), + TRANSCEIVER_TXFAULT_ATTR_ID(39), + TRANSCEIVER_TXFAULT_ATTR_ID(40), + TRANSCEIVER_TXFAULT_ATTR_ID(41), + TRANSCEIVER_TXFAULT_ATTR_ID(42), + TRANSCEIVER_TXFAULT_ATTR_ID(43), + TRANSCEIVER_TXFAULT_ATTR_ID(44), + TRANSCEIVER_TXFAULT_ATTR_ID(45), + TRANSCEIVER_TXFAULT_ATTR_ID(46), + TRANSCEIVER_TXFAULT_ATTR_ID(47), + TRANSCEIVER_TXFAULT_ATTR_ID(48), +}; + +/* sysfs attributes for hwmon + */ +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf); +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count); +static ssize_t show_version(struct device *dev, struct device_attribute *da, + char *buf); +static int as5916_54x_cpld_read_internal(struct i2c_client *client, u8 reg); +static int as5916_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value); + +/* transceiver attributes */ +#define DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_present_##index, S_IRUGO, show_status, NULL, MODULE_PRESENT_##index) +#define DECLARE_TRANSCEIVER_PRESENT_ATTR(index) &sensor_dev_attr_module_present_##index.dev_attr.attr + +#define DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(index) \ + static SENSOR_DEVICE_ATTR(module_tx_disable_##index, S_IRUGO | S_IWUSR, show_status, set_tx_disable, MODULE_TXDISABLE_##index); \ + static SENSOR_DEVICE_ATTR(module_rx_los_##index, S_IRUGO, show_status, NULL, MODULE_RXLOS_##index); \ + static SENSOR_DEVICE_ATTR(module_tx_fault_##index, S_IRUGO, show_status, NULL, MODULE_TXFAULT_##index) +#define DECLARE_SFP_TRANSCEIVER_ATTR(index) \ + &sensor_dev_attr_module_tx_disable_##index.dev_attr.attr, \ + &sensor_dev_attr_module_rx_los_##index.dev_attr.attr, \ + &sensor_dev_attr_module_tx_fault_##index.dev_attr.attr + +static SENSOR_DEVICE_ATTR(version, S_IRUGO, show_version, NULL, CPLD_VERSION); +static SENSOR_DEVICE_ATTR(access, S_IWUSR, NULL, access, ACCESS); +/* transceiver attributes */ +static SENSOR_DEVICE_ATTR(module_present_all, S_IRUGO, show_present_all, NULL, MODULE_PRESENT_ALL); +static SENSOR_DEVICE_ATTR(module_rx_los_all, S_IRUGO, show_rxlos_all, NULL, MODULE_RXLOS_ALL); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(1); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(2); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(3); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(4); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(5); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(6); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(7); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(8); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(9); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(10); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(11); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(12); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(13); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(14); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(15); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(16); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(17); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(18); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(19); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(20); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(21); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(22); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(23); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(24); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(25); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(26); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(27); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(28); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(29); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(30); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(31); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(32); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(33); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(34); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(35); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(36); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(37); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(38); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(39); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(40); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(41); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(42); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(43); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(44); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(45); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(46); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(47); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(48); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(49); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(50); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(51); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(52); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(53); +DECLARE_TRANSCEIVER_PRESENT_SENSOR_DEVICE_ATTR(54); + +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(1); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(2); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(3); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(4); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(5); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(6); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(7); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(8); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(9); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(10); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(11); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(12); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(13); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(14); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(15); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(16); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(17); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(18); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(19); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(20); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(21); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(22); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(23); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(24); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(25); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(26); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(27); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(28); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(29); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(30); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(31); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(32); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(33); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(34); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(35); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(36); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(37); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(38); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(39); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(40); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(41); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(42); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(43); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(44); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(45); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(46); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(47); +DECLARE_SFP_TRANSCEIVER_SENSOR_DEVICE_ATTR(48); + +static struct attribute *as5916_54x_cpld1_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(1), + DECLARE_TRANSCEIVER_PRESENT_ATTR(2), + DECLARE_TRANSCEIVER_PRESENT_ATTR(3), + DECLARE_TRANSCEIVER_PRESENT_ATTR(4), + DECLARE_TRANSCEIVER_PRESENT_ATTR(5), + DECLARE_TRANSCEIVER_PRESENT_ATTR(6), + DECLARE_TRANSCEIVER_PRESENT_ATTR(7), + DECLARE_TRANSCEIVER_PRESENT_ATTR(8), + DECLARE_TRANSCEIVER_PRESENT_ATTR(9), + DECLARE_TRANSCEIVER_PRESENT_ATTR(10), + DECLARE_TRANSCEIVER_PRESENT_ATTR(11), + DECLARE_TRANSCEIVER_PRESENT_ATTR(12), + DECLARE_TRANSCEIVER_PRESENT_ATTR(13), + DECLARE_TRANSCEIVER_PRESENT_ATTR(14), + DECLARE_TRANSCEIVER_PRESENT_ATTR(15), + DECLARE_TRANSCEIVER_PRESENT_ATTR(16), + DECLARE_TRANSCEIVER_PRESENT_ATTR(17), + DECLARE_TRANSCEIVER_PRESENT_ATTR(18), + DECLARE_TRANSCEIVER_PRESENT_ATTR(19), + DECLARE_TRANSCEIVER_PRESENT_ATTR(20), + DECLARE_TRANSCEIVER_PRESENT_ATTR(21), + DECLARE_TRANSCEIVER_PRESENT_ATTR(22), + DECLARE_TRANSCEIVER_PRESENT_ATTR(23), + DECLARE_TRANSCEIVER_PRESENT_ATTR(24), + DECLARE_SFP_TRANSCEIVER_ATTR(1), + DECLARE_SFP_TRANSCEIVER_ATTR(2), + DECLARE_SFP_TRANSCEIVER_ATTR(3), + DECLARE_SFP_TRANSCEIVER_ATTR(4), + DECLARE_SFP_TRANSCEIVER_ATTR(5), + DECLARE_SFP_TRANSCEIVER_ATTR(6), + DECLARE_SFP_TRANSCEIVER_ATTR(7), + DECLARE_SFP_TRANSCEIVER_ATTR(8), + DECLARE_SFP_TRANSCEIVER_ATTR(9), + DECLARE_SFP_TRANSCEIVER_ATTR(10), + DECLARE_SFP_TRANSCEIVER_ATTR(11), + DECLARE_SFP_TRANSCEIVER_ATTR(12), + DECLARE_SFP_TRANSCEIVER_ATTR(13), + DECLARE_SFP_TRANSCEIVER_ATTR(14), + DECLARE_SFP_TRANSCEIVER_ATTR(15), + DECLARE_SFP_TRANSCEIVER_ATTR(16), + DECLARE_SFP_TRANSCEIVER_ATTR(17), + DECLARE_SFP_TRANSCEIVER_ATTR(18), + DECLARE_SFP_TRANSCEIVER_ATTR(19), + DECLARE_SFP_TRANSCEIVER_ATTR(20), + DECLARE_SFP_TRANSCEIVER_ATTR(21), + DECLARE_SFP_TRANSCEIVER_ATTR(22), + DECLARE_SFP_TRANSCEIVER_ATTR(23), + DECLARE_SFP_TRANSCEIVER_ATTR(24), + NULL +}; + +static const struct attribute_group as5916_54x_cpld1_group = { + .attrs = as5916_54x_cpld1_attributes, +}; + +static struct attribute *as5916_54x_cpld2_attributes[] = { + &sensor_dev_attr_version.dev_attr.attr, + &sensor_dev_attr_access.dev_attr.attr, + /* transceiver attributes */ + &sensor_dev_attr_module_present_all.dev_attr.attr, + &sensor_dev_attr_module_rx_los_all.dev_attr.attr, + DECLARE_TRANSCEIVER_PRESENT_ATTR(25), + DECLARE_TRANSCEIVER_PRESENT_ATTR(26), + DECLARE_TRANSCEIVER_PRESENT_ATTR(27), + DECLARE_TRANSCEIVER_PRESENT_ATTR(28), + DECLARE_TRANSCEIVER_PRESENT_ATTR(29), + DECLARE_TRANSCEIVER_PRESENT_ATTR(30), + DECLARE_TRANSCEIVER_PRESENT_ATTR(31), + DECLARE_TRANSCEIVER_PRESENT_ATTR(32), + DECLARE_TRANSCEIVER_PRESENT_ATTR(33), + DECLARE_TRANSCEIVER_PRESENT_ATTR(34), + DECLARE_TRANSCEIVER_PRESENT_ATTR(35), + DECLARE_TRANSCEIVER_PRESENT_ATTR(36), + DECLARE_TRANSCEIVER_PRESENT_ATTR(37), + DECLARE_TRANSCEIVER_PRESENT_ATTR(38), + DECLARE_TRANSCEIVER_PRESENT_ATTR(39), + DECLARE_TRANSCEIVER_PRESENT_ATTR(40), + DECLARE_TRANSCEIVER_PRESENT_ATTR(41), + DECLARE_TRANSCEIVER_PRESENT_ATTR(42), + DECLARE_TRANSCEIVER_PRESENT_ATTR(43), + DECLARE_TRANSCEIVER_PRESENT_ATTR(44), + DECLARE_TRANSCEIVER_PRESENT_ATTR(45), + DECLARE_TRANSCEIVER_PRESENT_ATTR(46), + DECLARE_TRANSCEIVER_PRESENT_ATTR(47), + DECLARE_TRANSCEIVER_PRESENT_ATTR(48), + DECLARE_TRANSCEIVER_PRESENT_ATTR(49), + DECLARE_TRANSCEIVER_PRESENT_ATTR(50), + DECLARE_TRANSCEIVER_PRESENT_ATTR(51), + DECLARE_TRANSCEIVER_PRESENT_ATTR(52), + DECLARE_TRANSCEIVER_PRESENT_ATTR(53), + DECLARE_TRANSCEIVER_PRESENT_ATTR(54), + DECLARE_SFP_TRANSCEIVER_ATTR(25), + DECLARE_SFP_TRANSCEIVER_ATTR(26), + DECLARE_SFP_TRANSCEIVER_ATTR(27), + DECLARE_SFP_TRANSCEIVER_ATTR(28), + DECLARE_SFP_TRANSCEIVER_ATTR(29), + DECLARE_SFP_TRANSCEIVER_ATTR(30), + DECLARE_SFP_TRANSCEIVER_ATTR(31), + DECLARE_SFP_TRANSCEIVER_ATTR(32), + DECLARE_SFP_TRANSCEIVER_ATTR(33), + DECLARE_SFP_TRANSCEIVER_ATTR(34), + DECLARE_SFP_TRANSCEIVER_ATTR(35), + DECLARE_SFP_TRANSCEIVER_ATTR(36), + DECLARE_SFP_TRANSCEIVER_ATTR(37), + DECLARE_SFP_TRANSCEIVER_ATTR(38), + DECLARE_SFP_TRANSCEIVER_ATTR(39), + DECLARE_SFP_TRANSCEIVER_ATTR(40), + DECLARE_SFP_TRANSCEIVER_ATTR(41), + DECLARE_SFP_TRANSCEIVER_ATTR(42), + DECLARE_SFP_TRANSCEIVER_ATTR(43), + DECLARE_SFP_TRANSCEIVER_ATTR(44), + DECLARE_SFP_TRANSCEIVER_ATTR(45), + DECLARE_SFP_TRANSCEIVER_ATTR(46), + DECLARE_SFP_TRANSCEIVER_ATTR(47), + DECLARE_SFP_TRANSCEIVER_ATTR(48), + NULL +}; + +static const struct attribute_group as5916_54x_cpld2_group = { + .attrs = as5916_54x_cpld2_attributes, +}; + +static ssize_t show_present_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status, num_regs = 0; + u8 values[4] = {0}; + u8 regs[] = {0x10, 0x11, 0x12, 0x52}; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + num_regs = (data->type == as5916_54x_cpld1) ? 3 : 4; + + for (i = 0; i < num_regs; i++) { + status = as5916_54x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = ~(u8)status; + } + + mutex_unlock(&data->update_lock); + + if (data->type == as5916_54x_cpld1) { + status = sprintf(buf, "%.2x %.2x %.2x\n", + values[0], values[1], values[2]); + } + else { /* as5916_54x_cpld2 */ + values[3] &= 0x3F; + status = sprintf(buf, "%.2x %.2x %.2x %.2x\n", + values[0], values[1], values[2], values[3]); + } + + return status; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_rxlos_all(struct device *dev, struct device_attribute *da, + char *buf) +{ + int i, status; + u8 values[3] = {0}; + u8 regs[] = {0x30, 0x32, 0x34}; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + + mutex_lock(&data->update_lock); + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + status = as5916_54x_cpld_read_internal(client, regs[i]); + + if (status < 0) { + goto exit; + } + + values[i] = (u8)status; + } + + mutex_unlock(&data->update_lock); + + /* Return values 1 -> 24 in order */ + return sprintf(buf, "%.2x %.2x %.2x\n", values[0], values[1], values[2]); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t show_status(struct device *dev, struct device_attribute *da, + char *buf) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + int status = 0; + u8 reg = 0, mask = 0, revert = 0; + + switch (attr->index) { + case MODULE_PRESENT_1 ... MODULE_PRESENT_8: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_1); + break; + case MODULE_PRESENT_9 ... MODULE_PRESENT_16: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_9); + break; + case MODULE_PRESENT_17 ... MODULE_PRESENT_24: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_17); + break; + case MODULE_PRESENT_25 ... MODULE_PRESENT_32: + reg = 0x10; + mask = 0x1 << (attr->index - MODULE_PRESENT_25); + break; + case MODULE_PRESENT_33 ... MODULE_PRESENT_40: + reg = 0x11; + mask = 0x1 << (attr->index - MODULE_PRESENT_33); + break; + case MODULE_PRESENT_41 ... MODULE_PRESENT_48: + reg = 0x12; + mask = 0x1 << (attr->index - MODULE_PRESENT_41); + break; + case MODULE_PRESENT_49 ... MODULE_PRESENT_54: + reg = 0x52; + mask = 0x1 << (attr->index - MODULE_PRESENT_49); + break; + case MODULE_TXFAULT_1 ... MODULE_TXFAULT_8: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_1); + break; + case MODULE_TXFAULT_9 ... MODULE_TXFAULT_16: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_9); + break; + case MODULE_TXFAULT_17 ... MODULE_TXFAULT_24: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_17); + break; + case MODULE_TXFAULT_25 ... MODULE_TXFAULT_32: + reg = 0x14; + mask = 0x1 << (attr->index - MODULE_TXFAULT_25); + break; + case MODULE_TXFAULT_33 ... MODULE_TXFAULT_40: + reg = 0x16; + mask = 0x1 << (attr->index - MODULE_TXFAULT_33); + break; + case MODULE_TXFAULT_41 ... MODULE_TXFAULT_48: + reg = 0x18; + mask = 0x1 << (attr->index - MODULE_TXFAULT_41); + break; + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + case MODULE_RXLOS_1 ... MODULE_RXLOS_8: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_1); + break; + case MODULE_RXLOS_9 ... MODULE_RXLOS_16: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_9); + break; + case MODULE_RXLOS_17 ... MODULE_RXLOS_24: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_17); + break; + case MODULE_RXLOS_25 ... MODULE_RXLOS_32: + reg = 0x30; + mask = 0x1 << (attr->index - MODULE_RXLOS_25); + break; + case MODULE_RXLOS_33 ... MODULE_RXLOS_40: + reg = 0x32; + mask = 0x1 << (attr->index - MODULE_RXLOS_33); + break; + case MODULE_RXLOS_41 ... MODULE_RXLOS_48: + reg = 0x34; + mask = 0x1 << (attr->index - MODULE_RXLOS_41); + break; + default: + return 0; + } + + if (attr->index >= MODULE_PRESENT_1 && attr->index <= MODULE_PRESENT_54) { + revert = 1; + } + + mutex_lock(&data->update_lock); + status = as5916_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + + return sprintf(buf, "%d\n", revert ? !(status & mask) : !!(status & mask)); + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t set_tx_disable(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + struct sensor_device_attribute *attr = to_sensor_dev_attr(da); + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + long disable; + int status; + u8 reg = 0, mask = 0; + + status = kstrtol(buf, 10, &disable); + if (status) { + return status; + } + + switch (attr->index) { + case MODULE_TXDISABLE_1 ... MODULE_TXDISABLE_8: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_1); + break; + case MODULE_TXDISABLE_9 ... MODULE_TXDISABLE_16: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_9); + break; + case MODULE_TXDISABLE_17 ... MODULE_TXDISABLE_24: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_17); + break; + case MODULE_TXDISABLE_25 ... MODULE_TXDISABLE_32: + reg = 0x20; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_25); + break; + case MODULE_TXDISABLE_33 ... MODULE_TXDISABLE_40: + reg = 0x22; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_33); + break; + case MODULE_TXDISABLE_41 ... MODULE_TXDISABLE_48: + reg = 0x24; + mask = 0x1 << (attr->index - MODULE_TXDISABLE_41); + break; + default: + return 0; + } + + /* Read current status */ + mutex_lock(&data->update_lock); + status = as5916_54x_cpld_read_internal(client, reg); + if (unlikely(status < 0)) { + goto exit; + } + + /* Update tx_disable status */ + if (disable) { + status |= mask; + } + else { + status &= ~mask; + } + + status = as5916_54x_cpld_write_internal(client, reg, status); + if (unlikely(status < 0)) { + goto exit; + } + + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static ssize_t access(struct device *dev, struct device_attribute *da, + const char *buf, size_t count) +{ + int status; + u32 addr, val; + struct i2c_client *client = to_i2c_client(dev); + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + + if (sscanf(buf, "0x%x 0x%x", &addr, &val) != 2) { + return -EINVAL; + } + + if (addr > 0xFF || val > 0xFF) { + return -EINVAL; + } + + mutex_lock(&data->update_lock); + status = as5916_54x_cpld_write_internal(client, addr, val); + if (unlikely(status < 0)) { + goto exit; + } + mutex_unlock(&data->update_lock); + return count; + +exit: + mutex_unlock(&data->update_lock); + return status; +} + +static void as5916_54x_cpld_add_client(struct i2c_client *client) +{ + struct cpld_client_node *node = kzalloc(sizeof(struct cpld_client_node), GFP_KERNEL); + + if (!node) { + dev_dbg(&client->dev, "Can't allocate cpld_client_node (0x%x)\n", client->addr); + return; + } + + node->client = client; + + mutex_lock(&list_lock); + list_add(&node->list, &cpld_client_list); + mutex_unlock(&list_lock); +} + +static void as5916_54x_cpld_remove_client(struct i2c_client *client) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int found = 0; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client == client) { + found = 1; + break; + } + } + + if (found) { + list_del(list_node); + kfree(cpld_node); + } + + mutex_unlock(&list_lock); +} + +static ssize_t show_version(struct device *dev, struct device_attribute *attr, char *buf) +{ + int val = 0; + struct i2c_client *client = to_i2c_client(dev); + + val = i2c_smbus_read_byte_data(client, 0x1); + + if (val < 0) { + dev_dbg(&client->dev, "cpld(0x%x) reg(0x1) err %d\n", client->addr, val); + } + + return sprintf(buf, "%d", val); +} + +/* + * I2C init/probing/exit functions + */ +static int as5916_54x_cpld_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct i2c_adapter *adap = to_i2c_adapter(client->dev.parent); + struct as5916_54x_cpld_data *data; + int ret = -ENODEV; + const struct attribute_group *group = NULL; + + if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_BYTE)) + goto exit; + + data = kzalloc(sizeof(struct as5916_54x_cpld_data), GFP_KERNEL); + if (!data) { + ret = -ENOMEM; + goto exit; + } + + i2c_set_clientdata(client, data); + mutex_init(&data->update_lock); + data->type = id->driver_data; + + /* Register sysfs hooks */ + switch (data->type) { + case as5916_54x_cpld1: + group = &as5916_54x_cpld1_group; + break; + case as5916_54x_cpld2: + group = &as5916_54x_cpld2_group; + break; + default: + break; + } + + if (group) { + ret = sysfs_create_group(&client->dev.kobj, group); + if (ret) { + goto exit_free; + } + } + + as5916_54x_cpld_add_client(client); + return 0; + +exit_free: + kfree(data); +exit: + return ret; +} + +static int as5916_54x_cpld_remove(struct i2c_client *client) +{ + struct as5916_54x_cpld_data *data = i2c_get_clientdata(client); + const struct attribute_group *group = NULL; + + as5916_54x_cpld_remove_client(client); + + /* Remove sysfs hooks */ + switch (data->type) { + case as5916_54x_cpld1: + group = &as5916_54x_cpld1_group; + break; + case as5916_54x_cpld2: + group = &as5916_54x_cpld2_group; + break; + default: + break; + } + + if (group) { + sysfs_remove_group(&client->dev.kobj, group); + } + + kfree(data); + + return 0; +} + +static int as5916_54x_cpld_read_internal(struct i2c_client *client, u8 reg) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_read_byte_data(client, reg); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +static int as5916_54x_cpld_write_internal(struct i2c_client *client, u8 reg, u8 value) +{ + int status = 0, retry = I2C_RW_RETRY_COUNT; + + while (retry) { + status = i2c_smbus_write_byte_data(client, reg, value); + if (unlikely(status < 0)) { + msleep(I2C_RW_RETRY_INTERVAL); + retry--; + continue; + } + + break; + } + + return status; +} + +int as5916_54x_cpld_read(unsigned short cpld_addr, u8 reg) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EPERM; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5916_54x_cpld_read_internal(cpld_node->client, reg); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5916_54x_cpld_read); + +int as5916_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value) +{ + struct list_head *list_node = NULL; + struct cpld_client_node *cpld_node = NULL; + int ret = -EIO; + + mutex_lock(&list_lock); + + list_for_each(list_node, &cpld_client_list) + { + cpld_node = list_entry(list_node, struct cpld_client_node, list); + + if (cpld_node->client->addr == cpld_addr) { + ret = as5916_54x_cpld_write_internal(cpld_node->client, reg, value); + break; + } + } + + mutex_unlock(&list_lock); + + return ret; +} +EXPORT_SYMBOL(as5916_54x_cpld_write); + +static struct i2c_driver as5916_54x_cpld_driver = { + .driver = { + .name = "as5916_54x_cpld", + .owner = THIS_MODULE, + }, + .probe = as5916_54x_cpld_probe, + .remove = as5916_54x_cpld_remove, + .id_table = as5916_54x_cpld_id, +}; + +static int __init as5916_54x_cpld_init(void) +{ + mutex_init(&list_lock); + return i2c_add_driver(&as5916_54x_cpld_driver); +} + +static void __exit as5916_54x_cpld_exit(void) +{ + i2c_del_driver(&as5916_54x_cpld_driver); +} + +MODULE_AUTHOR("Brandon Chuang "); +MODULE_DESCRIPTION("Accton I2C CPLD driver"); +MODULE_LICENSE("GPL"); + +module_init(as5916_54x_cpld_init); +module_exit(as5916_54x_cpld_exit); + diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c index 7f55dae7..9f6be629 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-leds.c @@ -38,8 +38,8 @@ #define DEBUG_PRINT(fmt, args...) #endif -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); +extern int as5916_54x_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5916_54x_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); struct accton_as5916_54x_led_data { struct platform_device *pdev; @@ -157,12 +157,12 @@ static u8 led_light_mode_to_reg_val(enum led_type type, static int accton_as5916_54x_led_read_value(u8 reg) { - return accton_i2c_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); + return as5916_54x_cpld_read(LED_CNTRLER_I2C_ADDRESS, reg); } static int accton_as5916_54x_led_write_value(u8 reg, u8 value) { - return accton_i2c_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); + return as5916_54x_cpld_write(LED_CNTRLER_I2C_ADDRESS, reg, value); } static void accton_as5916_54x_led_update(void) diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c index 4627df9c..e9d00dfb 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-psu.c @@ -37,7 +37,7 @@ static ssize_t show_status(struct device *dev, struct device_attribute *da, char *buf); static ssize_t show_model_name(struct device *dev, struct device_attribute *da, char *buf); static int as5916_54x_psu_read_block(struct i2c_client *client, u8 command, u8 *data,int data_len); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); +extern int as5916_54x_cpld_read(unsigned short cpld_addr, u8 reg); /* Addresses scanned */ @@ -234,7 +234,7 @@ static struct as5916_54x_psu_data *as5916_54x_psu_update_device(struct device *d dev_dbg(&client->dev, "Starting as5916_54x update\n"); /* Read psu status */ - status = accton_i2c_cpld_read(0x60, 0x2); + status = as5916_54x_cpld_read(0x60, 0x2); if (status < 0) { dev_dbg(&client->dev, "cpld reg 0x60 err %d\n", status); diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c deleted file mode 100644 index c924772b..00000000 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/modules/builds/x86-64-accton-as5916-54x-sfp.c +++ /dev/null @@ -1,1315 +0,0 @@ -/* - * SFP driver for accton as5916_54x sfp - * - * Copyright (C) Brandon Chuang - * - * Based on ad7414.c - * Copyright 2006 Stefan Roese , DENX Software Engineering - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define DRIVER_NAME "as5916_54x_sfp" /* Platform dependent */ - -#define DEBUG_MODE 0 - -#if (DEBUG_MODE == 1) - #define DEBUG_PRINT(fmt, args...) \ - printk (KERN_INFO "%s:%s[%d]: " fmt "\r\n", __FILE__, __FUNCTION__, __LINE__, ##args) -#else - #define DEBUG_PRINT(fmt, args...) -#endif - -#define NUM_OF_SFP_PORT 54 -#define EEPROM_NAME "sfp_eeprom" -#define EEPROM_SIZE 256 /* 256 byte eeprom */ -#define BIT_INDEX(i) (1ULL << (i)) -#define USE_I2C_BLOCK_READ 1 /* Platform dependent */ -#define I2C_RW_RETRY_COUNT 3 -#define I2C_RW_RETRY_INTERVAL 100 /* ms */ - -#define SFP_EEPROM_A0_I2C_ADDR (0xA0 >> 1) -#define SFP_EEPROM_A2_I2C_ADDR (0xA2 >> 1) - -#define SFF8024_PHYSICAL_DEVICE_ID_ADDR 0x0 -#define SFF8024_DEVICE_ID_SFP 0x3 -#define SFF8024_DEVICE_ID_QSFP 0xC -#define SFF8024_DEVICE_ID_QSFP_PLUS 0xD -#define SFF8024_DEVICE_ID_QSFP28 0x11 - -#define SFF8472_DIAG_MON_TYPE_ADDR 92 -#define SFF8472_DIAG_MON_TYPE_DDM_MASK 0x40 -#define SFF8472_10G_ETH_COMPLIANCE_ADDR 0x3 -#define SFF8472_10G_BASE_MASK 0xF0 - -#define SFF8436_RX_LOS_ADDR 3 -#define SFF8436_TX_FAULT_ADDR 4 -#define SFF8436_TX_DISABLE_ADDR 86 - -/* Platform dependent +++ */ -#define I2C_ADDR_CPLD1 0x60 -#define I2C_ADDR_CPLD2 0x62 -/* Platform dependent --- */ - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t show_present(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count); -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, const char *buf, size_t count);; -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, char *buf); -static ssize_t sfp_eeprom_read(struct i2c_client *, u8, u8 *,int); -static ssize_t sfp_eeprom_write(struct i2c_client *, u8 , const char *,int); -extern int accton_i2c_cpld_read(unsigned short cpld_addr, u8 reg); -extern int accton_i2c_cpld_write(unsigned short cpld_addr, u8 reg, u8 value); - -enum sfp_sysfs_attributes { - PRESENT, - PRESENT_ALL, - PORT_NUMBER, - PORT_TYPE, - DDM_IMPLEMENTED, - TX_FAULT, - TX_FAULT1, - TX_FAULT2, - TX_FAULT3, - TX_FAULT4, - TX_DISABLE, - TX_DISABLE1, - TX_DISABLE2, - TX_DISABLE3, - TX_DISABLE4, - RX_LOS, - RX_LOS1, - RX_LOS2, - RX_LOS3, - RX_LOS4, - RX_LOS_ALL -}; - -/* SFP/QSFP common attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_port_number, S_IRUGO, show_port_number, NULL, PORT_NUMBER); -static SENSOR_DEVICE_ATTR(sfp_port_type, S_IRUGO, show_port_type, NULL, PORT_TYPE); -static SENSOR_DEVICE_ATTR(sfp_is_present, S_IRUGO, show_present, NULL, PRESENT); -static SENSOR_DEVICE_ATTR(sfp_is_present_all, S_IRUGO, show_present, NULL, PRESENT_ALL); -static SENSOR_DEVICE_ATTR(sfp_rx_los, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS); -static SENSOR_DEVICE_ATTR(sfp_tx_disable, S_IWUSR | S_IRUGO, sfp_show_tx_rx_status, sfp_set_tx_disable, TX_DISABLE); -static SENSOR_DEVICE_ATTR(sfp_tx_fault, S_IRUGO, sfp_show_tx_rx_status, NULL, TX_FAULT); - -/* QSFP attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_rx_los1, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS1); -static SENSOR_DEVICE_ATTR(sfp_rx_los2, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS2); -static SENSOR_DEVICE_ATTR(sfp_rx_los3, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS3); -static SENSOR_DEVICE_ATTR(sfp_rx_los4, S_IRUGO, qsfp_show_tx_rx_status, NULL, RX_LOS4); -static SENSOR_DEVICE_ATTR(sfp_tx_disable1, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE1); -static SENSOR_DEVICE_ATTR(sfp_tx_disable2, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE2); -static SENSOR_DEVICE_ATTR(sfp_tx_disable3, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE3); -static SENSOR_DEVICE_ATTR(sfp_tx_disable4, S_IWUSR | S_IRUGO, qsfp_show_tx_rx_status, qsfp_set_tx_disable, TX_DISABLE4); -static SENSOR_DEVICE_ATTR(sfp_tx_fault1, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT1); -static SENSOR_DEVICE_ATTR(sfp_tx_fault2, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT2); -static SENSOR_DEVICE_ATTR(sfp_tx_fault3, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT3); -static SENSOR_DEVICE_ATTR(sfp_tx_fault4, S_IRUGO, qsfp_show_tx_rx_status, NULL, TX_FAULT4); -static struct attribute *qsfp_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los1.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los2.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los3.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable4.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault1.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault2.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault3.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault4.dev_attr.attr, - NULL -}; - -/* SFP msa attributes for sysfs */ -static SENSOR_DEVICE_ATTR(sfp_ddm_implemented, S_IRUGO, sfp_show_ddm_implemented, NULL, DDM_IMPLEMENTED); -static SENSOR_DEVICE_ATTR(sfp_rx_los_all, S_IRUGO, sfp_show_tx_rx_status, NULL, RX_LOS_ALL); -static struct attribute *sfp_msa_attributes[] = { - &sensor_dev_attr_sfp_port_number.dev_attr.attr, - &sensor_dev_attr_sfp_port_type.dev_attr.attr, - &sensor_dev_attr_sfp_is_present.dev_attr.attr, - &sensor_dev_attr_sfp_is_present_all.dev_attr.attr, - &sensor_dev_attr_sfp_ddm_implemented.dev_attr.attr, - &sensor_dev_attr_sfp_tx_fault.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los.dev_attr.attr, - &sensor_dev_attr_sfp_rx_los_all.dev_attr.attr, - &sensor_dev_attr_sfp_tx_disable.dev_attr.attr, - NULL -}; - -/* SFP ddm attributes for sysfs */ -static struct attribute *sfp_ddm_attributes[] = { - NULL -}; - -/* Platform dependent +++ */ -#define CPLD_PORT_TO_FRONT_PORT(port) (port+1) - -enum port_numbers { -as5916_54x_sfp1, as5916_54x_sfp2, as5916_54x_sfp3, as5916_54x_sfp4, as5916_54x_sfp5, as5916_54x_sfp6, as5916_54x_sfp7, as5916_54x_sfp8, -as5916_54x_sfp9, as5916_54x_sfp10, as5916_54x_sfp11, as5916_54x_sfp12, as5916_54x_sfp13, as5916_54x_sfp14, as5916_54x_sfp15, as5916_54x_sfp16, -as5916_54x_sfp17, as5916_54x_sfp18, as5916_54x_sfp19, as5916_54x_sfp20, as5916_54x_sfp21, as5916_54x_sfp22, as5916_54x_sfp23, as5916_54x_sfp24, -as5916_54x_sfp25, as5916_54x_sfp26, as5916_54x_sfp27, as5916_54x_sfp28, as5916_54x_sfp29, as5916_54x_sfp30, as5916_54x_sfp31, as5916_54x_sfp32, -as5916_54x_sfp33, as5916_54x_sfp34, as5916_54x_sfp35, as5916_54x_sfp36, as5916_54x_sfp37, as5916_54x_sfp38, as5916_54x_sfp39, as5916_54x_sfp40, -as5916_54x_sfp41, as5916_54x_sfp42, as5916_54x_sfp43, as5916_54x_sfp44, as5916_54x_sfp45, as5916_54x_sfp46, as5916_54x_sfp47, as5916_54x_sfp48, -as5916_54x_sfp49, as5916_54x_sfp50, as5916_54x_sfp51, as5916_54x_sfp52, as5916_54x_sfp53, as5916_54x_sfp54 -}; - -static const struct i2c_device_id sfp_device_id[] = { -{ "as5916_54x_sfp1", as5916_54x_sfp1 }, { "as5916_54x_sfp2", as5916_54x_sfp2 }, { "as5916_54x_sfp3", as5916_54x_sfp3 }, { "as5916_54x_sfp4", as5916_54x_sfp4 }, -{ "as5916_54x_sfp5", as5916_54x_sfp5 }, { "as5916_54x_sfp6", as5916_54x_sfp6 }, { "as5916_54x_sfp7", as5916_54x_sfp7 }, { "as5916_54x_sfp8", as5916_54x_sfp8 }, -{ "as5916_54x_sfp9", as5916_54x_sfp9 }, { "as5916_54x_sfp10", as5916_54x_sfp10 }, { "as5916_54x_sfp11", as5916_54x_sfp11 }, { "as5916_54x_sfp12", as5916_54x_sfp12 }, -{ "as5916_54x_sfp13", as5916_54x_sfp13 }, { "as5916_54x_sfp14", as5916_54x_sfp14 }, { "as5916_54x_sfp15", as5916_54x_sfp15 }, { "as5916_54x_sfp16", as5916_54x_sfp16 }, -{ "as5916_54x_sfp17", as5916_54x_sfp17 }, { "as5916_54x_sfp18", as5916_54x_sfp18 }, { "as5916_54x_sfp19", as5916_54x_sfp19 }, { "as5916_54x_sfp20", as5916_54x_sfp20 }, -{ "as5916_54x_sfp21", as5916_54x_sfp21 }, { "as5916_54x_sfp22", as5916_54x_sfp22 }, { "as5916_54x_sfp23", as5916_54x_sfp23 }, { "as5916_54x_sfp24", as5916_54x_sfp24 }, -{ "as5916_54x_sfp25", as5916_54x_sfp25 }, { "as5916_54x_sfp26", as5916_54x_sfp26 }, { "as5916_54x_sfp27", as5916_54x_sfp27 }, { "as5916_54x_sfp28", as5916_54x_sfp28 }, -{ "as5916_54x_sfp29", as5916_54x_sfp29 }, { "as5916_54x_sfp30", as5916_54x_sfp30 }, { "as5916_54x_sfp31", as5916_54x_sfp31 }, { "as5916_54x_sfp32", as5916_54x_sfp32 }, -{ "as5916_54x_sfp33", as5916_54x_sfp33 }, { "as5916_54x_sfp34", as5916_54x_sfp34 }, { "as5916_54x_sfp35", as5916_54x_sfp35 }, { "as5916_54x_sfp36", as5916_54x_sfp36 }, -{ "as5916_54x_sfp37", as5916_54x_sfp37 }, { "as5916_54x_sfp38", as5916_54x_sfp38 }, { "as5916_54x_sfp39", as5916_54x_sfp39 }, { "as5916_54x_sfp40", as5916_54x_sfp40 }, -{ "as5916_54x_sfp41", as5916_54x_sfp41 }, { "as5916_54x_sfp42", as5916_54x_sfp42 }, { "as5916_54x_sfp43", as5916_54x_sfp43 }, { "as5916_54x_sfp44", as5916_54x_sfp44 }, -{ "as5916_54x_sfp45", as5916_54x_sfp45 }, { "as5916_54x_sfp46", as5916_54x_sfp46 }, { "as5916_54x_sfp47", as5916_54x_sfp47 }, { "as5916_54x_sfp48", as5916_54x_sfp48 }, -{ "as5916_54x_sfp49", as5916_54x_sfp49 }, { "as5916_54x_sfp50", as5916_54x_sfp50 }, { "as5916_54x_sfp51", as5916_54x_sfp51 }, { "as5916_54x_sfp52", as5916_54x_sfp52 }, -{ "as5916_54x_sfp53", as5916_54x_sfp53 }, { "as5916_54x_sfp54", as5916_54x_sfp54 }, -{ /* LIST END */ } -}; -MODULE_DEVICE_TABLE(i2c, sfp_device_id); -/* Platform dependent --- */ - -/* - * list of valid port types - * note OOM_PORT_TYPE_NOT_PRESENT to indicate no - * module is present in this port - */ -typedef enum oom_driver_port_type_e { - OOM_DRIVER_PORT_TYPE_INVALID, - OOM_DRIVER_PORT_TYPE_NOT_PRESENT, - OOM_DRIVER_PORT_TYPE_SFP, - OOM_DRIVER_PORT_TYPE_SFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP, - OOM_DRIVER_PORT_TYPE_QSFP_PLUS, - OOM_DRIVER_PORT_TYPE_QSFP28 -} oom_driver_port_type_t; - -enum driver_type_e { - DRIVER_TYPE_SFP_MSA, - DRIVER_TYPE_SFP_DDM, - DRIVER_TYPE_QSFP -}; - -/* Each client has this additional data - */ -struct eeprom_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - struct bin_attribute bin; /* eeprom data */ -}; - -struct sfp_msa_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u64 status[6]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss - 3 => device id - 4 => 10G Ethernet Compliance Codes - to distinguish SFP or SFP+ - 5 => DIAGNOSTIC MONITORING TYPE */ - struct eeprom_data eeprom; -}; - -struct sfp_ddm_data { - struct eeprom_data eeprom; -}; - -struct qsfp_data { - char valid; /* !=0 if registers are valid */ - unsigned long last_updated; /* In jiffies */ - u8 status[3]; /* bit0:port0, bit1:port1 and so on */ - /* index 0 => tx_fail - 1 => tx_disable - 2 => rx_loss */ - - u8 device_id; - struct eeprom_data eeprom; -}; - -struct sfp_port_data { - struct mutex update_lock; - enum driver_type_e driver_type; - int port; /* CPLD port index */ - oom_driver_port_type_t port_type; - u64 present; /* present status, bit0:port0, bit1:port1 and so on */ - - struct sfp_msa_data *msa; - struct sfp_ddm_data *ddm; - struct qsfp_data *qsfp; - - struct i2c_client *client; -}; - -static ssize_t show_port_number(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - return sprintf(buf, "%d\n", CPLD_PORT_TO_FRONT_PORT(data->port)); -} - -/* Platform dependent +++ */ -static struct sfp_port_data *sfp_update_present(struct i2c_client *client) -{ - int i = 0, j = 0, status = -1; - u8 reg; - unsigned short cpld_addr; - struct sfp_port_data *data = i2c_get_clientdata(client); - - DEBUG_PRINT("Starting sfp present status update"); - mutex_lock(&data->update_lock); - data->present = 0; - - /* Read present status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) { - cpld_addr = I2C_ADDR_CPLD1 + i*2; - reg = 0x10+j; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - - DEBUG_PRINT("Present status = 0x%lx\r\n", data->present); - data->present |= (u64)status << ((i*24) + (j%3)*8); - } - } - - /* Read present status of port 49-52(QSFP port) */ - cpld_addr = I2C_ADDR_CPLD2; - reg = 0x52; - status = accton_i2c_cpld_read(cpld_addr, reg); - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, reg, status); - goto exit; - } - else { - data->present |= (u64)(status & 0x3F) << 48; - } - - DEBUG_PRINT("Present status = 0x%lx", data->present); -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static struct sfp_port_data* sfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i = 0, j = 0; - int status = -1; - u8 tx_rx_regs[] = {0x14, 0x16, 0x18, 0x20, 0x22, 0x24, 0x30, 0x32, 0x34}; - - if (time_before(jiffies, data->msa->last_updated + HZ + HZ / 2) && data->msa->valid) { - return data; - } - - DEBUG_PRINT("Starting as5916_54x sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->msa->valid = 0; - memset(data->msa->status, 0, sizeof(data->msa->status)); - - /* Read status of port 1~48(SFP port) */ - for (i = 0; i < 2; i++) { - for (j = 0; j < ARRAY_SIZE(tx_rx_regs); j++) { - unsigned short cpld_addr = I2C_ADDR_CPLD1 + i*2; - - status = accton_i2c_cpld_read(cpld_addr, tx_rx_regs[j]); - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "cpld(0x%x) reg(0x%x) err %d\n", cpld_addr, tx_rx_regs[i], status); - goto exit; - } - - data->msa->status[j/3] |= (u64)status << ((i*24) + (j%3)*8); - } - } - - data->msa->valid = 1; - data->msa->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t sfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - unsigned short cpld_addr = 0; - u8 cpld_reg = 0, cpld_val = 0, cpld_bit = 0; - long disable; - int error; - u8 tx_disable_regs[] = {0x20, 0x22, 0x24}; - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_set_tx_disable(dev, da, buf, count); - } - - error = kstrtol(buf, 10, &disable); - if (error) { - return error; - } - - mutex_lock(&data->update_lock); - - if(data->port < 24) { - cpld_addr = I2C_ADDR_CPLD1; - cpld_reg = tx_disable_regs[data->port / 8]; - cpld_bit = 1 << (data->port % 8); - } - else { /* port 24 ~ 48 */ - cpld_addr = I2C_ADDR_CPLD2; - cpld_reg = tx_disable_regs[(data->port - 24) / 8]; - cpld_bit = 1 << (data->port % 8); - } - - /* Read current status */ - cpld_val = accton_i2c_cpld_read(cpld_addr, cpld_reg); - - /* Update tx_disable status */ - if (disable) { - data->msa->status[1] |= BIT_INDEX(data->port); - cpld_val |= cpld_bit; - } - else { - data->msa->status[1] &= ~BIT_INDEX(data->port); - cpld_val &= ~cpld_bit; - } - - accton_i2c_cpld_write(cpld_addr, cpld_reg, cpld_val); - mutex_unlock(&data->update_lock); - return count; -} - -static int sfp_is_port_present(struct i2c_client *client, int port) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - data = sfp_update_present(client); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - return !(data->present & BIT_INDEX(data->port)); /* Platform dependent */ -} - -static ssize_t show_present(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - - if (PRESENT_ALL == attr->index) { - int i; - u8 values[7] = {0}; - struct sfp_port_data *data = sfp_update_present(client); - - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = ~(u8)(data->present >> (i * 8)); - } - - /* Return values 1 -> 54 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5], - values[6] & 0x3F); - } - else { - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - /* PRESENT */ - return sprintf(buf, "%d\n", present); - } -} -/* Platform dependent --- */ - -static struct sfp_port_data *sfp_update_port_type(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - u8 buf = 0; - int status; - - mutex_lock(&data->update_lock); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - if (buf != SFF8024_DEVICE_ID_SFP) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - status = sfp_eeprom_read(client, SFF8472_10G_ETH_COMPLIANCE_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("sfp port type (0x3) data = (0x%x)", buf); - data->port_type = buf & SFF8472_10G_BASE_MASK ? OOM_DRIVER_PORT_TYPE_SFP_PLUS : OOM_DRIVER_PORT_TYPE_SFP; - break; - } - case DRIVER_TYPE_QSFP: - { - status = sfp_eeprom_read(client, SFF8024_PHYSICAL_DEVICE_ID_ADDR, &buf, sizeof(buf)); - if (unlikely(status < 0)) { - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - DEBUG_PRINT("qsfp port type (0x0) buf = (0x%x)", buf); - switch (buf) { - case SFF8024_DEVICE_ID_QSFP: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP; - break; - case SFF8024_DEVICE_ID_QSFP_PLUS: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - case SFF8024_DEVICE_ID_QSFP28: - data->port_type = OOM_DRIVER_PORT_TYPE_QSFP_PLUS; - break; - default: - data->port_type = OOM_DRIVER_PORT_TYPE_INVALID; - break; - } - - break; - } - default: - break; - } - - mutex_unlock(&data->update_lock); - return data; -} - -static ssize_t show_port_type(struct device *dev, struct device_attribute *da, - char *buf) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int present = sfp_is_port_present(client, data->port); - - if (IS_ERR_VALUE(present)) { - return present; - } - - if (!present) { - return sprintf(buf, "%d\n", OOM_DRIVER_PORT_TYPE_NOT_PRESENT); - } - - sfp_update_port_type(dev); - return sprintf(buf, "%d\n", data->port_type); -} - -static struct sfp_port_data *qsfp_update_tx_rx_status(struct device *dev) -{ - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - int i, status = -1; - u8 buf = 0; - u8 reg[] = {SFF8436_TX_FAULT_ADDR, SFF8436_TX_DISABLE_ADDR, SFF8436_RX_LOS_ADDR}; - - if (time_before(jiffies, data->qsfp->last_updated + HZ + HZ / 2) && data->qsfp->valid) { - return data; - } - - DEBUG_PRINT("Starting sfp tx rx status update"); - mutex_lock(&data->update_lock); - data->qsfp->valid = 0; - memset(data->qsfp->status, 0, sizeof(data->qsfp->status)); - - /* Notify device to update tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - } - msleep(200); - - /* Read actual tx fault/ tx disable/ rx los status */ - for (i = 0; i < ARRAY_SIZE(reg); i++) { - status = sfp_eeprom_read(client, reg[i], &buf, sizeof(buf)); - if (unlikely(status < 0)) { - goto exit; - } - - DEBUG_PRINT("qsfp reg(0x%x) status = (0x%x)", reg[i], data->qsfp->status[i]); - data->qsfp->status[i] = (buf & 0xF); - } - - data->qsfp->valid = 1; - data->qsfp->last_updated = jiffies; - -exit: - mutex_unlock(&data->update_lock); - return (status < 0) ? ERR_PTR(status) : data; -} - -static ssize_t qsfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - int present; - u8 val = 0; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - present = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENXIO; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - switch (attr->index) { - case TX_FAULT: - val = !!(data->qsfp->status[2] & 0xF); - break; - case TX_FAULT1: - case TX_FAULT2: - case TX_FAULT3: - case TX_FAULT4: - val = !!(data->qsfp->status[2] & BIT_INDEX(attr->index - TX_FAULT1)); - break; - case TX_DISABLE: - val = data->qsfp->status[1] & 0xF; - break; - case TX_DISABLE1: - case TX_DISABLE2: - case TX_DISABLE3: - case TX_DISABLE4: - val = !!(data->qsfp->status[1] & BIT_INDEX(attr->index - TX_DISABLE1)); - break; - case RX_LOS: - val = !!(data->qsfp->status[0] & 0xF); - break; - case RX_LOS1: - case RX_LOS2: - case RX_LOS3: - case RX_LOS4: - val = !!(data->qsfp->status[0] & BIT_INDEX(attr->index - RX_LOS1)); - break; - default: - break; - } - - return sprintf(buf, "%d\n", val); -} - -static ssize_t qsfp_set_tx_disable(struct device *dev, struct device_attribute *da, - const char *buf, size_t count) -{ - long disable; - int status; - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (!status) { - /* port is not present */ - return -ENXIO; - } - - status = kstrtol(buf, 10, &disable); - if (status) { - return status; - } - - data = qsfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - mutex_lock(&data->update_lock); - - if (attr->index == TX_DISABLE) { - data->qsfp->status[1] = disable & 0xF; - } - else {/* TX_DISABLE1 ~ TX_DISABLE4*/ - if (disable) { - data->qsfp->status[1] |= (1 << (attr->index - TX_DISABLE1)); - } - else { - data->qsfp->status[1] &= ~(1 << (attr->index - TX_DISABLE1)); - } - } - - DEBUG_PRINT("index = (%d), status = (0x%x)", attr->index, data->qsfp->status[1]); - status = sfp_eeprom_write(data->client, SFF8436_TX_DISABLE_ADDR, &data->qsfp->status[1], sizeof(data->qsfp->status[1])); - if (unlikely(status < 0)) { - count = status; - } - - mutex_unlock(&data->update_lock); - return count; -} - -static ssize_t sfp_show_ddm_implemented(struct device *dev, struct device_attribute *da, - char *buf) -{ - int status; - char ddm; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - - status = sfp_is_port_present(client, data->port); - if (IS_ERR_VALUE(status)) { - return status; - } - - if (status == 0) { - /* port is not present */ - return -ENODEV; - } - - status = sfp_eeprom_read(client, SFF8472_DIAG_MON_TYPE_ADDR, &ddm, sizeof(ddm)); - if (unlikely(status < 0)) { - return status; - } - - return sprintf(buf, "%d\n", !!(ddm & SFF8472_DIAG_MON_TYPE_DDM_MASK)); -} - -/* Platform dependent +++ */ -static ssize_t sfp_show_tx_rx_status(struct device *dev, struct device_attribute *da, - char *buf) -{ - u8 val = 0, index = 0; - struct i2c_client *client = to_i2c_client(dev); - struct sfp_port_data *data = i2c_get_clientdata(client); - struct sensor_device_attribute *attr = to_sensor_dev_attr(da); - - if (data->driver_type == DRIVER_TYPE_QSFP) { - return qsfp_show_tx_rx_status(dev, da, buf); - } - - data = sfp_update_tx_rx_status(dev); - if (IS_ERR(data)) { - return PTR_ERR(data); - } - - if(attr->index == RX_LOS_ALL) { - int i = 0; - u8 values[6] = {0}; - - for (i = 0; i < ARRAY_SIZE(values); i++) { - values[i] = (u8)(data->msa->status[2] >> (i * 8)); - } - - /** Return values 1 -> 48 in order */ - return sprintf(buf, "%.2x %.2x %.2x %.2x %.2x %.2x\n", - values[0], values[1], values[2], - values[3], values[4], values[5]); - } - - switch (attr->index) { - case TX_FAULT: - index = 0; - break; - case TX_DISABLE: - index = 1; - break; - case RX_LOS: - index = 2; - break; - default: - return 0; - } - - val = !!(data->msa->status[index] & BIT_INDEX(data->port)); - return sprintf(buf, "%d\n", val); -} -/* Platform dependent --- */ -static ssize_t sfp_eeprom_write(struct i2c_client *client, u8 command, const char *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_write_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return data_len; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_write_byte_data(client, command, *data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - return status; - } - - return 1; -#endif - - -} - -static ssize_t sfp_port_write(struct sfp_port_data *data, - 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(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_write(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; -} - - -static ssize_t sfp_bin_write(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("%s(%d) offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_write(data, buf, off, count); -} - -static ssize_t sfp_eeprom_read(struct i2c_client *client, u8 command, u8 *data, - int data_len) -{ -#if USE_I2C_BLOCK_READ - int status, retry = I2C_RW_RETRY_COUNT; - - if (data_len > I2C_SMBUS_BLOCK_MAX) { - data_len = I2C_SMBUS_BLOCK_MAX; - } - - while (retry) { - status = i2c_smbus_read_i2c_block_data(client, command, data_len, data); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - goto abort; - } - if (unlikely(status != data_len)) { - status = -EIO; - goto abort; - } - - //result = data_len; - -abort: - return status; -#else - int status, retry = I2C_RW_RETRY_COUNT; - - while (retry) { - status = i2c_smbus_read_byte_data(client, command); - if (unlikely(status < 0)) { - msleep(I2C_RW_RETRY_INTERVAL); - retry--; - continue; - } - - break; - } - - if (unlikely(status < 0)) { - dev_dbg(&client->dev, "sfp read byte data failed, command(0x%2x), data(0x%2x)\r\n", command, status); - goto abort; - } - - *data = (u8)status; - status = 1; - -abort: - return status; -#endif -} - -static ssize_t sfp_port_read(struct sfp_port_data *data, - char *buf, loff_t off, size_t count) -{ - ssize_t retval = 0; - - if (unlikely(!count)) { - DEBUG_PRINT("Count = 0, return"); - return count; - } - - /* - * Read data from chip, protecting against concurrent updates - * from this host, but not from other I2C masters. - */ - mutex_lock(&data->update_lock); - - while (count) { - ssize_t status; - - status = sfp_eeprom_read(data->client, off, buf, count); - if (status <= 0) { - if (retval == 0) { - retval = status; - } - break; - } - - buf += status; - off += status; - count -= status; - retval += status; - } - - mutex_unlock(&data->update_lock); - return retval; - -} - -static ssize_t sfp_bin_read(struct file *filp, struct kobject *kobj, - struct bin_attribute *attr, - char *buf, loff_t off, size_t count) -{ - int present; - struct sfp_port_data *data; - DEBUG_PRINT("offset = (%d), count = (%d)", off, count); - data = dev_get_drvdata(container_of(kobj, struct device, kobj)); - - present = sfp_is_port_present(data->client, data->port); - if (IS_ERR_VALUE(present)) { - return present; - } - - if (present == 0) { - /* port is not present */ - return -ENODEV; - } - - return sfp_port_read(data, buf, off, count); -} - -static int sfp_sysfs_eeprom_init(struct kobject *kobj, struct bin_attribute *eeprom) -{ - int err; - - sysfs_bin_attr_init(eeprom); - eeprom->attr.name = EEPROM_NAME; - eeprom->attr.mode = S_IWUSR | S_IRUGO; - eeprom->read = sfp_bin_read; - eeprom->write = sfp_bin_write; - eeprom->size = EEPROM_SIZE; - - /* Create eeprom file */ - err = sysfs_create_bin_file(kobj, eeprom); - if (err) { - return err; - } - - return 0; -} - -static int sfp_sysfs_eeprom_cleanup(struct kobject *kobj, struct bin_attribute *eeprom) -{ - sysfs_remove_bin_file(kobj, eeprom); - return 0; -} - -static const struct attribute_group sfp_msa_group = { - .attrs = sfp_msa_attributes, -}; - -static int sfp_i2c_check_functionality(struct i2c_client *client) -{ -#if USE_I2C_BLOCK_READ - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK); -#else - return i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA); -#endif -} - -static int sfp_msa_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_msa_data **data) -{ - int status; - struct sfp_msa_data *msa; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - msa = kzalloc(sizeof(struct sfp_msa_data), GFP_KERNEL); - if (!msa) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_msa_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &msa->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = msa; - dev_info(&client->dev, "sfp msa '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); -exit_free: - kfree(msa); -exit: - - return status; -} - -static const struct attribute_group sfp_ddm_group = { - .attrs = sfp_ddm_attributes, -}; - -static int sfp_ddm_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct sfp_ddm_data **data) -{ - int status; - struct sfp_ddm_data *ddm; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - ddm = kzalloc(sizeof(struct sfp_ddm_data), GFP_KERNEL); - if (!ddm) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &sfp_ddm_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &ddm->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = ddm; - dev_info(&client->dev, "sfp ddm '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); -exit_free: - kfree(ddm); -exit: - - return status; -} - -static const struct attribute_group qsfp_group = { - .attrs = qsfp_attributes, -}; - -static int qsfp_probe(struct i2c_client *client, const struct i2c_device_id *dev_id, - struct qsfp_data **data) -{ - int status; - struct qsfp_data *qsfp; - - if (!sfp_i2c_check_functionality(client)) { - status = -EIO; - goto exit; - } - - qsfp = kzalloc(sizeof(struct qsfp_data), GFP_KERNEL); - if (!qsfp) { - status = -ENOMEM; - goto exit; - } - - /* Register sysfs hooks */ - status = sysfs_create_group(&client->dev.kobj, &qsfp_group); - if (status) { - goto exit_free; - } - - /* init eeprom */ - status = sfp_sysfs_eeprom_init(&client->dev.kobj, &qsfp->eeprom.bin); - if (status) { - goto exit_remove; - } - - *data = qsfp; - dev_info(&client->dev, "qsfp '%s'\n", client->name); - - return 0; - -exit_remove: - sysfs_remove_group(&client->dev.kobj, &qsfp_group); -exit_free: - kfree(qsfp); -exit: - - return status; -} - -/* Platform dependent +++ */ -static int sfp_device_probe(struct i2c_client *client, - const struct i2c_device_id *dev_id) -{ - struct sfp_port_data *data = NULL; - - data = kzalloc(sizeof(struct sfp_port_data), GFP_KERNEL); - if (!data) { - return -ENOMEM; - } - - i2c_set_clientdata(client, data); - mutex_init(&data->update_lock); - data->port = dev_id->driver_data; - data->client = client; - - if (dev_id->driver_data >= as5916_54x_sfp1 && dev_id->driver_data <= as5916_54x_sfp48) { - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_MSA; - return sfp_msa_probe(client, dev_id, &data->msa); - } - else if (client->addr == SFP_EEPROM_A2_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_SFP_DDM; - return sfp_ddm_probe(client, dev_id, &data->ddm); - } - } - else { /* as5916_54x_sfp49 ~ as5916_54x_sfp54 */ - if (client->addr == SFP_EEPROM_A0_I2C_ADDR) { - data->driver_type = DRIVER_TYPE_QSFP; - return qsfp_probe(client, dev_id, &data->qsfp); - } - } - - return -ENODEV; -} -/* Platform dependent --- */ - -static int sfp_msa_remove(struct i2c_client *client, struct sfp_msa_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_msa_group); - kfree(data); - return 0; -} - -static int sfp_ddm_remove(struct i2c_client *client, struct sfp_ddm_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &sfp_ddm_group); - kfree(data); - return 0; -} - -static int qfp_remove(struct i2c_client *client, struct qsfp_data *data) -{ - sfp_sysfs_eeprom_cleanup(&client->dev.kobj, &data->eeprom.bin); - sysfs_remove_group(&client->dev.kobj, &qsfp_group); - kfree(data); - return 0; -} - -static int sfp_device_remove(struct i2c_client *client) -{ - struct sfp_port_data *data = i2c_get_clientdata(client); - - switch (data->driver_type) { - case DRIVER_TYPE_SFP_MSA: - return sfp_msa_remove(client, data->msa); - case DRIVER_TYPE_SFP_DDM: - return sfp_ddm_remove(client, data->ddm); - case DRIVER_TYPE_QSFP: - return qfp_remove(client, data->qsfp); - } - - return 0; -} - -/* Addresses scanned - */ -static const unsigned short normal_i2c[] = { I2C_CLIENT_END }; - -static struct i2c_driver sfp_driver = { - .driver = { - .name = DRIVER_NAME, - }, - .probe = sfp_device_probe, - .remove = sfp_device_remove, - .id_table = sfp_device_id, - .address_list = normal_i2c, -}; - -static int __init sfp_init(void) -{ - return i2c_add_driver(&sfp_driver); -} - -static void __exit sfp_exit(void) -{ - i2c_del_driver(&sfp_driver); -} - -MODULE_AUTHOR("Brandon Chuang "); -MODULE_DESCRIPTION("accton as5916_54x_sfp driver"); -MODULE_LICENSE("GPL"); - -late_initcall(sfp_init); -module_exit(sfp_exit); - - diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c index d1606f47..75f8ce55 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/onlp/builds/src/module/src/sfpi.c @@ -24,17 +24,21 @@ * ***********************************************************/ #include +#include #include -#include "platform_lib.h" - +#include "x86_64_accton_as5916_54x_int.h" #include "x86_64_accton_as5916_54x_log.h" -#define NUM_OF_SFP_PORT 54 -#define MAX_PORT_PATH 64 +#define PORT_BUS_INDEX(port) (port+33) -#define SFP_PORT_FORMAT "/sys/bus/i2c/devices/%d-0050/%s" -#define SFP_PORT_DOM_FORMAT "/sys/bus/i2c/devices/%d-0051/%s" -#define SFP_BUS_INDEX(port) (port+33) +#define PORT_EEPROM_FORMAT "/sys/bus/i2c/devices/%d-0050/eeprom" +#define MODULE_PRESENT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_present_%d" +#define MODULE_RXLOS_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_rx_los_%d" +#define MODULE_TXFAULT_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_fault_%d" +#define MODULE_TXDISABLE_FORMAT "/sys/bus/i2c/devices/%d-00%d/module_tx_disable_%d" +#define MODULE_PRESENT_ALL_ATTR "/sys/bus/i2c/devices/%d-00%d/module_present_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD1 "/sys/bus/i2c/devices/11-0060/module_rx_los_all" +#define MODULE_RXLOS_ALL_ATTR_CPLD2 "/sys/bus/i2c/devices/12-0062/module_rx_los_all" /************************************************************ * @@ -56,7 +60,7 @@ onlp_sfpi_bitmap_get(onlp_sfp_bitmap_t* bmap) */ int p; - for(p = 0; p < NUM_OF_SFP_PORT; p++) { + for(p = 0; p < 54; p++) { AIM_BITMAP_SET(bmap, p); } @@ -72,7 +76,12 @@ onlp_sfpi_is_present(int port) * Return < 0 if error. */ int present; - if (onlp_file_read_int(&present, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_is_present") < 0) { + int bus, addr; + + addr = (port < 24) ? 60 : 62; + bus = (addr == 60) ? 11 : 12; + + if (onlp_file_read_int(&present, MODULE_PRESENT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read present status from port(%d)\r\n", port); return ONLP_STATUS_E_INTERNAL; } @@ -83,31 +92,45 @@ onlp_sfpi_is_present(int port) int onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) { - uint32_t bytes[7]; - char path[MAX_PORT_PATH] = {0}; + uint32_t bytes[7], *ptr = NULL; FILE* fp; + int addr; - sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_is_present_all"); - fp = fopen(path, "r"); + ptr = bytes; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5, - bytes+6 - ); - fclose(fp); - if(count != AIM_ARRAYSIZE(bytes)) { - /* Likely a CPLD read timeout. */ - AIM_LOG_ERROR("Unable to read all fields from the sfp_is_present_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 60; addr <= 62; addr+=2) { + /* Read present status of port 0~53 */ + int count = 0; + char file[64] = {0}; + int bus = (addr == 60) ? 11 : 12; + + sprintf(file, MODULE_PRESENT_ALL_ATTR, bus, addr); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + + if (addr == 60) { /* CPLD1 */ + count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + else { /* CPLD2 */ + count = fscanf(fp, "%x %x %x %x", ptr+0, ptr+1, ptr+2, ptr+3); + fclose(fp); + if(count != 4) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields the module_present_all device file of CPLD(0x%d).", addr); + return ONLP_STATUS_E_INTERNAL; + } + } + + ptr += count; } /* Mask out non-existant QSFP ports */ @@ -130,64 +153,44 @@ onlp_sfpi_presence_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } -int -onlp_sfpi_eeprom_read(int port, uint8_t data[256]) -{ - int size = 0; - if(onlp_file_read(data, 256, &size, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { - if(size == 256) { - return ONLP_STATUS_OK; - } - } - - return ONLP_STATUS_E_INTERNAL; -} - -int -onlp_sfpi_dom_read(int port, uint8_t data[256]) -{ - int size = 0; - if(onlp_file_read(data, 256, &size, SFP_PORT_DOM_FORMAT, SFP_BUS_INDEX(port), "sfp_eeprom") == ONLP_STATUS_OK) { - if(size == 256) { - return ONLP_STATUS_OK; - } - } - - return ONLP_STATUS_E_INTERNAL; -} - int onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) { uint32_t bytes[6]; - char path[MAX_PORT_PATH] = {0}; + uint32_t *ptr = bytes; FILE* fp; - sprintf(path, SFP_PORT_FORMAT, SFP_BUS_INDEX(0), "sfp_rx_los_all"); - fp = fopen(path, "r"); + /* Read present status of port 0~23 */ + int addr, i = 0; - if(fp == NULL) { - AIM_LOG_ERROR("Unable to open the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; - } - int count = fscanf(fp, "%x %x %x %x %x %x", - bytes+0, - bytes+1, - bytes+2, - bytes+3, - bytes+4, - bytes+5 - ); - fclose(fp); - if(count != 6) { - AIM_LOG_ERROR("Unable to read all fields from the sfp_rx_los_all device file."); - return ONLP_STATUS_E_INTERNAL; + for (addr = 60; addr <= 62; addr+=2) { + if (addr == 60) { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD1, "r"); + } + else { + fp = fopen(MODULE_RXLOS_ALL_ATTR_CPLD2, "r"); + } + + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + int count = fscanf(fp, "%x %x %x", ptr+0, ptr+1, ptr+2); + fclose(fp); + if(count != 3) { + /* Likely a CPLD read timeout. */ + AIM_LOG_ERROR("Unable to read all fields from the module_rx_los_all device file of CPLD(0x%d)", addr); + return ONLP_STATUS_E_INTERNAL; + } + + ptr += count; } /* Convert to 64 bit integer in port order */ - int i = 0; + i = 0; uint64_t rx_los_all = 0 ; - for(i = 5; i >= 0; i--) { + for(i = AIM_ARRAYSIZE(bytes)-1; i >= 0; i--) { rx_los_all <<= 8; rx_los_all |= bytes[i]; } @@ -201,16 +204,77 @@ onlp_sfpi_rx_los_bitmap_get(onlp_sfp_bitmap_t* dst) return ONLP_STATUS_OK; } +int +onlp_sfpi_eeprom_read(int port, uint8_t data[256]) +{ + /* + * Read the SFP eeprom into data[] + * + * Return MISSING if SFP is missing. + * Return OK if eeprom is read + */ + int size = 0; + memset(data, 0, 256); + + if(onlp_file_read(data, 256, &size, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)) != ONLP_STATUS_OK) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d)\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (size != 256) { + AIM_LOG_ERROR("Unable to read eeprom from port(%d), size is different!\r\n", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + +int +onlp_sfpi_dom_read(int port, uint8_t data[256]) +{ + FILE* fp; + char file[64] = {0}; + + sprintf(file, PORT_EEPROM_FORMAT, PORT_BUS_INDEX(port)); + fp = fopen(file, "r"); + if(fp == NULL) { + AIM_LOG_ERROR("Unable to open the eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + if (fseek(fp, 256, SEEK_CUR) != 0) { + fclose(fp); + AIM_LOG_ERROR("Unable to set the file position indicator of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + int ret = fread(data, 1, 256, fp); + fclose(fp); + if (ret != 256) { + AIM_LOG_ERROR("Unable to read the module_eeprom device file of port(%d)", port); + return ONLP_STATUS_E_INTERNAL; + } + + return ONLP_STATUS_OK; +} + int onlp_sfpi_control_set(int port, onlp_sfp_control_t control, int value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 11 : 12; + switch(control) { case ONLP_SFP_CONTROL_TX_DISABLE: { - if (onlp_file_write_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") != 0) { + if (onlp_file_write_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to set tx_disable status to port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -233,12 +297,19 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) { int rv; + if (port < 0 || port >= 48) { + return ONLP_STATUS_E_UNSUPPORTED; + } + + int addr = (port < 24) ? 60 : 62; + int bus = (addr == 60) ? 11 : 12; + switch(control) { case ONLP_SFP_CONTROL_RX_LOS: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_rx_los") < 0) { - AIM_LOG_ERROR("Unable to read rx_los status from port(%d)\r\n", port); + if (onlp_file_read_int(value, MODULE_RXLOS_FORMAT, bus, addr, (port+1)) < 0) { + AIM_LOG_ERROR("Unable to read rx_loss status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } else { @@ -249,7 +320,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_FAULT: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_fault") < 0) { + if (onlp_file_read_int(value, MODULE_TXFAULT_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_fault status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -261,7 +332,7 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) case ONLP_SFP_CONTROL_TX_DISABLE: { - if (onlp_file_read_int(value, SFP_PORT_FORMAT, SFP_BUS_INDEX(port), "sfp_tx_disable") < 0) { + if (onlp_file_read_int(value, MODULE_TXDISABLE_FORMAT, bus, addr, (port+1)) < 0) { AIM_LOG_ERROR("Unable to read tx_disabled status from port(%d)\r\n", port); rv = ONLP_STATUS_E_INTERNAL; } @@ -278,7 +349,6 @@ onlp_sfpi_control_get(int port, onlp_sfp_control_t control, int* value) return rv; } - int onlp_sfpi_denit(void) { diff --git a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py index 171b3c20..c2b8e872 100644 --- a/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py +++ b/packages/platforms/accton/x86-64/x86-64-accton-as5916-54x/platform-config/r1/src/python/x86_64_accton_as5916_54x_r1/__init__.py @@ -8,9 +8,9 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, SYS_OBJECT_ID=".5916.54" def baseconfig(self): - self.insmod("accton_i2c_cpld") + self.insmod('optoe') self.insmod("ym2651y") - for m in [ "sfp", "psu", "fan", "leds" ]: + for m in [ "cpld", "psu", "fan", "leds" ]: self.insmod("x86-64-accton-as5916-54x-%s" % m) ########### initialize I2C bus 0 ########### @@ -30,8 +30,8 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, ('lm75', 0x4b, 10), # initialize CPLDs - ('accton_i2c_cpld', 0x60, 11), - ('accton_i2c_cpld', 0x62, 12), + ('as5916_54x_cpld1', 0x60, 11), + ('as5916_54x_cpld2', 0x62, 12), # initialize multiplexer (PCA9548) ('pca9548', 0x74, 2), @@ -61,12 +61,14 @@ class OnlPlatform_x86_64_accton_as5916_54x_r1(OnlPlatformAccton, # initialize SFP devices for port in range(1, 49): - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x51, port+32) + self.new_i2c_device('optoe2', 0x50, port+32) # initialize QSFP devices for port in range(49, 55): - self.new_i2c_device('as5916_54x_sfp%d' % port, 0x50, port+32) + self.new_i2c_device('optoe1', 0x50, port+32) + + for port in range(1, 55): + subprocess.call('echo port%d > /sys/bus/i2c/devices/%d-0050/port_name' % (port, port+32), shell=True) return True From bc949a5afbfbffb74b26eed9046f2dd4cd32c77f Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 2 Apr 2018 18:53:22 +0000 Subject: [PATCH 17/21] Latest --- packages/platforms-closed | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/platforms-closed b/packages/platforms-closed index 9cc37062..93a3eee2 160000 --- a/packages/platforms-closed +++ b/packages/platforms-closed @@ -1 +1 @@ -Subproject commit 9cc37062419222acc152d8d94b9f95965ccd665f +Subproject commit 93a3eee233b1543a8c3734354bbb77bf2747938b From 41bf6970e5c99d657153da8023455be2e858257f Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Mon, 2 Apr 2018 17:41:02 +0000 Subject: [PATCH 18/21] Add option for local script execution during autoboot. --- .../base/all/initrds/loader-initrd-files/src/bin/autoboot | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/base/all/initrds/loader-initrd-files/src/bin/autoboot b/packages/base/all/initrds/loader-initrd-files/src/bin/autoboot index 79bfa3fc..6638708a 100644 --- a/packages/base/all/initrds/loader-initrd-files/src/bin/autoboot +++ b/packages/base/all/initrds/loader-initrd-files/src/bin/autoboot @@ -21,6 +21,9 @@ if [ -f /etc/onl/abort ]; then exit 1 fi +if [ -f /mnt/onl/boot/autoboot ]; then + . /mnt/onl/boot/autoboot +fi # # The maximum number of times we will retry autobooting before @@ -118,4 +121,3 @@ else msg_error "BOOTMODE $BOOTMODE is not implemented. Autobooting cannot continue." exit 1 fi - From 3b45ae681311e22809b359b48c36dce4bf947a10 Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Tue, 3 Apr 2018 21:11:29 +0000 Subject: [PATCH 19/21] UDS Error Handling - Don't allow UDS connects() to block. - Add a 1 second timeout for all UDS read/write operations. --- .../base/any/onlp/src/onlplib/module/src/file.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/base/any/onlp/src/onlplib/module/src/file.c b/packages/base/any/onlp/src/onlplib/module/src/file.c index ef31b840..df73165c 100644 --- a/packages/base/any/onlp/src/onlplib/module/src/file.c +++ b/packages/base/any/onlp/src/onlplib/module/src/file.c @@ -50,11 +50,26 @@ ds_connect__(const char* path) return -1; } + /* + * UDS connects must be non-blocking. + */ + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK); + memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, path, sizeof(addr.sun_path)-1); if(connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0) { + + /* + * Set blocking with a 1 second timeout on all domain socket read/write operations. + */ + struct timeval tv; + + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_NONBLOCK); + tv.tv_sec = 1; + tv.tv_usec = 0; + setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (const char*)&tv, sizeof tv); return fd; } else { From fde45aafd78a58db5ae7940291bb14ca2fc3da2e Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 5 Apr 2018 17:27:21 +0000 Subject: [PATCH 20/21] Disable ASR generation by default. Packages using ASR must be updated explicitly. --- tools/onlpm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/onlpm.py b/tools/onlpm.py index ab68bdae..523287f0 100755 --- a/tools/onlpm.py +++ b/tools/onlpm.py @@ -431,7 +431,7 @@ class OnlPackage(object): if self.pkg.get('init-after-remove', True): command = command + "--after-remove %s " % OnlPackageAfterRemoveScript(self.pkg['init'], dir=workdir).name - if self.pkg.get('asr', True): + if self.pkg.get('asr', False): with onlu.Profiler() as profiler: # Generate the ASR documentation for this package. sys.path.append("%s/sm/infra/tools" % os.getenv('ONL')) From 7faad73b4a8105313e8e09230b2a6cbf354686ef Mon Sep 17 00:00:00 2001 From: Jeffrey Townsend Date: Thu, 5 Apr 2018 17:32:31 +0000 Subject: [PATCH 21/21] Enable ASR generation. --- packages/base/any/faultd/APKG.yml | 5 +---- packages/base/any/onlp-snmpd/APKG.yml | 3 +-- packages/base/any/onlp/APKG.yml | 5 +---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/packages/base/any/faultd/APKG.yml b/packages/base/any/faultd/APKG.yml index 6eb1b970..9a9d6eb5 100644 --- a/packages/base/any/faultd/APKG.yml +++ b/packages/base/any/faultd/APKG.yml @@ -16,7 +16,4 @@ packages: init: ${ONL}/packages/base/any/faultd/faultd.init changelog: Change changes changes., - - - - + asr: True diff --git a/packages/base/any/onlp-snmpd/APKG.yml b/packages/base/any/onlp-snmpd/APKG.yml index bb37f217..b21767cb 100644 --- a/packages/base/any/onlp-snmpd/APKG.yml +++ b/packages/base/any/onlp-snmpd/APKG.yml @@ -21,5 +21,4 @@ packages: init: ${ONL}/packages/base/any/onlp-snmpd/onlp-snmpd.init changelog: Change changes changes., - - + asr: True diff --git a/packages/base/any/onlp/APKG.yml b/packages/base/any/onlp/APKG.yml index 4597e63d..1d6832e5 100644 --- a/packages/base/any/onlp/APKG.yml +++ b/packages/base/any/onlp/APKG.yml @@ -36,7 +36,4 @@ packages: init: $ONL/packages/base/any/onlp/src/onlpd.init changelog: Change changes changes., - - - - + asr: True