blob: 205c3ab7c7149f4385a9b09ba78e5af988bd2f20 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02002 * Copyright (c) 2012-2017 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;
Maya Erezc2256ec2017-02-08 13:18:42 +020028module_param(max_assoc_sta, uint, 0644);
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +030029MODULE_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; */
Maya Erezc2256ec2017-02-08 13:18:42 +020032module_param(agg_wsize, int, 0644);
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +020033MODULE_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;
Maya Erezc2256ec2017-02-08 13:18:42 +020037module_param(led_id, byte, 0444);
Maya Erez10d599a2016-05-09 21:57:11 +030038MODULE_PARM_DESC(led_id,
39 " 60G device led enablement. Set the led ID (0-2) to enable");
40
Maya Ereze3309bf2017-05-15 16:57:46 +030041#define WIL_WAIT_FOR_SUSPEND_RESUME_COMP 200
42
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080043/**
44 * WMI event receiving - theory of operations
45 *
46 * When firmware about to report WMI event, it fills memory area
47 * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
48 * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
49 *
50 * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
51 * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
52 * and handles events within the @wmi_event_worker. Every event get detached
53 * from list, processed and deleted.
54 *
55 * Purpose for this mechanism is to release IRQ thread; otherwise,
56 * if WMI event handling involves another WMI command flow, this 2-nd flow
57 * won't be completed because of blocked IRQ thread.
58 */
59
60/**
61 * Addressing - theory of operations
62 *
63 * There are several buses present on the WIL6210 card.
64 * Same memory areas are visible at different address on
65 * the different busses. There are 3 main bus masters:
66 * - MAC CPU (ucode)
67 * - User CPU (firmware)
68 * - AHB (host)
69 *
70 * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
71 * AHB addresses starting from 0x880000
72 *
73 * Internally, firmware uses addresses that allows faster access but
74 * are invisible from the host. To read from these addresses, alternative
75 * AHB address must be used.
76 *
77 * Memory mapping
78 * Linker address PCI/Host address
79 * 0x880000 .. 0xa80000 2Mb BAR0
80 * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM
81 * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH
82 */
83
84/**
85 * @fw_mapping provides memory remapping table
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030086 *
87 * array size should be in sync with the declaration in the wil6210.h
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080088 */
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030089const struct fw_map fw_mapping[] = {
Lior Davida6a0de12016-12-06 17:12:36 +020090 /* FW code RAM 256k */
91 {0x000000, 0x040000, 0x8c0000, "fw_code", true},
92 /* FW data RAM 32k */
93 {0x800000, 0x808000, 0x900000, "fw_data", true},
94 /* periph data 128k */
95 {0x840000, 0x860000, 0x908000, "fw_peri", true},
96 /* various RGF 40k */
97 {0x880000, 0x88a000, 0x880000, "rgf", true},
98 /* AGC table 4k */
99 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true},
100 /* Pcie_ext_rgf 4k */
101 {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true},
102 /* mac_ext_rgf 512b */
103 {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext", true},
104 /* upper area 548k */
105 {0x8c0000, 0x949000, 0x8c0000, "upper", true},
106 /* UCODE areas - accessible by debugfs blobs but not by
107 * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800108 */
Lior Davida6a0de12016-12-06 17:12:36 +0200109 /* ucode code RAM 128k */
110 {0x000000, 0x020000, 0x920000, "uc_code", false},
111 /* ucode data RAM 16k */
112 {0x800000, 0x804000, 0x940000, "uc_data", false},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800113};
114
Maya Erez10d599a2016-05-09 21:57:11 +0300115struct blink_on_off_time led_blink_time[] = {
116 {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS},
117 {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS},
118 {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS},
119};
120
121u8 led_polarity = LED_POLARITY_LOW_ACTIVE;
122
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800123/**
Lior Davida6a0de12016-12-06 17:12:36 +0200124 * return AHB address for given firmware internal (linker) address
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800125 * @x - internal address
126 * If address have no valid AHB mapping, return 0
127 */
128static u32 wmi_addr_remap(u32 x)
129{
130 uint i;
131
132 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
Lior Davida6a0de12016-12-06 17:12:36 +0200133 if (fw_mapping[i].fw &&
134 ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)))
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800135 return x + fw_mapping[i].host - fw_mapping[i].from;
136 }
137
138 return 0;
139}
140
141/**
142 * Check address validity for WMI buffer; remap if needed
143 * @ptr - internal (linker) fw/ucode address
Lior David3c858a72017-10-17 11:13:36 +0300144 * @size - if non zero, validate the block does not
145 * exceed the device memory (bar)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800146 *
147 * Valid buffer should be DWORD aligned
148 *
149 * return address for accessing buffer from the host;
150 * if buffer is not valid, return NULL.
151 */
Lior David3c858a72017-10-17 11:13:36 +0300152void __iomem *wmi_buffer_block(struct wil6210_priv *wil, __le32 ptr_, u32 size)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800153{
154 u32 off;
155 u32 ptr = le32_to_cpu(ptr_);
156
157 if (ptr % 4)
158 return NULL;
159
160 ptr = wmi_addr_remap(ptr);
161 if (ptr < WIL6210_FW_HOST_OFF)
162 return NULL;
163
164 off = HOSTADDR(ptr);
Maya Erezd5361f62017-05-25 18:43:36 +0300165 if (off > wil->bar_size - 4)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800166 return NULL;
Lior David3c858a72017-10-17 11:13:36 +0300167 if (size && ((off + size > wil->bar_size) || (off + size < off)))
168 return NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800169
170 return wil->csr + off;
171}
172
Lior David3c858a72017-10-17 11:13:36 +0300173void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
174{
175 return wmi_buffer_block(wil, ptr_, 0);
176}
177
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800178/**
179 * Check address validity
180 */
181void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
182{
183 u32 off;
184
185 if (ptr % 4)
186 return NULL;
187
188 if (ptr < WIL6210_FW_HOST_OFF)
189 return NULL;
190
191 off = HOSTADDR(ptr);
Maya Erezd5361f62017-05-25 18:43:36 +0300192 if (off > wil->bar_size - 4)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800193 return NULL;
194
195 return wil->csr + off;
196}
197
198int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
199 struct wil6210_mbox_hdr *hdr)
200{
201 void __iomem *src = wmi_buffer(wil, ptr);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300202
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800203 if (!src)
204 return -EINVAL;
205
206 wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
207
208 return 0;
209}
210
211static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
212{
213 struct {
214 struct wil6210_mbox_hdr hdr;
Lior Davidb874dde2016-03-01 19:18:09 +0200215 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800216 } __packed cmd = {
217 .hdr = {
218 .type = WIL_MBOX_HDR_TYPE_WMI,
219 .flags = 0,
220 .len = cpu_to_le16(sizeof(cmd.wmi) + len),
221 },
222 .wmi = {
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300223 .mid = 0,
Lior Davidb874dde2016-03-01 19:18:09 +0200224 .command_id = cpu_to_le16(cmdid),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800225 },
226 };
227 struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
228 struct wil6210_mbox_ring_desc d_head;
229 u32 next_head;
230 void __iomem *dst;
231 void __iomem *head = wmi_addr(wil, r->head);
232 uint retry;
Maya Erez349214c2016-04-26 14:41:41 +0300233 int rc = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800234
Lior David2357ecb2017-10-16 20:39:31 +0300235 if (len > r->entry_size - sizeof(cmd)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800236 wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
237 (int)(sizeof(cmd) + len), r->entry_size);
238 return -ERANGE;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800239 }
240
241 might_sleep();
242
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200243 if (!test_bit(wil_status_fwready, wil->status)) {
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300244 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800245 return -EAGAIN;
246 }
247
Maya Ereze3309bf2017-05-15 16:57:46 +0300248 /* Allow sending only suspend / resume commands during susepnd flow */
249 if ((test_bit(wil_status_suspending, wil->status) ||
250 test_bit(wil_status_suspended, wil->status) ||
251 test_bit(wil_status_resuming, wil->status)) &&
252 ((cmdid != WMI_TRAFFIC_SUSPEND_CMDID) &&
253 (cmdid != WMI_TRAFFIC_RESUME_CMDID))) {
254 wil_err(wil, "WMI: reject send_command during suspend\n");
255 return -EINVAL;
256 }
257
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800258 if (!head) {
259 wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
260 return -EINVAL;
261 }
Maya Erez349214c2016-04-26 14:41:41 +0300262
263 wil_halp_vote(wil);
264
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800265 /* read Tx head till it is not busy */
266 for (retry = 5; retry > 0; retry--) {
267 wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
268 if (d_head.sync == 0)
269 break;
270 msleep(20);
271 }
272 if (d_head.sync != 0) {
273 wil_err(wil, "WMI head busy\n");
Maya Erez349214c2016-04-26 14:41:41 +0300274 rc = -EBUSY;
275 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800276 }
277 /* next head */
278 next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200279 wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800280 /* wait till FW finish with previous command */
281 for (retry = 5; retry > 0; retry--) {
Maya Erez452133a2015-11-24 09:30:15 +0200282 if (!test_bit(wil_status_fwready, wil->status)) {
283 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Maya Erez349214c2016-04-26 14:41:41 +0300284 rc = -EAGAIN;
285 goto out;
Maya Erez452133a2015-11-24 09:30:15 +0200286 }
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300287 r->tail = wil_r(wil, RGF_MBOX +
288 offsetof(struct wil6210_mbox_ctl, tx.tail));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800289 if (next_head != r->tail)
290 break;
291 msleep(20);
292 }
293 if (next_head == r->tail) {
294 wil_err(wil, "WMI ring full\n");
Maya Erez349214c2016-04-26 14:41:41 +0300295 rc = -EBUSY;
296 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800297 }
298 dst = wmi_buffer(wil, d_head.addr);
299 if (!dst) {
300 wil_err(wil, "invalid WMI buffer: 0x%08x\n",
301 le32_to_cpu(d_head.addr));
Maya Erez349214c2016-04-26 14:41:41 +0300302 rc = -EAGAIN;
303 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800304 }
305 cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
306 /* set command */
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200307 wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len);
308 wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800309 sizeof(cmd), true);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200310 wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800311 len, true);
312 wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
313 wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
314 /* mark entry as full */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300315 wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800316 /* advance next ptr */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300317 wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
318 r->head = next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800319
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300320 trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
Vladimir Kondratiev98658092013-05-12 14:43:35 +0300321
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800322 /* interrupt to FW */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300323 wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
324 SW_INT_MBOX);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800325
Maya Erez349214c2016-04-26 14:41:41 +0300326out:
327 wil_halp_unvote(wil);
328 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800329}
330
331int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
332{
333 int rc;
334
335 mutex_lock(&wil->wmi_mutex);
336 rc = __wmi_send(wil, cmdid, buf, len);
337 mutex_unlock(&wil->wmi_mutex);
338
339 return rc;
340}
341
342/*=== Event handlers ===*/
343static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len)
344{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800345 struct wireless_dev *wdev = wil->wdev;
346 struct wmi_ready_event *evt = d;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300347
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200348 wil->n_mids = evt->numof_additional_mids;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800349
Lior David13cd9f72016-08-22 12:42:22 +0300350 wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
351 wil->fw_version, le32_to_cpu(evt->sw_version),
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300352 evt->mac, wil->n_mids);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200353 /* ignore MAC address, we already have it from the boot loader */
Lior David13cd9f72016-08-22 12:42:22 +0300354 strlcpy(wdev->wiphy->fw_version, wil->fw_version,
355 sizeof(wdev->wiphy->fw_version));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800356
Dedy Lanskyecac1072017-08-21 22:53:18 +0300357 if (len > offsetof(struct wmi_ready_event, rfc_read_calib_result)) {
358 wil_dbg_wmi(wil, "rfc calibration result %d\n",
359 evt->rfc_read_calib_result);
360 wil->fw_calib_result = evt->rfc_read_calib_result;
361 }
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300362 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200363 set_bit(wil_status_fwready, wil->status);
Dedy Lansky59502642014-09-10 16:34:46 +0300364 /* let the reset sequence continue */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800365 complete(&wil->wmi_ready);
366}
367
368static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
369{
370 struct wmi_rx_mgmt_packet_event *data = d;
371 struct wiphy *wiphy = wil_to_wiphy(wil);
372 struct ieee80211_mgmt *rx_mgmt_frame =
373 (struct ieee80211_mgmt *)data->payload;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300374 int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
375 int ch_no;
376 u32 freq;
377 struct ieee80211_channel *channel;
378 s32 signal;
379 __le16 fc;
380 u32 d_len;
381 u16 d_status;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800382
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300383 if (flen < 0) {
384 wil_err(wil, "MGMT Rx: short event, len %d\n", len);
385 return;
386 }
387
388 d_len = le32_to_cpu(data->info.len);
389 if (d_len != flen) {
390 wil_err(wil,
391 "MGMT Rx: length mismatch, d_len %d should be %d\n",
392 d_len, flen);
393 return;
394 }
395
396 ch_no = data->info.channel + 1;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200397 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300398 channel = ieee80211_get_channel(wiphy, freq);
Dedy Lanskyb3f87382017-08-21 22:58:54 +0300399 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
400 signal = 100 * data->info.rssi;
401 else
402 signal = data->info.sqi;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300403 d_status = le16_to_cpu(data->info.status);
404 fc = rx_mgmt_frame->frame_control;
405
Dedy Lanskyb3f87382017-08-21 22:58:54 +0300406 wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d RSSI %d SQI %d%%\n",
407 data->info.channel, data->info.mcs, data->info.rssi,
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200408 data->info.sqi);
Vladimir Kondratievf27dbf72013-06-09 09:12:52 +0300409 wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
410 le16_to_cpu(fc));
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200411 wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800412 data->info.qid, data->info.mid, data->info.cid);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300413 wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
414 d_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800415
416 if (!channel) {
417 wil_err(wil, "Frame on unsupported channel\n");
418 return;
419 }
420
421 if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
422 struct cfg80211_bss *bss;
Vladimir Kondratiev8eea9442014-06-16 19:37:03 +0300423 u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
424 u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
425 u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
426 const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
427 size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
428 u.beacon.variable);
429 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
430 wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
431 wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
432 wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
433 ie_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800434
Dedy Lanskye6d68342016-03-01 19:18:12 +0200435 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
436
Vladimir Kondratieva0f78452013-03-13 14:12:44 +0200437 bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
438 d_len, signal, GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800439 if (bss) {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200440 wil_dbg_wmi(wil, "Added BSS %pM\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800441 rx_mgmt_frame->bssid);
Johannes Berg5b112d32013-02-01 01:49:58 +0100442 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800443 } else {
Johannes Berg5bc8c1f2014-08-12 21:01:28 +0200444 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800445 }
Vladimir Kondratiev102b1d92013-03-13 14:12:45 +0200446 } else {
Lior David4332cac2016-03-01 19:18:13 +0200447 mutex_lock(&wil->p2p_wdev_mutex);
448 cfg80211_rx_mgmt(wil->radio_wdev, freq, signal,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700449 (void *)rx_mgmt_frame, d_len, 0);
Lior David4332cac2016-03-01 19:18:13 +0200450 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800451 }
452}
453
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300454static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
455{
456 struct wmi_tx_mgmt_packet_event *data = d;
457 struct ieee80211_mgmt *mgmt_frame =
458 (struct ieee80211_mgmt *)data->payload;
459 int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
460
461 wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
462 flen, true);
463}
464
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
466 void *d, int len)
467{
Lior David5ffae432016-08-22 12:42:19 +0300468 mutex_lock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800469 if (wil->scan_request) {
470 struct wmi_scan_complete_event *data = d;
Maya Erez4cbb5852017-02-16 15:26:09 +0200471 int status = le32_to_cpu(data->status);
Avraham Stern1d762502016-07-05 17:10:13 +0300472 struct cfg80211_scan_info info = {
Maya Erez4cbb5852017-02-16 15:26:09 +0200473 .aborted = ((status != WMI_SCAN_SUCCESS) &&
474 (status != WMI_SCAN_ABORT_REJECTED)),
Avraham Stern1d762502016-07-05 17:10:13 +0300475 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800476
Maya Erez4cbb5852017-02-16 15:26:09 +0200477 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300478 wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
Avraham Stern1d762502016-07-05 17:10:13 +0300479 wil->scan_request, info.aborted);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300480 del_timer_sync(&wil->scan_timer);
Avraham Stern1d762502016-07-05 17:10:13 +0300481 cfg80211_scan_done(wil->scan_request, &info);
Lior David4332cac2016-03-01 19:18:13 +0200482 wil->radio_wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800483 wil->scan_request = NULL;
Maya Erez4cbb5852017-02-16 15:26:09 +0200484 wake_up_interruptible(&wil->wq);
Lior David42ba1c222017-02-15 20:37:20 +0200485 if (wil->p2p.pending_listen_wdev) {
486 wil_dbg_misc(wil, "Scheduling delayed listen\n");
487 schedule_work(&wil->p2p.delayed_listen_work);
488 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800489 } else {
490 wil_err(wil, "SCAN_COMPLETE while not scanning\n");
491 }
Lior David5ffae432016-08-22 12:42:19 +0300492 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800493}
494
495static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len)
496{
497 struct net_device *ndev = wil_to_ndev(wil);
498 struct wireless_dev *wdev = wil->wdev;
499 struct wmi_connect_event *evt = d;
500 int ch; /* channel number */
501 struct station_info sinfo;
502 u8 *assoc_req_ie, *assoc_resp_ie;
503 size_t assoc_req_ielen, assoc_resp_ielen;
504 /* capinfo(u16) + listen_interval(u16) + IEs */
505 const size_t assoc_req_ie_offset = sizeof(u16) * 2;
506 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
507 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
Maya Erez0916d9f2016-01-17 12:39:10 +0200508 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800509
510 if (len < sizeof(*evt)) {
511 wil_err(wil, "Connect event too short : %d bytes\n", len);
512 return;
513 }
514 if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
515 evt->assoc_resp_len) {
516 wil_err(wil,
517 "Connect event corrupted : %d != %d + %d + %d + %d\n",
518 len, (int)sizeof(*evt), evt->beacon_ie_len,
519 evt->assoc_req_len, evt->assoc_resp_len);
520 return;
521 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200522 if (evt->cid >= WIL6210_MAX_CID) {
523 wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
524 return;
525 }
526
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800527 ch = evt->channel + 1;
Lior Davida7629792017-02-08 13:16:37 +0200528 wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n",
529 evt->bssid, ch, evt->cid, evt->aid);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200530 wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800531 evt->assoc_info, len - sizeof(*evt), true);
532
533 /* figure out IE's */
534 assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
535 assoc_req_ie_offset];
536 assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
537 if (evt->assoc_req_len <= assoc_req_ie_offset) {
538 assoc_req_ie = NULL;
539 assoc_req_ielen = 0;
540 }
541
542 assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
543 evt->assoc_req_len +
544 assoc_resp_ie_offset];
545 assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
546 if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
547 assoc_resp_ie = NULL;
548 assoc_resp_ielen = 0;
549 }
550
Maya Erez0916d9f2016-01-17 12:39:10 +0200551 if (test_bit(wil_status_resetting, wil->status) ||
552 !test_bit(wil_status_fwready, wil->status)) {
553 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
554 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200555 /* no need for cleanup, wil_reset will do that */
556 return;
557 }
558
Hamad Kadmany0e2f6e32017-04-13 14:38:20 +0300559 mutex_lock(&wil->mutex);
560
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800561 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
562 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200563 if (!test_bit(wil_status_fwconnecting, wil->status)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800564 wil_err(wil, "Not in connecting state\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200565 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800566 return;
567 }
568 del_timer_sync(&wil->connect_timer);
Maya Erez3d287fb2016-03-01 19:18:05 +0200569 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
570 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
571 if (wil->sta[evt->cid].status != wil_sta_unused) {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200572 wil_err(wil, "AP: Invalid status %d for CID %d\n",
573 wil->sta[evt->cid].status, evt->cid);
Maya Erez3d287fb2016-03-01 19:18:05 +0200574 mutex_unlock(&wil->mutex);
575 return;
576 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200577 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800578
Maya Erez0916d9f2016-01-17 12:39:10 +0200579 /* FIXME FW can transmit only ucast frames to peer */
580 /* FIXME real ring_id instead of hard coded 0 */
581 ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
582 wil->sta[evt->cid].status = wil_sta_conn_pending;
583
584 rc = wil_tx_init(wil, evt->cid);
585 if (rc) {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200586 wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n",
587 evt->cid, rc);
Maya Erez0916d9f2016-01-17 12:39:10 +0200588 wmi_disconnect_sta(wil, wil->sta[evt->cid].addr,
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200589 WLAN_REASON_UNSPECIFIED, false, false);
Maya Erez0916d9f2016-01-17 12:39:10 +0200590 } else {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200591 wil_info(wil, "successful connection to CID %d\n", evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200592 }
593
594 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
595 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
596 if (rc) {
Maya Erez0916d9f2016-01-17 12:39:10 +0200597 netif_carrier_off(ndev);
Lior David704099f2017-05-04 21:31:02 +0300598 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
Lazar Alexei3190cc62017-02-23 14:34:14 +0200599 wil_err(wil, "cfg80211_connect_result with failure\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200600 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
601 NULL, 0,
602 WLAN_STATUS_UNSPECIFIED_FAILURE,
603 GFP_KERNEL);
604 goto out;
605 } else {
Dedy Lanskya4882782017-05-04 21:36:09 +0300606 struct wiphy *wiphy = wil_to_wiphy(wil);
607
608 cfg80211_ref_bss(wiphy, wil->bss);
609 cfg80211_connect_bss(ndev, evt->bssid, wil->bss,
610 assoc_req_ie, assoc_req_ielen,
611 assoc_resp_ie, assoc_resp_ielen,
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200612 WLAN_STATUS_SUCCESS, GFP_KERNEL,
613 NL80211_TIMEOUT_UNSPECIFIED);
Maya Erez0916d9f2016-01-17 12:39:10 +0200614 }
Dedy Lanskya4882782017-05-04 21:36:09 +0300615 wil->bss = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800616 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
617 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200618 if (rc) {
619 if (disable_ap_sme)
620 /* notify new_sta has failed */
621 cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200622 goto out;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200623 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200624
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800625 memset(&sinfo, 0, sizeof(sinfo));
626
627 sinfo.generation = wil->sinfo_gen++;
628
629 if (assoc_req_ie) {
630 sinfo.assoc_req_ies = assoc_req_ie;
631 sinfo.assoc_req_ies_len = assoc_req_ielen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800632 }
633
634 cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200635 } else {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200636 wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
637 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200638 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800639 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200640
641 wil->sta[evt->cid].status = wil_sta_connected;
Lior Davida7629792017-02-08 13:16:37 +0200642 wil->sta[evt->cid].aid = evt->aid;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200643 set_bit(wil_status_fwconnected, wil->status);
Dedy Lansky970a98f2016-12-06 08:26:49 +0200644 wil_update_net_queues_bh(wil, NULL, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800645
Maya Erez0916d9f2016-01-17 12:39:10 +0200646out:
647 if (rc)
648 wil->sta[evt->cid].status = wil_sta_unused;
649 clear_bit(wil_status_fwconnecting, wil->status);
650 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800651}
652
653static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
654 void *d, int len)
655{
656 struct wmi_disconnect_event *evt = d;
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200657 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800658
Maya Erez0916d9f2016-01-17 12:39:10 +0200659 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
660 evt->bssid, reason_code, evt->disconnect_reason);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800661
662 wil->sinfo_gen++;
663
Hamad Kadmany0e2f6e32017-04-13 14:38:20 +0300664 if (test_bit(wil_status_resetting, wil->status) ||
665 !test_bit(wil_status_fwready, wil->status)) {
666 wil_err(wil, "status_resetting, cancel disconnect event\n");
667 /* no need for cleanup, wil_reset will do that */
668 return;
669 }
670
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200671 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200672 wil6210_disconnect(wil, evt->bssid, reason_code, true);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200673 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800674}
675
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800676/*
677 * Firmware reports EAPOL frame using WME event.
678 * Reconstruct Ethernet frame and deliver it via normal Rx
679 */
680static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
681 void *d, int len)
682{
683 struct net_device *ndev = wil_to_ndev(wil);
684 struct wmi_eapol_rx_event *evt = d;
685 u16 eapol_len = le16_to_cpu(evt->eapol_len);
686 int sz = eapol_len + ETH_HLEN;
687 struct sk_buff *skb;
688 struct ethhdr *eth;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200689 int cid;
690 struct wil_net_stats *stats = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800691
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200692 wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800693 evt->src_mac);
694
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200695 cid = wil_find_cid(wil, evt->src_mac);
696 if (cid >= 0)
697 stats = &wil->sta[cid].stats;
698
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800699 if (eapol_len > 196) { /* TODO: revisit size limit */
700 wil_err(wil, "EAPOL too large\n");
701 return;
702 }
703
704 skb = alloc_skb(sz, GFP_KERNEL);
705 if (!skb) {
706 wil_err(wil, "Failed to allocate skb\n");
707 return;
708 }
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200709
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800710 eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200711 ether_addr_copy(eth->h_dest, ndev->dev_addr);
712 ether_addr_copy(eth->h_source, evt->src_mac);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800713 eth->h_proto = cpu_to_be16(ETH_P_PAE);
714 memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len);
715 skb->protocol = eth_type_trans(skb, ndev);
716 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
717 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200718 ndev->stats.rx_bytes += sz;
719 if (stats) {
720 stats->rx_packets++;
721 stats->rx_bytes += sz;
722 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800723 } else {
724 ndev->stats.rx_dropped++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200725 if (stats)
726 stats->rx_dropped++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800727 }
728}
729
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300730static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200731{
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300732 struct wmi_vring_en_event *evt = d;
733 u8 vri = evt->vring_index;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200734 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200735
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300736 wil_dbg_wmi(wil, "Enable vring %d\n", vri);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200737
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300738 if (vri >= ARRAY_SIZE(wil->vring_tx)) {
739 wil_err(wil, "Enable for invalid vring %d\n", vri);
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200740 return;
741 }
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200742
743 if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme)
744 /* in AP mode with disable_ap_sme, this is done by
745 * wil_cfg80211_change_station()
746 */
747 wil->vring_tx_data[vri].dot1x_open = true;
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300748 if (vri == wil->bcast_vring) /* no BA for bcast */
749 return;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200750 if (agg_wsize >= 0)
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300751 wil_addba_tx_request(wil, vri, agg_wsize);
Vladimir Kondratiev3442a502013-03-13 14:12:39 +0200752}
753
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200754static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
755 int len)
756{
Lior Davidb874dde2016-03-01 19:18:09 +0200757 struct wmi_ba_status_event *evt = d;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200758 struct vring_tx_data *txdata;
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200759
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200760 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200761 evt->ringid,
762 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200763 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
764 evt->amsdu ? "+" : "-");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200765
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200766 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
767 wil_err(wil, "invalid ring id %d\n", evt->ringid);
768 return;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200769 }
770
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200771 if (evt->status != WMI_BA_AGREED) {
772 evt->ba_timeout = 0;
773 evt->agg_wsize = 0;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200774 evt->amsdu = 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200775 }
Dedy Lansky8c86f752014-09-10 16:34:40 +0300776
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200777 txdata = &wil->vring_tx_data[evt->ringid];
778
779 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
780 txdata->agg_wsize = evt->agg_wsize;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200781 txdata->agg_amsdu = evt->amsdu;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200782 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200783}
784
785static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d,
786 int len)
787{
788 struct wmi_rcp_addba_req_event *evt = d;
789
790 wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token,
791 evt->ba_param_set, evt->ba_timeout,
792 evt->ba_seq_ctrl);
793}
794
795static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200796__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200797{
798 struct wmi_delba_event *evt = d;
799 u8 cid, tid;
800 u16 reason = __le16_to_cpu(evt->reason);
801 struct wil_sta_info *sta;
802 struct wil_tid_ampdu_rx *r;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200803
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200804 might_sleep();
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200805 parse_cidxtid(evt->cidxtid, &cid, &tid);
806 wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n",
807 cid, tid,
808 evt->from_initiator ? "originator" : "recipient",
809 reason);
810 if (!evt->from_initiator) {
811 int i;
812 /* find Tx vring it belongs to */
813 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
814 if ((wil->vring2cid_tid[i][0] == cid) &&
815 (wil->vring2cid_tid[i][1] == tid)) {
816 struct vring_tx_data *txdata =
817 &wil->vring_tx_data[i];
818
819 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
820 txdata->agg_timeout = 0;
821 txdata->agg_wsize = 0;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200822 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200823
824 break; /* max. 1 matching ring */
825 }
826 }
827 if (i >= ARRAY_SIZE(wil->vring2cid_tid))
828 wil_err(wil, "DELBA: unable to find Tx vring\n");
829 return;
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200830 }
831
832 sta = &wil->sta[cid];
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200833
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200834 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300835
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200836 r = sta->tid_rx[tid];
837 sta->tid_rx[tid] = NULL;
838 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300839
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200840 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200841}
842
Lior David8f1b5e02017-02-28 14:58:27 +0200843static void wmi_evt_aoa_meas(struct wil6210_priv *wil, int id,
844 void *d, int len)
845{
846 struct wmi_aoa_meas_event *evt = d;
847
848 wil_aoa_evt_meas(wil, evt, len);
849}
850
851static void wmi_evt_ftm_session_ended(struct wil6210_priv *wil, int id,
852 void *d, int len)
853{
854 struct wmi_tof_session_end_event *evt = d;
855
856 wil_ftm_evt_session_ended(wil, evt);
857}
858
859static void wmi_evt_per_dest_res(struct wil6210_priv *wil, int id,
860 void *d, int len)
861{
862 struct wmi_tof_ftm_per_dest_res_event *evt = d;
863
864 wil_ftm_evt_per_dest_res(wil, evt);
865}
866
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200867/**
868 * Some events are ignored for purpose; and need not be interpreted as
869 * "unhandled events"
870 */
871static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len)
872{
873 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
874}
875
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800876static const struct {
877 int eventid;
878 void (*handler)(struct wil6210_priv *wil, int eventid,
879 void *data, int data_len);
880} wmi_evt_handlers[] = {
881 {WMI_READY_EVENTID, wmi_evt_ready},
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200882 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800883 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300884 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800885 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
886 {WMI_CONNECT_EVENTID, wmi_evt_connect},
887 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800888 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200889 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200890 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
891 {WMI_DELBA_EVENTID, wmi_evt_delba},
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300892 {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200893 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
Lior David8f1b5e02017-02-28 14:58:27 +0200894 {WMI_AOA_MEAS_EVENTID, wmi_evt_aoa_meas},
895 {WMI_TOF_SESSION_END_EVENTID, wmi_evt_ftm_session_ended},
896 {WMI_TOF_GET_CAPABILITIES_EVENTID, wmi_evt_ignore},
897 {WMI_TOF_SET_LCR_EVENTID, wmi_evt_ignore},
898 {WMI_TOF_SET_LCI_EVENTID, wmi_evt_ignore},
899 {WMI_TOF_FTM_PER_DEST_RES_EVENTID, wmi_evt_per_dest_res},
900 {WMI_TOF_CHANNEL_INFO_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800901};
902
903/*
904 * Run in IRQ context
905 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
906 * that will be eventually handled by the @wmi_event_worker in the thread
907 * context of thread "wil6210_wmi"
908 */
909void wmi_recv_cmd(struct wil6210_priv *wil)
910{
911 struct wil6210_mbox_ring_desc d_tail;
912 struct wil6210_mbox_hdr hdr;
913 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
914 struct pending_wmi_event *evt;
915 u8 *cmd;
916 void __iomem *src;
917 ulong flags;
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300918 unsigned n;
Maya Erez0916d9f2016-01-17 12:39:10 +0200919 unsigned int num_immed_reply = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800920
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200921 if (!test_bit(wil_status_mbox_ready, wil->status)) {
Dedy Lansky4cf99c92014-09-10 16:34:41 +0300922 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
Vladimir Kondratiev55f7acd2013-03-13 14:12:49 +0200923 return;
924 }
925
Maya Ereze3309bf2017-05-15 16:57:46 +0300926 if (test_bit(wil_status_suspended, wil->status)) {
927 wil_err(wil, "suspended. cannot handle WMI event\n");
928 return;
929 }
930
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300931 for (n = 0;; n++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800932 u16 len;
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300933 bool q;
Maya Erez0916d9f2016-01-17 12:39:10 +0200934 bool immed_reply = false;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800935
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300936 r->head = wil_r(wil, RGF_MBOX +
937 offsetof(struct wil6210_mbox_ctl, rx.head));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300938 if (r->tail == r->head)
939 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800940
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300941 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
942 r->head, r->tail);
943 /* read cmd descriptor from tail */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800944 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
945 sizeof(struct wil6210_mbox_ring_desc));
946 if (d_tail.sync == 0) {
947 wil_err(wil, "Mbox evt not owned by FW?\n");
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300948 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800949 }
950
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300951 /* read cmd header from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800952 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
953 wil_err(wil, "Mbox evt at 0x%08x?\n",
954 le32_to_cpu(d_tail.addr));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300955 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800956 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800957 len = le16_to_cpu(hdr.len);
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300958 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
959 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
960 hdr.flags);
961
962 /* read cmd buffer from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800963 src = wmi_buffer(wil, d_tail.addr) +
964 sizeof(struct wil6210_mbox_hdr);
965 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
966 event.wmi) + len, 4),
967 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000968 if (!evt)
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300969 break;
Joe Perches14f8dc42013-02-07 11:46:27 +0000970
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800971 evt->event.hdr = hdr;
972 cmd = (void *)&evt->event.wmi;
973 wil_memcpy_fromio_32(cmd, src, len);
974 /* mark entry as empty */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300975 wil_w(wil, r->tail +
976 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800977 /* indicate */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800978 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +0200979 (len >= sizeof(struct wmi_cmd_hdr))) {
980 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
981 u16 id = le16_to_cpu(wmi->command_id);
982 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
Maya Ereze3309bf2017-05-15 16:57:46 +0300983 if (test_bit(wil_status_resuming, wil->status)) {
984 if (id == WMI_TRAFFIC_RESUME_EVENTID)
985 clear_bit(wil_status_resuming,
986 wil->status);
987 else
988 wil_err(wil,
989 "WMI evt %d while resuming\n",
990 id);
991 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200992 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
Maya Erez0916d9f2016-01-17 12:39:10 +0200993 if (wil->reply_id && wil->reply_id == id) {
994 if (wil->reply_buf) {
995 memcpy(wil->reply_buf, wmi,
996 min(len, wil->reply_size));
997 immed_reply = true;
998 }
Maya Ereze3309bf2017-05-15 16:57:46 +0300999 if (id == WMI_TRAFFIC_SUSPEND_EVENTID) {
1000 wil_dbg_wmi(wil,
1001 "set suspend_resp_rcvd\n");
1002 wil->suspend_resp_rcvd = true;
1003 }
Maya Erez0916d9f2016-01-17 12:39:10 +02001004 }
Maya Erezfe5c2712016-01-28 19:24:04 +02001005 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001006
Vladimir Kondratievf988b232013-07-11 18:03:37 +03001007 wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
1008 id, wmi->mid, tstamp);
1009 trace_wil6210_wmi_event(wmi, &wmi[1],
1010 len - sizeof(*wmi));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001011 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001012 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001013 &evt->event.hdr, sizeof(hdr) + len, true);
1014
1015 /* advance tail */
1016 r->tail = r->base + ((r->tail - r->base +
1017 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +03001018 wil_w(wil, RGF_MBOX +
1019 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001020
Maya Erez0916d9f2016-01-17 12:39:10 +02001021 if (immed_reply) {
Lazar Alexei3190cc62017-02-23 14:34:14 +02001022 wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
1023 wil->reply_id);
Maya Erez0916d9f2016-01-17 12:39:10 +02001024 kfree(evt);
1025 num_immed_reply++;
1026 complete(&wil->wmi_call);
1027 } else {
1028 /* add to the pending list */
1029 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1030 list_add_tail(&evt->list, &wil->pending_wmi_ev);
1031 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
1032 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
1033 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
1034 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001035 }
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +03001036 /* normally, 1 event per IRQ should be processed */
Lazar Alexei3190cc62017-02-23 14:34:14 +02001037 wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
Maya Erez0916d9f2016-01-17 12:39:10 +02001038 n - num_immed_reply, num_immed_reply);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001039}
1040
1041int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
1042 u16 reply_id, void *reply, u8 reply_size, int to_msec)
1043{
1044 int rc;
Nicholas Mc Guiref4bbb822015-08-13 15:38:31 +03001045 unsigned long remain;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001046
1047 mutex_lock(&wil->wmi_mutex);
1048
Maya Erezfe5c2712016-01-28 19:24:04 +02001049 spin_lock(&wil->wmi_ev_lock);
1050 wil->reply_id = reply_id;
1051 wil->reply_buf = reply;
1052 wil->reply_size = reply_size;
Lior David01660062017-02-22 15:15:23 +02001053 reinit_completion(&wil->wmi_call);
Maya Erezfe5c2712016-01-28 19:24:04 +02001054 spin_unlock(&wil->wmi_ev_lock);
1055
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001056 rc = __wmi_send(wil, cmdid, buf, len);
1057 if (rc)
1058 goto out;
1059
Dedy Lansky59502642014-09-10 16:34:46 +03001060 remain = wait_for_completion_timeout(&wil->wmi_call,
1061 msecs_to_jiffies(to_msec));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001062 if (0 == remain) {
1063 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
1064 cmdid, reply_id, to_msec);
1065 rc = -ETIME;
1066 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001067 wil_dbg_wmi(wil,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001068 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
1069 cmdid, reply_id,
1070 to_msec - jiffies_to_msecs(remain));
1071 }
Maya Erezfe5c2712016-01-28 19:24:04 +02001072
1073out:
1074 spin_lock(&wil->wmi_ev_lock);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001075 wil->reply_id = 0;
1076 wil->reply_buf = NULL;
1077 wil->reply_size = 0;
Maya Erezfe5c2712016-01-28 19:24:04 +02001078 spin_unlock(&wil->wmi_ev_lock);
1079
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001080 mutex_unlock(&wil->wmi_mutex);
1081
1082 return rc;
1083}
1084
1085int wmi_echo(struct wil6210_priv *wil)
1086{
1087 struct wmi_echo_cmd cmd = {
1088 .value = cpu_to_le32(0x12345678),
1089 };
1090
1091 return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratieva54a40d2015-04-30 16:25:05 +03001092 WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001093}
1094
1095int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
1096{
1097 struct wmi_set_mac_address_cmd cmd;
1098
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001099 ether_addr_copy(cmd.mac, addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001100
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001101 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001102
1103 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
1104}
1105
Maya Erez10d599a2016-05-09 21:57:11 +03001106int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
1107{
1108 int rc = 0;
1109 struct wmi_led_cfg_cmd cmd = {
1110 .led_mode = enable,
1111 .id = led_id,
1112 .slow_blink_cfg.blink_on =
1113 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
1114 .slow_blink_cfg.blink_off =
1115 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
1116 .medium_blink_cfg.blink_on =
1117 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
1118 .medium_blink_cfg.blink_off =
1119 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
1120 .fast_blink_cfg.blink_on =
1121 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
1122 .fast_blink_cfg.blink_off =
1123 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
1124 .led_polarity = led_polarity,
1125 };
1126 struct {
1127 struct wmi_cmd_hdr wmi;
1128 struct wmi_led_cfg_done_event evt;
1129 } __packed reply;
1130
1131 if (led_id == WIL_LED_INVALID_ID)
1132 goto out;
1133
1134 if (led_id > WIL_LED_MAX_ID) {
1135 wil_err(wil, "Invalid led id %d\n", led_id);
1136 rc = -EINVAL;
1137 goto out;
1138 }
1139
1140 wil_dbg_wmi(wil,
1141 "%s led %d\n",
1142 enable ? "enabling" : "disabling", led_id);
1143
1144 rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd),
1145 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
1146 100);
1147 if (rc)
1148 goto out;
1149
1150 if (reply.evt.status) {
1151 wil_err(wil, "led %d cfg failed with status %d\n",
1152 led_id, le32_to_cpu(reply.evt.status));
1153 rc = -EINVAL;
1154 }
1155
1156out:
1157 return rc;
1158}
1159
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001160int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype,
Lior Davidb4944f22016-03-01 19:18:17 +02001161 u8 chan, u8 hidden_ssid, u8 is_go)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001162{
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001163 int rc;
1164
1165 struct wmi_pcp_start_cmd cmd = {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001166 .bcon_interval = cpu_to_le16(bi),
1167 .network_type = wmi_nettype,
1168 .disable_sec_offload = 1,
Vladimir Kondratievadc2d122013-05-28 15:17:52 +03001169 .channel = chan - 1,
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001170 .pcp_max_assoc_sta = max_assoc_sta,
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001171 .hidden_ssid = hidden_ssid,
Lior Davidb4944f22016-03-01 19:18:17 +02001172 .is_go = is_go,
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001173 .disable_ap_sme = disable_ap_sme,
Lior David4bbecaf2017-02-08 13:17:35 +02001174 .abft_len = wil->abft_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001175 };
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001176 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001177 struct wmi_cmd_hdr wmi;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001178 struct wmi_pcp_started_event evt;
1179 } __packed reply;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001180
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001181 if (!wil->privacy)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001182 cmd.disable_sec = 1;
1183
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001184 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
1185 (cmd.pcp_max_assoc_sta <= 0)) {
1186 wil_info(wil,
1187 "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
1188 max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
1189 cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
1190 }
1191
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001192 if (disable_ap_sme &&
1193 !test_bit(WMI_FW_CAPABILITY_DISABLE_AP_SME,
1194 wil->fw_capabilities)) {
1195 wil_err(wil, "disable_ap_sme not supported by FW\n");
1196 return -EOPNOTSUPP;
1197 }
1198
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001199 /*
1200 * Processing time may be huge, in case of secure AP it takes about
1201 * 3500ms for FW to start AP
1202 */
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001203 rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001204 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001205 if (rc)
1206 return rc;
1207
1208 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
1209 rc = -EINVAL;
1210
Maya Erez10d599a2016-05-09 21:57:11 +03001211 if (wmi_nettype != WMI_NETTYPE_P2P)
1212 /* Don't fail due to error in the led configuration */
1213 wmi_led_cfg(wil, true);
1214
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001215 return rc;
1216}
1217
1218int wmi_pcp_stop(struct wil6210_priv *wil)
1219{
Maya Erez10d599a2016-05-09 21:57:11 +03001220 int rc;
1221
1222 rc = wmi_led_cfg(wil, false);
1223 if (rc)
1224 return rc;
1225
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001226 return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
1227 WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001228}
1229
1230int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
1231{
1232 struct wmi_set_ssid_cmd cmd = {
1233 .ssid_len = cpu_to_le32(ssid_len),
1234 };
1235
1236 if (ssid_len > sizeof(cmd.ssid))
1237 return -EINVAL;
1238
1239 memcpy(cmd.ssid, ssid, ssid_len);
1240
1241 return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
1242}
1243
1244int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
1245{
1246 int rc;
1247 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001248 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001249 struct wmi_set_ssid_cmd cmd;
1250 } __packed reply;
1251 int len; /* reply.cmd.ssid_len in CPU order */
1252
1253 rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
1254 &reply, sizeof(reply), 20);
1255 if (rc)
1256 return rc;
1257
1258 len = le32_to_cpu(reply.cmd.ssid_len);
1259 if (len > sizeof(reply.cmd.ssid))
1260 return -EINVAL;
1261
1262 *ssid_len = len;
1263 memcpy(ssid, reply.cmd.ssid, len);
1264
1265 return 0;
1266}
1267
1268int wmi_set_channel(struct wil6210_priv *wil, int channel)
1269{
1270 struct wmi_set_pcp_channel_cmd cmd = {
1271 .channel = channel - 1,
1272 };
1273
1274 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
1275}
1276
1277int wmi_get_channel(struct wil6210_priv *wil, int *channel)
1278{
1279 int rc;
1280 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001281 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001282 struct wmi_set_pcp_channel_cmd cmd;
1283 } __packed reply;
1284
1285 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
1286 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
1287 if (rc)
1288 return rc;
1289
1290 if (reply.cmd.channel > 3)
1291 return -EINVAL;
1292
1293 *channel = reply.cmd.channel + 1;
1294
1295 return 0;
1296}
1297
Dedy Lanskye6d68342016-03-01 19:18:12 +02001298int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi)
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001299{
Dedy Lanskye6d68342016-03-01 19:18:12 +02001300 int rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001301 struct wmi_p2p_cfg_cmd cmd = {
Dedy Lanskye6d68342016-03-01 19:18:12 +02001302 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
1303 .bcon_interval = cpu_to_le16(bi),
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001304 .channel = channel - 1,
1305 };
Dedy Lanskye6d68342016-03-01 19:18:12 +02001306 struct {
1307 struct wmi_cmd_hdr wmi;
1308 struct wmi_p2p_cfg_done_event evt;
1309 } __packed reply;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001310
Dedy Lanskye6d68342016-03-01 19:18:12 +02001311 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
1312
1313 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd),
1314 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
1315 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1316 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
1317 rc = -EINVAL;
1318 }
1319
1320 return rc;
1321}
1322
1323int wmi_start_listen(struct wil6210_priv *wil)
1324{
1325 int rc;
1326 struct {
1327 struct wmi_cmd_hdr wmi;
1328 struct wmi_listen_started_event evt;
1329 } __packed reply;
1330
1331 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
1332
1333 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1334 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
1335 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1336 wil_err(wil, "device failed to start listen. status %d\n",
1337 reply.evt.status);
1338 rc = -EINVAL;
1339 }
1340
1341 return rc;
1342}
1343
1344int wmi_start_search(struct wil6210_priv *wil)
1345{
1346 int rc;
1347 struct {
1348 struct wmi_cmd_hdr wmi;
1349 struct wmi_search_started_event evt;
1350 } __packed reply;
1351
1352 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
1353
1354 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0,
1355 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
1356 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1357 wil_err(wil, "device failed to start search. status %d\n",
1358 reply.evt.status);
1359 rc = -EINVAL;
1360 }
1361
1362 return rc;
1363}
1364
1365int wmi_stop_discovery(struct wil6210_priv *wil)
1366{
1367 int rc;
1368
1369 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
1370
1371 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1372 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
1373
1374 if (rc)
1375 wil_err(wil, "Failed to stop discovery\n");
1376
1377 return rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001378}
1379
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001380int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001381 const void *mac_addr, int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001382{
1383 struct wmi_delete_cipher_key_cmd cmd = {
1384 .key_index = key_index,
1385 };
1386
1387 if (mac_addr)
1388 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1389
1390 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1391}
1392
1393int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001394 const void *mac_addr, int key_len, const void *key,
1395 int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001396{
1397 struct wmi_add_cipher_key_cmd cmd = {
1398 .key_index = key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001399 .key_usage = key_usage,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001400 .key_len = key_len,
1401 };
1402
1403 if (!key || (key_len > sizeof(cmd.key)))
1404 return -EINVAL;
1405
1406 memcpy(cmd.key, key, key_len);
1407 if (mac_addr)
1408 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1409
1410 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1411}
1412
1413int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
1414{
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001415 static const char *const names[] = {
1416 [WMI_FRAME_BEACON] = "BEACON",
1417 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
1418 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
1419 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
1420 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
1421 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001422 int rc;
1423 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
Lior Davidee2fe142017-10-17 14:18:17 +03001424 struct wmi_set_appie_cmd *cmd;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001425
Lior Davidee2fe142017-10-17 14:18:17 +03001426 if (len < ie_len) {
1427 rc = -EINVAL;
1428 goto out;
1429 }
1430
1431 cmd = kzalloc(len, GFP_KERNEL);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001432 if (!cmd) {
1433 rc = -ENOMEM;
1434 goto out;
1435 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +03001436 if (!ie)
1437 ie_len = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001438
1439 cmd->mgmt_frm_type = type;
1440 /* BUG: FW API define ieLen as u8. Will fix FW */
1441 cmd->ie_len = cpu_to_le16(ie_len);
1442 memcpy(cmd->ie_info, ie, ie_len);
Vladimir Kondratiev03866e72013-03-13 14:12:42 +02001443 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001444 kfree(cmd);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001445out:
1446 if (rc) {
1447 const char *name = type < ARRAY_SIZE(names) ?
1448 names[type] : "??";
1449 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
1450 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001451
1452 return rc;
1453}
1454
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001455/**
1456 * wmi_rxon - turn radio on/off
1457 * @on: turn on if true, off otherwise
1458 *
1459 * Only switch radio. Channel should be set separately.
1460 * No timeout for rxon - radio turned on forever unless some other call
1461 * turns it off
1462 */
1463int wmi_rxon(struct wil6210_priv *wil, bool on)
1464{
1465 int rc;
1466 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001467 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001468 struct wmi_listen_started_event evt;
1469 } __packed reply;
1470
Lazar Alexei3190cc62017-02-23 14:34:14 +02001471 wil_info(wil, "(%s)\n", on ? "on" : "off");
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001472
1473 if (on) {
1474 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1475 WMI_LISTEN_STARTED_EVENTID,
1476 &reply, sizeof(reply), 100);
1477 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
1478 rc = -EINVAL;
1479 } else {
1480 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1481 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
1482 }
1483
1484 return rc;
1485}
1486
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001487int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1488{
1489 struct wireless_dev *wdev = wil->wdev;
1490 struct net_device *ndev = wil_to_ndev(wil);
1491 struct wmi_cfg_rx_chain_cmd cmd = {
1492 .action = WMI_RX_CHAIN_ADD,
1493 .rx_sw_ring = {
Lior David2e9a3212017-05-04 22:43:18 +03001494 .max_mpdu_size = cpu_to_le16(
1495 wil_mtu2macbuf(wil->rx_buf_len)),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001496 .ring_mem_base = cpu_to_le64(vring->pa),
1497 .ring_size = cpu_to_le16(vring->size),
1498 },
1499 .mid = 0, /* TODO - what is it? */
1500 .decap_trans_type = WMI_DECAP_TYPE_802_3,
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001501 .reorder_type = WMI_RX_SW_REORDER,
Vladimir Kondratievab954622014-12-23 09:47:20 +02001502 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001503 };
1504 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001505 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001506 struct wmi_cfg_rx_chain_done_event evt;
1507 } __packed evt;
1508 int rc;
1509
1510 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
1511 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
1512
1513 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
1514 if (ch)
1515 cmd.sniffer_cfg.channel = ch->hw_value - 1;
1516 cmd.sniffer_cfg.phy_info_mode =
1517 cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
1518 cmd.sniffer_cfg.phy_support =
1519 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
Vladimir Kondratiev47653322015-10-04 10:23:24 +03001520 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +03001521 } else {
1522 /* Initialize offload (in non-sniffer mode).
1523 * Linux IP stack always calculates IP checksum
1524 * HW always calculate TCP/UDP checksum
1525 */
1526 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001527 }
Vladimir Kondratievc406ea72015-03-15 16:00:19 +02001528
1529 if (rx_align_2)
1530 cmd.l2_802_3_offload_ctrl |=
1531 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
1532
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001533 /* typical time for secure PCP is 840ms */
1534 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
1535 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
1536 if (rc)
1537 return rc;
1538
1539 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
1540
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001541 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001542 le32_to_cpu(evt.evt.status), vring->hwtail);
1543
1544 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
1545 rc = -EINVAL;
1546
1547 return rc;
1548}
1549
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001550int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001551{
1552 int rc;
1553 struct wmi_temp_sense_cmd cmd = {
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001554 .measure_baseband_en = cpu_to_le32(!!t_bb),
1555 .measure_rf_en = cpu_to_le32(!!t_rf),
1556 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001557 };
1558 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001559 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001560 struct wmi_temp_sense_done_event evt;
1561 } __packed reply;
1562
1563 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
1564 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
1565 if (rc)
1566 return rc;
1567
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001568 if (t_bb)
1569 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
1570 if (t_rf)
1571 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001572
1573 return 0;
1574}
1575
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001576int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac,
1577 u16 reason, bool full_disconnect, bool del_sta)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001578{
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001579 int rc;
1580 u16 reason_code;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001581 struct wmi_disconnect_sta_cmd disc_sta_cmd = {
1582 .disconnect_reason = cpu_to_le16(reason),
1583 };
1584 struct wmi_del_sta_cmd del_sta_cmd = {
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001585 .disconnect_reason = cpu_to_le16(reason),
1586 };
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001587 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001588 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001589 struct wmi_disconnect_event evt;
1590 } __packed reply;
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001591
Lazar Alexei3190cc62017-02-23 14:34:14 +02001592 wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001593
Dedy Lansky0a4e9d12017-03-27 21:21:31 +03001594 wil->locally_generated_disc = true;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001595 if (del_sta) {
1596 ether_addr_copy(del_sta_cmd.dst_mac, mac);
1597 rc = wmi_call(wil, WMI_DEL_STA_CMDID, &del_sta_cmd,
1598 sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
1599 &reply, sizeof(reply), 1000);
1600 } else {
1601 ether_addr_copy(disc_sta_cmd.dst_mac, mac);
1602 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &disc_sta_cmd,
1603 sizeof(disc_sta_cmd), WMI_DISCONNECT_EVENTID,
1604 &reply, sizeof(reply), 1000);
1605 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001606 /* failure to disconnect in reasonable time treated as FW error */
1607 if (rc) {
1608 wil_fw_error_recovery(wil);
1609 return rc;
1610 }
1611
Maya Erez0916d9f2016-01-17 12:39:10 +02001612 if (full_disconnect) {
1613 /* call event handler manually after processing wmi_call,
1614 * to avoid deadlock - disconnect event handler acquires
1615 * wil->mutex while it is already held here
1616 */
1617 reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001618
Maya Erez0916d9f2016-01-17 12:39:10 +02001619 wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1620 reply.evt.bssid, reason_code,
1621 reply.evt.disconnect_reason);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001622
Maya Erez0916d9f2016-01-17 12:39:10 +02001623 wil->sinfo_gen++;
1624 wil6210_disconnect(wil, reply.evt.bssid, reason_code, true);
1625 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001626 return 0;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001627}
1628
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001629int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout)
1630{
1631 struct wmi_vring_ba_en_cmd cmd = {
1632 .ringid = ringid,
1633 .agg_max_wsize = size,
1634 .ba_timeout = cpu_to_le16(timeout),
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +02001635 .amsdu = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001636 };
1637
Lazar Alexei3190cc62017-02-23 14:34:14 +02001638 wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size,
1639 timeout);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001640
1641 return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd));
1642}
1643
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001644int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason)
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001645{
1646 struct wmi_vring_ba_dis_cmd cmd = {
1647 .ringid = ringid,
1648 .reason = cpu_to_le16(reason),
1649 };
1650
Lazar Alexei3190cc62017-02-23 14:34:14 +02001651 wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001652
1653 return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd));
1654}
1655
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001656int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason)
1657{
1658 struct wmi_rcp_delba_cmd cmd = {
1659 .cidxtid = cidxtid,
1660 .reason = cpu_to_le16(reason),
1661 };
1662
Lazar Alexei3190cc62017-02-23 14:34:14 +02001663 wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf,
1664 (cidxtid >> 4) & 0xf, reason);
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001665
1666 return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd));
1667}
1668
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001669int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
1670 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
1671{
1672 int rc;
1673 struct wmi_rcp_addba_resp_cmd cmd = {
1674 .cidxtid = mk_cidxtid(cid, tid),
1675 .dialog_token = token,
1676 .status_code = cpu_to_le16(status),
1677 /* bit 0: A-MSDU supported
1678 * bit 1: policy (should be 0 for us)
1679 * bits 2..5: TID
1680 * bits 6..15: buffer size
1681 */
1682 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
1683 (agg_wsize << 6)),
1684 .ba_timeout = cpu_to_le16(timeout),
1685 };
1686 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001687 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001688 struct wmi_rcp_addba_resp_sent_event evt;
1689 } __packed reply;
1690
1691 wil_dbg_wmi(wil,
1692 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
1693 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-");
1694
1695 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001696 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
1697 100);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001698 if (rc)
1699 return rc;
1700
1701 if (reply.evt.status) {
1702 wil_err(wil, "ADDBA response failed with status %d\n",
1703 le16_to_cpu(reply.evt.status));
1704 rc = -EINVAL;
1705 }
1706
1707 return rc;
1708}
1709
Maya Ereze77727f2016-12-06 12:21:17 +02001710int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
1711 enum wmi_ps_profile_type ps_profile)
1712{
1713 int rc;
1714 struct wmi_ps_dev_profile_cfg_cmd cmd = {
1715 .ps_profile = ps_profile,
1716 };
1717 struct {
1718 struct wmi_cmd_hdr wmi;
1719 struct wmi_ps_dev_profile_cfg_event evt;
1720 } __packed reply;
1721 u32 status;
1722
1723 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
1724
1725 reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR);
1726
1727 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd),
1728 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
1729 100);
1730 if (rc)
1731 return rc;
1732
1733 status = le32_to_cpu(reply.evt.status);
1734
1735 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
1736 wil_err(wil, "ps dev profile cfg failed with status %d\n",
1737 status);
1738 rc = -EINVAL;
1739 }
1740
1741 return rc;
1742}
1743
Lior Davidde21eba2017-02-15 20:33:10 +02001744int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
1745{
1746 int rc;
1747 struct wmi_set_mgmt_retry_limit_cmd cmd = {
1748 .mgmt_retry_limit = retry_short,
1749 };
1750 struct {
1751 struct wmi_cmd_hdr wmi;
1752 struct wmi_set_mgmt_retry_limit_event evt;
1753 } __packed reply;
1754
1755 wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
1756
1757 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1758 return -ENOTSUPP;
1759
1760 reply.evt.status = WMI_FW_STATUS_FAILURE;
1761
1762 rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd),
1763 WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1764 100);
1765 if (rc)
1766 return rc;
1767
1768 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1769 wil_err(wil, "set mgmt retry limit failed with status %d\n",
1770 reply.evt.status);
1771 rc = -EINVAL;
1772 }
1773
1774 return rc;
1775}
1776
1777int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
1778{
1779 int rc;
1780 struct {
1781 struct wmi_cmd_hdr wmi;
1782 struct wmi_get_mgmt_retry_limit_event evt;
1783 } __packed reply;
1784
1785 wil_dbg_wmi(wil, "getting mgmt retry short\n");
1786
1787 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1788 return -ENOTSUPP;
1789
1790 reply.evt.mgmt_retry_limit = 0;
1791 rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0,
1792 WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1793 100);
1794 if (rc)
1795 return rc;
1796
1797 if (retry_short)
1798 *retry_short = reply.evt.mgmt_retry_limit;
1799
1800 return 0;
1801}
1802
Maya Erez4cbb5852017-02-16 15:26:09 +02001803int wmi_abort_scan(struct wil6210_priv *wil)
1804{
1805 int rc;
1806
1807 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
1808
1809 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0);
1810 if (rc)
1811 wil_err(wil, "Failed to abort scan (%d)\n", rc);
1812
1813 return rc;
1814}
1815
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001816int wmi_new_sta(struct wil6210_priv *wil, const u8 *mac, u8 aid)
1817{
1818 int rc;
1819 struct wmi_new_sta_cmd cmd = {
1820 .aid = aid,
1821 };
1822
1823 wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
1824
1825 ether_addr_copy(cmd.dst_mac, mac);
1826
1827 rc = wmi_send(wil, WMI_NEW_STA_CMDID, &cmd, sizeof(cmd));
1828 if (rc)
1829 wil_err(wil, "Failed to send new sta (%d)\n", rc);
1830
1831 return rc;
1832}
1833
Dedy Lansky1b752712017-03-20 15:35:51 +02001834int wmi_set_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data)
1835{
1836 int rc;
1837 struct wmi_set_thermal_throttling_cfg_cmd cmd = {
1838 .tt_data = *tt_data,
1839 };
1840 struct {
1841 struct wmi_cmd_hdr wmi;
1842 struct wmi_set_thermal_throttling_cfg_event evt;
1843 } __packed reply;
1844
1845 if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING,
1846 wil->fw_capabilities))
1847 return -EOPNOTSUPP;
1848
1849 memset(&reply, 0, sizeof(reply));
1850 rc = wmi_call(wil, WMI_SET_THERMAL_THROTTLING_CFG_CMDID, &cmd,
1851 sizeof(cmd), WMI_SET_THERMAL_THROTTLING_CFG_EVENTID,
1852 &reply, sizeof(reply), 100);
1853 if (rc) {
1854 wil_err(wil, "failed to set thermal throttling\n");
1855 return rc;
1856 }
1857 if (reply.evt.status) {
1858 wil_err(wil, "set thermal throttling failed, error %d\n",
1859 reply.evt.status);
1860 return -EIO;
1861 }
1862
1863 wil->tt_data = *tt_data;
1864 wil->tt_data_set = true;
1865
1866 return 0;
1867}
1868
1869int wmi_get_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data)
1870{
1871 int rc;
1872 struct {
1873 struct wmi_cmd_hdr wmi;
1874 struct wmi_get_thermal_throttling_cfg_event evt;
1875 } __packed reply;
1876
1877 if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING,
1878 wil->fw_capabilities))
1879 return -EOPNOTSUPP;
1880
1881 rc = wmi_call(wil, WMI_GET_THERMAL_THROTTLING_CFG_CMDID, NULL, 0,
1882 WMI_GET_THERMAL_THROTTLING_CFG_EVENTID, &reply,
1883 sizeof(reply), 100);
1884 if (rc) {
1885 wil_err(wil, "failed to get thermal throttling\n");
1886 return rc;
1887 }
1888
1889 if (tt_data)
1890 *tt_data = reply.evt.tt_data;
1891
1892 return 0;
1893}
1894
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001895void wmi_event_flush(struct wil6210_priv *wil)
1896{
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001897 ulong flags;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001898 struct pending_wmi_event *evt, *t;
1899
Lazar Alexei3190cc62017-02-23 14:34:14 +02001900 wil_dbg_wmi(wil, "event_flush\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001901
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001902 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1903
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001904 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
1905 list_del(&evt->list);
1906 kfree(evt);
1907 }
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001908
1909 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001910}
1911
Hamad Kadmany105dd0f2017-04-04 15:14:17 +03001912int wmi_link_maintain_cfg_write(struct wil6210_priv *wil,
1913 const u8 *addr,
1914 bool fst_link_loss)
1915{
1916 int rc;
1917 int cid = wil_find_cid(wil, addr);
1918 u32 cfg_type;
1919 struct wmi_link_maintain_cfg_write_cmd cmd;
1920 struct {
1921 struct wmi_cmd_hdr wmi;
1922 struct wmi_link_maintain_cfg_write_done_event evt;
1923 } __packed reply;
1924
1925 if (cid < 0)
1926 return cid;
1927
1928 switch (wil->wdev->iftype) {
1929 case NL80211_IFTYPE_STATION:
1930 cfg_type = fst_link_loss ?
1931 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_FST_STA :
1932 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_NORMAL_STA;
1933 break;
1934 case NL80211_IFTYPE_AP:
1935 cfg_type = fst_link_loss ?
1936 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_FST_AP :
1937 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_NORMAL_AP;
1938 break;
1939 default:
1940 wil_err(wil, "Unsupported for iftype %d", wil->wdev->iftype);
1941 return -EINVAL;
1942 }
1943
1944 wil_dbg_misc(wil, "Setting cid:%d with cfg_type:%d\n", cid, cfg_type);
1945
1946 cmd.cfg_type = cpu_to_le32(cfg_type);
1947 cmd.cid = cpu_to_le32(cid);
1948
1949 reply.evt.status = cpu_to_le32(WMI_FW_STATUS_FAILURE);
1950
1951 rc = wmi_call(wil, WMI_LINK_MAINTAIN_CFG_WRITE_CMDID, &cmd, sizeof(cmd),
1952 WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENTID, &reply,
1953 sizeof(reply), 250);
1954 if (rc) {
1955 wil_err(wil, "Failed to %s FST link loss",
1956 fst_link_loss ? "enable" : "disable");
1957 } else if (reply.evt.status == WMI_FW_STATUS_SUCCESS) {
1958 wil->sta[cid].fst_link_loss = fst_link_loss;
1959 } else {
1960 wil_err(wil, "WMI_LINK_MAINTAIN_CFG_WRITE_CMDID returned status %d",
1961 reply.evt.status);
1962 rc = -EINVAL;
1963 }
1964 return rc;
1965}
1966
Maya Ereze3309bf2017-05-15 16:57:46 +03001967int wmi_suspend(struct wil6210_priv *wil)
1968{
1969 int rc;
1970 struct wmi_traffic_suspend_cmd cmd = {
1971 .wakeup_trigger = wil->wakeup_trigger,
1972 };
1973 struct {
1974 struct wmi_cmd_hdr wmi;
1975 struct wmi_traffic_suspend_event evt;
1976 } __packed reply;
1977 u32 suspend_to = WIL_WAIT_FOR_SUSPEND_RESUME_COMP;
1978
1979 wil->suspend_resp_rcvd = false;
1980 wil->suspend_resp_comp = false;
1981
1982 reply.evt.status = WMI_TRAFFIC_SUSPEND_REJECTED;
1983
1984 rc = wmi_call(wil, WMI_TRAFFIC_SUSPEND_CMDID, &cmd, sizeof(cmd),
1985 WMI_TRAFFIC_SUSPEND_EVENTID, &reply, sizeof(reply),
1986 suspend_to);
1987 if (rc) {
1988 wil_err(wil, "wmi_call for suspend req failed, rc=%d\n", rc);
1989 if (rc == -ETIME)
1990 /* wmi_call TO */
1991 wil->suspend_stats.rejected_by_device++;
1992 else
1993 wil->suspend_stats.rejected_by_host++;
1994 goto out;
1995 }
1996
1997 wil_dbg_wmi(wil, "waiting for suspend_response_completed\n");
1998
1999 rc = wait_event_interruptible_timeout(wil->wq,
2000 wil->suspend_resp_comp,
2001 msecs_to_jiffies(suspend_to));
2002 if (rc == 0) {
2003 wil_err(wil, "TO waiting for suspend_response_completed\n");
2004 if (wil->suspend_resp_rcvd)
2005 /* Device responded but we TO due to another reason */
2006 wil->suspend_stats.rejected_by_host++;
2007 else
2008 wil->suspend_stats.rejected_by_device++;
2009 rc = -EBUSY;
2010 goto out;
2011 }
2012
2013 wil_dbg_wmi(wil, "suspend_response_completed rcvd\n");
2014 if (reply.evt.status == WMI_TRAFFIC_SUSPEND_REJECTED) {
2015 wil_dbg_pm(wil, "device rejected the suspend\n");
2016 wil->suspend_stats.rejected_by_device++;
2017 }
2018 rc = reply.evt.status;
2019
2020out:
2021 wil->suspend_resp_rcvd = false;
2022 wil->suspend_resp_comp = false;
2023
2024 return rc;
2025}
2026
2027int wmi_resume(struct wil6210_priv *wil)
2028{
2029 int rc;
2030 struct {
2031 struct wmi_cmd_hdr wmi;
2032 struct wmi_traffic_resume_event evt;
2033 } __packed reply;
2034
2035 reply.evt.status = WMI_TRAFFIC_RESUME_FAILED;
2036
2037 rc = wmi_call(wil, WMI_TRAFFIC_RESUME_CMDID, NULL, 0,
2038 WMI_TRAFFIC_RESUME_EVENTID, &reply, sizeof(reply),
2039 WIL_WAIT_FOR_SUSPEND_RESUME_COMP);
2040 if (rc)
2041 return rc;
2042
2043 return reply.evt.status;
2044}
2045
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002046static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
2047 void *d, int len)
2048{
2049 uint i;
2050
2051 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
2052 if (wmi_evt_handlers[i].eventid == id) {
2053 wmi_evt_handlers[i].handler(wil, id, d, len);
2054 return true;
2055 }
2056 }
2057
2058 return false;
2059}
2060
2061static void wmi_event_handle(struct wil6210_priv *wil,
2062 struct wil6210_mbox_hdr *hdr)
2063{
2064 u16 len = le16_to_cpu(hdr->len);
2065
2066 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +02002067 (len >= sizeof(struct wmi_cmd_hdr))) {
2068 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002069 void *evt_data = (void *)(&wmi[1]);
Lior Davidb874dde2016-03-01 19:18:09 +02002070 u16 id = le16_to_cpu(wmi->command_id);
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03002071
2072 wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n",
2073 id, wil->reply_id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002074 /* check if someone waits for this event */
2075 if (wil->reply_id && wil->reply_id == id) {
Maya Erez0916d9f2016-01-17 12:39:10 +02002076 WARN_ON(wil->reply_buf);
2077 wmi_evt_call_handler(wil, id, evt_data,
2078 len - sizeof(*wmi));
Lazar Alexei3190cc62017-02-23 14:34:14 +02002079 wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
2080 id);
Dedy Lansky59502642014-09-10 16:34:46 +03002081 complete(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002082 return;
2083 }
2084 /* unsolicited event */
2085 /* search for handler */
2086 if (!wmi_evt_call_handler(wil, id, evt_data,
2087 len - sizeof(*wmi))) {
Dedy Lanskya3ce5ccd2015-07-30 13:51:58 +03002088 wil_info(wil, "Unhandled event 0x%04x\n", id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002089 }
2090 } else {
2091 wil_err(wil, "Unknown event type\n");
2092 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
2093 hdr, sizeof(*hdr) + len, true);
2094 }
2095}
2096
2097/*
2098 * Retrieve next WMI event from the pending list
2099 */
2100static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
2101{
2102 ulong flags;
2103 struct list_head *ret = NULL;
2104
2105 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2106
2107 if (!list_empty(&wil->pending_wmi_ev)) {
2108 ret = wil->pending_wmi_ev.next;
2109 list_del(ret);
2110 }
2111
2112 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2113
2114 return ret;
2115}
2116
2117/*
2118 * Handler for the WMI events
2119 */
2120void wmi_event_worker(struct work_struct *work)
2121{
2122 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
2123 wmi_event_worker);
2124 struct pending_wmi_event *evt;
2125 struct list_head *lh;
2126
Lazar Alexei3190cc62017-02-23 14:34:14 +02002127 wil_dbg_wmi(wil, "event_worker: Start\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002128 while ((lh = next_wmi_ev(wil)) != NULL) {
2129 evt = list_entry(lh, struct pending_wmi_event, list);
2130 wmi_event_handle(wil, &evt->event.hdr);
2131 kfree(evt);
2132 }
Lazar Alexei3190cc62017-02-23 14:34:14 +02002133 wil_dbg_wmi(wil, "event_worker: Finished\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002134}
Maya Ereze3309bf2017-05-15 16:57:46 +03002135
2136bool wil_is_wmi_idle(struct wil6210_priv *wil)
2137{
2138 ulong flags;
2139 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
2140 bool rc = false;
2141
2142 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2143
2144 /* Check if there are pending WMI events in the events queue */
2145 if (!list_empty(&wil->pending_wmi_ev)) {
2146 wil_dbg_pm(wil, "Pending WMI events in queue\n");
2147 goto out;
2148 }
2149
2150 /* Check if there is a pending WMI call */
2151 if (wil->reply_id) {
2152 wil_dbg_pm(wil, "Pending WMI call\n");
2153 goto out;
2154 }
2155
2156 /* Check if there are pending RX events in mbox */
2157 r->head = wil_r(wil, RGF_MBOX +
2158 offsetof(struct wil6210_mbox_ctl, rx.head));
2159 if (r->tail != r->head)
2160 wil_dbg_pm(wil, "Pending WMI mbox events\n");
2161 else
2162 rc = true;
2163
2164out:
2165 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2166 return rc;
2167}