tx99.c 6.6 KB

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