Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 1 | /* |
| 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 Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 17 | #include <linux/moduleparam.h> |
| 18 | #include <linux/if_arp.h> |
Vladimir Kondratiev | 108d1eb | 2014-02-27 16:20:53 +0200 | [diff] [blame] | 19 | #include <linux/etherdevice.h> |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 20 | |
| 21 | #include "wil6210.h" |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 22 | #include "txrx.h" |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * Due to a hardware issue, |
| 26 | * one has to read/write to/from NIC in 32-bit chunks; |
| 27 | * regular memcpy_fromio and siblings will |
| 28 | * not work on 64-bit platform - it uses 64-bit transactions |
| 29 | * |
| 30 | * Force 32-bit transactions to enable NIC on 64-bit platforms |
| 31 | * |
| 32 | * To avoid byte swap on big endian host, __raw_{read|write}l |
| 33 | * should be used - {read|write}l would swap bytes to provide |
| 34 | * little endian on PCI value in host endianness. |
| 35 | */ |
| 36 | void wil_memcpy_fromio_32(void *dst, const volatile void __iomem *src, |
| 37 | size_t count) |
| 38 | { |
| 39 | u32 *d = dst; |
| 40 | const volatile u32 __iomem *s = src; |
| 41 | |
| 42 | /* size_t is unsigned, if (count%4 != 0) it will wrap */ |
| 43 | for (count += 4; count > 4; count -= 4) |
| 44 | *d++ = __raw_readl(s++); |
| 45 | } |
| 46 | |
| 47 | void wil_memcpy_toio_32(volatile void __iomem *dst, const void *src, |
| 48 | size_t count) |
| 49 | { |
| 50 | volatile u32 __iomem *d = dst; |
| 51 | const u32 *s = src; |
| 52 | |
| 53 | for (count += 4; count > 4; count -= 4) |
| 54 | __raw_writel(*s++, d++); |
| 55 | } |
| 56 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 57 | static void wil_disconnect_cid(struct wil6210_priv *wil, int cid) |
| 58 | { |
| 59 | uint i; |
| 60 | struct wil_sta_info *sta = &wil->sta[cid]; |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 61 | |
Vladimir Kondratiev | e58c9f7 | 2014-03-17 15:34:06 +0200 | [diff] [blame] | 62 | sta->data_port_open = false; |
Vladimir Kondratiev | 4d55a0a | 2014-02-27 16:20:54 +0200 | [diff] [blame] | 63 | if (sta->status != wil_sta_unused) { |
| 64 | wmi_disconnect_sta(wil, sta->addr, WLAN_REASON_DEAUTH_LEAVING); |
| 65 | sta->status = wil_sta_unused; |
| 66 | } |
| 67 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 68 | for (i = 0; i < WIL_STA_TID_NUM; i++) { |
| 69 | struct wil_tid_ampdu_rx *r = sta->tid_rx[i]; |
| 70 | sta->tid_rx[i] = NULL; |
| 71 | wil_tid_ampdu_rx_free(wil, r); |
| 72 | } |
| 73 | for (i = 0; i < ARRAY_SIZE(wil->vring_tx); i++) { |
| 74 | if (wil->vring2cid_tid[i][0] == cid) |
| 75 | wil_vring_fini_tx(wil, i); |
| 76 | } |
| 77 | memset(&sta->stats, 0, sizeof(sta->stats)); |
| 78 | } |
| 79 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 80 | static void _wil6210_disconnect(struct wil6210_priv *wil, void *bssid) |
| 81 | { |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 82 | int cid = -ENOENT; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 83 | struct net_device *ndev = wil_to_ndev(wil); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 84 | struct wireless_dev *wdev = wil->wdev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 85 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 86 | might_sleep(); |
| 87 | if (bssid) { |
| 88 | cid = wil_find_cid(wil, bssid); |
| 89 | wil_dbg_misc(wil, "%s(%pM, CID %d)\n", __func__, bssid, cid); |
| 90 | } else { |
| 91 | wil_dbg_misc(wil, "%s(all)\n", __func__); |
| 92 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 93 | |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 94 | if (cid >= 0) /* disconnect 1 peer */ |
| 95 | wil_disconnect_cid(wil, cid); |
| 96 | else /* disconnect all */ |
| 97 | for (cid = 0; cid < WIL6210_MAX_CID; cid++) |
| 98 | wil_disconnect_cid(wil, cid); |
| 99 | |
| 100 | /* link state */ |
| 101 | switch (wdev->iftype) { |
| 102 | case NL80211_IFTYPE_STATION: |
| 103 | case NL80211_IFTYPE_P2P_CLIENT: |
| 104 | wil_link_off(wil); |
| 105 | if (test_bit(wil_status_fwconnected, &wil->status)) { |
| 106 | clear_bit(wil_status_fwconnected, &wil->status); |
| 107 | cfg80211_disconnected(ndev, |
| 108 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 109 | NULL, 0, GFP_KERNEL); |
| 110 | } else if (test_bit(wil_status_fwconnecting, &wil->status)) { |
| 111 | cfg80211_connect_result(ndev, bssid, NULL, 0, NULL, 0, |
| 112 | WLAN_STATUS_UNSPECIFIED_FAILURE, |
| 113 | GFP_KERNEL); |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 114 | } |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 115 | clear_bit(wil_status_fwconnecting, &wil->status); |
Vladimir Kondratiev | 91886b0 | 2014-02-27 16:20:50 +0200 | [diff] [blame] | 116 | break; |
| 117 | default: |
| 118 | /* AP-like interface and monitor: |
| 119 | * never scan, always connected |
| 120 | */ |
| 121 | if (bssid) |
| 122 | cfg80211_del_sta(ndev, bssid, GFP_KERNEL); |
| 123 | break; |
Vladimir Kondratiev | b4490f4 | 2014-02-27 16:20:44 +0200 | [diff] [blame] | 124 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static void wil_disconnect_worker(struct work_struct *work) |
| 128 | { |
| 129 | struct wil6210_priv *wil = container_of(work, |
| 130 | struct wil6210_priv, disconnect_worker); |
| 131 | |
| 132 | _wil6210_disconnect(wil, NULL); |
| 133 | } |
| 134 | |
| 135 | static void wil_connect_timer_fn(ulong x) |
| 136 | { |
| 137 | struct wil6210_priv *wil = (void *)x; |
| 138 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 139 | wil_dbg_misc(wil, "Connect timeout\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 140 | |
| 141 | /* reschedule to thread context - disconnect won't |
| 142 | * run from atomic context |
| 143 | */ |
| 144 | schedule_work(&wil->disconnect_worker); |
| 145 | } |
| 146 | |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 147 | static int wil_find_free_vring(struct wil6210_priv *wil) |
| 148 | { |
| 149 | int i; |
| 150 | for (i = 0; i < WIL6210_MAX_TX_RINGS; i++) { |
| 151 | if (!wil->vring_tx[i].va) |
| 152 | return i; |
| 153 | } |
| 154 | return -EINVAL; |
| 155 | } |
| 156 | |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 157 | static void wil_connect_worker(struct work_struct *work) |
| 158 | { |
| 159 | int rc; |
| 160 | struct wil6210_priv *wil = container_of(work, struct wil6210_priv, |
| 161 | connect_worker); |
| 162 | int cid = wil->pending_connect_cid; |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 163 | int ringid = wil_find_free_vring(wil); |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 164 | |
| 165 | if (cid < 0) { |
| 166 | wil_err(wil, "No connection pending\n"); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | wil_dbg_wmi(wil, "Configure for connection CID %d\n", cid); |
| 171 | |
Vladimir Kondratiev | 9a17738 | 2014-02-27 16:20:45 +0200 | [diff] [blame] | 172 | rc = wil_vring_init_tx(wil, ringid, WIL6210_TX_RING_SIZE, cid, 0); |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 173 | wil->pending_connect_cid = -1; |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 174 | if (rc == 0) { |
| 175 | wil->sta[cid].status = wil_sta_connected; |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 176 | wil_link_on(wil); |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 177 | } else { |
| 178 | wil->sta[cid].status = wil_sta_unused; |
| 179 | } |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 180 | } |
| 181 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 182 | int wil_priv_init(struct wil6210_priv *wil) |
| 183 | { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 184 | wil_dbg_misc(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 185 | |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 186 | memset(wil->sta, 0, sizeof(wil->sta)); |
| 187 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 188 | mutex_init(&wil->mutex); |
| 189 | mutex_init(&wil->wmi_mutex); |
| 190 | |
| 191 | init_completion(&wil->wmi_ready); |
| 192 | |
| 193 | wil->pending_connect_cid = -1; |
| 194 | setup_timer(&wil->connect_timer, wil_connect_timer_fn, (ulong)wil); |
| 195 | |
Vladimir Kondratiev | d81079f | 2013-03-13 14:12:43 +0200 | [diff] [blame] | 196 | INIT_WORK(&wil->connect_worker, wil_connect_worker); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 197 | INIT_WORK(&wil->disconnect_worker, wil_disconnect_worker); |
| 198 | INIT_WORK(&wil->wmi_event_worker, wmi_event_worker); |
| 199 | |
| 200 | INIT_LIST_HEAD(&wil->pending_wmi_ev); |
| 201 | spin_lock_init(&wil->wmi_ev_lock); |
| 202 | |
| 203 | wil->wmi_wq = create_singlethread_workqueue(WIL_NAME"_wmi"); |
| 204 | if (!wil->wmi_wq) |
| 205 | return -EAGAIN; |
| 206 | |
| 207 | wil->wmi_wq_conn = create_singlethread_workqueue(WIL_NAME"_connect"); |
| 208 | if (!wil->wmi_wq_conn) { |
| 209 | destroy_workqueue(wil->wmi_wq); |
| 210 | return -EAGAIN; |
| 211 | } |
| 212 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 213 | return 0; |
| 214 | } |
| 215 | |
| 216 | void wil6210_disconnect(struct wil6210_priv *wil, void *bssid) |
| 217 | { |
| 218 | del_timer_sync(&wil->connect_timer); |
| 219 | _wil6210_disconnect(wil, bssid); |
| 220 | } |
| 221 | |
| 222 | void wil_priv_deinit(struct wil6210_priv *wil) |
| 223 | { |
| 224 | cancel_work_sync(&wil->disconnect_worker); |
| 225 | wil6210_disconnect(wil, NULL); |
| 226 | wmi_event_flush(wil); |
| 227 | destroy_workqueue(wil->wmi_wq_conn); |
| 228 | destroy_workqueue(wil->wmi_wq); |
| 229 | } |
| 230 | |
| 231 | static void wil_target_reset(struct wil6210_priv *wil) |
| 232 | { |
Vladimir Kondratiev | 98a65b5 | 2014-03-17 15:34:12 +0200 | [diff] [blame] | 233 | int delay = 0; |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 234 | u32 baud_rate; |
| 235 | u32 rev_id; |
| 236 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 237 | wil_dbg_misc(wil, "Resetting...\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 238 | |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 239 | /* register read */ |
| 240 | #define R(a) ioread32(wil->csr + HOSTADDR(a)) |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 241 | /* register write */ |
| 242 | #define W(a, v) iowrite32(v, wil->csr + HOSTADDR(a)) |
| 243 | /* register set = read, OR, write */ |
| 244 | #define S(a, v) iowrite32(ioread32(wil->csr + HOSTADDR(a)) | v, \ |
| 245 | wil->csr + HOSTADDR(a)) |
| 246 | |
Vladimir Kondratiev | 1712399 | 2014-03-17 15:34:14 +0200 | [diff] [blame^] | 247 | wil->hw_version = R(RGF_USER_FW_REV_ID); |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 248 | rev_id = wil->hw_version & 0xff; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 249 | /* hpal_perst_from_pad_src_n_mask */ |
| 250 | S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(6)); |
| 251 | /* car_perst_rst_src_n_mask */ |
| 252 | S(RGF_USER_CLKS_CTL_SW_RST_MASK_0, BIT(7)); |
| 253 | |
| 254 | W(RGF_USER_MAC_CPU_0, BIT(1)); /* mac_cpu_man_rst */ |
| 255 | W(RGF_USER_USER_CPU_0, BIT(1)); /* user_cpu_man_rst */ |
| 256 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 257 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0xFE000000); |
| 258 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0x0000003F); |
| 259 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000170); |
| 260 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0xFFE7FC00); |
| 261 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 262 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0); |
| 263 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0); |
| 264 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_1, 0); |
| 265 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); |
| 266 | |
| 267 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_3, 0x00000001); |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 268 | if (rev_id == 1) { |
| 269 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00000080); |
| 270 | } else { |
Vladimir Kondratiev | 1712399 | 2014-03-17 15:34:14 +0200 | [diff] [blame^] | 271 | W(RGF_PCIE_LOS_COUNTER_CTL, BIT(6) | BIT(8)); |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 272 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_2, 0x00008000); |
| 273 | } |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 274 | W(RGF_USER_CLKS_CTL_SW_RST_VEC_0, 0); |
| 275 | |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 276 | /* wait until device ready. Use baud rate */ |
| 277 | do { |
| 278 | msleep(1); |
| 279 | baud_rate = R(RGF_USER_SERIAL_BAUD_RATE); |
Vladimir Kondratiev | 98a65b5 | 2014-03-17 15:34:12 +0200 | [diff] [blame] | 280 | if (delay++ > 100) { |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 281 | wil_err(wil, "Reset not completed\n"); |
| 282 | return; |
| 283 | } |
| 284 | } while (baud_rate != 0x15e); |
| 285 | |
| 286 | if (rev_id == 2) |
Vladimir Kondratiev | 1712399 | 2014-03-17 15:34:14 +0200 | [diff] [blame^] | 287 | W(RGF_PCIE_LOS_COUNTER_CTL, BIT(8)); |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 288 | |
Vladimir Kondratiev | 98a65b5 | 2014-03-17 15:34:12 +0200 | [diff] [blame] | 289 | wil_dbg_misc(wil, "Reset completed in %d ms\n", delay); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 290 | |
Vladimir Kondratiev | 36b10a7 | 2014-03-17 15:34:10 +0200 | [diff] [blame] | 291 | #undef R |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 292 | #undef W |
| 293 | #undef S |
| 294 | } |
| 295 | |
| 296 | void wil_mbox_ring_le2cpus(struct wil6210_mbox_ring *r) |
| 297 | { |
| 298 | le32_to_cpus(&r->base); |
| 299 | le16_to_cpus(&r->entry_size); |
| 300 | le16_to_cpus(&r->size); |
| 301 | le32_to_cpus(&r->tail); |
| 302 | le32_to_cpus(&r->head); |
| 303 | } |
| 304 | |
| 305 | static int wil_wait_for_fw_ready(struct wil6210_priv *wil) |
| 306 | { |
| 307 | ulong to = msecs_to_jiffies(1000); |
| 308 | ulong left = wait_for_completion_timeout(&wil->wmi_ready, to); |
| 309 | if (0 == left) { |
| 310 | wil_err(wil, "Firmware not ready\n"); |
| 311 | return -ETIME; |
| 312 | } else { |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 313 | wil_dbg_misc(wil, "FW ready after %d ms\n", |
Vladimir Kondratiev | 2057ebb | 2013-01-28 18:30:58 +0200 | [diff] [blame] | 314 | jiffies_to_msecs(to-left)); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 315 | } |
| 316 | return 0; |
| 317 | } |
| 318 | |
| 319 | /* |
| 320 | * We reset all the structures, and we reset the UMAC. |
| 321 | * After calling this routine, you're expected to reload |
| 322 | * the firmware. |
| 323 | */ |
| 324 | int wil_reset(struct wil6210_priv *wil) |
| 325 | { |
| 326 | int rc; |
| 327 | |
| 328 | cancel_work_sync(&wil->disconnect_worker); |
| 329 | wil6210_disconnect(wil, NULL); |
| 330 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 331 | wil6210_disable_irq(wil); |
| 332 | wil->status = 0; |
| 333 | |
Vladimir Kondratiev | e08b590 | 2013-01-28 18:31:05 +0200 | [diff] [blame] | 334 | wmi_event_flush(wil); |
| 335 | |
| 336 | flush_workqueue(wil->wmi_wq_conn); |
| 337 | flush_workqueue(wil->wmi_wq); |
| 338 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 339 | /* TODO: put MAC in reset */ |
| 340 | wil_target_reset(wil); |
| 341 | |
| 342 | /* init after reset */ |
| 343 | wil->pending_connect_cid = -1; |
Wolfram Sang | 16735d0 | 2013-11-14 14:32:02 -0800 | [diff] [blame] | 344 | reinit_completion(&wil->wmi_ready); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 345 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 346 | /* TODO: release MAC reset */ |
| 347 | wil6210_enable_irq(wil); |
| 348 | |
| 349 | /* we just started MAC, wait for FW ready */ |
| 350 | rc = wil_wait_for_fw_ready(wil); |
| 351 | |
| 352 | return rc; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | void wil_link_on(struct wil6210_priv *wil) |
| 357 | { |
| 358 | struct net_device *ndev = wil_to_ndev(wil); |
| 359 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 360 | wil_dbg_misc(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 361 | |
| 362 | netif_carrier_on(ndev); |
| 363 | netif_tx_wake_all_queues(ndev); |
| 364 | } |
| 365 | |
| 366 | void wil_link_off(struct wil6210_priv *wil) |
| 367 | { |
| 368 | struct net_device *ndev = wil_to_ndev(wil); |
| 369 | |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 370 | wil_dbg_misc(wil, "%s()\n", __func__); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 371 | |
| 372 | netif_tx_stop_all_queues(ndev); |
| 373 | netif_carrier_off(ndev); |
| 374 | } |
| 375 | |
| 376 | static int __wil_up(struct wil6210_priv *wil) |
| 377 | { |
| 378 | struct net_device *ndev = wil_to_ndev(wil); |
| 379 | struct wireless_dev *wdev = wil->wdev; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 380 | int rc; |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 381 | |
| 382 | rc = wil_reset(wil); |
| 383 | if (rc) |
| 384 | return rc; |
| 385 | |
Vladimir Kondratiev | e31b256 | 2013-06-09 09:12:55 +0300 | [diff] [blame] | 386 | /* Rx VRING. After MAC and beacon */ |
| 387 | rc = wil_rx_init(wil); |
| 388 | if (rc) |
| 389 | return rc; |
| 390 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 391 | switch (wdev->iftype) { |
| 392 | case NL80211_IFTYPE_STATION: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 393 | wil_dbg_misc(wil, "type: STATION\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 394 | ndev->type = ARPHRD_ETHER; |
| 395 | break; |
| 396 | case NL80211_IFTYPE_AP: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 397 | wil_dbg_misc(wil, "type: AP\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 398 | ndev->type = ARPHRD_ETHER; |
| 399 | break; |
| 400 | case NL80211_IFTYPE_P2P_CLIENT: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 401 | wil_dbg_misc(wil, "type: P2P_CLIENT\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 402 | ndev->type = ARPHRD_ETHER; |
| 403 | break; |
| 404 | case NL80211_IFTYPE_P2P_GO: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 405 | wil_dbg_misc(wil, "type: P2P_GO\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 406 | ndev->type = ARPHRD_ETHER; |
| 407 | break; |
| 408 | case NL80211_IFTYPE_MONITOR: |
Vladimir Kondratiev | 7743882 | 2013-01-28 18:31:06 +0200 | [diff] [blame] | 409 | wil_dbg_misc(wil, "type: Monitor\n"); |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 410 | ndev->type = ARPHRD_IEEE80211_RADIOTAP; |
| 411 | /* ARPHRD_IEEE80211 or ARPHRD_IEEE80211_RADIOTAP ? */ |
| 412 | break; |
| 413 | default: |
| 414 | return -EOPNOTSUPP; |
| 415 | } |
| 416 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 417 | /* MAC address - pre-requisite for other commands */ |
| 418 | wmi_set_mac_address(wil, ndev->dev_addr); |
| 419 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 420 | |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 421 | napi_enable(&wil->napi_rx); |
| 422 | napi_enable(&wil->napi_tx); |
| 423 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 424 | return 0; |
| 425 | } |
| 426 | |
| 427 | int wil_up(struct wil6210_priv *wil) |
| 428 | { |
| 429 | int rc; |
| 430 | |
| 431 | mutex_lock(&wil->mutex); |
| 432 | rc = __wil_up(wil); |
| 433 | mutex_unlock(&wil->mutex); |
| 434 | |
| 435 | return rc; |
| 436 | } |
| 437 | |
| 438 | static int __wil_down(struct wil6210_priv *wil) |
| 439 | { |
Vladimir Kondratiev | e0287c4 | 2013-05-12 14:43:36 +0300 | [diff] [blame] | 440 | napi_disable(&wil->napi_rx); |
| 441 | napi_disable(&wil->napi_tx); |
| 442 | |
Vladimir Kondratiev | 2be7d22 | 2012-12-20 13:13:19 -0800 | [diff] [blame] | 443 | if (wil->scan_request) { |
| 444 | cfg80211_scan_done(wil->scan_request, true); |
| 445 | wil->scan_request = NULL; |
| 446 | } |
| 447 | |
| 448 | wil6210_disconnect(wil, NULL); |
| 449 | wil_rx_fini(wil); |
| 450 | |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | int wil_down(struct wil6210_priv *wil) |
| 455 | { |
| 456 | int rc; |
| 457 | |
| 458 | mutex_lock(&wil->mutex); |
| 459 | rc = __wil_down(wil); |
| 460 | mutex_unlock(&wil->mutex); |
| 461 | |
| 462 | return rc; |
| 463 | } |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 464 | |
| 465 | int wil_find_cid(struct wil6210_priv *wil, const u8 *mac) |
| 466 | { |
| 467 | int i; |
| 468 | int rc = -ENOENT; |
| 469 | |
| 470 | for (i = 0; i < ARRAY_SIZE(wil->sta); i++) { |
| 471 | if ((wil->sta[i].status != wil_sta_unused) && |
Vladimir Kondratiev | 108d1eb | 2014-02-27 16:20:53 +0200 | [diff] [blame] | 472 | ether_addr_equal(wil->sta[i].addr, mac)) { |
Vladimir Kondratiev | 3df2cd36 | 2014-02-27 16:20:43 +0200 | [diff] [blame] | 473 | rc = i; |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | return rc; |
| 479 | } |