1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#include "ath9k.h"
18
19static void ath9k_tx99_stop(struct ath_softc *sc)
20{
21 struct ath_hw *ah = sc->sc_ah;
22 struct ath_common *common = ath9k_hw_common(ah);
23
24 ath_drain_all_txq(sc);
25 ath_startrecv(sc);
26
27 ath9k_hw_set_interrupts(ah);
28 ath9k_hw_enable_interrupts(ah);
29
30 ieee80211_wake_queues(sc->hw);
31
32 kfree_skb(sc->tx99_skb);
33 sc->tx99_skb = NULL;
34 sc->tx99_state = false;
35
36 ath9k_hw_tx99_stop(sc->sc_ah);
37 ath_dbg(common, XMIT, "TX99 stopped\n");
38}
39
40static struct sk_buff *ath9k_build_tx99_skb(struct ath_softc *sc)
41{
42 static u8 PN9Data[] = {0xff, 0x87, 0xb8, 0x59, 0xb7, 0xa1, 0xcc, 0x24,
43 0x57, 0x5e, 0x4b, 0x9c, 0x0e, 0xe9, 0xea, 0x50,
44 0x2a, 0xbe, 0xb4, 0x1b, 0xb6, 0xb0, 0x5d, 0xf1,
45 0xe6, 0x9a, 0xe3, 0x45, 0xfd, 0x2c, 0x53, 0x18,
46 0x0c, 0xca, 0xc9, 0xfb, 0x49, 0x37, 0xe5, 0xa8,
47 0x51, 0x3b, 0x2f, 0x61, 0xaa, 0x72, 0x18, 0x84,
48 0x02, 0x23, 0x23, 0xab, 0x63, 0x89, 0x51, 0xb3,
49 0xe7, 0x8b, 0x72, 0x90, 0x4c, 0xe8, 0xfb, 0xc0};
50 u32 len = 1200;
51 struct ieee80211_tx_rate *rate;
52 struct ieee80211_hw *hw = sc->hw;
53 struct ath_hw *ah = sc->sc_ah;
54 struct ieee80211_hdr *hdr;
55 struct ieee80211_tx_info *tx_info;
56 struct sk_buff *skb;
57 struct ath_vif *avp;
58
59 if (!sc->tx99_vif)
60 return NULL;
61
62 avp = (struct ath_vif *)sc->tx99_vif->drv_priv;
63
64 skb = alloc_skb(len, GFP_KERNEL);
65 if (!skb)
66 return NULL;
67
68 skb_put(skb, len);
69
70 memset(skb->data, 0, len);
71
72 hdr = (struct ieee80211_hdr *)skb->data;
73 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
74 hdr->duration_id = 0;
75
76 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
77 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
78 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
79
80 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
81
82 tx_info = IEEE80211_SKB_CB(skb);
83 memset(tx_info, 0, sizeof(*tx_info));
84 rate = &tx_info->control.rates[0];
85 tx_info->band = sc->cur_chan->chandef.chan->band;
86 tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
87 tx_info->control.vif = sc->tx99_vif;
88 rate->count = 1;
89 if (ah->curchan && IS_CHAN_HT(ah->curchan)) {
90 rate->flags |= IEEE80211_TX_RC_MCS;
91 if (IS_CHAN_HT40(ah->curchan))
92 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
93 }
94
95 memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
96
97 return skb;
98}
99
100static void ath9k_tx99_deinit(struct ath_softc *sc)
101{
102 ath_reset(sc, NULL);
103
104 ath9k_ps_wakeup(sc);
105 ath9k_tx99_stop(sc);
106 ath9k_ps_restore(sc);
107}
108
109static int ath9k_tx99_init(struct ath_softc *sc)
110{
111 struct ieee80211_hw *hw = sc->hw;
112 struct ath_hw *ah = sc->sc_ah;
113 struct ath_common *common = ath9k_hw_common(ah);
114 struct ath_tx_control txctl;
115 int r;
116
117 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
118 ath_err(common,
119 "driver is in invalid state unable to use TX99");
120 return -EINVAL;
121 }
122
123 sc->tx99_skb = ath9k_build_tx99_skb(sc);
124 if (!sc->tx99_skb)
125 return -ENOMEM;
126
127 memset(&txctl, 0, sizeof(txctl));
128 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
129
130 ath_reset(sc, NULL);
131
132 ath9k_ps_wakeup(sc);
133
134 ath9k_hw_disable_interrupts(ah);
135 ath_drain_all_txq(sc);
136 ath_stoprecv(sc);
137
138 sc->tx99_state = true;
139
140 ieee80211_stop_queues(hw);
141
142 if (sc->tx99_power == MAX_RATE_POWER + 1)
143 sc->tx99_power = MAX_RATE_POWER;
144
145 ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
146 r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
147 if (r) {
148 ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
149 return r;
150 }
151
152 ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
153 sc->tx99_power,
154 sc->tx99_power / 2);
155
156
157
158 return 0;
159}
160
161static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
162 size_t count, loff_t *ppos)
163{
164 struct ath_softc *sc = file->private_data;
165 char buf[3];
166 unsigned int len;
167
168 len = sprintf(buf, "%d\n", sc->tx99_state);
169 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
170}
171
172static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
173 size_t count, loff_t *ppos)
174{
175 struct ath_softc *sc = file->private_data;
176 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
177 char buf[32];
178 bool start;
179 ssize_t len;
180 int r;
181
182 if (count < 1)
183 return -EINVAL;
184
185 if (sc->cur_chan->nvifs > 1)
186 return -EOPNOTSUPP;
187
188 len = min(count, sizeof(buf) - 1);
189 if (copy_from_user(buf, user_buf, len))
190 return -EFAULT;
191
192 buf[len] = '\0';
193
194 if (strtobool(buf, &start))
195 return -EINVAL;
196
197 mutex_lock(&sc->mutex);
198
199 if (start == sc->tx99_state) {
200 if (!start)
201 goto out;
202 ath_dbg(common, XMIT, "Resetting TX99\n");
203 ath9k_tx99_deinit(sc);
204 }
205
206 if (!start) {
207 ath9k_tx99_deinit(sc);
208 goto out;
209 }
210
211 r = ath9k_tx99_init(sc);
212 if (r) {
213 mutex_unlock(&sc->mutex);
214 return r;
215 }
216out:
217 mutex_unlock(&sc->mutex);
218 return count;
219}
220
221static const struct file_operations fops_tx99 = {
222 .read = read_file_tx99,
223 .write = write_file_tx99,
224 .open = simple_open,
225 .owner = THIS_MODULE,
226 .llseek = default_llseek,
227};
228
229static ssize_t read_file_tx99_power(struct file *file,
230 char __user *user_buf,
231 size_t count, loff_t *ppos)
232{
233 struct ath_softc *sc = file->private_data;
234 char buf[32];
235 unsigned int len;
236
237 len = sprintf(buf, "%d (%d dBm)\n",
238 sc->tx99_power,
239 sc->tx99_power / 2);
240
241 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
242}
243
244static ssize_t write_file_tx99_power(struct file *file,
245 const char __user *user_buf,
246 size_t count, loff_t *ppos)
247{
248 struct ath_softc *sc = file->private_data;
249 int r;
250 u8 tx_power;
251
252 r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
253 if (r)
254 return r;
255
256 if (tx_power > MAX_RATE_POWER)
257 return -EINVAL;
258
259 sc->tx99_power = tx_power;
260
261 ath9k_ps_wakeup(sc);
262 ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
263 ath9k_ps_restore(sc);
264
265 return count;
266}
267
268static const struct file_operations fops_tx99_power = {
269 .read = read_file_tx99_power,
270 .write = write_file_tx99_power,
271 .open = simple_open,
272 .owner = THIS_MODULE,
273 .llseek = default_llseek,
274};
275
276void ath9k_tx99_init_debug(struct ath_softc *sc)
277{
278 if (!AR_SREV_9280_20_OR_LATER(sc->sc_ah))
279 return;
280
281 debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
282 sc->debug.debugfs_phy, sc,
283 &fops_tx99);
284 debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
285 sc->debug.debugfs_phy, sc,
286 &fops_tx99_power);
287}
288