summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStar Chang <starchang@google.com>2022-11-01 10:43:50 +0000
committerStar Chang <starchang@google.com>2022-11-04 01:48:59 +0000
commit7cffa0f2c8dc09e110f88fa2634e100a3719f763 (patch)
tree9539c91fb25c0a764c450175d6d39d4556865047
parenta8878c34c747769c7a069910d26d94de4efac03c (diff)
downloadwlan_ptracker-7cffa0f2c8dc09e110f88fa2634e100a3719f763.tar.gz
Bug: 253348062 Test: ST-stability/WiFi regression/WiFi performance Test pass Signed-off-by: Star Chang <starchang@google.com> Change-Id: Idbbdd9a1eaa8bf1207278b8dc0a198d8ae70efbb
-rw-r--r--core.h3
-rw-r--r--debugfs.c59
-rw-r--r--debugfs.h15
-rw-r--r--dynamic_twt_manager.c217
-rw-r--r--dynamic_twt_manager.h7
-rw-r--r--main.c64
-rw-r--r--notifier.c8
-rw-r--r--scenes_fsm.c1
-rw-r--r--tp_monitor.c20
9 files changed, 225 insertions, 169 deletions
diff --git a/core.h b/core.h
index 7cd8cea..8c43e98 100644
--- a/core.h
+++ b/core.h
@@ -29,7 +29,8 @@ struct wlan_ptracker_core {
struct wlan_ptracker_debugfs debugfs;
struct wlan_ptracker_fsm fsm;
struct net_device *dev;
- struct wlan_ptracker_client __rcu *client;
+ struct dytwt_manager *dytwt;
+ struct wlan_ptracker_client *client;
u8 dscp_to_ac[DSCP_MAX];
};
#endif /* _WLAN_PTRACKER_CORE_H */
diff --git a/debugfs.c b/debugfs.c
index 6fe6d99..6c52393 100644
--- a/debugfs.c
+++ b/debugfs.c
@@ -75,7 +75,7 @@ static ssize_t action_write(struct file *file,
ptracker_err(core, "action %d is not supported!\n", action);
return -ENOTSUPP;
}
- return 0;
+ return len;
}
static const struct file_operations dscp_ops = {
@@ -85,18 +85,56 @@ static const struct file_operations dscp_ops = {
.llseek = generic_file_llseek,
};
+static ssize_t ptracker_sysfs_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+ struct wlan_ptracker_debugfs *debugfs = container_of(kobj, struct wlan_ptracker_debugfs,
+ kobj);
+ struct ptracker_kobj_attr *ptracker_attr = container_of(attr, struct ptracker_kobj_attr,
+ attr);
+ int ret = -EIO;
+
+ if (ptracker_attr->show)
+ ret = ptracker_attr->show(debugfs, buf);
+ return ret;
+}
+
+static ssize_t ptracker_sysfs_store(struct kobject *kobj, struct attribute *attr, const char *buf,
+ size_t count)
+{
+ struct wlan_ptracker_debugfs *debugfs =
+ container_of(kobj, struct wlan_ptracker_debugfs, kobj);
+ struct ptracker_kobj_attr *ptracker_attr =
+ container_of(attr, struct ptracker_kobj_attr, attr);
+ int ret = -EIO;
+
+ if (ptracker_attr->store)
+ ret = ptracker_attr->store(debugfs, buf, count);
+ return ret;
+}
+
+static struct sysfs_ops ptracker_sysfs_ops = {
+ .show = ptracker_sysfs_show,
+ .store = ptracker_sysfs_store,
+};
+
+static struct kobj_type ptracker_ktype = {
+ .sysfs_ops = &ptracker_sysfs_ops,
+};
+
static int wlan_ptracker_sysfs_init(struct wlan_ptracker_debugfs *debugfs)
{
- debugfs->kobj = kobject_create_and_add("wlan_ptracker", NULL);
- if (!debugfs->kobj)
- return -ENODEV;
- return 0;
+ int ret;
+
+ ret = kobject_init_and_add(&debugfs->kobj, &ptracker_ktype, NULL, PTRACKER_PREFIX);
+ if (ret)
+ kobject_put(&debugfs->kobj);
+ return ret;
}
static void wlan_ptracker_sysfs_exit(struct wlan_ptracker_debugfs *debugfs)
{
- if (debugfs->kobj)
- kobject_put(debugfs->kobj);
+ kobject_del(&debugfs->kobj);
+ kobject_put(&debugfs->kobj);
}
int wlan_ptracker_debugfs_init(struct wlan_ptracker_debugfs *debugfs)
@@ -104,7 +142,7 @@ int wlan_ptracker_debugfs_init(struct wlan_ptracker_debugfs *debugfs)
struct wlan_ptracker_core *core = container_of(
debugfs, struct wlan_ptracker_core, debugfs);
- debugfs->root = debugfs_create_dir("wlan_ptracker", NULL);
+ debugfs->root = debugfs_create_dir(PTRACKER_PREFIX, NULL);
if (!debugfs->root)
return -ENODEV;
debugfs_create_file("action", 0600, debugfs->root, core, &dscp_ops);
@@ -177,7 +215,8 @@ static int history_get_tm(struct history_entry *entry, char *time, size_t len)
return scnprintf(time, len, "%ptRs", &tm);
}
-size_t wlan_ptracker_history_read(struct history_manager *hm, char *buf, int buf_len)
+size_t wlan_ptracker_history_read(struct wlan_ptracker_core *core, struct history_manager *hm,
+ char *buf, int buf_len)
{
u8 *ptr;
struct history_entry *cur, *next;
@@ -201,7 +240,7 @@ size_t wlan_ptracker_history_read(struct history_manager *hm, char *buf, int buf
len += history_get_tm(cur, buf + len, buf_len - len);
len += scnprintf(buf + len, buf_len - len, "%12s =>", state2str[cur->state]);
if (hm->priv_read)
- len += hm->priv_read(cur, next, buf + len, buf_len - len);
+ len += hm->priv_read(core, cur, next, buf + len, buf_len - len);
len += scnprintf(buf + len, buf_len - len, "\n");
ptr += hm->entry_size;
}
diff --git a/debugfs.h b/debugfs.h
index 2d4bfd4..7b2e282 100644
--- a/debugfs.h
+++ b/debugfs.h
@@ -14,15 +14,23 @@
#include <linux/sysfs.h>
#include <linux/kobject.h>
+struct wlan_ptracker_core;
+
struct wlan_ptracker_debugfs {
struct dentry *root;
- struct kobject *kobj;
+ struct kobject kobj;
u32 dscp;
u32 ac;
u32 action;
u32 log_level;
};
+struct ptracker_kobj_attr {
+ struct attribute attr;
+ ssize_t (*show)(struct wlan_ptracker_debugfs *, char *);
+ ssize_t (*store)(struct wlan_ptracker_debugfs *, const char *, size_t count);
+};
+
enum {
FEATURE_FLAG_TWT,
FEATURE_FLAG_MAX
@@ -52,7 +60,7 @@ struct history_manager {
int entry_count;
int entry_size;
struct mutex mutex;
- int (*priv_read)(void *cur, void *next, char *buf, int len);
+ int (*priv_read)(struct wlan_ptracker_core *core, void *cur, void *next, char *buf, int len);
u8 entries[0];
};
@@ -61,6 +69,7 @@ extern void wlan_ptracker_debugfs_exit(struct wlan_ptracker_debugfs *debugfs);
extern struct history_manager *wlan_ptracker_history_create(int entry_count, int entry_size);
extern void wlan_ptracker_history_destroy(struct history_manager *hm);
extern void *wlan_ptracker_history_store(struct history_manager *hm, u32 state);
-extern size_t wlan_ptracker_history_read(struct history_manager *hm, char *buf, int len);
+extern size_t wlan_ptracker_history_read(struct wlan_ptracker_core *core,
+ struct history_manager *hm, char *buf, int len);
#endif /* _WLAN_PTRACKER_DEBUGFS_H */
diff --git a/dynamic_twt_manager.c b/dynamic_twt_manager.c
index 2cf7aa3..1701a57 100644
--- a/dynamic_twt_manager.c
+++ b/dynamic_twt_manager.c
@@ -11,10 +11,6 @@
#include <linux/delay.h>
#include "core.h"
-static struct dytwt_manager dytwt_mgmt;
-
-#define dytwt_get_manager() (&dytwt_mgmt)
-
#define DYMAIC_TWT_CONFIG_ID 3
/* for tcp one pair case */
@@ -134,7 +130,8 @@ static int dytwt_client_twt_teardown(struct wlan_ptracker_client *client, u32 st
static bool dytwt_client_twt_cap(struct wlan_ptracker_client *client)
{
struct dytwt_cap param;
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct wlan_ptracker_core *core = client->core;
+ struct dytwt_manager *dytwt = core->dytwt;
int ret;
if (!client->dytwt_ops || !client->priv)
@@ -145,13 +142,13 @@ static bool dytwt_client_twt_cap(struct wlan_ptracker_client *client)
ret = client->dytwt_ops->get_cap(client->priv, &param);
- ptracker_dbg(dytwt->core, "%d, %d, %d, %d\n", param.device_cap, param.peer_cap,
+ ptracker_dbg(core, "%d, %d, %d, %d\n", param.device_cap, param.peer_cap,
param.link_speed, param.rssi);
if (ret)
return false;
if (!param.peer_cap || !param.device_cap) {
- ptracker_err(dytwt->core, "dytwt is not enabled due to capability: %d, %d\n",
+ ptracker_err(core, "dytwt is not enabled due to capability: %d, %d\n",
param.device_cap, param.peer_cap);
return false;
}
@@ -215,11 +212,11 @@ static inline void dytwt_record_get_pwr(u64 asleep, u64 awake, u64 *total, int *
*total /= 10;
}
-static int dytwt_record_priv_read(void *cur, void *next, char *buf, int len)
+static int dytwt_record_priv_read(struct wlan_ptracker_core *core, void *cur, void *next,
+ char *buf, int len)
{
struct dytwt_entry *c = cur;
struct dytwt_entry *n = next;
- struct dytwt_manager *dytwt = dytwt_get_manager();
int period_percent, total_percent;
u64 period_time, total_time;
u64 awake, asleep;
@@ -227,7 +224,7 @@ static int dytwt_record_priv_read(void *cur, void *next, char *buf, int len)
/* next is the current state */
if (n->pwr.asleep < c->pwr.asleep) {
struct dytwt_pwr_state pwr;
- dytwt_client_twt_pwrstates(dytwt->core->client, &pwr);
+ dytwt_client_twt_pwrstates(core->client, &pwr);
awake = pwr.awake - c->pwr.awake;
asleep = pwr.asleep - c->pwr.asleep;
/* get total */
@@ -317,29 +314,24 @@ out:
static void dytwt_delay_setup(struct work_struct *work)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct dytwt_manager *dytwt = container_of(work, struct dytwt_manager, setup_wq.work);
struct wlan_ptracker_core *core = dytwt->core;
struct wlan_ptracker_client *client;
if (!core)
return;
- rcu_read_lock();
- client = rcu_dereference(core->client);
- if (!client)
- goto end;
+ client = core->client;
/* for first time update value is required*/
dytwt->twt_cap = dytwt_client_twt_cap(client);
_dytwt_scene_change_handler(dytwt, client);
-end:
- rcu_read_unlock();
}
#define TWT_WAIT_STA_READY_TIME 2000
static int dytwt_scene_change_handler(struct wlan_ptracker_client *client)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
struct wlan_ptracker_core *core = client->core;
+ struct dytwt_manager *dytwt = core->dytwt;
struct wlan_scene_event *msg = &core->fsm.msg;
if (msg->reason == WLAN_PTRACKER_NOTIFY_STA_CONNECT)
@@ -352,7 +344,8 @@ static int dytwt_scene_change_handler(struct wlan_ptracker_client *client)
#define TWT_HISTORY_BUF_SIZE 10240
static ssize_t twt_read(struct file *file, char __user *userbuf, size_t count, loff_t *ppos)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct wlan_ptracker_core *core = file->private_data;
+ struct dytwt_manager *dytwt = core->dytwt;
char *buf;
int len;
ssize_t ret;
@@ -362,7 +355,7 @@ static ssize_t twt_read(struct file *file, char __user *userbuf, size_t count, l
if (!buf)
return -ENOMEM;
- len = wlan_ptracker_history_read(dytwt->hm, buf, TWT_HISTORY_BUF_SIZE);
+ len = wlan_ptracker_history_read(core, dytwt->hm, buf, TWT_HISTORY_BUF_SIZE);
ret = simple_read_from_buffer(userbuf, count, ppos, buf, len);
vfree(buf);
return ret;
@@ -401,7 +394,8 @@ static void dytwt_force_twt_setup(struct wlan_ptracker_client *client, struct dy
static inline void twt_enable(struct wlan_ptracker_client *client, bool enable, u32 reason)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct wlan_ptracker_core *core = client->core;
+ struct dytwt_manager *dytwt = core->dytwt;
if (enable) {
dytwt->feature_flag |= BIT(FEATURE_FLAG_TWT);
@@ -416,7 +410,7 @@ static inline void twt_enable(struct wlan_ptracker_client *client, bool enable,
#define DYTWT_RUNTIME_TIMER 2000
static void dytwt_runtime(struct work_struct *work)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct dytwt_manager *dytwt = container_of(work, struct dytwt_manager, wq.work);
struct dytwt_scene_action *act;
struct wlan_ptracker_client *client;
@@ -426,12 +420,7 @@ static void dytwt_runtime(struct work_struct *work)
if (dytwt->prev == WLAN_SCENE_MAX)
goto end;
- rcu_read_lock();
- client = rcu_dereference(dytwt->core->client);
-
- if (!client)
- goto unlock;
-
+ client = dytwt->core->client;
act = &dytwt_actions[dytwt->prev];
/* update twt_cap periodically */
dytwt->twt_cap = dytwt_client_twt_cap(client);
@@ -440,8 +429,6 @@ static void dytwt_runtime(struct work_struct *work)
ptracker_dbg(dytwt->core, "teardown twt due to hit threshold\n");
dytwt_force_twt_setup(client, dytwt, TWT_SETUP_REASON_RUNTIME);
}
-unlock:
- rcu_read_unlock();
end:
schedule_delayed_work(&dytwt->wq, msecs_to_jiffies(DYTWT_RUNTIME_TIMER));
}
@@ -505,14 +492,8 @@ static void dytwt_status_dump(struct wlan_ptracker_client *client, struct dytwt_
static int dytwt_debugfs_action(struct wlan_ptracker_core *core, u32 action)
{
struct dytwt_pwr_state pwr_state;
- struct dytwt_manager *dytwt = dytwt_get_manager();
- struct wlan_ptracker_client *client;
-
- rcu_read_lock();
- client = rcu_dereference(core->client);
-
- if (!client)
- goto unlock;
+ struct dytwt_manager *dytwt = core->dytwt;
+ struct wlan_ptracker_client *client = core->client;
switch (action) {
case TWT_TEST_FORCE_STATE:
@@ -537,11 +518,9 @@ static int dytwt_debugfs_action(struct wlan_ptracker_core *core, u32 action)
dytwt_status_dump(client, dytwt);
break;
default:
- ptracker_err(core, "action %d is not supported!\n", action);
+ ptracker_err(core, "action %d is not supported\n", action);
return -ENOTSUPP;
}
-unlock:
- rcu_read_unlock();
return 0;
}
@@ -554,7 +533,8 @@ static ssize_t twt_params_write(struct file *file, const char __user *buf, size_
if (kstrtouint_from_user(buf, len, 10, &action))
return -EFAULT;
- return dytwt_debugfs_action(core, action);
+ dytwt_debugfs_action(core, action);
+ return len;
}
static int dytwt_params_read(char *buf, int len)
@@ -607,9 +587,9 @@ static const struct file_operations twt_params_ops = {
.llseek = generic_file_llseek,
};
-static int dytwt_statistic_read(char *buf, int len)
+static int dytwt_statistic_read(struct wlan_ptracker_core *core, char *buf, int len)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct dytwt_manager *dytwt = core->dytwt;
struct dytwt_counters *counter = &dytwt->counters;
struct dytwt_statistic *ds;
struct dytwt_pwr_state pwr;
@@ -648,6 +628,7 @@ static int dytwt_statistic_read(char *buf, int len)
static ssize_t twt_statistic_read(struct file *file, char __user *userbuf, size_t count,
loff_t *ppos)
{
+ struct wlan_ptracker_core *core = file->private_data;
char *buf;
int len;
int ret;
@@ -656,7 +637,7 @@ static ssize_t twt_statistic_read(struct file *file, char __user *userbuf, size_
if (!buf)
return -ENOMEM;
- len = dytwt_statistic_read(buf, TWT_STATISTIC_SIZE);
+ len = dytwt_statistic_read(core, buf, TWT_STATISTIC_SIZE);
ret = simple_read_from_buffer(userbuf, count, ppos, buf, len);
vfree(buf);
return ret;
@@ -670,7 +651,8 @@ static const struct file_operations twt_statistic_ops = {
static void dytwt_scene_change_prepare_handler(struct wlan_ptracker_client *client)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct wlan_ptracker_core *core = client->core;
+ struct dytwt_manager *dytwt = core->dytwt;
u32 prev_state = dytwt->prev;
if (!(dytwt->feature_flag & BIT(FEATURE_FLAG_TWT)))
@@ -687,13 +669,8 @@ static void dytwt_scene_change_prepare_handler(struct wlan_ptracker_client *clie
static int dytwt_notifier_handler(struct notifier_block *nb, unsigned long event, void *ptr)
{
struct wlan_ptracker_core *core = ptr;
- struct wlan_ptracker_client *client;
- struct dytwt_manager *dytwt = dytwt_get_manager();
-
- rcu_read_lock();
- client = rcu_dereference(core->client);
- if (!client)
- goto unlock;
+ struct wlan_ptracker_client *client = core->client;
+ struct dytwt_manager *dytwt = core->dytwt;
switch (event) {
case WLAN_PTRACKER_NOTIFY_SCENE_CHANGE:
@@ -717,29 +694,24 @@ static int dytwt_notifier_handler(struct notifier_block *nb, unsigned long event
default:
break;
}
-unlock:
- rcu_read_unlock();
return NOTIFY_OK;
}
-static ssize_t dytwt_dumpstate_statistic(struct kobject *kobj, struct kobj_attribute *attr,
- char *buf)
+static ssize_t dytwt_dumpstate_statistic(struct dytwt_manager *dytwt, char *buf)
{
- return dytwt_statistic_read(buf, PAGE_SIZE);
+ return dytwt_statistic_read(dytwt->core, buf, PAGE_SIZE);
}
-static ssize_t dytwt_dumpstate_history(struct kobject *kobj, struct kobj_attribute *attr,
- char *buf)
+static ssize_t dytwt_dumpstate_history(struct dytwt_manager *dytwt, char *buf)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
- return wlan_ptracker_history_read(dytwt->hm, buf, PAGE_SIZE);
+ return wlan_ptracker_history_read(dytwt->core, dytwt->hm, buf, PAGE_SIZE);
}
-static struct kobj_attribute attr_twt_history =
- __ATTR(twt_history, 0664, dytwt_dumpstate_history, NULL);
+static struct dytwt_kobj_attr attr_twt_history =
+ __ATTR(history, 0664, dytwt_dumpstate_history, NULL);
-static struct kobj_attribute attr_twt_statistic =
- __ATTR(twt_statistic, 0664, dytwt_dumpstate_statistic, NULL);
+static struct dytwt_kobj_attr attr_twt_statistic =
+ __ATTR(statistic, 0664, dytwt_dumpstate_statistic, NULL);
static struct attribute *default_file_attrs[] = {
&attr_twt_history.attr,
@@ -747,14 +719,66 @@ static struct attribute *default_file_attrs[] = {
NULL,
};
-static const struct attribute_group attr_group = {
- .attrs = default_file_attrs,
+static ssize_t dytwt_sysfs_show(struct kobject *kobj, struct attribute *attr, char *buf)
+{
+ struct dytwt_manager *dytwt;
+ struct dytwt_kobj_attr *dytwt_attr;
+ int ret = -EIO;
+
+ dytwt = container_of(kobj, struct dytwt_manager, kobj);
+ dytwt_attr = container_of(attr, struct dytwt_kobj_attr, attr);
+
+ if (dytwt_attr->show)
+ ret = dytwt_attr->show(dytwt, buf);
+ return ret;
+}
+
+static ssize_t dytwt_sysfs_store(struct kobject *kobj, struct attribute *attr, const char *buf,
+ size_t count)
+{
+ struct dytwt_manager *dytwt;
+ struct dytwt_kobj_attr *dytwt_attr;
+ int ret = -EIO;
+
+ dytwt = container_of(kobj, struct dytwt_manager, kobj);
+ dytwt_attr = container_of(attr, struct dytwt_kobj_attr, attr);
+
+ if (dytwt_attr->show)
+ ret = dytwt_attr->store(dytwt, buf, count);
+ return ret;
+
+}
+
+static struct sysfs_ops dytwt_sysfs_ops = {
+ .show = dytwt_sysfs_show,
+ .store = dytwt_sysfs_store,
+};
+
+static struct kobj_type dytwt_ktype = {
+ .sysfs_ops = &dytwt_sysfs_ops,
+ .default_attrs = default_file_attrs,
};
+static int dytwt_sysfs_init(struct dytwt_manager *dytwt, struct wlan_ptracker_debugfs *debugfs)
+{
+ int ret;
+
+ ret = kobject_init_and_add(&dytwt->kobj, &dytwt_ktype, &debugfs->kobj, "twt");
+ if (ret)
+ kobject_put(&dytwt->kobj);
+ return ret;
+}
+
+static void dytwt_sysfs_exit(struct dytwt_manager *dytwt)
+{
+ kobject_del(&dytwt->kobj);
+ kobject_put(&dytwt->kobj);
+}
+
static int dytwt_debugfs_init(struct wlan_ptracker_core *core)
{
struct wlan_ptracker_debugfs *debugfs = &core->debugfs;
- struct dytwt_manager *dytwt = dytwt_get_manager();
+ struct dytwt_manager *dytwt = core->dytwt;
struct dytwt_scene_action *act = &dytwt_actions[WLAN_SCENE_MAX];
dytwt->feature_flag |= BIT(FEATURE_FLAG_TWT);
@@ -770,25 +794,28 @@ static int dytwt_debugfs_init(struct wlan_ptracker_core *core)
debugfs_create_u32("wake_duration", 0666, dytwt->dir, &act->param.wake_duration);
debugfs_create_u32("action", 0666, dytwt->dir, &act->action);
debugfs_create_u32("feature_flag", 0666, dytwt->dir, &dytwt->feature_flag);
- if (debugfs->kobj)
- sysfs_create_group(debugfs->kobj, &attr_group);
+ dytwt_sysfs_init(dytwt, debugfs);
return 0;
}
+static void dytwt_debugfs_exit(struct dytwt_manager *dytwt)
+{
+ if (dytwt->dir)
+ debugfs_remove_recursive(dytwt->dir);
+ dytwt_sysfs_exit(dytwt);
+}
+
#define TWT_DEFAULT_MIN_LINK_SPEED (180000)
#define TWT_DEFAULT_MIN_RSSI (-70)
#define DYTWT_RECORD_MAX 30
-static int dytwt_mgmt_init(struct wlan_ptracker_core *core)
+static struct dytwt_manager *dytwt_mgmt_init(struct wlan_ptracker_core *core)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
- struct wlan_ptracker_debugfs *debugfs = &core->debugfs;
struct history_manager *hm;
+ struct dytwt_manager *dytwt = kzalloc(sizeof(struct dytwt_manager), GFP_KERNEL);
+
+ if (!dytwt)
+ return NULL;
- if (debugfs->kobj)
- sysfs_remove_group(debugfs->kobj, &attr_group);
- if (dytwt->dir)
- debugfs_remove_recursive(dytwt->dir);
- memset(dytwt, 0, sizeof(*dytwt));
dytwt->state = WLAN_SCENE_IDLE;
dytwt->prev = WLAN_SCENE_MAX;
dytwt->core = core;
@@ -797,25 +824,23 @@ static int dytwt_mgmt_init(struct wlan_ptracker_core *core)
INIT_DELAYED_WORK(&dytwt->wq, dytwt_runtime);
INIT_DELAYED_WORK(&dytwt->setup_wq, dytwt_delay_setup);
hm = wlan_ptracker_history_create(DYTWT_RECORD_MAX, sizeof(struct dytwt_entry));
- if (!hm)
- return -ENOMEM;
+ if (!hm) {
+ kfree(dytwt);
+ return NULL;
+ }
strncpy(hm->name, "Dynamic TWT Setup", sizeof(hm->name));
hm->priv_read = dytwt_record_priv_read;
dytwt->hm = hm;
- return 0;
+
+ return dytwt;
}
-static void dytwt_mgmt_exit(void)
+static void dytwt_mgmt_exit(struct dytwt_manager *dytwt)
{
- struct dytwt_manager *dytwt = dytwt_get_manager();
-
cancel_delayed_work_sync(&dytwt->wq);
cancel_delayed_work_sync(&dytwt->setup_wq);
- if (dytwt->dir)
- debugfs_remove_recursive(dytwt->dir);
-
wlan_ptracker_history_destroy(dytwt->hm);
- memset(dytwt, 0, sizeof(*dytwt));
+ kfree(dytwt);
}
static struct notifier_block twt_nb = {
@@ -825,13 +850,21 @@ static struct notifier_block twt_nb = {
int dytwt_init(struct wlan_ptracker_core *core)
{
- dytwt_mgmt_init(core);
+ core->dytwt = dytwt_mgmt_init(core);
dytwt_debugfs_init(core);
return wlan_ptracker_register_notifier(&core->notifier, &twt_nb);
}
void dytwt_exit(struct wlan_ptracker_core *core)
{
- dytwt_mgmt_exit();
- return wlan_ptracker_unregister_notifier(&core->notifier, &twt_nb);
+ struct dytwt_manager *dytwt = core->dytwt;
+
+ core->dytwt = NULL;
+ wlan_ptracker_unregister_notifier(&core->notifier, &twt_nb);
+
+ if (!dytwt)
+ return;
+
+ dytwt_debugfs_exit(dytwt);
+ dytwt_mgmt_exit(dytwt);
}
diff --git a/dynamic_twt_manager.h b/dynamic_twt_manager.h
index 43cdf21..495329b 100644
--- a/dynamic_twt_manager.h
+++ b/dynamic_twt_manager.h
@@ -134,9 +134,16 @@ struct dytwt_manager {
struct delayed_work setup_wq;
struct wlan_ptracker_core *core;
struct dytwt_counters counters;
+ struct kobject kobj;
struct dentry *dir;
};
+struct dytwt_kobj_attr {
+ struct attribute attr;
+ ssize_t (*show)(struct dytwt_manager *, char *);
+ ssize_t (*store)(struct dytwt_manager *, const char *, size_t count);
+};
+
extern int dytwt_init(struct wlan_ptracker_core *core);
extern void dytwt_exit(struct wlan_ptracker_core *core);
#endif /* __TP_TRACKER_DYNAMIC_TWT_SETUP_H */
diff --git a/main.c b/main.c
index dc3eeed..f0d3ad5 100644
--- a/main.c
+++ b/main.c
@@ -13,14 +13,7 @@
#include <net/net_namespace.h>
#include "core.h"
-
-static struct wlan_ptracker_core ptracker_core;
-
-#define get_core() (&ptracker_core)
-
-#define client_to_core(client) \
- ((struct wlan_ptracker_core *)((client)->core))
-
+#define client_to_core(client) ((struct wlan_ptracker_core *)((client)->core))
/* Default mapping rule follow 802.11e */
static const int dscp_trans[WMM_AC_MAX][DSCP_MAP_MAX] = {
@@ -45,9 +38,15 @@ static void dscp_to_ac_init(u8 *dscp_to_ac)
}
}
-static int wlan_ptracker_core_init(struct wlan_ptracker_core *core)
+static struct wlan_ptracker_core *wlan_ptracker_core_init(struct wlan_ptracker_client *client)
{
- memset(core, 0, sizeof(*core));
+ struct wlan_ptracker_core *core;
+
+ core = kzalloc(sizeof(struct wlan_ptracker_core), GFP_KERNEL);
+ if (!core)
+ return NULL;
+
+ core->client = client;
device_initialize(&core->device);
dev_set_name(&core->device, PTRACKER_PREFIX);
device_add(&core->device);
@@ -56,7 +55,7 @@ static int wlan_ptracker_core_init(struct wlan_ptracker_core *core)
wlan_ptracker_notifier_init(&core->notifier);
scenes_fsm_init(&core->fsm);
dytwt_init(core);
- return 0;
+ return core;
}
static void wlan_ptracker_core_exit(struct wlan_ptracker_core *core)
@@ -66,7 +65,7 @@ static void wlan_ptracker_core_exit(struct wlan_ptracker_core *core)
wlan_ptracker_notifier_exit(&core->notifier);
wlan_ptracker_debugfs_exit(&core->debugfs);
device_del(&core->device);
- memset(core, 0, sizeof(struct wlan_ptracker_core));
+ kfree(core);
}
static int client_event_handler(void *priv, u32 event)
@@ -79,52 +78,35 @@ static int client_event_handler(void *priv, u32 event)
int wlan_ptracker_register_client(struct wlan_ptracker_client *client)
{
- struct wlan_ptracker_core *core = get_core();
-
- if (!core->client) {
- rcu_read_lock();
- rcu_assign_pointer(core->client, client);
- rcu_read_unlock();
- client->cb = client_event_handler;
- }
+ client->core = wlan_ptracker_core_init(client);
+ if (!client->core)
+ return -ENOMEM;
+ client->cb = client_event_handler;
return 0;
}
EXPORT_SYMBOL_GPL(wlan_ptracker_register_client);
void wlan_ptracker_unregister_client(struct wlan_ptracker_client *client)
{
- struct wlan_ptracker_core *core = get_core();
+ struct wlan_ptracker_core *core = client_to_core(client);
- if (core->client == client) {
- client->cb = NULL;
- rcu_read_lock();
- rcu_assign_pointer(core->client, NULL);
- rcu_read_unlock();
- }
+ if (!core)
+ return;
+ client->cb = NULL;
+ client->core = NULL;
+ wlan_ptracker_core_exit(core);
}
EXPORT_SYMBOL_GPL(wlan_ptracker_unregister_client);
static int __init wlan_ptracker_init(void)
{
- struct wlan_ptracker_core *core = get_core();
- int ret;
-
- ret = wlan_ptracker_core_init(core);
- if (ret)
- goto err;
- dev_dbg(&core->device, "module init\n");
+ pr_debug("module init: %s\n", PTRACKER_PREFIX);
return 0;
-err:
- wlan_ptracker_core_exit(core);
- return ret;
}
static void __exit wlan_ptracker_exit(void)
{
- struct wlan_ptracker_core *core = get_core();
-
- dev_dbg(&core->device, "module exit\n");
- wlan_ptracker_core_exit(core);
+ pr_debug("module exit: %s\n", PTRACKER_PREFIX);
}
module_init(wlan_ptracker_init);
diff --git a/notifier.c b/notifier.c
index 01dd768..fb950b8 100644
--- a/notifier.c
+++ b/notifier.c
@@ -8,16 +8,13 @@
*/
#include "core.h"
-#define notifier_to_core(notifier) \
- container_of(notifier, struct wlan_ptracker_core, notifier)
+#define notifier_to_core(notifier) container_of(notifier, struct wlan_ptracker_core, notifier)
-#define nb_to_notifier(nb) \
- (container_of(nb, struct wlan_ptracker_notifier, nb))
+#define nb_to_notifier(nb) container_of(nb, struct wlan_ptracker_notifier, nb)
static int up_event_handler(struct wlan_ptracker_core *core, struct net_device *dev)
{
core->dev = dev;
- core->client->core = core;
dev_hold(dev);
core->client->priv = dev;
return tp_monitor_init(&core->tp);
@@ -28,7 +25,6 @@ static void down_event_handler(struct wlan_ptracker_core *core)
struct net_device *dev = core->dev;
tp_monitor_exit(&core->tp);
core->dev = NULL;
- core->client->core = NULL;
core->client->priv = NULL;
if (dev)
dev_put(dev);
diff --git a/scenes_fsm.c b/scenes_fsm.c
index 6bb920c..622e13f 100644
--- a/scenes_fsm.c
+++ b/scenes_fsm.c
@@ -52,7 +52,6 @@ static int fsm_thread(void *param)
struct wlan_ptracker_core *core = fsm_to_core(fsm);
while (fsm->thread_run) {
- set_current_state(TASK_INTERRUPTIBLE);
if (kthread_should_stop()) {
ptracker_info(core, "kthread is stopped\n");
break;
diff --git a/tp_monitor.c b/tp_monitor.c
index 0fac073..3937506 100644
--- a/tp_monitor.c
+++ b/tp_monitor.c
@@ -175,26 +175,16 @@ static int tp_monitor_debugfs_init(struct wlan_ptracker_core *core)
{
struct wlan_ptracker_debugfs *debugfs = &core->debugfs;
struct tp_monitor_stats *stats = &core->tp;
- struct wlan_ptracker_client *client;
- int ret = 0;
+ struct wlan_ptracker_client *client = core->client;
- rcu_read_lock();
- client = rcu_dereference(core->client);
- if (!client) {
- ret = -ENODEV;
- goto out;
- }
stats->dir = debugfs_create_dir(client->ifname, debugfs->root);
- if (!stats->dir) {
- ret = -ENODEV;
- goto out;
- }
+ if (!stats->dir)
+ return -ENODEV;
+
debugfs_create_u32("log_level", 0600, stats->dir, &stats->debug);
debugfs_create_file("tx", 0400, stats->dir, &stats->tx, &counter_ops);
debugfs_create_file("rx", 0400, stats->dir, &stats->rx, &counter_ops);
-out:
- rcu_read_unlock();
- return ret;
+ return 0;
}
int tp_monitor_init(struct tp_monitor_stats *stats)