blob: 5f9a2ca49a573b0592ffbab9d6fbb0cee4dbe432 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
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>
17#include <net/mac80211.h>
18#include "ieee80211_i.h"
19#include "sta_info.h"
20
Johannes Berg8318d782008-01-24 19:38:38 +010021/* TODO: kdoc */
Mattias Nissler1abbe492007-12-20 13:50:07 +010022struct rate_selection {
23 /* Selected transmission rate */
24 struct ieee80211_rate *rate;
25 /* Non-ERP rate to use if mac80211 decides it cannot use an ERP rate */
Jiri Bencf0706e82007-05-05 11:45:53 -070026 struct ieee80211_rate *nonerp;
Mattias Nissler1abbe492007-12-20 13:50:07 +010027 /* probe with this rate, or NULL for no probing */
28 struct ieee80211_rate *probe;
Jiri Bencf0706e82007-05-05 11:45:53 -070029};
30
Jiri Bencf0706e82007-05-05 11:45:53 -070031struct rate_control_ops {
32 struct module *module;
33 const char *name;
34 void (*tx_status)(void *priv, struct net_device *dev,
35 struct sk_buff *skb,
36 struct ieee80211_tx_status *status);
Mattias Nissler1abbe492007-12-20 13:50:07 +010037 void (*get_rate)(void *priv, struct net_device *dev,
Johannes Berg8318d782008-01-24 19:38:38 +010038 struct ieee80211_supported_band *band,
39 struct sk_buff *skb,
Mattias Nissler1abbe492007-12-20 13:50:07 +010040 struct rate_selection *sel);
Jiri Bencf0706e82007-05-05 11:45:53 -070041 void (*rate_init)(void *priv, void *priv_sta,
42 struct ieee80211_local *local, struct sta_info *sta);
43 void (*clear)(void *priv);
44
45 void *(*alloc)(struct ieee80211_local *local);
46 void (*free)(void *priv);
47 void *(*alloc_sta)(void *priv, gfp_t gfp);
48 void (*free_sta)(void *priv, void *priv_sta);
49
50 int (*add_attrs)(void *priv, struct kobject *kobj);
51 void (*remove_attrs)(void *priv, struct kobject *kobj);
Jiri Bence9f207f2007-05-05 11:46:38 -070052 void (*add_sta_debugfs)(void *priv, void *priv_sta,
53 struct dentry *dir);
54 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
Jiri Bencf0706e82007-05-05 11:45:53 -070055};
56
57struct rate_control_ref {
58 struct rate_control_ops *ops;
59 void *priv;
60 struct kref kref;
61};
62
63int ieee80211_rate_control_register(struct rate_control_ops *ops);
64void ieee80211_rate_control_unregister(struct rate_control_ops *ops);
65
66/* Get a reference to the rate control algorithm. If `name' is NULL, get the
67 * first available algorithm. */
68struct rate_control_ref *rate_control_alloc(const char *name,
69 struct ieee80211_local *local);
Mattias Nissler1abbe492007-12-20 13:50:07 +010070void rate_control_get_rate(struct net_device *dev,
Johannes Berg8318d782008-01-24 19:38:38 +010071 struct ieee80211_supported_band *sband,
72 struct sk_buff *skb,
Mattias Nissler1abbe492007-12-20 13:50:07 +010073 struct rate_selection *sel);
Jiri Bencf0706e82007-05-05 11:45:53 -070074struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
75void rate_control_put(struct rate_control_ref *ref);
76
Mattias Nissler1abbe492007-12-20 13:50:07 +010077static inline void rate_control_tx_status(struct net_device *dev,
Jiri Bencf0706e82007-05-05 11:45:53 -070078 struct sk_buff *skb,
79 struct ieee80211_tx_status *status)
80{
Mattias Nissler1abbe492007-12-20 13:50:07 +010081 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Jiri Bencf0706e82007-05-05 11:45:53 -070082 struct rate_control_ref *ref = local->rate_ctrl;
Mattias Nissler1abbe492007-12-20 13:50:07 +010083
Jiri Bencf0706e82007-05-05 11:45:53 -070084 ref->ops->tx_status(ref->priv, dev, skb, status);
85}
86
87
Jiri Bencf0706e82007-05-05 11:45:53 -070088static inline void rate_control_rate_init(struct sta_info *sta,
89 struct ieee80211_local *local)
90{
91 struct rate_control_ref *ref = sta->rate_ctrl;
92 ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta);
93}
94
95
96static inline void rate_control_clear(struct ieee80211_local *local)
97{
98 struct rate_control_ref *ref = local->rate_ctrl;
99 ref->ops->clear(ref->priv);
100}
101
102static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
103 gfp_t gfp)
104{
105 return ref->ops->alloc_sta(ref->priv, gfp);
106}
107
108static inline void rate_control_free_sta(struct rate_control_ref *ref,
109 void *priv)
110{
111 ref->ops->free_sta(ref->priv, priv);
112}
113
Jiri Bence9f207f2007-05-05 11:46:38 -0700114static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
115{
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
122}
123
124static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
125{
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
131}
132
Johannes Berg8318d782008-01-24 19:38:38 +0100133static inline int rate_supported(struct sta_info *sta,
134 enum ieee80211_band band,
135 int index)
Mattias Nissler1abbe492007-12-20 13:50:07 +0100136{
Johannes Berg8318d782008-01-24 19:38:38 +0100137 return (sta == NULL || sta->supp_rates[band] & BIT(index));
Mattias Nissler1abbe492007-12-20 13:50:07 +0100138}
139
140static inline int
Johannes Berg8318d782008-01-24 19:38:38 +0100141rate_lowest_index(struct ieee80211_local *local,
142 struct ieee80211_supported_band *sband,
Mattias Nissler1abbe492007-12-20 13:50:07 +0100143 struct sta_info *sta)
144{
145 int i;
146
Johannes Berg8318d782008-01-24 19:38:38 +0100147 for (i = 0; i < sband->n_bitrates; i++)
148 if (rate_supported(sta, sband->band, i))
Mattias Nissler1abbe492007-12-20 13:50:07 +0100149 return i;
Mattias Nissler1abbe492007-12-20 13:50:07 +0100150
151 /* warn when we cannot find a rate. */
152 WARN_ON(1);
153
154 return 0;
155}
156
157static inline struct ieee80211_rate *
Johannes Berg8318d782008-01-24 19:38:38 +0100158rate_lowest(struct ieee80211_local *local,
159 struct ieee80211_supported_band *sband,
Mattias Nissler1abbe492007-12-20 13:50:07 +0100160 struct sta_info *sta)
161{
Johannes Berg8318d782008-01-24 19:38:38 +0100162 return &sband->bitrates[rate_lowest_index(local, sband, sta)];
Mattias Nissler1abbe492007-12-20 13:50:07 +0100163}
164
Johannes Bergff688082007-07-27 15:43:23 +0200165
166/* functions for rate control related to a device */
167int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
168 const char *name);
169void rate_control_deinitialize(struct ieee80211_local *local);
170
Johannes Berg4b475892008-01-02 15:17:03 +0100171
172/* Rate control algorithms */
173#if defined(RC80211_SIMPLE_COMPILE) || \
174 (defined(CONFIG_MAC80211_RC_SIMPLE) && \
175 !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE))
176extern int rc80211_simple_init(void);
177extern void rc80211_simple_exit(void);
178#else
179static inline int rc80211_simple_init(void)
180{
181 return 0;
182}
183static inline void rc80211_simple_exit(void)
184{
185}
186#endif
187
188#if defined(RC80211_PID_COMPILE) || \
189 (defined(CONFIG_MAC80211_RC_PID) && \
190 !defined(CONFIG_MAC80211_RC_PID_MODULE))
191extern int rc80211_pid_init(void);
192extern void rc80211_pid_exit(void);
193#else
194static inline int rc80211_pid_init(void)
195{
196 return 0;
197}
198static inline void rc80211_pid_exit(void)
199{
200}
201#endif
202
Jiri Bencf0706e82007-05-05 11:45:53 -0700203#endif /* IEEE80211_RATE_H */