12c8dccc7SJohannes Berg /* 22c8dccc7SJohannes Berg * Copyright 2002-2005, Instant802 Networks, Inc. 32c8dccc7SJohannes Berg * Copyright 2005, Devicescape Software, Inc. 42c8dccc7SJohannes Berg * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> 52c8dccc7SJohannes Berg * 62c8dccc7SJohannes Berg * This program is free software; you can redistribute it and/or modify 72c8dccc7SJohannes Berg * it under the terms of the GNU General Public License version 2 as 82c8dccc7SJohannes Berg * published by the Free Software Foundation. 92c8dccc7SJohannes Berg */ 102c8dccc7SJohannes Berg 112c8dccc7SJohannes Berg #ifndef IEEE80211_RATE_H 122c8dccc7SJohannes Berg #define IEEE80211_RATE_H 132c8dccc7SJohannes Berg 142c8dccc7SJohannes Berg #include <linux/netdevice.h> 152c8dccc7SJohannes Berg #include <linux/skbuff.h> 162c8dccc7SJohannes Berg #include <linux/types.h> 172c8dccc7SJohannes Berg #include <linux/kref.h> 182c8dccc7SJohannes Berg #include <net/mac80211.h> 192c8dccc7SJohannes Berg #include "ieee80211_i.h" 202c8dccc7SJohannes Berg #include "sta_info.h" 212c8dccc7SJohannes Berg 222c8dccc7SJohannes Berg struct rate_control_ref { 234b7679a5SJohannes Berg struct ieee80211_local *local; 242c8dccc7SJohannes Berg struct rate_control_ops *ops; 252c8dccc7SJohannes Berg void *priv; 262c8dccc7SJohannes Berg struct kref kref; 272c8dccc7SJohannes Berg }; 282c8dccc7SJohannes Berg 292c8dccc7SJohannes Berg /* Get a reference to the rate control algorithm. If `name' is NULL, get the 302c8dccc7SJohannes Berg * first available algorithm. */ 312c8dccc7SJohannes Berg struct rate_control_ref *rate_control_alloc(const char *name, 322c8dccc7SJohannes Berg struct ieee80211_local *local); 334b7679a5SJohannes Berg void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 342c8dccc7SJohannes Berg struct ieee80211_supported_band *sband, 354b7679a5SJohannes Berg struct sta_info *sta, struct sk_buff *skb, 362c8dccc7SJohannes Berg struct rate_selection *sel); 372c8dccc7SJohannes Berg struct rate_control_ref *rate_control_get(struct rate_control_ref *ref); 382c8dccc7SJohannes Berg void rate_control_put(struct rate_control_ref *ref); 392c8dccc7SJohannes Berg 404b7679a5SJohannes Berg static inline void rate_control_tx_status(struct ieee80211_local *local, 414b7679a5SJohannes Berg struct ieee80211_supported_band *sband, 424b7679a5SJohannes Berg struct sta_info *sta, 43e039fa4aSJohannes Berg struct sk_buff *skb) 442c8dccc7SJohannes Berg { 452c8dccc7SJohannes Berg struct rate_control_ref *ref = local->rate_ctrl; 464b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 474b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 482c8dccc7SJohannes Berg 494b7679a5SJohannes Berg ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb); 502c8dccc7SJohannes Berg } 512c8dccc7SJohannes Berg 522c8dccc7SJohannes Berg 534b7679a5SJohannes Berg static inline void rate_control_rate_init(struct sta_info *sta) 542c8dccc7SJohannes Berg { 554b7679a5SJohannes Berg struct ieee80211_local *local = sta->sdata->local; 562c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 574b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 584b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 594b7679a5SJohannes Berg struct ieee80211_supported_band *sband; 604b7679a5SJohannes Berg 614b7679a5SJohannes Berg sband = local->hw.wiphy->bands[local->hw.conf.channel->band]; 624b7679a5SJohannes Berg 634b7679a5SJohannes Berg ref->ops->rate_init(ref->priv, sband, ista, priv_sta); 642c8dccc7SJohannes Berg } 652c8dccc7SJohannes Berg 662c8dccc7SJohannes Berg 672c8dccc7SJohannes Berg static inline void rate_control_clear(struct ieee80211_local *local) 682c8dccc7SJohannes Berg { 692c8dccc7SJohannes Berg struct rate_control_ref *ref = local->rate_ctrl; 702c8dccc7SJohannes Berg ref->ops->clear(ref->priv); 712c8dccc7SJohannes Berg } 722c8dccc7SJohannes Berg 732c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, 744b7679a5SJohannes Berg struct ieee80211_sta *sta, 752c8dccc7SJohannes Berg gfp_t gfp) 762c8dccc7SJohannes Berg { 774b7679a5SJohannes Berg return ref->ops->alloc_sta(ref->priv, sta, gfp); 782c8dccc7SJohannes Berg } 792c8dccc7SJohannes Berg 804b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta) 812c8dccc7SJohannes Berg { 824b7679a5SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 834b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 844b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 854b7679a5SJohannes Berg 864b7679a5SJohannes Berg ref->ops->free_sta(ref->priv, ista, priv_sta); 872c8dccc7SJohannes Berg } 882c8dccc7SJohannes Berg 892c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta) 902c8dccc7SJohannes Berg { 912c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS 922c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 932c8dccc7SJohannes Berg if (sta->debugfs.dir && ref->ops->add_sta_debugfs) 942c8dccc7SJohannes Berg ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, 952c8dccc7SJohannes Berg sta->debugfs.dir); 962c8dccc7SJohannes Berg #endif 972c8dccc7SJohannes Berg } 982c8dccc7SJohannes Berg 992c8dccc7SJohannes Berg static inline void rate_control_remove_sta_debugfs(struct sta_info *sta) 1002c8dccc7SJohannes Berg { 1012c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS 1022c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 1032c8dccc7SJohannes Berg if (ref->ops->remove_sta_debugfs) 1042c8dccc7SJohannes Berg ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv); 1052c8dccc7SJohannes Berg #endif 1062c8dccc7SJohannes Berg } 1072c8dccc7SJohannes Berg 1082c8dccc7SJohannes Berg /* functions for rate control related to a device */ 1092c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, 1102c8dccc7SJohannes Berg const char *name); 1112c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local); 1122c8dccc7SJohannes Berg 1132c8dccc7SJohannes Berg 1142c8dccc7SJohannes Berg /* Rate control algorithms */ 115e5f5e733SAdrian Bunk #ifdef CONFIG_MAC80211_RC_PID 1162c8dccc7SJohannes Berg extern int rc80211_pid_init(void); 1172c8dccc7SJohannes Berg extern void rc80211_pid_exit(void); 1182c8dccc7SJohannes Berg #else 1192c8dccc7SJohannes Berg static inline int rc80211_pid_init(void) 1202c8dccc7SJohannes Berg { 1212c8dccc7SJohannes Berg return 0; 1222c8dccc7SJohannes Berg } 1232c8dccc7SJohannes Berg static inline void rc80211_pid_exit(void) 1242c8dccc7SJohannes Berg { 1252c8dccc7SJohannes Berg } 1262c8dccc7SJohannes Berg #endif 1272c8dccc7SJohannes Berg 128*cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL 129*cccf129fSFelix Fietkau extern int rc80211_minstrel_init(void); 130*cccf129fSFelix Fietkau extern void rc80211_minstrel_exit(void); 131*cccf129fSFelix Fietkau #else 132*cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void) 133*cccf129fSFelix Fietkau { 134*cccf129fSFelix Fietkau return 0; 135*cccf129fSFelix Fietkau } 136*cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void) 137*cccf129fSFelix Fietkau { 138*cccf129fSFelix Fietkau } 139*cccf129fSFelix Fietkau #endif 140*cccf129fSFelix Fietkau 141*cccf129fSFelix Fietkau 1422c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */ 143