1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * fs/hmdfs/comm/device_node.h
4 *
5 * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
6 */
7
8 #ifndef HMDFS_DEVICE_NODE_H
9 #define HMDFS_DEVICE_NODE_H
10
11 #include "hmdfs.h"
12 #include "transport.h"
13
14 enum CTRL_NODE_CMD {
15 CMD_UPDATE_SOCKET = 0,
16 CMD_UPDATE_DEVSL,
17 CMD_OFF_LINE,
18 CMD_OFF_LINE_ALL,
19 CMD_CNT,
20 };
21
22 struct update_socket_param {
23 int32_t cmd;
24 int32_t newfd;
25 uint32_t devsl;
26 uint8_t status;
27 uint8_t masterkey[HMDFS_KEY_SIZE];
28 uint8_t cid[HMDFS_CID_SIZE];
29 } __packed;
30
31 struct update_devsl_param {
32 int32_t cmd;
33 uint32_t devsl;
34 uint8_t cid[HMDFS_CID_SIZE];
35 } __attribute__((packed));
36
37 struct offline_param {
38 int32_t cmd;
39 uint8_t remote_cid[HMDFS_CID_SIZE];
40 } __packed;
41
42 struct offline_all_param {
43 int32_t cmd;
44 } __packed;
45
46 enum NOTIFY {
47 NOTIFY_GET_SESSION,
48 NOTIFY_OFFLINE,
49 NOTIFY_NONE,
50 NOTIFY_CNT,
51 };
52
53 struct notify_param {
54 int32_t notify;
55 int32_t fd;
56 uint8_t remote_cid[HMDFS_CID_SIZE];
57 } __packed;
58
59 struct sbi_attribute {
60 struct attribute attr;
61 ssize_t (*show)(struct kobject *kobj, struct sbi_attribute *attr,
62 char *buf);
63 ssize_t (*store)(struct kobject *kobj, struct sbi_attribute *attr,
64 const char *buf, size_t len);
65 };
66
67 struct peer_attribute {
68 struct attribute attr;
69 ssize_t (*show)(struct kobject *kobj, struct peer_attribute *attr,
70 char *buf);
71 ssize_t (*store)(struct kobject *kobj, struct peer_attribute *attr,
72 const char *buf, size_t len);
73 };
74
75 struct sbi_cmd_attribute {
76 struct attribute attr;
77 int command;
78 };
79
80 void notify(struct hmdfs_peer *node, struct notify_param *param);
81 int hmdfs_register_sysfs(const char *name, struct hmdfs_sb_info *sbi);
82 void hmdfs_unregister_sysfs(struct hmdfs_sb_info *sbi);
83 void hmdfs_release_sysfs(struct hmdfs_sb_info *sbi);
84 int hmdfs_register_peer_sysfs(struct hmdfs_sb_info *sbi,
85 struct hmdfs_peer *peer);
86 void hmdfs_release_peer_sysfs(struct hmdfs_peer *peer);
87 int hmdfs_sysfs_init(void);
88 void hmdfs_sysfs_exit(void);
89
to_sbi_attr(struct attribute * x)90 static inline struct sbi_attribute *to_sbi_attr(struct attribute *x)
91 {
92 return container_of(x, struct sbi_attribute, attr);
93 }
94
to_sbi(struct kobject * x)95 static inline struct hmdfs_sb_info *to_sbi(struct kobject *x)
96 {
97 return container_of(x, struct hmdfs_sb_info, kobj);
98 }
99
to_peer_attr(struct attribute * x)100 static inline struct peer_attribute *to_peer_attr(struct attribute *x)
101 {
102 return container_of(x, struct peer_attribute, attr);
103 }
104
to_peer(struct kobject * x)105 static inline struct hmdfs_peer *to_peer(struct kobject *x)
106 {
107 return container_of(x, struct hmdfs_peer, kobj);
108 }
109 #endif
110