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