xref: /openbmc/linux/net/mac80211/rate.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
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>
6b4f85443SJohannes 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,
3018fb84d9SFelix Fietkau 			    struct ieee80211_tx_status *st);
312c8dccc7SJohannes Berg 
32eb6d9293SDenys Vlasenko void rate_control_rate_init(struct sta_info *sta);
33eb6d9293SDenys Vlasenko void rate_control_rate_update(struct ieee80211_local *local,
3481cb7623SSujith 			      struct ieee80211_supported_band *sband,
35b4f85443SJohannes Berg 			      struct sta_info *sta,
36b4f85443SJohannes Berg 			      unsigned int link_id,
37b4f85443SJohannes Berg 			      u32 changed);
382c8dccc7SJohannes Berg 
rate_control_alloc_sta(struct rate_control_ref * ref,struct sta_info * sta,gfp_t gfp)392c8dccc7SJohannes Berg static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
4035c347acSJohannes Berg 					   struct sta_info *sta, gfp_t gfp)
412c8dccc7SJohannes Berg {
4235c347acSJohannes Berg 	spin_lock_init(&sta->rate_ctrl_lock);
4335c347acSJohannes Berg 	return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp);
442c8dccc7SJohannes Berg }
452c8dccc7SJohannes Berg 
rate_control_free_sta(struct sta_info * sta)464b7679a5SJohannes Berg static inline void rate_control_free_sta(struct sta_info *sta)
472c8dccc7SJohannes Berg {
484b7679a5SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
494b7679a5SJohannes Berg 	struct ieee80211_sta *ista = &sta->sta;
504b7679a5SJohannes Berg 	void *priv_sta = sta->rate_ctrl_priv;
514b7679a5SJohannes Berg 
524b7679a5SJohannes Berg 	ref->ops->free_sta(ref->priv, ista, priv_sta);
532c8dccc7SJohannes Berg }
542c8dccc7SJohannes Berg 
rate_control_add_sta_debugfs(struct sta_info * sta)552c8dccc7SJohannes Berg static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
562c8dccc7SJohannes Berg {
572c8dccc7SJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
582c8dccc7SJohannes Berg 	struct rate_control_ref *ref = sta->rate_ctrl;
59fc4a25c5SJohannes Berg 	if (ref && sta->debugfs_dir && ref->ops->add_sta_debugfs)
602c8dccc7SJohannes Berg 		ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
61fc4a25c5SJohannes Berg 					  sta->debugfs_dir);
622c8dccc7SJohannes Berg #endif
632c8dccc7SJohannes Berg }
642c8dccc7SJohannes Berg 
656cb5f3eaSJohannes Berg extern const struct file_operations rcname_ops;
666cb5f3eaSJohannes Berg 
rate_control_add_debugfs(struct ieee80211_local * local)676cb5f3eaSJohannes Berg static inline void rate_control_add_debugfs(struct ieee80211_local *local)
686cb5f3eaSJohannes Berg {
696cb5f3eaSJohannes Berg #ifdef CONFIG_MAC80211_DEBUGFS
706cb5f3eaSJohannes Berg 	struct dentry *debugfsdir;
716cb5f3eaSJohannes Berg 
726cb5f3eaSJohannes Berg 	if (!local->rate_ctrl)
736cb5f3eaSJohannes Berg 		return;
746cb5f3eaSJohannes Berg 
756cb5f3eaSJohannes Berg 	if (!local->rate_ctrl->ops->add_debugfs)
766cb5f3eaSJohannes Berg 		return;
776cb5f3eaSJohannes Berg 
786cb5f3eaSJohannes Berg 	debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
796cb5f3eaSJohannes Berg 	local->debugfs.rcdir = debugfsdir;
806cb5f3eaSJohannes Berg 	debugfs_create_file("name", 0400, debugfsdir,
816cb5f3eaSJohannes Berg 			    local->rate_ctrl, &rcname_ops);
826cb5f3eaSJohannes Berg 
836cb5f3eaSJohannes Berg 	local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
846cb5f3eaSJohannes Berg 					   debugfsdir);
856cb5f3eaSJohannes Berg #endif
866cb5f3eaSJohannes Berg }
876cb5f3eaSJohannes Berg 
88*de03f8acSJohannes Berg void ieee80211_check_rate_mask(struct ieee80211_link_data *link);
89e8e4f528SJohannes Berg 
90209c671dSAndres Salomon /* Get a reference to the rate control algorithm. If `name' is NULL, get the
91209c671dSAndres Salomon  * first available algorithm. */
922c8dccc7SJohannes Berg int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
932c8dccc7SJohannes Berg 				 const char *name);
942c8dccc7SJohannes Berg void rate_control_deinitialize(struct ieee80211_local *local);
952c8dccc7SJohannes Berg 
962c8dccc7SJohannes Berg 
972c8dccc7SJohannes Berg /* Rate control algorithms */
98cccf129fSFelix Fietkau #ifdef CONFIG_MAC80211_RC_MINSTREL
99c1b1203dSJoe Perches int rc80211_minstrel_init(void);
100c1b1203dSJoe Perches void rc80211_minstrel_exit(void);
101cccf129fSFelix Fietkau #else
rc80211_minstrel_init(void)102cccf129fSFelix Fietkau static inline int rc80211_minstrel_init(void)
103cccf129fSFelix Fietkau {
104cccf129fSFelix Fietkau 	return 0;
105cccf129fSFelix Fietkau }
rc80211_minstrel_exit(void)106cccf129fSFelix Fietkau static inline void rc80211_minstrel_exit(void)
107cccf129fSFelix Fietkau {
108cccf129fSFelix Fietkau }
109cccf129fSFelix Fietkau #endif
110cccf129fSFelix Fietkau 
111cccf129fSFelix Fietkau 
1122c8dccc7SJohannes Berg #endif /* IEEE80211_RATE_H */
113