ieee80211_rate.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. /* default 'simple' algorithm */
  54. extern struct rate_control_ops mac80211_rcsimple;
  55. /* 'PID' algorithm */
  56. extern struct rate_control_ops mac80211_rcpid;
  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_hw_mode *mode, 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
  115. rate_supported(struct sta_info *sta, struct ieee80211_hw_mode *mode, int index)
  116. {
  117. return (sta == NULL || sta->supp_rates & BIT(index)) &&
  118. (mode->rates[index].flags & IEEE80211_RATE_SUPPORTED);
  119. }
  120. static inline int
  121. rate_lowest_index(struct ieee80211_local *local, struct ieee80211_hw_mode *mode,
  122. struct sta_info *sta)
  123. {
  124. int i;
  125. for (i = 0; i < mode->num_rates; i++) {
  126. if (rate_supported(sta, mode, i))
  127. return i;
  128. }
  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, struct ieee80211_hw_mode *mode,
  135. struct sta_info *sta)
  136. {
  137. return &mode->rates[rate_lowest_index(local, mode, 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. #endif /* IEEE80211_RATE_H */