blob: aade16b126c49b86338b8f90e5a231f89ec4eb09 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
Vladimir Shulman1f80af22015-01-25 10:52:48 +02002 * Copyright (c) 2012-2015 Qualcomm Atheros, Inc.
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08003 *
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
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080017#include <linux/moduleparam.h>
18#include <linux/if_arp.h>
Vladimir Kondratiev108d1eb2014-02-27 16:20:53 +020019#include <linux/etherdevice.h>
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080020
21#include "wil6210.h"
Vladimir Kondratievb4490f42014-02-27 16:20:44 +020022#include "txrx.h"
Dedy Lanskyf172b562014-09-10 16:34:38 +030023#include "wmi.h"
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +030024#include "boot_loader.h"
Dedy Lanskyf172b562014-09-10 16:34:38 +030025
26#define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000
27#define WAIT_FOR_DISCONNECT_INTERVAL_MS 10
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080028
Vladimir Kondratievbfc2dc72015-03-30 11:28:50 +030029bool debug_fw; /* = false; */
30module_param(debug_fw, bool, S_IRUGO);
31MODULE_PARM_DESC(debug_fw, " do not perform card reset. For FW debug");
32
Vladimir Kondratievc33407a2014-10-01 15:05:24 +030033bool no_fw_recovery;
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +020034module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +030035MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +020036
Vladimir Kondratievab954622014-12-23 09:47:20 +020037/* if not set via modparam, will be set to default value of 1/8 of
38 * rx ring size during init flow
39 */
40unsigned short rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_INIT;
41module_param(rx_ring_overflow_thrsh, ushort, S_IRUGO);
42MODULE_PARM_DESC(rx_ring_overflow_thrsh,
43 " RX ring overflow threshold in descriptors.");
Vladimir Kondratievb6b1b0e2014-09-22 15:31:41 +030044
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +020045/* We allow allocation of more than 1 page buffers to support large packets.
46 * It is suboptimal behavior performance wise in case MTU above page size.
47 */
Vladimir Kondratievc44690a2014-12-23 09:47:11 +020048unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - WIL_MAX_MPDU_OVERHEAD;
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +020049static int mtu_max_set(const char *val, const struct kernel_param *kp)
50{
51 int ret;
52
53 /* sets mtu_max directly. no need to restore it in case of
54 * illegal value since we assume this will fail insmod
55 */
56 ret = param_set_uint(val, kp);
57 if (ret)
58 return ret;
59
Vladimir Kondratiev4590d812014-12-23 09:47:12 +020060 if (mtu_max < 68 || mtu_max > WIL_MAX_ETH_MTU)
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +020061 ret = -EINVAL;
62
63 return ret;
64}
65
Luis R. Rodriguez9c278472015-05-27 11:09:38 +093066static const struct kernel_param_ops mtu_max_ops = {
Vladimir Kondratiev9a06bec2014-10-28 16:51:27 +020067 .set = mtu_max_set,
68 .get = param_get_uint,
69};
70
71module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
72MODULE_PARM_DESC(mtu_max, " Max MTU value.");
73
Vladimir Kondratievd3762b42014-12-01 15:35:02 +020074static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
75static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +020076static uint bcast_ring_order = WIL_BCAST_RING_SIZE_ORDER_DEFAULT;
Vladimir Kondratievd3762b42014-12-01 15:35:02 +020077
78static int ring_order_set(const char *val, const struct kernel_param *kp)
79{
80 int ret;
81 uint x;
82
83 ret = kstrtouint(val, 0, &x);
84 if (ret)
85 return ret;
86
87 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
88 return -EINVAL;
89
90 *((uint *)kp->arg) = x;
91
92 return 0;
93}
94
Luis R. Rodriguez9c278472015-05-27 11:09:38 +093095static const struct kernel_param_ops ring_order_ops = {
Vladimir Kondratievd3762b42014-12-01 15:35:02 +020096 .set = ring_order_set,
97 .get = param_get_uint,
98};
99
100module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, S_IRUGO);
101MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
102module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, S_IRUGO);
103MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
Vladimir Kondratievd507d1b2015-06-09 14:11:17 +0300104module_param_cb(bcast_ring_order, &ring_order_ops, &bcast_ring_order, S_IRUGO);
105MODULE_PARM_DESC(bcast_ring_order, " Bcast ring order; size = 1 << order");
Vladimir Kondratievd3762b42014-12-01 15:35:02 +0200106
Vladimir Kondratiev520d68e2014-08-06 10:31:53 +0300107#define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
108#define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
109
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800110/*
111 * Due to a hardware issue,
112 * one has to read/write to/from NIC in 32-bit chunks;
113 * regular memcpy_fromio and siblings will
114 * not work on 64-bit platform - it uses 64-bit transactions
115 *
116 * Force 32-bit transactions to enable NIC on 64-bit platforms
117 *
118 * To avoid byte swap on big endian host, __raw_{read|write}l
119 * should be used - {read|write}l would swap bytes to provide
120 * little endian on PCI value in host endianness.
121 */
122void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
123 size_t count)
124{
125 u32 *d = dst;
126 const volatile u32 __iomem *s = src;
127
128 /* size_t is unsigned, if (count%4 != 0) it will wrap */
129 for (count += 4; count > 4; count -= 4)
130 *d++ = __raw_readl(s++);
131}
132
133void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
134 size_t count)
135{
136 volatile u32 __iomem *d = dst;
137 const u32 *s = src;
138
139 for (count += 4; count > 4; count -= 4)
140 __raw_writel(*s++, d++);
141}
142
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200143static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200144 u16 reason_code, bool from_event)
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200145__acquires(&sta->tid_rx_lock) __releases(&sta->tid_rx_lock)
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200146{
147 uint i;
Vladimir Kondratievfc58f682014-06-16 19:37:16 +0300148 struct net_device *ndev = wil_to_ndev(wil);
149 struct wireless_dev *wdev = wil->wdev;
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200150 struct wil_sta_info *sta = &wil->sta[cid];
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300151
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200152 might_sleep();
Vladimir Kondratievfc58f682014-06-16 19:37:16 +0300153 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
154 sta->status);
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200155
156 if (sta->status != wil_sta_unused) {
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200157 if (!from_event)
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200158 wmi_disconnect_sta(wil, sta->addr, reason_code);
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200159
Vladimir Kondratievfc58f682014-06-16 19:37:16 +0300160 switch (wdev->iftype) {
161 case NL80211_IFTYPE_AP:
162 case NL80211_IFTYPE_P2P_GO:
163 /* AP-like interface */
164 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
165 break;
166 default:
167 break;
168 }
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +0200169 sta->status = wil_sta_unused;
170 }
171
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200172 for (i = 0; i < WIL_STA_TID_NUM; i++) {
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300173 struct wil_tid_ampdu_rx *r;
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300174
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200175 spin_lock_bh(&sta->tid_rx_lock);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300176
177 r = sta->tid_rx[i];
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200178 sta->tid_rx[i] = NULL;
179 wil_tid_ampdu_rx_free(wil, r);
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300180
Vladimir Kondratievbd332732014-12-23 09:47:24 +0200181 spin_unlock_bh(&sta->tid_rx_lock);
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200182 }
183 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
184 if (wil->vring2cid_tid[i][0] == cid)
185 wil_vring_fini_tx(wil, i);
186 }
187 memset(&sta->stats, 0, sizeof(sta->stats));
188}
189
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200190static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200191 u16 reason_code, bool from_event)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800192{
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200193 int cid = -ENOENT;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800194 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200195 struct wireless_dev *wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800196
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200197 might_sleep();
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200198 wil_dbg_misc(wil, "%s(bssid=%pM, reason=%d, ev%s)\n", __func__, bssid,
199 reason_code, from_event ? "+" : "-");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800200
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200201 /* Cases are:
202 * - disconnect single STA, still connected
203 * - disconnect single STA, already disconnected
204 * - disconnect all
205 *
Vladimir Kondratiev68682b42015-10-04 10:23:22 +0300206 * For "disconnect all", there are 3 options:
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200207 * - bssid == NULL
Vladimir Kondratiev68682b42015-10-04 10:23:22 +0300208 * - bssid is broadcast address (ff:ff:ff:ff:ff:ff)
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200209 * - bssid is our MAC address
210 */
Vladimir Kondratiev68682b42015-10-04 10:23:22 +0300211 if (bssid && !is_broadcast_ether_addr(bssid) &&
212 !ether_addr_equal_unaligned(ndev->dev_addr, bssid)) {
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200213 cid = wil_find_cid(wil, bssid);
214 wil_dbg_misc(wil, "Disconnect %pM, CID=%d, reason=%d\n",
215 bssid, cid, reason_code);
216 if (cid >= 0) /* disconnect 1 peer */
217 wil_disconnect_cid(wil, cid, reason_code, from_event);
218 } else { /* all */
219 wil_dbg_misc(wil, "Disconnect all\n");
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200220 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200221 wil_disconnect_cid(wil, cid, reason_code, from_event);
Vladimir Kondratiev100106d2014-12-23 09:47:07 +0200222 }
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200223
224 /* link state */
225 switch (wdev->iftype) {
226 case NL80211_IFTYPE_STATION:
227 case NL80211_IFTYPE_P2P_CLIENT:
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200228 wil_bcast_fini(wil);
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200229 netif_tx_stop_all_queues(ndev);
230 netif_carrier_off(ndev);
231
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200232 if (test_bit(wil_status_fwconnected, wil->status)) {
233 clear_bit(wil_status_fwconnected, wil->status);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200234 cfg80211_disconnected(ndev, reason_code,
Johannes Berg80279fb2015-05-22 16:22:20 +0200235 NULL, 0, false, GFP_KERNEL);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200236 } else if (test_bit(wil_status_fwconnecting, wil->status)) {
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200237 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
238 WLAN_STATUS_UNSPECIFIED_FAILURE,
239 GFP_KERNEL);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200240 }
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200241 clear_bit(wil_status_fwconnecting, wil->status);
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200242 break;
243 default:
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200244 break;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200245 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800246}
247
248static void wil_disconnect_worker(struct work_struct *work)
249{
250 struct wil6210_priv *wil = container_of(work,
251 struct wil6210_priv, disconnect_worker);
252
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200253 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200254 _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200255 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800256}
257
258static void wil_connect_timer_fn(ulong x)
259{
260 struct wil6210_priv *wil = (void *)x;
261
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200262 wil_dbg_misc(wil, "Connect timeout\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800263
264 /* reschedule to thread context - disconnect won't
265 * run from atomic context
266 */
267 schedule_work(&wil->disconnect_worker);
268}
269
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300270static void wil_scan_timer_fn(ulong x)
271{
272 struct wil6210_priv *wil = (void *)x;
273
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200274 clear_bit(wil_status_fwready, wil->status);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300275 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
Vladimir Kondratiev8ad66002015-07-30 13:51:54 +0300276 wil_fw_error_recovery(wil);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300277}
278
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300279static int wil_wait_for_recovery(struct wil6210_priv *wil)
280{
281 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
282 fw_recovery_pending)) {
283 wil_err(wil, "Interrupt, canceling recovery\n");
284 return -ERESTARTSYS;
285 }
286 if (wil->recovery_state != fw_recovery_running) {
287 wil_info(wil, "Recovery cancelled\n");
288 return -EINTR;
289 }
290 wil_info(wil, "Proceed with recovery\n");
291 return 0;
292}
293
294void wil_set_recovery_state(struct wil6210_priv *wil, int state)
295{
296 wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
297 wil->recovery_state, state);
298
299 wil->recovery_state = state;
300 wake_up_interruptible(&wil->wq);
301}
302
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200303static void wil_fw_error_worker(struct work_struct *work)
304{
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300305 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
306 fw_error_worker);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200307 struct wireless_dev *wdev = wil->wdev;
308
309 wil_dbg_misc(wil, "fw error worker\n");
310
Vladimir Kondratievcded9362014-10-28 16:50:06 +0200311 if (!netif_running(wil_to_ndev(wil))) {
312 wil_info(wil, "No recovery - interface is down\n");
313 return;
314 }
315
Vladimir Kondratievfc219ee2014-05-27 14:45:45 +0300316 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
317 * passed since last recovery attempt
318 */
319 if (time_is_after_jiffies(wil->last_fw_recovery +
320 WIL6210_FW_RECOVERY_TO))
321 wil->recovery_count++;
322 else
323 wil->recovery_count = 1; /* fw was alive for a long time */
324
325 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
326 wil_err(wil, "too many recovery attempts (%d), giving up\n",
327 wil->recovery_count);
328 return;
329 }
330
331 wil->last_fw_recovery = jiffies;
332
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200333 mutex_lock(&wil->mutex);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200334 switch (wdev->iftype) {
335 case NL80211_IFTYPE_STATION:
336 case NL80211_IFTYPE_P2P_CLIENT:
337 case NL80211_IFTYPE_MONITOR:
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300338 wil_info(wil, "fw error recovery requested (try %d)...\n",
Vladimir Kondratievfc219ee2014-05-27 14:45:45 +0300339 wil->recovery_count);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300340 if (!no_fw_recovery)
341 wil->recovery_state = fw_recovery_running;
342 if (0 != wil_wait_for_recovery(wil))
343 break;
344
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300345 __wil_down(wil);
346 __wil_up(wil);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200347 break;
348 case NL80211_IFTYPE_AP:
349 case NL80211_IFTYPE_P2P_GO:
Vladimir Kondratieve2405372014-10-28 16:50:09 +0200350 wil_info(wil, "No recovery for AP-like interface\n");
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200351 /* recovery in these modes is done by upper layers */
352 break;
353 default:
Vladimir Kondratieve2405372014-10-28 16:50:09 +0200354 wil_err(wil, "No recovery - unknown interface type %d\n",
355 wdev->iftype);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200356 break;
357 }
Vladimir Kondratiev9c3bde52014-03-17 15:34:21 +0200358 mutex_unlock(&wil->mutex);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200359}
360
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200361static int wil_find_free_vring(struct wil6210_priv *wil)
362{
363 int i;
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300364
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200365 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
366 if (!wil->vring_tx[i].va)
367 return i;
368 }
369 return -EINVAL;
370}
371
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200372int wil_bcast_init(struct wil6210_priv *wil)
373{
374 int ri = wil->bcast_vring, rc;
375
376 if ((ri >= 0) && wil->vring_tx[ri].va)
377 return 0;
378
379 ri = wil_find_free_vring(wil);
380 if (ri < 0)
381 return ri;
382
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300383 wil->bcast_vring = ri;
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200384 rc = wil_vring_init_bcast(wil, ri, 1 << bcast_ring_order);
Vladimir Kondratiev230d8442015-04-30 16:25:10 +0300385 if (rc)
386 wil->bcast_vring = -1;
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200387
388 return rc;
389}
390
391void wil_bcast_fini(struct wil6210_priv *wil)
392{
393 int ri = wil->bcast_vring;
394
395 if (ri < 0)
396 return;
397
398 wil->bcast_vring = -1;
399 wil_vring_fini_tx(wil, ri);
400}
401
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200402static void wil_connect_worker(struct work_struct *work)
403{
404 int rc;
405 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
406 connect_worker);
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200407 struct net_device *ndev = wil_to_ndev(wil);
408
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200409 int cid = wil->pending_connect_cid;
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200410 int ringid = wil_find_free_vring(wil);
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200411
412 if (cid < 0) {
413 wil_err(wil, "No connection pending\n");
414 return;
415 }
416
417 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
418
Vladimir Kondratievd3762b42014-12-01 15:35:02 +0200419 rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200420 wil->pending_connect_cid = -1;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200421 if (rc == 0) {
422 wil->sta[cid].status = wil_sta_connected;
Dedy Lanskyc5e96c92015-01-25 10:52:43 +0200423 netif_tx_wake_all_queues(ndev);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200424 } else {
425 wil->sta[cid].status = wil_sta_unused;
426 }
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200427}
428
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800429int wil_priv_init(struct wil6210_priv *wil)
430{
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300431 uint i;
432
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200433 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800434
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200435 memset(wil->sta, 0, sizeof(wil->sta));
Dedy Lanskyec81b5a2014-09-10 16:34:42 +0300436 for (i = 0; i < WIL6210_MAX_CID; i++)
437 spin_lock_init(&wil->sta[i].tid_rx_lock);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200438
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800439 mutex_init(&wil->mutex);
440 mutex_init(&wil->wmi_mutex);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200441 mutex_init(&wil->back_rx_mutex);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200442 mutex_init(&wil->back_tx_mutex);
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200443 mutex_init(&wil->probe_client_mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800444
445 init_completion(&wil->wmi_ready);
Dedy Lansky59502642014-09-10 16:34:46 +0300446 init_completion(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800447
448 wil->pending_connect_cid = -1;
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200449 wil->bcast_vring = -1;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800450 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300451 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800452
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200453 INIT_WORK(&wil->connect_worker, wil_connect_worker);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800454 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
455 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200456 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200457 INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200458 INIT_WORK(&wil->back_tx_worker, wil_back_tx_worker);
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200459 INIT_WORK(&wil->probe_client_worker, wil_probe_client_worker);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800460
461 INIT_LIST_HEAD(&wil->pending_wmi_ev);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200462 INIT_LIST_HEAD(&wil->back_rx_pending);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200463 INIT_LIST_HEAD(&wil->back_tx_pending);
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200464 INIT_LIST_HEAD(&wil->probe_client_pending);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465 spin_lock_init(&wil->wmi_ev_lock);
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300466 init_waitqueue_head(&wil->wq);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800467
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200468 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800469 if (!wil->wmi_wq)
470 return -EAGAIN;
471
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200472 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
473 if (!wil->wq_service)
474 goto out_wmi_wq;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800475
Vladimir Kondratievfc219ee2014-05-27 14:45:45 +0300476 wil->last_fw_recovery = jiffies;
Vladimir Shulman1f80af22015-01-25 10:52:48 +0200477 wil->tx_interframe_timeout = WIL6210_ITR_TX_INTERFRAME_TIMEOUT_DEFAULT;
478 wil->rx_interframe_timeout = WIL6210_ITR_RX_INTERFRAME_TIMEOUT_DEFAULT;
479 wil->tx_max_burst_duration = WIL6210_ITR_TX_MAX_BURST_DURATION_DEFAULT;
480 wil->rx_max_burst_duration = WIL6210_ITR_RX_MAX_BURST_DURATION_DEFAULT;
Vladimir Kondratievfc219ee2014-05-27 14:45:45 +0300481
Vladimir Kondratievab954622014-12-23 09:47:20 +0200482 if (rx_ring_overflow_thrsh == WIL6210_RX_HIGH_TRSH_INIT)
483 rx_ring_overflow_thrsh = WIL6210_RX_HIGH_TRSH_DEFAULT;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800484 return 0;
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200485
486out_wmi_wq:
487 destroy_workqueue(wil->wmi_wq);
488
489 return -EAGAIN;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800490}
491
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200492/**
493 * wil6210_disconnect - disconnect one connection
494 * @wil: driver context
495 * @bssid: peer to disconnect, NULL to disconnect all
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200496 * @reason_code: Reason code for the Disassociation frame
Vladimir Kondratievb516fcc2014-10-28 16:50:08 +0200497 * @from_event: whether is invoked from FW event handler
498 *
499 * Disconnect and release associated resources. If invoked not from the
500 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
501 */
502void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200503 u16 reason_code, bool from_event)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800504{
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300505 wil_dbg_misc(wil, "%s()\n", __func__);
506
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800507 del_timer_sync(&wil->connect_timer);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200508 _wil6210_disconnect(wil, bssid, reason_code, from_event);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800509}
510
511void wil_priv_deinit(struct wil6210_priv *wil)
512{
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300513 wil_dbg_misc(wil, "%s()\n", __func__);
514
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300515 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300516 del_timer_sync(&wil->scan_timer);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800517 cancel_work_sync(&wil->disconnect_worker);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200518 cancel_work_sync(&wil->fw_error_worker);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200519 mutex_lock(&wil->mutex);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200520 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200521 mutex_unlock(&wil->mutex);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800522 wmi_event_flush(wil);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200523 wil_back_rx_flush(wil);
524 cancel_work_sync(&wil->back_rx_worker);
Vladimir Kondratiev3a124ed2014-12-23 09:47:04 +0200525 wil_back_tx_flush(wil);
526 cancel_work_sync(&wil->back_tx_worker);
Vladimir Kondratiev40822a92015-01-25 10:52:50 +0200527 wil_probe_client_flush(wil);
528 cancel_work_sync(&wil->probe_client_worker);
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200529 destroy_workqueue(wil->wq_service);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800530 destroy_workqueue(wil->wmi_wq);
531}
532
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300533static inline void wil_halt_cpu(struct wil6210_priv *wil)
534{
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300535 wil_w(wil, RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
536 wil_w(wil, RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300537}
538
539static inline void wil_release_cpu(struct wil6210_priv *wil)
540{
541 /* Start CPU */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300542 wil_w(wil, RGF_USER_USER_CPU_0, 1);
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300543}
544
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300545static int wil_target_reset(struct wil6210_priv *wil)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800546{
Vladimir Kondratiev98a65b52014-03-17 15:34:12 +0200547 int delay = 0;
Vladimir Kondratievbb6c8dc2015-04-30 16:25:07 +0300548 u32 x, x1 = 0;
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200549
Vladimir Kondratiev1aeda132014-12-23 09:47:18 +0200550 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->hw_name);
Vladimir Kondratiev65082812014-07-14 09:49:37 +0300551
552 /* Clear MAC link up */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300553 wil_s(wil, RGF_HP_CTRL, BIT(15));
554 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
555 wil_s(wil, RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300556
557 wil_halt_cpu(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800558
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200559 /* clear all boot loader "ready" bits */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300560 wil_w(wil, RGF_USER_BL +
561 offsetof(struct bl_dedicated_registers_v0, boot_loader_ready), 0);
Vladimir Kondratievcce477112014-12-01 15:36:31 +0200562 /* Clear Fw Download notification */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300563 wil_c(wil, RGF_USER_USAGE_6, BIT(0));
Vladimir Kondratievcce477112014-12-01 15:36:31 +0200564
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300565 wil_s(wil, RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +0200566 /* XTAL stabilization should take about 3ms */
567 usleep_range(5000, 7000);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300568 x = wil_r(wil, RGF_CAF_PLL_LOCK_STATUS);
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +0200569 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
570 wil_err(wil, "Xtal stabilization timeout\n"
571 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
572 return -ETIME;
Vladimir Kondratiev65082812014-07-14 09:49:37 +0300573 }
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +0200574 /* switch 10k to XTAL*/
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300575 wil_c(wil, RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +0200576 /* 40 MHz */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300577 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
Vladimir Kondratiev9a5511b2015-02-15 14:02:31 +0200578
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300579 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
580 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
Vladimir Kondratiev65082812014-07-14 09:49:37 +0300581
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300582 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
583 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
584 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x000000f0);
585 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800586
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300587 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
588 wil_w(wil, RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
Vladimir Kondratiev65082812014-07-14 09:49:37 +0300589
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300590 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
591 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
592 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
593 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800594
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300595 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
596 /* reset A2 PCIE AHB */
597 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
Vladimir Kondratiev65082812014-07-14 09:49:37 +0300598
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300599 wil_w(wil, RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800600
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200601 /* wait until device ready. typical time is 20..80 msec */
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200602 do {
Vladimir Kondratiev520d68e2014-08-06 10:31:53 +0300603 msleep(RST_DELAY);
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300604 x = wil_r(wil, RGF_USER_BL +
605 offsetof(struct bl_dedicated_registers_v0,
606 boot_loader_ready));
Vladimir Kondratievbb6c8dc2015-04-30 16:25:07 +0300607 if (x1 != x) {
608 wil_dbg_misc(wil, "BL.ready 0x%08x => 0x%08x\n", x1, x);
609 x1 = x;
610 }
Vladimir Kondratiev520d68e2014-08-06 10:31:53 +0300611 if (delay++ > RST_COUNT) {
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200612 wil_err(wil, "Reset not completed, bl.ready 0x%08x\n",
Vladimir Kondratiev48516292014-10-28 16:50:07 +0200613 x);
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300614 return -ETIME;
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200615 }
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300616 } while (x != BL_READY);
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200617
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300618 wil_c(wil, RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
Vladimir Kondratiev972072a2014-03-17 15:34:15 +0200619
Vladimir Kondratieve3351272015-02-15 14:02:32 +0200620 /* enable fix for HW bug related to the SA/DA swap in AP Rx */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300621 wil_s(wil, RGF_DMA_OFUL_NID_0, BIT_DMA_OFUL_NID_0_RX_EXT_TR_EN |
622 BIT_DMA_OFUL_NID_0_RX_EXT_A3_SRC);
Vladimir Kondratieve3351272015-02-15 14:02:32 +0200623
Vladimir Kondratiev520d68e2014-08-06 10:31:53 +0300624 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300625 return 0;
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300626}
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800627
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800628void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
629{
630 le32_to_cpus(&r->base);
631 le16_to_cpus(&r->entry_size);
632 le16_to_cpus(&r->size);
633 le32_to_cpus(&r->tail);
634 le32_to_cpus(&r->head);
635}
636
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200637static int wil_get_bl_info(struct wil6210_priv *wil)
638{
639 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300640 union {
641 struct bl_dedicated_registers_v0 bl0;
642 struct bl_dedicated_registers_v1 bl1;
643 } bl;
644 u32 bl_ver;
645 u8 *mac;
646 u16 rf_status;
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200647
Vladimir Kondratiev19c871c2015-07-30 13:52:07 +0300648 wil_memcpy_fromio_32(&bl, wil->csr + HOSTADDR(RGF_USER_BL),
649 sizeof(bl));
650 bl_ver = le32_to_cpu(bl.bl0.boot_loader_struct_version);
651 mac = bl.bl0.mac_address;
652
653 if (bl_ver == 0) {
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300654 le32_to_cpus(&bl.bl0.rf_type);
655 le32_to_cpus(&bl.bl0.baseband_type);
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300656 rf_status = 0; /* actually, unknown */
657 wil_info(wil,
658 "Boot Loader struct v%d: MAC = %pM RF = 0x%08x bband = 0x%08x\n",
659 bl_ver, mac,
660 bl.bl0.rf_type, bl.bl0.baseband_type);
661 wil_info(wil, "Boot Loader build unknown for struct v0\n");
Vladimir Kondratiev19c871c2015-07-30 13:52:07 +0300662 } else {
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300663 le16_to_cpus(&bl.bl1.rf_type);
664 rf_status = le16_to_cpu(bl.bl1.rf_status);
665 le32_to_cpus(&bl.bl1.baseband_type);
666 le16_to_cpus(&bl.bl1.bl_version_subminor);
667 le16_to_cpus(&bl.bl1.bl_version_build);
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300668 wil_info(wil,
669 "Boot Loader struct v%d: MAC = %pM RF = 0x%04x (status 0x%04x) bband = 0x%08x\n",
670 bl_ver, mac,
671 bl.bl1.rf_type, rf_status,
672 bl.bl1.baseband_type);
673 wil_info(wil, "Boot Loader build %d.%d.%d.%d\n",
674 bl.bl1.bl_version_major, bl.bl1.bl_version_minor,
675 bl.bl1.bl_version_subminor, bl.bl1.bl_version_build);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200676 }
677
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300678 if (!is_valid_ether_addr(mac)) {
679 wil_err(wil, "BL: Invalid MAC %pM\n", mac);
680 return -EINVAL;
681 }
682
683 ether_addr_copy(ndev->perm_addr, mac);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200684 if (!is_valid_ether_addr(ndev->dev_addr))
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300685 ether_addr_copy(ndev->dev_addr, mac);
686
687 if (rf_status) {/* bad RF cable? */
688 wil_err(wil, "RF communication error 0x%04x",
689 rf_status);
690 return -EAGAIN;
691 }
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200692
693 return 0;
694}
695
Vladimir Kondratiev409ead52015-07-30 13:52:06 +0300696static void wil_bl_crash_info(struct wil6210_priv *wil, bool is_err)
697{
698 u32 bl_assert_code, bl_assert_blink, bl_magic_number;
699 u32 bl_ver = wil_r(wil, RGF_USER_BL +
700 offsetof(struct bl_dedicated_registers_v0,
701 boot_loader_struct_version));
702
703 if (bl_ver < 2)
704 return;
705
706 bl_assert_code = wil_r(wil, RGF_USER_BL +
707 offsetof(struct bl_dedicated_registers_v1,
708 bl_assert_code));
709 bl_assert_blink = wil_r(wil, RGF_USER_BL +
710 offsetof(struct bl_dedicated_registers_v1,
711 bl_assert_blink));
712 bl_magic_number = wil_r(wil, RGF_USER_BL +
713 offsetof(struct bl_dedicated_registers_v1,
714 bl_magic_number));
715
716 if (is_err) {
717 wil_err(wil,
718 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
719 bl_assert_code, bl_assert_blink, bl_magic_number);
720 } else {
721 wil_dbg_misc(wil,
722 "BL assert code 0x%08x blink 0x%08x magic 0x%08x\n",
723 bl_assert_code, bl_assert_blink, bl_magic_number);
724 }
725}
726
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800727static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
728{
729 ulong to = msecs_to_jiffies(1000);
730 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
Vladimir Kondratiev8fe59622014-09-10 16:34:34 +0300731
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800732 if (0 == left) {
733 wil_err(wil, "Firmware not ready\n");
734 return -ETIME;
735 } else {
Vladimir Kondratiev15e23122014-04-08 11:36:16 +0300736 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
737 jiffies_to_msecs(to-left), wil->hw_version);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800738 }
739 return 0;
740}
741
742/*
743 * We reset all the structures, and we reset the UMAC.
744 * After calling this routine, you're expected to reload
745 * the firmware.
746 */
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200747int wil_reset(struct wil6210_priv *wil, bool load_fw)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800748{
749 int rc;
750
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300751 wil_dbg_misc(wil, "%s()\n", __func__);
752
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200753 WARN_ON(!mutex_is_locked(&wil->mutex));
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200754 WARN_ON(test_bit(wil_status_napi_en, wil->status));
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200755
Vladimir Kondratievbfc2dc72015-03-30 11:28:50 +0300756 if (debug_fw) {
757 static const u8 mac[ETH_ALEN] = {
758 0x00, 0xde, 0xad, 0x12, 0x34, 0x56,
759 };
760 struct net_device *ndev = wil_to_ndev(wil);
761
762 ether_addr_copy(ndev->perm_addr, mac);
763 ether_addr_copy(ndev->dev_addr, ndev->perm_addr);
764 return 0;
765 }
766
Vladimir Kondratiev67131a12015-07-30 13:51:55 +0300767 if (wil->hw_version == HW_VER_UNKNOWN)
768 return -ENODEV;
769
Hamad Kadmanyf13e0632015-10-04 10:23:27 +0300770 set_bit(wil_status_resetting, wil->status);
771
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200772 cancel_work_sync(&wil->disconnect_worker);
Vladimir Kondratiev4821e6d2014-12-01 15:33:15 +0200773 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
Vladimir Kondratiev41d6b092015-03-15 16:00:23 +0200774 wil_bcast_fini(wil);
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200775
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200776 /* prevent NAPI from being scheduled */
777 bitmap_zero(wil->status, wil_status_last);
Vladimir Kondratiev0fef1812014-03-17 15:34:18 +0200778
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200779 if (wil->scan_request) {
780 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
781 wil->scan_request);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300782 del_timer_sync(&wil->scan_timer);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200783 cfg80211_scan_done(wil->scan_request, true);
784 wil->scan_request = NULL;
785 }
786
Vladimir Kondratieve4dbb092014-09-10 16:34:49 +0300787 wil_mask_irq(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800788
Vladimir Kondratieve08b5902013-01-28 18:31:05 +0200789 wmi_event_flush(wil);
790
Vladimir Kondratiev32772132014-12-23 09:47:03 +0200791 flush_workqueue(wil->wq_service);
Vladimir Kondratieve08b5902013-01-28 18:31:05 +0200792 flush_workqueue(wil->wmi_wq);
793
Vladimir Kondratiev409ead52015-07-30 13:52:06 +0300794 wil_bl_crash_info(wil, false);
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300795 rc = wil_target_reset(wil);
Vladimir Kondratiev8bf6adb2014-03-17 15:34:17 +0200796 wil_rx_fini(wil);
Vladimir Kondratiev409ead52015-07-30 13:52:06 +0300797 if (rc) {
798 wil_bl_crash_info(wil, true);
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300799 return rc;
Vladimir Kondratiev409ead52015-07-30 13:52:06 +0300800 }
Vladimir Kondratievbbb2adc2014-08-06 10:31:52 +0300801
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200802 rc = wil_get_bl_info(wil);
Vladimir Kondratievf1ad8c92015-07-30 13:51:49 +0300803 if (rc == -EAGAIN && !load_fw) /* ignore RF error if not going up */
804 rc = 0;
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200805 if (rc)
806 return rc;
807
808 if (load_fw) {
809 wil_info(wil, "Use firmware <%s> + board <%s>\n", WIL_FW_NAME,
810 WIL_FW2_NAME);
811
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300812 wil_halt_cpu(wil);
813 /* Loading f/w from the file */
814 rc = wil_request_firmware(wil, WIL_FW_NAME);
815 if (rc)
816 return rc;
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200817 rc = wil_request_firmware(wil, WIL_FW2_NAME);
818 if (rc)
819 return rc;
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300820
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200821 /* Mark FW as loaded from host */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300822 wil_s(wil, RGF_USER_USAGE_6, 1);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200823
824 /* clear any interrupts which on-card-firmware
825 * may have set
826 */
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300827 wil6210_clear_irq(wil);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200828 /* CAF_ICR - clear and mask */
829 /* it is W1C, clear by writing back same value */
Vladimir Kondratievb9eeb512015-07-30 13:52:03 +0300830 wil_s(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, ICR), 0);
831 wil_w(wil, RGF_CAF_ICR + offsetof(struct RGF_ICR, IMV), ~0);
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300832
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300833 wil_release_cpu(wil);
Vladimir Kondratiev151a9702014-09-10 16:34:30 +0300834 }
Vladimir Kondratiev8bf6adb2014-03-17 15:34:17 +0200835
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800836 /* init after reset */
837 wil->pending_connect_cid = -1;
Vladimir Kondratiev02beaf12015-03-08 15:42:03 +0200838 wil->ap_isolate = 0;
Wolfram Sang16735d02013-11-14 14:32:02 -0800839 reinit_completion(&wil->wmi_ready);
Dedy Lansky59502642014-09-10 16:34:46 +0300840 reinit_completion(&wil->wmi_call);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800841
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200842 if (load_fw) {
843 wil_configure_interrupt_moderation(wil);
844 wil_unmask_irq(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800845
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200846 /* we just started MAC, wait for FW ready */
847 rc = wil_wait_for_fw_ready(wil);
Vladimir Kondratievcec94d82015-03-15 16:00:17 +0200848 if (rc == 0) /* check FW is responsive */
849 rc = wmi_echo(wil);
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200850 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800851
852 return rc;
853}
854
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200855void wil_fw_error_recovery(struct wil6210_priv *wil)
856{
857 wil_dbg_misc(wil, "starting fw error recovery\n");
Hamad Kadmanyf13e0632015-10-04 10:23:27 +0300858
859 if (test_bit(wil_status_resetting, wil->status)) {
860 wil_info(wil, "Reset already in progress\n");
861 return;
862 }
863
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300864 wil->recovery_state = fw_recovery_pending;
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200865 schedule_work(&wil->fw_error_worker);
866}
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800867
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300868int __wil_up(struct wil6210_priv *wil)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800869{
870 struct net_device *ndev = wil_to_ndev(wil);
871 struct wireless_dev *wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800872 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800873
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200874 WARN_ON(!mutex_is_locked(&wil->mutex));
875
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200876 rc = wil_reset(wil, true);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800877 if (rc)
878 return rc;
879
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300880 /* Rx VRING. After MAC and beacon */
Vladimir Kondratievd3762b42014-12-01 15:35:02 +0200881 rc = wil_rx_init(wil, 1 << rx_ring_order);
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300882 if (rc)
883 return rc;
884
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800885 switch (wdev->iftype) {
886 case NL80211_IFTYPE_STATION:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200887 wil_dbg_misc(wil, "type: STATION\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800888 ndev->type = ARPHRD_ETHER;
889 break;
890 case NL80211_IFTYPE_AP:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200891 wil_dbg_misc(wil, "type: AP\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800892 ndev->type = ARPHRD_ETHER;
893 break;
894 case NL80211_IFTYPE_P2P_CLIENT:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200895 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800896 ndev->type = ARPHRD_ETHER;
897 break;
898 case NL80211_IFTYPE_P2P_GO:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200899 wil_dbg_misc(wil, "type: P2P_GO\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800900 ndev->type = ARPHRD_ETHER;
901 break;
902 case NL80211_IFTYPE_MONITOR:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200903 wil_dbg_misc(wil, "type: Monitor\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800904 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
905 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
906 break;
907 default:
908 return -EOPNOTSUPP;
909 }
910
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800911 /* MAC address - pre-requisite for other commands */
912 wmi_set_mac_address(wil, ndev->dev_addr);
913
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300914 wil_dbg_misc(wil, "NAPI enable\n");
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300915 napi_enable(&wil->napi_rx);
916 napi_enable(&wil->napi_tx);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200917 set_bit(wil_status_napi_en, wil->status);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300918
Vladimir Kondratievf772ebf2014-09-10 16:34:35 +0300919 if (wil->platform_ops.bus_request)
920 wil->platform_ops.bus_request(wil->platform_handle,
921 WIL_MAX_BUS_REQUEST_KBPS);
922
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800923 return 0;
924}
925
926int wil_up(struct wil6210_priv *wil)
927{
928 int rc;
929
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300930 wil_dbg_misc(wil, "%s()\n", __func__);
931
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800932 mutex_lock(&wil->mutex);
933 rc = __wil_up(wil);
934 mutex_unlock(&wil->mutex);
935
936 return rc;
937}
938
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300939int __wil_down(struct wil6210_priv *wil)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800940{
Dedy Lanskyf172b562014-09-10 16:34:38 +0300941 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
942 WAIT_FOR_DISCONNECT_INTERVAL_MS;
943
Vladimir Kondratiev097638a2014-03-17 15:34:25 +0200944 WARN_ON(!mutex_is_locked(&wil->mutex));
945
Vladimir Kondratievf772ebf2014-09-10 16:34:35 +0300946 if (wil->platform_ops.bus_request)
947 wil->platform_ops.bus_request(wil->platform_handle, 0);
948
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300949 wil_disable_irq(wil);
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200950 if (test_and_clear_bit(wil_status_napi_en, wil->status)) {
Vladimir Kondratiev73d839a2014-09-10 16:34:50 +0300951 napi_disable(&wil->napi_rx);
952 napi_disable(&wil->napi_tx);
953 wil_dbg_misc(wil, "NAPI disable\n");
954 }
955 wil_enable_irq(wil);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300956
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800957 if (wil->scan_request) {
Vladimir Kondratiev2a91d7d2014-06-16 19:37:11 +0300958 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
959 wil->scan_request);
Vladimir Kondratiev047e5d72014-05-27 14:45:48 +0300960 del_timer_sync(&wil->scan_timer);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800961 cfg80211_scan_done(wil->scan_request, true);
962 wil->scan_request = NULL;
963 }
964
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200965 if (test_bit(wil_status_fwconnected, wil->status) ||
966 test_bit(wil_status_fwconnecting, wil->status))
Dedy Lanskyf172b562014-09-10 16:34:38 +0300967 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
968
969 /* make sure wil is idle (not connected) */
970 mutex_unlock(&wil->mutex);
971 while (iter--) {
Vladimir Kondratiev9419b6a2014-12-23 09:47:14 +0200972 int idle = !test_bit(wil_status_fwconnected, wil->status) &&
973 !test_bit(wil_status_fwconnecting, wil->status);
Dedy Lanskyf172b562014-09-10 16:34:38 +0300974 if (idle)
975 break;
976 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
977 }
978 mutex_lock(&wil->mutex);
979
980 if (!iter)
981 wil_err(wil, "timeout waiting for idle FW/HW\n");
982
Vladimir Kondratiev2cd0f022015-02-15 14:02:30 +0200983 wil_reset(wil, false);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800984
985 return 0;
986}
987
988int wil_down(struct wil6210_priv *wil)
989{
990 int rc;
991
Vladimir Kondratiev9cf10d62014-09-10 16:34:36 +0300992 wil_dbg_misc(wil, "%s()\n", __func__);
993
Vladimir Kondratievc33407a2014-10-01 15:05:24 +0300994 wil_set_recovery_state(wil, fw_recovery_idle);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800995 mutex_lock(&wil->mutex);
996 rc = __wil_down(wil);
997 mutex_unlock(&wil->mutex);
998
999 return rc;
1000}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001001
1002int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
1003{
1004 int i;
1005 int rc = -ENOENT;
1006
1007 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
1008 if ((wil->sta[i].status != wil_sta_unused) &&
Vladimir Kondratiev108d1eb2014-02-27 16:20:53 +02001009 ether_addr_equal(wil->sta[i].addr, mac)) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +02001010 rc = i;
1011 break;
1012 }
1013 }
1014
1015 return rc;
1016}