blob: 88bee03309fb75170c9fd021ab1555d702dcdc30 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Maya Erez0916d9f2016-01-17 12:39:10 +02002 * Copyright (c) 2012-2016 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +030017#include <linux/moduleparam.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080018#include <linux/etherdevice.h>
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +020019#include <linux/if_arp.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080020
21#include "wil6210.h"
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +020022#include "txrx.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080023#include "wmi.h"
Vladimir Kondratiev98658092013-05-12 14:43:35 +030024#include "trace.h"
Lior David8f1b5e02017-02-28 14:58:27 +020025#include "ftm.h"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080026
Vladimir Kondratiev327755f2014-12-23 09:47:13 +020027static uint max_assoc_sta = WIL6210_MAX_CID;
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +030028module_param(max_assoc_sta, uint, S_IRUGO | S_IWUSR);
29MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP");
30
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +020031int agg_wsize; /* = 0; */
32module_param(agg_wsize, int, S_IRUGO | S_IWUSR);
33MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;"
34 " 0 - use default; < 0 - don't auto-establish");
35
Maya Erez10d599a2016-05-09 21:57:11 +030036u8 led_id = WIL_LED_INVALID_ID;
37module_param(led_id, byte, S_IRUGO);
38MODULE_PARM_DESC(led_id,
39 " 60G device led enablement. Set the led ID (0-2) to enable");
40
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080041/**
42 * WMI event receiving - theory of operations
43 *
44 * When firmware about to report WMI event, it fills memory area
45 * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
46 * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
47 *
48 * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
49 * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
50 * and handles events within the @wmi_event_worker. Every event get detached
51 * from list, processed and deleted.
52 *
53 * Purpose for this mechanism is to release IRQ thread; otherwise,
54 * if WMI event handling involves another WMI command flow, this 2-nd flow
55 * won't be completed because of blocked IRQ thread.
56 */
57
58/**
59 * Addressing - theory of operations
60 *
61 * There are several buses present on the WIL6210 card.
62 * Same memory areas are visible at different address on
63 * the different busses. There are 3 main bus masters:
64 * - MAC CPU (ucode)
65 * - User CPU (firmware)
66 * - AHB (host)
67 *
68 * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
69 * AHB addresses starting from 0x880000
70 *
71 * Internally, firmware uses addresses that allows faster access but
72 * are invisible from the host. To read from these addresses, alternative
73 * AHB address must be used.
74 *
75 * Memory mapping
76 * Linker address PCI/Host address
77 * 0x880000 .. 0xa80000 2Mb BAR0
78 * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM
79 * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH
80 */
81
82/**
83 * @fw_mapping provides memory remapping table
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030084 *
85 * array size should be in sync with the declaration in the wil6210.h
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080086 */
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030087const struct fw_map fw_mapping[] = {
88 {0x000000, 0x040000, 0x8c0000, "fw_code"}, /* FW code RAM 256k */
89 {0x800000, 0x808000, 0x900000, "fw_data"}, /* FW data RAM 32k */
90 {0x840000, 0x860000, 0x908000, "fw_peri"}, /* periph. data RAM 128k */
91 {0x880000, 0x88a000, 0x880000, "rgf"}, /* various RGF 40k */
Vladimir Kondratiev72269142014-07-14 09:49:43 +030092 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl"}, /* AGC table 4k */
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030093 {0x88b000, 0x88c000, 0x88b000, "rgf_ext"}, /* Pcie_ext_rgf 4k */
Vladimir Kondratiev0fd37ff2015-06-09 14:11:17 +030094 {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext"}, /* mac_ext_rgf 512b */
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030095 {0x8c0000, 0x949000, 0x8c0000, "upper"}, /* upper area 548k */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080096 /*
97 * 920000..930000 ucode code RAM
98 * 930000..932000 ucode data RAM
Vladimir Kondratievaf6b48d2013-06-09 09:12:51 +030099 * 932000..949000 back-door debug data
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800100 */
101};
102
Maya Erez10d599a2016-05-09 21:57:11 +0300103struct blink_on_off_time led_blink_time[] = {
104 {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS},
105 {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS},
106 {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS},
107};
108
109u8 led_polarity = LED_POLARITY_LOW_ACTIVE;
110
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800111/**
112 * return AHB address for given firmware/ucode internal (linker) address
113 * @x - internal address
114 * If address have no valid AHB mapping, return 0
115 */
116static u32 wmi_addr_remap(u32 x)
117{
118 uint i;
119
120 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
121 if ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to))
122 return x + fw_mapping[i].host - fw_mapping[i].from;
123 }
124
125 return 0;
126}
127
128/**
129 * Check address validity for WMI buffer; remap if needed
130 * @ptr - internal (linker) fw/ucode address
131 *
132 * Valid buffer should be DWORD aligned
133 *
134 * return address for accessing buffer from the host;
135 * if buffer is not valid, return NULL.
136 */
137void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
138{
139 u32 off;
140 u32 ptr = le32_to_cpu(ptr_);
141
142 if (ptr % 4)
143 return NULL;
144
145 ptr = wmi_addr_remap(ptr);
146 if (ptr < WIL6210_FW_HOST_OFF)
147 return NULL;
148
149 off = HOSTADDR(ptr);
150 if (off > WIL6210_MEM_SIZE - 4)
151 return NULL;
152
153 return wil->csr + off;
154}
155
156/**
157 * Check address validity
158 */
159void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
160{
161 u32 off;
162
163 if (ptr % 4)
164 return NULL;
165
166 if (ptr < WIL6210_FW_HOST_OFF)
167 return NULL;
168
169 off = HOSTADDR(ptr);
170 if (off > WIL6210_MEM_SIZE - 4)
171 return NULL;
172
173 return wil->csr + off;
174}
175
176int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
177 struct wil6210_mbox_hdr *hdr)
178{
179 void __iomem *src = wmi_buffer(wil, ptr);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300180
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800181 if (!src)
182 return -EINVAL;
183
184 wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
185
186 return 0;
187}
188
189static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
190{
191 struct {
192 struct wil6210_mbox_hdr hdr;
Lior Davidb874dde2016-03-01 19:18:09 +0200193 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800194 } __packed cmd = {
195 .hdr = {
196 .type = WIL_MBOX_HDR_TYPE_WMI,
197 .flags = 0,
198 .len = cpu_to_le16(sizeof(cmd.wmi) + len),
199 },
200 .wmi = {
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300201 .mid = 0,
Lior Davidb874dde2016-03-01 19:18:09 +0200202 .command_id = cpu_to_le16(cmdid),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800203 },
204 };
205 struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
206 struct wil6210_mbox_ring_desc d_head;
207 u32 next_head;
208 void __iomem *dst;
209 void __iomem *head = wmi_addr(wil, r->head);
210 uint retry;
Maya Erez349214c2016-04-26 14:41:41 +0300211 int rc = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800212
213 if (sizeof(cmd) + len > r->entry_size) {
214 wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
215 (int)(sizeof(cmd) + len), r->entry_size);
216 return -ERANGE;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800217 }
218
219 might_sleep();
220
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200221 if (!test_bit(wil_status_fwready, wil->status)) {
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300222 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800223 return -EAGAIN;
224 }
225
226 if (!head) {
227 wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
228 return -EINVAL;
229 }
Maya Erez349214c2016-04-26 14:41:41 +0300230
231 wil_halp_vote(wil);
232
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800233 /* read Tx head till it is not busy */
234 for (retry = 5; retry > 0; retry--) {
235 wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
236 if (d_head.sync == 0)
237 break;
238 msleep(20);
239 }
240 if (d_head.sync != 0) {
241 wil_err(wil, "WMI head busy\n");
Maya Erez349214c2016-04-26 14:41:41 +0300242 rc = -EBUSY;
243 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800244 }
245 /* next head */
246 next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200247 wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800248 /* wait till FW finish with previous command */
249 for (retry = 5; retry > 0; retry--) {
Maya Erez452133a2015-11-24 09:30:15 +0200250 if (!test_bit(wil_status_fwready, wil->status)) {
251 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Maya Erez349214c2016-04-26 14:41:41 +0300252 rc = -EAGAIN;
253 goto out;
Maya Erez452133a2015-11-24 09:30:15 +0200254 }
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300255 r->tail = wil_r(wil, RGF_MBOX +
256 offsetof(struct wil6210_mbox_ctl, tx.tail));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800257 if (next_head != r->tail)
258 break;
259 msleep(20);
260 }
261 if (next_head == r->tail) {
262 wil_err(wil, "WMI ring full\n");
Maya Erez349214c2016-04-26 14:41:41 +0300263 rc = -EBUSY;
264 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800265 }
266 dst = wmi_buffer(wil, d_head.addr);
267 if (!dst) {
268 wil_err(wil, "invalid WMI buffer: 0x%08x\n",
269 le32_to_cpu(d_head.addr));
Maya Erez349214c2016-04-26 14:41:41 +0300270 rc = -EAGAIN;
271 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800272 }
273 cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
274 /* set command */
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200275 wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len);
276 wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800277 sizeof(cmd), true);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200278 wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800279 len, true);
280 wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
281 wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
282 /* mark entry as full */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300283 wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800284 /* advance next ptr */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300285 wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
286 r->head = next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800287
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300288 trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
Vladimir Kondratiev98658092013-05-12 14:43:35 +0300289
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800290 /* interrupt to FW */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300291 wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
292 SW_INT_MBOX);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800293
Maya Erez349214c2016-04-26 14:41:41 +0300294out:
295 wil_halp_unvote(wil);
296 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800297}
298
299int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
300{
301 int rc;
302
303 mutex_lock(&wil->wmi_mutex);
304 rc = __wmi_send(wil, cmdid, buf, len);
305 mutex_unlock(&wil->wmi_mutex);
306
307 return rc;
308}
309
310/*=== Event handlers ===*/
311static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len)
312{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800313 struct wireless_dev *wdev = wil->wdev;
314 struct wmi_ready_event *evt = d;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300315
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200316 wil->n_mids = evt->numof_additional_mids;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800317
Lior David13cd9f72016-08-22 12:42:22 +0300318 wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
319 wil->fw_version, le32_to_cpu(evt->sw_version),
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300320 evt->mac, wil->n_mids);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200321 /* ignore MAC address, we already have it from the boot loader */
Lior David13cd9f72016-08-22 12:42:22 +0300322 strlcpy(wdev->wiphy->fw_version, wil->fw_version,
323 sizeof(wdev->wiphy->fw_version));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800324
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300325 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200326 set_bit(wil_status_fwready, wil->status);
Dedy Lansky59502642014-09-10 16:34:46 +0300327 /* let the reset sequence continue */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800328 complete(&wil->wmi_ready);
329}
330
331static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
332{
333 struct wmi_rx_mgmt_packet_event *data = d;
334 struct wiphy *wiphy = wil_to_wiphy(wil);
335 struct ieee80211_mgmt *rx_mgmt_frame =
336 (struct ieee80211_mgmt *)data->payload;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300337 int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
338 int ch_no;
339 u32 freq;
340 struct ieee80211_channel *channel;
341 s32 signal;
342 __le16 fc;
343 u32 d_len;
344 u16 d_status;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800345
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300346 if (flen < 0) {
347 wil_err(wil, "MGMT Rx: short event, len %d\n", len);
348 return;
349 }
350
351 d_len = le32_to_cpu(data->info.len);
352 if (d_len != flen) {
353 wil_err(wil,
354 "MGMT Rx: length mismatch, d_len %d should be %d\n",
355 d_len, flen);
356 return;
357 }
358
359 ch_no = data->info.channel + 1;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200360 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300361 channel = ieee80211_get_channel(wiphy, freq);
362 signal = data->info.sqi;
363 d_status = le16_to_cpu(data->info.status);
364 fc = rx_mgmt_frame->frame_control;
365
366 wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d SNR %d SQI %d%%\n",
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200367 data->info.channel, data->info.mcs, data->info.snr,
368 data->info.sqi);
Vladimir Kondratievf27dbf72013-06-09 09:12:52 +0300369 wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
370 le16_to_cpu(fc));
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200371 wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800372 data->info.qid, data->info.mid, data->info.cid);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300373 wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
374 d_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800375
376 if (!channel) {
377 wil_err(wil, "Frame on unsupported channel\n");
378 return;
379 }
380
381 if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
382 struct cfg80211_bss *bss;
Vladimir Kondratiev8eea9442014-06-16 19:37:03 +0300383 u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
384 u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
385 u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
386 const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
387 size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
388 u.beacon.variable);
389 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
390 wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
391 wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
392 wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
393 ie_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800394
Dedy Lanskye6d68342016-03-01 19:18:12 +0200395 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
396
Vladimir Kondratieva0f78452013-03-13 14:12:44 +0200397 bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
398 d_len, signal, GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800399 if (bss) {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200400 wil_dbg_wmi(wil, "Added BSS %pM\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800401 rx_mgmt_frame->bssid);
Johannes Berg5b112d32013-02-01 01:49:58 +0100402 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800403 } else {
Johannes Berg5bc8c1f2014-08-12 21:01:28 +0200404 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800405 }
Vladimir Kondratiev102b1d92013-03-13 14:12:45 +0200406 } else {
Lior David4332cac2016-03-01 19:18:13 +0200407 mutex_lock(&wil->p2p_wdev_mutex);
408 cfg80211_rx_mgmt(wil->radio_wdev, freq, signal,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700409 (void *)rx_mgmt_frame, d_len, 0);
Lior David4332cac2016-03-01 19:18:13 +0200410 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800411 }
412}
413
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300414static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
415{
416 struct wmi_tx_mgmt_packet_event *data = d;
417 struct ieee80211_mgmt *mgmt_frame =
418 (struct ieee80211_mgmt *)data->payload;
419 int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
420
421 wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
422 flen, true);
423}
424
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800425static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
426 void *d, int len)
427{
Lior David5ffae432016-08-22 12:42:19 +0300428 mutex_lock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800429 if (wil->scan_request) {
430 struct wmi_scan_complete_event *data = d;
Maya Erez4cbb5852017-02-16 15:26:09 +0200431 int status = le32_to_cpu(data->status);
Avraham Stern1d762502016-07-05 17:10:13 +0300432 struct cfg80211_scan_info info = {
Maya Erez4cbb5852017-02-16 15:26:09 +0200433 .aborted = ((status != WMI_SCAN_SUCCESS) &&
434 (status != WMI_SCAN_ABORT_REJECTED)),
Avraham Stern1d762502016-07-05 17:10:13 +0300435 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800436
Maya Erez4cbb5852017-02-16 15:26:09 +0200437 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300438 wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
Avraham Stern1d762502016-07-05 17:10:13 +0300439 wil->scan_request, info.aborted);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300440 del_timer_sync(&wil->scan_timer);
Avraham Stern1d762502016-07-05 17:10:13 +0300441 cfg80211_scan_done(wil->scan_request, &info);
Lior David4332cac2016-03-01 19:18:13 +0200442 wil->radio_wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800443 wil->scan_request = NULL;
Maya Erez4cbb5852017-02-16 15:26:09 +0200444 wake_up_interruptible(&wil->wq);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800445 } else {
446 wil_err(wil, "SCAN_COMPLETE while not scanning\n");
447 }
Lior David5ffae432016-08-22 12:42:19 +0300448 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800449}
450
451static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len)
452{
453 struct net_device *ndev = wil_to_ndev(wil);
454 struct wireless_dev *wdev = wil->wdev;
455 struct wmi_connect_event *evt = d;
456 int ch; /* channel number */
457 struct station_info sinfo;
458 u8 *assoc_req_ie, *assoc_resp_ie;
459 size_t assoc_req_ielen, assoc_resp_ielen;
460 /* capinfo(u16) + listen_interval(u16) + IEs */
461 const size_t assoc_req_ie_offset = sizeof(u16) * 2;
462 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
463 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
Maya Erez0916d9f2016-01-17 12:39:10 +0200464 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465
466 if (len < sizeof(*evt)) {
467 wil_err(wil, "Connect event too short : %d bytes\n", len);
468 return;
469 }
470 if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
471 evt->assoc_resp_len) {
472 wil_err(wil,
473 "Connect event corrupted : %d != %d + %d + %d + %d\n",
474 len, (int)sizeof(*evt), evt->beacon_ie_len,
475 evt->assoc_req_len, evt->assoc_resp_len);
476 return;
477 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200478 if (evt->cid >= WIL6210_MAX_CID) {
479 wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
480 return;
481 }
482
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800483 ch = evt->channel + 1;
Maya Erez0916d9f2016-01-17 12:39:10 +0200484 wil_info(wil, "Connect %pM channel [%d] cid %d\n",
485 evt->bssid, ch, evt->cid);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200486 wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800487 evt->assoc_info, len - sizeof(*evt), true);
488
489 /* figure out IE's */
490 assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
491 assoc_req_ie_offset];
492 assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
493 if (evt->assoc_req_len <= assoc_req_ie_offset) {
494 assoc_req_ie = NULL;
495 assoc_req_ielen = 0;
496 }
497
498 assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
499 evt->assoc_req_len +
500 assoc_resp_ie_offset];
501 assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
502 if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
503 assoc_resp_ie = NULL;
504 assoc_resp_ielen = 0;
505 }
506
Maya Erez0916d9f2016-01-17 12:39:10 +0200507 mutex_lock(&wil->mutex);
508 if (test_bit(wil_status_resetting, wil->status) ||
509 !test_bit(wil_status_fwready, wil->status)) {
510 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
511 evt->cid);
512 mutex_unlock(&wil->mutex);
513 /* no need for cleanup, wil_reset will do that */
514 return;
515 }
516
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800517 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
518 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200519 if (!test_bit(wil_status_fwconnecting, wil->status)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800520 wil_err(wil, "Not in connecting state\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200521 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800522 return;
523 }
524 del_timer_sync(&wil->connect_timer);
Maya Erez3d287fb2016-03-01 19:18:05 +0200525 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
526 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
527 if (wil->sta[evt->cid].status != wil_sta_unused) {
528 wil_err(wil, "%s: AP: Invalid status %d for CID %d\n",
529 __func__, wil->sta[evt->cid].status, evt->cid);
530 mutex_unlock(&wil->mutex);
531 return;
532 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200533 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800534
Maya Erez0916d9f2016-01-17 12:39:10 +0200535 /* FIXME FW can transmit only ucast frames to peer */
536 /* FIXME real ring_id instead of hard coded 0 */
537 ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
538 wil->sta[evt->cid].status = wil_sta_conn_pending;
539
540 rc = wil_tx_init(wil, evt->cid);
541 if (rc) {
542 wil_err(wil, "%s: config tx vring failed for CID %d, rc (%d)\n",
543 __func__, evt->cid, rc);
544 wmi_disconnect_sta(wil, wil->sta[evt->cid].addr,
545 WLAN_REASON_UNSPECIFIED, false);
546 } else {
547 wil_info(wil, "%s: successful connection to CID %d\n",
548 __func__, evt->cid);
549 }
550
551 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
552 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
553 if (rc) {
Maya Erez0916d9f2016-01-17 12:39:10 +0200554 netif_carrier_off(ndev);
555 wil_err(wil,
556 "%s: cfg80211_connect_result with failure\n",
557 __func__);
558 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
559 NULL, 0,
560 WLAN_STATUS_UNSPECIFIED_FAILURE,
561 GFP_KERNEL);
562 goto out;
563 } else {
564 cfg80211_connect_result(ndev, evt->bssid,
565 assoc_req_ie, assoc_req_ielen,
566 assoc_resp_ie, assoc_resp_ielen,
567 WLAN_STATUS_SUCCESS,
568 GFP_KERNEL);
569 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800570 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
571 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
Maya Erez0916d9f2016-01-17 12:39:10 +0200572 if (rc)
573 goto out;
574
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800575 memset(&sinfo, 0, sizeof(sinfo));
576
577 sinfo.generation = wil->sinfo_gen++;
578
579 if (assoc_req_ie) {
580 sinfo.assoc_req_ies = assoc_req_ie;
581 sinfo.assoc_req_ies_len = assoc_req_ielen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800582 }
583
584 cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200585 } else {
586 wil_err(wil, "%s: unhandled iftype %d for CID %d\n",
587 __func__, wdev->iftype, evt->cid);
588 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800589 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200590
591 wil->sta[evt->cid].status = wil_sta_connected;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200592 set_bit(wil_status_fwconnected, wil->status);
Dedy Lansky970a98f2016-12-06 08:26:49 +0200593 wil_update_net_queues_bh(wil, NULL, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800594
Maya Erez0916d9f2016-01-17 12:39:10 +0200595out:
596 if (rc)
597 wil->sta[evt->cid].status = wil_sta_unused;
598 clear_bit(wil_status_fwconnecting, wil->status);
599 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800600}
601
602static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
603 void *d, int len)
604{
605 struct wmi_disconnect_event *evt = d;
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200606 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800607
Maya Erez0916d9f2016-01-17 12:39:10 +0200608 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
609 evt->bssid, reason_code, evt->disconnect_reason);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800610
611 wil->sinfo_gen++;
612
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200613 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200614 wil6210_disconnect(wil, evt->bssid, reason_code, true);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200615 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800616}
617
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800618/*
619 * Firmware reports EAPOL frame using WME event.
620 * Reconstruct Ethernet frame and deliver it via normal Rx
621 */
622static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
623 void *d, int len)
624{
625 struct net_device *ndev = wil_to_ndev(wil);
626 struct wmi_eapol_rx_event *evt = d;
627 u16 eapol_len = le16_to_cpu(evt->eapol_len);
628 int sz = eapol_len + ETH_HLEN;
629 struct sk_buff *skb;
630 struct ethhdr *eth;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200631 int cid;
632 struct wil_net_stats *stats = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800633
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200634 wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800635 evt->src_mac);
636
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200637 cid = wil_find_cid(wil, evt->src_mac);
638 if (cid >= 0)
639 stats = &wil->sta[cid].stats;
640
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800641 if (eapol_len > 196) { /* TODO: revisit size limit */
642 wil_err(wil, "EAPOL too large\n");
643 return;
644 }
645
646 skb = alloc_skb(sz, GFP_KERNEL);
647 if (!skb) {
648 wil_err(wil, "Failed to allocate skb\n");
649 return;
650 }
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200651
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800652 eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200653 ether_addr_copy(eth->h_dest, ndev->dev_addr);
654 ether_addr_copy(eth->h_source, evt->src_mac);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800655 eth->h_proto = cpu_to_be16(ETH_P_PAE);
656 memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len);
657 skb->protocol = eth_type_trans(skb, ndev);
658 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
659 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200660 ndev->stats.rx_bytes += sz;
661 if (stats) {
662 stats->rx_packets++;
663 stats->rx_bytes += sz;
664 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800665 } else {
666 ndev->stats.rx_dropped++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200667 if (stats)
668 stats->rx_dropped++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800669 }
670}
671
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300672static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200673{
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300674 struct wmi_vring_en_event *evt = d;
675 u8 vri = evt->vring_index;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200676
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300677 wil_dbg_wmi(wil, "Enable vring %d\n", vri);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200678
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300679 if (vri >= ARRAY_SIZE(wil->vring_tx)) {
680 wil_err(wil, "Enable for invalid vring %d\n", vri);
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200681 return;
682 }
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300683 wil->vring_tx_data[vri].dot1x_open = true;
684 if (vri == wil->bcast_vring) /* no BA for bcast */
685 return;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200686 if (agg_wsize >= 0)
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300687 wil_addba_tx_request(wil, vri, agg_wsize);
Vladimir Kondratiev3442a502013-03-13 14:12:39 +0200688}
689
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200690static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
691 int len)
692{
Lior Davidb874dde2016-03-01 19:18:09 +0200693 struct wmi_ba_status_event *evt = d;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200694 struct vring_tx_data *txdata;
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200695
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200696 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200697 evt->ringid,
698 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200699 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
700 evt->amsdu ? "+" : "-");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200701
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200702 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
703 wil_err(wil, "invalid ring id %d\n", evt->ringid);
704 return;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200705 }
706
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200707 if (evt->status != WMI_BA_AGREED) {
708 evt->ba_timeout = 0;
709 evt->agg_wsize = 0;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200710 evt->amsdu = 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200711 }
Dedy Lansky8c86f752014-09-10 16:34:40 +0300712
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200713 txdata = &wil->vring_tx_data[evt->ringid];
714
715 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
716 txdata->agg_wsize = evt->agg_wsize;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200717 txdata->agg_amsdu = evt->amsdu;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200718 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200719}
720
721static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d,
722 int len)
723{
724 struct wmi_rcp_addba_req_event *evt = d;
725
726 wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token,
727 evt->ba_param_set, evt->ba_timeout,
728 evt->ba_seq_ctrl);
729}
730
731static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200732__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200733{
734 struct wmi_delba_event *evt = d;
735 u8 cid, tid;
736 u16 reason = __le16_to_cpu(evt->reason);
737 struct wil_sta_info *sta;
738 struct wil_tid_ampdu_rx *r;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200739
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200740 might_sleep();
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200741 parse_cidxtid(evt->cidxtid, &cid, &tid);
742 wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n",
743 cid, tid,
744 evt->from_initiator ? "originator" : "recipient",
745 reason);
746 if (!evt->from_initiator) {
747 int i;
748 /* find Tx vring it belongs to */
749 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
750 if ((wil->vring2cid_tid[i][0] == cid) &&
751 (wil->vring2cid_tid[i][1] == tid)) {
752 struct vring_tx_data *txdata =
753 &wil->vring_tx_data[i];
754
755 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
756 txdata->agg_timeout = 0;
757 txdata->agg_wsize = 0;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200758 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200759
760 break; /* max. 1 matching ring */
761 }
762 }
763 if (i >= ARRAY_SIZE(wil->vring2cid_tid))
764 wil_err(wil, "DELBA: unable to find Tx vring\n");
765 return;
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200766 }
767
768 sta = &wil->sta[cid];
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200769
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200770 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300771
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200772 r = sta->tid_rx[tid];
773 sta->tid_rx[tid] = NULL;
774 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300775
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200776 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200777}
778
Lior David8f1b5e02017-02-28 14:58:27 +0200779static void wmi_evt_aoa_meas(struct wil6210_priv *wil, int id,
780 void *d, int len)
781{
782 struct wmi_aoa_meas_event *evt = d;
783
784 wil_aoa_evt_meas(wil, evt, len);
785}
786
787static void wmi_evt_ftm_session_ended(struct wil6210_priv *wil, int id,
788 void *d, int len)
789{
790 struct wmi_tof_session_end_event *evt = d;
791
792 wil_ftm_evt_session_ended(wil, evt);
793}
794
795static void wmi_evt_per_dest_res(struct wil6210_priv *wil, int id,
796 void *d, int len)
797{
798 struct wmi_tof_ftm_per_dest_res_event *evt = d;
799
800 wil_ftm_evt_per_dest_res(wil, evt);
801}
802
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200803/**
804 * Some events are ignored for purpose; and need not be interpreted as
805 * "unhandled events"
806 */
807static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len)
808{
809 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
810}
811
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800812static const struct {
813 int eventid;
814 void (*handler)(struct wil6210_priv *wil, int eventid,
815 void *data, int data_len);
816} wmi_evt_handlers[] = {
817 {WMI_READY_EVENTID, wmi_evt_ready},
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200818 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800819 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300820 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800821 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
822 {WMI_CONNECT_EVENTID, wmi_evt_connect},
823 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800824 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200825 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200826 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
827 {WMI_DELBA_EVENTID, wmi_evt_delba},
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300828 {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200829 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
Lior David8f1b5e02017-02-28 14:58:27 +0200830 {WMI_AOA_MEAS_EVENTID, wmi_evt_aoa_meas},
831 {WMI_TOF_SESSION_END_EVENTID, wmi_evt_ftm_session_ended},
832 {WMI_TOF_GET_CAPABILITIES_EVENTID, wmi_evt_ignore},
833 {WMI_TOF_SET_LCR_EVENTID, wmi_evt_ignore},
834 {WMI_TOF_SET_LCI_EVENTID, wmi_evt_ignore},
835 {WMI_TOF_FTM_PER_DEST_RES_EVENTID, wmi_evt_per_dest_res},
836 {WMI_TOF_CHANNEL_INFO_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800837};
838
839/*
840 * Run in IRQ context
841 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
842 * that will be eventually handled by the @wmi_event_worker in the thread
843 * context of thread "wil6210_wmi"
844 */
845void wmi_recv_cmd(struct wil6210_priv *wil)
846{
847 struct wil6210_mbox_ring_desc d_tail;
848 struct wil6210_mbox_hdr hdr;
849 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
850 struct pending_wmi_event *evt;
851 u8 *cmd;
852 void __iomem *src;
853 ulong flags;
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300854 unsigned n;
Maya Erez0916d9f2016-01-17 12:39:10 +0200855 unsigned int num_immed_reply = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800856
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200857 if (!test_bit(wil_status_mbox_ready, wil->status)) {
Dedy Lansky4cf99c92014-09-10 16:34:41 +0300858 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
Vladimir Kondratiev55f7acd2013-03-13 14:12:49 +0200859 return;
860 }
861
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300862 for (n = 0;; n++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800863 u16 len;
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300864 bool q;
Maya Erez0916d9f2016-01-17 12:39:10 +0200865 bool immed_reply = false;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800866
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300867 r->head = wil_r(wil, RGF_MBOX +
868 offsetof(struct wil6210_mbox_ctl, rx.head));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300869 if (r->tail == r->head)
870 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800871
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300872 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
873 r->head, r->tail);
874 /* read cmd descriptor from tail */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800875 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
876 sizeof(struct wil6210_mbox_ring_desc));
877 if (d_tail.sync == 0) {
878 wil_err(wil, "Mbox evt not owned by FW?\n");
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300879 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800880 }
881
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300882 /* read cmd header from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800883 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
884 wil_err(wil, "Mbox evt at 0x%08x?\n",
885 le32_to_cpu(d_tail.addr));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300886 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800887 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800888 len = le16_to_cpu(hdr.len);
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300889 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
890 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
891 hdr.flags);
892
893 /* read cmd buffer from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800894 src = wmi_buffer(wil, d_tail.addr) +
895 sizeof(struct wil6210_mbox_hdr);
896 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
897 event.wmi) + len, 4),
898 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000899 if (!evt)
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300900 break;
Joe Perches14f8dc42013-02-07 11:46:27 +0000901
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800902 evt->event.hdr = hdr;
903 cmd = (void *)&evt->event.wmi;
904 wil_memcpy_fromio_32(cmd, src, len);
905 /* mark entry as empty */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300906 wil_w(wil, r->tail +
907 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800908 /* indicate */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800909 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +0200910 (len >= sizeof(struct wmi_cmd_hdr))) {
911 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
912 u16 id = le16_to_cpu(wmi->command_id);
913 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
Maya Erezfe5c2712016-01-28 19:24:04 +0200914 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
Maya Erez0916d9f2016-01-17 12:39:10 +0200915 if (wil->reply_id && wil->reply_id == id) {
916 if (wil->reply_buf) {
917 memcpy(wil->reply_buf, wmi,
918 min(len, wil->reply_size));
919 immed_reply = true;
920 }
921 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200922 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300923
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300924 wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
925 id, wmi->mid, tstamp);
926 trace_wil6210_wmi_event(wmi, &wmi[1],
927 len - sizeof(*wmi));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200929 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800930 &evt->event.hdr, sizeof(hdr) + len, true);
931
932 /* advance tail */
933 r->tail = r->base + ((r->tail - r->base +
934 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300935 wil_w(wil, RGF_MBOX +
936 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800937
Maya Erez0916d9f2016-01-17 12:39:10 +0200938 if (immed_reply) {
939 wil_dbg_wmi(wil, "%s: Complete WMI 0x%04x\n",
940 __func__, wil->reply_id);
941 kfree(evt);
942 num_immed_reply++;
943 complete(&wil->wmi_call);
944 } else {
945 /* add to the pending list */
946 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
947 list_add_tail(&evt->list, &wil->pending_wmi_ev);
948 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
949 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
950 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
951 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800952 }
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300953 /* normally, 1 event per IRQ should be processed */
Maya Erez0916d9f2016-01-17 12:39:10 +0200954 wil_dbg_wmi(wil, "%s -> %d events queued, %d completed\n", __func__,
955 n - num_immed_reply, num_immed_reply);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800956}
957
958int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
959 u16 reply_id, void *reply, u8 reply_size, int to_msec)
960{
961 int rc;
Nicholas Mc Guiref4bbb822015-08-13 15:38:31 +0300962 unsigned long remain;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800963
964 mutex_lock(&wil->wmi_mutex);
965
Maya Erezfe5c2712016-01-28 19:24:04 +0200966 spin_lock(&wil->wmi_ev_lock);
967 wil->reply_id = reply_id;
968 wil->reply_buf = reply;
969 wil->reply_size = reply_size;
970 spin_unlock(&wil->wmi_ev_lock);
971
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800972 rc = __wmi_send(wil, cmdid, buf, len);
973 if (rc)
974 goto out;
975
Dedy Lansky59502642014-09-10 16:34:46 +0300976 remain = wait_for_completion_timeout(&wil->wmi_call,
977 msecs_to_jiffies(to_msec));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800978 if (0 == remain) {
979 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
980 cmdid, reply_id, to_msec);
981 rc = -ETIME;
982 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200983 wil_dbg_wmi(wil,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800984 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
985 cmdid, reply_id,
986 to_msec - jiffies_to_msecs(remain));
987 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200988
989out:
990 spin_lock(&wil->wmi_ev_lock);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800991 wil->reply_id = 0;
992 wil->reply_buf = NULL;
993 wil->reply_size = 0;
Maya Erezfe5c2712016-01-28 19:24:04 +0200994 spin_unlock(&wil->wmi_ev_lock);
995
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800996 mutex_unlock(&wil->wmi_mutex);
997
998 return rc;
999}
1000
1001int wmi_echo(struct wil6210_priv *wil)
1002{
1003 struct wmi_echo_cmd cmd = {
1004 .value = cpu_to_le32(0x12345678),
1005 };
1006
1007 return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratieva54a40d2015-04-30 16:25:05 +03001008 WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001009}
1010
1011int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
1012{
1013 struct wmi_set_mac_address_cmd cmd;
1014
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001015 ether_addr_copy(cmd.mac, addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001016
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001017 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001018
1019 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
1020}
1021
Maya Erez10d599a2016-05-09 21:57:11 +03001022int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
1023{
1024 int rc = 0;
1025 struct wmi_led_cfg_cmd cmd = {
1026 .led_mode = enable,
1027 .id = led_id,
1028 .slow_blink_cfg.blink_on =
1029 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
1030 .slow_blink_cfg.blink_off =
1031 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
1032 .medium_blink_cfg.blink_on =
1033 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
1034 .medium_blink_cfg.blink_off =
1035 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
1036 .fast_blink_cfg.blink_on =
1037 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
1038 .fast_blink_cfg.blink_off =
1039 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
1040 .led_polarity = led_polarity,
1041 };
1042 struct {
1043 struct wmi_cmd_hdr wmi;
1044 struct wmi_led_cfg_done_event evt;
1045 } __packed reply;
1046
1047 if (led_id == WIL_LED_INVALID_ID)
1048 goto out;
1049
1050 if (led_id > WIL_LED_MAX_ID) {
1051 wil_err(wil, "Invalid led id %d\n", led_id);
1052 rc = -EINVAL;
1053 goto out;
1054 }
1055
1056 wil_dbg_wmi(wil,
1057 "%s led %d\n",
1058 enable ? "enabling" : "disabling", led_id);
1059
1060 rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd),
1061 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
1062 100);
1063 if (rc)
1064 goto out;
1065
1066 if (reply.evt.status) {
1067 wil_err(wil, "led %d cfg failed with status %d\n",
1068 led_id, le32_to_cpu(reply.evt.status));
1069 rc = -EINVAL;
1070 }
1071
1072out:
1073 return rc;
1074}
1075
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001076int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype,
Lior Davidb4944f22016-03-01 19:18:17 +02001077 u8 chan, u8 hidden_ssid, u8 is_go)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001078{
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001079 int rc;
1080
1081 struct wmi_pcp_start_cmd cmd = {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001082 .bcon_interval = cpu_to_le16(bi),
1083 .network_type = wmi_nettype,
1084 .disable_sec_offload = 1,
Vladimir Kondratievadc2d122013-05-28 15:17:52 +03001085 .channel = chan - 1,
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001086 .pcp_max_assoc_sta = max_assoc_sta,
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001087 .hidden_ssid = hidden_ssid,
Lior Davidb4944f22016-03-01 19:18:17 +02001088 .is_go = is_go,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001089 };
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001090 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001091 struct wmi_cmd_hdr wmi;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001092 struct wmi_pcp_started_event evt;
1093 } __packed reply;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001094
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001095 if (!wil->privacy)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001096 cmd.disable_sec = 1;
1097
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001098 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
1099 (cmd.pcp_max_assoc_sta <= 0)) {
1100 wil_info(wil,
1101 "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
1102 max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
1103 cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
1104 }
1105
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001106 /*
1107 * Processing time may be huge, in case of secure AP it takes about
1108 * 3500ms for FW to start AP
1109 */
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001110 rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001111 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001112 if (rc)
1113 return rc;
1114
1115 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
1116 rc = -EINVAL;
1117
Maya Erez10d599a2016-05-09 21:57:11 +03001118 if (wmi_nettype != WMI_NETTYPE_P2P)
1119 /* Don't fail due to error in the led configuration */
1120 wmi_led_cfg(wil, true);
1121
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001122 return rc;
1123}
1124
1125int wmi_pcp_stop(struct wil6210_priv *wil)
1126{
Maya Erez10d599a2016-05-09 21:57:11 +03001127 int rc;
1128
1129 rc = wmi_led_cfg(wil, false);
1130 if (rc)
1131 return rc;
1132
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001133 return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
1134 WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001135}
1136
1137int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
1138{
1139 struct wmi_set_ssid_cmd cmd = {
1140 .ssid_len = cpu_to_le32(ssid_len),
1141 };
1142
1143 if (ssid_len > sizeof(cmd.ssid))
1144 return -EINVAL;
1145
1146 memcpy(cmd.ssid, ssid, ssid_len);
1147
1148 return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
1149}
1150
1151int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
1152{
1153 int rc;
1154 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001155 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001156 struct wmi_set_ssid_cmd cmd;
1157 } __packed reply;
1158 int len; /* reply.cmd.ssid_len in CPU order */
1159
1160 rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
1161 &reply, sizeof(reply), 20);
1162 if (rc)
1163 return rc;
1164
1165 len = le32_to_cpu(reply.cmd.ssid_len);
1166 if (len > sizeof(reply.cmd.ssid))
1167 return -EINVAL;
1168
1169 *ssid_len = len;
1170 memcpy(ssid, reply.cmd.ssid, len);
1171
1172 return 0;
1173}
1174
1175int wmi_set_channel(struct wil6210_priv *wil, int channel)
1176{
1177 struct wmi_set_pcp_channel_cmd cmd = {
1178 .channel = channel - 1,
1179 };
1180
1181 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
1182}
1183
1184int wmi_get_channel(struct wil6210_priv *wil, int *channel)
1185{
1186 int rc;
1187 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001188 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001189 struct wmi_set_pcp_channel_cmd cmd;
1190 } __packed reply;
1191
1192 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
1193 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
1194 if (rc)
1195 return rc;
1196
1197 if (reply.cmd.channel > 3)
1198 return -EINVAL;
1199
1200 *channel = reply.cmd.channel + 1;
1201
1202 return 0;
1203}
1204
Dedy Lanskye6d68342016-03-01 19:18:12 +02001205int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi)
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001206{
Dedy Lanskye6d68342016-03-01 19:18:12 +02001207 int rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001208 struct wmi_p2p_cfg_cmd cmd = {
Dedy Lanskye6d68342016-03-01 19:18:12 +02001209 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
1210 .bcon_interval = cpu_to_le16(bi),
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001211 .channel = channel - 1,
1212 };
Dedy Lanskye6d68342016-03-01 19:18:12 +02001213 struct {
1214 struct wmi_cmd_hdr wmi;
1215 struct wmi_p2p_cfg_done_event evt;
1216 } __packed reply;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001217
Dedy Lanskye6d68342016-03-01 19:18:12 +02001218 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
1219
1220 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd),
1221 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
1222 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1223 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
1224 rc = -EINVAL;
1225 }
1226
1227 return rc;
1228}
1229
1230int wmi_start_listen(struct wil6210_priv *wil)
1231{
1232 int rc;
1233 struct {
1234 struct wmi_cmd_hdr wmi;
1235 struct wmi_listen_started_event evt;
1236 } __packed reply;
1237
1238 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
1239
1240 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1241 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
1242 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1243 wil_err(wil, "device failed to start listen. status %d\n",
1244 reply.evt.status);
1245 rc = -EINVAL;
1246 }
1247
1248 return rc;
1249}
1250
1251int wmi_start_search(struct wil6210_priv *wil)
1252{
1253 int rc;
1254 struct {
1255 struct wmi_cmd_hdr wmi;
1256 struct wmi_search_started_event evt;
1257 } __packed reply;
1258
1259 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
1260
1261 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0,
1262 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
1263 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1264 wil_err(wil, "device failed to start search. status %d\n",
1265 reply.evt.status);
1266 rc = -EINVAL;
1267 }
1268
1269 return rc;
1270}
1271
1272int wmi_stop_discovery(struct wil6210_priv *wil)
1273{
1274 int rc;
1275
1276 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
1277
1278 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1279 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
1280
1281 if (rc)
1282 wil_err(wil, "Failed to stop discovery\n");
1283
1284 return rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001285}
1286
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001287int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001288 const void *mac_addr, int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001289{
1290 struct wmi_delete_cipher_key_cmd cmd = {
1291 .key_index = key_index,
1292 };
1293
1294 if (mac_addr)
1295 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1296
1297 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1298}
1299
1300int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001301 const void *mac_addr, int key_len, const void *key,
1302 int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001303{
1304 struct wmi_add_cipher_key_cmd cmd = {
1305 .key_index = key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001306 .key_usage = key_usage,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001307 .key_len = key_len,
1308 };
1309
1310 if (!key || (key_len > sizeof(cmd.key)))
1311 return -EINVAL;
1312
1313 memcpy(cmd.key, key, key_len);
1314 if (mac_addr)
1315 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1316
1317 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1318}
1319
1320int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
1321{
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001322 static const char *const names[] = {
1323 [WMI_FRAME_BEACON] = "BEACON",
1324 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
1325 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
1326 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
1327 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
1328 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001329 int rc;
1330 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
1331 struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001332
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001333 if (!cmd) {
1334 rc = -ENOMEM;
1335 goto out;
1336 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +03001337 if (!ie)
1338 ie_len = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001339
1340 cmd->mgmt_frm_type = type;
1341 /* BUG: FW API define ieLen as u8. Will fix FW */
1342 cmd->ie_len = cpu_to_le16(ie_len);
1343 memcpy(cmd->ie_info, ie, ie_len);
Vladimir Kondratiev03866e72013-03-13 14:12:42 +02001344 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001345 kfree(cmd);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001346out:
1347 if (rc) {
1348 const char *name = type < ARRAY_SIZE(names) ?
1349 names[type] : "??";
1350 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
1351 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001352
1353 return rc;
1354}
1355
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001356/**
1357 * wmi_rxon - turn radio on/off
1358 * @on: turn on if true, off otherwise
1359 *
1360 * Only switch radio. Channel should be set separately.
1361 * No timeout for rxon - radio turned on forever unless some other call
1362 * turns it off
1363 */
1364int wmi_rxon(struct wil6210_priv *wil, bool on)
1365{
1366 int rc;
1367 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001368 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001369 struct wmi_listen_started_event evt;
1370 } __packed reply;
1371
1372 wil_info(wil, "%s(%s)\n", __func__, on ? "on" : "off");
1373
1374 if (on) {
1375 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1376 WMI_LISTEN_STARTED_EVENTID,
1377 &reply, sizeof(reply), 100);
1378 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
1379 rc = -EINVAL;
1380 } else {
1381 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1382 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
1383 }
1384
1385 return rc;
1386}
1387
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001388int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1389{
1390 struct wireless_dev *wdev = wil->wdev;
1391 struct net_device *ndev = wil_to_ndev(wil);
1392 struct wmi_cfg_rx_chain_cmd cmd = {
1393 .action = WMI_RX_CHAIN_ADD,
1394 .rx_sw_ring = {
Vladimir Kondratievc44690a2014-12-23 09:47:11 +02001395 .max_mpdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001396 .ring_mem_base = cpu_to_le64(vring->pa),
1397 .ring_size = cpu_to_le16(vring->size),
1398 },
1399 .mid = 0, /* TODO - what is it? */
1400 .decap_trans_type = WMI_DECAP_TYPE_802_3,
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001401 .reorder_type = WMI_RX_SW_REORDER,
Vladimir Kondratievab954622014-12-23 09:47:20 +02001402 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001403 };
1404 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001405 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001406 struct wmi_cfg_rx_chain_done_event evt;
1407 } __packed evt;
1408 int rc;
1409
1410 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
1411 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
1412
1413 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
1414 if (ch)
1415 cmd.sniffer_cfg.channel = ch->hw_value - 1;
1416 cmd.sniffer_cfg.phy_info_mode =
1417 cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
1418 cmd.sniffer_cfg.phy_support =
1419 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
Vladimir Kondratiev47653322015-10-04 10:23:24 +03001420 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +03001421 } else {
1422 /* Initialize offload (in non-sniffer mode).
1423 * Linux IP stack always calculates IP checksum
1424 * HW always calculate TCP/UDP checksum
1425 */
1426 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001427 }
Vladimir Kondratievc406ea72015-03-15 16:00:19 +02001428
1429 if (rx_align_2)
1430 cmd.l2_802_3_offload_ctrl |=
1431 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
1432
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001433 /* typical time for secure PCP is 840ms */
1434 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
1435 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
1436 if (rc)
1437 return rc;
1438
1439 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
1440
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001441 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001442 le32_to_cpu(evt.evt.status), vring->hwtail);
1443
1444 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
1445 rc = -EINVAL;
1446
1447 return rc;
1448}
1449
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001450int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001451{
1452 int rc;
1453 struct wmi_temp_sense_cmd cmd = {
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001454 .measure_baseband_en = cpu_to_le32(!!t_bb),
1455 .measure_rf_en = cpu_to_le32(!!t_rf),
1456 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001457 };
1458 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001459 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001460 struct wmi_temp_sense_done_event evt;
1461 } __packed reply;
1462
1463 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
1464 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
1465 if (rc)
1466 return rc;
1467
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001468 if (t_bb)
1469 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
1470 if (t_rf)
1471 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001472
1473 return 0;
1474}
1475
Maya Erez0916d9f2016-01-17 12:39:10 +02001476int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason,
1477 bool full_disconnect)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001478{
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001479 int rc;
1480 u16 reason_code;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001481 struct wmi_disconnect_sta_cmd cmd = {
1482 .disconnect_reason = cpu_to_le16(reason),
1483 };
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001484 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001485 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001486 struct wmi_disconnect_event evt;
1487 } __packed reply;
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001488
1489 ether_addr_copy(cmd.dst_mac, mac);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001490
1491 wil_dbg_wmi(wil, "%s(%pM, reason %d)\n", __func__, mac, reason);
1492
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001493 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &cmd, sizeof(cmd),
1494 WMI_DISCONNECT_EVENTID, &reply, sizeof(reply), 1000);
1495 /* failure to disconnect in reasonable time treated as FW error */
1496 if (rc) {
1497 wil_fw_error_recovery(wil);
1498 return rc;
1499 }
1500
Maya Erez0916d9f2016-01-17 12:39:10 +02001501 if (full_disconnect) {
1502 /* call event handler manually after processing wmi_call,
1503 * to avoid deadlock - disconnect event handler acquires
1504 * wil->mutex while it is already held here
1505 */
1506 reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001507
Maya Erez0916d9f2016-01-17 12:39:10 +02001508 wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1509 reply.evt.bssid, reason_code,
1510 reply.evt.disconnect_reason);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001511
Maya Erez0916d9f2016-01-17 12:39:10 +02001512 wil->sinfo_gen++;
1513 wil6210_disconnect(wil, reply.evt.bssid, reason_code, true);
1514 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001515 return 0;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001516}
1517
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001518int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout)
1519{
1520 struct wmi_vring_ba_en_cmd cmd = {
1521 .ringid = ringid,
1522 .agg_max_wsize = size,
1523 .ba_timeout = cpu_to_le16(timeout),
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +02001524 .amsdu = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001525 };
1526
1527 wil_dbg_wmi(wil, "%s(ring %d size %d timeout %d)\n", __func__,
1528 ringid, size, timeout);
1529
1530 return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd));
1531}
1532
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001533int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason)
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001534{
1535 struct wmi_vring_ba_dis_cmd cmd = {
1536 .ringid = ringid,
1537 .reason = cpu_to_le16(reason),
1538 };
1539
1540 wil_dbg_wmi(wil, "%s(ring %d reason %d)\n", __func__,
1541 ringid, reason);
1542
1543 return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd));
1544}
1545
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001546int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason)
1547{
1548 struct wmi_rcp_delba_cmd cmd = {
1549 .cidxtid = cidxtid,
1550 .reason = cpu_to_le16(reason),
1551 };
1552
1553 wil_dbg_wmi(wil, "%s(CID %d TID %d reason %d)\n", __func__,
1554 cidxtid & 0xf, (cidxtid >> 4) & 0xf, reason);
1555
1556 return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd));
1557}
1558
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001559int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
1560 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
1561{
1562 int rc;
1563 struct wmi_rcp_addba_resp_cmd cmd = {
1564 .cidxtid = mk_cidxtid(cid, tid),
1565 .dialog_token = token,
1566 .status_code = cpu_to_le16(status),
1567 /* bit 0: A-MSDU supported
1568 * bit 1: policy (should be 0 for us)
1569 * bits 2..5: TID
1570 * bits 6..15: buffer size
1571 */
1572 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
1573 (agg_wsize << 6)),
1574 .ba_timeout = cpu_to_le16(timeout),
1575 };
1576 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001577 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001578 struct wmi_rcp_addba_resp_sent_event evt;
1579 } __packed reply;
1580
1581 wil_dbg_wmi(wil,
1582 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
1583 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-");
1584
1585 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001586 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
1587 100);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001588 if (rc)
1589 return rc;
1590
1591 if (reply.evt.status) {
1592 wil_err(wil, "ADDBA response failed with status %d\n",
1593 le16_to_cpu(reply.evt.status));
1594 rc = -EINVAL;
1595 }
1596
1597 return rc;
1598}
1599
Maya Ereze77727f2016-12-06 12:21:17 +02001600int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
1601 enum wmi_ps_profile_type ps_profile)
1602{
1603 int rc;
1604 struct wmi_ps_dev_profile_cfg_cmd cmd = {
1605 .ps_profile = ps_profile,
1606 };
1607 struct {
1608 struct wmi_cmd_hdr wmi;
1609 struct wmi_ps_dev_profile_cfg_event evt;
1610 } __packed reply;
1611 u32 status;
1612
1613 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
1614
1615 reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR);
1616
1617 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd),
1618 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
1619 100);
1620 if (rc)
1621 return rc;
1622
1623 status = le32_to_cpu(reply.evt.status);
1624
1625 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
1626 wil_err(wil, "ps dev profile cfg failed with status %d\n",
1627 status);
1628 rc = -EINVAL;
1629 }
1630
1631 return rc;
1632}
1633
Maya Erez4cbb5852017-02-16 15:26:09 +02001634int wmi_abort_scan(struct wil6210_priv *wil)
1635{
1636 int rc;
1637
1638 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
1639
1640 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0);
1641 if (rc)
1642 wil_err(wil, "Failed to abort scan (%d)\n", rc);
1643
1644 return rc;
1645}
1646
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001647void wmi_event_flush(struct wil6210_priv *wil)
1648{
1649 struct pending_wmi_event *evt, *t;
1650
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001651 wil_dbg_wmi(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001652
1653 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
1654 list_del(&evt->list);
1655 kfree(evt);
1656 }
1657}
1658
1659static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
1660 void *d, int len)
1661{
1662 uint i;
1663
1664 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
1665 if (wmi_evt_handlers[i].eventid == id) {
1666 wmi_evt_handlers[i].handler(wil, id, d, len);
1667 return true;
1668 }
1669 }
1670
1671 return false;
1672}
1673
1674static void wmi_event_handle(struct wil6210_priv *wil,
1675 struct wil6210_mbox_hdr *hdr)
1676{
1677 u16 len = le16_to_cpu(hdr->len);
1678
1679 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +02001680 (len >= sizeof(struct wmi_cmd_hdr))) {
1681 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001682 void *evt_data = (void *)(&wmi[1]);
Lior Davidb874dde2016-03-01 19:18:09 +02001683 u16 id = le16_to_cpu(wmi->command_id);
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03001684
1685 wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n",
1686 id, wil->reply_id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001687 /* check if someone waits for this event */
1688 if (wil->reply_id && wil->reply_id == id) {
Maya Erez0916d9f2016-01-17 12:39:10 +02001689 WARN_ON(wil->reply_buf);
1690 wmi_evt_call_handler(wil, id, evt_data,
1691 len - sizeof(*wmi));
1692 wil_dbg_wmi(wil, "%s: Complete WMI 0x%04x\n",
1693 __func__, id);
Dedy Lansky59502642014-09-10 16:34:46 +03001694 complete(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001695 return;
1696 }
1697 /* unsolicited event */
1698 /* search for handler */
1699 if (!wmi_evt_call_handler(wil, id, evt_data,
1700 len - sizeof(*wmi))) {
Dedy Lanskya3ce5ccd2015-07-30 13:51:58 +03001701 wil_info(wil, "Unhandled event 0x%04x\n", id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001702 }
1703 } else {
1704 wil_err(wil, "Unknown event type\n");
1705 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
1706 hdr, sizeof(*hdr) + len, true);
1707 }
1708}
1709
1710/*
1711 * Retrieve next WMI event from the pending list
1712 */
1713static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
1714{
1715 ulong flags;
1716 struct list_head *ret = NULL;
1717
1718 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1719
1720 if (!list_empty(&wil->pending_wmi_ev)) {
1721 ret = wil->pending_wmi_ev.next;
1722 list_del(ret);
1723 }
1724
1725 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
1726
1727 return ret;
1728}
1729
1730/*
1731 * Handler for the WMI events
1732 */
1733void wmi_event_worker(struct work_struct *work)
1734{
1735 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
1736 wmi_event_worker);
1737 struct pending_wmi_event *evt;
1738 struct list_head *lh;
1739
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03001740 wil_dbg_wmi(wil, "Start %s\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001741 while ((lh = next_wmi_ev(wil)) != NULL) {
1742 evt = list_entry(lh, struct pending_wmi_event, list);
1743 wmi_event_handle(wil, &evt->event.hdr);
1744 kfree(evt);
1745 }
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03001746 wil_dbg_wmi(wil, "Finished %s\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001747}