blob: 096902e0fdf5c4c88818168fb98cf1c98a913684 [file] [log] [blame]
Sujith Manoharanef6b19e2013-10-24 12:04:39 +05301/*
2 * Copyright (c) 2013 Qualcomm Atheros, Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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;
Lorenzo Bianconi55957fb2013-12-09 23:37:49 +010051 struct ieee80211_tx_rate *rate;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053052 struct ieee80211_hw *hw = sc->hw;
Lorenzo Bianconi55957fb2013-12-09 23:37:49 +010053 struct ath_hw *ah = sc->sc_ah;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053054 struct ieee80211_hdr *hdr;
55 struct ieee80211_tx_info *tx_info;
56 struct sk_buff *skb;
Felix Fietkau463950f2018-09-22 18:49:05 +020057 struct ath_vif *avp;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053058
59 skb = alloc_skb(len, GFP_KERNEL);
60 if (!skb)
61 return NULL;
62
63 skb_put(skb, len);
64
65 memset(skb->data, 0, len);
66
67 hdr = (struct ieee80211_hdr *)skb->data;
68 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
69 hdr->duration_id = 0;
70
71 memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
72 memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
73 memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
74
Felix Fietkau463950f2018-09-22 18:49:05 +020075 if (sc->tx99_vif) {
76 avp = (struct ath_vif *) sc->tx99_vif->drv_priv;
77 hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
78 }
79
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053080 tx_info = IEEE80211_SKB_CB(skb);
81 memset(tx_info, 0, sizeof(*tx_info));
Lorenzo Bianconi55957fb2013-12-09 23:37:49 +010082 rate = &tx_info->control.rates[0];
Felix Fietkau39305632014-06-11 16:17:57 +053083 tx_info->band = sc->cur_chan->chandef.chan->band;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053084 tx_info->flags = IEEE80211_TX_CTL_NO_ACK;
Felix Fietkau463950f2018-09-22 18:49:05 +020085 tx_info->control.vif = sc->tx99_vif;
Lorenzo Bianconi55957fb2013-12-09 23:37:49 +010086 rate->count = 1;
87 if (ah->curchan && IS_CHAN_HT(ah->curchan)) {
88 rate->flags |= IEEE80211_TX_RC_MCS;
89 if (IS_CHAN_HT40(ah->curchan))
90 rate->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
91 }
Sujith Manoharanef6b19e2013-10-24 12:04:39 +053092
93 memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data));
94
95 return skb;
96}
97
98static void ath9k_tx99_deinit(struct ath_softc *sc)
99{
Sujith Manoharan5555c952014-10-17 07:40:11 +0530100 ath_reset(sc, NULL);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530101
102 ath9k_ps_wakeup(sc);
103 ath9k_tx99_stop(sc);
104 ath9k_ps_restore(sc);
105}
106
107static int ath9k_tx99_init(struct ath_softc *sc)
108{
109 struct ieee80211_hw *hw = sc->hw;
110 struct ath_hw *ah = sc->sc_ah;
111 struct ath_common *common = ath9k_hw_common(ah);
112 struct ath_tx_control txctl;
113 int r;
114
Oleksij Rempeleefa01d2014-02-27 11:40:46 +0100115 if (test_bit(ATH_OP_INVALID, &common->op_flags)) {
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530116 ath_err(common,
117 "driver is in invalid state unable to use TX99");
118 return -EINVAL;
119 }
120
121 sc->tx99_skb = ath9k_build_tx99_skb(sc);
122 if (!sc->tx99_skb)
123 return -ENOMEM;
124
125 memset(&txctl, 0, sizeof(txctl));
126 txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO];
127
Sujith Manoharan5555c952014-10-17 07:40:11 +0530128 ath_reset(sc, NULL);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530129
130 ath9k_ps_wakeup(sc);
131
132 ath9k_hw_disable_interrupts(ah);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530133 ath_drain_all_txq(sc);
134 ath_stoprecv(sc);
135
136 sc->tx99_state = true;
137
138 ieee80211_stop_queues(hw);
139
140 if (sc->tx99_power == MAX_RATE_POWER + 1)
141 sc->tx99_power = MAX_RATE_POWER;
142
143 ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
144 r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
145 if (r) {
146 ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
147 return r;
148 }
149
150 ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
151 sc->tx99_power,
152 sc->tx99_power / 2);
153
154 /* We leave the harware awake as it will be chugging on */
155
156 return 0;
157}
158
159static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
160 size_t count, loff_t *ppos)
161{
162 struct ath_softc *sc = file->private_data;
163 char buf[3];
164 unsigned int len;
165
166 len = sprintf(buf, "%d\n", sc->tx99_state);
167 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
168}
169
170static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
171 size_t count, loff_t *ppos)
172{
173 struct ath_softc *sc = file->private_data;
174 struct ath_common *common = ath9k_hw_common(sc->sc_ah);
175 char buf[32];
176 bool start;
177 ssize_t len;
178 int r;
179
Miaoqing Paned70a222017-09-27 09:13:34 +0800180 if (count < 1)
181 return -EINVAL;
182
Sujith Manoharanca529c92014-09-05 08:03:19 +0530183 if (sc->cur_chan->nvifs > 1)
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530184 return -EOPNOTSUPP;
185
186 len = min(count, sizeof(buf) - 1);
187 if (copy_from_user(buf, user_buf, len))
188 return -EFAULT;
189
Miaoqing Paned70a222017-09-27 09:13:34 +0800190 buf[len] = '\0';
191
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530192 if (strtobool(buf, &start))
193 return -EINVAL;
194
Miaoqing Panb729a1a2017-06-27 17:31:49 +0300195 mutex_lock(&sc->mutex);
196
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530197 if (start == sc->tx99_state) {
198 if (!start)
Miaoqing Panb729a1a2017-06-27 17:31:49 +0300199 goto out;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530200 ath_dbg(common, XMIT, "Resetting TX99\n");
201 ath9k_tx99_deinit(sc);
202 }
203
204 if (!start) {
205 ath9k_tx99_deinit(sc);
Miaoqing Panb729a1a2017-06-27 17:31:49 +0300206 goto out;
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530207 }
208
209 r = ath9k_tx99_init(sc);
Miaoqing Panb729a1a2017-06-27 17:31:49 +0300210 if (r) {
211 mutex_unlock(&sc->mutex);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530212 return r;
Miaoqing Panb729a1a2017-06-27 17:31:49 +0300213 }
214out:
215 mutex_unlock(&sc->mutex);
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530216 return count;
217}
218
219static const struct file_operations fops_tx99 = {
220 .read = read_file_tx99,
221 .write = write_file_tx99,
222 .open = simple_open,
223 .owner = THIS_MODULE,
224 .llseek = default_llseek,
225};
226
227static ssize_t read_file_tx99_power(struct file *file,
228 char __user *user_buf,
229 size_t count, loff_t *ppos)
230{
231 struct ath_softc *sc = file->private_data;
232 char buf[32];
233 unsigned int len;
234
235 len = sprintf(buf, "%d (%d dBm)\n",
236 sc->tx99_power,
237 sc->tx99_power / 2);
238
239 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
240}
241
242static ssize_t write_file_tx99_power(struct file *file,
243 const char __user *user_buf,
244 size_t count, loff_t *ppos)
245{
246 struct ath_softc *sc = file->private_data;
247 int r;
248 u8 tx_power;
249
250 r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
251 if (r)
252 return r;
253
254 if (tx_power > MAX_RATE_POWER)
255 return -EINVAL;
256
257 sc->tx99_power = tx_power;
258
259 ath9k_ps_wakeup(sc);
260 ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
261 ath9k_ps_restore(sc);
262
263 return count;
264}
265
266static const struct file_operations fops_tx99_power = {
267 .read = read_file_tx99_power,
268 .write = write_file_tx99_power,
269 .open = simple_open,
270 .owner = THIS_MODULE,
271 .llseek = default_llseek,
272};
273
274void ath9k_tx99_init_debug(struct ath_softc *sc)
275{
Eduardo Abinadere94610c2016-05-09 14:38:40 +0200276 if (!AR_SREV_9280_20_OR_LATER(sc->sc_ah))
Sujith Manoharanef6b19e2013-10-24 12:04:39 +0530277 return;
278
279 debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
280 sc->debug.debugfs_phy, sc,
281 &fops_tx99);
282 debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
283 sc->debug.debugfs_phy, sc,
284 &fops_tx99_power);
285}