blob: dc1b30c57192c9b0eb278c30516334e846c685c3 [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
144 *
145 * Valid buffer should be DWORD aligned
146 *
147 * return address for accessing buffer from the host;
148 * if buffer is not valid, return NULL.
149 */
150void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
151{
152 u32 off;
153 u32 ptr = le32_to_cpu(ptr_);
154
155 if (ptr % 4)
156 return NULL;
157
158 ptr = wmi_addr_remap(ptr);
159 if (ptr < WIL6210_FW_HOST_OFF)
160 return NULL;
161
162 off = HOSTADDR(ptr);
Maya Erezd5361f62017-05-25 18:43:36 +0300163 if (off > wil->bar_size - 4)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800164 return NULL;
165
166 return wil->csr + off;
167}
168
169/**
170 * Check address validity
171 */
172void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
173{
174 u32 off;
175
176 if (ptr % 4)
177 return NULL;
178
179 if (ptr < WIL6210_FW_HOST_OFF)
180 return NULL;
181
182 off = HOSTADDR(ptr);
Maya Erezd5361f62017-05-25 18:43:36 +0300183 if (off > wil->bar_size - 4)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800184 return NULL;
185
186 return wil->csr + off;
187}
188
189int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
190 struct wil6210_mbox_hdr *hdr)
191{
192 void __iomem *src = wmi_buffer(wil, ptr);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300193
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800194 if (!src)
195 return -EINVAL;
196
197 wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
198
199 return 0;
200}
201
202static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
203{
204 struct {
205 struct wil6210_mbox_hdr hdr;
Lior Davidb874dde2016-03-01 19:18:09 +0200206 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800207 } __packed cmd = {
208 .hdr = {
209 .type = WIL_MBOX_HDR_TYPE_WMI,
210 .flags = 0,
211 .len = cpu_to_le16(sizeof(cmd.wmi) + len),
212 },
213 .wmi = {
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300214 .mid = 0,
Lior Davidb874dde2016-03-01 19:18:09 +0200215 .command_id = cpu_to_le16(cmdid),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800216 },
217 };
218 struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
219 struct wil6210_mbox_ring_desc d_head;
220 u32 next_head;
221 void __iomem *dst;
222 void __iomem *head = wmi_addr(wil, r->head);
223 uint retry;
Maya Erez349214c2016-04-26 14:41:41 +0300224 int rc = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800225
226 if (sizeof(cmd) + len > r->entry_size) {
227 wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
228 (int)(sizeof(cmd) + len), r->entry_size);
229 return -ERANGE;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800230 }
231
232 might_sleep();
233
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200234 if (!test_bit(wil_status_fwready, wil->status)) {
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300235 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800236 return -EAGAIN;
237 }
238
Maya Ereze3309bf2017-05-15 16:57:46 +0300239 /* Allow sending only suspend / resume commands during susepnd flow */
240 if ((test_bit(wil_status_suspending, wil->status) ||
241 test_bit(wil_status_suspended, wil->status) ||
242 test_bit(wil_status_resuming, wil->status)) &&
243 ((cmdid != WMI_TRAFFIC_SUSPEND_CMDID) &&
244 (cmdid != WMI_TRAFFIC_RESUME_CMDID))) {
245 wil_err(wil, "WMI: reject send_command during suspend\n");
246 return -EINVAL;
247 }
248
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800249 if (!head) {
250 wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
251 return -EINVAL;
252 }
Maya Erez349214c2016-04-26 14:41:41 +0300253
254 wil_halp_vote(wil);
255
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800256 /* read Tx head till it is not busy */
257 for (retry = 5; retry > 0; retry--) {
258 wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
259 if (d_head.sync == 0)
260 break;
261 msleep(20);
262 }
263 if (d_head.sync != 0) {
264 wil_err(wil, "WMI head busy\n");
Maya Erez349214c2016-04-26 14:41:41 +0300265 rc = -EBUSY;
266 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800267 }
268 /* next head */
269 next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200270 wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800271 /* wait till FW finish with previous command */
272 for (retry = 5; retry > 0; retry--) {
Maya Erez452133a2015-11-24 09:30:15 +0200273 if (!test_bit(wil_status_fwready, wil->status)) {
274 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Maya Erez349214c2016-04-26 14:41:41 +0300275 rc = -EAGAIN;
276 goto out;
Maya Erez452133a2015-11-24 09:30:15 +0200277 }
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300278 r->tail = wil_r(wil, RGF_MBOX +
279 offsetof(struct wil6210_mbox_ctl, tx.tail));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800280 if (next_head != r->tail)
281 break;
282 msleep(20);
283 }
284 if (next_head == r->tail) {
285 wil_err(wil, "WMI ring full\n");
Maya Erez349214c2016-04-26 14:41:41 +0300286 rc = -EBUSY;
287 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800288 }
289 dst = wmi_buffer(wil, d_head.addr);
290 if (!dst) {
291 wil_err(wil, "invalid WMI buffer: 0x%08x\n",
292 le32_to_cpu(d_head.addr));
Maya Erez349214c2016-04-26 14:41:41 +0300293 rc = -EAGAIN;
294 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800295 }
296 cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
297 /* set command */
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200298 wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len);
299 wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800300 sizeof(cmd), true);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200301 wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800302 len, true);
303 wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
304 wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
305 /* mark entry as full */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300306 wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800307 /* advance next ptr */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300308 wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
309 r->head = next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800310
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300311 trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
Vladimir Kondratiev98658092013-05-12 14:43:35 +0300312
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800313 /* interrupt to FW */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300314 wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
315 SW_INT_MBOX);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800316
Maya Erez349214c2016-04-26 14:41:41 +0300317out:
318 wil_halp_unvote(wil);
319 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800320}
321
322int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
323{
324 int rc;
325
326 mutex_lock(&wil->wmi_mutex);
327 rc = __wmi_send(wil, cmdid, buf, len);
328 mutex_unlock(&wil->wmi_mutex);
329
330 return rc;
331}
332
333/*=== Event handlers ===*/
334static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len)
335{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800336 struct wireless_dev *wdev = wil->wdev;
337 struct wmi_ready_event *evt = d;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300338
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200339 wil->n_mids = evt->numof_additional_mids;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800340
Lior David13cd9f72016-08-22 12:42:22 +0300341 wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
342 wil->fw_version, le32_to_cpu(evt->sw_version),
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300343 evt->mac, wil->n_mids);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200344 /* ignore MAC address, we already have it from the boot loader */
Lior David13cd9f72016-08-22 12:42:22 +0300345 strlcpy(wdev->wiphy->fw_version, wil->fw_version,
346 sizeof(wdev->wiphy->fw_version));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800347
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300348 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200349 set_bit(wil_status_fwready, wil->status);
Dedy Lansky59502642014-09-10 16:34:46 +0300350 /* let the reset sequence continue */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800351 complete(&wil->wmi_ready);
352}
353
354static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
355{
356 struct wmi_rx_mgmt_packet_event *data = d;
357 struct wiphy *wiphy = wil_to_wiphy(wil);
358 struct ieee80211_mgmt *rx_mgmt_frame =
359 (struct ieee80211_mgmt *)data->payload;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300360 int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
361 int ch_no;
362 u32 freq;
363 struct ieee80211_channel *channel;
364 s32 signal;
365 __le16 fc;
366 u32 d_len;
367 u16 d_status;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800368
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300369 if (flen < 0) {
370 wil_err(wil, "MGMT Rx: short event, len %d\n", len);
371 return;
372 }
373
374 d_len = le32_to_cpu(data->info.len);
375 if (d_len != flen) {
376 wil_err(wil,
377 "MGMT Rx: length mismatch, d_len %d should be %d\n",
378 d_len, flen);
379 return;
380 }
381
382 ch_no = data->info.channel + 1;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200383 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300384 channel = ieee80211_get_channel(wiphy, freq);
Dedy Lanskyb3f87382017-08-21 22:58:54 +0300385 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
386 signal = 100 * data->info.rssi;
387 else
388 signal = data->info.sqi;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300389 d_status = le16_to_cpu(data->info.status);
390 fc = rx_mgmt_frame->frame_control;
391
Dedy Lanskyb3f87382017-08-21 22:58:54 +0300392 wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d RSSI %d SQI %d%%\n",
393 data->info.channel, data->info.mcs, data->info.rssi,
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200394 data->info.sqi);
Vladimir Kondratievf27dbf72013-06-09 09:12:52 +0300395 wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
396 le16_to_cpu(fc));
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200397 wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800398 data->info.qid, data->info.mid, data->info.cid);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300399 wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
400 d_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800401
402 if (!channel) {
403 wil_err(wil, "Frame on unsupported channel\n");
404 return;
405 }
406
407 if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
408 struct cfg80211_bss *bss;
Vladimir Kondratiev8eea9442014-06-16 19:37:03 +0300409 u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
410 u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
411 u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
412 const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
413 size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
414 u.beacon.variable);
415 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
416 wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
417 wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
418 wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
419 ie_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800420
Dedy Lanskye6d68342016-03-01 19:18:12 +0200421 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
422
Vladimir Kondratieva0f78452013-03-13 14:12:44 +0200423 bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
424 d_len, signal, GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800425 if (bss) {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200426 wil_dbg_wmi(wil, "Added BSS %pM\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800427 rx_mgmt_frame->bssid);
Johannes Berg5b112d32013-02-01 01:49:58 +0100428 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800429 } else {
Johannes Berg5bc8c1f2014-08-12 21:01:28 +0200430 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800431 }
Vladimir Kondratiev102b1d92013-03-13 14:12:45 +0200432 } else {
Lior David4332cac2016-03-01 19:18:13 +0200433 mutex_lock(&wil->p2p_wdev_mutex);
434 cfg80211_rx_mgmt(wil->radio_wdev, freq, signal,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700435 (void *)rx_mgmt_frame, d_len, 0);
Lior David4332cac2016-03-01 19:18:13 +0200436 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800437 }
438}
439
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300440static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
441{
442 struct wmi_tx_mgmt_packet_event *data = d;
443 struct ieee80211_mgmt *mgmt_frame =
444 (struct ieee80211_mgmt *)data->payload;
445 int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
446
447 wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
448 flen, true);
449}
450
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800451static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
452 void *d, int len)
453{
Lior David5ffae432016-08-22 12:42:19 +0300454 mutex_lock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800455 if (wil->scan_request) {
456 struct wmi_scan_complete_event *data = d;
Maya Erez4cbb5852017-02-16 15:26:09 +0200457 int status = le32_to_cpu(data->status);
Avraham Stern1d762502016-07-05 17:10:13 +0300458 struct cfg80211_scan_info info = {
Maya Erez4cbb5852017-02-16 15:26:09 +0200459 .aborted = ((status != WMI_SCAN_SUCCESS) &&
460 (status != WMI_SCAN_ABORT_REJECTED)),
Avraham Stern1d762502016-07-05 17:10:13 +0300461 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800462
Maya Erez4cbb5852017-02-16 15:26:09 +0200463 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300464 wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
Avraham Stern1d762502016-07-05 17:10:13 +0300465 wil->scan_request, info.aborted);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300466 del_timer_sync(&wil->scan_timer);
Avraham Stern1d762502016-07-05 17:10:13 +0300467 cfg80211_scan_done(wil->scan_request, &info);
Lior David4332cac2016-03-01 19:18:13 +0200468 wil->radio_wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800469 wil->scan_request = NULL;
Maya Erez4cbb5852017-02-16 15:26:09 +0200470 wake_up_interruptible(&wil->wq);
Lior David42ba1c222017-02-15 20:37:20 +0200471 if (wil->p2p.pending_listen_wdev) {
472 wil_dbg_misc(wil, "Scheduling delayed listen\n");
473 schedule_work(&wil->p2p.delayed_listen_work);
474 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800475 } else {
476 wil_err(wil, "SCAN_COMPLETE while not scanning\n");
477 }
Lior David5ffae432016-08-22 12:42:19 +0300478 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800479}
480
481static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len)
482{
483 struct net_device *ndev = wil_to_ndev(wil);
484 struct wireless_dev *wdev = wil->wdev;
485 struct wmi_connect_event *evt = d;
486 int ch; /* channel number */
487 struct station_info sinfo;
488 u8 *assoc_req_ie, *assoc_resp_ie;
489 size_t assoc_req_ielen, assoc_resp_ielen;
490 /* capinfo(u16) + listen_interval(u16) + IEs */
491 const size_t assoc_req_ie_offset = sizeof(u16) * 2;
492 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
493 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
Maya Erez0916d9f2016-01-17 12:39:10 +0200494 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800495
496 if (len < sizeof(*evt)) {
497 wil_err(wil, "Connect event too short : %d bytes\n", len);
498 return;
499 }
500 if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
501 evt->assoc_resp_len) {
502 wil_err(wil,
503 "Connect event corrupted : %d != %d + %d + %d + %d\n",
504 len, (int)sizeof(*evt), evt->beacon_ie_len,
505 evt->assoc_req_len, evt->assoc_resp_len);
506 return;
507 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200508 if (evt->cid >= WIL6210_MAX_CID) {
509 wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
510 return;
511 }
512
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800513 ch = evt->channel + 1;
Lior Davida7629792017-02-08 13:16:37 +0200514 wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n",
515 evt->bssid, ch, evt->cid, evt->aid);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200516 wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800517 evt->assoc_info, len - sizeof(*evt), true);
518
519 /* figure out IE's */
520 assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
521 assoc_req_ie_offset];
522 assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
523 if (evt->assoc_req_len <= assoc_req_ie_offset) {
524 assoc_req_ie = NULL;
525 assoc_req_ielen = 0;
526 }
527
528 assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
529 evt->assoc_req_len +
530 assoc_resp_ie_offset];
531 assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
532 if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
533 assoc_resp_ie = NULL;
534 assoc_resp_ielen = 0;
535 }
536
Maya Erez0916d9f2016-01-17 12:39:10 +0200537 if (test_bit(wil_status_resetting, wil->status) ||
538 !test_bit(wil_status_fwready, wil->status)) {
539 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
540 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200541 /* no need for cleanup, wil_reset will do that */
542 return;
543 }
544
Hamad Kadmany0e2f6e32017-04-13 14:38:20 +0300545 mutex_lock(&wil->mutex);
546
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800547 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
548 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200549 if (!test_bit(wil_status_fwconnecting, wil->status)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800550 wil_err(wil, "Not in connecting state\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200551 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800552 return;
553 }
554 del_timer_sync(&wil->connect_timer);
Maya Erez3d287fb2016-03-01 19:18:05 +0200555 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
556 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
557 if (wil->sta[evt->cid].status != wil_sta_unused) {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200558 wil_err(wil, "AP: Invalid status %d for CID %d\n",
559 wil->sta[evt->cid].status, evt->cid);
Maya Erez3d287fb2016-03-01 19:18:05 +0200560 mutex_unlock(&wil->mutex);
561 return;
562 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200563 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800564
Maya Erez0916d9f2016-01-17 12:39:10 +0200565 /* FIXME FW can transmit only ucast frames to peer */
566 /* FIXME real ring_id instead of hard coded 0 */
567 ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
568 wil->sta[evt->cid].status = wil_sta_conn_pending;
569
570 rc = wil_tx_init(wil, evt->cid);
571 if (rc) {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200572 wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n",
573 evt->cid, rc);
Maya Erez0916d9f2016-01-17 12:39:10 +0200574 wmi_disconnect_sta(wil, wil->sta[evt->cid].addr,
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200575 WLAN_REASON_UNSPECIFIED, false, false);
Maya Erez0916d9f2016-01-17 12:39:10 +0200576 } else {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200577 wil_info(wil, "successful connection to CID %d\n", evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200578 }
579
580 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
581 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
582 if (rc) {
Maya Erez0916d9f2016-01-17 12:39:10 +0200583 netif_carrier_off(ndev);
Lior David704099f2017-05-04 21:31:02 +0300584 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
Lazar Alexei3190cc62017-02-23 14:34:14 +0200585 wil_err(wil, "cfg80211_connect_result with failure\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200586 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
587 NULL, 0,
588 WLAN_STATUS_UNSPECIFIED_FAILURE,
589 GFP_KERNEL);
590 goto out;
591 } else {
Dedy Lanskya4882782017-05-04 21:36:09 +0300592 struct wiphy *wiphy = wil_to_wiphy(wil);
593
594 cfg80211_ref_bss(wiphy, wil->bss);
595 cfg80211_connect_bss(ndev, evt->bssid, wil->bss,
596 assoc_req_ie, assoc_req_ielen,
597 assoc_resp_ie, assoc_resp_ielen,
Purushottam Kushwahadf935062017-01-13 01:12:21 +0200598 WLAN_STATUS_SUCCESS, GFP_KERNEL,
599 NL80211_TIMEOUT_UNSPECIFIED);
Maya Erez0916d9f2016-01-17 12:39:10 +0200600 }
Dedy Lanskya4882782017-05-04 21:36:09 +0300601 wil->bss = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800602 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
603 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200604 if (rc) {
605 if (disable_ap_sme)
606 /* notify new_sta has failed */
607 cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200608 goto out;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200609 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200610
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800611 memset(&sinfo, 0, sizeof(sinfo));
612
613 sinfo.generation = wil->sinfo_gen++;
614
615 if (assoc_req_ie) {
616 sinfo.assoc_req_ies = assoc_req_ie;
617 sinfo.assoc_req_ies_len = assoc_req_ielen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800618 }
619
620 cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200621 } else {
Lazar Alexei3190cc62017-02-23 14:34:14 +0200622 wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
623 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200624 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800625 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200626
627 wil->sta[evt->cid].status = wil_sta_connected;
Lior Davida7629792017-02-08 13:16:37 +0200628 wil->sta[evt->cid].aid = evt->aid;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200629 set_bit(wil_status_fwconnected, wil->status);
Dedy Lansky970a98f2016-12-06 08:26:49 +0200630 wil_update_net_queues_bh(wil, NULL, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800631
Maya Erez0916d9f2016-01-17 12:39:10 +0200632out:
633 if (rc)
634 wil->sta[evt->cid].status = wil_sta_unused;
635 clear_bit(wil_status_fwconnecting, wil->status);
636 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800637}
638
639static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
640 void *d, int len)
641{
642 struct wmi_disconnect_event *evt = d;
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200643 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800644
Maya Erez0916d9f2016-01-17 12:39:10 +0200645 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
646 evt->bssid, reason_code, evt->disconnect_reason);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800647
648 wil->sinfo_gen++;
649
Hamad Kadmany0e2f6e32017-04-13 14:38:20 +0300650 if (test_bit(wil_status_resetting, wil->status) ||
651 !test_bit(wil_status_fwready, wil->status)) {
652 wil_err(wil, "status_resetting, cancel disconnect event\n");
653 /* no need for cleanup, wil_reset will do that */
654 return;
655 }
656
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200657 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200658 wil6210_disconnect(wil, evt->bssid, reason_code, true);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200659 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800660}
661
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800662/*
663 * Firmware reports EAPOL frame using WME event.
664 * Reconstruct Ethernet frame and deliver it via normal Rx
665 */
666static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
667 void *d, int len)
668{
669 struct net_device *ndev = wil_to_ndev(wil);
670 struct wmi_eapol_rx_event *evt = d;
671 u16 eapol_len = le16_to_cpu(evt->eapol_len);
672 int sz = eapol_len + ETH_HLEN;
673 struct sk_buff *skb;
674 struct ethhdr *eth;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200675 int cid;
676 struct wil_net_stats *stats = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800677
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200678 wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800679 evt->src_mac);
680
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200681 cid = wil_find_cid(wil, evt->src_mac);
682 if (cid >= 0)
683 stats = &wil->sta[cid].stats;
684
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800685 if (eapol_len > 196) { /* TODO: revisit size limit */
686 wil_err(wil, "EAPOL too large\n");
687 return;
688 }
689
690 skb = alloc_skb(sz, GFP_KERNEL);
691 if (!skb) {
692 wil_err(wil, "Failed to allocate skb\n");
693 return;
694 }
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200695
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800696 eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200697 ether_addr_copy(eth->h_dest, ndev->dev_addr);
698 ether_addr_copy(eth->h_source, evt->src_mac);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800699 eth->h_proto = cpu_to_be16(ETH_P_PAE);
700 memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len);
701 skb->protocol = eth_type_trans(skb, ndev);
702 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
703 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200704 ndev->stats.rx_bytes += sz;
705 if (stats) {
706 stats->rx_packets++;
707 stats->rx_bytes += sz;
708 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800709 } else {
710 ndev->stats.rx_dropped++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200711 if (stats)
712 stats->rx_dropped++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800713 }
714}
715
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300716static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200717{
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300718 struct wmi_vring_en_event *evt = d;
719 u8 vri = evt->vring_index;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200720 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200721
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300722 wil_dbg_wmi(wil, "Enable vring %d\n", vri);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200723
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300724 if (vri >= ARRAY_SIZE(wil->vring_tx)) {
725 wil_err(wil, "Enable for invalid vring %d\n", vri);
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200726 return;
727 }
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +0200728
729 if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme)
730 /* in AP mode with disable_ap_sme, this is done by
731 * wil_cfg80211_change_station()
732 */
733 wil->vring_tx_data[vri].dot1x_open = true;
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300734 if (vri == wil->bcast_vring) /* no BA for bcast */
735 return;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200736 if (agg_wsize >= 0)
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300737 wil_addba_tx_request(wil, vri, agg_wsize);
Vladimir Kondratiev3442a502013-03-13 14:12:39 +0200738}
739
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200740static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
741 int len)
742{
Lior Davidb874dde2016-03-01 19:18:09 +0200743 struct wmi_ba_status_event *evt = d;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200744 struct vring_tx_data *txdata;
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200745
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200746 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200747 evt->ringid,
748 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200749 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
750 evt->amsdu ? "+" : "-");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200751
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200752 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
753 wil_err(wil, "invalid ring id %d\n", evt->ringid);
754 return;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200755 }
756
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200757 if (evt->status != WMI_BA_AGREED) {
758 evt->ba_timeout = 0;
759 evt->agg_wsize = 0;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200760 evt->amsdu = 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200761 }
Dedy Lansky8c86f752014-09-10 16:34:40 +0300762
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200763 txdata = &wil->vring_tx_data[evt->ringid];
764
765 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
766 txdata->agg_wsize = evt->agg_wsize;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200767 txdata->agg_amsdu = evt->amsdu;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200768 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200769}
770
771static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d,
772 int len)
773{
774 struct wmi_rcp_addba_req_event *evt = d;
775
776 wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token,
777 evt->ba_param_set, evt->ba_timeout,
778 evt->ba_seq_ctrl);
779}
780
781static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200782__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200783{
784 struct wmi_delba_event *evt = d;
785 u8 cid, tid;
786 u16 reason = __le16_to_cpu(evt->reason);
787 struct wil_sta_info *sta;
788 struct wil_tid_ampdu_rx *r;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200789
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200790 might_sleep();
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200791 parse_cidxtid(evt->cidxtid, &cid, &tid);
792 wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n",
793 cid, tid,
794 evt->from_initiator ? "originator" : "recipient",
795 reason);
796 if (!evt->from_initiator) {
797 int i;
798 /* find Tx vring it belongs to */
799 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
800 if ((wil->vring2cid_tid[i][0] == cid) &&
801 (wil->vring2cid_tid[i][1] == tid)) {
802 struct vring_tx_data *txdata =
803 &wil->vring_tx_data[i];
804
805 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
806 txdata->agg_timeout = 0;
807 txdata->agg_wsize = 0;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200808 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200809
810 break; /* max. 1 matching ring */
811 }
812 }
813 if (i >= ARRAY_SIZE(wil->vring2cid_tid))
814 wil_err(wil, "DELBA: unable to find Tx vring\n");
815 return;
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200816 }
817
818 sta = &wil->sta[cid];
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200819
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200820 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300821
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200822 r = sta->tid_rx[tid];
823 sta->tid_rx[tid] = NULL;
824 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300825
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200826 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200827}
828
Lior David8f1b5e02017-02-28 14:58:27 +0200829static void wmi_evt_aoa_meas(struct wil6210_priv *wil, int id,
830 void *d, int len)
831{
832 struct wmi_aoa_meas_event *evt = d;
833
834 wil_aoa_evt_meas(wil, evt, len);
835}
836
837static void wmi_evt_ftm_session_ended(struct wil6210_priv *wil, int id,
838 void *d, int len)
839{
840 struct wmi_tof_session_end_event *evt = d;
841
842 wil_ftm_evt_session_ended(wil, evt);
843}
844
845static void wmi_evt_per_dest_res(struct wil6210_priv *wil, int id,
846 void *d, int len)
847{
848 struct wmi_tof_ftm_per_dest_res_event *evt = d;
849
850 wil_ftm_evt_per_dest_res(wil, evt);
851}
852
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200853/**
854 * Some events are ignored for purpose; and need not be interpreted as
855 * "unhandled events"
856 */
857static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len)
858{
859 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
860}
861
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800862static const struct {
863 int eventid;
864 void (*handler)(struct wil6210_priv *wil, int eventid,
865 void *data, int data_len);
866} wmi_evt_handlers[] = {
867 {WMI_READY_EVENTID, wmi_evt_ready},
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200868 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800869 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300870 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800871 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
872 {WMI_CONNECT_EVENTID, wmi_evt_connect},
873 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800874 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200875 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200876 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
877 {WMI_DELBA_EVENTID, wmi_evt_delba},
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300878 {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200879 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
Lior David8f1b5e02017-02-28 14:58:27 +0200880 {WMI_AOA_MEAS_EVENTID, wmi_evt_aoa_meas},
881 {WMI_TOF_SESSION_END_EVENTID, wmi_evt_ftm_session_ended},
882 {WMI_TOF_GET_CAPABILITIES_EVENTID, wmi_evt_ignore},
883 {WMI_TOF_SET_LCR_EVENTID, wmi_evt_ignore},
884 {WMI_TOF_SET_LCI_EVENTID, wmi_evt_ignore},
885 {WMI_TOF_FTM_PER_DEST_RES_EVENTID, wmi_evt_per_dest_res},
886 {WMI_TOF_CHANNEL_INFO_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800887};
888
889/*
890 * Run in IRQ context
891 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
892 * that will be eventually handled by the @wmi_event_worker in the thread
893 * context of thread "wil6210_wmi"
894 */
895void wmi_recv_cmd(struct wil6210_priv *wil)
896{
897 struct wil6210_mbox_ring_desc d_tail;
898 struct wil6210_mbox_hdr hdr;
899 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
900 struct pending_wmi_event *evt;
901 u8 *cmd;
902 void __iomem *src;
903 ulong flags;
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300904 unsigned n;
Maya Erez0916d9f2016-01-17 12:39:10 +0200905 unsigned int num_immed_reply = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800906
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200907 if (!test_bit(wil_status_mbox_ready, wil->status)) {
Dedy Lansky4cf99c92014-09-10 16:34:41 +0300908 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
Vladimir Kondratiev55f7acd2013-03-13 14:12:49 +0200909 return;
910 }
911
Maya Ereze3309bf2017-05-15 16:57:46 +0300912 if (test_bit(wil_status_suspended, wil->status)) {
913 wil_err(wil, "suspended. cannot handle WMI event\n");
914 return;
915 }
916
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300917 for (n = 0;; n++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800918 u16 len;
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300919 bool q;
Maya Erez0916d9f2016-01-17 12:39:10 +0200920 bool immed_reply = false;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800921
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300922 r->head = wil_r(wil, RGF_MBOX +
923 offsetof(struct wil6210_mbox_ctl, rx.head));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300924 if (r->tail == r->head)
925 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800926
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300927 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
928 r->head, r->tail);
929 /* read cmd descriptor from tail */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800930 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
931 sizeof(struct wil6210_mbox_ring_desc));
932 if (d_tail.sync == 0) {
933 wil_err(wil, "Mbox evt not owned by FW?\n");
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300934 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800935 }
936
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300937 /* read cmd header from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800938 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
939 wil_err(wil, "Mbox evt at 0x%08x?\n",
940 le32_to_cpu(d_tail.addr));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300941 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800942 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800943 len = le16_to_cpu(hdr.len);
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300944 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
945 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
946 hdr.flags);
947
948 /* read cmd buffer from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800949 src = wmi_buffer(wil, d_tail.addr) +
950 sizeof(struct wil6210_mbox_hdr);
951 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
952 event.wmi) + len, 4),
953 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000954 if (!evt)
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300955 break;
Joe Perches14f8dc42013-02-07 11:46:27 +0000956
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800957 evt->event.hdr = hdr;
958 cmd = (void *)&evt->event.wmi;
959 wil_memcpy_fromio_32(cmd, src, len);
960 /* mark entry as empty */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300961 wil_w(wil, r->tail +
962 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800963 /* indicate */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800964 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +0200965 (len >= sizeof(struct wmi_cmd_hdr))) {
966 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
967 u16 id = le16_to_cpu(wmi->command_id);
968 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
Maya Ereze3309bf2017-05-15 16:57:46 +0300969 if (test_bit(wil_status_resuming, wil->status)) {
970 if (id == WMI_TRAFFIC_RESUME_EVENTID)
971 clear_bit(wil_status_resuming,
972 wil->status);
973 else
974 wil_err(wil,
975 "WMI evt %d while resuming\n",
976 id);
977 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200978 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
Maya Erez0916d9f2016-01-17 12:39:10 +0200979 if (wil->reply_id && wil->reply_id == id) {
980 if (wil->reply_buf) {
981 memcpy(wil->reply_buf, wmi,
982 min(len, wil->reply_size));
983 immed_reply = true;
984 }
Maya Ereze3309bf2017-05-15 16:57:46 +0300985 if (id == WMI_TRAFFIC_SUSPEND_EVENTID) {
986 wil_dbg_wmi(wil,
987 "set suspend_resp_rcvd\n");
988 wil->suspend_resp_rcvd = true;
989 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200990 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200991 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300992
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300993 wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
994 id, wmi->mid, tstamp);
995 trace_wil6210_wmi_event(wmi, &wmi[1],
996 len - sizeof(*wmi));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800997 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200998 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800999 &evt->event.hdr, sizeof(hdr) + len, true);
1000
1001 /* advance tail */
1002 r->tail = r->base + ((r->tail - r->base +
1003 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +03001004 wil_w(wil, RGF_MBOX +
1005 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001006
Maya Erez0916d9f2016-01-17 12:39:10 +02001007 if (immed_reply) {
Lazar Alexei3190cc62017-02-23 14:34:14 +02001008 wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
1009 wil->reply_id);
Maya Erez0916d9f2016-01-17 12:39:10 +02001010 kfree(evt);
1011 num_immed_reply++;
1012 complete(&wil->wmi_call);
1013 } else {
1014 /* add to the pending list */
1015 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1016 list_add_tail(&evt->list, &wil->pending_wmi_ev);
1017 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
1018 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
1019 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
1020 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001021 }
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +03001022 /* normally, 1 event per IRQ should be processed */
Lazar Alexei3190cc62017-02-23 14:34:14 +02001023 wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
Maya Erez0916d9f2016-01-17 12:39:10 +02001024 n - num_immed_reply, num_immed_reply);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001025}
1026
1027int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
1028 u16 reply_id, void *reply, u8 reply_size, int to_msec)
1029{
1030 int rc;
Nicholas Mc Guiref4bbb822015-08-13 15:38:31 +03001031 unsigned long remain;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001032
1033 mutex_lock(&wil->wmi_mutex);
1034
Maya Erezfe5c2712016-01-28 19:24:04 +02001035 spin_lock(&wil->wmi_ev_lock);
1036 wil->reply_id = reply_id;
1037 wil->reply_buf = reply;
1038 wil->reply_size = reply_size;
Lior David01660062017-02-22 15:15:23 +02001039 reinit_completion(&wil->wmi_call);
Maya Erezfe5c2712016-01-28 19:24:04 +02001040 spin_unlock(&wil->wmi_ev_lock);
1041
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001042 rc = __wmi_send(wil, cmdid, buf, len);
1043 if (rc)
1044 goto out;
1045
Dedy Lansky59502642014-09-10 16:34:46 +03001046 remain = wait_for_completion_timeout(&wil->wmi_call,
1047 msecs_to_jiffies(to_msec));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001048 if (0 == remain) {
1049 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
1050 cmdid, reply_id, to_msec);
1051 rc = -ETIME;
1052 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001053 wil_dbg_wmi(wil,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001054 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
1055 cmdid, reply_id,
1056 to_msec - jiffies_to_msecs(remain));
1057 }
Maya Erezfe5c2712016-01-28 19:24:04 +02001058
1059out:
1060 spin_lock(&wil->wmi_ev_lock);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001061 wil->reply_id = 0;
1062 wil->reply_buf = NULL;
1063 wil->reply_size = 0;
Maya Erezfe5c2712016-01-28 19:24:04 +02001064 spin_unlock(&wil->wmi_ev_lock);
1065
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001066 mutex_unlock(&wil->wmi_mutex);
1067
1068 return rc;
1069}
1070
1071int wmi_echo(struct wil6210_priv *wil)
1072{
1073 struct wmi_echo_cmd cmd = {
1074 .value = cpu_to_le32(0x12345678),
1075 };
1076
1077 return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratieva54a40d2015-04-30 16:25:05 +03001078 WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001079}
1080
1081int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
1082{
1083 struct wmi_set_mac_address_cmd cmd;
1084
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001085 ether_addr_copy(cmd.mac, addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001086
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001087 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001088
1089 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
1090}
1091
Maya Erez10d599a2016-05-09 21:57:11 +03001092int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
1093{
1094 int rc = 0;
1095 struct wmi_led_cfg_cmd cmd = {
1096 .led_mode = enable,
1097 .id = led_id,
1098 .slow_blink_cfg.blink_on =
1099 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
1100 .slow_blink_cfg.blink_off =
1101 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
1102 .medium_blink_cfg.blink_on =
1103 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
1104 .medium_blink_cfg.blink_off =
1105 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
1106 .fast_blink_cfg.blink_on =
1107 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
1108 .fast_blink_cfg.blink_off =
1109 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
1110 .led_polarity = led_polarity,
1111 };
1112 struct {
1113 struct wmi_cmd_hdr wmi;
1114 struct wmi_led_cfg_done_event evt;
1115 } __packed reply;
1116
1117 if (led_id == WIL_LED_INVALID_ID)
1118 goto out;
1119
1120 if (led_id > WIL_LED_MAX_ID) {
1121 wil_err(wil, "Invalid led id %d\n", led_id);
1122 rc = -EINVAL;
1123 goto out;
1124 }
1125
1126 wil_dbg_wmi(wil,
1127 "%s led %d\n",
1128 enable ? "enabling" : "disabling", led_id);
1129
1130 rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd),
1131 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
1132 100);
1133 if (rc)
1134 goto out;
1135
1136 if (reply.evt.status) {
1137 wil_err(wil, "led %d cfg failed with status %d\n",
1138 led_id, le32_to_cpu(reply.evt.status));
1139 rc = -EINVAL;
1140 }
1141
1142out:
1143 return rc;
1144}
1145
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001146int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype,
Lior Davidb4944f22016-03-01 19:18:17 +02001147 u8 chan, u8 hidden_ssid, u8 is_go)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001148{
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001149 int rc;
1150
1151 struct wmi_pcp_start_cmd cmd = {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001152 .bcon_interval = cpu_to_le16(bi),
1153 .network_type = wmi_nettype,
1154 .disable_sec_offload = 1,
Vladimir Kondratievadc2d122013-05-28 15:17:52 +03001155 .channel = chan - 1,
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001156 .pcp_max_assoc_sta = max_assoc_sta,
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001157 .hidden_ssid = hidden_ssid,
Lior Davidb4944f22016-03-01 19:18:17 +02001158 .is_go = is_go,
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001159 .disable_ap_sme = disable_ap_sme,
Lior David4bbecaf2017-02-08 13:17:35 +02001160 .abft_len = wil->abft_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001161 };
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001162 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001163 struct wmi_cmd_hdr wmi;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001164 struct wmi_pcp_started_event evt;
1165 } __packed reply;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001166
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001167 if (!wil->privacy)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001168 cmd.disable_sec = 1;
1169
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001170 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
1171 (cmd.pcp_max_assoc_sta <= 0)) {
1172 wil_info(wil,
1173 "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
1174 max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
1175 cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
1176 }
1177
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001178 if (disable_ap_sme &&
1179 !test_bit(WMI_FW_CAPABILITY_DISABLE_AP_SME,
1180 wil->fw_capabilities)) {
1181 wil_err(wil, "disable_ap_sme not supported by FW\n");
1182 return -EOPNOTSUPP;
1183 }
1184
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001185 /*
1186 * Processing time may be huge, in case of secure AP it takes about
1187 * 3500ms for FW to start AP
1188 */
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001189 rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001190 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001191 if (rc)
1192 return rc;
1193
1194 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
1195 rc = -EINVAL;
1196
Maya Erez10d599a2016-05-09 21:57:11 +03001197 if (wmi_nettype != WMI_NETTYPE_P2P)
1198 /* Don't fail due to error in the led configuration */
1199 wmi_led_cfg(wil, true);
1200
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001201 return rc;
1202}
1203
1204int wmi_pcp_stop(struct wil6210_priv *wil)
1205{
Maya Erez10d599a2016-05-09 21:57:11 +03001206 int rc;
1207
1208 rc = wmi_led_cfg(wil, false);
1209 if (rc)
1210 return rc;
1211
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001212 return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
1213 WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001214}
1215
1216int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
1217{
1218 struct wmi_set_ssid_cmd cmd = {
1219 .ssid_len = cpu_to_le32(ssid_len),
1220 };
1221
1222 if (ssid_len > sizeof(cmd.ssid))
1223 return -EINVAL;
1224
1225 memcpy(cmd.ssid, ssid, ssid_len);
1226
1227 return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
1228}
1229
1230int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
1231{
1232 int rc;
1233 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001234 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001235 struct wmi_set_ssid_cmd cmd;
1236 } __packed reply;
1237 int len; /* reply.cmd.ssid_len in CPU order */
1238
1239 rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
1240 &reply, sizeof(reply), 20);
1241 if (rc)
1242 return rc;
1243
1244 len = le32_to_cpu(reply.cmd.ssid_len);
1245 if (len > sizeof(reply.cmd.ssid))
1246 return -EINVAL;
1247
1248 *ssid_len = len;
1249 memcpy(ssid, reply.cmd.ssid, len);
1250
1251 return 0;
1252}
1253
1254int wmi_set_channel(struct wil6210_priv *wil, int channel)
1255{
1256 struct wmi_set_pcp_channel_cmd cmd = {
1257 .channel = channel - 1,
1258 };
1259
1260 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
1261}
1262
1263int wmi_get_channel(struct wil6210_priv *wil, int *channel)
1264{
1265 int rc;
1266 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001267 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001268 struct wmi_set_pcp_channel_cmd cmd;
1269 } __packed reply;
1270
1271 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
1272 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
1273 if (rc)
1274 return rc;
1275
1276 if (reply.cmd.channel > 3)
1277 return -EINVAL;
1278
1279 *channel = reply.cmd.channel + 1;
1280
1281 return 0;
1282}
1283
Dedy Lanskye6d68342016-03-01 19:18:12 +02001284int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi)
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001285{
Dedy Lanskye6d68342016-03-01 19:18:12 +02001286 int rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001287 struct wmi_p2p_cfg_cmd cmd = {
Dedy Lanskye6d68342016-03-01 19:18:12 +02001288 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
1289 .bcon_interval = cpu_to_le16(bi),
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001290 .channel = channel - 1,
1291 };
Dedy Lanskye6d68342016-03-01 19:18:12 +02001292 struct {
1293 struct wmi_cmd_hdr wmi;
1294 struct wmi_p2p_cfg_done_event evt;
1295 } __packed reply;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001296
Dedy Lanskye6d68342016-03-01 19:18:12 +02001297 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
1298
1299 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd),
1300 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
1301 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1302 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
1303 rc = -EINVAL;
1304 }
1305
1306 return rc;
1307}
1308
1309int wmi_start_listen(struct wil6210_priv *wil)
1310{
1311 int rc;
1312 struct {
1313 struct wmi_cmd_hdr wmi;
1314 struct wmi_listen_started_event evt;
1315 } __packed reply;
1316
1317 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
1318
1319 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1320 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
1321 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1322 wil_err(wil, "device failed to start listen. status %d\n",
1323 reply.evt.status);
1324 rc = -EINVAL;
1325 }
1326
1327 return rc;
1328}
1329
1330int wmi_start_search(struct wil6210_priv *wil)
1331{
1332 int rc;
1333 struct {
1334 struct wmi_cmd_hdr wmi;
1335 struct wmi_search_started_event evt;
1336 } __packed reply;
1337
1338 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
1339
1340 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0,
1341 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
1342 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1343 wil_err(wil, "device failed to start search. status %d\n",
1344 reply.evt.status);
1345 rc = -EINVAL;
1346 }
1347
1348 return rc;
1349}
1350
1351int wmi_stop_discovery(struct wil6210_priv *wil)
1352{
1353 int rc;
1354
1355 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
1356
1357 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1358 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
1359
1360 if (rc)
1361 wil_err(wil, "Failed to stop discovery\n");
1362
1363 return rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001364}
1365
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001366int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001367 const void *mac_addr, int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001368{
1369 struct wmi_delete_cipher_key_cmd cmd = {
1370 .key_index = key_index,
1371 };
1372
1373 if (mac_addr)
1374 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1375
1376 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1377}
1378
1379int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001380 const void *mac_addr, int key_len, const void *key,
1381 int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001382{
1383 struct wmi_add_cipher_key_cmd cmd = {
1384 .key_index = key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001385 .key_usage = key_usage,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001386 .key_len = key_len,
1387 };
1388
1389 if (!key || (key_len > sizeof(cmd.key)))
1390 return -EINVAL;
1391
1392 memcpy(cmd.key, key, key_len);
1393 if (mac_addr)
1394 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1395
1396 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1397}
1398
1399int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
1400{
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001401 static const char *const names[] = {
1402 [WMI_FRAME_BEACON] = "BEACON",
1403 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
1404 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
1405 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
1406 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
1407 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001408 int rc;
1409 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
1410 struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001411
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001412 if (!cmd) {
1413 rc = -ENOMEM;
1414 goto out;
1415 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +03001416 if (!ie)
1417 ie_len = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001418
1419 cmd->mgmt_frm_type = type;
1420 /* BUG: FW API define ieLen as u8. Will fix FW */
1421 cmd->ie_len = cpu_to_le16(ie_len);
1422 memcpy(cmd->ie_info, ie, ie_len);
Vladimir Kondratiev03866e72013-03-13 14:12:42 +02001423 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001424 kfree(cmd);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001425out:
1426 if (rc) {
1427 const char *name = type < ARRAY_SIZE(names) ?
1428 names[type] : "??";
1429 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
1430 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001431
1432 return rc;
1433}
1434
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001435/**
1436 * wmi_rxon - turn radio on/off
1437 * @on: turn on if true, off otherwise
1438 *
1439 * Only switch radio. Channel should be set separately.
1440 * No timeout for rxon - radio turned on forever unless some other call
1441 * turns it off
1442 */
1443int wmi_rxon(struct wil6210_priv *wil, bool on)
1444{
1445 int rc;
1446 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001447 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001448 struct wmi_listen_started_event evt;
1449 } __packed reply;
1450
Lazar Alexei3190cc62017-02-23 14:34:14 +02001451 wil_info(wil, "(%s)\n", on ? "on" : "off");
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001452
1453 if (on) {
1454 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1455 WMI_LISTEN_STARTED_EVENTID,
1456 &reply, sizeof(reply), 100);
1457 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
1458 rc = -EINVAL;
1459 } else {
1460 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1461 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
1462 }
1463
1464 return rc;
1465}
1466
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001467int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1468{
1469 struct wireless_dev *wdev = wil->wdev;
1470 struct net_device *ndev = wil_to_ndev(wil);
1471 struct wmi_cfg_rx_chain_cmd cmd = {
1472 .action = WMI_RX_CHAIN_ADD,
1473 .rx_sw_ring = {
Lior David2e9a3212017-05-04 22:43:18 +03001474 .max_mpdu_size = cpu_to_le16(
1475 wil_mtu2macbuf(wil->rx_buf_len)),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001476 .ring_mem_base = cpu_to_le64(vring->pa),
1477 .ring_size = cpu_to_le16(vring->size),
1478 },
1479 .mid = 0, /* TODO - what is it? */
1480 .decap_trans_type = WMI_DECAP_TYPE_802_3,
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001481 .reorder_type = WMI_RX_SW_REORDER,
Vladimir Kondratievab954622014-12-23 09:47:20 +02001482 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001483 };
1484 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001485 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001486 struct wmi_cfg_rx_chain_done_event evt;
1487 } __packed evt;
1488 int rc;
1489
1490 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
1491 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
1492
1493 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
1494 if (ch)
1495 cmd.sniffer_cfg.channel = ch->hw_value - 1;
1496 cmd.sniffer_cfg.phy_info_mode =
1497 cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
1498 cmd.sniffer_cfg.phy_support =
1499 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
Vladimir Kondratiev47653322015-10-04 10:23:24 +03001500 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +03001501 } else {
1502 /* Initialize offload (in non-sniffer mode).
1503 * Linux IP stack always calculates IP checksum
1504 * HW always calculate TCP/UDP checksum
1505 */
1506 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001507 }
Vladimir Kondratievc406ea72015-03-15 16:00:19 +02001508
1509 if (rx_align_2)
1510 cmd.l2_802_3_offload_ctrl |=
1511 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
1512
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001513 /* typical time for secure PCP is 840ms */
1514 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
1515 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
1516 if (rc)
1517 return rc;
1518
1519 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
1520
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001521 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001522 le32_to_cpu(evt.evt.status), vring->hwtail);
1523
1524 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
1525 rc = -EINVAL;
1526
1527 return rc;
1528}
1529
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001530int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001531{
1532 int rc;
1533 struct wmi_temp_sense_cmd cmd = {
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001534 .measure_baseband_en = cpu_to_le32(!!t_bb),
1535 .measure_rf_en = cpu_to_le32(!!t_rf),
1536 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001537 };
1538 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001539 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001540 struct wmi_temp_sense_done_event evt;
1541 } __packed reply;
1542
1543 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
1544 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
1545 if (rc)
1546 return rc;
1547
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001548 if (t_bb)
1549 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
1550 if (t_rf)
1551 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001552
1553 return 0;
1554}
1555
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001556int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac,
1557 u16 reason, bool full_disconnect, bool del_sta)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001558{
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001559 int rc;
1560 u16 reason_code;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001561 struct wmi_disconnect_sta_cmd disc_sta_cmd = {
1562 .disconnect_reason = cpu_to_le16(reason),
1563 };
1564 struct wmi_del_sta_cmd del_sta_cmd = {
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001565 .disconnect_reason = cpu_to_le16(reason),
1566 };
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001567 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001568 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001569 struct wmi_disconnect_event evt;
1570 } __packed reply;
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001571
Lazar Alexei3190cc62017-02-23 14:34:14 +02001572 wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001573
Dedy Lansky0a4e9d12017-03-27 21:21:31 +03001574 wil->locally_generated_disc = true;
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001575 if (del_sta) {
1576 ether_addr_copy(del_sta_cmd.dst_mac, mac);
1577 rc = wmi_call(wil, WMI_DEL_STA_CMDID, &del_sta_cmd,
1578 sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
1579 &reply, sizeof(reply), 1000);
1580 } else {
1581 ether_addr_copy(disc_sta_cmd.dst_mac, mac);
1582 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &disc_sta_cmd,
1583 sizeof(disc_sta_cmd), WMI_DISCONNECT_EVENTID,
1584 &reply, sizeof(reply), 1000);
1585 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001586 /* failure to disconnect in reasonable time treated as FW error */
1587 if (rc) {
1588 wil_fw_error_recovery(wil);
1589 return rc;
1590 }
1591
Maya Erez0916d9f2016-01-17 12:39:10 +02001592 if (full_disconnect) {
1593 /* call event handler manually after processing wmi_call,
1594 * to avoid deadlock - disconnect event handler acquires
1595 * wil->mutex while it is already held here
1596 */
1597 reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001598
Maya Erez0916d9f2016-01-17 12:39:10 +02001599 wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1600 reply.evt.bssid, reason_code,
1601 reply.evt.disconnect_reason);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001602
Maya Erez0916d9f2016-01-17 12:39:10 +02001603 wil->sinfo_gen++;
1604 wil6210_disconnect(wil, reply.evt.bssid, reason_code, true);
1605 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001606 return 0;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001607}
1608
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001609int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout)
1610{
1611 struct wmi_vring_ba_en_cmd cmd = {
1612 .ringid = ringid,
1613 .agg_max_wsize = size,
1614 .ba_timeout = cpu_to_le16(timeout),
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +02001615 .amsdu = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001616 };
1617
Lazar Alexei3190cc62017-02-23 14:34:14 +02001618 wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size,
1619 timeout);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001620
1621 return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd));
1622}
1623
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001624int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason)
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001625{
1626 struct wmi_vring_ba_dis_cmd cmd = {
1627 .ringid = ringid,
1628 .reason = cpu_to_le16(reason),
1629 };
1630
Lazar Alexei3190cc62017-02-23 14:34:14 +02001631 wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001632
1633 return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd));
1634}
1635
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001636int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason)
1637{
1638 struct wmi_rcp_delba_cmd cmd = {
1639 .cidxtid = cidxtid,
1640 .reason = cpu_to_le16(reason),
1641 };
1642
Lazar Alexei3190cc62017-02-23 14:34:14 +02001643 wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf,
1644 (cidxtid >> 4) & 0xf, reason);
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001645
1646 return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd));
1647}
1648
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001649int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
1650 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
1651{
1652 int rc;
1653 struct wmi_rcp_addba_resp_cmd cmd = {
1654 .cidxtid = mk_cidxtid(cid, tid),
1655 .dialog_token = token,
1656 .status_code = cpu_to_le16(status),
1657 /* bit 0: A-MSDU supported
1658 * bit 1: policy (should be 0 for us)
1659 * bits 2..5: TID
1660 * bits 6..15: buffer size
1661 */
1662 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
1663 (agg_wsize << 6)),
1664 .ba_timeout = cpu_to_le16(timeout),
1665 };
1666 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001667 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001668 struct wmi_rcp_addba_resp_sent_event evt;
1669 } __packed reply;
1670
1671 wil_dbg_wmi(wil,
1672 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
1673 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-");
1674
1675 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001676 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
1677 100);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001678 if (rc)
1679 return rc;
1680
1681 if (reply.evt.status) {
1682 wil_err(wil, "ADDBA response failed with status %d\n",
1683 le16_to_cpu(reply.evt.status));
1684 rc = -EINVAL;
1685 }
1686
1687 return rc;
1688}
1689
Maya Ereze77727f2016-12-06 12:21:17 +02001690int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
1691 enum wmi_ps_profile_type ps_profile)
1692{
1693 int rc;
1694 struct wmi_ps_dev_profile_cfg_cmd cmd = {
1695 .ps_profile = ps_profile,
1696 };
1697 struct {
1698 struct wmi_cmd_hdr wmi;
1699 struct wmi_ps_dev_profile_cfg_event evt;
1700 } __packed reply;
1701 u32 status;
1702
1703 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
1704
1705 reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR);
1706
1707 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd),
1708 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
1709 100);
1710 if (rc)
1711 return rc;
1712
1713 status = le32_to_cpu(reply.evt.status);
1714
1715 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
1716 wil_err(wil, "ps dev profile cfg failed with status %d\n",
1717 status);
1718 rc = -EINVAL;
1719 }
1720
1721 return rc;
1722}
1723
Lior Davidde21eba2017-02-15 20:33:10 +02001724int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
1725{
1726 int rc;
1727 struct wmi_set_mgmt_retry_limit_cmd cmd = {
1728 .mgmt_retry_limit = retry_short,
1729 };
1730 struct {
1731 struct wmi_cmd_hdr wmi;
1732 struct wmi_set_mgmt_retry_limit_event evt;
1733 } __packed reply;
1734
1735 wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
1736
1737 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1738 return -ENOTSUPP;
1739
1740 reply.evt.status = WMI_FW_STATUS_FAILURE;
1741
1742 rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd),
1743 WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1744 100);
1745 if (rc)
1746 return rc;
1747
1748 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1749 wil_err(wil, "set mgmt retry limit failed with status %d\n",
1750 reply.evt.status);
1751 rc = -EINVAL;
1752 }
1753
1754 return rc;
1755}
1756
1757int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
1758{
1759 int rc;
1760 struct {
1761 struct wmi_cmd_hdr wmi;
1762 struct wmi_get_mgmt_retry_limit_event evt;
1763 } __packed reply;
1764
1765 wil_dbg_wmi(wil, "getting mgmt retry short\n");
1766
1767 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1768 return -ENOTSUPP;
1769
1770 reply.evt.mgmt_retry_limit = 0;
1771 rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0,
1772 WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1773 100);
1774 if (rc)
1775 return rc;
1776
1777 if (retry_short)
1778 *retry_short = reply.evt.mgmt_retry_limit;
1779
1780 return 0;
1781}
1782
Maya Erez4cbb5852017-02-16 15:26:09 +02001783int wmi_abort_scan(struct wil6210_priv *wil)
1784{
1785 int rc;
1786
1787 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
1788
1789 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0);
1790 if (rc)
1791 wil_err(wil, "Failed to abort scan (%d)\n", rc);
1792
1793 return rc;
1794}
1795
Dedy Lanskyb94ee9e2017-02-23 15:53:29 +02001796int wmi_new_sta(struct wil6210_priv *wil, const u8 *mac, u8 aid)
1797{
1798 int rc;
1799 struct wmi_new_sta_cmd cmd = {
1800 .aid = aid,
1801 };
1802
1803 wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
1804
1805 ether_addr_copy(cmd.dst_mac, mac);
1806
1807 rc = wmi_send(wil, WMI_NEW_STA_CMDID, &cmd, sizeof(cmd));
1808 if (rc)
1809 wil_err(wil, "Failed to send new sta (%d)\n", rc);
1810
1811 return rc;
1812}
1813
Dedy Lansky1b752712017-03-20 15:35:51 +02001814int wmi_set_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data)
1815{
1816 int rc;
1817 struct wmi_set_thermal_throttling_cfg_cmd cmd = {
1818 .tt_data = *tt_data,
1819 };
1820 struct {
1821 struct wmi_cmd_hdr wmi;
1822 struct wmi_set_thermal_throttling_cfg_event evt;
1823 } __packed reply;
1824
1825 if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING,
1826 wil->fw_capabilities))
1827 return -EOPNOTSUPP;
1828
1829 memset(&reply, 0, sizeof(reply));
1830 rc = wmi_call(wil, WMI_SET_THERMAL_THROTTLING_CFG_CMDID, &cmd,
1831 sizeof(cmd), WMI_SET_THERMAL_THROTTLING_CFG_EVENTID,
1832 &reply, sizeof(reply), 100);
1833 if (rc) {
1834 wil_err(wil, "failed to set thermal throttling\n");
1835 return rc;
1836 }
1837 if (reply.evt.status) {
1838 wil_err(wil, "set thermal throttling failed, error %d\n",
1839 reply.evt.status);
1840 return -EIO;
1841 }
1842
1843 wil->tt_data = *tt_data;
1844 wil->tt_data_set = true;
1845
1846 return 0;
1847}
1848
1849int wmi_get_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data)
1850{
1851 int rc;
1852 struct {
1853 struct wmi_cmd_hdr wmi;
1854 struct wmi_get_thermal_throttling_cfg_event evt;
1855 } __packed reply;
1856
1857 if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING,
1858 wil->fw_capabilities))
1859 return -EOPNOTSUPP;
1860
1861 rc = wmi_call(wil, WMI_GET_THERMAL_THROTTLING_CFG_CMDID, NULL, 0,
1862 WMI_GET_THERMAL_THROTTLING_CFG_EVENTID, &reply,
1863 sizeof(reply), 100);
1864 if (rc) {
1865 wil_err(wil, "failed to get thermal throttling\n");
1866 return rc;
1867 }
1868
1869 if (tt_data)
1870 *tt_data = reply.evt.tt_data;
1871
1872 return 0;
1873}
1874
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001875void wmi_event_flush(struct wil6210_priv *wil)
1876{
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001877 ulong flags;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001878 struct pending_wmi_event *evt, *t;
1879
Lazar Alexei3190cc62017-02-23 14:34:14 +02001880 wil_dbg_wmi(wil, "event_flush\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001881
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001882 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1883
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001884 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
1885 list_del(&evt->list);
1886 kfree(evt);
1887 }
Hamad Kadmanyc33f7492017-02-06 11:46:36 +02001888
1889 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001890}
1891
Hamad Kadmany105dd0f2017-04-04 15:14:17 +03001892int wmi_link_maintain_cfg_write(struct wil6210_priv *wil,
1893 const u8 *addr,
1894 bool fst_link_loss)
1895{
1896 int rc;
1897 int cid = wil_find_cid(wil, addr);
1898 u32 cfg_type;
1899 struct wmi_link_maintain_cfg_write_cmd cmd;
1900 struct {
1901 struct wmi_cmd_hdr wmi;
1902 struct wmi_link_maintain_cfg_write_done_event evt;
1903 } __packed reply;
1904
1905 if (cid < 0)
1906 return cid;
1907
1908 switch (wil->wdev->iftype) {
1909 case NL80211_IFTYPE_STATION:
1910 cfg_type = fst_link_loss ?
1911 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_FST_STA :
1912 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_NORMAL_STA;
1913 break;
1914 case NL80211_IFTYPE_AP:
1915 cfg_type = fst_link_loss ?
1916 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_FST_AP :
1917 WMI_LINK_MAINTAIN_CFG_TYPE_DEFAULT_NORMAL_AP;
1918 break;
1919 default:
1920 wil_err(wil, "Unsupported for iftype %d", wil->wdev->iftype);
1921 return -EINVAL;
1922 }
1923
1924 wil_dbg_misc(wil, "Setting cid:%d with cfg_type:%d\n", cid, cfg_type);
1925
1926 cmd.cfg_type = cpu_to_le32(cfg_type);
1927 cmd.cid = cpu_to_le32(cid);
1928
1929 reply.evt.status = cpu_to_le32(WMI_FW_STATUS_FAILURE);
1930
1931 rc = wmi_call(wil, WMI_LINK_MAINTAIN_CFG_WRITE_CMDID, &cmd, sizeof(cmd),
1932 WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENTID, &reply,
1933 sizeof(reply), 250);
1934 if (rc) {
1935 wil_err(wil, "Failed to %s FST link loss",
1936 fst_link_loss ? "enable" : "disable");
1937 } else if (reply.evt.status == WMI_FW_STATUS_SUCCESS) {
1938 wil->sta[cid].fst_link_loss = fst_link_loss;
1939 } else {
1940 wil_err(wil, "WMI_LINK_MAINTAIN_CFG_WRITE_CMDID returned status %d",
1941 reply.evt.status);
1942 rc = -EINVAL;
1943 }
1944 return rc;
1945}
1946
Maya Ereze3309bf2017-05-15 16:57:46 +03001947int wmi_suspend(struct wil6210_priv *wil)
1948{
1949 int rc;
1950 struct wmi_traffic_suspend_cmd cmd = {
1951 .wakeup_trigger = wil->wakeup_trigger,
1952 };
1953 struct {
1954 struct wmi_cmd_hdr wmi;
1955 struct wmi_traffic_suspend_event evt;
1956 } __packed reply;
1957 u32 suspend_to = WIL_WAIT_FOR_SUSPEND_RESUME_COMP;
1958
1959 wil->suspend_resp_rcvd = false;
1960 wil->suspend_resp_comp = false;
1961
1962 reply.evt.status = WMI_TRAFFIC_SUSPEND_REJECTED;
1963
1964 rc = wmi_call(wil, WMI_TRAFFIC_SUSPEND_CMDID, &cmd, sizeof(cmd),
1965 WMI_TRAFFIC_SUSPEND_EVENTID, &reply, sizeof(reply),
1966 suspend_to);
1967 if (rc) {
1968 wil_err(wil, "wmi_call for suspend req failed, rc=%d\n", rc);
1969 if (rc == -ETIME)
1970 /* wmi_call TO */
1971 wil->suspend_stats.rejected_by_device++;
1972 else
1973 wil->suspend_stats.rejected_by_host++;
1974 goto out;
1975 }
1976
1977 wil_dbg_wmi(wil, "waiting for suspend_response_completed\n");
1978
1979 rc = wait_event_interruptible_timeout(wil->wq,
1980 wil->suspend_resp_comp,
1981 msecs_to_jiffies(suspend_to));
1982 if (rc == 0) {
1983 wil_err(wil, "TO waiting for suspend_response_completed\n");
1984 if (wil->suspend_resp_rcvd)
1985 /* Device responded but we TO due to another reason */
1986 wil->suspend_stats.rejected_by_host++;
1987 else
1988 wil->suspend_stats.rejected_by_device++;
1989 rc = -EBUSY;
1990 goto out;
1991 }
1992
1993 wil_dbg_wmi(wil, "suspend_response_completed rcvd\n");
1994 if (reply.evt.status == WMI_TRAFFIC_SUSPEND_REJECTED) {
1995 wil_dbg_pm(wil, "device rejected the suspend\n");
1996 wil->suspend_stats.rejected_by_device++;
1997 }
1998 rc = reply.evt.status;
1999
2000out:
2001 wil->suspend_resp_rcvd = false;
2002 wil->suspend_resp_comp = false;
2003
2004 return rc;
2005}
2006
2007int wmi_resume(struct wil6210_priv *wil)
2008{
2009 int rc;
2010 struct {
2011 struct wmi_cmd_hdr wmi;
2012 struct wmi_traffic_resume_event evt;
2013 } __packed reply;
2014
2015 reply.evt.status = WMI_TRAFFIC_RESUME_FAILED;
2016
2017 rc = wmi_call(wil, WMI_TRAFFIC_RESUME_CMDID, NULL, 0,
2018 WMI_TRAFFIC_RESUME_EVENTID, &reply, sizeof(reply),
2019 WIL_WAIT_FOR_SUSPEND_RESUME_COMP);
2020 if (rc)
2021 return rc;
2022
2023 return reply.evt.status;
2024}
2025
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002026static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
2027 void *d, int len)
2028{
2029 uint i;
2030
2031 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
2032 if (wmi_evt_handlers[i].eventid == id) {
2033 wmi_evt_handlers[i].handler(wil, id, d, len);
2034 return true;
2035 }
2036 }
2037
2038 return false;
2039}
2040
2041static void wmi_event_handle(struct wil6210_priv *wil,
2042 struct wil6210_mbox_hdr *hdr)
2043{
2044 u16 len = le16_to_cpu(hdr->len);
2045
2046 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +02002047 (len >= sizeof(struct wmi_cmd_hdr))) {
2048 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002049 void *evt_data = (void *)(&wmi[1]);
Lior Davidb874dde2016-03-01 19:18:09 +02002050 u16 id = le16_to_cpu(wmi->command_id);
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03002051
2052 wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n",
2053 id, wil->reply_id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002054 /* check if someone waits for this event */
2055 if (wil->reply_id && wil->reply_id == id) {
Maya Erez0916d9f2016-01-17 12:39:10 +02002056 WARN_ON(wil->reply_buf);
2057 wmi_evt_call_handler(wil, id, evt_data,
2058 len - sizeof(*wmi));
Lazar Alexei3190cc62017-02-23 14:34:14 +02002059 wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
2060 id);
Dedy Lansky59502642014-09-10 16:34:46 +03002061 complete(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002062 return;
2063 }
2064 /* unsolicited event */
2065 /* search for handler */
2066 if (!wmi_evt_call_handler(wil, id, evt_data,
2067 len - sizeof(*wmi))) {
Dedy Lanskya3ce5ccd2015-07-30 13:51:58 +03002068 wil_info(wil, "Unhandled event 0x%04x\n", id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002069 }
2070 } else {
2071 wil_err(wil, "Unknown event type\n");
2072 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
2073 hdr, sizeof(*hdr) + len, true);
2074 }
2075}
2076
2077/*
2078 * Retrieve next WMI event from the pending list
2079 */
2080static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
2081{
2082 ulong flags;
2083 struct list_head *ret = NULL;
2084
2085 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2086
2087 if (!list_empty(&wil->pending_wmi_ev)) {
2088 ret = wil->pending_wmi_ev.next;
2089 list_del(ret);
2090 }
2091
2092 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2093
2094 return ret;
2095}
2096
2097/*
2098 * Handler for the WMI events
2099 */
2100void wmi_event_worker(struct work_struct *work)
2101{
2102 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
2103 wmi_event_worker);
2104 struct pending_wmi_event *evt;
2105 struct list_head *lh;
2106
Lazar Alexei3190cc62017-02-23 14:34:14 +02002107 wil_dbg_wmi(wil, "event_worker: Start\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002108 while ((lh = next_wmi_ev(wil)) != NULL) {
2109 evt = list_entry(lh, struct pending_wmi_event, list);
2110 wmi_event_handle(wil, &evt->event.hdr);
2111 kfree(evt);
2112 }
Lazar Alexei3190cc62017-02-23 14:34:14 +02002113 wil_dbg_wmi(wil, "event_worker: Finished\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08002114}
Maya Ereze3309bf2017-05-15 16:57:46 +03002115
2116bool wil_is_wmi_idle(struct wil6210_priv *wil)
2117{
2118 ulong flags;
2119 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
2120 bool rc = false;
2121
2122 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2123
2124 /* Check if there are pending WMI events in the events queue */
2125 if (!list_empty(&wil->pending_wmi_ev)) {
2126 wil_dbg_pm(wil, "Pending WMI events in queue\n");
2127 goto out;
2128 }
2129
2130 /* Check if there is a pending WMI call */
2131 if (wil->reply_id) {
2132 wil_dbg_pm(wil, "Pending WMI call\n");
2133 goto out;
2134 }
2135
2136 /* Check if there are pending RX events in mbox */
2137 r->head = wil_r(wil, RGF_MBOX +
2138 offsetof(struct wil6210_mbox_ctl, rx.head));
2139 if (r->tail != r->head)
2140 wil_dbg_pm(wil, "Pending WMI mbox events\n");
2141 else
2142 rc = true;
2143
2144out:
2145 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2146 return rc;
2147}