mt76x02.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* SPDX-License-Identifier: ISC */
  2. /*
  3. * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
  4. * Copyright (C) 2018 Stanislaw Gruszka <stf_xl@wp.pl>
  5. */
  6. #ifndef __MT76x02_H
  7. #define __MT76x02_H
  8. #include <linux/kfifo.h>
  9. #include "mt76.h"
  10. #include "mt76x02_regs.h"
  11. #include "mt76x02_mac.h"
  12. #include "mt76x02_dfs.h"
  13. #include "mt76x02_dma.h"
  14. #define MT76x02_TX_RING_SIZE 512
  15. #define MT76x02_PSD_RING_SIZE 128
  16. #define MT76x02_N_WCIDS 128
  17. #define MT_CALIBRATE_INTERVAL HZ
  18. #define MT_MAC_WORK_INTERVAL (HZ / 10)
  19. #define MT_WATCHDOG_TIME (HZ / 10)
  20. #define MT_TX_HANG_TH 10
  21. #define MT_MAX_CHAINS 2
  22. struct mt76x02_rx_freq_cal {
  23. s8 high_gain[MT_MAX_CHAINS];
  24. s8 rssi_offset[MT_MAX_CHAINS];
  25. s8 lna_gain;
  26. u32 mcu_gain;
  27. s16 temp_offset;
  28. u8 freq_offset;
  29. };
  30. struct mt76x02_calibration {
  31. struct mt76x02_rx_freq_cal rx;
  32. u8 agc_gain_init[MT_MAX_CHAINS];
  33. u8 agc_gain_cur[MT_MAX_CHAINS];
  34. u16 false_cca;
  35. s8 avg_rssi_all;
  36. s8 agc_gain_adjust;
  37. s8 agc_lowest_gain;
  38. s8 low_gain;
  39. s8 temp_vco;
  40. s8 temp;
  41. bool init_cal_done;
  42. bool tssi_cal_done;
  43. bool tssi_comp_pending;
  44. bool dpd_cal_done;
  45. bool channel_cal_done;
  46. bool gain_init_done;
  47. int tssi_target;
  48. s8 tssi_dc;
  49. };
  50. struct mt76x02_beacon_ops {
  51. unsigned int nslots;
  52. unsigned int slot_size;
  53. void (*pre_tbtt_enable)(struct mt76x02_dev *dev, bool en);
  54. void (*beacon_enable)(struct mt76x02_dev *dev, bool en);
  55. };
  56. #define mt76x02_beacon_enable(dev, enable) \
  57. (dev)->beacon_ops->beacon_enable(dev, enable)
  58. #define mt76x02_pre_tbtt_enable(dev, enable) \
  59. (dev)->beacon_ops->pre_tbtt_enable(dev, enable)
  60. struct mt76x02_rate_power {
  61. union {
  62. struct {
  63. s8 cck[4];
  64. s8 ofdm[8];
  65. s8 ht[16];
  66. s8 vht[2];
  67. };
  68. s8 all[30];
  69. };
  70. };
  71. struct mt76x02_dev {
  72. union { /* must be first */
  73. struct mt76_dev mt76;
  74. struct mt76_phy mphy;
  75. };
  76. struct mac_address macaddr_list[8];
  77. struct mutex phy_mutex;
  78. u8 txdone_seq;
  79. DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status);
  80. spinlock_t txstatus_fifo_lock;
  81. u32 tx_airtime;
  82. u32 ampdu_ref;
  83. struct sk_buff *rx_head;
  84. struct delayed_work cal_work;
  85. struct delayed_work wdt_work;
  86. struct hrtimer pre_tbtt_timer;
  87. struct work_struct pre_tbtt_work;
  88. const struct mt76x02_beacon_ops *beacon_ops;
  89. u8 beacon_data_count;
  90. u8 tbtt_count;
  91. u32 tx_hang_reset;
  92. u8 tx_hang_check[4];
  93. u8 beacon_hang_check;
  94. u8 mcu_timeout;
  95. struct mt76x02_rate_power rate_power;
  96. struct mt76x02_calibration cal;
  97. int txpower_conf;
  98. s8 target_power;
  99. s8 target_power_delta[2];
  100. bool enable_tpc;
  101. bool no_2ghz;
  102. s16 coverage_class;
  103. u8 slottime;
  104. struct mt76x02_dfs_pattern_detector dfs_pd;
  105. /* edcca monitor */
  106. unsigned long ed_trigger_timeout;
  107. bool ed_tx_blocked;
  108. bool ed_monitor;
  109. u8 ed_monitor_enabled;
  110. u8 ed_monitor_learning;
  111. u8 ed_trigger;
  112. u8 ed_silent;
  113. ktime_t ed_time;
  114. };
  115. extern struct ieee80211_rate mt76x02_rates[12];
  116. int mt76x02_init_device(struct mt76x02_dev *dev);
  117. void mt76x02_configure_filter(struct ieee80211_hw *hw,
  118. unsigned int changed_flags,
  119. unsigned int *total_flags, u64 multicast);
  120. int mt76x02_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  121. struct ieee80211_sta *sta);
  122. void mt76x02_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  123. struct ieee80211_sta *sta);
  124. void mt76x02_config_mac_addr_list(struct mt76x02_dev *dev);
  125. int mt76x02_add_interface(struct ieee80211_hw *hw,
  126. struct ieee80211_vif *vif);
  127. void mt76x02_remove_interface(struct ieee80211_hw *hw,
  128. struct ieee80211_vif *vif);
  129. int mt76x02_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  130. struct ieee80211_ampdu_params *params);
  131. int mt76x02_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  132. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  133. struct ieee80211_key_conf *key);
  134. int mt76x02_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  135. unsigned int link_id, u16 queue,
  136. const struct ieee80211_tx_queue_params *params);
  137. void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
  138. struct ieee80211_vif *vif,
  139. struct ieee80211_sta *sta);
  140. s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev,
  141. const struct ieee80211_tx_rate *rate);
  142. s8 mt76x02_tx_get_txpwr_adj(struct mt76x02_dev *dev, s8 txpwr,
  143. s8 max_txpwr_adj);
  144. void mt76x02_wdt_work(struct work_struct *work);
  145. void mt76x02_tx_set_txpwr_auto(struct mt76x02_dev *dev, s8 txpwr);
  146. void mt76x02_set_tx_ackto(struct mt76x02_dev *dev);
  147. void mt76x02_set_coverage_class(struct ieee80211_hw *hw,
  148. s16 coverage_class);
  149. int mt76x02_set_rts_threshold(struct ieee80211_hw *hw, u32 val);
  150. void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len);
  151. bool mt76x02_tx_status_data(struct mt76_dev *mdev, u8 *update);
  152. void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
  153. struct sk_buff *skb, u32 *info);
  154. void mt76x02_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
  155. irqreturn_t mt76x02_irq_handler(int irq, void *dev_instance);
  156. void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
  157. struct sk_buff *skb);
  158. int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
  159. enum mt76_txq_id qid, struct mt76_wcid *wcid,
  160. struct ieee80211_sta *sta,
  161. struct mt76_tx_info *tx_info);
  162. void mt76x02_sw_scan_complete(struct ieee80211_hw *hw,
  163. struct ieee80211_vif *vif);
  164. void mt76x02_sta_ps(struct mt76_dev *dev, struct ieee80211_sta *sta, bool ps);
  165. void mt76x02_bss_info_changed(struct ieee80211_hw *hw,
  166. struct ieee80211_vif *vif,
  167. struct ieee80211_bss_conf *info, u64 changed);
  168. void mt76x02_reconfig_complete(struct ieee80211_hw *hw,
  169. enum ieee80211_reconfig_type reconfig_type);
  170. struct beacon_bc_data {
  171. struct mt76x02_dev *dev;
  172. struct sk_buff_head q;
  173. struct sk_buff *tail[8];
  174. };
  175. void mt76x02_init_beacon_config(struct mt76x02_dev *dev);
  176. void mt76x02e_init_beacon_config(struct mt76x02_dev *dev);
  177. void mt76x02_resync_beacon_timer(struct mt76x02_dev *dev);
  178. void mt76x02_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif);
  179. void mt76x02_enqueue_buffered_bc(struct mt76x02_dev *dev,
  180. struct beacon_bc_data *data,
  181. int max_nframes);
  182. void mt76x02_mac_start(struct mt76x02_dev *dev);
  183. void mt76x02_init_debugfs(struct mt76x02_dev *dev);
  184. static inline bool is_mt76x0(struct mt76x02_dev *dev)
  185. {
  186. return mt76_chip(&dev->mt76) == 0x7610 ||
  187. mt76_chip(&dev->mt76) == 0x7630 ||
  188. mt76_chip(&dev->mt76) == 0x7650;
  189. }
  190. static inline bool is_mt76x2(struct mt76x02_dev *dev)
  191. {
  192. return mt76_chip(&dev->mt76) == 0x7612 ||
  193. mt76_chip(&dev->mt76) == 0x7632 ||
  194. mt76_chip(&dev->mt76) == 0x7662 ||
  195. mt76_chip(&dev->mt76) == 0x7602;
  196. }
  197. static inline void mt76x02_irq_enable(struct mt76x02_dev *dev, u32 mask)
  198. {
  199. mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
  200. }
  201. static inline void mt76x02_irq_disable(struct mt76x02_dev *dev, u32 mask)
  202. {
  203. mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
  204. }
  205. static inline bool
  206. mt76x02_wait_for_txrx_idle(struct mt76_dev *dev)
  207. {
  208. return __mt76_poll_msec(dev, MT_MAC_STATUS,
  209. MT_MAC_STATUS_TX | MT_MAC_STATUS_RX,
  210. 0, 100);
  211. }
  212. static inline struct mt76x02_sta *
  213. mt76x02_rx_get_sta(struct mt76_dev *dev, u8 idx)
  214. {
  215. struct mt76_wcid *wcid;
  216. if (idx >= MT76x02_N_WCIDS)
  217. return NULL;
  218. wcid = rcu_dereference(dev->wcid[idx]);
  219. if (!wcid)
  220. return NULL;
  221. return container_of(wcid, struct mt76x02_sta, wcid);
  222. }
  223. static inline struct mt76_wcid *
  224. mt76x02_rx_get_sta_wcid(struct mt76x02_sta *sta, bool unicast)
  225. {
  226. if (!sta)
  227. return NULL;
  228. if (unicast)
  229. return &sta->wcid;
  230. else
  231. return &sta->vif->group_wcid;
  232. }
  233. #endif /* __MT76x02_H */