b21b671c10a51eead1234bbb5fce91291d6871d4
[openwrt/staging/mkresin.git] / package / kernel / mac80211 / patches / subsys / 380-mac80211-introduce-aql_enable-node-in-debugfs.patch
1 From: Lorenzo Bianconi <lorenzo@kernel.org>
2 Date: Sat, 9 Jan 2021 18:57:51 +0100
3 Subject: [PATCH] mac80211: introduce aql_enable node in debugfs
4
5 Introduce aql_enable node in debugfs in order to enable/disable aql.
6 This is useful for debugging purpose.
7
8 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
9 Link: https://lore.kernel.org/r/e7a934d5d84e4796c4f97ea5de4e66c824296b07.1610214851.git.lorenzo@kernel.org
10 Signed-off-by: Johannes Berg <johannes.berg@intel.com>
11 ---
12
13 --- a/net/mac80211/debugfs.c
14 +++ b/net/mac80211/debugfs.c
15 @@ -281,6 +281,56 @@ static const struct file_operations aql_
16 .llseek = default_llseek,
17 };
18
19 +static ssize_t aql_enable_read(struct file *file, char __user *user_buf,
20 + size_t count, loff_t *ppos)
21 +{
22 + char buf[3];
23 + int len;
24 +
25 + len = scnprintf(buf, sizeof(buf), "%d\n",
26 + !static_key_false(&aql_disable.key));
27 +
28 + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
29 +}
30 +
31 +static ssize_t aql_enable_write(struct file *file, const char __user *user_buf,
32 + size_t count, loff_t *ppos)
33 +{
34 + bool aql_disabled = static_key_false(&aql_disable.key);
35 + char buf[3];
36 + size_t len;
37 +
38 + if (count > sizeof(buf))
39 + return -EINVAL;
40 +
41 + if (copy_from_user(buf, user_buf, count))
42 + return -EFAULT;
43 +
44 + buf[sizeof(buf) - 1] = '\0';
45 + len = strlen(buf);
46 + if (len > 0 && buf[len - 1] == '\n')
47 + buf[len - 1] = 0;
48 +
49 + if (buf[0] == '0' && buf[1] == '\0') {
50 + if (!aql_disabled)
51 + static_branch_inc(&aql_disable);
52 + } else if (buf[0] == '1' && buf[1] == '\0') {
53 + if (aql_disabled)
54 + static_branch_dec(&aql_disable);
55 + } else {
56 + return -EINVAL;
57 + }
58 +
59 + return count;
60 +}
61 +
62 +static const struct file_operations aql_enable_ops = {
63 + .write = aql_enable_write,
64 + .read = aql_enable_read,
65 + .open = simple_open,
66 + .llseek = default_llseek,
67 +};
68 +
69 static ssize_t force_tx_status_read(struct file *file,
70 char __user *user_buf,
71 size_t count,
72 @@ -569,6 +619,7 @@ void debugfs_hw_add(struct ieee80211_loc
73 DEBUGFS_ADD(power);
74 DEBUGFS_ADD(hw_conf);
75 DEBUGFS_ADD_MODE(force_tx_status, 0600);
76 + DEBUGFS_ADD_MODE(aql_enable, 0600);
77
78 if (local->ops->wake_tx_queue)
79 DEBUGFS_ADD_MODE(aqm, 0600);
80 --- a/net/mac80211/ieee80211_i.h
81 +++ b/net/mac80211/ieee80211_i.h
82 @@ -1140,6 +1140,8 @@ enum mac80211_scan_state {
83 SCAN_ABORT,
84 };
85
86 +DECLARE_STATIC_KEY_FALSE(aql_disable);
87 +
88 struct ieee80211_local {
89 /* embed the driver visible part.
90 * don't cast (use the static inlines below), but we keep
91 --- a/net/mac80211/tx.c
92 +++ b/net/mac80211/tx.c
93 @@ -3887,6 +3887,8 @@ void __ieee80211_schedule_txq(struct iee
94 }
95 EXPORT_SYMBOL(__ieee80211_schedule_txq);
96
97 +DEFINE_STATIC_KEY_FALSE(aql_disable);
98 +
99 bool ieee80211_txq_airtime_check(struct ieee80211_hw *hw,
100 struct ieee80211_txq *txq)
101 {
102 @@ -3896,6 +3898,9 @@ bool ieee80211_txq_airtime_check(struct
103 if (!wiphy_ext_feature_isset(local->hw.wiphy, NL80211_EXT_FEATURE_AQL))
104 return true;
105
106 + if (static_branch_unlikely(&aql_disable))
107 + return true;
108 +
109 if (!txq->sta)
110 return true;
111