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