]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/net/wireless/iwlwifi/mvm/tof.c
Merge ath-next from ath.git
[mirror_ubuntu-bionic-kernel.git] / drivers / net / wireless / iwlwifi / mvm / tof.c
CommitLineData
ce792918
GG
1/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2015 Intel Deutschland GmbH
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
25 * in the file called COPYING.
26 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2015 Intel Deutschland GmbH
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63#include "mvm.h"
64#include "fw-api-tof.h"
65
66#define IWL_MVM_TOF_RANGE_REQ_MAX_ID 256
67
68void iwl_mvm_tof_init(struct iwl_mvm *mvm)
69{
70 struct iwl_mvm_tof_data *tof_data = &mvm->tof_data;
71
72 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
73 return;
74
75 memset(tof_data, 0, sizeof(*tof_data));
76
ce792918
GG
77 tof_data->tof_cfg.sub_grp_cmd_id = cpu_to_le32(TOF_CONFIG_CMD);
78
79#ifdef CONFIG_IWLWIFI_DEBUGFS
80 if (IWL_MVM_TOF_IS_RESPONDER) {
ce792918
GG
81 tof_data->responder_cfg.sub_grp_cmd_id =
82 cpu_to_le32(TOF_RESPONDER_CONFIG_CMD);
83 tof_data->responder_cfg.sta_id = IWL_MVM_STATION_COUNT;
84 }
85#endif
86
ce792918
GG
87 tof_data->range_req.sub_grp_cmd_id = cpu_to_le32(TOF_RANGE_REQ_CMD);
88 tof_data->range_req.req_timeout = 1;
89 tof_data->range_req.initiator = 1;
90 tof_data->range_req.report_policy = 3;
91
ce792918
GG
92 tof_data->range_req_ext.sub_grp_cmd_id =
93 cpu_to_le32(TOF_RANGE_REQ_EXT_CMD);
94
95 mvm->tof_data.active_range_request = IWL_MVM_TOF_RANGE_REQ_MAX_ID;
96}
97
98void iwl_mvm_tof_clean(struct iwl_mvm *mvm)
99{
100 struct iwl_mvm_tof_data *tof_data = &mvm->tof_data;
101
102 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
103 return;
104
105 memset(tof_data, 0, sizeof(*tof_data));
106 mvm->tof_data.active_range_request = IWL_MVM_TOF_RANGE_REQ_MAX_ID;
107}
108
109static void iwl_tof_iterator(void *_data, u8 *mac,
110 struct ieee80211_vif *vif)
111{
112 bool *enabled = _data;
113
114 /* non bss vif exists */
115 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION)
116 *enabled = false;
117}
118
119int iwl_mvm_tof_config_cmd(struct iwl_mvm *mvm)
120{
121 struct iwl_tof_config_cmd *cmd = &mvm->tof_data.tof_cfg;
122 bool enabled;
123
124 lockdep_assert_held(&mvm->mutex);
125
126 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
127 return -EINVAL;
128
129 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
130 IEEE80211_IFACE_ITER_NORMAL,
131 iwl_tof_iterator, &enabled);
132 if (!enabled) {
133 IWL_DEBUG_INFO(mvm, "ToF is not supported (non bss vif)\n");
134 return -EINVAL;
135 }
136
137 mvm->tof_data.active_range_request = IWL_MVM_TOF_RANGE_REQ_MAX_ID;
88742c9e
JB
138 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(TOF_CMD,
139 IWL_ALWAYS_LONG_GROUP, 0),
140 0, sizeof(*cmd), cmd);
ce792918
GG
141}
142
143int iwl_mvm_tof_range_abort_cmd(struct iwl_mvm *mvm, u8 id)
144{
145 struct iwl_tof_range_abort_cmd cmd = {
146 .sub_grp_cmd_id = cpu_to_le32(TOF_RANGE_ABORT_CMD),
ce792918
GG
147 .request_id = id,
148 };
149
150 lockdep_assert_held(&mvm->mutex);
151
152 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
153 return -EINVAL;
154
155 if (id != mvm->tof_data.active_range_request) {
156 IWL_ERR(mvm, "Invalid range request id %d (active %d)\n",
157 id, mvm->tof_data.active_range_request);
158 return -EINVAL;
159 }
160
161 /* after abort is sent there's no active request anymore */
162 mvm->tof_data.active_range_request = IWL_MVM_TOF_RANGE_REQ_MAX_ID;
163
88742c9e
JB
164 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(TOF_CMD,
165 IWL_ALWAYS_LONG_GROUP, 0),
166 0, sizeof(cmd), &cmd);
ce792918
GG
167}
168
169#ifdef CONFIG_IWLWIFI_DEBUGFS
170int iwl_mvm_tof_responder_cmd(struct iwl_mvm *mvm,
171 struct ieee80211_vif *vif)
172{
173 struct iwl_tof_responder_config_cmd *cmd = &mvm->tof_data.responder_cfg;
174 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
175
176 lockdep_assert_held(&mvm->mutex);
177
178 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
179 return -EINVAL;
180
181 if (vif->p2p || vif->type != NL80211_IFTYPE_AP) {
182 IWL_ERR(mvm, "Cannot start responder, not in AP mode\n");
183 return -EIO;
184 }
185
186 cmd->sta_id = mvmvif->bcast_sta.sta_id;
88742c9e
JB
187 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(TOF_CMD,
188 IWL_ALWAYS_LONG_GROUP, 0),
189 0, sizeof(*cmd), cmd);
ce792918
GG
190}
191#endif
192
193int iwl_mvm_tof_range_request_cmd(struct iwl_mvm *mvm,
194 struct ieee80211_vif *vif)
195{
196 struct iwl_host_cmd cmd = {
eed6e971 197 .id = iwl_cmd_id(TOF_CMD, IWL_ALWAYS_LONG_GROUP, 0),
ce792918
GG
198 .len = { sizeof(mvm->tof_data.range_req), },
199 /* no copy because of the command size */
200 .dataflags = { IWL_HCMD_DFL_NOCOPY, },
201 };
202
203 lockdep_assert_held(&mvm->mutex);
204
205 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
206 return -EINVAL;
207
208 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
209 IWL_ERR(mvm, "Cannot send range request, not STA mode\n");
210 return -EIO;
211 }
212
213 /* nesting of range requests is not supported in FW */
214 if (mvm->tof_data.active_range_request !=
215 IWL_MVM_TOF_RANGE_REQ_MAX_ID) {
216 IWL_ERR(mvm, "Cannot send range req, already active req %d\n",
217 mvm->tof_data.active_range_request);
218 return -EIO;
219 }
220
221 mvm->tof_data.active_range_request = mvm->tof_data.range_req.request_id;
222
223 cmd.data[0] = &mvm->tof_data.range_req;
224 return iwl_mvm_send_cmd(mvm, &cmd);
225}
226
227int iwl_mvm_tof_range_request_ext_cmd(struct iwl_mvm *mvm,
228 struct ieee80211_vif *vif)
229{
230 lockdep_assert_held(&mvm->mutex);
231
232 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_TOF_SUPPORT))
233 return -EINVAL;
234
235 if (ieee80211_vif_type_p2p(vif) != NL80211_IFTYPE_STATION) {
236 IWL_ERR(mvm, "Cannot send ext range req, not in STA mode\n");
237 return -EIO;
238 }
239
88742c9e
JB
240 return iwl_mvm_send_cmd_pdu(mvm, iwl_cmd_id(TOF_CMD,
241 IWL_ALWAYS_LONG_GROUP, 0),
242 0, sizeof(mvm->tof_data.range_req_ext),
ce792918
GG
243 &mvm->tof_data.range_req_ext);
244}
245
246static int iwl_mvm_tof_range_resp(struct iwl_mvm *mvm, void *data)
247{
248 struct iwl_tof_range_rsp_ntfy *resp = (void *)data;
249
250 if (resp->request_id != mvm->tof_data.active_range_request) {
251 IWL_ERR(mvm, "Request id mismatch, got %d, active %d\n",
252 resp->request_id, mvm->tof_data.active_range_request);
253 return -EIO;
254 }
255
256 memcpy(&mvm->tof_data.range_resp, resp,
257 sizeof(struct iwl_tof_range_rsp_ntfy));
258 mvm->tof_data.active_range_request = IWL_MVM_TOF_RANGE_REQ_MAX_ID;
259
260 return 0;
261}
262
263static int iwl_mvm_tof_mcsi_notif(struct iwl_mvm *mvm, void *data)
264{
265 struct iwl_tof_mcsi_notif *resp = (struct iwl_tof_mcsi_notif *)data;
266
267 IWL_DEBUG_INFO(mvm, "MCSI notification, token %d\n", resp->token);
268 return 0;
269}
270
271static int iwl_mvm_tof_nb_report_notif(struct iwl_mvm *mvm, void *data)
272{
273 struct iwl_tof_neighbor_report *report =
274 (struct iwl_tof_neighbor_report *)data;
275
276 IWL_DEBUG_INFO(mvm, "NB report, bssid %pM, token %d, status 0x%x\n",
277 report->bssid, report->request_token, report->status);
278 return 0;
279}
280
281void iwl_mvm_tof_resp_handler(struct iwl_mvm *mvm,
282 struct iwl_rx_cmd_buffer *rxb)
283{
284 struct iwl_rx_packet *pkt = rxb_addr(rxb);
285 struct iwl_tof_gen_resp_cmd *resp = (void *)pkt->data;
286
287 lockdep_assert_held(&mvm->mutex);
288
289 switch (le32_to_cpu(resp->sub_grp_cmd_id)) {
290 case TOF_RANGE_RESPONSE_NOTIF:
291 iwl_mvm_tof_range_resp(mvm, resp->data);
292 break;
293 case TOF_MCSI_DEBUG_NOTIF:
294 iwl_mvm_tof_mcsi_notif(mvm, resp->data);
295 break;
296 case TOF_NEIGHBOR_REPORT_RSP_NOTIF:
297 iwl_mvm_tof_nb_report_notif(mvm, resp->data);
298 break;
299 default:
300 IWL_ERR(mvm, "Unknown sub-group command 0x%x\n",
301 resp->sub_grp_cmd_id);
302 break;
303 }
304}