wil6210: ADDBA/DELBA flows
[deliverable/linux.git] / drivers / net / wireless / ath / wil6210 / main.c
CommitLineData
2be7d22f 1/*
02525a79 2 * Copyright (c) 2012-2014 Qualcomm Atheros, Inc.
2be7d22f
VK
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
2be7d22f
VK
17#include <linux/moduleparam.h>
18#include <linux/if_arp.h>
108d1eb6 19#include <linux/etherdevice.h>
2be7d22f
VK
20
21#include "wil6210.h"
b4490f42 22#include "txrx.h"
f172b563
DL
23#include "wmi.h"
24
25#define WAIT_FOR_DISCONNECT_TIMEOUT_MS 2000
26#define WAIT_FOR_DISCONNECT_INTERVAL_MS 10
2be7d22f 27
c33407a8 28bool no_fw_recovery;
ed6f9dc6 29module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
c33407a8 30MODULE_PARM_DESC(no_fw_recovery, " disable automatic FW error recovery");
ed6f9dc6 31
151a9706
VK
32static bool no_fw_load = true;
33module_param(no_fw_load, bool, S_IRUGO | S_IWUSR);
34MODULE_PARM_DESC(no_fw_load, " do not download FW, use one in on-card flash.");
35
b6b1b0ec
VK
36static unsigned int itr_trsh = WIL6210_ITR_TRSH_DEFAULT;
37
38module_param(itr_trsh, uint, S_IRUGO);
39MODULE_PARM_DESC(itr_trsh, " Interrupt moderation threshold, usecs.");
40
9a06bec9
VK
41/* We allow allocation of more than 1 page buffers to support large packets.
42 * It is suboptimal behavior performance wise in case MTU above page size.
43 */
44unsigned int mtu_max = TXRX_BUF_LEN_DEFAULT - ETH_HLEN;
45static int mtu_max_set(const char *val, const struct kernel_param *kp)
46{
47 int ret;
48
49 /* sets mtu_max directly. no need to restore it in case of
50 * illegal value since we assume this will fail insmod
51 */
52 ret = param_set_uint(val, kp);
53 if (ret)
54 return ret;
55
56 if (mtu_max < 68 || mtu_max > IEEE80211_MAX_DATA_LEN_DMG)
57 ret = -EINVAL;
58
59 return ret;
60}
61
62static struct kernel_param_ops mtu_max_ops = {
63 .set = mtu_max_set,
64 .get = param_get_uint,
65};
66
67module_param_cb(mtu_max, &mtu_max_ops, &mtu_max, S_IRUGO);
68MODULE_PARM_DESC(mtu_max, " Max MTU value.");
69
d3762b40
VK
70static uint rx_ring_order = WIL_RX_RING_SIZE_ORDER_DEFAULT;
71static uint tx_ring_order = WIL_TX_RING_SIZE_ORDER_DEFAULT;
72
73static int ring_order_set(const char *val, const struct kernel_param *kp)
74{
75 int ret;
76 uint x;
77
78 ret = kstrtouint(val, 0, &x);
79 if (ret)
80 return ret;
81
82 if ((x < WIL_RING_SIZE_ORDER_MIN) || (x > WIL_RING_SIZE_ORDER_MAX))
83 return -EINVAL;
84
85 *((uint *)kp->arg) = x;
86
87 return 0;
88}
89
90static struct kernel_param_ops ring_order_ops = {
91 .set = ring_order_set,
92 .get = param_get_uint,
93};
94
95module_param_cb(rx_ring_order, &ring_order_ops, &rx_ring_order, S_IRUGO);
96MODULE_PARM_DESC(rx_ring_order, " Rx ring order; size = 1 << order");
97module_param_cb(tx_ring_order, &ring_order_ops, &tx_ring_order, S_IRUGO);
98MODULE_PARM_DESC(tx_ring_order, " Tx ring order; size = 1 << order");
99
520d68e7
VK
100#define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
101#define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
102
2be7d22f
VK
103/*
104 * Due to a hardware issue,
105 * one has to read/write to/from NIC in 32-bit chunks;
106 * regular memcpy_fromio and siblings will
107 * not work on 64-bit platform - it uses 64-bit transactions
108 *
109 * Force 32-bit transactions to enable NIC on 64-bit platforms
110 *
111 * To avoid byte swap on big endian host, __raw_{read|write}l
112 * should be used - {read|write}l would swap bytes to provide
113 * little endian on PCI value in host endianness.
114 */
115void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
116 size_t count)
117{
118 u32 *d = dst;
119 const volatile u32 __iomem *s = src;
120
121 /* size_t is unsigned, if (count%4 != 0) it will wrap */
122 for (count += 4; count > 4; count -= 4)
123 *d++ = __raw_readl(s++);
124}
125
126void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
127 size_t count)
128{
129 volatile u32 __iomem *d = dst;
130 const u32 *s = src;
131
132 for (count += 4; count > 4; count -= 4)
133 __raw_writel(*s++, d++);
134}
135
b516fcc5 136static void wil_disconnect_cid(struct wil6210_priv *wil, int cid,
4821e6d8 137 u16 reason_code, bool from_event)
91886b0b
VK
138{
139 uint i;
fc58f681
VK
140 struct net_device *ndev = wil_to_ndev(wil);
141 struct wireless_dev *wdev = wil->wdev;
91886b0b 142 struct wil_sta_info *sta = &wil->sta[cid];
8fe59627 143
fc58f681
VK
144 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
145 sta->status);
4d55a0a1 146
e58c9f70 147 sta->data_port_open = false;
4d55a0a1 148 if (sta->status != wil_sta_unused) {
b516fcc5 149 if (!from_event)
4821e6d8 150 wmi_disconnect_sta(wil, sta->addr, reason_code);
b516fcc5 151
fc58f681
VK
152 switch (wdev->iftype) {
153 case NL80211_IFTYPE_AP:
154 case NL80211_IFTYPE_P2P_GO:
155 /* AP-like interface */
156 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
157 break;
158 default:
159 break;
160 }
4d55a0a1
VK
161 sta->status = wil_sta_unused;
162 }
163
91886b0b 164 for (i = 0; i < WIL_STA_TID_NUM; i++) {
ec81b5ad
DL
165 struct wil_tid_ampdu_rx *r;
166 unsigned long flags;
167
168 spin_lock_irqsave(&sta->tid_rx_lock, flags);
169
170 r = sta->tid_rx[i];
91886b0b
VK
171 sta->tid_rx[i] = NULL;
172 wil_tid_ampdu_rx_free(wil, r);
ec81b5ad
DL
173
174 spin_unlock_irqrestore(&sta->tid_rx_lock, flags);
91886b0b
VK
175 }
176 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
177 if (wil->vring2cid_tid[i][0] == cid)
178 wil_vring_fini_tx(wil, i);
179 }
180 memset(&sta->stats, 0, sizeof(sta->stats));
181}
182
b516fcc5 183static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
4821e6d8 184 u16 reason_code, bool from_event)
2be7d22f 185{
91886b0b 186 int cid = -ENOENT;
2be7d22f 187 struct net_device *ndev = wil_to_ndev(wil);
91886b0b
VK
188 struct wireless_dev *wdev = wil->wdev;
189
190 might_sleep();
191 if (bssid) {
192 cid = wil_find_cid(wil, bssid);
193 wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid);
194 } else {
195 wil_dbg_misc(wil, "%s(all)\n", __func__);
b4490f42
VK
196 }
197
91886b0b 198 if (cid >= 0) /* disconnect 1 peer */
4821e6d8 199 wil_disconnect_cid(wil, cid, reason_code, from_event);
91886b0b
VK
200 else /* disconnect all */
201 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
4821e6d8 202 wil_disconnect_cid(wil, cid, reason_code, from_event);
91886b0b
VK
203
204 /* link state */
205 switch (wdev->iftype) {
206 case NL80211_IFTYPE_STATION:
207 case NL80211_IFTYPE_P2P_CLIENT:
208 wil_link_off(wil);
209 if (test_bit(wil_status_fwconnected, &wil->status)) {
210 clear_bit(wil_status_fwconnected, &wil->status);
4821e6d8 211 cfg80211_disconnected(ndev, reason_code,
91886b0b
VK
212 NULL, 0, GFP_KERNEL);
213 } else if (test_bit(wil_status_fwconnecting, &wil->status)) {
214 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
215 WLAN_STATUS_UNSPECIFIED_FAILURE,
216 GFP_KERNEL);
217 }
218 clear_bit(wil_status_fwconnecting, &wil->status);
91886b0b
VK
219 break;
220 default:
91886b0b 221 break;
2be7d22f 222 }
2be7d22f
VK
223}
224
225static void wil_disconnect_worker(struct work_struct *work)
226{
227 struct wil6210_priv *wil = container_of(work,
228 struct wil6210_priv, disconnect_worker);
229
097638a0 230 mutex_lock(&wil->mutex);
4821e6d8 231 _wil6210_disconnect(wil, NULL, WLAN_REASON_UNSPECIFIED, false);
097638a0 232 mutex_unlock(&wil->mutex);
2be7d22f
VK
233}
234
235static void wil_connect_timer_fn(ulong x)
236{
237 struct wil6210_priv *wil = (void *)x;
238
7743882d 239 wil_dbg_misc(wil, "Connect timeout\n");
2be7d22f
VK
240
241 /* reschedule to thread context - disconnect won't
242 * run from atomic context
243 */
244 schedule_work(&wil->disconnect_worker);
245}
246
047e5d74
VK
247static void wil_scan_timer_fn(ulong x)
248{
249 struct wil6210_priv *wil = (void *)x;
250
251 clear_bit(wil_status_fwready, &wil->status);
252 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
60abbb6e 253 wil->recovery_state = fw_recovery_pending;
047e5d74
VK
254 schedule_work(&wil->fw_error_worker);
255}
256
c33407a8
VK
257static int wil_wait_for_recovery(struct wil6210_priv *wil)
258{
259 if (wait_event_interruptible(wil->wq, wil->recovery_state !=
260 fw_recovery_pending)) {
261 wil_err(wil, "Interrupt, canceling recovery\n");
262 return -ERESTARTSYS;
263 }
264 if (wil->recovery_state != fw_recovery_running) {
265 wil_info(wil, "Recovery cancelled\n");
266 return -EINTR;
267 }
268 wil_info(wil, "Proceed with recovery\n");
269 return 0;
270}
271
272void wil_set_recovery_state(struct wil6210_priv *wil, int state)
273{
274 wil_dbg_misc(wil, "%s(%d -> %d)\n", __func__,
275 wil->recovery_state, state);
276
277 wil->recovery_state = state;
278 wake_up_interruptible(&wil->wq);
279}
280
ed6f9dc6
VK
281static void wil_fw_error_worker(struct work_struct *work)
282{
c33407a8
VK
283 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
284 fw_error_worker);
ed6f9dc6
VK
285 struct wireless_dev *wdev = wil->wdev;
286
287 wil_dbg_misc(wil, "fw error worker\n");
288
cded9369
VK
289 if (!netif_running(wil_to_ndev(wil))) {
290 wil_info(wil, "No recovery - interface is down\n");
291 return;
292 }
293
fc219eed
VK
294 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
295 * passed since last recovery attempt
296 */
297 if (time_is_after_jiffies(wil->last_fw_recovery +
298 WIL6210_FW_RECOVERY_TO))
299 wil->recovery_count++;
300 else
301 wil->recovery_count = 1; /* fw was alive for a long time */
302
303 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
304 wil_err(wil, "too many recovery attempts (%d), giving up\n",
305 wil->recovery_count);
306 return;
307 }
308
309 wil->last_fw_recovery = jiffies;
310
9c3bde56 311 mutex_lock(&wil->mutex);
ed6f9dc6
VK
312 switch (wdev->iftype) {
313 case NL80211_IFTYPE_STATION:
314 case NL80211_IFTYPE_P2P_CLIENT:
315 case NL80211_IFTYPE_MONITOR:
c33407a8 316 wil_info(wil, "fw error recovery requested (try %d)...\n",
fc219eed 317 wil->recovery_count);
c33407a8
VK
318 if (!no_fw_recovery)
319 wil->recovery_state = fw_recovery_running;
320 if (0 != wil_wait_for_recovery(wil))
321 break;
322
73d839ae
VK
323 __wil_down(wil);
324 __wil_up(wil);
ed6f9dc6
VK
325 break;
326 case NL80211_IFTYPE_AP:
327 case NL80211_IFTYPE_P2P_GO:
e240537b 328 wil_info(wil, "No recovery for AP-like interface\n");
ed6f9dc6
VK
329 /* recovery in these modes is done by upper layers */
330 break;
331 default:
e240537b
VK
332 wil_err(wil, "No recovery - unknown interface type %d\n",
333 wdev->iftype);
ed6f9dc6
VK
334 break;
335 }
9c3bde56 336 mutex_unlock(&wil->mutex);
ed6f9dc6
VK
337}
338
9a177384
VK
339static int wil_find_free_vring(struct wil6210_priv *wil)
340{
341 int i;
8fe59627 342
9a177384
VK
343 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
344 if (!wil->vring_tx[i].va)
345 return i;
346 }
347 return -EINVAL;
348}
349
d81079f1
VK
350static void wil_connect_worker(struct work_struct *work)
351{
352 int rc;
353 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
354 connect_worker);
355 int cid = wil->pending_connect_cid;
9a177384 356 int ringid = wil_find_free_vring(wil);
d81079f1
VK
357
358 if (cid < 0) {
359 wil_err(wil, "No connection pending\n");
360 return;
361 }
362
363 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
364
d3762b40 365 rc = wil_vring_init_tx(wil, ringid, 1 << tx_ring_order, cid, 0);
d81079f1 366 wil->pending_connect_cid = -1;
3df2cd36
VK
367 if (rc == 0) {
368 wil->sta[cid].status = wil_sta_connected;
d81079f1 369 wil_link_on(wil);
3df2cd36
VK
370 } else {
371 wil->sta[cid].status = wil_sta_unused;
372 }
d81079f1
VK
373}
374
2be7d22f
VK
375int wil_priv_init(struct wil6210_priv *wil)
376{
ec81b5ad
DL
377 uint i;
378
7743882d 379 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f 380
3df2cd36 381 memset(wil->sta, 0, sizeof(wil->sta));
ec81b5ad
DL
382 for (i = 0; i < WIL6210_MAX_CID; i++)
383 spin_lock_init(&wil->sta[i].tid_rx_lock);
3df2cd36 384
2be7d22f
VK
385 mutex_init(&wil->mutex);
386 mutex_init(&wil->wmi_mutex);
3277213f 387 mutex_init(&wil->back_rx_mutex);
2be7d22f
VK
388
389 init_completion(&wil->wmi_ready);
59502647 390 init_completion(&wil->wmi_call);
2be7d22f
VK
391
392 wil->pending_connect_cid = -1;
393 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
047e5d74 394 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
2be7d22f 395
d81079f1 396 INIT_WORK(&wil->connect_worker, wil_connect_worker);
2be7d22f
VK
397 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
398 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
ed6f9dc6 399 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
3277213f 400 INIT_WORK(&wil->back_rx_worker, wil_back_rx_worker);
2be7d22f
VK
401
402 INIT_LIST_HEAD(&wil->pending_wmi_ev);
3277213f 403 INIT_LIST_HEAD(&wil->back_rx_pending);
2be7d22f 404 spin_lock_init(&wil->wmi_ev_lock);
c33407a8 405 init_waitqueue_head(&wil->wq);
2be7d22f 406
3277213f 407 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME "_wmi");
2be7d22f
VK
408 if (!wil->wmi_wq)
409 return -EAGAIN;
410
3277213f
VK
411 wil->wq_service = create_singlethread_workqueue(WIL_NAME "_service");
412 if (!wil->wq_service)
413 goto out_wmi_wq;
2be7d22f 414
fc219eed 415 wil->last_fw_recovery = jiffies;
b6b1b0ec 416 wil->itr_trsh = itr_trsh;
fc219eed 417
2be7d22f 418 return 0;
3277213f
VK
419
420out_wmi_wq:
421 destroy_workqueue(wil->wmi_wq);
422
423 return -EAGAIN;
2be7d22f
VK
424}
425
b516fcc5
VK
426/**
427 * wil6210_disconnect - disconnect one connection
428 * @wil: driver context
429 * @bssid: peer to disconnect, NULL to disconnect all
4821e6d8 430 * @reason_code: Reason code for the Disassociation frame
b516fcc5
VK
431 * @from_event: whether is invoked from FW event handler
432 *
433 * Disconnect and release associated resources. If invoked not from the
434 * FW event handler, issue WMI command(s) to trigger MAC disconnect.
435 */
436void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid,
4821e6d8 437 u16 reason_code, bool from_event)
2be7d22f 438{
9cf10d62
VK
439 wil_dbg_misc(wil, "%s()\n", __func__);
440
2be7d22f 441 del_timer_sync(&wil->connect_timer);
4821e6d8 442 _wil6210_disconnect(wil, bssid, reason_code, from_event);
2be7d22f
VK
443}
444
445void wil_priv_deinit(struct wil6210_priv *wil)
446{
9cf10d62
VK
447 wil_dbg_misc(wil, "%s()\n", __func__);
448
c33407a8 449 wil_set_recovery_state(wil, fw_recovery_idle);
047e5d74 450 del_timer_sync(&wil->scan_timer);
2be7d22f 451 cancel_work_sync(&wil->disconnect_worker);
ed6f9dc6 452 cancel_work_sync(&wil->fw_error_worker);
097638a0 453 mutex_lock(&wil->mutex);
4821e6d8 454 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
097638a0 455 mutex_unlock(&wil->mutex);
2be7d22f 456 wmi_event_flush(wil);
3277213f
VK
457 wil_back_rx_flush(wil);
458 cancel_work_sync(&wil->back_rx_worker);
459 destroy_workqueue(wil->wq_service);
2be7d22f
VK
460 destroy_workqueue(wil->wmi_wq);
461}
462
151a9706
VK
463/* target operations */
464/* register read */
465#define R(a) ioread32(wil->csr + HOSTADDR(a))
466/* register write. wmb() to make sure it is completed */
467#define W(a, v) do { iowrite32(v, wil->csr + HOSTADDR(a)); wmb(); } while (0)
468/* register set = read, OR, write */
469#define S(a, v) W(a, R(a) | v)
470/* register clear = read, AND with inverted, write */
471#define C(a, v) W(a, R(a) & ~v)
472
473static inline void wil_halt_cpu(struct wil6210_priv *wil)
474{
475 W(RGF_USER_USER_CPU_0, BIT_USER_USER_CPU_MAN_RST);
476 W(RGF_USER_MAC_CPU_0, BIT_USER_MAC_CPU_MAN_RST);
477}
478
479static inline void wil_release_cpu(struct wil6210_priv *wil)
480{
481 /* Start CPU */
482 W(RGF_USER_USER_CPU_0, 1);
483}
484
bbb2adc7 485static int wil_target_reset(struct wil6210_priv *wil)
2be7d22f 486{
98a65b59 487 int delay = 0;
48516298 488 u32 x;
36b10a72 489 u32 rev_id;
6508281b 490 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
36b10a72 491
6508281b 492 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
2be7d22f 493
17123991 494 wil->hw_version = R(RGF_USER_FW_REV_ID);
36b10a72 495 rev_id = wil->hw_version & 0xff;
6508281b
VK
496
497 /* Clear MAC link up */
498 S(RGF_HP_CTRL, BIT(15));
151a9706
VK
499 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_HPAL_PERST_FROM_PAD);
500 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT_CAR_PERST_RST);
501
502 wil_halt_cpu(wil);
2be7d22f 503
cce47711
VK
504 /* Clear Fw Download notification */
505 C(RGF_USER_USAGE_6, BIT(0));
506
6508281b 507 if (is_sparrow) {
48516298
VK
508 S(RGF_CAF_OSC_CONTROL, BIT_CAF_OSC_XTAL_EN);
509 /* XTAL stabilization should take about 3ms */
510 usleep_range(5000, 7000);
511 x = R(RGF_CAF_PLL_LOCK_STATUS);
512 if (!(x & BIT_CAF_OSC_DIG_XTAL_STABLE)) {
513 wil_err(wil, "Xtal stabilization timeout\n"
514 "RGF_CAF_PLL_LOCK_STATUS = 0x%08x\n", x);
515 return -ETIME;
516 }
517 /* switch 10k to XTAL*/
518 C(RGF_USER_SPARROW_M_4, BIT_SPARROW_M_4_SEL_SLEEP_OR_REF);
519 /* 40 MHz */
520 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_CAR_AHB_SW_SEL);
521
6508281b 522 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
151a9706 523 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0xf);
6508281b
VK
524 }
525
2be7d22f
VK
526 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
527 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
151a9706
VK
528 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000f0 : 0x00000170);
529 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FE00);
2be7d22f 530
6508281b
VK
531 if (is_sparrow) {
532 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
151a9706 533 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_1, 0x0);
6508281b
VK
534 }
535
2be7d22f
VK
536 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
537 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
538 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
539 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
540
6508281b
VK
541 if (is_sparrow) {
542 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
543 /* reset A2 PCIE AHB */
36b10a72 544 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
6508281b
VK
545 } else {
546 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
547 if (rev_id == 1) {
548 /* reset A1 BOTH PCIE AHB & PCIE RGF */
549 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
550 } else {
551 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
552 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
553 }
36b10a72 554 }
6508281b
VK
555
556 /* TODO: check order here!!! Erez code is different */
2be7d22f
VK
557 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
558
520d68e7 559 /* wait until device ready. typical time is 200..250 msec */
36b10a72 560 do {
520d68e7 561 msleep(RST_DELAY);
48516298 562 x = R(RGF_USER_HW_MACHINE_STATE);
520d68e7 563 if (delay++ > RST_COUNT) {
d28bcc30 564 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
48516298 565 x);
bbb2adc7 566 return -ETIME;
36b10a72 567 }
48516298 568 } while (x != HW_MACHINE_BOOT_DONE);
36b10a72 569
6508281b
VK
570 /* TODO: Erez check rev_id != 1 */
571 if (!is_sparrow && (rev_id != 1))
17123991 572 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
36b10a72 573
972072aa
VK
574 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
575
520d68e7 576 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
bbb2adc7 577 return 0;
151a9706 578}
2be7d22f 579
b6b1b0ec
VK
580/**
581 * wil_set_itr_trsh: - apply interrupt coalescing params
582 */
583void wil_set_itr_trsh(struct wil6210_priv *wil)
584{
585 /* disable, use usec resolution */
586 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EXT_TICK);
587
588 /* disable interrupt moderation for monitor
589 * to get better timestamp precision
590 */
591 if (wil->wdev->iftype == NL80211_IFTYPE_MONITOR)
592 return;
593
594 wil_info(wil, "set ITR_TRSH = %d usec\n", wil->itr_trsh);
595 W(RGF_DMA_ITR_CNT_TRSH, wil->itr_trsh);
596 W(RGF_DMA_ITR_CNT_CRL, BIT_DMA_ITR_CNT_CRL_EN |
597 BIT_DMA_ITR_CNT_CRL_EXT_TICK); /* start it */
598}
599
36b10a72 600#undef R
2be7d22f
VK
601#undef W
602#undef S
972072aa 603#undef C
2be7d22f
VK
604
605void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
606{
607 le32_to_cpus(&r->base);
608 le16_to_cpus(&r->entry_size);
609 le16_to_cpus(&r->size);
610 le32_to_cpus(&r->tail);
611 le32_to_cpus(&r->head);
612}
613
614static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
615{
616 ulong to = msecs_to_jiffies(1000);
617 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
8fe59627 618
2be7d22f
VK
619 if (0 == left) {
620 wil_err(wil, "Firmware not ready\n");
621 return -ETIME;
622 } else {
15e23124
VK
623 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
624 jiffies_to_msecs(to-left), wil->hw_version);
2be7d22f
VK
625 }
626 return 0;
627}
628
629/*
630 * We reset all the structures, and we reset the UMAC.
631 * After calling this routine, you're expected to reload
632 * the firmware.
633 */
634int wil_reset(struct wil6210_priv *wil)
635{
636 int rc;
637
9cf10d62
VK
638 wil_dbg_misc(wil, "%s()\n", __func__);
639
097638a0 640 WARN_ON(!mutex_is_locked(&wil->mutex));
73d839ae 641 WARN_ON(test_bit(wil_status_napi_en, &wil->status));
097638a0
VK
642
643 cancel_work_sync(&wil->disconnect_worker);
4821e6d8 644 wil6210_disconnect(wil, NULL, WLAN_REASON_DEAUTH_LEAVING, false);
097638a0 645
0fef1818 646 wil->status = 0; /* prevent NAPI from being scheduled */
0fef1818 647
ed6f9dc6
VK
648 if (wil->scan_request) {
649 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
650 wil->scan_request);
047e5d74 651 del_timer_sync(&wil->scan_timer);
ed6f9dc6
VK
652 cfg80211_scan_done(wil->scan_request, true);
653 wil->scan_request = NULL;
654 }
655
e4dbb093 656 wil_mask_irq(wil);
e08b5906 657
2be7d22f
VK
658 wmi_event_flush(wil);
659
3277213f 660 flush_workqueue(wil->wq_service);
e08b5906 661 flush_workqueue(wil->wmi_wq);
2be7d22f 662
bbb2adc7 663 rc = wil_target_reset(wil);
8bf6adb9 664 wil_rx_fini(wil);
bbb2adc7
VK
665 if (rc)
666 return rc;
667
151a9706
VK
668 if (!no_fw_load) {
669 wil_info(wil, "Use firmware <%s>\n", WIL_FW_NAME);
670 wil_halt_cpu(wil);
671 /* Loading f/w from the file */
672 rc = wil_request_firmware(wil, WIL_FW_NAME);
673 if (rc)
674 return rc;
675
676 /* clear any interrupts which on-card-firmware may have set */
677 wil6210_clear_irq(wil);
678 { /* CAF_ICR - clear and mask */
679 u32 a = HOSTADDR(RGF_CAF_ICR) +
680 offsetof(struct RGF_ICR, ICR);
681 u32 m = HOSTADDR(RGF_CAF_ICR) +
682 offsetof(struct RGF_ICR, IMV);
683 u32 icr = ioread32(wil->csr + a);
684
685 iowrite32(icr, wil->csr + a); /* W1C */
686 iowrite32(~0, wil->csr + m);
687 wmb(); /* wait for completion */
688 }
689 wil_release_cpu(wil);
690 } else {
691 wil_info(wil, "Use firmware from on-card flash\n");
692 }
8bf6adb9 693
2be7d22f
VK
694 /* init after reset */
695 wil->pending_connect_cid = -1;
16735d02 696 reinit_completion(&wil->wmi_ready);
59502647 697 reinit_completion(&wil->wmi_call);
2be7d22f 698
e4dbb093 699 wil_unmask_irq(wil);
2be7d22f
VK
700
701 /* we just started MAC, wait for FW ready */
702 rc = wil_wait_for_fw_ready(wil);
703
704 return rc;
705}
706
ed6f9dc6
VK
707void wil_fw_error_recovery(struct wil6210_priv *wil)
708{
709 wil_dbg_misc(wil, "starting fw error recovery\n");
c33407a8 710 wil->recovery_state = fw_recovery_pending;
ed6f9dc6
VK
711 schedule_work(&wil->fw_error_worker);
712}
2be7d22f
VK
713
714void wil_link_on(struct wil6210_priv *wil)
715{
716 struct net_device *ndev = wil_to_ndev(wil);
717
7743882d 718 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f
VK
719
720 netif_carrier_on(ndev);
55f8f680 721 wil_dbg_misc(wil, "netif_tx_wake : link on\n");
2be7d22f
VK
722 netif_tx_wake_all_queues(ndev);
723}
724
725void wil_link_off(struct wil6210_priv *wil)
726{
727 struct net_device *ndev = wil_to_ndev(wil);
728
7743882d 729 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f
VK
730
731 netif_tx_stop_all_queues(ndev);
55f8f680 732 wil_dbg_misc(wil, "netif_tx_stop : link off\n");
2be7d22f
VK
733 netif_carrier_off(ndev);
734}
735
73d839ae 736int __wil_up(struct wil6210_priv *wil)
2be7d22f
VK
737{
738 struct net_device *ndev = wil_to_ndev(wil);
739 struct wireless_dev *wdev = wil->wdev;
2be7d22f 740 int rc;
2be7d22f 741
097638a0
VK
742 WARN_ON(!mutex_is_locked(&wil->mutex));
743
2be7d22f
VK
744 rc = wil_reset(wil);
745 if (rc)
746 return rc;
747
e31b2562 748 /* Rx VRING. After MAC and beacon */
d3762b40 749 rc = wil_rx_init(wil, 1 << rx_ring_order);
e31b2562
VK
750 if (rc)
751 return rc;
752
2be7d22f
VK
753 switch (wdev->iftype) {
754 case NL80211_IFTYPE_STATION:
7743882d 755 wil_dbg_misc(wil, "type: STATION\n");
2be7d22f
VK
756 ndev->type = ARPHRD_ETHER;
757 break;
758 case NL80211_IFTYPE_AP:
7743882d 759 wil_dbg_misc(wil, "type: AP\n");
2be7d22f
VK
760 ndev->type = ARPHRD_ETHER;
761 break;
762 case NL80211_IFTYPE_P2P_CLIENT:
7743882d 763 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
2be7d22f
VK
764 ndev->type = ARPHRD_ETHER;
765 break;
766 case NL80211_IFTYPE_P2P_GO:
7743882d 767 wil_dbg_misc(wil, "type: P2P_GO\n");
2be7d22f
VK
768 ndev->type = ARPHRD_ETHER;
769 break;
770 case NL80211_IFTYPE_MONITOR:
7743882d 771 wil_dbg_misc(wil, "type: Monitor\n");
2be7d22f
VK
772 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
773 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
774 break;
775 default:
776 return -EOPNOTSUPP;
777 }
778
2be7d22f
VK
779 /* MAC address - pre-requisite for other commands */
780 wmi_set_mac_address(wil, ndev->dev_addr);
781
73d839ae 782 wil_dbg_misc(wil, "NAPI enable\n");
e0287c4a
VK
783 napi_enable(&wil->napi_rx);
784 napi_enable(&wil->napi_tx);
0fef1818 785 set_bit(wil_status_napi_en, &wil->status);
e0287c4a 786
f772ebfb
VK
787 if (wil->platform_ops.bus_request)
788 wil->platform_ops.bus_request(wil->platform_handle,
789 WIL_MAX_BUS_REQUEST_KBPS);
790
2be7d22f
VK
791 return 0;
792}
793
794int wil_up(struct wil6210_priv *wil)
795{
796 int rc;
797
9cf10d62
VK
798 wil_dbg_misc(wil, "%s()\n", __func__);
799
2be7d22f
VK
800 mutex_lock(&wil->mutex);
801 rc = __wil_up(wil);
802 mutex_unlock(&wil->mutex);
803
804 return rc;
805}
806
73d839ae 807int __wil_down(struct wil6210_priv *wil)
2be7d22f 808{
f172b563
DL
809 int iter = WAIT_FOR_DISCONNECT_TIMEOUT_MS /
810 WAIT_FOR_DISCONNECT_INTERVAL_MS;
811
097638a0
VK
812 WARN_ON(!mutex_is_locked(&wil->mutex));
813
f772ebfb
VK
814 if (wil->platform_ops.bus_request)
815 wil->platform_ops.bus_request(wil->platform_handle, 0);
816
73d839ae
VK
817 wil_disable_irq(wil);
818 if (test_and_clear_bit(wil_status_napi_en, &wil->status)) {
819 napi_disable(&wil->napi_rx);
820 napi_disable(&wil->napi_tx);
821 wil_dbg_misc(wil, "NAPI disable\n");
822 }
823 wil_enable_irq(wil);
e0287c4a 824
2be7d22f 825 if (wil->scan_request) {
2a91d7d0
VK
826 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
827 wil->scan_request);
047e5d74 828 del_timer_sync(&wil->scan_timer);
2be7d22f
VK
829 cfg80211_scan_done(wil->scan_request, true);
830 wil->scan_request = NULL;
831 }
832
f172b563
DL
833 if (test_bit(wil_status_fwconnected, &wil->status) ||
834 test_bit(wil_status_fwconnecting, &wil->status))
835 wmi_send(wil, WMI_DISCONNECT_CMDID, NULL, 0);
836
837 /* make sure wil is idle (not connected) */
838 mutex_unlock(&wil->mutex);
839 while (iter--) {
840 int idle = !test_bit(wil_status_fwconnected, &wil->status) &&
841 !test_bit(wil_status_fwconnecting, &wil->status);
842 if (idle)
843 break;
844 msleep(WAIT_FOR_DISCONNECT_INTERVAL_MS);
845 }
846 mutex_lock(&wil->mutex);
847
848 if (!iter)
849 wil_err(wil, "timeout waiting for idle FW/HW\n");
850
2be7d22f
VK
851 wil_rx_fini(wil);
852
853 return 0;
854}
855
856int wil_down(struct wil6210_priv *wil)
857{
858 int rc;
859
9cf10d62
VK
860 wil_dbg_misc(wil, "%s()\n", __func__);
861
c33407a8 862 wil_set_recovery_state(wil, fw_recovery_idle);
2be7d22f
VK
863 mutex_lock(&wil->mutex);
864 rc = __wil_down(wil);
865 mutex_unlock(&wil->mutex);
866
867 return rc;
868}
3df2cd36
VK
869
870int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
871{
872 int i;
873 int rc = -ENOENT;
874
875 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
876 if ((wil->sta[i].status != wil_sta_unused) &&
108d1eb6 877 ether_addr_equal(wil->sta[i].addr, mac)) {
3df2cd36
VK
878 rc = i;
879 break;
880 }
881 }
882
883 return rc;
884}
This page took 0.219539 seconds and 5 git commands to generate.