b43: HT-PHY: Set MAC frequency to correct values
[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"
2be7d22f 23
ed6f9dc6
VK
24static bool no_fw_recovery;
25module_param(no_fw_recovery, bool, S_IRUGO | S_IWUSR);
26MODULE_PARM_DESC(no_fw_recovery, " disable FW error recovery");
27
520d68e7
VK
28#define RST_DELAY (20) /* msec, for loop in @wil_target_reset */
29#define RST_COUNT (1 + 1000/RST_DELAY) /* round up to be above 1 sec total */
30
2be7d22f
VK
31/*
32 * Due to a hardware issue,
33 * one has to read/write to/from NIC in 32-bit chunks;
34 * regular memcpy_fromio and siblings will
35 * not work on 64-bit platform - it uses 64-bit transactions
36 *
37 * Force 32-bit transactions to enable NIC on 64-bit platforms
38 *
39 * To avoid byte swap on big endian host, __raw_{read|write}l
40 * should be used - {read|write}l would swap bytes to provide
41 * little endian on PCI value in host endianness.
42 */
43void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
44 size_t count)
45{
46 u32 *d = dst;
47 const volatile u32 __iomem *s = src;
48
49 /* size_t is unsigned, if (count%4 != 0) it will wrap */
50 for (count += 4; count > 4; count -= 4)
51 *d++ = __raw_readl(s++);
52}
53
54void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
55 size_t count)
56{
57 volatile u32 __iomem *d = dst;
58 const u32 *s = src;
59
60 for (count += 4; count > 4; count -= 4)
61 __raw_writel(*s++, d++);
62}
63
91886b0b
VK
64static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
65{
66 uint i;
fc58f681
VK
67 struct net_device *ndev = wil_to_ndev(wil);
68 struct wireless_dev *wdev = wil->wdev;
91886b0b 69 struct wil_sta_info *sta = &wil->sta[cid];
fc58f681
VK
70 wil_dbg_misc(wil, "%s(CID %d, status %d)\n", __func__, cid,
71 sta->status);
4d55a0a1 72
e58c9f70 73 sta->data_port_open = false;
4d55a0a1
VK
74 if (sta->status != wil_sta_unused) {
75 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING);
fc58f681
VK
76 switch (wdev->iftype) {
77 case NL80211_IFTYPE_AP:
78 case NL80211_IFTYPE_P2P_GO:
79 /* AP-like interface */
80 cfg80211_del_sta(ndev, sta->addr, GFP_KERNEL);
81 break;
82 default:
83 break;
84 }
4d55a0a1
VK
85 sta->status = wil_sta_unused;
86 }
87
91886b0b
VK
88 for (i = 0; i < WIL_STA_TID_NUM; i++) {
89 struct wil_tid_ampdu_rx *r = sta->tid_rx[i];
90 sta->tid_rx[i] = NULL;
91 wil_tid_ampdu_rx_free(wil, r);
92 }
93 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
94 if (wil->vring2cid_tid[i][0] == cid)
95 wil_vring_fini_tx(wil, i);
96 }
97 memset(&sta->stats, 0, sizeof(sta->stats));
98}
99
3b3a0162 100static void _wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
2be7d22f 101{
91886b0b 102 int cid = -ENOENT;
2be7d22f 103 struct net_device *ndev = wil_to_ndev(wil);
91886b0b
VK
104 struct wireless_dev *wdev = wil->wdev;
105
106 might_sleep();
107 if (bssid) {
108 cid = wil_find_cid(wil, bssid);
109 wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid);
110 } else {
111 wil_dbg_misc(wil, "%s(all)\n", __func__);
b4490f42
VK
112 }
113
91886b0b
VK
114 if (cid >= 0) /* disconnect 1 peer */
115 wil_disconnect_cid(wil, cid);
116 else /* disconnect all */
117 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
118 wil_disconnect_cid(wil, cid);
119
120 /* link state */
121 switch (wdev->iftype) {
122 case NL80211_IFTYPE_STATION:
123 case NL80211_IFTYPE_P2P_CLIENT:
124 wil_link_off(wil);
125 if (test_bit(wil_status_fwconnected, &wil->status)) {
126 clear_bit(wil_status_fwconnected, &wil->status);
127 cfg80211_disconnected(ndev,
128 WLAN_STATUS_UNSPECIFIED_FAILURE,
129 NULL, 0, GFP_KERNEL);
130 } else if (test_bit(wil_status_fwconnecting, &wil->status)) {
131 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
132 WLAN_STATUS_UNSPECIFIED_FAILURE,
133 GFP_KERNEL);
134 }
135 clear_bit(wil_status_fwconnecting, &wil->status);
91886b0b
VK
136 break;
137 default:
91886b0b 138 break;
2be7d22f 139 }
2be7d22f
VK
140}
141
142static void wil_disconnect_worker(struct work_struct *work)
143{
144 struct wil6210_priv *wil = container_of(work,
145 struct wil6210_priv, disconnect_worker);
146
097638a0 147 mutex_lock(&wil->mutex);
2be7d22f 148 _wil6210_disconnect(wil, NULL);
097638a0 149 mutex_unlock(&wil->mutex);
2be7d22f
VK
150}
151
152static void wil_connect_timer_fn(ulong x)
153{
154 struct wil6210_priv *wil = (void *)x;
155
7743882d 156 wil_dbg_misc(wil, "Connect timeout\n");
2be7d22f
VK
157
158 /* reschedule to thread context - disconnect won't
159 * run from atomic context
160 */
161 schedule_work(&wil->disconnect_worker);
162}
163
047e5d74
VK
164static void wil_scan_timer_fn(ulong x)
165{
166 struct wil6210_priv *wil = (void *)x;
167
168 clear_bit(wil_status_fwready, &wil->status);
169 wil_err(wil, "Scan timeout detected, start fw error recovery\n");
170 schedule_work(&wil->fw_error_worker);
171}
172
ed6f9dc6
VK
173static void wil_fw_error_worker(struct work_struct *work)
174{
175 struct wil6210_priv *wil = container_of(work,
176 struct wil6210_priv, fw_error_worker);
177 struct wireless_dev *wdev = wil->wdev;
178
179 wil_dbg_misc(wil, "fw error worker\n");
180
181 if (no_fw_recovery)
182 return;
183
fc219eed
VK
184 /* increment @recovery_count if less then WIL6210_FW_RECOVERY_TO
185 * passed since last recovery attempt
186 */
187 if (time_is_after_jiffies(wil->last_fw_recovery +
188 WIL6210_FW_RECOVERY_TO))
189 wil->recovery_count++;
190 else
191 wil->recovery_count = 1; /* fw was alive for a long time */
192
193 if (wil->recovery_count > WIL6210_FW_RECOVERY_RETRIES) {
194 wil_err(wil, "too many recovery attempts (%d), giving up\n",
195 wil->recovery_count);
196 return;
197 }
198
199 wil->last_fw_recovery = jiffies;
200
9c3bde56 201 mutex_lock(&wil->mutex);
ed6f9dc6
VK
202 switch (wdev->iftype) {
203 case NL80211_IFTYPE_STATION:
204 case NL80211_IFTYPE_P2P_CLIENT:
205 case NL80211_IFTYPE_MONITOR:
fc219eed
VK
206 wil_info(wil, "fw error recovery started (try %d)...\n",
207 wil->recovery_count);
ed6f9dc6
VK
208 wil_reset(wil);
209
210 /* need to re-allocate Rx ring after reset */
211 wil_rx_init(wil);
212 break;
213 case NL80211_IFTYPE_AP:
214 case NL80211_IFTYPE_P2P_GO:
215 /* recovery in these modes is done by upper layers */
216 break;
217 default:
218 break;
219 }
9c3bde56 220 mutex_unlock(&wil->mutex);
ed6f9dc6
VK
221}
222
9a177384
VK
223static int wil_find_free_vring(struct wil6210_priv *wil)
224{
225 int i;
226 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
227 if (!wil->vring_tx[i].va)
228 return i;
229 }
230 return -EINVAL;
231}
232
d81079f1
VK
233static void wil_connect_worker(struct work_struct *work)
234{
235 int rc;
236 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
237 connect_worker);
238 int cid = wil->pending_connect_cid;
9a177384 239 int ringid = wil_find_free_vring(wil);
d81079f1
VK
240
241 if (cid < 0) {
242 wil_err(wil, "No connection pending\n");
243 return;
244 }
245
246 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
247
9a177384 248 rc = wil_vring_init_tx(wil, ringid, WIL6210_TX_RING_SIZE, cid, 0);
d81079f1 249 wil->pending_connect_cid = -1;
3df2cd36
VK
250 if (rc == 0) {
251 wil->sta[cid].status = wil_sta_connected;
d81079f1 252 wil_link_on(wil);
3df2cd36
VK
253 } else {
254 wil->sta[cid].status = wil_sta_unused;
255 }
d81079f1
VK
256}
257
2be7d22f
VK
258int wil_priv_init(struct wil6210_priv *wil)
259{
7743882d 260 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f 261
3df2cd36
VK
262 memset(wil->sta, 0, sizeof(wil->sta));
263
2be7d22f
VK
264 mutex_init(&wil->mutex);
265 mutex_init(&wil->wmi_mutex);
266
267 init_completion(&wil->wmi_ready);
268
269 wil->pending_connect_cid = -1;
270 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
047e5d74 271 setup_timer(&wil->scan_timer, wil_scan_timer_fn, (ulong)wil);
2be7d22f 272
d81079f1 273 INIT_WORK(&wil->connect_worker, wil_connect_worker);
2be7d22f
VK
274 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
275 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
ed6f9dc6 276 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
2be7d22f
VK
277
278 INIT_LIST_HEAD(&wil->pending_wmi_ev);
279 spin_lock_init(&wil->wmi_ev_lock);
280
281 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME"_wmi");
282 if (!wil->wmi_wq)
283 return -EAGAIN;
284
285 wil->wmi_wq_conn = create_singlethread_workqueue(WIL_NAME"_connect");
286 if (!wil->wmi_wq_conn) {
287 destroy_workqueue(wil->wmi_wq);
288 return -EAGAIN;
289 }
290
fc219eed
VK
291 wil->last_fw_recovery = jiffies;
292
2be7d22f
VK
293 return 0;
294}
295
3b3a0162 296void wil6210_disconnect(struct wil6210_priv *wil, const u8 *bssid)
2be7d22f
VK
297{
298 del_timer_sync(&wil->connect_timer);
299 _wil6210_disconnect(wil, bssid);
300}
301
302void wil_priv_deinit(struct wil6210_priv *wil)
303{
047e5d74 304 del_timer_sync(&wil->scan_timer);
2be7d22f 305 cancel_work_sync(&wil->disconnect_worker);
ed6f9dc6 306 cancel_work_sync(&wil->fw_error_worker);
097638a0 307 mutex_lock(&wil->mutex);
2be7d22f 308 wil6210_disconnect(wil, NULL);
097638a0 309 mutex_unlock(&wil->mutex);
2be7d22f
VK
310 wmi_event_flush(wil);
311 destroy_workqueue(wil->wmi_wq_conn);
312 destroy_workqueue(wil->wmi_wq);
313}
314
bbb2adc7 315static int wil_target_reset(struct wil6210_priv *wil)
2be7d22f 316{
98a65b59 317 int delay = 0;
d28bcc30 318 u32 hw_state;
36b10a72 319 u32 rev_id;
6508281b 320 bool is_sparrow = (wil->board->board == WIL_BOARD_SPARROW);
36b10a72 321
6508281b 322 wil_dbg_misc(wil, "Resetting \"%s\"...\n", wil->board->name);
2be7d22f 323
36b10a72
VK
324 /* register read */
325#define R(a) ioread32(wil->csr + HOSTADDR(a))
2be7d22f
VK
326 /* register write */
327#define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a))
328 /* register set = read, OR, write */
972072aa
VK
329#define S(a, v) W(a, R(a) | v)
330 /* register clear = read, AND with inverted, write */
331#define C(a, v) W(a, R(a) & ~v)
2be7d22f 332
cc9e4a2b
VK
333 wmb(); /* If host reorder writes here -> race in NIC */
334 W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
17123991 335 wil->hw_version = R(RGF_USER_FW_REV_ID);
36b10a72 336 rev_id = wil->hw_version & 0xff;
6508281b
VK
337
338 /* Clear MAC link up */
339 S(RGF_HP_CTRL, BIT(15));
2be7d22f
VK
340 /* hpal_perst_from_pad_src_n_mask */
341 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6));
342 /* car_perst_rst_src_n_mask */
343 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7));
260e6951 344 wmb(); /* order is important here */
2be7d22f 345
6508281b
VK
346 if (is_sparrow) {
347 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x3ff81f);
348 wmb(); /* order is important here */
349 }
350
2be7d22f 351 W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */
cc9e4a2b
VK
352 wmb(); /* If host reorder writes here -> race in NIC */
353 W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
260e6951 354 wmb(); /* order is important here */
2be7d22f 355
2be7d22f
VK
356 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
357 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
6508281b 358 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, is_sparrow ? 0x000000B0 : 0x00000170);
2be7d22f 359 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00);
260e6951 360 wmb(); /* order is important here */
2be7d22f 361
6508281b
VK
362 if (is_sparrow) {
363 W(RGF_USER_CLKS_CTL_EXT_SW_RST_VEC_0, 0x0);
364 wmb(); /* order is important here */
365 }
366
2be7d22f
VK
367 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
368 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
369 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
370 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
260e6951 371 wmb(); /* order is important here */
2be7d22f 372
6508281b
VK
373 if (is_sparrow) {
374 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000003);
375 /* reset A2 PCIE AHB */
36b10a72 376 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
6508281b
VK
377
378 } else {
379 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
380 if (rev_id == 1) {
381 /* reset A1 BOTH PCIE AHB & PCIE RGF */
382 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
383 } else {
384 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
385 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
386 }
387
36b10a72 388 }
6508281b
VK
389
390 /* TODO: check order here!!! Erez code is different */
2be7d22f 391 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
260e6951 392 wmb(); /* order is important here */
2be7d22f 393
520d68e7 394 /* wait until device ready. typical time is 200..250 msec */
36b10a72 395 do {
520d68e7 396 msleep(RST_DELAY);
d28bcc30 397 hw_state = R(RGF_USER_HW_MACHINE_STATE);
520d68e7 398 if (delay++ > RST_COUNT) {
d28bcc30
VK
399 wil_err(wil, "Reset not completed, hw_state 0x%08x\n",
400 hw_state);
bbb2adc7 401 return -ETIME;
36b10a72 402 }
d28bcc30 403 } while (hw_state != HW_MACHINE_BOOT_DONE);
36b10a72 404
6508281b
VK
405 /* TODO: Erez check rev_id != 1 */
406 if (!is_sparrow && (rev_id != 1))
17123991 407 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
36b10a72 408
972072aa 409 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
260e6951 410 wmb(); /* order is important here */
972072aa 411
520d68e7 412 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay * RST_DELAY);
bbb2adc7 413 return 0;
2be7d22f 414
36b10a72 415#undef R
2be7d22f
VK
416#undef W
417#undef S
972072aa 418#undef C
2be7d22f
VK
419}
420
421void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
422{
423 le32_to_cpus(&r->base);
424 le16_to_cpus(&r->entry_size);
425 le16_to_cpus(&r->size);
426 le32_to_cpus(&r->tail);
427 le32_to_cpus(&r->head);
428}
429
430static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
431{
432 ulong to = msecs_to_jiffies(1000);
433 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
434 if (0 == left) {
435 wil_err(wil, "Firmware not ready\n");
436 return -ETIME;
437 } else {
15e23124
VK
438 wil_info(wil, "FW ready after %d ms. HW version 0x%08x\n",
439 jiffies_to_msecs(to-left), wil->hw_version);
2be7d22f
VK
440 }
441 return 0;
442}
443
444/*
445 * We reset all the structures, and we reset the UMAC.
446 * After calling this routine, you're expected to reload
447 * the firmware.
448 */
449int wil_reset(struct wil6210_priv *wil)
450{
451 int rc;
452
097638a0
VK
453 WARN_ON(!mutex_is_locked(&wil->mutex));
454
455 cancel_work_sync(&wil->disconnect_worker);
456 wil6210_disconnect(wil, NULL);
457
0fef1818
VK
458 wil->status = 0; /* prevent NAPI from being scheduled */
459 if (test_bit(wil_status_napi_en, &wil->status)) {
460 napi_synchronize(&wil->napi_rx);
0fef1818
VK
461 }
462
ed6f9dc6
VK
463 if (wil->scan_request) {
464 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
465 wil->scan_request);
047e5d74 466 del_timer_sync(&wil->scan_timer);
ed6f9dc6
VK
467 cfg80211_scan_done(wil->scan_request, true);
468 wil->scan_request = NULL;
469 }
470
e08b5906 471 wil6210_disable_irq(wil);
e08b5906 472
2be7d22f
VK
473 wmi_event_flush(wil);
474
2be7d22f 475 flush_workqueue(wil->wmi_wq_conn);
e08b5906 476 flush_workqueue(wil->wmi_wq);
2be7d22f 477
bbb2adc7 478 rc = wil_target_reset(wil);
8bf6adb9 479 wil_rx_fini(wil);
bbb2adc7
VK
480 if (rc)
481 return rc;
482
8bf6adb9 483
2be7d22f
VK
484 /* init after reset */
485 wil->pending_connect_cid = -1;
16735d02 486 reinit_completion(&wil->wmi_ready);
2be7d22f 487
2be7d22f
VK
488 /* TODO: release MAC reset */
489 wil6210_enable_irq(wil);
490
491 /* we just started MAC, wait for FW ready */
492 rc = wil_wait_for_fw_ready(wil);
493
494 return rc;
495}
496
ed6f9dc6
VK
497void wil_fw_error_recovery(struct wil6210_priv *wil)
498{
499 wil_dbg_misc(wil, "starting fw error recovery\n");
500 schedule_work(&wil->fw_error_worker);
501}
2be7d22f
VK
502
503void wil_link_on(struct wil6210_priv *wil)
504{
505 struct net_device *ndev = wil_to_ndev(wil);
506
7743882d 507 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f
VK
508
509 netif_carrier_on(ndev);
55f8f680 510 wil_dbg_misc(wil, "netif_tx_wake : link on\n");
2be7d22f
VK
511 netif_tx_wake_all_queues(ndev);
512}
513
514void wil_link_off(struct wil6210_priv *wil)
515{
516 struct net_device *ndev = wil_to_ndev(wil);
517
7743882d 518 wil_dbg_misc(wil, "%s()\n", __func__);
2be7d22f
VK
519
520 netif_tx_stop_all_queues(ndev);
55f8f680 521 wil_dbg_misc(wil, "netif_tx_stop : link off\n");
2be7d22f
VK
522 netif_carrier_off(ndev);
523}
524
525static int __wil_up(struct wil6210_priv *wil)
526{
527 struct net_device *ndev = wil_to_ndev(wil);
528 struct wireless_dev *wdev = wil->wdev;
2be7d22f 529 int rc;
2be7d22f 530
097638a0
VK
531 WARN_ON(!mutex_is_locked(&wil->mutex));
532
2be7d22f
VK
533 rc = wil_reset(wil);
534 if (rc)
535 return rc;
536
e31b2562
VK
537 /* Rx VRING. After MAC and beacon */
538 rc = wil_rx_init(wil);
539 if (rc)
540 return rc;
541
2be7d22f
VK
542 switch (wdev->iftype) {
543 case NL80211_IFTYPE_STATION:
7743882d 544 wil_dbg_misc(wil, "type: STATION\n");
2be7d22f
VK
545 ndev->type = ARPHRD_ETHER;
546 break;
547 case NL80211_IFTYPE_AP:
7743882d 548 wil_dbg_misc(wil, "type: AP\n");
2be7d22f
VK
549 ndev->type = ARPHRD_ETHER;
550 break;
551 case NL80211_IFTYPE_P2P_CLIENT:
7743882d 552 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
2be7d22f
VK
553 ndev->type = ARPHRD_ETHER;
554 break;
555 case NL80211_IFTYPE_P2P_GO:
7743882d 556 wil_dbg_misc(wil, "type: P2P_GO\n");
2be7d22f
VK
557 ndev->type = ARPHRD_ETHER;
558 break;
559 case NL80211_IFTYPE_MONITOR:
7743882d 560 wil_dbg_misc(wil, "type: Monitor\n");
2be7d22f
VK
561 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
562 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
563 break;
564 default:
565 return -EOPNOTSUPP;
566 }
567
2be7d22f
VK
568 /* MAC address - pre-requisite for other commands */
569 wmi_set_mac_address(wil, ndev->dev_addr);
570
2be7d22f 571
e0287c4a
VK
572 napi_enable(&wil->napi_rx);
573 napi_enable(&wil->napi_tx);
0fef1818 574 set_bit(wil_status_napi_en, &wil->status);
e0287c4a 575
2be7d22f
VK
576 return 0;
577}
578
579int wil_up(struct wil6210_priv *wil)
580{
581 int rc;
582
583 mutex_lock(&wil->mutex);
584 rc = __wil_up(wil);
585 mutex_unlock(&wil->mutex);
586
587 return rc;
588}
589
590static int __wil_down(struct wil6210_priv *wil)
591{
097638a0
VK
592 WARN_ON(!mutex_is_locked(&wil->mutex));
593
0fef1818 594 clear_bit(wil_status_napi_en, &wil->status);
e0287c4a
VK
595 napi_disable(&wil->napi_rx);
596 napi_disable(&wil->napi_tx);
597
2be7d22f 598 if (wil->scan_request) {
2a91d7d0
VK
599 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
600 wil->scan_request);
047e5d74 601 del_timer_sync(&wil->scan_timer);
2be7d22f
VK
602 cfg80211_scan_done(wil->scan_request, true);
603 wil->scan_request = NULL;
604 }
605
606 wil6210_disconnect(wil, NULL);
607 wil_rx_fini(wil);
608
609 return 0;
610}
611
612int wil_down(struct wil6210_priv *wil)
613{
614 int rc;
615
616 mutex_lock(&wil->mutex);
617 rc = __wil_down(wil);
618 mutex_unlock(&wil->mutex);
619
620 return rc;
621}
3df2cd36
VK
622
623int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
624{
625 int i;
626 int rc = -ENOENT;
627
628 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
629 if ((wil->sta[i].status != wil_sta_unused) &&
108d1eb6 630 ether_addr_equal(wil->sta[i].addr, mac)) {
3df2cd36
VK
631 rc = i;
632 break;
633 }
634 }
635
636 return rc;
637}
This page took 0.166635 seconds and 5 git commands to generate.