blob: 1f22c19696b11914e7e79a470882f7de692753c0 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Dedy Lansky849a5642017-01-20 13:49:44 +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"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080025
Vladimir Kondratiev327755f2014-12-23 09:47:13 +020026static uint max_assoc_sta = WIL6210_MAX_CID;
Maya Erez78484c42017-01-20 13:49:53 +020027module_param(max_assoc_sta, uint, 0644);
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +030028MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP");
29
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +020030int agg_wsize; /* = 0; */
Maya Erez78484c42017-01-20 13:49:53 +020031module_param(agg_wsize, int, 0644);
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +020032MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;"
33 " 0 - use default; < 0 - don't auto-establish");
34
Maya Erez10d599a2016-05-09 21:57:11 +030035u8 led_id = WIL_LED_INVALID_ID;
Maya Erez78484c42017-01-20 13:49:53 +020036module_param(led_id, byte, 0444);
Maya Erez10d599a2016-05-09 21:57:11 +030037MODULE_PARM_DESC(led_id,
38 " 60G device led enablement. Set the led ID (0-2) to enable");
39
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080040/**
41 * WMI event receiving - theory of operations
42 *
43 * When firmware about to report WMI event, it fills memory area
44 * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
45 * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
46 *
47 * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
48 * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
49 * and handles events within the @wmi_event_worker. Every event get detached
50 * from list, processed and deleted.
51 *
52 * Purpose for this mechanism is to release IRQ thread; otherwise,
53 * if WMI event handling involves another WMI command flow, this 2-nd flow
54 * won't be completed because of blocked IRQ thread.
55 */
56
57/**
58 * Addressing - theory of operations
59 *
60 * There are several buses present on the WIL6210 card.
61 * Same memory areas are visible at different address on
62 * the different busses. There are 3 main bus masters:
63 * - MAC CPU (ucode)
64 * - User CPU (firmware)
65 * - AHB (host)
66 *
67 * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
68 * AHB addresses starting from 0x880000
69 *
70 * Internally, firmware uses addresses that allows faster access but
71 * are invisible from the host. To read from these addresses, alternative
72 * AHB address must be used.
73 *
74 * Memory mapping
75 * Linker address PCI/Host address
76 * 0x880000 .. 0xa80000 2Mb BAR0
77 * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM
78 * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH
79 */
80
81/**
82 * @fw_mapping provides memory remapping table
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030083 *
84 * array size should be in sync with the declaration in the wil6210.h
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080085 */
Vladimir Kondratievb541d0a2014-07-14 09:49:41 +030086const struct fw_map fw_mapping[] = {
Lior David61578822016-11-28 13:49:02 +020087 /* FW code RAM 256k */
88 {0x000000, 0x040000, 0x8c0000, "fw_code", true},
89 /* FW data RAM 32k */
90 {0x800000, 0x808000, 0x900000, "fw_data", true},
91 /* periph data 128k */
92 {0x840000, 0x860000, 0x908000, "fw_peri", true},
93 /* various RGF 40k */
94 {0x880000, 0x88a000, 0x880000, "rgf", true},
95 /* AGC table 4k */
96 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true},
97 /* Pcie_ext_rgf 4k */
98 {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true},
99 /* mac_ext_rgf 512b */
100 {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext", true},
101 /* upper area 548k */
102 {0x8c0000, 0x949000, 0x8c0000, "upper", true},
103 /* UCODE areas - accessible by debugfs blobs but not by
104 * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800105 */
Lior David61578822016-11-28 13:49:02 +0200106 /* ucode code RAM 128k */
107 {0x000000, 0x020000, 0x920000, "uc_code", false},
108 /* ucode data RAM 16k */
109 {0x800000, 0x804000, 0x940000, "uc_data", false},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800110};
111
Maya Erez10d599a2016-05-09 21:57:11 +0300112struct blink_on_off_time led_blink_time[] = {
113 {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS},
114 {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS},
115 {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS},
116};
117
118u8 led_polarity = LED_POLARITY_LOW_ACTIVE;
119
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800120/**
Lior David61578822016-11-28 13:49:02 +0200121 * return AHB address for given firmware internal (linker) address
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800122 * @x - internal address
123 * If address have no valid AHB mapping, return 0
124 */
125static u32 wmi_addr_remap(u32 x)
126{
127 uint i;
128
129 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
Lior David61578822016-11-28 13:49:02 +0200130 if (fw_mapping[i].fw &&
131 ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)))
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800132 return x + fw_mapping[i].host - fw_mapping[i].from;
133 }
134
135 return 0;
136}
137
138/**
139 * Check address validity for WMI buffer; remap if needed
140 * @ptr - internal (linker) fw/ucode address
141 *
142 * Valid buffer should be DWORD aligned
143 *
144 * return address for accessing buffer from the host;
145 * if buffer is not valid, return NULL.
146 */
147void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
148{
149 u32 off;
150 u32 ptr = le32_to_cpu(ptr_);
151
152 if (ptr % 4)
153 return NULL;
154
155 ptr = wmi_addr_remap(ptr);
156 if (ptr < WIL6210_FW_HOST_OFF)
157 return NULL;
158
159 off = HOSTADDR(ptr);
160 if (off > WIL6210_MEM_SIZE - 4)
161 return NULL;
162
163 return wil->csr + off;
164}
165
166/**
167 * Check address validity
168 */
169void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
170{
171 u32 off;
172
173 if (ptr % 4)
174 return NULL;
175
176 if (ptr < WIL6210_FW_HOST_OFF)
177 return NULL;
178
179 off = HOSTADDR(ptr);
180 if (off > WIL6210_MEM_SIZE - 4)
181 return NULL;
182
183 return wil->csr + off;
184}
185
186int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
187 struct wil6210_mbox_hdr *hdr)
188{
189 void __iomem *src = wmi_buffer(wil, ptr);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300190
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800191 if (!src)
192 return -EINVAL;
193
194 wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
195
196 return 0;
197}
198
199static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
200{
201 struct {
202 struct wil6210_mbox_hdr hdr;
Lior Davidb874dde2016-03-01 19:18:09 +0200203 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800204 } __packed cmd = {
205 .hdr = {
206 .type = WIL_MBOX_HDR_TYPE_WMI,
207 .flags = 0,
208 .len = cpu_to_le16(sizeof(cmd.wmi) + len),
209 },
210 .wmi = {
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300211 .mid = 0,
Lior Davidb874dde2016-03-01 19:18:09 +0200212 .command_id = cpu_to_le16(cmdid),
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800213 },
214 };
215 struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
216 struct wil6210_mbox_ring_desc d_head;
217 u32 next_head;
218 void __iomem *dst;
219 void __iomem *head = wmi_addr(wil, r->head);
220 uint retry;
Maya Erez349214c2016-04-26 14:41:41 +0300221 int rc = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800222
223 if (sizeof(cmd) + len > r->entry_size) {
224 wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
225 (int)(sizeof(cmd) + len), r->entry_size);
226 return -ERANGE;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800227 }
228
229 might_sleep();
230
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200231 if (!test_bit(wil_status_fwready, wil->status)) {
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300232 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800233 return -EAGAIN;
234 }
235
236 if (!head) {
237 wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
238 return -EINVAL;
239 }
Maya Erez349214c2016-04-26 14:41:41 +0300240
241 wil_halp_vote(wil);
242
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800243 /* read Tx head till it is not busy */
244 for (retry = 5; retry > 0; retry--) {
245 wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
246 if (d_head.sync == 0)
247 break;
248 msleep(20);
249 }
250 if (d_head.sync != 0) {
251 wil_err(wil, "WMI head busy\n");
Maya Erez349214c2016-04-26 14:41:41 +0300252 rc = -EBUSY;
253 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800254 }
255 /* next head */
256 next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200257 wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800258 /* wait till FW finish with previous command */
259 for (retry = 5; retry > 0; retry--) {
Maya Erez452133a2015-11-24 09:30:15 +0200260 if (!test_bit(wil_status_fwready, wil->status)) {
261 wil_err(wil, "WMI: cannot send command while FW not ready\n");
Maya Erez349214c2016-04-26 14:41:41 +0300262 rc = -EAGAIN;
263 goto out;
Maya Erez452133a2015-11-24 09:30:15 +0200264 }
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300265 r->tail = wil_r(wil, RGF_MBOX +
266 offsetof(struct wil6210_mbox_ctl, tx.tail));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800267 if (next_head != r->tail)
268 break;
269 msleep(20);
270 }
271 if (next_head == r->tail) {
272 wil_err(wil, "WMI ring full\n");
Maya Erez349214c2016-04-26 14:41:41 +0300273 rc = -EBUSY;
274 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800275 }
276 dst = wmi_buffer(wil, d_head.addr);
277 if (!dst) {
278 wil_err(wil, "invalid WMI buffer: 0x%08x\n",
279 le32_to_cpu(d_head.addr));
Maya Erez349214c2016-04-26 14:41:41 +0300280 rc = -EAGAIN;
281 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800282 }
283 cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
284 /* set command */
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200285 wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len);
286 wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800287 sizeof(cmd), true);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200288 wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800289 len, true);
290 wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
291 wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
292 /* mark entry as full */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300293 wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800294 /* advance next ptr */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300295 wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
296 r->head = next_head);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800297
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300298 trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
Vladimir Kondratiev98658092013-05-12 14:43:35 +0300299
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800300 /* interrupt to FW */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300301 wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
302 SW_INT_MBOX);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800303
Maya Erez349214c2016-04-26 14:41:41 +0300304out:
305 wil_halp_unvote(wil);
306 return rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800307}
308
309int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len)
310{
311 int rc;
312
313 mutex_lock(&wil->wmi_mutex);
314 rc = __wmi_send(wil, cmdid, buf, len);
315 mutex_unlock(&wil->wmi_mutex);
316
317 return rc;
318}
319
320/*=== Event handlers ===*/
321static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len)
322{
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800323 struct wireless_dev *wdev = wil->wdev;
324 struct wmi_ready_event *evt = d;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300325
Vladimir Kondratievb8023172013-03-13 14:12:50 +0200326 wil->n_mids = evt->numof_additional_mids;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800327
Lior David13cd9f72016-08-22 12:42:22 +0300328 wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
329 wil->fw_version, le32_to_cpu(evt->sw_version),
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300330 evt->mac, wil->n_mids);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200331 /* ignore MAC address, we already have it from the boot loader */
Lior David13cd9f72016-08-22 12:42:22 +0300332 strlcpy(wdev->wiphy->fw_version, wil->fw_version,
333 sizeof(wdev->wiphy->fw_version));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800334
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300335 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200336 set_bit(wil_status_fwready, wil->status);
Dedy Lansky59502642014-09-10 16:34:46 +0300337 /* let the reset sequence continue */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800338 complete(&wil->wmi_ready);
339}
340
341static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
342{
343 struct wmi_rx_mgmt_packet_event *data = d;
344 struct wiphy *wiphy = wil_to_wiphy(wil);
345 struct ieee80211_mgmt *rx_mgmt_frame =
346 (struct ieee80211_mgmt *)data->payload;
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300347 int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
348 int ch_no;
349 u32 freq;
350 struct ieee80211_channel *channel;
351 s32 signal;
352 __le16 fc;
353 u32 d_len;
354 u16 d_status;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800355
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300356 if (flen < 0) {
357 wil_err(wil, "MGMT Rx: short event, len %d\n", len);
358 return;
359 }
360
361 d_len = le32_to_cpu(data->info.len);
362 if (d_len != flen) {
363 wil_err(wil,
364 "MGMT Rx: length mismatch, d_len %d should be %d\n",
365 d_len, flen);
366 return;
367 }
368
369 ch_no = data->info.channel + 1;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200370 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300371 channel = ieee80211_get_channel(wiphy, freq);
372 signal = data->info.sqi;
373 d_status = le16_to_cpu(data->info.status);
374 fc = rx_mgmt_frame->frame_control;
375
376 wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d SNR %d SQI %d%%\n",
Vladimir Kondratievb8b33a32014-02-27 16:20:52 +0200377 data->info.channel, data->info.mcs, data->info.snr,
378 data->info.sqi);
Vladimir Kondratievf27dbf72013-06-09 09:12:52 +0300379 wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
380 le16_to_cpu(fc));
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200381 wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800382 data->info.qid, data->info.mid, data->info.cid);
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300383 wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
384 d_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800385
386 if (!channel) {
387 wil_err(wil, "Frame on unsupported channel\n");
388 return;
389 }
390
391 if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
392 struct cfg80211_bss *bss;
Vladimir Kondratiev8eea9442014-06-16 19:37:03 +0300393 u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
394 u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
395 u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
396 const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
397 size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
398 u.beacon.variable);
399 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
400 wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
401 wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
402 wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
403 ie_len, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800404
Dedy Lanskye6d68342016-03-01 19:18:12 +0200405 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
406
Vladimir Kondratieva0f78452013-03-13 14:12:44 +0200407 bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame,
408 d_len, signal, GFP_KERNEL);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800409 if (bss) {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200410 wil_dbg_wmi(wil, "Added BSS %pM\n",
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800411 rx_mgmt_frame->bssid);
Johannes Berg5b112d32013-02-01 01:49:58 +0100412 cfg80211_put_bss(wiphy, bss);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800413 } else {
Johannes Berg5bc8c1f2014-08-12 21:01:28 +0200414 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800415 }
Vladimir Kondratiev102b1d92013-03-13 14:12:45 +0200416 } else {
Lior David4332cac2016-03-01 19:18:13 +0200417 mutex_lock(&wil->p2p_wdev_mutex);
418 cfg80211_rx_mgmt(wil->radio_wdev, freq, signal,
Vladimir Kondratiev970fdfa2014-08-11 03:29:57 -0700419 (void *)rx_mgmt_frame, d_len, 0);
Lior David4332cac2016-03-01 19:18:13 +0200420 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800421 }
422}
423
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300424static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len)
425{
426 struct wmi_tx_mgmt_packet_event *data = d;
427 struct ieee80211_mgmt *mgmt_frame =
428 (struct ieee80211_mgmt *)data->payload;
429 int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
430
431 wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
432 flen, true);
433}
434
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800435static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id,
436 void *d, int len)
437{
Lior David5ffae432016-08-22 12:42:19 +0300438 mutex_lock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800439 if (wil->scan_request) {
440 struct wmi_scan_complete_event *data = d;
Maya Erez035859a2016-11-23 16:06:42 +0200441 int status = le32_to_cpu(data->status);
Avraham Stern1d762502016-07-05 17:10:13 +0300442 struct cfg80211_scan_info info = {
Maya Erez035859a2016-11-23 16:06:42 +0200443 .aborted = ((status != WMI_SCAN_SUCCESS) &&
444 (status != WMI_SCAN_ABORT_REJECTED)),
Avraham Stern1d762502016-07-05 17:10:13 +0300445 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800446
Maya Erez035859a2016-11-23 16:06:42 +0200447 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300448 wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
Avraham Stern1d762502016-07-05 17:10:13 +0300449 wil->scan_request, info.aborted);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300450 del_timer_sync(&wil->scan_timer);
Avraham Stern1d762502016-07-05 17:10:13 +0300451 cfg80211_scan_done(wil->scan_request, &info);
Lior David4332cac2016-03-01 19:18:13 +0200452 wil->radio_wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800453 wil->scan_request = NULL;
Maya Erez035859a2016-11-23 16:06:42 +0200454 wake_up_interruptible(&wil->wq);
Lior Davidbb6743f72016-11-28 13:49:00 +0200455 if (wil->p2p.pending_listen_wdev) {
456 wil_dbg_misc(wil, "Scheduling delayed listen\n");
457 schedule_work(&wil->p2p.delayed_listen_work);
458 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800459 } else {
460 wil_err(wil, "SCAN_COMPLETE while not scanning\n");
461 }
Lior David5ffae432016-08-22 12:42:19 +0300462 mutex_unlock(&wil->p2p_wdev_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800463}
464
465static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len)
466{
467 struct net_device *ndev = wil_to_ndev(wil);
468 struct wireless_dev *wdev = wil->wdev;
469 struct wmi_connect_event *evt = d;
470 int ch; /* channel number */
471 struct station_info sinfo;
472 u8 *assoc_req_ie, *assoc_resp_ie;
473 size_t assoc_req_ielen, assoc_resp_ielen;
474 /* capinfo(u16) + listen_interval(u16) + IEs */
475 const size_t assoc_req_ie_offset = sizeof(u16) * 2;
476 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
477 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
Maya Erez0916d9f2016-01-17 12:39:10 +0200478 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800479
480 if (len < sizeof(*evt)) {
481 wil_err(wil, "Connect event too short : %d bytes\n", len);
482 return;
483 }
484 if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
485 evt->assoc_resp_len) {
486 wil_err(wil,
487 "Connect event corrupted : %d != %d + %d + %d + %d\n",
488 len, (int)sizeof(*evt), evt->beacon_ie_len,
489 evt->assoc_req_len, evt->assoc_resp_len);
490 return;
491 }
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200492 if (evt->cid >= WIL6210_MAX_CID) {
493 wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
494 return;
495 }
496
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800497 ch = evt->channel + 1;
Lior David9d865ee2017-01-20 13:49:51 +0200498 wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n",
499 evt->bssid, ch, evt->cid, evt->aid);
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200500 wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800501 evt->assoc_info, len - sizeof(*evt), true);
502
503 /* figure out IE's */
504 assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
505 assoc_req_ie_offset];
506 assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
507 if (evt->assoc_req_len <= assoc_req_ie_offset) {
508 assoc_req_ie = NULL;
509 assoc_req_ielen = 0;
510 }
511
512 assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
513 evt->assoc_req_len +
514 assoc_resp_ie_offset];
515 assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
516 if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
517 assoc_resp_ie = NULL;
518 assoc_resp_ielen = 0;
519 }
520
Maya Erez0916d9f2016-01-17 12:39:10 +0200521 mutex_lock(&wil->mutex);
522 if (test_bit(wil_status_resetting, wil->status) ||
523 !test_bit(wil_status_fwready, wil->status)) {
524 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
525 evt->cid);
526 mutex_unlock(&wil->mutex);
527 /* no need for cleanup, wil_reset will do that */
528 return;
529 }
530
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800531 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
532 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200533 if (!test_bit(wil_status_fwconnecting, wil->status)) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800534 wil_err(wil, "Not in connecting state\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200535 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800536 return;
537 }
538 del_timer_sync(&wil->connect_timer);
Maya Erez3d287fb2016-03-01 19:18:05 +0200539 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
540 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
541 if (wil->sta[evt->cid].status != wil_sta_unused) {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200542 wil_err(wil, "AP: Invalid status %d for CID %d\n",
543 wil->sta[evt->cid].status, evt->cid);
Maya Erez3d287fb2016-03-01 19:18:05 +0200544 mutex_unlock(&wil->mutex);
545 return;
546 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200547 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800548
Maya Erez0916d9f2016-01-17 12:39:10 +0200549 /* FIXME FW can transmit only ucast frames to peer */
550 /* FIXME real ring_id instead of hard coded 0 */
551 ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
552 wil->sta[evt->cid].status = wil_sta_conn_pending;
553
554 rc = wil_tx_init(wil, evt->cid);
555 if (rc) {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200556 wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n",
557 evt->cid, rc);
Maya Erez0916d9f2016-01-17 12:39:10 +0200558 wmi_disconnect_sta(wil, wil->sta[evt->cid].addr,
Dedy Lansky849a5642017-01-20 13:49:44 +0200559 WLAN_REASON_UNSPECIFIED, false, false);
Maya Erez0916d9f2016-01-17 12:39:10 +0200560 } else {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200561 wil_info(wil, "successful connection to CID %d\n", evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200562 }
563
564 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
565 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
566 if (rc) {
Maya Erez0916d9f2016-01-17 12:39:10 +0200567 netif_carrier_off(ndev);
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200568 wil_err(wil, "cfg80211_connect_result with failure\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200569 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
570 NULL, 0,
571 WLAN_STATUS_UNSPECIFIED_FAILURE,
572 GFP_KERNEL);
573 goto out;
574 } else {
575 cfg80211_connect_result(ndev, evt->bssid,
576 assoc_req_ie, assoc_req_ielen,
577 assoc_resp_ie, assoc_resp_ielen,
578 WLAN_STATUS_SUCCESS,
579 GFP_KERNEL);
580 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800581 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
582 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
Dedy Lansky849a5642017-01-20 13:49:44 +0200583 if (rc) {
584 if (disable_ap_sme)
585 /* notify new_sta has failed */
586 cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200587 goto out;
Dedy Lansky849a5642017-01-20 13:49:44 +0200588 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200589
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800590 memset(&sinfo, 0, sizeof(sinfo));
591
592 sinfo.generation = wil->sinfo_gen++;
593
594 if (assoc_req_ie) {
595 sinfo.assoc_req_ies = assoc_req_ie;
596 sinfo.assoc_req_ies_len = assoc_req_ielen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800597 }
598
599 cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200600 } else {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200601 wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
602 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200603 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800604 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200605
606 wil->sta[evt->cid].status = wil_sta_connected;
Lior David9d865ee2017-01-20 13:49:51 +0200607 wil->sta[evt->cid].aid = evt->aid;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200608 set_bit(wil_status_fwconnected, wil->status);
Dedy Lanskyf9e30332016-11-23 16:06:40 +0200609 wil_update_net_queues_bh(wil, NULL, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800610
Maya Erez0916d9f2016-01-17 12:39:10 +0200611out:
612 if (rc)
613 wil->sta[evt->cid].status = wil_sta_unused;
614 clear_bit(wil_status_fwconnecting, wil->status);
615 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800616}
617
618static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
619 void *d, int len)
620{
621 struct wmi_disconnect_event *evt = d;
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200622 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800623
Maya Erez0916d9f2016-01-17 12:39:10 +0200624 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
625 evt->bssid, reason_code, evt->disconnect_reason);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800626
627 wil->sinfo_gen++;
628
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200629 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200630 wil6210_disconnect(wil, evt->bssid, reason_code, true);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200631 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800632}
633
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800634/*
635 * Firmware reports EAPOL frame using WME event.
636 * Reconstruct Ethernet frame and deliver it via normal Rx
637 */
638static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
639 void *d, int len)
640{
641 struct net_device *ndev = wil_to_ndev(wil);
642 struct wmi_eapol_rx_event *evt = d;
643 u16 eapol_len = le16_to_cpu(evt->eapol_len);
644 int sz = eapol_len + ETH_HLEN;
645 struct sk_buff *skb;
646 struct ethhdr *eth;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200647 int cid;
648 struct wil_net_stats *stats = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800649
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200650 wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800651 evt->src_mac);
652
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200653 cid = wil_find_cid(wil, evt->src_mac);
654 if (cid >= 0)
655 stats = &wil->sta[cid].stats;
656
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800657 if (eapol_len > 196) { /* TODO: revisit size limit */
658 wil_err(wil, "EAPOL too large\n");
659 return;
660 }
661
662 skb = alloc_skb(sz, GFP_KERNEL);
663 if (!skb) {
664 wil_err(wil, "Failed to allocate skb\n");
665 return;
666 }
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200667
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800668 eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200669 ether_addr_copy(eth->h_dest, ndev->dev_addr);
670 ether_addr_copy(eth->h_source, evt->src_mac);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800671 eth->h_proto = cpu_to_be16(ETH_P_PAE);
672 memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len);
673 skb->protocol = eth_type_trans(skb, ndev);
674 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
675 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200676 ndev->stats.rx_bytes += sz;
677 if (stats) {
678 stats->rx_packets++;
679 stats->rx_bytes += sz;
680 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800681 } else {
682 ndev->stats.rx_dropped++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200683 if (stats)
684 stats->rx_dropped++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800685 }
686}
687
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300688static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200689{
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300690 struct wmi_vring_en_event *evt = d;
691 u8 vri = evt->vring_index;
Dedy Lansky849a5642017-01-20 13:49:44 +0200692 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200693
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300694 wil_dbg_wmi(wil, "Enable vring %d\n", vri);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200695
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300696 if (vri >= ARRAY_SIZE(wil->vring_tx)) {
697 wil_err(wil, "Enable for invalid vring %d\n", vri);
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200698 return;
699 }
Dedy Lansky849a5642017-01-20 13:49:44 +0200700
701 if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme)
702 /* in AP mode with disable_ap_sme, this is done by
703 * wil_cfg80211_change_station()
704 */
705 wil->vring_tx_data[vri].dot1x_open = true;
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300706 if (vri == wil->bcast_vring) /* no BA for bcast */
707 return;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200708 if (agg_wsize >= 0)
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300709 wil_addba_tx_request(wil, vri, agg_wsize);
Vladimir Kondratiev3442a502013-03-13 14:12:39 +0200710}
711
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200712static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
713 int len)
714{
Lior Davidb874dde2016-03-01 19:18:09 +0200715 struct wmi_ba_status_event *evt = d;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200716 struct vring_tx_data *txdata;
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200717
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200718 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200719 evt->ringid,
720 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200721 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
722 evt->amsdu ? "+" : "-");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200723
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200724 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
725 wil_err(wil, "invalid ring id %d\n", evt->ringid);
726 return;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200727 }
728
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200729 if (evt->status != WMI_BA_AGREED) {
730 evt->ba_timeout = 0;
731 evt->agg_wsize = 0;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200732 evt->amsdu = 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200733 }
Dedy Lansky8c86f752014-09-10 16:34:40 +0300734
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200735 txdata = &wil->vring_tx_data[evt->ringid];
736
737 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
738 txdata->agg_wsize = evt->agg_wsize;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200739 txdata->agg_amsdu = evt->amsdu;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200740 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200741}
742
743static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d,
744 int len)
745{
746 struct wmi_rcp_addba_req_event *evt = d;
747
748 wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token,
749 evt->ba_param_set, evt->ba_timeout,
750 evt->ba_seq_ctrl);
751}
752
753static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200754__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200755{
756 struct wmi_delba_event *evt = d;
757 u8 cid, tid;
758 u16 reason = __le16_to_cpu(evt->reason);
759 struct wil_sta_info *sta;
760 struct wil_tid_ampdu_rx *r;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200761
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200762 might_sleep();
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200763 parse_cidxtid(evt->cidxtid, &cid, &tid);
764 wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n",
765 cid, tid,
766 evt->from_initiator ? "originator" : "recipient",
767 reason);
768 if (!evt->from_initiator) {
769 int i;
770 /* find Tx vring it belongs to */
771 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
772 if ((wil->vring2cid_tid[i][0] == cid) &&
773 (wil->vring2cid_tid[i][1] == tid)) {
774 struct vring_tx_data *txdata =
775 &wil->vring_tx_data[i];
776
777 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
778 txdata->agg_timeout = 0;
779 txdata->agg_wsize = 0;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200780 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200781
782 break; /* max. 1 matching ring */
783 }
784 }
785 if (i >= ARRAY_SIZE(wil->vring2cid_tid))
786 wil_err(wil, "DELBA: unable to find Tx vring\n");
787 return;
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200788 }
789
790 sta = &wil->sta[cid];
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200791
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200792 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300793
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200794 r = sta->tid_rx[tid];
795 sta->tid_rx[tid] = NULL;
796 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300797
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200798 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200799}
800
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200801/**
802 * Some events are ignored for purpose; and need not be interpreted as
803 * "unhandled events"
804 */
805static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len)
806{
807 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
808}
809
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800810static const struct {
811 int eventid;
812 void (*handler)(struct wil6210_priv *wil, int eventid,
813 void *data, int data_len);
814} wmi_evt_handlers[] = {
815 {WMI_READY_EVENTID, wmi_evt_ready},
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200816 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800817 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300818 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800819 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
820 {WMI_CONNECT_EVENTID, wmi_evt_connect},
821 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800822 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200823 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200824 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
825 {WMI_DELBA_EVENTID, wmi_evt_delba},
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300826 {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200827 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800828};
829
830/*
831 * Run in IRQ context
832 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
833 * that will be eventually handled by the @wmi_event_worker in the thread
834 * context of thread "wil6210_wmi"
835 */
836void wmi_recv_cmd(struct wil6210_priv *wil)
837{
838 struct wil6210_mbox_ring_desc d_tail;
839 struct wil6210_mbox_hdr hdr;
840 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
841 struct pending_wmi_event *evt;
842 u8 *cmd;
843 void __iomem *src;
844 ulong flags;
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300845 unsigned n;
Maya Erez0916d9f2016-01-17 12:39:10 +0200846 unsigned int num_immed_reply = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800847
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200848 if (!test_bit(wil_status_mbox_ready, wil->status)) {
Dedy Lansky4cf99c92014-09-10 16:34:41 +0300849 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
Vladimir Kondratiev55f7acd2013-03-13 14:12:49 +0200850 return;
851 }
852
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300853 for (n = 0;; n++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800854 u16 len;
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300855 bool q;
Maya Erez0916d9f2016-01-17 12:39:10 +0200856 bool immed_reply = false;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800857
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300858 r->head = wil_r(wil, RGF_MBOX +
859 offsetof(struct wil6210_mbox_ctl, rx.head));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300860 if (r->tail == r->head)
861 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800862
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300863 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
864 r->head, r->tail);
865 /* read cmd descriptor from tail */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800866 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
867 sizeof(struct wil6210_mbox_ring_desc));
868 if (d_tail.sync == 0) {
869 wil_err(wil, "Mbox evt not owned by FW?\n");
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300870 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800871 }
872
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300873 /* read cmd header from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800874 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
875 wil_err(wil, "Mbox evt at 0x%08x?\n",
876 le32_to_cpu(d_tail.addr));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300877 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800878 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800879 len = le16_to_cpu(hdr.len);
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300880 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
881 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
882 hdr.flags);
883
884 /* read cmd buffer from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800885 src = wmi_buffer(wil, d_tail.addr) +
886 sizeof(struct wil6210_mbox_hdr);
887 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
888 event.wmi) + len, 4),
889 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000890 if (!evt)
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300891 break;
Joe Perches14f8dc42013-02-07 11:46:27 +0000892
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800893 evt->event.hdr = hdr;
894 cmd = (void *)&evt->event.wmi;
895 wil_memcpy_fromio_32(cmd, src, len);
896 /* mark entry as empty */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300897 wil_w(wil, r->tail +
898 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800899 /* indicate */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800900 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +0200901 (len >= sizeof(struct wmi_cmd_hdr))) {
902 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
903 u16 id = le16_to_cpu(wmi->command_id);
904 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
Maya Erezfe5c2712016-01-28 19:24:04 +0200905 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
Maya Erez0916d9f2016-01-17 12:39:10 +0200906 if (wil->reply_id && wil->reply_id == id) {
907 if (wil->reply_buf) {
908 memcpy(wil->reply_buf, wmi,
909 min(len, wil->reply_size));
910 immed_reply = true;
911 }
912 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200913 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300914
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300915 wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
916 id, wmi->mid, tstamp);
917 trace_wil6210_wmi_event(wmi, &wmi[1],
918 len - sizeof(*wmi));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800919 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200920 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800921 &evt->event.hdr, sizeof(hdr) + len, true);
922
923 /* advance tail */
924 r->tail = r->base + ((r->tail - r->base +
925 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300926 wil_w(wil, RGF_MBOX +
927 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800928
Maya Erez0916d9f2016-01-17 12:39:10 +0200929 if (immed_reply) {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200930 wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
931 wil->reply_id);
Maya Erez0916d9f2016-01-17 12:39:10 +0200932 kfree(evt);
933 num_immed_reply++;
934 complete(&wil->wmi_call);
935 } else {
936 /* add to the pending list */
937 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
938 list_add_tail(&evt->list, &wil->pending_wmi_ev);
939 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
940 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
941 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
942 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800943 }
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300944 /* normally, 1 event per IRQ should be processed */
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200945 wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
Maya Erez0916d9f2016-01-17 12:39:10 +0200946 n - num_immed_reply, num_immed_reply);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800947}
948
949int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
950 u16 reply_id, void *reply, u8 reply_size, int to_msec)
951{
952 int rc;
Nicholas Mc Guiref4bbb822015-08-13 15:38:31 +0300953 unsigned long remain;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800954
955 mutex_lock(&wil->wmi_mutex);
956
Maya Erezfe5c2712016-01-28 19:24:04 +0200957 spin_lock(&wil->wmi_ev_lock);
958 wil->reply_id = reply_id;
959 wil->reply_buf = reply;
960 wil->reply_size = reply_size;
Lior David4d4c4dc2017-01-20 13:49:48 +0200961 reinit_completion(&wil->wmi_call);
Maya Erezfe5c2712016-01-28 19:24:04 +0200962 spin_unlock(&wil->wmi_ev_lock);
963
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800964 rc = __wmi_send(wil, cmdid, buf, len);
965 if (rc)
966 goto out;
967
Dedy Lansky59502642014-09-10 16:34:46 +0300968 remain = wait_for_completion_timeout(&wil->wmi_call,
969 msecs_to_jiffies(to_msec));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800970 if (0 == remain) {
971 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
972 cmdid, reply_id, to_msec);
973 rc = -ETIME;
974 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200975 wil_dbg_wmi(wil,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800976 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
977 cmdid, reply_id,
978 to_msec - jiffies_to_msecs(remain));
979 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200980
981out:
982 spin_lock(&wil->wmi_ev_lock);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800983 wil->reply_id = 0;
984 wil->reply_buf = NULL;
985 wil->reply_size = 0;
Maya Erezfe5c2712016-01-28 19:24:04 +0200986 spin_unlock(&wil->wmi_ev_lock);
987
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800988 mutex_unlock(&wil->wmi_mutex);
989
990 return rc;
991}
992
993int wmi_echo(struct wil6210_priv *wil)
994{
995 struct wmi_echo_cmd cmd = {
996 .value = cpu_to_le32(0x12345678),
997 };
998
999 return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratieva54a40d2015-04-30 16:25:05 +03001000 WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001001}
1002
1003int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
1004{
1005 struct wmi_set_mac_address_cmd cmd;
1006
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001007 ether_addr_copy(cmd.mac, addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001008
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001009 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001010
1011 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
1012}
1013
Maya Erez10d599a2016-05-09 21:57:11 +03001014int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
1015{
1016 int rc = 0;
1017 struct wmi_led_cfg_cmd cmd = {
1018 .led_mode = enable,
1019 .id = led_id,
1020 .slow_blink_cfg.blink_on =
1021 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
1022 .slow_blink_cfg.blink_off =
1023 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
1024 .medium_blink_cfg.blink_on =
1025 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
1026 .medium_blink_cfg.blink_off =
1027 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
1028 .fast_blink_cfg.blink_on =
1029 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
1030 .fast_blink_cfg.blink_off =
1031 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
1032 .led_polarity = led_polarity,
1033 };
1034 struct {
1035 struct wmi_cmd_hdr wmi;
1036 struct wmi_led_cfg_done_event evt;
1037 } __packed reply;
1038
1039 if (led_id == WIL_LED_INVALID_ID)
1040 goto out;
1041
1042 if (led_id > WIL_LED_MAX_ID) {
1043 wil_err(wil, "Invalid led id %d\n", led_id);
1044 rc = -EINVAL;
1045 goto out;
1046 }
1047
1048 wil_dbg_wmi(wil,
1049 "%s led %d\n",
1050 enable ? "enabling" : "disabling", led_id);
1051
1052 rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd),
1053 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
1054 100);
1055 if (rc)
1056 goto out;
1057
1058 if (reply.evt.status) {
1059 wil_err(wil, "led %d cfg failed with status %d\n",
1060 led_id, le32_to_cpu(reply.evt.status));
1061 rc = -EINVAL;
1062 }
1063
1064out:
1065 return rc;
1066}
1067
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001068int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype,
Lior Davidb4944f22016-03-01 19:18:17 +02001069 u8 chan, u8 hidden_ssid, u8 is_go)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001070{
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001071 int rc;
1072
1073 struct wmi_pcp_start_cmd cmd = {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001074 .bcon_interval = cpu_to_le16(bi),
1075 .network_type = wmi_nettype,
1076 .disable_sec_offload = 1,
Vladimir Kondratievadc2d122013-05-28 15:17:52 +03001077 .channel = chan - 1,
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001078 .pcp_max_assoc_sta = max_assoc_sta,
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001079 .hidden_ssid = hidden_ssid,
Lior Davidb4944f22016-03-01 19:18:17 +02001080 .is_go = is_go,
Dedy Lansky849a5642017-01-20 13:49:44 +02001081 .disable_ap_sme = disable_ap_sme,
Lior Davidc3bfea02017-01-20 13:49:52 +02001082 .abft_len = wil->abft_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001083 };
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001084 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001085 struct wmi_cmd_hdr wmi;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001086 struct wmi_pcp_started_event evt;
1087 } __packed reply;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001088
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001089 if (!wil->privacy)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001090 cmd.disable_sec = 1;
1091
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001092 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
1093 (cmd.pcp_max_assoc_sta <= 0)) {
1094 wil_info(wil,
1095 "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
1096 max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
1097 cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
1098 }
1099
Dedy Lansky849a5642017-01-20 13:49:44 +02001100 if (disable_ap_sme &&
1101 !test_bit(WMI_FW_CAPABILITY_DISABLE_AP_SME,
1102 wil->fw_capabilities)) {
1103 wil_err(wil, "disable_ap_sme not supported by FW\n");
1104 return -EOPNOTSUPP;
1105 }
1106
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001107 /*
1108 * Processing time may be huge, in case of secure AP it takes about
1109 * 3500ms for FW to start AP
1110 */
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001111 rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001112 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001113 if (rc)
1114 return rc;
1115
1116 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
1117 rc = -EINVAL;
1118
Maya Erez10d599a2016-05-09 21:57:11 +03001119 if (wmi_nettype != WMI_NETTYPE_P2P)
1120 /* Don't fail due to error in the led configuration */
1121 wmi_led_cfg(wil, true);
1122
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001123 return rc;
1124}
1125
1126int wmi_pcp_stop(struct wil6210_priv *wil)
1127{
Maya Erez10d599a2016-05-09 21:57:11 +03001128 int rc;
1129
1130 rc = wmi_led_cfg(wil, false);
1131 if (rc)
1132 return rc;
1133
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001134 return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
1135 WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001136}
1137
1138int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
1139{
1140 struct wmi_set_ssid_cmd cmd = {
1141 .ssid_len = cpu_to_le32(ssid_len),
1142 };
1143
1144 if (ssid_len > sizeof(cmd.ssid))
1145 return -EINVAL;
1146
1147 memcpy(cmd.ssid, ssid, ssid_len);
1148
1149 return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
1150}
1151
1152int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
1153{
1154 int rc;
1155 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001156 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001157 struct wmi_set_ssid_cmd cmd;
1158 } __packed reply;
1159 int len; /* reply.cmd.ssid_len in CPU order */
1160
1161 rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
1162 &reply, sizeof(reply), 20);
1163 if (rc)
1164 return rc;
1165
1166 len = le32_to_cpu(reply.cmd.ssid_len);
1167 if (len > sizeof(reply.cmd.ssid))
1168 return -EINVAL;
1169
1170 *ssid_len = len;
1171 memcpy(ssid, reply.cmd.ssid, len);
1172
1173 return 0;
1174}
1175
1176int wmi_set_channel(struct wil6210_priv *wil, int channel)
1177{
1178 struct wmi_set_pcp_channel_cmd cmd = {
1179 .channel = channel - 1,
1180 };
1181
1182 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
1183}
1184
1185int wmi_get_channel(struct wil6210_priv *wil, int *channel)
1186{
1187 int rc;
1188 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001189 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001190 struct wmi_set_pcp_channel_cmd cmd;
1191 } __packed reply;
1192
1193 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
1194 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
1195 if (rc)
1196 return rc;
1197
1198 if (reply.cmd.channel > 3)
1199 return -EINVAL;
1200
1201 *channel = reply.cmd.channel + 1;
1202
1203 return 0;
1204}
1205
Dedy Lanskye6d68342016-03-01 19:18:12 +02001206int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi)
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001207{
Dedy Lanskye6d68342016-03-01 19:18:12 +02001208 int rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001209 struct wmi_p2p_cfg_cmd cmd = {
Dedy Lanskye6d68342016-03-01 19:18:12 +02001210 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
1211 .bcon_interval = cpu_to_le16(bi),
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001212 .channel = channel - 1,
1213 };
Dedy Lanskye6d68342016-03-01 19:18:12 +02001214 struct {
1215 struct wmi_cmd_hdr wmi;
1216 struct wmi_p2p_cfg_done_event evt;
1217 } __packed reply;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001218
Dedy Lanskye6d68342016-03-01 19:18:12 +02001219 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
1220
1221 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd),
1222 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
1223 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1224 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
1225 rc = -EINVAL;
1226 }
1227
1228 return rc;
1229}
1230
1231int wmi_start_listen(struct wil6210_priv *wil)
1232{
1233 int rc;
1234 struct {
1235 struct wmi_cmd_hdr wmi;
1236 struct wmi_listen_started_event evt;
1237 } __packed reply;
1238
1239 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
1240
1241 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1242 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
1243 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1244 wil_err(wil, "device failed to start listen. status %d\n",
1245 reply.evt.status);
1246 rc = -EINVAL;
1247 }
1248
1249 return rc;
1250}
1251
1252int wmi_start_search(struct wil6210_priv *wil)
1253{
1254 int rc;
1255 struct {
1256 struct wmi_cmd_hdr wmi;
1257 struct wmi_search_started_event evt;
1258 } __packed reply;
1259
1260 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
1261
1262 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0,
1263 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
1264 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1265 wil_err(wil, "device failed to start search. status %d\n",
1266 reply.evt.status);
1267 rc = -EINVAL;
1268 }
1269
1270 return rc;
1271}
1272
1273int wmi_stop_discovery(struct wil6210_priv *wil)
1274{
1275 int rc;
1276
1277 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
1278
1279 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1280 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
1281
1282 if (rc)
1283 wil_err(wil, "Failed to stop discovery\n");
1284
1285 return rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001286}
1287
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001288int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001289 const void *mac_addr, int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001290{
1291 struct wmi_delete_cipher_key_cmd cmd = {
1292 .key_index = key_index,
1293 };
1294
1295 if (mac_addr)
1296 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1297
1298 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1299}
1300
1301int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001302 const void *mac_addr, int key_len, const void *key,
1303 int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001304{
1305 struct wmi_add_cipher_key_cmd cmd = {
1306 .key_index = key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001307 .key_usage = key_usage,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001308 .key_len = key_len,
1309 };
1310
1311 if (!key || (key_len > sizeof(cmd.key)))
1312 return -EINVAL;
1313
1314 memcpy(cmd.key, key, key_len);
1315 if (mac_addr)
1316 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1317
1318 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1319}
1320
1321int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
1322{
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001323 static const char *const names[] = {
1324 [WMI_FRAME_BEACON] = "BEACON",
1325 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
1326 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
1327 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
1328 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
1329 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001330 int rc;
1331 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
1332 struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001333
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001334 if (!cmd) {
1335 rc = -ENOMEM;
1336 goto out;
1337 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +03001338 if (!ie)
1339 ie_len = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001340
1341 cmd->mgmt_frm_type = type;
1342 /* BUG: FW API define ieLen as u8. Will fix FW */
1343 cmd->ie_len = cpu_to_le16(ie_len);
1344 memcpy(cmd->ie_info, ie, ie_len);
Vladimir Kondratiev03866e72013-03-13 14:12:42 +02001345 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001346 kfree(cmd);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001347out:
1348 if (rc) {
1349 const char *name = type < ARRAY_SIZE(names) ?
1350 names[type] : "??";
1351 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
1352 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001353
1354 return rc;
1355}
1356
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001357/**
1358 * wmi_rxon - turn radio on/off
1359 * @on: turn on if true, off otherwise
1360 *
1361 * Only switch radio. Channel should be set separately.
1362 * No timeout for rxon - radio turned on forever unless some other call
1363 * turns it off
1364 */
1365int wmi_rxon(struct wil6210_priv *wil, bool on)
1366{
1367 int rc;
1368 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001369 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001370 struct wmi_listen_started_event evt;
1371 } __packed reply;
1372
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001373 wil_info(wil, "(%s)\n", on ? "on" : "off");
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001374
1375 if (on) {
1376 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1377 WMI_LISTEN_STARTED_EVENTID,
1378 &reply, sizeof(reply), 100);
1379 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
1380 rc = -EINVAL;
1381 } else {
1382 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1383 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
1384 }
1385
1386 return rc;
1387}
1388
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001389int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1390{
1391 struct wireless_dev *wdev = wil->wdev;
1392 struct net_device *ndev = wil_to_ndev(wil);
1393 struct wmi_cfg_rx_chain_cmd cmd = {
1394 .action = WMI_RX_CHAIN_ADD,
1395 .rx_sw_ring = {
Vladimir Kondratievc44690a2014-12-23 09:47:11 +02001396 .max_mpdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001397 .ring_mem_base = cpu_to_le64(vring->pa),
1398 .ring_size = cpu_to_le16(vring->size),
1399 },
1400 .mid = 0, /* TODO - what is it? */
1401 .decap_trans_type = WMI_DECAP_TYPE_802_3,
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001402 .reorder_type = WMI_RX_SW_REORDER,
Vladimir Kondratievab954622014-12-23 09:47:20 +02001403 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001404 };
1405 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001406 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001407 struct wmi_cfg_rx_chain_done_event evt;
1408 } __packed evt;
1409 int rc;
1410
1411 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
1412 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
1413
1414 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
1415 if (ch)
1416 cmd.sniffer_cfg.channel = ch->hw_value - 1;
1417 cmd.sniffer_cfg.phy_info_mode =
1418 cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
1419 cmd.sniffer_cfg.phy_support =
1420 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
Vladimir Kondratiev47653322015-10-04 10:23:24 +03001421 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +03001422 } else {
1423 /* Initialize offload (in non-sniffer mode).
1424 * Linux IP stack always calculates IP checksum
1425 * HW always calculate TCP/UDP checksum
1426 */
1427 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001428 }
Vladimir Kondratievc406ea72015-03-15 16:00:19 +02001429
1430 if (rx_align_2)
1431 cmd.l2_802_3_offload_ctrl |=
1432 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
1433
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001434 /* typical time for secure PCP is 840ms */
1435 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
1436 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
1437 if (rc)
1438 return rc;
1439
1440 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
1441
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001442 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001443 le32_to_cpu(evt.evt.status), vring->hwtail);
1444
1445 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
1446 rc = -EINVAL;
1447
1448 return rc;
1449}
1450
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001451int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001452{
1453 int rc;
1454 struct wmi_temp_sense_cmd cmd = {
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001455 .measure_baseband_en = cpu_to_le32(!!t_bb),
1456 .measure_rf_en = cpu_to_le32(!!t_rf),
1457 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001458 };
1459 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001460 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001461 struct wmi_temp_sense_done_event evt;
1462 } __packed reply;
1463
1464 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
1465 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
1466 if (rc)
1467 return rc;
1468
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001469 if (t_bb)
1470 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
1471 if (t_rf)
1472 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001473
1474 return 0;
1475}
1476
Dedy Lansky849a5642017-01-20 13:49:44 +02001477int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac,
1478 u16 reason, bool full_disconnect, bool del_sta)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001479{
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001480 int rc;
1481 u16 reason_code;
Dedy Lansky849a5642017-01-20 13:49:44 +02001482 struct wmi_disconnect_sta_cmd disc_sta_cmd = {
1483 .disconnect_reason = cpu_to_le16(reason),
1484 };
1485 struct wmi_del_sta_cmd del_sta_cmd = {
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001486 .disconnect_reason = cpu_to_le16(reason),
1487 };
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001488 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001489 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001490 struct wmi_disconnect_event evt;
1491 } __packed reply;
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001492
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001493 wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001494
Dedy Lansky849a5642017-01-20 13:49:44 +02001495 if (del_sta) {
1496 ether_addr_copy(del_sta_cmd.dst_mac, mac);
1497 rc = wmi_call(wil, WMI_DEL_STA_CMDID, &del_sta_cmd,
1498 sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
1499 &reply, sizeof(reply), 1000);
1500 } else {
1501 ether_addr_copy(disc_sta_cmd.dst_mac, mac);
1502 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &disc_sta_cmd,
1503 sizeof(disc_sta_cmd), WMI_DISCONNECT_EVENTID,
1504 &reply, sizeof(reply), 1000);
1505 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001506 /* failure to disconnect in reasonable time treated as FW error */
1507 if (rc) {
1508 wil_fw_error_recovery(wil);
1509 return rc;
1510 }
1511
Maya Erez0916d9f2016-01-17 12:39:10 +02001512 if (full_disconnect) {
1513 /* call event handler manually after processing wmi_call,
1514 * to avoid deadlock - disconnect event handler acquires
1515 * wil->mutex while it is already held here
1516 */
1517 reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001518
Maya Erez0916d9f2016-01-17 12:39:10 +02001519 wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1520 reply.evt.bssid, reason_code,
1521 reply.evt.disconnect_reason);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001522
Maya Erez0916d9f2016-01-17 12:39:10 +02001523 wil->sinfo_gen++;
1524 wil6210_disconnect(wil, reply.evt.bssid, reason_code, true);
1525 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001526 return 0;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001527}
1528
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001529int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout)
1530{
1531 struct wmi_vring_ba_en_cmd cmd = {
1532 .ringid = ringid,
1533 .agg_max_wsize = size,
1534 .ba_timeout = cpu_to_le16(timeout),
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +02001535 .amsdu = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001536 };
1537
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001538 wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size,
1539 timeout);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001540
1541 return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd));
1542}
1543
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001544int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason)
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001545{
1546 struct wmi_vring_ba_dis_cmd cmd = {
1547 .ringid = ringid,
1548 .reason = cpu_to_le16(reason),
1549 };
1550
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001551 wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001552
1553 return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd));
1554}
1555
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001556int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason)
1557{
1558 struct wmi_rcp_delba_cmd cmd = {
1559 .cidxtid = cidxtid,
1560 .reason = cpu_to_le16(reason),
1561 };
1562
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001563 wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf,
1564 (cidxtid >> 4) & 0xf, reason);
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001565
1566 return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd));
1567}
1568
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001569int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
1570 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
1571{
1572 int rc;
1573 struct wmi_rcp_addba_resp_cmd cmd = {
1574 .cidxtid = mk_cidxtid(cid, tid),
1575 .dialog_token = token,
1576 .status_code = cpu_to_le16(status),
1577 /* bit 0: A-MSDU supported
1578 * bit 1: policy (should be 0 for us)
1579 * bits 2..5: TID
1580 * bits 6..15: buffer size
1581 */
1582 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
1583 (agg_wsize << 6)),
1584 .ba_timeout = cpu_to_le16(timeout),
1585 };
1586 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001587 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001588 struct wmi_rcp_addba_resp_sent_event evt;
1589 } __packed reply;
1590
1591 wil_dbg_wmi(wil,
1592 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
1593 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-");
1594
1595 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001596 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
1597 100);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001598 if (rc)
1599 return rc;
1600
1601 if (reply.evt.status) {
1602 wil_err(wil, "ADDBA response failed with status %d\n",
1603 le16_to_cpu(reply.evt.status));
1604 rc = -EINVAL;
1605 }
1606
1607 return rc;
1608}
1609
Maya Erez2c207eb2016-11-23 16:06:40 +02001610int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
1611 enum wmi_ps_profile_type ps_profile)
1612{
1613 int rc;
1614 struct wmi_ps_dev_profile_cfg_cmd cmd = {
1615 .ps_profile = ps_profile,
1616 };
1617 struct {
1618 struct wmi_cmd_hdr wmi;
1619 struct wmi_ps_dev_profile_cfg_event evt;
1620 } __packed reply;
1621 u32 status;
1622
1623 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
1624
1625 reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR);
1626
1627 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd),
1628 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
1629 100);
1630 if (rc)
1631 return rc;
1632
1633 status = le32_to_cpu(reply.evt.status);
1634
1635 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
1636 wil_err(wil, "ps dev profile cfg failed with status %d\n",
1637 status);
1638 rc = -EINVAL;
1639 }
1640
1641 return rc;
1642}
1643
Lior David3fea18d2016-11-23 16:06:43 +02001644int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
1645{
1646 int rc;
1647 struct wmi_set_mgmt_retry_limit_cmd cmd = {
1648 .mgmt_retry_limit = retry_short,
1649 };
1650 struct {
1651 struct wmi_cmd_hdr wmi;
1652 struct wmi_set_mgmt_retry_limit_event evt;
1653 } __packed reply;
1654
1655 wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
1656
1657 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1658 return -ENOTSUPP;
1659
1660 reply.evt.status = WMI_FW_STATUS_FAILURE;
1661
1662 rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd),
1663 WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1664 100);
1665 if (rc)
1666 return rc;
1667
1668 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1669 wil_err(wil, "set mgmt retry limit failed with status %d\n",
1670 reply.evt.status);
1671 rc = -EINVAL;
1672 }
1673
1674 return rc;
1675}
1676
1677int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
1678{
1679 int rc;
1680 struct {
1681 struct wmi_cmd_hdr wmi;
1682 struct wmi_get_mgmt_retry_limit_event evt;
1683 } __packed reply;
1684
1685 wil_dbg_wmi(wil, "getting mgmt retry short\n");
1686
1687 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1688 return -ENOTSUPP;
1689
1690 reply.evt.mgmt_retry_limit = 0;
1691 rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0,
1692 WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1693 100);
1694 if (rc)
1695 return rc;
1696
1697 if (retry_short)
1698 *retry_short = reply.evt.mgmt_retry_limit;
1699
1700 return 0;
1701}
1702
Maya Erez035859a2016-11-23 16:06:42 +02001703int wmi_abort_scan(struct wil6210_priv *wil)
1704{
1705 int rc;
1706
1707 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
1708
1709 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0);
1710 if (rc)
1711 wil_err(wil, "Failed to abort scan (%d)\n", rc);
1712
1713 return rc;
1714}
1715
Dedy Lansky849a5642017-01-20 13:49:44 +02001716int wmi_new_sta(struct wil6210_priv *wil, const u8 *mac, u8 aid)
1717{
1718 int rc;
1719 struct wmi_new_sta_cmd cmd = {
1720 .aid = aid,
1721 };
1722
1723 wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
1724
1725 ether_addr_copy(cmd.dst_mac, mac);
1726
1727 rc = wmi_send(wil, WMI_NEW_STA_CMDID, &cmd, sizeof(cmd));
1728 if (rc)
1729 wil_err(wil, "Failed to send new sta (%d)\n", rc);
1730
1731 return rc;
1732}
1733
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001734void wmi_event_flush(struct wil6210_priv *wil)
1735{
1736 struct pending_wmi_event *evt, *t;
1737
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001738 wil_dbg_wmi(wil, "event_flush\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001739
1740 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
1741 list_del(&evt->list);
1742 kfree(evt);
1743 }
1744}
1745
1746static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
1747 void *d, int len)
1748{
1749 uint i;
1750
1751 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
1752 if (wmi_evt_handlers[i].eventid == id) {
1753 wmi_evt_handlers[i].handler(wil, id, d, len);
1754 return true;
1755 }
1756 }
1757
1758 return false;
1759}
1760
1761static void wmi_event_handle(struct wil6210_priv *wil,
1762 struct wil6210_mbox_hdr *hdr)
1763{
1764 u16 len = le16_to_cpu(hdr->len);
1765
1766 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +02001767 (len >= sizeof(struct wmi_cmd_hdr))) {
1768 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001769 void *evt_data = (void *)(&wmi[1]);
Lior Davidb874dde2016-03-01 19:18:09 +02001770 u16 id = le16_to_cpu(wmi->command_id);
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03001771
1772 wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n",
1773 id, wil->reply_id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001774 /* check if someone waits for this event */
1775 if (wil->reply_id && wil->reply_id == id) {
Maya Erez0916d9f2016-01-17 12:39:10 +02001776 WARN_ON(wil->reply_buf);
1777 wmi_evt_call_handler(wil, id, evt_data,
1778 len - sizeof(*wmi));
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001779 wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
1780 id);
Dedy Lansky59502642014-09-10 16:34:46 +03001781 complete(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001782 return;
1783 }
1784 /* unsolicited event */
1785 /* search for handler */
1786 if (!wmi_evt_call_handler(wil, id, evt_data,
1787 len - sizeof(*wmi))) {
Dedy Lanskya3ce5ccd2015-07-30 13:51:58 +03001788 wil_info(wil, "Unhandled event 0x%04x\n", id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001789 }
1790 } else {
1791 wil_err(wil, "Unknown event type\n");
1792 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
1793 hdr, sizeof(*hdr) + len, true);
1794 }
1795}
1796
1797/*
1798 * Retrieve next WMI event from the pending list
1799 */
1800static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
1801{
1802 ulong flags;
1803 struct list_head *ret = NULL;
1804
1805 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1806
1807 if (!list_empty(&wil->pending_wmi_ev)) {
1808 ret = wil->pending_wmi_ev.next;
1809 list_del(ret);
1810 }
1811
1812 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
1813
1814 return ret;
1815}
1816
1817/*
1818 * Handler for the WMI events
1819 */
1820void wmi_event_worker(struct work_struct *work)
1821{
1822 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
1823 wmi_event_worker);
1824 struct pending_wmi_event *evt;
1825 struct list_head *lh;
1826
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001827 wil_dbg_wmi(wil, "event_worker: Start\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001828 while ((lh = next_wmi_ev(wil)) != NULL) {
1829 evt = list_entry(lh, struct pending_wmi_event, list);
1830 wmi_event_handle(wil, &evt->event.hdr);
1831 kfree(evt);
1832 }
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001833 wil_dbg_wmi(wil, "event_worker: Finished\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001834}