blob: 32ac1b906abefd51e7d0faa5eca5102515d663e4 [file] [log] [blame]
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -08001/*
2 * Copyright (c) 2012 Qualcomm Atheros, Inc.
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
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"
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080023
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +020024static 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
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080028/*
29 * Due to a hardware issue,
30 * one has to read/write to/from NIC in 32-bit chunks;
31 * regular memcpy_fromio and siblings will
32 * not work on 64-bit platform - it uses 64-bit transactions
33 *
34 * Force 32-bit transactions to enable NIC on 64-bit platforms
35 *
36 * To avoid byte swap on big endian host, __raw_{read|write}l
37 * should be used - {read|write}l would swap bytes to provide
38 * little endian on PCI value in host endianness.
39 */
40void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src,
41 size_t count)
42{
43 u32 *d = dst;
44 const volatile u32 __iomem *s = src;
45
46 /* size_t is unsigned, if (count%4 != 0) it will wrap */
47 for (count += 4; count > 4; count -= 4)
48 *d++ = __raw_readl(s++);
49}
50
51void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src,
52 size_t count)
53{
54 volatile u32 __iomem *d = dst;
55 const u32 *s = src;
56
57 for (count += 4; count > 4; count -= 4)
58 __raw_writel(*s++, d++);
59}
60
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020061static void wil_disconnect_cid(struct wil6210_priv *wil, int cid)
62{
63 uint i;
64 struct wil_sta_info *sta = &wil->sta[cid];
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +020065
Vladimir Kondratieve58c9f72014-03-17 15:34:06 +020066 sta->data_port_open = false;
Vladimir Kondratiev4d55a0a2014-02-27 16:20:54 +020067 if (sta->status != wil_sta_unused) {
68 wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING);
69 sta->status = wil_sta_unused;
70 }
71
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020072 for (i = 0; i < WIL_STA_TID_NUM; i++) {
73 struct wil_tid_ampdu_rx *r = sta->tid_rx[i];
74 sta->tid_rx[i] = NULL;
75 wil_tid_ampdu_rx_free(wil, r);
76 }
77 for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) {
78 if (wil->vring2cid_tid[i][0] == cid)
79 wil_vring_fini_tx(wil, i);
80 }
81 memset(&sta->stats, 0, sizeof(sta->stats));
82}
83
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080084static void _wil6210_disconnect(struct wil6210_priv *wil, void *bssid)
85{
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020086 int cid = -ENOENT;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080087 struct net_device *ndev = wil_to_ndev(wil);
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020088 struct wireless_dev *wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080089
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020090 might_sleep();
91 if (bssid) {
92 cid = wil_find_cid(wil, bssid);
93 wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid);
94 } else {
95 wil_dbg_misc(wil, "%s(all)\n", __func__);
96 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -080097
Vladimir Kondratiev91886b02014-02-27 16:20:50 +020098 if (cid >= 0) /* disconnect 1 peer */
99 wil_disconnect_cid(wil, cid);
100 else /* disconnect all */
101 for (cid = 0; cid < WIL6210_MAX_CID; cid++)
102 wil_disconnect_cid(wil, cid);
103
104 /* link state */
105 switch (wdev->iftype) {
106 case NL80211_IFTYPE_STATION:
107 case NL80211_IFTYPE_P2P_CLIENT:
108 wil_link_off(wil);
109 if (test_bit(wil_status_fwconnected, &wil->status)) {
110 clear_bit(wil_status_fwconnected, &wil->status);
111 cfg80211_disconnected(ndev,
112 WLAN_STATUS_UNSPECIFIED_FAILURE,
113 NULL, 0, GFP_KERNEL);
114 } else if (test_bit(wil_status_fwconnecting, &wil->status)) {
115 cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0,
116 WLAN_STATUS_UNSPECIFIED_FAILURE,
117 GFP_KERNEL);
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200118 }
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200119 clear_bit(wil_status_fwconnecting, &wil->status);
Vladimir Kondratiev91886b02014-02-27 16:20:50 +0200120 break;
121 default:
122 /* AP-like interface and monitor:
123 * never scan, always connected
124 */
125 if (bssid)
126 cfg80211_del_sta(ndev, bssid, GFP_KERNEL);
127 break;
Vladimir Kondratievb4490f42014-02-27 16:20:44 +0200128 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800129}
130
131static void wil_disconnect_worker(struct work_struct *work)
132{
133 struct wil6210_priv *wil = container_of(work,
134 struct wil6210_priv, disconnect_worker);
135
136 _wil6210_disconnect(wil, NULL);
137}
138
139static void wil_connect_timer_fn(ulong x)
140{
141 struct wil6210_priv *wil = (void *)x;
142
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200143 wil_dbg_misc(wil, "Connect timeout\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800144
145 /* reschedule to thread context - disconnect won't
146 * run from atomic context
147 */
148 schedule_work(&wil->disconnect_worker);
149}
150
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200151static void wil_fw_error_worker(struct work_struct *work)
152{
153 struct wil6210_priv *wil = container_of(work,
154 struct wil6210_priv, fw_error_worker);
155 struct wireless_dev *wdev = wil->wdev;
156
157 wil_dbg_misc(wil, "fw error worker\n");
158
159 if (no_fw_recovery)
160 return;
161
162 switch (wdev->iftype) {
163 case NL80211_IFTYPE_STATION:
164 case NL80211_IFTYPE_P2P_CLIENT:
165 case NL80211_IFTYPE_MONITOR:
166 wil_info(wil, "fw error recovery started...\n");
167 wil_reset(wil);
168
169 /* need to re-allocate Rx ring after reset */
170 wil_rx_init(wil);
171 break;
172 case NL80211_IFTYPE_AP:
173 case NL80211_IFTYPE_P2P_GO:
174 /* recovery in these modes is done by upper layers */
175 break;
176 default:
177 break;
178 }
179}
180
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200181static int wil_find_free_vring(struct wil6210_priv *wil)
182{
183 int i;
184 for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) {
185 if (!wil->vring_tx[i].va)
186 return i;
187 }
188 return -EINVAL;
189}
190
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200191static void wil_connect_worker(struct work_struct *work)
192{
193 int rc;
194 struct wil6210_priv *wil = container_of(work, struct wil6210_priv,
195 connect_worker);
196 int cid = wil->pending_connect_cid;
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200197 int ringid = wil_find_free_vring(wil);
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200198
199 if (cid < 0) {
200 wil_err(wil, "No connection pending\n");
201 return;
202 }
203
204 wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid);
205
Vladimir Kondratiev9a177382014-02-27 16:20:45 +0200206 rc = wil_vring_init_tx(wil, ringid, WIL6210_TX_RING_SIZE, cid, 0);
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200207 wil->pending_connect_cid = -1;
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200208 if (rc == 0) {
209 wil->sta[cid].status = wil_sta_connected;
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200210 wil_link_on(wil);
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200211 } else {
212 wil->sta[cid].status = wil_sta_unused;
213 }
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200214}
215
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800216int wil_priv_init(struct wil6210_priv *wil)
217{
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200218 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800219
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200220 memset(wil->sta, 0, sizeof(wil->sta));
221
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800222 mutex_init(&wil->mutex);
223 mutex_init(&wil->wmi_mutex);
224
225 init_completion(&wil->wmi_ready);
226
227 wil->pending_connect_cid = -1;
228 setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil);
229
Vladimir Kondratievd81079f2013-03-13 14:12:43 +0200230 INIT_WORK(&wil->connect_worker, wil_connect_worker);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800231 INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker);
232 INIT_WORK(&wil->wmi_event_worker, wmi_event_worker);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200233 INIT_WORK(&wil->fw_error_worker, wil_fw_error_worker);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800234
235 INIT_LIST_HEAD(&wil->pending_wmi_ev);
236 spin_lock_init(&wil->wmi_ev_lock);
237
238 wil->wmi_wq = create_singlethread_workqueue(WIL_NAME"_wmi");
239 if (!wil->wmi_wq)
240 return -EAGAIN;
241
242 wil->wmi_wq_conn = create_singlethread_workqueue(WIL_NAME"_connect");
243 if (!wil->wmi_wq_conn) {
244 destroy_workqueue(wil->wmi_wq);
245 return -EAGAIN;
246 }
247
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800248 return 0;
249}
250
251void wil6210_disconnect(struct wil6210_priv *wil, void *bssid)
252{
253 del_timer_sync(&wil->connect_timer);
254 _wil6210_disconnect(wil, bssid);
255}
256
257void wil_priv_deinit(struct wil6210_priv *wil)
258{
259 cancel_work_sync(&wil->disconnect_worker);
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200260 cancel_work_sync(&wil->fw_error_worker);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800261 wil6210_disconnect(wil, NULL);
262 wmi_event_flush(wil);
263 destroy_workqueue(wil->wmi_wq_conn);
264 destroy_workqueue(wil->wmi_wq);
265}
266
267static void wil_target_reset(struct wil6210_priv *wil)
268{
Vladimir Kondratiev98a65b52014-03-17 15:34:12 +0200269 int delay = 0;
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200270 u32 baud_rate;
271 u32 rev_id;
272
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200273 wil_dbg_misc(wil, "Resetting...\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800274
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200275 /* register read */
276#define R(a) ioread32(wil->csr + HOSTADDR(a))
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800277 /* register write */
278#define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a))
279 /* register set = read, OR, write */
Vladimir Kondratiev972072a2014-03-17 15:34:15 +0200280#define S(a, v) W(a, R(a) | v)
281 /* register clear = read, AND with inverted, write */
282#define C(a, v) W(a, R(a) & ~v)
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800283
Vladimir Kondratiev17123992014-03-17 15:34:14 +0200284 wil->hw_version = R(RGF_USER_FW_REV_ID);
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200285 rev_id = wil->hw_version & 0xff;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800286 /* hpal_perst_from_pad_src_n_mask */
287 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6));
288 /* car_perst_rst_src_n_mask */
289 S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7));
290
291 W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */
292 W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */
293
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800294 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000);
295 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F);
296 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000170);
297 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00);
298
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800299 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0);
300 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0);
301 W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0);
302 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
303
304 W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001);
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200305 if (rev_id == 1) {
306 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080);
307 } else {
Vladimir Kondratiev17123992014-03-17 15:34:14 +0200308 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8));
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200309 W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000);
310 }
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800311 W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0);
312
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200313 /* wait until device ready. Use baud rate */
314 do {
315 msleep(1);
316 baud_rate = R(RGF_USER_SERIAL_BAUD_RATE);
Vladimir Kondratiev98a65b52014-03-17 15:34:12 +0200317 if (delay++ > 100) {
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200318 wil_err(wil, "Reset not completed\n");
319 return;
320 }
321 } while (baud_rate != 0x15e);
322
323 if (rev_id == 2)
Vladimir Kondratiev17123992014-03-17 15:34:14 +0200324 W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8));
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200325
Vladimir Kondratiev972072a2014-03-17 15:34:15 +0200326 C(RGF_USER_CLKS_CTL_0, BIT_USER_CLKS_RST_PWGD);
327
Vladimir Kondratiev98a65b52014-03-17 15:34:12 +0200328 wil_dbg_misc(wil, "Reset completed in %d ms\n", delay);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800329
Vladimir Kondratiev36b10a72014-03-17 15:34:10 +0200330#undef R
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800331#undef W
332#undef S
Vladimir Kondratiev972072a2014-03-17 15:34:15 +0200333#undef C
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800334}
335
336void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r)
337{
338 le32_to_cpus(&r->base);
339 le16_to_cpus(&r->entry_size);
340 le16_to_cpus(&r->size);
341 le32_to_cpus(&r->tail);
342 le32_to_cpus(&r->head);
343}
344
345static int wil_wait_for_fw_ready(struct wil6210_priv *wil)
346{
347 ulong to = msecs_to_jiffies(1000);
348 ulong left = wait_for_completion_timeout(&wil->wmi_ready, to);
349 if (0 == left) {
350 wil_err(wil, "Firmware not ready\n");
351 return -ETIME;
352 } else {
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200353 wil_dbg_misc(wil, "FW ready after %d ms\n",
Vladimir Kondratiev2057ebb2013-01-28 18:30:58 +0200354 jiffies_to_msecs(to-left));
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800355 }
356 return 0;
357}
358
359/*
360 * We reset all the structures, and we reset the UMAC.
361 * After calling this routine, you're expected to reload
362 * the firmware.
363 */
364int wil_reset(struct wil6210_priv *wil)
365{
366 int rc;
367
Vladimir Kondratiev0fef1812014-03-17 15:34:18 +0200368 wil->status = 0; /* prevent NAPI from being scheduled */
369 if (test_bit(wil_status_napi_en, &wil->status)) {
370 napi_synchronize(&wil->napi_rx);
371 napi_synchronize(&wil->napi_tx);
372 }
373
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200374 if (wil->scan_request) {
375 wil_dbg_misc(wil, "Abort scan_request 0x%p\n",
376 wil->scan_request);
377 cfg80211_scan_done(wil->scan_request, true);
378 wil->scan_request = NULL;
379 }
380
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800381 cancel_work_sync(&wil->disconnect_worker);
382 wil6210_disconnect(wil, NULL);
383
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800384 wil6210_disable_irq(wil);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800385
Vladimir Kondratieve08b5902013-01-28 18:31:05 +0200386 wmi_event_flush(wil);
387
388 flush_workqueue(wil->wmi_wq_conn);
389 flush_workqueue(wil->wmi_wq);
390
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800391 /* TODO: put MAC in reset */
392 wil_target_reset(wil);
393
Vladimir Kondratiev8bf6adb2014-03-17 15:34:17 +0200394 wil_rx_fini(wil);
395
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800396 /* init after reset */
397 wil->pending_connect_cid = -1;
Wolfram Sang16735d02013-11-14 14:32:02 -0800398 reinit_completion(&wil->wmi_ready);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800399
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800400 /* TODO: release MAC reset */
401 wil6210_enable_irq(wil);
402
403 /* we just started MAC, wait for FW ready */
404 rc = wil_wait_for_fw_ready(wil);
405
406 return rc;
407}
408
Vladimir Kondratieved6f9dc2014-03-17 15:34:19 +0200409void wil_fw_error_recovery(struct wil6210_priv *wil)
410{
411 wil_dbg_misc(wil, "starting fw error recovery\n");
412 schedule_work(&wil->fw_error_worker);
413}
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800414
415void wil_link_on(struct wil6210_priv *wil)
416{
417 struct net_device *ndev = wil_to_ndev(wil);
418
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200419 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800420
421 netif_carrier_on(ndev);
422 netif_tx_wake_all_queues(ndev);
423}
424
425void wil_link_off(struct wil6210_priv *wil)
426{
427 struct net_device *ndev = wil_to_ndev(wil);
428
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200429 wil_dbg_misc(wil, "%s()\n", __func__);
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800430
431 netif_tx_stop_all_queues(ndev);
432 netif_carrier_off(ndev);
433}
434
435static int __wil_up(struct wil6210_priv *wil)
436{
437 struct net_device *ndev = wil_to_ndev(wil);
438 struct wireless_dev *wdev = wil->wdev;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800439 int rc;
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800440
441 rc = wil_reset(wil);
442 if (rc)
443 return rc;
444
Vladimir Kondratieve31b2562013-06-09 09:12:55 +0300445 /* Rx VRING. After MAC and beacon */
446 rc = wil_rx_init(wil);
447 if (rc)
448 return rc;
449
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800450 switch (wdev->iftype) {
451 case NL80211_IFTYPE_STATION:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200452 wil_dbg_misc(wil, "type: STATION\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800453 ndev->type = ARPHRD_ETHER;
454 break;
455 case NL80211_IFTYPE_AP:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200456 wil_dbg_misc(wil, "type: AP\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800457 ndev->type = ARPHRD_ETHER;
458 break;
459 case NL80211_IFTYPE_P2P_CLIENT:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200460 wil_dbg_misc(wil, "type: P2P_CLIENT\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800461 ndev->type = ARPHRD_ETHER;
462 break;
463 case NL80211_IFTYPE_P2P_GO:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200464 wil_dbg_misc(wil, "type: P2P_GO\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800465 ndev->type = ARPHRD_ETHER;
466 break;
467 case NL80211_IFTYPE_MONITOR:
Vladimir Kondratiev77438822013-01-28 18:31:06 +0200468 wil_dbg_misc(wil, "type: Monitor\n");
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800469 ndev->type = ARPHRD_IEEE80211_RADIOTAP;
470 /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */
471 break;
472 default:
473 return -EOPNOTSUPP;
474 }
475
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800476 /* MAC address - pre-requisite for other commands */
477 wmi_set_mac_address(wil, ndev->dev_addr);
478
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800479
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300480 napi_enable(&wil->napi_rx);
481 napi_enable(&wil->napi_tx);
Vladimir Kondratiev0fef1812014-03-17 15:34:18 +0200482 set_bit(wil_status_napi_en, &wil->status);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300483
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800484 return 0;
485}
486
487int wil_up(struct wil6210_priv *wil)
488{
489 int rc;
490
491 mutex_lock(&wil->mutex);
492 rc = __wil_up(wil);
493 mutex_unlock(&wil->mutex);
494
495 return rc;
496}
497
498static int __wil_down(struct wil6210_priv *wil)
499{
Vladimir Kondratiev0fef1812014-03-17 15:34:18 +0200500 clear_bit(wil_status_napi_en, &wil->status);
Vladimir Kondratieve0287c42013-05-12 14:43:36 +0300501 napi_disable(&wil->napi_rx);
502 napi_disable(&wil->napi_tx);
503
Vladimir Kondratiev2be7d222012-12-20 13:13:19 -0800504 if (wil->scan_request) {
505 cfg80211_scan_done(wil->scan_request, true);
506 wil->scan_request = NULL;
507 }
508
509 wil6210_disconnect(wil, NULL);
510 wil_rx_fini(wil);
511
512 return 0;
513}
514
515int wil_down(struct wil6210_priv *wil)
516{
517 int rc;
518
519 mutex_lock(&wil->mutex);
520 rc = __wil_down(wil);
521 mutex_unlock(&wil->mutex);
522
523 return rc;
524}
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200525
526int wil_find_cid(struct wil6210_priv *wil, const u8 *mac)
527{
528 int i;
529 int rc = -ENOENT;
530
531 for (i = 0; i < ARRAY_SIZE(wil->sta); i++) {
532 if ((wil->sta[i].status != wil_sta_unused) &&
Vladimir Kondratiev108d1eb2014-02-27 16:20:53 +0200533 ether_addr_equal(wil->sta[i].addr, mac)) {
Vladimir Kondratiev3df2cd362014-02-27 16:20:43 +0200534 rc = i;
535 break;
536 }
537 }
538
539 return rc;
540}