mt76_connac.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* SPDX-License-Identifier: ISC */
  2. /* Copyright (C) 2020 MediaTek Inc. */
  3. #ifndef __MT76_CONNAC_H
  4. #define __MT76_CONNAC_H
  5. #include "mt76.h"
  6. #define MT76_CONNAC_SCAN_IE_LEN 600
  7. #define MT76_CONNAC_MAX_NUM_SCHED_SCAN_INTERVAL 10
  8. #define MT76_CONNAC_MAX_TIME_SCHED_SCAN_INTERVAL U16_MAX
  9. #define MT76_CONNAC_MAX_SCHED_SCAN_SSID 10
  10. #define MT76_CONNAC_MAX_SCAN_MATCH 16
  11. #define MT76_CONNAC_COREDUMP_TIMEOUT (HZ / 20)
  12. #define MT76_CONNAC_COREDUMP_SZ (1300 * 1024)
  13. enum {
  14. CMD_CBW_20MHZ = IEEE80211_STA_RX_BW_20,
  15. CMD_CBW_40MHZ = IEEE80211_STA_RX_BW_40,
  16. CMD_CBW_80MHZ = IEEE80211_STA_RX_BW_80,
  17. CMD_CBW_160MHZ = IEEE80211_STA_RX_BW_160,
  18. CMD_CBW_10MHZ,
  19. CMD_CBW_5MHZ,
  20. CMD_CBW_8080MHZ,
  21. CMD_HE_MCS_BW80 = 0,
  22. CMD_HE_MCS_BW160,
  23. CMD_HE_MCS_BW8080,
  24. CMD_HE_MCS_BW_NUM
  25. };
  26. enum {
  27. HW_BSSID_0 = 0x0,
  28. HW_BSSID_1,
  29. HW_BSSID_2,
  30. HW_BSSID_3,
  31. HW_BSSID_MAX = HW_BSSID_3,
  32. EXT_BSSID_START = 0x10,
  33. EXT_BSSID_1,
  34. EXT_BSSID_15 = 0x1f,
  35. EXT_BSSID_MAX = EXT_BSSID_15,
  36. REPEATER_BSSID_START = 0x20,
  37. REPEATER_BSSID_MAX = 0x3f,
  38. };
  39. struct mt76_connac_pm {
  40. bool enable;
  41. bool ds_enable;
  42. bool suspended;
  43. spinlock_t txq_lock;
  44. struct {
  45. struct mt76_wcid *wcid;
  46. struct sk_buff *skb;
  47. } tx_q[IEEE80211_NUM_ACS];
  48. struct work_struct wake_work;
  49. wait_queue_head_t wait;
  50. struct {
  51. spinlock_t lock;
  52. u32 count;
  53. } wake;
  54. struct mutex mutex;
  55. struct delayed_work ps_work;
  56. unsigned long last_activity;
  57. unsigned long idle_timeout;
  58. struct {
  59. unsigned long last_wake_event;
  60. unsigned long awake_time;
  61. unsigned long last_doze_event;
  62. unsigned long doze_time;
  63. unsigned int lp_wake;
  64. } stats;
  65. };
  66. struct mt76_connac_coredump {
  67. struct sk_buff_head msg_list;
  68. struct delayed_work work;
  69. unsigned long last_activity;
  70. };
  71. extern const struct wiphy_wowlan_support mt76_connac_wowlan_support;
  72. static inline bool is_mt7921(struct mt76_dev *dev)
  73. {
  74. return mt76_chip(dev) == 0x7961;
  75. }
  76. static inline bool is_mt7663(struct mt76_dev *dev)
  77. {
  78. return mt76_chip(dev) == 0x7663;
  79. }
  80. int mt76_connac_pm_wake(struct mt76_phy *phy, struct mt76_connac_pm *pm);
  81. void mt76_connac_power_save_sched(struct mt76_phy *phy,
  82. struct mt76_connac_pm *pm);
  83. void mt76_connac_free_pending_tx_skbs(struct mt76_connac_pm *pm,
  84. struct mt76_wcid *wcid);
  85. static inline bool
  86. mt76_connac_pm_ref(struct mt76_phy *phy, struct mt76_connac_pm *pm)
  87. {
  88. bool ret = false;
  89. spin_lock_bh(&pm->wake.lock);
  90. if (test_bit(MT76_STATE_PM, &phy->state))
  91. goto out;
  92. pm->wake.count++;
  93. ret = true;
  94. out:
  95. spin_unlock_bh(&pm->wake.lock);
  96. return ret;
  97. }
  98. static inline void
  99. mt76_connac_pm_unref(struct mt76_phy *phy, struct mt76_connac_pm *pm)
  100. {
  101. spin_lock_bh(&pm->wake.lock);
  102. pm->last_activity = jiffies;
  103. if (--pm->wake.count == 0 &&
  104. test_bit(MT76_STATE_MCU_RUNNING, &phy->state))
  105. mt76_connac_power_save_sched(phy, pm);
  106. spin_unlock_bh(&pm->wake.lock);
  107. }
  108. static inline bool
  109. mt76_connac_skip_fw_pmctrl(struct mt76_phy *phy, struct mt76_connac_pm *pm)
  110. {
  111. struct mt76_dev *dev = phy->dev;
  112. bool ret;
  113. if (dev->token_count)
  114. return true;
  115. spin_lock_bh(&pm->wake.lock);
  116. ret = pm->wake.count || test_and_set_bit(MT76_STATE_PM, &phy->state);
  117. spin_unlock_bh(&pm->wake.lock);
  118. return ret;
  119. }
  120. static inline void
  121. mt76_connac_mutex_acquire(struct mt76_dev *dev, struct mt76_connac_pm *pm)
  122. __acquires(&dev->mutex)
  123. {
  124. mutex_lock(&dev->mutex);
  125. mt76_connac_pm_wake(&dev->phy, pm);
  126. }
  127. static inline void
  128. mt76_connac_mutex_release(struct mt76_dev *dev, struct mt76_connac_pm *pm)
  129. __releases(&dev->mutex)
  130. {
  131. mt76_connac_power_save_sched(&dev->phy, pm);
  132. mutex_unlock(&dev->mutex);
  133. }
  134. void mt76_connac_pm_queue_skb(struct ieee80211_hw *hw,
  135. struct mt76_connac_pm *pm,
  136. struct mt76_wcid *wcid,
  137. struct sk_buff *skb);
  138. void mt76_connac_pm_dequeue_skbs(struct mt76_phy *phy,
  139. struct mt76_connac_pm *pm);
  140. #endif /* __MT76_CONNAC_H */