ieee80211_rate.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. 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. struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
  63. void rate_control_put(struct rate_control_ref *ref);
  64. static inline void rate_control_tx_status(struct ieee80211_local *local,
  65. struct net_device *dev,
  66. struct sk_buff *skb,
  67. struct ieee80211_tx_status *status)
  68. {
  69. struct rate_control_ref *ref = local->rate_ctrl;
  70. ref->ops->tx_status(ref->priv, dev, skb, status);
  71. }
  72. static inline struct ieee80211_rate *
  73. rate_control_get_rate(struct ieee80211_local *local, struct net_device *dev,
  74. struct sk_buff *skb, struct rate_control_extra *extra)
  75. {
  76. struct rate_control_ref *ref = local->rate_ctrl;
  77. return ref->ops->get_rate(ref->priv, dev, skb, extra);
  78. }
  79. static inline void rate_control_rate_init(struct sta_info *sta,
  80. struct ieee80211_local *local)
  81. {
  82. struct rate_control_ref *ref = sta->rate_ctrl;
  83. ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
  84. }
  85. static inline void rate_control_clear(struct ieee80211_local *local)
  86. {
  87. struct rate_control_ref *ref = local->rate_ctrl;
  88. ref->ops->clear(ref->priv);
  89. }
  90. static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
  91. gfp_t gfp)
  92. {
  93. return ref->ops->alloc_sta(ref->priv, gfp);
  94. }
  95. static inline void rate_control_free_sta(struct rate_control_ref *ref,
  96. void *priv)
  97. {
  98. ref->ops->free_sta(ref->priv, priv);
  99. }
  100. static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
  101. {
  102. #ifdef CONFIG_MAC80211_DEBUGFS
  103. struct rate_control_ref *ref = sta->rate_ctrl;
  104. if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
  105. ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
  106. sta->debugfs.dir);
  107. #endif
  108. }
  109. static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
  110. {
  111. #ifdef CONFIG_MAC80211_DEBUGFS
  112. struct rate_control_ref *ref = sta->rate_ctrl;
  113. if (ref->ops->remove_sta_debugfs)
  114. ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
  115. #endif
  116. }
  117. /* functions for rate control related to a device */
  118. int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
  119. const char *name);
  120. void rate_control_deinitialize(struct ieee80211_local *local);
  121. #endif /* IEEE80211_RATE_H */