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