xref: /linux/net/mac80211/rate.h (revision 4b132aacb0768ac1e652cf517097ea6f237214b9)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright 2002-2005, Instant802 Networks, Inc.
4  * Copyright 2005, Devicescape Software, Inc.
5  * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
6  * Copyright (C) 2022 Intel Corporation
7  */
8 
9 #ifndef IEEE80211_RATE_H
10 #define IEEE80211_RATE_H
11 
12 #include <linux/netdevice.h>
13 #include <linux/skbuff.h>
14 #include <linux/types.h>
15 #include <net/mac80211.h>
16 #include "ieee80211_i.h"
17 #include "sta_info.h"
18 #include "driver-ops.h"
19 
20 struct rate_control_ref {
21 	const struct rate_control_ops *ops;
22 	void *priv;
23 };
24 
25 void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
26 			   struct sta_info *sta,
27 			   struct ieee80211_tx_rate_control *txrc);
28 
29 void rate_control_tx_status(struct ieee80211_local *local,
30 			    struct ieee80211_tx_status *st);
31 
32 void rate_control_rate_init(struct sta_info *sta);
33 void rate_control_rate_update(struct ieee80211_local *local,
34 			      struct ieee80211_supported_band *sband,
35 			      struct sta_info *sta,
36 			      unsigned int link_id,
37 			      u32 changed);
38 
39 static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
40 					   struct sta_info *sta, gfp_t gfp)
41 {
42 	spin_lock_init(&sta->rate_ctrl_lock);
43 	return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp);
44 }
45 
46 static inline void rate_control_free_sta(struct sta_info *sta)
47 {
48 	struct rate_control_ref *ref = sta->rate_ctrl;
49 	struct ieee80211_sta *ista = &sta->sta;
50 	void *priv_sta = sta->rate_ctrl_priv;
51 
52 	ref->ops->free_sta(ref->priv, ista, priv_sta);
53 }
54 
55 static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
56 {
57 #ifdef CONFIG_MAC80211_DEBUGFS
58 	struct rate_control_ref *ref = sta->rate_ctrl;
59 	if (ref && sta->debugfs_dir && ref->ops->add_sta_debugfs)
60 		ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
61 					  sta->debugfs_dir);
62 #endif
63 }
64 
65 extern const struct file_operations rcname_ops;
66 
67 static inline void rate_control_add_debugfs(struct ieee80211_local *local)
68 {
69 #ifdef CONFIG_MAC80211_DEBUGFS
70 	struct dentry *debugfsdir;
71 
72 	if (!local->rate_ctrl)
73 		return;
74 
75 	if (!local->rate_ctrl->ops->add_debugfs)
76 		return;
77 
78 	debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
79 	local->debugfs.rcdir = debugfsdir;
80 	debugfs_create_file("name", 0400, debugfsdir,
81 			    local->rate_ctrl, &rcname_ops);
82 
83 	local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
84 					   debugfsdir);
85 #endif
86 }
87 
88 void ieee80211_check_rate_mask(struct ieee80211_link_data *link);
89 
90 /* Get a reference to the rate control algorithm. If `name' is NULL, get the
91  * first available algorithm. */
92 int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
93 				 const char *name);
94 void rate_control_deinitialize(struct ieee80211_local *local);
95 
96 
97 /* Rate control algorithms */
98 #ifdef CONFIG_MAC80211_RC_MINSTREL
99 int rc80211_minstrel_init(void);
100 void rc80211_minstrel_exit(void);
101 #else
102 static inline int rc80211_minstrel_init(void)
103 {
104 	return 0;
105 }
106 static inline void rc80211_minstrel_exit(void)
107 {
108 }
109 #endif
110 
111 
112 #endif /* IEEE80211_RATE_H */
113