mt76x02.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /* SPDX-License-Identifier: ISC */
  2. /*
  3. * Copyright (C) 2016 Felix Fietkau <[email protected]>
  4. * Copyright (C) 2018 Stanislaw Gruszka <[email protected]>
  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_dev {
  61. union { /* must be first */
  62. struct mt76_dev mt76;
  63. struct mt76_phy mphy;
  64. };
  65. struct mac_address macaddr_list[8];
  66. struct mutex phy_mutex;
  67. u8 txdone_seq;
  68. DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x02_tx_status);
  69. spinlock_t txstatus_fifo_lock;
  70. u32 tx_airtime;
  71. u32 ampdu_ref;
  72. struct sk_buff *rx_head;
  73. struct delayed_work cal_work;
  74. struct delayed_work wdt_work;
  75. struct hrtimer pre_tbtt_timer;
  76. struct work_struct pre_tbtt_work;
  77. const struct mt76x02_beacon_ops *beacon_ops;
  78. u8 beacon_data_count;
  79. u8 tbtt_count;
  80. u32 tx_hang_reset;
  81. u8 tx_hang_check[4];
  82. u8 beacon_hang_check;
  83. u8 mcu_timeout;
  84. struct mt76x02_calibration cal;
  85. int txpower_conf;
  86. s8 target_power;
  87. s8 target_power_delta[2];
  88. bool enable_tpc;
  89. bool no_2ghz;
  90. s16 coverage_class;
  91. u8 slottime;
  92. struct mt76x02_dfs_pattern_detector dfs_pd;
  93. /* edcca monitor */
  94. unsigned long ed_trigger_timeout;
  95. bool ed_tx_blocked;
  96. bool ed_monitor;
  97. u8 ed_monitor_enabled;
  98. u8 ed_monitor_learning;
  99. u8 ed_trigger;
  100. u8 ed_silent;
  101. ktime_t ed_time;
  102. };
  103. extern struct ieee80211_rate mt76x02_rates[12];
  104. int mt76x02_init_device(struct mt76x02_dev *dev);
  105. void mt76x02_configure_filter(struct ieee80211_hw *hw,
  106. unsigned int changed_flags,
  107. unsigned int *total_flags, u64 multicast);
  108. int mt76x02_sta_add(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  109. struct ieee80211_sta *sta);
  110. void mt76x02_sta_remove(struct mt76_dev *mdev, struct ieee80211_vif *vif,
  111. struct ieee80211_sta *sta);
  112. void mt76x02_config_mac_addr_list(struct mt76x02_dev *dev);
  113. int mt76x02_add_interface(struct ieee80211_hw *hw,
  114. struct ieee80211_vif *vif);
  115. void mt76x02_remove_interface(struct ieee80211_hw *hw,
  116. struct ieee80211_vif *vif);
  117. int mt76x02_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  118. struct ieee80211_ampdu_params *params);
  119. int mt76x02_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  120. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  121. struct ieee80211_key_conf *key);
  122. int mt76x02_conf_tx(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  123. unsigned int link_id, u16 queue,
  124. const struct ieee80211_tx_queue_params *params);
  125. void mt76x02_sta_rate_tbl_update(struct ieee80211_hw *hw,
  126. struct ieee80211_vif *vif,
  127. struct ieee80211_sta *sta);
  128. s8 mt76x02_tx_get_max_txpwr_adj(struct mt76x02_dev *dev,
  129. const struct ieee80211_tx_rate *rate);
  130. s8 mt76x02_tx_get_txpwr_adj(struct mt76x02_dev *dev, s8 txpwr,
  131. s8 max_txpwr_adj);
  132. void mt76x02_wdt_work(struct work_struct *work);
  133. void mt76x02_tx_set_txpwr_auto(struct mt76x02_dev *dev, s8 txpwr);
  134. void mt76x02_set_tx_ackto(struct mt76x02_dev *dev);
  135. void mt76x02_set_coverage_class(struct ieee80211_hw *hw,
  136. s16 coverage_class);
  137. int mt76x02_set_rts_threshold(struct ieee80211_hw *hw, u32 val);
  138. void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len);
  139. bool mt76x02_tx_status_data(struct mt76_dev *mdev, u8 *update);
  140. void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
  141. struct sk_buff *skb);
  142. void mt76x02_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
  143. irqreturn_t mt76x02_irq_handler(int irq, void *dev_instance);
  144. void mt76x02_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
  145. struct sk_buff *skb);
  146. int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
  147. enum mt76_txq_id qid, struct mt76_wcid *wcid,
  148. struct ieee80211_sta *sta,
  149. struct mt76_tx_info *tx_info);
  150. void mt76x02_sw_scan_complete(struct ieee80211_hw *hw,
  151. struct ieee80211_vif *vif);
  152. void mt76x02_sta_ps(struct mt76_dev *dev, struct ieee80211_sta *sta, bool ps);
  153. void mt76x02_bss_info_changed(struct ieee80211_hw *hw,
  154. struct ieee80211_vif *vif,
  155. struct ieee80211_bss_conf *info, u64 changed);
  156. void mt76x02_reconfig_complete(struct ieee80211_hw *hw,
  157. enum ieee80211_reconfig_type reconfig_type);
  158. struct beacon_bc_data {
  159. struct mt76x02_dev *dev;
  160. struct sk_buff_head q;
  161. struct sk_buff *tail[8];
  162. };
  163. void mt76x02_init_beacon_config(struct mt76x02_dev *dev);
  164. void mt76x02e_init_beacon_config(struct mt76x02_dev *dev);
  165. void mt76x02_resync_beacon_timer(struct mt76x02_dev *dev);
  166. void mt76x02_update_beacon_iter(void *priv, u8 *mac, struct ieee80211_vif *vif);
  167. void mt76x02_enqueue_buffered_bc(struct mt76x02_dev *dev,
  168. struct beacon_bc_data *data,
  169. int max_nframes);
  170. void mt76x02_mac_start(struct mt76x02_dev *dev);
  171. void mt76x02_init_debugfs(struct mt76x02_dev *dev);
  172. static inline bool is_mt76x0(struct mt76x02_dev *dev)
  173. {
  174. return mt76_chip(&dev->mt76) == 0x7610 ||
  175. mt76_chip(&dev->mt76) == 0x7630 ||
  176. mt76_chip(&dev->mt76) == 0x7650;
  177. }
  178. static inline bool is_mt76x2(struct mt76x02_dev *dev)
  179. {
  180. return mt76_chip(&dev->mt76) == 0x7612 ||
  181. mt76_chip(&dev->mt76) == 0x7632 ||
  182. mt76_chip(&dev->mt76) == 0x7662 ||
  183. mt76_chip(&dev->mt76) == 0x7602;
  184. }
  185. static inline void mt76x02_irq_enable(struct mt76x02_dev *dev, u32 mask)
  186. {
  187. mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, 0, mask);
  188. }
  189. static inline void mt76x02_irq_disable(struct mt76x02_dev *dev, u32 mask)
  190. {
  191. mt76_set_irq_mask(&dev->mt76, MT_INT_MASK_CSR, mask, 0);
  192. }
  193. static inline bool
  194. mt76x02_wait_for_txrx_idle(struct mt76_dev *dev)
  195. {
  196. return __mt76_poll_msec(dev, MT_MAC_STATUS,
  197. MT_MAC_STATUS_TX | MT_MAC_STATUS_RX,
  198. 0, 100);
  199. }
  200. static inline struct mt76x02_sta *
  201. mt76x02_rx_get_sta(struct mt76_dev *dev, u8 idx)
  202. {
  203. struct mt76_wcid *wcid;
  204. if (idx >= MT76x02_N_WCIDS)
  205. return NULL;
  206. wcid = rcu_dereference(dev->wcid[idx]);
  207. if (!wcid)
  208. return NULL;
  209. return container_of(wcid, struct mt76x02_sta, wcid);
  210. }
  211. static inline struct mt76_wcid *
  212. mt76x02_rx_get_sta_wcid(struct mt76x02_sta *sta, bool unicast)
  213. {
  214. if (!sta)
  215. return NULL;
  216. if (unicast)
  217. return &sta->wcid;
  218. else
  219. return &sta->vif->group_wcid;
  220. }
  221. #endif /* __MT76x02_H */