rate.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. 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. if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  36. return;
  37. ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
  38. }
  39. static inline void rate_control_rate_init(struct sta_info *sta)
  40. {
  41. struct ieee80211_local *local = sta->sdata->local;
  42. struct rate_control_ref *ref = sta->rate_ctrl;
  43. struct ieee80211_sta *ista = &sta->sta;
  44. void *priv_sta = sta->rate_ctrl_priv;
  45. struct ieee80211_supported_band *sband;
  46. struct ieee80211_chanctx_conf *chanctx_conf;
  47. if (!ref)
  48. return;
  49. rcu_read_lock();
  50. chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf);
  51. if (WARN_ON(!chanctx_conf)) {
  52. rcu_read_unlock();
  53. return;
  54. }
  55. sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band];
  56. rcu_read_unlock();
  57. ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
  58. set_sta_flag(sta, WLAN_STA_RATE_CONTROL);
  59. }
  60. static inline void rate_control_rate_update(struct ieee80211_local *local,
  61. struct ieee80211_supported_band *sband,
  62. struct sta_info *sta, u32 changed)
  63. {
  64. struct rate_control_ref *ref = local->rate_ctrl;
  65. struct ieee80211_sta *ista = &sta->sta;
  66. void *priv_sta = sta->rate_ctrl_priv;
  67. if (ref && ref->ops->rate_update)
  68. ref->ops->rate_update(ref->priv, sband, ista,
  69. priv_sta, changed);
  70. drv_sta_rc_update(local, sta->sdata, &sta->sta, changed);
  71. }
  72. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  73. struct ieee80211_sta *sta,
  74. gfp_t gfp)
  75. {
  76. return ref->ops->alloc_sta(ref->priv, sta, gfp);
  77. }
  78. static inline void rate_control_free_sta(struct sta_info *sta)
  79. {
  80. struct rate_control_ref *ref = sta->rate_ctrl;
  81. struct ieee80211_sta *ista = &sta->sta;
  82. void *priv_sta = sta->rate_ctrl_priv;
  83. ref->ops->free_sta(ref->priv, ista, priv_sta);
  84. }
  85. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  86. {
  87. #ifdef CONFIG_MAC80211_DEBUGFS
  88. struct rate_control_ref *ref = sta->rate_ctrl;
  89. if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
  90. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  91. sta->debugfs.dir);
  92. #endif
  93. }
  94. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  95. {
  96. #ifdef CONFIG_MAC80211_DEBUGFS
  97. struct rate_control_ref *ref = sta->rate_ctrl;
  98. if (ref && ref->ops->remove_sta_debugfs)
  99. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  100. #endif
  101. }
  102. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  103. * first available algorithm. */
  104. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  105. const char *name);
  106. void rate_control_deinitialize(struct ieee80211_local *local);
  107. /* Rate control algorithms */
  108. #ifdef CONFIG_MAC80211_RC_PID
  109. extern int rc80211_pid_init(void);
  110. extern void rc80211_pid_exit(void);
  111. #else
  112. static inline int rc80211_pid_init(void)
  113. {
  114. return 0;
  115. }
  116. static inline void rc80211_pid_exit(void)
  117. {
  118. }
  119. #endif
  120. #ifdef CONFIG_MAC80211_RC_MINSTREL
  121. extern int rc80211_minstrel_init(void);
  122. extern void rc80211_minstrel_exit(void);
  123. #else
  124. static inline int rc80211_minstrel_init(void)
  125. {
  126. return 0;
  127. }
  128. static inline void rc80211_minstrel_exit(void)
  129. {
  130. }
  131. #endif
  132. #ifdef CONFIG_MAC80211_RC_MINSTREL_HT
  133. extern int rc80211_minstrel_ht_init(void);
  134. extern void rc80211_minstrel_ht_exit(void);
  135. #else
  136. static inline int rc80211_minstrel_ht_init(void)
  137. {
  138. return 0;
  139. }
  140. static inline void rc80211_minstrel_ht_exit(void)
  141. {
  142. }
  143. #endif
  144. #endif /* IEEE80211_RATE_H */