1 // SPDX-License-Identifier: ISC
2 /*
3 * Copyright (c) 2012-2017 Qualcomm Atheros, Inc.
4 * Copyright (c) 2018-2019, The Linux Foundation. All rights reserved.
5 */
6
7 #include <linux/moduleparam.h>
8 #include <linux/etherdevice.h>
9 #include <linux/if_arp.h>
10
11 #include "wil6210.h"
12 #include "txrx.h"
13 #include "wmi.h"
14 #include "trace.h"
15
16 /* set the default max assoc sta to max supported by driver */
17 uint max_assoc_sta = WIL6210_MAX_CID;
18 module_param(max_assoc_sta, uint, 0444);
19 MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP");
20
21 int agg_wsize; /* = 0; */
22 module_param(agg_wsize, int, 0644);
23 MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;"
24 " 0 - use default; < 0 - don't auto-establish");
25
26 u8 led_id = WIL_LED_INVALID_ID;
27 module_param(led_id, byte, 0444);
28 MODULE_PARM_DESC(led_id,
29 " 60G device led enablement. Set the led ID (0-2) to enable");
30
31 #define WIL_WAIT_FOR_SUSPEND_RESUME_COMP 200
32 #define WIL_WMI_PCP_STOP_TO_MS 5000
33
34 /**
35 * DOC: WMI event receiving - theory of operations
36 *
37 * When firmware about to report WMI event, it fills memory area
38 * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for
39 * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler.
40 *
41 * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the
42 * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up
43 * and handles events within the @wmi_event_worker. Every event get detached
44 * from list, processed and deleted.
45 *
46 * Purpose for this mechanism is to release IRQ thread; otherwise,
47 * if WMI event handling involves another WMI command flow, this 2-nd flow
48 * won't be completed because of blocked IRQ thread.
49 */
50
51 /**
52 * DOC: Addressing - theory of operations
53 *
54 * There are several buses present on the WIL6210 card.
55 * Same memory areas are visible at different address on
56 * the different busses. There are 3 main bus masters:
57 * - MAC CPU (ucode)
58 * - User CPU (firmware)
59 * - AHB (host)
60 *
61 * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing
62 * AHB addresses starting from 0x880000
63 *
64 * Internally, firmware uses addresses that allow faster access but
65 * are invisible from the host. To read from these addresses, alternative
66 * AHB address must be used.
67 */
68
69 /* sparrow_fw_mapping provides memory remapping table for sparrow
70 *
71 * array size should be in sync with the declaration in the wil6210.h
72 *
73 * Sparrow memory mapping:
74 * Linker address PCI/Host address
75 * 0x880000 .. 0xa80000 2Mb BAR0
76 * 0x800000 .. 0x808000 0x900000 .. 0x908000 32k DCCM
77 * 0x840000 .. 0x860000 0x908000 .. 0x928000 128k PERIPH
78 */
79 const struct fw_map sparrow_fw_mapping[] = {
80 /* FW code RAM 256k */
81 {0x000000, 0x040000, 0x8c0000, "fw_code", true, true},
82 /* FW data RAM 32k */
83 {0x800000, 0x808000, 0x900000, "fw_data", true, true},
84 /* periph data 128k */
85 {0x840000, 0x860000, 0x908000, "fw_peri", true, true},
86 /* various RGF 40k */
87 {0x880000, 0x88a000, 0x880000, "rgf", true, true},
88 /* AGC table 4k */
89 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true, true},
90 /* Pcie_ext_rgf 4k */
91 {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true, true},
92 /* mac_ext_rgf 512b */
93 {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext", true, true},
94 /* upper area 548k */
95 {0x8c0000, 0x949000, 0x8c0000, "upper", true, true},
96 /* UCODE areas - accessible by debugfs blobs but not by
97 * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
98 */
99 /* ucode code RAM 128k */
100 {0x000000, 0x020000, 0x920000, "uc_code", false, false},
101 /* ucode data RAM 16k */
102 {0x800000, 0x804000, 0x940000, "uc_data", false, false},
103 };
104
105 /* sparrow_d0_mac_rgf_ext - mac_rgf_ext section for Sparrow D0
106 * it is a bit larger to support extra features
107 */
108 const struct fw_map sparrow_d0_mac_rgf_ext = {
109 0x88c000, 0x88c500, 0x88c000, "mac_rgf_ext", true, true
110 };
111
112 /* talyn_fw_mapping provides memory remapping table for Talyn
113 *
114 * array size should be in sync with the declaration in the wil6210.h
115 *
116 * Talyn memory mapping:
117 * Linker address PCI/Host address
118 * 0x880000 .. 0xc80000 4Mb BAR0
119 * 0x800000 .. 0x820000 0xa00000 .. 0xa20000 128k DCCM
120 * 0x840000 .. 0x858000 0xa20000 .. 0xa38000 96k PERIPH
121 */
122 const struct fw_map talyn_fw_mapping[] = {
123 /* FW code RAM 1M */
124 {0x000000, 0x100000, 0x900000, "fw_code", true, true},
125 /* FW data RAM 128k */
126 {0x800000, 0x820000, 0xa00000, "fw_data", true, true},
127 /* periph. data RAM 96k */
128 {0x840000, 0x858000, 0xa20000, "fw_peri", true, true},
129 /* various RGF 40k */
130 {0x880000, 0x88a000, 0x880000, "rgf", true, true},
131 /* AGC table 4k */
132 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true, true},
133 /* Pcie_ext_rgf 4k */
134 {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true, true},
135 /* mac_ext_rgf 1344b */
136 {0x88c000, 0x88c540, 0x88c000, "mac_rgf_ext", true, true},
137 /* ext USER RGF 4k */
138 {0x88d000, 0x88e000, 0x88d000, "ext_user_rgf", true, true},
139 /* OTP 4k */
140 {0x8a0000, 0x8a1000, 0x8a0000, "otp", true, false},
141 /* DMA EXT RGF 64k */
142 {0x8b0000, 0x8c0000, 0x8b0000, "dma_ext_rgf", true, true},
143 /* upper area 1536k */
144 {0x900000, 0xa80000, 0x900000, "upper", true, true},
145 /* UCODE areas - accessible by debugfs blobs but not by
146 * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
147 */
148 /* ucode code RAM 256k */
149 {0x000000, 0x040000, 0xa38000, "uc_code", false, false},
150 /* ucode data RAM 32k */
151 {0x800000, 0x808000, 0xa78000, "uc_data", false, false},
152 };
153
154 /* talyn_mb_fw_mapping provides memory remapping table for Talyn-MB
155 *
156 * array size should be in sync with the declaration in the wil6210.h
157 *
158 * Talyn MB memory mapping:
159 * Linker address PCI/Host address
160 * 0x880000 .. 0xc80000 4Mb BAR0
161 * 0x800000 .. 0x820000 0xa00000 .. 0xa20000 128k DCCM
162 * 0x840000 .. 0x858000 0xa20000 .. 0xa38000 96k PERIPH
163 */
164 const struct fw_map talyn_mb_fw_mapping[] = {
165 /* FW code RAM 768k */
166 {0x000000, 0x0c0000, 0x900000, "fw_code", true, true},
167 /* FW data RAM 128k */
168 {0x800000, 0x820000, 0xa00000, "fw_data", true, true},
169 /* periph. data RAM 96k */
170 {0x840000, 0x858000, 0xa20000, "fw_peri", true, true},
171 /* various RGF 40k */
172 {0x880000, 0x88a000, 0x880000, "rgf", true, true},
173 /* AGC table 4k */
174 {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true, true},
175 /* Pcie_ext_rgf 4k */
176 {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true, true},
177 /* mac_ext_rgf 2256b */
178 {0x88c000, 0x88c8d0, 0x88c000, "mac_rgf_ext", true, true},
179 /* ext USER RGF 4k */
180 {0x88d000, 0x88e000, 0x88d000, "ext_user_rgf", true, true},
181 /* SEC PKA 16k */
182 {0x890000, 0x894000, 0x890000, "sec_pka", true, true},
183 /* SEC KDF RGF 3096b */
184 {0x898000, 0x898c18, 0x898000, "sec_kdf_rgf", true, true},
185 /* SEC MAIN 2124b */
186 {0x89a000, 0x89a84c, 0x89a000, "sec_main", true, true},
187 /* OTP 4k */
188 {0x8a0000, 0x8a1000, 0x8a0000, "otp", true, false},
189 /* DMA EXT RGF 64k */
190 {0x8b0000, 0x8c0000, 0x8b0000, "dma_ext_rgf", true, true},
191 /* DUM USER RGF 528b */
192 {0x8c0000, 0x8c0210, 0x8c0000, "dum_user_rgf", true, true},
193 /* DMA OFU 296b */
194 {0x8c2000, 0x8c2128, 0x8c2000, "dma_ofu", true, true},
195 /* ucode debug 256b */
196 {0x8c3000, 0x8c3100, 0x8c3000, "ucode_debug", true, true},
197 /* upper area 1536k */
198 {0x900000, 0xa80000, 0x900000, "upper", true, true},
199 /* UCODE areas - accessible by debugfs blobs but not by
200 * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas!
201 */
202 /* ucode code RAM 256k */
203 {0x000000, 0x040000, 0xa38000, "uc_code", false, false},
204 /* ucode data RAM 32k */
205 {0x800000, 0x808000, 0xa78000, "uc_data", false, false},
206 };
207
208 struct fw_map fw_mapping[MAX_FW_MAPPING_TABLE_SIZE];
209
210 struct blink_on_off_time led_blink_time[] = {
211 {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS},
212 {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS},
213 {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS},
214 };
215
216 struct auth_no_hdr {
217 __le16 auth_alg;
218 __le16 auth_transaction;
219 __le16 status_code;
220 /* possibly followed by Challenge text */
221 u8 variable[];
222 } __packed;
223
224 u8 led_polarity = LED_POLARITY_LOW_ACTIVE;
225
226 /**
227 * return AHB address for given firmware internal (linker) address
228 * @x: internal address
229 * If address have no valid AHB mapping, return 0
230 */
wmi_addr_remap(u32 x)231 static u32 wmi_addr_remap(u32 x)
232 {
233 uint i;
234
235 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) {
236 if (fw_mapping[i].fw &&
237 ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)))
238 return x + fw_mapping[i].host - fw_mapping[i].from;
239 }
240
241 return 0;
242 }
243
244 /**
245 * find fw_mapping entry by section name
246 * @section: section name
247 *
248 * Return pointer to section or NULL if not found
249 */
wil_find_fw_mapping(const char * section)250 struct fw_map *wil_find_fw_mapping(const char *section)
251 {
252 int i;
253
254 for (i = 0; i < ARRAY_SIZE(fw_mapping); i++)
255 if (fw_mapping[i].name &&
256 !strcmp(section, fw_mapping[i].name))
257 return &fw_mapping[i];
258
259 return NULL;
260 }
261
262 /**
263 * Check address validity for WMI buffer; remap if needed
264 * @wil: driver data
265 * @ptr: internal (linker) fw/ucode address
266 * @size: if non zero, validate the block does not
267 * exceed the device memory (bar)
268 *
269 * Valid buffer should be DWORD aligned
270 *
271 * return address for accessing buffer from the host;
272 * if buffer is not valid, return NULL.
273 */
wmi_buffer_block(struct wil6210_priv * wil,__le32 ptr_,u32 size)274 void __iomem *wmi_buffer_block(struct wil6210_priv *wil, __le32 ptr_, u32 size)
275 {
276 u32 off;
277 u32 ptr = le32_to_cpu(ptr_);
278
279 if (ptr % 4)
280 return NULL;
281
282 ptr = wmi_addr_remap(ptr);
283 if (ptr < WIL6210_FW_HOST_OFF)
284 return NULL;
285
286 off = HOSTADDR(ptr);
287 if (off > wil->bar_size - 4)
288 return NULL;
289 if (size && ((off + size > wil->bar_size) || (off + size < off)))
290 return NULL;
291
292 return wil->csr + off;
293 }
294
wmi_buffer(struct wil6210_priv * wil,__le32 ptr_)295 void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_)
296 {
297 return wmi_buffer_block(wil, ptr_, 0);
298 }
299
300 /* Check address validity */
wmi_addr(struct wil6210_priv * wil,u32 ptr)301 void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr)
302 {
303 u32 off;
304
305 if (ptr % 4)
306 return NULL;
307
308 if (ptr < WIL6210_FW_HOST_OFF)
309 return NULL;
310
311 off = HOSTADDR(ptr);
312 if (off > wil->bar_size - 4)
313 return NULL;
314
315 return wil->csr + off;
316 }
317
wmi_read_hdr(struct wil6210_priv * wil,__le32 ptr,struct wil6210_mbox_hdr * hdr)318 int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr,
319 struct wil6210_mbox_hdr *hdr)
320 {
321 void __iomem *src = wmi_buffer(wil, ptr);
322
323 if (!src)
324 return -EINVAL;
325
326 wil_memcpy_fromio_32(hdr, src, sizeof(*hdr));
327
328 return 0;
329 }
330
cmdid2name(u16 cmdid)331 static const char *cmdid2name(u16 cmdid)
332 {
333 switch (cmdid) {
334 case WMI_NOTIFY_REQ_CMDID:
335 return "WMI_NOTIFY_REQ_CMD";
336 case WMI_START_SCAN_CMDID:
337 return "WMI_START_SCAN_CMD";
338 case WMI_CONNECT_CMDID:
339 return "WMI_CONNECT_CMD";
340 case WMI_DISCONNECT_CMDID:
341 return "WMI_DISCONNECT_CMD";
342 case WMI_SW_TX_REQ_CMDID:
343 return "WMI_SW_TX_REQ_CMD";
344 case WMI_GET_RF_SECTOR_PARAMS_CMDID:
345 return "WMI_GET_RF_SECTOR_PARAMS_CMD";
346 case WMI_SET_RF_SECTOR_PARAMS_CMDID:
347 return "WMI_SET_RF_SECTOR_PARAMS_CMD";
348 case WMI_GET_SELECTED_RF_SECTOR_INDEX_CMDID:
349 return "WMI_GET_SELECTED_RF_SECTOR_INDEX_CMD";
350 case WMI_SET_SELECTED_RF_SECTOR_INDEX_CMDID:
351 return "WMI_SET_SELECTED_RF_SECTOR_INDEX_CMD";
352 case WMI_BRP_SET_ANT_LIMIT_CMDID:
353 return "WMI_BRP_SET_ANT_LIMIT_CMD";
354 case WMI_TOF_SESSION_START_CMDID:
355 return "WMI_TOF_SESSION_START_CMD";
356 case WMI_AOA_MEAS_CMDID:
357 return "WMI_AOA_MEAS_CMD";
358 case WMI_PMC_CMDID:
359 return "WMI_PMC_CMD";
360 case WMI_TOF_GET_TX_RX_OFFSET_CMDID:
361 return "WMI_TOF_GET_TX_RX_OFFSET_CMD";
362 case WMI_TOF_SET_TX_RX_OFFSET_CMDID:
363 return "WMI_TOF_SET_TX_RX_OFFSET_CMD";
364 case WMI_VRING_CFG_CMDID:
365 return "WMI_VRING_CFG_CMD";
366 case WMI_BCAST_VRING_CFG_CMDID:
367 return "WMI_BCAST_VRING_CFG_CMD";
368 case WMI_TRAFFIC_SUSPEND_CMDID:
369 return "WMI_TRAFFIC_SUSPEND_CMD";
370 case WMI_TRAFFIC_RESUME_CMDID:
371 return "WMI_TRAFFIC_RESUME_CMD";
372 case WMI_ECHO_CMDID:
373 return "WMI_ECHO_CMD";
374 case WMI_SET_MAC_ADDRESS_CMDID:
375 return "WMI_SET_MAC_ADDRESS_CMD";
376 case WMI_LED_CFG_CMDID:
377 return "WMI_LED_CFG_CMD";
378 case WMI_PCP_START_CMDID:
379 return "WMI_PCP_START_CMD";
380 case WMI_PCP_STOP_CMDID:
381 return "WMI_PCP_STOP_CMD";
382 case WMI_SET_SSID_CMDID:
383 return "WMI_SET_SSID_CMD";
384 case WMI_GET_SSID_CMDID:
385 return "WMI_GET_SSID_CMD";
386 case WMI_SET_PCP_CHANNEL_CMDID:
387 return "WMI_SET_PCP_CHANNEL_CMD";
388 case WMI_GET_PCP_CHANNEL_CMDID:
389 return "WMI_GET_PCP_CHANNEL_CMD";
390 case WMI_P2P_CFG_CMDID:
391 return "WMI_P2P_CFG_CMD";
392 case WMI_PORT_ALLOCATE_CMDID:
393 return "WMI_PORT_ALLOCATE_CMD";
394 case WMI_PORT_DELETE_CMDID:
395 return "WMI_PORT_DELETE_CMD";
396 case WMI_START_LISTEN_CMDID:
397 return "WMI_START_LISTEN_CMD";
398 case WMI_START_SEARCH_CMDID:
399 return "WMI_START_SEARCH_CMD";
400 case WMI_DISCOVERY_STOP_CMDID:
401 return "WMI_DISCOVERY_STOP_CMD";
402 case WMI_DELETE_CIPHER_KEY_CMDID:
403 return "WMI_DELETE_CIPHER_KEY_CMD";
404 case WMI_ADD_CIPHER_KEY_CMDID:
405 return "WMI_ADD_CIPHER_KEY_CMD";
406 case WMI_SET_APPIE_CMDID:
407 return "WMI_SET_APPIE_CMD";
408 case WMI_CFG_RX_CHAIN_CMDID:
409 return "WMI_CFG_RX_CHAIN_CMD";
410 case WMI_TEMP_SENSE_CMDID:
411 return "WMI_TEMP_SENSE_CMD";
412 case WMI_DEL_STA_CMDID:
413 return "WMI_DEL_STA_CMD";
414 case WMI_DISCONNECT_STA_CMDID:
415 return "WMI_DISCONNECT_STA_CMD";
416 case WMI_RING_BA_EN_CMDID:
417 return "WMI_RING_BA_EN_CMD";
418 case WMI_RING_BA_DIS_CMDID:
419 return "WMI_RING_BA_DIS_CMD";
420 case WMI_RCP_DELBA_CMDID:
421 return "WMI_RCP_DELBA_CMD";
422 case WMI_RCP_ADDBA_RESP_CMDID:
423 return "WMI_RCP_ADDBA_RESP_CMD";
424 case WMI_RCP_ADDBA_RESP_EDMA_CMDID:
425 return "WMI_RCP_ADDBA_RESP_EDMA_CMD";
426 case WMI_PS_DEV_PROFILE_CFG_CMDID:
427 return "WMI_PS_DEV_PROFILE_CFG_CMD";
428 case WMI_SET_MGMT_RETRY_LIMIT_CMDID:
429 return "WMI_SET_MGMT_RETRY_LIMIT_CMD";
430 case WMI_GET_MGMT_RETRY_LIMIT_CMDID:
431 return "WMI_GET_MGMT_RETRY_LIMIT_CMD";
432 case WMI_ABORT_SCAN_CMDID:
433 return "WMI_ABORT_SCAN_CMD";
434 case WMI_NEW_STA_CMDID:
435 return "WMI_NEW_STA_CMD";
436 case WMI_SET_THERMAL_THROTTLING_CFG_CMDID:
437 return "WMI_SET_THERMAL_THROTTLING_CFG_CMD";
438 case WMI_GET_THERMAL_THROTTLING_CFG_CMDID:
439 return "WMI_GET_THERMAL_THROTTLING_CFG_CMD";
440 case WMI_LINK_MAINTAIN_CFG_WRITE_CMDID:
441 return "WMI_LINK_MAINTAIN_CFG_WRITE_CMD";
442 case WMI_LO_POWER_CALIB_FROM_OTP_CMDID:
443 return "WMI_LO_POWER_CALIB_FROM_OTP_CMD";
444 case WMI_START_SCHED_SCAN_CMDID:
445 return "WMI_START_SCHED_SCAN_CMD";
446 case WMI_STOP_SCHED_SCAN_CMDID:
447 return "WMI_STOP_SCHED_SCAN_CMD";
448 case WMI_TX_STATUS_RING_ADD_CMDID:
449 return "WMI_TX_STATUS_RING_ADD_CMD";
450 case WMI_RX_STATUS_RING_ADD_CMDID:
451 return "WMI_RX_STATUS_RING_ADD_CMD";
452 case WMI_TX_DESC_RING_ADD_CMDID:
453 return "WMI_TX_DESC_RING_ADD_CMD";
454 case WMI_RX_DESC_RING_ADD_CMDID:
455 return "WMI_RX_DESC_RING_ADD_CMD";
456 case WMI_BCAST_DESC_RING_ADD_CMDID:
457 return "WMI_BCAST_DESC_RING_ADD_CMD";
458 case WMI_CFG_DEF_RX_OFFLOAD_CMDID:
459 return "WMI_CFG_DEF_RX_OFFLOAD_CMD";
460 case WMI_LINK_STATS_CMDID:
461 return "WMI_LINK_STATS_CMD";
462 case WMI_SW_TX_REQ_EXT_CMDID:
463 return "WMI_SW_TX_REQ_EXT_CMDID";
464 case WMI_FT_AUTH_CMDID:
465 return "WMI_FT_AUTH_CMD";
466 case WMI_FT_REASSOC_CMDID:
467 return "WMI_FT_REASSOC_CMD";
468 case WMI_UPDATE_FT_IES_CMDID:
469 return "WMI_UPDATE_FT_IES_CMD";
470 case WMI_RBUFCAP_CFG_CMDID:
471 return "WMI_RBUFCAP_CFG_CMD";
472 case WMI_TEMP_SENSE_ALL_CMDID:
473 return "WMI_TEMP_SENSE_ALL_CMDID";
474 case WMI_SET_LINK_MONITOR_CMDID:
475 return "WMI_SET_LINK_MONITOR_CMD";
476 default:
477 return "Untracked CMD";
478 }
479 }
480
eventid2name(u16 eventid)481 static const char *eventid2name(u16 eventid)
482 {
483 switch (eventid) {
484 case WMI_NOTIFY_REQ_DONE_EVENTID:
485 return "WMI_NOTIFY_REQ_DONE_EVENT";
486 case WMI_DISCONNECT_EVENTID:
487 return "WMI_DISCONNECT_EVENT";
488 case WMI_SW_TX_COMPLETE_EVENTID:
489 return "WMI_SW_TX_COMPLETE_EVENT";
490 case WMI_GET_RF_SECTOR_PARAMS_DONE_EVENTID:
491 return "WMI_GET_RF_SECTOR_PARAMS_DONE_EVENT";
492 case WMI_SET_RF_SECTOR_PARAMS_DONE_EVENTID:
493 return "WMI_SET_RF_SECTOR_PARAMS_DONE_EVENT";
494 case WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID:
495 return "WMI_GET_SELECTED_RF_SECTOR_INDEX_DONE_EVENT";
496 case WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENTID:
497 return "WMI_SET_SELECTED_RF_SECTOR_INDEX_DONE_EVENT";
498 case WMI_BRP_SET_ANT_LIMIT_EVENTID:
499 return "WMI_BRP_SET_ANT_LIMIT_EVENT";
500 case WMI_FW_READY_EVENTID:
501 return "WMI_FW_READY_EVENT";
502 case WMI_TRAFFIC_RESUME_EVENTID:
503 return "WMI_TRAFFIC_RESUME_EVENT";
504 case WMI_TOF_GET_TX_RX_OFFSET_EVENTID:
505 return "WMI_TOF_GET_TX_RX_OFFSET_EVENT";
506 case WMI_TOF_SET_TX_RX_OFFSET_EVENTID:
507 return "WMI_TOF_SET_TX_RX_OFFSET_EVENT";
508 case WMI_VRING_CFG_DONE_EVENTID:
509 return "WMI_VRING_CFG_DONE_EVENT";
510 case WMI_READY_EVENTID:
511 return "WMI_READY_EVENT";
512 case WMI_RX_MGMT_PACKET_EVENTID:
513 return "WMI_RX_MGMT_PACKET_EVENT";
514 case WMI_TX_MGMT_PACKET_EVENTID:
515 return "WMI_TX_MGMT_PACKET_EVENT";
516 case WMI_SCAN_COMPLETE_EVENTID:
517 return "WMI_SCAN_COMPLETE_EVENT";
518 case WMI_ACS_PASSIVE_SCAN_COMPLETE_EVENTID:
519 return "WMI_ACS_PASSIVE_SCAN_COMPLETE_EVENT";
520 case WMI_CONNECT_EVENTID:
521 return "WMI_CONNECT_EVENT";
522 case WMI_EAPOL_RX_EVENTID:
523 return "WMI_EAPOL_RX_EVENT";
524 case WMI_BA_STATUS_EVENTID:
525 return "WMI_BA_STATUS_EVENT";
526 case WMI_RCP_ADDBA_REQ_EVENTID:
527 return "WMI_RCP_ADDBA_REQ_EVENT";
528 case WMI_DELBA_EVENTID:
529 return "WMI_DELBA_EVENT";
530 case WMI_RING_EN_EVENTID:
531 return "WMI_RING_EN_EVENT";
532 case WMI_DATA_PORT_OPEN_EVENTID:
533 return "WMI_DATA_PORT_OPEN_EVENT";
534 case WMI_AOA_MEAS_EVENTID:
535 return "WMI_AOA_MEAS_EVENT";
536 case WMI_TOF_SESSION_END_EVENTID:
537 return "WMI_TOF_SESSION_END_EVENT";
538 case WMI_TOF_GET_CAPABILITIES_EVENTID:
539 return "WMI_TOF_GET_CAPABILITIES_EVENT";
540 case WMI_TOF_SET_LCR_EVENTID:
541 return "WMI_TOF_SET_LCR_EVENT";
542 case WMI_TOF_SET_LCI_EVENTID:
543 return "WMI_TOF_SET_LCI_EVENT";
544 case WMI_TOF_FTM_PER_DEST_RES_EVENTID:
545 return "WMI_TOF_FTM_PER_DEST_RES_EVENT";
546 case WMI_TOF_CHANNEL_INFO_EVENTID:
547 return "WMI_TOF_CHANNEL_INFO_EVENT";
548 case WMI_TRAFFIC_SUSPEND_EVENTID:
549 return "WMI_TRAFFIC_SUSPEND_EVENT";
550 case WMI_ECHO_RSP_EVENTID:
551 return "WMI_ECHO_RSP_EVENT";
552 case WMI_LED_CFG_DONE_EVENTID:
553 return "WMI_LED_CFG_DONE_EVENT";
554 case WMI_PCP_STARTED_EVENTID:
555 return "WMI_PCP_STARTED_EVENT";
556 case WMI_PCP_STOPPED_EVENTID:
557 return "WMI_PCP_STOPPED_EVENT";
558 case WMI_GET_SSID_EVENTID:
559 return "WMI_GET_SSID_EVENT";
560 case WMI_GET_PCP_CHANNEL_EVENTID:
561 return "WMI_GET_PCP_CHANNEL_EVENT";
562 case WMI_P2P_CFG_DONE_EVENTID:
563 return "WMI_P2P_CFG_DONE_EVENT";
564 case WMI_PORT_ALLOCATED_EVENTID:
565 return "WMI_PORT_ALLOCATED_EVENT";
566 case WMI_PORT_DELETED_EVENTID:
567 return "WMI_PORT_DELETED_EVENT";
568 case WMI_LISTEN_STARTED_EVENTID:
569 return "WMI_LISTEN_STARTED_EVENT";
570 case WMI_SEARCH_STARTED_EVENTID:
571 return "WMI_SEARCH_STARTED_EVENT";
572 case WMI_DISCOVERY_STOPPED_EVENTID:
573 return "WMI_DISCOVERY_STOPPED_EVENT";
574 case WMI_CFG_RX_CHAIN_DONE_EVENTID:
575 return "WMI_CFG_RX_CHAIN_DONE_EVENT";
576 case WMI_TEMP_SENSE_DONE_EVENTID:
577 return "WMI_TEMP_SENSE_DONE_EVENT";
578 case WMI_RCP_ADDBA_RESP_SENT_EVENTID:
579 return "WMI_RCP_ADDBA_RESP_SENT_EVENT";
580 case WMI_PS_DEV_PROFILE_CFG_EVENTID:
581 return "WMI_PS_DEV_PROFILE_CFG_EVENT";
582 case WMI_SET_MGMT_RETRY_LIMIT_EVENTID:
583 return "WMI_SET_MGMT_RETRY_LIMIT_EVENT";
584 case WMI_GET_MGMT_RETRY_LIMIT_EVENTID:
585 return "WMI_GET_MGMT_RETRY_LIMIT_EVENT";
586 case WMI_SET_THERMAL_THROTTLING_CFG_EVENTID:
587 return "WMI_SET_THERMAL_THROTTLING_CFG_EVENT";
588 case WMI_GET_THERMAL_THROTTLING_CFG_EVENTID:
589 return "WMI_GET_THERMAL_THROTTLING_CFG_EVENT";
590 case WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENTID:
591 return "WMI_LINK_MAINTAIN_CFG_WRITE_DONE_EVENT";
592 case WMI_LO_POWER_CALIB_FROM_OTP_EVENTID:
593 return "WMI_LO_POWER_CALIB_FROM_OTP_EVENT";
594 case WMI_START_SCHED_SCAN_EVENTID:
595 return "WMI_START_SCHED_SCAN_EVENT";
596 case WMI_STOP_SCHED_SCAN_EVENTID:
597 return "WMI_STOP_SCHED_SCAN_EVENT";
598 case WMI_SCHED_SCAN_RESULT_EVENTID:
599 return "WMI_SCHED_SCAN_RESULT_EVENT";
600 case WMI_TX_STATUS_RING_CFG_DONE_EVENTID:
601 return "WMI_TX_STATUS_RING_CFG_DONE_EVENT";
602 case WMI_RX_STATUS_RING_CFG_DONE_EVENTID:
603 return "WMI_RX_STATUS_RING_CFG_DONE_EVENT";
604 case WMI_TX_DESC_RING_CFG_DONE_EVENTID:
605 return "WMI_TX_DESC_RING_CFG_DONE_EVENT";
606 case WMI_RX_DESC_RING_CFG_DONE_EVENTID:
607 return "WMI_RX_DESC_RING_CFG_DONE_EVENT";
608 case WMI_CFG_DEF_RX_OFFLOAD_DONE_EVENTID:
609 return "WMI_CFG_DEF_RX_OFFLOAD_DONE_EVENT";
610 case WMI_LINK_STATS_CONFIG_DONE_EVENTID:
611 return "WMI_LINK_STATS_CONFIG_DONE_EVENT";
612 case WMI_LINK_STATS_EVENTID:
613 return "WMI_LINK_STATS_EVENT";
614 case WMI_COMMAND_NOT_SUPPORTED_EVENTID:
615 return "WMI_COMMAND_NOT_SUPPORTED_EVENT";
616 case WMI_FT_AUTH_STATUS_EVENTID:
617 return "WMI_FT_AUTH_STATUS_EVENT";
618 case WMI_FT_REASSOC_STATUS_EVENTID:
619 return "WMI_FT_REASSOC_STATUS_EVENT";
620 case WMI_RBUFCAP_CFG_EVENTID:
621 return "WMI_RBUFCAP_CFG_EVENT";
622 case WMI_TEMP_SENSE_ALL_DONE_EVENTID:
623 return "WMI_TEMP_SENSE_ALL_DONE_EVENTID";
624 case WMI_SET_LINK_MONITOR_EVENTID:
625 return "WMI_SET_LINK_MONITOR_EVENT";
626 case WMI_LINK_MONITOR_EVENTID:
627 return "WMI_LINK_MONITOR_EVENT";
628 default:
629 return "Untracked EVENT";
630 }
631 }
632
__wmi_send(struct wil6210_priv * wil,u16 cmdid,u8 mid,void * buf,u16 len)633 static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, u8 mid,
634 void *buf, u16 len)
635 {
636 struct {
637 struct wil6210_mbox_hdr hdr;
638 struct wmi_cmd_hdr wmi;
639 } __packed cmd = {
640 .hdr = {
641 .type = WIL_MBOX_HDR_TYPE_WMI,
642 .flags = 0,
643 .len = cpu_to_le16(sizeof(cmd.wmi) + len),
644 },
645 .wmi = {
646 .mid = mid,
647 .command_id = cpu_to_le16(cmdid),
648 },
649 };
650 struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx;
651 struct wil6210_mbox_ring_desc d_head;
652 u32 next_head;
653 void __iomem *dst;
654 void __iomem *head = wmi_addr(wil, r->head);
655 uint retry;
656 int rc = 0;
657
658 if (len > r->entry_size - sizeof(cmd)) {
659 wil_err(wil, "WMI size too large: %d bytes, max is %d\n",
660 (int)(sizeof(cmd) + len), r->entry_size);
661 return -ERANGE;
662 }
663
664 might_sleep();
665
666 if (!test_bit(wil_status_fwready, wil->status)) {
667 wil_err(wil, "WMI: cannot send command while FW not ready\n");
668 return -EAGAIN;
669 }
670
671 /* Allow sending only suspend / resume commands during susepnd flow */
672 if ((test_bit(wil_status_suspending, wil->status) ||
673 test_bit(wil_status_suspended, wil->status) ||
674 test_bit(wil_status_resuming, wil->status)) &&
675 ((cmdid != WMI_TRAFFIC_SUSPEND_CMDID) &&
676 (cmdid != WMI_TRAFFIC_RESUME_CMDID))) {
677 wil_err(wil, "WMI: reject send_command during suspend\n");
678 return -EINVAL;
679 }
680
681 if (!head) {
682 wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head);
683 return -EINVAL;
684 }
685
686 wil_halp_vote(wil);
687
688 /* read Tx head till it is not busy */
689 for (retry = 5; retry > 0; retry--) {
690 wil_memcpy_fromio_32(&d_head, head, sizeof(d_head));
691 if (d_head.sync == 0)
692 break;
693 msleep(20);
694 }
695 if (d_head.sync != 0) {
696 wil_err(wil, "WMI head busy\n");
697 rc = -EBUSY;
698 goto out;
699 }
700 /* next head */
701 next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size);
702 wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head);
703 /* wait till FW finish with previous command */
704 for (retry = 5; retry > 0; retry--) {
705 if (!test_bit(wil_status_fwready, wil->status)) {
706 wil_err(wil, "WMI: cannot send command while FW not ready\n");
707 rc = -EAGAIN;
708 goto out;
709 }
710 r->tail = wil_r(wil, RGF_MBOX +
711 offsetof(struct wil6210_mbox_ctl, tx.tail));
712 if (next_head != r->tail)
713 break;
714 msleep(20);
715 }
716 if (next_head == r->tail) {
717 wil_err(wil, "WMI ring full\n");
718 rc = -EBUSY;
719 goto out;
720 }
721 dst = wmi_buffer(wil, d_head.addr);
722 if (!dst) {
723 wil_err(wil, "invalid WMI buffer: 0x%08x\n",
724 le32_to_cpu(d_head.addr));
725 rc = -EAGAIN;
726 goto out;
727 }
728 cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq);
729 /* set command */
730 wil_dbg_wmi(wil, "sending %s (0x%04x) [%d] mid %d\n",
731 cmdid2name(cmdid), cmdid, len, mid);
732 wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd,
733 sizeof(cmd), true);
734 wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf,
735 len, true);
736 wil_memcpy_toio_32(dst, &cmd, sizeof(cmd));
737 wil_memcpy_toio_32(dst + sizeof(cmd), buf, len);
738 /* mark entry as full */
739 wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1);
740 /* advance next ptr */
741 wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head),
742 r->head = next_head);
743
744 trace_wil6210_wmi_cmd(&cmd.wmi, buf, len);
745
746 /* interrupt to FW */
747 wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS),
748 SW_INT_MBOX);
749
750 out:
751 wil_halp_unvote(wil);
752 return rc;
753 }
754
wmi_send(struct wil6210_priv * wil,u16 cmdid,u8 mid,void * buf,u16 len)755 int wmi_send(struct wil6210_priv *wil, u16 cmdid, u8 mid, void *buf, u16 len)
756 {
757 int rc;
758
759 mutex_lock(&wil->wmi_mutex);
760 rc = __wmi_send(wil, cmdid, mid, buf, len);
761 mutex_unlock(&wil->wmi_mutex);
762
763 return rc;
764 }
765
766 /*=== Event handlers ===*/
wmi_evt_ready(struct wil6210_vif * vif,int id,void * d,int len)767 static void wmi_evt_ready(struct wil6210_vif *vif, int id, void *d, int len)
768 {
769 struct wil6210_priv *wil = vif_to_wil(vif);
770 struct wiphy *wiphy = wil_to_wiphy(wil);
771 struct wmi_ready_event *evt = d;
772 u8 fw_max_assoc_sta;
773
774 wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n",
775 wil->fw_version, le32_to_cpu(evt->sw_version),
776 evt->mac, evt->numof_additional_mids);
777 if (evt->numof_additional_mids + 1 < wil->max_vifs) {
778 wil_err(wil, "FW does not support enough MIDs (need %d)",
779 wil->max_vifs - 1);
780 return; /* FW load will fail after timeout */
781 }
782 /* ignore MAC address, we already have it from the boot loader */
783 strlcpy(wiphy->fw_version, wil->fw_version, sizeof(wiphy->fw_version));
784
785 if (len > offsetof(struct wmi_ready_event, rfc_read_calib_result)) {
786 wil_dbg_wmi(wil, "rfc calibration result %d\n",
787 evt->rfc_read_calib_result);
788 wil->fw_calib_result = evt->rfc_read_calib_result;
789 }
790
791 fw_max_assoc_sta = WIL6210_RX_DESC_MAX_CID;
792 if (len > offsetof(struct wmi_ready_event, max_assoc_sta) &&
793 evt->max_assoc_sta > 0) {
794 fw_max_assoc_sta = evt->max_assoc_sta;
795 wil_dbg_wmi(wil, "fw reported max assoc sta %d\n",
796 fw_max_assoc_sta);
797
798 if (fw_max_assoc_sta > WIL6210_MAX_CID) {
799 wil_dbg_wmi(wil,
800 "fw max assoc sta %d exceeds max driver supported %d\n",
801 fw_max_assoc_sta, WIL6210_MAX_CID);
802 fw_max_assoc_sta = WIL6210_MAX_CID;
803 }
804 }
805
806 wil->max_assoc_sta = min_t(uint, max_assoc_sta, fw_max_assoc_sta);
807 wil_dbg_wmi(wil, "setting max assoc sta to %d\n", wil->max_assoc_sta);
808
809 wil_set_recovery_state(wil, fw_recovery_idle);
810 set_bit(wil_status_fwready, wil->status);
811 /* let the reset sequence continue */
812 complete(&wil->wmi_ready);
813 }
814
wmi_evt_rx_mgmt(struct wil6210_vif * vif,int id,void * d,int len)815 static void wmi_evt_rx_mgmt(struct wil6210_vif *vif, int id, void *d, int len)
816 {
817 struct wil6210_priv *wil = vif_to_wil(vif);
818 struct wmi_rx_mgmt_packet_event *data = d;
819 struct wiphy *wiphy = wil_to_wiphy(wil);
820 struct ieee80211_mgmt *rx_mgmt_frame =
821 (struct ieee80211_mgmt *)data->payload;
822 int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload);
823 int ch_no;
824 u32 freq;
825 struct ieee80211_channel *channel;
826 s32 signal;
827 __le16 fc;
828 u32 d_len;
829 u16 d_status;
830
831 if (flen < 0) {
832 wil_err(wil, "MGMT Rx: short event, len %d\n", len);
833 return;
834 }
835
836 d_len = le32_to_cpu(data->info.len);
837 if (d_len != flen) {
838 wil_err(wil,
839 "MGMT Rx: length mismatch, d_len %d should be %d\n",
840 d_len, flen);
841 return;
842 }
843
844 ch_no = data->info.channel + 1;
845 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
846 channel = ieee80211_get_channel(wiphy, freq);
847 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
848 signal = 100 * data->info.rssi;
849 else
850 signal = data->info.sqi;
851 d_status = le16_to_cpu(data->info.status);
852 fc = rx_mgmt_frame->frame_control;
853
854 wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d RSSI %d SQI %d%%\n",
855 data->info.channel, data->info.mcs, data->info.rssi,
856 data->info.sqi);
857 wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len,
858 le16_to_cpu(fc));
859 wil_dbg_wmi(wil, "qid %d mid %d cid %d\n",
860 data->info.qid, data->info.mid, data->info.cid);
861 wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
862 d_len, true);
863
864 if (!channel) {
865 wil_err(wil, "Frame on unsupported channel\n");
866 return;
867 }
868
869 if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) {
870 struct cfg80211_bss *bss;
871 struct cfg80211_inform_bss bss_data = {
872 .chan = channel,
873 .scan_width = NL80211_BSS_CHAN_WIDTH_20,
874 .signal = signal,
875 .boottime_ns = ktime_to_ns(ktime_get_boottime()),
876 };
877 u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp);
878 u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info);
879 u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int);
880 const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable;
881 size_t ie_len = d_len - offsetof(struct ieee80211_mgmt,
882 u.beacon.variable);
883 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
884 wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf);
885 wil_dbg_wmi(wil, "Beacon interval : %d\n", bi);
886 wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf,
887 ie_len, true);
888
889 wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap);
890
891 bss = cfg80211_inform_bss_frame_data(wiphy, &bss_data,
892 rx_mgmt_frame,
893 d_len, GFP_KERNEL);
894 if (bss) {
895 wil_dbg_wmi(wil, "Added BSS %pM\n",
896 rx_mgmt_frame->bssid);
897 cfg80211_put_bss(wiphy, bss);
898 } else {
899 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
900 }
901 } else {
902 mutex_lock(&wil->vif_mutex);
903 cfg80211_rx_mgmt(vif_to_radio_wdev(wil, vif), freq, signal,
904 (void *)rx_mgmt_frame, d_len, 0);
905 mutex_unlock(&wil->vif_mutex);
906 }
907 }
908
wmi_evt_tx_mgmt(struct wil6210_vif * vif,int id,void * d,int len)909 static void wmi_evt_tx_mgmt(struct wil6210_vif *vif, int id, void *d, int len)
910 {
911 struct wmi_tx_mgmt_packet_event *data = d;
912 struct ieee80211_mgmt *mgmt_frame =
913 (struct ieee80211_mgmt *)data->payload;
914 int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload);
915
916 wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame,
917 flen, true);
918 }
919
wmi_evt_scan_complete(struct wil6210_vif * vif,int id,void * d,int len)920 static void wmi_evt_scan_complete(struct wil6210_vif *vif, int id,
921 void *d, int len)
922 {
923 struct wil6210_priv *wil = vif_to_wil(vif);
924
925 mutex_lock(&wil->vif_mutex);
926 if (vif->scan_request) {
927 struct wmi_scan_complete_event *data = d;
928 int status = le32_to_cpu(data->status);
929 struct cfg80211_scan_info info = {
930 .aborted = ((status != WMI_SCAN_SUCCESS) &&
931 (status != WMI_SCAN_ABORT_REJECTED)),
932 };
933
934 wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status);
935 wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n",
936 vif->scan_request, info.aborted);
937 del_timer_sync(&vif->scan_timer);
938 cfg80211_scan_done(vif->scan_request, &info);
939 if (vif->mid == 0)
940 wil->radio_wdev = wil->main_ndev->ieee80211_ptr;
941 vif->scan_request = NULL;
942 wake_up_interruptible(&wil->wq);
943 if (vif->p2p.pending_listen_wdev) {
944 wil_dbg_misc(wil, "Scheduling delayed listen\n");
945 schedule_work(&vif->p2p.delayed_listen_work);
946 }
947 } else {
948 wil_err(wil, "SCAN_COMPLETE while not scanning\n");
949 }
950 mutex_unlock(&wil->vif_mutex);
951 }
952
wmi_evt_connect(struct wil6210_vif * vif,int id,void * d,int len)953 static void wmi_evt_connect(struct wil6210_vif *vif, int id, void *d, int len)
954 {
955 struct wil6210_priv *wil = vif_to_wil(vif);
956 struct net_device *ndev = vif_to_ndev(vif);
957 struct wireless_dev *wdev = vif_to_wdev(vif);
958 struct wmi_connect_event *evt = d;
959 int ch; /* channel number */
960 struct station_info *sinfo;
961 u8 *assoc_req_ie, *assoc_resp_ie;
962 size_t assoc_req_ielen, assoc_resp_ielen;
963 /* capinfo(u16) + listen_interval(u16) + IEs */
964 const size_t assoc_req_ie_offset = sizeof(u16) * 2;
965 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
966 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
967 int rc;
968
969 if (len < sizeof(*evt)) {
970 wil_err(wil, "Connect event too short : %d bytes\n", len);
971 return;
972 }
973 if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len +
974 evt->assoc_resp_len) {
975 wil_err(wil,
976 "Connect event corrupted : %d != %d + %d + %d + %d\n",
977 len, (int)sizeof(*evt), evt->beacon_ie_len,
978 evt->assoc_req_len, evt->assoc_resp_len);
979 return;
980 }
981 if (evt->cid >= wil->max_assoc_sta) {
982 wil_err(wil, "Connect CID invalid : %d\n", evt->cid);
983 return;
984 }
985
986 ch = evt->channel + 1;
987 wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n",
988 evt->bssid, ch, evt->cid, evt->aid);
989 wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1,
990 evt->assoc_info, len - sizeof(*evt), true);
991
992 /* figure out IE's */
993 assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len +
994 assoc_req_ie_offset];
995 assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset;
996 if (evt->assoc_req_len <= assoc_req_ie_offset) {
997 assoc_req_ie = NULL;
998 assoc_req_ielen = 0;
999 }
1000
1001 assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len +
1002 evt->assoc_req_len +
1003 assoc_resp_ie_offset];
1004 assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset;
1005 if (evt->assoc_resp_len <= assoc_resp_ie_offset) {
1006 assoc_resp_ie = NULL;
1007 assoc_resp_ielen = 0;
1008 }
1009
1010 if (test_bit(wil_status_resetting, wil->status) ||
1011 !test_bit(wil_status_fwready, wil->status)) {
1012 wil_err(wil, "status_resetting, cancel connect event, CID %d\n",
1013 evt->cid);
1014 /* no need for cleanup, wil_reset will do that */
1015 return;
1016 }
1017
1018 mutex_lock(&wil->mutex);
1019
1020 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
1021 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
1022 if (!test_bit(wil_vif_fwconnecting, vif->status)) {
1023 wil_err(wil, "Not in connecting state\n");
1024 mutex_unlock(&wil->mutex);
1025 return;
1026 }
1027 del_timer_sync(&vif->connect_timer);
1028 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
1029 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
1030 if (wil->sta[evt->cid].status != wil_sta_unused) {
1031 wil_err(wil, "AP: Invalid status %d for CID %d\n",
1032 wil->sta[evt->cid].status, evt->cid);
1033 mutex_unlock(&wil->mutex);
1034 return;
1035 }
1036 }
1037
1038 ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid);
1039 wil->sta[evt->cid].mid = vif->mid;
1040 wil->sta[evt->cid].status = wil_sta_conn_pending;
1041
1042 rc = wil_ring_init_tx(vif, evt->cid);
1043 if (rc) {
1044 wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n",
1045 evt->cid, rc);
1046 wmi_disconnect_sta(vif, wil->sta[evt->cid].addr,
1047 WLAN_REASON_UNSPECIFIED, false);
1048 } else {
1049 wil_info(wil, "successful connection to CID %d\n", evt->cid);
1050 }
1051
1052 if ((wdev->iftype == NL80211_IFTYPE_STATION) ||
1053 (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) {
1054 if (rc) {
1055 netif_carrier_off(ndev);
1056 wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS);
1057 wil_err(wil, "cfg80211_connect_result with failure\n");
1058 cfg80211_connect_result(ndev, evt->bssid, NULL, 0,
1059 NULL, 0,
1060 WLAN_STATUS_UNSPECIFIED_FAILURE,
1061 GFP_KERNEL);
1062 goto out;
1063 } else {
1064 struct wiphy *wiphy = wil_to_wiphy(wil);
1065
1066 cfg80211_ref_bss(wiphy, vif->bss);
1067 cfg80211_connect_bss(ndev, evt->bssid, vif->bss,
1068 assoc_req_ie, assoc_req_ielen,
1069 assoc_resp_ie, assoc_resp_ielen,
1070 WLAN_STATUS_SUCCESS, GFP_KERNEL,
1071 NL80211_TIMEOUT_UNSPECIFIED);
1072 }
1073 vif->bss = NULL;
1074 } else if ((wdev->iftype == NL80211_IFTYPE_AP) ||
1075 (wdev->iftype == NL80211_IFTYPE_P2P_GO)) {
1076
1077 if (rc) {
1078 if (disable_ap_sme)
1079 /* notify new_sta has failed */
1080 cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL);
1081 goto out;
1082 }
1083
1084 sinfo = kzalloc(sizeof(*sinfo), GFP_KERNEL);
1085 if (!sinfo) {
1086 rc = -ENOMEM;
1087 goto out;
1088 }
1089
1090 sinfo->generation = wil->sinfo_gen++;
1091
1092 if (assoc_req_ie) {
1093 sinfo->assoc_req_ies = assoc_req_ie;
1094 sinfo->assoc_req_ies_len = assoc_req_ielen;
1095 }
1096
1097 cfg80211_new_sta(ndev, evt->bssid, sinfo, GFP_KERNEL);
1098
1099 kfree(sinfo);
1100 } else {
1101 wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype,
1102 evt->cid);
1103 goto out;
1104 }
1105
1106 wil->sta[evt->cid].status = wil_sta_connected;
1107 wil->sta[evt->cid].aid = evt->aid;
1108 if (!test_and_set_bit(wil_vif_fwconnected, vif->status))
1109 atomic_inc(&wil->connected_vifs);
1110 wil_update_net_queues_bh(wil, vif, NULL, false);
1111
1112 out:
1113 if (rc) {
1114 wil->sta[evt->cid].status = wil_sta_unused;
1115 wil->sta[evt->cid].mid = U8_MAX;
1116 }
1117 clear_bit(wil_vif_fwconnecting, vif->status);
1118 mutex_unlock(&wil->mutex);
1119 }
1120
wmi_evt_disconnect(struct wil6210_vif * vif,int id,void * d,int len)1121 static void wmi_evt_disconnect(struct wil6210_vif *vif, int id,
1122 void *d, int len)
1123 {
1124 struct wil6210_priv *wil = vif_to_wil(vif);
1125 struct wmi_disconnect_event *evt = d;
1126 u16 reason_code = le16_to_cpu(evt->protocol_reason_status);
1127
1128 wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n",
1129 evt->bssid, reason_code, evt->disconnect_reason);
1130
1131 wil->sinfo_gen++;
1132
1133 if (test_bit(wil_status_resetting, wil->status) ||
1134 !test_bit(wil_status_fwready, wil->status)) {
1135 wil_err(wil, "status_resetting, cancel disconnect event\n");
1136 /* no need for cleanup, wil_reset will do that */
1137 return;
1138 }
1139
1140 mutex_lock(&wil->mutex);
1141 wil6210_disconnect_complete(vif, evt->bssid, reason_code);
1142 if (disable_ap_sme) {
1143 struct wireless_dev *wdev = vif_to_wdev(vif);
1144 struct net_device *ndev = vif_to_ndev(vif);
1145
1146 /* disconnect event in disable_ap_sme mode means link loss */
1147 switch (wdev->iftype) {
1148 /* AP-like interface */
1149 case NL80211_IFTYPE_AP:
1150 case NL80211_IFTYPE_P2P_GO:
1151 /* notify hostapd about link loss */
1152 cfg80211_cqm_pktloss_notify(ndev, evt->bssid, 0,
1153 GFP_KERNEL);
1154 break;
1155 default:
1156 break;
1157 }
1158 }
1159 mutex_unlock(&wil->mutex);
1160 }
1161
1162 /*
1163 * Firmware reports EAPOL frame using WME event.
1164 * Reconstruct Ethernet frame and deliver it via normal Rx
1165 */
wmi_evt_eapol_rx(struct wil6210_vif * vif,int id,void * d,int len)1166 static void wmi_evt_eapol_rx(struct wil6210_vif *vif, int id, void *d, int len)
1167 {
1168 struct wil6210_priv *wil = vif_to_wil(vif);
1169 struct net_device *ndev = vif_to_ndev(vif);
1170 struct wmi_eapol_rx_event *evt = d;
1171 u16 eapol_len = le16_to_cpu(evt->eapol_len);
1172 int sz = eapol_len + ETH_HLEN;
1173 struct sk_buff *skb;
1174 struct ethhdr *eth;
1175 int cid;
1176 struct wil_net_stats *stats = NULL;
1177
1178 wil_dbg_wmi(wil, "EAPOL len %d from %pM MID %d\n", eapol_len,
1179 evt->src_mac, vif->mid);
1180
1181 cid = wil_find_cid(wil, vif->mid, evt->src_mac);
1182 if (cid >= 0)
1183 stats = &wil->sta[cid].stats;
1184
1185 if (eapol_len > 196) { /* TODO: revisit size limit */
1186 wil_err(wil, "EAPOL too large\n");
1187 return;
1188 }
1189
1190 skb = alloc_skb(sz, GFP_KERNEL);
1191 if (!skb) {
1192 wil_err(wil, "Failed to allocate skb\n");
1193 return;
1194 }
1195
1196 eth = skb_put(skb, ETH_HLEN);
1197 ether_addr_copy(eth->h_dest, ndev->dev_addr);
1198 ether_addr_copy(eth->h_source, evt->src_mac);
1199 eth->h_proto = cpu_to_be16(ETH_P_PAE);
1200 skb_put_data(skb, evt->eapol, eapol_len);
1201 skb->protocol = eth_type_trans(skb, ndev);
1202 if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) {
1203 ndev->stats.rx_packets++;
1204 ndev->stats.rx_bytes += sz;
1205 if (stats) {
1206 stats->rx_packets++;
1207 stats->rx_bytes += sz;
1208 }
1209 } else {
1210 ndev->stats.rx_dropped++;
1211 if (stats)
1212 stats->rx_dropped++;
1213 }
1214 }
1215
wmi_evt_ring_en(struct wil6210_vif * vif,int id,void * d,int len)1216 static void wmi_evt_ring_en(struct wil6210_vif *vif, int id, void *d, int len)
1217 {
1218 struct wil6210_priv *wil = vif_to_wil(vif);
1219 struct wmi_ring_en_event *evt = d;
1220 u8 vri = evt->ring_index;
1221 struct wireless_dev *wdev = vif_to_wdev(vif);
1222 struct wil_sta_info *sta;
1223 u8 cid;
1224 struct key_params params;
1225
1226 wil_dbg_wmi(wil, "Enable vring %d MID %d\n", vri, vif->mid);
1227
1228 if (vri >= ARRAY_SIZE(wil->ring_tx)) {
1229 wil_err(wil, "Enable for invalid vring %d\n", vri);
1230 return;
1231 }
1232
1233 if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme ||
1234 test_bit(wil_vif_ft_roam, vif->status))
1235 /* in AP mode with disable_ap_sme that is not FT,
1236 * this is done by wil_cfg80211_change_station()
1237 */
1238 wil->ring_tx_data[vri].dot1x_open = true;
1239 if (vri == vif->bcast_ring) /* no BA for bcast */
1240 return;
1241
1242 cid = wil->ring2cid_tid[vri][0];
1243 if (!wil_cid_valid(wil, cid)) {
1244 wil_err(wil, "invalid cid %d for vring %d\n", cid, vri);
1245 return;
1246 }
1247
1248 /* In FT mode we get key but not store it as it is received
1249 * before WMI_CONNECT_EVENT received from FW.
1250 * wil_set_crypto_rx is called here to reset the security PN
1251 */
1252 sta = &wil->sta[cid];
1253 if (test_bit(wil_vif_ft_roam, vif->status)) {
1254 memset(¶ms, 0, sizeof(params));
1255 wil_set_crypto_rx(0, WMI_KEY_USE_PAIRWISE, sta, ¶ms);
1256 if (wdev->iftype != NL80211_IFTYPE_AP)
1257 clear_bit(wil_vif_ft_roam, vif->status);
1258 }
1259
1260 if (agg_wsize >= 0)
1261 wil_addba_tx_request(wil, vri, agg_wsize);
1262 }
1263
wmi_evt_ba_status(struct wil6210_vif * vif,int id,void * d,int len)1264 static void wmi_evt_ba_status(struct wil6210_vif *vif, int id,
1265 void *d, int len)
1266 {
1267 struct wil6210_priv *wil = vif_to_wil(vif);
1268 struct wmi_ba_status_event *evt = d;
1269 struct wil_ring_tx_data *txdata;
1270
1271 wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n",
1272 evt->ringid,
1273 evt->status == WMI_BA_AGREED ? "OK" : "N/A",
1274 evt->agg_wsize, __le16_to_cpu(evt->ba_timeout),
1275 evt->amsdu ? "+" : "-");
1276
1277 if (evt->ringid >= WIL6210_MAX_TX_RINGS) {
1278 wil_err(wil, "invalid ring id %d\n", evt->ringid);
1279 return;
1280 }
1281
1282 if (evt->status != WMI_BA_AGREED) {
1283 evt->ba_timeout = 0;
1284 evt->agg_wsize = 0;
1285 evt->amsdu = 0;
1286 }
1287
1288 txdata = &wil->ring_tx_data[evt->ringid];
1289
1290 txdata->agg_timeout = le16_to_cpu(evt->ba_timeout);
1291 txdata->agg_wsize = evt->agg_wsize;
1292 txdata->agg_amsdu = evt->amsdu;
1293 txdata->addba_in_progress = false;
1294 }
1295
wmi_evt_addba_rx_req(struct wil6210_vif * vif,int id,void * d,int len)1296 static void wmi_evt_addba_rx_req(struct wil6210_vif *vif, int id,
1297 void *d, int len)
1298 {
1299 struct wil6210_priv *wil = vif_to_wil(vif);
1300 u8 cid, tid;
1301 struct wmi_rcp_addba_req_event *evt = d;
1302
1303 if (evt->cidxtid != CIDXTID_EXTENDED_CID_TID) {
1304 parse_cidxtid(evt->cidxtid, &cid, &tid);
1305 } else {
1306 cid = evt->cid;
1307 tid = evt->tid;
1308 }
1309 wil_addba_rx_request(wil, vif->mid, cid, tid, evt->dialog_token,
1310 evt->ba_param_set, evt->ba_timeout,
1311 evt->ba_seq_ctrl);
1312 }
1313
wmi_evt_delba(struct wil6210_vif * vif,int id,void * d,int len)1314 static void wmi_evt_delba(struct wil6210_vif *vif, int id, void *d, int len)
1315 __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
1316 {
1317 struct wil6210_priv *wil = vif_to_wil(vif);
1318 struct wmi_delba_event *evt = d;
1319 u8 cid, tid;
1320 u16 reason = __le16_to_cpu(evt->reason);
1321 struct wil_sta_info *sta;
1322 struct wil_tid_ampdu_rx *r;
1323
1324 might_sleep();
1325
1326 if (evt->cidxtid != CIDXTID_EXTENDED_CID_TID) {
1327 parse_cidxtid(evt->cidxtid, &cid, &tid);
1328 } else {
1329 cid = evt->cid;
1330 tid = evt->tid;
1331 }
1332
1333 if (!wil_cid_valid(wil, cid)) {
1334 wil_err(wil, "DELBA: Invalid CID %d\n", cid);
1335 return;
1336 }
1337
1338 wil_dbg_wmi(wil, "DELBA MID %d CID %d TID %d from %s reason %d\n",
1339 vif->mid, cid, tid,
1340 evt->from_initiator ? "originator" : "recipient",
1341 reason);
1342 if (!evt->from_initiator) {
1343 int i;
1344 /* find Tx vring it belongs to */
1345 for (i = 0; i < ARRAY_SIZE(wil->ring2cid_tid); i++) {
1346 if (wil->ring2cid_tid[i][0] == cid &&
1347 wil->ring2cid_tid[i][1] == tid) {
1348 struct wil_ring_tx_data *txdata =
1349 &wil->ring_tx_data[i];
1350
1351 wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i);
1352 txdata->agg_timeout = 0;
1353 txdata->agg_wsize = 0;
1354 txdata->addba_in_progress = false;
1355
1356 break; /* max. 1 matching ring */
1357 }
1358 }
1359 if (i >= ARRAY_SIZE(wil->ring2cid_tid))
1360 wil_err(wil, "DELBA: unable to find Tx vring\n");
1361 return;
1362 }
1363
1364 sta = &wil->sta[cid];
1365
1366 spin_lock_bh(&sta->tid_rx_lock);
1367
1368 r = sta->tid_rx[tid];
1369 sta->tid_rx[tid] = NULL;
1370 wil_tid_ampdu_rx_free(wil, r);
1371
1372 spin_unlock_bh(&sta->tid_rx_lock);
1373 }
1374
1375 static void
wmi_evt_sched_scan_result(struct wil6210_vif * vif,int id,void * d,int len)1376 wmi_evt_sched_scan_result(struct wil6210_vif *vif, int id, void *d, int len)
1377 {
1378 struct wil6210_priv *wil = vif_to_wil(vif);
1379 struct wmi_sched_scan_result_event *data = d;
1380 struct wiphy *wiphy = wil_to_wiphy(wil);
1381 struct ieee80211_mgmt *rx_mgmt_frame =
1382 (struct ieee80211_mgmt *)data->payload;
1383 int flen = len - offsetof(struct wmi_sched_scan_result_event, payload);
1384 int ch_no;
1385 u32 freq;
1386 struct ieee80211_channel *channel;
1387 s32 signal;
1388 __le16 fc;
1389 u32 d_len;
1390 struct cfg80211_bss *bss;
1391 struct cfg80211_inform_bss bss_data = {
1392 .scan_width = NL80211_BSS_CHAN_WIDTH_20,
1393 .boottime_ns = ktime_to_ns(ktime_get_boottime()),
1394 };
1395
1396 if (flen < 0) {
1397 wil_err(wil, "sched scan result event too short, len %d\n",
1398 len);
1399 return;
1400 }
1401
1402 d_len = le32_to_cpu(data->info.len);
1403 if (d_len != flen) {
1404 wil_err(wil,
1405 "sched scan result length mismatch, d_len %d should be %d\n",
1406 d_len, flen);
1407 return;
1408 }
1409
1410 fc = rx_mgmt_frame->frame_control;
1411 if (!ieee80211_is_probe_resp(fc)) {
1412 wil_err(wil, "sched scan result invalid frame, fc 0x%04x\n",
1413 fc);
1414 return;
1415 }
1416
1417 ch_no = data->info.channel + 1;
1418 freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ);
1419 channel = ieee80211_get_channel(wiphy, freq);
1420 if (test_bit(WMI_FW_CAPABILITY_RSSI_REPORTING, wil->fw_capabilities))
1421 signal = 100 * data->info.rssi;
1422 else
1423 signal = data->info.sqi;
1424
1425 wil_dbg_wmi(wil, "sched scan result: channel %d MCS %d RSSI %d\n",
1426 data->info.channel, data->info.mcs, data->info.rssi);
1427 wil_dbg_wmi(wil, "len %d qid %d mid %d cid %d\n",
1428 d_len, data->info.qid, data->info.mid, data->info.cid);
1429 wil_hex_dump_wmi("PROBE ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame,
1430 d_len, true);
1431
1432 if (!channel) {
1433 wil_err(wil, "Frame on unsupported channel\n");
1434 return;
1435 }
1436
1437 bss_data.signal = signal;
1438 bss_data.chan = channel;
1439 bss = cfg80211_inform_bss_frame_data(wiphy, &bss_data, rx_mgmt_frame,
1440 d_len, GFP_KERNEL);
1441 if (bss) {
1442 wil_dbg_wmi(wil, "Added BSS %pM\n", rx_mgmt_frame->bssid);
1443 cfg80211_put_bss(wiphy, bss);
1444 } else {
1445 wil_err(wil, "cfg80211_inform_bss_frame() failed\n");
1446 }
1447
1448 cfg80211_sched_scan_results(wiphy, 0);
1449 }
1450
wil_link_stats_store_basic(struct wil6210_vif * vif,struct wmi_link_stats_basic * basic)1451 static void wil_link_stats_store_basic(struct wil6210_vif *vif,
1452 struct wmi_link_stats_basic *basic)
1453 {
1454 struct wil6210_priv *wil = vif_to_wil(vif);
1455 u8 cid = basic->cid;
1456 struct wil_sta_info *sta;
1457
1458 if (cid < 0 || cid >= wil->max_assoc_sta) {
1459 wil_err(wil, "invalid cid %d\n", cid);
1460 return;
1461 }
1462
1463 sta = &wil->sta[cid];
1464 sta->fw_stats_basic = *basic;
1465 }
1466
wil_link_stats_store_global(struct wil6210_vif * vif,struct wmi_link_stats_global * global)1467 static void wil_link_stats_store_global(struct wil6210_vif *vif,
1468 struct wmi_link_stats_global *global)
1469 {
1470 struct wil6210_priv *wil = vif_to_wil(vif);
1471
1472 wil->fw_stats_global.stats = *global;
1473 }
1474
wmi_link_stats_parse(struct wil6210_vif * vif,u64 tsf,bool has_next,void * payload,size_t payload_size)1475 static void wmi_link_stats_parse(struct wil6210_vif *vif, u64 tsf,
1476 bool has_next, void *payload,
1477 size_t payload_size)
1478 {
1479 struct wil6210_priv *wil = vif_to_wil(vif);
1480 size_t hdr_size = sizeof(struct wmi_link_stats_record);
1481 size_t stats_size, record_size, expected_size;
1482 struct wmi_link_stats_record *hdr;
1483
1484 if (payload_size < hdr_size) {
1485 wil_err(wil, "link stats wrong event size %zu\n", payload_size);
1486 return;
1487 }
1488
1489 while (payload_size >= hdr_size) {
1490 hdr = payload;
1491 stats_size = le16_to_cpu(hdr->record_size);
1492 record_size = hdr_size + stats_size;
1493
1494 if (payload_size < record_size) {
1495 wil_err(wil, "link stats payload ended unexpectedly, size %zu < %zu\n",
1496 payload_size, record_size);
1497 return;
1498 }
1499
1500 switch (hdr->record_type_id) {
1501 case WMI_LINK_STATS_TYPE_BASIC:
1502 expected_size = sizeof(struct wmi_link_stats_basic);
1503 if (stats_size < expected_size) {
1504 wil_err(wil, "link stats invalid basic record size %zu < %zu\n",
1505 stats_size, expected_size);
1506 return;
1507 }
1508 if (vif->fw_stats_ready) {
1509 /* clean old statistics */
1510 vif->fw_stats_tsf = 0;
1511 vif->fw_stats_ready = false;
1512 }
1513
1514 wil_link_stats_store_basic(vif, payload + hdr_size);
1515
1516 if (!has_next) {
1517 vif->fw_stats_tsf = tsf;
1518 vif->fw_stats_ready = true;
1519 }
1520
1521 break;
1522 case WMI_LINK_STATS_TYPE_GLOBAL:
1523 expected_size = sizeof(struct wmi_link_stats_global);
1524 if (stats_size < sizeof(struct wmi_link_stats_global)) {
1525 wil_err(wil, "link stats invalid global record size %zu < %zu\n",
1526 stats_size, expected_size);
1527 return;
1528 }
1529
1530 if (wil->fw_stats_global.ready) {
1531 /* clean old statistics */
1532 wil->fw_stats_global.tsf = 0;
1533 wil->fw_stats_global.ready = false;
1534 }
1535
1536 wil_link_stats_store_global(vif, payload + hdr_size);
1537
1538 if (!has_next) {
1539 wil->fw_stats_global.tsf = tsf;
1540 wil->fw_stats_global.ready = true;
1541 }
1542
1543 break;
1544 default:
1545 break;
1546 }
1547
1548 /* skip to next record */
1549 payload += record_size;
1550 payload_size -= record_size;
1551 }
1552 }
1553
1554 static void
wmi_evt_link_stats(struct wil6210_vif * vif,int id,void * d,int len)1555 wmi_evt_link_stats(struct wil6210_vif *vif, int id, void *d, int len)
1556 {
1557 struct wil6210_priv *wil = vif_to_wil(vif);
1558 struct wmi_link_stats_event *evt = d;
1559 size_t payload_size;
1560
1561 if (len < offsetof(struct wmi_link_stats_event, payload)) {
1562 wil_err(wil, "stats event way too short %d\n", len);
1563 return;
1564 }
1565 payload_size = le16_to_cpu(evt->payload_size);
1566 if (len < sizeof(struct wmi_link_stats_event) + payload_size) {
1567 wil_err(wil, "stats event too short %d\n", len);
1568 return;
1569 }
1570
1571 wmi_link_stats_parse(vif, le64_to_cpu(evt->tsf), evt->has_next,
1572 evt->payload, payload_size);
1573 }
1574
1575 /* find cid and ringid for the station vif
1576 *
1577 * return error, if other interfaces are used or ring was not found
1578 */
wil_find_cid_ringid_sta(struct wil6210_priv * wil,struct wil6210_vif * vif,int * cid,int * ringid)1579 static int wil_find_cid_ringid_sta(struct wil6210_priv *wil,
1580 struct wil6210_vif *vif,
1581 int *cid,
1582 int *ringid)
1583 {
1584 struct wil_ring *ring;
1585 struct wil_ring_tx_data *txdata;
1586 int min_ring_id = wil_get_min_tx_ring_id(wil);
1587 int i;
1588 u8 lcid;
1589
1590 if (!(vif->wdev.iftype == NL80211_IFTYPE_STATION ||
1591 vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT)) {
1592 wil_err(wil, "invalid interface type %d\n", vif->wdev.iftype);
1593 return -EINVAL;
1594 }
1595
1596 /* In the STA mode, it is expected to have only one ring
1597 * for the AP we are connected to.
1598 * find it and return the cid associated with it.
1599 */
1600 for (i = min_ring_id; i < WIL6210_MAX_TX_RINGS; i++) {
1601 ring = &wil->ring_tx[i];
1602 txdata = &wil->ring_tx_data[i];
1603 if (!ring->va || !txdata->enabled || txdata->mid != vif->mid)
1604 continue;
1605
1606 lcid = wil->ring2cid_tid[i][0];
1607 if (lcid >= wil->max_assoc_sta) /* skip BCAST */
1608 continue;
1609
1610 wil_dbg_wmi(wil, "find sta -> ringid %d cid %d\n", i, lcid);
1611 *cid = lcid;
1612 *ringid = i;
1613 return 0;
1614 }
1615
1616 wil_dbg_wmi(wil, "find sta cid while no rings active?\n");
1617
1618 return -ENOENT;
1619 }
1620
1621 static void
wmi_evt_auth_status(struct wil6210_vif * vif,int id,void * d,int len)1622 wmi_evt_auth_status(struct wil6210_vif *vif, int id, void *d, int len)
1623 {
1624 struct wil6210_priv *wil = vif_to_wil(vif);
1625 struct net_device *ndev = vif_to_ndev(vif);
1626 struct wmi_ft_auth_status_event *data = d;
1627 int ie_len = len - offsetof(struct wmi_ft_auth_status_event, ie_info);
1628 int rc, cid = 0, ringid = 0;
1629 struct cfg80211_ft_event_params ft;
1630 u16 d_len;
1631 /* auth_alg(u16) + auth_transaction(u16) + status_code(u16) */
1632 const size_t auth_ie_offset = sizeof(u16) * 3;
1633 struct auth_no_hdr *auth = (struct auth_no_hdr *)data->ie_info;
1634
1635 /* check the status */
1636 if (ie_len >= 0 && data->status != WMI_FW_STATUS_SUCCESS) {
1637 wil_err(wil, "FT: auth failed. status %d\n", data->status);
1638 goto fail;
1639 }
1640
1641 if (ie_len < auth_ie_offset) {
1642 wil_err(wil, "FT: auth event too short, len %d\n", len);
1643 goto fail;
1644 }
1645
1646 d_len = le16_to_cpu(data->ie_len);
1647 if (d_len != ie_len) {
1648 wil_err(wil,
1649 "FT: auth ie length mismatch, d_len %d should be %d\n",
1650 d_len, ie_len);
1651 goto fail;
1652 }
1653
1654 if (!test_bit(wil_vif_ft_roam, wil->status)) {
1655 wil_err(wil, "FT: Not in roaming state\n");
1656 goto fail;
1657 }
1658
1659 if (le16_to_cpu(auth->auth_transaction) != 2) {
1660 wil_err(wil, "FT: auth error. auth_transaction %d\n",
1661 le16_to_cpu(auth->auth_transaction));
1662 goto fail;
1663 }
1664
1665 if (le16_to_cpu(auth->auth_alg) != WLAN_AUTH_FT) {
1666 wil_err(wil, "FT: auth error. auth_alg %d\n",
1667 le16_to_cpu(auth->auth_alg));
1668 goto fail;
1669 }
1670
1671 wil_dbg_wmi(wil, "FT: Auth to %pM successfully\n", data->mac_addr);
1672 wil_hex_dump_wmi("FT Auth ies : ", DUMP_PREFIX_OFFSET, 16, 1,
1673 data->ie_info, d_len, true);
1674
1675 /* find cid and ringid */
1676 rc = wil_find_cid_ringid_sta(wil, vif, &cid, &ringid);
1677 if (rc) {
1678 wil_err(wil, "No valid cid found\n");
1679 goto fail;
1680 }
1681
1682 if (vif->privacy) {
1683 /* For secure assoc, remove old keys */
1684 rc = wmi_del_cipher_key(vif, 0, wil->sta[cid].addr,
1685 WMI_KEY_USE_PAIRWISE);
1686 if (rc) {
1687 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(PTK) failed\n");
1688 goto fail;
1689 }
1690 rc = wmi_del_cipher_key(vif, 0, wil->sta[cid].addr,
1691 WMI_KEY_USE_RX_GROUP);
1692 if (rc) {
1693 wil_err(wil, "WMI_DELETE_CIPHER_KEY_CMD(GTK) failed\n");
1694 goto fail;
1695 }
1696 }
1697
1698 memset(&ft, 0, sizeof(ft));
1699 ft.ies = data->ie_info + auth_ie_offset;
1700 ft.ies_len = d_len - auth_ie_offset;
1701 ft.target_ap = data->mac_addr;
1702 cfg80211_ft_event(ndev, &ft);
1703
1704 return;
1705
1706 fail:
1707 wil6210_disconnect(vif, NULL, WLAN_REASON_PREV_AUTH_NOT_VALID);
1708 }
1709
1710 static void
wmi_evt_reassoc_status(struct wil6210_vif * vif,int id,void * d,int len)1711 wmi_evt_reassoc_status(struct wil6210_vif *vif, int id, void *d, int len)
1712 {
1713 struct wil6210_priv *wil = vif_to_wil(vif);
1714 struct net_device *ndev = vif_to_ndev(vif);
1715 struct wiphy *wiphy = wil_to_wiphy(wil);
1716 struct wmi_ft_reassoc_status_event *data = d;
1717 int ies_len = len - offsetof(struct wmi_ft_reassoc_status_event,
1718 ie_info);
1719 int rc = -ENOENT, cid = 0, ringid = 0;
1720 int ch; /* channel number (primary) */
1721 size_t assoc_req_ie_len = 0, assoc_resp_ie_len = 0;
1722 u8 *assoc_req_ie = NULL, *assoc_resp_ie = NULL;
1723 /* capinfo(u16) + listen_interval(u16) + current_ap mac addr + IEs */
1724 const size_t assoc_req_ie_offset = sizeof(u16) * 2 + ETH_ALEN;
1725 /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */
1726 const size_t assoc_resp_ie_offset = sizeof(u16) * 3;
1727 u16 d_len;
1728 int freq;
1729 struct cfg80211_roam_info info;
1730
1731 if (ies_len < 0) {
1732 wil_err(wil, "ft reassoc event too short, len %d\n", len);
1733 goto fail;
1734 }
1735
1736 wil_dbg_wmi(wil, "Reasoc Status event: status=%d, aid=%d",
1737 data->status, data->aid);
1738 wil_dbg_wmi(wil, " mac_addr=%pM, beacon_ie_len=%d",
1739 data->mac_addr, data->beacon_ie_len);
1740 wil_dbg_wmi(wil, " reassoc_req_ie_len=%d, reassoc_resp_ie_len=%d",
1741 le16_to_cpu(data->reassoc_req_ie_len),
1742 le16_to_cpu(data->reassoc_resp_ie_len));
1743
1744 d_len = le16_to_cpu(data->beacon_ie_len) +
1745 le16_to_cpu(data->reassoc_req_ie_len) +
1746 le16_to_cpu(data->reassoc_resp_ie_len);
1747 if (d_len != ies_len) {
1748 wil_err(wil,
1749 "ft reassoc ie length mismatch, d_len %d should be %d\n",
1750 d_len, ies_len);
1751 goto fail;
1752 }
1753
1754 /* check the status */
1755 if (data->status != WMI_FW_STATUS_SUCCESS) {
1756 wil_err(wil, "ft reassoc failed. status %d\n", data->status);
1757 goto fail;
1758 }
1759
1760 /* find cid and ringid */
1761 rc = wil_find_cid_ringid_sta(wil, vif, &cid, &ringid);
1762 if (rc) {
1763 wil_err(wil, "No valid cid found\n");
1764 goto fail;
1765 }
1766
1767 ch = data->channel + 1;
1768 wil_info(wil, "FT: Roam %pM channel [%d] cid %d aid %d\n",
1769 data->mac_addr, ch, cid, data->aid);
1770
1771 wil_hex_dump_wmi("reassoc AI : ", DUMP_PREFIX_OFFSET, 16, 1,
1772 data->ie_info, len - sizeof(*data), true);
1773
1774 /* figure out IE's */
1775 if (le16_to_cpu(data->reassoc_req_ie_len) > assoc_req_ie_offset) {
1776 assoc_req_ie = &data->ie_info[assoc_req_ie_offset];
1777 assoc_req_ie_len = le16_to_cpu(data->reassoc_req_ie_len) -
1778 assoc_req_ie_offset;
1779 }
1780 if (le16_to_cpu(data->reassoc_resp_ie_len) <= assoc_resp_ie_offset) {
1781 wil_err(wil, "FT: reassoc resp ie len is too short, len %d\n",
1782 le16_to_cpu(data->reassoc_resp_ie_len));
1783 goto fail;
1784 }
1785
1786 assoc_resp_ie = &data->ie_info[le16_to_cpu(data->reassoc_req_ie_len) +
1787 assoc_resp_ie_offset];
1788 assoc_resp_ie_len = le16_to_cpu(data->reassoc_resp_ie_len) -
1789 assoc_resp_ie_offset;
1790
1791 if (test_bit(wil_status_resetting, wil->status) ||
1792 !test_bit(wil_status_fwready, wil->status)) {
1793 wil_err(wil, "FT: status_resetting, cancel reassoc event\n");
1794 /* no need for cleanup, wil_reset will do that */
1795 return;
1796 }
1797
1798 mutex_lock(&wil->mutex);
1799
1800 /* ring modify to set the ring for the roamed AP settings */
1801 wil_dbg_wmi(wil,
1802 "ft modify tx config for connection CID %d ring %d\n",
1803 cid, ringid);
1804
1805 rc = wil->txrx_ops.tx_ring_modify(vif, ringid, cid, 0);
1806 if (rc) {
1807 wil_err(wil, "modify TX for CID %d MID %d ring %d failed (%d)\n",
1808 cid, vif->mid, ringid, rc);
1809 mutex_unlock(&wil->mutex);
1810 goto fail;
1811 }
1812
1813 /* Update the driver STA members with the new bss */
1814 wil->sta[cid].aid = data->aid;
1815 wil->sta[cid].stats.ft_roams++;
1816 ether_addr_copy(wil->sta[cid].addr, vif->bss->bssid);
1817 mutex_unlock(&wil->mutex);
1818 del_timer_sync(&vif->connect_timer);
1819
1820 cfg80211_ref_bss(wiphy, vif->bss);
1821 freq = ieee80211_channel_to_frequency(ch, NL80211_BAND_60GHZ);
1822
1823 memset(&info, 0, sizeof(info));
1824 info.channel = ieee80211_get_channel(wiphy, freq);
1825 info.bss = vif->bss;
1826 info.req_ie = assoc_req_ie;
1827 info.req_ie_len = assoc_req_ie_len;
1828 info.resp_ie = assoc_resp_ie;
1829 info.resp_ie_len = assoc_resp_ie_len;
1830 cfg80211_roamed(ndev, &info, GFP_KERNEL);
1831 vif->bss = NULL;
1832
1833 return;
1834
1835 fail:
1836 wil6210_disconnect(vif, NULL, WLAN_REASON_PREV_AUTH_NOT_VALID);
1837 }
1838
1839 static void
wmi_evt_link_monitor(struct wil6210_vif * vif,int id,void * d,int len)1840 wmi_evt_link_monitor(struct wil6210_vif *vif, int id, void *d, int len)
1841 {
1842 struct wil6210_priv *wil = vif_to_wil(vif);
1843 struct net_device *ndev = vif_to_ndev(vif);
1844 struct wmi_link_monitor_event *evt = d;
1845 enum nl80211_cqm_rssi_threshold_event event_type;
1846
1847 if (len < sizeof(*evt)) {
1848 wil_err(wil, "link monitor event too short %d\n", len);
1849 return;
1850 }
1851
1852 wil_dbg_wmi(wil, "link monitor event, type %d rssi %d (stored %d)\n",
1853 evt->type, evt->rssi_level, wil->cqm_rssi_thold);
1854
1855 if (evt->type != WMI_LINK_MONITOR_NOTIF_RSSI_THRESHOLD_EVT)
1856 /* ignore */
1857 return;
1858
1859 event_type = (evt->rssi_level > wil->cqm_rssi_thold ?
1860 NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH :
1861 NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW);
1862 cfg80211_cqm_rssi_notify(ndev, event_type, evt->rssi_level, GFP_KERNEL);
1863 }
1864
1865 /* Some events are ignored for purpose; and need not be interpreted as
1866 * "unhandled events"
1867 */
wmi_evt_ignore(struct wil6210_vif * vif,int id,void * d,int len)1868 static void wmi_evt_ignore(struct wil6210_vif *vif, int id, void *d, int len)
1869 {
1870 struct wil6210_priv *wil = vif_to_wil(vif);
1871
1872 wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len);
1873 }
1874
1875 static const struct {
1876 int eventid;
1877 void (*handler)(struct wil6210_vif *vif,
1878 int eventid, void *data, int data_len);
1879 } wmi_evt_handlers[] = {
1880 {WMI_READY_EVENTID, wmi_evt_ready},
1881 {WMI_FW_READY_EVENTID, wmi_evt_ignore},
1882 {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt},
1883 {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt},
1884 {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete},
1885 {WMI_CONNECT_EVENTID, wmi_evt_connect},
1886 {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect},
1887 {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx},
1888 {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status},
1889 {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req},
1890 {WMI_DELBA_EVENTID, wmi_evt_delba},
1891 {WMI_RING_EN_EVENTID, wmi_evt_ring_en},
1892 {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore},
1893 {WMI_SCHED_SCAN_RESULT_EVENTID, wmi_evt_sched_scan_result},
1894 {WMI_LINK_STATS_EVENTID, wmi_evt_link_stats},
1895 {WMI_FT_AUTH_STATUS_EVENTID, wmi_evt_auth_status},
1896 {WMI_FT_REASSOC_STATUS_EVENTID, wmi_evt_reassoc_status},
1897 {WMI_LINK_MONITOR_EVENTID, wmi_evt_link_monitor},
1898 };
1899
1900 /*
1901 * Run in IRQ context
1902 * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev
1903 * that will be eventually handled by the @wmi_event_worker in the thread
1904 * context of thread "wil6210_wmi"
1905 */
wmi_recv_cmd(struct wil6210_priv * wil)1906 void wmi_recv_cmd(struct wil6210_priv *wil)
1907 {
1908 struct wil6210_mbox_ring_desc d_tail;
1909 struct wil6210_mbox_hdr hdr;
1910 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
1911 struct pending_wmi_event *evt;
1912 u8 *cmd;
1913 void __iomem *src;
1914 ulong flags;
1915 unsigned n;
1916 unsigned int num_immed_reply = 0;
1917
1918 if (!test_bit(wil_status_mbox_ready, wil->status)) {
1919 wil_err(wil, "Reset in progress. Cannot handle WMI event\n");
1920 return;
1921 }
1922
1923 if (test_bit(wil_status_suspended, wil->status)) {
1924 wil_err(wil, "suspended. cannot handle WMI event\n");
1925 return;
1926 }
1927
1928 for (n = 0;; n++) {
1929 u16 len;
1930 bool q;
1931 bool immed_reply = false;
1932
1933 r->head = wil_r(wil, RGF_MBOX +
1934 offsetof(struct wil6210_mbox_ctl, rx.head));
1935 if (r->tail == r->head)
1936 break;
1937
1938 wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n",
1939 r->head, r->tail);
1940 /* read cmd descriptor from tail */
1941 wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail),
1942 sizeof(struct wil6210_mbox_ring_desc));
1943 if (d_tail.sync == 0) {
1944 wil_err(wil, "Mbox evt not owned by FW?\n");
1945 break;
1946 }
1947
1948 /* read cmd header from descriptor */
1949 if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) {
1950 wil_err(wil, "Mbox evt at 0x%08x?\n",
1951 le32_to_cpu(d_tail.addr));
1952 break;
1953 }
1954 len = le16_to_cpu(hdr.len);
1955 wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n",
1956 le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type),
1957 hdr.flags);
1958
1959 /* read cmd buffer from descriptor */
1960 src = wmi_buffer(wil, d_tail.addr) +
1961 sizeof(struct wil6210_mbox_hdr);
1962 evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event,
1963 event.wmi) + len, 4),
1964 GFP_KERNEL);
1965 if (!evt)
1966 break;
1967
1968 evt->event.hdr = hdr;
1969 cmd = (void *)&evt->event.wmi;
1970 wil_memcpy_fromio_32(cmd, src, len);
1971 /* mark entry as empty */
1972 wil_w(wil, r->tail +
1973 offsetof(struct wil6210_mbox_ring_desc, sync), 0);
1974 /* indicate */
1975 if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) &&
1976 (len >= sizeof(struct wmi_cmd_hdr))) {
1977 struct wmi_cmd_hdr *wmi = &evt->event.wmi;
1978 u16 id = le16_to_cpu(wmi->command_id);
1979 u8 mid = wmi->mid;
1980 u32 tstamp = le32_to_cpu(wmi->fw_timestamp);
1981 if (test_bit(wil_status_resuming, wil->status)) {
1982 if (id == WMI_TRAFFIC_RESUME_EVENTID)
1983 clear_bit(wil_status_resuming,
1984 wil->status);
1985 else
1986 wil_err(wil,
1987 "WMI evt %d while resuming\n",
1988 id);
1989 }
1990 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
1991 if (wil->reply_id && wil->reply_id == id &&
1992 wil->reply_mid == mid) {
1993 if (wil->reply_buf) {
1994 memcpy(wil->reply_buf, wmi,
1995 min(len, wil->reply_size));
1996 immed_reply = true;
1997 }
1998 if (id == WMI_TRAFFIC_SUSPEND_EVENTID) {
1999 wil_dbg_wmi(wil,
2000 "set suspend_resp_rcvd\n");
2001 wil->suspend_resp_rcvd = true;
2002 }
2003 }
2004 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2005
2006 wil_dbg_wmi(wil, "recv %s (0x%04x) MID %d @%d msec\n",
2007 eventid2name(id), id, wmi->mid, tstamp);
2008 trace_wil6210_wmi_event(wmi, &wmi[1],
2009 len - sizeof(*wmi));
2010 }
2011 wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1,
2012 &evt->event.hdr, sizeof(hdr) + len, true);
2013
2014 /* advance tail */
2015 r->tail = r->base + ((r->tail - r->base +
2016 sizeof(struct wil6210_mbox_ring_desc)) % r->size);
2017 wil_w(wil, RGF_MBOX +
2018 offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail);
2019
2020 if (immed_reply) {
2021 wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n",
2022 wil->reply_id);
2023 kfree(evt);
2024 num_immed_reply++;
2025 complete(&wil->wmi_call);
2026 } else {
2027 /* add to the pending list */
2028 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2029 list_add_tail(&evt->list, &wil->pending_wmi_ev);
2030 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2031 q = queue_work(wil->wmi_wq, &wil->wmi_event_worker);
2032 wil_dbg_wmi(wil, "queue_work -> %d\n", q);
2033 }
2034 }
2035 /* normally, 1 event per IRQ should be processed */
2036 wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n",
2037 n - num_immed_reply, num_immed_reply);
2038 }
2039
wmi_call(struct wil6210_priv * wil,u16 cmdid,u8 mid,void * buf,u16 len,u16 reply_id,void * reply,u16 reply_size,int to_msec)2040 int wmi_call(struct wil6210_priv *wil, u16 cmdid, u8 mid, void *buf, u16 len,
2041 u16 reply_id, void *reply, u16 reply_size, int to_msec)
2042 {
2043 int rc;
2044 unsigned long remain;
2045 ulong flags;
2046
2047 mutex_lock(&wil->wmi_mutex);
2048
2049 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2050 wil->reply_id = reply_id;
2051 wil->reply_mid = mid;
2052 wil->reply_buf = reply;
2053 wil->reply_size = reply_size;
2054 reinit_completion(&wil->wmi_call);
2055 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2056
2057 rc = __wmi_send(wil, cmdid, mid, buf, len);
2058 if (rc)
2059 goto out;
2060
2061 remain = wait_for_completion_timeout(&wil->wmi_call,
2062 msecs_to_jiffies(to_msec));
2063 if (0 == remain) {
2064 wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n",
2065 cmdid, reply_id, to_msec);
2066 rc = -ETIME;
2067 } else {
2068 wil_dbg_wmi(wil,
2069 "wmi_call(0x%04x->0x%04x) completed in %d msec\n",
2070 cmdid, reply_id,
2071 to_msec - jiffies_to_msecs(remain));
2072 }
2073
2074 out:
2075 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
2076 wil->reply_id = 0;
2077 wil->reply_mid = U8_MAX;
2078 wil->reply_buf = NULL;
2079 wil->reply_size = 0;
2080 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
2081
2082 mutex_unlock(&wil->wmi_mutex);
2083
2084 return rc;
2085 }
2086
wmi_echo(struct wil6210_priv * wil)2087 int wmi_echo(struct wil6210_priv *wil)
2088 {
2089 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2090 struct wmi_echo_cmd cmd = {
2091 .value = cpu_to_le32(0x12345678),
2092 };
2093
2094 return wmi_call(wil, WMI_ECHO_CMDID, vif->mid, &cmd, sizeof(cmd),
2095 WMI_ECHO_RSP_EVENTID, NULL, 0,
2096 WIL_WMI_CALL_GENERAL_TO_MS);
2097 }
2098
wmi_set_mac_address(struct wil6210_priv * wil,void * addr)2099 int wmi_set_mac_address(struct wil6210_priv *wil, void *addr)
2100 {
2101 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2102 struct wmi_set_mac_address_cmd cmd;
2103
2104 ether_addr_copy(cmd.mac, addr);
2105
2106 wil_dbg_wmi(wil, "Set MAC %pM\n", addr);
2107
2108 return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, vif->mid,
2109 &cmd, sizeof(cmd));
2110 }
2111
wmi_led_cfg(struct wil6210_priv * wil,bool enable)2112 int wmi_led_cfg(struct wil6210_priv *wil, bool enable)
2113 {
2114 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2115 int rc = 0;
2116 struct wmi_led_cfg_cmd cmd = {
2117 .led_mode = enable,
2118 .id = led_id,
2119 .slow_blink_cfg.blink_on =
2120 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms),
2121 .slow_blink_cfg.blink_off =
2122 cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms),
2123 .medium_blink_cfg.blink_on =
2124 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms),
2125 .medium_blink_cfg.blink_off =
2126 cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms),
2127 .fast_blink_cfg.blink_on =
2128 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms),
2129 .fast_blink_cfg.blink_off =
2130 cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms),
2131 .led_polarity = led_polarity,
2132 };
2133 struct {
2134 struct wmi_cmd_hdr wmi;
2135 struct wmi_led_cfg_done_event evt;
2136 } __packed reply = {
2137 .evt = {.status = cpu_to_le32(WMI_FW_STATUS_FAILURE)},
2138 };
2139
2140 if (led_id == WIL_LED_INVALID_ID)
2141 goto out;
2142
2143 if (led_id > WIL_LED_MAX_ID) {
2144 wil_err(wil, "Invalid led id %d\n", led_id);
2145 rc = -EINVAL;
2146 goto out;
2147 }
2148
2149 wil_dbg_wmi(wil,
2150 "%s led %d\n",
2151 enable ? "enabling" : "disabling", led_id);
2152
2153 rc = wmi_call(wil, WMI_LED_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
2154 WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply),
2155 WIL_WMI_CALL_GENERAL_TO_MS);
2156 if (rc)
2157 goto out;
2158
2159 if (reply.evt.status) {
2160 wil_err(wil, "led %d cfg failed with status %d\n",
2161 led_id, le32_to_cpu(reply.evt.status));
2162 rc = -EINVAL;
2163 }
2164
2165 out:
2166 return rc;
2167 }
2168
wmi_rbufcap_cfg(struct wil6210_priv * wil,bool enable,u16 threshold)2169 int wmi_rbufcap_cfg(struct wil6210_priv *wil, bool enable, u16 threshold)
2170 {
2171 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2172 int rc;
2173
2174 struct wmi_rbufcap_cfg_cmd cmd = {
2175 .enable = enable,
2176 .rx_desc_threshold = cpu_to_le16(threshold),
2177 };
2178 struct {
2179 struct wmi_cmd_hdr wmi;
2180 struct wmi_rbufcap_cfg_event evt;
2181 } __packed reply = {
2182 .evt = {.status = WMI_FW_STATUS_FAILURE},
2183 };
2184
2185 rc = wmi_call(wil, WMI_RBUFCAP_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
2186 WMI_RBUFCAP_CFG_EVENTID, &reply, sizeof(reply),
2187 WIL_WMI_CALL_GENERAL_TO_MS);
2188 if (rc)
2189 return rc;
2190
2191 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
2192 wil_err(wil, "RBUFCAP_CFG failed. status %d\n",
2193 reply.evt.status);
2194 rc = -EINVAL;
2195 }
2196
2197 return rc;
2198 }
2199
wmi_pcp_start(struct wil6210_vif * vif,int bi,u8 wmi_nettype,u8 chan,u8 wmi_edmg_chan,u8 hidden_ssid,u8 is_go)2200 int wmi_pcp_start(struct wil6210_vif *vif, int bi, u8 wmi_nettype,
2201 u8 chan, u8 wmi_edmg_chan, u8 hidden_ssid, u8 is_go)
2202 {
2203 struct wil6210_priv *wil = vif_to_wil(vif);
2204 int rc;
2205
2206 struct wmi_pcp_start_cmd cmd = {
2207 .bcon_interval = cpu_to_le16(bi),
2208 .network_type = wmi_nettype,
2209 .disable_sec_offload = 1,
2210 .channel = chan - 1,
2211 .edmg_channel = wmi_edmg_chan,
2212 .pcp_max_assoc_sta = wil->max_assoc_sta,
2213 .hidden_ssid = hidden_ssid,
2214 .is_go = is_go,
2215 .ap_sme_offload_mode = disable_ap_sme ?
2216 WMI_AP_SME_OFFLOAD_PARTIAL :
2217 WMI_AP_SME_OFFLOAD_FULL,
2218 .abft_len = wil->abft_len,
2219 };
2220 struct {
2221 struct wmi_cmd_hdr wmi;
2222 struct wmi_pcp_started_event evt;
2223 } __packed reply = {
2224 .evt = {.status = WMI_FW_STATUS_FAILURE},
2225 };
2226
2227 if (!vif->privacy)
2228 cmd.disable_sec = 1;
2229
2230 if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) ||
2231 (cmd.pcp_max_assoc_sta <= 0)) {
2232 wil_err(wil, "unexpected max_assoc_sta %d\n",
2233 cmd.pcp_max_assoc_sta);
2234 return -EOPNOTSUPP;
2235 }
2236
2237 if (disable_ap_sme &&
2238 !test_bit(WMI_FW_CAPABILITY_AP_SME_OFFLOAD_PARTIAL,
2239 wil->fw_capabilities)) {
2240 wil_err(wil, "disable_ap_sme not supported by FW\n");
2241 return -EOPNOTSUPP;
2242 }
2243
2244 /*
2245 * Processing time may be huge, in case of secure AP it takes about
2246 * 3500ms for FW to start AP
2247 */
2248 rc = wmi_call(wil, WMI_PCP_START_CMDID, vif->mid, &cmd, sizeof(cmd),
2249 WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000);
2250 if (rc)
2251 return rc;
2252
2253 if (reply.evt.status != WMI_FW_STATUS_SUCCESS)
2254 rc = -EINVAL;
2255
2256 if (wmi_nettype != WMI_NETTYPE_P2P)
2257 /* Don't fail due to error in the led configuration */
2258 wmi_led_cfg(wil, true);
2259
2260 return rc;
2261 }
2262
wmi_pcp_stop(struct wil6210_vif * vif)2263 int wmi_pcp_stop(struct wil6210_vif *vif)
2264 {
2265 struct wil6210_priv *wil = vif_to_wil(vif);
2266 int rc;
2267
2268 rc = wmi_led_cfg(wil, false);
2269 if (rc)
2270 return rc;
2271
2272 return wmi_call(wil, WMI_PCP_STOP_CMDID, vif->mid, NULL, 0,
2273 WMI_PCP_STOPPED_EVENTID, NULL, 0,
2274 WIL_WMI_PCP_STOP_TO_MS);
2275 }
2276
wmi_set_ssid(struct wil6210_vif * vif,u8 ssid_len,const void * ssid)2277 int wmi_set_ssid(struct wil6210_vif *vif, u8 ssid_len, const void *ssid)
2278 {
2279 struct wil6210_priv *wil = vif_to_wil(vif);
2280 struct wmi_set_ssid_cmd cmd = {
2281 .ssid_len = cpu_to_le32(ssid_len),
2282 };
2283
2284 if (ssid_len > sizeof(cmd.ssid))
2285 return -EINVAL;
2286
2287 memcpy(cmd.ssid, ssid, ssid_len);
2288
2289 return wmi_send(wil, WMI_SET_SSID_CMDID, vif->mid, &cmd, sizeof(cmd));
2290 }
2291
wmi_get_ssid(struct wil6210_vif * vif,u8 * ssid_len,void * ssid)2292 int wmi_get_ssid(struct wil6210_vif *vif, u8 *ssid_len, void *ssid)
2293 {
2294 struct wil6210_priv *wil = vif_to_wil(vif);
2295 int rc;
2296 struct {
2297 struct wmi_cmd_hdr wmi;
2298 struct wmi_set_ssid_cmd cmd;
2299 } __packed reply;
2300 int len; /* reply.cmd.ssid_len in CPU order */
2301
2302 memset(&reply, 0, sizeof(reply));
2303
2304 rc = wmi_call(wil, WMI_GET_SSID_CMDID, vif->mid, NULL, 0,
2305 WMI_GET_SSID_EVENTID, &reply, sizeof(reply),
2306 WIL_WMI_CALL_GENERAL_TO_MS);
2307 if (rc)
2308 return rc;
2309
2310 len = le32_to_cpu(reply.cmd.ssid_len);
2311 if (len > sizeof(reply.cmd.ssid))
2312 return -EINVAL;
2313
2314 *ssid_len = len;
2315 memcpy(ssid, reply.cmd.ssid, len);
2316
2317 return 0;
2318 }
2319
wmi_set_channel(struct wil6210_priv * wil,int channel)2320 int wmi_set_channel(struct wil6210_priv *wil, int channel)
2321 {
2322 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2323 struct wmi_set_pcp_channel_cmd cmd = {
2324 .channel = channel - 1,
2325 };
2326
2327 return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, vif->mid,
2328 &cmd, sizeof(cmd));
2329 }
2330
wmi_get_channel(struct wil6210_priv * wil,int * channel)2331 int wmi_get_channel(struct wil6210_priv *wil, int *channel)
2332 {
2333 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2334 int rc;
2335 struct {
2336 struct wmi_cmd_hdr wmi;
2337 struct wmi_set_pcp_channel_cmd cmd;
2338 } __packed reply;
2339
2340 memset(&reply, 0, sizeof(reply));
2341
2342 rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, vif->mid, NULL, 0,
2343 WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply),
2344 WIL_WMI_CALL_GENERAL_TO_MS);
2345 if (rc)
2346 return rc;
2347
2348 if (reply.cmd.channel > 3)
2349 return -EINVAL;
2350
2351 *channel = reply.cmd.channel + 1;
2352
2353 return 0;
2354 }
2355
wmi_p2p_cfg(struct wil6210_vif * vif,int channel,int bi)2356 int wmi_p2p_cfg(struct wil6210_vif *vif, int channel, int bi)
2357 {
2358 struct wil6210_priv *wil = vif_to_wil(vif);
2359 int rc;
2360 struct wmi_p2p_cfg_cmd cmd = {
2361 .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER,
2362 .bcon_interval = cpu_to_le16(bi),
2363 .channel = channel - 1,
2364 };
2365 struct {
2366 struct wmi_cmd_hdr wmi;
2367 struct wmi_p2p_cfg_done_event evt;
2368 } __packed reply = {
2369 .evt = {.status = WMI_FW_STATUS_FAILURE},
2370 };
2371
2372 wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n");
2373
2374 rc = wmi_call(wil, WMI_P2P_CFG_CMDID, vif->mid, &cmd, sizeof(cmd),
2375 WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300);
2376 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
2377 wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status);
2378 rc = -EINVAL;
2379 }
2380
2381 return rc;
2382 }
2383
wmi_start_listen(struct wil6210_vif * vif)2384 int wmi_start_listen(struct wil6210_vif *vif)
2385 {
2386 struct wil6210_priv *wil = vif_to_wil(vif);
2387 int rc;
2388 struct {
2389 struct wmi_cmd_hdr wmi;
2390 struct wmi_listen_started_event evt;
2391 } __packed reply = {
2392 .evt = {.status = WMI_FW_STATUS_FAILURE},
2393 };
2394
2395 wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n");
2396
2397 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, vif->mid, NULL, 0,
2398 WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300);
2399 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
2400 wil_err(wil, "device failed to start listen. status %d\n",
2401 reply.evt.status);
2402 rc = -EINVAL;
2403 }
2404
2405 return rc;
2406 }
2407
wmi_start_search(struct wil6210_vif * vif)2408 int wmi_start_search(struct wil6210_vif *vif)
2409 {
2410 struct wil6210_priv *wil = vif_to_wil(vif);
2411 int rc;
2412 struct {
2413 struct wmi_cmd_hdr wmi;
2414 struct wmi_search_started_event evt;
2415 } __packed reply = {
2416 .evt = {.status = WMI_FW_STATUS_FAILURE},
2417 };
2418
2419 wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n");
2420
2421 rc = wmi_call(wil, WMI_START_SEARCH_CMDID, vif->mid, NULL, 0,
2422 WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300);
2423 if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) {
2424 wil_err(wil, "device failed to start search. status %d\n",
2425 reply.evt.status);
2426 rc = -EINVAL;
2427 }
2428
2429 return rc;
2430 }
2431
wmi_stop_discovery(struct wil6210_vif * vif)2432 int wmi_stop_discovery(struct wil6210_vif *vif)
2433 {
2434 struct wil6210_priv *wil = vif_to_wil(vif);
2435 int rc;
2436
2437 wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n");
2438
2439 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, vif->mid, NULL, 0,
2440 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0,
2441 WIL_WMI_CALL_GENERAL_TO_MS);
2442
2443 if (rc)
2444 wil_err(wil, "Failed to stop discovery\n");
2445
2446 return rc;
2447 }
2448
wmi_del_cipher_key(struct wil6210_vif * vif,u8 key_index,const void * mac_addr,int key_usage)2449 int wmi_del_cipher_key(struct wil6210_vif *vif, u8 key_index,
2450 const void *mac_addr, int key_usage)
2451 {
2452 struct wil6210_priv *wil = vif_to_wil(vif);
2453 struct wmi_delete_cipher_key_cmd cmd = {
2454 .key_index = key_index,
2455 };
2456
2457 if (mac_addr)
2458 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
2459
2460 return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, vif->mid,
2461 &cmd, sizeof(cmd));
2462 }
2463
wmi_add_cipher_key(struct wil6210_vif * vif,u8 key_index,const void * mac_addr,int key_len,const void * key,int key_usage)2464 int wmi_add_cipher_key(struct wil6210_vif *vif, u8 key_index,
2465 const void *mac_addr, int key_len, const void *key,
2466 int key_usage)
2467 {
2468 struct wil6210_priv *wil = vif_to_wil(vif);
2469 struct wmi_add_cipher_key_cmd cmd = {
2470 .key_index = key_index,
2471 .key_usage = key_usage,
2472 .key_len = key_len,
2473 };
2474
2475 if (key_len > sizeof(cmd.key))
2476 return -EINVAL;
2477
2478 /* key len = 0 is allowed only for usage of WMI_KEY_USE_APPLY */
2479 if ((key_len == 0 || !key) &&
2480 key_usage != WMI_KEY_USE_APPLY_PTK)
2481 return -EINVAL;
2482
2483 if (key)
2484 memcpy(cmd.key, key, key_len);
2485
2486 if (mac_addr)
2487 memcpy(cmd.mac, mac_addr, WMI_MAC_LEN);
2488
2489 return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, vif->mid,
2490 &cmd, sizeof(cmd));
2491 }
2492
wmi_set_ie(struct wil6210_vif * vif,u8 type,u16 ie_len,const void * ie)2493 int wmi_set_ie(struct wil6210_vif *vif, u8 type, u16 ie_len, const void *ie)
2494 {
2495 struct wil6210_priv *wil = vif_to_wil(vif);
2496 static const char *const names[] = {
2497 [WMI_FRAME_BEACON] = "BEACON",
2498 [WMI_FRAME_PROBE_REQ] = "PROBE_REQ",
2499 [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP",
2500 [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ",
2501 [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP",
2502 };
2503 int rc;
2504 u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len;
2505 struct wmi_set_appie_cmd *cmd;
2506
2507 if (len < ie_len) {
2508 rc = -EINVAL;
2509 goto out;
2510 }
2511
2512 cmd = kzalloc(len, GFP_KERNEL);
2513 if (!cmd) {
2514 rc = -ENOMEM;
2515 goto out;
2516 }
2517 if (!ie)
2518 ie_len = 0;
2519
2520 cmd->mgmt_frm_type = type;
2521 /* BUG: FW API define ieLen as u8. Will fix FW */
2522 cmd->ie_len = cpu_to_le16(ie_len);
2523 if (ie_len)
2524 memcpy(cmd->ie_info, ie, ie_len);
2525 rc = wmi_send(wil, WMI_SET_APPIE_CMDID, vif->mid, cmd, len);
2526 kfree(cmd);
2527 out:
2528 if (rc) {
2529 const char *name = type < ARRAY_SIZE(names) ?
2530 names[type] : "??";
2531 wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc);
2532 }
2533
2534 return rc;
2535 }
2536
wmi_update_ft_ies(struct wil6210_vif * vif,u16 ie_len,const void * ie)2537 int wmi_update_ft_ies(struct wil6210_vif *vif, u16 ie_len, const void *ie)
2538 {
2539 struct wil6210_priv *wil = vif_to_wil(vif);
2540 u16 len;
2541 struct wmi_update_ft_ies_cmd *cmd;
2542 int rc;
2543
2544 if (!ie)
2545 ie_len = 0;
2546
2547 len = sizeof(struct wmi_update_ft_ies_cmd) + ie_len;
2548 if (len < ie_len) {
2549 wil_err(wil, "wraparound. ie len %d\n", ie_len);
2550 return -EINVAL;
2551 }
2552
2553 cmd = kzalloc(len, GFP_KERNEL);
2554 if (!cmd) {
2555 rc = -ENOMEM;
2556 goto out;
2557 }
2558
2559 cmd->ie_len = cpu_to_le16(ie_len);
2560 if (ie_len)
2561 memcpy(cmd->ie_info, ie, ie_len);
2562 rc = wmi_send(wil, WMI_UPDATE_FT_IES_CMDID, vif->mid, cmd, len);
2563 kfree(cmd);
2564
2565 out:
2566 if (rc)
2567 wil_err(wil, "update ft ies failed : %d\n", rc);
2568
2569 return rc;
2570 }
2571
2572 /**
2573 * wmi_rxon - turn radio on/off
2574 * @wil: driver data
2575 * @on: turn on if true, off otherwise
2576 *
2577 * Only switch radio. Channel should be set separately.
2578 * No timeout for rxon - radio turned on forever unless some other call
2579 * turns it off
2580 */
wmi_rxon(struct wil6210_priv * wil,bool on)2581 int wmi_rxon(struct wil6210_priv *wil, bool on)
2582 {
2583 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2584 int rc;
2585 struct {
2586 struct wmi_cmd_hdr wmi;
2587 struct wmi_listen_started_event evt;
2588 } __packed reply = {
2589 .evt = {.status = WMI_FW_STATUS_FAILURE},
2590 };
2591
2592 wil_info(wil, "(%s)\n", on ? "on" : "off");
2593
2594 if (on) {
2595 rc = wmi_call(wil, WMI_START_LISTEN_CMDID, vif->mid, NULL, 0,
2596 WMI_LISTEN_STARTED_EVENTID,
2597 &reply, sizeof(reply),
2598 WIL_WMI_CALL_GENERAL_TO_MS);
2599 if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS))
2600 rc = -EINVAL;
2601 } else {
2602 rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, vif->mid, NULL, 0,
2603 WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0,
2604 WIL_WMI_CALL_GENERAL_TO_MS);
2605 }
2606
2607 return rc;
2608 }
2609
wmi_rx_chain_add(struct wil6210_priv * wil,struct wil_ring * vring)2610 int wmi_rx_chain_add(struct wil6210_priv *wil, struct wil_ring *vring)
2611 {
2612 struct net_device *ndev = wil->main_ndev;
2613 struct wireless_dev *wdev = ndev->ieee80211_ptr;
2614 struct wil6210_vif *vif = ndev_to_vif(ndev);
2615 struct wmi_cfg_rx_chain_cmd cmd = {
2616 .action = WMI_RX_CHAIN_ADD,
2617 .rx_sw_ring = {
2618 .max_mpdu_size = cpu_to_le16(
2619 wil_mtu2macbuf(wil->rx_buf_len)),
2620 .ring_mem_base = cpu_to_le64(vring->pa),
2621 .ring_size = cpu_to_le16(vring->size),
2622 },
2623 .mid = 0, /* TODO - what is it? */
2624 .decap_trans_type = WMI_DECAP_TYPE_802_3,
2625 .reorder_type = WMI_RX_SW_REORDER,
2626 .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh),
2627 };
2628 struct {
2629 struct wmi_cmd_hdr wmi;
2630 struct wmi_cfg_rx_chain_done_event evt;
2631 } __packed evt;
2632 int rc;
2633
2634 memset(&evt, 0, sizeof(evt));
2635
2636 if (wdev->iftype == NL80211_IFTYPE_MONITOR) {
2637 struct ieee80211_channel *ch = wil->monitor_chandef.chan;
2638
2639 cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON);
2640 if (ch)
2641 cmd.sniffer_cfg.channel = ch->hw_value - 1;
2642 cmd.sniffer_cfg.phy_info_mode =
2643 cpu_to_le32(WMI_SNIFFER_PHY_INFO_DISABLED);
2644 cmd.sniffer_cfg.phy_support =
2645 cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL)
2646 ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS);
2647 } else {
2648 /* Initialize offload (in non-sniffer mode).
2649 * Linux IP stack always calculates IP checksum
2650 * HW always calculate TCP/UDP checksum
2651 */
2652 cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS);
2653 }
2654
2655 if (rx_align_2)
2656 cmd.l2_802_3_offload_ctrl |=
2657 L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK;
2658
2659 /* typical time for secure PCP is 840ms */
2660 rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, vif->mid, &cmd, sizeof(cmd),
2661 WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000);
2662 if (rc)
2663 return rc;
2664
2665 if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS)
2666 rc = -EINVAL;
2667
2668 vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr);
2669
2670 wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n",
2671 le32_to_cpu(evt.evt.status), vring->hwtail);
2672
2673 return rc;
2674 }
2675
wmi_get_temperature(struct wil6210_priv * wil,u32 * t_bb,u32 * t_rf)2676 int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf)
2677 {
2678 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2679 int rc;
2680 struct wmi_temp_sense_cmd cmd = {
2681 .measure_baseband_en = cpu_to_le32(!!t_bb),
2682 .measure_rf_en = cpu_to_le32(!!t_rf),
2683 .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW),
2684 };
2685 struct {
2686 struct wmi_cmd_hdr wmi;
2687 struct wmi_temp_sense_done_event evt;
2688 } __packed reply;
2689
2690 memset(&reply, 0, sizeof(reply));
2691
2692 rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, vif->mid, &cmd, sizeof(cmd),
2693 WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply),
2694 WIL_WMI_CALL_GENERAL_TO_MS);
2695 if (rc)
2696 return rc;
2697
2698 if (t_bb)
2699 *t_bb = le32_to_cpu(reply.evt.baseband_t1000);
2700 if (t_rf)
2701 *t_rf = le32_to_cpu(reply.evt.rf_t1000);
2702
2703 return 0;
2704 }
2705
wmi_get_all_temperatures(struct wil6210_priv * wil,struct wmi_temp_sense_all_done_event * sense_all_evt)2706 int wmi_get_all_temperatures(struct wil6210_priv *wil,
2707 struct wmi_temp_sense_all_done_event
2708 *sense_all_evt)
2709 {
2710 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2711 int rc;
2712 struct wmi_temp_sense_all_cmd cmd = {
2713 .measure_baseband_en = true,
2714 .measure_rf_en = true,
2715 .measure_mode = TEMPERATURE_MEASURE_NOW,
2716 };
2717 struct {
2718 struct wmi_cmd_hdr wmi;
2719 struct wmi_temp_sense_all_done_event evt;
2720 } __packed reply;
2721
2722 if (!sense_all_evt) {
2723 wil_err(wil, "Invalid sense_all_evt value\n");
2724 return -EINVAL;
2725 }
2726
2727 memset(&reply, 0, sizeof(reply));
2728 reply.evt.status = WMI_FW_STATUS_FAILURE;
2729 rc = wmi_call(wil, WMI_TEMP_SENSE_ALL_CMDID, vif->mid, &cmd,
2730 sizeof(cmd), WMI_TEMP_SENSE_ALL_DONE_EVENTID,
2731 &reply, sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
2732 if (rc)
2733 return rc;
2734
2735 if (reply.evt.status == WMI_FW_STATUS_FAILURE) {
2736 wil_err(wil, "Failed getting TEMP_SENSE_ALL\n");
2737 return -EINVAL;
2738 }
2739
2740 memcpy(sense_all_evt, &reply.evt, sizeof(reply.evt));
2741 return 0;
2742 }
2743
wmi_disconnect_sta(struct wil6210_vif * vif,const u8 * mac,u16 reason,bool del_sta)2744 int wmi_disconnect_sta(struct wil6210_vif *vif, const u8 *mac, u16 reason,
2745 bool del_sta)
2746 {
2747 struct wil6210_priv *wil = vif_to_wil(vif);
2748 int rc;
2749 struct wmi_disconnect_sta_cmd disc_sta_cmd = {
2750 .disconnect_reason = cpu_to_le16(reason),
2751 };
2752 struct wmi_del_sta_cmd del_sta_cmd = {
2753 .disconnect_reason = cpu_to_le16(reason),
2754 };
2755 struct {
2756 struct wmi_cmd_hdr wmi;
2757 struct wmi_disconnect_event evt;
2758 } __packed reply;
2759
2760 wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason);
2761
2762 memset(&reply, 0, sizeof(reply));
2763 vif->locally_generated_disc = true;
2764 if (del_sta) {
2765 ether_addr_copy(del_sta_cmd.dst_mac, mac);
2766 rc = wmi_call(wil, WMI_DEL_STA_CMDID, vif->mid, &del_sta_cmd,
2767 sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID,
2768 &reply, sizeof(reply), 1000);
2769 } else {
2770 ether_addr_copy(disc_sta_cmd.dst_mac, mac);
2771 rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, vif->mid,
2772 &disc_sta_cmd, sizeof(disc_sta_cmd),
2773 WMI_DISCONNECT_EVENTID,
2774 &reply, sizeof(reply), 1000);
2775 }
2776 /* failure to disconnect in reasonable time treated as FW error */
2777 if (rc) {
2778 wil_fw_error_recovery(wil);
2779 return rc;
2780 }
2781 wil->sinfo_gen++;
2782
2783 return 0;
2784 }
2785
wmi_addba(struct wil6210_priv * wil,u8 mid,u8 ringid,u8 size,u16 timeout)2786 int wmi_addba(struct wil6210_priv *wil, u8 mid,
2787 u8 ringid, u8 size, u16 timeout)
2788 {
2789 u8 amsdu = wil->use_enhanced_dma_hw && wil->use_rx_hw_reordering &&
2790 test_bit(WMI_FW_CAPABILITY_AMSDU, wil->fw_capabilities) &&
2791 wil->amsdu_en;
2792 struct wmi_ring_ba_en_cmd cmd = {
2793 .ring_id = ringid,
2794 .agg_max_wsize = size,
2795 .ba_timeout = cpu_to_le16(timeout),
2796 .amsdu = amsdu,
2797 };
2798
2799 wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d amsdu %d)\n",
2800 ringid, size, timeout, amsdu);
2801
2802 return wmi_send(wil, WMI_RING_BA_EN_CMDID, mid, &cmd, sizeof(cmd));
2803 }
2804
wmi_delba_tx(struct wil6210_priv * wil,u8 mid,u8 ringid,u16 reason)2805 int wmi_delba_tx(struct wil6210_priv *wil, u8 mid, u8 ringid, u16 reason)
2806 {
2807 struct wmi_ring_ba_dis_cmd cmd = {
2808 .ring_id = ringid,
2809 .reason = cpu_to_le16(reason),
2810 };
2811
2812 wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason);
2813
2814 return wmi_send(wil, WMI_RING_BA_DIS_CMDID, mid, &cmd, sizeof(cmd));
2815 }
2816
wmi_delba_rx(struct wil6210_priv * wil,u8 mid,u8 cid,u8 tid,u16 reason)2817 int wmi_delba_rx(struct wil6210_priv *wil, u8 mid, u8 cid, u8 tid, u16 reason)
2818 {
2819 struct wmi_rcp_delba_cmd cmd = {
2820 .reason = cpu_to_le16(reason),
2821 };
2822
2823 if (cid >= WIL6210_RX_DESC_MAX_CID) {
2824 cmd.cidxtid = CIDXTID_EXTENDED_CID_TID;
2825 cmd.cid = cid;
2826 cmd.tid = tid;
2827 } else {
2828 cmd.cidxtid = mk_cidxtid(cid, tid);
2829 }
2830
2831 wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cid,
2832 tid, reason);
2833
2834 return wmi_send(wil, WMI_RCP_DELBA_CMDID, mid, &cmd, sizeof(cmd));
2835 }
2836
wmi_addba_rx_resp(struct wil6210_priv * wil,u8 mid,u8 cid,u8 tid,u8 token,u16 status,bool amsdu,u16 agg_wsize,u16 timeout)2837 int wmi_addba_rx_resp(struct wil6210_priv *wil,
2838 u8 mid, u8 cid, u8 tid, u8 token,
2839 u16 status, bool amsdu, u16 agg_wsize, u16 timeout)
2840 {
2841 int rc;
2842 struct wmi_rcp_addba_resp_cmd cmd = {
2843 .dialog_token = token,
2844 .status_code = cpu_to_le16(status),
2845 /* bit 0: A-MSDU supported
2846 * bit 1: policy (controlled by FW)
2847 * bits 2..5: TID
2848 * bits 6..15: buffer size
2849 */
2850 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
2851 (agg_wsize << 6)),
2852 .ba_timeout = cpu_to_le16(timeout),
2853 };
2854 struct {
2855 struct wmi_cmd_hdr wmi;
2856 struct wmi_rcp_addba_resp_sent_event evt;
2857 } __packed reply = {
2858 .evt = {.status = cpu_to_le16(WMI_FW_STATUS_FAILURE)},
2859 };
2860
2861 if (cid >= WIL6210_RX_DESC_MAX_CID) {
2862 cmd.cidxtid = CIDXTID_EXTENDED_CID_TID;
2863 cmd.cid = cid;
2864 cmd.tid = tid;
2865 } else {
2866 cmd.cidxtid = mk_cidxtid(cid, tid);
2867 }
2868
2869 wil_dbg_wmi(wil,
2870 "ADDBA response for MID %d CID %d TID %d size %d timeout %d status %d AMSDU%s\n",
2871 mid, cid, tid, agg_wsize,
2872 timeout, status, amsdu ? "+" : "-");
2873
2874 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, mid, &cmd, sizeof(cmd),
2875 WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply),
2876 WIL_WMI_CALL_GENERAL_TO_MS);
2877 if (rc)
2878 return rc;
2879
2880 if (reply.evt.status) {
2881 wil_err(wil, "ADDBA response failed with status %d\n",
2882 le16_to_cpu(reply.evt.status));
2883 rc = -EINVAL;
2884 }
2885
2886 return rc;
2887 }
2888
wmi_addba_rx_resp_edma(struct wil6210_priv * wil,u8 mid,u8 cid,u8 tid,u8 token,u16 status,bool amsdu,u16 agg_wsize,u16 timeout)2889 int wmi_addba_rx_resp_edma(struct wil6210_priv *wil, u8 mid, u8 cid, u8 tid,
2890 u8 token, u16 status, bool amsdu, u16 agg_wsize,
2891 u16 timeout)
2892 {
2893 int rc;
2894 struct wmi_rcp_addba_resp_edma_cmd cmd = {
2895 .cid = cid,
2896 .tid = tid,
2897 .dialog_token = token,
2898 .status_code = cpu_to_le16(status),
2899 /* bit 0: A-MSDU supported
2900 * bit 1: policy (controlled by FW)
2901 * bits 2..5: TID
2902 * bits 6..15: buffer size
2903 */
2904 .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) |
2905 (agg_wsize << 6)),
2906 .ba_timeout = cpu_to_le16(timeout),
2907 /* route all the connections to status ring 0 */
2908 .status_ring_id = WIL_DEFAULT_RX_STATUS_RING_ID,
2909 };
2910 struct {
2911 struct wmi_cmd_hdr wmi;
2912 struct wmi_rcp_addba_resp_sent_event evt;
2913 } __packed reply = {
2914 .evt = {.status = cpu_to_le16(WMI_FW_STATUS_FAILURE)},
2915 };
2916
2917 wil_dbg_wmi(wil,
2918 "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s, sring_id %d\n",
2919 cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-",
2920 WIL_DEFAULT_RX_STATUS_RING_ID);
2921
2922 rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_EDMA_CMDID, mid, &cmd,
2923 sizeof(cmd), WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply,
2924 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
2925 if (rc)
2926 return rc;
2927
2928 if (reply.evt.status) {
2929 wil_err(wil, "ADDBA response failed with status %d\n",
2930 le16_to_cpu(reply.evt.status));
2931 rc = -EINVAL;
2932 }
2933
2934 return rc;
2935 }
2936
wmi_ps_dev_profile_cfg(struct wil6210_priv * wil,enum wmi_ps_profile_type ps_profile)2937 int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil,
2938 enum wmi_ps_profile_type ps_profile)
2939 {
2940 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2941 int rc;
2942 struct wmi_ps_dev_profile_cfg_cmd cmd = {
2943 .ps_profile = ps_profile,
2944 };
2945 struct {
2946 struct wmi_cmd_hdr wmi;
2947 struct wmi_ps_dev_profile_cfg_event evt;
2948 } __packed reply = {
2949 .evt = {.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR)},
2950 };
2951 u32 status;
2952
2953 wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile);
2954
2955 rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, vif->mid,
2956 &cmd, sizeof(cmd),
2957 WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply),
2958 WIL_WMI_CALL_GENERAL_TO_MS);
2959 if (rc)
2960 return rc;
2961
2962 status = le32_to_cpu(reply.evt.status);
2963
2964 if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) {
2965 wil_err(wil, "ps dev profile cfg failed with status %d\n",
2966 status);
2967 rc = -EINVAL;
2968 }
2969
2970 return rc;
2971 }
2972
wmi_set_mgmt_retry(struct wil6210_priv * wil,u8 retry_short)2973 int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short)
2974 {
2975 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
2976 int rc;
2977 struct wmi_set_mgmt_retry_limit_cmd cmd = {
2978 .mgmt_retry_limit = retry_short,
2979 };
2980 struct {
2981 struct wmi_cmd_hdr wmi;
2982 struct wmi_set_mgmt_retry_limit_event evt;
2983 } __packed reply = {
2984 .evt = {.status = WMI_FW_STATUS_FAILURE},
2985 };
2986
2987 wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short);
2988
2989 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
2990 return -ENOTSUPP;
2991
2992 rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, vif->mid,
2993 &cmd, sizeof(cmd),
2994 WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
2995 WIL_WMI_CALL_GENERAL_TO_MS);
2996 if (rc)
2997 return rc;
2998
2999 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3000 wil_err(wil, "set mgmt retry limit failed with status %d\n",
3001 reply.evt.status);
3002 rc = -EINVAL;
3003 }
3004
3005 return rc;
3006 }
3007
wmi_get_mgmt_retry(struct wil6210_priv * wil,u8 * retry_short)3008 int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short)
3009 {
3010 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3011 int rc;
3012 struct {
3013 struct wmi_cmd_hdr wmi;
3014 struct wmi_get_mgmt_retry_limit_event evt;
3015 } __packed reply;
3016
3017 wil_dbg_wmi(wil, "getting mgmt retry short\n");
3018
3019 if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities))
3020 return -ENOTSUPP;
3021
3022 memset(&reply, 0, sizeof(reply));
3023 rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, vif->mid, NULL, 0,
3024 WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply),
3025 WIL_WMI_CALL_GENERAL_TO_MS);
3026 if (rc)
3027 return rc;
3028
3029 if (retry_short)
3030 *retry_short = reply.evt.mgmt_retry_limit;
3031
3032 return 0;
3033 }
3034
wmi_abort_scan(struct wil6210_vif * vif)3035 int wmi_abort_scan(struct wil6210_vif *vif)
3036 {
3037 struct wil6210_priv *wil = vif_to_wil(vif);
3038 int rc;
3039
3040 wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n");
3041
3042 rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, vif->mid, NULL, 0);
3043 if (rc)
3044 wil_err(wil, "Failed to abort scan (%d)\n", rc);
3045
3046 return rc;
3047 }
3048
wmi_new_sta(struct wil6210_vif * vif,const u8 * mac,u8 aid)3049 int wmi_new_sta(struct wil6210_vif *vif, const u8 *mac, u8 aid)
3050 {
3051 struct wil6210_priv *wil = vif_to_wil(vif);
3052 int rc;
3053 struct wmi_new_sta_cmd cmd = {
3054 .aid = aid,
3055 };
3056
3057 wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid);
3058
3059 ether_addr_copy(cmd.dst_mac, mac);
3060
3061 rc = wmi_send(wil, WMI_NEW_STA_CMDID, vif->mid, &cmd, sizeof(cmd));
3062 if (rc)
3063 wil_err(wil, "Failed to send new sta (%d)\n", rc);
3064
3065 return rc;
3066 }
3067
wmi_event_flush(struct wil6210_priv * wil)3068 void wmi_event_flush(struct wil6210_priv *wil)
3069 {
3070 ulong flags;
3071 struct pending_wmi_event *evt, *t;
3072
3073 wil_dbg_wmi(wil, "event_flush\n");
3074
3075 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
3076
3077 list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) {
3078 list_del(&evt->list);
3079 kfree(evt);
3080 }
3081
3082 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
3083 }
3084
suspend_status2name(u8 status)3085 static const char *suspend_status2name(u8 status)
3086 {
3087 switch (status) {
3088 case WMI_TRAFFIC_SUSPEND_REJECTED_LINK_NOT_IDLE:
3089 return "LINK_NOT_IDLE";
3090 case WMI_TRAFFIC_SUSPEND_REJECTED_DISCONNECT:
3091 return "DISCONNECT";
3092 case WMI_TRAFFIC_SUSPEND_REJECTED_OTHER:
3093 return "OTHER";
3094 default:
3095 return "Untracked status";
3096 }
3097 }
3098
wmi_suspend(struct wil6210_priv * wil)3099 int wmi_suspend(struct wil6210_priv *wil)
3100 {
3101 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3102 int rc;
3103 struct wmi_traffic_suspend_cmd cmd = {
3104 .wakeup_trigger = wil->wakeup_trigger,
3105 };
3106 struct {
3107 struct wmi_cmd_hdr wmi;
3108 struct wmi_traffic_suspend_event evt;
3109 } __packed reply = {
3110 .evt = {.status = WMI_TRAFFIC_SUSPEND_REJECTED_LINK_NOT_IDLE},
3111 };
3112
3113 u32 suspend_to = WIL_WAIT_FOR_SUSPEND_RESUME_COMP;
3114
3115 wil->suspend_resp_rcvd = false;
3116 wil->suspend_resp_comp = false;
3117
3118 rc = wmi_call(wil, WMI_TRAFFIC_SUSPEND_CMDID, vif->mid,
3119 &cmd, sizeof(cmd),
3120 WMI_TRAFFIC_SUSPEND_EVENTID, &reply, sizeof(reply),
3121 suspend_to);
3122 if (rc) {
3123 wil_err(wil, "wmi_call for suspend req failed, rc=%d\n", rc);
3124 if (rc == -ETIME)
3125 /* wmi_call TO */
3126 wil->suspend_stats.rejected_by_device++;
3127 else
3128 wil->suspend_stats.rejected_by_host++;
3129 goto out;
3130 }
3131
3132 wil_dbg_wmi(wil, "waiting for suspend_response_completed\n");
3133
3134 rc = wait_event_interruptible_timeout(wil->wq,
3135 wil->suspend_resp_comp,
3136 msecs_to_jiffies(suspend_to));
3137 if (rc == 0) {
3138 wil_err(wil, "TO waiting for suspend_response_completed\n");
3139 if (wil->suspend_resp_rcvd)
3140 /* Device responded but we TO due to another reason */
3141 wil->suspend_stats.rejected_by_host++;
3142 else
3143 wil->suspend_stats.rejected_by_device++;
3144 rc = -EBUSY;
3145 goto out;
3146 }
3147
3148 wil_dbg_wmi(wil, "suspend_response_completed rcvd\n");
3149 if (reply.evt.status != WMI_TRAFFIC_SUSPEND_APPROVED) {
3150 wil_dbg_pm(wil, "device rejected the suspend, %s\n",
3151 suspend_status2name(reply.evt.status));
3152 wil->suspend_stats.rejected_by_device++;
3153 }
3154 rc = reply.evt.status;
3155
3156 out:
3157 wil->suspend_resp_rcvd = false;
3158 wil->suspend_resp_comp = false;
3159
3160 return rc;
3161 }
3162
resume_triggers2string(u32 triggers,char * string,int str_size)3163 static void resume_triggers2string(u32 triggers, char *string, int str_size)
3164 {
3165 string[0] = '\0';
3166
3167 if (!triggers) {
3168 strlcat(string, " UNKNOWN", str_size);
3169 return;
3170 }
3171
3172 if (triggers & WMI_RESUME_TRIGGER_HOST)
3173 strlcat(string, " HOST", str_size);
3174
3175 if (triggers & WMI_RESUME_TRIGGER_UCAST_RX)
3176 strlcat(string, " UCAST_RX", str_size);
3177
3178 if (triggers & WMI_RESUME_TRIGGER_BCAST_RX)
3179 strlcat(string, " BCAST_RX", str_size);
3180
3181 if (triggers & WMI_RESUME_TRIGGER_WMI_EVT)
3182 strlcat(string, " WMI_EVT", str_size);
3183
3184 if (triggers & WMI_RESUME_TRIGGER_DISCONNECT)
3185 strlcat(string, " DISCONNECT", str_size);
3186 }
3187
wmi_resume(struct wil6210_priv * wil)3188 int wmi_resume(struct wil6210_priv *wil)
3189 {
3190 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3191 int rc;
3192 char string[100];
3193 struct {
3194 struct wmi_cmd_hdr wmi;
3195 struct wmi_traffic_resume_event evt;
3196 } __packed reply = {
3197 .evt = {.status = WMI_TRAFFIC_RESUME_FAILED,
3198 .resume_triggers =
3199 cpu_to_le32(WMI_RESUME_TRIGGER_UNKNOWN)},
3200 };
3201
3202 rc = wmi_call(wil, WMI_TRAFFIC_RESUME_CMDID, vif->mid, NULL, 0,
3203 WMI_TRAFFIC_RESUME_EVENTID, &reply, sizeof(reply),
3204 WIL_WAIT_FOR_SUSPEND_RESUME_COMP);
3205 if (rc)
3206 return rc;
3207 resume_triggers2string(le32_to_cpu(reply.evt.resume_triggers), string,
3208 sizeof(string));
3209 wil_dbg_pm(wil, "device resume %s, resume triggers:%s (0x%x)\n",
3210 reply.evt.status ? "failed" : "passed", string,
3211 le32_to_cpu(reply.evt.resume_triggers));
3212
3213 return reply.evt.status;
3214 }
3215
wmi_port_allocate(struct wil6210_priv * wil,u8 mid,const u8 * mac,enum nl80211_iftype iftype)3216 int wmi_port_allocate(struct wil6210_priv *wil, u8 mid,
3217 const u8 *mac, enum nl80211_iftype iftype)
3218 {
3219 int rc;
3220 struct wmi_port_allocate_cmd cmd = {
3221 .mid = mid,
3222 };
3223 struct {
3224 struct wmi_cmd_hdr wmi;
3225 struct wmi_port_allocated_event evt;
3226 } __packed reply = {
3227 .evt = {.status = WMI_FW_STATUS_FAILURE},
3228 };
3229
3230 wil_dbg_misc(wil, "port allocate, mid %d iftype %d, mac %pM\n",
3231 mid, iftype, mac);
3232
3233 ether_addr_copy(cmd.mac, mac);
3234 switch (iftype) {
3235 case NL80211_IFTYPE_STATION:
3236 cmd.port_role = WMI_PORT_STA;
3237 break;
3238 case NL80211_IFTYPE_AP:
3239 cmd.port_role = WMI_PORT_AP;
3240 break;
3241 case NL80211_IFTYPE_P2P_CLIENT:
3242 cmd.port_role = WMI_PORT_P2P_CLIENT;
3243 break;
3244 case NL80211_IFTYPE_P2P_GO:
3245 cmd.port_role = WMI_PORT_P2P_GO;
3246 break;
3247 /* what about monitor??? */
3248 default:
3249 wil_err(wil, "unsupported iftype: %d\n", iftype);
3250 return -EINVAL;
3251 }
3252
3253 rc = wmi_call(wil, WMI_PORT_ALLOCATE_CMDID, mid,
3254 &cmd, sizeof(cmd),
3255 WMI_PORT_ALLOCATED_EVENTID, &reply,
3256 sizeof(reply), 300);
3257 if (rc) {
3258 wil_err(wil, "failed to allocate port, status %d\n", rc);
3259 return rc;
3260 }
3261 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3262 wil_err(wil, "WMI_PORT_ALLOCATE returned status %d\n",
3263 reply.evt.status);
3264 return -EINVAL;
3265 }
3266
3267 return 0;
3268 }
3269
wmi_port_delete(struct wil6210_priv * wil,u8 mid)3270 int wmi_port_delete(struct wil6210_priv *wil, u8 mid)
3271 {
3272 int rc;
3273 struct wmi_port_delete_cmd cmd = {
3274 .mid = mid,
3275 };
3276 struct {
3277 struct wmi_cmd_hdr wmi;
3278 struct wmi_port_deleted_event evt;
3279 } __packed reply = {
3280 .evt = {.status = WMI_FW_STATUS_FAILURE},
3281 };
3282
3283 wil_dbg_misc(wil, "port delete, mid %d\n", mid);
3284
3285 rc = wmi_call(wil, WMI_PORT_DELETE_CMDID, mid,
3286 &cmd, sizeof(cmd),
3287 WMI_PORT_DELETED_EVENTID, &reply,
3288 sizeof(reply), 2000);
3289 if (rc) {
3290 wil_err(wil, "failed to delete port, status %d\n", rc);
3291 return rc;
3292 }
3293 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3294 wil_err(wil, "WMI_PORT_DELETE returned status %d\n",
3295 reply.evt.status);
3296 return -EINVAL;
3297 }
3298
3299 return 0;
3300 }
3301
wmi_evt_call_handler(struct wil6210_vif * vif,int id,void * d,int len)3302 static bool wmi_evt_call_handler(struct wil6210_vif *vif, int id,
3303 void *d, int len)
3304 {
3305 uint i;
3306
3307 for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) {
3308 if (wmi_evt_handlers[i].eventid == id) {
3309 wmi_evt_handlers[i].handler(vif, id, d, len);
3310 return true;
3311 }
3312 }
3313
3314 return false;
3315 }
3316
wmi_event_handle(struct wil6210_priv * wil,struct wil6210_mbox_hdr * hdr)3317 static void wmi_event_handle(struct wil6210_priv *wil,
3318 struct wil6210_mbox_hdr *hdr)
3319 {
3320 u16 len = le16_to_cpu(hdr->len);
3321 struct wil6210_vif *vif;
3322
3323 if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) &&
3324 (len >= sizeof(struct wmi_cmd_hdr))) {
3325 struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]);
3326 void *evt_data = (void *)(&wmi[1]);
3327 u16 id = le16_to_cpu(wmi->command_id);
3328 u8 mid = wmi->mid;
3329
3330 wil_dbg_wmi(wil, "Handle %s (0x%04x) (reply_id 0x%04x,%d)\n",
3331 eventid2name(id), id, wil->reply_id,
3332 wil->reply_mid);
3333
3334 if (mid == MID_BROADCAST)
3335 mid = 0;
3336 if (mid >= GET_MAX_VIFS(wil)) {
3337 wil_dbg_wmi(wil, "invalid mid %d, event skipped\n",
3338 mid);
3339 return;
3340 }
3341 vif = wil->vifs[mid];
3342 if (!vif) {
3343 wil_dbg_wmi(wil, "event for empty VIF(%d), skipped\n",
3344 mid);
3345 return;
3346 }
3347
3348 /* check if someone waits for this event */
3349 if (wil->reply_id && wil->reply_id == id &&
3350 wil->reply_mid == mid) {
3351 if (wil->reply_buf) {
3352 /* event received while wmi_call is waiting
3353 * with a buffer. Such event should be handled
3354 * in wmi_recv_cmd function. Handling the event
3355 * here means a previous wmi_call was timeout.
3356 * Drop the event and do not handle it.
3357 */
3358 wil_err(wil,
3359 "Old event (%d, %s) while wmi_call is waiting. Drop it and Continue waiting\n",
3360 id, eventid2name(id));
3361 return;
3362 }
3363
3364 wmi_evt_call_handler(vif, id, evt_data,
3365 len - sizeof(*wmi));
3366 wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n",
3367 id);
3368 complete(&wil->wmi_call);
3369 return;
3370 }
3371 /* unsolicited event */
3372 /* search for handler */
3373 if (!wmi_evt_call_handler(vif, id, evt_data,
3374 len - sizeof(*wmi))) {
3375 wil_info(wil, "Unhandled event 0x%04x\n", id);
3376 }
3377 } else {
3378 wil_err(wil, "Unknown event type\n");
3379 print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1,
3380 hdr, sizeof(*hdr) + len, true);
3381 }
3382 }
3383
3384 /*
3385 * Retrieve next WMI event from the pending list
3386 */
next_wmi_ev(struct wil6210_priv * wil)3387 static struct list_head *next_wmi_ev(struct wil6210_priv *wil)
3388 {
3389 ulong flags;
3390 struct list_head *ret = NULL;
3391
3392 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
3393
3394 if (!list_empty(&wil->pending_wmi_ev)) {
3395 ret = wil->pending_wmi_ev.next;
3396 list_del(ret);
3397 }
3398
3399 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
3400
3401 return ret;
3402 }
3403
3404 /*
3405 * Handler for the WMI events
3406 */
wmi_event_worker(struct work_struct * work)3407 void wmi_event_worker(struct work_struct *work)
3408 {
3409 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
3410 wmi_event_worker);
3411 struct pending_wmi_event *evt;
3412 struct list_head *lh;
3413
3414 wil_dbg_wmi(wil, "event_worker: Start\n");
3415 while ((lh = next_wmi_ev(wil)) != NULL) {
3416 evt = list_entry(lh, struct pending_wmi_event, list);
3417 wmi_event_handle(wil, &evt->event.hdr);
3418 kfree(evt);
3419 }
3420 wil_dbg_wmi(wil, "event_worker: Finished\n");
3421 }
3422
wil_is_wmi_idle(struct wil6210_priv * wil)3423 bool wil_is_wmi_idle(struct wil6210_priv *wil)
3424 {
3425 ulong flags;
3426 struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx;
3427 bool rc = false;
3428
3429 spin_lock_irqsave(&wil->wmi_ev_lock, flags);
3430
3431 /* Check if there are pending WMI events in the events queue */
3432 if (!list_empty(&wil->pending_wmi_ev)) {
3433 wil_dbg_pm(wil, "Pending WMI events in queue\n");
3434 goto out;
3435 }
3436
3437 /* Check if there is a pending WMI call */
3438 if (wil->reply_id) {
3439 wil_dbg_pm(wil, "Pending WMI call\n");
3440 goto out;
3441 }
3442
3443 /* Check if there are pending RX events in mbox */
3444 r->head = wil_r(wil, RGF_MBOX +
3445 offsetof(struct wil6210_mbox_ctl, rx.head));
3446 if (r->tail != r->head)
3447 wil_dbg_pm(wil, "Pending WMI mbox events\n");
3448 else
3449 rc = true;
3450
3451 out:
3452 spin_unlock_irqrestore(&wil->wmi_ev_lock, flags);
3453 return rc;
3454 }
3455
3456 static void
wmi_sched_scan_set_ssids(struct wil6210_priv * wil,struct wmi_start_sched_scan_cmd * cmd,struct cfg80211_ssid * ssids,int n_ssids,struct cfg80211_match_set * match_sets,int n_match_sets)3457 wmi_sched_scan_set_ssids(struct wil6210_priv *wil,
3458 struct wmi_start_sched_scan_cmd *cmd,
3459 struct cfg80211_ssid *ssids, int n_ssids,
3460 struct cfg80211_match_set *match_sets,
3461 int n_match_sets)
3462 {
3463 int i;
3464
3465 if (n_match_sets > WMI_MAX_PNO_SSID_NUM) {
3466 wil_dbg_wmi(wil, "too many match sets (%d), use first %d\n",
3467 n_match_sets, WMI_MAX_PNO_SSID_NUM);
3468 n_match_sets = WMI_MAX_PNO_SSID_NUM;
3469 }
3470 cmd->num_of_ssids = n_match_sets;
3471
3472 for (i = 0; i < n_match_sets; i++) {
3473 struct wmi_sched_scan_ssid_match *wmi_match =
3474 &cmd->ssid_for_match[i];
3475 struct cfg80211_match_set *cfg_match = &match_sets[i];
3476 int j;
3477
3478 wmi_match->ssid_len = cfg_match->ssid.ssid_len;
3479 memcpy(wmi_match->ssid, cfg_match->ssid.ssid,
3480 min_t(u8, wmi_match->ssid_len, WMI_MAX_SSID_LEN));
3481 wmi_match->rssi_threshold = S8_MIN;
3482 if (cfg_match->rssi_thold >= S8_MIN &&
3483 cfg_match->rssi_thold <= S8_MAX)
3484 wmi_match->rssi_threshold = cfg_match->rssi_thold;
3485
3486 for (j = 0; j < n_ssids; j++)
3487 if (wmi_match->ssid_len == ssids[j].ssid_len &&
3488 memcmp(wmi_match->ssid, ssids[j].ssid,
3489 wmi_match->ssid_len) == 0)
3490 wmi_match->add_ssid_to_probe = true;
3491 }
3492 }
3493
3494 static void
wmi_sched_scan_set_channels(struct wil6210_priv * wil,struct wmi_start_sched_scan_cmd * cmd,u32 n_channels,struct ieee80211_channel ** channels)3495 wmi_sched_scan_set_channels(struct wil6210_priv *wil,
3496 struct wmi_start_sched_scan_cmd *cmd,
3497 u32 n_channels,
3498 struct ieee80211_channel **channels)
3499 {
3500 int i;
3501
3502 if (n_channels > WMI_MAX_CHANNEL_NUM) {
3503 wil_dbg_wmi(wil, "too many channels (%d), use first %d\n",
3504 n_channels, WMI_MAX_CHANNEL_NUM);
3505 n_channels = WMI_MAX_CHANNEL_NUM;
3506 }
3507 cmd->num_of_channels = n_channels;
3508
3509 for (i = 0; i < n_channels; i++) {
3510 struct ieee80211_channel *cfg_chan = channels[i];
3511
3512 cmd->channel_list[i] = cfg_chan->hw_value - 1;
3513 }
3514 }
3515
3516 static void
wmi_sched_scan_set_plans(struct wil6210_priv * wil,struct wmi_start_sched_scan_cmd * cmd,struct cfg80211_sched_scan_plan * scan_plans,int n_scan_plans)3517 wmi_sched_scan_set_plans(struct wil6210_priv *wil,
3518 struct wmi_start_sched_scan_cmd *cmd,
3519 struct cfg80211_sched_scan_plan *scan_plans,
3520 int n_scan_plans)
3521 {
3522 int i;
3523
3524 if (n_scan_plans > WMI_MAX_PLANS_NUM) {
3525 wil_dbg_wmi(wil, "too many plans (%d), use first %d\n",
3526 n_scan_plans, WMI_MAX_PLANS_NUM);
3527 n_scan_plans = WMI_MAX_PLANS_NUM;
3528 }
3529
3530 for (i = 0; i < n_scan_plans; i++) {
3531 struct cfg80211_sched_scan_plan *cfg_plan = &scan_plans[i];
3532
3533 cmd->scan_plans[i].interval_sec =
3534 cpu_to_le16(cfg_plan->interval);
3535 cmd->scan_plans[i].num_of_iterations =
3536 cpu_to_le16(cfg_plan->iterations);
3537 }
3538 }
3539
wmi_start_sched_scan(struct wil6210_priv * wil,struct cfg80211_sched_scan_request * request)3540 int wmi_start_sched_scan(struct wil6210_priv *wil,
3541 struct cfg80211_sched_scan_request *request)
3542 {
3543 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3544 int rc;
3545 struct wmi_start_sched_scan_cmd cmd = {
3546 .min_rssi_threshold = S8_MIN,
3547 .initial_delay_sec = cpu_to_le16(request->delay),
3548 };
3549 struct {
3550 struct wmi_cmd_hdr wmi;
3551 struct wmi_start_sched_scan_event evt;
3552 } __packed reply = {
3553 .evt = {.result = WMI_PNO_REJECT},
3554 };
3555
3556 if (!test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities))
3557 return -ENOTSUPP;
3558
3559 if (request->min_rssi_thold >= S8_MIN &&
3560 request->min_rssi_thold <= S8_MAX)
3561 cmd.min_rssi_threshold = request->min_rssi_thold;
3562
3563 wmi_sched_scan_set_ssids(wil, &cmd, request->ssids, request->n_ssids,
3564 request->match_sets, request->n_match_sets);
3565 wmi_sched_scan_set_channels(wil, &cmd,
3566 request->n_channels, request->channels);
3567 wmi_sched_scan_set_plans(wil, &cmd,
3568 request->scan_plans, request->n_scan_plans);
3569
3570 rc = wmi_call(wil, WMI_START_SCHED_SCAN_CMDID, vif->mid,
3571 &cmd, sizeof(cmd),
3572 WMI_START_SCHED_SCAN_EVENTID, &reply, sizeof(reply),
3573 WIL_WMI_CALL_GENERAL_TO_MS);
3574 if (rc)
3575 return rc;
3576
3577 if (reply.evt.result != WMI_PNO_SUCCESS) {
3578 wil_err(wil, "start sched scan failed, result %d\n",
3579 reply.evt.result);
3580 return -EINVAL;
3581 }
3582
3583 return 0;
3584 }
3585
wmi_stop_sched_scan(struct wil6210_priv * wil)3586 int wmi_stop_sched_scan(struct wil6210_priv *wil)
3587 {
3588 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3589 int rc;
3590 struct {
3591 struct wmi_cmd_hdr wmi;
3592 struct wmi_stop_sched_scan_event evt;
3593 } __packed reply = {
3594 .evt = {.result = WMI_PNO_REJECT},
3595 };
3596
3597 if (!test_bit(WMI_FW_CAPABILITY_PNO, wil->fw_capabilities))
3598 return -ENOTSUPP;
3599
3600 rc = wmi_call(wil, WMI_STOP_SCHED_SCAN_CMDID, vif->mid, NULL, 0,
3601 WMI_STOP_SCHED_SCAN_EVENTID, &reply, sizeof(reply),
3602 WIL_WMI_CALL_GENERAL_TO_MS);
3603 if (rc)
3604 return rc;
3605
3606 if (reply.evt.result != WMI_PNO_SUCCESS) {
3607 wil_err(wil, "stop sched scan failed, result %d\n",
3608 reply.evt.result);
3609 return -EINVAL;
3610 }
3611
3612 return 0;
3613 }
3614
wmi_mgmt_tx(struct wil6210_vif * vif,const u8 * buf,size_t len)3615 int wmi_mgmt_tx(struct wil6210_vif *vif, const u8 *buf, size_t len)
3616 {
3617 size_t total;
3618 struct wil6210_priv *wil = vif_to_wil(vif);
3619 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
3620 struct wmi_sw_tx_req_cmd *cmd;
3621 struct {
3622 struct wmi_cmd_hdr wmi;
3623 struct wmi_sw_tx_complete_event evt;
3624 } __packed evt = {
3625 .evt = {.status = WMI_FW_STATUS_FAILURE},
3626 };
3627 int rc;
3628
3629 wil_dbg_misc(wil, "mgmt_tx mid %d\n", vif->mid);
3630 wil_hex_dump_misc("mgmt tx frame ", DUMP_PREFIX_OFFSET, 16, 1, buf,
3631 len, true);
3632
3633 if (len < sizeof(struct ieee80211_hdr_3addr))
3634 return -EINVAL;
3635
3636 total = sizeof(*cmd) + len;
3637 if (total < len) {
3638 wil_err(wil, "mgmt_tx invalid len %zu\n", len);
3639 return -EINVAL;
3640 }
3641
3642 cmd = kmalloc(total, GFP_KERNEL);
3643 if (!cmd)
3644 return -ENOMEM;
3645
3646 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
3647 cmd->len = cpu_to_le16(len);
3648 memcpy(cmd->payload, buf, len);
3649
3650 rc = wmi_call(wil, WMI_SW_TX_REQ_CMDID, vif->mid, cmd, total,
3651 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
3652 if (!rc && evt.evt.status != WMI_FW_STATUS_SUCCESS) {
3653 wil_dbg_wmi(wil, "mgmt_tx failed with status %d\n",
3654 evt.evt.status);
3655 rc = -EAGAIN;
3656 }
3657
3658 kfree(cmd);
3659
3660 return rc;
3661 }
3662
wmi_mgmt_tx_ext(struct wil6210_vif * vif,const u8 * buf,size_t len,u8 channel,u16 duration_ms)3663 int wmi_mgmt_tx_ext(struct wil6210_vif *vif, const u8 *buf, size_t len,
3664 u8 channel, u16 duration_ms)
3665 {
3666 size_t total;
3667 struct wil6210_priv *wil = vif_to_wil(vif);
3668 struct ieee80211_mgmt *mgmt_frame = (void *)buf;
3669 struct wmi_sw_tx_req_ext_cmd *cmd;
3670 struct {
3671 struct wmi_cmd_hdr wmi;
3672 struct wmi_sw_tx_complete_event evt;
3673 } __packed evt = {
3674 .evt = {.status = WMI_FW_STATUS_FAILURE},
3675 };
3676 int rc;
3677
3678 wil_dbg_wmi(wil, "mgmt_tx_ext mid %d channel %d duration %d\n",
3679 vif->mid, channel, duration_ms);
3680 wil_hex_dump_wmi("mgmt_tx_ext frame ", DUMP_PREFIX_OFFSET, 16, 1, buf,
3681 len, true);
3682
3683 if (len < sizeof(struct ieee80211_hdr_3addr)) {
3684 wil_err(wil, "short frame. len %zu\n", len);
3685 return -EINVAL;
3686 }
3687
3688 total = sizeof(*cmd) + len;
3689 if (total < len) {
3690 wil_err(wil, "mgmt_tx_ext invalid len %zu\n", len);
3691 return -EINVAL;
3692 }
3693
3694 cmd = kzalloc(total, GFP_KERNEL);
3695 if (!cmd)
3696 return -ENOMEM;
3697
3698 memcpy(cmd->dst_mac, mgmt_frame->da, WMI_MAC_LEN);
3699 cmd->len = cpu_to_le16(len);
3700 memcpy(cmd->payload, buf, len);
3701 cmd->channel = channel - 1;
3702 cmd->duration_ms = cpu_to_le16(duration_ms);
3703
3704 rc = wmi_call(wil, WMI_SW_TX_REQ_EXT_CMDID, vif->mid, cmd, total,
3705 WMI_SW_TX_COMPLETE_EVENTID, &evt, sizeof(evt), 2000);
3706 if (!rc && evt.evt.status != WMI_FW_STATUS_SUCCESS) {
3707 wil_dbg_wmi(wil, "mgmt_tx_ext failed with status %d\n",
3708 evt.evt.status);
3709 rc = -EAGAIN;
3710 }
3711
3712 kfree(cmd);
3713
3714 return rc;
3715 }
3716
wil_wmi_tx_sring_cfg(struct wil6210_priv * wil,int ring_id)3717 int wil_wmi_tx_sring_cfg(struct wil6210_priv *wil, int ring_id)
3718 {
3719 int rc;
3720 struct wil6210_vif *vif = ndev_to_vif(wil->main_ndev);
3721 struct wil_status_ring *sring = &wil->srings[ring_id];
3722 struct wmi_tx_status_ring_add_cmd cmd = {
3723 .ring_cfg = {
3724 .ring_size = cpu_to_le16(sring->size),
3725 },
3726 .irq_index = WIL_TX_STATUS_IRQ_IDX
3727 };
3728 struct {
3729 struct wmi_cmd_hdr hdr;
3730 struct wmi_tx_status_ring_cfg_done_event evt;
3731 } __packed reply = {
3732 .evt = {.status = WMI_FW_STATUS_FAILURE},
3733 };
3734
3735 cmd.ring_cfg.ring_id = ring_id;
3736
3737 cmd.ring_cfg.ring_mem_base = cpu_to_le64(sring->pa);
3738 rc = wmi_call(wil, WMI_TX_STATUS_RING_ADD_CMDID, vif->mid, &cmd,
3739 sizeof(cmd), WMI_TX_STATUS_RING_CFG_DONE_EVENTID,
3740 &reply, sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3741 if (rc) {
3742 wil_err(wil, "TX_STATUS_RING_ADD_CMD failed, rc %d\n", rc);
3743 return rc;
3744 }
3745
3746 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3747 wil_err(wil, "TX_STATUS_RING_ADD_CMD failed, status %d\n",
3748 reply.evt.status);
3749 return -EINVAL;
3750 }
3751
3752 sring->hwtail = le32_to_cpu(reply.evt.ring_tail_ptr);
3753
3754 return 0;
3755 }
3756
wil_wmi_cfg_def_rx_offload(struct wil6210_priv * wil,u16 max_rx_pl_per_desc)3757 int wil_wmi_cfg_def_rx_offload(struct wil6210_priv *wil, u16 max_rx_pl_per_desc)
3758 {
3759 struct net_device *ndev = wil->main_ndev;
3760 struct wil6210_vif *vif = ndev_to_vif(ndev);
3761 int rc;
3762 struct wmi_cfg_def_rx_offload_cmd cmd = {
3763 .max_msdu_size = cpu_to_le16(wil_mtu2macbuf(WIL_MAX_ETH_MTU)),
3764 .max_rx_pl_per_desc = cpu_to_le16(max_rx_pl_per_desc),
3765 .decap_trans_type = WMI_DECAP_TYPE_802_3,
3766 .l2_802_3_offload_ctrl = 0,
3767 .l3_l4_ctrl = 1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS,
3768 };
3769 struct {
3770 struct wmi_cmd_hdr hdr;
3771 struct wmi_cfg_def_rx_offload_done_event evt;
3772 } __packed reply = {
3773 .evt = {.status = WMI_FW_STATUS_FAILURE},
3774 };
3775
3776 rc = wmi_call(wil, WMI_CFG_DEF_RX_OFFLOAD_CMDID, vif->mid, &cmd,
3777 sizeof(cmd), WMI_CFG_DEF_RX_OFFLOAD_DONE_EVENTID, &reply,
3778 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3779 if (rc) {
3780 wil_err(wil, "WMI_CFG_DEF_RX_OFFLOAD_CMD failed, rc %d\n", rc);
3781 return rc;
3782 }
3783
3784 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3785 wil_err(wil, "WMI_CFG_DEF_RX_OFFLOAD_CMD failed, status %d\n",
3786 reply.evt.status);
3787 return -EINVAL;
3788 }
3789
3790 return 0;
3791 }
3792
wil_wmi_rx_sring_add(struct wil6210_priv * wil,u16 ring_id)3793 int wil_wmi_rx_sring_add(struct wil6210_priv *wil, u16 ring_id)
3794 {
3795 struct net_device *ndev = wil->main_ndev;
3796 struct wil6210_vif *vif = ndev_to_vif(ndev);
3797 struct wil_status_ring *sring = &wil->srings[ring_id];
3798 int rc;
3799 struct wmi_rx_status_ring_add_cmd cmd = {
3800 .ring_cfg = {
3801 .ring_size = cpu_to_le16(sring->size),
3802 .ring_id = ring_id,
3803 },
3804 .rx_msg_type = wil->use_compressed_rx_status ?
3805 WMI_RX_MSG_TYPE_COMPRESSED :
3806 WMI_RX_MSG_TYPE_EXTENDED,
3807 .irq_index = WIL_RX_STATUS_IRQ_IDX,
3808 };
3809 struct {
3810 struct wmi_cmd_hdr hdr;
3811 struct wmi_rx_status_ring_cfg_done_event evt;
3812 } __packed reply = {
3813 .evt = {.status = WMI_FW_STATUS_FAILURE},
3814 };
3815
3816 cmd.ring_cfg.ring_mem_base = cpu_to_le64(sring->pa);
3817 rc = wmi_call(wil, WMI_RX_STATUS_RING_ADD_CMDID, vif->mid, &cmd,
3818 sizeof(cmd), WMI_RX_STATUS_RING_CFG_DONE_EVENTID, &reply,
3819 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3820 if (rc) {
3821 wil_err(wil, "RX_STATUS_RING_ADD_CMD failed, rc %d\n", rc);
3822 return rc;
3823 }
3824
3825 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3826 wil_err(wil, "RX_STATUS_RING_ADD_CMD failed, status %d\n",
3827 reply.evt.status);
3828 return -EINVAL;
3829 }
3830
3831 sring->hwtail = le32_to_cpu(reply.evt.ring_tail_ptr);
3832
3833 return 0;
3834 }
3835
wil_wmi_rx_desc_ring_add(struct wil6210_priv * wil,int status_ring_id)3836 int wil_wmi_rx_desc_ring_add(struct wil6210_priv *wil, int status_ring_id)
3837 {
3838 struct net_device *ndev = wil->main_ndev;
3839 struct wil6210_vif *vif = ndev_to_vif(ndev);
3840 struct wil_ring *ring = &wil->ring_rx;
3841 int rc;
3842 struct wmi_rx_desc_ring_add_cmd cmd = {
3843 .ring_cfg = {
3844 .ring_size = cpu_to_le16(ring->size),
3845 .ring_id = WIL_RX_DESC_RING_ID,
3846 },
3847 .status_ring_id = status_ring_id,
3848 .irq_index = WIL_RX_STATUS_IRQ_IDX,
3849 };
3850 struct {
3851 struct wmi_cmd_hdr hdr;
3852 struct wmi_rx_desc_ring_cfg_done_event evt;
3853 } __packed reply = {
3854 .evt = {.status = WMI_FW_STATUS_FAILURE},
3855 };
3856
3857 cmd.ring_cfg.ring_mem_base = cpu_to_le64(ring->pa);
3858 cmd.sw_tail_host_addr = cpu_to_le64(ring->edma_rx_swtail.pa);
3859 rc = wmi_call(wil, WMI_RX_DESC_RING_ADD_CMDID, vif->mid, &cmd,
3860 sizeof(cmd), WMI_RX_DESC_RING_CFG_DONE_EVENTID, &reply,
3861 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3862 if (rc) {
3863 wil_err(wil, "WMI_RX_DESC_RING_ADD_CMD failed, rc %d\n", rc);
3864 return rc;
3865 }
3866
3867 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3868 wil_err(wil, "WMI_RX_DESC_RING_ADD_CMD failed, status %d\n",
3869 reply.evt.status);
3870 return -EINVAL;
3871 }
3872
3873 ring->hwtail = le32_to_cpu(reply.evt.ring_tail_ptr);
3874
3875 return 0;
3876 }
3877
wil_wmi_tx_desc_ring_add(struct wil6210_vif * vif,int ring_id,int cid,int tid)3878 int wil_wmi_tx_desc_ring_add(struct wil6210_vif *vif, int ring_id, int cid,
3879 int tid)
3880 {
3881 struct wil6210_priv *wil = vif_to_wil(vif);
3882 int sring_id = wil->tx_sring_idx; /* there is only one TX sring */
3883 int rc;
3884 struct wil_ring *ring = &wil->ring_tx[ring_id];
3885 struct wil_ring_tx_data *txdata = &wil->ring_tx_data[ring_id];
3886 struct wmi_tx_desc_ring_add_cmd cmd = {
3887 .ring_cfg = {
3888 .ring_size = cpu_to_le16(ring->size),
3889 .ring_id = ring_id,
3890 },
3891 .status_ring_id = sring_id,
3892 .cid = cid,
3893 .tid = tid,
3894 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
3895 .max_msdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)),
3896 .schd_params = {
3897 .priority = cpu_to_le16(0),
3898 .timeslot_us = cpu_to_le16(0xfff),
3899 }
3900 };
3901 struct {
3902 struct wmi_cmd_hdr hdr;
3903 struct wmi_tx_desc_ring_cfg_done_event evt;
3904 } __packed reply = {
3905 .evt = {.status = WMI_FW_STATUS_FAILURE},
3906 };
3907
3908 cmd.ring_cfg.ring_mem_base = cpu_to_le64(ring->pa);
3909 rc = wmi_call(wil, WMI_TX_DESC_RING_ADD_CMDID, vif->mid, &cmd,
3910 sizeof(cmd), WMI_TX_DESC_RING_CFG_DONE_EVENTID, &reply,
3911 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3912 if (rc) {
3913 wil_err(wil, "WMI_TX_DESC_RING_ADD_CMD failed, rc %d\n", rc);
3914 return rc;
3915 }
3916
3917 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3918 wil_err(wil, "WMI_TX_DESC_RING_ADD_CMD failed, status %d\n",
3919 reply.evt.status);
3920 return -EINVAL;
3921 }
3922
3923 spin_lock_bh(&txdata->lock);
3924 ring->hwtail = le32_to_cpu(reply.evt.ring_tail_ptr);
3925 txdata->mid = vif->mid;
3926 txdata->enabled = 1;
3927 spin_unlock_bh(&txdata->lock);
3928
3929 return 0;
3930 }
3931
wil_wmi_bcast_desc_ring_add(struct wil6210_vif * vif,int ring_id)3932 int wil_wmi_bcast_desc_ring_add(struct wil6210_vif *vif, int ring_id)
3933 {
3934 struct wil6210_priv *wil = vif_to_wil(vif);
3935 struct wil_ring *ring = &wil->ring_tx[ring_id];
3936 int rc;
3937 struct wmi_bcast_desc_ring_add_cmd cmd = {
3938 .ring_cfg = {
3939 .ring_size = cpu_to_le16(ring->size),
3940 .ring_id = ring_id,
3941 },
3942 .max_msdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)),
3943 .status_ring_id = wil->tx_sring_idx,
3944 .encap_trans_type = WMI_VRING_ENC_TYPE_802_3,
3945 };
3946 struct {
3947 struct wmi_cmd_hdr hdr;
3948 struct wmi_rx_desc_ring_cfg_done_event evt;
3949 } __packed reply = {
3950 .evt = {.status = WMI_FW_STATUS_FAILURE},
3951 };
3952 struct wil_ring_tx_data *txdata = &wil->ring_tx_data[ring_id];
3953
3954 cmd.ring_cfg.ring_mem_base = cpu_to_le64(ring->pa);
3955 rc = wmi_call(wil, WMI_BCAST_DESC_RING_ADD_CMDID, vif->mid, &cmd,
3956 sizeof(cmd), WMI_TX_DESC_RING_CFG_DONE_EVENTID, &reply,
3957 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3958 if (rc) {
3959 wil_err(wil, "WMI_BCAST_DESC_RING_ADD_CMD failed, rc %d\n", rc);
3960 return rc;
3961 }
3962
3963 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
3964 wil_err(wil, "Broadcast Tx config failed, status %d\n",
3965 reply.evt.status);
3966 return -EINVAL;
3967 }
3968
3969 spin_lock_bh(&txdata->lock);
3970 ring->hwtail = le32_to_cpu(reply.evt.ring_tail_ptr);
3971 txdata->mid = vif->mid;
3972 txdata->enabled = 1;
3973 spin_unlock_bh(&txdata->lock);
3974
3975 return 0;
3976 }
3977
wmi_link_stats_cfg(struct wil6210_vif * vif,u32 type,u8 cid,u32 interval)3978 int wmi_link_stats_cfg(struct wil6210_vif *vif, u32 type, u8 cid, u32 interval)
3979 {
3980 struct wil6210_priv *wil = vif_to_wil(vif);
3981 struct wmi_link_stats_cmd cmd = {
3982 .record_type_mask = cpu_to_le32(type),
3983 .cid = cid,
3984 .action = WMI_LINK_STATS_SNAPSHOT,
3985 .interval_msec = cpu_to_le32(interval),
3986 };
3987 struct {
3988 struct wmi_cmd_hdr wmi;
3989 struct wmi_link_stats_config_done_event evt;
3990 } __packed reply = {
3991 .evt = {.status = WMI_FW_STATUS_FAILURE},
3992 };
3993 int rc;
3994
3995 rc = wmi_call(wil, WMI_LINK_STATS_CMDID, vif->mid, &cmd, sizeof(cmd),
3996 WMI_LINK_STATS_CONFIG_DONE_EVENTID, &reply,
3997 sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
3998 if (rc) {
3999 wil_err(wil, "WMI_LINK_STATS_CMDID failed, rc %d\n", rc);
4000 return rc;
4001 }
4002
4003 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
4004 wil_err(wil, "Link statistics config failed, status %d\n",
4005 reply.evt.status);
4006 return -EINVAL;
4007 }
4008
4009 return 0;
4010 }
4011
wmi_set_cqm_rssi_config(struct wil6210_priv * wil,s32 rssi_thold,u32 rssi_hyst)4012 int wmi_set_cqm_rssi_config(struct wil6210_priv *wil,
4013 s32 rssi_thold, u32 rssi_hyst)
4014 {
4015 struct net_device *ndev = wil->main_ndev;
4016 struct wil6210_vif *vif = ndev_to_vif(ndev);
4017 int rc;
4018 struct {
4019 struct wmi_set_link_monitor_cmd cmd;
4020 s8 rssi_thold;
4021 } __packed cmd = {
4022 .cmd = {
4023 .rssi_hyst = rssi_hyst,
4024 .rssi_thresholds_list_size = 1,
4025 },
4026 .rssi_thold = rssi_thold,
4027 };
4028 struct {
4029 struct wmi_cmd_hdr hdr;
4030 struct wmi_set_link_monitor_event evt;
4031 } __packed reply = {
4032 .evt = {.status = WMI_FW_STATUS_FAILURE},
4033 };
4034
4035 if (rssi_thold > S8_MAX || rssi_thold < S8_MIN || rssi_hyst > U8_MAX)
4036 return -EINVAL;
4037
4038 rc = wmi_call(wil, WMI_SET_LINK_MONITOR_CMDID, vif->mid, &cmd,
4039 sizeof(cmd), WMI_SET_LINK_MONITOR_EVENTID,
4040 &reply, sizeof(reply), WIL_WMI_CALL_GENERAL_TO_MS);
4041 if (rc) {
4042 wil_err(wil, "WMI_SET_LINK_MONITOR_CMDID failed, rc %d\n", rc);
4043 return rc;
4044 }
4045
4046 if (reply.evt.status != WMI_FW_STATUS_SUCCESS) {
4047 wil_err(wil, "WMI_SET_LINK_MONITOR_CMDID failed, status %d\n",
4048 reply.evt.status);
4049 return -EINVAL;
4050 }
4051
4052 return 0;
4053 }
4054