mt76x02.h 7.2 KB

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