Skip to content

Commit

Permalink
The slot and switch_rootsysfs driver framework module complies with s…
Browse files Browse the repository at this point in the history
…3ip sysfs specification (#12893) (#13216)
  • Loading branch information
mssonicbld authored Jan 1, 2023
1 parent 5489913 commit fe5732a
Show file tree
Hide file tree
Showing 5 changed files with 2,506 additions and 0 deletions.
57 changes: 57 additions & 0 deletions platform/s3ip-sysfs/s3ip_sysfs_frame/include/slot_sysfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#ifndef _SLOT_SYSFS_H_
#define _SLOT_SYSFS_H_

struct s3ip_sysfs_slot_drivers_s {
int (*get_slot_number)(void);
int (*get_slot_temp_number)(unsigned int slot_index);
int (*get_slot_vol_number)(unsigned int slot_index);
int (*get_slot_curr_number)(unsigned int slot_index);
int (*get_slot_cpld_number)(unsigned int slot_index);
int (*get_slot_fpga_number)(unsigned int slot_index);
ssize_t (*get_slot_model_name)(unsigned int slot_index, char *buf, size_t count);
ssize_t (*get_slot_serial_number)(unsigned int slot_index, char *buf, size_t count);
ssize_t (*get_slot_part_number)(unsigned int slot_index, char *buf, size_t count);
ssize_t (*get_slot_hardware_version)(unsigned int slot_index, char *buf, size_t count);
ssize_t (*get_slot_status)(unsigned int slot_index, char *buf, size_t count);
ssize_t (*get_slot_led_status)(unsigned int slot_index, char *buf, size_t count);
int (*set_slot_led_status)(unsigned int slot_index, int status);
ssize_t (*get_slot_temp_alias)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
ssize_t (*get_slot_temp_type)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
ssize_t (*get_slot_temp_max)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
int (*set_slot_temp_max)(unsigned int slot_index, unsigned int temp_index, const char *buf, size_t count);
ssize_t (*get_slot_temp_min)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
int (*set_slot_temp_min)(unsigned int slot_index, unsigned int temp_index, const char *buf, size_t count);
ssize_t (*get_slot_temp_value)(unsigned int slot_index, unsigned int temp_index, char *buf, size_t count);
ssize_t (*get_slot_vol_alias)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
ssize_t (*get_slot_vol_type)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
ssize_t (*get_slot_vol_max)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
int (*set_slot_vol_max)(unsigned int slot_index, unsigned int vol_index, const char *buf, size_t count);
ssize_t (*get_slot_vol_min)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
int (*set_slot_vol_min)(unsigned int slot_index, unsigned int vol_index, const char *buf, size_t count);
ssize_t (*get_slot_vol_range)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
ssize_t (*get_slot_vol_nominal_value)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
ssize_t (*get_slot_vol_value)(unsigned int slot_index, unsigned int vol_index, char *buf, size_t count);
ssize_t (*get_slot_curr_alias)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
ssize_t (*get_slot_curr_type)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
ssize_t (*get_slot_curr_max)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
int (*set_slot_curr_max)(unsigned int slot_index, unsigned int curr_index, const char *buf, size_t count);
ssize_t (*get_slot_curr_min)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
int (*set_slot_curr_min)(unsigned int slot_index, unsigned int curr_index, const char *buf, size_t count);
ssize_t (*get_slot_curr_value)(unsigned int slot_index, unsigned int curr_index, char *buf, size_t count);
ssize_t (*get_slot_fpga_alias)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
ssize_t (*get_slot_fpga_type)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
ssize_t (*get_slot_fpga_firmware_version)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
ssize_t (*get_slot_fpga_board_version)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
ssize_t (*get_slot_fpga_test_reg)(unsigned int slot_index, unsigned int fpga_index, char *buf, size_t count);
int (*set_slot_fpga_test_reg)(unsigned int slot_index, unsigned int fpga_index, unsigned int value);
ssize_t (*get_slot_cpld_alias)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
ssize_t (*get_slot_cpld_type)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
ssize_t (*get_slot_cpld_firmware_version)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
ssize_t (*get_slot_cpld_board_version)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
ssize_t (*get_slot_cpld_test_reg)(unsigned int slot_index, unsigned int cpld_index, char *buf, size_t count);
int (*set_slot_cpld_test_reg)(unsigned int slot_index, unsigned int cpld_index, unsigned int value);
};

extern int s3ip_sysfs_slot_drivers_register(struct s3ip_sysfs_slot_drivers_s *drv);
extern void s3ip_sysfs_slot_drivers_unregister(void);
#endif /*_SLOT_SYSFS_H_ */
68 changes: 68 additions & 0 deletions platform/s3ip-sysfs/s3ip_sysfs_frame/include/switch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#ifndef _SWITCH_H_
#define _SWITCH_H_

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/sysfs.h>
#include <linux/slab.h>
#include <linux/device.h>
#include <linux/workqueue.h>
#include <linux/kobject.h>
#include <linux/delay.h>

#define DIR_NAME_MAX_LEN (64)
#define SYSFS_DEV_ERROR "NA"

enum LOG_LEVEL{
INFO = 0x1,
ERR = 0x2,
DBG = 0x4,
ALL = 0xf
};

extern int g_switch_loglevel;

#define check_pfun(p) do { \
if (p == NULL) { \
if (g_switch_loglevel & ERR) { \
printk( KERN_ERR "%s, %s is NULL.\n", __FUNCTION__, #p); \
} \
return -ENOSYS; \
} \
} while(0)

#define check_p(p) check_pfun(p)

#define to_switch_obj(x) container_of(x, struct switch_obj, kobj)
#define to_switch_attr(x) container_of(x, struct switch_attribute, attr)
#define to_switch_device_attr(x) container_of(x, struct switch_device_attribute, switch_attr)

#define SWITCH_ATTR(_name, _mode, _show, _store, _type) \
{ .switch_attr = __ATTR(_name, _mode, _show, _store), \
.type = _type }

#define SWITCH_DEVICE_ATTR(_name, _mode, _show, _store, _type) \
struct switch_device_attribute switch_dev_attr_##_name \
= SWITCH_ATTR(_name, _mode, _show, _store, _type)

struct switch_obj {
struct kobject kobj;
unsigned int index;
};

/* a custom attribute that works just for a struct switch_obj. */
struct switch_attribute {
struct attribute attr;
ssize_t (*show)(struct switch_obj *foo, struct switch_attribute *attr, char *buf);
ssize_t (*store)(struct switch_obj *foo, struct switch_attribute *attr, const char *buf, size_t count);
};

struct switch_device_attribute {
struct switch_attribute switch_attr;
int type;
};

struct switch_obj *switch_kobject_create(const char *name, struct kobject *parent);
void switch_kobject_delete(struct switch_obj **obj);

#endif /* _SWITCH_H_ */
12 changes: 12 additions & 0 deletions platform/s3ip-sysfs/s3ip_sysfs_frame/include/syseeprom_sysfs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#ifndef _SYSEEPROM_SYSFS_H_
#define _SYSEEPROM_SYSFS_H_

struct s3ip_sysfs_syseeprom_drivers_s {
int (*get_syseeprom_size)(void);
ssize_t (*read_syseeprom_data)(char *buf, loff_t offset, size_t count);
ssize_t (*write_syseeprom_data)(char *buf, loff_t offset, size_t count);
};

extern int s3ip_sysfs_syseeprom_drivers_register(struct s3ip_sysfs_syseeprom_drivers_s *drv);
extern void s3ip_sysfs_syseeprom_drivers_unregister(void);
#endif /*_SYSEEPROM_SYSFS_H_ */
Loading

0 comments on commit fe5732a

Please sign in to comment.