USB: isp1760: use a specific PLX bridge instead of any bdridge
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / net / mac80211 / rate.h
blobede7ab56f65bc269f2363a56541d4944f32f56b7
1 /*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, Devicescape Software, Inc.
4 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
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 */
11 #ifndef IEEE80211_RATE_H
12 #define IEEE80211_RATE_H
14 #include <linux/netdevice.h>
15 #include <linux/skbuff.h>
16 #include <linux/types.h>
17 #include <linux/kref.h>
18 #include <net/mac80211.h>
19 #include "ieee80211_i.h"
20 #include "sta_info.h"
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)
29 struct rate_selection {
30 s8 rate_idx, nonerp_idx, probe_idx;
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 void (*get_rate)(void *priv, struct net_device *dev,
39 struct ieee80211_supported_band *band,
40 struct sk_buff *skb,
41 struct rate_selection *sel);
42 void (*rate_init)(void *priv, void *priv_sta,
43 struct ieee80211_local *local, struct sta_info *sta);
44 void (*clear)(void *priv);
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);
51 int (*add_attrs)(void *priv, struct kobject *kobj);
52 void (*remove_attrs)(void *priv, struct kobject *kobj);
53 void (*add_sta_debugfs)(void *priv, void *priv_sta,
54 struct dentry *dir);
55 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
58 struct rate_control_ref {
59 struct rate_control_ops *ops;
60 void *priv;
61 struct kref kref;
64 int ieee80211_rate_control_register(struct rate_control_ops *ops);
65 void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
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);
71 void rate_control_get_rate(struct net_device *dev,
72 struct ieee80211_supported_band *sband,
73 struct sk_buff *skb,
74 struct rate_selection *sel);
75 struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
76 void rate_control_put(struct rate_control_ref *ref);
78 static inline void rate_control_tx_status(struct net_device *dev,
79 struct sk_buff *skb)
81 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
82 struct rate_control_ref *ref = local->rate_ctrl;
84 ref->ops->tx_status(ref->priv, dev, skb);
88 static inline void rate_control_rate_init(struct sta_info *sta,
89 struct ieee80211_local *local)
91 struct rate_control_ref *ref = sta->rate_ctrl;
92 ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
96 static inline void rate_control_clear(struct ieee80211_local *local)
98 struct rate_control_ref *ref = local->rate_ctrl;
99 ref->ops->clear(ref->priv);
102 static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
103 gfp_t gfp)
105 return ref->ops->alloc_sta(ref->priv, gfp);
108 static inline void rate_control_free_sta(struct rate_control_ref *ref,
109 void *priv)
111 ref->ops->free_sta(ref->priv, priv);
114 static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
116 #ifdef CONFIG_MAC80211_DEBUGFS
117 struct rate_control_ref *ref = sta->rate_ctrl;
118 if (sta->debugfs.dir && ref->ops->add_sta_debugfs)
119 ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
120 sta->debugfs.dir);
121 #endif
124 static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
126 #ifdef CONFIG_MAC80211_DEBUGFS
127 struct rate_control_ref *ref = sta->rate_ctrl;
128 if (ref->ops->remove_sta_debugfs)
129 ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
130 #endif
133 static inline int rate_supported(struct sta_info *sta,
134 enum ieee80211_band band,
135 int index)
137 return (sta == NULL || sta->supp_rates[band] & BIT(index));
140 static inline s8
141 rate_lowest_index(struct ieee80211_local *local,
142 struct ieee80211_supported_band *sband,
143 struct sta_info *sta)
145 int i;
147 for (i = 0; i < sband->n_bitrates; i++)
148 if (rate_supported(sta, sband->band, i))
149 return i;
151 /* warn when we cannot find a rate. */
152 WARN_ON(1);
154 return 0;
158 /* functions for rate control related to a device */
159 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
160 const char *name);
161 void rate_control_deinitialize(struct ieee80211_local *local);
164 /* Rate control algorithms */
165 #ifdef CONFIG_MAC80211_RC_PID
166 extern int rc80211_pid_init(void);
167 extern void rc80211_pid_exit(void);
168 #else
169 static inline int rc80211_pid_init(void)
171 return 0;
173 static inline void rc80211_pid_exit(void)
176 #endif
178 #endif /* IEEE80211_RATE_H */