tx99.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. if (!sc->tx99_vif)
  51. return NULL;
  52. avp = (struct ath_vif *)sc->tx99_vif->drv_priv;
  53. skb = alloc_skb(len, GFP_KERNEL);
  54. if (!skb)
  55. return NULL;
  56. skb_put(skb, len);
  57. memset(skb->data, 0, len);
  58. hdr = (struct ieee80211_hdr *)skb->data;
  59. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA);
  60. hdr->duration_id = 0;
  61. memcpy(hdr->addr1, hw->wiphy->perm_addr, ETH_ALEN);
  62. memcpy(hdr->addr2, hw->wiphy->perm_addr, ETH_ALEN);
  63. memcpy(hdr->addr3, hw->wiphy->perm_addr, ETH_ALEN);
  64. hdr->seq_ctrl |= cpu_to_le16(avp->seq_no);
  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. atomic_set(&ah->intr_ref_cnt, -1);
  108. ath_drain_all_txq(sc);
  109. ath_stoprecv(sc);
  110. sc->tx99_state = true;
  111. ieee80211_stop_queues(hw);
  112. if (sc->tx99_power == MAX_RATE_POWER + 1)
  113. sc->tx99_power = MAX_RATE_POWER;
  114. ath9k_hw_tx99_set_txpower(ah, sc->tx99_power);
  115. r = ath9k_tx99_send(sc, sc->tx99_skb, &txctl);
  116. if (r) {
  117. ath_dbg(common, XMIT, "Failed to xmit TX99 skb\n");
  118. return r;
  119. }
  120. ath_dbg(common, XMIT, "TX99 xmit started using %d ( %ddBm)\n",
  121. sc->tx99_power,
  122. sc->tx99_power / 2);
  123. /* We leave the harware awake as it will be chugging on */
  124. return 0;
  125. }
  126. static ssize_t read_file_tx99(struct file *file, char __user *user_buf,
  127. size_t count, loff_t *ppos)
  128. {
  129. struct ath_softc *sc = file->private_data;
  130. char buf[3];
  131. unsigned int len;
  132. len = sprintf(buf, "%d\n", sc->tx99_state);
  133. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  134. }
  135. static ssize_t write_file_tx99(struct file *file, const char __user *user_buf,
  136. size_t count, loff_t *ppos)
  137. {
  138. struct ath_softc *sc = file->private_data;
  139. struct ath_common *common = ath9k_hw_common(sc->sc_ah);
  140. char buf[32];
  141. bool start;
  142. ssize_t len;
  143. int r;
  144. if (count < 1)
  145. return -EINVAL;
  146. if (sc->cur_chan->nvifs > 1)
  147. return -EOPNOTSUPP;
  148. len = min(count, sizeof(buf) - 1);
  149. if (copy_from_user(buf, user_buf, len))
  150. return -EFAULT;
  151. buf[len] = '\0';
  152. if (strtobool(buf, &start))
  153. return -EINVAL;
  154. mutex_lock(&sc->mutex);
  155. if (start == sc->tx99_state) {
  156. if (!start)
  157. goto out;
  158. ath_dbg(common, XMIT, "Resetting TX99\n");
  159. ath9k_tx99_deinit(sc);
  160. }
  161. if (!start) {
  162. ath9k_tx99_deinit(sc);
  163. goto out;
  164. }
  165. r = ath9k_tx99_init(sc);
  166. if (r) {
  167. mutex_unlock(&sc->mutex);
  168. return r;
  169. }
  170. out:
  171. mutex_unlock(&sc->mutex);
  172. return count;
  173. }
  174. static const struct file_operations fops_tx99 = {
  175. .read = read_file_tx99,
  176. .write = write_file_tx99,
  177. .open = simple_open,
  178. .owner = THIS_MODULE,
  179. .llseek = default_llseek,
  180. };
  181. static ssize_t read_file_tx99_power(struct file *file,
  182. char __user *user_buf,
  183. size_t count, loff_t *ppos)
  184. {
  185. struct ath_softc *sc = file->private_data;
  186. char buf[32];
  187. unsigned int len;
  188. len = sprintf(buf, "%d (%d dBm)\n",
  189. sc->tx99_power,
  190. sc->tx99_power / 2);
  191. return simple_read_from_buffer(user_buf, count, ppos, buf, len);
  192. }
  193. static ssize_t write_file_tx99_power(struct file *file,
  194. const char __user *user_buf,
  195. size_t count, loff_t *ppos)
  196. {
  197. struct ath_softc *sc = file->private_data;
  198. int r;
  199. u8 tx_power;
  200. r = kstrtou8_from_user(user_buf, count, 0, &tx_power);
  201. if (r)
  202. return r;
  203. if (tx_power > MAX_RATE_POWER)
  204. return -EINVAL;
  205. sc->tx99_power = tx_power;
  206. ath9k_ps_wakeup(sc);
  207. ath9k_hw_tx99_set_txpower(sc->sc_ah, sc->tx99_power);
  208. ath9k_ps_restore(sc);
  209. return count;
  210. }
  211. static const struct file_operations fops_tx99_power = {
  212. .read = read_file_tx99_power,
  213. .write = write_file_tx99_power,
  214. .open = simple_open,
  215. .owner = THIS_MODULE,
  216. .llseek = default_llseek,
  217. };
  218. void ath9k_tx99_init_debug(struct ath_softc *sc)
  219. {
  220. if (!AR_SREV_9300_20_OR_LATER(sc->sc_ah))
  221. return;
  222. debugfs_create_file("tx99", S_IRUSR | S_IWUSR,
  223. sc->debug.debugfs_phy, sc,
  224. &fops_tx99);
  225. debugfs_create_file("tx99_power", S_IRUSR | S_IWUSR,
  226. sc->debug.debugfs_phy, sc,
  227. &fops_tx99_power);
  228. }