rate.h 4.9 KB

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