12be7d22fSVladimir Kondratiev /* 20916d9f2SMaya Erez * Copyright (c) 2012-2016 Qualcomm Atheros, Inc. 32be7d22fSVladimir Kondratiev * 42be7d22fSVladimir Kondratiev * Permission to use, copy, modify, and/or distribute this software for any 52be7d22fSVladimir Kondratiev * purpose with or without fee is hereby granted, provided that the above 62be7d22fSVladimir Kondratiev * copyright notice and this permission notice appear in all copies. 72be7d22fSVladimir Kondratiev * 82be7d22fSVladimir Kondratiev * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 92be7d22fSVladimir Kondratiev * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 102be7d22fSVladimir Kondratiev * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 112be7d22fSVladimir Kondratiev * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 122be7d22fSVladimir Kondratiev * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 132be7d22fSVladimir Kondratiev * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 142be7d22fSVladimir Kondratiev * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 152be7d22fSVladimir Kondratiev */ 162be7d22fSVladimir Kondratiev 171eb9d1e5SDedy Lansky #include <linux/moduleparam.h> 182be7d22fSVladimir Kondratiev #include <linux/etherdevice.h> 1947e19af9SVladimir Kondratiev #include <linux/if_arp.h> 202be7d22fSVladimir Kondratiev 212be7d22fSVladimir Kondratiev #include "wil6210.h" 2247e19af9SVladimir Kondratiev #include "txrx.h" 232be7d22fSVladimir Kondratiev #include "wmi.h" 2498658095SVladimir Kondratiev #include "trace.h" 252be7d22fSVladimir Kondratiev 26327755fbSVladimir Kondratiev static uint max_assoc_sta = WIL6210_MAX_CID; 271eb9d1e5SDedy Lansky module_param(max_assoc_sta, uint, S_IRUGO | S_IWUSR); 281eb9d1e5SDedy Lansky MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP"); 291eb9d1e5SDedy Lansky 303a3def8dSVladimir Kondratiev int agg_wsize; /* = 0; */ 313a3def8dSVladimir Kondratiev module_param(agg_wsize, int, S_IRUGO | S_IWUSR); 323a3def8dSVladimir Kondratiev MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;" 333a3def8dSVladimir Kondratiev " 0 - use default; < 0 - don't auto-establish"); 343a3def8dSVladimir Kondratiev 3510d599adSMaya Erez u8 led_id = WIL_LED_INVALID_ID; 3610d599adSMaya Erez module_param(led_id, byte, S_IRUGO); 3710d599adSMaya Erez MODULE_PARM_DESC(led_id, 3810d599adSMaya Erez " 60G device led enablement. Set the led ID (0-2) to enable"); 3910d599adSMaya Erez 402be7d22fSVladimir Kondratiev /** 412be7d22fSVladimir Kondratiev * WMI event receiving - theory of operations 422be7d22fSVladimir Kondratiev * 432be7d22fSVladimir Kondratiev * When firmware about to report WMI event, it fills memory area 442be7d22fSVladimir Kondratiev * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for 452be7d22fSVladimir Kondratiev * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler. 462be7d22fSVladimir Kondratiev * 472be7d22fSVladimir Kondratiev * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the 482be7d22fSVladimir Kondratiev * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up 492be7d22fSVladimir Kondratiev * and handles events within the @wmi_event_worker. Every event get detached 502be7d22fSVladimir Kondratiev * from list, processed and deleted. 512be7d22fSVladimir Kondratiev * 522be7d22fSVladimir Kondratiev * Purpose for this mechanism is to release IRQ thread; otherwise, 532be7d22fSVladimir Kondratiev * if WMI event handling involves another WMI command flow, this 2-nd flow 542be7d22fSVladimir Kondratiev * won't be completed because of blocked IRQ thread. 552be7d22fSVladimir Kondratiev */ 562be7d22fSVladimir Kondratiev 572be7d22fSVladimir Kondratiev /** 582be7d22fSVladimir Kondratiev * Addressing - theory of operations 592be7d22fSVladimir Kondratiev * 602be7d22fSVladimir Kondratiev * There are several buses present on the WIL6210 card. 612be7d22fSVladimir Kondratiev * Same memory areas are visible at different address on 622be7d22fSVladimir Kondratiev * the different busses. There are 3 main bus masters: 632be7d22fSVladimir Kondratiev * - MAC CPU (ucode) 642be7d22fSVladimir Kondratiev * - User CPU (firmware) 652be7d22fSVladimir Kondratiev * - AHB (host) 662be7d22fSVladimir Kondratiev * 672be7d22fSVladimir Kondratiev * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing 682be7d22fSVladimir Kondratiev * AHB addresses starting from 0x880000 692be7d22fSVladimir Kondratiev * 702be7d22fSVladimir Kondratiev * Internally, firmware uses addresses that allows faster access but 712be7d22fSVladimir Kondratiev * are invisible from the host. To read from these addresses, alternative 722be7d22fSVladimir Kondratiev * AHB address must be used. 732be7d22fSVladimir Kondratiev * 742be7d22fSVladimir Kondratiev * Memory mapping 752be7d22fSVladimir Kondratiev * Linker address PCI/Host address 762be7d22fSVladimir Kondratiev * 0x880000 .. 0xa80000 2Mb BAR0 772be7d22fSVladimir Kondratiev * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM 782be7d22fSVladimir Kondratiev * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH 792be7d22fSVladimir Kondratiev */ 802be7d22fSVladimir Kondratiev 812be7d22fSVladimir Kondratiev /** 822be7d22fSVladimir Kondratiev * @fw_mapping provides memory remapping table 83b541d0a0SVladimir Kondratiev * 84b541d0a0SVladimir Kondratiev * array size should be in sync with the declaration in the wil6210.h 852be7d22fSVladimir Kondratiev */ 86b541d0a0SVladimir Kondratiev const struct fw_map fw_mapping[] = { 87b541d0a0SVladimir Kondratiev {0x000000, 0x040000, 0x8c0000, "fw_code"}, /* FW code RAM 256k */ 88b541d0a0SVladimir Kondratiev {0x800000, 0x808000, 0x900000, "fw_data"}, /* FW data RAM 32k */ 89b541d0a0SVladimir Kondratiev {0x840000, 0x860000, 0x908000, "fw_peri"}, /* periph. data RAM 128k */ 90b541d0a0SVladimir Kondratiev {0x880000, 0x88a000, 0x880000, "rgf"}, /* various RGF 40k */ 9172269146SVladimir Kondratiev {0x88a000, 0x88b000, 0x88a000, "AGC_tbl"}, /* AGC table 4k */ 92b541d0a0SVladimir Kondratiev {0x88b000, 0x88c000, 0x88b000, "rgf_ext"}, /* Pcie_ext_rgf 4k */ 930fd37ff8SVladimir Kondratiev {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext"}, /* mac_ext_rgf 512b */ 94b541d0a0SVladimir Kondratiev {0x8c0000, 0x949000, 0x8c0000, "upper"}, /* upper area 548k */ 952be7d22fSVladimir Kondratiev /* 962be7d22fSVladimir Kondratiev * 920000..930000 ucode code RAM 972be7d22fSVladimir Kondratiev * 930000..932000 ucode data RAM 98af6b48dbSVladimir Kondratiev * 932000..949000 back-door debug data 992be7d22fSVladimir Kondratiev */ 1002be7d22fSVladimir Kondratiev }; 1012be7d22fSVladimir Kondratiev 10210d599adSMaya Erez struct blink_on_off_time led_blink_time[] = { 10310d599adSMaya Erez {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS}, 10410d599adSMaya Erez {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS}, 10510d599adSMaya Erez {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS}, 10610d599adSMaya Erez }; 10710d599adSMaya Erez 10810d599adSMaya Erez u8 led_polarity = LED_POLARITY_LOW_ACTIVE; 10910d599adSMaya Erez 1102be7d22fSVladimir Kondratiev /** 1112be7d22fSVladimir Kondratiev * return AHB address for given firmware/ucode internal (linker) address 1122be7d22fSVladimir Kondratiev * @x - internal address 1132be7d22fSVladimir Kondratiev * If address have no valid AHB mapping, return 0 1142be7d22fSVladimir Kondratiev */ 1152be7d22fSVladimir Kondratiev static u32 wmi_addr_remap(u32 x) 1162be7d22fSVladimir Kondratiev { 1172be7d22fSVladimir Kondratiev uint i; 1182be7d22fSVladimir Kondratiev 1192be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 1202be7d22fSVladimir Kondratiev if ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)) 1212be7d22fSVladimir Kondratiev return x + fw_mapping[i].host - fw_mapping[i].from; 1222be7d22fSVladimir Kondratiev } 1232be7d22fSVladimir Kondratiev 1242be7d22fSVladimir Kondratiev return 0; 1252be7d22fSVladimir Kondratiev } 1262be7d22fSVladimir Kondratiev 1272be7d22fSVladimir Kondratiev /** 1282be7d22fSVladimir Kondratiev * Check address validity for WMI buffer; remap if needed 1292be7d22fSVladimir Kondratiev * @ptr - internal (linker) fw/ucode address 1302be7d22fSVladimir Kondratiev * 1312be7d22fSVladimir Kondratiev * Valid buffer should be DWORD aligned 1322be7d22fSVladimir Kondratiev * 1332be7d22fSVladimir Kondratiev * return address for accessing buffer from the host; 1342be7d22fSVladimir Kondratiev * if buffer is not valid, return NULL. 1352be7d22fSVladimir Kondratiev */ 1362be7d22fSVladimir Kondratiev void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_) 1372be7d22fSVladimir Kondratiev { 1382be7d22fSVladimir Kondratiev u32 off; 1392be7d22fSVladimir Kondratiev u32 ptr = le32_to_cpu(ptr_); 1402be7d22fSVladimir Kondratiev 1412be7d22fSVladimir Kondratiev if (ptr % 4) 1422be7d22fSVladimir Kondratiev return NULL; 1432be7d22fSVladimir Kondratiev 1442be7d22fSVladimir Kondratiev ptr = wmi_addr_remap(ptr); 1452be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1462be7d22fSVladimir Kondratiev return NULL; 1472be7d22fSVladimir Kondratiev 1482be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1492be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1502be7d22fSVladimir Kondratiev return NULL; 1512be7d22fSVladimir Kondratiev 1522be7d22fSVladimir Kondratiev return wil->csr + off; 1532be7d22fSVladimir Kondratiev } 1542be7d22fSVladimir Kondratiev 1552be7d22fSVladimir Kondratiev /** 1562be7d22fSVladimir Kondratiev * Check address validity 1572be7d22fSVladimir Kondratiev */ 1582be7d22fSVladimir Kondratiev void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr) 1592be7d22fSVladimir Kondratiev { 1602be7d22fSVladimir Kondratiev u32 off; 1612be7d22fSVladimir Kondratiev 1622be7d22fSVladimir Kondratiev if (ptr % 4) 1632be7d22fSVladimir Kondratiev return NULL; 1642be7d22fSVladimir Kondratiev 1652be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1662be7d22fSVladimir Kondratiev return NULL; 1672be7d22fSVladimir Kondratiev 1682be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1692be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1702be7d22fSVladimir Kondratiev return NULL; 1712be7d22fSVladimir Kondratiev 1722be7d22fSVladimir Kondratiev return wil->csr + off; 1732be7d22fSVladimir Kondratiev } 1742be7d22fSVladimir Kondratiev 1752be7d22fSVladimir Kondratiev int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr, 1762be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 1772be7d22fSVladimir Kondratiev { 1782be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, ptr); 1798fe59627SVladimir Kondratiev 1802be7d22fSVladimir Kondratiev if (!src) 1812be7d22fSVladimir Kondratiev return -EINVAL; 1822be7d22fSVladimir Kondratiev 1832be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(hdr, src, sizeof(*hdr)); 1842be7d22fSVladimir Kondratiev 1852be7d22fSVladimir Kondratiev return 0; 1862be7d22fSVladimir Kondratiev } 1872be7d22fSVladimir Kondratiev 1882be7d22fSVladimir Kondratiev static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) 1892be7d22fSVladimir Kondratiev { 1902be7d22fSVladimir Kondratiev struct { 1912be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 192b874ddecSLior David struct wmi_cmd_hdr wmi; 1932be7d22fSVladimir Kondratiev } __packed cmd = { 1942be7d22fSVladimir Kondratiev .hdr = { 1952be7d22fSVladimir Kondratiev .type = WIL_MBOX_HDR_TYPE_WMI, 1962be7d22fSVladimir Kondratiev .flags = 0, 1972be7d22fSVladimir Kondratiev .len = cpu_to_le16(sizeof(cmd.wmi) + len), 1982be7d22fSVladimir Kondratiev }, 1992be7d22fSVladimir Kondratiev .wmi = { 200f988b23fSVladimir Kondratiev .mid = 0, 201b874ddecSLior David .command_id = cpu_to_le16(cmdid), 2022be7d22fSVladimir Kondratiev }, 2032be7d22fSVladimir Kondratiev }; 2042be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx; 2052be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_head; 2062be7d22fSVladimir Kondratiev u32 next_head; 2072be7d22fSVladimir Kondratiev void __iomem *dst; 2082be7d22fSVladimir Kondratiev void __iomem *head = wmi_addr(wil, r->head); 2092be7d22fSVladimir Kondratiev uint retry; 210349214c1SMaya Erez int rc = 0; 2112be7d22fSVladimir Kondratiev 2122be7d22fSVladimir Kondratiev if (sizeof(cmd) + len > r->entry_size) { 2132be7d22fSVladimir Kondratiev wil_err(wil, "WMI size too large: %d bytes, max is %d\n", 2142be7d22fSVladimir Kondratiev (int)(sizeof(cmd) + len), r->entry_size); 2152be7d22fSVladimir Kondratiev return -ERANGE; 2162be7d22fSVladimir Kondratiev } 2172be7d22fSVladimir Kondratiev 2182be7d22fSVladimir Kondratiev might_sleep(); 2192be7d22fSVladimir Kondratiev 2209419b6a2SVladimir Kondratiev if (!test_bit(wil_status_fwready, wil->status)) { 22115e23124SVladimir Kondratiev wil_err(wil, "WMI: cannot send command while FW not ready\n"); 2222be7d22fSVladimir Kondratiev return -EAGAIN; 2232be7d22fSVladimir Kondratiev } 2242be7d22fSVladimir Kondratiev 2252be7d22fSVladimir Kondratiev if (!head) { 2262be7d22fSVladimir Kondratiev wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head); 2272be7d22fSVladimir Kondratiev return -EINVAL; 2282be7d22fSVladimir Kondratiev } 229349214c1SMaya Erez 230349214c1SMaya Erez wil_halp_vote(wil); 231349214c1SMaya Erez 2322be7d22fSVladimir Kondratiev /* read Tx head till it is not busy */ 2332be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 2342be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_head, head, sizeof(d_head)); 2352be7d22fSVladimir Kondratiev if (d_head.sync == 0) 2362be7d22fSVladimir Kondratiev break; 2372be7d22fSVladimir Kondratiev msleep(20); 2382be7d22fSVladimir Kondratiev } 2392be7d22fSVladimir Kondratiev if (d_head.sync != 0) { 2402be7d22fSVladimir Kondratiev wil_err(wil, "WMI head busy\n"); 241349214c1SMaya Erez rc = -EBUSY; 242349214c1SMaya Erez goto out; 2432be7d22fSVladimir Kondratiev } 2442be7d22fSVladimir Kondratiev /* next head */ 2452be7d22fSVladimir Kondratiev next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size); 2467743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head); 2472be7d22fSVladimir Kondratiev /* wait till FW finish with previous command */ 2482be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 249452133a7SMaya Erez if (!test_bit(wil_status_fwready, wil->status)) { 250452133a7SMaya Erez wil_err(wil, "WMI: cannot send command while FW not ready\n"); 251349214c1SMaya Erez rc = -EAGAIN; 252349214c1SMaya Erez goto out; 253452133a7SMaya Erez } 254b9eeb512SVladimir Kondratiev r->tail = wil_r(wil, RGF_MBOX + 2552be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx.tail)); 2562be7d22fSVladimir Kondratiev if (next_head != r->tail) 2572be7d22fSVladimir Kondratiev break; 2582be7d22fSVladimir Kondratiev msleep(20); 2592be7d22fSVladimir Kondratiev } 2602be7d22fSVladimir Kondratiev if (next_head == r->tail) { 2612be7d22fSVladimir Kondratiev wil_err(wil, "WMI ring full\n"); 262349214c1SMaya Erez rc = -EBUSY; 263349214c1SMaya Erez goto out; 2642be7d22fSVladimir Kondratiev } 2652be7d22fSVladimir Kondratiev dst = wmi_buffer(wil, d_head.addr); 2662be7d22fSVladimir Kondratiev if (!dst) { 2672be7d22fSVladimir Kondratiev wil_err(wil, "invalid WMI buffer: 0x%08x\n", 2682be7d22fSVladimir Kondratiev le32_to_cpu(d_head.addr)); 269349214c1SMaya Erez rc = -EAGAIN; 270349214c1SMaya Erez goto out; 2712be7d22fSVladimir Kondratiev } 2722be7d22fSVladimir Kondratiev cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq); 2732be7d22fSVladimir Kondratiev /* set command */ 2747743882dSVladimir Kondratiev wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len); 2757743882dSVladimir Kondratiev wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd, 2762be7d22fSVladimir Kondratiev sizeof(cmd), true); 2777743882dSVladimir Kondratiev wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf, 2782be7d22fSVladimir Kondratiev len, true); 2792be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst, &cmd, sizeof(cmd)); 2802be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst + sizeof(cmd), buf, len); 2812be7d22fSVladimir Kondratiev /* mark entry as full */ 282b9eeb512SVladimir Kondratiev wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1); 2832be7d22fSVladimir Kondratiev /* advance next ptr */ 284b9eeb512SVladimir Kondratiev wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head), 285b9eeb512SVladimir Kondratiev r->head = next_head); 2862be7d22fSVladimir Kondratiev 287f988b23fSVladimir Kondratiev trace_wil6210_wmi_cmd(&cmd.wmi, buf, len); 28898658095SVladimir Kondratiev 2892be7d22fSVladimir Kondratiev /* interrupt to FW */ 290b9eeb512SVladimir Kondratiev wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS), 291b9eeb512SVladimir Kondratiev SW_INT_MBOX); 2922be7d22fSVladimir Kondratiev 293349214c1SMaya Erez out: 294349214c1SMaya Erez wil_halp_unvote(wil); 295349214c1SMaya Erez return rc; 2962be7d22fSVladimir Kondratiev } 2972be7d22fSVladimir Kondratiev 2982be7d22fSVladimir Kondratiev int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) 2992be7d22fSVladimir Kondratiev { 3002be7d22fSVladimir Kondratiev int rc; 3012be7d22fSVladimir Kondratiev 3022be7d22fSVladimir Kondratiev mutex_lock(&wil->wmi_mutex); 3032be7d22fSVladimir Kondratiev rc = __wmi_send(wil, cmdid, buf, len); 3042be7d22fSVladimir Kondratiev mutex_unlock(&wil->wmi_mutex); 3052be7d22fSVladimir Kondratiev 3062be7d22fSVladimir Kondratiev return rc; 3072be7d22fSVladimir Kondratiev } 3082be7d22fSVladimir Kondratiev 3092be7d22fSVladimir Kondratiev /*=== Event handlers ===*/ 3102be7d22fSVladimir Kondratiev static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len) 3112be7d22fSVladimir Kondratiev { 3122be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 3132be7d22fSVladimir Kondratiev struct wmi_ready_event *evt = d; 3148fe59627SVladimir Kondratiev 315b8023177SVladimir Kondratiev wil->n_mids = evt->numof_additional_mids; 3162be7d22fSVladimir Kondratiev 31713cd9f75SLior David wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n", 31813cd9f75SLior David wil->fw_version, le32_to_cpu(evt->sw_version), 319b8023177SVladimir Kondratiev evt->mac, wil->n_mids); 3202cd0f021SVladimir Kondratiev /* ignore MAC address, we already have it from the boot loader */ 32113cd9f75SLior David strlcpy(wdev->wiphy->fw_version, wil->fw_version, 32213cd9f75SLior David sizeof(wdev->wiphy->fw_version)); 3232be7d22fSVladimir Kondratiev 324c33407a8SVladimir Kondratiev wil_set_recovery_state(wil, fw_recovery_idle); 3259419b6a2SVladimir Kondratiev set_bit(wil_status_fwready, wil->status); 32659502647SDedy Lansky /* let the reset sequence continue */ 3272be7d22fSVladimir Kondratiev complete(&wil->wmi_ready); 3282be7d22fSVladimir Kondratiev } 3292be7d22fSVladimir Kondratiev 3302be7d22fSVladimir Kondratiev static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) 3312be7d22fSVladimir Kondratiev { 3322be7d22fSVladimir Kondratiev struct wmi_rx_mgmt_packet_event *data = d; 3332be7d22fSVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 3342be7d22fSVladimir Kondratiev struct ieee80211_mgmt *rx_mgmt_frame = 3352be7d22fSVladimir Kondratiev (struct ieee80211_mgmt *)data->payload; 33690d89e9aSVladimir Kondratiev int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload); 33790d89e9aSVladimir Kondratiev int ch_no; 33890d89e9aSVladimir Kondratiev u32 freq; 33990d89e9aSVladimir Kondratiev struct ieee80211_channel *channel; 34090d89e9aSVladimir Kondratiev s32 signal; 34190d89e9aSVladimir Kondratiev __le16 fc; 34290d89e9aSVladimir Kondratiev u32 d_len; 34390d89e9aSVladimir Kondratiev u16 d_status; 3442be7d22fSVladimir Kondratiev 34590d89e9aSVladimir Kondratiev if (flen < 0) { 34690d89e9aSVladimir Kondratiev wil_err(wil, "MGMT Rx: short event, len %d\n", len); 34790d89e9aSVladimir Kondratiev return; 34890d89e9aSVladimir Kondratiev } 34990d89e9aSVladimir Kondratiev 35090d89e9aSVladimir Kondratiev d_len = le32_to_cpu(data->info.len); 35190d89e9aSVladimir Kondratiev if (d_len != flen) { 35290d89e9aSVladimir Kondratiev wil_err(wil, 35390d89e9aSVladimir Kondratiev "MGMT Rx: length mismatch, d_len %d should be %d\n", 35490d89e9aSVladimir Kondratiev d_len, flen); 35590d89e9aSVladimir Kondratiev return; 35690d89e9aSVladimir Kondratiev } 35790d89e9aSVladimir Kondratiev 35890d89e9aSVladimir Kondratiev ch_no = data->info.channel + 1; 35957fbcce3SJohannes Berg freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ); 36090d89e9aSVladimir Kondratiev channel = ieee80211_get_channel(wiphy, freq); 36190d89e9aSVladimir Kondratiev signal = data->info.sqi; 36290d89e9aSVladimir Kondratiev d_status = le16_to_cpu(data->info.status); 36390d89e9aSVladimir Kondratiev fc = rx_mgmt_frame->frame_control; 36490d89e9aSVladimir Kondratiev 36590d89e9aSVladimir Kondratiev wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d SNR %d SQI %d%%\n", 366b8b33a3aSVladimir Kondratiev data->info.channel, data->info.mcs, data->info.snr, 367b8b33a3aSVladimir Kondratiev data->info.sqi); 368f27dbf78SVladimir Kondratiev wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len, 369f27dbf78SVladimir Kondratiev le16_to_cpu(fc)); 3707743882dSVladimir Kondratiev wil_dbg_wmi(wil, "qid %d mid %d cid %d\n", 3712be7d22fSVladimir Kondratiev data->info.qid, data->info.mid, data->info.cid); 37290d89e9aSVladimir Kondratiev wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame, 37390d89e9aSVladimir Kondratiev d_len, true); 3742be7d22fSVladimir Kondratiev 3752be7d22fSVladimir Kondratiev if (!channel) { 3762be7d22fSVladimir Kondratiev wil_err(wil, "Frame on unsupported channel\n"); 3772be7d22fSVladimir Kondratiev return; 3782be7d22fSVladimir Kondratiev } 3792be7d22fSVladimir Kondratiev 3802be7d22fSVladimir Kondratiev if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) { 3812be7d22fSVladimir Kondratiev struct cfg80211_bss *bss; 3828eea944aSVladimir Kondratiev u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp); 3838eea944aSVladimir Kondratiev u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info); 3848eea944aSVladimir Kondratiev u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int); 3858eea944aSVladimir Kondratiev const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable; 3868eea944aSVladimir Kondratiev size_t ie_len = d_len - offsetof(struct ieee80211_mgmt, 3878eea944aSVladimir Kondratiev u.beacon.variable); 3888eea944aSVladimir Kondratiev wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap); 3898eea944aSVladimir Kondratiev wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf); 3908eea944aSVladimir Kondratiev wil_dbg_wmi(wil, "Beacon interval : %d\n", bi); 3918eea944aSVladimir Kondratiev wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf, 3928eea944aSVladimir Kondratiev ie_len, true); 3932be7d22fSVladimir Kondratiev 394e6d68341SDedy Lansky wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap); 395e6d68341SDedy Lansky 396a0f7845bSVladimir Kondratiev bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame, 397a0f7845bSVladimir Kondratiev d_len, signal, GFP_KERNEL); 3982be7d22fSVladimir Kondratiev if (bss) { 3997743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Added BSS %pM\n", 4002be7d22fSVladimir Kondratiev rx_mgmt_frame->bssid); 4015b112d3dSJohannes Berg cfg80211_put_bss(wiphy, bss); 4022be7d22fSVladimir Kondratiev } else { 4035bc8c1f2SJohannes Berg wil_err(wil, "cfg80211_inform_bss_frame() failed\n"); 4042be7d22fSVladimir Kondratiev } 405102b1d99SVladimir Kondratiev } else { 4064332cac1SLior David mutex_lock(&wil->p2p_wdev_mutex); 4074332cac1SLior David cfg80211_rx_mgmt(wil->radio_wdev, freq, signal, 408970fdfa8SVladimir Kondratiev (void *)rx_mgmt_frame, d_len, 0); 4094332cac1SLior David mutex_unlock(&wil->p2p_wdev_mutex); 4102be7d22fSVladimir Kondratiev } 4112be7d22fSVladimir Kondratiev } 4122be7d22fSVladimir Kondratiev 41390d89e9aSVladimir Kondratiev static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) 41490d89e9aSVladimir Kondratiev { 41590d89e9aSVladimir Kondratiev struct wmi_tx_mgmt_packet_event *data = d; 41690d89e9aSVladimir Kondratiev struct ieee80211_mgmt *mgmt_frame = 41790d89e9aSVladimir Kondratiev (struct ieee80211_mgmt *)data->payload; 41890d89e9aSVladimir Kondratiev int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload); 41990d89e9aSVladimir Kondratiev 42090d89e9aSVladimir Kondratiev wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame, 42190d89e9aSVladimir Kondratiev flen, true); 42290d89e9aSVladimir Kondratiev } 42390d89e9aSVladimir Kondratiev 4242be7d22fSVladimir Kondratiev static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id, 4252be7d22fSVladimir Kondratiev void *d, int len) 4262be7d22fSVladimir Kondratiev { 4275ffae432SLior David mutex_lock(&wil->p2p_wdev_mutex); 4282be7d22fSVladimir Kondratiev if (wil->scan_request) { 4292be7d22fSVladimir Kondratiev struct wmi_scan_complete_event *data = d; 430035859a5SMaya Erez int status = le32_to_cpu(data->status); 4311d76250bSAvraham Stern struct cfg80211_scan_info info = { 432035859a5SMaya Erez .aborted = ((status != WMI_SCAN_SUCCESS) && 433035859a5SMaya Erez (status != WMI_SCAN_ABORT_REJECTED)), 4341d76250bSAvraham Stern }; 4352be7d22fSVladimir Kondratiev 436035859a5SMaya Erez wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status); 4372a91d7d0SVladimir Kondratiev wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n", 4381d76250bSAvraham Stern wil->scan_request, info.aborted); 439047e5d74SVladimir Kondratiev del_timer_sync(&wil->scan_timer); 4401d76250bSAvraham Stern cfg80211_scan_done(wil->scan_request, &info); 4414332cac1SLior David wil->radio_wdev = wil->wdev; 4422be7d22fSVladimir Kondratiev wil->scan_request = NULL; 443035859a5SMaya Erez wake_up_interruptible(&wil->wq); 4442be7d22fSVladimir Kondratiev } else { 4452be7d22fSVladimir Kondratiev wil_err(wil, "SCAN_COMPLETE while not scanning\n"); 4462be7d22fSVladimir Kondratiev } 4475ffae432SLior David mutex_unlock(&wil->p2p_wdev_mutex); 4482be7d22fSVladimir Kondratiev } 4492be7d22fSVladimir Kondratiev 4502be7d22fSVladimir Kondratiev static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len) 4512be7d22fSVladimir Kondratiev { 4522be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 4532be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 4542be7d22fSVladimir Kondratiev struct wmi_connect_event *evt = d; 4552be7d22fSVladimir Kondratiev int ch; /* channel number */ 4562be7d22fSVladimir Kondratiev struct station_info sinfo; 4572be7d22fSVladimir Kondratiev u8 *assoc_req_ie, *assoc_resp_ie; 4582be7d22fSVladimir Kondratiev size_t assoc_req_ielen, assoc_resp_ielen; 4592be7d22fSVladimir Kondratiev /* capinfo(u16) + listen_interval(u16) + IEs */ 4602be7d22fSVladimir Kondratiev const size_t assoc_req_ie_offset = sizeof(u16) * 2; 4612be7d22fSVladimir Kondratiev /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */ 4622be7d22fSVladimir Kondratiev const size_t assoc_resp_ie_offset = sizeof(u16) * 3; 4630916d9f2SMaya Erez int rc; 4642be7d22fSVladimir Kondratiev 4652be7d22fSVladimir Kondratiev if (len < sizeof(*evt)) { 4662be7d22fSVladimir Kondratiev wil_err(wil, "Connect event too short : %d bytes\n", len); 4672be7d22fSVladimir Kondratiev return; 4682be7d22fSVladimir Kondratiev } 4692be7d22fSVladimir Kondratiev if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len + 4702be7d22fSVladimir Kondratiev evt->assoc_resp_len) { 4712be7d22fSVladimir Kondratiev wil_err(wil, 4722be7d22fSVladimir Kondratiev "Connect event corrupted : %d != %d + %d + %d + %d\n", 4732be7d22fSVladimir Kondratiev len, (int)sizeof(*evt), evt->beacon_ie_len, 4742be7d22fSVladimir Kondratiev evt->assoc_req_len, evt->assoc_resp_len); 4752be7d22fSVladimir Kondratiev return; 4762be7d22fSVladimir Kondratiev } 4773df2cd36SVladimir Kondratiev if (evt->cid >= WIL6210_MAX_CID) { 4783df2cd36SVladimir Kondratiev wil_err(wil, "Connect CID invalid : %d\n", evt->cid); 4793df2cd36SVladimir Kondratiev return; 4803df2cd36SVladimir Kondratiev } 4813df2cd36SVladimir Kondratiev 4822be7d22fSVladimir Kondratiev ch = evt->channel + 1; 4830916d9f2SMaya Erez wil_info(wil, "Connect %pM channel [%d] cid %d\n", 4842be7d22fSVladimir Kondratiev evt->bssid, ch, evt->cid); 4857743882dSVladimir Kondratiev wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1, 4862be7d22fSVladimir Kondratiev evt->assoc_info, len - sizeof(*evt), true); 4872be7d22fSVladimir Kondratiev 4882be7d22fSVladimir Kondratiev /* figure out IE's */ 4892be7d22fSVladimir Kondratiev assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len + 4902be7d22fSVladimir Kondratiev assoc_req_ie_offset]; 4912be7d22fSVladimir Kondratiev assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset; 4922be7d22fSVladimir Kondratiev if (evt->assoc_req_len <= assoc_req_ie_offset) { 4932be7d22fSVladimir Kondratiev assoc_req_ie = NULL; 4942be7d22fSVladimir Kondratiev assoc_req_ielen = 0; 4952be7d22fSVladimir Kondratiev } 4962be7d22fSVladimir Kondratiev 4972be7d22fSVladimir Kondratiev assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len + 4982be7d22fSVladimir Kondratiev evt->assoc_req_len + 4992be7d22fSVladimir Kondratiev assoc_resp_ie_offset]; 5002be7d22fSVladimir Kondratiev assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset; 5012be7d22fSVladimir Kondratiev if (evt->assoc_resp_len <= assoc_resp_ie_offset) { 5022be7d22fSVladimir Kondratiev assoc_resp_ie = NULL; 5032be7d22fSVladimir Kondratiev assoc_resp_ielen = 0; 5042be7d22fSVladimir Kondratiev } 5052be7d22fSVladimir Kondratiev 5060916d9f2SMaya Erez mutex_lock(&wil->mutex); 5070916d9f2SMaya Erez if (test_bit(wil_status_resetting, wil->status) || 5080916d9f2SMaya Erez !test_bit(wil_status_fwready, wil->status)) { 5090916d9f2SMaya Erez wil_err(wil, "status_resetting, cancel connect event, CID %d\n", 5100916d9f2SMaya Erez evt->cid); 5110916d9f2SMaya Erez mutex_unlock(&wil->mutex); 5120916d9f2SMaya Erez /* no need for cleanup, wil_reset will do that */ 5130916d9f2SMaya Erez return; 5140916d9f2SMaya Erez } 5150916d9f2SMaya Erez 5162be7d22fSVladimir Kondratiev if ((wdev->iftype == NL80211_IFTYPE_STATION) || 5172be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { 5189419b6a2SVladimir Kondratiev if (!test_bit(wil_status_fwconnecting, wil->status)) { 5192be7d22fSVladimir Kondratiev wil_err(wil, "Not in connecting state\n"); 5200916d9f2SMaya Erez mutex_unlock(&wil->mutex); 5212be7d22fSVladimir Kondratiev return; 5222be7d22fSVladimir Kondratiev } 5232be7d22fSVladimir Kondratiev del_timer_sync(&wil->connect_timer); 5243d287fb3SMaya Erez } else if ((wdev->iftype == NL80211_IFTYPE_AP) || 5253d287fb3SMaya Erez (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { 5263d287fb3SMaya Erez if (wil->sta[evt->cid].status != wil_sta_unused) { 5273d287fb3SMaya Erez wil_err(wil, "%s: AP: Invalid status %d for CID %d\n", 5283d287fb3SMaya Erez __func__, wil->sta[evt->cid].status, evt->cid); 5293d287fb3SMaya Erez mutex_unlock(&wil->mutex); 5303d287fb3SMaya Erez return; 5313d287fb3SMaya Erez } 5320916d9f2SMaya Erez } 5330916d9f2SMaya Erez 5340916d9f2SMaya Erez /* FIXME FW can transmit only ucast frames to peer */ 5350916d9f2SMaya Erez /* FIXME real ring_id instead of hard coded 0 */ 5360916d9f2SMaya Erez ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid); 5370916d9f2SMaya Erez wil->sta[evt->cid].status = wil_sta_conn_pending; 5380916d9f2SMaya Erez 5390916d9f2SMaya Erez rc = wil_tx_init(wil, evt->cid); 5400916d9f2SMaya Erez if (rc) { 5410916d9f2SMaya Erez wil_err(wil, "%s: config tx vring failed for CID %d, rc (%d)\n", 5420916d9f2SMaya Erez __func__, evt->cid, rc); 5430916d9f2SMaya Erez wmi_disconnect_sta(wil, wil->sta[evt->cid].addr, 5440916d9f2SMaya Erez WLAN_REASON_UNSPECIFIED, false); 5450916d9f2SMaya Erez } else { 5460916d9f2SMaya Erez wil_info(wil, "%s: successful connection to CID %d\n", 5470916d9f2SMaya Erez __func__, evt->cid); 5480916d9f2SMaya Erez } 5490916d9f2SMaya Erez 5500916d9f2SMaya Erez if ((wdev->iftype == NL80211_IFTYPE_STATION) || 5510916d9f2SMaya Erez (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { 5520916d9f2SMaya Erez if (rc) { 5530916d9f2SMaya Erez netif_carrier_off(ndev); 5540916d9f2SMaya Erez wil_err(wil, 5550916d9f2SMaya Erez "%s: cfg80211_connect_result with failure\n", 5560916d9f2SMaya Erez __func__); 5570916d9f2SMaya Erez cfg80211_connect_result(ndev, evt->bssid, NULL, 0, 5580916d9f2SMaya Erez NULL, 0, 5590916d9f2SMaya Erez WLAN_STATUS_UNSPECIFIED_FAILURE, 5600916d9f2SMaya Erez GFP_KERNEL); 5610916d9f2SMaya Erez goto out; 5620916d9f2SMaya Erez } else { 5632be7d22fSVladimir Kondratiev cfg80211_connect_result(ndev, evt->bssid, 5642be7d22fSVladimir Kondratiev assoc_req_ie, assoc_req_ielen, 5652be7d22fSVladimir Kondratiev assoc_resp_ie, assoc_resp_ielen, 5660916d9f2SMaya Erez WLAN_STATUS_SUCCESS, 5670916d9f2SMaya Erez GFP_KERNEL); 5680916d9f2SMaya Erez } 5692be7d22fSVladimir Kondratiev } else if ((wdev->iftype == NL80211_IFTYPE_AP) || 5702be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { 5710916d9f2SMaya Erez if (rc) 5720916d9f2SMaya Erez goto out; 5730916d9f2SMaya Erez 5742be7d22fSVladimir Kondratiev memset(&sinfo, 0, sizeof(sinfo)); 5752be7d22fSVladimir Kondratiev 5762be7d22fSVladimir Kondratiev sinfo.generation = wil->sinfo_gen++; 5772be7d22fSVladimir Kondratiev 5782be7d22fSVladimir Kondratiev if (assoc_req_ie) { 5792be7d22fSVladimir Kondratiev sinfo.assoc_req_ies = assoc_req_ie; 5802be7d22fSVladimir Kondratiev sinfo.assoc_req_ies_len = assoc_req_ielen; 5812be7d22fSVladimir Kondratiev } 5822be7d22fSVladimir Kondratiev 5832be7d22fSVladimir Kondratiev cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL); 5840916d9f2SMaya Erez } else { 5850916d9f2SMaya Erez wil_err(wil, "%s: unhandled iftype %d for CID %d\n", 5860916d9f2SMaya Erez __func__, wdev->iftype, evt->cid); 5870916d9f2SMaya Erez goto out; 5882be7d22fSVladimir Kondratiev } 5890916d9f2SMaya Erez 5900916d9f2SMaya Erez wil->sta[evt->cid].status = wil_sta_connected; 5919419b6a2SVladimir Kondratiev set_bit(wil_status_fwconnected, wil->status); 592f9e3033fSDedy Lansky wil_update_net_queues_bh(wil, NULL, false); 5932be7d22fSVladimir Kondratiev 5940916d9f2SMaya Erez out: 5950916d9f2SMaya Erez if (rc) 5960916d9f2SMaya Erez wil->sta[evt->cid].status = wil_sta_unused; 5970916d9f2SMaya Erez clear_bit(wil_status_fwconnecting, wil->status); 5980916d9f2SMaya Erez mutex_unlock(&wil->mutex); 5992be7d22fSVladimir Kondratiev } 6002be7d22fSVladimir Kondratiev 6012be7d22fSVladimir Kondratiev static void wmi_evt_disconnect(struct wil6210_priv *wil, int id, 6022be7d22fSVladimir Kondratiev void *d, int len) 6032be7d22fSVladimir Kondratiev { 6042be7d22fSVladimir Kondratiev struct wmi_disconnect_event *evt = d; 6054821e6d8SVladimir Kondratiev u16 reason_code = le16_to_cpu(evt->protocol_reason_status); 6062be7d22fSVladimir Kondratiev 6070916d9f2SMaya Erez wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n", 6084821e6d8SVladimir Kondratiev evt->bssid, reason_code, evt->disconnect_reason); 6092be7d22fSVladimir Kondratiev 6102be7d22fSVladimir Kondratiev wil->sinfo_gen++; 6112be7d22fSVladimir Kondratiev 612097638a0SVladimir Kondratiev mutex_lock(&wil->mutex); 6134821e6d8SVladimir Kondratiev wil6210_disconnect(wil, evt->bssid, reason_code, true); 614097638a0SVladimir Kondratiev mutex_unlock(&wil->mutex); 6152be7d22fSVladimir Kondratiev } 6162be7d22fSVladimir Kondratiev 6172be7d22fSVladimir Kondratiev /* 6182be7d22fSVladimir Kondratiev * Firmware reports EAPOL frame using WME event. 6192be7d22fSVladimir Kondratiev * Reconstruct Ethernet frame and deliver it via normal Rx 6202be7d22fSVladimir Kondratiev */ 6212be7d22fSVladimir Kondratiev static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id, 6222be7d22fSVladimir Kondratiev void *d, int len) 6232be7d22fSVladimir Kondratiev { 6242be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 6252be7d22fSVladimir Kondratiev struct wmi_eapol_rx_event *evt = d; 6262be7d22fSVladimir Kondratiev u16 eapol_len = le16_to_cpu(evt->eapol_len); 6272be7d22fSVladimir Kondratiev int sz = eapol_len + ETH_HLEN; 6282be7d22fSVladimir Kondratiev struct sk_buff *skb; 6292be7d22fSVladimir Kondratiev struct ethhdr *eth; 630c8b78b5fSVladimir Kondratiev int cid; 631c8b78b5fSVladimir Kondratiev struct wil_net_stats *stats = NULL; 6322be7d22fSVladimir Kondratiev 6337743882dSVladimir Kondratiev wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len, 6342be7d22fSVladimir Kondratiev evt->src_mac); 6352be7d22fSVladimir Kondratiev 636c8b78b5fSVladimir Kondratiev cid = wil_find_cid(wil, evt->src_mac); 637c8b78b5fSVladimir Kondratiev if (cid >= 0) 638c8b78b5fSVladimir Kondratiev stats = &wil->sta[cid].stats; 639c8b78b5fSVladimir Kondratiev 6402be7d22fSVladimir Kondratiev if (eapol_len > 196) { /* TODO: revisit size limit */ 6412be7d22fSVladimir Kondratiev wil_err(wil, "EAPOL too large\n"); 6422be7d22fSVladimir Kondratiev return; 6432be7d22fSVladimir Kondratiev } 6442be7d22fSVladimir Kondratiev 6452be7d22fSVladimir Kondratiev skb = alloc_skb(sz, GFP_KERNEL); 6462be7d22fSVladimir Kondratiev if (!skb) { 6472be7d22fSVladimir Kondratiev wil_err(wil, "Failed to allocate skb\n"); 6482be7d22fSVladimir Kondratiev return; 6492be7d22fSVladimir Kondratiev } 650c8b78b5fSVladimir Kondratiev 6512be7d22fSVladimir Kondratiev eth = (struct ethhdr *)skb_put(skb, ETH_HLEN); 652a82553bbSVladimir Kondratiev ether_addr_copy(eth->h_dest, ndev->dev_addr); 653a82553bbSVladimir Kondratiev ether_addr_copy(eth->h_source, evt->src_mac); 6542be7d22fSVladimir Kondratiev eth->h_proto = cpu_to_be16(ETH_P_PAE); 6552be7d22fSVladimir Kondratiev memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len); 6562be7d22fSVladimir Kondratiev skb->protocol = eth_type_trans(skb, ndev); 6572be7d22fSVladimir Kondratiev if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) { 6582be7d22fSVladimir Kondratiev ndev->stats.rx_packets++; 659c8b78b5fSVladimir Kondratiev ndev->stats.rx_bytes += sz; 660c8b78b5fSVladimir Kondratiev if (stats) { 661c8b78b5fSVladimir Kondratiev stats->rx_packets++; 662c8b78b5fSVladimir Kondratiev stats->rx_bytes += sz; 663c8b78b5fSVladimir Kondratiev } 6642be7d22fSVladimir Kondratiev } else { 6652be7d22fSVladimir Kondratiev ndev->stats.rx_dropped++; 666c8b78b5fSVladimir Kondratiev if (stats) 667c8b78b5fSVladimir Kondratiev stats->rx_dropped++; 6682be7d22fSVladimir Kondratiev } 6692be7d22fSVladimir Kondratiev } 6702be7d22fSVladimir Kondratiev 671230d8442SVladimir Kondratiev static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len) 6723a124ed6SVladimir Kondratiev { 673230d8442SVladimir Kondratiev struct wmi_vring_en_event *evt = d; 674230d8442SVladimir Kondratiev u8 vri = evt->vring_index; 6753a124ed6SVladimir Kondratiev 676230d8442SVladimir Kondratiev wil_dbg_wmi(wil, "Enable vring %d\n", vri); 6773a124ed6SVladimir Kondratiev 678230d8442SVladimir Kondratiev if (vri >= ARRAY_SIZE(wil->vring_tx)) { 679230d8442SVladimir Kondratiev wil_err(wil, "Enable for invalid vring %d\n", vri); 680e58c9f70SVladimir Kondratiev return; 681e58c9f70SVladimir Kondratiev } 682230d8442SVladimir Kondratiev wil->vring_tx_data[vri].dot1x_open = true; 683230d8442SVladimir Kondratiev if (vri == wil->bcast_vring) /* no BA for bcast */ 684230d8442SVladimir Kondratiev return; 6853a3def8dSVladimir Kondratiev if (agg_wsize >= 0) 686230d8442SVladimir Kondratiev wil_addba_tx_request(wil, vri, agg_wsize); 6873442a504SVladimir Kondratiev } 6883442a504SVladimir Kondratiev 689249a382bSVladimir Kondratiev static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d, 690249a382bSVladimir Kondratiev int len) 691249a382bSVladimir Kondratiev { 692b874ddecSLior David struct wmi_ba_status_event *evt = d; 6933277213fSVladimir Kondratiev struct vring_tx_data *txdata; 694249a382bSVladimir Kondratiev 695cbcf5866SVladimir Kondratiev wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n", 6967b05b0abSVladimir Kondratiev evt->ringid, 6977b05b0abSVladimir Kondratiev evt->status == WMI_BA_AGREED ? "OK" : "N/A", 698cbcf5866SVladimir Kondratiev evt->agg_wsize, __le16_to_cpu(evt->ba_timeout), 699cbcf5866SVladimir Kondratiev evt->amsdu ? "+" : "-"); 700b4490f42SVladimir Kondratiev 7017b05b0abSVladimir Kondratiev if (evt->ringid >= WIL6210_MAX_TX_RINGS) { 7027b05b0abSVladimir Kondratiev wil_err(wil, "invalid ring id %d\n", evt->ringid); 7037b05b0abSVladimir Kondratiev return; 7047b05b0abSVladimir Kondratiev } 7057b05b0abSVladimir Kondratiev 7063277213fSVladimir Kondratiev if (evt->status != WMI_BA_AGREED) { 7073277213fSVladimir Kondratiev evt->ba_timeout = 0; 7083277213fSVladimir Kondratiev evt->agg_wsize = 0; 709cbcf5866SVladimir Kondratiev evt->amsdu = 0; 7107b05b0abSVladimir Kondratiev } 7117b05b0abSVladimir Kondratiev 7123277213fSVladimir Kondratiev txdata = &wil->vring_tx_data[evt->ringid]; 7133277213fSVladimir Kondratiev 7143277213fSVladimir Kondratiev txdata->agg_timeout = le16_to_cpu(evt->ba_timeout); 7153277213fSVladimir Kondratiev txdata->agg_wsize = evt->agg_wsize; 716cbcf5866SVladimir Kondratiev txdata->agg_amsdu = evt->amsdu; 7173a124ed6SVladimir Kondratiev txdata->addba_in_progress = false; 7187b05b0abSVladimir Kondratiev } 7197b05b0abSVladimir Kondratiev 7203277213fSVladimir Kondratiev static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d, 7213277213fSVladimir Kondratiev int len) 7223277213fSVladimir Kondratiev { 7233277213fSVladimir Kondratiev struct wmi_rcp_addba_req_event *evt = d; 7243277213fSVladimir Kondratiev 7253277213fSVladimir Kondratiev wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token, 7263277213fSVladimir Kondratiev evt->ba_param_set, evt->ba_timeout, 7273277213fSVladimir Kondratiev evt->ba_seq_ctrl); 7283277213fSVladimir Kondratiev } 7293277213fSVladimir Kondratiev 7303277213fSVladimir Kondratiev static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len) 731bd33273bSVladimir Kondratiev __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock) 7323277213fSVladimir Kondratiev { 7333277213fSVladimir Kondratiev struct wmi_delba_event *evt = d; 7343277213fSVladimir Kondratiev u8 cid, tid; 7353277213fSVladimir Kondratiev u16 reason = __le16_to_cpu(evt->reason); 7363277213fSVladimir Kondratiev struct wil_sta_info *sta; 737ec81b5adSDedy Lansky struct wil_tid_ampdu_rx *r; 738ec81b5adSDedy Lansky 739bd33273bSVladimir Kondratiev might_sleep(); 7403277213fSVladimir Kondratiev parse_cidxtid(evt->cidxtid, &cid, &tid); 7413277213fSVladimir Kondratiev wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n", 7423277213fSVladimir Kondratiev cid, tid, 7433277213fSVladimir Kondratiev evt->from_initiator ? "originator" : "recipient", 7443277213fSVladimir Kondratiev reason); 7453277213fSVladimir Kondratiev if (!evt->from_initiator) { 7463277213fSVladimir Kondratiev int i; 7473277213fSVladimir Kondratiev /* find Tx vring it belongs to */ 7483277213fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) { 7493277213fSVladimir Kondratiev if ((wil->vring2cid_tid[i][0] == cid) && 7503277213fSVladimir Kondratiev (wil->vring2cid_tid[i][1] == tid)) { 7513277213fSVladimir Kondratiev struct vring_tx_data *txdata = 7523277213fSVladimir Kondratiev &wil->vring_tx_data[i]; 7533277213fSVladimir Kondratiev 7543277213fSVladimir Kondratiev wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i); 7553277213fSVladimir Kondratiev txdata->agg_timeout = 0; 7563277213fSVladimir Kondratiev txdata->agg_wsize = 0; 7573a124ed6SVladimir Kondratiev txdata->addba_in_progress = false; 7583277213fSVladimir Kondratiev 7593277213fSVladimir Kondratiev break; /* max. 1 matching ring */ 7603277213fSVladimir Kondratiev } 7613277213fSVladimir Kondratiev } 7623277213fSVladimir Kondratiev if (i >= ARRAY_SIZE(wil->vring2cid_tid)) 7633277213fSVladimir Kondratiev wil_err(wil, "DELBA: unable to find Tx vring\n"); 7643277213fSVladimir Kondratiev return; 7653277213fSVladimir Kondratiev } 7663277213fSVladimir Kondratiev 7673277213fSVladimir Kondratiev sta = &wil->sta[cid]; 7683277213fSVladimir Kondratiev 769bd33273bSVladimir Kondratiev spin_lock_bh(&sta->tid_rx_lock); 770ec81b5adSDedy Lansky 7713277213fSVladimir Kondratiev r = sta->tid_rx[tid]; 7723277213fSVladimir Kondratiev sta->tid_rx[tid] = NULL; 773b4490f42SVladimir Kondratiev wil_tid_ampdu_rx_free(wil, r); 774ec81b5adSDedy Lansky 775bd33273bSVladimir Kondratiev spin_unlock_bh(&sta->tid_rx_lock); 776b4490f42SVladimir Kondratiev } 777b4490f42SVladimir Kondratiev 778b03fbab0SVladimir Kondratiev /** 779b03fbab0SVladimir Kondratiev * Some events are ignored for purpose; and need not be interpreted as 780b03fbab0SVladimir Kondratiev * "unhandled events" 781b03fbab0SVladimir Kondratiev */ 782b03fbab0SVladimir Kondratiev static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len) 783b03fbab0SVladimir Kondratiev { 784b03fbab0SVladimir Kondratiev wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len); 785b03fbab0SVladimir Kondratiev } 786b03fbab0SVladimir Kondratiev 7872be7d22fSVladimir Kondratiev static const struct { 7882be7d22fSVladimir Kondratiev int eventid; 7892be7d22fSVladimir Kondratiev void (*handler)(struct wil6210_priv *wil, int eventid, 7902be7d22fSVladimir Kondratiev void *data, int data_len); 7912be7d22fSVladimir Kondratiev } wmi_evt_handlers[] = { 7922be7d22fSVladimir Kondratiev {WMI_READY_EVENTID, wmi_evt_ready}, 793817f1853SVladimir Kondratiev {WMI_FW_READY_EVENTID, wmi_evt_ignore}, 7942be7d22fSVladimir Kondratiev {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt}, 79590d89e9aSVladimir Kondratiev {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt}, 7962be7d22fSVladimir Kondratiev {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete}, 7972be7d22fSVladimir Kondratiev {WMI_CONNECT_EVENTID, wmi_evt_connect}, 7982be7d22fSVladimir Kondratiev {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect}, 7992be7d22fSVladimir Kondratiev {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx}, 800249a382bSVladimir Kondratiev {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status}, 8013277213fSVladimir Kondratiev {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req}, 8023277213fSVladimir Kondratiev {WMI_DELBA_EVENTID, wmi_evt_delba}, 803230d8442SVladimir Kondratiev {WMI_VRING_EN_EVENTID, wmi_evt_vring_en}, 804b03fbab0SVladimir Kondratiev {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore}, 8052be7d22fSVladimir Kondratiev }; 8062be7d22fSVladimir Kondratiev 8072be7d22fSVladimir Kondratiev /* 8082be7d22fSVladimir Kondratiev * Run in IRQ context 8092be7d22fSVladimir Kondratiev * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev 8102be7d22fSVladimir Kondratiev * that will be eventually handled by the @wmi_event_worker in the thread 8112be7d22fSVladimir Kondratiev * context of thread "wil6210_wmi" 8122be7d22fSVladimir Kondratiev */ 8132be7d22fSVladimir Kondratiev void wmi_recv_cmd(struct wil6210_priv *wil) 8142be7d22fSVladimir Kondratiev { 8152be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_tail; 8162be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 8172be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx; 8182be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 8192be7d22fSVladimir Kondratiev u8 *cmd; 8202be7d22fSVladimir Kondratiev void __iomem *src; 8212be7d22fSVladimir Kondratiev ulong flags; 822a715c7ddSVladimir Kondratiev unsigned n; 8230916d9f2SMaya Erez unsigned int num_immed_reply = 0; 8242be7d22fSVladimir Kondratiev 825817f1853SVladimir Kondratiev if (!test_bit(wil_status_mbox_ready, wil->status)) { 8264cf99c93SDedy Lansky wil_err(wil, "Reset in progress. Cannot handle WMI event\n"); 82755f7acddSVladimir Kondratiev return; 82855f7acddSVladimir Kondratiev } 82955f7acddSVladimir Kondratiev 830a715c7ddSVladimir Kondratiev for (n = 0;; n++) { 8312be7d22fSVladimir Kondratiev u16 len; 83295266dc0SVladimir Kondratiev bool q; 8330916d9f2SMaya Erez bool immed_reply = false; 8342be7d22fSVladimir Kondratiev 835b9eeb512SVladimir Kondratiev r->head = wil_r(wil, RGF_MBOX + 8362be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.head)); 83795266dc0SVladimir Kondratiev if (r->tail == r->head) 83895266dc0SVladimir Kondratiev break; 8392be7d22fSVladimir Kondratiev 840a715c7ddSVladimir Kondratiev wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n", 841a715c7ddSVladimir Kondratiev r->head, r->tail); 842a715c7ddSVladimir Kondratiev /* read cmd descriptor from tail */ 8432be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail), 8442be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)); 8452be7d22fSVladimir Kondratiev if (d_tail.sync == 0) { 8462be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt not owned by FW?\n"); 84795266dc0SVladimir Kondratiev break; 8482be7d22fSVladimir Kondratiev } 8492be7d22fSVladimir Kondratiev 850a715c7ddSVladimir Kondratiev /* read cmd header from descriptor */ 8512be7d22fSVladimir Kondratiev if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) { 8522be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt at 0x%08x?\n", 8532be7d22fSVladimir Kondratiev le32_to_cpu(d_tail.addr)); 85495266dc0SVladimir Kondratiev break; 8552be7d22fSVladimir Kondratiev } 8562be7d22fSVladimir Kondratiev len = le16_to_cpu(hdr.len); 857a715c7ddSVladimir Kondratiev wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n", 858a715c7ddSVladimir Kondratiev le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type), 859a715c7ddSVladimir Kondratiev hdr.flags); 860a715c7ddSVladimir Kondratiev 861a715c7ddSVladimir Kondratiev /* read cmd buffer from descriptor */ 8622be7d22fSVladimir Kondratiev src = wmi_buffer(wil, d_tail.addr) + 8632be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr); 8642be7d22fSVladimir Kondratiev evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event, 8652be7d22fSVladimir Kondratiev event.wmi) + len, 4), 8662be7d22fSVladimir Kondratiev GFP_KERNEL); 86714f8dc49SJoe Perches if (!evt) 86895266dc0SVladimir Kondratiev break; 86914f8dc49SJoe Perches 8702be7d22fSVladimir Kondratiev evt->event.hdr = hdr; 8712be7d22fSVladimir Kondratiev cmd = (void *)&evt->event.wmi; 8722be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(cmd, src, len); 8732be7d22fSVladimir Kondratiev /* mark entry as empty */ 874b9eeb512SVladimir Kondratiev wil_w(wil, r->tail + 875b9eeb512SVladimir Kondratiev offsetof(struct wil6210_mbox_ring_desc, sync), 0); 8762be7d22fSVladimir Kondratiev /* indicate */ 8772be7d22fSVladimir Kondratiev if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) && 878b874ddecSLior David (len >= sizeof(struct wmi_cmd_hdr))) { 879b874ddecSLior David struct wmi_cmd_hdr *wmi = &evt->event.wmi; 880b874ddecSLior David u16 id = le16_to_cpu(wmi->command_id); 881b874ddecSLior David u32 tstamp = le32_to_cpu(wmi->fw_timestamp); 882fe5c271eSMaya Erez spin_lock_irqsave(&wil->wmi_ev_lock, flags); 8830916d9f2SMaya Erez if (wil->reply_id && wil->reply_id == id) { 8840916d9f2SMaya Erez if (wil->reply_buf) { 8850916d9f2SMaya Erez memcpy(wil->reply_buf, wmi, 8860916d9f2SMaya Erez min(len, wil->reply_size)); 8870916d9f2SMaya Erez immed_reply = true; 8880916d9f2SMaya Erez } 8890916d9f2SMaya Erez } 890fe5c271eSMaya Erez spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 8918fe59627SVladimir Kondratiev 892f988b23fSVladimir Kondratiev wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n", 893f988b23fSVladimir Kondratiev id, wmi->mid, tstamp); 894f988b23fSVladimir Kondratiev trace_wil6210_wmi_event(wmi, &wmi[1], 895f988b23fSVladimir Kondratiev len - sizeof(*wmi)); 8962be7d22fSVladimir Kondratiev } 8977743882dSVladimir Kondratiev wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1, 8982be7d22fSVladimir Kondratiev &evt->event.hdr, sizeof(hdr) + len, true); 8992be7d22fSVladimir Kondratiev 9002be7d22fSVladimir Kondratiev /* advance tail */ 9012be7d22fSVladimir Kondratiev r->tail = r->base + ((r->tail - r->base + 9022be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)) % r->size); 903b9eeb512SVladimir Kondratiev wil_w(wil, RGF_MBOX + 904b9eeb512SVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail); 9052be7d22fSVladimir Kondratiev 9060916d9f2SMaya Erez if (immed_reply) { 9070916d9f2SMaya Erez wil_dbg_wmi(wil, "%s: Complete WMI 0x%04x\n", 9080916d9f2SMaya Erez __func__, wil->reply_id); 9090916d9f2SMaya Erez kfree(evt); 9100916d9f2SMaya Erez num_immed_reply++; 9110916d9f2SMaya Erez complete(&wil->wmi_call); 9120916d9f2SMaya Erez } else { 9132be7d22fSVladimir Kondratiev /* add to the pending list */ 9142be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 9152be7d22fSVladimir Kondratiev list_add_tail(&evt->list, &wil->pending_wmi_ev); 9162be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 91795266dc0SVladimir Kondratiev q = queue_work(wil->wmi_wq, &wil->wmi_event_worker); 9187743882dSVladimir Kondratiev wil_dbg_wmi(wil, "queue_work -> %d\n", q); 9192be7d22fSVladimir Kondratiev } 9200916d9f2SMaya Erez } 92195266dc0SVladimir Kondratiev /* normally, 1 event per IRQ should be processed */ 9220916d9f2SMaya Erez wil_dbg_wmi(wil, "%s -> %d events queued, %d completed\n", __func__, 9230916d9f2SMaya Erez n - num_immed_reply, num_immed_reply); 9242be7d22fSVladimir Kondratiev } 9252be7d22fSVladimir Kondratiev 9262be7d22fSVladimir Kondratiev int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len, 9272be7d22fSVladimir Kondratiev u16 reply_id, void *reply, u8 reply_size, int to_msec) 9282be7d22fSVladimir Kondratiev { 9292be7d22fSVladimir Kondratiev int rc; 930f4bbb829SNicholas Mc Guire unsigned long remain; 9312be7d22fSVladimir Kondratiev 9322be7d22fSVladimir Kondratiev mutex_lock(&wil->wmi_mutex); 9332be7d22fSVladimir Kondratiev 934fe5c271eSMaya Erez spin_lock(&wil->wmi_ev_lock); 935fe5c271eSMaya Erez wil->reply_id = reply_id; 936fe5c271eSMaya Erez wil->reply_buf = reply; 937fe5c271eSMaya Erez wil->reply_size = reply_size; 938fe5c271eSMaya Erez spin_unlock(&wil->wmi_ev_lock); 939fe5c271eSMaya Erez 9402be7d22fSVladimir Kondratiev rc = __wmi_send(wil, cmdid, buf, len); 9412be7d22fSVladimir Kondratiev if (rc) 9422be7d22fSVladimir Kondratiev goto out; 9432be7d22fSVladimir Kondratiev 94459502647SDedy Lansky remain = wait_for_completion_timeout(&wil->wmi_call, 9452be7d22fSVladimir Kondratiev msecs_to_jiffies(to_msec)); 9462be7d22fSVladimir Kondratiev if (0 == remain) { 9472be7d22fSVladimir Kondratiev wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n", 9482be7d22fSVladimir Kondratiev cmdid, reply_id, to_msec); 9492be7d22fSVladimir Kondratiev rc = -ETIME; 9502be7d22fSVladimir Kondratiev } else { 9517743882dSVladimir Kondratiev wil_dbg_wmi(wil, 9522be7d22fSVladimir Kondratiev "wmi_call(0x%04x->0x%04x) completed in %d msec\n", 9532be7d22fSVladimir Kondratiev cmdid, reply_id, 9542be7d22fSVladimir Kondratiev to_msec - jiffies_to_msecs(remain)); 9552be7d22fSVladimir Kondratiev } 956fe5c271eSMaya Erez 957fe5c271eSMaya Erez out: 958fe5c271eSMaya Erez spin_lock(&wil->wmi_ev_lock); 9592be7d22fSVladimir Kondratiev wil->reply_id = 0; 9602be7d22fSVladimir Kondratiev wil->reply_buf = NULL; 9612be7d22fSVladimir Kondratiev wil->reply_size = 0; 962fe5c271eSMaya Erez spin_unlock(&wil->wmi_ev_lock); 963fe5c271eSMaya Erez 9642be7d22fSVladimir Kondratiev mutex_unlock(&wil->wmi_mutex); 9652be7d22fSVladimir Kondratiev 9662be7d22fSVladimir Kondratiev return rc; 9672be7d22fSVladimir Kondratiev } 9682be7d22fSVladimir Kondratiev 9692be7d22fSVladimir Kondratiev int wmi_echo(struct wil6210_priv *wil) 9702be7d22fSVladimir Kondratiev { 9712be7d22fSVladimir Kondratiev struct wmi_echo_cmd cmd = { 9722be7d22fSVladimir Kondratiev .value = cpu_to_le32(0x12345678), 9732be7d22fSVladimir Kondratiev }; 9742be7d22fSVladimir Kondratiev 9752be7d22fSVladimir Kondratiev return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd), 976a54a40daSVladimir Kondratiev WMI_ECHO_RSP_EVENTID, NULL, 0, 50); 9772be7d22fSVladimir Kondratiev } 9782be7d22fSVladimir Kondratiev 9792be7d22fSVladimir Kondratiev int wmi_set_mac_address(struct wil6210_priv *wil, void *addr) 9802be7d22fSVladimir Kondratiev { 9812be7d22fSVladimir Kondratiev struct wmi_set_mac_address_cmd cmd; 9822be7d22fSVladimir Kondratiev 983a82553bbSVladimir Kondratiev ether_addr_copy(cmd.mac, addr); 9842be7d22fSVladimir Kondratiev 9857743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Set MAC %pM\n", addr); 9862be7d22fSVladimir Kondratiev 9872be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd)); 9882be7d22fSVladimir Kondratiev } 9892be7d22fSVladimir Kondratiev 99010d599adSMaya Erez int wmi_led_cfg(struct wil6210_priv *wil, bool enable) 99110d599adSMaya Erez { 99210d599adSMaya Erez int rc = 0; 99310d599adSMaya Erez struct wmi_led_cfg_cmd cmd = { 99410d599adSMaya Erez .led_mode = enable, 99510d599adSMaya Erez .id = led_id, 99610d599adSMaya Erez .slow_blink_cfg.blink_on = 99710d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms), 99810d599adSMaya Erez .slow_blink_cfg.blink_off = 99910d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms), 100010d599adSMaya Erez .medium_blink_cfg.blink_on = 100110d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms), 100210d599adSMaya Erez .medium_blink_cfg.blink_off = 100310d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms), 100410d599adSMaya Erez .fast_blink_cfg.blink_on = 100510d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms), 100610d599adSMaya Erez .fast_blink_cfg.blink_off = 100710d599adSMaya Erez cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms), 100810d599adSMaya Erez .led_polarity = led_polarity, 100910d599adSMaya Erez }; 101010d599adSMaya Erez struct { 101110d599adSMaya Erez struct wmi_cmd_hdr wmi; 101210d599adSMaya Erez struct wmi_led_cfg_done_event evt; 101310d599adSMaya Erez } __packed reply; 101410d599adSMaya Erez 101510d599adSMaya Erez if (led_id == WIL_LED_INVALID_ID) 101610d599adSMaya Erez goto out; 101710d599adSMaya Erez 101810d599adSMaya Erez if (led_id > WIL_LED_MAX_ID) { 101910d599adSMaya Erez wil_err(wil, "Invalid led id %d\n", led_id); 102010d599adSMaya Erez rc = -EINVAL; 102110d599adSMaya Erez goto out; 102210d599adSMaya Erez } 102310d599adSMaya Erez 102410d599adSMaya Erez wil_dbg_wmi(wil, 102510d599adSMaya Erez "%s led %d\n", 102610d599adSMaya Erez enable ? "enabling" : "disabling", led_id); 102710d599adSMaya Erez 102810d599adSMaya Erez rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd), 102910d599adSMaya Erez WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply), 103010d599adSMaya Erez 100); 103110d599adSMaya Erez if (rc) 103210d599adSMaya Erez goto out; 103310d599adSMaya Erez 103410d599adSMaya Erez if (reply.evt.status) { 103510d599adSMaya Erez wil_err(wil, "led %d cfg failed with status %d\n", 103610d599adSMaya Erez led_id, le32_to_cpu(reply.evt.status)); 103710d599adSMaya Erez rc = -EINVAL; 103810d599adSMaya Erez } 103910d599adSMaya Erez 104010d599adSMaya Erez out: 104110d599adSMaya Erez return rc; 104210d599adSMaya Erez } 104310d599adSMaya Erez 10448e52fe30SHamad Kadmany int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, 1045b4944f2cSLior David u8 chan, u8 hidden_ssid, u8 is_go) 10462be7d22fSVladimir Kondratiev { 1047b8023177SVladimir Kondratiev int rc; 1048b8023177SVladimir Kondratiev 1049b8023177SVladimir Kondratiev struct wmi_pcp_start_cmd cmd = { 10502be7d22fSVladimir Kondratiev .bcon_interval = cpu_to_le16(bi), 10512be7d22fSVladimir Kondratiev .network_type = wmi_nettype, 10522be7d22fSVladimir Kondratiev .disable_sec_offload = 1, 1053adc2d122SVladimir Kondratiev .channel = chan - 1, 10541eb9d1e5SDedy Lansky .pcp_max_assoc_sta = max_assoc_sta, 10558e52fe30SHamad Kadmany .hidden_ssid = hidden_ssid, 1056b4944f2cSLior David .is_go = is_go, 10572be7d22fSVladimir Kondratiev }; 1058b8023177SVladimir Kondratiev struct { 1059b874ddecSLior David struct wmi_cmd_hdr wmi; 1060b8023177SVladimir Kondratiev struct wmi_pcp_started_event evt; 1061b8023177SVladimir Kondratiev } __packed reply; 10622be7d22fSVladimir Kondratiev 1063774974e5SVladimir Kondratiev if (!wil->privacy) 10642be7d22fSVladimir Kondratiev cmd.disable_sec = 1; 10652be7d22fSVladimir Kondratiev 10661eb9d1e5SDedy Lansky if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) || 10671eb9d1e5SDedy Lansky (cmd.pcp_max_assoc_sta <= 0)) { 10681eb9d1e5SDedy Lansky wil_info(wil, 10691eb9d1e5SDedy Lansky "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n", 10701eb9d1e5SDedy Lansky max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID); 10711eb9d1e5SDedy Lansky cmd.pcp_max_assoc_sta = WIL6210_MAX_CID; 10721eb9d1e5SDedy Lansky } 10731eb9d1e5SDedy Lansky 10748b5c7f6cSVladimir Kondratiev /* 10758b5c7f6cSVladimir Kondratiev * Processing time may be huge, in case of secure AP it takes about 10768b5c7f6cSVladimir Kondratiev * 3500ms for FW to start AP 10778b5c7f6cSVladimir Kondratiev */ 1078b8023177SVladimir Kondratiev rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd), 10798b5c7f6cSVladimir Kondratiev WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000); 1080b8023177SVladimir Kondratiev if (rc) 1081b8023177SVladimir Kondratiev return rc; 1082b8023177SVladimir Kondratiev 1083b8023177SVladimir Kondratiev if (reply.evt.status != WMI_FW_STATUS_SUCCESS) 1084b8023177SVladimir Kondratiev rc = -EINVAL; 1085b8023177SVladimir Kondratiev 108610d599adSMaya Erez if (wmi_nettype != WMI_NETTYPE_P2P) 108710d599adSMaya Erez /* Don't fail due to error in the led configuration */ 108810d599adSMaya Erez wmi_led_cfg(wil, true); 108910d599adSMaya Erez 1090b8023177SVladimir Kondratiev return rc; 1091b8023177SVladimir Kondratiev } 1092b8023177SVladimir Kondratiev 1093b8023177SVladimir Kondratiev int wmi_pcp_stop(struct wil6210_priv *wil) 1094b8023177SVladimir Kondratiev { 109510d599adSMaya Erez int rc; 109610d599adSMaya Erez 109710d599adSMaya Erez rc = wmi_led_cfg(wil, false); 109810d599adSMaya Erez if (rc) 109910d599adSMaya Erez return rc; 110010d599adSMaya Erez 1101b8023177SVladimir Kondratiev return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0, 1102b8023177SVladimir Kondratiev WMI_PCP_STOPPED_EVENTID, NULL, 0, 20); 11032be7d22fSVladimir Kondratiev } 11042be7d22fSVladimir Kondratiev 11052be7d22fSVladimir Kondratiev int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid) 11062be7d22fSVladimir Kondratiev { 11072be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd = { 11082be7d22fSVladimir Kondratiev .ssid_len = cpu_to_le32(ssid_len), 11092be7d22fSVladimir Kondratiev }; 11102be7d22fSVladimir Kondratiev 11112be7d22fSVladimir Kondratiev if (ssid_len > sizeof(cmd.ssid)) 11122be7d22fSVladimir Kondratiev return -EINVAL; 11132be7d22fSVladimir Kondratiev 11142be7d22fSVladimir Kondratiev memcpy(cmd.ssid, ssid, ssid_len); 11152be7d22fSVladimir Kondratiev 11162be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd)); 11172be7d22fSVladimir Kondratiev } 11182be7d22fSVladimir Kondratiev 11192be7d22fSVladimir Kondratiev int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid) 11202be7d22fSVladimir Kondratiev { 11212be7d22fSVladimir Kondratiev int rc; 11222be7d22fSVladimir Kondratiev struct { 1123b874ddecSLior David struct wmi_cmd_hdr wmi; 11242be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd; 11252be7d22fSVladimir Kondratiev } __packed reply; 11262be7d22fSVladimir Kondratiev int len; /* reply.cmd.ssid_len in CPU order */ 11272be7d22fSVladimir Kondratiev 11282be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID, 11292be7d22fSVladimir Kondratiev &reply, sizeof(reply), 20); 11302be7d22fSVladimir Kondratiev if (rc) 11312be7d22fSVladimir Kondratiev return rc; 11322be7d22fSVladimir Kondratiev 11332be7d22fSVladimir Kondratiev len = le32_to_cpu(reply.cmd.ssid_len); 11342be7d22fSVladimir Kondratiev if (len > sizeof(reply.cmd.ssid)) 11352be7d22fSVladimir Kondratiev return -EINVAL; 11362be7d22fSVladimir Kondratiev 11372be7d22fSVladimir Kondratiev *ssid_len = len; 11382be7d22fSVladimir Kondratiev memcpy(ssid, reply.cmd.ssid, len); 11392be7d22fSVladimir Kondratiev 11402be7d22fSVladimir Kondratiev return 0; 11412be7d22fSVladimir Kondratiev } 11422be7d22fSVladimir Kondratiev 11432be7d22fSVladimir Kondratiev int wmi_set_channel(struct wil6210_priv *wil, int channel) 11442be7d22fSVladimir Kondratiev { 11452be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd = { 11462be7d22fSVladimir Kondratiev .channel = channel - 1, 11472be7d22fSVladimir Kondratiev }; 11482be7d22fSVladimir Kondratiev 11492be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd)); 11502be7d22fSVladimir Kondratiev } 11512be7d22fSVladimir Kondratiev 11522be7d22fSVladimir Kondratiev int wmi_get_channel(struct wil6210_priv *wil, int *channel) 11532be7d22fSVladimir Kondratiev { 11542be7d22fSVladimir Kondratiev int rc; 11552be7d22fSVladimir Kondratiev struct { 1156b874ddecSLior David struct wmi_cmd_hdr wmi; 11572be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd; 11582be7d22fSVladimir Kondratiev } __packed reply; 11592be7d22fSVladimir Kondratiev 11602be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0, 11612be7d22fSVladimir Kondratiev WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20); 11622be7d22fSVladimir Kondratiev if (rc) 11632be7d22fSVladimir Kondratiev return rc; 11642be7d22fSVladimir Kondratiev 11652be7d22fSVladimir Kondratiev if (reply.cmd.channel > 3) 11662be7d22fSVladimir Kondratiev return -EINVAL; 11672be7d22fSVladimir Kondratiev 11682be7d22fSVladimir Kondratiev *channel = reply.cmd.channel + 1; 11692be7d22fSVladimir Kondratiev 11702be7d22fSVladimir Kondratiev return 0; 11712be7d22fSVladimir Kondratiev } 11722be7d22fSVladimir Kondratiev 1173e6d68341SDedy Lansky int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi) 1174b8023177SVladimir Kondratiev { 1175e6d68341SDedy Lansky int rc; 1176b8023177SVladimir Kondratiev struct wmi_p2p_cfg_cmd cmd = { 1177e6d68341SDedy Lansky .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER, 1178e6d68341SDedy Lansky .bcon_interval = cpu_to_le16(bi), 1179b8023177SVladimir Kondratiev .channel = channel - 1, 1180b8023177SVladimir Kondratiev }; 1181e6d68341SDedy Lansky struct { 1182e6d68341SDedy Lansky struct wmi_cmd_hdr wmi; 1183e6d68341SDedy Lansky struct wmi_p2p_cfg_done_event evt; 1184e6d68341SDedy Lansky } __packed reply; 1185b8023177SVladimir Kondratiev 1186e6d68341SDedy Lansky wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n"); 1187e6d68341SDedy Lansky 1188e6d68341SDedy Lansky rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd), 1189e6d68341SDedy Lansky WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300); 1190e6d68341SDedy Lansky if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { 1191e6d68341SDedy Lansky wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status); 1192e6d68341SDedy Lansky rc = -EINVAL; 1193e6d68341SDedy Lansky } 1194e6d68341SDedy Lansky 1195e6d68341SDedy Lansky return rc; 1196e6d68341SDedy Lansky } 1197e6d68341SDedy Lansky 1198e6d68341SDedy Lansky int wmi_start_listen(struct wil6210_priv *wil) 1199e6d68341SDedy Lansky { 1200e6d68341SDedy Lansky int rc; 1201e6d68341SDedy Lansky struct { 1202e6d68341SDedy Lansky struct wmi_cmd_hdr wmi; 1203e6d68341SDedy Lansky struct wmi_listen_started_event evt; 1204e6d68341SDedy Lansky } __packed reply; 1205e6d68341SDedy Lansky 1206e6d68341SDedy Lansky wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n"); 1207e6d68341SDedy Lansky 1208e6d68341SDedy Lansky rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0, 1209e6d68341SDedy Lansky WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300); 1210e6d68341SDedy Lansky if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { 1211e6d68341SDedy Lansky wil_err(wil, "device failed to start listen. status %d\n", 1212e6d68341SDedy Lansky reply.evt.status); 1213e6d68341SDedy Lansky rc = -EINVAL; 1214e6d68341SDedy Lansky } 1215e6d68341SDedy Lansky 1216e6d68341SDedy Lansky return rc; 1217e6d68341SDedy Lansky } 1218e6d68341SDedy Lansky 1219e6d68341SDedy Lansky int wmi_start_search(struct wil6210_priv *wil) 1220e6d68341SDedy Lansky { 1221e6d68341SDedy Lansky int rc; 1222e6d68341SDedy Lansky struct { 1223e6d68341SDedy Lansky struct wmi_cmd_hdr wmi; 1224e6d68341SDedy Lansky struct wmi_search_started_event evt; 1225e6d68341SDedy Lansky } __packed reply; 1226e6d68341SDedy Lansky 1227e6d68341SDedy Lansky wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n"); 1228e6d68341SDedy Lansky 1229e6d68341SDedy Lansky rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0, 1230e6d68341SDedy Lansky WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300); 1231e6d68341SDedy Lansky if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { 1232e6d68341SDedy Lansky wil_err(wil, "device failed to start search. status %d\n", 1233e6d68341SDedy Lansky reply.evt.status); 1234e6d68341SDedy Lansky rc = -EINVAL; 1235e6d68341SDedy Lansky } 1236e6d68341SDedy Lansky 1237e6d68341SDedy Lansky return rc; 1238e6d68341SDedy Lansky } 1239e6d68341SDedy Lansky 1240e6d68341SDedy Lansky int wmi_stop_discovery(struct wil6210_priv *wil) 1241e6d68341SDedy Lansky { 1242e6d68341SDedy Lansky int rc; 1243e6d68341SDedy Lansky 1244e6d68341SDedy Lansky wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n"); 1245e6d68341SDedy Lansky 1246e6d68341SDedy Lansky rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0, 1247e6d68341SDedy Lansky WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100); 1248e6d68341SDedy Lansky 1249e6d68341SDedy Lansky if (rc) 1250e6d68341SDedy Lansky wil_err(wil, "Failed to stop discovery\n"); 1251e6d68341SDedy Lansky 1252e6d68341SDedy Lansky return rc; 1253b8023177SVladimir Kondratiev } 1254b8023177SVladimir Kondratiev 12552be7d22fSVladimir Kondratiev int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index, 1256230d8442SVladimir Kondratiev const void *mac_addr, int key_usage) 12572be7d22fSVladimir Kondratiev { 12582be7d22fSVladimir Kondratiev struct wmi_delete_cipher_key_cmd cmd = { 12592be7d22fSVladimir Kondratiev .key_index = key_index, 12602be7d22fSVladimir Kondratiev }; 12612be7d22fSVladimir Kondratiev 12622be7d22fSVladimir Kondratiev if (mac_addr) 12632be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 12642be7d22fSVladimir Kondratiev 12652be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 12662be7d22fSVladimir Kondratiev } 12672be7d22fSVladimir Kondratiev 12682be7d22fSVladimir Kondratiev int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index, 1269230d8442SVladimir Kondratiev const void *mac_addr, int key_len, const void *key, 1270230d8442SVladimir Kondratiev int key_usage) 12712be7d22fSVladimir Kondratiev { 12722be7d22fSVladimir Kondratiev struct wmi_add_cipher_key_cmd cmd = { 12732be7d22fSVladimir Kondratiev .key_index = key_index, 1274230d8442SVladimir Kondratiev .key_usage = key_usage, 12752be7d22fSVladimir Kondratiev .key_len = key_len, 12762be7d22fSVladimir Kondratiev }; 12772be7d22fSVladimir Kondratiev 12782be7d22fSVladimir Kondratiev if (!key || (key_len > sizeof(cmd.key))) 12792be7d22fSVladimir Kondratiev return -EINVAL; 12802be7d22fSVladimir Kondratiev 12812be7d22fSVladimir Kondratiev memcpy(cmd.key, key, key_len); 12822be7d22fSVladimir Kondratiev if (mac_addr) 12832be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 12842be7d22fSVladimir Kondratiev 12852be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 12862be7d22fSVladimir Kondratiev } 12872be7d22fSVladimir Kondratiev 12882be7d22fSVladimir Kondratiev int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie) 12892be7d22fSVladimir Kondratiev { 12905421bf0cSVladimir Kondratiev static const char *const names[] = { 12915421bf0cSVladimir Kondratiev [WMI_FRAME_BEACON] = "BEACON", 12925421bf0cSVladimir Kondratiev [WMI_FRAME_PROBE_REQ] = "PROBE_REQ", 12935421bf0cSVladimir Kondratiev [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP", 12945421bf0cSVladimir Kondratiev [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ", 12955421bf0cSVladimir Kondratiev [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP", 12965421bf0cSVladimir Kondratiev }; 12972be7d22fSVladimir Kondratiev int rc; 12982be7d22fSVladimir Kondratiev u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len; 12992be7d22fSVladimir Kondratiev struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL); 13008fe59627SVladimir Kondratiev 13015421bf0cSVladimir Kondratiev if (!cmd) { 13025421bf0cSVladimir Kondratiev rc = -ENOMEM; 13035421bf0cSVladimir Kondratiev goto out; 13045421bf0cSVladimir Kondratiev } 1305ac4acdb7SVladimir Kondratiev if (!ie) 1306ac4acdb7SVladimir Kondratiev ie_len = 0; 13072be7d22fSVladimir Kondratiev 13082be7d22fSVladimir Kondratiev cmd->mgmt_frm_type = type; 13092be7d22fSVladimir Kondratiev /* BUG: FW API define ieLen as u8. Will fix FW */ 13102be7d22fSVladimir Kondratiev cmd->ie_len = cpu_to_le16(ie_len); 13112be7d22fSVladimir Kondratiev memcpy(cmd->ie_info, ie, ie_len); 131203866e7dSVladimir Kondratiev rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len); 13132be7d22fSVladimir Kondratiev kfree(cmd); 13145421bf0cSVladimir Kondratiev out: 13155421bf0cSVladimir Kondratiev if (rc) { 13165421bf0cSVladimir Kondratiev const char *name = type < ARRAY_SIZE(names) ? 13175421bf0cSVladimir Kondratiev names[type] : "??"; 13185421bf0cSVladimir Kondratiev wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc); 13195421bf0cSVladimir Kondratiev } 13202be7d22fSVladimir Kondratiev 13212be7d22fSVladimir Kondratiev return rc; 13222be7d22fSVladimir Kondratiev } 13232be7d22fSVladimir Kondratiev 13241647f12fSVladimir Kondratiev /** 13251647f12fSVladimir Kondratiev * wmi_rxon - turn radio on/off 13261647f12fSVladimir Kondratiev * @on: turn on if true, off otherwise 13271647f12fSVladimir Kondratiev * 13281647f12fSVladimir Kondratiev * Only switch radio. Channel should be set separately. 13291647f12fSVladimir Kondratiev * No timeout for rxon - radio turned on forever unless some other call 13301647f12fSVladimir Kondratiev * turns it off 13311647f12fSVladimir Kondratiev */ 13321647f12fSVladimir Kondratiev int wmi_rxon(struct wil6210_priv *wil, bool on) 13331647f12fSVladimir Kondratiev { 13341647f12fSVladimir Kondratiev int rc; 13351647f12fSVladimir Kondratiev struct { 1336b874ddecSLior David struct wmi_cmd_hdr wmi; 13371647f12fSVladimir Kondratiev struct wmi_listen_started_event evt; 13381647f12fSVladimir Kondratiev } __packed reply; 13391647f12fSVladimir Kondratiev 13401647f12fSVladimir Kondratiev wil_info(wil, "%s(%s)\n", __func__, on ? "on" : "off"); 13411647f12fSVladimir Kondratiev 13421647f12fSVladimir Kondratiev if (on) { 13431647f12fSVladimir Kondratiev rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0, 13441647f12fSVladimir Kondratiev WMI_LISTEN_STARTED_EVENTID, 13451647f12fSVladimir Kondratiev &reply, sizeof(reply), 100); 13461647f12fSVladimir Kondratiev if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS)) 13471647f12fSVladimir Kondratiev rc = -EINVAL; 13481647f12fSVladimir Kondratiev } else { 13491647f12fSVladimir Kondratiev rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0, 13501647f12fSVladimir Kondratiev WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20); 13511647f12fSVladimir Kondratiev } 13521647f12fSVladimir Kondratiev 13531647f12fSVladimir Kondratiev return rc; 13541647f12fSVladimir Kondratiev } 13551647f12fSVladimir Kondratiev 135647e19af9SVladimir Kondratiev int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring) 135747e19af9SVladimir Kondratiev { 135847e19af9SVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 135947e19af9SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 136047e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_cmd cmd = { 136147e19af9SVladimir Kondratiev .action = WMI_RX_CHAIN_ADD, 136247e19af9SVladimir Kondratiev .rx_sw_ring = { 1363c44690a1SVladimir Kondratiev .max_mpdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)), 136447e19af9SVladimir Kondratiev .ring_mem_base = cpu_to_le64(vring->pa), 136547e19af9SVladimir Kondratiev .ring_size = cpu_to_le16(vring->size), 136647e19af9SVladimir Kondratiev }, 136747e19af9SVladimir Kondratiev .mid = 0, /* TODO - what is it? */ 136847e19af9SVladimir Kondratiev .decap_trans_type = WMI_DECAP_TYPE_802_3, 1369b4490f42SVladimir Kondratiev .reorder_type = WMI_RX_SW_REORDER, 1370ab954628SVladimir Kondratiev .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh), 137147e19af9SVladimir Kondratiev }; 137247e19af9SVladimir Kondratiev struct { 1373b874ddecSLior David struct wmi_cmd_hdr wmi; 137447e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_done_event evt; 137547e19af9SVladimir Kondratiev } __packed evt; 137647e19af9SVladimir Kondratiev int rc; 137747e19af9SVladimir Kondratiev 137847e19af9SVladimir Kondratiev if (wdev->iftype == NL80211_IFTYPE_MONITOR) { 137947e19af9SVladimir Kondratiev struct ieee80211_channel *ch = wdev->preset_chandef.chan; 138047e19af9SVladimir Kondratiev 138147e19af9SVladimir Kondratiev cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON); 138247e19af9SVladimir Kondratiev if (ch) 138347e19af9SVladimir Kondratiev cmd.sniffer_cfg.channel = ch->hw_value - 1; 138447e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_info_mode = 138547e19af9SVladimir Kondratiev cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP); 138647e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_support = 138747e19af9SVladimir Kondratiev cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL) 13884765332dSVladimir Kondratiev ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS); 1389504937d4SKirshenbaum Erez } else { 1390504937d4SKirshenbaum Erez /* Initialize offload (in non-sniffer mode). 1391504937d4SKirshenbaum Erez * Linux IP stack always calculates IP checksum 1392504937d4SKirshenbaum Erez * HW always calculate TCP/UDP checksum 1393504937d4SKirshenbaum Erez */ 1394504937d4SKirshenbaum Erez cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS); 139547e19af9SVladimir Kondratiev } 1396c406ea7cSVladimir Kondratiev 1397c406ea7cSVladimir Kondratiev if (rx_align_2) 1398c406ea7cSVladimir Kondratiev cmd.l2_802_3_offload_ctrl |= 1399c406ea7cSVladimir Kondratiev L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK; 1400c406ea7cSVladimir Kondratiev 140147e19af9SVladimir Kondratiev /* typical time for secure PCP is 840ms */ 140247e19af9SVladimir Kondratiev rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd), 140347e19af9SVladimir Kondratiev WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000); 140447e19af9SVladimir Kondratiev if (rc) 140547e19af9SVladimir Kondratiev return rc; 140647e19af9SVladimir Kondratiev 140747e19af9SVladimir Kondratiev vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr); 140847e19af9SVladimir Kondratiev 14097743882dSVladimir Kondratiev wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n", 141047e19af9SVladimir Kondratiev le32_to_cpu(evt.evt.status), vring->hwtail); 141147e19af9SVladimir Kondratiev 141247e19af9SVladimir Kondratiev if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS) 141347e19af9SVladimir Kondratiev rc = -EINVAL; 141447e19af9SVladimir Kondratiev 141547e19af9SVladimir Kondratiev return rc; 141647e19af9SVladimir Kondratiev } 141747e19af9SVladimir Kondratiev 14188c679675SVladimir Kondratiev int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf) 14191a2780e0SVladimir Kondratiev { 14201a2780e0SVladimir Kondratiev int rc; 14211a2780e0SVladimir Kondratiev struct wmi_temp_sense_cmd cmd = { 14228c679675SVladimir Kondratiev .measure_baseband_en = cpu_to_le32(!!t_bb), 14238c679675SVladimir Kondratiev .measure_rf_en = cpu_to_le32(!!t_rf), 14248c679675SVladimir Kondratiev .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW), 14251a2780e0SVladimir Kondratiev }; 14261a2780e0SVladimir Kondratiev struct { 1427b874ddecSLior David struct wmi_cmd_hdr wmi; 14281a2780e0SVladimir Kondratiev struct wmi_temp_sense_done_event evt; 14291a2780e0SVladimir Kondratiev } __packed reply; 14301a2780e0SVladimir Kondratiev 14311a2780e0SVladimir Kondratiev rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd), 14321a2780e0SVladimir Kondratiev WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100); 14331a2780e0SVladimir Kondratiev if (rc) 14341a2780e0SVladimir Kondratiev return rc; 14351a2780e0SVladimir Kondratiev 14368c679675SVladimir Kondratiev if (t_bb) 14378c679675SVladimir Kondratiev *t_bb = le32_to_cpu(reply.evt.baseband_t1000); 14388c679675SVladimir Kondratiev if (t_rf) 14398c679675SVladimir Kondratiev *t_rf = le32_to_cpu(reply.evt.rf_t1000); 14401a2780e0SVladimir Kondratiev 14411a2780e0SVladimir Kondratiev return 0; 14421a2780e0SVladimir Kondratiev } 14431a2780e0SVladimir Kondratiev 14440916d9f2SMaya Erez int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, u16 reason, 14450916d9f2SMaya Erez bool full_disconnect) 14464d55a0a1SVladimir Kondratiev { 14473e9191fcSVladimir Kondratiev int rc; 14483e9191fcSVladimir Kondratiev u16 reason_code; 14494d55a0a1SVladimir Kondratiev struct wmi_disconnect_sta_cmd cmd = { 14504d55a0a1SVladimir Kondratiev .disconnect_reason = cpu_to_le16(reason), 14514d55a0a1SVladimir Kondratiev }; 14523e9191fcSVladimir Kondratiev struct { 1453b874ddecSLior David struct wmi_cmd_hdr wmi; 14543e9191fcSVladimir Kondratiev struct wmi_disconnect_event evt; 14553e9191fcSVladimir Kondratiev } __packed reply; 1456a82553bbSVladimir Kondratiev 1457a82553bbSVladimir Kondratiev ether_addr_copy(cmd.dst_mac, mac); 14584d55a0a1SVladimir Kondratiev 14594d55a0a1SVladimir Kondratiev wil_dbg_wmi(wil, "%s(%pM, reason %d)\n", __func__, mac, reason); 14604d55a0a1SVladimir Kondratiev 14613e9191fcSVladimir Kondratiev rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &cmd, sizeof(cmd), 14623e9191fcSVladimir Kondratiev WMI_DISCONNECT_EVENTID, &reply, sizeof(reply), 1000); 14633e9191fcSVladimir Kondratiev /* failure to disconnect in reasonable time treated as FW error */ 14643e9191fcSVladimir Kondratiev if (rc) { 14653e9191fcSVladimir Kondratiev wil_fw_error_recovery(wil); 14663e9191fcSVladimir Kondratiev return rc; 14673e9191fcSVladimir Kondratiev } 14683e9191fcSVladimir Kondratiev 14690916d9f2SMaya Erez if (full_disconnect) { 14703e9191fcSVladimir Kondratiev /* call event handler manually after processing wmi_call, 14710916d9f2SMaya Erez * to avoid deadlock - disconnect event handler acquires 14720916d9f2SMaya Erez * wil->mutex while it is already held here 14733e9191fcSVladimir Kondratiev */ 14743e9191fcSVladimir Kondratiev reason_code = le16_to_cpu(reply.evt.protocol_reason_status); 14753e9191fcSVladimir Kondratiev 14763e9191fcSVladimir Kondratiev wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n", 14773e9191fcSVladimir Kondratiev reply.evt.bssid, reason_code, 14783e9191fcSVladimir Kondratiev reply.evt.disconnect_reason); 14793e9191fcSVladimir Kondratiev 14803e9191fcSVladimir Kondratiev wil->sinfo_gen++; 14813e9191fcSVladimir Kondratiev wil6210_disconnect(wil, reply.evt.bssid, reason_code, true); 14820916d9f2SMaya Erez } 14833e9191fcSVladimir Kondratiev return 0; 14844d55a0a1SVladimir Kondratiev } 14854d55a0a1SVladimir Kondratiev 14863277213fSVladimir Kondratiev int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout) 14873277213fSVladimir Kondratiev { 14883277213fSVladimir Kondratiev struct wmi_vring_ba_en_cmd cmd = { 14893277213fSVladimir Kondratiev .ringid = ringid, 14903277213fSVladimir Kondratiev .agg_max_wsize = size, 14913277213fSVladimir Kondratiev .ba_timeout = cpu_to_le16(timeout), 1492cbcf5866SVladimir Kondratiev .amsdu = 0, 14933277213fSVladimir Kondratiev }; 14943277213fSVladimir Kondratiev 14953277213fSVladimir Kondratiev wil_dbg_wmi(wil, "%s(ring %d size %d timeout %d)\n", __func__, 14963277213fSVladimir Kondratiev ringid, size, timeout); 14973277213fSVladimir Kondratiev 14983277213fSVladimir Kondratiev return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd)); 14993277213fSVladimir Kondratiev } 15003277213fSVladimir Kondratiev 150126a359d9SVladimir Kondratiev int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason) 15023277213fSVladimir Kondratiev { 15033277213fSVladimir Kondratiev struct wmi_vring_ba_dis_cmd cmd = { 15043277213fSVladimir Kondratiev .ringid = ringid, 15053277213fSVladimir Kondratiev .reason = cpu_to_le16(reason), 15063277213fSVladimir Kondratiev }; 15073277213fSVladimir Kondratiev 15083277213fSVladimir Kondratiev wil_dbg_wmi(wil, "%s(ring %d reason %d)\n", __func__, 15093277213fSVladimir Kondratiev ringid, reason); 15103277213fSVladimir Kondratiev 15113277213fSVladimir Kondratiev return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd)); 15123277213fSVladimir Kondratiev } 15133277213fSVladimir Kondratiev 151426a359d9SVladimir Kondratiev int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason) 151526a359d9SVladimir Kondratiev { 151626a359d9SVladimir Kondratiev struct wmi_rcp_delba_cmd cmd = { 151726a359d9SVladimir Kondratiev .cidxtid = cidxtid, 151826a359d9SVladimir Kondratiev .reason = cpu_to_le16(reason), 151926a359d9SVladimir Kondratiev }; 152026a359d9SVladimir Kondratiev 152126a359d9SVladimir Kondratiev wil_dbg_wmi(wil, "%s(CID %d TID %d reason %d)\n", __func__, 152226a359d9SVladimir Kondratiev cidxtid & 0xf, (cidxtid >> 4) & 0xf, reason); 152326a359d9SVladimir Kondratiev 152426a359d9SVladimir Kondratiev return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd)); 152526a359d9SVladimir Kondratiev } 152626a359d9SVladimir Kondratiev 15273277213fSVladimir Kondratiev int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token, 15283277213fSVladimir Kondratiev u16 status, bool amsdu, u16 agg_wsize, u16 timeout) 15293277213fSVladimir Kondratiev { 15303277213fSVladimir Kondratiev int rc; 15313277213fSVladimir Kondratiev struct wmi_rcp_addba_resp_cmd cmd = { 15323277213fSVladimir Kondratiev .cidxtid = mk_cidxtid(cid, tid), 15333277213fSVladimir Kondratiev .dialog_token = token, 15343277213fSVladimir Kondratiev .status_code = cpu_to_le16(status), 15353277213fSVladimir Kondratiev /* bit 0: A-MSDU supported 15363277213fSVladimir Kondratiev * bit 1: policy (should be 0 for us) 15373277213fSVladimir Kondratiev * bits 2..5: TID 15383277213fSVladimir Kondratiev * bits 6..15: buffer size 15393277213fSVladimir Kondratiev */ 15403277213fSVladimir Kondratiev .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) | 15413277213fSVladimir Kondratiev (agg_wsize << 6)), 15423277213fSVladimir Kondratiev .ba_timeout = cpu_to_le16(timeout), 15433277213fSVladimir Kondratiev }; 15443277213fSVladimir Kondratiev struct { 1545b874ddecSLior David struct wmi_cmd_hdr wmi; 15463277213fSVladimir Kondratiev struct wmi_rcp_addba_resp_sent_event evt; 15473277213fSVladimir Kondratiev } __packed reply; 15483277213fSVladimir Kondratiev 15493277213fSVladimir Kondratiev wil_dbg_wmi(wil, 15503277213fSVladimir Kondratiev "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n", 15513277213fSVladimir Kondratiev cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-"); 15523277213fSVladimir Kondratiev 15533277213fSVladimir Kondratiev rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd), 1554230d8442SVladimir Kondratiev WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply), 1555230d8442SVladimir Kondratiev 100); 15563277213fSVladimir Kondratiev if (rc) 15573277213fSVladimir Kondratiev return rc; 15583277213fSVladimir Kondratiev 15593277213fSVladimir Kondratiev if (reply.evt.status) { 15603277213fSVladimir Kondratiev wil_err(wil, "ADDBA response failed with status %d\n", 15613277213fSVladimir Kondratiev le16_to_cpu(reply.evt.status)); 15623277213fSVladimir Kondratiev rc = -EINVAL; 15633277213fSVladimir Kondratiev } 15643277213fSVladimir Kondratiev 15653277213fSVladimir Kondratiev return rc; 15663277213fSVladimir Kondratiev } 15673277213fSVladimir Kondratiev 15682c207eb8SMaya Erez int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil, 15692c207eb8SMaya Erez enum wmi_ps_profile_type ps_profile) 15702c207eb8SMaya Erez { 15712c207eb8SMaya Erez int rc; 15722c207eb8SMaya Erez struct wmi_ps_dev_profile_cfg_cmd cmd = { 15732c207eb8SMaya Erez .ps_profile = ps_profile, 15742c207eb8SMaya Erez }; 15752c207eb8SMaya Erez struct { 15762c207eb8SMaya Erez struct wmi_cmd_hdr wmi; 15772c207eb8SMaya Erez struct wmi_ps_dev_profile_cfg_event evt; 15782c207eb8SMaya Erez } __packed reply; 15792c207eb8SMaya Erez u32 status; 15802c207eb8SMaya Erez 15812c207eb8SMaya Erez wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile); 15822c207eb8SMaya Erez 15832c207eb8SMaya Erez reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR); 15842c207eb8SMaya Erez 15852c207eb8SMaya Erez rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd), 15862c207eb8SMaya Erez WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply), 15872c207eb8SMaya Erez 100); 15882c207eb8SMaya Erez if (rc) 15892c207eb8SMaya Erez return rc; 15902c207eb8SMaya Erez 15912c207eb8SMaya Erez status = le32_to_cpu(reply.evt.status); 15922c207eb8SMaya Erez 15932c207eb8SMaya Erez if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) { 15942c207eb8SMaya Erez wil_err(wil, "ps dev profile cfg failed with status %d\n", 15952c207eb8SMaya Erez status); 15962c207eb8SMaya Erez rc = -EINVAL; 15972c207eb8SMaya Erez } 15982c207eb8SMaya Erez 15992c207eb8SMaya Erez return rc; 16002c207eb8SMaya Erez } 16012c207eb8SMaya Erez 16023fea18d0SLior David int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short) 16033fea18d0SLior David { 16043fea18d0SLior David int rc; 16053fea18d0SLior David struct wmi_set_mgmt_retry_limit_cmd cmd = { 16063fea18d0SLior David .mgmt_retry_limit = retry_short, 16073fea18d0SLior David }; 16083fea18d0SLior David struct { 16093fea18d0SLior David struct wmi_cmd_hdr wmi; 16103fea18d0SLior David struct wmi_set_mgmt_retry_limit_event evt; 16113fea18d0SLior David } __packed reply; 16123fea18d0SLior David 16133fea18d0SLior David wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short); 16143fea18d0SLior David 16153fea18d0SLior David if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities)) 16163fea18d0SLior David return -ENOTSUPP; 16173fea18d0SLior David 16183fea18d0SLior David reply.evt.status = WMI_FW_STATUS_FAILURE; 16193fea18d0SLior David 16203fea18d0SLior David rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd), 16213fea18d0SLior David WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply), 16223fea18d0SLior David 100); 16233fea18d0SLior David if (rc) 16243fea18d0SLior David return rc; 16253fea18d0SLior David 16263fea18d0SLior David if (reply.evt.status != WMI_FW_STATUS_SUCCESS) { 16273fea18d0SLior David wil_err(wil, "set mgmt retry limit failed with status %d\n", 16283fea18d0SLior David reply.evt.status); 16293fea18d0SLior David rc = -EINVAL; 16303fea18d0SLior David } 16313fea18d0SLior David 16323fea18d0SLior David return rc; 16333fea18d0SLior David } 16343fea18d0SLior David 16353fea18d0SLior David int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short) 16363fea18d0SLior David { 16373fea18d0SLior David int rc; 16383fea18d0SLior David struct { 16393fea18d0SLior David struct wmi_cmd_hdr wmi; 16403fea18d0SLior David struct wmi_get_mgmt_retry_limit_event evt; 16413fea18d0SLior David } __packed reply; 16423fea18d0SLior David 16433fea18d0SLior David wil_dbg_wmi(wil, "getting mgmt retry short\n"); 16443fea18d0SLior David 16453fea18d0SLior David if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities)) 16463fea18d0SLior David return -ENOTSUPP; 16473fea18d0SLior David 16483fea18d0SLior David reply.evt.mgmt_retry_limit = 0; 16493fea18d0SLior David rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0, 16503fea18d0SLior David WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply), 16513fea18d0SLior David 100); 16523fea18d0SLior David if (rc) 16533fea18d0SLior David return rc; 16543fea18d0SLior David 16553fea18d0SLior David if (retry_short) 16563fea18d0SLior David *retry_short = reply.evt.mgmt_retry_limit; 16573fea18d0SLior David 16583fea18d0SLior David return 0; 16593fea18d0SLior David } 16603fea18d0SLior David 1661035859a5SMaya Erez int wmi_abort_scan(struct wil6210_priv *wil) 1662035859a5SMaya Erez { 1663035859a5SMaya Erez int rc; 1664035859a5SMaya Erez 1665035859a5SMaya Erez wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n"); 1666035859a5SMaya Erez 1667035859a5SMaya Erez rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0); 1668035859a5SMaya Erez if (rc) 1669035859a5SMaya Erez wil_err(wil, "Failed to abort scan (%d)\n", rc); 1670035859a5SMaya Erez 1671035859a5SMaya Erez return rc; 1672035859a5SMaya Erez } 1673035859a5SMaya Erez 16742be7d22fSVladimir Kondratiev void wmi_event_flush(struct wil6210_priv *wil) 16752be7d22fSVladimir Kondratiev { 16762be7d22fSVladimir Kondratiev struct pending_wmi_event *evt, *t; 16772be7d22fSVladimir Kondratiev 16787743882dSVladimir Kondratiev wil_dbg_wmi(wil, "%s()\n", __func__); 16792be7d22fSVladimir Kondratiev 16802be7d22fSVladimir Kondratiev list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) { 16812be7d22fSVladimir Kondratiev list_del(&evt->list); 16822be7d22fSVladimir Kondratiev kfree(evt); 16832be7d22fSVladimir Kondratiev } 16842be7d22fSVladimir Kondratiev } 16852be7d22fSVladimir Kondratiev 16862be7d22fSVladimir Kondratiev static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id, 16872be7d22fSVladimir Kondratiev void *d, int len) 16882be7d22fSVladimir Kondratiev { 16892be7d22fSVladimir Kondratiev uint i; 16902be7d22fSVladimir Kondratiev 16912be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) { 16922be7d22fSVladimir Kondratiev if (wmi_evt_handlers[i].eventid == id) { 16932be7d22fSVladimir Kondratiev wmi_evt_handlers[i].handler(wil, id, d, len); 16942be7d22fSVladimir Kondratiev return true; 16952be7d22fSVladimir Kondratiev } 16962be7d22fSVladimir Kondratiev } 16972be7d22fSVladimir Kondratiev 16982be7d22fSVladimir Kondratiev return false; 16992be7d22fSVladimir Kondratiev } 17002be7d22fSVladimir Kondratiev 17012be7d22fSVladimir Kondratiev static void wmi_event_handle(struct wil6210_priv *wil, 17022be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 17032be7d22fSVladimir Kondratiev { 17042be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr->len); 17052be7d22fSVladimir Kondratiev 17062be7d22fSVladimir Kondratiev if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) && 1707b874ddecSLior David (len >= sizeof(struct wmi_cmd_hdr))) { 1708b874ddecSLior David struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]); 17092be7d22fSVladimir Kondratiev void *evt_data = (void *)(&wmi[1]); 1710b874ddecSLior David u16 id = le16_to_cpu(wmi->command_id); 1711028e1836SVladimir Kondratiev 1712028e1836SVladimir Kondratiev wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n", 1713028e1836SVladimir Kondratiev id, wil->reply_id); 17142be7d22fSVladimir Kondratiev /* check if someone waits for this event */ 17152be7d22fSVladimir Kondratiev if (wil->reply_id && wil->reply_id == id) { 17160916d9f2SMaya Erez WARN_ON(wil->reply_buf); 17172be7d22fSVladimir Kondratiev wmi_evt_call_handler(wil, id, evt_data, 17182be7d22fSVladimir Kondratiev len - sizeof(*wmi)); 17190916d9f2SMaya Erez wil_dbg_wmi(wil, "%s: Complete WMI 0x%04x\n", 17200916d9f2SMaya Erez __func__, id); 172159502647SDedy Lansky complete(&wil->wmi_call); 17222be7d22fSVladimir Kondratiev return; 17232be7d22fSVladimir Kondratiev } 17242be7d22fSVladimir Kondratiev /* unsolicited event */ 17252be7d22fSVladimir Kondratiev /* search for handler */ 17262be7d22fSVladimir Kondratiev if (!wmi_evt_call_handler(wil, id, evt_data, 17272be7d22fSVladimir Kondratiev len - sizeof(*wmi))) { 1728a3ce5ccdSDedy Lansky wil_info(wil, "Unhandled event 0x%04x\n", id); 17292be7d22fSVladimir Kondratiev } 17302be7d22fSVladimir Kondratiev } else { 17312be7d22fSVladimir Kondratiev wil_err(wil, "Unknown event type\n"); 17322be7d22fSVladimir Kondratiev print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1, 17332be7d22fSVladimir Kondratiev hdr, sizeof(*hdr) + len, true); 17342be7d22fSVladimir Kondratiev } 17352be7d22fSVladimir Kondratiev } 17362be7d22fSVladimir Kondratiev 17372be7d22fSVladimir Kondratiev /* 17382be7d22fSVladimir Kondratiev * Retrieve next WMI event from the pending list 17392be7d22fSVladimir Kondratiev */ 17402be7d22fSVladimir Kondratiev static struct list_head *next_wmi_ev(struct wil6210_priv *wil) 17412be7d22fSVladimir Kondratiev { 17422be7d22fSVladimir Kondratiev ulong flags; 17432be7d22fSVladimir Kondratiev struct list_head *ret = NULL; 17442be7d22fSVladimir Kondratiev 17452be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 17462be7d22fSVladimir Kondratiev 17472be7d22fSVladimir Kondratiev if (!list_empty(&wil->pending_wmi_ev)) { 17482be7d22fSVladimir Kondratiev ret = wil->pending_wmi_ev.next; 17492be7d22fSVladimir Kondratiev list_del(ret); 17502be7d22fSVladimir Kondratiev } 17512be7d22fSVladimir Kondratiev 17522be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 17532be7d22fSVladimir Kondratiev 17542be7d22fSVladimir Kondratiev return ret; 17552be7d22fSVladimir Kondratiev } 17562be7d22fSVladimir Kondratiev 17572be7d22fSVladimir Kondratiev /* 17582be7d22fSVladimir Kondratiev * Handler for the WMI events 17592be7d22fSVladimir Kondratiev */ 17602be7d22fSVladimir Kondratiev void wmi_event_worker(struct work_struct *work) 17612be7d22fSVladimir Kondratiev { 17622be7d22fSVladimir Kondratiev struct wil6210_priv *wil = container_of(work, struct wil6210_priv, 17632be7d22fSVladimir Kondratiev wmi_event_worker); 17642be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 17652be7d22fSVladimir Kondratiev struct list_head *lh; 17662be7d22fSVladimir Kondratiev 1767028e1836SVladimir Kondratiev wil_dbg_wmi(wil, "Start %s\n", __func__); 17682be7d22fSVladimir Kondratiev while ((lh = next_wmi_ev(wil)) != NULL) { 17692be7d22fSVladimir Kondratiev evt = list_entry(lh, struct pending_wmi_event, list); 17702be7d22fSVladimir Kondratiev wmi_event_handle(wil, &evt->event.hdr); 17712be7d22fSVladimir Kondratiev kfree(evt); 17722be7d22fSVladimir Kondratiev } 1773028e1836SVladimir Kondratiev wil_dbg_wmi(wil, "Finished %s\n", __func__); 17742be7d22fSVladimir Kondratiev } 1775