Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 2 | * Copyright (c) 2012-2017 Qualcomm Atheros, Inc. |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, and/or distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
Dedy Lansky | 1eb9d1e | 2014-08-06 10:31:58 +0300 | [diff] [blame] | 17 | #include <linux/moduleparam.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 18 | #include <linux/etherdevice.h> |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 19 | #include <linux/if_arp.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 20 | |
| 21 | #include "wil6210.h" |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 22 | #include "txrx.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 23 | #include "wmi.h" |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 24 | #include "trace.h" |
Lior David | 8f1b5e0 | 2017-02-28 14:58:27 +0200 | [diff] [blame] | 25 | #include "ftm.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 26 | |
Vladimir Kondratiev | 327755f | 2014-12-23 09:47:13 +0200 | [diff] [blame] | 27 | static uint max_assoc_sta = WIL6210_MAX_CID; |
Maya Erez | c2256ec | 2017-02-08 13:18:42 +0200 | [diff] [blame] | 28 | module_param(max_assoc_sta, uint, 0644); |
Dedy Lansky | 1eb9d1e | 2014-08-06 10:31:58 +0300 | [diff] [blame] | 29 | MODULE_PARM_DESC(max_assoc_sta, " Max number of stations associated to the AP"); |
| 30 | |
Vladimir Kondratiev | 3a3def8 | 2014-12-23 09:47:05 +0200 | [diff] [blame] | 31 | int agg_wsize; /* = 0; */ |
Maya Erez | c2256ec | 2017-02-08 13:18:42 +0200 | [diff] [blame] | 32 | module_param(agg_wsize, int, 0644); |
Vladimir Kondratiev | 3a3def8 | 2014-12-23 09:47:05 +0200 | [diff] [blame] | 33 | MODULE_PARM_DESC(agg_wsize, " Window size for Tx Block Ack after connect;" |
| 34 | " 0 - use default; < 0 - don't auto-establish"); |
| 35 | |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 36 | u8 led_id = WIL_LED_INVALID_ID; |
Maya Erez | c2256ec | 2017-02-08 13:18:42 +0200 | [diff] [blame] | 37 | module_param(led_id, byte, 0444); |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 38 | MODULE_PARM_DESC(led_id, |
| 39 | " 60G device led enablement. Set the led ID (0-2) to enable"); |
| 40 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 41 | /** |
| 42 | * WMI event receiving - theory of operations |
| 43 | * |
| 44 | * When firmware about to report WMI event, it fills memory area |
| 45 | * in the mailbox and raises misc. IRQ. Thread interrupt handler invoked for |
| 46 | * the misc IRQ, function @wmi_recv_cmd called by thread IRQ handler. |
| 47 | * |
| 48 | * @wmi_recv_cmd reads event, allocates memory chunk and attaches it to the |
| 49 | * event list @wil->pending_wmi_ev. Then, work queue @wil->wmi_wq wakes up |
| 50 | * and handles events within the @wmi_event_worker. Every event get detached |
| 51 | * from list, processed and deleted. |
| 52 | * |
| 53 | * Purpose for this mechanism is to release IRQ thread; otherwise, |
| 54 | * if WMI event handling involves another WMI command flow, this 2-nd flow |
| 55 | * won't be completed because of blocked IRQ thread. |
| 56 | */ |
| 57 | |
| 58 | /** |
| 59 | * Addressing - theory of operations |
| 60 | * |
| 61 | * There are several buses present on the WIL6210 card. |
| 62 | * Same memory areas are visible at different address on |
| 63 | * the different busses. There are 3 main bus masters: |
| 64 | * - MAC CPU (ucode) |
| 65 | * - User CPU (firmware) |
| 66 | * - AHB (host) |
| 67 | * |
| 68 | * On the PCI bus, there is one BAR (BAR0) of 2Mb size, exposing |
| 69 | * AHB addresses starting from 0x880000 |
| 70 | * |
| 71 | * Internally, firmware uses addresses that allows faster access but |
| 72 | * are invisible from the host. To read from these addresses, alternative |
| 73 | * AHB address must be used. |
| 74 | * |
| 75 | * Memory mapping |
| 76 | * Linker address PCI/Host address |
| 77 | * 0x880000 .. 0xa80000 2Mb BAR0 |
| 78 | * 0x800000 .. 0x807000 0x900000 .. 0x907000 28k DCCM |
| 79 | * 0x840000 .. 0x857000 0x908000 .. 0x91f000 92k PERIPH |
| 80 | */ |
| 81 | |
| 82 | /** |
| 83 | * @fw_mapping provides memory remapping table |
Vladimir Kondratiev | b541d0a | 2014-07-14 09:49:41 +0300 | [diff] [blame] | 84 | * |
| 85 | * array size should be in sync with the declaration in the wil6210.h |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 86 | */ |
Vladimir Kondratiev | b541d0a | 2014-07-14 09:49:41 +0300 | [diff] [blame] | 87 | const struct fw_map fw_mapping[] = { |
Lior David | a6a0de1 | 2016-12-06 17:12:36 +0200 | [diff] [blame] | 88 | /* FW code RAM 256k */ |
| 89 | {0x000000, 0x040000, 0x8c0000, "fw_code", true}, |
| 90 | /* FW data RAM 32k */ |
| 91 | {0x800000, 0x808000, 0x900000, "fw_data", true}, |
| 92 | /* periph data 128k */ |
| 93 | {0x840000, 0x860000, 0x908000, "fw_peri", true}, |
| 94 | /* various RGF 40k */ |
| 95 | {0x880000, 0x88a000, 0x880000, "rgf", true}, |
| 96 | /* AGC table 4k */ |
| 97 | {0x88a000, 0x88b000, 0x88a000, "AGC_tbl", true}, |
| 98 | /* Pcie_ext_rgf 4k */ |
| 99 | {0x88b000, 0x88c000, 0x88b000, "rgf_ext", true}, |
| 100 | /* mac_ext_rgf 512b */ |
| 101 | {0x88c000, 0x88c200, 0x88c000, "mac_rgf_ext", true}, |
| 102 | /* upper area 548k */ |
| 103 | {0x8c0000, 0x949000, 0x8c0000, "upper", true}, |
| 104 | /* UCODE areas - accessible by debugfs blobs but not by |
| 105 | * wmi_addr_remap. UCODE areas MUST be added AFTER FW areas! |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 106 | */ |
Lior David | a6a0de1 | 2016-12-06 17:12:36 +0200 | [diff] [blame] | 107 | /* ucode code RAM 128k */ |
| 108 | {0x000000, 0x020000, 0x920000, "uc_code", false}, |
| 109 | /* ucode data RAM 16k */ |
| 110 | {0x800000, 0x804000, 0x940000, "uc_data", false}, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 113 | struct blink_on_off_time led_blink_time[] = { |
| 114 | {WIL_LED_BLINK_ON_SLOW_MS, WIL_LED_BLINK_OFF_SLOW_MS}, |
| 115 | {WIL_LED_BLINK_ON_MED_MS, WIL_LED_BLINK_OFF_MED_MS}, |
| 116 | {WIL_LED_BLINK_ON_FAST_MS, WIL_LED_BLINK_OFF_FAST_MS}, |
| 117 | }; |
| 118 | |
| 119 | u8 led_polarity = LED_POLARITY_LOW_ACTIVE; |
| 120 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 121 | /** |
Lior David | a6a0de1 | 2016-12-06 17:12:36 +0200 | [diff] [blame] | 122 | * return AHB address for given firmware internal (linker) address |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 123 | * @x - internal address |
| 124 | * If address have no valid AHB mapping, return 0 |
| 125 | */ |
| 126 | static u32 wmi_addr_remap(u32 x) |
| 127 | { |
| 128 | uint i; |
| 129 | |
| 130 | for (i = 0; i < ARRAY_SIZE(fw_mapping); i++) { |
Lior David | a6a0de1 | 2016-12-06 17:12:36 +0200 | [diff] [blame] | 131 | if (fw_mapping[i].fw && |
| 132 | ((x >= fw_mapping[i].from) && (x < fw_mapping[i].to))) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 133 | return x + fw_mapping[i].host - fw_mapping[i].from; |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Check address validity for WMI buffer; remap if needed |
| 141 | * @ptr - internal (linker) fw/ucode address |
| 142 | * |
| 143 | * Valid buffer should be DWORD aligned |
| 144 | * |
| 145 | * return address for accessing buffer from the host; |
| 146 | * if buffer is not valid, return NULL. |
| 147 | */ |
| 148 | void __iomem *wmi_buffer(struct wil6210_priv *wil, __le32 ptr_) |
| 149 | { |
| 150 | u32 off; |
| 151 | u32 ptr = le32_to_cpu(ptr_); |
| 152 | |
| 153 | if (ptr % 4) |
| 154 | return NULL; |
| 155 | |
| 156 | ptr = wmi_addr_remap(ptr); |
| 157 | if (ptr < WIL6210_FW_HOST_OFF) |
| 158 | return NULL; |
| 159 | |
| 160 | off = HOSTADDR(ptr); |
| 161 | if (off > WIL6210_MEM_SIZE - 4) |
| 162 | return NULL; |
| 163 | |
| 164 | return wil->csr + off; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Check address validity |
| 169 | */ |
| 170 | void __iomem *wmi_addr(struct wil6210_priv *wil, u32 ptr) |
| 171 | { |
| 172 | u32 off; |
| 173 | |
| 174 | if (ptr % 4) |
| 175 | return NULL; |
| 176 | |
| 177 | if (ptr < WIL6210_FW_HOST_OFF) |
| 178 | return NULL; |
| 179 | |
| 180 | off = HOSTADDR(ptr); |
| 181 | if (off > WIL6210_MEM_SIZE - 4) |
| 182 | return NULL; |
| 183 | |
| 184 | return wil->csr + off; |
| 185 | } |
| 186 | |
| 187 | int wmi_read_hdr(struct wil6210_priv *wil, __le32 ptr, |
| 188 | struct wil6210_mbox_hdr *hdr) |
| 189 | { |
| 190 | void __iomem *src = wmi_buffer(wil, ptr); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 191 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 192 | if (!src) |
| 193 | return -EINVAL; |
| 194 | |
| 195 | wil_memcpy_fromio_32(hdr, src, sizeof(*hdr)); |
| 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | static int __wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) |
| 201 | { |
| 202 | struct { |
| 203 | struct wil6210_mbox_hdr hdr; |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 204 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 205 | } __packed cmd = { |
| 206 | .hdr = { |
| 207 | .type = WIL_MBOX_HDR_TYPE_WMI, |
| 208 | .flags = 0, |
| 209 | .len = cpu_to_le16(sizeof(cmd.wmi) + len), |
| 210 | }, |
| 211 | .wmi = { |
Vladimir Kondratiev | f988b23 | 2013-07-11 18:03:37 +0300 | [diff] [blame] | 212 | .mid = 0, |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 213 | .command_id = cpu_to_le16(cmdid), |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 214 | }, |
| 215 | }; |
| 216 | struct wil6210_mbox_ring *r = &wil->mbox_ctl.tx; |
| 217 | struct wil6210_mbox_ring_desc d_head; |
| 218 | u32 next_head; |
| 219 | void __iomem *dst; |
| 220 | void __iomem *head = wmi_addr(wil, r->head); |
| 221 | uint retry; |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 222 | int rc = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 223 | |
| 224 | if (sizeof(cmd) + len > r->entry_size) { |
| 225 | wil_err(wil, "WMI size too large: %d bytes, max is %d\n", |
| 226 | (int)(sizeof(cmd) + len), r->entry_size); |
| 227 | return -ERANGE; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | might_sleep(); |
| 231 | |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 232 | if (!test_bit(wil_status_fwready, wil->status)) { |
Vladimir Kondratiev | 15e2312 | 2014-04-08 11:36:16 +0300 | [diff] [blame] | 233 | wil_err(wil, "WMI: cannot send command while FW not ready\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 234 | return -EAGAIN; |
| 235 | } |
| 236 | |
| 237 | if (!head) { |
| 238 | wil_err(wil, "WMI head is garbage: 0x%08x\n", r->head); |
| 239 | return -EINVAL; |
| 240 | } |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 241 | |
| 242 | wil_halp_vote(wil); |
| 243 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 244 | /* read Tx head till it is not busy */ |
| 245 | for (retry = 5; retry > 0; retry--) { |
| 246 | wil_memcpy_fromio_32(&d_head, head, sizeof(d_head)); |
| 247 | if (d_head.sync == 0) |
| 248 | break; |
| 249 | msleep(20); |
| 250 | } |
| 251 | if (d_head.sync != 0) { |
| 252 | wil_err(wil, "WMI head busy\n"); |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 253 | rc = -EBUSY; |
| 254 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 255 | } |
| 256 | /* next head */ |
| 257 | next_head = r->base + ((r->head - r->base + sizeof(d_head)) % r->size); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 258 | wil_dbg_wmi(wil, "Head 0x%08x -> 0x%08x\n", r->head, next_head); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 259 | /* wait till FW finish with previous command */ |
| 260 | for (retry = 5; retry > 0; retry--) { |
Maya Erez | 452133a | 2015-11-24 09:30:15 +0200 | [diff] [blame] | 261 | if (!test_bit(wil_status_fwready, wil->status)) { |
| 262 | wil_err(wil, "WMI: cannot send command while FW not ready\n"); |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 263 | rc = -EAGAIN; |
| 264 | goto out; |
Maya Erez | 452133a | 2015-11-24 09:30:15 +0200 | [diff] [blame] | 265 | } |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 266 | r->tail = wil_r(wil, RGF_MBOX + |
| 267 | offsetof(struct wil6210_mbox_ctl, tx.tail)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 268 | if (next_head != r->tail) |
| 269 | break; |
| 270 | msleep(20); |
| 271 | } |
| 272 | if (next_head == r->tail) { |
| 273 | wil_err(wil, "WMI ring full\n"); |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 274 | rc = -EBUSY; |
| 275 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 276 | } |
| 277 | dst = wmi_buffer(wil, d_head.addr); |
| 278 | if (!dst) { |
| 279 | wil_err(wil, "invalid WMI buffer: 0x%08x\n", |
| 280 | le32_to_cpu(d_head.addr)); |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 281 | rc = -EAGAIN; |
| 282 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 283 | } |
| 284 | cmd.hdr.seq = cpu_to_le16(++wil->wmi_seq); |
| 285 | /* set command */ |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 286 | wil_dbg_wmi(wil, "WMI command 0x%04x [%d]\n", cmdid, len); |
| 287 | wil_hex_dump_wmi("Cmd ", DUMP_PREFIX_OFFSET, 16, 1, &cmd, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 288 | sizeof(cmd), true); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 289 | wil_hex_dump_wmi("cmd ", DUMP_PREFIX_OFFSET, 16, 1, buf, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 290 | len, true); |
| 291 | wil_memcpy_toio_32(dst, &cmd, sizeof(cmd)); |
| 292 | wil_memcpy_toio_32(dst + sizeof(cmd), buf, len); |
| 293 | /* mark entry as full */ |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 294 | wil_w(wil, r->head + offsetof(struct wil6210_mbox_ring_desc, sync), 1); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 295 | /* advance next ptr */ |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 296 | wil_w(wil, RGF_MBOX + offsetof(struct wil6210_mbox_ctl, tx.head), |
| 297 | r->head = next_head); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 298 | |
Vladimir Kondratiev | f988b23 | 2013-07-11 18:03:37 +0300 | [diff] [blame] | 299 | trace_wil6210_wmi_cmd(&cmd.wmi, buf, len); |
Vladimir Kondratiev | 9865809 | 2013-05-12 14:43:35 +0300 | [diff] [blame] | 300 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 301 | /* interrupt to FW */ |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 302 | wil_w(wil, RGF_USER_USER_ICR + offsetof(struct RGF_ICR, ICS), |
| 303 | SW_INT_MBOX); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 304 | |
Maya Erez | 349214c | 2016-04-26 14:41:41 +0300 | [diff] [blame] | 305 | out: |
| 306 | wil_halp_unvote(wil); |
| 307 | return rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | int wmi_send(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len) |
| 311 | { |
| 312 | int rc; |
| 313 | |
| 314 | mutex_lock(&wil->wmi_mutex); |
| 315 | rc = __wmi_send(wil, cmdid, buf, len); |
| 316 | mutex_unlock(&wil->wmi_mutex); |
| 317 | |
| 318 | return rc; |
| 319 | } |
| 320 | |
| 321 | /*=== Event handlers ===*/ |
| 322 | static void wmi_evt_ready(struct wil6210_priv *wil, int id, void *d, int len) |
| 323 | { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 324 | struct wireless_dev *wdev = wil->wdev; |
| 325 | struct wmi_ready_event *evt = d; |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 326 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 327 | wil->n_mids = evt->numof_additional_mids; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 328 | |
Lior David | 13cd9f7 | 2016-08-22 12:42:22 +0300 | [diff] [blame] | 329 | wil_info(wil, "FW ver. %s(SW %d); MAC %pM; %d MID's\n", |
| 330 | wil->fw_version, le32_to_cpu(evt->sw_version), |
Vladimir Kondratiev | 15e2312 | 2014-04-08 11:36:16 +0300 | [diff] [blame] | 331 | evt->mac, wil->n_mids); |
Vladimir Kondratiev | 2cd0f02 | 2015-02-15 14:02:30 +0200 | [diff] [blame] | 332 | /* ignore MAC address, we already have it from the boot loader */ |
Lior David | 13cd9f7 | 2016-08-22 12:42:22 +0300 | [diff] [blame] | 333 | strlcpy(wdev->wiphy->fw_version, wil->fw_version, |
| 334 | sizeof(wdev->wiphy->fw_version)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 335 | |
Vladimir Kondratiev | c33407a | 2014-10-01 15:05:24 +0300 | [diff] [blame] | 336 | wil_set_recovery_state(wil, fw_recovery_idle); |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 337 | set_bit(wil_status_fwready, wil->status); |
Dedy Lansky | 5950264 | 2014-09-10 16:34:46 +0300 | [diff] [blame] | 338 | /* let the reset sequence continue */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 339 | complete(&wil->wmi_ready); |
| 340 | } |
| 341 | |
| 342 | static void wmi_evt_rx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) |
| 343 | { |
| 344 | struct wmi_rx_mgmt_packet_event *data = d; |
| 345 | struct wiphy *wiphy = wil_to_wiphy(wil); |
| 346 | struct ieee80211_mgmt *rx_mgmt_frame = |
| 347 | (struct ieee80211_mgmt *)data->payload; |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 348 | int flen = len - offsetof(struct wmi_rx_mgmt_packet_event, payload); |
| 349 | int ch_no; |
| 350 | u32 freq; |
| 351 | struct ieee80211_channel *channel; |
| 352 | s32 signal; |
| 353 | __le16 fc; |
| 354 | u32 d_len; |
| 355 | u16 d_status; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 356 | |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 357 | if (flen < 0) { |
| 358 | wil_err(wil, "MGMT Rx: short event, len %d\n", len); |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | d_len = le32_to_cpu(data->info.len); |
| 363 | if (d_len != flen) { |
| 364 | wil_err(wil, |
| 365 | "MGMT Rx: length mismatch, d_len %d should be %d\n", |
| 366 | d_len, flen); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | ch_no = data->info.channel + 1; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 371 | freq = ieee80211_channel_to_frequency(ch_no, NL80211_BAND_60GHZ); |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 372 | channel = ieee80211_get_channel(wiphy, freq); |
| 373 | signal = data->info.sqi; |
| 374 | d_status = le16_to_cpu(data->info.status); |
| 375 | fc = rx_mgmt_frame->frame_control; |
| 376 | |
| 377 | wil_dbg_wmi(wil, "MGMT Rx: channel %d MCS %d SNR %d SQI %d%%\n", |
Vladimir Kondratiev | b8b33a3 | 2014-02-27 16:20:52 +0200 | [diff] [blame] | 378 | data->info.channel, data->info.mcs, data->info.snr, |
| 379 | data->info.sqi); |
Vladimir Kondratiev | f27dbf7 | 2013-06-09 09:12:52 +0300 | [diff] [blame] | 380 | wil_dbg_wmi(wil, "status 0x%04x len %d fc 0x%04x\n", d_status, d_len, |
| 381 | le16_to_cpu(fc)); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 382 | wil_dbg_wmi(wil, "qid %d mid %d cid %d\n", |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 383 | data->info.qid, data->info.mid, data->info.cid); |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 384 | wil_hex_dump_wmi("MGMT Rx ", DUMP_PREFIX_OFFSET, 16, 1, rx_mgmt_frame, |
| 385 | d_len, true); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 386 | |
| 387 | if (!channel) { |
| 388 | wil_err(wil, "Frame on unsupported channel\n"); |
| 389 | return; |
| 390 | } |
| 391 | |
| 392 | if (ieee80211_is_beacon(fc) || ieee80211_is_probe_resp(fc)) { |
| 393 | struct cfg80211_bss *bss; |
Vladimir Kondratiev | 8eea944 | 2014-06-16 19:37:03 +0300 | [diff] [blame] | 394 | u64 tsf = le64_to_cpu(rx_mgmt_frame->u.beacon.timestamp); |
| 395 | u16 cap = le16_to_cpu(rx_mgmt_frame->u.beacon.capab_info); |
| 396 | u16 bi = le16_to_cpu(rx_mgmt_frame->u.beacon.beacon_int); |
| 397 | const u8 *ie_buf = rx_mgmt_frame->u.beacon.variable; |
| 398 | size_t ie_len = d_len - offsetof(struct ieee80211_mgmt, |
| 399 | u.beacon.variable); |
| 400 | wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap); |
| 401 | wil_dbg_wmi(wil, "TSF : 0x%016llx\n", tsf); |
| 402 | wil_dbg_wmi(wil, "Beacon interval : %d\n", bi); |
| 403 | wil_hex_dump_wmi("IE ", DUMP_PREFIX_OFFSET, 16, 1, ie_buf, |
| 404 | ie_len, true); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 405 | |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 406 | wil_dbg_wmi(wil, "Capability info : 0x%04x\n", cap); |
| 407 | |
Vladimir Kondratiev | a0f7845 | 2013-03-13 14:12:44 +0200 | [diff] [blame] | 408 | bss = cfg80211_inform_bss_frame(wiphy, channel, rx_mgmt_frame, |
| 409 | d_len, signal, GFP_KERNEL); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 410 | if (bss) { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 411 | wil_dbg_wmi(wil, "Added BSS %pM\n", |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 412 | rx_mgmt_frame->bssid); |
Johannes Berg | 5b112d3 | 2013-02-01 01:49:58 +0100 | [diff] [blame] | 413 | cfg80211_put_bss(wiphy, bss); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 414 | } else { |
Johannes Berg | 5bc8c1f | 2014-08-12 21:01:28 +0200 | [diff] [blame] | 415 | wil_err(wil, "cfg80211_inform_bss_frame() failed\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 416 | } |
Vladimir Kondratiev | 102b1d9 | 2013-03-13 14:12:45 +0200 | [diff] [blame] | 417 | } else { |
Lior David | 4332cac | 2016-03-01 19:18:13 +0200 | [diff] [blame] | 418 | mutex_lock(&wil->p2p_wdev_mutex); |
| 419 | cfg80211_rx_mgmt(wil->radio_wdev, freq, signal, |
Vladimir Kondratiev | 970fdfa | 2014-08-11 03:29:57 -0700 | [diff] [blame] | 420 | (void *)rx_mgmt_frame, d_len, 0); |
Lior David | 4332cac | 2016-03-01 19:18:13 +0200 | [diff] [blame] | 421 | mutex_unlock(&wil->p2p_wdev_mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 425 | static void wmi_evt_tx_mgmt(struct wil6210_priv *wil, int id, void *d, int len) |
| 426 | { |
| 427 | struct wmi_tx_mgmt_packet_event *data = d; |
| 428 | struct ieee80211_mgmt *mgmt_frame = |
| 429 | (struct ieee80211_mgmt *)data->payload; |
| 430 | int flen = len - offsetof(struct wmi_tx_mgmt_packet_event, payload); |
| 431 | |
| 432 | wil_hex_dump_wmi("MGMT Tx ", DUMP_PREFIX_OFFSET, 16, 1, mgmt_frame, |
| 433 | flen, true); |
| 434 | } |
| 435 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 436 | static void wmi_evt_scan_complete(struct wil6210_priv *wil, int id, |
| 437 | void *d, int len) |
| 438 | { |
Lior David | 5ffae43 | 2016-08-22 12:42:19 +0300 | [diff] [blame] | 439 | mutex_lock(&wil->p2p_wdev_mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 440 | if (wil->scan_request) { |
| 441 | struct wmi_scan_complete_event *data = d; |
Maya Erez | 4cbb585 | 2017-02-16 15:26:09 +0200 | [diff] [blame] | 442 | int status = le32_to_cpu(data->status); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 443 | struct cfg80211_scan_info info = { |
Maya Erez | 4cbb585 | 2017-02-16 15:26:09 +0200 | [diff] [blame] | 444 | .aborted = ((status != WMI_SCAN_SUCCESS) && |
| 445 | (status != WMI_SCAN_ABORT_REJECTED)), |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 446 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 447 | |
Maya Erez | 4cbb585 | 2017-02-16 15:26:09 +0200 | [diff] [blame] | 448 | wil_dbg_wmi(wil, "SCAN_COMPLETE(0x%08x)\n", status); |
Vladimir Kondratiev | 2a91d7d | 2014-06-16 19:37:11 +0300 | [diff] [blame] | 449 | wil_dbg_misc(wil, "Complete scan_request 0x%p aborted %d\n", |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 450 | wil->scan_request, info.aborted); |
Vladimir Kondratiev | 047e5d7 | 2014-05-27 14:45:48 +0300 | [diff] [blame] | 451 | del_timer_sync(&wil->scan_timer); |
Avraham Stern | 1d76250 | 2016-07-05 17:10:13 +0300 | [diff] [blame] | 452 | cfg80211_scan_done(wil->scan_request, &info); |
Lior David | 4332cac | 2016-03-01 19:18:13 +0200 | [diff] [blame] | 453 | wil->radio_wdev = wil->wdev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 454 | wil->scan_request = NULL; |
Maya Erez | 4cbb585 | 2017-02-16 15:26:09 +0200 | [diff] [blame] | 455 | wake_up_interruptible(&wil->wq); |
Lior David | 42ba1c22 | 2017-02-15 20:37:20 +0200 | [diff] [blame] | 456 | if (wil->p2p.pending_listen_wdev) { |
| 457 | wil_dbg_misc(wil, "Scheduling delayed listen\n"); |
| 458 | schedule_work(&wil->p2p.delayed_listen_work); |
| 459 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 460 | } else { |
| 461 | wil_err(wil, "SCAN_COMPLETE while not scanning\n"); |
| 462 | } |
Lior David | 5ffae43 | 2016-08-22 12:42:19 +0300 | [diff] [blame] | 463 | mutex_unlock(&wil->p2p_wdev_mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | static void wmi_evt_connect(struct wil6210_priv *wil, int id, void *d, int len) |
| 467 | { |
| 468 | struct net_device *ndev = wil_to_ndev(wil); |
| 469 | struct wireless_dev *wdev = wil->wdev; |
| 470 | struct wmi_connect_event *evt = d; |
| 471 | int ch; /* channel number */ |
| 472 | struct station_info sinfo; |
| 473 | u8 *assoc_req_ie, *assoc_resp_ie; |
| 474 | size_t assoc_req_ielen, assoc_resp_ielen; |
| 475 | /* capinfo(u16) + listen_interval(u16) + IEs */ |
| 476 | const size_t assoc_req_ie_offset = sizeof(u16) * 2; |
| 477 | /* capinfo(u16) + status_code(u16) + associd(u16) + IEs */ |
| 478 | const size_t assoc_resp_ie_offset = sizeof(u16) * 3; |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 479 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 480 | |
| 481 | if (len < sizeof(*evt)) { |
| 482 | wil_err(wil, "Connect event too short : %d bytes\n", len); |
| 483 | return; |
| 484 | } |
| 485 | if (len != sizeof(*evt) + evt->beacon_ie_len + evt->assoc_req_len + |
| 486 | evt->assoc_resp_len) { |
| 487 | wil_err(wil, |
| 488 | "Connect event corrupted : %d != %d + %d + %d + %d\n", |
| 489 | len, (int)sizeof(*evt), evt->beacon_ie_len, |
| 490 | evt->assoc_req_len, evt->assoc_resp_len); |
| 491 | return; |
| 492 | } |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 493 | if (evt->cid >= WIL6210_MAX_CID) { |
| 494 | wil_err(wil, "Connect CID invalid : %d\n", evt->cid); |
| 495 | return; |
| 496 | } |
| 497 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 498 | ch = evt->channel + 1; |
Lior David | a762979 | 2017-02-08 13:16:37 +0200 | [diff] [blame] | 499 | wil_info(wil, "Connect %pM channel [%d] cid %d aid %d\n", |
| 500 | evt->bssid, ch, evt->cid, evt->aid); |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 501 | wil_hex_dump_wmi("connect AI : ", DUMP_PREFIX_OFFSET, 16, 1, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 502 | evt->assoc_info, len - sizeof(*evt), true); |
| 503 | |
| 504 | /* figure out IE's */ |
| 505 | assoc_req_ie = &evt->assoc_info[evt->beacon_ie_len + |
| 506 | assoc_req_ie_offset]; |
| 507 | assoc_req_ielen = evt->assoc_req_len - assoc_req_ie_offset; |
| 508 | if (evt->assoc_req_len <= assoc_req_ie_offset) { |
| 509 | assoc_req_ie = NULL; |
| 510 | assoc_req_ielen = 0; |
| 511 | } |
| 512 | |
| 513 | assoc_resp_ie = &evt->assoc_info[evt->beacon_ie_len + |
| 514 | evt->assoc_req_len + |
| 515 | assoc_resp_ie_offset]; |
| 516 | assoc_resp_ielen = evt->assoc_resp_len - assoc_resp_ie_offset; |
| 517 | if (evt->assoc_resp_len <= assoc_resp_ie_offset) { |
| 518 | assoc_resp_ie = NULL; |
| 519 | assoc_resp_ielen = 0; |
| 520 | } |
| 521 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 522 | mutex_lock(&wil->mutex); |
| 523 | if (test_bit(wil_status_resetting, wil->status) || |
| 524 | !test_bit(wil_status_fwready, wil->status)) { |
| 525 | wil_err(wil, "status_resetting, cancel connect event, CID %d\n", |
| 526 | evt->cid); |
| 527 | mutex_unlock(&wil->mutex); |
| 528 | /* no need for cleanup, wil_reset will do that */ |
| 529 | return; |
| 530 | } |
| 531 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 532 | if ((wdev->iftype == NL80211_IFTYPE_STATION) || |
| 533 | (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 534 | if (!test_bit(wil_status_fwconnecting, wil->status)) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 535 | wil_err(wil, "Not in connecting state\n"); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 536 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 537 | return; |
| 538 | } |
| 539 | del_timer_sync(&wil->connect_timer); |
Maya Erez | 3d287fb | 2016-03-01 19:18:05 +0200 | [diff] [blame] | 540 | } else if ((wdev->iftype == NL80211_IFTYPE_AP) || |
| 541 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { |
| 542 | if (wil->sta[evt->cid].status != wil_sta_unused) { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 543 | wil_err(wil, "AP: Invalid status %d for CID %d\n", |
| 544 | wil->sta[evt->cid].status, evt->cid); |
Maya Erez | 3d287fb | 2016-03-01 19:18:05 +0200 | [diff] [blame] | 545 | mutex_unlock(&wil->mutex); |
| 546 | return; |
| 547 | } |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 548 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 549 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 550 | /* FIXME FW can transmit only ucast frames to peer */ |
| 551 | /* FIXME real ring_id instead of hard coded 0 */ |
| 552 | ether_addr_copy(wil->sta[evt->cid].addr, evt->bssid); |
| 553 | wil->sta[evt->cid].status = wil_sta_conn_pending; |
| 554 | |
| 555 | rc = wil_tx_init(wil, evt->cid); |
| 556 | if (rc) { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 557 | wil_err(wil, "config tx vring failed for CID %d, rc (%d)\n", |
| 558 | evt->cid, rc); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 559 | wmi_disconnect_sta(wil, wil->sta[evt->cid].addr, |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 560 | WLAN_REASON_UNSPECIFIED, false, false); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 561 | } else { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 562 | wil_info(wil, "successful connection to CID %d\n", evt->cid); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | if ((wdev->iftype == NL80211_IFTYPE_STATION) || |
| 566 | (wdev->iftype == NL80211_IFTYPE_P2P_CLIENT)) { |
| 567 | if (rc) { |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 568 | netif_carrier_off(ndev); |
Lior David | 704099f | 2017-05-04 21:31:02 +0300 | [diff] [blame] | 569 | wil6210_bus_request(wil, WIL_DEFAULT_BUS_REQUEST_KBPS); |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 570 | wil_err(wil, "cfg80211_connect_result with failure\n"); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 571 | cfg80211_connect_result(ndev, evt->bssid, NULL, 0, |
| 572 | NULL, 0, |
| 573 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 574 | GFP_KERNEL); |
| 575 | goto out; |
| 576 | } else { |
Dedy Lansky | a488278 | 2017-05-04 21:36:09 +0300 | [diff] [blame] | 577 | struct wiphy *wiphy = wil_to_wiphy(wil); |
| 578 | |
| 579 | cfg80211_ref_bss(wiphy, wil->bss); |
| 580 | cfg80211_connect_bss(ndev, evt->bssid, wil->bss, |
| 581 | assoc_req_ie, assoc_req_ielen, |
| 582 | assoc_resp_ie, assoc_resp_ielen, |
| 583 | WLAN_STATUS_SUCCESS, GFP_KERNEL, |
| 584 | NL80211_TIMEOUT_UNSPECIFIED); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 585 | } |
Dedy Lansky | a488278 | 2017-05-04 21:36:09 +0300 | [diff] [blame] | 586 | wil->bss = NULL; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 587 | } else if ((wdev->iftype == NL80211_IFTYPE_AP) || |
| 588 | (wdev->iftype == NL80211_IFTYPE_P2P_GO)) { |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 589 | if (rc) { |
| 590 | if (disable_ap_sme) |
| 591 | /* notify new_sta has failed */ |
| 592 | cfg80211_del_sta(ndev, evt->bssid, GFP_KERNEL); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 593 | goto out; |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 594 | } |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 595 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 596 | memset(&sinfo, 0, sizeof(sinfo)); |
| 597 | |
| 598 | sinfo.generation = wil->sinfo_gen++; |
| 599 | |
| 600 | if (assoc_req_ie) { |
| 601 | sinfo.assoc_req_ies = assoc_req_ie; |
| 602 | sinfo.assoc_req_ies_len = assoc_req_ielen; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | cfg80211_new_sta(ndev, evt->bssid, &sinfo, GFP_KERNEL); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 606 | } else { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 607 | wil_err(wil, "unhandled iftype %d for CID %d\n", wdev->iftype, |
| 608 | evt->cid); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 609 | goto out; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 610 | } |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 611 | |
| 612 | wil->sta[evt->cid].status = wil_sta_connected; |
Lior David | a762979 | 2017-02-08 13:16:37 +0200 | [diff] [blame] | 613 | wil->sta[evt->cid].aid = evt->aid; |
Vladimir Kondratiev | 9419b6a | 2014-12-23 09:47:14 +0200 | [diff] [blame] | 614 | set_bit(wil_status_fwconnected, wil->status); |
Dedy Lansky | 970a98f | 2016-12-06 08:26:49 +0200 | [diff] [blame] | 615 | wil_update_net_queues_bh(wil, NULL, false); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 616 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 617 | out: |
| 618 | if (rc) |
| 619 | wil->sta[evt->cid].status = wil_sta_unused; |
| 620 | clear_bit(wil_status_fwconnecting, wil->status); |
| 621 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | static void wmi_evt_disconnect(struct wil6210_priv *wil, int id, |
| 625 | void *d, int len) |
| 626 | { |
| 627 | struct wmi_disconnect_event *evt = d; |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 628 | u16 reason_code = le16_to_cpu(evt->protocol_reason_status); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 629 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 630 | wil_info(wil, "Disconnect %pM reason [proto %d wmi %d]\n", |
| 631 | evt->bssid, reason_code, evt->disconnect_reason); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 632 | |
| 633 | wil->sinfo_gen++; |
| 634 | |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 635 | mutex_lock(&wil->mutex); |
Vladimir Kondratiev | 4821e6d | 2014-12-01 15:33:15 +0200 | [diff] [blame] | 636 | wil6210_disconnect(wil, evt->bssid, reason_code, true); |
Vladimir Kondratiev | 097638a | 2014-03-17 15:34:25 +0200 | [diff] [blame] | 637 | mutex_unlock(&wil->mutex); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 638 | } |
| 639 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 640 | /* |
| 641 | * Firmware reports EAPOL frame using WME event. |
| 642 | * Reconstruct Ethernet frame and deliver it via normal Rx |
| 643 | */ |
| 644 | static void wmi_evt_eapol_rx(struct wil6210_priv *wil, int id, |
| 645 | void *d, int len) |
| 646 | { |
| 647 | struct net_device *ndev = wil_to_ndev(wil); |
| 648 | struct wmi_eapol_rx_event *evt = d; |
| 649 | u16 eapol_len = le16_to_cpu(evt->eapol_len); |
| 650 | int sz = eapol_len + ETH_HLEN; |
| 651 | struct sk_buff *skb; |
| 652 | struct ethhdr *eth; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 653 | int cid; |
| 654 | struct wil_net_stats *stats = NULL; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 655 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 656 | wil_dbg_wmi(wil, "EAPOL len %d from %pM\n", eapol_len, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 657 | evt->src_mac); |
| 658 | |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 659 | cid = wil_find_cid(wil, evt->src_mac); |
| 660 | if (cid >= 0) |
| 661 | stats = &wil->sta[cid].stats; |
| 662 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 663 | if (eapol_len > 196) { /* TODO: revisit size limit */ |
| 664 | wil_err(wil, "EAPOL too large\n"); |
| 665 | return; |
| 666 | } |
| 667 | |
| 668 | skb = alloc_skb(sz, GFP_KERNEL); |
| 669 | if (!skb) { |
| 670 | wil_err(wil, "Failed to allocate skb\n"); |
| 671 | return; |
| 672 | } |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 673 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 674 | eth = (struct ethhdr *)skb_put(skb, ETH_HLEN); |
Vladimir Kondratiev | a82553bb | 2015-03-15 16:00:21 +0200 | [diff] [blame] | 675 | ether_addr_copy(eth->h_dest, ndev->dev_addr); |
| 676 | ether_addr_copy(eth->h_source, evt->src_mac); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 677 | eth->h_proto = cpu_to_be16(ETH_P_PAE); |
| 678 | memcpy(skb_put(skb, eapol_len), evt->eapol, eapol_len); |
| 679 | skb->protocol = eth_type_trans(skb, ndev); |
| 680 | if (likely(netif_rx_ni(skb) == NET_RX_SUCCESS)) { |
| 681 | ndev->stats.rx_packets++; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 682 | ndev->stats.rx_bytes += sz; |
| 683 | if (stats) { |
| 684 | stats->rx_packets++; |
| 685 | stats->rx_bytes += sz; |
| 686 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 687 | } else { |
| 688 | ndev->stats.rx_dropped++; |
Vladimir Kondratiev | c8b78b5 | 2014-02-27 16:20:49 +0200 | [diff] [blame] | 689 | if (stats) |
| 690 | stats->rx_dropped++; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 691 | } |
| 692 | } |
| 693 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 694 | static void wmi_evt_vring_en(struct wil6210_priv *wil, int id, void *d, int len) |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 695 | { |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 696 | struct wmi_vring_en_event *evt = d; |
| 697 | u8 vri = evt->vring_index; |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 698 | struct wireless_dev *wdev = wil_to_wdev(wil); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 699 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 700 | wil_dbg_wmi(wil, "Enable vring %d\n", vri); |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 701 | |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 702 | if (vri >= ARRAY_SIZE(wil->vring_tx)) { |
| 703 | wil_err(wil, "Enable for invalid vring %d\n", vri); |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 704 | return; |
| 705 | } |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 706 | |
| 707 | if (wdev->iftype != NL80211_IFTYPE_AP || !disable_ap_sme) |
| 708 | /* in AP mode with disable_ap_sme, this is done by |
| 709 | * wil_cfg80211_change_station() |
| 710 | */ |
| 711 | wil->vring_tx_data[vri].dot1x_open = true; |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 712 | if (vri == wil->bcast_vring) /* no BA for bcast */ |
| 713 | return; |
Vladimir Kondratiev | 3a3def8 | 2014-12-23 09:47:05 +0200 | [diff] [blame] | 714 | if (agg_wsize >= 0) |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 715 | wil_addba_tx_request(wil, vri, agg_wsize); |
Vladimir Kondratiev | 3442a50 | 2013-03-13 14:12:39 +0200 | [diff] [blame] | 716 | } |
| 717 | |
Vladimir Kondratiev | 249a382 | 2013-03-13 14:12:40 +0200 | [diff] [blame] | 718 | static void wmi_evt_ba_status(struct wil6210_priv *wil, int id, void *d, |
| 719 | int len) |
| 720 | { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 721 | struct wmi_ba_status_event *evt = d; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 722 | struct vring_tx_data *txdata; |
Vladimir Kondratiev | 249a382 | 2013-03-13 14:12:40 +0200 | [diff] [blame] | 723 | |
Vladimir Kondratiev | cbcf586 | 2014-12-23 09:47:09 +0200 | [diff] [blame] | 724 | wil_dbg_wmi(wil, "BACK[%d] %s {%d} timeout %d AMSDU%s\n", |
Vladimir Kondratiev | 7b05b0a | 2014-02-27 16:20:47 +0200 | [diff] [blame] | 725 | evt->ringid, |
| 726 | evt->status == WMI_BA_AGREED ? "OK" : "N/A", |
Vladimir Kondratiev | cbcf586 | 2014-12-23 09:47:09 +0200 | [diff] [blame] | 727 | evt->agg_wsize, __le16_to_cpu(evt->ba_timeout), |
| 728 | evt->amsdu ? "+" : "-"); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 729 | |
Vladimir Kondratiev | 7b05b0a | 2014-02-27 16:20:47 +0200 | [diff] [blame] | 730 | if (evt->ringid >= WIL6210_MAX_TX_RINGS) { |
| 731 | wil_err(wil, "invalid ring id %d\n", evt->ringid); |
| 732 | return; |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 733 | } |
| 734 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 735 | if (evt->status != WMI_BA_AGREED) { |
| 736 | evt->ba_timeout = 0; |
| 737 | evt->agg_wsize = 0; |
Vladimir Kondratiev | cbcf586 | 2014-12-23 09:47:09 +0200 | [diff] [blame] | 738 | evt->amsdu = 0; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 739 | } |
Dedy Lansky | 8c86f75 | 2014-09-10 16:34:40 +0300 | [diff] [blame] | 740 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 741 | txdata = &wil->vring_tx_data[evt->ringid]; |
| 742 | |
| 743 | txdata->agg_timeout = le16_to_cpu(evt->ba_timeout); |
| 744 | txdata->agg_wsize = evt->agg_wsize; |
Vladimir Kondratiev | cbcf586 | 2014-12-23 09:47:09 +0200 | [diff] [blame] | 745 | txdata->agg_amsdu = evt->amsdu; |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 746 | txdata->addba_in_progress = false; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | static void wmi_evt_addba_rx_req(struct wil6210_priv *wil, int id, void *d, |
| 750 | int len) |
| 751 | { |
| 752 | struct wmi_rcp_addba_req_event *evt = d; |
| 753 | |
| 754 | wil_addba_rx_request(wil, evt->cidxtid, evt->dialog_token, |
| 755 | evt->ba_param_set, evt->ba_timeout, |
| 756 | evt->ba_seq_ctrl); |
| 757 | } |
| 758 | |
| 759 | static void wmi_evt_delba(struct wil6210_priv *wil, int id, void *d, int len) |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 760 | __acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock) |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 761 | { |
| 762 | struct wmi_delba_event *evt = d; |
| 763 | u8 cid, tid; |
| 764 | u16 reason = __le16_to_cpu(evt->reason); |
| 765 | struct wil_sta_info *sta; |
| 766 | struct wil_tid_ampdu_rx *r; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 767 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 768 | might_sleep(); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 769 | parse_cidxtid(evt->cidxtid, &cid, &tid); |
| 770 | wil_dbg_wmi(wil, "DELBA CID %d TID %d from %s reason %d\n", |
| 771 | cid, tid, |
| 772 | evt->from_initiator ? "originator" : "recipient", |
| 773 | reason); |
| 774 | if (!evt->from_initiator) { |
| 775 | int i; |
| 776 | /* find Tx vring it belongs to */ |
| 777 | for (i = 0; i < ARRAY_SIZE(wil->vring2cid_tid); i++) { |
| 778 | if ((wil->vring2cid_tid[i][0] == cid) && |
| 779 | (wil->vring2cid_tid[i][1] == tid)) { |
| 780 | struct vring_tx_data *txdata = |
| 781 | &wil->vring_tx_data[i]; |
| 782 | |
| 783 | wil_dbg_wmi(wil, "DELBA Tx vring %d\n", i); |
| 784 | txdata->agg_timeout = 0; |
| 785 | txdata->agg_wsize = 0; |
Vladimir Kondratiev | 3a124ed | 2014-12-23 09:47:04 +0200 | [diff] [blame] | 786 | txdata->addba_in_progress = false; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 787 | |
| 788 | break; /* max. 1 matching ring */ |
| 789 | } |
| 790 | } |
| 791 | if (i >= ARRAY_SIZE(wil->vring2cid_tid)) |
| 792 | wil_err(wil, "DELBA: unable to find Tx vring\n"); |
| 793 | return; |
Vladimir Kondratiev | 7b05b0a | 2014-02-27 16:20:47 +0200 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | sta = &wil->sta[cid]; |
Vladimir Kondratiev | 7b05b0a | 2014-02-27 16:20:47 +0200 | [diff] [blame] | 797 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 798 | spin_lock_bh(&sta->tid_rx_lock); |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 799 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 800 | r = sta->tid_rx[tid]; |
| 801 | sta->tid_rx[tid] = NULL; |
| 802 | wil_tid_ampdu_rx_free(wil, r); |
Dedy Lansky | ec81b5a | 2014-09-10 16:34:42 +0300 | [diff] [blame] | 803 | |
Vladimir Kondratiev | bd33273 | 2014-12-23 09:47:24 +0200 | [diff] [blame] | 804 | spin_unlock_bh(&sta->tid_rx_lock); |
Vladimir Kondratiev | 249a382 | 2013-03-13 14:12:40 +0200 | [diff] [blame] | 805 | } |
| 806 | |
Lior David | 8f1b5e0 | 2017-02-28 14:58:27 +0200 | [diff] [blame] | 807 | static void wmi_evt_aoa_meas(struct wil6210_priv *wil, int id, |
| 808 | void *d, int len) |
| 809 | { |
| 810 | struct wmi_aoa_meas_event *evt = d; |
| 811 | |
| 812 | wil_aoa_evt_meas(wil, evt, len); |
| 813 | } |
| 814 | |
| 815 | static void wmi_evt_ftm_session_ended(struct wil6210_priv *wil, int id, |
| 816 | void *d, int len) |
| 817 | { |
| 818 | struct wmi_tof_session_end_event *evt = d; |
| 819 | |
| 820 | wil_ftm_evt_session_ended(wil, evt); |
| 821 | } |
| 822 | |
| 823 | static void wmi_evt_per_dest_res(struct wil6210_priv *wil, int id, |
| 824 | void *d, int len) |
| 825 | { |
| 826 | struct wmi_tof_ftm_per_dest_res_event *evt = d; |
| 827 | |
| 828 | wil_ftm_evt_per_dest_res(wil, evt); |
| 829 | } |
| 830 | |
Vladimir Kondratiev | b03fbab | 2015-10-25 15:59:21 +0200 | [diff] [blame] | 831 | /** |
| 832 | * Some events are ignored for purpose; and need not be interpreted as |
| 833 | * "unhandled events" |
| 834 | */ |
| 835 | static void wmi_evt_ignore(struct wil6210_priv *wil, int id, void *d, int len) |
| 836 | { |
| 837 | wil_dbg_wmi(wil, "Ignore event 0x%04x len %d\n", id, len); |
| 838 | } |
| 839 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 840 | static const struct { |
| 841 | int eventid; |
| 842 | void (*handler)(struct wil6210_priv *wil, int eventid, |
| 843 | void *data, int data_len); |
| 844 | } wmi_evt_handlers[] = { |
| 845 | {WMI_READY_EVENTID, wmi_evt_ready}, |
Vladimir Kondratiev | 817f185 | 2015-10-25 15:59:23 +0200 | [diff] [blame] | 846 | {WMI_FW_READY_EVENTID, wmi_evt_ignore}, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 847 | {WMI_RX_MGMT_PACKET_EVENTID, wmi_evt_rx_mgmt}, |
Vladimir Kondratiev | 90d89e9 | 2015-07-30 13:51:57 +0300 | [diff] [blame] | 848 | {WMI_TX_MGMT_PACKET_EVENTID, wmi_evt_tx_mgmt}, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 849 | {WMI_SCAN_COMPLETE_EVENTID, wmi_evt_scan_complete}, |
| 850 | {WMI_CONNECT_EVENTID, wmi_evt_connect}, |
| 851 | {WMI_DISCONNECT_EVENTID, wmi_evt_disconnect}, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 852 | {WMI_EAPOL_RX_EVENTID, wmi_evt_eapol_rx}, |
Vladimir Kondratiev | 249a382 | 2013-03-13 14:12:40 +0200 | [diff] [blame] | 853 | {WMI_BA_STATUS_EVENTID, wmi_evt_ba_status}, |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 854 | {WMI_RCP_ADDBA_REQ_EVENTID, wmi_evt_addba_rx_req}, |
| 855 | {WMI_DELBA_EVENTID, wmi_evt_delba}, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 856 | {WMI_VRING_EN_EVENTID, wmi_evt_vring_en}, |
Vladimir Kondratiev | b03fbab | 2015-10-25 15:59:21 +0200 | [diff] [blame] | 857 | {WMI_DATA_PORT_OPEN_EVENTID, wmi_evt_ignore}, |
Lior David | 8f1b5e0 | 2017-02-28 14:58:27 +0200 | [diff] [blame] | 858 | {WMI_AOA_MEAS_EVENTID, wmi_evt_aoa_meas}, |
| 859 | {WMI_TOF_SESSION_END_EVENTID, wmi_evt_ftm_session_ended}, |
| 860 | {WMI_TOF_GET_CAPABILITIES_EVENTID, wmi_evt_ignore}, |
| 861 | {WMI_TOF_SET_LCR_EVENTID, wmi_evt_ignore}, |
| 862 | {WMI_TOF_SET_LCI_EVENTID, wmi_evt_ignore}, |
| 863 | {WMI_TOF_FTM_PER_DEST_RES_EVENTID, wmi_evt_per_dest_res}, |
| 864 | {WMI_TOF_CHANNEL_INFO_EVENTID, wmi_evt_ignore}, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 865 | }; |
| 866 | |
| 867 | /* |
| 868 | * Run in IRQ context |
| 869 | * Extract WMI command from mailbox. Queue it to the @wil->pending_wmi_ev |
| 870 | * that will be eventually handled by the @wmi_event_worker in the thread |
| 871 | * context of thread "wil6210_wmi" |
| 872 | */ |
| 873 | void wmi_recv_cmd(struct wil6210_priv *wil) |
| 874 | { |
| 875 | struct wil6210_mbox_ring_desc d_tail; |
| 876 | struct wil6210_mbox_hdr hdr; |
| 877 | struct wil6210_mbox_ring *r = &wil->mbox_ctl.rx; |
| 878 | struct pending_wmi_event *evt; |
| 879 | u8 *cmd; |
| 880 | void __iomem *src; |
| 881 | ulong flags; |
Vladimir Kondratiev | a715c7d | 2014-05-29 18:37:52 +0300 | [diff] [blame] | 882 | unsigned n; |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 883 | unsigned int num_immed_reply = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 884 | |
Vladimir Kondratiev | 817f185 | 2015-10-25 15:59:23 +0200 | [diff] [blame] | 885 | if (!test_bit(wil_status_mbox_ready, wil->status)) { |
Dedy Lansky | 4cf99c9 | 2014-09-10 16:34:41 +0300 | [diff] [blame] | 886 | wil_err(wil, "Reset in progress. Cannot handle WMI event\n"); |
Vladimir Kondratiev | 55f7acd | 2013-03-13 14:12:49 +0200 | [diff] [blame] | 887 | return; |
| 888 | } |
| 889 | |
Vladimir Kondratiev | a715c7d | 2014-05-29 18:37:52 +0300 | [diff] [blame] | 890 | for (n = 0;; n++) { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 891 | u16 len; |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 892 | bool q; |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 893 | bool immed_reply = false; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 894 | |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 895 | r->head = wil_r(wil, RGF_MBOX + |
| 896 | offsetof(struct wil6210_mbox_ctl, rx.head)); |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 897 | if (r->tail == r->head) |
| 898 | break; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 899 | |
Vladimir Kondratiev | a715c7d | 2014-05-29 18:37:52 +0300 | [diff] [blame] | 900 | wil_dbg_wmi(wil, "Mbox head %08x tail %08x\n", |
| 901 | r->head, r->tail); |
| 902 | /* read cmd descriptor from tail */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 903 | wil_memcpy_fromio_32(&d_tail, wil->csr + HOSTADDR(r->tail), |
| 904 | sizeof(struct wil6210_mbox_ring_desc)); |
| 905 | if (d_tail.sync == 0) { |
| 906 | wil_err(wil, "Mbox evt not owned by FW?\n"); |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 907 | break; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 908 | } |
| 909 | |
Vladimir Kondratiev | a715c7d | 2014-05-29 18:37:52 +0300 | [diff] [blame] | 910 | /* read cmd header from descriptor */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 911 | if (0 != wmi_read_hdr(wil, d_tail.addr, &hdr)) { |
| 912 | wil_err(wil, "Mbox evt at 0x%08x?\n", |
| 913 | le32_to_cpu(d_tail.addr)); |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 914 | break; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 915 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 916 | len = le16_to_cpu(hdr.len); |
Vladimir Kondratiev | a715c7d | 2014-05-29 18:37:52 +0300 | [diff] [blame] | 917 | wil_dbg_wmi(wil, "Mbox evt %04x %04x %04x %02x\n", |
| 918 | le16_to_cpu(hdr.seq), len, le16_to_cpu(hdr.type), |
| 919 | hdr.flags); |
| 920 | |
| 921 | /* read cmd buffer from descriptor */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 922 | src = wmi_buffer(wil, d_tail.addr) + |
| 923 | sizeof(struct wil6210_mbox_hdr); |
| 924 | evt = kmalloc(ALIGN(offsetof(struct pending_wmi_event, |
| 925 | event.wmi) + len, 4), |
| 926 | GFP_KERNEL); |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 927 | if (!evt) |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 928 | break; |
Joe Perches | 14f8dc4 | 2013-02-07 11:46:27 +0000 | [diff] [blame] | 929 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 930 | evt->event.hdr = hdr; |
| 931 | cmd = (void *)&evt->event.wmi; |
| 932 | wil_memcpy_fromio_32(cmd, src, len); |
| 933 | /* mark entry as empty */ |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 934 | wil_w(wil, r->tail + |
| 935 | offsetof(struct wil6210_mbox_ring_desc, sync), 0); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 936 | /* indicate */ |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 937 | if ((hdr.type == WIL_MBOX_HDR_TYPE_WMI) && |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 938 | (len >= sizeof(struct wmi_cmd_hdr))) { |
| 939 | struct wmi_cmd_hdr *wmi = &evt->event.wmi; |
| 940 | u16 id = le16_to_cpu(wmi->command_id); |
| 941 | u32 tstamp = le32_to_cpu(wmi->fw_timestamp); |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 942 | spin_lock_irqsave(&wil->wmi_ev_lock, flags); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 943 | if (wil->reply_id && wil->reply_id == id) { |
| 944 | if (wil->reply_buf) { |
| 945 | memcpy(wil->reply_buf, wmi, |
| 946 | min(len, wil->reply_size)); |
| 947 | immed_reply = true; |
| 948 | } |
| 949 | } |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 950 | spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 951 | |
Vladimir Kondratiev | f988b23 | 2013-07-11 18:03:37 +0300 | [diff] [blame] | 952 | wil_dbg_wmi(wil, "WMI event 0x%04x MID %d @%d msec\n", |
| 953 | id, wmi->mid, tstamp); |
| 954 | trace_wil6210_wmi_event(wmi, &wmi[1], |
| 955 | len - sizeof(*wmi)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 956 | } |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 957 | wil_hex_dump_wmi("evt ", DUMP_PREFIX_OFFSET, 16, 1, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 958 | &evt->event.hdr, sizeof(hdr) + len, true); |
| 959 | |
| 960 | /* advance tail */ |
| 961 | r->tail = r->base + ((r->tail - r->base + |
| 962 | sizeof(struct wil6210_mbox_ring_desc)) % r->size); |
Vladimir Kondratiev | b9eeb51 | 2015-07-30 13:52:03 +0300 | [diff] [blame] | 963 | wil_w(wil, RGF_MBOX + |
| 964 | offsetof(struct wil6210_mbox_ctl, rx.tail), r->tail); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 965 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 966 | if (immed_reply) { |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 967 | wil_dbg_wmi(wil, "recv_cmd: Complete WMI 0x%04x\n", |
| 968 | wil->reply_id); |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 969 | kfree(evt); |
| 970 | num_immed_reply++; |
| 971 | complete(&wil->wmi_call); |
| 972 | } else { |
| 973 | /* add to the pending list */ |
| 974 | spin_lock_irqsave(&wil->wmi_ev_lock, flags); |
| 975 | list_add_tail(&evt->list, &wil->pending_wmi_ev); |
| 976 | spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); |
| 977 | q = queue_work(wil->wmi_wq, &wil->wmi_event_worker); |
| 978 | wil_dbg_wmi(wil, "queue_work -> %d\n", q); |
| 979 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 980 | } |
Vladimir Kondratiev | 95266dc | 2014-06-16 19:37:19 +0300 | [diff] [blame] | 981 | /* normally, 1 event per IRQ should be processed */ |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 982 | wil_dbg_wmi(wil, "recv_cmd: -> %d events queued, %d completed\n", |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 983 | n - num_immed_reply, num_immed_reply); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | int wmi_call(struct wil6210_priv *wil, u16 cmdid, void *buf, u16 len, |
| 987 | u16 reply_id, void *reply, u8 reply_size, int to_msec) |
| 988 | { |
| 989 | int rc; |
Nicholas Mc Guire | f4bbb82 | 2015-08-13 15:38:31 +0300 | [diff] [blame] | 990 | unsigned long remain; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 991 | |
| 992 | mutex_lock(&wil->wmi_mutex); |
| 993 | |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 994 | spin_lock(&wil->wmi_ev_lock); |
| 995 | wil->reply_id = reply_id; |
| 996 | wil->reply_buf = reply; |
| 997 | wil->reply_size = reply_size; |
Lior David | 0166006 | 2017-02-22 15:15:23 +0200 | [diff] [blame] | 998 | reinit_completion(&wil->wmi_call); |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 999 | spin_unlock(&wil->wmi_ev_lock); |
| 1000 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1001 | rc = __wmi_send(wil, cmdid, buf, len); |
| 1002 | if (rc) |
| 1003 | goto out; |
| 1004 | |
Dedy Lansky | 5950264 | 2014-09-10 16:34:46 +0300 | [diff] [blame] | 1005 | remain = wait_for_completion_timeout(&wil->wmi_call, |
| 1006 | msecs_to_jiffies(to_msec)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1007 | if (0 == remain) { |
| 1008 | wil_err(wil, "wmi_call(0x%04x->0x%04x) timeout %d msec\n", |
| 1009 | cmdid, reply_id, to_msec); |
| 1010 | rc = -ETIME; |
| 1011 | } else { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1012 | wil_dbg_wmi(wil, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1013 | "wmi_call(0x%04x->0x%04x) completed in %d msec\n", |
| 1014 | cmdid, reply_id, |
| 1015 | to_msec - jiffies_to_msecs(remain)); |
| 1016 | } |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 1017 | |
| 1018 | out: |
| 1019 | spin_lock(&wil->wmi_ev_lock); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1020 | wil->reply_id = 0; |
| 1021 | wil->reply_buf = NULL; |
| 1022 | wil->reply_size = 0; |
Maya Erez | fe5c271 | 2016-01-28 19:24:04 +0200 | [diff] [blame] | 1023 | spin_unlock(&wil->wmi_ev_lock); |
| 1024 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1025 | mutex_unlock(&wil->wmi_mutex); |
| 1026 | |
| 1027 | return rc; |
| 1028 | } |
| 1029 | |
| 1030 | int wmi_echo(struct wil6210_priv *wil) |
| 1031 | { |
| 1032 | struct wmi_echo_cmd cmd = { |
| 1033 | .value = cpu_to_le32(0x12345678), |
| 1034 | }; |
| 1035 | |
| 1036 | return wmi_call(wil, WMI_ECHO_CMDID, &cmd, sizeof(cmd), |
Vladimir Kondratiev | a54a40d | 2015-04-30 16:25:05 +0300 | [diff] [blame] | 1037 | WMI_ECHO_RSP_EVENTID, NULL, 0, 50); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | int wmi_set_mac_address(struct wil6210_priv *wil, void *addr) |
| 1041 | { |
| 1042 | struct wmi_set_mac_address_cmd cmd; |
| 1043 | |
Vladimir Kondratiev | a82553bb | 2015-03-15 16:00:21 +0200 | [diff] [blame] | 1044 | ether_addr_copy(cmd.mac, addr); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1045 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1046 | wil_dbg_wmi(wil, "Set MAC %pM\n", addr); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1047 | |
| 1048 | return wmi_send(wil, WMI_SET_MAC_ADDRESS_CMDID, &cmd, sizeof(cmd)); |
| 1049 | } |
| 1050 | |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 1051 | int wmi_led_cfg(struct wil6210_priv *wil, bool enable) |
| 1052 | { |
| 1053 | int rc = 0; |
| 1054 | struct wmi_led_cfg_cmd cmd = { |
| 1055 | .led_mode = enable, |
| 1056 | .id = led_id, |
| 1057 | .slow_blink_cfg.blink_on = |
| 1058 | cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].on_ms), |
| 1059 | .slow_blink_cfg.blink_off = |
| 1060 | cpu_to_le32(led_blink_time[WIL_LED_TIME_SLOW].off_ms), |
| 1061 | .medium_blink_cfg.blink_on = |
| 1062 | cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].on_ms), |
| 1063 | .medium_blink_cfg.blink_off = |
| 1064 | cpu_to_le32(led_blink_time[WIL_LED_TIME_MED].off_ms), |
| 1065 | .fast_blink_cfg.blink_on = |
| 1066 | cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].on_ms), |
| 1067 | .fast_blink_cfg.blink_off = |
| 1068 | cpu_to_le32(led_blink_time[WIL_LED_TIME_FAST].off_ms), |
| 1069 | .led_polarity = led_polarity, |
| 1070 | }; |
| 1071 | struct { |
| 1072 | struct wmi_cmd_hdr wmi; |
| 1073 | struct wmi_led_cfg_done_event evt; |
| 1074 | } __packed reply; |
| 1075 | |
| 1076 | if (led_id == WIL_LED_INVALID_ID) |
| 1077 | goto out; |
| 1078 | |
| 1079 | if (led_id > WIL_LED_MAX_ID) { |
| 1080 | wil_err(wil, "Invalid led id %d\n", led_id); |
| 1081 | rc = -EINVAL; |
| 1082 | goto out; |
| 1083 | } |
| 1084 | |
| 1085 | wil_dbg_wmi(wil, |
| 1086 | "%s led %d\n", |
| 1087 | enable ? "enabling" : "disabling", led_id); |
| 1088 | |
| 1089 | rc = wmi_call(wil, WMI_LED_CFG_CMDID, &cmd, sizeof(cmd), |
| 1090 | WMI_LED_CFG_DONE_EVENTID, &reply, sizeof(reply), |
| 1091 | 100); |
| 1092 | if (rc) |
| 1093 | goto out; |
| 1094 | |
| 1095 | if (reply.evt.status) { |
| 1096 | wil_err(wil, "led %d cfg failed with status %d\n", |
| 1097 | led_id, le32_to_cpu(reply.evt.status)); |
| 1098 | rc = -EINVAL; |
| 1099 | } |
| 1100 | |
| 1101 | out: |
| 1102 | return rc; |
| 1103 | } |
| 1104 | |
Hamad Kadmany | 8e52fe3 | 2015-06-09 14:11:18 +0300 | [diff] [blame] | 1105 | int wmi_pcp_start(struct wil6210_priv *wil, int bi, u8 wmi_nettype, |
Lior David | b4944f2 | 2016-03-01 19:18:17 +0200 | [diff] [blame] | 1106 | u8 chan, u8 hidden_ssid, u8 is_go) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1107 | { |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1108 | int rc; |
| 1109 | |
| 1110 | struct wmi_pcp_start_cmd cmd = { |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1111 | .bcon_interval = cpu_to_le16(bi), |
| 1112 | .network_type = wmi_nettype, |
| 1113 | .disable_sec_offload = 1, |
Vladimir Kondratiev | adc2d12 | 2013-05-28 15:17:52 +0300 | [diff] [blame] | 1114 | .channel = chan - 1, |
Dedy Lansky | 1eb9d1e | 2014-08-06 10:31:58 +0300 | [diff] [blame] | 1115 | .pcp_max_assoc_sta = max_assoc_sta, |
Hamad Kadmany | 8e52fe3 | 2015-06-09 14:11:18 +0300 | [diff] [blame] | 1116 | .hidden_ssid = hidden_ssid, |
Lior David | b4944f2 | 2016-03-01 19:18:17 +0200 | [diff] [blame] | 1117 | .is_go = is_go, |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1118 | .disable_ap_sme = disable_ap_sme, |
Lior David | 4bbecaf | 2017-02-08 13:17:35 +0200 | [diff] [blame] | 1119 | .abft_len = wil->abft_len, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1120 | }; |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1121 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1122 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1123 | struct wmi_pcp_started_event evt; |
| 1124 | } __packed reply; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1125 | |
Vladimir Kondratiev | 774974e | 2015-02-15 14:02:36 +0200 | [diff] [blame] | 1126 | if (!wil->privacy) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1127 | cmd.disable_sec = 1; |
| 1128 | |
Dedy Lansky | 1eb9d1e | 2014-08-06 10:31:58 +0300 | [diff] [blame] | 1129 | if ((cmd.pcp_max_assoc_sta > WIL6210_MAX_CID) || |
| 1130 | (cmd.pcp_max_assoc_sta <= 0)) { |
| 1131 | wil_info(wil, |
| 1132 | "Requested connection limit %u, valid values are 1 - %d. Setting to %d\n", |
| 1133 | max_assoc_sta, WIL6210_MAX_CID, WIL6210_MAX_CID); |
| 1134 | cmd.pcp_max_assoc_sta = WIL6210_MAX_CID; |
| 1135 | } |
| 1136 | |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1137 | if (disable_ap_sme && |
| 1138 | !test_bit(WMI_FW_CAPABILITY_DISABLE_AP_SME, |
| 1139 | wil->fw_capabilities)) { |
| 1140 | wil_err(wil, "disable_ap_sme not supported by FW\n"); |
| 1141 | return -EOPNOTSUPP; |
| 1142 | } |
| 1143 | |
Vladimir Kondratiev | 8b5c7f6 | 2013-06-09 09:12:50 +0300 | [diff] [blame] | 1144 | /* |
| 1145 | * Processing time may be huge, in case of secure AP it takes about |
| 1146 | * 3500ms for FW to start AP |
| 1147 | */ |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1148 | rc = wmi_call(wil, WMI_PCP_START_CMDID, &cmd, sizeof(cmd), |
Vladimir Kondratiev | 8b5c7f6 | 2013-06-09 09:12:50 +0300 | [diff] [blame] | 1149 | WMI_PCP_STARTED_EVENTID, &reply, sizeof(reply), 5000); |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1150 | if (rc) |
| 1151 | return rc; |
| 1152 | |
| 1153 | if (reply.evt.status != WMI_FW_STATUS_SUCCESS) |
| 1154 | rc = -EINVAL; |
| 1155 | |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 1156 | if (wmi_nettype != WMI_NETTYPE_P2P) |
| 1157 | /* Don't fail due to error in the led configuration */ |
| 1158 | wmi_led_cfg(wil, true); |
| 1159 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1160 | return rc; |
| 1161 | } |
| 1162 | |
| 1163 | int wmi_pcp_stop(struct wil6210_priv *wil) |
| 1164 | { |
Maya Erez | 10d599a | 2016-05-09 21:57:11 +0300 | [diff] [blame] | 1165 | int rc; |
| 1166 | |
| 1167 | rc = wmi_led_cfg(wil, false); |
| 1168 | if (rc) |
| 1169 | return rc; |
| 1170 | |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1171 | return wmi_call(wil, WMI_PCP_STOP_CMDID, NULL, 0, |
| 1172 | WMI_PCP_STOPPED_EVENTID, NULL, 0, 20); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1173 | } |
| 1174 | |
| 1175 | int wmi_set_ssid(struct wil6210_priv *wil, u8 ssid_len, const void *ssid) |
| 1176 | { |
| 1177 | struct wmi_set_ssid_cmd cmd = { |
| 1178 | .ssid_len = cpu_to_le32(ssid_len), |
| 1179 | }; |
| 1180 | |
| 1181 | if (ssid_len > sizeof(cmd.ssid)) |
| 1182 | return -EINVAL; |
| 1183 | |
| 1184 | memcpy(cmd.ssid, ssid, ssid_len); |
| 1185 | |
| 1186 | return wmi_send(wil, WMI_SET_SSID_CMDID, &cmd, sizeof(cmd)); |
| 1187 | } |
| 1188 | |
| 1189 | int wmi_get_ssid(struct wil6210_priv *wil, u8 *ssid_len, void *ssid) |
| 1190 | { |
| 1191 | int rc; |
| 1192 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1193 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1194 | struct wmi_set_ssid_cmd cmd; |
| 1195 | } __packed reply; |
| 1196 | int len; /* reply.cmd.ssid_len in CPU order */ |
| 1197 | |
| 1198 | rc = wmi_call(wil, WMI_GET_SSID_CMDID, NULL, 0, WMI_GET_SSID_EVENTID, |
| 1199 | &reply, sizeof(reply), 20); |
| 1200 | if (rc) |
| 1201 | return rc; |
| 1202 | |
| 1203 | len = le32_to_cpu(reply.cmd.ssid_len); |
| 1204 | if (len > sizeof(reply.cmd.ssid)) |
| 1205 | return -EINVAL; |
| 1206 | |
| 1207 | *ssid_len = len; |
| 1208 | memcpy(ssid, reply.cmd.ssid, len); |
| 1209 | |
| 1210 | return 0; |
| 1211 | } |
| 1212 | |
| 1213 | int wmi_set_channel(struct wil6210_priv *wil, int channel) |
| 1214 | { |
| 1215 | struct wmi_set_pcp_channel_cmd cmd = { |
| 1216 | .channel = channel - 1, |
| 1217 | }; |
| 1218 | |
| 1219 | return wmi_send(wil, WMI_SET_PCP_CHANNEL_CMDID, &cmd, sizeof(cmd)); |
| 1220 | } |
| 1221 | |
| 1222 | int wmi_get_channel(struct wil6210_priv *wil, int *channel) |
| 1223 | { |
| 1224 | int rc; |
| 1225 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1226 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1227 | struct wmi_set_pcp_channel_cmd cmd; |
| 1228 | } __packed reply; |
| 1229 | |
| 1230 | rc = wmi_call(wil, WMI_GET_PCP_CHANNEL_CMDID, NULL, 0, |
| 1231 | WMI_GET_PCP_CHANNEL_EVENTID, &reply, sizeof(reply), 20); |
| 1232 | if (rc) |
| 1233 | return rc; |
| 1234 | |
| 1235 | if (reply.cmd.channel > 3) |
| 1236 | return -EINVAL; |
| 1237 | |
| 1238 | *channel = reply.cmd.channel + 1; |
| 1239 | |
| 1240 | return 0; |
| 1241 | } |
| 1242 | |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 1243 | int wmi_p2p_cfg(struct wil6210_priv *wil, int channel, int bi) |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1244 | { |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 1245 | int rc; |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1246 | struct wmi_p2p_cfg_cmd cmd = { |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 1247 | .discovery_mode = WMI_DISCOVERY_MODE_PEER2PEER, |
| 1248 | .bcon_interval = cpu_to_le16(bi), |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1249 | .channel = channel - 1, |
| 1250 | }; |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 1251 | struct { |
| 1252 | struct wmi_cmd_hdr wmi; |
| 1253 | struct wmi_p2p_cfg_done_event evt; |
| 1254 | } __packed reply; |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1255 | |
Dedy Lansky | e6d6834 | 2016-03-01 19:18:12 +0200 | [diff] [blame] | 1256 | wil_dbg_wmi(wil, "sending WMI_P2P_CFG_CMDID\n"); |
| 1257 | |
| 1258 | rc = wmi_call(wil, WMI_P2P_CFG_CMDID, &cmd, sizeof(cmd), |
| 1259 | WMI_P2P_CFG_DONE_EVENTID, &reply, sizeof(reply), 300); |
| 1260 | if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { |
| 1261 | wil_err(wil, "P2P_CFG failed. status %d\n", reply.evt.status); |
| 1262 | rc = -EINVAL; |
| 1263 | } |
| 1264 | |
| 1265 | return rc; |
| 1266 | } |
| 1267 | |
| 1268 | int wmi_start_listen(struct wil6210_priv *wil) |
| 1269 | { |
| 1270 | int rc; |
| 1271 | struct { |
| 1272 | struct wmi_cmd_hdr wmi; |
| 1273 | struct wmi_listen_started_event evt; |
| 1274 | } __packed reply; |
| 1275 | |
| 1276 | wil_dbg_wmi(wil, "sending WMI_START_LISTEN_CMDID\n"); |
| 1277 | |
| 1278 | rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0, |
| 1279 | WMI_LISTEN_STARTED_EVENTID, &reply, sizeof(reply), 300); |
| 1280 | if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { |
| 1281 | wil_err(wil, "device failed to start listen. status %d\n", |
| 1282 | reply.evt.status); |
| 1283 | rc = -EINVAL; |
| 1284 | } |
| 1285 | |
| 1286 | return rc; |
| 1287 | } |
| 1288 | |
| 1289 | int wmi_start_search(struct wil6210_priv *wil) |
| 1290 | { |
| 1291 | int rc; |
| 1292 | struct { |
| 1293 | struct wmi_cmd_hdr wmi; |
| 1294 | struct wmi_search_started_event evt; |
| 1295 | } __packed reply; |
| 1296 | |
| 1297 | wil_dbg_wmi(wil, "sending WMI_START_SEARCH_CMDID\n"); |
| 1298 | |
| 1299 | rc = wmi_call(wil, WMI_START_SEARCH_CMDID, NULL, 0, |
| 1300 | WMI_SEARCH_STARTED_EVENTID, &reply, sizeof(reply), 300); |
| 1301 | if (!rc && reply.evt.status != WMI_FW_STATUS_SUCCESS) { |
| 1302 | wil_err(wil, "device failed to start search. status %d\n", |
| 1303 | reply.evt.status); |
| 1304 | rc = -EINVAL; |
| 1305 | } |
| 1306 | |
| 1307 | return rc; |
| 1308 | } |
| 1309 | |
| 1310 | int wmi_stop_discovery(struct wil6210_priv *wil) |
| 1311 | { |
| 1312 | int rc; |
| 1313 | |
| 1314 | wil_dbg_wmi(wil, "sending WMI_DISCOVERY_STOP_CMDID\n"); |
| 1315 | |
| 1316 | rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0, |
| 1317 | WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 100); |
| 1318 | |
| 1319 | if (rc) |
| 1320 | wil_err(wil, "Failed to stop discovery\n"); |
| 1321 | |
| 1322 | return rc; |
Vladimir Kondratiev | b802317 | 2013-03-13 14:12:50 +0200 | [diff] [blame] | 1323 | } |
| 1324 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1325 | int wmi_del_cipher_key(struct wil6210_priv *wil, u8 key_index, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1326 | const void *mac_addr, int key_usage) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1327 | { |
| 1328 | struct wmi_delete_cipher_key_cmd cmd = { |
| 1329 | .key_index = key_index, |
| 1330 | }; |
| 1331 | |
| 1332 | if (mac_addr) |
| 1333 | memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); |
| 1334 | |
| 1335 | return wmi_send(wil, WMI_DELETE_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); |
| 1336 | } |
| 1337 | |
| 1338 | int wmi_add_cipher_key(struct wil6210_priv *wil, u8 key_index, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1339 | const void *mac_addr, int key_len, const void *key, |
| 1340 | int key_usage) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1341 | { |
| 1342 | struct wmi_add_cipher_key_cmd cmd = { |
| 1343 | .key_index = key_index, |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1344 | .key_usage = key_usage, |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1345 | .key_len = key_len, |
| 1346 | }; |
| 1347 | |
| 1348 | if (!key || (key_len > sizeof(cmd.key))) |
| 1349 | return -EINVAL; |
| 1350 | |
| 1351 | memcpy(cmd.key, key, key_len); |
| 1352 | if (mac_addr) |
| 1353 | memcpy(cmd.mac, mac_addr, WMI_MAC_LEN); |
| 1354 | |
| 1355 | return wmi_send(wil, WMI_ADD_CIPHER_KEY_CMDID, &cmd, sizeof(cmd)); |
| 1356 | } |
| 1357 | |
| 1358 | int wmi_set_ie(struct wil6210_priv *wil, u8 type, u16 ie_len, const void *ie) |
| 1359 | { |
Vladimir Kondratiev | 5421bf0 | 2015-07-30 13:52:00 +0300 | [diff] [blame] | 1360 | static const char *const names[] = { |
| 1361 | [WMI_FRAME_BEACON] = "BEACON", |
| 1362 | [WMI_FRAME_PROBE_REQ] = "PROBE_REQ", |
| 1363 | [WMI_FRAME_PROBE_RESP] = "WMI_FRAME_PROBE_RESP", |
| 1364 | [WMI_FRAME_ASSOC_REQ] = "WMI_FRAME_ASSOC_REQ", |
| 1365 | [WMI_FRAME_ASSOC_RESP] = "WMI_FRAME_ASSOC_RESP", |
| 1366 | }; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1367 | int rc; |
| 1368 | u16 len = sizeof(struct wmi_set_appie_cmd) + ie_len; |
| 1369 | struct wmi_set_appie_cmd *cmd = kzalloc(len, GFP_KERNEL); |
Vladimir Kondratiev | 8fe5962 | 2014-09-10 16:34:34 +0300 | [diff] [blame] | 1370 | |
Vladimir Kondratiev | 5421bf0 | 2015-07-30 13:52:00 +0300 | [diff] [blame] | 1371 | if (!cmd) { |
| 1372 | rc = -ENOMEM; |
| 1373 | goto out; |
| 1374 | } |
Vladimir Kondratiev | ac4acdb | 2014-09-10 16:34:43 +0300 | [diff] [blame] | 1375 | if (!ie) |
| 1376 | ie_len = 0; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1377 | |
| 1378 | cmd->mgmt_frm_type = type; |
| 1379 | /* BUG: FW API define ieLen as u8. Will fix FW */ |
| 1380 | cmd->ie_len = cpu_to_le16(ie_len); |
| 1381 | memcpy(cmd->ie_info, ie, ie_len); |
Vladimir Kondratiev | 03866e7 | 2013-03-13 14:12:42 +0200 | [diff] [blame] | 1382 | rc = wmi_send(wil, WMI_SET_APPIE_CMDID, cmd, len); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1383 | kfree(cmd); |
Vladimir Kondratiev | 5421bf0 | 2015-07-30 13:52:00 +0300 | [diff] [blame] | 1384 | out: |
| 1385 | if (rc) { |
| 1386 | const char *name = type < ARRAY_SIZE(names) ? |
| 1387 | names[type] : "??"; |
| 1388 | wil_err(wil, "set_ie(%d %s) failed : %d\n", type, name, rc); |
| 1389 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1390 | |
| 1391 | return rc; |
| 1392 | } |
| 1393 | |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 1394 | /** |
| 1395 | * wmi_rxon - turn radio on/off |
| 1396 | * @on: turn on if true, off otherwise |
| 1397 | * |
| 1398 | * Only switch radio. Channel should be set separately. |
| 1399 | * No timeout for rxon - radio turned on forever unless some other call |
| 1400 | * turns it off |
| 1401 | */ |
| 1402 | int wmi_rxon(struct wil6210_priv *wil, bool on) |
| 1403 | { |
| 1404 | int rc; |
| 1405 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1406 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 1407 | struct wmi_listen_started_event evt; |
| 1408 | } __packed reply; |
| 1409 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1410 | wil_info(wil, "(%s)\n", on ? "on" : "off"); |
Vladimir Kondratiev | 1647f12 | 2014-02-27 16:20:40 +0200 | [diff] [blame] | 1411 | |
| 1412 | if (on) { |
| 1413 | rc = wmi_call(wil, WMI_START_LISTEN_CMDID, NULL, 0, |
| 1414 | WMI_LISTEN_STARTED_EVENTID, |
| 1415 | &reply, sizeof(reply), 100); |
| 1416 | if ((rc == 0) && (reply.evt.status != WMI_FW_STATUS_SUCCESS)) |
| 1417 | rc = -EINVAL; |
| 1418 | } else { |
| 1419 | rc = wmi_call(wil, WMI_DISCOVERY_STOP_CMDID, NULL, 0, |
| 1420 | WMI_DISCOVERY_STOPPED_EVENTID, NULL, 0, 20); |
| 1421 | } |
| 1422 | |
| 1423 | return rc; |
| 1424 | } |
| 1425 | |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1426 | int wmi_rx_chain_add(struct wil6210_priv *wil, struct vring *vring) |
| 1427 | { |
| 1428 | struct wireless_dev *wdev = wil->wdev; |
| 1429 | struct net_device *ndev = wil_to_ndev(wil); |
| 1430 | struct wmi_cfg_rx_chain_cmd cmd = { |
| 1431 | .action = WMI_RX_CHAIN_ADD, |
| 1432 | .rx_sw_ring = { |
Vladimir Kondratiev | c44690a | 2014-12-23 09:47:11 +0200 | [diff] [blame] | 1433 | .max_mpdu_size = cpu_to_le16(wil_mtu2macbuf(mtu_max)), |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1434 | .ring_mem_base = cpu_to_le64(vring->pa), |
| 1435 | .ring_size = cpu_to_le16(vring->size), |
| 1436 | }, |
| 1437 | .mid = 0, /* TODO - what is it? */ |
| 1438 | .decap_trans_type = WMI_DECAP_TYPE_802_3, |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 1439 | .reorder_type = WMI_RX_SW_REORDER, |
Vladimir Kondratiev | ab95462 | 2014-12-23 09:47:20 +0200 | [diff] [blame] | 1440 | .host_thrsh = cpu_to_le16(rx_ring_overflow_thrsh), |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1441 | }; |
| 1442 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1443 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1444 | struct wmi_cfg_rx_chain_done_event evt; |
| 1445 | } __packed evt; |
| 1446 | int rc; |
| 1447 | |
| 1448 | if (wdev->iftype == NL80211_IFTYPE_MONITOR) { |
| 1449 | struct ieee80211_channel *ch = wdev->preset_chandef.chan; |
| 1450 | |
| 1451 | cmd.sniffer_cfg.mode = cpu_to_le32(WMI_SNIFFER_ON); |
| 1452 | if (ch) |
| 1453 | cmd.sniffer_cfg.channel = ch->hw_value - 1; |
| 1454 | cmd.sniffer_cfg.phy_info_mode = |
| 1455 | cpu_to_le32(ndev->type == ARPHRD_IEEE80211_RADIOTAP); |
| 1456 | cmd.sniffer_cfg.phy_support = |
| 1457 | cpu_to_le32((wil->monitor_flags & MONITOR_FLAG_CONTROL) |
Vladimir Kondratiev | 4765332 | 2015-10-04 10:23:24 +0300 | [diff] [blame] | 1458 | ? WMI_SNIFFER_CP : WMI_SNIFFER_BOTH_PHYS); |
Kirshenbaum Erez | 504937d | 2013-07-21 11:34:37 +0300 | [diff] [blame] | 1459 | } else { |
| 1460 | /* Initialize offload (in non-sniffer mode). |
| 1461 | * Linux IP stack always calculates IP checksum |
| 1462 | * HW always calculate TCP/UDP checksum |
| 1463 | */ |
| 1464 | cmd.l3_l4_ctrl |= (1 << L3_L4_CTRL_TCPIP_CHECKSUM_EN_POS); |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1465 | } |
Vladimir Kondratiev | c406ea7 | 2015-03-15 16:00:19 +0200 | [diff] [blame] | 1466 | |
| 1467 | if (rx_align_2) |
| 1468 | cmd.l2_802_3_offload_ctrl |= |
| 1469 | L2_802_3_OFFLOAD_CTRL_SNAP_KEEP_MSK; |
| 1470 | |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1471 | /* typical time for secure PCP is 840ms */ |
| 1472 | rc = wmi_call(wil, WMI_CFG_RX_CHAIN_CMDID, &cmd, sizeof(cmd), |
| 1473 | WMI_CFG_RX_CHAIN_DONE_EVENTID, &evt, sizeof(evt), 2000); |
| 1474 | if (rc) |
| 1475 | return rc; |
| 1476 | |
| 1477 | vring->hwtail = le32_to_cpu(evt.evt.rx_ring_tail_ptr); |
| 1478 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 1479 | wil_dbg_misc(wil, "Rx init: status %d tail 0x%08x\n", |
Vladimir Kondratiev | 47e19af | 2013-01-28 18:30:59 +0200 | [diff] [blame] | 1480 | le32_to_cpu(evt.evt.status), vring->hwtail); |
| 1481 | |
| 1482 | if (le32_to_cpu(evt.evt.status) != WMI_CFG_RX_CHAIN_SUCCESS) |
| 1483 | rc = -EINVAL; |
| 1484 | |
| 1485 | return rc; |
| 1486 | } |
| 1487 | |
Vladimir Kondratiev | 8c67967 | 2015-01-25 10:52:42 +0200 | [diff] [blame] | 1488 | int wmi_get_temperature(struct wil6210_priv *wil, u32 *t_bb, u32 *t_rf) |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1489 | { |
| 1490 | int rc; |
| 1491 | struct wmi_temp_sense_cmd cmd = { |
Vladimir Kondratiev | 8c67967 | 2015-01-25 10:52:42 +0200 | [diff] [blame] | 1492 | .measure_baseband_en = cpu_to_le32(!!t_bb), |
| 1493 | .measure_rf_en = cpu_to_le32(!!t_rf), |
| 1494 | .measure_mode = cpu_to_le32(TEMPERATURE_MEASURE_NOW), |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1495 | }; |
| 1496 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1497 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1498 | struct wmi_temp_sense_done_event evt; |
| 1499 | } __packed reply; |
| 1500 | |
| 1501 | rc = wmi_call(wil, WMI_TEMP_SENSE_CMDID, &cmd, sizeof(cmd), |
| 1502 | WMI_TEMP_SENSE_DONE_EVENTID, &reply, sizeof(reply), 100); |
| 1503 | if (rc) |
| 1504 | return rc; |
| 1505 | |
Vladimir Kondratiev | 8c67967 | 2015-01-25 10:52:42 +0200 | [diff] [blame] | 1506 | if (t_bb) |
| 1507 | *t_bb = le32_to_cpu(reply.evt.baseband_t1000); |
| 1508 | if (t_rf) |
| 1509 | *t_rf = le32_to_cpu(reply.evt.rf_t1000); |
Vladimir Kondratiev | 1a2780e | 2013-03-13 14:12:51 +0200 | [diff] [blame] | 1510 | |
| 1511 | return 0; |
| 1512 | } |
| 1513 | |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1514 | int wmi_disconnect_sta(struct wil6210_priv *wil, const u8 *mac, |
| 1515 | u16 reason, bool full_disconnect, bool del_sta) |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 1516 | { |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1517 | int rc; |
| 1518 | u16 reason_code; |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1519 | struct wmi_disconnect_sta_cmd disc_sta_cmd = { |
| 1520 | .disconnect_reason = cpu_to_le16(reason), |
| 1521 | }; |
| 1522 | struct wmi_del_sta_cmd del_sta_cmd = { |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 1523 | .disconnect_reason = cpu_to_le16(reason), |
| 1524 | }; |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1525 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1526 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1527 | struct wmi_disconnect_event evt; |
| 1528 | } __packed reply; |
Vladimir Kondratiev | a82553bb | 2015-03-15 16:00:21 +0200 | [diff] [blame] | 1529 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1530 | wil_dbg_wmi(wil, "disconnect_sta: (%pM, reason %d)\n", mac, reason); |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 1531 | |
Dedy Lansky | 0a4e9d1 | 2017-03-27 21:21:31 +0300 | [diff] [blame] | 1532 | wil->locally_generated_disc = true; |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1533 | if (del_sta) { |
| 1534 | ether_addr_copy(del_sta_cmd.dst_mac, mac); |
| 1535 | rc = wmi_call(wil, WMI_DEL_STA_CMDID, &del_sta_cmd, |
| 1536 | sizeof(del_sta_cmd), WMI_DISCONNECT_EVENTID, |
| 1537 | &reply, sizeof(reply), 1000); |
| 1538 | } else { |
| 1539 | ether_addr_copy(disc_sta_cmd.dst_mac, mac); |
| 1540 | rc = wmi_call(wil, WMI_DISCONNECT_STA_CMDID, &disc_sta_cmd, |
| 1541 | sizeof(disc_sta_cmd), WMI_DISCONNECT_EVENTID, |
| 1542 | &reply, sizeof(reply), 1000); |
| 1543 | } |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1544 | /* failure to disconnect in reasonable time treated as FW error */ |
| 1545 | if (rc) { |
| 1546 | wil_fw_error_recovery(wil); |
| 1547 | return rc; |
| 1548 | } |
| 1549 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 1550 | if (full_disconnect) { |
| 1551 | /* call event handler manually after processing wmi_call, |
| 1552 | * to avoid deadlock - disconnect event handler acquires |
| 1553 | * wil->mutex while it is already held here |
| 1554 | */ |
| 1555 | reason_code = le16_to_cpu(reply.evt.protocol_reason_status); |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1556 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 1557 | wil_dbg_wmi(wil, "Disconnect %pM reason [proto %d wmi %d]\n", |
| 1558 | reply.evt.bssid, reason_code, |
| 1559 | reply.evt.disconnect_reason); |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1560 | |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 1561 | wil->sinfo_gen++; |
| 1562 | wil6210_disconnect(wil, reply.evt.bssid, reason_code, true); |
| 1563 | } |
Vladimir Kondratiev | 3e9191f | 2015-07-30 13:51:53 +0300 | [diff] [blame] | 1564 | return 0; |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 1565 | } |
| 1566 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1567 | int wmi_addba(struct wil6210_priv *wil, u8 ringid, u8 size, u16 timeout) |
| 1568 | { |
| 1569 | struct wmi_vring_ba_en_cmd cmd = { |
| 1570 | .ringid = ringid, |
| 1571 | .agg_max_wsize = size, |
| 1572 | .ba_timeout = cpu_to_le16(timeout), |
Vladimir Kondratiev | cbcf586 | 2014-12-23 09:47:09 +0200 | [diff] [blame] | 1573 | .amsdu = 0, |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1574 | }; |
| 1575 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1576 | wil_dbg_wmi(wil, "addba: (ring %d size %d timeout %d)\n", ringid, size, |
| 1577 | timeout); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1578 | |
| 1579 | return wmi_send(wil, WMI_VRING_BA_EN_CMDID, &cmd, sizeof(cmd)); |
| 1580 | } |
| 1581 | |
Vladimir Kondratiev | 26a359d | 2014-12-23 09:47:10 +0200 | [diff] [blame] | 1582 | int wmi_delba_tx(struct wil6210_priv *wil, u8 ringid, u16 reason) |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1583 | { |
| 1584 | struct wmi_vring_ba_dis_cmd cmd = { |
| 1585 | .ringid = ringid, |
| 1586 | .reason = cpu_to_le16(reason), |
| 1587 | }; |
| 1588 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1589 | wil_dbg_wmi(wil, "delba_tx: (ring %d reason %d)\n", ringid, reason); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1590 | |
| 1591 | return wmi_send(wil, WMI_VRING_BA_DIS_CMDID, &cmd, sizeof(cmd)); |
| 1592 | } |
| 1593 | |
Vladimir Kondratiev | 26a359d | 2014-12-23 09:47:10 +0200 | [diff] [blame] | 1594 | int wmi_delba_rx(struct wil6210_priv *wil, u8 cidxtid, u16 reason) |
| 1595 | { |
| 1596 | struct wmi_rcp_delba_cmd cmd = { |
| 1597 | .cidxtid = cidxtid, |
| 1598 | .reason = cpu_to_le16(reason), |
| 1599 | }; |
| 1600 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1601 | wil_dbg_wmi(wil, "delba_rx: (CID %d TID %d reason %d)\n", cidxtid & 0xf, |
| 1602 | (cidxtid >> 4) & 0xf, reason); |
Vladimir Kondratiev | 26a359d | 2014-12-23 09:47:10 +0200 | [diff] [blame] | 1603 | |
| 1604 | return wmi_send(wil, WMI_RCP_DELBA_CMDID, &cmd, sizeof(cmd)); |
| 1605 | } |
| 1606 | |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1607 | int wmi_addba_rx_resp(struct wil6210_priv *wil, u8 cid, u8 tid, u8 token, |
| 1608 | u16 status, bool amsdu, u16 agg_wsize, u16 timeout) |
| 1609 | { |
| 1610 | int rc; |
| 1611 | struct wmi_rcp_addba_resp_cmd cmd = { |
| 1612 | .cidxtid = mk_cidxtid(cid, tid), |
| 1613 | .dialog_token = token, |
| 1614 | .status_code = cpu_to_le16(status), |
| 1615 | /* bit 0: A-MSDU supported |
| 1616 | * bit 1: policy (should be 0 for us) |
| 1617 | * bits 2..5: TID |
| 1618 | * bits 6..15: buffer size |
| 1619 | */ |
| 1620 | .ba_param_set = cpu_to_le16((amsdu ? 1 : 0) | (tid << 2) | |
| 1621 | (agg_wsize << 6)), |
| 1622 | .ba_timeout = cpu_to_le16(timeout), |
| 1623 | }; |
| 1624 | struct { |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1625 | struct wmi_cmd_hdr wmi; |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1626 | struct wmi_rcp_addba_resp_sent_event evt; |
| 1627 | } __packed reply; |
| 1628 | |
| 1629 | wil_dbg_wmi(wil, |
| 1630 | "ADDBA response for CID %d TID %d size %d timeout %d status %d AMSDU%s\n", |
| 1631 | cid, tid, agg_wsize, timeout, status, amsdu ? "+" : "-"); |
| 1632 | |
| 1633 | rc = wmi_call(wil, WMI_RCP_ADDBA_RESP_CMDID, &cmd, sizeof(cmd), |
Vladimir Kondratiev | 230d844 | 2015-04-30 16:25:10 +0300 | [diff] [blame] | 1634 | WMI_RCP_ADDBA_RESP_SENT_EVENTID, &reply, sizeof(reply), |
| 1635 | 100); |
Vladimir Kondratiev | 3277213 | 2014-12-23 09:47:03 +0200 | [diff] [blame] | 1636 | if (rc) |
| 1637 | return rc; |
| 1638 | |
| 1639 | if (reply.evt.status) { |
| 1640 | wil_err(wil, "ADDBA response failed with status %d\n", |
| 1641 | le16_to_cpu(reply.evt.status)); |
| 1642 | rc = -EINVAL; |
| 1643 | } |
| 1644 | |
| 1645 | return rc; |
| 1646 | } |
| 1647 | |
Maya Erez | e77727f | 2016-12-06 12:21:17 +0200 | [diff] [blame] | 1648 | int wmi_ps_dev_profile_cfg(struct wil6210_priv *wil, |
| 1649 | enum wmi_ps_profile_type ps_profile) |
| 1650 | { |
| 1651 | int rc; |
| 1652 | struct wmi_ps_dev_profile_cfg_cmd cmd = { |
| 1653 | .ps_profile = ps_profile, |
| 1654 | }; |
| 1655 | struct { |
| 1656 | struct wmi_cmd_hdr wmi; |
| 1657 | struct wmi_ps_dev_profile_cfg_event evt; |
| 1658 | } __packed reply; |
| 1659 | u32 status; |
| 1660 | |
| 1661 | wil_dbg_wmi(wil, "Setting ps dev profile %d\n", ps_profile); |
| 1662 | |
| 1663 | reply.evt.status = cpu_to_le32(WMI_PS_CFG_CMD_STATUS_ERROR); |
| 1664 | |
| 1665 | rc = wmi_call(wil, WMI_PS_DEV_PROFILE_CFG_CMDID, &cmd, sizeof(cmd), |
| 1666 | WMI_PS_DEV_PROFILE_CFG_EVENTID, &reply, sizeof(reply), |
| 1667 | 100); |
| 1668 | if (rc) |
| 1669 | return rc; |
| 1670 | |
| 1671 | status = le32_to_cpu(reply.evt.status); |
| 1672 | |
| 1673 | if (status != WMI_PS_CFG_CMD_STATUS_SUCCESS) { |
| 1674 | wil_err(wil, "ps dev profile cfg failed with status %d\n", |
| 1675 | status); |
| 1676 | rc = -EINVAL; |
| 1677 | } |
| 1678 | |
| 1679 | return rc; |
| 1680 | } |
| 1681 | |
Lior David | de21eba | 2017-02-15 20:33:10 +0200 | [diff] [blame] | 1682 | int wmi_set_mgmt_retry(struct wil6210_priv *wil, u8 retry_short) |
| 1683 | { |
| 1684 | int rc; |
| 1685 | struct wmi_set_mgmt_retry_limit_cmd cmd = { |
| 1686 | .mgmt_retry_limit = retry_short, |
| 1687 | }; |
| 1688 | struct { |
| 1689 | struct wmi_cmd_hdr wmi; |
| 1690 | struct wmi_set_mgmt_retry_limit_event evt; |
| 1691 | } __packed reply; |
| 1692 | |
| 1693 | wil_dbg_wmi(wil, "Setting mgmt retry short %d\n", retry_short); |
| 1694 | |
| 1695 | if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities)) |
| 1696 | return -ENOTSUPP; |
| 1697 | |
| 1698 | reply.evt.status = WMI_FW_STATUS_FAILURE; |
| 1699 | |
| 1700 | rc = wmi_call(wil, WMI_SET_MGMT_RETRY_LIMIT_CMDID, &cmd, sizeof(cmd), |
| 1701 | WMI_SET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply), |
| 1702 | 100); |
| 1703 | if (rc) |
| 1704 | return rc; |
| 1705 | |
| 1706 | if (reply.evt.status != WMI_FW_STATUS_SUCCESS) { |
| 1707 | wil_err(wil, "set mgmt retry limit failed with status %d\n", |
| 1708 | reply.evt.status); |
| 1709 | rc = -EINVAL; |
| 1710 | } |
| 1711 | |
| 1712 | return rc; |
| 1713 | } |
| 1714 | |
| 1715 | int wmi_get_mgmt_retry(struct wil6210_priv *wil, u8 *retry_short) |
| 1716 | { |
| 1717 | int rc; |
| 1718 | struct { |
| 1719 | struct wmi_cmd_hdr wmi; |
| 1720 | struct wmi_get_mgmt_retry_limit_event evt; |
| 1721 | } __packed reply; |
| 1722 | |
| 1723 | wil_dbg_wmi(wil, "getting mgmt retry short\n"); |
| 1724 | |
| 1725 | if (!test_bit(WMI_FW_CAPABILITY_MGMT_RETRY_LIMIT, wil->fw_capabilities)) |
| 1726 | return -ENOTSUPP; |
| 1727 | |
| 1728 | reply.evt.mgmt_retry_limit = 0; |
| 1729 | rc = wmi_call(wil, WMI_GET_MGMT_RETRY_LIMIT_CMDID, NULL, 0, |
| 1730 | WMI_GET_MGMT_RETRY_LIMIT_EVENTID, &reply, sizeof(reply), |
| 1731 | 100); |
| 1732 | if (rc) |
| 1733 | return rc; |
| 1734 | |
| 1735 | if (retry_short) |
| 1736 | *retry_short = reply.evt.mgmt_retry_limit; |
| 1737 | |
| 1738 | return 0; |
| 1739 | } |
| 1740 | |
Maya Erez | 4cbb585 | 2017-02-16 15:26:09 +0200 | [diff] [blame] | 1741 | int wmi_abort_scan(struct wil6210_priv *wil) |
| 1742 | { |
| 1743 | int rc; |
| 1744 | |
| 1745 | wil_dbg_wmi(wil, "sending WMI_ABORT_SCAN_CMDID\n"); |
| 1746 | |
| 1747 | rc = wmi_send(wil, WMI_ABORT_SCAN_CMDID, NULL, 0); |
| 1748 | if (rc) |
| 1749 | wil_err(wil, "Failed to abort scan (%d)\n", rc); |
| 1750 | |
| 1751 | return rc; |
| 1752 | } |
| 1753 | |
Dedy Lansky | b94ee9e | 2017-02-23 15:53:29 +0200 | [diff] [blame] | 1754 | int wmi_new_sta(struct wil6210_priv *wil, const u8 *mac, u8 aid) |
| 1755 | { |
| 1756 | int rc; |
| 1757 | struct wmi_new_sta_cmd cmd = { |
| 1758 | .aid = aid, |
| 1759 | }; |
| 1760 | |
| 1761 | wil_dbg_wmi(wil, "new sta %pM, aid %d\n", mac, aid); |
| 1762 | |
| 1763 | ether_addr_copy(cmd.dst_mac, mac); |
| 1764 | |
| 1765 | rc = wmi_send(wil, WMI_NEW_STA_CMDID, &cmd, sizeof(cmd)); |
| 1766 | if (rc) |
| 1767 | wil_err(wil, "Failed to send new sta (%d)\n", rc); |
| 1768 | |
| 1769 | return rc; |
| 1770 | } |
| 1771 | |
Dedy Lansky | 1b75271 | 2017-03-20 15:35:51 +0200 | [diff] [blame] | 1772 | int wmi_set_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data) |
| 1773 | { |
| 1774 | int rc; |
| 1775 | struct wmi_set_thermal_throttling_cfg_cmd cmd = { |
| 1776 | .tt_data = *tt_data, |
| 1777 | }; |
| 1778 | struct { |
| 1779 | struct wmi_cmd_hdr wmi; |
| 1780 | struct wmi_set_thermal_throttling_cfg_event evt; |
| 1781 | } __packed reply; |
| 1782 | |
| 1783 | if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING, |
| 1784 | wil->fw_capabilities)) |
| 1785 | return -EOPNOTSUPP; |
| 1786 | |
| 1787 | memset(&reply, 0, sizeof(reply)); |
| 1788 | rc = wmi_call(wil, WMI_SET_THERMAL_THROTTLING_CFG_CMDID, &cmd, |
| 1789 | sizeof(cmd), WMI_SET_THERMAL_THROTTLING_CFG_EVENTID, |
| 1790 | &reply, sizeof(reply), 100); |
| 1791 | if (rc) { |
| 1792 | wil_err(wil, "failed to set thermal throttling\n"); |
| 1793 | return rc; |
| 1794 | } |
| 1795 | if (reply.evt.status) { |
| 1796 | wil_err(wil, "set thermal throttling failed, error %d\n", |
| 1797 | reply.evt.status); |
| 1798 | return -EIO; |
| 1799 | } |
| 1800 | |
| 1801 | wil->tt_data = *tt_data; |
| 1802 | wil->tt_data_set = true; |
| 1803 | |
| 1804 | return 0; |
| 1805 | } |
| 1806 | |
| 1807 | int wmi_get_tt_cfg(struct wil6210_priv *wil, struct wmi_tt_data *tt_data) |
| 1808 | { |
| 1809 | int rc; |
| 1810 | struct { |
| 1811 | struct wmi_cmd_hdr wmi; |
| 1812 | struct wmi_get_thermal_throttling_cfg_event evt; |
| 1813 | } __packed reply; |
| 1814 | |
| 1815 | if (!test_bit(WMI_FW_CAPABILITY_THERMAL_THROTTLING, |
| 1816 | wil->fw_capabilities)) |
| 1817 | return -EOPNOTSUPP; |
| 1818 | |
| 1819 | rc = wmi_call(wil, WMI_GET_THERMAL_THROTTLING_CFG_CMDID, NULL, 0, |
| 1820 | WMI_GET_THERMAL_THROTTLING_CFG_EVENTID, &reply, |
| 1821 | sizeof(reply), 100); |
| 1822 | if (rc) { |
| 1823 | wil_err(wil, "failed to get thermal throttling\n"); |
| 1824 | return rc; |
| 1825 | } |
| 1826 | |
| 1827 | if (tt_data) |
| 1828 | *tt_data = reply.evt.tt_data; |
| 1829 | |
| 1830 | return 0; |
| 1831 | } |
| 1832 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1833 | void wmi_event_flush(struct wil6210_priv *wil) |
| 1834 | { |
Hamad Kadmany | c33f749 | 2017-02-06 11:46:36 +0200 | [diff] [blame] | 1835 | ulong flags; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1836 | struct pending_wmi_event *evt, *t; |
| 1837 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1838 | wil_dbg_wmi(wil, "event_flush\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1839 | |
Hamad Kadmany | c33f749 | 2017-02-06 11:46:36 +0200 | [diff] [blame] | 1840 | spin_lock_irqsave(&wil->wmi_ev_lock, flags); |
| 1841 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1842 | list_for_each_entry_safe(evt, t, &wil->pending_wmi_ev, list) { |
| 1843 | list_del(&evt->list); |
| 1844 | kfree(evt); |
| 1845 | } |
Hamad Kadmany | c33f749 | 2017-02-06 11:46:36 +0200 | [diff] [blame] | 1846 | |
| 1847 | spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1848 | } |
| 1849 | |
| 1850 | static bool wmi_evt_call_handler(struct wil6210_priv *wil, int id, |
| 1851 | void *d, int len) |
| 1852 | { |
| 1853 | uint i; |
| 1854 | |
| 1855 | for (i = 0; i < ARRAY_SIZE(wmi_evt_handlers); i++) { |
| 1856 | if (wmi_evt_handlers[i].eventid == id) { |
| 1857 | wmi_evt_handlers[i].handler(wil, id, d, len); |
| 1858 | return true; |
| 1859 | } |
| 1860 | } |
| 1861 | |
| 1862 | return false; |
| 1863 | } |
| 1864 | |
| 1865 | static void wmi_event_handle(struct wil6210_priv *wil, |
| 1866 | struct wil6210_mbox_hdr *hdr) |
| 1867 | { |
| 1868 | u16 len = le16_to_cpu(hdr->len); |
| 1869 | |
| 1870 | if ((hdr->type == WIL_MBOX_HDR_TYPE_WMI) && |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1871 | (len >= sizeof(struct wmi_cmd_hdr))) { |
| 1872 | struct wmi_cmd_hdr *wmi = (void *)(&hdr[1]); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1873 | void *evt_data = (void *)(&wmi[1]); |
Lior David | b874dde | 2016-03-01 19:18:09 +0200 | [diff] [blame] | 1874 | u16 id = le16_to_cpu(wmi->command_id); |
Vladimir Kondratiev | 028e183 | 2014-09-10 16:34:33 +0300 | [diff] [blame] | 1875 | |
| 1876 | wil_dbg_wmi(wil, "Handle WMI 0x%04x (reply_id 0x%04x)\n", |
| 1877 | id, wil->reply_id); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1878 | /* check if someone waits for this event */ |
| 1879 | if (wil->reply_id && wil->reply_id == id) { |
Maya Erez | 0916d9f | 2016-01-17 12:39:10 +0200 | [diff] [blame] | 1880 | WARN_ON(wil->reply_buf); |
| 1881 | wmi_evt_call_handler(wil, id, evt_data, |
| 1882 | len - sizeof(*wmi)); |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1883 | wil_dbg_wmi(wil, "event_handle: Complete WMI 0x%04x\n", |
| 1884 | id); |
Dedy Lansky | 5950264 | 2014-09-10 16:34:46 +0300 | [diff] [blame] | 1885 | complete(&wil->wmi_call); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1886 | return; |
| 1887 | } |
| 1888 | /* unsolicited event */ |
| 1889 | /* search for handler */ |
| 1890 | if (!wmi_evt_call_handler(wil, id, evt_data, |
| 1891 | len - sizeof(*wmi))) { |
Dedy Lansky | a3ce5ccd | 2015-07-30 13:51:58 +0300 | [diff] [blame] | 1892 | wil_info(wil, "Unhandled event 0x%04x\n", id); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1893 | } |
| 1894 | } else { |
| 1895 | wil_err(wil, "Unknown event type\n"); |
| 1896 | print_hex_dump(KERN_ERR, "evt?? ", DUMP_PREFIX_OFFSET, 16, 1, |
| 1897 | hdr, sizeof(*hdr) + len, true); |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | /* |
| 1902 | * Retrieve next WMI event from the pending list |
| 1903 | */ |
| 1904 | static struct list_head *next_wmi_ev(struct wil6210_priv *wil) |
| 1905 | { |
| 1906 | ulong flags; |
| 1907 | struct list_head *ret = NULL; |
| 1908 | |
| 1909 | spin_lock_irqsave(&wil->wmi_ev_lock, flags); |
| 1910 | |
| 1911 | if (!list_empty(&wil->pending_wmi_ev)) { |
| 1912 | ret = wil->pending_wmi_ev.next; |
| 1913 | list_del(ret); |
| 1914 | } |
| 1915 | |
| 1916 | spin_unlock_irqrestore(&wil->wmi_ev_lock, flags); |
| 1917 | |
| 1918 | return ret; |
| 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * Handler for the WMI events |
| 1923 | */ |
| 1924 | void wmi_event_worker(struct work_struct *work) |
| 1925 | { |
| 1926 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, |
| 1927 | wmi_event_worker); |
| 1928 | struct pending_wmi_event *evt; |
| 1929 | struct list_head *lh; |
| 1930 | |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1931 | wil_dbg_wmi(wil, "event_worker: Start\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1932 | while ((lh = next_wmi_ev(wil)) != NULL) { |
| 1933 | evt = list_entry(lh, struct pending_wmi_event, list); |
| 1934 | wmi_event_handle(wil, &evt->event.hdr); |
| 1935 | kfree(evt); |
| 1936 | } |
Lazar Alexei | 3190cc6 | 2017-02-23 14:34:14 +0200 | [diff] [blame] | 1937 | wil_dbg_wmi(wil, "event_worker: Finished\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1938 | } |