Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 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 | |
| 11 | #ifndef IEEE80211_RATE_H |
| 12 | #define IEEE80211_RATE_H |
| 13 | |
| 14 | #include <linux/netdevice.h> |
| 15 | #include <linux/skbuff.h> |
| 16 | #include <linux/types.h> |
Johannes Berg | d0709a6 | 2008-02-25 16:27:46 +0100 | [diff] [blame^] | 17 | #include <linux/kref.h> |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | #include <net/mac80211.h> |
| 19 | #include "ieee80211_i.h" |
| 20 | #include "sta_info.h" |
| 21 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 22 | /* TODO: kdoc */ |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 23 | struct rate_selection { |
| 24 | /* Selected transmission rate */ |
| 25 | struct ieee80211_rate *rate; |
| 26 | /* Non-ERP rate to use if mac80211 decides it cannot use an ERP rate */ |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | struct ieee80211_rate *nonerp; |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 28 | /* probe with this rate, or NULL for no probing */ |
| 29 | struct ieee80211_rate *probe; |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 32 | struct rate_control_ops { |
| 33 | struct module *module; |
| 34 | const char *name; |
| 35 | void (*tx_status)(void *priv, struct net_device *dev, |
| 36 | struct sk_buff *skb, |
| 37 | struct ieee80211_tx_status *status); |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 38 | void (*get_rate)(void *priv, struct net_device *dev, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 39 | struct ieee80211_supported_band *band, |
| 40 | struct sk_buff *skb, |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 41 | struct rate_selection *sel); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | void (*rate_init)(void *priv, void *priv_sta, |
| 43 | struct ieee80211_local *local, struct sta_info *sta); |
| 44 | void (*clear)(void *priv); |
| 45 | |
| 46 | void *(*alloc)(struct ieee80211_local *local); |
| 47 | void (*free)(void *priv); |
| 48 | void *(*alloc_sta)(void *priv, gfp_t gfp); |
| 49 | void (*free_sta)(void *priv, void *priv_sta); |
| 50 | |
| 51 | int (*add_attrs)(void *priv, struct kobject *kobj); |
| 52 | void (*remove_attrs)(void *priv, struct kobject *kobj); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 53 | void (*add_sta_debugfs)(void *priv, void *priv_sta, |
| 54 | struct dentry *dir); |
| 55 | void (*remove_sta_debugfs)(void *priv, void *priv_sta); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
| 58 | struct rate_control_ref { |
| 59 | struct rate_control_ops *ops; |
| 60 | void *priv; |
| 61 | struct kref kref; |
| 62 | }; |
| 63 | |
| 64 | int ieee80211_rate_control_register(struct rate_control_ops *ops); |
| 65 | void ieee80211_rate_control_unregister(struct rate_control_ops *ops); |
| 66 | |
| 67 | /* Get a reference to the rate control algorithm. If `name' is NULL, get the |
| 68 | * first available algorithm. */ |
| 69 | struct rate_control_ref *rate_control_alloc(const char *name, |
| 70 | struct ieee80211_local *local); |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 71 | void rate_control_get_rate(struct net_device *dev, |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 72 | struct ieee80211_supported_band *sband, |
| 73 | struct sk_buff *skb, |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 74 | struct rate_selection *sel); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 75 | struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); |
| 76 | void rate_control_put(struct rate_control_ref *ref); |
| 77 | |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 78 | static inline void rate_control_tx_status(struct net_device *dev, |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 79 | struct sk_buff *skb, |
| 80 | struct ieee80211_tx_status *status) |
| 81 | { |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 82 | struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 83 | struct rate_control_ref *ref = local->rate_ctrl; |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 84 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 85 | ref->ops->tx_status(ref->priv, dev, skb, status); |
| 86 | } |
| 87 | |
| 88 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 89 | static inline void rate_control_rate_init(struct sta_info *sta, |
| 90 | struct ieee80211_local *local) |
| 91 | { |
| 92 | struct rate_control_ref *ref = sta->rate_ctrl; |
| 93 | ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | static inline void rate_control_clear(struct ieee80211_local *local) |
| 98 | { |
| 99 | struct rate_control_ref *ref = local->rate_ctrl; |
| 100 | ref->ops->clear(ref->priv); |
| 101 | } |
| 102 | |
| 103 | static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, |
| 104 | gfp_t gfp) |
| 105 | { |
| 106 | return ref->ops->alloc_sta(ref->priv, gfp); |
| 107 | } |
| 108 | |
| 109 | static inline void rate_control_free_sta(struct rate_control_ref *ref, |
| 110 | void *priv) |
| 111 | { |
| 112 | ref->ops->free_sta(ref->priv, priv); |
| 113 | } |
| 114 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 115 | static inline void rate_control_add_sta_debugfs(struct sta_info *sta) |
| 116 | { |
| 117 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 118 | struct rate_control_ref *ref = sta->rate_ctrl; |
| 119 | if (sta->debugfs.dir && ref->ops->add_sta_debugfs) |
| 120 | ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, |
| 121 | sta->debugfs.dir); |
| 122 | #endif |
| 123 | } |
| 124 | |
| 125 | static inline void rate_control_remove_sta_debugfs(struct sta_info *sta) |
| 126 | { |
| 127 | #ifdef CONFIG_MAC80211_DEBUGFS |
| 128 | struct rate_control_ref *ref = sta->rate_ctrl; |
| 129 | if (ref->ops->remove_sta_debugfs) |
| 130 | ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv); |
| 131 | #endif |
| 132 | } |
| 133 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 134 | static inline int rate_supported(struct sta_info *sta, |
| 135 | enum ieee80211_band band, |
| 136 | int index) |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 137 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 138 | return (sta == NULL || sta->supp_rates[band] & BIT(index)); |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static inline int |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 142 | rate_lowest_index(struct ieee80211_local *local, |
| 143 | struct ieee80211_supported_band *sband, |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 144 | struct sta_info *sta) |
| 145 | { |
| 146 | int i; |
| 147 | |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 148 | for (i = 0; i < sband->n_bitrates; i++) |
| 149 | if (rate_supported(sta, sband->band, i)) |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 150 | return i; |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 151 | |
| 152 | /* warn when we cannot find a rate. */ |
| 153 | WARN_ON(1); |
| 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | static inline struct ieee80211_rate * |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 159 | rate_lowest(struct ieee80211_local *local, |
| 160 | struct ieee80211_supported_band *sband, |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 161 | struct sta_info *sta) |
| 162 | { |
Johannes Berg | 8318d78 | 2008-01-24 19:38:38 +0100 | [diff] [blame] | 163 | return &sband->bitrates[rate_lowest_index(local, sband, sta)]; |
Mattias Nissler | 1abbe49 | 2007-12-20 13:50:07 +0100 | [diff] [blame] | 164 | } |
| 165 | |
Johannes Berg | ff68808 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 166 | |
| 167 | /* functions for rate control related to a device */ |
| 168 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, |
| 169 | const char *name); |
| 170 | void rate_control_deinitialize(struct ieee80211_local *local); |
| 171 | |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 172 | |
| 173 | /* Rate control algorithms */ |
| 174 | #if defined(RC80211_SIMPLE_COMPILE) || \ |
| 175 | (defined(CONFIG_MAC80211_RC_SIMPLE) && \ |
| 176 | !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE)) |
| 177 | extern int rc80211_simple_init(void); |
| 178 | extern void rc80211_simple_exit(void); |
| 179 | #else |
| 180 | static inline int rc80211_simple_init(void) |
| 181 | { |
| 182 | return 0; |
| 183 | } |
| 184 | static inline void rc80211_simple_exit(void) |
| 185 | { |
| 186 | } |
| 187 | #endif |
| 188 | |
| 189 | #if defined(RC80211_PID_COMPILE) || \ |
| 190 | (defined(CONFIG_MAC80211_RC_PID) && \ |
| 191 | !defined(CONFIG_MAC80211_RC_PID_MODULE)) |
| 192 | extern int rc80211_pid_init(void); |
| 193 | extern void rc80211_pid_exit(void); |
| 194 | #else |
| 195 | static inline int rc80211_pid_init(void) |
| 196 | { |
| 197 | return 0; |
| 198 | } |
| 199 | static inline void rc80211_pid_exit(void) |
| 200 | { |
| 201 | } |
| 202 | #endif |
| 203 | |
Jiri Benc | f0706e82 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 204 | #endif /* IEEE80211_RATE_H */ |