rate.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /**
  20. * struct rate_selection - rate selection for rate control algos
  21. * @rate: selected transmission rate index
  22. * @nonerp: Non-ERP rate to use instead if ERP cannot be used
  23. * @probe: rate for probing (or -1)
  24. *
  25. */
  26. struct rate_selection {
  27. s8 rate_idx, nonerp_idx, probe_idx;
  28. };
  29. struct rate_control_ops {
  30. struct module *module;
  31. const char *name;
  32. void (*tx_status)(void *priv, struct net_device *dev,
  33. struct sk_buff *skb);
  34. void (*get_rate)(void *priv, struct net_device *dev,
  35. struct ieee80211_supported_band *band,
  36. struct sk_buff *skb,
  37. struct rate_selection *sel);
  38. void (*rate_init)(void *priv, void *priv_sta,
  39. struct ieee80211_local *local, struct sta_info *sta);
  40. void (*clear)(void *priv);
  41. void *(*alloc)(struct ieee80211_local *local);
  42. void (*free)(void *priv);
  43. void *(*alloc_sta)(void *priv, gfp_t gfp);
  44. void (*free_sta)(void *priv, void *priv_sta);
  45. int (*add_attrs)(void *priv, struct kobject *kobj);
  46. void (*remove_attrs)(void *priv, struct kobject *kobj);
  47. void (*add_sta_debugfs)(void *priv, void *priv_sta,
  48. struct dentry *dir);
  49. void (*remove_sta_debugfs)(void *priv, void *priv_sta);
  50. };
  51. struct rate_control_ref {
  52. struct rate_control_ops *ops;
  53. void *priv;
  54. struct kref kref;
  55. };
  56. int ieee80211_rate_control_register(struct rate_control_ops *ops);
  57. void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
  58. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  59. * first available algorithm. */
  60. struct rate_control_ref *rate_control_alloc(const char *name,
  61. struct ieee80211_local *local);
  62. void rate_control_get_rate(struct net_device *dev,
  63. struct ieee80211_supported_band *sband,
  64. struct sk_buff *skb,
  65. struct rate_selection *sel);
  66. struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
  67. void rate_control_put(struct rate_control_ref *ref);
  68. static inline void rate_control_tx_status(struct net_device *dev,
  69. struct sk_buff *skb)
  70. {
  71. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  72. struct rate_control_ref *ref = local->rate_ctrl;
  73. ref->ops->tx_status(ref->priv, dev, skb);
  74. }
  75. static inline void rate_control_rate_init(struct sta_info *sta,
  76. struct ieee80211_local *local)
  77. {
  78. struct rate_control_ref *ref = sta->rate_ctrl;
  79. ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
  80. }
  81. static inline void rate_control_clear(struct ieee80211_local *local)
  82. {
  83. struct rate_control_ref *ref = local->rate_ctrl;
  84. ref->ops->clear(ref->priv);
  85. }
  86. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  87. gfp_t gfp)
  88. {
  89. return ref->ops->alloc_sta(ref->priv, gfp);
  90. }
  91. static inline void rate_control_free_sta(struct rate_control_ref *ref,
  92. void *priv)
  93. {
  94. ref->ops->free_sta(ref->priv, priv);
  95. }
  96. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  97. {
  98. #ifdef CONFIG_MAC80211_DEBUGFS
  99. struct rate_control_ref *ref = sta->rate_ctrl;
  100. if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
  101. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  102. sta->debugfs.dir);
  103. #endif
  104. }
  105. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  106. {
  107. #ifdef CONFIG_MAC80211_DEBUGFS
  108. struct rate_control_ref *ref = sta->rate_ctrl;
  109. if (ref->ops->remove_sta_debugfs)
  110. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  111. #endif
  112. }
  113. static inline int rate_supported(struct sta_info *sta,
  114. enum ieee80211_band band,
  115. int index)
  116. {
  117. return (sta == NULL || sta->supp_rates[band] & BIT(index));
  118. }
  119. static inline s8
  120. rate_lowest_index(struct ieee80211_local *local,
  121. struct ieee80211_supported_band *sband,
  122. struct sta_info *sta)
  123. {
  124. int i;
  125. for (i = 0; i < sband->n_bitrates; i++)
  126. if (rate_supported(sta, sband->band, i))
  127. return i;
  128. /* warn when we cannot find a rate. */
  129. WARN_ON(1);
  130. return 0;
  131. }
  132. /* functions for rate control related to a device */
  133. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  134. const char *name);
  135. void rate_control_deinitialize(struct ieee80211_local *local);
  136. /* Rate control algorithms */
  137. #ifdef CONFIG_MAC80211_RC_PID
  138. extern int rc80211_pid_init(void);
  139. extern void rc80211_pid_exit(void);
  140. #else
  141. static inline int rc80211_pid_init(void)
  142. {
  143. return 0;
  144. }
  145. static inline void rc80211_pid_exit(void)
  146. {
  147. }
  148. #endif
  149. #endif /* IEEE80211_RATE_H */