12be7d22fSVladimir Kondratiev /* 22be7d22fSVladimir Kondratiev * Copyright (c) 2012 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 172be7d22fSVladimir Kondratiev #include <linux/pci.h> 182be7d22fSVladimir Kondratiev #include <linux/io.h> 192be7d22fSVladimir Kondratiev #include <linux/list.h> 202be7d22fSVladimir Kondratiev #include <linux/etherdevice.h> 2147e19af9SVladimir Kondratiev #include <linux/if_arp.h> 222be7d22fSVladimir Kondratiev 232be7d22fSVladimir Kondratiev #include "wil6210.h" 2447e19af9SVladimir Kondratiev #include "txrx.h" 252be7d22fSVladimir Kondratiev #include "wmi.h" 262be7d22fSVladimir Kondratiev 272be7d22fSVladimir Kondratiev /** 282be7d22fSVladimir Kondratiev * WMI event receiving - theory of operations 292be7d22fSVladimir Kondratiev * 302be7d22fSVladimir Kondratiev * When firmware about to report WMI event, it fills memory area 312be7d22fSVladimir Kondratiev * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for 322be7d22fSVladimir Kondratiev * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler. 332be7d22fSVladimir Kondratiev * 342be7d22fSVladimir Kondratiev * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the 352be7d22fSVladimir Kondratiev * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up 362be7d22fSVladimir Kondratiev * and handles events within the @wmi_event_worker. Every event get detached 372be7d22fSVladimir Kondratiev * from list, processed and deleted. 382be7d22fSVladimir Kondratiev * 392be7d22fSVladimir Kondratiev * Purpose for this mechanism is to release IRQ thread; otherwise, 402be7d22fSVladimir Kondratiev * if WMI event handling involves another WMI command flow, this 2-nd flow 412be7d22fSVladimir Kondratiev * won't be completed because of blocked IRQ thread. 422be7d22fSVladimir Kondratiev */ 432be7d22fSVladimir Kondratiev 442be7d22fSVladimir Kondratiev /** 452be7d22fSVladimir Kondratiev * Addressing - theory of operations 462be7d22fSVladimir Kondratiev * 472be7d22fSVladimir Kondratiev * There are several buses present on the WIL6210 card. 482be7d22fSVladimir Kondratiev * Same memory areas are visible at different address on 492be7d22fSVladimir Kondratiev * the different busses. There are 3 main bus masters: 502be7d22fSVladimir Kondratiev * - MAC CPU (ucode) 512be7d22fSVladimir Kondratiev * - User CPU (firmware) 522be7d22fSVladimir Kondratiev * - AHB (host) 532be7d22fSVladimir Kondratiev * 542be7d22fSVladimir Kondratiev * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing 552be7d22fSVladimir Kondratiev * AHB addresses starting from 0x880000 562be7d22fSVladimir Kondratiev * 572be7d22fSVladimir Kondratiev * Internally, firmware uses addresses that allows faster access but 582be7d22fSVladimir Kondratiev * are invisible from the host. To read from these addresses, alternative 592be7d22fSVladimir Kondratiev * AHB address must be used. 602be7d22fSVladimir Kondratiev * 612be7d22fSVladimir Kondratiev * Memory mapping 622be7d22fSVladimir Kondratiev * Linker address PCI/Host address 632be7d22fSVladimir Kondratiev * 0x880000 .. 0xa80000 2Mb BAR0 642be7d22fSVladimir Kondratiev * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM 652be7d22fSVladimir Kondratiev * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH 662be7d22fSVladimir Kondratiev */ 672be7d22fSVladimir Kondratiev 682be7d22fSVladimir Kondratiev /** 692be7d22fSVladimir Kondratiev * @fw_mapping provides memory remapping table 702be7d22fSVladimir Kondratiev */ 712be7d22fSVladimir Kondratiev static const struct { 722be7d22fSVladimir Kondratiev u32 from; /* linker address - from, inclusive */ 732be7d22fSVladimir Kondratiev u32 to; /* linker address - to, exclusive */ 742be7d22fSVladimir Kondratiev u32 host; /* PCI/Host address - BAR0 + 0x880000 */ 752be7d22fSVladimir Kondratiev } fw_mapping[] = { 762be7d22fSVladimir Kondratiev {0x000000, 0x040000, 0x8c0000}, /* FW code RAM 256k */ 772be7d22fSVladimir Kondratiev {0x800000, 0x808000, 0x900000}, /* FW data RAM 32k */ 782be7d22fSVladimir Kondratiev {0x840000, 0x860000, 0x908000}, /* peripheral data RAM 128k/96k used */ 792be7d22fSVladimir Kondratiev {0x880000, 0x88a000, 0x880000}, /* various RGF */ 802be7d22fSVladimir Kondratiev {0x8c0000, 0x932000, 0x8c0000}, /* trivial mapping for upper area */ 812be7d22fSVladimir Kondratiev /* 822be7d22fSVladimir Kondratiev * 920000..930000 ucode code RAM 832be7d22fSVladimir Kondratiev * 930000..932000 ucode data RAM 842be7d22fSVladimir Kondratiev */ 852be7d22fSVladimir Kondratiev }; 862be7d22fSVladimir Kondratiev 872be7d22fSVladimir Kondratiev /** 882be7d22fSVladimir Kondratiev * return AHB address for given firmware/ucode internal (linker) address 892be7d22fSVladimir Kondratiev * @x - internal address 902be7d22fSVladimir Kondratiev * If address have no valid AHB mapping, return 0 912be7d22fSVladimir Kondratiev */ 922be7d22fSVladimir Kondratiev static u32 wmi_addr_remap(u32 x) 932be7d22fSVladimir Kondratiev { 942be7d22fSVladimir Kondratiev uint i; 952be7d22fSVladimir Kondratiev 962be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 972be7d22fSVladimir Kondratiev if ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)) 982be7d22fSVladimir Kondratiev return x + fw_mapping[i].host - fw_mapping[i].from; 992be7d22fSVladimir Kondratiev } 1002be7d22fSVladimir Kondratiev 1012be7d22fSVladimir Kondratiev return 0; 1022be7d22fSVladimir Kondratiev } 1032be7d22fSVladimir Kondratiev 1042be7d22fSVladimir Kondratiev /** 1052be7d22fSVladimir Kondratiev * Check address validity for WMI buffer; remap if needed 1062be7d22fSVladimir Kondratiev * @ptr - internal (linker) fw/ucode address 1072be7d22fSVladimir Kondratiev * 1082be7d22fSVladimir Kondratiev * Valid buffer should be DWORD aligned 1092be7d22fSVladimir Kondratiev * 1102be7d22fSVladimir Kondratiev * return address for accessing buffer from the host; 1112be7d22fSVladimir Kondratiev * if buffer is not valid, return NULL. 1122be7d22fSVladimir Kondratiev */ 1132be7d22fSVladimir Kondratiev void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_) 1142be7d22fSVladimir Kondratiev { 1152be7d22fSVladimir Kondratiev u32 off; 1162be7d22fSVladimir Kondratiev u32 ptr = le32_to_cpu(ptr_); 1172be7d22fSVladimir Kondratiev 1182be7d22fSVladimir Kondratiev if (ptr % 4) 1192be7d22fSVladimir Kondratiev return NULL; 1202be7d22fSVladimir Kondratiev 1212be7d22fSVladimir Kondratiev ptr = wmi_addr_remap(ptr); 1222be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1232be7d22fSVladimir Kondratiev return NULL; 1242be7d22fSVladimir Kondratiev 1252be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1262be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1272be7d22fSVladimir Kondratiev return NULL; 1282be7d22fSVladimir Kondratiev 1292be7d22fSVladimir Kondratiev return wil->csr + off; 1302be7d22fSVladimir Kondratiev } 1312be7d22fSVladimir Kondratiev 1322be7d22fSVladimir Kondratiev /** 1332be7d22fSVladimir Kondratiev * Check address validity 1342be7d22fSVladimir Kondratiev */ 1352be7d22fSVladimir Kondratiev void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr) 1362be7d22fSVladimir Kondratiev { 1372be7d22fSVladimir Kondratiev u32 off; 1382be7d22fSVladimir Kondratiev 1392be7d22fSVladimir Kondratiev if (ptr % 4) 1402be7d22fSVladimir Kondratiev return NULL; 1412be7d22fSVladimir Kondratiev 1422be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1432be7d22fSVladimir Kondratiev return NULL; 1442be7d22fSVladimir Kondratiev 1452be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1462be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1472be7d22fSVladimir Kondratiev return NULL; 1482be7d22fSVladimir Kondratiev 1492be7d22fSVladimir Kondratiev return wil->csr + off; 1502be7d22fSVladimir Kondratiev } 1512be7d22fSVladimir Kondratiev 1522be7d22fSVladimir Kondratiev int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr, 1532be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 1542be7d22fSVladimir Kondratiev { 1552be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, ptr); 1562be7d22fSVladimir Kondratiev if (!src) 1572be7d22fSVladimir Kondratiev return -EINVAL; 1582be7d22fSVladimir Kondratiev 1592be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(hdr, src, sizeof(*hdr)); 1602be7d22fSVladimir Kondratiev 1612be7d22fSVladimir Kondratiev return 0; 1622be7d22fSVladimir Kondratiev } 1632be7d22fSVladimir Kondratiev 1642be7d22fSVladimir Kondratiev static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) 1652be7d22fSVladimir Kondratiev { 1662be7d22fSVladimir Kondratiev struct { 1672be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 1682be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 1692be7d22fSVladimir Kondratiev } __packed cmd = { 1702be7d22fSVladimir Kondratiev .hdr = { 1712be7d22fSVladimir Kondratiev .type = WIL_MBOX_HDR_TYPE_WMI, 1722be7d22fSVladimir Kondratiev .flags = 0, 1732be7d22fSVladimir Kondratiev .len = cpu_to_le16(sizeof(cmd.wmi) + len), 1742be7d22fSVladimir Kondratiev }, 1752be7d22fSVladimir Kondratiev .wmi = { 1762be7d22fSVladimir Kondratiev .id = cpu_to_le16(cmdid), 1772be7d22fSVladimir Kondratiev .info1 = 0, 1782be7d22fSVladimir Kondratiev }, 1792be7d22fSVladimir Kondratiev }; 1802be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx; 1812be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_head; 1822be7d22fSVladimir Kondratiev u32 next_head; 1832be7d22fSVladimir Kondratiev void __iomem *dst; 1842be7d22fSVladimir Kondratiev void __iomem *head = wmi_addr(wil, r->head); 1852be7d22fSVladimir Kondratiev uint retry; 1862be7d22fSVladimir Kondratiev 1872be7d22fSVladimir Kondratiev if (sizeof(cmd) + len > r->entry_size) { 1882be7d22fSVladimir Kondratiev wil_err(wil, "WMI size too large: %d bytes, max is %d\n", 1892be7d22fSVladimir Kondratiev (int)(sizeof(cmd) + len), r->entry_size); 1902be7d22fSVladimir Kondratiev return -ERANGE; 1912be7d22fSVladimir Kondratiev 1922be7d22fSVladimir Kondratiev } 1932be7d22fSVladimir Kondratiev 1942be7d22fSVladimir Kondratiev might_sleep(); 1952be7d22fSVladimir Kondratiev 1962be7d22fSVladimir Kondratiev if (!test_bit(wil_status_fwready, &wil->status)) { 1972be7d22fSVladimir Kondratiev wil_err(wil, "FW not ready\n"); 1982be7d22fSVladimir Kondratiev return -EAGAIN; 1992be7d22fSVladimir Kondratiev } 2002be7d22fSVladimir Kondratiev 2012be7d22fSVladimir Kondratiev if (!head) { 2022be7d22fSVladimir Kondratiev wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head); 2032be7d22fSVladimir Kondratiev return -EINVAL; 2042be7d22fSVladimir Kondratiev } 2052be7d22fSVladimir Kondratiev /* read Tx head till it is not busy */ 2062be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 2072be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_head, head, sizeof(d_head)); 2082be7d22fSVladimir Kondratiev if (d_head.sync == 0) 2092be7d22fSVladimir Kondratiev break; 2102be7d22fSVladimir Kondratiev msleep(20); 2112be7d22fSVladimir Kondratiev } 2122be7d22fSVladimir Kondratiev if (d_head.sync != 0) { 2132be7d22fSVladimir Kondratiev wil_err(wil, "WMI head busy\n"); 2142be7d22fSVladimir Kondratiev return -EBUSY; 2152be7d22fSVladimir Kondratiev } 2162be7d22fSVladimir Kondratiev /* next head */ 2172be7d22fSVladimir Kondratiev next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size); 2182be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head); 2192be7d22fSVladimir Kondratiev /* wait till FW finish with previous command */ 2202be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 2212be7d22fSVladimir Kondratiev r->tail = ioread32(wil->csr + HOST_MBOX + 2222be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx.tail)); 2232be7d22fSVladimir Kondratiev if (next_head != r->tail) 2242be7d22fSVladimir Kondratiev break; 2252be7d22fSVladimir Kondratiev msleep(20); 2262be7d22fSVladimir Kondratiev } 2272be7d22fSVladimir Kondratiev if (next_head == r->tail) { 2282be7d22fSVladimir Kondratiev wil_err(wil, "WMI ring full\n"); 2292be7d22fSVladimir Kondratiev return -EBUSY; 2302be7d22fSVladimir Kondratiev } 2312be7d22fSVladimir Kondratiev dst = wmi_buffer(wil, d_head.addr); 2322be7d22fSVladimir Kondratiev if (!dst) { 2332be7d22fSVladimir Kondratiev wil_err(wil, "invalid WMI buffer: 0x%08x\n", 2342be7d22fSVladimir Kondratiev le32_to_cpu(d_head.addr)); 2352be7d22fSVladimir Kondratiev return -EINVAL; 2362be7d22fSVladimir Kondratiev } 2372be7d22fSVladimir Kondratiev cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq); 2382be7d22fSVladimir Kondratiev /* set command */ 2392be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "WMI command 0x%04x [%d]\n", cmdid, len); 2402be7d22fSVladimir Kondratiev wil_hex_dump_WMI("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd, 2412be7d22fSVladimir Kondratiev sizeof(cmd), true); 2422be7d22fSVladimir Kondratiev wil_hex_dump_WMI("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf, 2432be7d22fSVladimir Kondratiev len, true); 2442be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst, &cmd, sizeof(cmd)); 2452be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst + sizeof(cmd), buf, len); 2462be7d22fSVladimir Kondratiev /* mark entry as full */ 2472be7d22fSVladimir Kondratiev iowrite32(1, wil->csr + HOSTADDR(r->head) + 2482be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ring_desc, sync)); 2492be7d22fSVladimir Kondratiev /* advance next ptr */ 2502be7d22fSVladimir Kondratiev iowrite32(r->head = next_head, wil->csr + HOST_MBOX + 2512be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx.head)); 2522be7d22fSVladimir Kondratiev 2532be7d22fSVladimir Kondratiev /* interrupt to FW */ 2542be7d22fSVladimir Kondratiev iowrite32(SW_INT_MBOX, wil->csr + HOST_SW_INT); 2552be7d22fSVladimir Kondratiev 2562be7d22fSVladimir Kondratiev return 0; 2572be7d22fSVladimir Kondratiev } 2582be7d22fSVladimir Kondratiev 2592be7d22fSVladimir Kondratiev int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) 2602be7d22fSVladimir Kondratiev { 2612be7d22fSVladimir Kondratiev int rc; 2622be7d22fSVladimir Kondratiev 2632be7d22fSVladimir Kondratiev mutex_lock(&wil->wmi_mutex); 2642be7d22fSVladimir Kondratiev rc = __wmi_send(wil, cmdid, buf, len); 2652be7d22fSVladimir Kondratiev mutex_unlock(&wil->wmi_mutex); 2662be7d22fSVladimir Kondratiev 2672be7d22fSVladimir Kondratiev return rc; 2682be7d22fSVladimir Kondratiev } 2692be7d22fSVladimir Kondratiev 2702be7d22fSVladimir Kondratiev /*=== Event handlers ===*/ 2712be7d22fSVladimir Kondratiev static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len) 2722be7d22fSVladimir Kondratiev { 2732be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 2742be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 2752be7d22fSVladimir Kondratiev struct wmi_ready_event *evt = d; 2762be7d22fSVladimir Kondratiev u32 ver = le32_to_cpu(evt->sw_version); 2772be7d22fSVladimir Kondratiev 2782be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "FW ver. %d; MAC %pM\n", ver, evt->mac); 2792be7d22fSVladimir Kondratiev 2802be7d22fSVladimir Kondratiev if (!is_valid_ether_addr(ndev->dev_addr)) { 2812be7d22fSVladimir Kondratiev memcpy(ndev->dev_addr, evt->mac, ETH_ALEN); 2822be7d22fSVladimir Kondratiev memcpy(ndev->perm_addr, evt->mac, ETH_ALEN); 2832be7d22fSVladimir Kondratiev } 2842be7d22fSVladimir Kondratiev snprintf(wdev->wiphy->fw_version, sizeof(wdev->wiphy->fw_version), 2852be7d22fSVladimir Kondratiev "%d", ver); 2862be7d22fSVladimir Kondratiev } 2872be7d22fSVladimir Kondratiev 2882be7d22fSVladimir Kondratiev static void wmi_evt_fw_ready(struct wil6210_priv *wil, int id, void *d, 2892be7d22fSVladimir Kondratiev int len) 2902be7d22fSVladimir Kondratiev { 2912be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "WMI: FW ready\n"); 2922be7d22fSVladimir Kondratiev 2932be7d22fSVladimir Kondratiev set_bit(wil_status_fwready, &wil->status); 2942be7d22fSVladimir Kondratiev /* reuse wmi_ready for the firmware ready indication */ 2952be7d22fSVladimir Kondratiev complete(&wil->wmi_ready); 2962be7d22fSVladimir Kondratiev } 2972be7d22fSVladimir Kondratiev 2982be7d22fSVladimir Kondratiev static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) 2992be7d22fSVladimir Kondratiev { 3002be7d22fSVladimir Kondratiev struct wmi_rx_mgmt_packet_event *data = d; 3012be7d22fSVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 3022be7d22fSVladimir Kondratiev struct ieee80211_mgmt *rx_mgmt_frame = 3032be7d22fSVladimir Kondratiev (struct ieee80211_mgmt *)data->payload; 3042be7d22fSVladimir Kondratiev int ch_no = data->info.channel+1; 3052be7d22fSVladimir Kondratiev u32 freq = ieee80211_channel_to_frequency(ch_no, 3062be7d22fSVladimir Kondratiev IEEE80211_BAND_60GHZ); 3072be7d22fSVladimir Kondratiev struct ieee80211_channel *channel = ieee80211_get_channel(wiphy, freq); 3082be7d22fSVladimir Kondratiev /* TODO convert LE to CPU */ 3092be7d22fSVladimir Kondratiev s32 signal = 0; /* TODO */ 3102be7d22fSVladimir Kondratiev __le16 fc = rx_mgmt_frame->frame_control; 3112be7d22fSVladimir Kondratiev u32 d_len = le32_to_cpu(data->info.len); 3122be7d22fSVladimir Kondratiev u16 d_status = le16_to_cpu(data->info.status); 3132be7d22fSVladimir Kondratiev 3142be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "MGMT: channel %d MCS %d SNR %d\n", 3152be7d22fSVladimir Kondratiev data->info.channel, data->info.mcs, data->info.snr); 3162be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "status 0x%04x len %d stype %04x\n", d_status, d_len, 3172be7d22fSVladimir Kondratiev le16_to_cpu(data->info.stype)); 3182be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "qid %d mid %d cid %d\n", 3192be7d22fSVladimir Kondratiev data->info.qid, data->info.mid, data->info.cid); 3202be7d22fSVladimir Kondratiev 3212be7d22fSVladimir Kondratiev if (!channel) { 3222be7d22fSVladimir Kondratiev wil_err(wil, "Frame on unsupported channel\n"); 3232be7d22fSVladimir Kondratiev return; 3242be7d22fSVladimir Kondratiev } 3252be7d22fSVladimir Kondratiev 3262be7d22fSVladimir Kondratiev if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) { 3272be7d22fSVladimir Kondratiev struct cfg80211_bss *bss; 3282be7d22fSVladimir Kondratiev u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp); 3292be7d22fSVladimir Kondratiev u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info); 3302be7d22fSVladimir Kondratiev u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int); 3312be7d22fSVladimir Kondratiev const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable; 3322be7d22fSVladimir Kondratiev size_t ie_len = d_len - offsetof(struct ieee80211_mgmt, 3332be7d22fSVladimir Kondratiev u.beacon.variable); 3342be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Capability info : 0x%04x\n", cap); 3352be7d22fSVladimir Kondratiev 3362be7d22fSVladimir Kondratiev bss = cfg80211_inform_bss(wiphy, channel, rx_mgmt_frame->bssid, 3372be7d22fSVladimir Kondratiev tsf, cap, bi, ie_buf, ie_len, 3382be7d22fSVladimir Kondratiev signal, GFP_KERNEL); 3392be7d22fSVladimir Kondratiev if (bss) { 3402be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Added BSS %pM\n", 3412be7d22fSVladimir Kondratiev rx_mgmt_frame->bssid); 3422be7d22fSVladimir Kondratiev cfg80211_put_bss(bss); 3432be7d22fSVladimir Kondratiev } else { 3442be7d22fSVladimir Kondratiev wil_err(wil, "cfg80211_inform_bss() failed\n"); 3452be7d22fSVladimir Kondratiev } 3462be7d22fSVladimir Kondratiev } 3472be7d22fSVladimir Kondratiev } 3482be7d22fSVladimir Kondratiev 3492be7d22fSVladimir Kondratiev static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id, 3502be7d22fSVladimir Kondratiev void *d, int len) 3512be7d22fSVladimir Kondratiev { 3522be7d22fSVladimir Kondratiev if (wil->scan_request) { 3532be7d22fSVladimir Kondratiev struct wmi_scan_complete_event *data = d; 3542be7d22fSVladimir Kondratiev bool aborted = (data->status != 0); 3552be7d22fSVladimir Kondratiev 3562be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "SCAN_COMPLETE(0x%08x)\n", data->status); 3572be7d22fSVladimir Kondratiev cfg80211_scan_done(wil->scan_request, aborted); 3582be7d22fSVladimir Kondratiev wil->scan_request = NULL; 3592be7d22fSVladimir Kondratiev } else { 3602be7d22fSVladimir Kondratiev wil_err(wil, "SCAN_COMPLETE while not scanning\n"); 3612be7d22fSVladimir Kondratiev } 3622be7d22fSVladimir Kondratiev } 3632be7d22fSVladimir Kondratiev 3642be7d22fSVladimir Kondratiev static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len) 3652be7d22fSVladimir Kondratiev { 3662be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 3672be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 3682be7d22fSVladimir Kondratiev struct wmi_connect_event *evt = d; 3692be7d22fSVladimir Kondratiev int ch; /* channel number */ 3702be7d22fSVladimir Kondratiev struct station_info sinfo; 3712be7d22fSVladimir Kondratiev u8 *assoc_req_ie, *assoc_resp_ie; 3722be7d22fSVladimir Kondratiev size_t assoc_req_ielen, assoc_resp_ielen; 3732be7d22fSVladimir Kondratiev /* capinfo(u16) + listen_interval(u16) + IEs */ 3742be7d22fSVladimir Kondratiev const size_t assoc_req_ie_offset = sizeof(u16) * 2; 3752be7d22fSVladimir Kondratiev /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */ 3762be7d22fSVladimir Kondratiev const size_t assoc_resp_ie_offset = sizeof(u16) * 3; 3772be7d22fSVladimir Kondratiev 3782be7d22fSVladimir Kondratiev if (len < sizeof(*evt)) { 3792be7d22fSVladimir Kondratiev wil_err(wil, "Connect event too short : %d bytes\n", len); 3802be7d22fSVladimir Kondratiev return; 3812be7d22fSVladimir Kondratiev } 3822be7d22fSVladimir Kondratiev if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len + 3832be7d22fSVladimir Kondratiev evt->assoc_resp_len) { 3842be7d22fSVladimir Kondratiev wil_err(wil, 3852be7d22fSVladimir Kondratiev "Connect event corrupted : %d != %d + %d + %d + %d\n", 3862be7d22fSVladimir Kondratiev len, (int)sizeof(*evt), evt->beacon_ie_len, 3872be7d22fSVladimir Kondratiev evt->assoc_req_len, evt->assoc_resp_len); 3882be7d22fSVladimir Kondratiev return; 3892be7d22fSVladimir Kondratiev } 3902be7d22fSVladimir Kondratiev ch = evt->channel + 1; 3912be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Connect %pM channel [%d] cid %d\n", 3922be7d22fSVladimir Kondratiev evt->bssid, ch, evt->cid); 3932be7d22fSVladimir Kondratiev wil_hex_dump_WMI("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1, 3942be7d22fSVladimir Kondratiev evt->assoc_info, len - sizeof(*evt), true); 3952be7d22fSVladimir Kondratiev 3962be7d22fSVladimir Kondratiev /* figure out IE's */ 3972be7d22fSVladimir Kondratiev assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len + 3982be7d22fSVladimir Kondratiev assoc_req_ie_offset]; 3992be7d22fSVladimir Kondratiev assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset; 4002be7d22fSVladimir Kondratiev if (evt->assoc_req_len <= assoc_req_ie_offset) { 4012be7d22fSVladimir Kondratiev assoc_req_ie = NULL; 4022be7d22fSVladimir Kondratiev assoc_req_ielen = 0; 4032be7d22fSVladimir Kondratiev } 4042be7d22fSVladimir Kondratiev 4052be7d22fSVladimir Kondratiev assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len + 4062be7d22fSVladimir Kondratiev evt->assoc_req_len + 4072be7d22fSVladimir Kondratiev assoc_resp_ie_offset]; 4082be7d22fSVladimir Kondratiev assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset; 4092be7d22fSVladimir Kondratiev if (evt->assoc_resp_len <= assoc_resp_ie_offset) { 4102be7d22fSVladimir Kondratiev assoc_resp_ie = NULL; 4112be7d22fSVladimir Kondratiev assoc_resp_ielen = 0; 4122be7d22fSVladimir Kondratiev } 4132be7d22fSVladimir Kondratiev 4142be7d22fSVladimir Kondratiev if ((wdev->iftype == NL80211_IFTYPE_STATION) || 4152be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { 4162be7d22fSVladimir Kondratiev if (wdev->sme_state != CFG80211_SME_CONNECTING) { 4172be7d22fSVladimir Kondratiev wil_err(wil, "Not in connecting state\n"); 4182be7d22fSVladimir Kondratiev return; 4192be7d22fSVladimir Kondratiev } 4202be7d22fSVladimir Kondratiev del_timer_sync(&wil->connect_timer); 4212be7d22fSVladimir Kondratiev cfg80211_connect_result(ndev, evt->bssid, 4222be7d22fSVladimir Kondratiev assoc_req_ie, assoc_req_ielen, 4232be7d22fSVladimir Kondratiev assoc_resp_ie, assoc_resp_ielen, 4242be7d22fSVladimir Kondratiev WLAN_STATUS_SUCCESS, GFP_KERNEL); 4252be7d22fSVladimir Kondratiev 4262be7d22fSVladimir Kondratiev } else if ((wdev->iftype == NL80211_IFTYPE_AP) || 4272be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { 4282be7d22fSVladimir Kondratiev memset(&sinfo, 0, sizeof(sinfo)); 4292be7d22fSVladimir Kondratiev 4302be7d22fSVladimir Kondratiev sinfo.generation = wil->sinfo_gen++; 4312be7d22fSVladimir Kondratiev 4322be7d22fSVladimir Kondratiev if (assoc_req_ie) { 4332be7d22fSVladimir Kondratiev sinfo.assoc_req_ies = assoc_req_ie; 4342be7d22fSVladimir Kondratiev sinfo.assoc_req_ies_len = assoc_req_ielen; 4352be7d22fSVladimir Kondratiev sinfo.filled |= STATION_INFO_ASSOC_REQ_IES; 4362be7d22fSVladimir Kondratiev } 4372be7d22fSVladimir Kondratiev 4382be7d22fSVladimir Kondratiev cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL); 4392be7d22fSVladimir Kondratiev } 4402be7d22fSVladimir Kondratiev set_bit(wil_status_fwconnected, &wil->status); 4412be7d22fSVladimir Kondratiev 4422be7d22fSVladimir Kondratiev /* FIXME FW can transmit only ucast frames to peer */ 4432be7d22fSVladimir Kondratiev /* FIXME real ring_id instead of hard coded 0 */ 4442be7d22fSVladimir Kondratiev memcpy(wil->dst_addr[0], evt->bssid, ETH_ALEN); 4452be7d22fSVladimir Kondratiev 4462be7d22fSVladimir Kondratiev wil->pending_connect_cid = evt->cid; 4472be7d22fSVladimir Kondratiev queue_work(wil->wmi_wq_conn, &wil->wmi_connect_worker); 4482be7d22fSVladimir Kondratiev } 4492be7d22fSVladimir Kondratiev 4502be7d22fSVladimir Kondratiev static void wmi_evt_disconnect(struct wil6210_priv *wil, int id, 4512be7d22fSVladimir Kondratiev void *d, int len) 4522be7d22fSVladimir Kondratiev { 4532be7d22fSVladimir Kondratiev struct wmi_disconnect_event *evt = d; 4542be7d22fSVladimir Kondratiev 4552be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Disconnect %pM reason %d proto %d wmi\n", 4562be7d22fSVladimir Kondratiev evt->bssid, 4572be7d22fSVladimir Kondratiev evt->protocol_reason_status, evt->disconnect_reason); 4582be7d22fSVladimir Kondratiev 4592be7d22fSVladimir Kondratiev wil->sinfo_gen++; 4602be7d22fSVladimir Kondratiev 4612be7d22fSVladimir Kondratiev wil6210_disconnect(wil, evt->bssid); 4622be7d22fSVladimir Kondratiev clear_bit(wil_status_dontscan, &wil->status); 4632be7d22fSVladimir Kondratiev } 4642be7d22fSVladimir Kondratiev 4652be7d22fSVladimir Kondratiev static void wmi_evt_notify(struct wil6210_priv *wil, int id, void *d, int len) 4662be7d22fSVladimir Kondratiev { 4672be7d22fSVladimir Kondratiev struct wmi_notify_req_done_event *evt = d; 4682be7d22fSVladimir Kondratiev 4692be7d22fSVladimir Kondratiev if (len < sizeof(*evt)) { 4702be7d22fSVladimir Kondratiev wil_err(wil, "Short NOTIFY event\n"); 4712be7d22fSVladimir Kondratiev return; 4722be7d22fSVladimir Kondratiev } 4732be7d22fSVladimir Kondratiev 4742be7d22fSVladimir Kondratiev wil->stats.tsf = le64_to_cpu(evt->tsf); 4752be7d22fSVladimir Kondratiev wil->stats.snr = le32_to_cpu(evt->snr_val); 4762be7d22fSVladimir Kondratiev wil->stats.bf_mcs = le16_to_cpu(evt->bf_mcs); 4772be7d22fSVladimir Kondratiev wil->stats.my_rx_sector = le16_to_cpu(evt->my_rx_sector); 4782be7d22fSVladimir Kondratiev wil->stats.my_tx_sector = le16_to_cpu(evt->my_tx_sector); 4792be7d22fSVladimir Kondratiev wil->stats.peer_rx_sector = le16_to_cpu(evt->other_rx_sector); 4802be7d22fSVladimir Kondratiev wil->stats.peer_tx_sector = le16_to_cpu(evt->other_tx_sector); 4812be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Link status, MCS %d TSF 0x%016llx\n" 4822be7d22fSVladimir Kondratiev "BF status 0x%08x SNR 0x%08x\n" 4832be7d22fSVladimir Kondratiev "Tx Tpt %d goodput %d Rx goodput %d\n" 4842be7d22fSVladimir Kondratiev "Sectors(rx:tx) my %d:%d peer %d:%d\n", 4852be7d22fSVladimir Kondratiev wil->stats.bf_mcs, wil->stats.tsf, evt->status, 4862be7d22fSVladimir Kondratiev wil->stats.snr, le32_to_cpu(evt->tx_tpt), 4872be7d22fSVladimir Kondratiev le32_to_cpu(evt->tx_goodput), le32_to_cpu(evt->rx_goodput), 4882be7d22fSVladimir Kondratiev wil->stats.my_rx_sector, wil->stats.my_tx_sector, 4892be7d22fSVladimir Kondratiev wil->stats.peer_rx_sector, wil->stats.peer_tx_sector); 4902be7d22fSVladimir Kondratiev } 4912be7d22fSVladimir Kondratiev 4922be7d22fSVladimir Kondratiev /* 4932be7d22fSVladimir Kondratiev * Firmware reports EAPOL frame using WME event. 4942be7d22fSVladimir Kondratiev * Reconstruct Ethernet frame and deliver it via normal Rx 4952be7d22fSVladimir Kondratiev */ 4962be7d22fSVladimir Kondratiev static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id, 4972be7d22fSVladimir Kondratiev void *d, int len) 4982be7d22fSVladimir Kondratiev { 4992be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 5002be7d22fSVladimir Kondratiev struct wmi_eapol_rx_event *evt = d; 5012be7d22fSVladimir Kondratiev u16 eapol_len = le16_to_cpu(evt->eapol_len); 5022be7d22fSVladimir Kondratiev int sz = eapol_len + ETH_HLEN; 5032be7d22fSVladimir Kondratiev struct sk_buff *skb; 5042be7d22fSVladimir Kondratiev struct ethhdr *eth; 5052be7d22fSVladimir Kondratiev 5062be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "EAPOL len %d from %pM\n", eapol_len, 5072be7d22fSVladimir Kondratiev evt->src_mac); 5082be7d22fSVladimir Kondratiev 5092be7d22fSVladimir Kondratiev if (eapol_len > 196) { /* TODO: revisit size limit */ 5102be7d22fSVladimir Kondratiev wil_err(wil, "EAPOL too large\n"); 5112be7d22fSVladimir Kondratiev return; 5122be7d22fSVladimir Kondratiev } 5132be7d22fSVladimir Kondratiev 5142be7d22fSVladimir Kondratiev skb = alloc_skb(sz, GFP_KERNEL); 5152be7d22fSVladimir Kondratiev if (!skb) { 5162be7d22fSVladimir Kondratiev wil_err(wil, "Failed to allocate skb\n"); 5172be7d22fSVladimir Kondratiev return; 5182be7d22fSVladimir Kondratiev } 5192be7d22fSVladimir Kondratiev eth = (struct ethhdr *)skb_put(skb, ETH_HLEN); 5202be7d22fSVladimir Kondratiev memcpy(eth->h_dest, ndev->dev_addr, ETH_ALEN); 5212be7d22fSVladimir Kondratiev memcpy(eth->h_source, evt->src_mac, ETH_ALEN); 5222be7d22fSVladimir Kondratiev eth->h_proto = cpu_to_be16(ETH_P_PAE); 5232be7d22fSVladimir Kondratiev memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len); 5242be7d22fSVladimir Kondratiev skb->protocol = eth_type_trans(skb, ndev); 5252be7d22fSVladimir Kondratiev if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) { 5262be7d22fSVladimir Kondratiev ndev->stats.rx_packets++; 5272be7d22fSVladimir Kondratiev ndev->stats.rx_bytes += skb->len; 5282be7d22fSVladimir Kondratiev } else { 5292be7d22fSVladimir Kondratiev ndev->stats.rx_dropped++; 5302be7d22fSVladimir Kondratiev } 5312be7d22fSVladimir Kondratiev } 5322be7d22fSVladimir Kondratiev 5332be7d22fSVladimir Kondratiev static const struct { 5342be7d22fSVladimir Kondratiev int eventid; 5352be7d22fSVladimir Kondratiev void (*handler)(struct wil6210_priv *wil, int eventid, 5362be7d22fSVladimir Kondratiev void *data, int data_len); 5372be7d22fSVladimir Kondratiev } wmi_evt_handlers[] = { 5382be7d22fSVladimir Kondratiev {WMI_READY_EVENTID, wmi_evt_ready}, 5392be7d22fSVladimir Kondratiev {WMI_FW_READY_EVENTID, wmi_evt_fw_ready}, 5402be7d22fSVladimir Kondratiev {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt}, 5412be7d22fSVladimir Kondratiev {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete}, 5422be7d22fSVladimir Kondratiev {WMI_CONNECT_EVENTID, wmi_evt_connect}, 5432be7d22fSVladimir Kondratiev {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect}, 5442be7d22fSVladimir Kondratiev {WMI_NOTIFY_REQ_DONE_EVENTID, wmi_evt_notify}, 5452be7d22fSVladimir Kondratiev {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx}, 5462be7d22fSVladimir Kondratiev }; 5472be7d22fSVladimir Kondratiev 5482be7d22fSVladimir Kondratiev /* 5492be7d22fSVladimir Kondratiev * Run in IRQ context 5502be7d22fSVladimir Kondratiev * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev 5512be7d22fSVladimir Kondratiev * that will be eventually handled by the @wmi_event_worker in the thread 5522be7d22fSVladimir Kondratiev * context of thread "wil6210_wmi" 5532be7d22fSVladimir Kondratiev */ 5542be7d22fSVladimir Kondratiev void wmi_recv_cmd(struct wil6210_priv *wil) 5552be7d22fSVladimir Kondratiev { 5562be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_tail; 5572be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 5582be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx; 5592be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 5602be7d22fSVladimir Kondratiev u8 *cmd; 5612be7d22fSVladimir Kondratiev void __iomem *src; 5622be7d22fSVladimir Kondratiev ulong flags; 5632be7d22fSVladimir Kondratiev 5642be7d22fSVladimir Kondratiev for (;;) { 5652be7d22fSVladimir Kondratiev u16 len; 5662be7d22fSVladimir Kondratiev 5672be7d22fSVladimir Kondratiev r->head = ioread32(wil->csr + HOST_MBOX + 5682be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.head)); 5692be7d22fSVladimir Kondratiev if (r->tail == r->head) 5702be7d22fSVladimir Kondratiev return; 5712be7d22fSVladimir Kondratiev 5722be7d22fSVladimir Kondratiev /* read cmd from tail */ 5732be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail), 5742be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)); 5752be7d22fSVladimir Kondratiev if (d_tail.sync == 0) { 5762be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt not owned by FW?\n"); 5772be7d22fSVladimir Kondratiev return; 5782be7d22fSVladimir Kondratiev } 5792be7d22fSVladimir Kondratiev 5802be7d22fSVladimir Kondratiev if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) { 5812be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt at 0x%08x?\n", 5822be7d22fSVladimir Kondratiev le32_to_cpu(d_tail.addr)); 5832be7d22fSVladimir Kondratiev return; 5842be7d22fSVladimir Kondratiev } 5852be7d22fSVladimir Kondratiev 5862be7d22fSVladimir Kondratiev len = le16_to_cpu(hdr.len); 5872be7d22fSVladimir Kondratiev src = wmi_buffer(wil, d_tail.addr) + 5882be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr); 5892be7d22fSVladimir Kondratiev evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event, 5902be7d22fSVladimir Kondratiev event.wmi) + len, 4), 5912be7d22fSVladimir Kondratiev GFP_KERNEL); 5922be7d22fSVladimir Kondratiev if (!evt) { 5932be7d22fSVladimir Kondratiev wil_err(wil, "kmalloc for WMI event (%d) failed\n", 5942be7d22fSVladimir Kondratiev len); 5952be7d22fSVladimir Kondratiev return; 5962be7d22fSVladimir Kondratiev } 5972be7d22fSVladimir Kondratiev evt->event.hdr = hdr; 5982be7d22fSVladimir Kondratiev cmd = (void *)&evt->event.wmi; 5992be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(cmd, src, len); 6002be7d22fSVladimir Kondratiev /* mark entry as empty */ 6012be7d22fSVladimir Kondratiev iowrite32(0, wil->csr + HOSTADDR(r->tail) + 6022be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ring_desc, sync)); 6032be7d22fSVladimir Kondratiev /* indicate */ 6042be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Mbox evt %04x %04x %04x %02x\n", 6052be7d22fSVladimir Kondratiev le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type), 6062be7d22fSVladimir Kondratiev hdr.flags); 6072be7d22fSVladimir Kondratiev if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) && 6082be7d22fSVladimir Kondratiev (len >= sizeof(struct wil6210_mbox_hdr_wmi))) { 6092be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "WMI event 0x%04x\n", 6102be7d22fSVladimir Kondratiev evt->event.wmi.id); 6112be7d22fSVladimir Kondratiev } 6122be7d22fSVladimir Kondratiev wil_hex_dump_WMI("evt ", DUMP_PREFIX_OFFSET, 16, 1, 6132be7d22fSVladimir Kondratiev &evt->event.hdr, sizeof(hdr) + len, true); 6142be7d22fSVladimir Kondratiev 6152be7d22fSVladimir Kondratiev /* advance tail */ 6162be7d22fSVladimir Kondratiev r->tail = r->base + ((r->tail - r->base + 6172be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)) % r->size); 6182be7d22fSVladimir Kondratiev iowrite32(r->tail, wil->csr + HOST_MBOX + 6192be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.tail)); 6202be7d22fSVladimir Kondratiev 6212be7d22fSVladimir Kondratiev /* add to the pending list */ 6222be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 6232be7d22fSVladimir Kondratiev list_add_tail(&evt->list, &wil->pending_wmi_ev); 6242be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 6252be7d22fSVladimir Kondratiev { 6262be7d22fSVladimir Kondratiev int q = queue_work(wil->wmi_wq, 6272be7d22fSVladimir Kondratiev &wil->wmi_event_worker); 6282be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "queue_work -> %d\n", q); 6292be7d22fSVladimir Kondratiev } 6302be7d22fSVladimir Kondratiev } 6312be7d22fSVladimir Kondratiev } 6322be7d22fSVladimir Kondratiev 6332be7d22fSVladimir Kondratiev int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len, 6342be7d22fSVladimir Kondratiev u16 reply_id, void *reply, u8 reply_size, int to_msec) 6352be7d22fSVladimir Kondratiev { 6362be7d22fSVladimir Kondratiev int rc; 6372be7d22fSVladimir Kondratiev int remain; 6382be7d22fSVladimir Kondratiev 6392be7d22fSVladimir Kondratiev mutex_lock(&wil->wmi_mutex); 6402be7d22fSVladimir Kondratiev 6412be7d22fSVladimir Kondratiev rc = __wmi_send(wil, cmdid, buf, len); 6422be7d22fSVladimir Kondratiev if (rc) 6432be7d22fSVladimir Kondratiev goto out; 6442be7d22fSVladimir Kondratiev 6452be7d22fSVladimir Kondratiev wil->reply_id = reply_id; 6462be7d22fSVladimir Kondratiev wil->reply_buf = reply; 6472be7d22fSVladimir Kondratiev wil->reply_size = reply_size; 6482be7d22fSVladimir Kondratiev remain = wait_for_completion_timeout(&wil->wmi_ready, 6492be7d22fSVladimir Kondratiev msecs_to_jiffies(to_msec)); 6502be7d22fSVladimir Kondratiev if (0 == remain) { 6512be7d22fSVladimir Kondratiev wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n", 6522be7d22fSVladimir Kondratiev cmdid, reply_id, to_msec); 6532be7d22fSVladimir Kondratiev rc = -ETIME; 6542be7d22fSVladimir Kondratiev } else { 6552be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, 6562be7d22fSVladimir Kondratiev "wmi_call(0x%04x->0x%04x) completed in %d msec\n", 6572be7d22fSVladimir Kondratiev cmdid, reply_id, 6582be7d22fSVladimir Kondratiev to_msec - jiffies_to_msecs(remain)); 6592be7d22fSVladimir Kondratiev } 6602be7d22fSVladimir Kondratiev wil->reply_id = 0; 6612be7d22fSVladimir Kondratiev wil->reply_buf = NULL; 6622be7d22fSVladimir Kondratiev wil->reply_size = 0; 6632be7d22fSVladimir Kondratiev out: 6642be7d22fSVladimir Kondratiev mutex_unlock(&wil->wmi_mutex); 6652be7d22fSVladimir Kondratiev 6662be7d22fSVladimir Kondratiev return rc; 6672be7d22fSVladimir Kondratiev } 6682be7d22fSVladimir Kondratiev 6692be7d22fSVladimir Kondratiev int wmi_echo(struct wil6210_priv *wil) 6702be7d22fSVladimir Kondratiev { 6712be7d22fSVladimir Kondratiev struct wmi_echo_cmd cmd = { 6722be7d22fSVladimir Kondratiev .value = cpu_to_le32(0x12345678), 6732be7d22fSVladimir Kondratiev }; 6742be7d22fSVladimir Kondratiev 6752be7d22fSVladimir Kondratiev return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd), 6762be7d22fSVladimir Kondratiev WMI_ECHO_RSP_EVENTID, NULL, 0, 20); 6772be7d22fSVladimir Kondratiev } 6782be7d22fSVladimir Kondratiev 6792be7d22fSVladimir Kondratiev int wmi_set_mac_address(struct wil6210_priv *wil, void *addr) 6802be7d22fSVladimir Kondratiev { 6812be7d22fSVladimir Kondratiev struct wmi_set_mac_address_cmd cmd; 6822be7d22fSVladimir Kondratiev 6832be7d22fSVladimir Kondratiev memcpy(cmd.mac, addr, ETH_ALEN); 6842be7d22fSVladimir Kondratiev 6852be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Set MAC %pM\n", addr); 6862be7d22fSVladimir Kondratiev 6872be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd)); 6882be7d22fSVladimir Kondratiev } 6892be7d22fSVladimir Kondratiev 6902be7d22fSVladimir Kondratiev int wmi_set_bcon(struct wil6210_priv *wil, int bi, u8 wmi_nettype) 6912be7d22fSVladimir Kondratiev { 6922be7d22fSVladimir Kondratiev struct wmi_bcon_ctrl_cmd cmd = { 6932be7d22fSVladimir Kondratiev .bcon_interval = cpu_to_le16(bi), 6942be7d22fSVladimir Kondratiev .network_type = wmi_nettype, 6952be7d22fSVladimir Kondratiev .disable_sec_offload = 1, 6962be7d22fSVladimir Kondratiev }; 6972be7d22fSVladimir Kondratiev 6982be7d22fSVladimir Kondratiev if (!wil->secure_pcp) 6992be7d22fSVladimir Kondratiev cmd.disable_sec = 1; 7002be7d22fSVladimir Kondratiev 7012be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_BCON_CTRL_CMDID, &cmd, sizeof(cmd)); 7022be7d22fSVladimir Kondratiev } 7032be7d22fSVladimir Kondratiev 7042be7d22fSVladimir Kondratiev int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid) 7052be7d22fSVladimir Kondratiev { 7062be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd = { 7072be7d22fSVladimir Kondratiev .ssid_len = cpu_to_le32(ssid_len), 7082be7d22fSVladimir Kondratiev }; 7092be7d22fSVladimir Kondratiev 7102be7d22fSVladimir Kondratiev if (ssid_len > sizeof(cmd.ssid)) 7112be7d22fSVladimir Kondratiev return -EINVAL; 7122be7d22fSVladimir Kondratiev 7132be7d22fSVladimir Kondratiev memcpy(cmd.ssid, ssid, ssid_len); 7142be7d22fSVladimir Kondratiev 7152be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd)); 7162be7d22fSVladimir Kondratiev } 7172be7d22fSVladimir Kondratiev 7182be7d22fSVladimir Kondratiev int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid) 7192be7d22fSVladimir Kondratiev { 7202be7d22fSVladimir Kondratiev int rc; 7212be7d22fSVladimir Kondratiev struct { 7222be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 7232be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd; 7242be7d22fSVladimir Kondratiev } __packed reply; 7252be7d22fSVladimir Kondratiev int len; /* reply.cmd.ssid_len in CPU order */ 7262be7d22fSVladimir Kondratiev 7272be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID, 7282be7d22fSVladimir Kondratiev &reply, sizeof(reply), 20); 7292be7d22fSVladimir Kondratiev if (rc) 7302be7d22fSVladimir Kondratiev return rc; 7312be7d22fSVladimir Kondratiev 7322be7d22fSVladimir Kondratiev len = le32_to_cpu(reply.cmd.ssid_len); 7332be7d22fSVladimir Kondratiev if (len > sizeof(reply.cmd.ssid)) 7342be7d22fSVladimir Kondratiev return -EINVAL; 7352be7d22fSVladimir Kondratiev 7362be7d22fSVladimir Kondratiev *ssid_len = len; 7372be7d22fSVladimir Kondratiev memcpy(ssid, reply.cmd.ssid, len); 7382be7d22fSVladimir Kondratiev 7392be7d22fSVladimir Kondratiev return 0; 7402be7d22fSVladimir Kondratiev } 7412be7d22fSVladimir Kondratiev 7422be7d22fSVladimir Kondratiev int wmi_set_channel(struct wil6210_priv *wil, int channel) 7432be7d22fSVladimir Kondratiev { 7442be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd = { 7452be7d22fSVladimir Kondratiev .channel = channel - 1, 7462be7d22fSVladimir Kondratiev }; 7472be7d22fSVladimir Kondratiev 7482be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd)); 7492be7d22fSVladimir Kondratiev } 7502be7d22fSVladimir Kondratiev 7512be7d22fSVladimir Kondratiev int wmi_get_channel(struct wil6210_priv *wil, int *channel) 7522be7d22fSVladimir Kondratiev { 7532be7d22fSVladimir Kondratiev int rc; 7542be7d22fSVladimir Kondratiev struct { 7552be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 7562be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd; 7572be7d22fSVladimir Kondratiev } __packed reply; 7582be7d22fSVladimir Kondratiev 7592be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0, 7602be7d22fSVladimir Kondratiev WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20); 7612be7d22fSVladimir Kondratiev if (rc) 7622be7d22fSVladimir Kondratiev return rc; 7632be7d22fSVladimir Kondratiev 7642be7d22fSVladimir Kondratiev if (reply.cmd.channel > 3) 7652be7d22fSVladimir Kondratiev return -EINVAL; 7662be7d22fSVladimir Kondratiev 7672be7d22fSVladimir Kondratiev *channel = reply.cmd.channel + 1; 7682be7d22fSVladimir Kondratiev 7692be7d22fSVladimir Kondratiev return 0; 7702be7d22fSVladimir Kondratiev } 7712be7d22fSVladimir Kondratiev 7722be7d22fSVladimir Kondratiev int wmi_tx_eapol(struct wil6210_priv *wil, struct sk_buff *skb) 7732be7d22fSVladimir Kondratiev { 7742be7d22fSVladimir Kondratiev struct wmi_eapol_tx_cmd *cmd; 7752be7d22fSVladimir Kondratiev struct ethhdr *eth; 7762be7d22fSVladimir Kondratiev u16 eapol_len = skb->len - ETH_HLEN; 7772be7d22fSVladimir Kondratiev void *eapol = skb->data + ETH_HLEN; 7782be7d22fSVladimir Kondratiev uint i; 7792be7d22fSVladimir Kondratiev int rc; 7802be7d22fSVladimir Kondratiev 7812be7d22fSVladimir Kondratiev skb_set_mac_header(skb, 0); 7822be7d22fSVladimir Kondratiev eth = eth_hdr(skb); 7832be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "EAPOL %d bytes to %pM\n", eapol_len, eth->h_dest); 7842be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { 7852be7d22fSVladimir Kondratiev if (memcmp(wil->dst_addr[i], eth->h_dest, ETH_ALEN) == 0) 7862be7d22fSVladimir Kondratiev goto found_dest; 7872be7d22fSVladimir Kondratiev } 7882be7d22fSVladimir Kondratiev 7892be7d22fSVladimir Kondratiev return -EINVAL; 7902be7d22fSVladimir Kondratiev 7912be7d22fSVladimir Kondratiev found_dest: 7922be7d22fSVladimir Kondratiev /* find out eapol data & len */ 7932be7d22fSVladimir Kondratiev cmd = kzalloc(sizeof(*cmd) + eapol_len, GFP_KERNEL); 7942be7d22fSVladimir Kondratiev if (!cmd) 7952be7d22fSVladimir Kondratiev return -EINVAL; 7962be7d22fSVladimir Kondratiev 7972be7d22fSVladimir Kondratiev memcpy(cmd->dst_mac, eth->h_dest, ETH_ALEN); 7982be7d22fSVladimir Kondratiev cmd->eapol_len = cpu_to_le16(eapol_len); 7992be7d22fSVladimir Kondratiev memcpy(cmd->eapol, eapol, eapol_len); 8002be7d22fSVladimir Kondratiev rc = wmi_send(wil, WMI_EAPOL_TX_CMDID, cmd, sizeof(*cmd) + eapol_len); 8012be7d22fSVladimir Kondratiev kfree(cmd); 8022be7d22fSVladimir Kondratiev 8032be7d22fSVladimir Kondratiev return rc; 8042be7d22fSVladimir Kondratiev } 8052be7d22fSVladimir Kondratiev 8062be7d22fSVladimir Kondratiev int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index, 8072be7d22fSVladimir Kondratiev const void *mac_addr) 8082be7d22fSVladimir Kondratiev { 8092be7d22fSVladimir Kondratiev struct wmi_delete_cipher_key_cmd cmd = { 8102be7d22fSVladimir Kondratiev .key_index = key_index, 8112be7d22fSVladimir Kondratiev }; 8122be7d22fSVladimir Kondratiev 8132be7d22fSVladimir Kondratiev if (mac_addr) 8142be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 8152be7d22fSVladimir Kondratiev 8162be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 8172be7d22fSVladimir Kondratiev } 8182be7d22fSVladimir Kondratiev 8192be7d22fSVladimir Kondratiev int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index, 8202be7d22fSVladimir Kondratiev const void *mac_addr, int key_len, const void *key) 8212be7d22fSVladimir Kondratiev { 8222be7d22fSVladimir Kondratiev struct wmi_add_cipher_key_cmd cmd = { 8232be7d22fSVladimir Kondratiev .key_index = key_index, 8242be7d22fSVladimir Kondratiev .key_usage = WMI_KEY_USE_PAIRWISE, 8252be7d22fSVladimir Kondratiev .key_len = key_len, 8262be7d22fSVladimir Kondratiev }; 8272be7d22fSVladimir Kondratiev 8282be7d22fSVladimir Kondratiev if (!key || (key_len > sizeof(cmd.key))) 8292be7d22fSVladimir Kondratiev return -EINVAL; 8302be7d22fSVladimir Kondratiev 8312be7d22fSVladimir Kondratiev memcpy(cmd.key, key, key_len); 8322be7d22fSVladimir Kondratiev if (mac_addr) 8332be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 8342be7d22fSVladimir Kondratiev 8352be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 8362be7d22fSVladimir Kondratiev } 8372be7d22fSVladimir Kondratiev 8382be7d22fSVladimir Kondratiev int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie) 8392be7d22fSVladimir Kondratiev { 8402be7d22fSVladimir Kondratiev int rc; 8412be7d22fSVladimir Kondratiev u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len; 8422be7d22fSVladimir Kondratiev struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL); 8432be7d22fSVladimir Kondratiev if (!cmd) { 8442be7d22fSVladimir Kondratiev wil_err(wil, "kmalloc(%d) failed\n", len); 8452be7d22fSVladimir Kondratiev return -ENOMEM; 8462be7d22fSVladimir Kondratiev } 8472be7d22fSVladimir Kondratiev 8482be7d22fSVladimir Kondratiev cmd->mgmt_frm_type = type; 8492be7d22fSVladimir Kondratiev /* BUG: FW API define ieLen as u8. Will fix FW */ 8502be7d22fSVladimir Kondratiev cmd->ie_len = cpu_to_le16(ie_len); 8512be7d22fSVladimir Kondratiev memcpy(cmd->ie_info, ie, ie_len); 8522be7d22fSVladimir Kondratiev rc = wmi_send(wil, WMI_SET_APPIE_CMDID, &cmd, len); 8532be7d22fSVladimir Kondratiev kfree(cmd); 8542be7d22fSVladimir Kondratiev 8552be7d22fSVladimir Kondratiev return rc; 8562be7d22fSVladimir Kondratiev } 8572be7d22fSVladimir Kondratiev 85847e19af9SVladimir Kondratiev int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring) 85947e19af9SVladimir Kondratiev { 86047e19af9SVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 86147e19af9SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 86247e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_cmd cmd = { 86347e19af9SVladimir Kondratiev .action = WMI_RX_CHAIN_ADD, 86447e19af9SVladimir Kondratiev .rx_sw_ring = { 86547e19af9SVladimir Kondratiev .max_mpdu_size = cpu_to_le16(RX_BUF_LEN), 86647e19af9SVladimir Kondratiev .ring_mem_base = cpu_to_le64(vring->pa), 86747e19af9SVladimir Kondratiev .ring_size = cpu_to_le16(vring->size), 86847e19af9SVladimir Kondratiev }, 86947e19af9SVladimir Kondratiev .mid = 0, /* TODO - what is it? */ 87047e19af9SVladimir Kondratiev .decap_trans_type = WMI_DECAP_TYPE_802_3, 87147e19af9SVladimir Kondratiev }; 87247e19af9SVladimir Kondratiev struct { 87347e19af9SVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 87447e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_done_event evt; 87547e19af9SVladimir Kondratiev } __packed evt; 87647e19af9SVladimir Kondratiev int rc; 87747e19af9SVladimir Kondratiev 87847e19af9SVladimir Kondratiev if (wdev->iftype == NL80211_IFTYPE_MONITOR) { 87947e19af9SVladimir Kondratiev struct ieee80211_channel *ch = wdev->preset_chandef.chan; 88047e19af9SVladimir Kondratiev 88147e19af9SVladimir Kondratiev cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON); 88247e19af9SVladimir Kondratiev if (ch) 88347e19af9SVladimir Kondratiev cmd.sniffer_cfg.channel = ch->hw_value - 1; 88447e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_info_mode = 88547e19af9SVladimir Kondratiev cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP); 88647e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_support = 88747e19af9SVladimir Kondratiev cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL) 88847e19af9SVladimir Kondratiev ? WMI_SNIFFER_CP : WMI_SNIFFER_DP); 88947e19af9SVladimir Kondratiev } 89047e19af9SVladimir Kondratiev /* typical time for secure PCP is 840ms */ 89147e19af9SVladimir Kondratiev rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd), 89247e19af9SVladimir Kondratiev WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000); 89347e19af9SVladimir Kondratiev if (rc) 89447e19af9SVladimir Kondratiev return rc; 89547e19af9SVladimir Kondratiev 89647e19af9SVladimir Kondratiev vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr); 89747e19af9SVladimir Kondratiev 89847e19af9SVladimir Kondratiev wil_dbg_MISC(wil, "Rx init: status %d tail 0x%08x\n", 89947e19af9SVladimir Kondratiev le32_to_cpu(evt.evt.status), vring->hwtail); 90047e19af9SVladimir Kondratiev 90147e19af9SVladimir Kondratiev if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS) 90247e19af9SVladimir Kondratiev rc = -EINVAL; 90347e19af9SVladimir Kondratiev 90447e19af9SVladimir Kondratiev return rc; 90547e19af9SVladimir Kondratiev } 90647e19af9SVladimir Kondratiev 90747e19af9SVladimir Kondratiev int wmi_rx_chain_del(struct wil6210_priv *wil) 90847e19af9SVladimir Kondratiev { 90947e19af9SVladimir Kondratiev int rc; 91047e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_cmd cmd = { 91147e19af9SVladimir Kondratiev .action = cpu_to_le32(WMI_RX_CHAIN_DEL), 91247e19af9SVladimir Kondratiev .rx_sw_ring = { 91347e19af9SVladimir Kondratiev .max_mpdu_size = cpu_to_le16(RX_BUF_LEN), 91447e19af9SVladimir Kondratiev }, 91547e19af9SVladimir Kondratiev }; 91647e19af9SVladimir Kondratiev struct { 91747e19af9SVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 91847e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_done_event cfg; 91947e19af9SVladimir Kondratiev } __packed wmi_rx_cfg_reply; 92047e19af9SVladimir Kondratiev 92147e19af9SVladimir Kondratiev rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd), 92247e19af9SVladimir Kondratiev WMI_CFG_RX_CHAIN_DONE_EVENTID, 92347e19af9SVladimir Kondratiev &wmi_rx_cfg_reply, sizeof(wmi_rx_cfg_reply), 92447e19af9SVladimir Kondratiev 100); 92547e19af9SVladimir Kondratiev 92647e19af9SVladimir Kondratiev return rc; 92747e19af9SVladimir Kondratiev } 92847e19af9SVladimir Kondratiev 9292be7d22fSVladimir Kondratiev void wmi_event_flush(struct wil6210_priv *wil) 9302be7d22fSVladimir Kondratiev { 9312be7d22fSVladimir Kondratiev struct pending_wmi_event *evt, *t; 9322be7d22fSVladimir Kondratiev 9332be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "%s()\n", __func__); 9342be7d22fSVladimir Kondratiev 9352be7d22fSVladimir Kondratiev list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) { 9362be7d22fSVladimir Kondratiev list_del(&evt->list); 9372be7d22fSVladimir Kondratiev kfree(evt); 9382be7d22fSVladimir Kondratiev } 9392be7d22fSVladimir Kondratiev } 9402be7d22fSVladimir Kondratiev 9412be7d22fSVladimir Kondratiev static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id, 9422be7d22fSVladimir Kondratiev void *d, int len) 9432be7d22fSVladimir Kondratiev { 9442be7d22fSVladimir Kondratiev uint i; 9452be7d22fSVladimir Kondratiev 9462be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) { 9472be7d22fSVladimir Kondratiev if (wmi_evt_handlers[i].eventid == id) { 9482be7d22fSVladimir Kondratiev wmi_evt_handlers[i].handler(wil, id, d, len); 9492be7d22fSVladimir Kondratiev return true; 9502be7d22fSVladimir Kondratiev } 9512be7d22fSVladimir Kondratiev } 9522be7d22fSVladimir Kondratiev 9532be7d22fSVladimir Kondratiev return false; 9542be7d22fSVladimir Kondratiev } 9552be7d22fSVladimir Kondratiev 9562be7d22fSVladimir Kondratiev static void wmi_event_handle(struct wil6210_priv *wil, 9572be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 9582be7d22fSVladimir Kondratiev { 9592be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr->len); 9602be7d22fSVladimir Kondratiev 9612be7d22fSVladimir Kondratiev if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) && 9622be7d22fSVladimir Kondratiev (len >= sizeof(struct wil6210_mbox_hdr_wmi))) { 9632be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi *wmi = (void *)(&hdr[1]); 9642be7d22fSVladimir Kondratiev void *evt_data = (void *)(&wmi[1]); 9652be7d22fSVladimir Kondratiev u16 id = le16_to_cpu(wmi->id); 9662be7d22fSVladimir Kondratiev /* check if someone waits for this event */ 9672be7d22fSVladimir Kondratiev if (wil->reply_id && wil->reply_id == id) { 9682be7d22fSVladimir Kondratiev if (wil->reply_buf) { 9692be7d22fSVladimir Kondratiev memcpy(wil->reply_buf, wmi, 9702be7d22fSVladimir Kondratiev min(len, wil->reply_size)); 9712be7d22fSVladimir Kondratiev } else { 9722be7d22fSVladimir Kondratiev wmi_evt_call_handler(wil, id, evt_data, 9732be7d22fSVladimir Kondratiev len - sizeof(*wmi)); 9742be7d22fSVladimir Kondratiev } 9752be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Complete WMI 0x%04x\n", id); 9762be7d22fSVladimir Kondratiev complete(&wil->wmi_ready); 9772be7d22fSVladimir Kondratiev return; 9782be7d22fSVladimir Kondratiev } 9792be7d22fSVladimir Kondratiev /* unsolicited event */ 9802be7d22fSVladimir Kondratiev /* search for handler */ 9812be7d22fSVladimir Kondratiev if (!wmi_evt_call_handler(wil, id, evt_data, 9822be7d22fSVladimir Kondratiev len - sizeof(*wmi))) { 9832be7d22fSVladimir Kondratiev wil_err(wil, "Unhandled event 0x%04x\n", id); 9842be7d22fSVladimir Kondratiev } 9852be7d22fSVladimir Kondratiev } else { 9862be7d22fSVladimir Kondratiev wil_err(wil, "Unknown event type\n"); 9872be7d22fSVladimir Kondratiev print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1, 9882be7d22fSVladimir Kondratiev hdr, sizeof(*hdr) + len, true); 9892be7d22fSVladimir Kondratiev } 9902be7d22fSVladimir Kondratiev } 9912be7d22fSVladimir Kondratiev 9922be7d22fSVladimir Kondratiev /* 9932be7d22fSVladimir Kondratiev * Retrieve next WMI event from the pending list 9942be7d22fSVladimir Kondratiev */ 9952be7d22fSVladimir Kondratiev static struct list_head *next_wmi_ev(struct wil6210_priv *wil) 9962be7d22fSVladimir Kondratiev { 9972be7d22fSVladimir Kondratiev ulong flags; 9982be7d22fSVladimir Kondratiev struct list_head *ret = NULL; 9992be7d22fSVladimir Kondratiev 10002be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 10012be7d22fSVladimir Kondratiev 10022be7d22fSVladimir Kondratiev if (!list_empty(&wil->pending_wmi_ev)) { 10032be7d22fSVladimir Kondratiev ret = wil->pending_wmi_ev.next; 10042be7d22fSVladimir Kondratiev list_del(ret); 10052be7d22fSVladimir Kondratiev } 10062be7d22fSVladimir Kondratiev 10072be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 10082be7d22fSVladimir Kondratiev 10092be7d22fSVladimir Kondratiev return ret; 10102be7d22fSVladimir Kondratiev } 10112be7d22fSVladimir Kondratiev 10122be7d22fSVladimir Kondratiev /* 10132be7d22fSVladimir Kondratiev * Handler for the WMI events 10142be7d22fSVladimir Kondratiev */ 10152be7d22fSVladimir Kondratiev void wmi_event_worker(struct work_struct *work) 10162be7d22fSVladimir Kondratiev { 10172be7d22fSVladimir Kondratiev struct wil6210_priv *wil = container_of(work, struct wil6210_priv, 10182be7d22fSVladimir Kondratiev wmi_event_worker); 10192be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 10202be7d22fSVladimir Kondratiev struct list_head *lh; 10212be7d22fSVladimir Kondratiev 10222be7d22fSVladimir Kondratiev while ((lh = next_wmi_ev(wil)) != NULL) { 10232be7d22fSVladimir Kondratiev evt = list_entry(lh, struct pending_wmi_event, list); 10242be7d22fSVladimir Kondratiev wmi_event_handle(wil, &evt->event.hdr); 10252be7d22fSVladimir Kondratiev kfree(evt); 10262be7d22fSVladimir Kondratiev } 10272be7d22fSVladimir Kondratiev } 10282be7d22fSVladimir Kondratiev 10292be7d22fSVladimir Kondratiev void wmi_connect_worker(struct work_struct *work) 10302be7d22fSVladimir Kondratiev { 10312be7d22fSVladimir Kondratiev int rc; 10322be7d22fSVladimir Kondratiev struct wil6210_priv *wil = container_of(work, struct wil6210_priv, 10332be7d22fSVladimir Kondratiev wmi_connect_worker); 10342be7d22fSVladimir Kondratiev 10352be7d22fSVladimir Kondratiev if (wil->pending_connect_cid < 0) { 10362be7d22fSVladimir Kondratiev wil_err(wil, "No connection pending\n"); 10372be7d22fSVladimir Kondratiev return; 10382be7d22fSVladimir Kondratiev } 10392be7d22fSVladimir Kondratiev 10402be7d22fSVladimir Kondratiev wil_dbg_WMI(wil, "Configure for connection CID %d\n", 10412be7d22fSVladimir Kondratiev wil->pending_connect_cid); 10422be7d22fSVladimir Kondratiev 10432be7d22fSVladimir Kondratiev rc = wil_vring_init_tx(wil, 0, WIL6210_TX_RING_SIZE, 10442be7d22fSVladimir Kondratiev wil->pending_connect_cid, 0); 10452be7d22fSVladimir Kondratiev wil->pending_connect_cid = -1; 10462be7d22fSVladimir Kondratiev if (rc == 0) 10472be7d22fSVladimir Kondratiev wil_link_on(wil); 10482be7d22fSVladimir Kondratiev } 1049