xref: /openbmc/linux/net/mac80211/rate.h (revision b4f85443c17c7edb49c82fc1d28d26860c8c850d)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
22c8dccc7SJohannes Berg /*
32c8dccc7SJohannes Berg  * Copyright 2002-2005, Instant802 Networks, Inc.
42c8dccc7SJohannes Berg  * Copyright 2005, Devicescape Software, Inc.
52c8dccc7SJohannes Berg  * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
6*b4f85443SJohannes Berg  * Copyright (C) 2022 Intel Corporation
72c8dccc7SJohannes Berg  */
82c8dccc7SJohannes Berg 
92c8dccc7SJohannes Berg #ifndef IEEE80211_RATE_H
102c8dccc7SJohannes Berg #define IEEE80211_RATE_H
112c8dccc7SJohannes Berg 
122c8dccc7SJohannes Berg #include <linux/netdevice.h>
132c8dccc7SJohannes Berg #include <linux/skbuff.h>
142c8dccc7SJohannes Berg #include <linux/types.h>
152c8dccc7SJohannes Berg #include <net/mac80211.h>
162c8dccc7SJohannes Berg #include "ieee80211_i.h"
172c8dccc7SJohannes Berg #include "sta_info.h"
188f727ef3SJohannes Berg #include "driver-ops.h"
192c8dccc7SJohannes Berg 
202c8dccc7SJohannes Berg struct rate_control_ref {
21631ad703SJohannes Berg 	const struct rate_control_ops *ops;
222c8dccc7SJohannes Berg 	void *priv;
232c8dccc7SJohannes Berg };
242c8dccc7SJohannes Berg 
254b7679a5SJohannes Berg void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
26e6a9854bSJohannes Berg 			   struct sta_info *sta,
27e6a9854bSJohannes Berg 			   struct ieee80211_tx_rate_control *txrc);
282c8dccc7SJohannes Berg 
2918fb84d9SFelix Fietkau void rate_control_tx_status(struct ieee80211_local *local,
304b7679a5SJohannes Berg 			    struct ieee80211_supported_band *sband,
3118fb84d9SFelix Fietkau 			    struct ieee80211_tx_status *st);
322c8dccc7SJohannes Berg 
33eb6d9293SDenys Vlasenko void rate_control_rate_init(struct sta_info *sta);
34eb6d9293SDenys Vlasenko void rate_control_rate_update(struct ieee80211_local *local,
3581cb7623SSujith 			      struct ieee80211_supported_band *sband,
36*b4f85443SJohannes Berg 			      struct sta_info *sta,
37*b4f85443SJohannes Berg 			      unsigned int link_id,
38*b4f85443SJohannes Berg 			      u32 changed);
392c8dccc7SJohannes Berg 
402c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
4135c347acSJohannes Berg 					   struct sta_info *sta, gfp_t gfp)
422c8dccc7SJohannes Berg {
4335c347acSJohannes Berg 	spin_lock_init(&sta->rate_ctrl_lock);
4435c347acSJohannes Berg 	return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp);
452c8dccc7SJohannes Berg }
462c8dccc7SJohannes Berg 
474b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta)
482c8dccc7SJohannes Berg {
494b7679a5SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
504b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
514b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
524b7679a5SJohannes Berg 
534b7679a5SJohannes Berg 	ref->ops->free_sta(ref->priv, ista, priv_sta);
542c8dccc7SJohannes Berg }
552c8dccc7SJohannes Berg 
562c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
572c8dccc7SJohannes Berg {
582c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
592c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
60fc4a25c5SJohannes Berg 	if (ref && sta->debugfs_dir && ref->ops->add_sta_debugfs)
612c8dccc7SJohannes Berg 		ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
62fc4a25c5SJohannes Berg 					  sta->debugfs_dir);
632c8dccc7SJohannes Berg #endif
642c8dccc7SJohannes Berg }
652c8dccc7SJohannes Berg 
666cb5f3eaSJohannes Berg extern const struct file_operations rcname_ops;
676cb5f3eaSJohannes Berg 
686cb5f3eaSJohannes Berg static inline void rate_control_add_debugfs(struct ieee80211_local *local)
696cb5f3eaSJohannes Berg {
706cb5f3eaSJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
716cb5f3eaSJohannes Berg 	struct dentry *debugfsdir;
726cb5f3eaSJohannes Berg 
736cb5f3eaSJohannes Berg 	if (!local->rate_ctrl)
746cb5f3eaSJohannes Berg 		return;
756cb5f3eaSJohannes Berg 
766cb5f3eaSJohannes Berg 	if (!local->rate_ctrl->ops->add_debugfs)
776cb5f3eaSJohannes Berg 		return;
786cb5f3eaSJohannes Berg 
796cb5f3eaSJohannes Berg 	debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
806cb5f3eaSJohannes Berg 	local->debugfs.rcdir = debugfsdir;
816cb5f3eaSJohannes Berg 	debugfs_create_file("name", 0400, debugfsdir,
826cb5f3eaSJohannes Berg 			    local->rate_ctrl, &rcname_ops);
836cb5f3eaSJohannes Berg 
846cb5f3eaSJohannes Berg 	local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
856cb5f3eaSJohannes Berg 					   debugfsdir);
866cb5f3eaSJohannes Berg #endif
876cb5f3eaSJohannes Berg }
886cb5f3eaSJohannes Berg 
89e8e4f528SJohannes Berg void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
90e8e4f528SJohannes Berg 
91209c671dSAndres Salomon /* Get a reference to the rate control algorithm. If `name' is NULL, get the
92209c671dSAndres Salomon  * first available algorithm. */
932c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
942c8dccc7SJohannes Berg 				 const char *name);
952c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local);
962c8dccc7SJohannes Berg 
972c8dccc7SJohannes Berg 
982c8dccc7SJohannes Berg /* Rate control algorithms */
99cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL
100c1b1203dSJoe Perches int rc80211_minstrel_init(void);
101c1b1203dSJoe Perches void rc80211_minstrel_exit(void);
102cccf129fSFelix Fietkau #else
103cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void)
104cccf129fSFelix Fietkau {
105cccf129fSFelix Fietkau 	return 0;
106cccf129fSFelix Fietkau }
107cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void)
108cccf129fSFelix Fietkau {
109cccf129fSFelix Fietkau }
110cccf129fSFelix Fietkau #endif
111cccf129fSFelix Fietkau 
112cccf129fSFelix Fietkau 
1132c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */
114