xref: /openbmc/linux/net/mac80211/rate.h (revision 209c671db7a917740ab9873d442b10ae7e369937)
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 
294b7679a5SJohannes Berg void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
30e6a9854bSJohannes Berg 			   struct sta_info *sta,
31e6a9854bSJohannes Berg 			   struct ieee80211_tx_rate_control *txrc);
322c8dccc7SJohannes Berg struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
332c8dccc7SJohannes Berg void rate_control_put(struct rate_control_ref *ref);
342c8dccc7SJohannes Berg 
354b7679a5SJohannes Berg static inline void rate_control_tx_status(struct ieee80211_local *local,
364b7679a5SJohannes Berg 					  struct ieee80211_supported_band *sband,
374b7679a5SJohannes Berg 					  struct sta_info *sta,
38e039fa4aSJohannes Berg 					  struct sk_buff *skb)
392c8dccc7SJohannes Berg {
402c8dccc7SJohannes Berg 	struct rate_control_ref *ref = local->rate_ctrl;
414b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
424b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
433c384053SVasanthakumar 
443c384053SVasanthakumar 	if (!ref)
453c384053SVasanthakumar 		return;
463c384053SVasanthakumar 
474b7679a5SJohannes Berg 	ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
482c8dccc7SJohannes Berg }
492c8dccc7SJohannes Berg 
502c8dccc7SJohannes Berg 
514b7679a5SJohannes Berg static inline void rate_control_rate_init(struct sta_info *sta)
522c8dccc7SJohannes Berg {
534b7679a5SJohannes Berg 	struct ieee80211_local *local = sta->sdata->local;
542c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
554b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
564b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
574b7679a5SJohannes Berg 	struct ieee80211_supported_band *sband;
584b7679a5SJohannes Berg 
59af65cd96SJohannes Berg 	if (!ref)
60af65cd96SJohannes Berg 		return;
61af65cd96SJohannes Berg 
624b7679a5SJohannes Berg 	sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
634b7679a5SJohannes Berg 
644b7679a5SJohannes Berg 	ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
652c8dccc7SJohannes Berg }
662c8dccc7SJohannes Berg 
6781cb7623SSujith static inline void rate_control_rate_update(struct ieee80211_local *local,
6881cb7623SSujith 				    struct ieee80211_supported_band *sband,
6981cb7623SSujith 				    struct sta_info *sta, u32 changed)
7081cb7623SSujith {
7181cb7623SSujith 	struct rate_control_ref *ref = local->rate_ctrl;
7281cb7623SSujith 	struct ieee80211_sta *ista = &sta->sta;
7381cb7623SSujith 	void *priv_sta = sta->rate_ctrl_priv;
7481cb7623SSujith 
75af65cd96SJohannes Berg 	if (ref && ref->ops->rate_update)
7681cb7623SSujith 		ref->ops->rate_update(ref->priv, sband, ista,
7781cb7623SSujith 				      priv_sta, changed);
7881cb7623SSujith }
792c8dccc7SJohannes Berg 
802c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
814b7679a5SJohannes Berg 					   struct ieee80211_sta *sta,
822c8dccc7SJohannes Berg 					   gfp_t gfp)
832c8dccc7SJohannes Berg {
844b7679a5SJohannes Berg 	return ref->ops->alloc_sta(ref->priv, sta, gfp);
852c8dccc7SJohannes Berg }
862c8dccc7SJohannes Berg 
874b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta)
882c8dccc7SJohannes Berg {
894b7679a5SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
904b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
914b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
924b7679a5SJohannes Berg 
934b7679a5SJohannes Berg 	ref->ops->free_sta(ref->priv, ista, priv_sta);
942c8dccc7SJohannes Berg }
952c8dccc7SJohannes Berg 
962c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
972c8dccc7SJohannes Berg {
982c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
992c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
100af65cd96SJohannes Berg 	if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
1012c8dccc7SJohannes Berg 		ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
1022c8dccc7SJohannes Berg 					  sta->debugfs.dir);
1032c8dccc7SJohannes Berg #endif
1042c8dccc7SJohannes Berg }
1052c8dccc7SJohannes Berg 
1062c8dccc7SJohannes Berg static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
1072c8dccc7SJohannes Berg {
1082c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
1092c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
110af65cd96SJohannes Berg 	if (ref && ref->ops->remove_sta_debugfs)
1112c8dccc7SJohannes Berg 		ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
1122c8dccc7SJohannes Berg #endif
1132c8dccc7SJohannes Berg }
1142c8dccc7SJohannes Berg 
115*209c671dSAndres Salomon /* Get a reference to the rate control algorithm. If `name' is NULL, get the
116*209c671dSAndres Salomon  * first available algorithm. */
1172c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
1182c8dccc7SJohannes Berg 				 const char *name);
1192c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local);
1202c8dccc7SJohannes Berg 
1212c8dccc7SJohannes Berg 
1222c8dccc7SJohannes Berg /* Rate control algorithms */
123e5f5e733SAdrian Bunk #ifdef CONFIG_MAC80211_RC_PID
1242c8dccc7SJohannes Berg extern int rc80211_pid_init(void);
1252c8dccc7SJohannes Berg extern void rc80211_pid_exit(void);
1262c8dccc7SJohannes Berg #else
1272c8dccc7SJohannes Berg static inline int rc80211_pid_init(void)
1282c8dccc7SJohannes Berg {
1292c8dccc7SJohannes Berg 	return 0;
1302c8dccc7SJohannes Berg }
1312c8dccc7SJohannes Berg static inline void rc80211_pid_exit(void)
1322c8dccc7SJohannes Berg {
1332c8dccc7SJohannes Berg }
1342c8dccc7SJohannes Berg #endif
1352c8dccc7SJohannes Berg 
136cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL
137cccf129fSFelix Fietkau extern int rc80211_minstrel_init(void);
138cccf129fSFelix Fietkau extern void rc80211_minstrel_exit(void);
139cccf129fSFelix Fietkau #else
140cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void)
141cccf129fSFelix Fietkau {
142cccf129fSFelix Fietkau 	return 0;
143cccf129fSFelix Fietkau }
144cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void)
145cccf129fSFelix Fietkau {
146cccf129fSFelix Fietkau }
147cccf129fSFelix Fietkau #endif
148cccf129fSFelix Fietkau 
149cccf129fSFelix Fietkau 
1502c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */
151