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