rate.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /* TODO: kdoc */
  20. struct rate_selection {
  21. /* Selected transmission rate */
  22. struct ieee80211_rate *rate;
  23. /* Non-ERP rate to use if mac80211 decides it cannot use an ERP rate */
  24. struct ieee80211_rate *nonerp;
  25. /* probe with this rate, or NULL for no probing */
  26. struct ieee80211_rate *probe;
  27. };
  28. struct rate_control_ops {
  29. struct module *module;
  30. const char *name;
  31. void (*tx_status)(void *priv, struct net_device *dev,
  32. struct sk_buff *skb,
  33. struct ieee80211_tx_status *status);
  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. struct ieee80211_tx_status *status)
  71. {
  72. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  73. struct rate_control_ref *ref = local->rate_ctrl;
  74. ref->ops->tx_status(ref->priv, dev, skb, status);
  75. }
  76. static inline void rate_control_rate_init(struct sta_info *sta,
  77. struct ieee80211_local *local)
  78. {
  79. struct rate_control_ref *ref = sta->rate_ctrl;
  80. ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
  81. }
  82. static inline void rate_control_clear(struct ieee80211_local *local)
  83. {
  84. struct rate_control_ref *ref = local->rate_ctrl;
  85. ref->ops->clear(ref->priv);
  86. }
  87. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  88. gfp_t gfp)
  89. {
  90. return ref->ops->alloc_sta(ref->priv, gfp);
  91. }
  92. static inline void rate_control_free_sta(struct rate_control_ref *ref,
  93. void *priv)
  94. {
  95. ref->ops->free_sta(ref->priv, priv);
  96. }
  97. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  98. {
  99. #ifdef CONFIG_MAC80211_DEBUGFS
  100. struct rate_control_ref *ref = sta->rate_ctrl;
  101. if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
  102. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  103. sta->debugfs.dir);
  104. #endif
  105. }
  106. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  107. {
  108. #ifdef CONFIG_MAC80211_DEBUGFS
  109. struct rate_control_ref *ref = sta->rate_ctrl;
  110. if (ref->ops->remove_sta_debugfs)
  111. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  112. #endif
  113. }
  114. static inline int rate_supported(struct sta_info *sta,
  115. enum ieee80211_band band,
  116. int index)
  117. {
  118. return (sta == NULL || sta->supp_rates[band] & BIT(index));
  119. }
  120. static inline int
  121. rate_lowest_index(struct ieee80211_local *local,
  122. struct ieee80211_supported_band *sband,
  123. struct sta_info *sta)
  124. {
  125. int i;
  126. for (i = 0; i < sband->n_bitrates; i++)
  127. if (rate_supported(sta, sband->band, i))
  128. return i;
  129. /* warn when we cannot find a rate. */
  130. WARN_ON(1);
  131. return 0;
  132. }
  133. static inline struct ieee80211_rate *
  134. rate_lowest(struct ieee80211_local *local,
  135. struct ieee80211_supported_band *sband,
  136. struct sta_info *sta)
  137. {
  138. return &sband->bitrates[rate_lowest_index(local, sband, sta)];
  139. }
  140. /* functions for rate control related to a device */
  141. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  142. const char *name);
  143. void rate_control_deinitialize(struct ieee80211_local *local);
  144. /* Rate control algorithms */
  145. #if defined(RC80211_PID_COMPILE) || \
  146. (defined(CONFIG_MAC80211_RC_PID) && \
  147. !defined(CONFIG_MAC80211_RC_PID_MODULE))
  148. extern int rc80211_pid_init(void);
  149. extern void rc80211_pid_exit(void);
  150. #else
  151. static inline int rc80211_pid_init(void)
  152. {
  153. return 0;
  154. }
  155. static inline void rc80211_pid_exit(void)
  156. {
  157. }
  158. #endif
  159. #endif /* IEEE80211_RATE_H */