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/etherdevice.h> 1847e19af9SVladimir Kondratiev #include <linux/if_arp.h> 192be7d22fSVladimir Kondratiev 202be7d22fSVladimir Kondratiev #include "wil6210.h" 2147e19af9SVladimir Kondratiev #include "txrx.h" 222be7d22fSVladimir Kondratiev #include "wmi.h" 2398658095SVladimir Kondratiev #include "trace.h" 242be7d22fSVladimir Kondratiev 252be7d22fSVladimir Kondratiev /** 262be7d22fSVladimir Kondratiev * WMI event receiving - theory of operations 272be7d22fSVladimir Kondratiev * 282be7d22fSVladimir Kondratiev * When firmware about to report WMI event, it fills memory area 292be7d22fSVladimir Kondratiev * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for 302be7d22fSVladimir Kondratiev * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler. 312be7d22fSVladimir Kondratiev * 322be7d22fSVladimir Kondratiev * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the 332be7d22fSVladimir Kondratiev * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up 342be7d22fSVladimir Kondratiev * and handles events within the @wmi_event_worker. Every event get detached 352be7d22fSVladimir Kondratiev * from list, processed and deleted. 362be7d22fSVladimir Kondratiev * 372be7d22fSVladimir Kondratiev * Purpose for this mechanism is to release IRQ thread; otherwise, 382be7d22fSVladimir Kondratiev * if WMI event handling involves another WMI command flow, this 2-nd flow 392be7d22fSVladimir Kondratiev * won't be completed because of blocked IRQ thread. 402be7d22fSVladimir Kondratiev */ 412be7d22fSVladimir Kondratiev 422be7d22fSVladimir Kondratiev /** 432be7d22fSVladimir Kondratiev * Addressing - theory of operations 442be7d22fSVladimir Kondratiev * 452be7d22fSVladimir Kondratiev * There are several buses present on the WIL6210 card. 462be7d22fSVladimir Kondratiev * Same memory areas are visible at different address on 472be7d22fSVladimir Kondratiev * the different busses. There are 3 main bus masters: 482be7d22fSVladimir Kondratiev * - MAC CPU (ucode) 492be7d22fSVladimir Kondratiev * - User CPU (firmware) 502be7d22fSVladimir Kondratiev * - AHB (host) 512be7d22fSVladimir Kondratiev * 522be7d22fSVladimir Kondratiev * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing 532be7d22fSVladimir Kondratiev * AHB addresses starting from 0x880000 542be7d22fSVladimir Kondratiev * 552be7d22fSVladimir Kondratiev * Internally, firmware uses addresses that allows faster access but 562be7d22fSVladimir Kondratiev * are invisible from the host. To read from these addresses, alternative 572be7d22fSVladimir Kondratiev * AHB address must be used. 582be7d22fSVladimir Kondratiev * 592be7d22fSVladimir Kondratiev * Memory mapping 602be7d22fSVladimir Kondratiev * Linker address PCI/Host address 612be7d22fSVladimir Kondratiev * 0x880000 .. 0xa80000 2Mb BAR0 622be7d22fSVladimir Kondratiev * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM 632be7d22fSVladimir Kondratiev * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH 642be7d22fSVladimir Kondratiev */ 652be7d22fSVladimir Kondratiev 662be7d22fSVladimir Kondratiev /** 672be7d22fSVladimir Kondratiev * @fw_mapping provides memory remapping table 682be7d22fSVladimir Kondratiev */ 692be7d22fSVladimir Kondratiev static const struct { 702be7d22fSVladimir Kondratiev u32 from; /* linker address - from, inclusive */ 712be7d22fSVladimir Kondratiev u32 to; /* linker address - to, exclusive */ 722be7d22fSVladimir Kondratiev u32 host; /* PCI/Host address - BAR0 + 0x880000 */ 732be7d22fSVladimir Kondratiev } fw_mapping[] = { 742be7d22fSVladimir Kondratiev {0x000000, 0x040000, 0x8c0000}, /* FW code RAM 256k */ 752be7d22fSVladimir Kondratiev {0x800000, 0x808000, 0x900000}, /* FW data RAM 32k */ 762be7d22fSVladimir Kondratiev {0x840000, 0x860000, 0x908000}, /* peripheral data RAM 128k/96k used */ 772be7d22fSVladimir Kondratiev {0x880000, 0x88a000, 0x880000}, /* various RGF */ 78af6b48dbSVladimir Kondratiev {0x8c0000, 0x949000, 0x8c0000}, /* trivial mapping for upper area */ 792be7d22fSVladimir Kondratiev /* 802be7d22fSVladimir Kondratiev * 920000..930000 ucode code RAM 812be7d22fSVladimir Kondratiev * 930000..932000 ucode data RAM 82af6b48dbSVladimir Kondratiev * 932000..949000 back-door debug data 832be7d22fSVladimir Kondratiev */ 842be7d22fSVladimir Kondratiev }; 852be7d22fSVladimir Kondratiev 862be7d22fSVladimir Kondratiev /** 872be7d22fSVladimir Kondratiev * return AHB address for given firmware/ucode internal (linker) address 882be7d22fSVladimir Kondratiev * @x - internal address 892be7d22fSVladimir Kondratiev * If address have no valid AHB mapping, return 0 902be7d22fSVladimir Kondratiev */ 912be7d22fSVladimir Kondratiev static u32 wmi_addr_remap(u32 x) 922be7d22fSVladimir Kondratiev { 932be7d22fSVladimir Kondratiev uint i; 942be7d22fSVladimir Kondratiev 952be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { 962be7d22fSVladimir Kondratiev if ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to)) 972be7d22fSVladimir Kondratiev return x + fw_mapping[i].host - fw_mapping[i].from; 982be7d22fSVladimir Kondratiev } 992be7d22fSVladimir Kondratiev 1002be7d22fSVladimir Kondratiev return 0; 1012be7d22fSVladimir Kondratiev } 1022be7d22fSVladimir Kondratiev 1032be7d22fSVladimir Kondratiev /** 1042be7d22fSVladimir Kondratiev * Check address validity for WMI buffer; remap if needed 1052be7d22fSVladimir Kondratiev * @ptr - internal (linker) fw/ucode address 1062be7d22fSVladimir Kondratiev * 1072be7d22fSVladimir Kondratiev * Valid buffer should be DWORD aligned 1082be7d22fSVladimir Kondratiev * 1092be7d22fSVladimir Kondratiev * return address for accessing buffer from the host; 1102be7d22fSVladimir Kondratiev * if buffer is not valid, return NULL. 1112be7d22fSVladimir Kondratiev */ 1122be7d22fSVladimir Kondratiev void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_) 1132be7d22fSVladimir Kondratiev { 1142be7d22fSVladimir Kondratiev u32 off; 1152be7d22fSVladimir Kondratiev u32 ptr = le32_to_cpu(ptr_); 1162be7d22fSVladimir Kondratiev 1172be7d22fSVladimir Kondratiev if (ptr % 4) 1182be7d22fSVladimir Kondratiev return NULL; 1192be7d22fSVladimir Kondratiev 1202be7d22fSVladimir Kondratiev ptr = wmi_addr_remap(ptr); 1212be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1222be7d22fSVladimir Kondratiev return NULL; 1232be7d22fSVladimir Kondratiev 1242be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1252be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1262be7d22fSVladimir Kondratiev return NULL; 1272be7d22fSVladimir Kondratiev 1282be7d22fSVladimir Kondratiev return wil->csr + off; 1292be7d22fSVladimir Kondratiev } 1302be7d22fSVladimir Kondratiev 1312be7d22fSVladimir Kondratiev /** 1322be7d22fSVladimir Kondratiev * Check address validity 1332be7d22fSVladimir Kondratiev */ 1342be7d22fSVladimir Kondratiev void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr) 1352be7d22fSVladimir Kondratiev { 1362be7d22fSVladimir Kondratiev u32 off; 1372be7d22fSVladimir Kondratiev 1382be7d22fSVladimir Kondratiev if (ptr % 4) 1392be7d22fSVladimir Kondratiev return NULL; 1402be7d22fSVladimir Kondratiev 1412be7d22fSVladimir Kondratiev if (ptr < WIL6210_FW_HOST_OFF) 1422be7d22fSVladimir Kondratiev return NULL; 1432be7d22fSVladimir Kondratiev 1442be7d22fSVladimir Kondratiev off = HOSTADDR(ptr); 1452be7d22fSVladimir Kondratiev if (off > WIL6210_MEM_SIZE - 4) 1462be7d22fSVladimir Kondratiev return NULL; 1472be7d22fSVladimir Kondratiev 1482be7d22fSVladimir Kondratiev return wil->csr + off; 1492be7d22fSVladimir Kondratiev } 1502be7d22fSVladimir Kondratiev 1512be7d22fSVladimir Kondratiev int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr, 1522be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 1532be7d22fSVladimir Kondratiev { 1542be7d22fSVladimir Kondratiev void __iomem *src = wmi_buffer(wil, ptr); 1552be7d22fSVladimir Kondratiev if (!src) 1562be7d22fSVladimir Kondratiev return -EINVAL; 1572be7d22fSVladimir Kondratiev 1582be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(hdr, src, sizeof(*hdr)); 1592be7d22fSVladimir Kondratiev 1602be7d22fSVladimir Kondratiev return 0; 1612be7d22fSVladimir Kondratiev } 1622be7d22fSVladimir Kondratiev 1632be7d22fSVladimir Kondratiev static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) 1642be7d22fSVladimir Kondratiev { 1652be7d22fSVladimir Kondratiev struct { 1662be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 1672be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 1682be7d22fSVladimir Kondratiev } __packed cmd = { 1692be7d22fSVladimir Kondratiev .hdr = { 1702be7d22fSVladimir Kondratiev .type = WIL_MBOX_HDR_TYPE_WMI, 1712be7d22fSVladimir Kondratiev .flags = 0, 1722be7d22fSVladimir Kondratiev .len = cpu_to_le16(sizeof(cmd.wmi) + len), 1732be7d22fSVladimir Kondratiev }, 1742be7d22fSVladimir Kondratiev .wmi = { 175f988b23fSVladimir Kondratiev .mid = 0, 1762be7d22fSVladimir Kondratiev .id = cpu_to_le16(cmdid), 1772be7d22fSVladimir Kondratiev }, 1782be7d22fSVladimir Kondratiev }; 1792be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx; 1802be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_head; 1812be7d22fSVladimir Kondratiev u32 next_head; 1822be7d22fSVladimir Kondratiev void __iomem *dst; 1832be7d22fSVladimir Kondratiev void __iomem *head = wmi_addr(wil, r->head); 1842be7d22fSVladimir Kondratiev uint retry; 1852be7d22fSVladimir Kondratiev 1862be7d22fSVladimir Kondratiev if (sizeof(cmd) + len > r->entry_size) { 1872be7d22fSVladimir Kondratiev wil_err(wil, "WMI size too large: %d bytes, max is %d\n", 1882be7d22fSVladimir Kondratiev (int)(sizeof(cmd) + len), r->entry_size); 1892be7d22fSVladimir Kondratiev return -ERANGE; 1902be7d22fSVladimir Kondratiev } 1912be7d22fSVladimir Kondratiev 1922be7d22fSVladimir Kondratiev might_sleep(); 1932be7d22fSVladimir Kondratiev 1942be7d22fSVladimir Kondratiev if (!test_bit(wil_status_fwready, &wil->status)) { 1952be7d22fSVladimir Kondratiev wil_err(wil, "FW not ready\n"); 1962be7d22fSVladimir Kondratiev return -EAGAIN; 1972be7d22fSVladimir Kondratiev } 1982be7d22fSVladimir Kondratiev 1992be7d22fSVladimir Kondratiev if (!head) { 2002be7d22fSVladimir Kondratiev wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head); 2012be7d22fSVladimir Kondratiev return -EINVAL; 2022be7d22fSVladimir Kondratiev } 2032be7d22fSVladimir Kondratiev /* read Tx head till it is not busy */ 2042be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 2052be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_head, head, sizeof(d_head)); 2062be7d22fSVladimir Kondratiev if (d_head.sync == 0) 2072be7d22fSVladimir Kondratiev break; 2082be7d22fSVladimir Kondratiev msleep(20); 2092be7d22fSVladimir Kondratiev } 2102be7d22fSVladimir Kondratiev if (d_head.sync != 0) { 2112be7d22fSVladimir Kondratiev wil_err(wil, "WMI head busy\n"); 2122be7d22fSVladimir Kondratiev return -EBUSY; 2132be7d22fSVladimir Kondratiev } 2142be7d22fSVladimir Kondratiev /* next head */ 2152be7d22fSVladimir Kondratiev next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size); 2167743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head); 2172be7d22fSVladimir Kondratiev /* wait till FW finish with previous command */ 2182be7d22fSVladimir Kondratiev for (retry = 5; retry > 0; retry--) { 2192be7d22fSVladimir Kondratiev r->tail = ioread32(wil->csr + HOST_MBOX + 2202be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx.tail)); 2212be7d22fSVladimir Kondratiev if (next_head != r->tail) 2222be7d22fSVladimir Kondratiev break; 2232be7d22fSVladimir Kondratiev msleep(20); 2242be7d22fSVladimir Kondratiev } 2252be7d22fSVladimir Kondratiev if (next_head == r->tail) { 2262be7d22fSVladimir Kondratiev wil_err(wil, "WMI ring full\n"); 2272be7d22fSVladimir Kondratiev return -EBUSY; 2282be7d22fSVladimir Kondratiev } 2292be7d22fSVladimir Kondratiev dst = wmi_buffer(wil, d_head.addr); 2302be7d22fSVladimir Kondratiev if (!dst) { 2312be7d22fSVladimir Kondratiev wil_err(wil, "invalid WMI buffer: 0x%08x\n", 2322be7d22fSVladimir Kondratiev le32_to_cpu(d_head.addr)); 2332be7d22fSVladimir Kondratiev return -EINVAL; 2342be7d22fSVladimir Kondratiev } 2352be7d22fSVladimir Kondratiev cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq); 2362be7d22fSVladimir Kondratiev /* set command */ 2377743882dSVladimir Kondratiev wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len); 2387743882dSVladimir Kondratiev wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd, 2392be7d22fSVladimir Kondratiev sizeof(cmd), true); 2407743882dSVladimir Kondratiev wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf, 2412be7d22fSVladimir Kondratiev len, true); 2422be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst, &cmd, sizeof(cmd)); 2432be7d22fSVladimir Kondratiev wil_memcpy_toio_32(dst + sizeof(cmd), buf, len); 2442be7d22fSVladimir Kondratiev /* mark entry as full */ 2452be7d22fSVladimir Kondratiev iowrite32(1, wil->csr + HOSTADDR(r->head) + 2462be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ring_desc, sync)); 2472be7d22fSVladimir Kondratiev /* advance next ptr */ 2482be7d22fSVladimir Kondratiev iowrite32(r->head = next_head, wil->csr + HOST_MBOX + 2492be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, tx.head)); 2502be7d22fSVladimir Kondratiev 251f988b23fSVladimir Kondratiev trace_wil6210_wmi_cmd(&cmd.wmi, buf, len); 25298658095SVladimir 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; 276b8023177SVladimir Kondratiev wil->fw_version = le32_to_cpu(evt->sw_version); 277b8023177SVladimir Kondratiev wil->n_mids = evt->numof_additional_mids; 2782be7d22fSVladimir Kondratiev 279b8023177SVladimir Kondratiev wil_dbg_wmi(wil, "FW ver. %d; MAC %pM; %d MID's\n", wil->fw_version, 280b8023177SVladimir Kondratiev evt->mac, wil->n_mids); 2812be7d22fSVladimir Kondratiev 2822be7d22fSVladimir Kondratiev if (!is_valid_ether_addr(ndev->dev_addr)) { 2832be7d22fSVladimir Kondratiev memcpy(ndev->dev_addr, evt->mac, ETH_ALEN); 2842be7d22fSVladimir Kondratiev memcpy(ndev->perm_addr, evt->mac, ETH_ALEN); 2852be7d22fSVladimir Kondratiev } 2862be7d22fSVladimir Kondratiev snprintf(wdev->wiphy->fw_version, sizeof(wdev->wiphy->fw_version), 287b8023177SVladimir Kondratiev "%d", wil->fw_version); 2882be7d22fSVladimir Kondratiev } 2892be7d22fSVladimir Kondratiev 2902be7d22fSVladimir Kondratiev static void wmi_evt_fw_ready(struct wil6210_priv *wil, int id, void *d, 2912be7d22fSVladimir Kondratiev int len) 2922be7d22fSVladimir Kondratiev { 2937743882dSVladimir Kondratiev wil_dbg_wmi(wil, "WMI: FW ready\n"); 2942be7d22fSVladimir Kondratiev 2952be7d22fSVladimir Kondratiev set_bit(wil_status_fwready, &wil->status); 2962be7d22fSVladimir Kondratiev /* reuse wmi_ready for the firmware ready indication */ 2972be7d22fSVladimir Kondratiev complete(&wil->wmi_ready); 2982be7d22fSVladimir Kondratiev } 2992be7d22fSVladimir Kondratiev 3002be7d22fSVladimir Kondratiev static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) 3012be7d22fSVladimir Kondratiev { 3022be7d22fSVladimir Kondratiev struct wmi_rx_mgmt_packet_event *data = d; 3032be7d22fSVladimir Kondratiev struct wiphy *wiphy = wil_to_wiphy(wil); 3042be7d22fSVladimir Kondratiev struct ieee80211_mgmt *rx_mgmt_frame = 3052be7d22fSVladimir Kondratiev (struct ieee80211_mgmt *)data->payload; 3062be7d22fSVladimir Kondratiev int ch_no = data->info.channel+1; 3072be7d22fSVladimir Kondratiev u32 freq = ieee80211_channel_to_frequency(ch_no, 3082be7d22fSVladimir Kondratiev IEEE80211_BAND_60GHZ); 3092be7d22fSVladimir Kondratiev struct ieee80211_channel *channel = ieee80211_get_channel(wiphy, freq); 3102be7d22fSVladimir Kondratiev /* TODO convert LE to CPU */ 3112be7d22fSVladimir Kondratiev s32 signal = 0; /* TODO */ 3122be7d22fSVladimir Kondratiev __le16 fc = rx_mgmt_frame->frame_control; 3132be7d22fSVladimir Kondratiev u32 d_len = le32_to_cpu(data->info.len); 3142be7d22fSVladimir Kondratiev u16 d_status = le16_to_cpu(data->info.status); 3152be7d22fSVladimir Kondratiev 3167743882dSVladimir Kondratiev wil_dbg_wmi(wil, "MGMT: channel %d MCS %d SNR %d\n", 3172be7d22fSVladimir Kondratiev data->info.channel, data->info.mcs, data->info.snr); 318f27dbf78SVladimir Kondratiev wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len, 319f27dbf78SVladimir Kondratiev le16_to_cpu(fc)); 3207743882dSVladimir Kondratiev wil_dbg_wmi(wil, "qid %d mid %d cid %d\n", 3212be7d22fSVladimir Kondratiev data->info.qid, data->info.mid, data->info.cid); 3222be7d22fSVladimir Kondratiev 3232be7d22fSVladimir Kondratiev if (!channel) { 3242be7d22fSVladimir Kondratiev wil_err(wil, "Frame on unsupported channel\n"); 3252be7d22fSVladimir Kondratiev return; 3262be7d22fSVladimir Kondratiev } 3272be7d22fSVladimir Kondratiev 3282be7d22fSVladimir Kondratiev if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) { 3292be7d22fSVladimir Kondratiev struct cfg80211_bss *bss; 3302be7d22fSVladimir Kondratiev 331a0f7845bSVladimir Kondratiev bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame, 332a0f7845bSVladimir Kondratiev d_len, signal, GFP_KERNEL); 3332be7d22fSVladimir Kondratiev if (bss) { 3347743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Added BSS %pM\n", 3352be7d22fSVladimir Kondratiev rx_mgmt_frame->bssid); 3365b112d3dSJohannes Berg cfg80211_put_bss(wiphy, bss); 3372be7d22fSVladimir Kondratiev } else { 3382be7d22fSVladimir Kondratiev wil_err(wil, "cfg80211_inform_bss() failed\n"); 3392be7d22fSVladimir Kondratiev } 340102b1d99SVladimir Kondratiev } else { 341102b1d99SVladimir Kondratiev cfg80211_rx_mgmt(wil->wdev, freq, signal, 34219504cf5SVladimir Kondratiev (void *)rx_mgmt_frame, d_len, 0, GFP_KERNEL); 3432be7d22fSVladimir Kondratiev } 3442be7d22fSVladimir Kondratiev } 3452be7d22fSVladimir Kondratiev 3462be7d22fSVladimir Kondratiev static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id, 3472be7d22fSVladimir Kondratiev void *d, int len) 3482be7d22fSVladimir Kondratiev { 3492be7d22fSVladimir Kondratiev if (wil->scan_request) { 3502be7d22fSVladimir Kondratiev struct wmi_scan_complete_event *data = d; 3512be7d22fSVladimir Kondratiev bool aborted = (data->status != 0); 3522be7d22fSVladimir Kondratiev 3537743882dSVladimir Kondratiev wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", data->status); 3542be7d22fSVladimir Kondratiev cfg80211_scan_done(wil->scan_request, aborted); 3552be7d22fSVladimir Kondratiev wil->scan_request = NULL; 3562be7d22fSVladimir Kondratiev } else { 3572be7d22fSVladimir Kondratiev wil_err(wil, "SCAN_COMPLETE while not scanning\n"); 3582be7d22fSVladimir Kondratiev } 3592be7d22fSVladimir Kondratiev } 3602be7d22fSVladimir Kondratiev 3612be7d22fSVladimir Kondratiev static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len) 3622be7d22fSVladimir Kondratiev { 3632be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 3642be7d22fSVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 3652be7d22fSVladimir Kondratiev struct wmi_connect_event *evt = d; 3662be7d22fSVladimir Kondratiev int ch; /* channel number */ 3672be7d22fSVladimir Kondratiev struct station_info sinfo; 3682be7d22fSVladimir Kondratiev u8 *assoc_req_ie, *assoc_resp_ie; 3692be7d22fSVladimir Kondratiev size_t assoc_req_ielen, assoc_resp_ielen; 3702be7d22fSVladimir Kondratiev /* capinfo(u16) + listen_interval(u16) + IEs */ 3712be7d22fSVladimir Kondratiev const size_t assoc_req_ie_offset = sizeof(u16) * 2; 3722be7d22fSVladimir Kondratiev /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */ 3732be7d22fSVladimir Kondratiev const size_t assoc_resp_ie_offset = sizeof(u16) * 3; 3742be7d22fSVladimir Kondratiev 3752be7d22fSVladimir Kondratiev if (len < sizeof(*evt)) { 3762be7d22fSVladimir Kondratiev wil_err(wil, "Connect event too short : %d bytes\n", len); 3772be7d22fSVladimir Kondratiev return; 3782be7d22fSVladimir Kondratiev } 3792be7d22fSVladimir Kondratiev if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len + 3802be7d22fSVladimir Kondratiev evt->assoc_resp_len) { 3812be7d22fSVladimir Kondratiev wil_err(wil, 3822be7d22fSVladimir Kondratiev "Connect event corrupted : %d != %d + %d + %d + %d\n", 3832be7d22fSVladimir Kondratiev len, (int)sizeof(*evt), evt->beacon_ie_len, 3842be7d22fSVladimir Kondratiev evt->assoc_req_len, evt->assoc_resp_len); 3852be7d22fSVladimir Kondratiev return; 3862be7d22fSVladimir Kondratiev } 3873df2cd36SVladimir Kondratiev if (evt->cid >= WIL6210_MAX_CID) { 3883df2cd36SVladimir Kondratiev wil_err(wil, "Connect CID invalid : %d\n", evt->cid); 3893df2cd36SVladimir Kondratiev return; 3903df2cd36SVladimir Kondratiev } 3913df2cd36SVladimir Kondratiev 3922be7d22fSVladimir Kondratiev ch = evt->channel + 1; 3937743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Connect %pM channel [%d] cid %d\n", 3942be7d22fSVladimir Kondratiev evt->bssid, ch, evt->cid); 3957743882dSVladimir Kondratiev wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1, 3962be7d22fSVladimir Kondratiev evt->assoc_info, len - sizeof(*evt), true); 3972be7d22fSVladimir Kondratiev 3982be7d22fSVladimir Kondratiev /* figure out IE's */ 3992be7d22fSVladimir Kondratiev assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len + 4002be7d22fSVladimir Kondratiev assoc_req_ie_offset]; 4012be7d22fSVladimir Kondratiev assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset; 4022be7d22fSVladimir Kondratiev if (evt->assoc_req_len <= assoc_req_ie_offset) { 4032be7d22fSVladimir Kondratiev assoc_req_ie = NULL; 4042be7d22fSVladimir Kondratiev assoc_req_ielen = 0; 4052be7d22fSVladimir Kondratiev } 4062be7d22fSVladimir Kondratiev 4072be7d22fSVladimir Kondratiev assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len + 4082be7d22fSVladimir Kondratiev evt->assoc_req_len + 4092be7d22fSVladimir Kondratiev assoc_resp_ie_offset]; 4102be7d22fSVladimir Kondratiev assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset; 4112be7d22fSVladimir Kondratiev if (evt->assoc_resp_len <= assoc_resp_ie_offset) { 4122be7d22fSVladimir Kondratiev assoc_resp_ie = NULL; 4132be7d22fSVladimir Kondratiev assoc_resp_ielen = 0; 4142be7d22fSVladimir Kondratiev } 4152be7d22fSVladimir Kondratiev 4162be7d22fSVladimir Kondratiev if ((wdev->iftype == NL80211_IFTYPE_STATION) || 4172be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { 418b338f74eSVladimir Kondratiev if (!test_bit(wil_status_fwconnecting, &wil->status)) { 4192be7d22fSVladimir Kondratiev wil_err(wil, "Not in connecting state\n"); 4202be7d22fSVladimir Kondratiev return; 4212be7d22fSVladimir Kondratiev } 4222be7d22fSVladimir Kondratiev del_timer_sync(&wil->connect_timer); 4232be7d22fSVladimir Kondratiev cfg80211_connect_result(ndev, evt->bssid, 4242be7d22fSVladimir Kondratiev assoc_req_ie, assoc_req_ielen, 4252be7d22fSVladimir Kondratiev assoc_resp_ie, assoc_resp_ielen, 4262be7d22fSVladimir Kondratiev WLAN_STATUS_SUCCESS, GFP_KERNEL); 4272be7d22fSVladimir Kondratiev 4282be7d22fSVladimir Kondratiev } else if ((wdev->iftype == NL80211_IFTYPE_AP) || 4292be7d22fSVladimir Kondratiev (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { 4302be7d22fSVladimir Kondratiev memset(&sinfo, 0, sizeof(sinfo)); 4312be7d22fSVladimir Kondratiev 4322be7d22fSVladimir Kondratiev sinfo.generation = wil->sinfo_gen++; 4332be7d22fSVladimir Kondratiev 4342be7d22fSVladimir Kondratiev if (assoc_req_ie) { 4352be7d22fSVladimir Kondratiev sinfo.assoc_req_ies = assoc_req_ie; 4362be7d22fSVladimir Kondratiev sinfo.assoc_req_ies_len = assoc_req_ielen; 4372be7d22fSVladimir Kondratiev sinfo.filled |= STATION_INFO_ASSOC_REQ_IES; 4382be7d22fSVladimir Kondratiev } 4392be7d22fSVladimir Kondratiev 4402be7d22fSVladimir Kondratiev cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL); 4412be7d22fSVladimir Kondratiev } 442b338f74eSVladimir Kondratiev clear_bit(wil_status_fwconnecting, &wil->status); 4432be7d22fSVladimir Kondratiev set_bit(wil_status_fwconnected, &wil->status); 4442be7d22fSVladimir Kondratiev 4452be7d22fSVladimir Kondratiev /* FIXME FW can transmit only ucast frames to peer */ 4462be7d22fSVladimir Kondratiev /* FIXME real ring_id instead of hard coded 0 */ 4473df2cd36SVladimir Kondratiev memcpy(wil->sta[evt->cid].addr, evt->bssid, ETH_ALEN); 4483df2cd36SVladimir Kondratiev wil->sta[evt->cid].status = wil_sta_conn_pending; 4492be7d22fSVladimir Kondratiev 4502be7d22fSVladimir Kondratiev wil->pending_connect_cid = evt->cid; 451d81079f1SVladimir Kondratiev queue_work(wil->wmi_wq_conn, &wil->connect_worker); 4522be7d22fSVladimir Kondratiev } 4532be7d22fSVladimir Kondratiev 4542be7d22fSVladimir Kondratiev static void wmi_evt_disconnect(struct wil6210_priv *wil, int id, 4552be7d22fSVladimir Kondratiev void *d, int len) 4562be7d22fSVladimir Kondratiev { 4572be7d22fSVladimir Kondratiev struct wmi_disconnect_event *evt = d; 4583df2cd36SVladimir Kondratiev int cid = wil_find_cid(wil, evt->bssid); 4592be7d22fSVladimir Kondratiev 4603df2cd36SVladimir Kondratiev wil_dbg_wmi(wil, "Disconnect %pM CID %d reason %d proto %d wmi\n", 4613df2cd36SVladimir Kondratiev evt->bssid, cid, 4622be7d22fSVladimir Kondratiev evt->protocol_reason_status, evt->disconnect_reason); 4632be7d22fSVladimir Kondratiev 4642be7d22fSVladimir Kondratiev wil->sinfo_gen++; 4652be7d22fSVladimir Kondratiev 4663df2cd36SVladimir Kondratiev /* TODO: fix for multiple connections */ 4673df2cd36SVladimir Kondratiev 4682be7d22fSVladimir Kondratiev wil6210_disconnect(wil, evt->bssid); 4693df2cd36SVladimir Kondratiev if (cid >= 0) 4703df2cd36SVladimir Kondratiev wil->sta[cid].status = wil_sta_unused; 4712be7d22fSVladimir Kondratiev } 4722be7d22fSVladimir Kondratiev 4732be7d22fSVladimir Kondratiev static void wmi_evt_notify(struct wil6210_priv *wil, int id, void *d, int len) 4742be7d22fSVladimir Kondratiev { 4752be7d22fSVladimir Kondratiev struct wmi_notify_req_done_event *evt = d; 4762be7d22fSVladimir Kondratiev 4772be7d22fSVladimir Kondratiev if (len < sizeof(*evt)) { 4782be7d22fSVladimir Kondratiev wil_err(wil, "Short NOTIFY event\n"); 4792be7d22fSVladimir Kondratiev return; 4802be7d22fSVladimir Kondratiev } 4812be7d22fSVladimir Kondratiev 4822be7d22fSVladimir Kondratiev wil->stats.tsf = le64_to_cpu(evt->tsf); 4832be7d22fSVladimir Kondratiev wil->stats.snr = le32_to_cpu(evt->snr_val); 4842be7d22fSVladimir Kondratiev wil->stats.bf_mcs = le16_to_cpu(evt->bf_mcs); 4852be7d22fSVladimir Kondratiev wil->stats.my_rx_sector = le16_to_cpu(evt->my_rx_sector); 4862be7d22fSVladimir Kondratiev wil->stats.my_tx_sector = le16_to_cpu(evt->my_tx_sector); 4872be7d22fSVladimir Kondratiev wil->stats.peer_rx_sector = le16_to_cpu(evt->other_rx_sector); 4882be7d22fSVladimir Kondratiev wil->stats.peer_tx_sector = le16_to_cpu(evt->other_tx_sector); 4897743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Link status, MCS %d TSF 0x%016llx\n" 4902be7d22fSVladimir Kondratiev "BF status 0x%08x SNR 0x%08x\n" 4912be7d22fSVladimir Kondratiev "Tx Tpt %d goodput %d Rx goodput %d\n" 4922be7d22fSVladimir Kondratiev "Sectors(rx:tx) my %d:%d peer %d:%d\n", 4932be7d22fSVladimir Kondratiev wil->stats.bf_mcs, wil->stats.tsf, evt->status, 4942be7d22fSVladimir Kondratiev wil->stats.snr, le32_to_cpu(evt->tx_tpt), 4952be7d22fSVladimir Kondratiev le32_to_cpu(evt->tx_goodput), le32_to_cpu(evt->rx_goodput), 4962be7d22fSVladimir Kondratiev wil->stats.my_rx_sector, wil->stats.my_tx_sector, 4972be7d22fSVladimir Kondratiev wil->stats.peer_rx_sector, wil->stats.peer_tx_sector); 4982be7d22fSVladimir Kondratiev } 4992be7d22fSVladimir Kondratiev 5002be7d22fSVladimir Kondratiev /* 5012be7d22fSVladimir Kondratiev * Firmware reports EAPOL frame using WME event. 5022be7d22fSVladimir Kondratiev * Reconstruct Ethernet frame and deliver it via normal Rx 5032be7d22fSVladimir Kondratiev */ 5042be7d22fSVladimir Kondratiev static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id, 5052be7d22fSVladimir Kondratiev void *d, int len) 5062be7d22fSVladimir Kondratiev { 5072be7d22fSVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 5082be7d22fSVladimir Kondratiev struct wmi_eapol_rx_event *evt = d; 5092be7d22fSVladimir Kondratiev u16 eapol_len = le16_to_cpu(evt->eapol_len); 5102be7d22fSVladimir Kondratiev int sz = eapol_len + ETH_HLEN; 5112be7d22fSVladimir Kondratiev struct sk_buff *skb; 5122be7d22fSVladimir Kondratiev struct ethhdr *eth; 5132be7d22fSVladimir Kondratiev 5147743882dSVladimir Kondratiev wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len, 5152be7d22fSVladimir Kondratiev evt->src_mac); 5162be7d22fSVladimir Kondratiev 5172be7d22fSVladimir Kondratiev if (eapol_len > 196) { /* TODO: revisit size limit */ 5182be7d22fSVladimir Kondratiev wil_err(wil, "EAPOL too large\n"); 5192be7d22fSVladimir Kondratiev return; 5202be7d22fSVladimir Kondratiev } 5212be7d22fSVladimir Kondratiev 5222be7d22fSVladimir Kondratiev skb = alloc_skb(sz, GFP_KERNEL); 5232be7d22fSVladimir Kondratiev if (!skb) { 5242be7d22fSVladimir Kondratiev wil_err(wil, "Failed to allocate skb\n"); 5252be7d22fSVladimir Kondratiev return; 5262be7d22fSVladimir Kondratiev } 5272be7d22fSVladimir Kondratiev eth = (struct ethhdr *)skb_put(skb, ETH_HLEN); 5282be7d22fSVladimir Kondratiev memcpy(eth->h_dest, ndev->dev_addr, ETH_ALEN); 5292be7d22fSVladimir Kondratiev memcpy(eth->h_source, evt->src_mac, ETH_ALEN); 5302be7d22fSVladimir Kondratiev eth->h_proto = cpu_to_be16(ETH_P_PAE); 5312be7d22fSVladimir Kondratiev memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len); 5322be7d22fSVladimir Kondratiev skb->protocol = eth_type_trans(skb, ndev); 5332be7d22fSVladimir Kondratiev if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) { 5342be7d22fSVladimir Kondratiev ndev->stats.rx_packets++; 5352be7d22fSVladimir Kondratiev ndev->stats.rx_bytes += skb->len; 5362be7d22fSVladimir Kondratiev } else { 5372be7d22fSVladimir Kondratiev ndev->stats.rx_dropped++; 5382be7d22fSVladimir Kondratiev } 5392be7d22fSVladimir Kondratiev } 5402be7d22fSVladimir Kondratiev 5413442a504SVladimir Kondratiev static void wmi_evt_linkup(struct wil6210_priv *wil, int id, void *d, int len) 5423442a504SVladimir Kondratiev { 5433442a504SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 5443442a504SVladimir Kondratiev struct wmi_data_port_open_event *evt = d; 5453442a504SVladimir Kondratiev 5463442a504SVladimir Kondratiev wil_dbg_wmi(wil, "Link UP for CID %d\n", evt->cid); 5473442a504SVladimir Kondratiev 5483442a504SVladimir Kondratiev netif_carrier_on(ndev); 5493442a504SVladimir Kondratiev } 5503442a504SVladimir Kondratiev 5513442a504SVladimir Kondratiev static void wmi_evt_linkdown(struct wil6210_priv *wil, int id, void *d, int len) 5523442a504SVladimir Kondratiev { 5533442a504SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 5543442a504SVladimir Kondratiev struct wmi_wbe_link_down_event *evt = d; 5553442a504SVladimir Kondratiev 5563442a504SVladimir Kondratiev wil_dbg_wmi(wil, "Link DOWN for CID %d, reason %d\n", 5573442a504SVladimir Kondratiev evt->cid, le32_to_cpu(evt->reason)); 5583442a504SVladimir Kondratiev 5593442a504SVladimir Kondratiev netif_carrier_off(ndev); 5603442a504SVladimir Kondratiev } 5613442a504SVladimir Kondratiev 562249a382bSVladimir Kondratiev static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d, 563249a382bSVladimir Kondratiev int len) 564249a382bSVladimir Kondratiev { 565249a382bSVladimir Kondratiev struct wmi_vring_ba_status_event *evt = d; 5667b05b0abSVladimir Kondratiev struct wil_sta_info *sta; 5677b05b0abSVladimir Kondratiev uint i, cid; 5687b05b0abSVladimir Kondratiev 5697b05b0abSVladimir Kondratiev /* TODO: use Rx BA status, not Tx one */ 570249a382bSVladimir Kondratiev 571249a382bSVladimir Kondratiev wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d\n", 5727b05b0abSVladimir Kondratiev evt->ringid, 5737b05b0abSVladimir Kondratiev evt->status == WMI_BA_AGREED ? "OK" : "N/A", 574b4490f42SVladimir Kondratiev evt->agg_wsize, __le16_to_cpu(evt->ba_timeout)); 575b4490f42SVladimir Kondratiev 5767b05b0abSVladimir Kondratiev if (evt->ringid >= WIL6210_MAX_TX_RINGS) { 5777b05b0abSVladimir Kondratiev wil_err(wil, "invalid ring id %d\n", evt->ringid); 5787b05b0abSVladimir Kondratiev return; 5797b05b0abSVladimir Kondratiev } 5807b05b0abSVladimir Kondratiev 5817b05b0abSVladimir Kondratiev cid = wil->vring2cid_tid[evt->ringid][0]; 5827b05b0abSVladimir Kondratiev if (cid >= WIL6210_MAX_CID) { 5837b05b0abSVladimir Kondratiev wil_err(wil, "invalid CID %d for vring %d\n", cid, evt->ringid); 5847b05b0abSVladimir Kondratiev return; 5857b05b0abSVladimir Kondratiev } 5867b05b0abSVladimir Kondratiev 5877b05b0abSVladimir Kondratiev sta = &wil->sta[cid]; 5887b05b0abSVladimir Kondratiev if (sta->status == wil_sta_unused) { 5897b05b0abSVladimir Kondratiev wil_err(wil, "CID %d unused\n", cid); 5907b05b0abSVladimir Kondratiev return; 5917b05b0abSVladimir Kondratiev } 5927b05b0abSVladimir Kondratiev 5937b05b0abSVladimir Kondratiev wil_dbg_wmi(wil, "BACK for CID %d %pM\n", cid, sta->addr); 594b4490f42SVladimir Kondratiev for (i = 0; i < WIL_STA_TID_NUM; i++) { 595b4490f42SVladimir Kondratiev struct wil_tid_ampdu_rx *r = sta->tid_rx[i]; 596b4490f42SVladimir Kondratiev sta->tid_rx[i] = NULL; 597b4490f42SVladimir Kondratiev wil_tid_ampdu_rx_free(wil, r); 598b4490f42SVladimir Kondratiev if ((evt->status == WMI_BA_AGREED) && evt->agg_wsize) 599b4490f42SVladimir Kondratiev sta->tid_rx[i] = wil_tid_ampdu_rx_alloc(wil, 600b4490f42SVladimir Kondratiev evt->agg_wsize, 0); 601b4490f42SVladimir Kondratiev } 602b4490f42SVladimir Kondratiev } 603b4490f42SVladimir Kondratiev 6042be7d22fSVladimir Kondratiev static const struct { 6052be7d22fSVladimir Kondratiev int eventid; 6062be7d22fSVladimir Kondratiev void (*handler)(struct wil6210_priv *wil, int eventid, 6072be7d22fSVladimir Kondratiev void *data, int data_len); 6082be7d22fSVladimir Kondratiev } wmi_evt_handlers[] = { 6092be7d22fSVladimir Kondratiev {WMI_READY_EVENTID, wmi_evt_ready}, 6102be7d22fSVladimir Kondratiev {WMI_FW_READY_EVENTID, wmi_evt_fw_ready}, 6112be7d22fSVladimir Kondratiev {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt}, 6122be7d22fSVladimir Kondratiev {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete}, 6132be7d22fSVladimir Kondratiev {WMI_CONNECT_EVENTID, wmi_evt_connect}, 6142be7d22fSVladimir Kondratiev {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect}, 6152be7d22fSVladimir Kondratiev {WMI_NOTIFY_REQ_DONE_EVENTID, wmi_evt_notify}, 6162be7d22fSVladimir Kondratiev {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx}, 6173442a504SVladimir Kondratiev {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_linkup}, 6183442a504SVladimir Kondratiev {WMI_WBE_LINKDOWN_EVENTID, wmi_evt_linkdown}, 619249a382bSVladimir Kondratiev {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status}, 6202be7d22fSVladimir Kondratiev }; 6212be7d22fSVladimir Kondratiev 6222be7d22fSVladimir Kondratiev /* 6232be7d22fSVladimir Kondratiev * Run in IRQ context 6242be7d22fSVladimir Kondratiev * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev 6252be7d22fSVladimir Kondratiev * that will be eventually handled by the @wmi_event_worker in the thread 6262be7d22fSVladimir Kondratiev * context of thread "wil6210_wmi" 6272be7d22fSVladimir Kondratiev */ 6282be7d22fSVladimir Kondratiev void wmi_recv_cmd(struct wil6210_priv *wil) 6292be7d22fSVladimir Kondratiev { 6302be7d22fSVladimir Kondratiev struct wil6210_mbox_ring_desc d_tail; 6312be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr hdr; 6322be7d22fSVladimir Kondratiev struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx; 6332be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 6342be7d22fSVladimir Kondratiev u8 *cmd; 6352be7d22fSVladimir Kondratiev void __iomem *src; 6362be7d22fSVladimir Kondratiev ulong flags; 6372be7d22fSVladimir Kondratiev 63855f7acddSVladimir Kondratiev if (!test_bit(wil_status_reset_done, &wil->status)) { 63955f7acddSVladimir Kondratiev wil_err(wil, "Reset not completed\n"); 64055f7acddSVladimir Kondratiev return; 64155f7acddSVladimir Kondratiev } 64255f7acddSVladimir Kondratiev 6432be7d22fSVladimir Kondratiev for (;;) { 6442be7d22fSVladimir Kondratiev u16 len; 6452be7d22fSVladimir Kondratiev 6462be7d22fSVladimir Kondratiev r->head = ioread32(wil->csr + HOST_MBOX + 6472be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.head)); 6482be7d22fSVladimir Kondratiev if (r->tail == r->head) 6492be7d22fSVladimir Kondratiev return; 6502be7d22fSVladimir Kondratiev 6512be7d22fSVladimir Kondratiev /* read cmd from tail */ 6522be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail), 6532be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)); 6542be7d22fSVladimir Kondratiev if (d_tail.sync == 0) { 6552be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt not owned by FW?\n"); 6562be7d22fSVladimir Kondratiev return; 6572be7d22fSVladimir Kondratiev } 6582be7d22fSVladimir Kondratiev 6592be7d22fSVladimir Kondratiev if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) { 6602be7d22fSVladimir Kondratiev wil_err(wil, "Mbox evt at 0x%08x?\n", 6612be7d22fSVladimir Kondratiev le32_to_cpu(d_tail.addr)); 6622be7d22fSVladimir Kondratiev return; 6632be7d22fSVladimir Kondratiev } 6642be7d22fSVladimir Kondratiev 6652be7d22fSVladimir Kondratiev len = le16_to_cpu(hdr.len); 6662be7d22fSVladimir Kondratiev src = wmi_buffer(wil, d_tail.addr) + 6672be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_hdr); 6682be7d22fSVladimir Kondratiev evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event, 6692be7d22fSVladimir Kondratiev event.wmi) + len, 4), 6702be7d22fSVladimir Kondratiev GFP_KERNEL); 67114f8dc49SJoe Perches if (!evt) 6722be7d22fSVladimir Kondratiev return; 67314f8dc49SJoe Perches 6742be7d22fSVladimir Kondratiev evt->event.hdr = hdr; 6752be7d22fSVladimir Kondratiev cmd = (void *)&evt->event.wmi; 6762be7d22fSVladimir Kondratiev wil_memcpy_fromio_32(cmd, src, len); 6772be7d22fSVladimir Kondratiev /* mark entry as empty */ 6782be7d22fSVladimir Kondratiev iowrite32(0, wil->csr + HOSTADDR(r->tail) + 6792be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ring_desc, sync)); 6802be7d22fSVladimir Kondratiev /* indicate */ 6817743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n", 6822be7d22fSVladimir Kondratiev le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type), 6832be7d22fSVladimir Kondratiev hdr.flags); 6842be7d22fSVladimir Kondratiev if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) && 6852be7d22fSVladimir Kondratiev (len >= sizeof(struct wil6210_mbox_hdr_wmi))) { 686f988b23fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi *wmi = &evt->event.wmi; 687f988b23fSVladimir Kondratiev u16 id = le16_to_cpu(wmi->id); 688f988b23fSVladimir Kondratiev u32 tstamp = le32_to_cpu(wmi->timestamp); 689f988b23fSVladimir Kondratiev wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n", 690f988b23fSVladimir Kondratiev id, wmi->mid, tstamp); 691f988b23fSVladimir Kondratiev trace_wil6210_wmi_event(wmi, &wmi[1], 692f988b23fSVladimir Kondratiev len - sizeof(*wmi)); 6932be7d22fSVladimir Kondratiev } 6947743882dSVladimir Kondratiev wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1, 6952be7d22fSVladimir Kondratiev &evt->event.hdr, sizeof(hdr) + len, true); 6962be7d22fSVladimir Kondratiev 6972be7d22fSVladimir Kondratiev /* advance tail */ 6982be7d22fSVladimir Kondratiev r->tail = r->base + ((r->tail - r->base + 6992be7d22fSVladimir Kondratiev sizeof(struct wil6210_mbox_ring_desc)) % r->size); 7002be7d22fSVladimir Kondratiev iowrite32(r->tail, wil->csr + HOST_MBOX + 7012be7d22fSVladimir Kondratiev offsetof(struct wil6210_mbox_ctl, rx.tail)); 7022be7d22fSVladimir Kondratiev 7032be7d22fSVladimir Kondratiev /* add to the pending list */ 7042be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 7052be7d22fSVladimir Kondratiev list_add_tail(&evt->list, &wil->pending_wmi_ev); 7062be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 7072be7d22fSVladimir Kondratiev { 7082be7d22fSVladimir Kondratiev int q = queue_work(wil->wmi_wq, 7092be7d22fSVladimir Kondratiev &wil->wmi_event_worker); 7107743882dSVladimir Kondratiev wil_dbg_wmi(wil, "queue_work -> %d\n", q); 7112be7d22fSVladimir Kondratiev } 7122be7d22fSVladimir Kondratiev } 7132be7d22fSVladimir Kondratiev } 7142be7d22fSVladimir Kondratiev 7152be7d22fSVladimir Kondratiev int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len, 7162be7d22fSVladimir Kondratiev u16 reply_id, void *reply, u8 reply_size, int to_msec) 7172be7d22fSVladimir Kondratiev { 7182be7d22fSVladimir Kondratiev int rc; 7192be7d22fSVladimir Kondratiev int remain; 7202be7d22fSVladimir Kondratiev 7212be7d22fSVladimir Kondratiev mutex_lock(&wil->wmi_mutex); 7222be7d22fSVladimir Kondratiev 7232be7d22fSVladimir Kondratiev rc = __wmi_send(wil, cmdid, buf, len); 7242be7d22fSVladimir Kondratiev if (rc) 7252be7d22fSVladimir Kondratiev goto out; 7262be7d22fSVladimir Kondratiev 7272be7d22fSVladimir Kondratiev wil->reply_id = reply_id; 7282be7d22fSVladimir Kondratiev wil->reply_buf = reply; 7292be7d22fSVladimir Kondratiev wil->reply_size = reply_size; 7302be7d22fSVladimir Kondratiev remain = wait_for_completion_timeout(&wil->wmi_ready, 7312be7d22fSVladimir Kondratiev msecs_to_jiffies(to_msec)); 7322be7d22fSVladimir Kondratiev if (0 == remain) { 7332be7d22fSVladimir Kondratiev wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n", 7342be7d22fSVladimir Kondratiev cmdid, reply_id, to_msec); 7352be7d22fSVladimir Kondratiev rc = -ETIME; 7362be7d22fSVladimir Kondratiev } else { 7377743882dSVladimir Kondratiev wil_dbg_wmi(wil, 7382be7d22fSVladimir Kondratiev "wmi_call(0x%04x->0x%04x) completed in %d msec\n", 7392be7d22fSVladimir Kondratiev cmdid, reply_id, 7402be7d22fSVladimir Kondratiev to_msec - jiffies_to_msecs(remain)); 7412be7d22fSVladimir Kondratiev } 7422be7d22fSVladimir Kondratiev wil->reply_id = 0; 7432be7d22fSVladimir Kondratiev wil->reply_buf = NULL; 7442be7d22fSVladimir Kondratiev wil->reply_size = 0; 7452be7d22fSVladimir Kondratiev out: 7462be7d22fSVladimir Kondratiev mutex_unlock(&wil->wmi_mutex); 7472be7d22fSVladimir Kondratiev 7482be7d22fSVladimir Kondratiev return rc; 7492be7d22fSVladimir Kondratiev } 7502be7d22fSVladimir Kondratiev 7512be7d22fSVladimir Kondratiev int wmi_echo(struct wil6210_priv *wil) 7522be7d22fSVladimir Kondratiev { 7532be7d22fSVladimir Kondratiev struct wmi_echo_cmd cmd = { 7542be7d22fSVladimir Kondratiev .value = cpu_to_le32(0x12345678), 7552be7d22fSVladimir Kondratiev }; 7562be7d22fSVladimir Kondratiev 7572be7d22fSVladimir Kondratiev return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd), 7582be7d22fSVladimir Kondratiev WMI_ECHO_RSP_EVENTID, NULL, 0, 20); 7592be7d22fSVladimir Kondratiev } 7602be7d22fSVladimir Kondratiev 7612be7d22fSVladimir Kondratiev int wmi_set_mac_address(struct wil6210_priv *wil, void *addr) 7622be7d22fSVladimir Kondratiev { 7632be7d22fSVladimir Kondratiev struct wmi_set_mac_address_cmd cmd; 7642be7d22fSVladimir Kondratiev 7652be7d22fSVladimir Kondratiev memcpy(cmd.mac, addr, ETH_ALEN); 7662be7d22fSVladimir Kondratiev 7677743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Set MAC %pM\n", addr); 7682be7d22fSVladimir Kondratiev 7692be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd)); 7702be7d22fSVladimir Kondratiev } 7712be7d22fSVladimir Kondratiev 772b8023177SVladimir Kondratiev int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, u8 chan) 7732be7d22fSVladimir Kondratiev { 774b8023177SVladimir Kondratiev int rc; 775b8023177SVladimir Kondratiev 776b8023177SVladimir Kondratiev struct wmi_pcp_start_cmd cmd = { 7772be7d22fSVladimir Kondratiev .bcon_interval = cpu_to_le16(bi), 7782be7d22fSVladimir Kondratiev .network_type = wmi_nettype, 7792be7d22fSVladimir Kondratiev .disable_sec_offload = 1, 780adc2d122SVladimir Kondratiev .channel = chan - 1, 7812be7d22fSVladimir Kondratiev }; 782b8023177SVladimir Kondratiev struct { 783b8023177SVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 784b8023177SVladimir Kondratiev struct wmi_pcp_started_event evt; 785b8023177SVladimir Kondratiev } __packed reply; 7862be7d22fSVladimir Kondratiev 7872be7d22fSVladimir Kondratiev if (!wil->secure_pcp) 7882be7d22fSVladimir Kondratiev cmd.disable_sec = 1; 7892be7d22fSVladimir Kondratiev 7908b5c7f6cSVladimir Kondratiev /* 7918b5c7f6cSVladimir Kondratiev * Processing time may be huge, in case of secure AP it takes about 7928b5c7f6cSVladimir Kondratiev * 3500ms for FW to start AP 7938b5c7f6cSVladimir Kondratiev */ 794b8023177SVladimir Kondratiev rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd), 7958b5c7f6cSVladimir Kondratiev WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000); 796b8023177SVladimir Kondratiev if (rc) 797b8023177SVladimir Kondratiev return rc; 798b8023177SVladimir Kondratiev 799b8023177SVladimir Kondratiev if (reply.evt.status != WMI_FW_STATUS_SUCCESS) 800b8023177SVladimir Kondratiev rc = -EINVAL; 801b8023177SVladimir Kondratiev 802b8023177SVladimir Kondratiev return rc; 803b8023177SVladimir Kondratiev } 804b8023177SVladimir Kondratiev 805b8023177SVladimir Kondratiev int wmi_pcp_stop(struct wil6210_priv *wil) 806b8023177SVladimir Kondratiev { 807b8023177SVladimir Kondratiev return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0, 808b8023177SVladimir Kondratiev WMI_PCP_STOPPED_EVENTID, NULL, 0, 20); 8092be7d22fSVladimir Kondratiev } 8102be7d22fSVladimir Kondratiev 8112be7d22fSVladimir Kondratiev int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid) 8122be7d22fSVladimir Kondratiev { 8132be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd = { 8142be7d22fSVladimir Kondratiev .ssid_len = cpu_to_le32(ssid_len), 8152be7d22fSVladimir Kondratiev }; 8162be7d22fSVladimir Kondratiev 8172be7d22fSVladimir Kondratiev if (ssid_len > sizeof(cmd.ssid)) 8182be7d22fSVladimir Kondratiev return -EINVAL; 8192be7d22fSVladimir Kondratiev 8202be7d22fSVladimir Kondratiev memcpy(cmd.ssid, ssid, ssid_len); 8212be7d22fSVladimir Kondratiev 8222be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd)); 8232be7d22fSVladimir Kondratiev } 8242be7d22fSVladimir Kondratiev 8252be7d22fSVladimir Kondratiev int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid) 8262be7d22fSVladimir Kondratiev { 8272be7d22fSVladimir Kondratiev int rc; 8282be7d22fSVladimir Kondratiev struct { 8292be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 8302be7d22fSVladimir Kondratiev struct wmi_set_ssid_cmd cmd; 8312be7d22fSVladimir Kondratiev } __packed reply; 8322be7d22fSVladimir Kondratiev int len; /* reply.cmd.ssid_len in CPU order */ 8332be7d22fSVladimir Kondratiev 8342be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID, 8352be7d22fSVladimir Kondratiev &reply, sizeof(reply), 20); 8362be7d22fSVladimir Kondratiev if (rc) 8372be7d22fSVladimir Kondratiev return rc; 8382be7d22fSVladimir Kondratiev 8392be7d22fSVladimir Kondratiev len = le32_to_cpu(reply.cmd.ssid_len); 8402be7d22fSVladimir Kondratiev if (len > sizeof(reply.cmd.ssid)) 8412be7d22fSVladimir Kondratiev return -EINVAL; 8422be7d22fSVladimir Kondratiev 8432be7d22fSVladimir Kondratiev *ssid_len = len; 8442be7d22fSVladimir Kondratiev memcpy(ssid, reply.cmd.ssid, len); 8452be7d22fSVladimir Kondratiev 8462be7d22fSVladimir Kondratiev return 0; 8472be7d22fSVladimir Kondratiev } 8482be7d22fSVladimir Kondratiev 8492be7d22fSVladimir Kondratiev int wmi_set_channel(struct wil6210_priv *wil, int channel) 8502be7d22fSVladimir Kondratiev { 8512be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd = { 8522be7d22fSVladimir Kondratiev .channel = channel - 1, 8532be7d22fSVladimir Kondratiev }; 8542be7d22fSVladimir Kondratiev 8552be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd)); 8562be7d22fSVladimir Kondratiev } 8572be7d22fSVladimir Kondratiev 8582be7d22fSVladimir Kondratiev int wmi_get_channel(struct wil6210_priv *wil, int *channel) 8592be7d22fSVladimir Kondratiev { 8602be7d22fSVladimir Kondratiev int rc; 8612be7d22fSVladimir Kondratiev struct { 8622be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 8632be7d22fSVladimir Kondratiev struct wmi_set_pcp_channel_cmd cmd; 8642be7d22fSVladimir Kondratiev } __packed reply; 8652be7d22fSVladimir Kondratiev 8662be7d22fSVladimir Kondratiev rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0, 8672be7d22fSVladimir Kondratiev WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20); 8682be7d22fSVladimir Kondratiev if (rc) 8692be7d22fSVladimir Kondratiev return rc; 8702be7d22fSVladimir Kondratiev 8712be7d22fSVladimir Kondratiev if (reply.cmd.channel > 3) 8722be7d22fSVladimir Kondratiev return -EINVAL; 8732be7d22fSVladimir Kondratiev 8742be7d22fSVladimir Kondratiev *channel = reply.cmd.channel + 1; 8752be7d22fSVladimir Kondratiev 8762be7d22fSVladimir Kondratiev return 0; 8772be7d22fSVladimir Kondratiev } 8782be7d22fSVladimir Kondratiev 879b8023177SVladimir Kondratiev int wmi_p2p_cfg(struct wil6210_priv *wil, int channel) 880b8023177SVladimir Kondratiev { 881b8023177SVladimir Kondratiev struct wmi_p2p_cfg_cmd cmd = { 882b8023177SVladimir Kondratiev .discovery_mode = WMI_DISCOVERY_MODE_NON_OFFLOAD, 883b8023177SVladimir Kondratiev .channel = channel - 1, 884b8023177SVladimir Kondratiev }; 885b8023177SVladimir Kondratiev 886b8023177SVladimir Kondratiev return wmi_send(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd)); 887b8023177SVladimir Kondratiev } 888b8023177SVladimir Kondratiev 8892be7d22fSVladimir Kondratiev int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index, 8902be7d22fSVladimir Kondratiev const void *mac_addr) 8912be7d22fSVladimir Kondratiev { 8922be7d22fSVladimir Kondratiev struct wmi_delete_cipher_key_cmd cmd = { 8932be7d22fSVladimir Kondratiev .key_index = key_index, 8942be7d22fSVladimir Kondratiev }; 8952be7d22fSVladimir Kondratiev 8962be7d22fSVladimir Kondratiev if (mac_addr) 8972be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 8982be7d22fSVladimir Kondratiev 8992be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 9002be7d22fSVladimir Kondratiev } 9012be7d22fSVladimir Kondratiev 9022be7d22fSVladimir Kondratiev int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index, 9032be7d22fSVladimir Kondratiev const void *mac_addr, int key_len, const void *key) 9042be7d22fSVladimir Kondratiev { 9052be7d22fSVladimir Kondratiev struct wmi_add_cipher_key_cmd cmd = { 9062be7d22fSVladimir Kondratiev .key_index = key_index, 9072be7d22fSVladimir Kondratiev .key_usage = WMI_KEY_USE_PAIRWISE, 9082be7d22fSVladimir Kondratiev .key_len = key_len, 9092be7d22fSVladimir Kondratiev }; 9102be7d22fSVladimir Kondratiev 9112be7d22fSVladimir Kondratiev if (!key || (key_len > sizeof(cmd.key))) 9122be7d22fSVladimir Kondratiev return -EINVAL; 9132be7d22fSVladimir Kondratiev 9142be7d22fSVladimir Kondratiev memcpy(cmd.key, key, key_len); 9152be7d22fSVladimir Kondratiev if (mac_addr) 9162be7d22fSVladimir Kondratiev memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); 9172be7d22fSVladimir Kondratiev 9182be7d22fSVladimir Kondratiev return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); 9192be7d22fSVladimir Kondratiev } 9202be7d22fSVladimir Kondratiev 9212be7d22fSVladimir Kondratiev int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie) 9222be7d22fSVladimir Kondratiev { 9232be7d22fSVladimir Kondratiev int rc; 9242be7d22fSVladimir Kondratiev u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len; 9252be7d22fSVladimir Kondratiev struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL); 92614f8dc49SJoe Perches if (!cmd) 9272be7d22fSVladimir Kondratiev return -ENOMEM; 9282be7d22fSVladimir Kondratiev 9292be7d22fSVladimir Kondratiev cmd->mgmt_frm_type = type; 9302be7d22fSVladimir Kondratiev /* BUG: FW API define ieLen as u8. Will fix FW */ 9312be7d22fSVladimir Kondratiev cmd->ie_len = cpu_to_le16(ie_len); 9322be7d22fSVladimir Kondratiev memcpy(cmd->ie_info, ie, ie_len); 93303866e7dSVladimir Kondratiev rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len); 9342be7d22fSVladimir Kondratiev kfree(cmd); 9352be7d22fSVladimir Kondratiev 9362be7d22fSVladimir Kondratiev return rc; 9372be7d22fSVladimir Kondratiev } 9382be7d22fSVladimir Kondratiev 9391647f12fSVladimir Kondratiev /** 9401647f12fSVladimir Kondratiev * wmi_rxon - turn radio on/off 9411647f12fSVladimir Kondratiev * @on: turn on if true, off otherwise 9421647f12fSVladimir Kondratiev * 9431647f12fSVladimir Kondratiev * Only switch radio. Channel should be set separately. 9441647f12fSVladimir Kondratiev * No timeout for rxon - radio turned on forever unless some other call 9451647f12fSVladimir Kondratiev * turns it off 9461647f12fSVladimir Kondratiev */ 9471647f12fSVladimir Kondratiev int wmi_rxon(struct wil6210_priv *wil, bool on) 9481647f12fSVladimir Kondratiev { 9491647f12fSVladimir Kondratiev int rc; 9501647f12fSVladimir Kondratiev struct { 9511647f12fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 9521647f12fSVladimir Kondratiev struct wmi_listen_started_event evt; 9531647f12fSVladimir Kondratiev } __packed reply; 9541647f12fSVladimir Kondratiev 9551647f12fSVladimir Kondratiev wil_info(wil, "%s(%s)\n", __func__, on ? "on" : "off"); 9561647f12fSVladimir Kondratiev 9571647f12fSVladimir Kondratiev if (on) { 9581647f12fSVladimir Kondratiev rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0, 9591647f12fSVladimir Kondratiev WMI_LISTEN_STARTED_EVENTID, 9601647f12fSVladimir Kondratiev &reply, sizeof(reply), 100); 9611647f12fSVladimir Kondratiev if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS)) 9621647f12fSVladimir Kondratiev rc = -EINVAL; 9631647f12fSVladimir Kondratiev } else { 9641647f12fSVladimir Kondratiev rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0, 9651647f12fSVladimir Kondratiev WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20); 9661647f12fSVladimir Kondratiev } 9671647f12fSVladimir Kondratiev 9681647f12fSVladimir Kondratiev return rc; 9691647f12fSVladimir Kondratiev } 9701647f12fSVladimir Kondratiev 97147e19af9SVladimir Kondratiev int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring) 97247e19af9SVladimir Kondratiev { 97347e19af9SVladimir Kondratiev struct wireless_dev *wdev = wil->wdev; 97447e19af9SVladimir Kondratiev struct net_device *ndev = wil_to_ndev(wil); 97547e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_cmd cmd = { 97647e19af9SVladimir Kondratiev .action = WMI_RX_CHAIN_ADD, 97747e19af9SVladimir Kondratiev .rx_sw_ring = { 97847e19af9SVladimir Kondratiev .max_mpdu_size = cpu_to_le16(RX_BUF_LEN), 97947e19af9SVladimir Kondratiev .ring_mem_base = cpu_to_le64(vring->pa), 98047e19af9SVladimir Kondratiev .ring_size = cpu_to_le16(vring->size), 98147e19af9SVladimir Kondratiev }, 98247e19af9SVladimir Kondratiev .mid = 0, /* TODO - what is it? */ 98347e19af9SVladimir Kondratiev .decap_trans_type = WMI_DECAP_TYPE_802_3, 984b4490f42SVladimir Kondratiev .reorder_type = WMI_RX_SW_REORDER, 98547e19af9SVladimir Kondratiev }; 98647e19af9SVladimir Kondratiev struct { 98747e19af9SVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 98847e19af9SVladimir Kondratiev struct wmi_cfg_rx_chain_done_event evt; 98947e19af9SVladimir Kondratiev } __packed evt; 99047e19af9SVladimir Kondratiev int rc; 99147e19af9SVladimir Kondratiev 99247e19af9SVladimir Kondratiev if (wdev->iftype == NL80211_IFTYPE_MONITOR) { 99347e19af9SVladimir Kondratiev struct ieee80211_channel *ch = wdev->preset_chandef.chan; 99447e19af9SVladimir Kondratiev 99547e19af9SVladimir Kondratiev cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON); 99647e19af9SVladimir Kondratiev if (ch) 99747e19af9SVladimir Kondratiev cmd.sniffer_cfg.channel = ch->hw_value - 1; 99847e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_info_mode = 99947e19af9SVladimir Kondratiev cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP); 100047e19af9SVladimir Kondratiev cmd.sniffer_cfg.phy_support = 100147e19af9SVladimir Kondratiev cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL) 100247e19af9SVladimir Kondratiev ? WMI_SNIFFER_CP : WMI_SNIFFER_DP); 1003504937d4SKirshenbaum Erez } else { 1004504937d4SKirshenbaum Erez /* Initialize offload (in non-sniffer mode). 1005504937d4SKirshenbaum Erez * Linux IP stack always calculates IP checksum 1006504937d4SKirshenbaum Erez * HW always calculate TCP/UDP checksum 1007504937d4SKirshenbaum Erez */ 1008504937d4SKirshenbaum Erez cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS); 100947e19af9SVladimir Kondratiev } 101047e19af9SVladimir Kondratiev /* typical time for secure PCP is 840ms */ 101147e19af9SVladimir Kondratiev rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd), 101247e19af9SVladimir Kondratiev WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000); 101347e19af9SVladimir Kondratiev if (rc) 101447e19af9SVladimir Kondratiev return rc; 101547e19af9SVladimir Kondratiev 101647e19af9SVladimir Kondratiev vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr); 101747e19af9SVladimir Kondratiev 10187743882dSVladimir Kondratiev wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n", 101947e19af9SVladimir Kondratiev le32_to_cpu(evt.evt.status), vring->hwtail); 102047e19af9SVladimir Kondratiev 102147e19af9SVladimir Kondratiev if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS) 102247e19af9SVladimir Kondratiev rc = -EINVAL; 102347e19af9SVladimir Kondratiev 102447e19af9SVladimir Kondratiev return rc; 102547e19af9SVladimir Kondratiev } 102647e19af9SVladimir Kondratiev 10271a2780e0SVladimir Kondratiev int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_m, u32 *t_r) 10281a2780e0SVladimir Kondratiev { 10291a2780e0SVladimir Kondratiev int rc; 10301a2780e0SVladimir Kondratiev struct wmi_temp_sense_cmd cmd = { 10311a2780e0SVladimir Kondratiev .measure_marlon_m_en = cpu_to_le32(!!t_m), 10321a2780e0SVladimir Kondratiev .measure_marlon_r_en = cpu_to_le32(!!t_r), 10331a2780e0SVladimir Kondratiev }; 10341a2780e0SVladimir Kondratiev struct { 10351a2780e0SVladimir Kondratiev struct wil6210_mbox_hdr_wmi wmi; 10361a2780e0SVladimir Kondratiev struct wmi_temp_sense_done_event evt; 10371a2780e0SVladimir Kondratiev } __packed reply; 10381a2780e0SVladimir Kondratiev 10391a2780e0SVladimir Kondratiev rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd), 10401a2780e0SVladimir Kondratiev WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100); 10411a2780e0SVladimir Kondratiev if (rc) 10421a2780e0SVladimir Kondratiev return rc; 10431a2780e0SVladimir Kondratiev 10441a2780e0SVladimir Kondratiev if (t_m) 10451a2780e0SVladimir Kondratiev *t_m = le32_to_cpu(reply.evt.marlon_m_t1000); 10461a2780e0SVladimir Kondratiev if (t_r) 10471a2780e0SVladimir Kondratiev *t_r = le32_to_cpu(reply.evt.marlon_r_t1000); 10481a2780e0SVladimir Kondratiev 10491a2780e0SVladimir Kondratiev return 0; 10501a2780e0SVladimir Kondratiev } 10511a2780e0SVladimir Kondratiev 10522be7d22fSVladimir Kondratiev void wmi_event_flush(struct wil6210_priv *wil) 10532be7d22fSVladimir Kondratiev { 10542be7d22fSVladimir Kondratiev struct pending_wmi_event *evt, *t; 10552be7d22fSVladimir Kondratiev 10567743882dSVladimir Kondratiev wil_dbg_wmi(wil, "%s()\n", __func__); 10572be7d22fSVladimir Kondratiev 10582be7d22fSVladimir Kondratiev list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) { 10592be7d22fSVladimir Kondratiev list_del(&evt->list); 10602be7d22fSVladimir Kondratiev kfree(evt); 10612be7d22fSVladimir Kondratiev } 10622be7d22fSVladimir Kondratiev } 10632be7d22fSVladimir Kondratiev 10642be7d22fSVladimir Kondratiev static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id, 10652be7d22fSVladimir Kondratiev void *d, int len) 10662be7d22fSVladimir Kondratiev { 10672be7d22fSVladimir Kondratiev uint i; 10682be7d22fSVladimir Kondratiev 10692be7d22fSVladimir Kondratiev for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) { 10702be7d22fSVladimir Kondratiev if (wmi_evt_handlers[i].eventid == id) { 10712be7d22fSVladimir Kondratiev wmi_evt_handlers[i].handler(wil, id, d, len); 10722be7d22fSVladimir Kondratiev return true; 10732be7d22fSVladimir Kondratiev } 10742be7d22fSVladimir Kondratiev } 10752be7d22fSVladimir Kondratiev 10762be7d22fSVladimir Kondratiev return false; 10772be7d22fSVladimir Kondratiev } 10782be7d22fSVladimir Kondratiev 10792be7d22fSVladimir Kondratiev static void wmi_event_handle(struct wil6210_priv *wil, 10802be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr *hdr) 10812be7d22fSVladimir Kondratiev { 10822be7d22fSVladimir Kondratiev u16 len = le16_to_cpu(hdr->len); 10832be7d22fSVladimir Kondratiev 10842be7d22fSVladimir Kondratiev if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) && 10852be7d22fSVladimir Kondratiev (len >= sizeof(struct wil6210_mbox_hdr_wmi))) { 10862be7d22fSVladimir Kondratiev struct wil6210_mbox_hdr_wmi *wmi = (void *)(&hdr[1]); 10872be7d22fSVladimir Kondratiev void *evt_data = (void *)(&wmi[1]); 10882be7d22fSVladimir Kondratiev u16 id = le16_to_cpu(wmi->id); 10892be7d22fSVladimir Kondratiev /* check if someone waits for this event */ 10902be7d22fSVladimir Kondratiev if (wil->reply_id && wil->reply_id == id) { 10912be7d22fSVladimir Kondratiev if (wil->reply_buf) { 10922be7d22fSVladimir Kondratiev memcpy(wil->reply_buf, wmi, 10932be7d22fSVladimir Kondratiev min(len, wil->reply_size)); 10942be7d22fSVladimir Kondratiev } else { 10952be7d22fSVladimir Kondratiev wmi_evt_call_handler(wil, id, evt_data, 10962be7d22fSVladimir Kondratiev len - sizeof(*wmi)); 10972be7d22fSVladimir Kondratiev } 10987743882dSVladimir Kondratiev wil_dbg_wmi(wil, "Complete WMI 0x%04x\n", id); 10992be7d22fSVladimir Kondratiev complete(&wil->wmi_ready); 11002be7d22fSVladimir Kondratiev return; 11012be7d22fSVladimir Kondratiev } 11022be7d22fSVladimir Kondratiev /* unsolicited event */ 11032be7d22fSVladimir Kondratiev /* search for handler */ 11042be7d22fSVladimir Kondratiev if (!wmi_evt_call_handler(wil, id, evt_data, 11052be7d22fSVladimir Kondratiev len - sizeof(*wmi))) { 11062be7d22fSVladimir Kondratiev wil_err(wil, "Unhandled event 0x%04x\n", id); 11072be7d22fSVladimir Kondratiev } 11082be7d22fSVladimir Kondratiev } else { 11092be7d22fSVladimir Kondratiev wil_err(wil, "Unknown event type\n"); 11102be7d22fSVladimir Kondratiev print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1, 11112be7d22fSVladimir Kondratiev hdr, sizeof(*hdr) + len, true); 11122be7d22fSVladimir Kondratiev } 11132be7d22fSVladimir Kondratiev } 11142be7d22fSVladimir Kondratiev 11152be7d22fSVladimir Kondratiev /* 11162be7d22fSVladimir Kondratiev * Retrieve next WMI event from the pending list 11172be7d22fSVladimir Kondratiev */ 11182be7d22fSVladimir Kondratiev static struct list_head *next_wmi_ev(struct wil6210_priv *wil) 11192be7d22fSVladimir Kondratiev { 11202be7d22fSVladimir Kondratiev ulong flags; 11212be7d22fSVladimir Kondratiev struct list_head *ret = NULL; 11222be7d22fSVladimir Kondratiev 11232be7d22fSVladimir Kondratiev spin_lock_irqsave(&wil->wmi_ev_lock, flags); 11242be7d22fSVladimir Kondratiev 11252be7d22fSVladimir Kondratiev if (!list_empty(&wil->pending_wmi_ev)) { 11262be7d22fSVladimir Kondratiev ret = wil->pending_wmi_ev.next; 11272be7d22fSVladimir Kondratiev list_del(ret); 11282be7d22fSVladimir Kondratiev } 11292be7d22fSVladimir Kondratiev 11302be7d22fSVladimir Kondratiev spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); 11312be7d22fSVladimir Kondratiev 11322be7d22fSVladimir Kondratiev return ret; 11332be7d22fSVladimir Kondratiev } 11342be7d22fSVladimir Kondratiev 11352be7d22fSVladimir Kondratiev /* 11362be7d22fSVladimir Kondratiev * Handler for the WMI events 11372be7d22fSVladimir Kondratiev */ 11382be7d22fSVladimir Kondratiev void wmi_event_worker(struct work_struct *work) 11392be7d22fSVladimir Kondratiev { 11402be7d22fSVladimir Kondratiev struct wil6210_priv *wil = container_of(work, struct wil6210_priv, 11412be7d22fSVladimir Kondratiev wmi_event_worker); 11422be7d22fSVladimir Kondratiev struct pending_wmi_event *evt; 11432be7d22fSVladimir Kondratiev struct list_head *lh; 11442be7d22fSVladimir Kondratiev 11452be7d22fSVladimir Kondratiev while ((lh = next_wmi_ev(wil)) != NULL) { 11462be7d22fSVladimir Kondratiev evt = list_entry(lh, struct pending_wmi_event, list); 11472be7d22fSVladimir Kondratiev wmi_event_handle(wil, &evt->event.hdr); 11482be7d22fSVladimir Kondratiev kfree(evt); 11492be7d22fSVladimir Kondratiev } 11502be7d22fSVladimir Kondratiev } 1151