rate.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 <linux/kref.h>
  16. #include <net/mac80211.h>
  17. #include "ieee80211_i.h"
  18. #include "sta_info.h"
  19. struct rate_control_ref {
  20. struct ieee80211_local *local;
  21. struct rate_control_ops *ops;
  22. void *priv;
  23. struct kref kref;
  24. };
  25. void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
  26. struct sta_info *sta,
  27. struct ieee80211_tx_rate_control *txrc);
  28. struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
  29. void rate_control_put(struct rate_control_ref *ref);
  30. static inline void rate_control_tx_status(struct ieee80211_local *local,
  31. struct ieee80211_supported_band *sband,
  32. struct sta_info *sta,
  33. struct sk_buff *skb)
  34. {
  35. struct rate_control_ref *ref = local->rate_ctrl;
  36. struct ieee80211_sta *ista = &sta->sta;
  37. void *priv_sta = sta->rate_ctrl_priv;
  38. if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL))
  39. return;
  40. ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
  41. }
  42. static inline void rate_control_rate_init(struct sta_info *sta)
  43. {
  44. struct ieee80211_local *local = sta->sdata->local;
  45. struct rate_control_ref *ref = sta->rate_ctrl;
  46. struct ieee80211_sta *ista = &sta->sta;
  47. void *priv_sta = sta->rate_ctrl_priv;
  48. struct ieee80211_supported_band *sband;
  49. if (!ref)
  50. return;
  51. sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
  52. ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
  53. set_sta_flag(sta, WLAN_STA_RATE_CONTROL);
  54. }
  55. static inline void rate_control_rate_update(struct ieee80211_local *local,
  56. struct ieee80211_supported_band *sband,
  57. struct sta_info *sta, u32 changed,
  58. enum nl80211_channel_type oper_chan_type)
  59. {
  60. struct rate_control_ref *ref = local->rate_ctrl;
  61. struct ieee80211_sta *ista = &sta->sta;
  62. void *priv_sta = sta->rate_ctrl_priv;
  63. if (ref && ref->ops->rate_update)
  64. ref->ops->rate_update(ref->priv, sband, ista,
  65. priv_sta, changed, oper_chan_type);
  66. }
  67. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  68. struct ieee80211_sta *sta,
  69. gfp_t gfp)
  70. {
  71. return ref->ops->alloc_sta(ref->priv, sta, gfp);
  72. }
  73. static inline void rate_control_free_sta(struct sta_info *sta)
  74. {
  75. struct rate_control_ref *ref = sta->rate_ctrl;
  76. struct ieee80211_sta *ista = &sta->sta;
  77. void *priv_sta = sta->rate_ctrl_priv;
  78. ref->ops->free_sta(ref->priv, ista, priv_sta);
  79. }
  80. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  81. {
  82. #ifdef CONFIG_MAC80211_DEBUGFS
  83. struct rate_control_ref *ref = sta->rate_ctrl;
  84. if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
  85. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  86. sta->debugfs.dir);
  87. #endif
  88. }
  89. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  90. {
  91. #ifdef CONFIG_MAC80211_DEBUGFS
  92. struct rate_control_ref *ref = sta->rate_ctrl;
  93. if (ref && ref->ops->remove_sta_debugfs)
  94. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  95. #endif
  96. }
  97. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  98. * first available algorithm. */
  99. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  100. const char *name);
  101. void rate_control_deinitialize(struct ieee80211_local *local);
  102. /* Rate control algorithms */
  103. #ifdef CONFIG_MAC80211_RC_PID
  104. extern int rc80211_pid_init(void);
  105. extern void rc80211_pid_exit(void);
  106. #else
  107. static inline int rc80211_pid_init(void)
  108. {
  109. return 0;
  110. }
  111. static inline void rc80211_pid_exit(void)
  112. {
  113. }
  114. #endif
  115. #ifdef CONFIG_MAC80211_RC_MINSTREL
  116. extern int rc80211_minstrel_init(void);
  117. extern void rc80211_minstrel_exit(void);
  118. #else
  119. static inline int rc80211_minstrel_init(void)
  120. {
  121. return 0;
  122. }
  123. static inline void rc80211_minstrel_exit(void)
  124. {
  125. }
  126. #endif
  127. #ifdef CONFIG_MAC80211_RC_MINSTREL_HT
  128. extern int rc80211_minstrel_ht_init(void);
  129. extern void rc80211_minstrel_ht_exit(void);
  130. #else
  131. static inline int rc80211_minstrel_ht_init(void)
  132. {
  133. return 0;
  134. }
  135. static inline void rc80211_minstrel_ht_exit(void)
  136. {
  137. }
  138. #endif
  139. #endif /* IEEE80211_RATE_H */