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.
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 <net/mac80211.h>
18 #include "ieee80211_i.h"
21 struct rate_selection
{
22 /* Selected transmission rate */
23 struct ieee80211_rate
*rate
;
24 /* Non-ERP rate to use if mac80211 decides it cannot use an ERP rate */
25 struct ieee80211_rate
*nonerp
;
26 /* probe with this rate, or NULL for no probing */
27 struct ieee80211_rate
*probe
;
30 struct rate_control_ops
{
31 struct module
*module
;
33 void (*tx_status
)(void *priv
, struct net_device
*dev
,
35 struct ieee80211_tx_status
*status
);
36 void (*get_rate
)(void *priv
, struct net_device
*dev
,
37 struct ieee80211_hw_mode
*mode
, struct sk_buff
*skb
,
38 struct rate_selection
*sel
);
39 void (*rate_init
)(void *priv
, void *priv_sta
,
40 struct ieee80211_local
*local
, struct sta_info
*sta
);
41 void (*clear
)(void *priv
);
43 void *(*alloc
)(struct ieee80211_local
*local
);
44 void (*free
)(void *priv
);
45 void *(*alloc_sta
)(void *priv
, gfp_t gfp
);
46 void (*free_sta
)(void *priv
, void *priv_sta
);
48 int (*add_attrs
)(void *priv
, struct kobject
*kobj
);
49 void (*remove_attrs
)(void *priv
, struct kobject
*kobj
);
50 void (*add_sta_debugfs
)(void *priv
, void *priv_sta
,
52 void (*remove_sta_debugfs
)(void *priv
, void *priv_sta
);
55 struct rate_control_ref
{
56 struct rate_control_ops
*ops
;
61 int ieee80211_rate_control_register(struct rate_control_ops
*ops
);
62 void ieee80211_rate_control_unregister(struct rate_control_ops
*ops
);
64 /* Get a reference to the rate control algorithm. If `name' is NULL, get the
65 * first available algorithm. */
66 struct rate_control_ref
*rate_control_alloc(const char *name
,
67 struct ieee80211_local
*local
);
68 void rate_control_get_rate(struct net_device
*dev
,
69 struct ieee80211_hw_mode
*mode
, struct sk_buff
*skb
,
70 struct rate_selection
*sel
);
71 struct rate_control_ref
*rate_control_get(struct rate_control_ref
*ref
);
72 void rate_control_put(struct rate_control_ref
*ref
);
74 static inline void rate_control_tx_status(struct net_device
*dev
,
76 struct ieee80211_tx_status
*status
)
78 struct ieee80211_local
*local
= wdev_priv(dev
->ieee80211_ptr
);
79 struct rate_control_ref
*ref
= local
->rate_ctrl
;
81 ref
->ops
->tx_status(ref
->priv
, dev
, skb
, status
);
85 static inline void rate_control_rate_init(struct sta_info
*sta
,
86 struct ieee80211_local
*local
)
88 struct rate_control_ref
*ref
= sta
->rate_ctrl
;
89 ref
->ops
->rate_init(ref
->priv
, sta
->rate_ctrl_priv
, local
, sta
);
93 static inline void rate_control_clear(struct ieee80211_local
*local
)
95 struct rate_control_ref
*ref
= local
->rate_ctrl
;
96 ref
->ops
->clear(ref
->priv
);
99 static inline void *rate_control_alloc_sta(struct rate_control_ref
*ref
,
102 return ref
->ops
->alloc_sta(ref
->priv
, gfp
);
105 static inline void rate_control_free_sta(struct rate_control_ref
*ref
,
108 ref
->ops
->free_sta(ref
->priv
, priv
);
111 static inline void rate_control_add_sta_debugfs(struct sta_info
*sta
)
113 #ifdef CONFIG_MAC80211_DEBUGFS
114 struct rate_control_ref
*ref
= sta
->rate_ctrl
;
115 if (sta
->debugfs
.dir
&& ref
->ops
->add_sta_debugfs
)
116 ref
->ops
->add_sta_debugfs(ref
->priv
, sta
->rate_ctrl_priv
,
121 static inline void rate_control_remove_sta_debugfs(struct sta_info
*sta
)
123 #ifdef CONFIG_MAC80211_DEBUGFS
124 struct rate_control_ref
*ref
= sta
->rate_ctrl
;
125 if (ref
->ops
->remove_sta_debugfs
)
126 ref
->ops
->remove_sta_debugfs(ref
->priv
, sta
->rate_ctrl_priv
);
131 rate_supported(struct sta_info
*sta
, struct ieee80211_hw_mode
*mode
, int index
)
133 return (sta
== NULL
|| sta
->supp_rates
& BIT(index
)) &&
134 (mode
->rates
[index
].flags
& IEEE80211_RATE_SUPPORTED
);
138 rate_lowest_index(struct ieee80211_local
*local
, struct ieee80211_hw_mode
*mode
,
139 struct sta_info
*sta
)
143 for (i
= 0; i
< mode
->num_rates
; i
++) {
144 if (rate_supported(sta
, mode
, i
))
148 /* warn when we cannot find a rate. */
154 static inline struct ieee80211_rate
*
155 rate_lowest(struct ieee80211_local
*local
, struct ieee80211_hw_mode
*mode
,
156 struct sta_info
*sta
)
158 return &mode
->rates
[rate_lowest_index(local
, mode
, sta
)];
162 /* functions for rate control related to a device */
163 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local
*local
,
165 void rate_control_deinitialize(struct ieee80211_local
*local
);
168 /* Rate control algorithms */
169 #if defined(RC80211_SIMPLE_COMPILE) || \
170 (defined(CONFIG_MAC80211_RC_SIMPLE) && \
171 !defined(CONFIG_MAC80211_RC_SIMPLE_MODULE))
172 extern int rc80211_simple_init(void);
173 extern void rc80211_simple_exit(void);
175 static inline int rc80211_simple_init(void)
179 static inline void rc80211_simple_exit(void)
184 #if defined(RC80211_PID_COMPILE) || \
185 (defined(CONFIG_MAC80211_RC_PID) && \
186 !defined(CONFIG_MAC80211_RC_PID_MODULE))
187 extern int rc80211_pid_init(void);
188 extern void rc80211_pid_exit(void);
190 static inline int rc80211_pid_init(void)
194 static inline void rc80211_pid_exit(void)
199 #endif /* IEEE80211_RATE_H */