Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2002-2005, Instant802 Networks, Inc. |
| 4 | * Copyright 2005, Devicescape Software, Inc. |
| 5 | * Copyright (c) 2006 Jiri Benc <jbenc@suse.cz> |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 6 | */ |
| 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 Berg | 8f727ef | 2012-03-30 08:43:32 +0200 | [diff] [blame] | 17 | #include "driver-ops.h" |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 18 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 19 | struct rate_control_ref { |
Johannes Berg | 631ad70 | 2014-01-20 23:29:34 +0100 | [diff] [blame] | 20 | const struct rate_control_ops *ops; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 21 | void *priv; |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 24 | void rate_control_get_rate(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | e6a9854 | 2008-10-21 12:40:02 +0200 | [diff] [blame] | 25 | struct sta_info *sta, |
| 26 | struct ieee80211_tx_rate_control *txrc); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 27 | |
Felix Fietkau | 18fb84d | 2017-04-26 17:11:35 +0200 | [diff] [blame] | 28 | void rate_control_tx_status(struct ieee80211_local *local, |
| 29 | struct ieee80211_supported_band *sband, |
| 30 | struct ieee80211_tx_status *st); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 31 | |
Denys Vlasenko | eb6d929 | 2015-07-15 14:56:06 +0200 | [diff] [blame] | 32 | void rate_control_rate_init(struct sta_info *sta); |
| 33 | void rate_control_rate_update(struct ieee80211_local *local, |
Sujith | 81cb762 | 2009-02-12 11:38:37 +0530 | [diff] [blame] | 34 | struct ieee80211_supported_band *sband, |
Denys Vlasenko | eb6d929 | 2015-07-15 14:56:06 +0200 | [diff] [blame] | 35 | struct sta_info *sta, u32 changed); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 36 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 37 | static inline void *rate_control_alloc_sta(struct rate_control_ref *ref, |
Johannes Berg | 35c347a | 2015-03-05 16:10:08 +0100 | [diff] [blame] | 38 | struct sta_info *sta, gfp_t gfp) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 39 | { |
Johannes Berg | 35c347a | 2015-03-05 16:10:08 +0100 | [diff] [blame] | 40 | spin_lock_init(&sta->rate_ctrl_lock); |
| 41 | return ref->ops->alloc_sta(ref->priv, &sta->sta, gfp); |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 44 | static inline void rate_control_free_sta(struct sta_info *sta) |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 45 | { |
Johannes Berg | 4b7679a | 2008-09-18 18:14:18 +0200 | [diff] [blame] | 46 | 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 Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 53 | static 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 Berg | fc4a25c | 2016-04-05 11:59:05 +0200 | [diff] [blame] | 57 | if (ref && sta->debugfs_dir && ref->ops->add_sta_debugfs) |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 58 | ref->ops->add_sta_debugfs(ref->priv, sta->rate_ctrl_priv, |
Johannes Berg | fc4a25c | 2016-04-05 11:59:05 +0200 | [diff] [blame] | 59 | sta->debugfs_dir); |
Jiri Benc | e9f207f | 2007-05-05 11:46:38 -0700 | [diff] [blame] | 60 | #endif |
| 61 | } |
| 62 | |
Johannes Berg | 6cb5f3e | 2020-04-23 11:13:49 +0200 | [diff] [blame] | 63 | extern const struct file_operations rcname_ops; |
| 64 | |
| 65 | static 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 Berg | e8e4f52 | 2017-03-08 11:12:10 +0100 | [diff] [blame] | 86 | void ieee80211_check_rate_mask(struct ieee80211_sub_if_data *sdata); |
| 87 | |
Andres Salomon | 209c671 | 2010-02-07 21:47:50 -0500 | [diff] [blame] | 88 | /* Get a reference to the rate control algorithm. If `name' is NULL, get the |
| 89 | * first available algorithm. */ |
Johannes Berg | ff68808 | 2007-07-27 15:43:23 +0200 | [diff] [blame] | 90 | int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local, |
| 91 | const char *name); |
| 92 | void rate_control_deinitialize(struct ieee80211_local *local); |
| 93 | |
Johannes Berg | 4b47589 | 2008-01-02 15:17:03 +0100 | [diff] [blame] | 94 | |
| 95 | /* Rate control algorithms */ |
Felix Fietkau | cccf129 | 2008-10-05 18:07:45 +0200 | [diff] [blame] | 96 | #ifdef CONFIG_MAC80211_RC_MINSTREL |
Joe Perches | c1b1203 | 2013-10-18 13:48:25 -0700 | [diff] [blame] | 97 | int rc80211_minstrel_init(void); |
| 98 | void rc80211_minstrel_exit(void); |
Felix Fietkau | cccf129 | 2008-10-05 18:07:45 +0200 | [diff] [blame] | 99 | #else |
| 100 | static inline int rc80211_minstrel_init(void) |
| 101 | { |
| 102 | return 0; |
| 103 | } |
| 104 | static inline void rc80211_minstrel_exit(void) |
| 105 | { |
| 106 | } |
| 107 | #endif |
| 108 | |
| 109 | |
Jiri Benc | f0706e8 | 2007-05-05 11:45:53 -0700 | [diff] [blame] | 110 | #endif /* IEEE80211_RATE_H */ |