1 /*
2  * Copyright (c) 2020-2021 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 /**
19  * DOC: wlan_hdd_medium_assess.h
20  *
21  * WLAN Host Device Driver medium assess related implementation
22  *
23  */
24 
25 #if !defined(__WLAN_HDD_MEDIUM_ASSESS_H)
26 #define __WLAN_HDD_MEDIUM_ASSESS_H
27 
28 #include <linux/netdevice.h>
29 #include <net/netlink.h>
30 #include <net/cfg80211.h>
31 #include <qca_vendor.h>
32 #include "wlan_hdd_main.h"
33 
34 #ifdef WLAN_FEATURE_MEDIUM_ASSESS
35 #include "wlan_cp_stats_mc_defs.h"
36 
37 #define MEDIUM_ASSESS_NUM 31
38 
39 /**
40  * struct hdd_medium_assess_config: configuration from framework
41  * @interval: the update period to framework. An integral multiple of 1 second,
42  *	      less or equal to 30 seconds
43  * @threshold: threshold for congestion percentage of pdev
44  */
45 struct hdd_medium_assess_config {
46 	uint8_t interval;
47 	uint8_t threshold;
48 };
49 
50 /**
51  * struct hdd_medium_assess_info: the medium assess info for pdev
52  * @pdev_id: pdev id
53  * @vdev_id: vdev id
54  * @config: config info from user
55  * @index: the data's index
56  * @data: the raw info from fw
57  * @count: the times of timer triggered
58  */
59 struct hdd_medium_assess_info {
60 	uint8_t pdev_id;
61 	uint8_t vdev_id;
62 	struct hdd_medium_assess_config config;
63 
64 	int32_t index;
65 	struct medium_assess_data data[MEDIUM_ASSESS_NUM];
66 
67 	uint32_t count;
68 };
69 
70 /* QCA_NL80211_VENDOR_SUBCMD_MEDIUM_ASSESS */
71 extern const struct nla_policy
72 hdd_medium_assess_policy[QCA_WLAN_VENDOR_ATTR_MEDIUM_ASSESS_MAX + 1];
73 
74 /**
75  * hdd_cfg80211_medium_assess() - medium assess
76  * @wiphy: Pointer to wiphy
77  * @wdev: Pointer to wdev
78  * @data: Pointer to data
79  * @data_len: Data length
80  *
81  * Return: success(0) or reason code for failure
82  */
83 int hdd_cfg80211_medium_assess(struct wiphy *wiphy,
84 			       struct wireless_dev *wdev,
85 			       const void *data,
86 			       int data_len);
87 
88 #define FEATURE_MEDIUM_ASSESS_VENDOR_COMMANDS                         \
89 {                                                                     \
90 	.info.vendor_id = QCA_NL80211_VENDOR_ID,                      \
91 	.info.subcmd = QCA_NL80211_VENDOR_SUBCMD_MEDIUM_ASSESS,       \
92 	.flags = WIPHY_VENDOR_CMD_NEED_WDEV |                         \
93 		WIPHY_VENDOR_CMD_NEED_NETDEV |                        \
94 		WIPHY_VENDOR_CMD_NEED_RUNNING,                        \
95 	.doit = hdd_cfg80211_medium_assess,                           \
96 	vendor_command_policy(hdd_medium_assess_policy,               \
97 			      QCA_WLAN_VENDOR_ATTR_MEDIUM_ASSESS_MAX) \
98 },
99 
100 #define FEATURE_MEDIUM_ASSESS_VENDOR_EVENTS                \
101 [QCA_NL80211_VENDOR_SUBCMD_MEDIUM_ASSESS_INDEX] = {        \
102 	.vendor_id = QCA_NL80211_VENDOR_ID,                \
103 	.subcmd = QCA_NL80211_VENDOR_SUBCMD_MEDIUM_ASSESS, \
104 },
105 
106 /**
107  * hdd_medium_assess_ssr_reinit() - medium assess reinit timer in ssr
108  *
109  * Return: none
110  */
111 void hdd_medium_assess_ssr_reinit(void);
112 
113 /**
114  * hdd_medium_assess_stop_timer() - medium assess reset and stop timer
115  * @pdev_id: pdev id
116  * @hdd_ctx: hdd context
117  *
118  * Return: none
119  */
120 void hdd_medium_assess_stop_timer(uint8_t pdev_id, struct hdd_context *hdd_ctx);
121 
122 /**
123  * hdd_medium_assess_ssr_enable_flag() - medium assess set ssr enable flag
124  *
125  * Return: none
126  */
127 void hdd_medium_assess_ssr_enable_flag(void);
128 #else
129 #define FEATURE_MEDIUM_ASSESS_VENDOR_COMMANDS
130 #define FEATURE_MEDIUM_ASSESS_VENDOR_EVENTS
hdd_medium_assess_ssr_reinit(void)131 static inline void hdd_medium_assess_ssr_reinit(void) {}
hdd_medium_assess_stop_timer(uint8_t pdev_id,struct hdd_context * hdd_ctx)132 static inline void hdd_medium_assess_stop_timer(uint8_t pdev_id,
133 						struct hdd_context *hdd_ctx) {}
hdd_medium_assess_ssr_enable_flag(void)134 static inline void hdd_medium_assess_ssr_enable_flag(void) {}
135 #endif
136 #endif /* end #if !defined(__WLAN_HDD_MEDIUM_ASSESS_H) */
137