ieee80211_rate.h 5.4 KB

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