ieee80211_rate.h 5.5 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. /* TODO: kdoc */
  19. struct rate_selection {
  20. /* Selected transmission rate */
  21. struct ieee80211_rate *rate;
  22. /* Non-ERP rate to use if mac80211 decides it cannot use an ERP rate */
  23. struct ieee80211_rate *nonerp;
  24. /* probe with this rate, or NULL for no probing */
  25. struct ieee80211_rate *probe;
  26. };
  27. struct rate_control_ops {
  28. struct module *module;
  29. const char *name;
  30. void (*tx_status)(void *priv, struct net_device *dev,
  31. struct sk_buff *skb,
  32. struct ieee80211_tx_status *status);
  33. void (*get_rate)(void *priv, struct net_device *dev,
  34. struct ieee80211_supported_band *band,
  35. struct sk_buff *skb,
  36. struct rate_selection *sel);
  37. void (*rate_init)(void *priv, void *priv_sta,
  38. struct ieee80211_local *local, struct sta_info *sta);
  39. void (*clear)(void *priv);
  40. void *(*alloc)(struct ieee80211_local *local);
  41. void (*free)(void *priv);
  42. void *(*alloc_sta)(void *priv, gfp_t gfp);
  43. void (*free_sta)(void *priv, void *priv_sta);
  44. int (*add_attrs)(void *priv, struct kobject *kobj);
  45. void (*remove_attrs)(void *priv, struct kobject *kobj);
  46. void (*add_sta_debugfs)(void *priv, void *priv_sta,
  47. struct dentry *dir);
  48. void (*remove_sta_debugfs)(void *priv, void *priv_sta);
  49. };
  50. struct rate_control_ref {
  51. struct rate_control_ops *ops;
  52. void *priv;
  53. struct kref kref;
  54. };
  55. int ieee80211_rate_control_register(struct rate_control_ops *ops);
  56. void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
  57. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  58. * first available algorithm. */
  59. struct rate_control_ref *rate_control_alloc(const char *name,
  60. struct ieee80211_local *local);
  61. void rate_control_get_rate(struct net_device *dev,
  62. struct ieee80211_supported_band *sband,
  63. struct sk_buff *skb,
  64. struct rate_selection *sel);
  65. struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
  66. void rate_control_put(struct rate_control_ref *ref);
  67. static inline void rate_control_tx_status(struct net_device *dev,
  68. struct sk_buff *skb,
  69. struct ieee80211_tx_status *status)
  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, status);
  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 int
  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. static inline struct ieee80211_rate *
  133. rate_lowest(struct ieee80211_local *local,
  134. struct ieee80211_supported_band *sband,
  135. struct sta_info *sta)
  136. {
  137. return &sband->bitrates[rate_lowest_index(local, sband, sta)];
  138. }
  139. /* functions for rate control related to a device */
  140. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  141. const char *name);
  142. void rate_control_deinitialize(struct ieee80211_local *local);
  143. /* Rate control algorithms */
  144. #if defined(RC80211_SIMPLE_COMPILE) || \
  145. (defined(CONFIG_MAC80211_RC_SIMPLE) && \
  146. !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE))
  147. extern int rc80211_simple_init(void);
  148. extern void rc80211_simple_exit(void);
  149. #else
  150. static inline int rc80211_simple_init(void)
  151. {
  152. return 0;
  153. }
  154. static inline void rc80211_simple_exit(void)
  155. {
  156. }
  157. #endif
  158. #if defined(RC80211_PID_COMPILE) || \
  159. (defined(CONFIG_MAC80211_RC_PID) && \
  160. !defined(CONFIG_MAC80211_RC_PID_MODULE))
  161. extern int rc80211_pid_init(void);
  162. extern void rc80211_pid_exit(void);
  163. #else
  164. static inline int rc80211_pid_init(void)
  165. {
  166. return 0;
  167. }
  168. static inline void rc80211_pid_exit(void)
  169. {
  170. }
  171. #endif
  172. #endif /* IEEE80211_RATE_H */