blob: 9d2562954fb0a47180a629c322dd09dc7da6c6c0 [file] [log] [blame]
Qiwei Caie689a262018-07-26 15:50:22 +08001/*
2 * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for
5 * any purpose with or without fee is hereby granted, provided that the
6 * above copyright notice and this permission notice appear in all
7 * copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
10 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
11 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
12 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
13 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
14 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
15 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16 * PERFORMANCE OF THIS SOFTWARE.
17 */
18
19/**
20 * DOC: wlan_hdd_active_tos.c
21 *
22 * WLAN active tos functions
23 *
24 */
25
26#include <wlan_hdd_includes.h>
27#include <linux/netdevice.h>
28#include <linux/skbuff.h>
29#include <linux/etherdevice.h>
30#include <linux/if_ether.h>
31#include <wlan_hdd_active_tos.h>
Krunal Sonie71838d2018-09-27 10:45:05 -070032#include "wlan_policy_mgr_ucfg.h"
Harprit Chhabada4691a472018-12-07 11:22:48 -080033#include "wlan_scan_ucfg_api.h"
Qiwei Caie689a262018-07-26 15:50:22 +080034
35/**
36 * tos - Type of service requested by the application
37 * TOS_BK: Back ground traffic
38 * TOS_BE: Best effort traffic
39 * TOS_VI: Video traffic
40 * TOS_VO: Voice traffic
41 */
42enum tos {
43 TOS_BK = 0,
44 TOS_BE = 1,
45 TOS_VI = 2,
46 TOS_VO = 3,
47};
48
49#define HDD_AC_BK_BIT 1
50#define HDD_AC_BE_BIT 2
51#define HDD_AC_VI_BIT 4
52#define HDD_AC_VO_BIT 8
53
54#define HDD_MAX_OFF_CHAN_TIME_FOR_VO 20
55#define HDD_MAX_OFF_CHAN_TIME_FOR_VI 20
56#define HDD_MAX_OFF_CHAN_TIME_FOR_BE 40
57#define HDD_MAX_OFF_CHAN_TIME_FOR_BK 40
58
59#define HDD_MAX_AC 4
60#define HDD_MAX_OFF_CHAN_ENTRIES 2
61
62#define HDD_AC_BIT_INDX 0
63#define HDD_DWELL_TIME_INDX 1
64
65static int limit_off_chan_tbl[HDD_MAX_AC][HDD_MAX_OFF_CHAN_ENTRIES] = {
66 { HDD_AC_BK_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BK },
67 { HDD_AC_BE_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_BE },
68 { HDD_AC_VI_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VI },
69 { HDD_AC_VO_BIT, HDD_MAX_OFF_CHAN_TIME_FOR_VO },
70};
71
72static const struct nla_policy
73wlan_hdd_set_limit_off_channel_param_policy
74[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_MAX + 1] = {
75 [QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS] = {.type = NLA_U8 },
76 [QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_START] = {.type = NLA_U8 },
77};
78
79/**
80 * hdd_set_limit_off_chan_for_tos() - set limit off-channel command parameters
81 * @adapter: HDD adapter
82 * @tos: type of service
83 * @is_tos_active: status of the traffic
84 *
85 * Return: 0 on success and non zero value on failure
86 */
87
88static int
89hdd_set_limit_off_chan_for_tos(struct hdd_adapter *adapter,
90 enum tos tos,
91 bool is_tos_active)
92{
93 int ac_bit;
94 struct hdd_context *hdd_ctx;
95 uint32_t max_off_chan_time = 0;
96 QDF_STATUS status;
97 int ret;
Krunal Sonie71838d2018-09-27 10:45:05 -070098 uint8_t def_sys_pref = 0;
Harprit Chhabada4691a472018-12-07 11:22:48 -080099 uint32_t rest_conc_time;
Qiwei Caie689a262018-07-26 15:50:22 +0800100
101 hdd_ctx = WLAN_HDD_GET_CTX(adapter);
102 ret = wlan_hdd_validate_context(hdd_ctx);
103
104 if (ret < 0)
105 return ret;
Krunal Sonie71838d2018-09-27 10:45:05 -0700106 ucfg_policy_mgr_get_sys_pref(hdd_ctx->psoc,
107 &def_sys_pref);
Qiwei Caie689a262018-07-26 15:50:22 +0800108
109 ac_bit = limit_off_chan_tbl[tos][HDD_AC_BIT_INDX];
110
111 if (is_tos_active)
112 adapter->active_ac |= ac_bit;
113 else
114 adapter->active_ac &= ~ac_bit;
115
116 if (adapter->active_ac) {
117 if (adapter->active_ac & HDD_AC_VO_BIT) {
118 max_off_chan_time =
119 limit_off_chan_tbl[TOS_VO][HDD_DWELL_TIME_INDX];
Dustin Brown76cd2932018-09-11 16:03:05 -0700120 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc,
Qiwei Caie689a262018-07-26 15:50:22 +0800121 PM_LATENCY);
122 } else if (adapter->active_ac & HDD_AC_VI_BIT) {
123 max_off_chan_time =
124 limit_off_chan_tbl[TOS_VI][HDD_DWELL_TIME_INDX];
Dustin Brown76cd2932018-09-11 16:03:05 -0700125 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc,
Qiwei Caie689a262018-07-26 15:50:22 +0800126 PM_LATENCY);
127 } else {
128 /*ignore this command if only BE/BK is active */
129 is_tos_active = false;
Dustin Brown76cd2932018-09-11 16:03:05 -0700130 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc,
Krunal Sonie71838d2018-09-27 10:45:05 -0700131 def_sys_pref);
Qiwei Caie689a262018-07-26 15:50:22 +0800132 }
133 } else {
134 /* No active tos */
Dustin Brown76cd2932018-09-11 16:03:05 -0700135 policy_mgr_set_cur_conc_system_pref(hdd_ctx->psoc,
Krunal Sonie71838d2018-09-27 10:45:05 -0700136 def_sys_pref);
Qiwei Caie689a262018-07-26 15:50:22 +0800137 }
138
Harprit Chhabada4691a472018-12-07 11:22:48 -0800139 ucfg_scan_cfg_get_conc_max_resttime(hdd_ctx->psoc, &rest_conc_time);
Qiwei Caie689a262018-07-26 15:50:22 +0800140 status = sme_send_limit_off_channel_params(hdd_ctx->mac_handle,
141 adapter->session_id,
142 is_tos_active,
143 max_off_chan_time,
Harprit Chhabada4691a472018-12-07 11:22:48 -0800144 rest_conc_time,
Qiwei Caie689a262018-07-26 15:50:22 +0800145 true);
146 if (!QDF_IS_STATUS_SUCCESS(status)) {
147 hdd_err("failed to set limit off chan params");
148 ret = -EINVAL;
149 }
150
151 return ret;
152}
153
154/**
155 * __wlan_hdd_cfg80211_set_limit_offchan_param() - set limit off-channel cmd
156 * parameters
157 * @wiphy: pointer to wireless wiphy structure.
158 * @wdev: pointer to wireless_dev structure.
159 * @data: pointer to limit off-channel command parameters.
160 * @data_len: the length in byte of limit off-channel command parameters.
161 *
162 * This is called when application wants to limit the off channel time due to
163 * active voip traffic.
164 *
165 * Return: An error code or 0 on success.
166 */
167static int
168__wlan_hdd_cfg80211_set_limit_offchan_param(struct wiphy *wiphy,
169 struct wireless_dev *wdev,
170 const void *data,
171 int data_len)
172{
173 struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_MAX + 1];
174 struct net_device *dev = wdev->netdev;
175 struct hdd_adapter *adapter = WLAN_HDD_GET_PRIV_PTR(dev);
176 struct hdd_context *hdd_ctx = wiphy_priv(wiphy);
177 int ret = 0;
178 uint8_t tos;
179 uint8_t tos_status;
180
181 hdd_enter();
182
183 ret = wlan_hdd_validate_context(hdd_ctx);
184 if (ret < 0)
185 return ret;
186
187 if (wlan_cfg80211_nla_parse(tb, QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_MAX,
188 data, data_len,
189 wlan_hdd_set_limit_off_channel_param_policy)) {
190 hdd_err("Invalid ATTR");
191 return -EINVAL;
192 }
193
194 if (!tb[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS]) {
195 hdd_err("attr tos failed");
196 goto fail;
197 }
198
199 tos = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS]);
200 if (tos >= HDD_MAX_AC) {
201 hdd_err("tos value %d exceeded Max value %d",
202 tos, HDD_MAX_AC);
203 goto fail;
204 }
205 hdd_debug("tos %d", tos);
206
207 if (!tb[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_START]) {
208 hdd_err("attr tos active failed");
209 goto fail;
210 }
211 tos_status = nla_get_u8(tb[QCA_WLAN_VENDOR_ATTR_ACTIVE_TOS_START]);
212
213 hdd_debug("tos status %d", tos_status);
214 ret = hdd_set_limit_off_chan_for_tos(adapter, tos, tos_status);
215
216fail:
217 return ret;
218}
219
220int wlan_hdd_cfg80211_set_limit_offchan_param(struct wiphy *wiphy,
221 struct wireless_dev *wdev,
222 const void *data, int data_len)
223
224{
225 int ret;
226
227 cds_ssr_protect(__func__);
228 ret = __wlan_hdd_cfg80211_set_limit_offchan_param(wiphy, wdev, data,
229 data_len);
230 cds_ssr_unprotect(__func__);
231
232 return ret;
233}
234