Skip to content

Commit 8fe4fab

Browse files
authored
The slot and switch_rootsysfs driver framework module complies with s3ip sysfs specification (#12893)
Why I did it Provide slot and switch_rootsysfs driver framework that complies with s3ip sysfs specification How I did it 1、 The framework module provides register and unregister interface and implementation. 2、 The framework will help you create the sysfs node How to verify it A demo driver base on this framework will display the sysfs node wich conform to the s3ip sysfs specification
1 parent 8f124dc commit 8fe4fab

File tree

5 files changed

+2506
-0
lines changed

5 files changed

+2506
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#ifndef _SLOT_SYSFS_H_
2+
#define _SLOT_SYSFS_H_
3+
4+
struct s3ip_sysfs_slot_drivers_s {
5+
int (*get_slot_number)(void);
6+
int (*get_slot_temp_number)(unsigned int slot_index);
7+
int (*get_slot_vol_number)(unsigned int slot_index);
8+
int (*get_slot_curr_number)(unsigned int slot_index);
9+
int (*get_slot_cpld_number)(unsigned int slot_index);
10+
int (*get_slot_fpga_number)(unsigned int slot_index);
11+
ssize_t (*get_slot_model_name)(unsigned int slot_index, char *buf, size_t count);
12+
ssize_t (*get_slot_serial_number)(unsigned int slot_index, char *buf, size_t count);
13+
ssize_t (*get_slot_part_number)(unsigned int slot_index, char *buf, size_t count);
14+
ssize_t (*get_slot_hardware_version)(unsigned int slot_index, char *buf, size_t count);
15+
ssize_t (*get_slot_status)(unsigned int slot_index, char *buf, size_t count);
16+
ssize_t (*get_slot_led_status)(unsigned int slot_index, char *buf, size_t count);
17+
int (*set_slot_led_status)(unsigned int slot_index, int status);
18+
ssize_t (*get_slot_temp_alias)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
19+
ssize_t (*get_slot_temp_type)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
20+
ssize_t (*get_slot_temp_max)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
21+
int (*set_slot_temp_max)(unsigned int slot_index, unsigned int temp_index, const char *buf, size_t count);
22+
ssize_t (*get_slot_temp_min)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
23+
int (*set_slot_temp_min)(unsigned int slot_index, unsigned int temp_index, const char *buf, size_t count);
24+
ssize_t (*get_slot_temp_value)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
25+
ssize_t (*get_slot_vol_alias)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
26+
ssize_t (*get_slot_vol_type)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
27+
ssize_t (*get_slot_vol_max)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
28+
int (*set_slot_vol_max)(unsigned int slot_index, unsigned int vol_index, const char *buf, size_t count);
29+
ssize_t (*get_slot_vol_min)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
30+
int (*set_slot_vol_min)(unsigned int slot_index, unsigned int vol_index, const char *buf, size_t count);
31+
ssize_t (*get_slot_vol_range)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
32+
ssize_t (*get_slot_vol_nominal_value)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
33+
ssize_t (*get_slot_vol_value)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
34+
ssize_t (*get_slot_curr_alias)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
35+
ssize_t (*get_slot_curr_type)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
36+
ssize_t (*get_slot_curr_max)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
37+
int (*set_slot_curr_max)(unsigned int slot_index, unsigned int curr_index, const char *buf, size_t count);
38+
ssize_t (*get_slot_curr_min)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
39+
int (*set_slot_curr_min)(unsigned int slot_index, unsigned int curr_index, const char *buf, size_t count);
40+
ssize_t (*get_slot_curr_value)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
41+
ssize_t (*get_slot_fpga_alias)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
42+
ssize_t (*get_slot_fpga_type)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
43+
ssize_t (*get_slot_fpga_firmware_version)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
44+
ssize_t (*get_slot_fpga_board_version)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
45+
ssize_t (*get_slot_fpga_test_reg)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
46+
int (*set_slot_fpga_test_reg)(unsigned int slot_index, unsigned int fpga_index, unsigned int value);
47+
ssize_t (*get_slot_cpld_alias)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
48+
ssize_t (*get_slot_cpld_type)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
49+
ssize_t (*get_slot_cpld_firmware_version)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
50+
ssize_t (*get_slot_cpld_board_version)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
51+
ssize_t (*get_slot_cpld_test_reg)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
52+
int (*set_slot_cpld_test_reg)(unsigned int slot_index, unsigned int cpld_index, unsigned int value);
53+
};
54+
55+
extern int s3ip_sysfs_slot_drivers_register(struct s3ip_sysfs_slot_drivers_s *drv);
56+
extern void s3ip_sysfs_slot_drivers_unregister(void);
57+
#endif /*_SLOT_SYSFS_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef _SWITCH_H_
2+
#define _SWITCH_H_
3+
4+
#include <linux/module.h>
5+
#include <linux/kernel.h>
6+
#include <linux/sysfs.h>
7+
#include <linux/slab.h>
8+
#include <linux/device.h>
9+
#include <linux/workqueue.h>
10+
#include <linux/kobject.h>
11+
#include <linux/delay.h>
12+
13+
#define DIR_NAME_MAX_LEN (64)
14+
#define SYSFS_DEV_ERROR "NA"
15+
16+
enum LOG_LEVEL{
17+
INFO = 0x1,
18+
ERR = 0x2,
19+
DBG = 0x4,
20+
ALL = 0xf
21+
};
22+
23+
extern int g_switch_loglevel;
24+
25+
#define check_pfun(p) do { \
26+
if (p == NULL) { \
27+
if (g_switch_loglevel & ERR) { \
28+
printk( KERN_ERR "%s, %s is NULL.\n", __FUNCTION__, #p); \
29+
} \
30+
return -ENOSYS; \
31+
} \
32+
} while(0)
33+
34+
#define check_p(p) check_pfun(p)
35+
36+
#define to_switch_obj(x) container_of(x, struct switch_obj, kobj)
37+
#define to_switch_attr(x) container_of(x, struct switch_attribute, attr)
38+
#define to_switch_device_attr(x) container_of(x, struct switch_device_attribute, switch_attr)
39+
40+
#define SWITCH_ATTR(_name, _mode, _show, _store, _type) \
41+
{ .switch_attr = __ATTR(_name, _mode, _show, _store), \
42+
.type = _type }
43+
44+
#define SWITCH_DEVICE_ATTR(_name, _mode, _show, _store, _type) \
45+
struct switch_device_attribute switch_dev_attr_##_name \
46+
= SWITCH_ATTR(_name, _mode, _show, _store, _type)
47+
48+
struct switch_obj {
49+
struct kobject kobj;
50+
unsigned int index;
51+
};
52+
53+
/* a custom attribute that works just for a struct switch_obj. */
54+
struct switch_attribute {
55+
struct attribute attr;
56+
ssize_t (*show)(struct switch_obj *foo, struct switch_attribute *attr, char *buf);
57+
ssize_t (*store)(struct switch_obj *foo, struct switch_attribute *attr, const char *buf, size_t count);
58+
};
59+
60+
struct switch_device_attribute {
61+
struct switch_attribute switch_attr;
62+
int type;
63+
};
64+
65+
struct switch_obj *switch_kobject_create(const char *name, struct kobject *parent);
66+
void switch_kobject_delete(struct switch_obj **obj);
67+
68+
#endif /* _SWITCH_H_ */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef _SYSEEPROM_SYSFS_H_
2+
#define _SYSEEPROM_SYSFS_H_
3+
4+
struct s3ip_sysfs_syseeprom_drivers_s {
5+
int (*get_syseeprom_size)(void);
6+
ssize_t (*read_syseeprom_data)(char *buf, loff_t offset, size_t count);
7+
ssize_t (*write_syseeprom_data)(char *buf, loff_t offset, size_t count);
8+
};
9+
10+
extern int s3ip_sysfs_syseeprom_drivers_register(struct s3ip_sysfs_syseeprom_drivers_s *drv);
11+
extern void s3ip_sysfs_syseeprom_drivers_unregister(void);
12+
#endif /*_SYSEEPROM_SYSFS_H_ */

0 commit comments

Comments
 (0)