blob: 79b44d3db171e9ddbc1d6e2de041d88e350696ac [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Jiri Bencf0706e82007-05-05 11:45:53 -07002/*
3 * Copyright 2002-2005, Instant802 Networks, Inc.
4 * Copyright 2005, Devicescape Software, Inc.
5 * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz>
Jiri Bencf0706e82007-05-05 11:45:53 -07006 */
7
8#ifndef IEEE80211_RATE_H
9#define IEEE80211_RATE_H
10
11#include <linux/netdevice.h>
12#include <linux/skbuff.h>
13#include <linux/types.h>
14#include <net/mac80211.h>
15#include "ieee80211_i.h"
16#include "sta_info.h"
Johannes Berg8f727ef2012-03-30 08:43:32 +020017#include "driver-ops.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070018
Jiri Bencf0706e82007-05-05 11:45:53 -070019struct rate_control_ref {
Johannes Berg631ad702014-01-20 23:29:34 +010020 const struct rate_control_ops *ops;
Jiri Bencf0706e82007-05-05 11:45:53 -070021 void *priv;
Jiri Bencf0706e82007-05-05 11:45:53 -070022};
23
Johannes Berg4b7679a2008-09-18 18:14:18 +020024void rate_control_get_rate(struct ieee80211_sub_if_data *sdata,
Johannes Berge6a98542008-10-21 12:40:02 +020025 struct sta_info *sta,
26 struct ieee80211_tx_rate_control *txrc);
Jiri Bencf0706e82007-05-05 11:45:53 -070027
Felix Fietkau18fb84d2017-04-26 17:11:35 +020028void rate_control_tx_status(struct ieee80211_local *local,
29 struct ieee80211_supported_band *sband,
30 struct ieee80211_tx_status *st);
Jiri Bencf0706e82007-05-05 11:45:53 -070031
Denys Vlasenkoeb6d9292015-07-15 14:56:06 +020032void rate_control_rate_init(struct sta_info *sta);
33void rate_control_rate_update(struct ieee80211_local *local,
Sujith81cb7622009-02-12 11:38:37 +053034 struct ieee80211_supported_band *sband,
Denys Vlasenkoeb6d9292015-07-15 14:56:06 +020035 struct sta_info *sta, u32 changed);
Jiri Bencf0706e82007-05-05 11:45:53 -070036
Jiri Bencf0706e82007-05-05 11:45:53 -070037static inline void *rate_control_alloc_sta(struct rate_control_ref *ref,
Johannes Berg35c347a2015-03-05 16:10:08 +010038 struct sta_info *sta, gfp_t gfp)
Jiri Bencf0706e82007-05-05 11:45:53 -070039{
Johannes Berg35c347a2015-03-05 16:10:08 +010040 spin_lock_init(&sta->rate_ctrl_lock);
41 return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp);
Jiri Bencf0706e82007-05-05 11:45:53 -070042}
43
Johannes Berg4b7679a2008-09-18 18:14:18 +020044static inline void rate_control_free_sta(struct sta_info *sta)
Jiri Bencf0706e82007-05-05 11:45:53 -070045{
Johannes Berg4b7679a2008-09-18 18:14:18 +020046 struct rate_control_ref *ref = sta->rate_ctrl;
47 struct ieee80211_sta *ista = &sta->sta;
48 void *priv_sta = sta->rate_ctrl_priv;
49
50 ref->ops->free_sta(ref->priv, ista, priv_sta);
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Jiri Bence9f207f2007-05-05 11:46:38 -070053static inline void rate_control_add_sta_debugfs(struct sta_info *sta)
54{
55#ifdef CONFIG_MAC80211_DEBUGFS
56 struct rate_control_ref *ref = sta->rate_ctrl;
Johannes Bergfc4a25c2016-04-05 11:59:05 +020057 if (ref && sta->debugfs_dir && ref->ops->add_sta_debugfs)
Jiri Bence9f207f2007-05-05 11:46:38 -070058 ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv,
Johannes Bergfc4a25c2016-04-05 11:59:05 +020059 sta->debugfs_dir);
Jiri Bence9f207f2007-05-05 11:46:38 -070060#endif
61}
62
Johannes Berg6cb5f3e2020-04-23 11:13:49 +020063extern const struct file_operations rcname_ops;
64
65static inline void rate_control_add_debugfs(struct ieee80211_local *local)
66{
67#ifdef CONFIG_MAC80211_DEBUGFS
68 struct dentry *debugfsdir;
69
70 if (!local->rate_ctrl)
71 return;
72
73 if (!local->rate_ctrl->ops->add_debugfs)
74 return;
75
76 debugfsdir = debugfs_create_dir("rc", local->hw.wiphy->debugfsdir);
77 local->debugfs.rcdir = debugfsdir;
78 debugfs_create_file("name", 0400, debugfsdir,
79 local->rate_ctrl, &rcname_ops);
80
81 local->rate_ctrl->ops->add_debugfs(&local->hw, local->rate_ctrl->priv,
82 debugfsdir);
83#endif
84}
85
Johannes Berge8e4f522017-03-08 11:12:10 +010086void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata);
87
Andres Salomon209c6712010-02-07 21:47:50 -050088/* Get a reference to the rate control algorithm. If `name' is NULL, get the
89 * first available algorithm. */
Johannes Bergff688082007-07-27 15:43:23 +020090int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
91 const char *name);
92void rate_control_deinitialize(struct ieee80211_local *local);
93
Johannes Berg4b475892008-01-02 15:17:03 +010094
95/* Rate control algorithms */
Felix Fietkaucccf1292008-10-05 18:07:45 +020096#ifdef CONFIG_MAC80211_RC_MINSTREL
Joe Perchesc1b12032013-10-18 13:48:25 -070097int rc80211_minstrel_init(void);
98void rc80211_minstrel_exit(void);
Felix Fietkaucccf1292008-10-05 18:07:45 +020099#else
100static inline int rc80211_minstrel_init(void)
101{
102 return 0;
103}
104static inline void rc80211_minstrel_exit(void)
105{
106}
107#endif
108
109
Jiri Bencf0706e82007-05-05 11:45:53 -0700110#endif /* IEEE80211_RATE_H */