ieee80211_rate.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #define RATE_CONTROL_NUM_DOWN 20
  19. #define RATE_CONTROL_NUM_UP 15
  20. struct rate_control_extra {
  21. /* values from rate_control_get_rate() to the caller: */
  22. struct ieee80211_rate *probe; /* probe with this rate, or NULL for no
  23. * probing */
  24. struct ieee80211_rate *nonerp;
  25. /* parameters from the caller to rate_control_get_rate(): */
  26. struct ieee80211_hw_mode *mode;
  27. u16 ethertype;
  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. struct ieee80211_rate *(*get_rate)(void *priv, struct net_device *dev,
  36. struct sk_buff *skb,
  37. struct rate_control_extra *extra);
  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. /* default 'simple' algorithm */
  57. extern struct rate_control_ops mac80211_rcsimple;
  58. int ieee80211_rate_control_register(struct rate_control_ops *ops);
  59. void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
  60. /* Get a reference to the rate control algorithm. If `name' is NULL, get the
  61. * first available algorithm. */
  62. struct rate_control_ref *rate_control_alloc(const char *name,
  63. struct ieee80211_local *local);
  64. struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
  65. void rate_control_put(struct rate_control_ref *ref);
  66. static inline void rate_control_tx_status(struct ieee80211_local *local,
  67. struct net_device *dev,
  68. struct sk_buff *skb,
  69. struct ieee80211_tx_status *status)
  70. {
  71. struct rate_control_ref *ref = local->rate_ctrl;
  72. ref->ops->tx_status(ref->priv, dev, skb, status);
  73. }
  74. static inline struct ieee80211_rate *
  75. rate_control_get_rate(struct ieee80211_local *local, struct net_device *dev,
  76. struct sk_buff *skb, struct rate_control_extra *extra)
  77. {
  78. struct rate_control_ref *ref = local->rate_ctrl;
  79. return ref->ops->get_rate(ref->priv, dev, skb, extra);
  80. }
  81. static inline void rate_control_rate_init(struct sta_info *sta,
  82. struct ieee80211_local *local)
  83. {
  84. struct rate_control_ref *ref = sta->rate_ctrl;
  85. ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
  86. }
  87. static inline void rate_control_clear(struct ieee80211_local *local)
  88. {
  89. struct rate_control_ref *ref = local->rate_ctrl;
  90. ref->ops->clear(ref->priv);
  91. }
  92. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  93. gfp_t gfp)
  94. {
  95. return ref->ops->alloc_sta(ref->priv, gfp);
  96. }
  97. static inline void rate_control_free_sta(struct rate_control_ref *ref,
  98. void *priv)
  99. {
  100. ref->ops->free_sta(ref->priv, priv);
  101. }
  102. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  103. {
  104. #ifdef CONFIG_MAC80211_DEBUGFS
  105. struct rate_control_ref *ref = sta->rate_ctrl;
  106. if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
  107. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  108. sta->debugfs.dir);
  109. #endif
  110. }
  111. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  112. {
  113. #ifdef CONFIG_MAC80211_DEBUGFS
  114. struct rate_control_ref *ref = sta->rate_ctrl;
  115. if (ref->ops->remove_sta_debugfs)
  116. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  117. #endif
  118. }
  119. /* functions for rate control related to a device */
  120. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  121. const char *name);
  122. void rate_control_deinitialize(struct ieee80211_local *local);
  123. #endif /* IEEE80211_RATE_H */