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 <net/mac80211.h> 182c8dccc7SJohannes Berg #include "ieee80211_i.h" 192c8dccc7SJohannes Berg #include "sta_info.h" 208f727ef3SJohannes Berg #include "driver-ops.h" 212c8dccc7SJohannes Berg 222c8dccc7SJohannes Berg struct rate_control_ref { 234b7679a5SJohannes Berg struct ieee80211_local *local; 24*631ad703SJohannes Berg const struct rate_control_ops *ops; 252c8dccc7SJohannes Berg void *priv; 262c8dccc7SJohannes Berg }; 272c8dccc7SJohannes Berg 284b7679a5SJohannes Berg void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, 29e6a9854bSJohannes Berg struct sta_info *sta, 30e6a9854bSJohannes Berg struct ieee80211_tx_rate_control *txrc); 312c8dccc7SJohannes Berg 324b7679a5SJohannes Berg static inline void rate_control_tx_status(struct ieee80211_local *local, 334b7679a5SJohannes Berg struct ieee80211_supported_band *sband, 344b7679a5SJohannes Berg struct sta_info *sta, 35e039fa4aSJohannes Berg struct sk_buff *skb) 362c8dccc7SJohannes Berg { 372c8dccc7SJohannes Berg struct rate_control_ref *ref = local->rate_ctrl; 384b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 394b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 403c384053SVasanthakumar 412cfc6fc5SFelix Fietkau if (!ref || !test_sta_flag(sta, WLAN_STA_RATE_CONTROL)) 423c384053SVasanthakumar return; 433c384053SVasanthakumar 444b7679a5SJohannes Berg ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb); 452c8dccc7SJohannes Berg } 462c8dccc7SJohannes Berg 472c8dccc7SJohannes Berg 484b7679a5SJohannes Berg static inline void rate_control_rate_init(struct sta_info *sta) 492c8dccc7SJohannes Berg { 504b7679a5SJohannes Berg struct ieee80211_local *local = sta->sdata->local; 512c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 524b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 534b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 544b7679a5SJohannes Berg struct ieee80211_supported_band *sband; 5555de908aSJohannes Berg struct ieee80211_chanctx_conf *chanctx_conf; 564b7679a5SJohannes Berg 57ddcc347bSMichal Kazior ieee80211_sta_set_rx_nss(sta); 58ddcc347bSMichal Kazior 59af65cd96SJohannes Berg if (!ref) 60af65cd96SJohannes Berg return; 61af65cd96SJohannes Berg 6255de908aSJohannes Berg rcu_read_lock(); 6355de908aSJohannes Berg 6455de908aSJohannes Berg chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf); 6555de908aSJohannes Berg if (WARN_ON(!chanctx_conf)) { 6655de908aSJohannes Berg rcu_read_unlock(); 6755de908aSJohannes Berg return; 6855de908aSJohannes Berg } 6955de908aSJohannes Berg 704bf88530SJohannes Berg sband = local->hw.wiphy->bands[chanctx_conf->def.chan->band]; 714b7679a5SJohannes Berg 723de805cfSSimon Wunderlich ref->ops->rate_init(ref->priv, sband, &chanctx_conf->def, ista, 733de805cfSSimon Wunderlich priv_sta); 743de805cfSSimon Wunderlich rcu_read_unlock(); 75e1936e94SJohannes Berg set_sta_flag(sta, WLAN_STA_RATE_CONTROL); 762c8dccc7SJohannes Berg } 772c8dccc7SJohannes Berg 7881cb7623SSujith static inline void rate_control_rate_update(struct ieee80211_local *local, 7981cb7623SSujith struct ieee80211_supported_band *sband, 8064f68e5dSJohannes Berg struct sta_info *sta, u32 changed) 8181cb7623SSujith { 8281cb7623SSujith struct rate_control_ref *ref = local->rate_ctrl; 8381cb7623SSujith struct ieee80211_sta *ista = &sta->sta; 8481cb7623SSujith void *priv_sta = sta->rate_ctrl_priv; 853de805cfSSimon Wunderlich struct ieee80211_chanctx_conf *chanctx_conf; 8681cb7623SSujith 873de805cfSSimon Wunderlich if (ref && ref->ops->rate_update) { 883de805cfSSimon Wunderlich rcu_read_lock(); 893de805cfSSimon Wunderlich 903de805cfSSimon Wunderlich chanctx_conf = rcu_dereference(sta->sdata->vif.chanctx_conf); 913de805cfSSimon Wunderlich if (WARN_ON(!chanctx_conf)) { 923de805cfSSimon Wunderlich rcu_read_unlock(); 933de805cfSSimon Wunderlich return; 943de805cfSSimon Wunderlich } 953de805cfSSimon Wunderlich 963de805cfSSimon Wunderlich ref->ops->rate_update(ref->priv, sband, &chanctx_conf->def, 973de805cfSSimon Wunderlich ista, priv_sta, changed); 983de805cfSSimon Wunderlich rcu_read_unlock(); 993de805cfSSimon Wunderlich } 1008f727ef3SJohannes Berg drv_sta_rc_update(local, sta->sdata, &sta->sta, changed); 10181cb7623SSujith } 1022c8dccc7SJohannes Berg 1032c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, 1044b7679a5SJohannes Berg struct ieee80211_sta *sta, 1052c8dccc7SJohannes Berg gfp_t gfp) 1062c8dccc7SJohannes Berg { 1074b7679a5SJohannes Berg return ref->ops->alloc_sta(ref->priv, sta, gfp); 1082c8dccc7SJohannes Berg } 1092c8dccc7SJohannes Berg 1104b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta) 1112c8dccc7SJohannes Berg { 1124b7679a5SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 1134b7679a5SJohannes Berg struct ieee80211_sta *ista = &sta->sta; 1144b7679a5SJohannes Berg void *priv_sta = sta->rate_ctrl_priv; 1154b7679a5SJohannes Berg 1164b7679a5SJohannes Berg ref->ops->free_sta(ref->priv, ista, priv_sta); 1172c8dccc7SJohannes Berg } 1182c8dccc7SJohannes Berg 1192c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta) 1202c8dccc7SJohannes Berg { 1212c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS 1222c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 123af65cd96SJohannes Berg if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs) 1242c8dccc7SJohannes Berg ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, 1252c8dccc7SJohannes Berg sta->debugfs.dir); 1262c8dccc7SJohannes Berg #endif 1272c8dccc7SJohannes Berg } 1282c8dccc7SJohannes Berg 1292c8dccc7SJohannes Berg static inline void rate_control_remove_sta_debugfs(struct sta_info *sta) 1302c8dccc7SJohannes Berg { 1312c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS 1322c8dccc7SJohannes Berg struct rate_control_ref *ref = sta->rate_ctrl; 133af65cd96SJohannes Berg if (ref && ref->ops->remove_sta_debugfs) 1342c8dccc7SJohannes Berg ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv); 1352c8dccc7SJohannes Berg #endif 1362c8dccc7SJohannes Berg } 1372c8dccc7SJohannes Berg 138209c671dSAndres Salomon /* Get a reference to the rate control algorithm. If `name' is NULL, get the 139209c671dSAndres Salomon * first available algorithm. */ 1402c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, 1412c8dccc7SJohannes Berg const char *name); 1422c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local); 1432c8dccc7SJohannes Berg 1442c8dccc7SJohannes Berg 1452c8dccc7SJohannes Berg /* Rate control algorithms */ 146e5f5e733SAdrian Bunk #ifdef CONFIG_MAC80211_RC_PID 147c1b1203dSJoe Perches int rc80211_pid_init(void); 148c1b1203dSJoe Perches void rc80211_pid_exit(void); 1492c8dccc7SJohannes Berg #else 1502c8dccc7SJohannes Berg static inline int rc80211_pid_init(void) 1512c8dccc7SJohannes Berg { 1522c8dccc7SJohannes Berg return 0; 1532c8dccc7SJohannes Berg } 1542c8dccc7SJohannes Berg static inline void rc80211_pid_exit(void) 1552c8dccc7SJohannes Berg { 1562c8dccc7SJohannes Berg } 1572c8dccc7SJohannes Berg #endif 1582c8dccc7SJohannes Berg 159cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL 160c1b1203dSJoe Perches int rc80211_minstrel_init(void); 161c1b1203dSJoe Perches void rc80211_minstrel_exit(void); 162cccf129fSFelix Fietkau #else 163cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void) 164cccf129fSFelix Fietkau { 165cccf129fSFelix Fietkau return 0; 166cccf129fSFelix Fietkau } 167cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void) 168cccf129fSFelix Fietkau { 169cccf129fSFelix Fietkau } 170cccf129fSFelix Fietkau #endif 171cccf129fSFelix Fietkau 172ec8aa669SFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL_HT 173c1b1203dSJoe Perches int rc80211_minstrel_ht_init(void); 174c1b1203dSJoe Perches void rc80211_minstrel_ht_exit(void); 175ec8aa669SFelix Fietkau #else 176ec8aa669SFelix Fietkau static inline int rc80211_minstrel_ht_init(void) 177ec8aa669SFelix Fietkau { 178ec8aa669SFelix Fietkau return 0; 179ec8aa669SFelix Fietkau } 180ec8aa669SFelix Fietkau static inline void rc80211_minstrel_ht_exit(void) 181ec8aa669SFelix Fietkau { 182ec8aa669SFelix Fietkau } 183ec8aa669SFelix Fietkau #endif 184ec8aa669SFelix Fietkau 185cccf129fSFelix Fietkau 1862c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */ 187