xref: /openbmc/linux/net/mac80211/rate.h (revision 3c384053ce4cb1949f5575c28e30e6ceea8cb39b)
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,
34e6a9854bSJohannes Berg 			   struct sta_info *sta,
35e6a9854bSJohannes Berg 			   struct ieee80211_tx_rate_control *txrc);
362c8dccc7SJohannes Berg struct rate_control_ref *rate_control_get(struct rate_control_ref *ref);
372c8dccc7SJohannes Berg void rate_control_put(struct rate_control_ref *ref);
382c8dccc7SJohannes Berg 
394b7679a5SJohannes Berg static inline void rate_control_tx_status(struct ieee80211_local *local,
404b7679a5SJohannes Berg 					  struct ieee80211_supported_band *sband,
414b7679a5SJohannes Berg 					  struct sta_info *sta,
42e039fa4aSJohannes Berg 					  struct sk_buff *skb)
432c8dccc7SJohannes Berg {
442c8dccc7SJohannes Berg 	struct rate_control_ref *ref = local->rate_ctrl;
454b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
464b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
47*3c384053SVasanthakumar 
48*3c384053SVasanthakumar 	if (!ref)
49*3c384053SVasanthakumar 		return;
50*3c384053SVasanthakumar 
514b7679a5SJohannes Berg 	ref->ops->tx_status(ref->priv, sband, ista, priv_sta, skb);
522c8dccc7SJohannes Berg }
532c8dccc7SJohannes Berg 
542c8dccc7SJohannes Berg 
554b7679a5SJohannes Berg static inline void rate_control_rate_init(struct sta_info *sta)
562c8dccc7SJohannes Berg {
574b7679a5SJohannes Berg 	struct ieee80211_local *local = sta->sdata->local;
582c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
594b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
604b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
614b7679a5SJohannes Berg 	struct ieee80211_supported_band *sband;
624b7679a5SJohannes Berg 
63af65cd96SJohannes Berg 	if (!ref)
64af65cd96SJohannes Berg 		return;
65af65cd96SJohannes Berg 
664b7679a5SJohannes Berg 	sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
674b7679a5SJohannes Berg 
684b7679a5SJohannes Berg 	ref->ops->rate_init(ref->priv, sband, ista, priv_sta);
692c8dccc7SJohannes Berg }
702c8dccc7SJohannes Berg 
7181cb7623SSujith static inline void rate_control_rate_update(struct ieee80211_local *local,
7281cb7623SSujith 				    struct ieee80211_supported_band *sband,
7381cb7623SSujith 				    struct sta_info *sta, u32 changed)
7481cb7623SSujith {
7581cb7623SSujith 	struct rate_control_ref *ref = local->rate_ctrl;
7681cb7623SSujith 	struct ieee80211_sta *ista = &sta->sta;
7781cb7623SSujith 	void *priv_sta = sta->rate_ctrl_priv;
7881cb7623SSujith 
79af65cd96SJohannes Berg 	if (ref && ref->ops->rate_update)
8081cb7623SSujith 		ref->ops->rate_update(ref->priv, sband, ista,
8181cb7623SSujith 				      priv_sta, changed);
8281cb7623SSujith }
832c8dccc7SJohannes Berg 
842c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
854b7679a5SJohannes Berg 					   struct ieee80211_sta *sta,
862c8dccc7SJohannes Berg 					   gfp_t gfp)
872c8dccc7SJohannes Berg {
884b7679a5SJohannes Berg 	return ref->ops->alloc_sta(ref->priv, sta, gfp);
892c8dccc7SJohannes Berg }
902c8dccc7SJohannes Berg 
914b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta)
922c8dccc7SJohannes Berg {
934b7679a5SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
944b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
954b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
964b7679a5SJohannes Berg 
974b7679a5SJohannes Berg 	ref->ops->free_sta(ref->priv, ista, priv_sta);
982c8dccc7SJohannes Berg }
992c8dccc7SJohannes Berg 
1002c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
1012c8dccc7SJohannes Berg {
1022c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
1032c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
104af65cd96SJohannes Berg 	if (ref && sta->debugfs.dir && ref->ops->add_sta_debugfs)
1052c8dccc7SJohannes Berg 		ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
1062c8dccc7SJohannes Berg 					  sta->debugfs.dir);
1072c8dccc7SJohannes Berg #endif
1082c8dccc7SJohannes Berg }
1092c8dccc7SJohannes Berg 
1102c8dccc7SJohannes Berg static inline void rate_control_remove_sta_debugfs(struct sta_info *sta)
1112c8dccc7SJohannes Berg {
1122c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
1132c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
114af65cd96SJohannes Berg 	if (ref && ref->ops->remove_sta_debugfs)
1152c8dccc7SJohannes Berg 		ref->ops->remove_sta_debugfs(ref->priv, sta->rate_ctrl_priv);
1162c8dccc7SJohannes Berg #endif
1172c8dccc7SJohannes Berg }
1182c8dccc7SJohannes Berg 
1192c8dccc7SJohannes Berg /* functions for rate control related to a device */
1202c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
1212c8dccc7SJohannes Berg 				 const char *name);
1222c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local);
1232c8dccc7SJohannes Berg 
1242c8dccc7SJohannes Berg 
1252c8dccc7SJohannes Berg /* Rate control algorithms */
126e5f5e733SAdrian Bunk #ifdef CONFIG_MAC80211_RC_PID
1272c8dccc7SJohannes Berg extern int rc80211_pid_init(void);
1282c8dccc7SJohannes Berg extern void rc80211_pid_exit(void);
1292c8dccc7SJohannes Berg #else
1302c8dccc7SJohannes Berg static inline int rc80211_pid_init(void)
1312c8dccc7SJohannes Berg {
1322c8dccc7SJohannes Berg 	return 0;
1332c8dccc7SJohannes Berg }
1342c8dccc7SJohannes Berg static inline void rc80211_pid_exit(void)
1352c8dccc7SJohannes Berg {
1362c8dccc7SJohannes Berg }
1372c8dccc7SJohannes Berg #endif
1382c8dccc7SJohannes Berg 
139cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL
140cccf129fSFelix Fietkau extern int rc80211_minstrel_init(void);
141cccf129fSFelix Fietkau extern void rc80211_minstrel_exit(void);
142cccf129fSFelix Fietkau #else
143cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void)
144cccf129fSFelix Fietkau {
145cccf129fSFelix Fietkau 	return 0;
146cccf129fSFelix Fietkau }
147cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void)
148cccf129fSFelix Fietkau {
149cccf129fSFelix Fietkau }
150cccf129fSFelix Fietkau #endif
151cccf129fSFelix Fietkau 
152cccf129fSFelix Fietkau 
1532c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */
154