mt76x2_mac.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  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. #ifndef __MT76x2_MAC_H
  17. #define __MT76x2_MAC_H
  18. #include "mt76.h"
  19. struct mt76x2_dev;
  20. struct mt76x2_sta;
  21. struct mt76x2_vif;
  22. struct mt76x2_txwi;
  23. struct mt76x2_tx_status {
  24. u8 valid:1;
  25. u8 success:1;
  26. u8 aggr:1;
  27. u8 ack_req:1;
  28. u8 wcid;
  29. u8 pktid;
  30. u8 retry;
  31. u16 rate;
  32. } __packed __aligned(2);
  33. struct mt76x2_tx_info {
  34. unsigned long jiffies;
  35. u8 tries;
  36. u8 wcid;
  37. u8 pktid;
  38. u8 retry;
  39. };
  40. struct mt76x2_rxwi {
  41. __le32 rxinfo;
  42. __le32 ctl;
  43. __le16 tid_sn;
  44. __le16 rate;
  45. u8 rssi[4];
  46. __le32 bbp_rxinfo[4];
  47. };
  48. #define MT_RXINFO_BA BIT(0)
  49. #define MT_RXINFO_DATA BIT(1)
  50. #define MT_RXINFO_NULL BIT(2)
  51. #define MT_RXINFO_FRAG BIT(3)
  52. #define MT_RXINFO_UNICAST BIT(4)
  53. #define MT_RXINFO_MULTICAST BIT(5)
  54. #define MT_RXINFO_BROADCAST BIT(6)
  55. #define MT_RXINFO_MYBSS BIT(7)
  56. #define MT_RXINFO_CRCERR BIT(8)
  57. #define MT_RXINFO_ICVERR BIT(9)
  58. #define MT_RXINFO_MICERR BIT(10)
  59. #define MT_RXINFO_AMSDU BIT(11)
  60. #define MT_RXINFO_HTC BIT(12)
  61. #define MT_RXINFO_RSSI BIT(13)
  62. #define MT_RXINFO_L2PAD BIT(14)
  63. #define MT_RXINFO_AMPDU BIT(15)
  64. #define MT_RXINFO_DECRYPT BIT(16)
  65. #define MT_RXINFO_BSSIDX3 BIT(17)
  66. #define MT_RXINFO_WAPI_KEY BIT(18)
  67. #define MT_RXINFO_PN_LEN GENMASK(21, 19)
  68. #define MT_RXINFO_SW_FTYPE0 BIT(22)
  69. #define MT_RXINFO_SW_FTYPE1 BIT(23)
  70. #define MT_RXINFO_PROBE_RESP BIT(24)
  71. #define MT_RXINFO_BEACON BIT(25)
  72. #define MT_RXINFO_DISASSOC BIT(26)
  73. #define MT_RXINFO_DEAUTH BIT(27)
  74. #define MT_RXINFO_ACTION BIT(28)
  75. #define MT_RXINFO_TCP_SUM_ERR BIT(30)
  76. #define MT_RXINFO_IP_SUM_ERR BIT(31)
  77. #define MT_RXWI_CTL_WCID GENMASK(7, 0)
  78. #define MT_RXWI_CTL_KEY_IDX GENMASK(9, 8)
  79. #define MT_RXWI_CTL_BSS_IDX GENMASK(12, 10)
  80. #define MT_RXWI_CTL_UDF GENMASK(15, 13)
  81. #define MT_RXWI_CTL_MPDU_LEN GENMASK(29, 16)
  82. #define MT_RXWI_CTL_EOF BIT(31)
  83. #define MT_RXWI_TID GENMASK(3, 0)
  84. #define MT_RXWI_SN GENMASK(15, 4)
  85. #define MT_RXWI_RATE_INDEX GENMASK(5, 0)
  86. #define MT_RXWI_RATE_LDPC BIT(6)
  87. #define MT_RXWI_RATE_BW GENMASK(8, 7)
  88. #define MT_RXWI_RATE_SGI BIT(9)
  89. #define MT_RXWI_RATE_STBC BIT(10)
  90. #define MT_RXWI_RATE_LDPC_EXSYM BIT(11)
  91. #define MT_RXWI_RATE_PHY GENMASK(15, 13)
  92. #define MT_RATE_INDEX_VHT_IDX GENMASK(3, 0)
  93. #define MT_RATE_INDEX_VHT_NSS GENMASK(5, 4)
  94. #define MT_TX_PWR_ADJ GENMASK(3, 0)
  95. enum mt76x2_phy_bandwidth {
  96. MT_PHY_BW_20,
  97. MT_PHY_BW_40,
  98. MT_PHY_BW_80,
  99. };
  100. #define MT_TXWI_FLAGS_FRAG BIT(0)
  101. #define MT_TXWI_FLAGS_MMPS BIT(1)
  102. #define MT_TXWI_FLAGS_CFACK BIT(2)
  103. #define MT_TXWI_FLAGS_TS BIT(3)
  104. #define MT_TXWI_FLAGS_AMPDU BIT(4)
  105. #define MT_TXWI_FLAGS_MPDU_DENSITY GENMASK(7, 5)
  106. #define MT_TXWI_FLAGS_TXOP GENMASK(9, 8)
  107. #define MT_TXWI_FLAGS_NDPS BIT(10)
  108. #define MT_TXWI_FLAGS_RTSBWSIG BIT(11)
  109. #define MT_TXWI_FLAGS_NDP_BW GENMASK(13, 12)
  110. #define MT_TXWI_FLAGS_SOUND BIT(14)
  111. #define MT_TXWI_FLAGS_TX_RATE_LUT BIT(15)
  112. #define MT_TXWI_ACK_CTL_REQ BIT(0)
  113. #define MT_TXWI_ACK_CTL_NSEQ BIT(1)
  114. #define MT_TXWI_ACK_CTL_BA_WINDOW GENMASK(7, 2)
  115. #define MT_TXWI_PKTID_PROBE BIT(7)
  116. struct mt76x2_txwi {
  117. __le16 flags;
  118. __le16 rate;
  119. u8 ack_ctl;
  120. u8 wcid;
  121. __le16 len_ctl;
  122. __le32 iv;
  123. __le32 eiv;
  124. u8 aid;
  125. u8 txstream;
  126. u8 ctl2;
  127. u8 pktid;
  128. } __packed __aligned(4);
  129. static inline struct mt76x2_tx_info *
  130. mt76x2_skb_tx_info(struct sk_buff *skb)
  131. {
  132. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  133. return (void *) info->status.status_driver_data;
  134. }
  135. int mt76x2_mac_start(struct mt76x2_dev *dev);
  136. void mt76x2_mac_stop(struct mt76x2_dev *dev, bool force);
  137. void mt76x2_mac_resume(struct mt76x2_dev *dev);
  138. void mt76x2_mac_set_bssid(struct mt76x2_dev *dev, u8 idx, const u8 *addr);
  139. int mt76x2_mac_process_rx(struct mt76x2_dev *dev, struct sk_buff *skb,
  140. void *rxi);
  141. void mt76x2_mac_write_txwi(struct mt76x2_dev *dev, struct mt76x2_txwi *txwi,
  142. struct sk_buff *skb, struct mt76_wcid *wcid,
  143. struct ieee80211_sta *sta, int len);
  144. void mt76x2_mac_wcid_setup(struct mt76x2_dev *dev, u8 idx, u8 vif_idx, u8 *mac);
  145. int mt76x2_mac_wcid_set_key(struct mt76x2_dev *dev, u8 idx,
  146. struct ieee80211_key_conf *key);
  147. void mt76x2_mac_wcid_set_rate(struct mt76x2_dev *dev, struct mt76_wcid *wcid,
  148. const struct ieee80211_tx_rate *rate);
  149. void mt76x2_mac_wcid_set_drop(struct mt76x2_dev *dev, u8 idx, bool drop);
  150. int mt76x2_mac_shared_key_setup(struct mt76x2_dev *dev, u8 vif_idx, u8 key_idx,
  151. struct ieee80211_key_conf *key);
  152. int mt76x2_mac_set_beacon(struct mt76x2_dev *dev, u8 vif_idx,
  153. struct sk_buff *skb);
  154. void mt76x2_mac_set_beacon_enable(struct mt76x2_dev *dev, u8 vif_idx, bool val);
  155. void mt76x2_mac_poll_tx_status(struct mt76x2_dev *dev, bool irq);
  156. void mt76x2_mac_process_tx_status_fifo(struct mt76x2_dev *dev);
  157. void mt76x2_mac_work(struct work_struct *work);
  158. #endif