mt76x2.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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_H
  17. #define __MT76x2_H
  18. #include <linux/device.h>
  19. #include <linux/dma-mapping.h>
  20. #include <linux/spinlock.h>
  21. #include <linux/skbuff.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/irq.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/mutex.h>
  26. #include <linux/bitops.h>
  27. #include <linux/kfifo.h>
  28. #define MT7662_FIRMWARE "mt7662.bin"
  29. #define MT7662_ROM_PATCH "mt7662_rom_patch.bin"
  30. #define MT7662_EEPROM_SIZE 512
  31. #define MT76x2_RX_RING_SIZE 256
  32. #define MT_RX_HEADROOM 32
  33. #define MT_MAX_CHAINS 2
  34. #define MT_CALIBRATE_INTERVAL HZ
  35. #include "mt76.h"
  36. #include "mt76x2_regs.h"
  37. #include "mt76x2_mac.h"
  38. #include "mt76x2_dfs.h"
  39. struct mt76x2_mcu {
  40. struct mutex mutex;
  41. wait_queue_head_t wait;
  42. struct sk_buff_head res_q;
  43. u32 msg_seq;
  44. };
  45. struct mt76x2_rx_freq_cal {
  46. s8 high_gain[MT_MAX_CHAINS];
  47. s8 rssi_offset[MT_MAX_CHAINS];
  48. s8 lna_gain;
  49. u32 mcu_gain;
  50. };
  51. struct mt76x2_calibration {
  52. struct mt76x2_rx_freq_cal rx;
  53. u8 agc_gain_init[MT_MAX_CHAINS];
  54. u8 agc_gain_cur[MT_MAX_CHAINS];
  55. int avg_rssi[MT_MAX_CHAINS];
  56. int avg_rssi_all;
  57. s8 agc_gain_adjust;
  58. s8 low_gain;
  59. u8 temp;
  60. bool init_cal_done;
  61. bool tssi_cal_done;
  62. bool tssi_comp_pending;
  63. bool dpd_cal_done;
  64. bool channel_cal_done;
  65. };
  66. struct mt76x2_dev {
  67. struct mt76_dev mt76; /* must be first */
  68. struct mac_address macaddr_list[8];
  69. struct mutex mutex;
  70. const u16 *beacon_offsets;
  71. unsigned long wcid_mask[128 / BITS_PER_LONG];
  72. int txpower_conf;
  73. int txpower_cur;
  74. u8 txdone_seq;
  75. DECLARE_KFIFO_PTR(txstatus_fifo, struct mt76x2_tx_status);
  76. struct mt76x2_mcu mcu;
  77. struct sk_buff *rx_head;
  78. struct tasklet_struct tx_tasklet;
  79. struct tasklet_struct pre_tbtt_tasklet;
  80. struct delayed_work cal_work;
  81. struct delayed_work mac_work;
  82. u32 aggr_stats[32];
  83. struct mt76_wcid global_wcid;
  84. struct mt76_wcid __rcu *wcid[128];
  85. spinlock_t irq_lock;
  86. u32 irqmask;
  87. struct sk_buff *beacons[8];
  88. u8 beacon_mask;
  89. u8 beacon_data_mask;
  90. u32 rev;
  91. u32 rxfilter;
  92. u16 chainmask;
  93. struct mt76x2_calibration cal;
  94. s8 target_power;
  95. s8 target_power_delta[2];
  96. struct mt76_rate_power rate_power;
  97. bool enable_tpc;
  98. u8 coverage_class;
  99. u8 slottime;
  100. struct mt76x2_dfs_pattern_detector dfs_pd;
  101. };
  102. struct mt76x2_vif {
  103. u8 idx;
  104. struct mt76_wcid group_wcid;
  105. };
  106. struct mt76x2_sta {
  107. struct mt76_wcid wcid; /* must be first */
  108. struct mt76x2_vif *vif;
  109. struct mt76x2_tx_status status;
  110. int n_frames;
  111. };
  112. static inline bool is_mt7612(struct mt76x2_dev *dev)
  113. {
  114. return (dev->rev >> 16) == 0x7612;
  115. }
  116. void mt76x2_set_irq_mask(struct mt76x2_dev *dev, u32 clear, u32 set);
  117. static inline void mt76x2_irq_enable(struct mt76x2_dev *dev, u32 mask)
  118. {
  119. mt76x2_set_irq_mask(dev, 0, mask);
  120. }
  121. static inline void mt76x2_irq_disable(struct mt76x2_dev *dev, u32 mask)
  122. {
  123. mt76x2_set_irq_mask(dev, mask, 0);
  124. }
  125. extern const struct ieee80211_ops mt76x2_ops;
  126. struct mt76x2_dev *mt76x2_alloc_device(struct device *pdev);
  127. int mt76x2_register_device(struct mt76x2_dev *dev);
  128. void mt76x2_init_debugfs(struct mt76x2_dev *dev);
  129. irqreturn_t mt76x2_irq_handler(int irq, void *dev_instance);
  130. void mt76x2_phy_power_on(struct mt76x2_dev *dev);
  131. int mt76x2_init_hardware(struct mt76x2_dev *dev);
  132. void mt76x2_stop_hardware(struct mt76x2_dev *dev);
  133. int mt76x2_eeprom_init(struct mt76x2_dev *dev);
  134. int mt76x2_apply_calibration_data(struct mt76x2_dev *dev, int channel);
  135. void mt76x2_set_tx_ackto(struct mt76x2_dev *dev);
  136. void mt76x2_phy_set_antenna(struct mt76x2_dev *dev);
  137. int mt76x2_phy_start(struct mt76x2_dev *dev);
  138. int mt76x2_phy_set_channel(struct mt76x2_dev *dev,
  139. struct cfg80211_chan_def *chandef);
  140. int mt76x2_phy_get_rssi(struct mt76x2_dev *dev, s8 rssi, int chain);
  141. void mt76x2_phy_calibrate(struct work_struct *work);
  142. void mt76x2_phy_set_txpower(struct mt76x2_dev *dev);
  143. int mt76x2_mcu_init(struct mt76x2_dev *dev);
  144. int mt76x2_mcu_set_channel(struct mt76x2_dev *dev, u8 channel, u8 bw,
  145. u8 bw_index, bool scan);
  146. int mt76x2_mcu_set_radio_state(struct mt76x2_dev *dev, bool on);
  147. int mt76x2_mcu_load_cr(struct mt76x2_dev *dev, u8 type, u8 temp_level,
  148. u8 channel);
  149. int mt76x2_mcu_cleanup(struct mt76x2_dev *dev);
  150. int mt76x2_dma_init(struct mt76x2_dev *dev);
  151. void mt76x2_dma_cleanup(struct mt76x2_dev *dev);
  152. void mt76x2_cleanup(struct mt76x2_dev *dev);
  153. int mt76x2_tx_queue_mcu(struct mt76x2_dev *dev, enum mt76_txq_id qid,
  154. struct sk_buff *skb, int cmd, int seq);
  155. void mt76x2_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control,
  156. struct sk_buff *skb);
  157. void mt76x2_tx_complete(struct mt76x2_dev *dev, struct sk_buff *skb);
  158. int mt76x2_tx_prepare_skb(struct mt76_dev *mdev, void *txwi,
  159. struct sk_buff *skb, struct mt76_queue *q,
  160. struct mt76_wcid *wcid, struct ieee80211_sta *sta,
  161. u32 *tx_info);
  162. void mt76x2_tx_complete_skb(struct mt76_dev *mdev, struct mt76_queue *q,
  163. struct mt76_queue_entry *e, bool flush);
  164. void mt76x2_pre_tbtt_tasklet(unsigned long arg);
  165. void mt76x2_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
  166. void mt76x2_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
  167. struct sk_buff *skb);
  168. void mt76x2_sta_ps(struct mt76_dev *dev, struct ieee80211_sta *sta, bool ps);
  169. void mt76x2_update_channel(struct mt76_dev *mdev);
  170. s8 mt76x2_tx_get_max_txpwr_adj(struct mt76x2_dev *dev,
  171. const struct ieee80211_tx_rate *rate);
  172. s8 mt76x2_tx_get_txpwr_adj(struct mt76x2_dev *dev, s8 txpwr, s8 max_txpwr_adj);
  173. void mt76x2_tx_set_txpwr_auto(struct mt76x2_dev *dev, s8 txpwr);
  174. #endif