mt76_connac.h 3.5 KB

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