mac80211: rebase ontop of v4.18.5
[openwrt/openwrt.git] / package / kernel / mac80211 / patches / ath / 440-ath5k_channel_bw_debugfs.patch
1 This adds a bwmode debugfs file which can be used to set alternate
2 channel operating bandwidths. Only tested with AR5413 and only at
3 5 and 20 mhz channels.
4
5 Signed-off-by: Pat Erley <pat-lkml at erley.org>
6 ---
7 Other devices will need to be added to the switch in write_file_bwmode
8
9 drivers/net/wireless/ath/ath5k/debug.c | 86 ++++++++++++++++++++++++++++++++
10 1 files changed, 86 insertions(+), 0 deletions(-)
11
12 Index: backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/debug.c
13 ===================================================================
14 --- backports-v4.18-rc7.orig/drivers/net/wireless/ath/ath5k/debug.c
15 +++ backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/debug.c
16 @@ -822,6 +822,97 @@ static const struct file_operations fops
17 .llseek = default_llseek,
18 };
19
20 +/* debugfs: bwmode */
21 +
22 +static ssize_t read_file_bwmode(struct file *file, char __user *user_buf,
23 + size_t count, loff_t *ppos)
24 +{
25 + struct ath5k_hw *ah = file->private_data;
26 + char buf[15];
27 + unsigned int len = 0;
28 +
29 + int cur_ah_bwmode = ah->ah_bwmode_debug;
30 +
31 +#define print_selected(MODE, LABEL) \
32 + if (cur_ah_bwmode == MODE) \
33 + len += snprintf(buf+len, sizeof(buf)-len, "[%s]", LABEL); \
34 + else \
35 + len += snprintf(buf+len, sizeof(buf)-len, "%s", LABEL); \
36 + len += snprintf(buf+len, sizeof(buf)-len, " ");
37 +
38 + print_selected(AR5K_BWMODE_5MHZ, "5");
39 + print_selected(AR5K_BWMODE_10MHZ, "10");
40 + print_selected(AR5K_BWMODE_DEFAULT, "20");
41 + print_selected(AR5K_BWMODE_40MHZ, "40");
42 +#undef print_selected
43 +
44 + len += snprintf(buf+len, sizeof(buf)-len, "\n");
45 +
46 + return simple_read_from_buffer(user_buf, count, ppos, buf, len);
47 +}
48 +
49 +static ssize_t write_file_bwmode(struct file *file,
50 + const char __user *userbuf,
51 + size_t count, loff_t *ppos)
52 +{
53 + struct ath5k_hw *ah = file->private_data;
54 + char buf[3];
55 + int bw = 20;
56 + int tobwmode = AR5K_BWMODE_DEFAULT;
57 +
58 + if (copy_from_user(buf, userbuf, min(count, sizeof(buf))))
59 + return -EFAULT;
60 +
61 + /* TODO: Add check for active interface */
62 +
63 + if(strncmp(buf, "5", 1) == 0 ) {
64 + tobwmode = AR5K_BWMODE_5MHZ;
65 + bw = 5;
66 + } else if ( strncmp(buf, "10", 2) == 0 ) {
67 + tobwmode = AR5K_BWMODE_10MHZ;
68 + bw = 10;
69 + } else if ( strncmp(buf, "20", 2) == 0 ) {
70 + tobwmode = AR5K_BWMODE_DEFAULT;
71 + bw = 20;
72 + } else if ( strncmp(buf, "40", 2) == 0 ) {
73 + tobwmode = AR5K_BWMODE_40MHZ;
74 + bw = 40;
75 + } else
76 + return -EINVAL;
77 +
78 + ATH5K_INFO(ah, "Changing to %imhz channel width[%i]\n",
79 + bw, tobwmode);
80 +
81 + switch (ah->ah_radio) {
82 + /* TODO: only define radios that actually support 5/10mhz channels */
83 + case AR5K_RF5413:
84 + case AR5K_RF5110:
85 + case AR5K_RF5111:
86 + case AR5K_RF5112:
87 + case AR5K_RF2413:
88 + case AR5K_RF2316:
89 + case AR5K_RF2317:
90 + case AR5K_RF2425:
91 + if(ah->ah_bwmode_debug != tobwmode) {
92 + mutex_lock(&ah->lock);
93 + ah->ah_bwmode = tobwmode;
94 + ah->ah_bwmode_debug = tobwmode;
95 + mutex_unlock(&ah->lock);
96 + }
97 + break;
98 + default:
99 + return -EOPNOTSUPP;
100 + }
101 + return count;
102 +}
103 +
104 +static const struct file_operations fops_bwmode = {
105 + .read = read_file_bwmode,
106 + .write = write_file_bwmode,
107 + .open = simple_open,
108 + .owner = THIS_MODULE,
109 + .llseek = default_llseek,
110 +};
111
112 /* debugfs: queues etc */
113
114 @@ -1016,6 +1107,8 @@ ath5k_debug_init_device(struct ath5k_hw
115 debugfs_create_file("queue", 0600, phydir, ah, &fops_queue);
116 debugfs_create_bool("32khz_clock", 0600, phydir,
117 &ah->ah_use_32khz_clock);
118 + debugfs_create_file("bwmode", S_IWUSR | S_IRUSR, phydir, ah,
119 + &fops_bwmode);
120 }
121
122 /* functions used in other places */
123 Index: backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/ath5k.h
124 ===================================================================
125 --- backports-v4.18-rc7.orig/drivers/net/wireless/ath/ath5k/ath5k.h
126 +++ backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/ath5k.h
127 @@ -1372,6 +1372,7 @@ struct ath5k_hw {
128 u8 ah_coverage_class;
129 bool ah_ack_bitrate_high;
130 u8 ah_bwmode;
131 + u8 ah_bwmode_debug;
132 bool ah_short_slot;
133
134 /* Antenna Control */
135 Index: backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/base.c
136 ===================================================================
137 --- backports-v4.18-rc7.orig/drivers/net/wireless/ath/ath5k/base.c
138 +++ backports-v4.18-rc7/drivers/net/wireless/ath/ath5k/base.c
139 @@ -466,6 +466,9 @@ ath5k_chan_set(struct ath5k_hw *ah, stru
140 return -EINVAL;
141 }
142
143 + if (ah->ah_bwmode_debug != AR5K_BWMODE_DEFAULT)
144 + ah->ah_bwmode = ah->ah_bwmode_debug;
145 +
146 /*
147 * To switch channels clear any pending DMA operations;
148 * wait long enough for the RX fifo to drain, reset the