Commit | Line | Data |
---|---|---|
ef6b19e4 SM |
1 | /* |
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 | ||
19 | static 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 | ||
40 | static 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_hw *hw = sc->hw; | |
52 | struct ieee80211_hdr *hdr; | |
53 | struct ieee80211_tx_info *tx_info; | |
54 | struct sk_buff *skb; | |
55 | ||
56 | skb = alloc_skb(len, GFP_KERNEL); | |
57 | if (!skb) | |
58 | return NULL; | |
59 | ||
60 | skb_put(skb, len); | |
61 | ||
62 | memset(skb->data, 0, len); | |
63 | ||
64 | hdr = (struct ieee80211_hdr *)skb->data; | |
65 | hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA); | |
66 | hdr->duration_id = 0; | |
67 | ||
68 | memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN); | |
69 | memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN); | |
70 | memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN); | |
71 | ||
72 | hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no); | |
73 | ||
74 | tx_info = IEEE80211_SKB_CB(skb); | |
75 | memset(tx_info, 0, sizeof(*tx_info)); | |
76 | tx_info->band = hw->conf.chandef.chan->band; | |
77 | tx_info->flags = IEEE80211_TX_CTL_NO_ACK; | |
78 | tx_info->control.vif = sc->tx99_vif; | |
fc70ff72 | 79 | tx_info->control.rates[0].count = 1; |
ef6b19e4 SM |
80 | |
81 | memcpy(skb->data + sizeof(*hdr), PN9Data, sizeof(PN9Data)); | |
82 | ||
83 | return skb; | |
84 | } | |
85 | ||
86 | static void ath9k_tx99_deinit(struct ath_softc *sc) | |
87 | { | |
88 | ath_reset(sc); | |
89 | ||
90 | ath9k_ps_wakeup(sc); | |
91 | ath9k_tx99_stop(sc); | |
92 | ath9k_ps_restore(sc); | |
93 | } | |
94 | ||
95 | static int ath9k_tx99_init(struct ath_softc *sc) | |
96 | { | |
97 | struct ieee80211_hw *hw = sc->hw; | |
98 | struct ath_hw *ah = sc->sc_ah; | |
99 | struct ath_common *common = ath9k_hw_common(ah); | |
100 | struct ath_tx_control txctl; | |
101 | int r; | |
102 | ||
26f2a64a | 103 | if (test_bit(SC_OP_INVALID, &sc->sc_flags)) { |
ef6b19e4 SM |
104 | ath_err(common, |
105 | "driver is in invalid state unable to use TX99"); | |
106 | return -EINVAL; | |
107 | } | |
108 | ||
109 | sc->tx99_skb = ath9k_build_tx99_skb(sc); | |
110 | if (!sc->tx99_skb) | |
111 | return -ENOMEM; | |
112 | ||
113 | memset(&txctl, 0, sizeof(txctl)); | |
114 | txctl.txq = sc->tx.txq_map[IEEE80211_AC_VO]; | |
115 | ||
116 | ath_reset(sc); | |
117 | ||
118 | ath9k_ps_wakeup(sc); | |
119 | ||
120 | ath9k_hw_disable_interrupts(ah); | |
121 | atomic_set(&ah->intr_ref_cnt, -1); | |
122 | ath_drain_all_txq(sc); | |
123 | ath_stoprecv(sc); | |
124 | ||
125 | sc->tx99_state = true; | |
126 | ||
127 | ieee80211_stop_queues(hw); | |
128 | ||
129 | if (sc->tx99_power == MAX_RATE_POWER + 1) | |
130 | sc->tx99_power = MAX_RATE_POWER; | |
131 | ||
132 | ath9k_hw_tx99_set_txpower(ah, sc->tx99_power); | |
133 | r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl); | |
134 | if (r) { | |
135 | ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n"); | |
136 | return r; | |
137 | } | |
138 | ||
139 | ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n", | |
140 | sc->tx99_power, | |
141 | sc->tx99_power / 2); | |
142 | ||
143 | /* We leave the harware awake as it will be chugging on */ | |
144 | ||
145 | return 0; | |
146 | } | |
147 | ||
148 | static ssize_t read_file_tx99(struct file *file, char __user *user_buf, | |
149 | size_t count, loff_t *ppos) | |
150 | { | |
151 | struct ath_softc *sc = file->private_data; | |
152 | char buf[3]; | |
153 | unsigned int len; | |
154 | ||
155 | len = sprintf(buf, "%d\n", sc->tx99_state); | |
156 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
157 | } | |
158 | ||
159 | static ssize_t write_file_tx99(struct file *file, const char __user *user_buf, | |
160 | size_t count, loff_t *ppos) | |
161 | { | |
162 | struct ath_softc *sc = file->private_data; | |
163 | struct ath_common *common = ath9k_hw_common(sc->sc_ah); | |
164 | char buf[32]; | |
165 | bool start; | |
166 | ssize_t len; | |
167 | int r; | |
168 | ||
169 | if (sc->nvifs > 1) | |
170 | return -EOPNOTSUPP; | |
171 | ||
172 | len = min(count, sizeof(buf) - 1); | |
173 | if (copy_from_user(buf, user_buf, len)) | |
174 | return -EFAULT; | |
175 | ||
176 | if (strtobool(buf, &start)) | |
177 | return -EINVAL; | |
178 | ||
179 | if (start == sc->tx99_state) { | |
180 | if (!start) | |
181 | return count; | |
182 | ath_dbg(common, XMIT, "Resetting TX99\n"); | |
183 | ath9k_tx99_deinit(sc); | |
184 | } | |
185 | ||
186 | if (!start) { | |
187 | ath9k_tx99_deinit(sc); | |
188 | return count; | |
189 | } | |
190 | ||
191 | r = ath9k_tx99_init(sc); | |
192 | if (r) | |
193 | return r; | |
194 | ||
195 | return count; | |
196 | } | |
197 | ||
198 | static const struct file_operations fops_tx99 = { | |
199 | .read = read_file_tx99, | |
200 | .write = write_file_tx99, | |
201 | .open = simple_open, | |
202 | .owner = THIS_MODULE, | |
203 | .llseek = default_llseek, | |
204 | }; | |
205 | ||
206 | static ssize_t read_file_tx99_power(struct file *file, | |
207 | char __user *user_buf, | |
208 | size_t count, loff_t *ppos) | |
209 | { | |
210 | struct ath_softc *sc = file->private_data; | |
211 | char buf[32]; | |
212 | unsigned int len; | |
213 | ||
214 | len = sprintf(buf, "%d (%d dBm)\n", | |
215 | sc->tx99_power, | |
216 | sc->tx99_power / 2); | |
217 | ||
218 | return simple_read_from_buffer(user_buf, count, ppos, buf, len); | |
219 | } | |
220 | ||
221 | static ssize_t write_file_tx99_power(struct file *file, | |
222 | const char __user *user_buf, | |
223 | size_t count, loff_t *ppos) | |
224 | { | |
225 | struct ath_softc *sc = file->private_data; | |
226 | int r; | |
227 | u8 tx_power; | |
228 | ||
229 | r = kstrtou8_from_user(user_buf, count, 0, &tx_power); | |
230 | if (r) | |
231 | return r; | |
232 | ||
233 | if (tx_power > MAX_RATE_POWER) | |
234 | return -EINVAL; | |
235 | ||
236 | sc->tx99_power = tx_power; | |
237 | ||
238 | ath9k_ps_wakeup(sc); | |
239 | ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power); | |
240 | ath9k_ps_restore(sc); | |
241 | ||
242 | return count; | |
243 | } | |
244 | ||
245 | static const struct file_operations fops_tx99_power = { | |
246 | .read = read_file_tx99_power, | |
247 | .write = write_file_tx99_power, | |
248 | .open = simple_open, | |
249 | .owner = THIS_MODULE, | |
250 | .llseek = default_llseek, | |
251 | }; | |
252 | ||
253 | void ath9k_tx99_init_debug(struct ath_softc *sc) | |
254 | { | |
255 | if (!AR_SREV_9300_20_OR_LATER(sc->sc_ah)) | |
256 | return; | |
257 | ||
258 | debugfs_create_file("tx99", S_IRUSR | S_IWUSR, | |
259 | sc->debug.debugfs_phy, sc, | |
260 | &fops_tx99); | |
261 | debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR, | |
262 | sc->debug.debugfs_phy, sc, | |
263 | &fops_tx99_power); | |
264 | } |