Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

s3ip sysfs framework and demo #12384

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions platform/s3ip-sysfs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
PWD = $(shell pwd)
SYSFS_OUT_PUT := $(PWD)/build
sysfs_out_put_dir := $(SYSFS_OUT_PUT)/S3IP_sysfs/
export sysfs_out_put_dir
KERNEL_SRC=/lib/modules/$(shell uname -r)
export KERNEL_SRC

SYSFS_DRIVER_DIR = $(PWD)/s3ip_sysfs_frame
SWITCH_DRIVER_DIR = $(PWD)/demo_driver

KBUILD_EXTRA_SYMBOLS += $(SYSFS_DRIVER_DIR)/Module.symvers
KBUILD_EXTRA_SYMBOLS += $(SWITCH_DRIVER_DIR)/Module.symvers
export KBUILD_EXTRA_SYMBOLS

all :
$(MAKE) -C $(SYSFS_DRIVER_DIR)
$(MAKE) -C $(SWITCH_DRIVER_DIR)

clean :
-rm -rf $(SYSFS_OUT_PUT)
$(MAKE) -C $(SYSFS_DRIVER_DIR) clean
$(MAKE) -C $(SWITCH_DRIVER_DIR) clean



install:
install -d $(DESTDIR)/lib/modules/s3ip/
install -D $(sysfs_out_put_dir)/*.ko \
$(DESTDIR)/lib/modules/s3ip/
install -D scripts/s3ip_load.py \
$(DESTDIR)/$(prefix)/bin/s3ip_load.py
install -D scripts/s3ip_sysfs_conf.json \
$(DESTDIR)/etc/s3ip/s3ip_sysfs_conf.json
install -D scripts/s3ip_sysfs_tool.sh \
$(DESTDIR)/$(prefix)/bin/s3ip_sysfs_tool.sh
install -D scripts/s3ip-sysfs.service \
$(DESTDIR)/etc/systemd/system/s3ip-sysfs.service


uninstall:
-rm -f $(DESTDIR)$(prefix)/bin/s3ip_load.py
-rm -f $(DESTDIR)/lib/modules/s3ip/
-rm -f $(DESTDIR)/etc/s3ip
-rm -f $(DESTDIR)/$(prefix)/bin/s3ip_sysfs_tool.sh
-rm -f $(DESTDIR)/etc/systemd/system/s3ip-sysfs.service

3 changes: 3 additions & 0 deletions platform/s3ip-sysfs/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#! /bin/bash

dpkg-buildpackage -rfakeroot -b -us -uc
8 changes: 8 additions & 0 deletions platform/s3ip-sysfs/debian/README.Debian
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
s3ip-sysfs for Debian

Please edit this to provide information specific to
this libkbc Debian package.

(Automatically generated by debmake Version 4.2.9)

-- ubuntu <ubuntu@localhost> Mon, 07 Sep 2020 20:06:06 +0800
6 changes: 6 additions & 0 deletions platform/s3ip-sysfs/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
s3ip-sysfs (1.0.0) unstable; urgency=medium

* Initial release.

-- shangfei tian <timsftian@tencent.com> Wed, 09 Sep 2021 12:00:00 -0800

1 change: 1 addition & 0 deletions platform/s3ip-sysfs/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
14 changes: 14 additions & 0 deletions platform/s3ip-sysfs/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Source: s3ip-sysfs
Maintainer: timsftian <timsftian@tencent.com>
Section: libs
Priority: optional
Build-Depends: dh-exec (>=0.3),debhelper (>= 8.0.0), autotools-dev
Standards-Version: 3.9.3
Homepage: https://tencent.com

Package: s3ip-sysfs
Architecture: any
Section: libdevel
Depends: ${misc:Depends}
Description: This package contains development files for s3ip sysfs

13 changes: 13 additions & 0 deletions platform/s3ip-sysfs/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: s3ip-sysfs
Source: <url://example.com>
#
# Please double check copyright with the licensecheck(1) command.

Files: Makefile
Copyright: __NO_COPYRIGHT_NOR_LICENSE__
License: __NO_COPYRIGHT_NOR_LICENSE__

#----------------------------------------------------------------------------
# Files marked as NO_LICENSE_TEXT_FOUND may be covered by the following
# license/copyright files.
2 changes: 2 additions & 0 deletions platform/s3ip-sysfs/debian/files
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s3ip-sysfs_1.0.0_amd64.buildinfo libs optional
s3ip-sysfs_1.0.0_amd64.deb libdevel optional
17 changes: 17 additions & 0 deletions platform/s3ip-sysfs/debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/make -f
# You must remove unused comment lines for the released package.
#export DH_VERBOSE = 1

#export DEB_BUILD_MAINT_OPTIONS = hardening=+all
#export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
dh $@

override_dh_auto_install:
dh_auto_install -- prefix=/usr

override_dh_shlibdeps:

override_dh_installmodules:
3 changes: 3 additions & 0 deletions platform/s3ip-sysfs/debian/s3ip-sysfs.postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
systemctl daemon-reload
systemctl start s3ip-sysfs
systemctl enable s3ip-sysfs
2 changes: 2 additions & 0 deletions platform/s3ip-sysfs/debian/s3ip-sysfs.prerm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
systemctl stop s3ip-sysfs
systemctl disable s3ip-sysfs
2 changes: 2 additions & 0 deletions platform/s3ip-sysfs/debian/s3ip-sysfs.substvars
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
misc:Depends=
misc:Pre-Depends=
2 changes: 2 additions & 0 deletions platform/s3ip-sysfs/debian/watch
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# You must remove unused comment lines for the released package.
#version=3
33 changes: 33 additions & 0 deletions platform/s3ip-sysfs/demo_driver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
PWD = $(shell pwd)

MAKEFILE_FILE_PATH = $(abspath $(lastword $(MAKEFILE_LIST)))
DEV_SYSFS_HEADER_DIR = $(abspath $(MAKEFILE_FILE_PATH)/../../s3ip_sysfs_frame/include)
SWITCH_DVR_HEADER_DIR = $(abspath $(MAKEFILE_FILE_PATH)/../../s3ip_sysfs_frame/include)
EXTRA_CFLAGS:= -I$(M)/include
EXTRA_CFLAGS+= -I$(DEV_SYSFS_HEADER_DIR)
EXTRA_CFLAGS+= -I$(SWITCH_DVR_HEADER_DIR)
EXTRA_CFLAGS+= -Wall

obj-m := syseeprom_device_driver.o
obj-m += fan_device_driver.o
obj-m += cpld_device_driver.o
obj-m += sysled_device_driver.o
obj-m += slot_device_driver.o
obj-m += psu_device_driver.o
obj-m += transceiver_device_driver.o
obj-m += temp_sensor_device_driver.o
obj-m += vol_sensor_device_driver.o
obj-m += curr_sensor_device_driver.o
obj-m += fpga_device_driver.o
obj-m += watchdog_device_driver.o


all:
$(MAKE) -C $(KERNEL_SRC)/build M=$(PWD) modules
@if [ ! -d $(sysfs_out_put_dir) ]; then mkdir -p $(sysfs_out_put_dir) ;fi
cp -p $(PWD)/*.ko $(sysfs_out_put_dir)
clean:
rm -f $(PWD)/*.o $(PWD)/*.ko $(PWD)/*.mod.c $(PWD)/.*.cmd
rm -f $(PWD)/Module.markers $(PWD)/Module.symvers $(PWD)/modules.order
rm -rf $(PWD)/.tmp_versions
rm -rf $(PWD)/.cache.mk
168 changes: 168 additions & 0 deletions platform/s3ip-sysfs/demo_driver/cpld_device_driver.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
/*
* cpld_device_driver.c
*
* This module realize /sys/s3ip/cpld attributes read and write functions
*
* History
* [Version] [Date] [Description]
* * v1.0 2021-08-31 S3IP sysfs
*/

#include <linux/slab.h>

#include "device_driver_common.h"
#include "cpld_sysfs.h"

#define CPLD_INFO(fmt, args...) LOG_INFO("cpld: ", fmt, ##args)
#define CPLD_ERR(fmt, args...) LOG_ERR("cpld: ", fmt, ##args)
#define CPLD_DBG(fmt, args...) LOG_DBG("cpld: ", fmt, ##args)

static int g_loglevel = 0;

/******************************************CPLD***********************************************/
static int demo_get_main_board_cpld_number(void)
{
/* add vendor codes here */
return 1;
}

/*
* demo_get_main_board_cpld_alias - Used to identify the location of cpld,
* @cpld_index: start with 1
* @buf: Data receiving buffer
* @count: length of buf
*
* This function returns the length of the filled buffer,
* if not support this attributes filled "NA" to buf,
* otherwise it returns a negative value on failed.
*/
static ssize_t demo_get_main_board_cpld_alias(unsigned int cpld_index, char *buf, size_t count)
{
/* add vendor codes here */
return -ENOSYS;
}

/*
* demo_get_main_board_cpld_type - Used to get cpld model name
* @cpld_index: start with 1
* @buf: Data receiving buffer
* @count: length of buf
*
* This function returns the length of the filled buffer,
* if not support this attributes filled "NA" to buf,
* otherwise it returns a negative value on failed.
*/
static ssize_t demo_get_main_board_cpld_type(unsigned int cpld_index, char *buf, size_t count)
{
/* add vendor codes here */
return -ENOSYS;
}

/*
* demo_get_main_board_cpld_firmware_version - Used to get cpld firmware version,
* @cpld_index: start with 1
* @buf: Data receiving buffer
* @count: length of buf
*
* This function returns the length of the filled buffer,
* if not support this attributes filled "NA" to buf,
* otherwise it returns a negative value on failed.
*/
static ssize_t demo_get_main_board_cpld_firmware_version(unsigned int cpld_index, char *buf, size_t count)
{
/* add vendor codes here */
return -ENOSYS;
}

/*
* demo_get_main_board_cpld_board_version - Used to get cpld board version,
* @cpld_index: start with 1
* @buf: Data receiving buffer
* @count: length of buf
*
* This function returns the length of the filled buffer,
* if not support this attributes filled "NA" to buf,
* otherwise it returns a negative value on failed.
*/
static ssize_t demo_get_main_board_cpld_board_version(unsigned int cpld_index, char *buf, size_t count)
{
/* add vendor codes here */
return -ENOSYS;
}

/*
* demo_get_main_board_cpld_test_reg - Used to test cpld register read
* filled the value to buf, value is hexadecimal, start with 0x
* @cpld_index: start with 1
* @buf: Data receiving buffer
* @count: length of buf
*
* This function returns the length of the filled buffer,
* if not support this attributes filled "NA" to buf,
* otherwise it returns a negative value on failed.
*/
static ssize_t demo_get_main_board_cpld_test_reg(unsigned int cpld_index, char *buf, size_t count)
{
/* add vendor codes here */
return -ENOSYS;
}

/*
* demo_set_main_board_cpld_test_reg - Used to test cpld register write
* @cpld_index: start with 1
* @value: value write to cpld
*
* This function returns 0 on success,
* otherwise it returns a negative value on failed.
*/
static int demo_set_main_board_cpld_test_reg(unsigned int cpld_index, unsigned int value)
{
/* add vendor codes here */
return -ENOSYS;
}
/***************************************end of CPLD*******************************************/

static struct s3ip_sysfs_cpld_drivers_s drivers = {
/*
* set ODM CPLD drivers to /sys/s3ip/cpld,
* if not support the function, set corresponding hook to NULL.
*/
.get_main_board_cpld_number = demo_get_main_board_cpld_number,
.get_main_board_cpld_alias = demo_get_main_board_cpld_alias,
.get_main_board_cpld_type = demo_get_main_board_cpld_type,
.get_main_board_cpld_firmware_version = demo_get_main_board_cpld_firmware_version,
.get_main_board_cpld_board_version = demo_get_main_board_cpld_board_version,
.get_main_board_cpld_test_reg = demo_get_main_board_cpld_test_reg,
.set_main_board_cpld_test_reg = demo_set_main_board_cpld_test_reg,
};

static int __init cpld_device_driver_init(void)
{
int ret;

CPLD_INFO("cpld_init...\n");

ret = s3ip_sysfs_cpld_drivers_register(&drivers);
if (ret < 0) {
CPLD_ERR("cpld drivers register err, ret %d.\n", ret);
return ret;
}

CPLD_INFO("cpld_init success.\n");
return 0;
}

static void __exit cpld_device_driver_exit(void)
{
s3ip_sysfs_cpld_drivers_unregister();
CPLD_INFO("cpld_exit success.\n");
return;
}

module_init(cpld_device_driver_init);
module_exit(cpld_device_driver_exit);
module_param(g_loglevel, int, 0644);
MODULE_PARM_DESC(g_loglevel, "the log level(info=0x1, err=0x2, dbg=0x4, all=0xf).\n");
MODULE_LICENSE("GPL");
MODULE_AUTHOR("sonic S3IP sysfs");
MODULE_DESCRIPTION("cpld device driver");
Loading