rate.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005, Devicescape Software, Inc.
  4. * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #ifndef IEEE80211_RATE_H
  11. #define IEEE80211_RATE_H
  12. #include <linux/netdevice.h>
  13. #include <linux/skbuff.h>
  14. #include <linux/types.h>
  15. #include <net/mac80211.h>
  16. #include "ieee80211_i.h"
  17. #include "sta_info.h"
  18. #include "driver-ops.h"
  19. struct rate_control_ref {
  20. struct ieee80211_local *local;
  21. const struct rate_control_ops *ops;
  22. void *priv;
  23. };
  24. void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
  25. struct sta_info *sta,
  26. struct ieee80211_tx_rate_control *txrc);
  27. static inline void rate_control_tx_status(struct ieee80211_local *local,
  28. struct ieee80211_supported_band *sband,
  29. struct sta_info *sta,
  30. struct sk_buff *skb)
  31. {
  32. struct rate_control_ref *ref = local->rate_ctrl;
  33. struct ieee80211_sta *ista = &sta->sta;
  34. void *priv_sta = sta->rate_ctrl_priv;
  35. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  36. if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  37. return;
  38. spin_lock_bh(&sta->rate_ctrl_lock);
  39. if (ref->ops->tx_status)
  40. ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
  41. else
  42. ref->ops->tx_status_noskb(ref->priv, sband, ista, priv_sta, info);
  43. spin_unlock_bh(&sta->rate_ctrl_lock);
  44. }
  45. static inline void
  46. rate_control_tx_status_noskb(struct ieee80211_local *local,
  47. struct ieee80211_supported_band *sband,
  48. struct sta_info *sta,
  49. struct ieee80211_tx_info *info)
  50. {
  51. struct rate_control_ref *ref = local->rate_ctrl;
  52. struct ieee80211_sta *ista = &sta->sta;
  53. void *priv_sta = sta->rate_ctrl_priv;
  54. if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  55. return;
  56. if (WARN_ON_ONCE(!ref->ops->tx_status_noskb))
  57. return;
  58. spin_lock_bh(&sta->rate_ctrl_lock);
  59. ref->ops->tx_status_noskb(ref->priv, sband, ista, priv_sta, info);
  60. spin_unlock_bh(&sta->rate_ctrl_lock);
  61. }
  62. static inline void rate_control_rate_init(struct sta_info *sta)
  63. {
  64. struct ieee80211_local *local = sta->sdata->local;
  65. struct rate_control_ref *ref = sta->rate_ctrl;
  66. struct ieee80211_sta *ista = &sta->sta;
  67. void *priv_sta = sta->rate_ctrl_priv;
  68. struct ieee80211_supported_band *sband;
  69. struct ieee80211_chanctx_conf *chanctx_conf;
  70. ieee80211_sta_set_rx_nss(sta);
  71. if (!ref)
  72. return;
  73. rcu_read_lock();
  74. chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf);
  75. if (WARN_ON(!chanctx_conf)) {
  76. rcu_read_unlock();
  77. return;
  78. }
  79. sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band];
  80. spin_lock_bh(&sta->rate_ctrl_lock);
  81. ref->ops->rate_init(ref->priv, sband, &chanctx_conf->def, ista,
  82. priv_sta);
  83. spin_unlock_bh(&sta->rate_ctrl_lock);
  84. rcu_read_unlock();
  85. set_sta_flag(sta, WLAN_STA_RATE_CONTROL);
  86. }
  87. static inline void rate_control_rate_update(struct ieee80211_local *local,
  88. struct ieee80211_supported_band *sband,
  89. struct sta_info *sta, u32 changed)
  90. {
  91. struct rate_control_ref *ref = local->rate_ctrl;
  92. struct ieee80211_sta *ista = &sta->sta;
  93. void *priv_sta = sta->rate_ctrl_priv;
  94. struct ieee80211_chanctx_conf *chanctx_conf;
  95. if (ref && ref->ops->rate_update) {
  96. rcu_read_lock();
  97. chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf);
  98. if (WARN_ON(!chanctx_conf)) {
  99. rcu_read_unlock();
  100. return;
  101. }
  102. spin_lock_bh(&sta->rate_ctrl_lock);
  103. ref->ops->rate_update(ref->priv, sband, &chanctx_conf->def,
  104. ista, priv_sta, changed);
  105. spin_unlock_bh(&sta->rate_ctrl_lock);
  106. rcu_read_unlock();
  107. }
  108. drv_sta_rc_update(local, sta->sdata, &sta->sta, changed);
  109. }
  110. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  111. struct sta_info *sta, gfp_t gfp)
  112. {
  113. spin_lock_init(&sta->rate_ctrl_lock);
  114. return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp);
  115. }
  116. static inline void rate_control_free_sta(struct sta_info *sta)
  117. {
  118. struct rate_control_ref *ref = sta->rate_ctrl;
  119. struct ieee80211_sta *ista = &sta->sta;
  120. void *priv_sta = sta->rate_ctrl_priv;
  121. ref->ops->free_sta(ref->priv, ista, priv_sta);
  122. }
  123. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  124. {
  125. #ifdef CONFIG_MAC80211_DEBUGFS
  126. struct rate_control_ref *ref = sta->rate_ctrl;
  127. if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
  128. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  129. sta->debugfs.dir);
  130. #endif
  131. }
  132. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  133. {
  134. #ifdef CONFIG_MAC80211_DEBUGFS
  135. struct rate_control_ref *ref = sta->rate_ctrl;
  136. if (ref && ref->ops->remove_sta_debugfs)
  137. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  138. #endif
  139. }
  140. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  141. * first available algorithm. */
  142. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  143. const char *name);
  144. void rate_control_deinitialize(struct ieee80211_local *local);
  145. /* Rate control algorithms */
  146. #ifdef CONFIG_MAC80211_RC_MINSTREL
  147. int rc80211_minstrel_init(void);
  148. void rc80211_minstrel_exit(void);
  149. #else
  150. static inline int rc80211_minstrel_init(void)
  151. {
  152. return 0;
  153. }
  154. static inline void rc80211_minstrel_exit(void)
  155. {
  156. }
  157. #endif
  158. #ifdef CONFIG_MAC80211_RC_MINSTREL_HT
  159. int rc80211_minstrel_ht_init(void);
  160. void rc80211_minstrel_ht_exit(void);
  161. #else
  162. static inline int rc80211_minstrel_ht_init(void)
  163. {
  164. return 0;
  165. }
  166. static inline void rc80211_minstrel_ht_exit(void)
  167. {
  168. }
  169. #endif
  170. #endif /* IEEE80211_RATE_H */