Merge pull request #11 from opencomputeproject/master

merge from upstream
This commit is contained in:
Lewis Kang
2017-09-27 09:41:20 +08:00
committed by GitHub
233 changed files with 16093 additions and 653 deletions

3
.gitmodules vendored
View File

@@ -16,3 +16,6 @@
[submodule "packages/platforms-closed"]
path = packages/platforms-closed
url = git@github.com:opennetworklinux/platforms-closed
[submodule "sm/build-artifacts"]
path = sm/build-artifacts
url = git://github.com/opennetworklinux/build-artifacts

View File

@@ -26,6 +26,7 @@ $(foreach a,$(ALL_ARCHES),$(eval $(call build_arch_template,$(a))))
# Available build architectures based on the current suite
BUILD_ARCHES_wheezy := amd64 powerpc
BUILD_ARCHES_jessie := $(ALL_ARCHES)
BUILD_ARCHES_stretch := amd64
# Build available architectures by default.
.DEFAULT_GOAL := all

1
REPO/stretch/Makefile Normal file
View File

@@ -0,0 +1 @@
include $(ONL)/make/repo-suite.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/repo.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/repo.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/repo.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/repo.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/repo.mk

View File

@@ -528,7 +528,7 @@ installer_force_umount() {
dev=$1; shift
mpt=$1; shift
case "$mpt" in
/mnt/*)
/mnt/*|/boot/*)
installer_say "Unmounting $mpt (--force)"
umount "$mpt"
;;

View File

@@ -11,3 +11,5 @@
- hw-management
- sx-kernel
- onl-kernel-3.16-lts-x86-64-all-modules
- efibootmgr
- gdisk

View File

@@ -17,3 +17,11 @@ mounts:
mount: ro
dir: /mnt/onl/boot
fsck: false
# ESP (EFI system partition)
EFI-BOOT:
mount: ro
dir: /boot/efi
fsck: false
label: EFI System
optional: true

View File

@@ -0,0 +1,79 @@
############################################################
#
# Common Release Packages for all systems.
#
############################################################
- base-files
- sysvinit-core
- locales
- python
- apt
- apt-utils
- procps
- net-tools
- iputils-ping
- less
- sudo
- openssh-server
- iproute
- resolvconf
- vim-tiny
- zile
- nano
- lsof
- mingetty
- traceroute
- realpath
- rsyslog
- nfs-common
- netbase
- bsdmainutils
- ifupdown
- psmisc
- make
- python-cherrypy3
- python-tz
- scapy
- python-pypcap
- snmpd
- snmp
- pciutils
- usbutils
- mtd-utils
- i2c-tools
- isc-dhcp-client
- ntp
- wget
- ethtool
- localepurge
- telnetd
- python-pyinotify
- cpio
- util-linux
- dosfstools
- rssh
- u-boot-tools
- ntpdate
- onlp
- parted
- watchdog
- netplug
- binutils
- file
- smartmontools
- realpath
- iptables
- onl-faultd
- onlp-snmpd
- oom-shim
- python-parted
- python-yaml
- bzip2
- xz-utils
- unzip
- onl-mibs
- openssl
- gdb
- tcpdump
- strace
- sysstat

View File

@@ -0,0 +1,15 @@
############################################################
#
# Common packages for all amd64 systems.
#
############################################################
- dmidecode
- parted
- smartmontools
- grub2
- onl-upgrade
- hw-management
- sx-kernel
- onl-kernel-3.16-lts-x86-64-all-modules
- efibootmgr
- gdisk

View File

@@ -0,0 +1,11 @@
############################################################
#
# These packages are specific to the ONL root filesystem build.
#
############################################################
- onl-upgrade

View File

@@ -0,0 +1 @@
- u-boot-tools

View File

@@ -0,0 +1,9 @@
############################################################
#
# These packages are specific to the ONL root filesystem build.
#
############################################################
- onl-loader-fit

View File

@@ -0,0 +1 @@
- u-boot-tools

View File

@@ -0,0 +1,9 @@
############################################################
#
# These packages are specific to the ONL root filesystem build.
#
############################################################
- onl-loader-fit

View File

@@ -0,0 +1 @@
0.0 0 0.0

View File

@@ -0,0 +1,6 @@
jffs2
ubifs
vfat
ext4
ext3
ext2

View File

@@ -0,0 +1,3 @@
telnet stream tcp nowait telnetd /usr/sbin/tcpd /usr/sbin/in.telnetd
qotd stream tcp nowait telnetd /usr/sbin/tcpd /sbin/versiond

View File

@@ -0,0 +1,67 @@
# The default runlevel.
id:2:initdefault:
# Boot-time system configuration/initialization script.
# This is run first except when booting in emergency (-b) mode.
si0::sysinit:/etc/boot.d/boot
si1::sysinit:/etc/init.d/rcS
# What to do in single-user mode.
~~:S:wait:/sbin/sulogin
# /etc/init.d executes the S and K scripts upon change
# of runlevel.
#
# Runlevel 0 is halt.
# Runlevel 1 is single-user.
# Runlevels 2-5 are multi-user.
# Runlevel 6 is reboot.
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
# Normally not reached, but fallthrough in case of emergency.
z6:6:respawn:/sbin/sulogin
# What to do when CTRL-ALT-DEL is pressed.
ca:12345:ctrlaltdel:/sbin/shutdown -t1 -a -r now
# Action on special keypress (ALT-UpArrow).
#kb::kbrequest:/bin/echo "Keyboard Request--edit /etc/inittab to let this work."
# What to do when the power fails/returns.
pf::powerwait:/etc/init.d/powerfail start
pn::powerfailnow:/etc/init.d/powerfail now
po::powerokwait:/etc/init.d/powerfail stop
# /sbin/getty invocations for the runlevels.
#
# The "id" field MUST be the same as the last
# characters of the device (after "tty").
#
# Format:
# <id>:<runlevels>:<action>:<process>
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/getty 38400 tty6
# Example how to put a getty on a serial line (for a terminal)
#
#T0:23:respawn:/sbin/getty -L ttyS0 9600 vt100
#T1:23:respawn:/sbin/getty -L ttyS1 9600 vt100
# Example how to put a getty on a modem line.
#
#T3:23:respawn:/sbin/mgetty -x0 -s 57600 ttyS3

View File

@@ -0,0 +1,27 @@
mounts:
ONL-IMAGES:
mount: ro
dir: /mnt/onl/images
fsck: true
ONL-DATA:
mount: rw
dir: /mnt/onl/data
ONL-CONFIG:
mount: ro
dir: /mnt/onl/config
fsck: true
ONL-BOOT:
mount: ro
dir: /mnt/onl/boot
fsck: false
# ESP (EFI system partition)
EFI-BOOT:
mount: ro
dir: /boot/efi
fsck: false
label: EFI System
optional: true

View File

@@ -0,0 +1,7 @@
############################################################
#
# Add platform specific directories to path.
#
############################################################
dir=/lib/platform-config/current/onl
export PATH="$PATH:$dir/bin:$dir/sbin:$dir/lib/bin:$dir/lib/sbin"

View File

@@ -0,0 +1,4 @@
logfacility = LOG_USER
allowsftp
allowscp
umask = 022

View File

@@ -0,0 +1,195 @@
###############################################################################
#
# EXAMPLE.conf:
# An example configuration file for configuring the Net-SNMP agent ('snmpd')
# See the 'snmpd.conf(5)' man page for details
#
# Some entries are deliberately commented out, and will need to be explicitly activated
#
###############################################################################
#
# AGENT BEHAVIOUR
#
# Listen for connections from the local system only
# agentAddress udp:127.0.0.1:161
# Listen for connections on all interfaces (both IPv4 *and* IPv6)
agentAddress udp:161,udp6:[::1]:161
###############################################################################
#
# SNMPv3 AUTHENTICATION
#
# Note that these particular settings don't actually belong here.
# They should be copied to the file /var/lib/snmp/snmpd.conf
# and the passwords changed, before being uncommented in that file *only*.
# Then restart the agent
# createUser authOnlyUser MD5 "remember to change this password"
# createUser authPrivUser SHA "remember to change this one too" DES
# createUser internalUser MD5 "this is only ever used internally, but still change the password"
# If you also change the usernames (which might be sensible),
# then remember to update the other occurances in this example config file to match.
###############################################################################
#
# ACCESS CONTROL
#
# system + hrSystem groups only
view systemonly included .1.3.6.1.2.1.1
view systemonly included .1.3.6.1.2.1.25.1
view systemonly included .1.3.6.1.4.1.42623
# Full access from the local host
rocommunity public localhost
# Default access to basic system info
rocommunity public default -V systemonly
# rocommunity6 is for IPv6
rocommunity6 public default -V systemonly
# Full access from an example network
# Adjust this network address to match your local
# settings, change the community string,
# and check the 'agentAddress' setting above
#rocommunity secret 10.0.0.0/16
# Full read-only access for SNMPv3
rouser authOnlyUser
# Full write access for encrypted requests
# Remember to activate the 'createUser' lines above
#rwuser authPrivUser priv
# It's no longer typically necessary to use the full 'com2sec/group/access' configuration
# r[ow]user and r[ow]community, together with suitable views, should cover most requirements
###############################################################################
#
# SYSTEM INFORMATION
#
# Note that setting these values here, results in the corresponding MIB objects being 'read-only'
# See snmpd.conf(5) for more details
sysLocation Sitting on the Dock of the Bay
sysContact Me <me@example.org>
# Application + End-to-End layers
sysServices 72
#
# Process Monitoring
#
# At least one 'mountd' process
proc mountd
# No more than 4 'ntalkd' processes - 0 is OK
proc ntalkd 4
# At least one 'sendmail' process, but no more than 10
proc sendmail 10 1
# Walk the UCD-SNMP-MIB::prTable to see the resulting output
# Note that this table will be empty if there are no "proc" entries in the snmpd.conf file
#
# Disk Monitoring
#
# 10MBs required on root disk, 5% free on /var, 10% free on all other disks
disk / 10000
disk /var 5%
includeAllDisks 10%
# Walk the UCD-SNMP-MIB::dskTable to see the resulting output
# Note that this table will be empty if there are no "disk" entries in the snmpd.conf file
#
# System Load
#
# Unacceptable 1-, 5-, and 15-minute load averages
load 12 10 5
# Walk the UCD-SNMP-MIB::laTable to see the resulting output
# Note that this table *will* be populated, even without a "load" entry in the snmpd.conf file
###############################################################################
#
# ACTIVE MONITORING
#
# send SNMPv1 traps
trapsink localhost public
# send SNMPv2c traps
#trap2sink localhost public
# send SNMPv2c INFORMs
#informsink localhost public
# Note that you typically only want *one* of these three lines
# Uncommenting two (or all three) will result in multiple copies of each notification.
#
# Event MIB - automatically generate alerts
#
# Remember to activate the 'createUser' lines above
iquerySecName internalUser
rouser internalUser
# generate traps on UCD error conditions
defaultMonitors yes
# generate traps on linkUp/Down
linkUpDownNotifications yes
###############################################################################
#
# EXTENDING THE AGENT
#
#
# Arbitrary extension commands
#
extend test1 /bin/echo Hello, world!
extend-sh test2 echo Hello, world! ; echo Hi there ; exit 35
#extend-sh test3 /bin/sh /tmp/shtest
# Note that this last entry requires the script '/tmp/shtest' to be created first,
# containing the same three shell commands, before the line is uncommented
# Walk the NET-SNMP-EXTEND-MIB tables (nsExtendConfigTable, nsExtendOutput1Table
# and nsExtendOutput2Table) to see the resulting output
# Note that the "extend" directive supercedes the previous "exec" and "sh" directives
# However, walking the UCD-SNMP-MIB::extTable should still returns the same output,
# as well as the fuller results in the above tables.
#
# "Pass-through" MIB extension command
#
#pass .1.3.6.1.4.1.8072.2.255 /bin/sh PREFIX/local/passtest
#pass .1.3.6.1.4.1.8072.2.255 /usr/bin/perl PREFIX/local/passtest.pl
# Note that this requires one of the two 'passtest' scripts to be installed first,
# before the appropriate line is uncommented.
# These scripts can be found in the 'local' directory of the source distribution,
# and are not installed automatically.
# Walk the NET-SNMP-PASS-MIB::netSnmpPassExamples subtree to see the resulting output
#
# AgentX Sub-agents
#
# Run as an AgentX master agent
master agentx
# Listen for network connections (from localhost)
# rather than the default named socket /var/agentx/master
#agentXSocket tcp:localhost:705

View File

@@ -0,0 +1 @@
SUBSYSTEM=="block", RUN+="/sbin/initblockdev $kernel $env{ACTION}"

View File

@@ -0,0 +1 @@
SUBSYSTEM=="net", RUN+="/sbin/initnetdev $kernel $env{ACTION}"

View File

@@ -0,0 +1,23 @@
#!/bin/sh
t=/dev/$1
# if $1 is not set, use linux cmdline console as default tty
[ -z "$1" ] && {
tty=$(/bin/sed 's/.*console=\([^,]*\).*/\1/' /proc/cmdline)
t=/dev/$tty
}
# Reset the console tty to standard settings
/bin/stty -F $t sane pass8 -ixon -cstopb clocal
# Kill any processes with the console tty open before starting a new
# login session (login tries to do this, but vhangup() spares processes
# that ignore SIGHUP)
#/usr/bin/lsof -p ^$$ -t $t 0<&- 1>&- 2>&- | /usr/bin/xargs -r /bin/kill -9
# Flush tty input and output queues
#/sbin/flushtty <$t
# We use mingetty instead of agetty, as the latter messes up the tty
# settings if it receives junk characters at the wrong speed
exec /sbin/mingetty --noclear $t

View File

@@ -0,0 +1,71 @@
#!/usr/bin/python
############################################################
# <bsn.cl fy=2013 v=onl>
#
# Copyright 2013, 2014 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.
#
# </bsn.cl>
############################################################
#
# watchdir
#
############################################################
import optparse, os.path, sys
import pyinotify
#pyinotify.log.setLevel(pyinotify.logging.DEBUG)
op = optparse.OptionParser( usage="%prog [OPTIONS] command")
op.add_option("-w", "--watchdir", action="append",
help="monitor watchdir for changes (may be used multiple times)")
op.add_option("--period", action="store", type="float",
help="run command at most every period sec (default=%default)")
op.add_option("-d", "--daemon", action="store_true",
help="run in background")
op.add_option("--logfile", action="store",
help="send output to logfile when running in background")
op.add_option("--pidfile", action="store",
help="write pid to pidfile when running in background")
op.set_defaults(period=0, logfile="/dev/stdout", pidfile=False)
opts, args = op.parse_args()
if not opts.watchdir:
op.error("need at least one watchdir")
os.close(0)
os.open("/dev/null", os.O_RDONLY)
wm = pyinotify.WatchManager()
n = pyinotify.Notifier(wm, read_freq=opts.period)
def handle(event):
dir = None
for d in opts.watchdir:
if os.path.commonprefix([d, event.pathname]) == d:
dir = d
sys.stdout.write("%s: %s %s\n" % (dir, event.pathname, event))
sys.stdout.flush()
if args:
os.spawnvp(os.P_WAIT, args[0],
args + [dir, event.pathname, event.maskname])
wm.add_watch(
opts.watchdir,
pyinotify.IN_ATTRIB | pyinotify.IN_CREATE | pyinotify.IN_DELETE |
pyinotify.IN_MODIFY | pyinotify.IN_MOVED_FROM | pyinotify.IN_MOVED_TO,
handle,
rec=True,
auto_add=True)
n.loop(daemonize=opts.daemon, stdout=opts.logfile, stderr=opts.logfile,
pid_file=opts.pidfile)

View File

@@ -0,0 +1,11 @@
############################################################
#
# Common packages for all PowerPC systems.
#
############################################################
- u-boot-tools

View File

@@ -0,0 +1,9 @@
############################################################
#
# These packages are specific to the ONL root filesystem build.
#
############################################################
- onl-loader-fit

View File

@@ -0,0 +1,105 @@
############################################################
#
# Standard ONL Debian 9 Root Filesystem Configuration.
#
# Requires:
# ARCH, PLATFORM_LIST
#
#
############################################################
variables:
!include $ONL/make/versions/version-onl.yml
Packages: &Packages
- !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/all-base-packages.yml
- !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/${ARCH}-base-packages.yml
- !include $ONL/builds/any/rootfs/$ONL_DEBIAN_SUITE/common/${ARCH}-onl-packages.yml
- !script $ONL/tools/onl-platform-pkgs.py ${PLATFORM_LIST}
Multistrap:
General:
arch: ${ARCH}
cleanup: true
noauth: true
explicitsuite: false
unpack: true
debootstrap: Debian-Local Local-All Local-Arch ONL
aptsources: Debian ONL
Debian:
packages: *Packages
source: http://${DEBIAN_MIRROR}
suite: ${ONL_DEBIAN_SUITE}
keyring: debian-archive-keyring
omitdebsrc: true
Debian-Local:
packages: *Packages
source: http://${APT_CACHE}${DEBIAN_MIRROR}
suite: ${ONL_DEBIAN_SUITE}
keyring: debian-archive-keyring
omitdebsrc: true
ONL:
packages: *Packages
source: http://apt.opennetlinux.org/debian
suite: unstable
omitdebsrc: true
Local-All:
source: ${ONLPM_OPTION_REPO}/${ONL_DEBIAN_SUITE}/packages/binary-all
omitdebsrc: true
Local-Arch:
source: ${ONLPM_OPTION_REPO}/${ONL_DEBIAN_SUITE}/packages/binary-${ARCH}
omitdebsrc: true
Configure:
overlays:
- ${ONL}/builds/any/rootfs/${ONL_DEBIAN_SUITE}/common/overlay
update-rc.d:
- 'faultd defaults'
- 'onlpd defaults'
- 'snmpd defaults'
- 'onlp-snmpd defaults'
- 'ssh defaults'
- 'openbsd-inetd remove'
- 'ntp remove'
- 'nfs-common remove'
- 'rpcbind remove'
- 'motd remove'
- 'mountall-bootclean.sh remove'
- 'mountall.sh remove'
- 'checkfs.sh remove'
- 'mtab.sh remove'
- 'checkroot-bootclean.sh remove'
- 'checkroot.sh remove'
- 'mountnfs-bootclean.sh remove'
- 'mountnfs.sh remove'
- 'lm-sensors remove'
- 'netplug defaults'
- 'watchdog defaults'
- 'wd_keepalive remove'
options:
clean: True
securetty: False
ttys: False
console: True
PermitRootLogin: 'yes'
users:
root:
password: onl
manifests:
'/etc/onl/rootfs/manifest.json' :
version : $ONL/make/versions/version-onl.json
platforms : $PLATFORM_LIST
issue: $VERSION_STRING
files:
remove:
- /etc/motd

View File

@@ -0,0 +1,137 @@
FROM debian:9.1
MAINTAINER Jeff Townsend <jeffrey.townsend@bigswitch.com>
# First round of dependences
RUN apt-get update && apt-get install -y \
apt \
apt-cacher-ng \
apt-file \
apt-utils \
autoconf \
automake \
autotools-dev \
bash-completion \
bc \
bind9-host \
binfmt-support \
binfmt-support \
bison \
bsdmainutils \
build-essential \
ccache \
cdbs \
cpio \
cryptsetup-bin \
debhelper \
debhelper \
debhelper \
device-tree-compiler \
devscripts \
devscripts \
dialog \
dosfstools \
doxygen \
dpkg-sig \
emacs \
file \
flex \
gawk \
gcc \
gdb \
genisoimage \
git \
gperf \
ifupdown \
iproute \
iputils-ping \
isolinux \
kmod \
less \
libc6-dev \
libcurl4-nss-dev \
libdouble-conversion-dev \
libedit-dev \
libevent-dev \
libexpat1-dev \
libgoogle-glog-dev \
libi2c-dev \
libkrb5-dev \
libnuma-dev \
libsasl2-dev \
libsnappy-dev \
libpam-dev \
libpcap-dev \
libsnmp-dev \
libssl-dev \
libtool \
libtool-bin \
locales \
lsof \
make \
mingetty \
mtd-utils \
mtools \
multistrap \
nano \
ncurses-dev \
netbase \
net-tools \
nfs-common \
openssh-server \
pkg-config \
pkg-config \
procps \
psmisc \
python \
python-debian \
python-dnspython \
python-yaml \
qemu \
qemu-user-static \
realpath \
realpath \
rsyslog \
ruby \
ruby-dev \
rubygems \
screen \
squashfs-tools \
sshpass \
stgit \
sudo \
syslinux-utils \
telnet \
texinfo \
traceroute \
u-boot-tools \
vim-tiny \
wget \
xorriso \
zile \
zip
RUN apt-get install -y \
chrpath devscripts dh-autoreconf dh-systemd flex \
libcap-dev libc-ares-dev libjson-c-dev libpam0g-dev libpcre3-dev \
libreadline-dev libsystemd-dev pkg-config \
texlive-generic-recommended texinfo texlive-latex-base
RUN gem install --version 1.3.3 fpm
#
# The i2c-dev.h user/kernel header conflict is a nightmare.
#
# The ONLP implementation expects a new file called <linux/i2c-device.h> to be in place which contains the correct user-space driver definitions.
# This should be manually populated here after the toolchains have been installed.
#
RUN cp /usr/include/linux/i2c-dev.h /usr/include/linux/i2c-devices.h
RUN rm /etc/apt/apt.conf.d/docker-* && \
wget "https://launchpad.net/ubuntu/+source/qemu/1.4.0+dfsg-1expubuntu3/+build/4336762/+files/qemu-user-static_1.4.0%2Bdfsg-1expubuntu3_amd64.deb" && \
dpkg -i qemu-user-static_1.4.0+dfsg-1expubuntu3_amd64.deb
#
# Copy the docker shell init script to /bin
#
COPY docker_shell /bin/docker_shell
COPY container-id /bin/container-id

View File

@@ -0,0 +1,19 @@
VERSION=1.0
USER=opennetworklinux
REPO=builder9
TOOLS=../../../tools/docker_shell ../../../tools/container-id
build: check_version
cp $(TOOLS) .
docker build -t $(USER)/$(REPO):$(VERSION) .
rm -rf $(notdir $(TOOLS))
#
# Todo: Query remote repository to see if the request version already exists to avoid accidental overwrites
# when a new image is built but the VERSION variable is not updated.
#
check_version:
push:
docker push $(USER)/$(REPO):$(VERSION)

View File

@@ -19,6 +19,7 @@ g_timestamp = datetime.datetime.now().strftime("%Y-%m-%d.%H%M%S")
g_builder7_image_name="opennetworklinux/builder7:1.2"
g_builder8_image_name="opennetworklinux/builder8:1.7"
g_builder9_image_name="opennetworklinux/builder9:1.0"
g_default_image_name=g_builder8_image_name
g_default_container_name = "%s_%s" % (g_current_user, g_timestamp)
@@ -26,6 +27,9 @@ g_default_user="%s:%s" % (g_current_user, g_current_uid)
ap = argparse.ArgumentParser("ONL Docker Build")
ap.add_argument('--9', '-9',
help="Run the Debian 9 version.",
action='store_true', dest='debian9')
ap.add_argument('--8', '-8',
help="Run the Debian 8 version.",
action='store_true', dest='debian8')
@@ -117,6 +121,8 @@ if ops.debian7:
if ops.debian8:
ops.image = g_builder8_image_name
if ops.debian9:
ops.image = g_builder9_image_name
if ops.verbose or ops.dry:
logger.setLevel(logging.DEBUG)

View File

@@ -7,5 +7,4 @@ include $(ONL)/make/config.mk
export TOOLCHAIN := x86_64-linux-gnu
export ARCH := amd64
export UARCH := AMD64
export __$(ARCH)__ := 1

View File

@@ -7,3 +7,4 @@ include $(ONL)/make/config.mk
export TOOLCHAIN := aarch64-linux-gnu
export ARCH := arm64
export UARCH := ARM64
export __$(ARCH)__ := 1

View File

@@ -7,3 +7,4 @@ include $(ONL)/make/config.mk
export TOOLCHAIN := arm-linux-gnueabi
export ARCH := armel
export UARCH := ARMEL
export __$(ARCH)__ := 1

View File

@@ -7,5 +7,4 @@ include $(ONL)/make/config.mk
export TOOLCHAIN := powerpc-linux-gnu
export ARCH := powerpc
export UARCH := PPC
export __$(ARCH)__ := 1

View File

@@ -141,4 +141,7 @@ wait_link_up()
return 1
}
wait_link_up $NETDEV 100
if [ -n "${NETAUTO}" ]; then
wait_link_up $NETDEV 100
fi
return 0

View File

@@ -49,7 +49,13 @@ done <${mtab}
rm -f ${mtab}
mount --move /proc /newroot/proc
if [ -d /sys/firmware/efi/efivars ]; then
umount /sys/firmware/efi/efivars || :
fi
mount --move /sys /newroot/sys
if [ -d /newroot/sys/firmware/efi/efivars ]; then
mount -t efivarfs efivarfs /newroot/sys/firmware/efi/efivars
fi
mount --move /dev /newroot/dev
# Switch to /newroot if possible, else re-execute /init
@@ -58,3 +64,8 @@ if [ -x /newroot/sbin/init ]; then
else
exec /init
fi
# Local variables:
# sh-indentation: 4
# sh-basic-offset: 4
# End:

View File

@@ -35,6 +35,9 @@ trap "restoreconsole; reboot -f" EXIT
# Mount special filesystems
mount -t proc proc /proc
mount -t sysfs sysfs /sys
if [ -d /sys/firmware/efi/efivars ]; then
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi
mount -o remount,size=1M /dev
case "$(stat -f -c "%T" /tmp)" in
tmpfs|ramfs) ;;
@@ -144,4 +147,5 @@ trap - EXIT
# Local variables:
# sh-basic-offset: 4
# sh-indentation: 4
# End:

View File

@@ -18,3 +18,11 @@ mounts:
mount: rw
dir: /mnt/onl/boot
fsck: true
# ESP (EFI system partition)
EFI-BOOT:
mount: ro
dir: /boot/efi
fsck: false
label: EFI System
optional: true

View File

@@ -113,6 +113,9 @@ installer_mkchroot() {
mkdir -p ${rootdir}/dev/pts
fi
mount -t devpts devpts "${rootdir}/dev/pts"
if test -d "${rootdir}/sys/firmware/efi/efivars"; then
mount -t efivarfs efivarfs "${rootdir}/sys/firmware/efi/efivars"
fi
if test ${TMPDIR+set}; then
# make the tempdir available to the chroot
@@ -233,7 +236,7 @@ blkid_find_gpt_boot() {
}
installer_fixup_gpt() {
local buf dat sts dev
local buf dat sts dev do_recover
buf=$(mktemp -u -t sgdisk-XXXXXX)
@@ -261,32 +264,79 @@ installer_fixup_gpt() {
fi
test -b "$dev" || return 0
# see if it's a clean GPT partition table
if sgdisk -p "$dev" > "$buf" 2>&1; then
sts=0
do_recover=
# simple validation using sgdisk
if test "$do_recover"; then
:
else
sts=$?
fi
if test $sts -ne 0; then
cat "$buf" 1>&2
rm -f "$buf"
installer_say "Cannot reliably get GPT partition table"
return 1
fi
if sgdisk -p "$dev" > "$buf" 2>&1; then
sts=0
else
sts=$?
fi
if test $sts -ne 0; then
cat "$buf" 1>&2
rm -f "$buf"
installer_say "Cannot reliably get GPT partition table"
return 1
fi
case $(cat "$buf") in
*Caution*|*Warning*)
cat $buf 1>&2
installer_say "Found issues with the GPT partition table"
rm -f "$buf"
;;
*)
installer_say "Found a clean GPT partition table"
rm -f "$buf"
return 0
case $(cat "$buf") in
*Caution*|*Warning*)
cat $buf 1>&2
installer_say "Found issues with the GPT partition table"
do_recover=1
rm -f "$buf"
;;
esac
esac
fi
# more thorough validation
if test "$do_recover"; then
:
else
local inp
inp=$(mktemp -u -t sgdisk-XXXXXX)
cat > "$inp" <<-END
x
r
v
q
END
if gdisk "$dev" < "$inp" > "$buf" 2>&1; then
sts=0
else
sts=$?
fi
rm -f "$inp"
if test $sts -ne 0; then
cat "$buf" 1>&2
rm -f "$buf"
installer_say "Cannot reliably verify GPT partition table"
return 1
fi
case $(cat "$buf") in
*Caution*|*Warning*|*Problem:*)
cat $buf 1>&2
installer_say "Found issues with the GPT partition table"
do_recover=1
rm -f "$buf"
;;
esac
fi
if test "$do_recover"; then
:
else
installer_say "Found a clean GPT partition table"
rm -f "$buf"
return 0
fi
installer_say "Attempting to correct the GPT partition table"
# this is the simple method; gdisk/sfgdisk will correct

View File

@@ -19,8 +19,12 @@ import fnmatch, glob
from InstallUtils import SubprocessMixin
from InstallUtils import MountContext, BlkidParser, PartedParser
from InstallUtils import ProcMountsParser
from InstallUtils import GdiskParser
from InstallUtils import OnieSubprocess
from Plugin import Plugin
import onl.install.ConfUtils
import onl.YamlUtils
from onl.sysconfig import sysconfig
@@ -509,14 +513,33 @@ menuentry %(boot_menu_entry)s {
initrd /%(platform)s.cpio.gz
}
set onie_boot_label="ONIE-BOOT"
set onie_boot_uuid="%(onie_boot_uuid)s"
# filesystem UUID, *not* GPT partition GUID, *not* GPT partition unique GUID
# (tee hee, GPT GRUB cannot grok partition attributes)
function onie_boot_uefi {
set root='(hd0,gpt1)'
search --no-floppy --fs-uuid --set=root "${onie_boot_uuid}"
echo 'Loading ONIE ...'
chainloader /EFI/onie/grubx64.efi
}
function onie_boot_dos {
search --no-floppy --label --set=root "${onie_boot_label}"
set saved_entry="0"
save_env saved_entry
echo 'Loading ONIE ...'
chainloader +1
}
# Menu entry to chainload ONIE
menuentry ONIE {
%(set_root_para)s
search --no-floppy %(set_search_para2)s --set=root %(onie_boot)s
%(set_save_entry_para)s
%(set_save_env_para)s
echo 'Loading ONIE ...'
chainloader %(set_chainloader_para)s
if [ -n "${onie_boot_uuid}" ]; then
onie_boot_uefi
else
onie_boot_dos
fi
}
"""
@@ -528,7 +551,14 @@ class GrubInstaller(SubprocessMixin, Base):
def __init__(self, *args, **kwargs):
Base.__init__(self, *args, **kwargs)
self.isUEFI = False
self.espDevice = None
self.espFsUuid = None
# optionally fill in ESP partition information
@property
def isUEFI(self):
return os.path.isdir('/sys/firmware/efi/efivars')
def findGpt(self):
self.blkidParts = BlkidParser(log=self.log.getChild("blkid"))
@@ -612,6 +642,42 @@ class GrubInstaller(SubprocessMixin, Base):
return 0
def findEsp(self):
"""Find the block device holding the EFI System Partition.
XXX assume boot (ESP) partition is on the same device as GRUB
"""
self.log.info("extracting partition UUIDs for %s", self.device)
if isinstance(self.im.grubEnv, onl.install.ConfUtils.GrubEnv):
# direct (or chroot) access
gp = GdiskParser(self.device,
subprocessContext=self.im.grubEnv,
log=self.log)
else:
# indirect access using onie-shell
ctx = OnieSubprocess(log=self.log.getChild("onie"))
gp = GdiskParser(self.device,
subprocessContext=ctx,
log=self.log)
espParts = [x for x in gp.parts if x.isEsp]
if not espParts:
self.log.error("cannot find ESP partition on %s", self.device)
return 1
self.espDevice = espParts[0].device
self.log.info("found ESP partition %s", self.espDevice)
espParts = [x for x in self.blkidParts if x.device==self.espDevice]
if not espParts:
self.log.error("cannot find blkid entry for ESP partition on %s", self.espDevice)
return 1
self.espFsUuid = espParts[0].uuid
self.log.info("found ESP filesystem UUID %s", self.espFsUuid)
return 0
def installLoader(self):
kernels = []
@@ -659,20 +725,9 @@ class GrubInstaller(SubprocessMixin, Base):
ctx['boot_loading_name'] = sysconfig.installer.os_name
if self.isUEFI:
ctx['set_root_para'] = "set root='(hd0,gpt1)'"
ctx['set_search_para2'] = "--fs-uuid"
ctx['set_save_entry_para'] = ""
ctx['set_save_env_para'] = ""
dev_UEFI = self.blkidParts['EFI System']
ctx['onie_boot'] = dev_UEFI.uuid
ctx['set_chainloader_para'] = "/EFI/onie/grubx64.efi"
ctx['onie_boot_uuid'] = self.espFsUuid
else:
ctx['set_root_para'] = ""
ctx['set_search_para2'] = "--label"
ctx['set_save_entry_para'] = "set saved_entry=\"0\""
ctx['set_save_env_para'] = "save_env saved_entry"
ctx['onie_boot'] = "ONIE-BOOT"
ctx['set_chainloader_para'] = "+1"
ctx['onie_boot_uuid'] = ""
cf = GRUB_TPL % ctx
@@ -688,7 +743,7 @@ class GrubInstaller(SubprocessMixin, Base):
def installGrub(self):
self.log.info("Installing GRUB to %s", self.partedDevice.path)
self.im.grubEnv.install(self.partedDevice.path, self.isUEFI)
self.im.grubEnv.install(self.partedDevice.path)
return 0
def installGpt(self):
@@ -707,6 +762,13 @@ class GrubInstaller(SubprocessMixin, Base):
code = self.findGpt()
if code: return code
if self.isUEFI:
code = self.findEsp()
if code: return code
self.im.grubEnv.__dict__['espPart'] = self.espDevice
else:
self.im.grubEnv.__dict__['espPart'] = None
self.log.info("Installing to %s starting at partition %d",
self.device, self.minpart)
@@ -775,8 +837,6 @@ class GrubInstaller(SubprocessMixin, Base):
if label != 'gpt':
self.log.error("invalid GRUB label in platform config: %s", label)
return 1
if os.path.isdir('/sys/firmware/efi/efivars'):
self.isUEFI = True
return self.installGpt()

View File

@@ -7,7 +7,11 @@ import os
import logging
import subprocess
from InstallUtils import SubprocessMixin, ChrootSubprocessMixin, MountContext
from InstallUtils import OnieSubprocess
from cStringIO import StringIO
import re
from onl.sysconfig import sysconfig
class ConfBase:
@@ -90,13 +94,16 @@ class GrubEnv(SubprocessMixin):
INSTALL = "grub-install"
EDITENV = "grub-editenv"
EFIBOOTMGR = "efibootmgr"
# system default
ENV_PATH = "/grub/grubenv"
# override me
EFI_BOOT_RE = re.compile("Boot([0-9a-fA-F]*)[*] (.*)")
def __init__(self,
bootDir=None, bootPart=None,
bootDir=None, bootPart=None, espPart=None,
path=None,
log=None):
@@ -108,13 +115,16 @@ class GrubEnv(SubprocessMixin):
self.__dict__['bootPart'] = bootPart
# location of GRUB boot files (mounted directory or unmounted partition)
self.__dict__['espPart'] = espPart
# location of EFI System Partition
self.__dict__['path'] = path or self.ENV_PATH
# path to grubenv, relative to above
self.__dict__['log'] = log or logging.getLogger("grub")
def mountCtx(self, device):
return MountContext(device, fsType='ext4', log=self.log)
def mountCtx(self, device, fsType='ext4'):
return MountContext(device, fsType=fsType, log=self.log)
def asDict(self):
if self.bootPart:
@@ -164,36 +174,83 @@ class GrubEnv(SubprocessMixin):
cmd = (self.EDITENV, p, 'unset', attr,)
self.check_call(cmd)
@property
def isUEFI(self):
return os.path.isdir('/sys/firmware/efi/efivars')
def install(self, device):
if self.bootDir is not None:
self.check_call((self.INSTALL, '--boot-directory=' + self.bootDir, device,))
elif self.bootPart is not None:
with self.mountCtx(self.bootPart) as ctx:
self.check_call((self.INSTALL, '--boot-directory=' + ctx.dir, device,))
uidx = None
if self.isUEFI:
buf = self.check_output((self.EFIBOOTMGR,))
for line in buf.splitlines(False):
m = self.EFI_BOOT_RE.match(line)
if m:
if m.group(2) == sysconfig.installer.os_name:
uidx = m.group(1)
break
if uidx is not None:
self.check_output((self.EFIBOOTMGR, '-b', uidx, '-B',))
grubOpts = []
if self.isUEFI:
grubOpts.append('--target=x86_64-efi')
grubOpts.append('--no-nvram')
grubOpts.append('--recheck')
grubOpts.append('--bootloader-id=ONL')
# All ONL-derived distros should be able to use
# the same profile
def _install():
if self.bootDir is not None:
self.check_call([self.INSTALL, '--boot-directory=' + self.bootDir,]
+ grubOpts
+ [device,])
elif self.bootPart is not None:
with self.mountCtx(self.bootPart) as ctx:
self.check_call([self.INSTALL, '--boot-directory=' + ctx.dir,]
+ grubOpts
+ [device,])
else:
self.check_call([self.INSTALL,] + grubOpts + [device,])
if self.espPart is not None:
with self.mountCtx(self.espPart, fsType=None) as ctx:
grubOpts.append('--efi-directory=' + ctx.dir)
_install()
else:
self.check_call((self.INSTALL, device,))
_install()
if self.isUEFI:
self.check_call((self.EFIBOOTMGR,
'--create',
'--label', sysconfig.installer.os_name,
'--disk', device,
'--part', '1',
'--loader', '/EFI/ONL/grubx64.efi',))
class ChrootGrubEnv(ChrootSubprocessMixin, GrubEnv):
def __init__(self,
chrootDir,
mounted=False,
bootDir=None, bootPart=None,
bootDir=None, bootPart=None, espPart=None,
path=None,
log=None):
self.__dict__['chrootDir'] = chrootDir
self.__dict__['mounted'] = mounted
GrubEnv.__init__(self,
bootDir=bootDir, bootPart=bootPart,
bootDir=bootDir, bootPart=bootPart, espPart=espPart,
path=path,
log=log)
def mountCtx(self, device):
def mountCtx(self, device, fsType='ext4'):
return MountContext(device,
chroot=self.chrootDir, fsType='ext4',
chroot=self.chrootDir, fsType=fsType,
log=self.log)
class ProxyGrubEnv:
class ProxyGrubEnv(SubprocessMixin):
"""Pretend to manipulate the GRUB environment.
Instead, write a trace of shell commands to a log
@@ -211,7 +268,7 @@ class ProxyGrubEnv:
def __init__(self,
installerConf,
bootDir=None, chroot=True, bootPart=None,
bootDir=None, chroot=True, bootPart=None, espPart=None,
path=None,
log=None):
@@ -226,6 +283,9 @@ class ProxyGrubEnv:
self.__dict__['bootPart'] = bootPart
# location of GRUB boot files (mounted directory or unmounted partition)
self.__dict__['espPart'] = espPart
# location of EFI System Partition
self.__dict__['chroot'] = chroot
# True of the bootDir is inside the chroot,
# else bootDir is in the host's file namespace
@@ -261,7 +321,8 @@ class ProxyGrubEnv:
% (self.path.lstrip('/'),))
cmds.append("mpt=$(mktemp -t -d)")
cmds.append("mount %s $mpt" % self.bootPart)
cmds.append(("sts=0; %s %s set %s=\"%s\" || sts=$?"
cmds.append("sts=0")
cmds.append(("%s %s set %s=\"%s\" || sts=$?"
% (self.EDITENV, p, attr, val,)))
cmds.append("umount $mpt")
cmds.append("rmdir $mpt")
@@ -291,7 +352,8 @@ class ProxyGrubEnv:
% (self.path.lstrip('/'),))
cmds.append("mpt=$(mktemp -t -d)")
cmds.append("mount %s $mpt" % self.bootPart)
cmds.append(("sts=0; %s %s unset %s || sts=$?"
cmds.append("sts=0")
cmds.append(("%s %s unset %s || sts=$?"
% (self.EDITENV, p, attr,)))
cmds.append("umount $mpt")
cmds.append("rmdir $mpt")
@@ -303,35 +365,83 @@ class ProxyGrubEnv:
fd.write(cmd)
fd.write("\n")
def install(self, device, isUEFI=False):
@property
def isUEFI(self):
return os.path.isdir('/sys/firmware/efi/efivars')
def install(self, device):
self.log.warn("deferring commands to %s...", self.installerConf.installer_postinst)
cmds.append("os_name=\"%s\"" % sysconfig.installer.os_name)
if self.isUEFI:
sub = OnieSubprocess(log=self.log.getChild("onie"))
cmd = (self.EFIBOOTMGR,)
buf = sub.check_output(cmd)
bidx = None
for line in buf.splitlines(False):
m = self.EFI_BOOT_RE.match(line)
if m:
if m.group(2) == sysconfig.installer.os_name:
uidx = m.group(1)
break
if uidx is not None:
cmds.append("%s -b %s -B || sts=$?" % (self.EFIBOOTMGR, bidx,))
grubOpts = []
if self.isUEFI:
grubOpts.append('--target=x86_64-efi')
grubOpts.append('--no-nvram')
grubOpts.append('--bootloader-id=ONL')
grubOpts.append('--efi-directory=/boot/efi')
grubOpts.append('--recheck')
cmds = []
if self.bootPart and not self.bootDir:
cmds.append("bootMpt=$(mktemp -t -d)")
cmds.append("mount %s $bootMpt" % self.bootPart)
if self.espPart is not None:
cmds.append("espMpt=$(mktemp -t -d)")
cmds.append("mount %s $espMpt" % self.espPart)
cmds.append("sts=0")
if self.bootDir and self.chroot:
p = os.pat.join(self.installerConf.installer_chroot,
self.bootDir.lstrip('/'))
cmds.append(("%s --boot-directory=\"%s\" %s" % (self.INSTALL, p, device,)))
cmd = ([self.INSTALL, '--boot-directory=' + p,]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
elif self.bootDir:
p = self.bootDir
cmds.append(("%s --boot-directory=\"%s\" %s" % (self.INSTALL, p, device,)))
cmd = ([self.INSTALL, '--boot-directory=' + p,]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
elif self.bootPart:
cmds.append("mpt=$(mktemp -t -d)")
cmds.append("mount %s $mpt" % self.bootPart)
if isUEFI:
cmds.append("[ -n \"$(efibootmgr -v | grep 'Open Network Linux')\" ] && (efibootmgr -b $(efibootmgr | grep \"Open Network Linux\" | sed 's/^.*Boot//g'| sed 's/** Open.*$//g') -B)")
cmds.append(("sts=0; %s --target=x86_64-efi --no-nvram --bootloader-id=ONL --efi-directory=/boot/efi --boot-directory=\"$mpt\" --recheck %s || sts=$?"
% (self.INSTALL, device,)))
cmds.append("test $sts -eq 0")
cmds.append(("sts=0; %s --quiet --create --label \"Open Network Linux\" --disk %s --part 1 --loader /EFI/ONL/grubx64.efi || sts=$?"
% (self.EFIBOOTMGR , device,)))
else:
cmds.append(("sts=0; %s --boot-directory=\"$mpt\" %s || sts=$?"
% (self.INSTALL, device,)))
cmds.append("umount $mpt")
cmds.append("rmdir $mpt")
cmds.append("test $sts -eq 0")
cmd = ([self.INSTALL, '--boot-directory=\"$bootMpt\"',]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
else:
cmds.append(("%s %s"
% (self.INSTALL, device,)))
cmd = ([self.INSTALL,]
+ grubOpts
+ [device,])
cmds.append(" ".join(cmd) + " || sts=$?")
if self.bootPart and not self.bootDir:
cmds.append("umount $bootMpt")
cmds.append("rmdir $bootMpt")
if self.espPart is not None:
cmds.append("umount $espMpt")
cmds.append("rmdir $espMpt")
cmds.append("test $sts -eq 0")
with open(self.installerConf.installer_postinst, "a") as fd:
for cmd in cmds:

View File

@@ -9,6 +9,7 @@ import subprocess
import tempfile
import string
import shutil
import re
import Fit, Legacy
@@ -620,6 +621,186 @@ class PartedParser(SubprocessMixin):
def __len__(self):
return len(self.parts)
class GdiskDiskEntry:
DEVICE_RE = re.compile("Disk ([^:]*): .*")
BLOCKS_RE = re.compile("Disk [^:]*: ([0-9][0-9]*) sectors")
LBSZ_RE = re.compile("Logical sector size: ([0-9][0-9]*) bytes")
GUID_RE = re.compile("Disk identifier [(]GUID[)]: ([0-9a-fA-F-][0-9a-fA-F-]*)")
def __init__(self, device, blocks, lbsz, guid):
self.device = device
self.blocks = blocks
self.lbsz = lbsz
self.guid = guid
@classmethod
def fromOutput(cls, buf):
m = cls.BLOCKS_RE.search(buf)
if m:
blocks = int(m.group(1))
else:
raise ValueError("cannot get block count")
m = cls.DEVICE_RE.search(buf)
if m:
device = m.group(1)
else:
raise ValueError("cannot get block count")
m = cls.LBSZ_RE.search(buf)
if m:
lbsz = int(m.group(1))
else:
raise ValueError("cannot get block size")
m = cls.GUID_RE.search(buf)
if m:
guid = m.group(1)
else:
raise ValueError("cannot get block size")
return cls(device, blocks, lbsz, guid)
class GdiskPartEntry:
PGUID_RE = re.compile("Partition GUID code: ([0-9a-fA-F-][0-9a-fA-F-]*) [(]([^)]*)[)]")
PGUID2_RE = re.compile("Partition GUID code: ([0-9a-fA-F-][0-9a-fA-F-]*)")
GUID_RE = re.compile("Partition unique GUID: ([0-9a-fA-F-][0-9a-fA-F-]*)")
START_RE = re.compile("First sector: ([0-9][0-9]*)")
END_RE = re.compile("Last sector: ([0-9][0-9]*)")
SIZE_RE = re.compile("Partition size: ([0-9][0-9]*) sectors")
NAME_RE = re.compile("Partition name: [']([^']+)[']")
ESP_PGUID = "c12a7328-f81f-11d2-ba4b-00a0c93ec93b"
GRUB_PGUID = "21686148-6449-6e6f-744e-656564454649"
ONIE_PGUID = "7412f7d5-a156-4b13-81dc-867174929325"
def __init__(self, device, pguid, guid, start, end, sz, pguidName=None, name=None):
self.device = device
self.pguid = pguid
self.pguidName = pguidName
self.guid = guid
self.name = name
self.start = start
self.end = end
self.sz = sz
@property
def isEsp(self):
return self.pguid == self.ESP_PGUID
@property
def isGrub(self):
return self.pguid == self.GRUB_PGUID
@property
def isOnie(self):
return self.pguid == self.ONIE_PGUID
@classmethod
def fromOutput(cls, partDevice, buf):
m = cls.PGUID_RE.search(buf)
if m:
pguid = m.group(1).lower()
pguidName = m.group(2)
else:
m = cls.PGUID2_RE.search(buf)
if m:
pguid = m.group(1).lower()
pguidName = None
else:
raise ValueError("cannot get partition GUID")
m = cls.GUID_RE.search(buf)
if m:
guid = m.group(1).lower()
else:
raise ValueError("cannot get partition unique GUID")
m = cls.START_RE.search(buf)
if m:
start = int(m.group(1))
else:
raise ValueError("cannot get partition start")
m = cls.END_RE.search(buf)
if m:
end = int(m.group(1))
else:
raise ValueError("cannot get partition end")
m = cls.SIZE_RE.search(buf)
if m:
sz = int(m.group(1))
else:
raise ValueError("cannot get partition size")
m = cls.NAME_RE.search(buf)
if m:
name = m.group(1)
else:
name = None
return cls(partDevice,
pguid, guid, start, end, sz,
pguidName=pguidName,
name=name)
class GdiskParser(SubprocessMixin):
def __init__(self, device, subprocessContext=subprocess, log=None):
self.device = device
self.log = log or logging.getLogger("parted")
self.subprocessContext = subprocessContext
self.parse()
def parse(self):
cmd = ('sgdisk', '-p', self.device,)
buf = self.subprocessContext.check_output(cmd)
self.disk = GdiskDiskEntry.fromOutput(buf)
parts = {}
pidx = 1
for line in buf.splitlines():
line = line.strip()
if not line: continue
if not line[0] in string.digits: continue
partno = int(line.split()[0])
partDevice = "%s%d" % (self.device, pidx,)
pidx += 1
# linux partitions may be numbered differently,
# if there are holes in the GPT partition table
cmd = ('sgdisk', '-i', str(partno), self.device,)
try:
buf = self.subprocessContext.check_output(cmd)
except subprocess.CalledProcessError as ex:
sys.stdout.write(ex.output)
self.log.warn("sgdisk failed with code %s", ex.returncode)
continue
# skip this partition, but otherwise do not give up
ent = GdiskPartEntry.fromOutput(partDevice, buf)
parts[partno] = ent
self.parts = []
for partno in sorted(parts.keys()):
self.parts.append(parts[partno])
if self.disk is None:
raise ValueError("no partition table found")
def __len__(self):
return len(self.parts)
class ProcMountsEntry:
def __init__(self, device, dir, fsType, flags={}):
@@ -821,6 +1002,11 @@ class InitrdContext(SubprocessMixin):
cmd = ('mount', '-t', 'sysfs', 'sysfs', dst,)
self.check_call(cmd, vmode=self.V1)
dst = os.path.join(self.dir, "sys/firmware/efi/efivars")
if os.path.exists(dst):
cmd = ('mount', '-t', 'efivarfs', 'efivarfs', dst,)
self.check_call(cmd, vmode=self.V1)
# maybe mount devtmpfs
if self._hasDevTmpfs:
dst = os.path.join(self.dir, "dev")
@@ -1022,9 +1208,55 @@ class ChrootSubprocessMixin:
cmd = ['chroot', self.chrootDir,] + list(cmd)
if not self.mounted:
with InitrdContext(self.chrootDir, log=self.log) as ctx:
with InitrdContext(dir=self.chrootDir, log=self.log) as ctx:
self.log.debug("+ " + " ".join(cmd))
return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs)
else:
self.log.debug("+ " + " ".join(cmd))
return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs)
class OnieSubprocess:
"""Simple subprocess mixin that defers to onie-shell."""
def __init__(self, log=None):
self.log = log or logging.getLogger("onie")
def check_call(self, *args, **kwargs):
args = list(args)
kwargs = dict(kwargs)
cwd = kwargs.pop('cwd', None)
if cwd is not None:
raise ValueError("cwd not supported")
if args:
cmd = args.pop(0)
else:
cmd = kwargs.pop('cmd')
if isinstance(cmd, basestring):
cmd = ('onie-shell', '-c', 'IFS=;' + cmd,)
else:
cmd = ['onie-shell', '-c',] + " ".join(cmd)
self.log.debug("+ " + " ".join(cmd))
subprocess.check_call(cmd, *args, cwd=cwd, **kwargs)
def check_output(self, *args, **kwargs):
args = list(args)
kwargs = dict(kwargs)
cwd = kwargs.pop('cwd', None)
if cwd is not None:
raise ValueError("cwd not supported")
if args:
cmd = args.pop(0)
else:
cmd = kwargs.pop('cmd')
if isinstance(cmd, basestring):
cmd = ('onie-shell', '-c', 'IFS=;' + cmd,)
else:
cmd = ['onie-shell', '-c',] + " ".join(list(cmd))
self.log.debug("+ " + " ".join(cmd))
return subprocess.check_output(cmd, *args, cwd=cwd, **kwargs)

View File

@@ -88,7 +88,7 @@ class AppBase(SubprocessMixin, object):
sys.exit(code)
class OnieBootContext:
"""Find the ONIE initrd and umpack/mount it."""
"""Find the ONIE initrd and unpack/mount it."""
def __init__(self, log=None):
self.log = log or logging.getLogger(self.__class__.__name__)
@@ -128,6 +128,7 @@ class OnieBootContext:
initrd = _g(parts[0].dir)
if initrd is None:
raise ValueError("cannot find ONIE initrd on %s" % parts[0].dir)
self.onieDir = parts[0].dir
self.log.debug("found ONIE initrd at %s", initrd)
with InitrdContext(initrd=initrd, log=self.log) as self.ictx:
self.initrd = initrd

View File

@@ -138,35 +138,53 @@ class OnlMountManager(object):
def init(self, timeout=5):
for(k, v) in self.mdata['mounts'].iteritems():
#
# Get the partition device for the given label.
# The timeout logic is here to handle waiting for the
# block devices to arrive at boot.
#
t = timeout
while t >= 0:
try:
v['device'] = subprocess.check_output("blkid -L %s" % k, shell=True).strip()
break
except subprocess.CalledProcessError:
self.logger.debug("Block label %s does not yet exist..." % k)
time.sleep(1)
t -= 1
now = time.time()
future = now + timeout
if 'device' not in v:
self.logger.error("Timeout waiting for block label %s after %d seconds." % (k, timeout))
self.missing = k
md = self.mdata['mounts']
optional = set(x for x in md if md[x].get('optional', False))
pending = set(x for x in md if not md[x].get('optional', False))
def _discover(k):
v = md[k]
lbl = v.get('label', k)
try:
v['device'] = subprocess.check_output(('blkid', '-L', lbl,)).strip()
except subprocess.CalledProcessError:
return False
#
# Make the mount point for future use.
#
if not os.path.isdir(v['dir']):
self.logger.debug("Make directory '%s'..." % v['dir'])
self.logger.debug("Make directory '%s'...", v['dir'])
os.makedirs(v['dir'])
self.logger.debug("%s @ %s" % (k, v['device']))
self.logger.debug("%s @ %s", k, v['dir'])
return True
while True:
now = time.time()
if now > future:
break
pending_ = pending
pending = [k for k in pending_ if not _discover(k)]
optional_ = optional
optional = [k for k in optional_ if not _discover(k)]
if not pending: break
if pending != pending_: continue
if optional != optional_: continue
self.logger.debug("Still waiting for block devices: %s",
" ".join(pending+optional))
time.sleep(0.25)
if pending:
for k in pending+optional:
self.logger.error("Timeout waiting for block label %s after %d seconds.", k, timeout)
# ignore the any optional labels that were not found
def __fsck(self, label, device):
self.logger.info("Running fsck on %s [ %s ]..." % (label, device))
@@ -202,20 +220,37 @@ class OnlMountManager(object):
raise ValueError("invalid labels argument.")
if 'all' in labels:
labels = filter(lambda l: l != 'all', labels) + self.mdata['mounts'].keys()
labels = list(labels)
labels.remove('all')
labels = labels + self.mdata['mounts'].keys()
def _f(label):
"""skip labels that do not resolve to a block device (ideally, optional ones)"""
mpt = self.mdata['mounts'][label]
dev = mpt.get('device', None)
opt = mpt.get('optional', False)
if dev: return True
if not opt: return True
return False
rv = []
for l in list(set(labels)):
if self.__label_entry("ONL-%s" % l.upper(), False):
rv.append("ONL-%s" % l.upper())
elif self.__label_entry(l.upper(), False):
rv.append(l.upper())
elif self.__label_entry(l):
rv.append(l)
else:
pass
return rv;
lbl = "ONL-%s" % l.upper()
if self.__label_entry(lbl, False) and _f(lbl):
rv.append("ONL-%s" % l.upper())
continue
lbl = l.upper()
if self.__label_entry(lbl, False) and _f(lbl):
rv.append(l.upper())
continue
lbl = l
if self.__label_entry(lbl) and _f(lbl):
rv.append(l)
return rv
def fsck(self, labels, force=False):
labels = self.validate_labels(labels)

View File

@@ -1,6 +1,5 @@
prerequisites:
packages:
- onl-kernel-3.2-lts-x86-64-all:amd64
- onl-kernel-3.16-lts-x86-64-all:amd64
- onl-kernel-4.9-lts-x86-64-all:amd64
- onl-loader-initrd:amd64

View File

@@ -1,8 +1,7 @@
include $(ONL)/make/config.amd64.mk
# All amd64 kernels
KERNELS := $(shell $(ONLPM) --find-file onl-kernel-3.2-lts-x86-64-all:amd64 kernel-3.2-lts-x86_64-all) \
$(shell $(ONLPM) --find-file onl-kernel-3.16-lts-x86-64-all:amd64 kernel-3.16-lts-x86_64-all) \
KERNELS := $(shell $(ONLPM) --find-file onl-kernel-3.16-lts-x86-64-all:amd64 kernel-3.16-lts-x86_64-all) \
$(shell $(ONLPM) --find-file onl-kernel-4.9-lts-x86-64-all:amd64 kernel-4.9-lts-x86_64-all)

View File

@@ -1,21 +1,21 @@
/**************************************************************************//**
* <bsn.cl fy=2013 v=onl>
*
* Copyright 2013, 2014 BigSwitch Networks, Inc.
*
*
* Copyright 2013, 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.
*
*
* </bsn.cl>
*****************************************************************************/
#include <faultd/faultd_config.h>
@@ -46,157 +46,151 @@
static pthread_spinlock_t thread_lock__;
static faultd_client_t* faultd_client__ = NULL;
static faultd_client_t* faultd_client__ = NULL;
static faultd_info_t faultd_info__;
static int localfd__ = -1;
static int localfd__ = -1;
inline int signal_backtrace__(void** buffer, int size, ucontext_t* context,
int signal_backtrace__(void** buffer, int size, ucontext_t* context,
int distance)
{
#define IP_STACK_FRAME_NUMBER 3
int rv;
int rv;
rv = backtrace(buffer, size);
if(context) {
distance += IP_STACK_FRAME_NUMBER;
if(context) {
distance += IP_STACK_FRAME_NUMBER;
#ifdef __i386__
buffer[distance] = (void*)(context->uc_mcontext.gregs[REG_EIP]);
buffer[distance] = (void*)(context->uc_mcontext.gregs[REG_EIP]);
#endif
#ifdef __PPC__
buffer[distance] = (void*)(context->uc_mcontext.regs->nip);
buffer[distance] = (void*)(context->uc_mcontext.regs->nip);
#endif
/* Note -- 64bit does not require require modifications */
}
return rv;
}
#include <AIM/aim_pvs.h>
static void
}
return rv;
}
#include <AIM/aim_pvs.h>
static void
faultd_signal_handler__(int signal, siginfo_t* siginfo, void* context)
{
int rv;
int rv;
/*
* Make sure we syncronize properly with other threads that
* may *also* be faulting
*/
rv = pthread_spin_trylock(&thread_lock__);
rv = pthread_spin_trylock(&thread_lock__);
if (rv == EBUSY) {
sigset_t mask;
sigemptyset(&mask);
pselect(0, NULL, NULL, NULL, NULL, &mask);
if (rv == EBUSY) {
sigset_t mask;
sigemptyset(&mask);
pselect(0, NULL, NULL, NULL, NULL, &mask);
}
/*
* Generate our fault information.
*/
faultd_info__.pid = getpid();
faultd_info__.tid = 0;
faultd_info__.signal = signal;
faultd_info__.signal_code = siginfo->si_code;
faultd_info__.fault_address = siginfo->si_addr;
faultd_info__.last_errno = errno;
* Generate our fault information.
*/
faultd_info__.pid = getpid();
faultd_info__.tid = 0;
faultd_info__.signal = signal;
faultd_info__.signal_code = siginfo->si_code;
faultd_info__.fault_address = siginfo->si_addr;
faultd_info__.last_errno = errno;
faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace,
faultd_info__.backtrace_size = signal_backtrace__(faultd_info__.backtrace,
AIM_ARRAYSIZE(faultd_info__.backtrace),
context, 0);
faultd_info__.backtrace_symbols = (void*)1;
if(faultd_client__) {
faultd_client_write(faultd_client__, &faultd_info__);
context, 0);
faultd_info__.backtrace_symbols = (void*)1;
if(faultd_client__) {
faultd_client_write(faultd_client__, &faultd_info__);
}
if(localfd__ >= 0) {
char* signame = strsignal(faultd_info__.signal);
char* nl = "\n";
write(localfd__, signame, strlen(signame)+1);
write(localfd__, nl, 2);
backtrace_symbols_fd(faultd_info__.backtrace,
faultd_info__.backtrace_size,
localfd__);
if(localfd__ >= 0) {
char* signame = strsignal(faultd_info__.signal);
char* nl = "\n";
write(localfd__, signame, strlen(signame)+1);
write(localfd__, nl, 2);
backtrace_symbols_fd(faultd_info__.backtrace,
faultd_info__.backtrace_size,
localfd__);
}
/*
/*
* Unlock spinlock, in case this signal wasn't fatal
*/
pthread_spin_unlock(&thread_lock__);
pthread_spin_unlock(&thread_lock__);
}
int
faultd_handler_register(int localfd,
const char* pipename,
faultd_handler_register(int localfd,
const char* pipename,
const char* binaryname)
{
int rv;
struct sigaction saction;
void* dummy_backtrace[1];
int dummy_backtrace_size;
int fd;
int rv;
struct sigaction saction;
void* dummy_backtrace[1];
int dummy_backtrace_size;
int fd;
if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) {
return rv;
if ( (rv = pthread_spin_init(&thread_lock__, 0)) ) {
return rv;
}
/*
* These calls to backtrace are to assure that
* backtrace() and backtrace_symbols_fd() have actually
* been loaded into our process -- its possible they
/*
* These calls to backtrace are to assure that
* backtrace() and backtrace_symbols_fd() have actually
* been loaded into our process -- its possible they
* come from a dynamic library, and we don't want them
* to get loaded at fault-time.
*/
dummy_backtrace_size = backtrace(dummy_backtrace, 1);
/** Note - we could just pass an invalid descriptor here, but it
* it flags errors in valgrind.
dummy_backtrace_size = backtrace(dummy_backtrace, 1);
/** Note - we could just pass an invalid descriptor here, but it
* it flags errors in valgrind.
*/
fd = open("/dev/null", O_WRONLY);
backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd);
close(fd);
fd = open("/dev/null", O_WRONLY);
backtrace_symbols_fd(dummy_backtrace, dummy_backtrace_size, fd);
close(fd);
AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__));
if(!binaryname) {
binaryname = "Not specified.";
AIM_MEMSET(&faultd_info__, 0, sizeof(faultd_info__));
if(!binaryname) {
binaryname = "Not specified.";
}
aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary));
aim_strlcpy(faultd_info__.binary, binaryname, sizeof(faultd_info__.binary));
if(pipename) {
faultd_client_create(&faultd_client__, pipename);
if(pipename) {
faultd_client_create(&faultd_client__, pipename);
}
AIM_MEMSET(&saction, 0, sizeof(saction));
saction.sa_sigaction = faultd_signal_handler__;
AIM_MEMSET(&saction, 0, sizeof(saction));
saction.sa_sigaction = faultd_signal_handler__;
sigfillset(&saction.sa_mask);
saction.sa_flags = SA_SIGINFO | SA_RESETHAND;
rv = sigaction (SIGSEGV, &saction, NULL);
sigfillset(&saction.sa_mask);
saction.sa_flags = SA_SIGINFO | SA_RESETHAND;
rv = sigaction (SIGSEGV, &saction, NULL);
rv |= sigaction (SIGILL, &saction, NULL);
rv |= sigaction (SIGFPE, &saction, NULL);
rv |= sigaction (SIGFPE, &saction, NULL);
rv |= sigaction (SIGBUS, &saction, NULL);
rv |= sigaction (SIGQUIT, &saction, NULL);
rv |= sigaction (SIGALRM, &saction, NULL);
/*
* SIGUSR2 can be used to request a backtrace explicitly.
* In this case, we don't want to reset the handler.
* SIGUSR2 can be used to request a backtrace explicitly.
* In this case, we don't want to reset the handler.
*/
saction.sa_flags = SA_SIGINFO;
rv |= sigaction (SIGUSR2, &saction, NULL);
saction.sa_flags = SA_SIGINFO;
rv |= sigaction (SIGUSR2, &saction, NULL);
/*
* The local fault handler will attempt to write a subset of
* the fault information (signal type and backtrace)
* to the localfd descriptor if specified.
* the fault information (signal type and backtrace)
* to the localfd descriptor if specified.
*/
localfd__ = localfd;
localfd__ = localfd;
return rv;
}

View File

@@ -1203,7 +1203,7 @@ CONFIG_EDA_DEF_ALIGN=0x00100000
#
CONFIG_EEPROM_AT24=y
CONFIG_EEPROM_AT25=y
# CONFIG_EEPROM_LEGACY is not set
CONFIG_EEPROM_LEGACY=m
# CONFIG_EEPROM_MAX6875 is not set
CONFIG_EEPROM_93CX6=y
# CONFIG_EEPROM_93XX46 is not set
@@ -2208,7 +2208,8 @@ CONFIG_SENSORS_W83781D=y
# CONFIG_SENSORS_W83791D is not set
# CONFIG_SENSORS_W83792D is not set
# CONFIG_SENSORS_W83793 is not set
# CONFIG_SENSORS_W83795 is not set
CONFIG_SENSORS_W83795=m
CONFIG_SENSORS_W83795_FANCTRL=y
# CONFIG_SENSORS_W83L785TS is not set
# CONFIG_SENSORS_W83L786NG is not set
# CONFIG_SENSORS_W83627HF is not set

View File

@@ -0,0 +1,16 @@
diff -urpN a/Makefile b/Makefile
--- a/Makefile 2017-08-22 17:42:57.037875653 +0000
+++ b/Makefile 2017-08-22 17:43:53.089875539 +0000
@@ -616,6 +616,12 @@ include $(srctree)/arch/$(SRCARCH)/Makef
KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
+# Required for GCC-5/6
+KBUILD_CFLAGS += $(call cc-option, -fno-pie)
+KBUILD_CFLAGS += $(call cc-option, -no-pie)
+KBUILD_AFLAGS += $(call cc-option, -fno-pie)
+KBUILD_CPPFLAGS += $(call cc-option, -fno-pie)
+
ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
KBUILD_CFLAGS += -Os $(call cc-disable-warning,maybe-uninitialized,)
else

View File

@@ -26,3 +26,4 @@ platform-powerpc-dni-7448-r0.patch
platform-powerpc-quanta-lb9-r0.patch
driver-support-intel-igb-bcm50210-phy.patch
driver-igb-netberg-aurora.patch
gcc-no-pie.patch

View File

@@ -14,6 +14,11 @@ Average: all 5.17 0.00 2.07 0.00 0.00 0.00 0.00 0.00
import subprocess
import json
import argparse
ap = argparse.ArgumentParser("onl-snmp-mpstat")
ap.add_argument("-u", required=False, help="Output current utilization only.", action='store_true')
ops = ap.parse_args()
stats = {}
@@ -30,5 +35,13 @@ for line in out.split('\n'):
vals = line.split()[1:]
stats[vals[0]] = { k:int(round(100*float(v))) \
for (k,v) in zip(keys[1:],vals[1:]) }
print json.dumps(stats)
if ops.u:
u = 0;
try:
idle = stats['all']['%idle']
u = 10000 - idle
except:
pass
print u
else:
print json.dumps(stats)

View File

@@ -1,21 +1,21 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# Copyright 2014, 2015 Big Switch Networks, Inc.
#
#
# 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.
#
#
# </bsn.cl>
############################################################
#
@@ -24,6 +24,5 @@
############################################################
onlp_AUTO_DEFS := module/auto/onlp.yml
onlp_AUTO_DIRS := module/inc/onlp module/src
onlp_AUTO_DIRS := module/inc/onlp module/src module/py
include $(BUILDER)/auto.mk

View File

@@ -231,6 +231,17 @@ psu_caps: &psu_caps
- PIN : (1 << 7)
- POUT : (1 << 8)
# SFP Controls
sfp_controls: &sfp_controls
- RESET
- RESET_STATE
- RX_LOS
- TX_FAULT
- TX_DISABLE
- TX_DISABLE_CHANNEL
- LP_MODE
- POWER_OVERRIDE
definitions:
cdefs:
ONLP_CONFIG_HEADER:
@@ -255,25 +266,13 @@ definitions:
members: *thermal_threshold
onlp_sfp_control:
tag: sfp1
members:
- RESET
- RESET_STATE
- RX_LOS
- TX_FAULT
- TX_DISABLE
- TX_DISABLE_CHANNEL
- LP_MODE
- POWER_OVERRIDE
members: *sfp_controls
onlp_sfp_control_flag:
tag: sfp2
members:
- RESET : (1 << ONLP_SFP_CONTROL_RESET)
- RESET_STATE : ( 1 << ONLP_SFP_CONTROL_RESET_STATE )
- RX_LOS : ( 1 << ONLP_SFP_CONTROL_RX_LOS )
- TX_FAULT : ( 1 << ONLP_SFP_CONTROL_TX_FAULT )
- TX_DISABLE : ( 1 << ONLP_SFP_CONTROL_TX_DISABLE )
- LP_MODE : ( 1 << ONLP_SFP_CONTROL_LP_MODE )
- POWER_OVERRIDE : ( 1 << ONLP_SFP_CONTROL_POWER_OVERRIDE )
members: *sfp_controls
flags: True
onlp_fan_mode:
tag: fan
members: *fan_modes
@@ -302,6 +301,8 @@ definitions:
tag: psu
members: *psu_caps
pyenum: *enums
portingmacro:
ONLP:
macros:

View File

@@ -59,6 +59,7 @@ typedef enum onlp_status_e {
*/
int onlp_init(void);
int onlp_denit(void);
/**
* @brief Dump the current platform data.

View File

@@ -51,13 +51,14 @@ typedef enum onlp_sfp_control_e {
/* <auto.start.enum(tag:sfp2).define> */
/** onlp_sfp_control_flag */
typedef enum onlp_sfp_control_flag_e {
ONLP_SFP_CONTROL_FLAG_RESET = (1 << ONLP_SFP_CONTROL_RESET),
ONLP_SFP_CONTROL_FLAG_RESET_STATE = ( 1 << ONLP_SFP_CONTROL_RESET_STATE ),
ONLP_SFP_CONTROL_FLAG_RX_LOS = ( 1 << ONLP_SFP_CONTROL_RX_LOS ),
ONLP_SFP_CONTROL_FLAG_TX_FAULT = ( 1 << ONLP_SFP_CONTROL_TX_FAULT ),
ONLP_SFP_CONTROL_FLAG_TX_DISABLE = ( 1 << ONLP_SFP_CONTROL_TX_DISABLE ),
ONLP_SFP_CONTROL_FLAG_LP_MODE = ( 1 << ONLP_SFP_CONTROL_LP_MODE ),
ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = ( 1 << ONLP_SFP_CONTROL_POWER_OVERRIDE ),
ONLP_SFP_CONTROL_FLAG_RESET = (1 << 0),
ONLP_SFP_CONTROL_FLAG_RESET_STATE = (1 << 1),
ONLP_SFP_CONTROL_FLAG_RX_LOS = (1 << 2),
ONLP_SFP_CONTROL_FLAG_TX_FAULT = (1 << 3),
ONLP_SFP_CONTROL_FLAG_TX_DISABLE = (1 << 4),
ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL = (1 << 5),
ONLP_SFP_CONTROL_FLAG_LP_MODE = (1 << 6),
ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE = (1 << 7),
} onlp_sfp_control_flag_t;
/* <auto.end.enum(tag:sfp2).define> */

View File

@@ -0,0 +1,169 @@
#!/usr/bin/python
############################################################
#
# These are all ONLP Enumeration values
# for use with the Python API.
#
############################################################
class Enumeration(object):
@classmethod
def name(klass, value):
for (k, v) in klass.__dict__.iteritems():
if v == value:
return k
return None
# <auto.start.pyenum(ALL).define>
class ONLP_FAN_CAPS(Enumeration):
B2F = (1 << 0)
F2B = (1 << 1)
SET_RPM = (1 << 2)
SET_PERCENTAGE = (1 << 3)
GET_RPM = (1 << 4)
GET_PERCENTAGE = (1 << 5)
class ONLP_FAN_DIR(Enumeration):
B2F = 0
F2B = 1
class ONLP_FAN_MODE(Enumeration):
OFF = 0
SLOW = 1
NORMAL = 2
FAST = 3
MAX = 4
class ONLP_FAN_STATUS(Enumeration):
PRESENT = (1 << 0)
FAILED = (1 << 1)
B2F = (1 << 2)
F2B = (1 << 3)
class ONLP_LED_CAPS(Enumeration):
ON_OFF = (1 << 0)
CHAR = (1 << 1)
RED = (1 << 10)
RED_BLINKING = (1 << 11)
ORANGE = (1 << 12)
ORANGE_BLINKING = (1 << 13)
YELLOW = (1 << 14)
YELLOW_BLINKING = (1 << 15)
GREEN = (1 << 16)
GREEN_BLINKING = (1 << 17)
BLUE = (1 << 18)
BLUE_BLINKING = (1 << 19)
PURPLE = (1 << 20)
PURPLE_BLINKING = (1 << 21)
AUTO = (1 << 22)
AUTO_BLINKING = (1 << 23)
class ONLP_LED_MODE(Enumeration):
OFF = 0
ON = 1
BLINKING = 2
RED = 10
RED_BLINKING = 11
ORANGE = 12
ORANGE_BLINKING = 13
YELLOW = 14
YELLOW_BLINKING = 15
GREEN = 16
GREEN_BLINKING = 17
BLUE = 18
BLUE_BLINKING = 19
PURPLE = 20
PURPLE_BLINKING = 21
AUTO = 22
AUTO_BLINKING = 23
class ONLP_LED_STATUS(Enumeration):
PRESENT = (1 << 0)
FAILED = (1 << 1)
ON = (1 << 2)
class ONLP_OID_TYPE(Enumeration):
SYS = 1
THERMAL = 2
FAN = 3
PSU = 4
LED = 5
MODULE = 6
RTC = 7
class ONLP_PSU_CAPS(Enumeration):
AC = (1 << 0)
DC12 = (1 << 1)
DC48 = (1 << 2)
VIN = (1 << 3)
VOUT = (1 << 4)
IIN = (1 << 5)
IOUT = (1 << 6)
PIN = (1 << 7)
POUT = (1 << 8)
class ONLP_PSU_STATUS(Enumeration):
PRESENT = (1 << 0)
FAILED = (1 << 1)
UNPLUGGED = (1 << 2)
class ONLP_SFP_CONTROL(Enumeration):
RESET = 0
RESET_STATE = 1
RX_LOS = 2
TX_FAULT = 3
TX_DISABLE = 4
TX_DISABLE_CHANNEL = 5
LP_MODE = 6
POWER_OVERRIDE = 7
class ONLP_SFP_CONTROL_FLAG(Enumeration):
RESET = (1 << 0)
RESET_STATE = (1 << 1)
RX_LOS = (1 << 2)
TX_FAULT = (1 << 3)
TX_DISABLE = (1 << 4)
TX_DISABLE_CHANNEL = (1 << 5)
LP_MODE = (1 << 6)
POWER_OVERRIDE = (1 << 7)
class ONLP_STATUS(Enumeration):
OK = 0
E_GENERIC = -1
E_UNSUPPORTED = -10
E_MISSING = -11
E_INVALID = -12
E_INTERNAL = -13
E_PARAM = -14
E_I2C = -15
class ONLP_THERMAL_CAPS(Enumeration):
GET_TEMPERATURE = (1 << 0)
GET_WARNING_THRESHOLD = (1 << 1)
GET_ERROR_THRESHOLD = (1 << 2)
GET_SHUTDOWN_THRESHOLD = (1 << 3)
class ONLP_THERMAL_STATUS(Enumeration):
PRESENT = (1 << 0)
FAILED = (1 << 1)
class ONLP_THERMAL_THRESHOLD(Enumeration):
WARNING_DEFAULT = 45000
ERROR_DEFAULT = 55000
SHUTDOWN_DEFAULT = 60000
# <auto.end.pyenum(ALL).define>

View File

@@ -1,21 +1,21 @@
/************************************************************
* <bsn.cl fy=2014 v=onl>
*
* Copyright 2014, 2015 Big Switch Networks, Inc.
*
*
* 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.
*
*
* </bsn.cl>
************************************************************
*
@@ -62,3 +62,15 @@ onlp_init(void)
onlp_thermal_init();
return 0;
}
int
onlp_denit(void)
{
#if ONLP_CONFIG_INCLUDE_API_LOCK == 1
onlp_api_lock_denit();
#endif
onlp_json_denit();
return 0;
}

View File

@@ -798,6 +798,7 @@ aim_map_si_t onlp_sfp_control_flag_map[] =
{ "RX_LOS", ONLP_SFP_CONTROL_FLAG_RX_LOS },
{ "TX_FAULT", ONLP_SFP_CONTROL_FLAG_TX_FAULT },
{ "TX_DISABLE", ONLP_SFP_CONTROL_FLAG_TX_DISABLE },
{ "TX_DISABLE_CHANNEL", ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL },
{ "LP_MODE", ONLP_SFP_CONTROL_FLAG_LP_MODE },
{ "POWER_OVERRIDE", ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE },
{ NULL, 0 }
@@ -810,6 +811,7 @@ aim_map_si_t onlp_sfp_control_flag_desc_map[] =
{ "None", ONLP_SFP_CONTROL_FLAG_RX_LOS },
{ "None", ONLP_SFP_CONTROL_FLAG_TX_FAULT },
{ "None", ONLP_SFP_CONTROL_FLAG_TX_DISABLE },
{ "None", ONLP_SFP_CONTROL_FLAG_TX_DISABLE_CHANNEL },
{ "None", ONLP_SFP_CONTROL_FLAG_LP_MODE },
{ "None", ONLP_SFP_CONTROL_FLAG_POWER_OVERRIDE },
{ NULL, 0 }

View File

@@ -45,6 +45,12 @@ onlp_api_lock_init(void)
api_sem__ = os_sem_create_flags(1, OS_SEM_CREATE_F_TRUE_RELATIVE_TIMEOUTS);
}
void
onlp_api_lock_denit(void)
{
os_sem_destroy(api_sem__);
}
void
onlp_api_lock(const char* api)
{
@@ -71,6 +77,12 @@ onlp_api_lock_init(void)
onlp_shlock_global_init();
}
void
onlp_api_lock_denit(void)
{
/* TODO */
}
void
onlp_api_lock(const char* api)
{
@@ -119,5 +131,3 @@ onlp_api_lock_test(void)
}
#endif /* ONLP_CONFIG_INCLUDE_API_LOCK */

View File

@@ -33,6 +33,7 @@
* @brief Initialize the ONLP API lock infrastructure.
*/
void onlp_api_lock_init();
void onlp_api_lock_denit();
/**
* @brief Take the ONLP API lock.

View File

@@ -53,6 +53,8 @@ sff_module_types: &sff_module_types
desc: "100GBASE-LR4"
- 100G_CWDM4:
desc: "100G-CWDM4"
- 100G_PSM4:
desc: "100G-PSM4"
- 40G_BASE_CR4:
desc: "40GBASE-CR4"
- 40G_BASE_SR4:
@@ -69,8 +71,12 @@ sff_module_types: &sff_module_types
desc: "40GBASE-SR2"
- 40G_BASE_SM4:
desc: "40GBASE-SM4"
- 40G_BASE_ER4:
desc: "40GBASE-ER4"
- 25G_BASE_CR:
desc: "25GBASE-CR"
- 25G_BASE_SR:
desc: "25GBASE-SR"
- 10G_BASE_SR:
desc: "10GBASE-SR"
- 10G_BASE_LR:
@@ -121,6 +127,8 @@ sff_sfp_types: &sff_sfp_types
desc: "QSFP+"
- QSFP28:
desc: "QSFP28"
- SFP28:
desc: "SFP28"
definitions:
cdefs:

View File

@@ -115,7 +115,7 @@
((idprom[131] & SFF8436_CC131_40GE_ACTIVE) != 0)
#define SFF8436_MEDIA_NONE(idprom) \
(idprom[131] == 0)
((idprom[131] & 0x7F) == 0)
#define SFF8436_CC132_40G_OTN 0x08
#define SFF8436_CC132_OC48_LONG SFF8472_CC4_OC48_LONG
@@ -291,6 +291,23 @@ _sff8436_qsfp_40g_sm4(const uint8_t* idprom)
return 1;
}
static inline int
_sff8436_qsfp_40g_er4(const uint8_t* idprom)
{
if(!SFF8436_MODULE_QSFP_PLUS_V2(idprom)) {
return 0;
}
if (idprom[130] != SFF8436_CONN_LC) return 0;
if (!SFF8436_MEDIA_NONE(idprom)) return 0;
/* 40 kilometer SMF */
if (idprom[142] != 40) {
return 0;
}
return 1;
}
static inline int
_sff8436_bitrate(const uint8_t *idprom)
{

View File

@@ -148,6 +148,7 @@
#define SFF8472_CC36_XGE_UNALLOCATED 0x01
#define SFF8472_CC36_UNALLOCATED1 0xF7
#define SFF8472_CC36_100G_25G_SR 0x02
#define SFF8471_CC60_FC_PI_4_LIMITING 0x08
#define SFF8471_CC60_SFF8431_LIMITING 0x04
@@ -973,4 +974,17 @@ _sff8472_media_sfp28_cr(const uint8_t* idprom)
return 0;
}
static inline int
_sff8472_media_sfp28_sr(const uint8_t* idprom)
{
/* module should be sfp */
if (!SFF8472_MODULE_SFP(idprom)) return 0;
if (idprom[12] != 0xFF) return 0;
if (idprom[36] == SFF8472_CC36_100G_25G_SR) return 1;
return 0;
}
#endif

View File

@@ -144,6 +144,8 @@
(idprom[192] == SFF8636_CC192_100GE_LR4)
#define SFF8636_MEDIA_100GE_CWDM4(idprom) \
(idprom[192] == SFF8636_CC192_100GE_CWDM4)
#define SFF8636_MEDIA_100GE_PSM4(idprom) \
(idprom[192] == SFF8636_CC192_100GE_PSM4)
#define SFF8636_MEDIA_100GE_CR4(idprom) \
(idprom[192] == SFF8636_CC192_100GE_CR4)
#define SFF8636_MEDIA_25GE_CR_S(idprom) \

View File

@@ -102,6 +102,7 @@ typedef enum sff_module_type_e {
SFF_MODULE_TYPE_100G_BASE_SR4,
SFF_MODULE_TYPE_100G_BASE_LR4,
SFF_MODULE_TYPE_100G_CWDM4,
SFF_MODULE_TYPE_100G_PSM4,
SFF_MODULE_TYPE_40G_BASE_CR4,
SFF_MODULE_TYPE_40G_BASE_SR4,
SFF_MODULE_TYPE_40G_BASE_LR4,
@@ -110,7 +111,9 @@ typedef enum sff_module_type_e {
SFF_MODULE_TYPE_40G_BASE_CR,
SFF_MODULE_TYPE_40G_BASE_SR2,
SFF_MODULE_TYPE_40G_BASE_SM4,
SFF_MODULE_TYPE_40G_BASE_ER4,
SFF_MODULE_TYPE_25G_BASE_CR,
SFF_MODULE_TYPE_25G_BASE_SR,
SFF_MODULE_TYPE_10G_BASE_SR,
SFF_MODULE_TYPE_10G_BASE_LR,
SFF_MODULE_TYPE_10G_BASE_LRM,
@@ -140,6 +143,7 @@ typedef enum sff_module_type_e {
"100G_BASE_SR4", \
"100G_BASE_LR4", \
"100G_CWDM4", \
"100G_PSM4", \
"40G_BASE_CR4", \
"40G_BASE_SR4", \
"40G_BASE_LR4", \
@@ -148,7 +152,9 @@ typedef enum sff_module_type_e {
"40G_BASE_CR", \
"40G_BASE_SR2", \
"40G_BASE_SM4", \
"40G_BASE_ER4", \
"25G_BASE_CR", \
"25G_BASE_SR", \
"10G_BASE_SR", \
"10G_BASE_LR", \
"10G_BASE_LRM", \
@@ -190,7 +196,8 @@ typedef enum sff_sfp_type_e {
SFF_SFP_TYPE_QSFP,
SFF_SFP_TYPE_QSFP_PLUS,
SFF_SFP_TYPE_QSFP28,
SFF_SFP_TYPE_LAST = SFF_SFP_TYPE_QSFP28,
SFF_SFP_TYPE_SFP28,
SFF_SFP_TYPE_LAST = SFF_SFP_TYPE_SFP28,
SFF_SFP_TYPE_COUNT,
SFF_SFP_TYPE_INVALID = -1,
} sff_sfp_type_t;
@@ -202,6 +209,7 @@ typedef enum sff_sfp_type_e {
"QSFP", \
"QSFP_PLUS", \
"QSFP28", \
"SFP28", \
}
/** Enum names. */
const char* sff_sfp_type_name(sff_sfp_type_t e);
@@ -214,7 +222,7 @@ const char* sff_sfp_type_desc(sff_sfp_type_t e);
/** validator */
#define SFF_SFP_TYPE_VALID(_e) \
( (0 <= (_e)) && ((_e) <= SFF_SFP_TYPE_QSFP28))
( (0 <= (_e)) && ((_e) <= SFF_SFP_TYPE_SFP28))
/** sff_sfp_type_map table. */
extern aim_map_si_t sff_sfp_type_map[];

View File

@@ -12,6 +12,7 @@ SFF_MEDIA_TYPE_ENTRY(100G_BASE_CR4, 100GBASE-CR4)
SFF_MEDIA_TYPE_ENTRY(100G_BASE_SR4, 100GBASE-SR4)
SFF_MEDIA_TYPE_ENTRY(100G_BASE_LR4, 100GBASE-LR4)
SFF_MEDIA_TYPE_ENTRY(100G_CWDM4, 100G-CWDM4)
SFF_MEDIA_TYPE_ENTRY(100G_PSM4, 100G-PSM4)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_CR4, 40GBASE-CR4)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_SR4, 40GBASE-SR4)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_LR4, 40GBASE-LR4)
@@ -20,7 +21,9 @@ SFF_MEDIA_TYPE_ENTRY(40G_BASE_ACTIVE, 40GBASE-ACTIVE)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_CR, 40GBASE-CR)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4)
SFF_MEDIA_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4)
SFF_MEDIA_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR)
SFF_MEDIA_TYPE_ENTRY(25G_BASE_SR, 25GBASE-SR)
SFF_MEDIA_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR)
SFF_MEDIA_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR)
SFF_MEDIA_TYPE_ENTRY(10G_BASE_LRM, 10GBASE-LRM)
@@ -56,6 +59,7 @@ SFF_MODULE_TYPE_ENTRY(100G_BASE_CR4, 100GBASE-CR4)
SFF_MODULE_TYPE_ENTRY(100G_BASE_SR4, 100GBASE-SR4)
SFF_MODULE_TYPE_ENTRY(100G_BASE_LR4, 100GBASE-LR4)
SFF_MODULE_TYPE_ENTRY(100G_CWDM4, 100G-CWDM4)
SFF_MODULE_TYPE_ENTRY(100G_PSM4, 100G-PSM4)
SFF_MODULE_TYPE_ENTRY(40G_BASE_CR4, 40GBASE-CR4)
SFF_MODULE_TYPE_ENTRY(40G_BASE_SR4, 40GBASE-SR4)
SFF_MODULE_TYPE_ENTRY(40G_BASE_LR4, 40GBASE-LR4)
@@ -64,7 +68,9 @@ SFF_MODULE_TYPE_ENTRY(40G_BASE_ACTIVE, 40GBASE-ACTIVE)
SFF_MODULE_TYPE_ENTRY(40G_BASE_CR, 40GBASE-CR)
SFF_MODULE_TYPE_ENTRY(40G_BASE_SR2, 40GBASE-SR2)
SFF_MODULE_TYPE_ENTRY(40G_BASE_SM4, 40GBASE-SM4)
SFF_MODULE_TYPE_ENTRY(40G_BASE_ER4, 40GBASE-ER4)
SFF_MODULE_TYPE_ENTRY(25G_BASE_CR, 25GBASE-CR)
SFF_MODULE_TYPE_ENTRY(25G_BASE_SR, 25GBASE-SR)
SFF_MODULE_TYPE_ENTRY(10G_BASE_SR, 10GBASE-SR)
SFF_MODULE_TYPE_ENTRY(10G_BASE_LR, 10GBASE-LR)
SFF_MODULE_TYPE_ENTRY(10G_BASE_LRM, 10GBASE-LRM)
@@ -89,6 +95,7 @@ SFF_SFP_TYPE_ENTRY(SFP, SFP)
SFF_SFP_TYPE_ENTRY(QSFP, QSFP)
SFF_SFP_TYPE_ENTRY(QSFP_PLUS, QSFP+)
SFF_SFP_TYPE_ENTRY(QSFP28, QSFP28)
SFF_SFP_TYPE_ENTRY(SFP28, SFP28)
#undef SFF_SFP_TYPE_ENTRY
#endif
/* <auto.end.xmacro(ALL).define> */

View File

@@ -76,6 +76,11 @@ sff_module_type_get(const uint8_t* eeprom)
&& SFF8636_MEDIA_100GE_CWDM4(eeprom))
return SFF_MODULE_TYPE_100G_CWDM4;
if (SFF8636_MODULE_QSFP28(eeprom)
&& SFF8636_MEDIA_EXTENDED(eeprom)
&& SFF8636_MEDIA_100GE_PSM4(eeprom))
return SFF_MODULE_TYPE_100G_PSM4;
if (SFF8436_MODULE_QSFP_PLUS_V2(eeprom)
&& SFF8436_MEDIA_40GE_CR4(eeprom))
return SFF_MODULE_TYPE_40G_BASE_CR4;
@@ -132,6 +137,11 @@ sff_module_type_get(const uint8_t* eeprom)
return SFF_MODULE_TYPE_40G_BASE_SM4;
}
if (SFF8436_MODULE_QSFP_PLUS_V2(eeprom)
&& _sff8436_qsfp_40g_er4(eeprom)) {
return SFF_MODULE_TYPE_40G_BASE_ER4;
}
if (SFF8472_MODULE_SFP(eeprom)
&& SFF8472_MEDIA_XGE_SR(eeprom)
&& !_sff8472_media_gbe_sx_fc_hack(eeprom))
@@ -177,6 +187,11 @@ sff_module_type_get(const uint8_t* eeprom)
return SFF_MODULE_TYPE_25G_BASE_CR;
}
if (SFF8472_MODULE_SFP(eeprom)
&& _sff8472_media_sfp28_sr(eeprom)) {
return SFF_MODULE_TYPE_25G_BASE_SR;
}
if (SFF8472_MODULE_SFP(eeprom)
&& SFF8472_MEDIA_GBE_SX(eeprom))
return SFF_MODULE_TYPE_1G_BASE_SX;
@@ -236,12 +251,15 @@ sff_media_type_get(sff_module_type_t mt)
case SFF_MODULE_TYPE_100G_BASE_SR4:
case SFF_MODULE_TYPE_100G_BASE_LR4:
case SFF_MODULE_TYPE_100G_CWDM4:
case SFF_MODULE_TYPE_100G_PSM4:
case SFF_MODULE_TYPE_40G_BASE_SR4:
case SFF_MODULE_TYPE_40G_BASE_LR4:
case SFF_MODULE_TYPE_40G_BASE_LM4:
case SFF_MODULE_TYPE_40G_BASE_ACTIVE:
case SFF_MODULE_TYPE_40G_BASE_SR2:
case SFF_MODULE_TYPE_40G_BASE_SM4:
case SFF_MODULE_TYPE_40G_BASE_ER4:
case SFF_MODULE_TYPE_25G_BASE_SR:
case SFF_MODULE_TYPE_10G_BASE_SR:
case SFF_MODULE_TYPE_10G_BASE_LR:
case SFF_MODULE_TYPE_10G_BASE_LRM:
@@ -280,6 +298,7 @@ sff_module_caps_get(sff_module_type_t mt, uint32_t *caps)
case SFF_MODULE_TYPE_100G_BASE_LR4:
case SFF_MODULE_TYPE_100G_BASE_CR4:
case SFF_MODULE_TYPE_100G_CWDM4:
case SFF_MODULE_TYPE_100G_PSM4:
*caps |= SFF_MODULE_CAPS_F_100G;
return 0;
@@ -291,10 +310,12 @@ sff_module_caps_get(sff_module_type_t mt, uint32_t *caps)
case SFF_MODULE_TYPE_40G_BASE_CR:
case SFF_MODULE_TYPE_40G_BASE_SR2:
case SFF_MODULE_TYPE_40G_BASE_SM4:
case SFF_MODULE_TYPE_40G_BASE_ER4:
*caps |= SFF_MODULE_CAPS_F_40G;
return 0;
case SFF_MODULE_TYPE_25G_BASE_CR:
case SFF_MODULE_TYPE_25G_BASE_SR:
*caps |= SFF_MODULE_CAPS_F_25G;
return 0;
@@ -670,6 +691,7 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt,
case SFF_MODULE_TYPE_100G_BASE_SR4:
case SFF_MODULE_TYPE_100G_BASE_LR4:
case SFF_MODULE_TYPE_100G_CWDM4:
case SFF_MODULE_TYPE_100G_PSM4:
info->sfp_type = SFF_SFP_TYPE_QSFP28;
info->media_type = SFF_MEDIA_TYPE_FIBER;
info->caps = SFF_MODULE_CAPS_F_100G;
@@ -687,6 +709,7 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt,
case SFF_MODULE_TYPE_40G_BASE_ACTIVE:
case SFF_MODULE_TYPE_40G_BASE_SR2:
case SFF_MODULE_TYPE_40G_BASE_SM4:
case SFF_MODULE_TYPE_40G_BASE_ER4:
case SFF_MODULE_TYPE_4X_MUX:
info->sfp_type = SFF_SFP_TYPE_QSFP_PLUS;
info->media_type = SFF_MEDIA_TYPE_FIBER;
@@ -701,11 +724,17 @@ sff_info_init(sff_info_t* info, sff_module_type_t mt,
break;
case SFF_MODULE_TYPE_25G_BASE_CR:
info->sfp_type = SFF_SFP_TYPE_SFP;
info->sfp_type = SFF_SFP_TYPE_SFP28;
info->media_type = SFF_MEDIA_TYPE_COPPER;
info->caps = SFF_MODULE_CAPS_F_25G;
break;
case SFF_MODULE_TYPE_25G_BASE_SR:
info->sfp_type = SFF_SFP_TYPE_SFP28;
info->media_type = SFF_MEDIA_TYPE_FIBER;
info->caps = SFF_MODULE_CAPS_F_25G;
break;
case SFF_MODULE_TYPE_10G_BASE_CR:
info->sfp_type = SFF_SFP_TYPE_SFP;
info->media_type = SFF_MEDIA_TYPE_COPPER;

View File

@@ -28,6 +28,9 @@
#define SFF_10G_BASE_SRL_PROPERTIES \
SFF_SFP_TYPE_SFP, "SFP", SFF_MODULE_TYPE_10G_BASE_SRL, "1GBASE-SRL", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_10G
#define SFF_25G_BASE_SR_PROPERTIES \
SFF_SFP_TYPE_SFP28, "SFP28", SFF_MODULE_TYPE_25G_BASE_SR, "25GBASE-SR", SFF_MEDIA_TYPE_FIBER, "Fiber",SFF_MODULE_CAPS_F_25G
#define SFF_40G_BASE_SR4_PROPERTIES \
SFF_SFP_TYPE_QSFP_PLUS, "QSFP+", SFF_MODULE_TYPE_40G_BASE_SR4, "40GBASE-SR4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_40G
@@ -61,6 +64,10 @@
#define SFF_100G_CWDM4_PROPERTIES \
SFF_SFP_TYPE_QSFP28, "QSFP28", SFF_MODULE_TYPE_100G_CWDM4, "100G-CWDM4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_100G
#define SFF_100G_PSM4_PROPERTIES \
SFF_SFP_TYPE_QSFP28, "QSFP28", SFF_MODULE_TYPE_100G_PSM4, "100G-PSM4", SFF_MEDIA_TYPE_FIBER, "Fiber", SFF_MODULE_CAPS_F_100G
static sff_db_entry_t sff_database__[] =
{
@@ -1413,6 +1420,64 @@ static sff_db_entry_t sff_database__[] =
},
},
},
{
{
.eeprom = {
0x03, 0x04, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0xff, 0x00, 0x00, 0x00,
0x02, 0x00, 0x0a, 0x07, 0x46, 0x49, 0x4e, 0x49, 0x53, 0x41, 0x52, 0x20, 0x43, 0x4f, 0x52, 0x50,
0x2e, 0x20, 0x20, 0x20, 0x02, 0x00, 0x90, 0x65, 0x46, 0x54, 0x4c, 0x46, 0x38, 0x35, 0x33, 0x36,
0x50, 0x34, 0x42, 0x43, 0x4c, 0x20, 0x20, 0x20, 0x41, 0x20, 0x20, 0x20, 0x03, 0x52, 0x00, 0xb8,
0x08, 0x1a, 0x70, 0x00, 0x55, 0x57, 0x42, 0x30, 0x34, 0x56, 0x59, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x31, 0x36, 0x31, 0x32, 0x32, 0x35, 0x20, 0x20, 0x68, 0xf0, 0x08, 0x84,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
},
.info = {
"FINISAR CORP. ",
"FTLF8536P4BCL ",
"UWB04VY ",
SFF_25G_BASE_SR_PROPERTIES,
-1,
}
}
},
{
{
.eeprom = {
0x11, 0x07, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0xb8, 0x00, 0x00, 0x85, 0x0b, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x45, 0x26, 0x44, 0xf0, 0x45, 0x63,
0x45, 0x3a, 0x1d, 0xee, 0x1d, 0x88, 0x23, 0x8a, 0x24, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x11, 0xcc, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xff, 0x00, 0x02, 0x00,
0x00, 0x00, 0x00, 0x40, 0x49, 0x4e, 0x4e, 0x4f, 0x4c, 0x49, 0x47, 0x48, 0x54, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x00, 0x44, 0x7c, 0x7f, 0x54, 0x52, 0x2d, 0x56, 0x43, 0x31, 0x33, 0x54,
0x2d, 0x4e, 0x30, 0x30, 0x20, 0x20, 0x20, 0x20, 0x30, 0x31, 0x66, 0x58, 0x07, 0xd0, 0x46, 0x33,
0x07, 0x07, 0xff, 0xda, 0x49, 0x4e, 0x47, 0x41, 0x54, 0x36, 0x36, 0x35, 0x30, 0x30, 0x37, 0x39,
0x20, 0x20, 0x20, 0x20, 0x31, 0x36, 0x30, 0x35, 0x31, 0x32, 0x31, 0x39, 0x0c, 0x00, 0x67, 0x57,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
},
.info = {
"INNOLIGHT ",
"TR-VC13T-N00 ",
"INGAT6650079 ",
SFF_100G_PSM4_PROPERTIES,
-1,
},
},
},
#endif /** SFF_CONFIG_INCLUDE_DATABASE */
};

View File

@@ -136,6 +136,7 @@ aim_map_si_t sff_module_type_map[] =
{ "100G_BASE_SR4", SFF_MODULE_TYPE_100G_BASE_SR4 },
{ "100G_BASE_LR4", SFF_MODULE_TYPE_100G_BASE_LR4 },
{ "100G_CWDM4", SFF_MODULE_TYPE_100G_CWDM4 },
{ "100G_PSM4", SFF_MODULE_TYPE_100G_PSM4 },
{ "40G_BASE_CR4", SFF_MODULE_TYPE_40G_BASE_CR4 },
{ "40G_BASE_SR4", SFF_MODULE_TYPE_40G_BASE_SR4 },
{ "40G_BASE_LR4", SFF_MODULE_TYPE_40G_BASE_LR4 },
@@ -144,7 +145,9 @@ aim_map_si_t sff_module_type_map[] =
{ "40G_BASE_CR", SFF_MODULE_TYPE_40G_BASE_CR },
{ "40G_BASE_SR2", SFF_MODULE_TYPE_40G_BASE_SR2 },
{ "40G_BASE_SM4", SFF_MODULE_TYPE_40G_BASE_SM4 },
{ "40G_BASE_ER4", SFF_MODULE_TYPE_40G_BASE_ER4 },
{ "25G_BASE_CR", SFF_MODULE_TYPE_25G_BASE_CR },
{ "25G_BASE_SR", SFF_MODULE_TYPE_25G_BASE_SR },
{ "10G_BASE_SR", SFF_MODULE_TYPE_10G_BASE_SR },
{ "10G_BASE_LR", SFF_MODULE_TYPE_10G_BASE_LR },
{ "10G_BASE_LRM", SFF_MODULE_TYPE_10G_BASE_LRM },
@@ -171,6 +174,7 @@ aim_map_si_t sff_module_type_desc_map[] =
{ "100GBASE-SR4", SFF_MODULE_TYPE_100G_BASE_SR4 },
{ "100GBASE-LR4", SFF_MODULE_TYPE_100G_BASE_LR4 },
{ "100G-CWDM4", SFF_MODULE_TYPE_100G_CWDM4 },
{ "100G-PSM4", SFF_MODULE_TYPE_100G_PSM4 },
{ "40GBASE-CR4", SFF_MODULE_TYPE_40G_BASE_CR4 },
{ "40GBASE-SR4", SFF_MODULE_TYPE_40G_BASE_SR4 },
{ "40GBASE-LR4", SFF_MODULE_TYPE_40G_BASE_LR4 },
@@ -179,7 +183,9 @@ aim_map_si_t sff_module_type_desc_map[] =
{ "40GBASE-CR", SFF_MODULE_TYPE_40G_BASE_CR },
{ "40GBASE-SR2", SFF_MODULE_TYPE_40G_BASE_SR2 },
{ "40GBASE-SM4", SFF_MODULE_TYPE_40G_BASE_SM4 },
{ "40GBASE-ER4", SFF_MODULE_TYPE_40G_BASE_ER4 },
{ "25GBASE-CR", SFF_MODULE_TYPE_25G_BASE_CR },
{ "25GBASE-SR", SFF_MODULE_TYPE_25G_BASE_SR },
{ "10GBASE-SR", SFF_MODULE_TYPE_10G_BASE_SR },
{ "10GBASE-LR", SFF_MODULE_TYPE_10G_BASE_LR },
{ "10GBASE-LRM", SFF_MODULE_TYPE_10G_BASE_LRM },
@@ -245,6 +251,7 @@ aim_map_si_t sff_sfp_type_map[] =
{ "QSFP", SFF_SFP_TYPE_QSFP },
{ "QSFP_PLUS", SFF_SFP_TYPE_QSFP_PLUS },
{ "QSFP28", SFF_SFP_TYPE_QSFP28 },
{ "SFP28", SFF_SFP_TYPE_SFP28 },
{ NULL, 0 }
};
@@ -254,6 +261,7 @@ aim_map_si_t sff_sfp_type_desc_map[] =
{ "QSFP", SFF_SFP_TYPE_QSFP },
{ "QSFP+", SFF_SFP_TYPE_QSFP_PLUS },
{ "QSFP28", SFF_SFP_TYPE_QSFP28 },
{ "SFP28", SFF_SFP_TYPE_SFP28 },
{ NULL, 0 }
};

View File

@@ -3,7 +3,7 @@
#
# Inclusive Makefile for the sff module.
#
# Autogenerated 2017-05-22 21:57:32.679978
# Autogenerated 2017-09-25 18:15:50.901582
#
###############################################################################
sff_BASEDIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

View File

@@ -6,28 +6,4 @@
# Assumes revision r0
#
############################################################
variables:
install: /lib/platform-config/${PLATFORM}-r0/onl
common:
version: 1.0.0
arch: $ARCH
copyright: Copyright 2013, 2014, 2015 Big Switch Networks
maintainer: support@bigswitch.com
support: opennetworklinux@googlegroups.com
packages:
- name: onlp-${PLATFORM}-r0
summary: ONLP Package for the ${PLATFORM}-r0 platform.
platform-config: True
files:
builds/lib/$BUILD_DIR/$TOOLCHAIN/bin/libonlp-${PLATFORM}.so : ${install}/lib/
builds/onlpdump/$BUILD_DIR/$TOOLCHAIN/bin/onlpdump : ${install}/bin/
changelog: Change changes changes.,
!include $ONL/packages/base/any/templates/onlp-platform-revision.yml REVISION=r0

View File

@@ -0,0 +1,28 @@
############################################################
#
# ONLP Platform Package Template
#
# Requires: PLATFORM, ARCH, REVISION
#
############################################################
variables:
install: /lib/platform-config/${PLATFORM}-${REVISION}/onl
common:
version: 1.0.0
arch: $ARCH
copyright: Copyright 2013, 2014, 2015 Big Switch Networks
maintainer: support@bigswitch.com
support: opennetworklinux@googlegroups.com
packages:
- name: onlp-${PLATFORM}-${REVISION}
summary: ONLP Package for the ${PLATFORM}-${REVISION} platform.
platform-config: True
files:
builds/lib/$BUILD_DIR/$TOOLCHAIN/bin/libonlp-${PLATFORM}.so : ${install}/lib/
builds/onlpdump/$BUILD_DIR/$TOOLCHAIN/bin/onlpdump : ${install}/bin/
changelog: Change changes changes.,

View File

@@ -0,0 +1,2 @@
*x86*64*accton*as5912*54xk*.mk
onlpdump.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/platform-modules.yml VENDOR=accton BASENAME=x86-64-accton-as5912-54xk ARCH=amd64 KERNELS="onl-kernel-3.16-lts-x86-64-all:amd64"

View File

@@ -0,0 +1,6 @@
KERNELS := onl-kernel-3.16-lts-x86-64-all:amd64
KMODULES := $(wildcard *.c)
VENDOR := accton
BASENAME := x86-64-accton-as5912-54xk
ARCH := x86_64
include $(ONL)/make/kmodule.mk

View File

@@ -0,0 +1,485 @@
/*
* A hwmon driver for the Accton as5912 54xk fan
*
* Copyright (C) 2016 Accton Technology Corporation.
* Brandon Chuang <brandon_chuang@accton.com.tw>
*
* 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 <linux/module.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/dmi.h>
#define DRVNAME "as5912_54xk_fan"
#define MAX_FAN_SPEED_RPM 25500
static struct as5912_54xk_fan_data *as5912_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);
/* 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 as5912_54xk_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 *as5912_54xk_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 as5912_54xk_fan_read_value(struct i2c_client *client, u8 reg)
{
return i2c_smbus_read_byte_data(client, reg);
}
static int as5912_54xk_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 as5912_54xk_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;
as5912_54xk_fan_write_value(client, 0x33, 0); /* Disable fan speed watch dog */
as5912_54xk_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 as5912_54xk_fan_data *data = as5912_54xk_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 as5912_54xk_fan_group = {
.attrs = as5912_54xk_fan_attributes,
};
static struct as5912_54xk_fan_data *as5912_54xk_fan_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct as5912_54xk_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 as5912_54xk_fan update\n");
data->valid = 0;
/* Update fan data
*/
for (i = 0; i < ARRAY_SIZE(data->reg_val); i++) {
int status = as5912_54xk_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 as5912_54xk_fan_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
struct as5912_54xk_fan_data *data;
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
status = -EIO;
goto exit;
}
data = kzalloc(sizeof(struct as5912_54xk_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, &as5912_54xk_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, &as5912_54xk_fan_group);
exit_free:
kfree(data);
exit:
return status;
}
static int as5912_54xk_fan_remove(struct i2c_client *client)
{
struct as5912_54xk_fan_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &as5912_54xk_fan_group);
return 0;
}
/* Addresses to scan */
static const unsigned short normal_i2c[] = { 0x66, I2C_CLIENT_END };
static const struct i2c_device_id as5912_54xk_fan_id[] = {
{ "as5912_54xk_fan", 0 },
{}
};
MODULE_DEVICE_TABLE(i2c, as5912_54xk_fan_id);
static struct i2c_driver as5912_54xk_fan_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = DRVNAME,
},
.probe = as5912_54xk_fan_probe,
.remove = as5912_54xk_fan_remove,
.id_table = as5912_54xk_fan_id,
.address_list = normal_i2c,
};
static int __init as5912_54xk_fan_init(void)
{
return i2c_add_driver(&as5912_54xk_fan_driver);
}
static void __exit as5912_54xk_fan_exit(void)
{
i2c_del_driver(&as5912_54xk_fan_driver);
}
module_init(as5912_54xk_fan_init);
module_exit(as5912_54xk_fan_exit);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as5912_54xk_fan driver");
MODULE_LICENSE("GPL");

View File

@@ -0,0 +1,386 @@
/*
* A LED driver for the accton_as5912_54xk_led
*
* Copyright (C) 2016 Accton Technology Corporation.
* Brandon Chuang <brandon_chuang@accton.com.tw>
*
* 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 <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/platform_device.h>
#include <linux/err.h>
#include <linux/leds.h>
#include <linux/slab.h>
#define DRVNAME "accton_as5912_54xk_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_as5912_54xk_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_as5912_54xk_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_as5912_54xk_led_read_value(u8 reg)
{
return accton_i2c_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);
}
static void accton_as5912_54xk_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_as5912_54xk_led update\n");
ledctl->valid = 0;
/* Update LED data
*/
for (i = 0; i < ARRAY_SIZE(ledctl->reg_val); i++) {
int status = accton_as5912_54xk_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_as5912_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_as5912_54xk_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_as5912_54xk_led_write_value(reg, reg_val);
ledctl->valid = 0;
exit:
mutex_unlock(&ledctl->update_lock);
}
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_54xk_led_auto_get(struct led_classdev *cdev)
{
return LED_MODE_AUTO;
}
static void accton_as5912_54xk_led_diag_set(struct led_classdev *led_cdev,
enum led_brightness led_light_mode)
{
accton_as5912_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_DIAG);
}
static enum led_brightness accton_as5912_54xk_led_diag_get(struct led_classdev *cdev)
{
accton_as5912_54xk_led_update();
return led_reg_val_to_light_mode(LED_TYPE_DIAG, ledctl->reg_val[0]);
}
static enum led_brightness accton_as5912_54xk_led_loc_get(struct led_classdev *cdev)
{
accton_as5912_54xk_led_update();
return led_reg_val_to_light_mode(LED_TYPE_LOC, ledctl->reg_val[0]);
}
static void accton_as5912_54xk_led_loc_set(struct led_classdev *led_cdev,
enum led_brightness led_light_mode)
{
accton_as5912_54xk_led_set(led_cdev, led_light_mode, led_reg[0], LED_TYPE_LOC);
}
static struct led_classdev accton_as5912_54xk_leds[] = {
[LED_TYPE_LOC] = {
.name = "accton_as5912_54xk_led::loc",
.default_trigger = "unused",
.brightness_set = accton_as5912_54xk_led_loc_set,
.brightness_get = accton_as5912_54xk_led_loc_get,
.max_brightness = LED_MODE_ORANGE,
},
[LED_TYPE_DIAG] = {
.name = "accton_as5912_54xk_led::diag",
.default_trigger = "unused",
.brightness_set = accton_as5912_54xk_led_diag_set,
.brightness_get = accton_as5912_54xk_led_diag_get,
.max_brightness = LED_MODE_GREEN,
},
[LED_TYPE_PSU1] = {
.name = "accton_as5912_54xk_led::psu1",
.default_trigger = "unused",
.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_as5912_54xk_led::psu2",
.default_trigger = "unused",
.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_as5912_54xk_led::fan",
.default_trigger = "unused",
.brightness_set = accton_as7312_54xk_led_auto_set,
.brightness_get = accton_as7312_54xk_led_auto_get,
.max_brightness = LED_MODE_AUTO,
},
};
static int accton_as5912_54xk_led_probe(struct platform_device *pdev)
{
int ret, i;
for (i = 0; i < ARRAY_SIZE(accton_as5912_54xk_leds); i++) {
ret = led_classdev_register(&pdev->dev, &accton_as5912_54xk_leds[i]);
if (ret < 0) {
break;
}
}
/* Check if all LEDs were successfully registered */
if (i != ARRAY_SIZE(accton_as5912_54xk_leds)){
int j;
/* only unregister the LEDs that were successfully registered */
for (j = 0; j < i; j++) {
led_classdev_unregister(&accton_as5912_54xk_leds[i]);
}
}
return ret;
}
static int accton_as5912_54xk_led_remove(struct platform_device *pdev)
{
int i;
for (i = 0; i < ARRAY_SIZE(accton_as5912_54xk_leds); i++) {
led_classdev_unregister(&accton_as5912_54xk_leds[i]);
}
return 0;
}
static struct platform_driver accton_as5912_54xk_led_driver = {
.probe = accton_as5912_54xk_led_probe,
.remove = accton_as5912_54xk_led_remove,
.driver = {
.name = DRVNAME,
.owner = THIS_MODULE,
},
};
static int __init accton_as5912_54xk_led_init(void)
{
int ret;
ret = platform_driver_register(&accton_as5912_54xk_led_driver);
if (ret < 0) {
goto exit;
}
ledctl = kzalloc(sizeof(struct accton_as5912_54xk_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_as5912_54xk_led_driver);
exit:
return ret;
}
static void __exit accton_as5912_54xk_led_exit(void)
{
platform_device_unregister(ledctl->pdev);
platform_driver_unregister(&accton_as5912_54xk_led_driver);
kfree(ledctl);
}
late_initcall(accton_as5912_54xk_led_init);
module_exit(accton_as5912_54xk_led_exit);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("accton_as5912_54xk_led driver");
MODULE_LICENSE("GPL");

View File

@@ -0,0 +1,288 @@
/*
* An hwmon driver for accton as5912_54xk Power Module
*
* Copyright (C) 2014 Accton Technology Corporation.
* Brandon Chuang <brandon_chuang@accton.com.tw>
*
* Based on ad7414.c
* Copyright 2006 Stefan Roese <sr at denx.de>, 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 <linux/module.h>
#include <linux/jiffies.h>
#include <linux/i2c.h>
#include <linux/hwmon.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/delay.h>
#include <linux/dmi.h>
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);
/* Addresses scanned
*/
static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
/* Each client has this additional data
*/
struct as5912_54xk_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 as5912_54xk_psu_data *as5912_54xk_psu_update_device(struct device *dev);
enum as5912_54xk_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 *as5912_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,
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 as5912_54xk_psu_data *data = as5912_54xk_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 as5912_54xk_psu_data *data = as5912_54xk_psu_update_device(dev);
return sprintf(buf, "%s\n", data->model_name);
}
static const struct attribute_group as5912_54xk_psu_group = {
.attrs = as5912_54xk_psu_attributes,
};
static int as5912_54xk_psu_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
struct as5912_54xk_psu_data *data;
int status;
if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
status = -EIO;
goto exit;
}
data = kzalloc(sizeof(struct as5912_54xk_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, &as5912_54xk_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, &as5912_54xk_psu_group);
exit_free:
kfree(data);
exit:
return status;
}
static int as5912_54xk_psu_remove(struct i2c_client *client)
{
struct as5912_54xk_psu_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&client->dev.kobj, &as5912_54xk_psu_group);
kfree(data);
return 0;
}
enum psu_index
{
as5912_54xk_psu1,
as5912_54xk_psu2
};
static const struct i2c_device_id as5912_54xk_psu_id[] = {
{ "as5912_54xk_psu1", as5912_54xk_psu1 },
{ "as5912_54xk_psu2", as5912_54xk_psu2 },
{}
};
MODULE_DEVICE_TABLE(i2c, as5912_54xk_psu_id);
static struct i2c_driver as5912_54xk_psu_driver = {
.class = I2C_CLASS_HWMON,
.driver = {
.name = "as5912_54xk_psu",
},
.probe = as5912_54xk_psu_probe,
.remove = as5912_54xk_psu_remove,
.id_table = as5912_54xk_psu_id,
.address_list = normal_i2c,
};
static int as5912_54xk_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 as5912_54xk_psu_data *as5912_54xk_psu_update_device(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
struct as5912_54xk_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 as5912_54xk 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 = as5912_54xk_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 as5912_54xk_psu_init(void)
{
return i2c_add_driver(&as5912_54xk_psu_driver);
}
static void __exit as5912_54xk_psu_exit(void)
{
i2c_del_driver(&as5912_54xk_psu_driver);
}
module_init(as5912_54xk_psu_init);
module_exit(as5912_54xk_psu_exit);
MODULE_AUTHOR("Brandon Chuang <brandon_chuang@accton.com.tw>");
MODULE_DESCRIPTION("as5912_54xk_psu driver");
MODULE_LICENSE("GPL");

View File

@@ -0,0 +1 @@
include $(ONL)/make/pkg.mk

View File

@@ -0,0 +1 @@
!include $ONL_TEMPLATES/onlp-platform-any.yml PLATFORM=x86-64-accton-as5912-54xk ARCH=amd64 TOOLCHAIN=x86_64-linux-gnu

View File

@@ -0,0 +1,2 @@
FILTER=src
include $(ONL)/make/subdirs.mk

View File

@@ -0,0 +1,45 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# 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.
#
# </bsn.cl>
############################################################
#
#
############################################################
include $(ONL)/make/config.amd64.mk
MODULE := libonlp-x86-64-accton-as5912-54xk
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF x86_64_accton_as5912_54xk onlplib
DEPENDMODULE_HEADERS := sff
include $(BUILDER)/dependmodules.mk
SHAREDLIB := libonlp-x86-64-accton-as5912-54xk.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

View File

@@ -0,0 +1,46 @@
############################################################
# <bsn.cl fy=2014 v=onl>
#
# 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.
#
# </bsn.cl>
############################################################
#
#
#
############################################################
include $(ONL)/make/config.amd64.mk
.DEFAULT_GOAL := onlpdump
MODULE := onlpdump
include $(BUILDER)/standardinit.mk
DEPENDMODULES := AIM IOF onlp x86_64_accton_as5912_54xk 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

View File

@@ -0,0 +1 @@
name: x86_64_accton_as5912_54xk

View File

@@ -0,0 +1,9 @@
###############################################################################
#
#
#
###############################################################################
include ../../init.mk
MODULE := x86_64_accton_as5912_54xk
AUTOMODULE := x86_64_accton_as5912_54xk
include $(BUILDER)/definemodule.mk

View File

@@ -0,0 +1,6 @@
###############################################################################
#
# x86_64_accton_as5912_54xk README
#
###############################################################################

View File

@@ -0,0 +1,9 @@
###############################################################################
#
# x86_64_accton_as5912_54xk Autogeneration
#
###############################################################################
x86_64_accton_as5912_54xk_AUTO_DEFS := module/auto/x86_64_accton_as5912_54xk.yml
x86_64_accton_as5912_54xk_AUTO_DIRS := module/inc/x86_64_accton_as5912_54xk module/src
include $(BUILDER)/auto.mk

View File

@@ -0,0 +1,50 @@
###############################################################################
#
# x86_64_accton_as5912_54xk Autogeneration Definitions.
#
###############################################################################
cdefs: &cdefs
- X86_64_ACCTON_AS5912_54XK_CONFIG_INCLUDE_LOGGING:
doc: "Include or exclude logging."
default: 1
- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_OPTIONS_DEFAULT:
doc: "Default enabled log options."
default: AIM_LOG_OPTIONS_DEFAULT
- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_BITS_DEFAULT:
doc: "Default enabled log bits."
default: AIM_LOG_BITS_DEFAULT
- X86_64_ACCTON_AS5912_54XK_CONFIG_LOG_CUSTOM_BITS_DEFAULT:
doc: "Default enabled custom log bits."
default: 0
- X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_STDLIB:
doc: "Default all porting macros to use the C standard libraries."
default: 1
- X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_INCLUDE_STDLIB_HEADERS:
doc: "Include standard library headers for stdlib porting macros."
default: X86_64_ACCTON_AS5912_54XK_CONFIG_PORTING_STDLIB
- X86_64_ACCTON_AS5912_54XK_CONFIG_INCLUDE_UCLI:
doc: "Include generic uCli support."
default: 0
- X86_64_ACCTON_AS5912_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_AS5912_54XK_CONFIG_HEADER:
defs: *cdefs
basename: x86_64_accton_as5912_54xk_config
portingmacro:
x86_64_accton_as5912_54xk:
macros:
- malloc
- free
- memset
- memcpy
- strncpy
- vsnprintf
- snprintf
- strlen

View File

@@ -0,0 +1,14 @@
/**************************************************************************//**
*
*
*
*****************************************************************************/
#include <x86_64_accton_as5912_54xk/x86_64_accton_as5912_54xk_config.h>
/* <--auto.start.xmacro(ALL).define> */
/* <auto.end.xmacro(ALL).define> */
/* <--auto.start.xenum(ALL).define> */
/* <auto.end.xenum(ALL).define> */

Some files were not shown because too many files have changed in this diff Show More