tx99.c 6.8 KB

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