| 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> | 
|  | 17 | #include <net/mac80211.h> | 
|  | 18 | #include "ieee80211_i.h" | 
|  | 19 | #include "sta_info.h" | 
|  | 20 |  | 
|  | 21 | #define RATE_CONTROL_NUM_DOWN 20 | 
|  | 22 | #define RATE_CONTROL_NUM_UP   15 | 
|  | 23 |  | 
|  | 24 |  | 
|  | 25 | struct rate_control_extra { | 
|  | 26 | /* values from rate_control_get_rate() to the caller: */ | 
|  | 27 | struct ieee80211_rate *probe; /* probe with this rate, or NULL for no | 
|  | 28 | * probing */ | 
|  | 29 | struct ieee80211_rate *nonerp; | 
|  | 30 |  | 
|  | 31 | /* parameters from the caller to rate_control_get_rate(): */ | 
|  | 32 | struct ieee80211_hw_mode *mode; | 
| Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 33 | u16 ethertype; | 
|  | 34 | }; | 
|  | 35 |  | 
|  | 36 |  | 
|  | 37 | struct rate_control_ops { | 
|  | 38 | struct module *module; | 
|  | 39 | const char *name; | 
|  | 40 | void (*tx_status)(void *priv, struct net_device *dev, | 
|  | 41 | struct sk_buff *skb, | 
|  | 42 | struct ieee80211_tx_status *status); | 
|  | 43 | struct ieee80211_rate *(*get_rate)(void *priv, struct net_device *dev, | 
|  | 44 | struct sk_buff *skb, | 
|  | 45 | struct rate_control_extra *extra); | 
|  | 46 | void (*rate_init)(void *priv, void *priv_sta, | 
|  | 47 | struct ieee80211_local *local, struct sta_info *sta); | 
|  | 48 | void (*clear)(void *priv); | 
|  | 49 |  | 
|  | 50 | void *(*alloc)(struct ieee80211_local *local); | 
|  | 51 | void (*free)(void *priv); | 
|  | 52 | void *(*alloc_sta)(void *priv, gfp_t gfp); | 
|  | 53 | void (*free_sta)(void *priv, void *priv_sta); | 
|  | 54 |  | 
|  | 55 | int (*add_attrs)(void *priv, struct kobject *kobj); | 
|  | 56 | void (*remove_attrs)(void *priv, struct kobject *kobj); | 
| Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 57 | void (*add_sta_debugfs)(void *priv, void *priv_sta, | 
|  | 58 | struct dentry *dir); | 
|  | 59 | void (*remove_sta_debugfs)(void *priv, void *priv_sta); | 
| Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 60 | }; | 
|  | 61 |  | 
|  | 62 | struct rate_control_ref { | 
|  | 63 | struct rate_control_ops *ops; | 
|  | 64 | void *priv; | 
|  | 65 | struct kref kref; | 
|  | 66 | }; | 
|  | 67 |  | 
| Johannes Berg | ac71c69 | 2007-10-28 14:17:44 +0100 | [diff] [blame] | 68 | /* default 'simple' algorithm */ | 
|  | 69 | extern struct rate_control_ops mac80211_rcsimple; | 
|  | 70 |  | 
| Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 71 | int ieee80211_rate_control_register(struct rate_control_ops *ops); | 
|  | 72 | void ieee80211_rate_control_unregister(struct rate_control_ops *ops); | 
|  | 73 |  | 
|  | 74 | /* Get a reference to the rate control algorithm. If `name' is NULL, get the | 
|  | 75 | * first available algorithm. */ | 
|  | 76 | struct rate_control_ref *rate_control_alloc(const char *name, | 
|  | 77 | struct ieee80211_local *local); | 
|  | 78 | struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); | 
|  | 79 | void rate_control_put(struct rate_control_ref *ref); | 
|  | 80 |  | 
|  | 81 | static inline void rate_control_tx_status(struct ieee80211_local *local, | 
|  | 82 | struct net_device *dev, | 
|  | 83 | struct sk_buff *skb, | 
|  | 84 | struct ieee80211_tx_status *status) | 
|  | 85 | { | 
|  | 86 | struct rate_control_ref *ref = local->rate_ctrl; | 
|  | 87 | ref->ops->tx_status(ref->priv, dev, skb, status); | 
|  | 88 | } | 
|  | 89 |  | 
|  | 90 |  | 
|  | 91 | static inline struct ieee80211_rate * | 
|  | 92 | rate_control_get_rate(struct ieee80211_local *local, struct net_device *dev, | 
|  | 93 | struct sk_buff *skb, struct rate_control_extra *extra) | 
|  | 94 | { | 
|  | 95 | struct rate_control_ref *ref = local->rate_ctrl; | 
|  | 96 | return ref->ops->get_rate(ref->priv, dev, skb, extra); | 
|  | 97 | } | 
|  | 98 |  | 
|  | 99 |  | 
|  | 100 | static inline void rate_control_rate_init(struct sta_info *sta, | 
|  | 101 | struct ieee80211_local *local) | 
|  | 102 | { | 
|  | 103 | struct rate_control_ref *ref = sta->rate_ctrl; | 
|  | 104 | ref->ops->rate_init(ref->priv, sta->rate_ctrl_priv, local, sta); | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 |  | 
|  | 108 | static inline void rate_control_clear(struct ieee80211_local *local) | 
|  | 109 | { | 
|  | 110 | struct rate_control_ref *ref = local->rate_ctrl; | 
|  | 111 | ref->ops->clear(ref->priv); | 
|  | 112 | } | 
|  | 113 |  | 
|  | 114 | static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, | 
|  | 115 | gfp_t gfp) | 
|  | 116 | { | 
|  | 117 | return ref->ops->alloc_sta(ref->priv, gfp); | 
|  | 118 | } | 
|  | 119 |  | 
|  | 120 | static inline void rate_control_free_sta(struct rate_control_ref *ref, | 
|  | 121 | void *priv) | 
|  | 122 | { | 
|  | 123 | ref->ops->free_sta(ref->priv, priv); | 
|  | 124 | } | 
|  | 125 |  | 
| Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 126 | static inline void rate_control_add_sta_debugfs(struct sta_info *sta) | 
|  | 127 | { | 
|  | 128 | #ifdef CONFIG_MAC80211_DEBUGFS | 
|  | 129 | struct rate_control_ref *ref = sta->rate_ctrl; | 
|  | 130 | if (sta->debugfs.dir && ref->ops->add_sta_debugfs) | 
|  | 131 | ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, | 
|  | 132 | sta->debugfs.dir); | 
|  | 133 | #endif | 
|  | 134 | } | 
|  | 135 |  | 
|  | 136 | static inline void rate_control_remove_sta_debugfs(struct sta_info *sta) | 
|  | 137 | { | 
|  | 138 | #ifdef CONFIG_MAC80211_DEBUGFS | 
|  | 139 | struct rate_control_ref *ref = sta->rate_ctrl; | 
|  | 140 | if (ref->ops->remove_sta_debugfs) | 
|  | 141 | ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv); | 
|  | 142 | #endif | 
|  | 143 | } | 
|  | 144 |  | 
| Johannes Berg | ff68808 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 145 |  | 
|  | 146 | /* functions for rate control related to a device */ | 
|  | 147 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, | 
|  | 148 | const char *name); | 
|  | 149 | void rate_control_deinitialize(struct ieee80211_local *local); | 
|  | 150 |  | 
| Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 151 | #endif /* IEEE80211_RATE_H */ |