blob: cff9c585972f1aff4b3b31fcd4b4ce7645a2bc38 [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 Kondratiev15e231242014-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 Kondratiev15e231242014-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 if (test_bit(wil_status_resetting, wil->status) ||
522 !test_bit(wil_status_fwready, wil->status)) {
523 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
524 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200525 /* no need for cleanup, wil_reset will do that */
526 return;
527 }
528
Hamad Kadmanyb8194472017-04-05 14:58:08 +0300529 mutex_lock(&wil->mutex);
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);
Lior David9953a782017-03-08 13:52:12 +0200568 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200569 wil_err(wil, "cfg80211_connect_result with failure\n");
Maya Erez0916d9f2016-01-17 12:39:10 +0200570 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
571 NULL, 0,
572 WLAN_STATUS_UNSPECIFIED_FAILURE,
573 GFP_KERNEL);
574 goto out;
575 } else {
Dedy Lanskybcdd49b2017-03-08 13:52:15 +0200576 struct wiphy *wiphy = wil_to_wiphy(wil);
577
578 cfg80211_ref_bss(wiphy, wil->bss);
579 cfg80211_connect_bss(ndev, evt->bssid, wil->bss,
580 assoc_req_ie, assoc_req_ielen,
581 assoc_resp_ie, assoc_resp_ielen,
582 WLAN_STATUS_SUCCESS, GFP_KERNEL,
583 NL80211_TIMEOUT_UNSPECIFIED);
Maya Erez0916d9f2016-01-17 12:39:10 +0200584 }
Dedy Lanskybcdd49b2017-03-08 13:52:15 +0200585 wil->bss = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800586 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
587 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
Dedy Lansky849a5642017-01-20 13:49:44 +0200588 if (rc) {
589 if (disable_ap_sme)
590 /* notify new_sta has failed */
591 cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200592 goto out;
Dedy Lansky849a5642017-01-20 13:49:44 +0200593 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200594
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800595 memset(&sinfo, 0, sizeof(sinfo));
596
597 sinfo.generation = wil->sinfo_gen++;
598
599 if (assoc_req_ie) {
600 sinfo.assoc_req_ies = assoc_req_ie;
601 sinfo.assoc_req_ies_len = assoc_req_ielen;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800602 }
603
604 cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL);
Maya Erez0916d9f2016-01-17 12:39:10 +0200605 } else {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200606 wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
607 evt->cid);
Maya Erez0916d9f2016-01-17 12:39:10 +0200608 goto out;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800609 }
Maya Erez0916d9f2016-01-17 12:39:10 +0200610
611 wil->sta[evt->cid].status = wil_sta_connected;
Lior David9d865ee2017-01-20 13:49:51 +0200612 wil->sta[evt->cid].aid = evt->aid;
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200613 set_bit(wil_status_fwconnected, wil->status);
Dedy Lanskyf9e30332016-11-23 16:06:40 +0200614 wil_update_net_queues_bh(wil, NULL, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800615
Maya Erez0916d9f2016-01-17 12:39:10 +0200616out:
617 if (rc)
618 wil->sta[evt->cid].status = wil_sta_unused;
619 clear_bit(wil_status_fwconnecting, wil->status);
620 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800621}
622
623static void wmi_evt_disconnect(struct wil6210_priv *wil, int id,
624 void *d, int len)
625{
626 struct wmi_disconnect_event *evt = d;
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200627 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800628
Maya Erez0916d9f2016-01-17 12:39:10 +0200629 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
630 evt->bssid, reason_code, evt->disconnect_reason);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800631
632 wil->sinfo_gen++;
633
Hamad Kadmanyb8194472017-04-05 14:58:08 +0300634 if (test_bit(wil_status_resetting, wil->status) ||
635 !test_bit(wil_status_fwready, wil->status)) {
636 wil_err(wil, "status_resetting, cancel disconnect event\n");
637 /* no need for cleanup, wil_reset will do that */
638 return;
639 }
640
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200641 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200642 wil6210_disconnect(wil, evt->bssid, reason_code, true);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200643 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800644}
645
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800646/*
647 * Firmware reports EAPOL frame using WME event.
648 * Reconstruct Ethernet frame and deliver it via normal Rx
649 */
650static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id,
651 void *d, int len)
652{
653 struct net_device *ndev = wil_to_ndev(wil);
654 struct wmi_eapol_rx_event *evt = d;
655 u16 eapol_len = le16_to_cpu(evt->eapol_len);
656 int sz = eapol_len + ETH_HLEN;
657 struct sk_buff *skb;
658 struct ethhdr *eth;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200659 int cid;
660 struct wil_net_stats *stats = NULL;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800661
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200662 wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800663 evt->src_mac);
664
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200665 cid = wil_find_cid(wil, evt->src_mac);
666 if (cid >= 0)
667 stats = &wil->sta[cid].stats;
668
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800669 if (eapol_len > 196) { /* TODO: revisit size limit */
670 wil_err(wil, "EAPOL too large\n");
671 return;
672 }
673
674 skb = alloc_skb(sz, GFP_KERNEL);
675 if (!skb) {
676 wil_err(wil, "Failed to allocate skb\n");
677 return;
678 }
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200679
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800680 eth = (struct ethhdr *)skb_put(skb, ETH_HLEN);
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +0200681 ether_addr_copy(eth->h_dest, ndev->dev_addr);
682 ether_addr_copy(eth->h_source, evt->src_mac);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800683 eth->h_proto = cpu_to_be16(ETH_P_PAE);
Johannes Berg59ae1d12017-06-16 14:29:20 +0200684 skb_put_data(skb, evt->eapol, eapol_len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800685 skb->protocol = eth_type_trans(skb, ndev);
686 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
687 ndev->stats.rx_packets++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200688 ndev->stats.rx_bytes += sz;
689 if (stats) {
690 stats->rx_packets++;
691 stats->rx_bytes += sz;
692 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800693 } else {
694 ndev->stats.rx_dropped++;
Vladimir Kondratievc8b78b52014-02-27 16:20:49 +0200695 if (stats)
696 stats->rx_dropped++;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800697 }
698}
699
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300700static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200701{
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300702 struct wmi_vring_en_event *evt = d;
703 u8 vri = evt->vring_index;
Dedy Lansky849a5642017-01-20 13:49:44 +0200704 struct wireless_dev *wdev = wil_to_wdev(wil);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200705
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300706 wil_dbg_wmi(wil, "Enable vring %d\n", vri);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200707
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300708 if (vri >= ARRAY_SIZE(wil->vring_tx)) {
709 wil_err(wil, "Enable for invalid vring %d\n", vri);
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +0200710 return;
711 }
Dedy Lansky849a5642017-01-20 13:49:44 +0200712
713 if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme)
714 /* in AP mode with disable_ap_sme, this is done by
715 * wil_cfg80211_change_station()
716 */
717 wil->vring_tx_data[vri].dot1x_open = true;
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300718 if (vri == wil->bcast_vring) /* no BA for bcast */
719 return;
Vladimir Kondratiev3a3def82014-12-23 09:47:05 +0200720 if (agg_wsize >= 0)
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300721 wil_addba_tx_request(wil, vri, agg_wsize);
Vladimir Kondratiev3442a502013-03-13 14:12:39 +0200722}
723
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200724static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d,
725 int len)
726{
Lior Davidb874dde2016-03-01 19:18:09 +0200727 struct wmi_ba_status_event *evt = d;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200728 struct vring_tx_data *txdata;
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200729
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200730 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200731 evt->ringid,
732 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200733 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
734 evt->amsdu ? "+" : "-");
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200735
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200736 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
737 wil_err(wil, "invalid ring id %d\n", evt->ringid);
738 return;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200739 }
740
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200741 if (evt->status != WMI_BA_AGREED) {
742 evt->ba_timeout = 0;
743 evt->agg_wsize = 0;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200744 evt->amsdu = 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200745 }
Dedy Lansky8c86f752014-09-10 16:34:40 +0300746
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200747 txdata = &wil->vring_tx_data[evt->ringid];
748
749 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
750 txdata->agg_wsize = evt->agg_wsize;
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +0200751 txdata->agg_amsdu = evt->amsdu;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200752 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200753}
754
755static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d,
756 int len)
757{
758 struct wmi_rcp_addba_req_event *evt = d;
759
760 wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token,
761 evt->ba_param_set, evt->ba_timeout,
762 evt->ba_seq_ctrl);
763}
764
765static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200766__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200767{
768 struct wmi_delba_event *evt = d;
769 u8 cid, tid;
770 u16 reason = __le16_to_cpu(evt->reason);
771 struct wil_sta_info *sta;
772 struct wil_tid_ampdu_rx *r;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200773
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200774 might_sleep();
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200775 parse_cidxtid(evt->cidxtid, &cid, &tid);
776 wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n",
777 cid, tid,
778 evt->from_initiator ? "originator" : "recipient",
779 reason);
780 if (!evt->from_initiator) {
781 int i;
782 /* find Tx vring it belongs to */
783 for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) {
784 if ((wil->vring2cid_tid[i][0] == cid) &&
785 (wil->vring2cid_tid[i][1] == tid)) {
786 struct vring_tx_data *txdata =
787 &wil->vring_tx_data[i];
788
789 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
790 txdata->agg_timeout = 0;
791 txdata->agg_wsize = 0;
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200792 txdata->addba_in_progress = false;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200793
794 break; /* max. 1 matching ring */
795 }
796 }
797 if (i >= ARRAY_SIZE(wil->vring2cid_tid))
798 wil_err(wil, "DELBA: unable to find Tx vring\n");
799 return;
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200800 }
801
802 sta = &wil->sta[cid];
Vladimir Kondratiev7b05b0a2014-02-27 16:20:47 +0200803
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200804 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300805
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200806 r = sta->tid_rx[tid];
807 sta->tid_rx[tid] = NULL;
808 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300809
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200810 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200811}
812
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200813/**
814 * Some events are ignored for purpose; and need not be interpreted as
815 * "unhandled events"
816 */
817static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len)
818{
819 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
820}
821
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800822static const struct {
823 int eventid;
824 void (*handler)(struct wil6210_priv *wil, int eventid,
825 void *data, int data_len);
826} wmi_evt_handlers[] = {
827 {WMI_READY_EVENTID, wmi_evt_ready},
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200828 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800829 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
Vladimir Kondratiev90d89e92015-07-30 13:51:57 +0300830 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800831 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
832 {WMI_CONNECT_EVENTID, wmi_evt_connect},
833 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800834 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
Vladimir Kondratiev249a3822013-03-13 14:12:40 +0200835 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200836 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
837 {WMI_DELBA_EVENTID, wmi_evt_delba},
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300838 {WMI_VRING_EN_EVENTID, wmi_evt_vring_en},
Vladimir Kondratievb03fbab2015-10-25 15:59:21 +0200839 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800840};
841
842/*
843 * Run in IRQ context
844 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
845 * that will be eventually handled by the @wmi_event_worker in the thread
846 * context of thread "wil6210_wmi"
847 */
848void wmi_recv_cmd(struct wil6210_priv *wil)
849{
850 struct wil6210_mbox_ring_desc d_tail;
851 struct wil6210_mbox_hdr hdr;
852 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
853 struct pending_wmi_event *evt;
854 u8 *cmd;
855 void __iomem *src;
856 ulong flags;
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300857 unsigned n;
Maya Erez0916d9f2016-01-17 12:39:10 +0200858 unsigned int num_immed_reply = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800859
Vladimir Kondratiev817f1852015-10-25 15:59:23 +0200860 if (!test_bit(wil_status_mbox_ready, wil->status)) {
Dedy Lansky4cf99c92014-09-10 16:34:41 +0300861 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
Vladimir Kondratiev55f7acd2013-03-13 14:12:49 +0200862 return;
863 }
864
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300865 for (n = 0;; n++) {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800866 u16 len;
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300867 bool q;
Maya Erez0916d9f2016-01-17 12:39:10 +0200868 bool immed_reply = false;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800869
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300870 r->head = wil_r(wil, RGF_MBOX +
871 offsetof(struct wil6210_mbox_ctl, rx.head));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300872 if (r->tail == r->head)
873 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800874
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300875 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
876 r->head, r->tail);
877 /* read cmd descriptor from tail */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800878 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
879 sizeof(struct wil6210_mbox_ring_desc));
880 if (d_tail.sync == 0) {
881 wil_err(wil, "Mbox evt not owned by FW?\n");
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300882 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800883 }
884
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300885 /* read cmd header from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800886 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
887 wil_err(wil, "Mbox evt at 0x%08x?\n",
888 le32_to_cpu(d_tail.addr));
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300889 break;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800890 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800891 len = le16_to_cpu(hdr.len);
Vladimir Kondratieva715c7d2014-05-29 18:37:52 +0300892 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
893 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
894 hdr.flags);
895
896 /* read cmd buffer from descriptor */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800897 src = wmi_buffer(wil, d_tail.addr) +
898 sizeof(struct wil6210_mbox_hdr);
899 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
900 event.wmi) + len, 4),
901 GFP_KERNEL);
Joe Perches14f8dc42013-02-07 11:46:27 +0000902 if (!evt)
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300903 break;
Joe Perches14f8dc42013-02-07 11:46:27 +0000904
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800905 evt->event.hdr = hdr;
906 cmd = (void *)&evt->event.wmi;
907 wil_memcpy_fromio_32(cmd, src, len);
908 /* mark entry as empty */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300909 wil_w(wil, r->tail +
910 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800911 /* indicate */
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800912 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +0200913 (len >= sizeof(struct wmi_cmd_hdr))) {
914 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
915 u16 id = le16_to_cpu(wmi->command_id);
916 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
Maya Erezfe5c2712016-01-28 19:24:04 +0200917 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
Maya Erez0916d9f2016-01-17 12:39:10 +0200918 if (wil->reply_id && wil->reply_id == id) {
919 if (wil->reply_buf) {
920 memcpy(wil->reply_buf, wmi,
921 min(len, wil->reply_size));
922 immed_reply = true;
923 }
924 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200925 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300926
Vladimir Kondratievf988b232013-07-11 18:03:37 +0300927 wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n",
928 id, wmi->mid, tstamp);
929 trace_wil6210_wmi_event(wmi, &wmi[1],
930 len - sizeof(*wmi));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800931 }
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200932 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800933 &evt->event.hdr, sizeof(hdr) + len, true);
934
935 /* advance tail */
936 r->tail = r->base + ((r->tail - r->base +
937 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300938 wil_w(wil, RGF_MBOX +
939 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800940
Maya Erez0916d9f2016-01-17 12:39:10 +0200941 if (immed_reply) {
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200942 wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
943 wil->reply_id);
Maya Erez0916d9f2016-01-17 12:39:10 +0200944 kfree(evt);
945 num_immed_reply++;
946 complete(&wil->wmi_call);
947 } else {
948 /* add to the pending list */
949 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
950 list_add_tail(&evt->list, &wil->pending_wmi_ev);
951 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
952 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
953 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
954 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800955 }
Vladimir Kondratiev95266dc2014-06-16 19:37:19 +0300956 /* normally, 1 event per IRQ should be processed */
Lazar Alexeiaf3db602017-01-20 13:49:46 +0200957 wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
Maya Erez0916d9f2016-01-17 12:39:10 +0200958 n - num_immed_reply, num_immed_reply);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800959}
960
961int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len,
962 u16 reply_id, void *reply, u8 reply_size, int to_msec)
963{
964 int rc;
Nicholas Mc Guiref4bbb822015-08-13 15:38:31 +0300965 unsigned long remain;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800966
967 mutex_lock(&wil->wmi_mutex);
968
Maya Erezfe5c2712016-01-28 19:24:04 +0200969 spin_lock(&wil->wmi_ev_lock);
970 wil->reply_id = reply_id;
971 wil->reply_buf = reply;
972 wil->reply_size = reply_size;
Lior David4d4c4dc2017-01-20 13:49:48 +0200973 reinit_completion(&wil->wmi_call);
Maya Erezfe5c2712016-01-28 19:24:04 +0200974 spin_unlock(&wil->wmi_ev_lock);
975
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800976 rc = __wmi_send(wil, cmdid, buf, len);
977 if (rc)
978 goto out;
979
Dedy Lansky59502642014-09-10 16:34:46 +0300980 remain = wait_for_completion_timeout(&wil->wmi_call,
981 msecs_to_jiffies(to_msec));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800982 if (0 == remain) {
983 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
984 cmdid, reply_id, to_msec);
985 rc = -ETIME;
986 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200987 wil_dbg_wmi(wil,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800988 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
989 cmdid, reply_id,
990 to_msec - jiffies_to_msecs(remain));
991 }
Maya Erezfe5c2712016-01-28 19:24:04 +0200992
993out:
994 spin_lock(&wil->wmi_ev_lock);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800995 wil->reply_id = 0;
996 wil->reply_buf = NULL;
997 wil->reply_size = 0;
Maya Erezfe5c2712016-01-28 19:24:04 +0200998 spin_unlock(&wil->wmi_ev_lock);
999
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001000 mutex_unlock(&wil->wmi_mutex);
1001
1002 return rc;
1003}
1004
1005int wmi_echo(struct wil6210_priv *wil)
1006{
1007 struct wmi_echo_cmd cmd = {
1008 .value = cpu_to_le32(0x12345678),
1009 };
1010
1011 return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratieva54a40d2015-04-30 16:25:05 +03001012 WMI_ECHO_RSP_EVENTID, NULL, 0, 50);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001013}
1014
1015int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
1016{
1017 struct wmi_set_mac_address_cmd cmd;
1018
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001019 ether_addr_copy(cmd.mac, addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001020
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001021 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001022
1023 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd));
1024}
1025
Maya Erez10d599a2016-05-09 21:57:11 +03001026int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
1027{
1028 int rc = 0;
1029 struct wmi_led_cfg_cmd cmd = {
1030 .led_mode = enable,
1031 .id = led_id,
1032 .slow_blink_cfg.blink_on =
1033 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
1034 .slow_blink_cfg.blink_off =
1035 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
1036 .medium_blink_cfg.blink_on =
1037 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
1038 .medium_blink_cfg.blink_off =
1039 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
1040 .fast_blink_cfg.blink_on =
1041 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
1042 .fast_blink_cfg.blink_off =
1043 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
1044 .led_polarity = led_polarity,
1045 };
1046 struct {
1047 struct wmi_cmd_hdr wmi;
1048 struct wmi_led_cfg_done_event evt;
1049 } __packed reply;
1050
1051 if (led_id == WIL_LED_INVALID_ID)
1052 goto out;
1053
1054 if (led_id > WIL_LED_MAX_ID) {
1055 wil_err(wil, "Invalid led id %d\n", led_id);
1056 rc = -EINVAL;
1057 goto out;
1058 }
1059
1060 wil_dbg_wmi(wil,
1061 "%s led %d\n",
1062 enable ? "enabling" : "disabling", led_id);
1063
1064 rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd),
1065 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
1066 100);
1067 if (rc)
1068 goto out;
1069
1070 if (reply.evt.status) {
1071 wil_err(wil, "led %d cfg failed with status %d\n",
1072 led_id, le32_to_cpu(reply.evt.status));
1073 rc = -EINVAL;
1074 }
1075
1076out:
1077 return rc;
1078}
1079
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001080int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype,
Lior Davidb4944f22016-03-01 19:18:17 +02001081 u8 chan, u8 hidden_ssid, u8 is_go)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001082{
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001083 int rc;
1084
1085 struct wmi_pcp_start_cmd cmd = {
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001086 .bcon_interval = cpu_to_le16(bi),
1087 .network_type = wmi_nettype,
1088 .disable_sec_offload = 1,
Vladimir Kondratievadc2d122013-05-28 15:17:52 +03001089 .channel = chan - 1,
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001090 .pcp_max_assoc_sta = max_assoc_sta,
Hamad Kadmany8e52fe32015-06-09 14:11:18 +03001091 .hidden_ssid = hidden_ssid,
Lior Davidb4944f22016-03-01 19:18:17 +02001092 .is_go = is_go,
Dedy Lansky849a5642017-01-20 13:49:44 +02001093 .disable_ap_sme = disable_ap_sme,
Lior Davidc3bfea02017-01-20 13:49:52 +02001094 .abft_len = wil->abft_len,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001095 };
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001096 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001097 struct wmi_cmd_hdr wmi;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001098 struct wmi_pcp_started_event evt;
1099 } __packed reply;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001100
Vladimir Kondratiev774974e2015-02-15 14:02:36 +02001101 if (!wil->privacy)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001102 cmd.disable_sec = 1;
1103
Dedy Lansky1eb9d1e2014-08-06 10:31:58 +03001104 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
1105 (cmd.pcp_max_assoc_sta <= 0)) {
1106 wil_info(wil,
1107 "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n",
1108 max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID);
1109 cmd.pcp_max_assoc_sta = WIL6210_MAX_CID;
1110 }
1111
Dedy Lansky849a5642017-01-20 13:49:44 +02001112 if (disable_ap_sme &&
1113 !test_bit(WMI_FW_CAPABILITY_DISABLE_AP_SME,
1114 wil->fw_capabilities)) {
1115 wil_err(wil, "disable_ap_sme not supported by FW\n");
1116 return -EOPNOTSUPP;
1117 }
1118
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001119 /*
1120 * Processing time may be huge, in case of secure AP it takes about
1121 * 3500ms for FW to start AP
1122 */
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001123 rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev8b5c7f62013-06-09 09:12:50 +03001124 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001125 if (rc)
1126 return rc;
1127
1128 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
1129 rc = -EINVAL;
1130
Maya Erez10d599a2016-05-09 21:57:11 +03001131 if (wmi_nettype != WMI_NETTYPE_P2P)
1132 /* Don't fail due to error in the led configuration */
1133 wmi_led_cfg(wil, true);
1134
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001135 return rc;
1136}
1137
1138int wmi_pcp_stop(struct wil6210_priv *wil)
1139{
Maya Erez10d599a2016-05-09 21:57:11 +03001140 int rc;
1141
1142 rc = wmi_led_cfg(wil, false);
1143 if (rc)
1144 return rc;
1145
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001146 return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0,
1147 WMI_PCP_STOPPED_EVENTID, NULL, 0, 20);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001148}
1149
1150int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid)
1151{
1152 struct wmi_set_ssid_cmd cmd = {
1153 .ssid_len = cpu_to_le32(ssid_len),
1154 };
1155
1156 if (ssid_len > sizeof(cmd.ssid))
1157 return -EINVAL;
1158
1159 memcpy(cmd.ssid, ssid, ssid_len);
1160
1161 return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd));
1162}
1163
1164int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid)
1165{
1166 int rc;
1167 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001168 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001169 struct wmi_set_ssid_cmd cmd;
1170 } __packed reply;
1171 int len; /* reply.cmd.ssid_len in CPU order */
1172
1173 rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID,
1174 &reply, sizeof(reply), 20);
1175 if (rc)
1176 return rc;
1177
1178 len = le32_to_cpu(reply.cmd.ssid_len);
1179 if (len > sizeof(reply.cmd.ssid))
1180 return -EINVAL;
1181
1182 *ssid_len = len;
1183 memcpy(ssid, reply.cmd.ssid, len);
1184
1185 return 0;
1186}
1187
1188int wmi_set_channel(struct wil6210_priv *wil, int channel)
1189{
1190 struct wmi_set_pcp_channel_cmd cmd = {
1191 .channel = channel - 1,
1192 };
1193
1194 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd));
1195}
1196
1197int wmi_get_channel(struct wil6210_priv *wil, int *channel)
1198{
1199 int rc;
1200 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001201 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001202 struct wmi_set_pcp_channel_cmd cmd;
1203 } __packed reply;
1204
1205 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0,
1206 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20);
1207 if (rc)
1208 return rc;
1209
1210 if (reply.cmd.channel > 3)
1211 return -EINVAL;
1212
1213 *channel = reply.cmd.channel + 1;
1214
1215 return 0;
1216}
1217
Dedy Lanskye6d68342016-03-01 19:18:12 +02001218int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi)
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001219{
Dedy Lanskye6d68342016-03-01 19:18:12 +02001220 int rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001221 struct wmi_p2p_cfg_cmd cmd = {
Dedy Lanskye6d68342016-03-01 19:18:12 +02001222 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
1223 .bcon_interval = cpu_to_le16(bi),
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001224 .channel = channel - 1,
1225 };
Dedy Lanskye6d68342016-03-01 19:18:12 +02001226 struct {
1227 struct wmi_cmd_hdr wmi;
1228 struct wmi_p2p_cfg_done_event evt;
1229 } __packed reply;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001230
Dedy Lanskye6d68342016-03-01 19:18:12 +02001231 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
1232
1233 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd),
1234 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
1235 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1236 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
1237 rc = -EINVAL;
1238 }
1239
1240 return rc;
1241}
1242
1243int wmi_start_listen(struct wil6210_priv *wil)
1244{
1245 int rc;
1246 struct {
1247 struct wmi_cmd_hdr wmi;
1248 struct wmi_listen_started_event evt;
1249 } __packed reply;
1250
1251 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
1252
1253 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1254 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
1255 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1256 wil_err(wil, "device failed to start listen. status %d\n",
1257 reply.evt.status);
1258 rc = -EINVAL;
1259 }
1260
1261 return rc;
1262}
1263
1264int wmi_start_search(struct wil6210_priv *wil)
1265{
1266 int rc;
1267 struct {
1268 struct wmi_cmd_hdr wmi;
1269 struct wmi_search_started_event evt;
1270 } __packed reply;
1271
1272 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
1273
1274 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0,
1275 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
1276 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1277 wil_err(wil, "device failed to start search. status %d\n",
1278 reply.evt.status);
1279 rc = -EINVAL;
1280 }
1281
1282 return rc;
1283}
1284
1285int wmi_stop_discovery(struct wil6210_priv *wil)
1286{
1287 int rc;
1288
1289 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
1290
1291 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1292 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100);
1293
1294 if (rc)
1295 wil_err(wil, "Failed to stop discovery\n");
1296
1297 return rc;
Vladimir Kondratievb8023172013-03-13 14:12:50 +02001298}
1299
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001300int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001301 const void *mac_addr, int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001302{
1303 struct wmi_delete_cipher_key_cmd cmd = {
1304 .key_index = key_index,
1305 };
1306
1307 if (mac_addr)
1308 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1309
1310 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1311}
1312
1313int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001314 const void *mac_addr, int key_len, const void *key,
1315 int key_usage)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001316{
1317 struct wmi_add_cipher_key_cmd cmd = {
1318 .key_index = key_index,
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001319 .key_usage = key_usage,
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001320 .key_len = key_len,
1321 };
1322
1323 if (!key || (key_len > sizeof(cmd.key)))
1324 return -EINVAL;
1325
1326 memcpy(cmd.key, key, key_len);
1327 if (mac_addr)
1328 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
1329
1330 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd));
1331}
1332
1333int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie)
1334{
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001335 static const char *const names[] = {
1336 [WMI_FRAME_BEACON] = "BEACON",
1337 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
1338 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
1339 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
1340 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
1341 };
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001342 int rc;
1343 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
1344 struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +03001345
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001346 if (!cmd) {
1347 rc = -ENOMEM;
1348 goto out;
1349 }
Vladimir Kondratievac4acdb2014-09-10 16:34:43 +03001350 if (!ie)
1351 ie_len = 0;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001352
1353 cmd->mgmt_frm_type = type;
1354 /* BUG: FW API define ieLen as u8. Will fix FW */
1355 cmd->ie_len = cpu_to_le16(ie_len);
1356 memcpy(cmd->ie_info, ie, ie_len);
Vladimir Kondratiev03866e72013-03-13 14:12:42 +02001357 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001358 kfree(cmd);
Vladimir Kondratiev5421bf02015-07-30 13:52:00 +03001359out:
1360 if (rc) {
1361 const char *name = type < ARRAY_SIZE(names) ?
1362 names[type] : "??";
1363 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
1364 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001365
1366 return rc;
1367}
1368
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001369/**
1370 * wmi_rxon - turn radio on/off
1371 * @on: turn on if true, off otherwise
1372 *
1373 * Only switch radio. Channel should be set separately.
1374 * No timeout for rxon - radio turned on forever unless some other call
1375 * turns it off
1376 */
1377int wmi_rxon(struct wil6210_priv *wil, bool on)
1378{
1379 int rc;
1380 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001381 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001382 struct wmi_listen_started_event evt;
1383 } __packed reply;
1384
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001385 wil_info(wil, "(%s)\n", on ? "on" : "off");
Vladimir Kondratiev1647f122014-02-27 16:20:40 +02001386
1387 if (on) {
1388 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0,
1389 WMI_LISTEN_STARTED_EVENTID,
1390 &reply, sizeof(reply), 100);
1391 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
1392 rc = -EINVAL;
1393 } else {
1394 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0,
1395 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20);
1396 }
1397
1398 return rc;
1399}
1400
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001401int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring)
1402{
1403 struct wireless_dev *wdev = wil->wdev;
1404 struct net_device *ndev = wil_to_ndev(wil);
1405 struct wmi_cfg_rx_chain_cmd cmd = {
1406 .action = WMI_RX_CHAIN_ADD,
1407 .rx_sw_ring = {
Lior David52a45702017-04-05 14:58:06 +03001408 .max_mpdu_size = cpu_to_le16(
1409 wil_mtu2macbuf(wil->rx_buf_len)),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001410 .ring_mem_base = cpu_to_le64(vring->pa),
1411 .ring_size = cpu_to_le16(vring->size),
1412 },
1413 .mid = 0, /* TODO - what is it? */
1414 .decap_trans_type = WMI_DECAP_TYPE_802_3,
Vladimir Kondratievb4490f42014-02-27 16:20:44 +02001415 .reorder_type = WMI_RX_SW_REORDER,
Vladimir Kondratievab954622014-12-23 09:47:20 +02001416 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001417 };
1418 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001419 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001420 struct wmi_cfg_rx_chain_done_event evt;
1421 } __packed evt;
1422 int rc;
1423
1424 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
1425 struct ieee80211_channel *ch = wdev->preset_chandef.chan;
1426
1427 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
1428 if (ch)
1429 cmd.sniffer_cfg.channel = ch->hw_value - 1;
1430 cmd.sniffer_cfg.phy_info_mode =
1431 cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP);
1432 cmd.sniffer_cfg.phy_support =
1433 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
Vladimir Kondratiev47653322015-10-04 10:23:24 +03001434 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
Kirshenbaum Erez504937d2013-07-21 11:34:37 +03001435 } else {
1436 /* Initialize offload (in non-sniffer mode).
1437 * Linux IP stack always calculates IP checksum
1438 * HW always calculate TCP/UDP checksum
1439 */
1440 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001441 }
Vladimir Kondratievc406ea72015-03-15 16:00:19 +02001442
1443 if (rx_align_2)
1444 cmd.l2_802_3_offload_ctrl |=
1445 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
1446
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001447 /* typical time for secure PCP is 840ms */
1448 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd),
1449 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
1450 if (rc)
1451 return rc;
1452
1453 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
1454
Vladimir Kondratiev77438822013-01-28 18:31:06 +02001455 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
Vladimir Kondratiev47e19af2013-01-28 18:30:59 +02001456 le32_to_cpu(evt.evt.status), vring->hwtail);
1457
1458 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
1459 rc = -EINVAL;
1460
1461 return rc;
1462}
1463
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001464int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001465{
1466 int rc;
1467 struct wmi_temp_sense_cmd cmd = {
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001468 .measure_baseband_en = cpu_to_le32(!!t_bb),
1469 .measure_rf_en = cpu_to_le32(!!t_rf),
1470 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001471 };
1472 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001473 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001474 struct wmi_temp_sense_done_event evt;
1475 } __packed reply;
1476
1477 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd),
1478 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100);
1479 if (rc)
1480 return rc;
1481
Vladimir Kondratiev8c679672015-01-25 10:52:42 +02001482 if (t_bb)
1483 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
1484 if (t_rf)
1485 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
Vladimir Kondratiev1a2780e2013-03-13 14:12:51 +02001486
1487 return 0;
1488}
1489
Dedy Lansky849a5642017-01-20 13:49:44 +02001490int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac,
1491 u16 reason, bool full_disconnect, bool del_sta)
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001492{
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001493 int rc;
1494 u16 reason_code;
Dedy Lansky849a5642017-01-20 13:49:44 +02001495 struct wmi_disconnect_sta_cmd disc_sta_cmd = {
1496 .disconnect_reason = cpu_to_le16(reason),
1497 };
1498 struct wmi_del_sta_cmd del_sta_cmd = {
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001499 .disconnect_reason = cpu_to_le16(reason),
1500 };
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001501 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001502 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001503 struct wmi_disconnect_event evt;
1504 } __packed reply;
Vladimir Kondratieva82553bb2015-03-15 16:00:21 +02001505
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001506 wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001507
Dedy Lansky3b56c152017-03-08 13:52:18 +02001508 wil->locally_generated_disc = true;
Dedy Lansky849a5642017-01-20 13:49:44 +02001509 if (del_sta) {
1510 ether_addr_copy(del_sta_cmd.dst_mac, mac);
1511 rc = wmi_call(wil, WMI_DEL_STA_CMDID, &del_sta_cmd,
1512 sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
1513 &reply, sizeof(reply), 1000);
1514 } else {
1515 ether_addr_copy(disc_sta_cmd.dst_mac, mac);
1516 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &disc_sta_cmd,
1517 sizeof(disc_sta_cmd), WMI_DISCONNECT_EVENTID,
1518 &reply, sizeof(reply), 1000);
1519 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001520 /* failure to disconnect in reasonable time treated as FW error */
1521 if (rc) {
1522 wil_fw_error_recovery(wil);
1523 return rc;
1524 }
1525
Maya Erez0916d9f2016-01-17 12:39:10 +02001526 if (full_disconnect) {
1527 /* call event handler manually after processing wmi_call,
1528 * to avoid deadlock - disconnect event handler acquires
1529 * wil->mutex while it is already held here
1530 */
1531 reason_code = le16_to_cpu(reply.evt.protocol_reason_status);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001532
Maya Erez0916d9f2016-01-17 12:39:10 +02001533 wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1534 reply.evt.bssid, reason_code,
1535 reply.evt.disconnect_reason);
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001536
Maya Erez0916d9f2016-01-17 12:39:10 +02001537 wil->sinfo_gen++;
1538 wil6210_disconnect(wil, reply.evt.bssid, reason_code, true);
1539 }
Vladimir Kondratiev3e9191f2015-07-30 13:51:53 +03001540 return 0;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +02001541}
1542
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001543int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout)
1544{
1545 struct wmi_vring_ba_en_cmd cmd = {
1546 .ringid = ringid,
1547 .agg_max_wsize = size,
1548 .ba_timeout = cpu_to_le16(timeout),
Vladimir Kondratievcbcf5862014-12-23 09:47:09 +02001549 .amsdu = 0,
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001550 };
1551
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001552 wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size,
1553 timeout);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001554
1555 return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd));
1556}
1557
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001558int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason)
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001559{
1560 struct wmi_vring_ba_dis_cmd cmd = {
1561 .ringid = ringid,
1562 .reason = cpu_to_le16(reason),
1563 };
1564
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001565 wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001566
1567 return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd));
1568}
1569
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001570int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason)
1571{
1572 struct wmi_rcp_delba_cmd cmd = {
1573 .cidxtid = cidxtid,
1574 .reason = cpu_to_le16(reason),
1575 };
1576
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001577 wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf,
1578 (cidxtid >> 4) & 0xf, reason);
Vladimir Kondratiev26a359d2014-12-23 09:47:10 +02001579
1580 return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd));
1581}
1582
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001583int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token,
1584 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
1585{
1586 int rc;
1587 struct wmi_rcp_addba_resp_cmd cmd = {
1588 .cidxtid = mk_cidxtid(cid, tid),
1589 .dialog_token = token,
1590 .status_code = cpu_to_le16(status),
1591 /* bit 0: A-MSDU supported
1592 * bit 1: policy (should be 0 for us)
1593 * bits 2..5: TID
1594 * bits 6..15: buffer size
1595 */
1596 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
1597 (agg_wsize << 6)),
1598 .ba_timeout = cpu_to_le16(timeout),
1599 };
1600 struct {
Lior Davidb874dde2016-03-01 19:18:09 +02001601 struct wmi_cmd_hdr wmi;
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001602 struct wmi_rcp_addba_resp_sent_event evt;
1603 } __packed reply;
1604
1605 wil_dbg_wmi(wil,
1606 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
1607 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-");
1608
1609 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd),
Vladimir Kondratiev230d8442015-04-30 16:25:10 +03001610 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
1611 100);
Vladimir Kondratiev32772132014-12-23 09:47:03 +02001612 if (rc)
1613 return rc;
1614
1615 if (reply.evt.status) {
1616 wil_err(wil, "ADDBA response failed with status %d\n",
1617 le16_to_cpu(reply.evt.status));
1618 rc = -EINVAL;
1619 }
1620
1621 return rc;
1622}
1623
Maya Erez2c207eb2016-11-23 16:06:40 +02001624int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
1625 enum wmi_ps_profile_type ps_profile)
1626{
1627 int rc;
1628 struct wmi_ps_dev_profile_cfg_cmd cmd = {
1629 .ps_profile = ps_profile,
1630 };
1631 struct {
1632 struct wmi_cmd_hdr wmi;
1633 struct wmi_ps_dev_profile_cfg_event evt;
1634 } __packed reply;
1635 u32 status;
1636
1637 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
1638
1639 reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR);
1640
1641 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd),
1642 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
1643 100);
1644 if (rc)
1645 return rc;
1646
1647 status = le32_to_cpu(reply.evt.status);
1648
1649 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
1650 wil_err(wil, "ps dev profile cfg failed with status %d\n",
1651 status);
1652 rc = -EINVAL;
1653 }
1654
1655 return rc;
1656}
1657
Lior David3fea18d2016-11-23 16:06:43 +02001658int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
1659{
1660 int rc;
1661 struct wmi_set_mgmt_retry_limit_cmd cmd = {
1662 .mgmt_retry_limit = retry_short,
1663 };
1664 struct {
1665 struct wmi_cmd_hdr wmi;
1666 struct wmi_set_mgmt_retry_limit_event evt;
1667 } __packed reply;
1668
1669 wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
1670
1671 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1672 return -ENOTSUPP;
1673
1674 reply.evt.status = WMI_FW_STATUS_FAILURE;
1675
1676 rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd),
1677 WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1678 100);
1679 if (rc)
1680 return rc;
1681
1682 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
1683 wil_err(wil, "set mgmt retry limit failed with status %d\n",
1684 reply.evt.status);
1685 rc = -EINVAL;
1686 }
1687
1688 return rc;
1689}
1690
1691int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
1692{
1693 int rc;
1694 struct {
1695 struct wmi_cmd_hdr wmi;
1696 struct wmi_get_mgmt_retry_limit_event evt;
1697 } __packed reply;
1698
1699 wil_dbg_wmi(wil, "getting mgmt retry short\n");
1700
1701 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
1702 return -ENOTSUPP;
1703
1704 reply.evt.mgmt_retry_limit = 0;
1705 rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0,
1706 WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
1707 100);
1708 if (rc)
1709 return rc;
1710
1711 if (retry_short)
1712 *retry_short = reply.evt.mgmt_retry_limit;
1713
1714 return 0;
1715}
1716
Maya Erez035859a2016-11-23 16:06:42 +02001717int wmi_abort_scan(struct wil6210_priv *wil)
1718{
1719 int rc;
1720
1721 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
1722
1723 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0);
1724 if (rc)
1725 wil_err(wil, "Failed to abort scan (%d)\n", rc);
1726
1727 return rc;
1728}
1729
Dedy Lansky849a5642017-01-20 13:49:44 +02001730int wmi_new_sta(struct wil6210_priv *wil, const u8 *mac, u8 aid)
1731{
1732 int rc;
1733 struct wmi_new_sta_cmd cmd = {
1734 .aid = aid,
1735 };
1736
1737 wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
1738
1739 ether_addr_copy(cmd.dst_mac, mac);
1740
1741 rc = wmi_send(wil, WMI_NEW_STA_CMDID, &cmd, sizeof(cmd));
1742 if (rc)
1743 wil_err(wil, "Failed to send new sta (%d)\n", rc);
1744
1745 return rc;
1746}
1747
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001748void wmi_event_flush(struct wil6210_priv *wil)
1749{
Hamad Kadmanyf6b29b62017-03-08 13:52:16 +02001750 ulong flags;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001751 struct pending_wmi_event *evt, *t;
1752
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001753 wil_dbg_wmi(wil, "event_flush\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001754
Hamad Kadmanyf6b29b62017-03-08 13:52:16 +02001755 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1756
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001757 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
1758 list_del(&evt->list);
1759 kfree(evt);
1760 }
Hamad Kadmanyf6b29b62017-03-08 13:52:16 +02001761
1762 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001763}
1764
1765static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id,
1766 void *d, int len)
1767{
1768 uint i;
1769
1770 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
1771 if (wmi_evt_handlers[i].eventid == id) {
1772 wmi_evt_handlers[i].handler(wil, id, d, len);
1773 return true;
1774 }
1775 }
1776
1777 return false;
1778}
1779
1780static void wmi_event_handle(struct wil6210_priv *wil,
1781 struct wil6210_mbox_hdr *hdr)
1782{
1783 u16 len = le16_to_cpu(hdr->len);
1784
1785 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
Lior Davidb874dde2016-03-01 19:18:09 +02001786 (len >= sizeof(struct wmi_cmd_hdr))) {
1787 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001788 void *evt_data = (void *)(&wmi[1]);
Lior Davidb874dde2016-03-01 19:18:09 +02001789 u16 id = le16_to_cpu(wmi->command_id);
Vladimir Kondratiev028e1832014-09-10 16:34:33 +03001790
1791 wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n",
1792 id, wil->reply_id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001793 /* check if someone waits for this event */
1794 if (wil->reply_id && wil->reply_id == id) {
Maya Erez0916d9f2016-01-17 12:39:10 +02001795 WARN_ON(wil->reply_buf);
1796 wmi_evt_call_handler(wil, id, evt_data,
1797 len - sizeof(*wmi));
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001798 wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
1799 id);
Dedy Lansky59502642014-09-10 16:34:46 +03001800 complete(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001801 return;
1802 }
1803 /* unsolicited event */
1804 /* search for handler */
1805 if (!wmi_evt_call_handler(wil, id, evt_data,
1806 len - sizeof(*wmi))) {
Dedy Lanskya3ce5ccd2015-07-30 13:51:58 +03001807 wil_info(wil, "Unhandled event 0x%04x\n", id);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001808 }
1809 } else {
1810 wil_err(wil, "Unknown event type\n");
1811 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
1812 hdr, sizeof(*hdr) + len, true);
1813 }
1814}
1815
1816/*
1817 * Retrieve next WMI event from the pending list
1818 */
1819static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
1820{
1821 ulong flags;
1822 struct list_head *ret = NULL;
1823
1824 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1825
1826 if (!list_empty(&wil->pending_wmi_ev)) {
1827 ret = wil->pending_wmi_ev.next;
1828 list_del(ret);
1829 }
1830
1831 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
1832
1833 return ret;
1834}
1835
1836/*
1837 * Handler for the WMI events
1838 */
1839void wmi_event_worker(struct work_struct *work)
1840{
1841 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
1842 wmi_event_worker);
1843 struct pending_wmi_event *evt;
1844 struct list_head *lh;
1845
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001846 wil_dbg_wmi(wil, "event_worker: Start\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001847 while ((lh = next_wmi_ev(wil)) != NULL) {
1848 evt = list_entry(lh, struct pending_wmi_event, list);
1849 wmi_event_handle(wil, &evt->event.hdr);
1850 kfree(evt);
1851 }
Lazar Alexeiaf3db602017-01-20 13:49:46 +02001852 wil_dbg_wmi(wil, "event_worker: Finished\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001853}