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