Commit | Line | Data |
---|---|---|
94a79942 LF |
1 | /****************************************************************************** |
2 | * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved. | |
3 | * | |
4 | * Based on the r8180 driver, which is: | |
559a4c31 | 5 | * Copyright 2004-2005 Andrea Merello <andrea.merello@gmail.com>, et al. |
94a79942 LF |
6 | * This program is free software; you can redistribute it and/or modify it |
7 | * under the terms of version 2 of the GNU General Public License as | |
8 | * published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
94a79942 LF |
15 | * The full GNU General Public License is included in this distribution in the |
16 | * file called LICENSE. | |
17 | * | |
18 | * Contact Information: | |
19 | * wlanfae <wlanfae@realtek.com> | |
20 | ******************************************************************************/ | |
1344ee25 | 21 | #include <linux/uaccess.h> |
94a79942 | 22 | #include <linux/pci.h> |
09ebd6f2 | 23 | #include <linux/vmalloc.h> |
acd442db | 24 | #include <linux/ieee80211.h> |
94a79942 LF |
25 | #include "rtl_core.h" |
26 | #include "r8192E_phy.h" | |
27 | #include "r8192E_phyreg.h" | |
28 | #include "r8190P_rtl8256.h" | |
29 | #include "r8192E_cmdpkt.h" | |
30 | ||
31 | #include "rtl_wx.h" | |
94a79942 | 32 | #include "rtl_dm.h" |
94a79942 | 33 | |
94a79942 | 34 | #include "rtl_pm.h" |
94a79942 LF |
35 | |
36 | int hwwep = 1; | |
37 | static int channels = 0x3fff; | |
49aab5fd | 38 | static char *ifname = "wlan%d"; |
94a79942 LF |
39 | |
40 | ||
1c099ed6 | 41 | static const struct rtl819x_ops rtl819xp_ops = { |
1344ee25 | 42 | .nic_type = NIC_8192E, |
b095be37 | 43 | .get_eeprom_size = rtl92e_get_eeprom_size, |
df85a131 | 44 | .init_adapter_variable = rtl92e_init_variables, |
46026629 | 45 | .initialize_adapter = rtl92e_start_adapter, |
b974b289 | 46 | .link_change = rtl92e_link_change, |
072b3948 | 47 | .tx_fill_descriptor = rtl92e_fill_tx_desc, |
63b544a1 | 48 | .tx_fill_cmd_descriptor = rtl92e_fill_tx_cmd_desc, |
7897285c | 49 | .rx_query_status_descriptor = rtl92e_get_rx_stats, |
94a79942 | 50 | .rx_command_packet_handler = NULL, |
fe99c77b | 51 | .stop_adapter = rtl92e_stop_adapter, |
575d48c5 | 52 | .update_ratr_table = rtl92e_update_ratr_table, |
6d99c68e | 53 | .irq_enable = rtl92e_enable_irq, |
baadea56 | 54 | .irq_disable = rtl92e_disable_irq, |
dc578b41 | 55 | .irq_clear = rtl92e_clear_irq, |
78c352b2 | 56 | .rx_enable = rtl92e_enable_rx, |
6af7a8b6 | 57 | .tx_enable = rtl92e_enable_tx, |
a57165d1 | 58 | .interrupt_recognized = rtl92e_ack_irq, |
c9cf5e78 | 59 | .TxCheckStuckHandler = rtl92e_is_tx_stuck, |
4d73bd26 | 60 | .RxCheckStuckHandler = rtl92e_is_rx_stuck, |
94a79942 LF |
61 | }; |
62 | ||
83f5789c | 63 | static struct pci_device_id rtl8192_pci_id_tbl[] = { |
94a79942 LF |
64 | {RTL_PCI_DEVICE(0x10ec, 0x8192, rtl819xp_ops)}, |
65 | {RTL_PCI_DEVICE(0x07aa, 0x0044, rtl819xp_ops)}, | |
66 | {RTL_PCI_DEVICE(0x07aa, 0x0047, rtl819xp_ops)}, | |
67 | {} | |
68 | }; | |
69 | ||
70 | MODULE_DEVICE_TABLE(pci, rtl8192_pci_id_tbl); | |
71 | ||
93cc57b5 MK |
72 | static int _rtl92e_pci_probe(struct pci_dev *pdev, |
73 | const struct pci_device_id *id); | |
4a851821 | 74 | static void _rtl92e_pci_disconnect(struct pci_dev *pdev); |
87e01f22 | 75 | static irqreturn_t _rtl92e_irq(int irq, void *netdev); |
94a79942 LF |
76 | |
77 | static struct pci_driver rtl8192_pci_driver = { | |
1344ee25 LF |
78 | .name = DRV_NAME, /* Driver name */ |
79 | .id_table = rtl8192_pci_id_tbl, /* PCI_ID table */ | |
93cc57b5 | 80 | .probe = _rtl92e_pci_probe, /* probe fn */ |
4a851821 | 81 | .remove = _rtl92e_pci_disconnect, /* remove fn */ |
3683dc1f | 82 | .suspend = rtl92e_suspend, /* PM suspend fn */ |
0ba6623d | 83 | .resume = rtl92e_resume, /* PM resume fn */ |
94a79942 LF |
84 | }; |
85 | ||
6f8d4a7d | 86 | static short _rtl92e_is_tx_queue_empty(struct net_device *dev); |
7e2d598a | 87 | static void _rtl92e_watchdog_wq_cb(void *data); |
2cfc3758 | 88 | static void _rtl92e_watchdog_timer_cb(unsigned long data); |
52a74045 | 89 | static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, |
235a86c3 | 90 | int rate); |
3e49f3ec | 91 | static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev); |
98208f96 | 92 | static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb); |
374a3c5a | 93 | static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb); |
197917a8 | 94 | static short _rtl92e_pci_initdescring(struct net_device *dev); |
a2743b2c | 95 | static void _rtl92e_irq_tx_tasklet(struct r8192_priv *priv); |
2940405b | 96 | static void _rtl92e_irq_rx_tasklet(struct r8192_priv *priv); |
4dba03a2 | 97 | static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv); |
81524bbc | 98 | static int _rtl92e_up(struct net_device *dev, bool is_silent_reset); |
b1665a67 | 99 | static int _rtl92e_try_up(struct net_device *dev); |
33bec9bd | 100 | static int _rtl92e_down(struct net_device *dev, bool shutdownrf); |
78e67df3 | 101 | static void _rtl92e_restart(void *data); |
235a86c3 | 102 | |
94a79942 LF |
103 | /**************************************************************************** |
104 | -----------------------------IO STUFF------------------------- | |
105 | *****************************************************************************/ | |
94a79942 | 106 | |
b59a4ca3 | 107 | u8 rtl92e_readb(struct net_device *dev, int x) |
94a79942 | 108 | { |
49aab5fd | 109 | return 0xff & readb((u8 __iomem *)dev->mem_start + x); |
94a79942 LF |
110 | } |
111 | ||
99aa47e0 | 112 | u32 rtl92e_readl(struct net_device *dev, int x) |
94a79942 | 113 | { |
49aab5fd | 114 | return readl((u8 __iomem *)dev->mem_start + x); |
94a79942 LF |
115 | } |
116 | ||
1c0a7c0e | 117 | u16 rtl92e_readw(struct net_device *dev, int x) |
94a79942 | 118 | { |
49aab5fd | 119 | return readw((u8 __iomem *)dev->mem_start + x); |
94a79942 LF |
120 | } |
121 | ||
d8ae1967 | 122 | void rtl92e_writeb(struct net_device *dev, int x, u8 y) |
94a79942 | 123 | { |
49aab5fd | 124 | writeb(y, (u8 __iomem *)dev->mem_start + x); |
94a79942 | 125 | |
94a79942 | 126 | udelay(20); |
94a79942 LF |
127 | } |
128 | ||
8ea54100 | 129 | void rtl92e_writel(struct net_device *dev, int x, u32 y) |
94a79942 | 130 | { |
49aab5fd | 131 | writel(y, (u8 __iomem *)dev->mem_start + x); |
94a79942 | 132 | |
94a79942 | 133 | udelay(20); |
94a79942 LF |
134 | } |
135 | ||
6dee0c88 | 136 | void rtl92e_writew(struct net_device *dev, int x, u16 y) |
94a79942 | 137 | { |
49aab5fd | 138 | writew(y, (u8 __iomem *)dev->mem_start + x); |
94a79942 | 139 | |
94a79942 | 140 | udelay(20); |
94a79942 LF |
141 | } |
142 | ||
143 | /**************************************************************************** | |
144 | -----------------------------GENERAL FUNCTION------------------------- | |
145 | *****************************************************************************/ | |
f434f9d5 | 146 | bool rtl92e_set_rf_state(struct net_device *dev, |
1344ee25 | 147 | enum rt_rf_power_state StateToSet, |
2937a5d2 | 148 | RT_RF_CHANGE_SOURCE ChangeSource) |
94a79942 LF |
149 | { |
150 | struct r8192_priv *priv = rtllib_priv(dev); | |
1344ee25 | 151 | struct rtllib_device *ieee = priv->rtllib; |
94a79942 LF |
152 | bool bActionAllowed = false; |
153 | bool bConnectBySSID = false; | |
de7c885a | 154 | enum rt_rf_power_state rtState; |
94a79942 LF |
155 | u16 RFWaitCounter = 0; |
156 | unsigned long flag; | |
3a6b70c3 | 157 | |
0822339b | 158 | RT_TRACE((COMP_PS | COMP_RF), |
f434f9d5 | 159 | "===>rtl92e_set_rf_state(): StateToSet(%d)\n", StateToSet); |
94a79942 | 160 | |
2937a5d2 MK |
161 | while (true) { |
162 | spin_lock_irqsave(&priv->rf_ps_lock, flag); | |
163 | if (priv->RFChangeInProgress) { | |
164 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); | |
165 | RT_TRACE((COMP_PS | COMP_RF), | |
166 | "rtl92e_set_rf_state(): RF Change in progress! Wait to set..StateToSet(%d).\n", | |
167 | StateToSet); | |
94a79942 | 168 | |
2937a5d2 MK |
169 | while (priv->RFChangeInProgress) { |
170 | RFWaitCounter++; | |
1344ee25 | 171 | RT_TRACE((COMP_PS | COMP_RF), |
2937a5d2 MK |
172 | "rtl92e_set_rf_state(): Wait 1 ms (%d times)...\n", |
173 | RFWaitCounter); | |
174 | mdelay(1); | |
175 | ||
176 | if (RFWaitCounter > 100) { | |
177 | netdev_warn(dev, | |
178 | "%s(): Timeout waiting for RF change.\n", | |
179 | __func__); | |
180 | return false; | |
94a79942 LF |
181 | } |
182 | } | |
2937a5d2 MK |
183 | } else { |
184 | priv->RFChangeInProgress = true; | |
185 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); | |
186 | break; | |
94a79942 | 187 | } |
94a79942 LF |
188 | } |
189 | ||
190 | rtState = priv->rtllib->eRFPowerState; | |
191 | ||
1344ee25 | 192 | switch (StateToSet) { |
94a79942 | 193 | case eRfOn: |
94a79942 LF |
194 | priv->rtllib->RfOffReason &= (~ChangeSource); |
195 | ||
4bb01423 | 196 | if ((ChangeSource == RF_CHANGE_BY_HW) && priv->bHwRadioOff) |
94a79942 | 197 | priv->bHwRadioOff = false; |
94a79942 | 198 | |
1344ee25 | 199 | if (!priv->rtllib->RfOffReason) { |
94a79942 LF |
200 | priv->rtllib->RfOffReason = 0; |
201 | bActionAllowed = true; | |
202 | ||
203 | ||
1344ee25 LF |
204 | if (rtState == eRfOff && |
205 | ChangeSource >= RF_CHANGE_BY_HW) | |
94a79942 | 206 | bConnectBySSID = true; |
1344ee25 | 207 | } else { |
0822339b | 208 | RT_TRACE((COMP_PS | COMP_RF), |
f434f9d5 | 209 | "rtl92e_set_rf_state - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", |
1344ee25 LF |
210 | priv->rtllib->RfOffReason, ChangeSource); |
211 | } | |
94a79942 LF |
212 | |
213 | break; | |
214 | ||
215 | case eRfOff: | |
216 | ||
1344ee25 LF |
217 | if ((priv->rtllib->iw_mode == IW_MODE_INFRA) || |
218 | (priv->rtllib->iw_mode == IW_MODE_ADHOC)) { | |
219 | if ((priv->rtllib->RfOffReason > RF_CHANGE_BY_IPS) || | |
220 | (ChangeSource > RF_CHANGE_BY_IPS)) { | |
94a79942 LF |
221 | if (ieee->state == RTLLIB_LINKED) |
222 | priv->blinked_ingpio = true; | |
223 | else | |
224 | priv->blinked_ingpio = false; | |
1344ee25 | 225 | rtllib_MgntDisconnect(priv->rtllib, |
acd442db | 226 | WLAN_REASON_DISASSOC_STA_HAS_LEFT); |
94a79942 LF |
227 | } |
228 | } | |
4bb01423 | 229 | if ((ChangeSource == RF_CHANGE_BY_HW) && !priv->bHwRadioOff) |
94a79942 | 230 | priv->bHwRadioOff = true; |
94a79942 LF |
231 | priv->rtllib->RfOffReason |= ChangeSource; |
232 | bActionAllowed = true; | |
233 | break; | |
234 | ||
235 | case eRfSleep: | |
236 | priv->rtllib->RfOffReason |= ChangeSource; | |
237 | bActionAllowed = true; | |
238 | break; | |
239 | ||
240 | default: | |
241 | break; | |
242 | } | |
243 | ||
1344ee25 | 244 | if (bActionAllowed) { |
0822339b | 245 | RT_TRACE((COMP_PS | COMP_RF), |
f434f9d5 | 246 | "rtl92e_set_rf_state(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", |
1344ee25 | 247 | StateToSet, priv->rtllib->RfOffReason); |
94a79942 | 248 | PHY_SetRFPowerState(dev, StateToSet); |
1344ee25 | 249 | if (StateToSet == eRfOn) { |
94a79942 | 250 | |
4bb01423 | 251 | if (bConnectBySSID && priv->blinked_ingpio) { |
354605f4 | 252 | schedule_delayed_work( |
1344ee25 | 253 | &ieee->associate_procedure_wq, 0); |
94a79942 | 254 | priv->blinked_ingpio = false; |
94a79942 LF |
255 | } |
256 | } | |
257 | } else { | |
0822339b | 258 | RT_TRACE((COMP_PS | COMP_RF), |
f434f9d5 | 259 | "rtl92e_set_rf_state(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", |
0822339b | 260 | StateToSet, ChangeSource, priv->rtllib->RfOffReason); |
94a79942 LF |
261 | } |
262 | ||
2937a5d2 MK |
263 | spin_lock_irqsave(&priv->rf_ps_lock, flag); |
264 | priv->RFChangeInProgress = false; | |
265 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); | |
94a79942 | 266 | |
f434f9d5 | 267 | RT_TRACE((COMP_PS | COMP_RF), "<===rtl92e_set_rf_state()\n"); |
94a79942 LF |
268 | return bActionAllowed; |
269 | } | |
270 | ||
288adaf5 | 271 | static short _rtl92e_check_nic_enough_desc(struct net_device *dev, int prio) |
94a79942 | 272 | { |
1344ee25 LF |
273 | struct r8192_priv *priv = rtllib_priv(dev); |
274 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; | |
94a79942 | 275 | |
1344ee25 LF |
276 | if (ring->entries - skb_queue_len(&ring->queue) >= 2) |
277 | return 1; | |
278 | return 0; | |
94a79942 LF |
279 | } |
280 | ||
ac392655 | 281 | static void _rtl92e_tx_timeout(struct net_device *dev) |
94a79942 | 282 | { |
1344ee25 | 283 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 284 | |
1344ee25 | 285 | schedule_work(&priv->reset_wq); |
d69d2054 | 286 | netdev_info(dev, "TXTIMEOUT"); |
94a79942 LF |
287 | } |
288 | ||
b74299cd | 289 | void rtl92e_irq_enable(struct net_device *dev) |
94a79942 | 290 | { |
a4eed41f | 291 | struct r8192_priv *priv = rtllib_priv(dev); |
3a6b70c3 | 292 | |
94a79942 LF |
293 | priv->irq_enabled = 1; |
294 | ||
295 | priv->ops->irq_enable(dev); | |
296 | } | |
297 | ||
b7b50d65 | 298 | void rtl92e_irq_disable(struct net_device *dev) |
94a79942 | 299 | { |
a4eed41f | 300 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
301 | |
302 | priv->ops->irq_disable(dev); | |
303 | ||
304 | priv->irq_enabled = 0; | |
305 | } | |
306 | ||
5da06ad8 | 307 | static void _rtl92e_set_chan(struct net_device *dev, short ch) |
94a79942 | 308 | { |
a4eed41f | 309 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 310 | |
1344ee25 LF |
311 | RT_TRACE(COMP_CH, "=====>%s()====ch:%d\n", __func__, ch); |
312 | if (priv->chan_forced) | |
313 | return; | |
94a79942 | 314 | |
1344ee25 | 315 | priv->chan = ch; |
94a79942 | 316 | |
1344ee25 LF |
317 | if (priv->rf_set_chan) |
318 | priv->rf_set_chan(dev, priv->chan); | |
94a79942 LF |
319 | } |
320 | ||
9a99c563 | 321 | static void _rtl92e_update_cap(struct net_device *dev, u16 cap) |
94a79942 LF |
322 | { |
323 | struct r8192_priv *priv = rtllib_priv(dev); | |
324 | struct rtllib_network *net = &priv->rtllib->current_network; | |
1344ee25 LF |
325 | bool ShortPreamble; |
326 | ||
327 | if (cap & WLAN_CAPABILITY_SHORT_PREAMBLE) { | |
328 | if (priv->dot11CurrentPreambleMode != PREAMBLE_SHORT) { | |
329 | ShortPreamble = true; | |
330 | priv->dot11CurrentPreambleMode = PREAMBLE_SHORT; | |
0822339b MK |
331 | RT_TRACE(COMP_DBG, |
332 | "%s(): WLAN_CAPABILITY_SHORT_PREAMBLE\n", | |
333 | __func__); | |
1344ee25 LF |
334 | priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE, |
335 | (unsigned char *)&ShortPreamble); | |
94a79942 | 336 | } |
1344ee25 LF |
337 | } else { |
338 | if (priv->dot11CurrentPreambleMode != PREAMBLE_LONG) { | |
339 | ShortPreamble = false; | |
340 | priv->dot11CurrentPreambleMode = PREAMBLE_LONG; | |
0822339b MK |
341 | RT_TRACE(COMP_DBG, |
342 | "%s(): WLAN_CAPABILITY_LONG_PREAMBLE\n", | |
343 | __func__); | |
1344ee25 LF |
344 | priv->rtllib->SetHwRegHandler(dev, HW_VAR_ACK_PREAMBLE, |
345 | (unsigned char *)&ShortPreamble); | |
94a79942 LF |
346 | } |
347 | } | |
348 | ||
1344ee25 | 349 | if (net->mode & (IEEE_G|IEEE_N_24G)) { |
94a79942 LF |
350 | u8 slot_time_val; |
351 | u8 CurSlotTime = priv->slot_time; | |
352 | ||
1344ee25 LF |
353 | if ((cap & WLAN_CAPABILITY_SHORT_SLOT_TIME) && |
354 | (!priv->rtllib->pHTInfo->bCurrentRT2RTLongSlotTime)) { | |
355 | if (CurSlotTime != SHORT_SLOT_TIME) { | |
94a79942 | 356 | slot_time_val = SHORT_SLOT_TIME; |
1344ee25 LF |
357 | priv->rtllib->SetHwRegHandler(dev, |
358 | HW_VAR_SLOT_TIME, &slot_time_val); | |
94a79942 | 359 | } |
1344ee25 LF |
360 | } else { |
361 | if (CurSlotTime != NON_SHORT_SLOT_TIME) { | |
94a79942 | 362 | slot_time_val = NON_SHORT_SLOT_TIME; |
1344ee25 LF |
363 | priv->rtllib->SetHwRegHandler(dev, |
364 | HW_VAR_SLOT_TIME, &slot_time_val); | |
94a79942 LF |
365 | } |
366 | } | |
367 | } | |
368 | } | |
369 | ||
370 | static struct rtllib_qos_parameters def_qos_parameters = { | |
34e987e6 RK |
371 | {cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3), cpu_to_le16(3)}, |
372 | {cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7), cpu_to_le16(7)}, | |
1344ee25 LF |
373 | {2, 2, 2, 2}, |
374 | {0, 0, 0, 0}, | |
375 | {0, 0, 0, 0} | |
94a79942 LF |
376 | }; |
377 | ||
dc888405 | 378 | static void _rtl92e_update_beacon(void *data) |
94a79942 | 379 | { |
1344ee25 LF |
380 | struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, |
381 | update_beacon_wq.work); | |
94a79942 | 382 | struct net_device *dev = priv->rtllib->dev; |
1344ee25 LF |
383 | struct rtllib_device *ieee = priv->rtllib; |
384 | struct rtllib_network *net = &ieee->current_network; | |
94a79942 LF |
385 | |
386 | if (ieee->pHTInfo->bCurrentHTSupport) | |
976d5341 | 387 | HT_update_self_and_peer_setting(ieee, net); |
1344ee25 LF |
388 | ieee->pHTInfo->bCurrentRT2RTLongSlotTime = |
389 | net->bssht.bdRT2RTLongSlotTime; | |
94a79942 | 390 | ieee->pHTInfo->RT2RT_HT_Mode = net->bssht.RT2RT_HT_Mode; |
9a99c563 | 391 | _rtl92e_update_cap(dev, net->capability); |
94a79942 LF |
392 | } |
393 | ||
ae1fe0db | 394 | static void _rtl92e_qos_activate(void *data) |
94a79942 | 395 | { |
1344ee25 LF |
396 | struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, |
397 | qos_activate); | |
94a79942 | 398 | struct net_device *dev = priv->rtllib->dev; |
1344ee25 | 399 | int i; |
94a79942 | 400 | |
1344ee25 LF |
401 | mutex_lock(&priv->mutex); |
402 | if (priv->rtllib->state != RTLLIB_LINKED) | |
94a79942 | 403 | goto success; |
0822339b MK |
404 | RT_TRACE(COMP_QOS, |
405 | "qos active process with associate response received\n"); | |
94a79942 | 406 | |
fe40a0b3 | 407 | for (i = 0; i < QOS_QUEUE_NUM; i++) |
1344ee25 | 408 | priv->rtllib->SetHwRegHandler(dev, HW_VAR_AC_PARAM, (u8 *)(&i)); |
fe40a0b3 | 409 | |
94a79942 LF |
410 | |
411 | success: | |
1344ee25 | 412 | mutex_unlock(&priv->mutex); |
94a79942 LF |
413 | } |
414 | ||
c5d0d6f5 MK |
415 | static int _rtl92e_qos_handle_probe_response(struct r8192_priv *priv, |
416 | int active_network, | |
417 | struct rtllib_network *network) | |
94a79942 LF |
418 | { |
419 | int ret = 0; | |
420 | u32 size = sizeof(struct rtllib_qos_parameters); | |
421 | ||
1344ee25 LF |
422 | if (priv->rtllib->state != RTLLIB_LINKED) |
423 | return ret; | |
94a79942 | 424 | |
025b8bbe | 425 | if (priv->rtllib->iw_mode != IW_MODE_INFRA) |
94a79942 LF |
426 | return ret; |
427 | ||
428 | if (network->flags & NETWORK_HAS_QOS_MASK) { | |
429 | if (active_network && | |
430 | (network->flags & NETWORK_HAS_QOS_PARAMETERS)) | |
431 | network->qos_data.active = network->qos_data.supported; | |
432 | ||
433 | if ((network->qos_data.active == 1) && (active_network == 1) && | |
434 | (network->flags & NETWORK_HAS_QOS_PARAMETERS) && | |
435 | (network->qos_data.old_param_count != | |
1344ee25 | 436 | network->qos_data.param_count)) { |
94a79942 LF |
437 | network->qos_data.old_param_count = |
438 | network->qos_data.param_count; | |
1344ee25 | 439 | priv->rtllib->wmm_acm = network->qos_data.wmm_acm; |
ecfdd3a0 | 440 | schedule_work(&priv->qos_activate); |
0822339b MK |
441 | RT_TRACE(COMP_QOS, |
442 | "QoS parameters change call qos_activate\n"); | |
94a79942 LF |
443 | } |
444 | } else { | |
1344ee25 | 445 | memcpy(&priv->rtllib->current_network.qos_data.parameters, |
94a79942 LF |
446 | &def_qos_parameters, size); |
447 | ||
448 | if ((network->qos_data.active == 1) && (active_network == 1)) { | |
ecfdd3a0 | 449 | schedule_work(&priv->qos_activate); |
0822339b MK |
450 | RT_TRACE(COMP_QOS, |
451 | "QoS was disabled call qos_activate\n"); | |
94a79942 LF |
452 | } |
453 | network->qos_data.active = 0; | |
454 | network->qos_data.supported = 0; | |
455 | } | |
456 | ||
457 | return 0; | |
458 | } | |
459 | ||
5341f070 MK |
460 | static int _rtl92e_handle_beacon(struct net_device *dev, |
461 | struct rtllib_beacon *beacon, | |
462 | struct rtllib_network *network) | |
94a79942 LF |
463 | { |
464 | struct r8192_priv *priv = rtllib_priv(dev); | |
465 | ||
c5d0d6f5 | 466 | _rtl92e_qos_handle_probe_response(priv, 1, network); |
94a79942 | 467 | |
ecfdd3a0 | 468 | schedule_delayed_work(&priv->update_beacon_wq, 0); |
94a79942 LF |
469 | return 0; |
470 | ||
471 | } | |
472 | ||
24bee78a MK |
473 | static int _rtl92e_qos_assoc_resp(struct r8192_priv *priv, |
474 | struct rtllib_network *network) | |
94a79942 | 475 | { |
1344ee25 LF |
476 | unsigned long flags; |
477 | u32 size = sizeof(struct rtllib_qos_parameters); | |
478 | int set_qos_param = 0; | |
94a79942 | 479 | |
1344ee25 | 480 | if ((priv == NULL) || (network == NULL)) |
5c8b3961 | 481 | return 0; |
94a79942 | 482 | |
1344ee25 | 483 | if (priv->rtllib->state != RTLLIB_LINKED) |
5c8b3961 | 484 | return 0; |
94a79942 | 485 | |
025b8bbe | 486 | if (priv->rtllib->iw_mode != IW_MODE_INFRA) |
5c8b3961 | 487 | return 0; |
94a79942 | 488 | |
1344ee25 | 489 | spin_lock_irqsave(&priv->rtllib->lock, flags); |
94a79942 | 490 | if (network->flags & NETWORK_HAS_QOS_PARAMETERS) { |
1344ee25 LF |
491 | memcpy(&priv->rtllib->current_network.qos_data.parameters, |
492 | &network->qos_data.parameters, | |
493 | sizeof(struct rtllib_qos_parameters)); | |
94a79942 | 494 | priv->rtllib->current_network.qos_data.active = 1; |
1344ee25 | 495 | priv->rtllib->wmm_acm = network->qos_data.wmm_acm; |
94a79942 LF |
496 | set_qos_param = 1; |
497 | priv->rtllib->current_network.qos_data.old_param_count = | |
1344ee25 | 498 | priv->rtllib->current_network.qos_data.param_count; |
94a79942 | 499 | priv->rtllib->current_network.qos_data.param_count = |
1344ee25 LF |
500 | network->qos_data.param_count; |
501 | } else { | |
94a79942 | 502 | memcpy(&priv->rtllib->current_network.qos_data.parameters, |
1344ee25 | 503 | &def_qos_parameters, size); |
94a79942 LF |
504 | priv->rtllib->current_network.qos_data.active = 0; |
505 | priv->rtllib->current_network.qos_data.supported = 0; | |
1344ee25 LF |
506 | set_qos_param = 1; |
507 | } | |
94a79942 | 508 | |
1344ee25 | 509 | spin_unlock_irqrestore(&priv->rtllib->lock, flags); |
94a79942 LF |
510 | |
511 | RT_TRACE(COMP_QOS, "%s: network->flags = %d,%d\n", __func__, | |
1344ee25 | 512 | network->flags, priv->rtllib->current_network.qos_data.active); |
94a79942 | 513 | if (set_qos_param == 1) { |
7842c2d5 | 514 | rtl92e_dm_init_edca_turbo(priv->rtllib->dev); |
ecfdd3a0 | 515 | schedule_work(&priv->qos_activate); |
94a79942 | 516 | } |
5c8b3961 | 517 | return 0; |
94a79942 LF |
518 | } |
519 | ||
8b5a8031 | 520 | static int _rtl92e_handle_assoc_response(struct net_device *dev, |
1344ee25 LF |
521 | struct rtllib_assoc_response_frame *resp, |
522 | struct rtllib_network *network) | |
94a79942 | 523 | { |
1344ee25 | 524 | struct r8192_priv *priv = rtllib_priv(dev); |
3a6b70c3 | 525 | |
24bee78a | 526 | _rtl92e_qos_assoc_resp(priv, network); |
1344ee25 | 527 | return 0; |
94a79942 LF |
528 | } |
529 | ||
e009a849 | 530 | static void _rtl92e_prepare_beacon(struct r8192_priv *priv) |
94a79942 LF |
531 | { |
532 | struct net_device *dev = priv->rtllib->dev; | |
533 | struct sk_buff *pskb = NULL, *pnewskb = NULL; | |
3b83db43 | 534 | struct cb_desc *tcb_desc = NULL; |
94a79942 | 535 | struct rtl8192_tx_ring *ring = NULL; |
bc27e89b | 536 | struct tx_desc *pdesc = NULL; |
94a79942 LF |
537 | |
538 | ring = &priv->tx_ring[BEACON_QUEUE]; | |
539 | pskb = __skb_dequeue(&ring->queue); | |
085b5018 | 540 | kfree_skb(pskb); |
94a79942 LF |
541 | |
542 | pnewskb = rtllib_get_beacon(priv->rtllib); | |
543 | if (!pnewskb) | |
544 | return; | |
545 | ||
3b83db43 | 546 | tcb_desc = (struct cb_desc *)(pnewskb->cb + 8); |
94a79942 LF |
547 | tcb_desc->queue_index = BEACON_QUEUE; |
548 | tcb_desc->data_rate = 2; | |
549 | tcb_desc->RATRIndex = 7; | |
550 | tcb_desc->bTxDisableRateFallBack = 1; | |
551 | tcb_desc->bTxUseDriverAssingedRate = 1; | |
552 | skb_push(pnewskb, priv->rtllib->tx_headroom); | |
553 | ||
554 | pdesc = &ring->desc[0]; | |
555 | priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, pnewskb); | |
556 | __skb_queue_tail(&ring->queue, pnewskb); | |
557 | pdesc->OWN = 1; | |
94a79942 LF |
558 | } |
559 | ||
f2f08fc5 | 560 | static void _rtl92e_stop_beacon(struct net_device *dev) |
94a79942 LF |
561 | { |
562 | } | |
563 | ||
122fe9f1 | 564 | void rtl92e_config_rate(struct net_device *dev, u16 *rate_config) |
1344ee25 LF |
565 | { |
566 | struct r8192_priv *priv = rtllib_priv(dev); | |
567 | struct rtllib_network *net; | |
568 | u8 i = 0, basic_rate = 0; | |
3a6b70c3 | 569 | |
1344ee25 LF |
570 | net = &priv->rtllib->current_network; |
571 | ||
572 | for (i = 0; i < net->rates_len; i++) { | |
573 | basic_rate = net->rates[i] & 0x7f; | |
574 | switch (basic_rate) { | |
575 | case MGN_1M: | |
576 | *rate_config |= RRSR_1M; | |
577 | break; | |
578 | case MGN_2M: | |
579 | *rate_config |= RRSR_2M; | |
580 | break; | |
581 | case MGN_5_5M: | |
582 | *rate_config |= RRSR_5_5M; | |
583 | break; | |
584 | case MGN_11M: | |
585 | *rate_config |= RRSR_11M; | |
586 | break; | |
587 | case MGN_6M: | |
588 | *rate_config |= RRSR_6M; | |
589 | break; | |
590 | case MGN_9M: | |
591 | *rate_config |= RRSR_9M; | |
592 | break; | |
593 | case MGN_12M: | |
594 | *rate_config |= RRSR_12M; | |
595 | break; | |
596 | case MGN_18M: | |
597 | *rate_config |= RRSR_18M; | |
598 | break; | |
599 | case MGN_24M: | |
600 | *rate_config |= RRSR_24M; | |
601 | break; | |
602 | case MGN_36M: | |
603 | *rate_config |= RRSR_36M; | |
604 | break; | |
605 | case MGN_48M: | |
606 | *rate_config |= RRSR_48M; | |
607 | break; | |
608 | case MGN_54M: | |
609 | *rate_config |= RRSR_54M; | |
610 | break; | |
611 | } | |
612 | } | |
613 | ||
614 | for (i = 0; i < net->rates_ex_len; i++) { | |
615 | basic_rate = net->rates_ex[i] & 0x7f; | |
616 | switch (basic_rate) { | |
617 | case MGN_1M: | |
618 | *rate_config |= RRSR_1M; | |
619 | break; | |
620 | case MGN_2M: | |
621 | *rate_config |= RRSR_2M; | |
622 | break; | |
623 | case MGN_5_5M: | |
624 | *rate_config |= RRSR_5_5M; | |
625 | break; | |
626 | case MGN_11M: | |
627 | *rate_config |= RRSR_11M; | |
628 | break; | |
629 | case MGN_6M: | |
630 | *rate_config |= RRSR_6M; | |
631 | break; | |
632 | case MGN_9M: | |
633 | *rate_config |= RRSR_9M; | |
634 | break; | |
635 | case MGN_12M: | |
636 | *rate_config |= RRSR_12M; | |
637 | break; | |
638 | case MGN_18M: | |
639 | *rate_config |= RRSR_18M; | |
640 | break; | |
641 | case MGN_24M: | |
642 | *rate_config |= RRSR_24M; | |
643 | break; | |
644 | case MGN_36M: | |
645 | *rate_config |= RRSR_36M; | |
646 | break; | |
647 | case MGN_48M: | |
648 | *rate_config |= RRSR_48M; | |
649 | break; | |
650 | case MGN_54M: | |
651 | *rate_config |= RRSR_54M; | |
652 | break; | |
653 | } | |
654 | } | |
655 | } | |
656 | ||
422c8bef | 657 | static void _rtl92e_refresh_support_rate(struct r8192_priv *priv) |
1344ee25 LF |
658 | { |
659 | struct rtllib_device *ieee = priv->rtllib; | |
3a6b70c3 | 660 | |
1344ee25 LF |
661 | if (ieee->mode == WIRELESS_MODE_N_24G || |
662 | ieee->mode == WIRELESS_MODE_N_5G) { | |
663 | memcpy(ieee->Regdot11HTOperationalRateSet, | |
664 | ieee->RegHTSuppRateSet, 16); | |
665 | memcpy(ieee->Regdot11TxHTOperationalRateSet, | |
666 | ieee->RegHTSuppRateSet, 16); | |
94a79942 | 667 | |
94a79942 LF |
668 | } else { |
669 | memset(ieee->Regdot11HTOperationalRateSet, 0, 16); | |
670 | } | |
94a79942 LF |
671 | } |
672 | ||
ee394a7f | 673 | static u8 _rtl92e_get_supported_wireless_mode(struct net_device *dev) |
94a79942 LF |
674 | { |
675 | struct r8192_priv *priv = rtllib_priv(dev); | |
676 | u8 ret = 0; | |
677 | ||
678 | switch (priv->rf_chip) { | |
679 | case RF_8225: | |
680 | case RF_8256: | |
681 | case RF_6052: | |
682 | case RF_PSEUDO_11N: | |
683 | ret = (WIRELESS_MODE_N_24G|WIRELESS_MODE_G | WIRELESS_MODE_B); | |
684 | break; | |
685 | case RF_8258: | |
686 | ret = (WIRELESS_MODE_A | WIRELESS_MODE_N_5G); | |
687 | break; | |
688 | default: | |
689 | ret = WIRELESS_MODE_B; | |
690 | break; | |
691 | } | |
692 | return ret; | |
693 | } | |
694 | ||
35bf848f | 695 | void rtl92e_set_wireless_mode(struct net_device *dev, u8 wireless_mode) |
94a79942 LF |
696 | { |
697 | struct r8192_priv *priv = rtllib_priv(dev); | |
ee394a7f | 698 | u8 bSupportMode = _rtl92e_get_supported_wireless_mode(dev); |
94a79942 | 699 | |
1344ee25 LF |
700 | if ((wireless_mode == WIRELESS_MODE_AUTO) || |
701 | ((wireless_mode & bSupportMode) == 0)) { | |
94a79942 LF |
702 | if (bSupportMode & WIRELESS_MODE_N_24G) { |
703 | wireless_mode = WIRELESS_MODE_N_24G; | |
704 | } else if (bSupportMode & WIRELESS_MODE_N_5G) { | |
705 | wireless_mode = WIRELESS_MODE_N_5G; | |
706 | } else if ((bSupportMode & WIRELESS_MODE_A)) { | |
707 | wireless_mode = WIRELESS_MODE_A; | |
708 | } else if ((bSupportMode & WIRELESS_MODE_G)) { | |
709 | wireless_mode = WIRELESS_MODE_G; | |
710 | } else if ((bSupportMode & WIRELESS_MODE_B)) { | |
711 | wireless_mode = WIRELESS_MODE_B; | |
712 | } else { | |
3b4140af MK |
713 | netdev_info(dev, |
714 | "%s(): Unsupported mode requested. Fallback to 802.11b\n", | |
715 | __func__); | |
94a79942 LF |
716 | wireless_mode = WIRELESS_MODE_B; |
717 | } | |
718 | } | |
719 | ||
1344ee25 LF |
720 | if ((wireless_mode & (WIRELESS_MODE_B | WIRELESS_MODE_G)) == |
721 | (WIRELESS_MODE_G | WIRELESS_MODE_B)) | |
94a79942 LF |
722 | wireless_mode = WIRELESS_MODE_G; |
723 | ||
724 | priv->rtllib->mode = wireless_mode; | |
725 | ||
1344ee25 LF |
726 | if ((wireless_mode == WIRELESS_MODE_N_24G) || |
727 | (wireless_mode == WIRELESS_MODE_N_5G)) { | |
94a79942 | 728 | priv->rtllib->pHTInfo->bEnableHT = 1; |
1344ee25 LF |
729 | RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 1\n", |
730 | __func__, wireless_mode); | |
731 | } else { | |
94a79942 | 732 | priv->rtllib->pHTInfo->bEnableHT = 0; |
1344ee25 LF |
733 | RT_TRACE(COMP_DBG, "%s(), wireless_mode:%x, bEnableHT = 0\n", |
734 | __func__, wireless_mode); | |
735 | } | |
94a79942 LF |
736 | |
737 | RT_TRACE(COMP_INIT, "Current Wireless Mode is %x\n", wireless_mode); | |
422c8bef | 738 | _rtl92e_refresh_support_rate(priv); |
94a79942 LF |
739 | } |
740 | ||
dba0e06f | 741 | static int _rtl92e_sta_up(struct net_device *dev, bool is_silent_reset) |
94a79942 LF |
742 | { |
743 | struct r8192_priv *priv = rtllib_priv(dev); | |
1344ee25 LF |
744 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) |
745 | (&(priv->rtllib->PowerSaveControl)); | |
94a79942 | 746 | bool init_status = true; |
3a6b70c3 | 747 | |
94a79942 LF |
748 | priv->bDriverIsGoingToUnload = false; |
749 | priv->bdisable_nic = false; | |
750 | ||
1344ee25 LF |
751 | priv->up = 1; |
752 | priv->rtllib->ieee_up = 1; | |
94a79942 LF |
753 | |
754 | priv->up_first_time = 0; | |
755 | RT_TRACE(COMP_INIT, "Bringing up iface"); | |
756 | priv->bfirst_init = true; | |
757 | init_status = priv->ops->initialize_adapter(dev); | |
4bb01423 | 758 | if (!init_status) { |
3b4140af | 759 | netdev_err(dev, "%s(): Initialization failed!\n", __func__); |
94a79942 LF |
760 | priv->bfirst_init = false; |
761 | return -1; | |
762 | } | |
763 | ||
764 | RT_TRACE(COMP_INIT, "start adapter finished\n"); | |
765 | RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); | |
766 | priv->bfirst_init = false; | |
94a79942 | 767 | |
1344ee25 | 768 | if (priv->polling_timer_on == 0) |
a643d927 | 769 | rtl92e_check_rfctrl_gpio_timer((unsigned long)dev); |
94a79942 LF |
770 | |
771 | if (priv->rtllib->state != RTLLIB_LINKED) | |
1344ee25 | 772 | rtllib_softmac_start_protocol(priv->rtllib, 0); |
94a79942 | 773 | rtllib_reset_queue(priv->rtllib); |
2cfc3758 | 774 | _rtl92e_watchdog_timer_cb((unsigned long)dev); |
94a79942 | 775 | |
94a79942 LF |
776 | if (!netif_queue_stopped(dev)) |
777 | netif_start_queue(dev); | |
778 | else | |
779 | netif_wake_queue(dev); | |
780 | ||
781 | return 0; | |
782 | } | |
783 | ||
2b19e222 | 784 | static int _rtl92e_sta_down(struct net_device *dev, bool shutdownrf) |
94a79942 LF |
785 | { |
786 | struct r8192_priv *priv = rtllib_priv(dev); | |
787 | unsigned long flags = 0; | |
788 | u8 RFInProgressTimeOut = 0; | |
789 | ||
1344ee25 LF |
790 | if (priv->up == 0) |
791 | return -1; | |
94a79942 LF |
792 | |
793 | if (priv->rtllib->rtllib_ips_leave != NULL) | |
794 | priv->rtllib->rtllib_ips_leave(dev); | |
795 | ||
796 | if (priv->rtllib->state == RTLLIB_LINKED) | |
9c4a55d1 | 797 | rtl92e_leisure_ps_leave(dev); |
94a79942 LF |
798 | |
799 | priv->bDriverIsGoingToUnload = true; | |
1344ee25 | 800 | priv->up = 0; |
94a79942 | 801 | priv->rtllib->ieee_up = 0; |
014e4c27 | 802 | priv->bfirst_after_down = true; |
94a79942 LF |
803 | RT_TRACE(COMP_DOWN, "==========>%s()\n", __func__); |
804 | if (!netif_queue_stopped(dev)) | |
805 | netif_stop_queue(dev); | |
806 | ||
807 | priv->rtllib->wpa_ie_len = 0; | |
1344ee25 | 808 | kfree(priv->rtllib->wpa_ie); |
94a79942 | 809 | priv->rtllib->wpa_ie = NULL; |
358e4ee1 | 810 | rtl92e_cam_reset(dev); |
1344ee25 | 811 | memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32); |
b7b50d65 | 812 | rtl92e_irq_disable(dev); |
94a79942 LF |
813 | |
814 | del_timer_sync(&priv->watch_dog_timer); | |
4dba03a2 | 815 | _rtl92e_cancel_deferred_work(priv); |
94a79942 | 816 | cancel_delayed_work(&priv->rtllib->hw_wakeup_wq); |
94a79942 LF |
817 | |
818 | rtllib_softmac_stop_protocol(priv->rtllib, 0, true); | |
1344ee25 LF |
819 | spin_lock_irqsave(&priv->rf_ps_lock, flags); |
820 | while (priv->RFChangeInProgress) { | |
821 | spin_unlock_irqrestore(&priv->rf_ps_lock, flags); | |
822 | if (RFInProgressTimeOut > 100) { | |
823 | spin_lock_irqsave(&priv->rf_ps_lock, flags); | |
94a79942 LF |
824 | break; |
825 | } | |
0822339b MK |
826 | RT_TRACE(COMP_DBG, |
827 | "===>%s():RF is in progress, need to wait until rf change is done.\n", | |
828 | __func__); | |
94a79942 | 829 | mdelay(1); |
1344ee25 LF |
830 | RFInProgressTimeOut++; |
831 | spin_lock_irqsave(&priv->rf_ps_lock, flags); | |
94a79942 LF |
832 | } |
833 | priv->RFChangeInProgress = true; | |
1344ee25 | 834 | spin_unlock_irqrestore(&priv->rf_ps_lock, flags); |
94a79942 | 835 | priv->ops->stop_adapter(dev, false); |
1344ee25 | 836 | spin_lock_irqsave(&priv->rf_ps_lock, flags); |
94a79942 | 837 | priv->RFChangeInProgress = false; |
1344ee25 | 838 | spin_unlock_irqrestore(&priv->rf_ps_lock, flags); |
94a79942 | 839 | udelay(100); |
1344ee25 LF |
840 | memset(&priv->rtllib->current_network, 0, |
841 | offsetof(struct rtllib_network, list)); | |
94a79942 LF |
842 | RT_TRACE(COMP_DOWN, "<==========%s()\n", __func__); |
843 | ||
844 | return 0; | |
845 | } | |
846 | ||
b8d0dc3c | 847 | static void _rtl92e_init_priv_handler(struct net_device *dev) |
94a79942 LF |
848 | { |
849 | struct r8192_priv *priv = rtllib_priv(dev); | |
850 | ||
3e49f3ec | 851 | priv->rtllib->softmac_hard_start_xmit = _rtl92e_hard_start_xmit; |
5da06ad8 | 852 | priv->rtllib->set_chan = _rtl92e_set_chan; |
1344ee25 | 853 | priv->rtllib->link_change = priv->ops->link_change; |
52a74045 | 854 | priv->rtllib->softmac_data_hard_start_xmit = _rtl92e_hard_data_xmit; |
288adaf5 | 855 | priv->rtllib->check_nic_enough_desc = _rtl92e_check_nic_enough_desc; |
8b5a8031 | 856 | priv->rtllib->handle_assoc_response = _rtl92e_handle_assoc_response; |
5341f070 | 857 | priv->rtllib->handle_beacon = _rtl92e_handle_beacon; |
35bf848f | 858 | priv->rtllib->SetWirelessMode = rtl92e_set_wireless_mode; |
9c4a55d1 | 859 | priv->rtllib->LeisurePSLeave = rtl92e_leisure_ps_leave; |
ae924acd | 860 | priv->rtllib->SetBWModeHandler = rtl92e_set_bw_mode; |
68a5143c | 861 | priv->rf_set_chan = rtl92e_set_channel; |
94a79942 | 862 | |
89d4a8be | 863 | priv->rtllib->start_send_beacons = rtl92e_start_beacon; |
f2f08fc5 | 864 | priv->rtllib->stop_send_beacons = _rtl92e_stop_beacon; |
94a79942 | 865 | |
43bcb3b4 | 866 | priv->rtllib->sta_wake_up = rtl92e_hw_wakeup; |
feb257e5 | 867 | priv->rtllib->enter_sleep_state = rtl92e_enter_sleep; |
6f8d4a7d | 868 | priv->rtllib->ps_is_queue_empty = _rtl92e_is_tx_queue_empty; |
94a79942 | 869 | |
56a5b5af | 870 | priv->rtllib->GetNmodeSupportBySecCfg = rtl92e_get_nmode_support_by_sec; |
1344ee25 | 871 | priv->rtllib->GetHalfNmodeSupportByAPsHandler = |
86534a29 | 872 | rtl92e_is_halfn_supported_by_ap; |
94a79942 | 873 | |
61fea239 | 874 | priv->rtllib->SetHwRegHandler = rtl92e_set_reg; |
33e1748d | 875 | priv->rtllib->AllowAllDestAddrHandler = rtl92e_set_monitor_mode; |
94a79942 | 876 | priv->rtllib->SetFwCmdHandler = NULL; |
dfb7a127 | 877 | priv->rtllib->InitialGainHandler = rtl92e_init_gain; |
d66e938e | 878 | priv->rtllib->rtllib_ips_leave_wq = rtl92e_rtllib_ips_leave_wq; |
bf135a16 | 879 | priv->rtllib->rtllib_ips_leave = rtl92e_rtllib_ips_leave; |
94a79942 LF |
880 | |
881 | priv->rtllib->LedControlHandler = NULL; | |
882 | priv->rtllib->UpdateBeaconInterruptHandler = NULL; | |
883 | ||
9a44c6e6 | 884 | priv->rtllib->ScanOperationBackupHandler = rtl92e_scan_op_backup; |
94a79942 LF |
885 | } |
886 | ||
6b2aaeae | 887 | static void _rtl92e_init_priv_constant(struct net_device *dev) |
94a79942 | 888 | { |
94a79942 | 889 | struct r8192_priv *priv = rtllib_priv(dev); |
1344ee25 LF |
890 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) |
891 | &(priv->rtllib->PowerSaveControl); | |
94a79942 | 892 | |
94a79942 | 893 | pPSC->RegMaxLPSAwakeIntvl = 5; |
94a79942 LF |
894 | } |
895 | ||
896 | ||
414f401f | 897 | static void _rtl92e_init_priv_variable(struct net_device *dev) |
94a79942 LF |
898 | { |
899 | struct r8192_priv *priv = rtllib_priv(dev); | |
900 | u8 i; | |
901 | ||
902 | priv->AcmMethod = eAcmWay2_SW; | |
903 | priv->dot11CurrentPreambleMode = PREAMBLE_AUTO; | |
94a79942 | 904 | priv->rtllib->status = 0; |
94a79942 LF |
905 | priv->polling_timer_on = 0; |
906 | priv->up_first_time = 1; | |
907 | priv->blinked_ingpio = false; | |
908 | priv->bDriverIsGoingToUnload = false; | |
909 | priv->being_init_adapter = false; | |
910 | priv->initialized_at_probe = false; | |
94a79942 LF |
911 | priv->bdisable_nic = false; |
912 | priv->bfirst_init = false; | |
913 | priv->txringcount = 64; | |
914 | priv->rxbuffersize = 9100; | |
915 | priv->rxringcount = MAX_RX_COUNT; | |
1344ee25 | 916 | priv->irq_enabled = 0; |
94a79942 | 917 | priv->chan = 1; |
94a79942 | 918 | priv->RegChannelPlan = 0xf; |
94a79942 LF |
919 | priv->rtllib->mode = WIRELESS_MODE_AUTO; |
920 | priv->rtllib->iw_mode = IW_MODE_INFRA; | |
921 | priv->rtllib->bNetPromiscuousMode = false; | |
922 | priv->rtllib->IntelPromiscuousModeInfo.bPromiscuousOn = false; | |
1344ee25 LF |
923 | priv->rtllib->IntelPromiscuousModeInfo.bFilterSourceStationFrame = |
924 | false; | |
925 | priv->rtllib->ieee_up = 0; | |
94a79942 LF |
926 | priv->retry_rts = DEFAULT_RETRY_RTS; |
927 | priv->retry_data = DEFAULT_RETRY_DATA; | |
928 | priv->rtllib->rts = DEFAULT_RTS_THRESHOLD; | |
929 | priv->rtllib->rate = 110; | |
930 | priv->rtllib->short_slot = 1; | |
1344ee25 | 931 | priv->promisc = (dev->flags & IFF_PROMISC) ? 1 : 0; |
94a79942 LF |
932 | priv->bcck_in_ch14 = false; |
933 | priv->bfsync_processing = false; | |
934 | priv->CCKPresentAttentuation = 0; | |
935 | priv->rfa_txpowertrackingindex = 0; | |
936 | priv->rfc_txpowertrackingindex = 0; | |
937 | priv->CckPwEnl = 6; | |
938 | priv->ScanDelay = 50; | |
939 | priv->ResetProgress = RESET_TYPE_NORESET; | |
014e4c27 | 940 | priv->bForcedSilentReset = false; |
94a79942 LF |
941 | priv->bDisableNormalResetCheck = false; |
942 | priv->force_reset = false; | |
1344ee25 | 943 | memset(priv->rtllib->swcamtable, 0, sizeof(struct sw_cam_table) * 32); |
94a79942 | 944 | |
1344ee25 | 945 | memset(&priv->InterruptLog, 0, sizeof(struct log_int_8190)); |
94a79942 | 946 | priv->RxCounter = 0; |
1344ee25 | 947 | priv->rtllib->wx_set_enc = 0; |
94a79942 | 948 | priv->bHwRadioOff = false; |
014e4c27 | 949 | priv->RegRfOff = false; |
94a79942 LF |
950 | priv->isRFOff = false; |
951 | priv->bInPowerSaveMode = false; | |
952 | priv->rtllib->RfOffReason = 0; | |
953 | priv->RFChangeInProgress = false; | |
954 | priv->bHwRfOffAction = 0; | |
955 | priv->SetRFPowerStateInProgress = false; | |
956 | priv->rtllib->PowerSaveControl.bInactivePs = true; | |
957 | priv->rtllib->PowerSaveControl.bIPSModeBackup = false; | |
958 | priv->rtllib->PowerSaveControl.bLeisurePs = true; | |
959 | priv->rtllib->PowerSaveControl.bFwCtrlLPS = false; | |
960 | priv->rtllib->LPSDelayCnt = 0; | |
961 | priv->rtllib->sta_sleep = LPS_IS_WAKE; | |
962 | priv->rtllib->eRFPowerState = eRfOn; | |
963 | ||
94a79942 LF |
964 | priv->rtllib->current_network.beacon_interval = DEFAULT_BEACONINTERVAL; |
965 | priv->rtllib->iw_mode = IW_MODE_INFRA; | |
966 | priv->rtllib->active_scan = 1; | |
967 | priv->rtllib->be_scan_inprogress = false; | |
1344ee25 LF |
968 | priv->rtllib->modulation = RTLLIB_CCK_MODULATION | |
969 | RTLLIB_OFDM_MODULATION; | |
94a79942 LF |
970 | priv->rtllib->host_encrypt = 1; |
971 | priv->rtllib->host_decrypt = 1; | |
972 | ||
94a79942 | 973 | priv->rtllib->fts = DEFAULT_FRAG_THRESHOLD; |
94a79942 LF |
974 | |
975 | priv->card_type = PCI; | |
976 | ||
49aab5fd LF |
977 | priv->pFirmware = vzalloc(sizeof(struct rt_firmware)); |
978 | if (!priv->pFirmware) | |
d69d2054 MK |
979 | netdev_err(dev, |
980 | "rtl8192e: Unable to allocate space for firmware\n"); | |
94a79942 | 981 | |
94a79942 LF |
982 | skb_queue_head_init(&priv->skb_queue); |
983 | ||
1344ee25 LF |
984 | for (i = 0; i < MAX_QUEUE_SIZE; i++) |
985 | skb_queue_head_init(&priv->rtllib->skb_waitQ[i]); | |
986 | for (i = 0; i < MAX_QUEUE_SIZE; i++) | |
987 | skb_queue_head_init(&priv->rtllib->skb_aggQ[i]); | |
94a79942 LF |
988 | } |
989 | ||
529c66c1 | 990 | static void _rtl92e_init_priv_lock(struct r8192_priv *priv) |
94a79942 | 991 | { |
94a79942 | 992 | spin_lock_init(&priv->tx_lock); |
94a79942 LF |
993 | spin_lock_init(&priv->irq_th_lock); |
994 | spin_lock_init(&priv->rf_ps_lock); | |
995 | spin_lock_init(&priv->ps_lock); | |
3044975f | 996 | mutex_init(&priv->wx_mutex); |
5333496c | 997 | mutex_init(&priv->rf_mutex); |
94a79942 | 998 | mutex_init(&priv->mutex); |
94a79942 LF |
999 | } |
1000 | ||
4ab2a8fe | 1001 | static void _rtl92e_init_priv_task(struct net_device *dev) |
94a79942 LF |
1002 | { |
1003 | struct r8192_priv *priv = rtllib_priv(dev); | |
1004 | ||
78e67df3 | 1005 | INIT_WORK_RSL(&priv->reset_wq, (void *)_rtl92e_restart, dev); |
a514c798 MK |
1006 | INIT_WORK_RSL(&priv->rtllib->ips_leave_wq, (void *)rtl92e_ips_leave_wq, |
1007 | dev); | |
1344ee25 | 1008 | INIT_DELAYED_WORK_RSL(&priv->watch_dog_wq, |
7e2d598a | 1009 | (void *)_rtl92e_watchdog_wq_cb, dev); |
1344ee25 | 1010 | INIT_DELAYED_WORK_RSL(&priv->txpower_tracking_wq, |
33059f54 | 1011 | (void *)rtl92e_dm_txpower_tracking_wq, dev); |
1344ee25 | 1012 | INIT_DELAYED_WORK_RSL(&priv->rfpath_check_wq, |
3cd4db70 | 1013 | (void *)rtl92e_dm_rf_pathcheck_wq, dev); |
1344ee25 | 1014 | INIT_DELAYED_WORK_RSL(&priv->update_beacon_wq, |
dc888405 | 1015 | (void *)_rtl92e_update_beacon, dev); |
ae1fe0db | 1016 | INIT_WORK_RSL(&priv->qos_activate, (void *)_rtl92e_qos_activate, dev); |
1344ee25 | 1017 | INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_wakeup_wq, |
c34b29f7 | 1018 | (void *) rtl92e_hw_wakeup_wq, dev); |
1344ee25 | 1019 | INIT_DELAYED_WORK_RSL(&priv->rtllib->hw_sleep_wq, |
bcdcc1ea | 1020 | (void *) rtl92e_hw_sleep_wq, dev); |
94a79942 | 1021 | tasklet_init(&priv->irq_rx_tasklet, |
2940405b | 1022 | (void(*)(unsigned long))_rtl92e_irq_rx_tasklet, |
1344ee25 | 1023 | (unsigned long)priv); |
94a79942 | 1024 | tasklet_init(&priv->irq_tx_tasklet, |
a2743b2c | 1025 | (void(*)(unsigned long))_rtl92e_irq_tx_tasklet, |
1344ee25 LF |
1026 | (unsigned long)priv); |
1027 | tasklet_init(&priv->irq_prepare_beacon_tasklet, | |
e009a849 | 1028 | (void(*)(unsigned long))_rtl92e_prepare_beacon, |
1344ee25 | 1029 | (unsigned long)priv); |
94a79942 LF |
1030 | } |
1031 | ||
66a5c29b | 1032 | static short _rtl92e_get_channel_map(struct net_device *dev) |
94a79942 LF |
1033 | { |
1034 | int i; | |
1035 | ||
94a79942 | 1036 | struct r8192_priv *priv = rtllib_priv(dev); |
3a6b70c3 | 1037 | |
94a79942 LF |
1038 | if ((priv->rf_chip != RF_8225) && (priv->rf_chip != RF_8256) |
1039 | && (priv->rf_chip != RF_6052)) { | |
3b4140af MK |
1040 | netdev_err(dev, "%s: unknown rf chip, can't set channel map\n", |
1041 | __func__); | |
94a79942 LF |
1042 | return -1; |
1043 | } | |
1044 | ||
8f019bfe | 1045 | if (priv->ChannelPlan >= COUNTRY_CODE_MAX) { |
d69d2054 MK |
1046 | netdev_info(dev, |
1047 | "rtl819x_init:Error channel plan! Set to default.\n"); | |
1344ee25 | 1048 | priv->ChannelPlan = COUNTRY_CODE_FCC; |
94a79942 | 1049 | } |
1344ee25 | 1050 | RT_TRACE(COMP_INIT, "Channel plan is %d\n", priv->ChannelPlan); |
976d5341 | 1051 | dot11d_init(priv->rtllib); |
94a79942 | 1052 | Dot11d_Channelmap(priv->ChannelPlan, priv->rtllib); |
1344ee25 | 1053 | for (i = 1; i <= 11; i++) |
94a79942 | 1054 | (priv->rtllib->active_channel_map)[i] = 1; |
94a79942 LF |
1055 | (priv->rtllib->active_channel_map)[12] = 2; |
1056 | (priv->rtllib->active_channel_map)[13] = 2; | |
1057 | ||
1058 | return 0; | |
1059 | } | |
1060 | ||
6bd5e8e0 | 1061 | static short _rtl92e_init(struct net_device *dev) |
94a79942 LF |
1062 | { |
1063 | struct r8192_priv *priv = rtllib_priv(dev); | |
1064 | ||
1344ee25 | 1065 | memset(&(priv->stats), 0, sizeof(struct rt_stats)); |
94a79942 | 1066 | |
b8d0dc3c | 1067 | _rtl92e_init_priv_handler(dev); |
6b2aaeae | 1068 | _rtl92e_init_priv_constant(dev); |
414f401f | 1069 | _rtl92e_init_priv_variable(dev); |
529c66c1 | 1070 | _rtl92e_init_priv_lock(priv); |
4ab2a8fe | 1071 | _rtl92e_init_priv_task(dev); |
94a79942 LF |
1072 | priv->ops->get_eeprom_size(dev); |
1073 | priv->ops->init_adapter_variable(dev); | |
66a5c29b | 1074 | _rtl92e_get_channel_map(dev); |
94a79942 | 1075 | |
ab743598 | 1076 | rtl92e_dm_init(dev); |
94a79942 | 1077 | |
94a79942 | 1078 | setup_timer(&priv->watch_dog_timer, |
2cfc3758 | 1079 | _rtl92e_watchdog_timer_cb, |
94a79942 LF |
1080 | (unsigned long) dev); |
1081 | ||
94a79942 | 1082 | setup_timer(&priv->gpio_polling_timer, |
a643d927 | 1083 | rtl92e_check_rfctrl_gpio_timer, |
94a79942 LF |
1084 | (unsigned long)dev); |
1085 | ||
b7b50d65 | 1086 | rtl92e_irq_disable(dev); |
87e01f22 | 1087 | if (request_irq(dev->irq, _rtl92e_irq, IRQF_SHARED, dev->name, dev)) { |
d69d2054 | 1088 | netdev_err(dev, "Error allocating IRQ %d", dev->irq); |
94a79942 | 1089 | return -1; |
94a79942 LF |
1090 | } |
1091 | ||
285b7c00 MK |
1092 | priv->irq = dev->irq; |
1093 | RT_TRACE(COMP_INIT, "IRQ %d\n", dev->irq); | |
1094 | ||
197917a8 | 1095 | if (_rtl92e_pci_initdescring(dev) != 0) { |
d69d2054 | 1096 | netdev_err(dev, "Endopoints initialization failed"); |
35f8673d | 1097 | free_irq(dev->irq, dev); |
94a79942 LF |
1098 | return -1; |
1099 | } | |
1100 | ||
1101 | return 0; | |
1102 | } | |
1103 | ||
94a79942 | 1104 | /*************************************************************************** |
1344ee25 | 1105 | -------------------------------WATCHDOG STUFF--------------------------- |
94a79942 | 1106 | ***************************************************************************/ |
6f8d4a7d | 1107 | static short _rtl92e_is_tx_queue_empty(struct net_device *dev) |
94a79942 | 1108 | { |
1344ee25 | 1109 | int i = 0; |
94a79942 | 1110 | struct r8192_priv *priv = rtllib_priv(dev); |
3a6b70c3 | 1111 | |
1344ee25 LF |
1112 | for (i = 0; i <= MGNT_QUEUE; i++) { |
1113 | if ((i == TXCMD_QUEUE) || (i == HCCA_QUEUE)) | |
94a79942 | 1114 | continue; |
1344ee25 | 1115 | if (skb_queue_len(&(&priv->tx_ring[i])->queue) > 0) { |
d69d2054 | 1116 | netdev_info(dev, "===>tx queue is not empty:%d, %d\n", |
1344ee25 | 1117 | i, skb_queue_len(&(&priv->tx_ring[i])->queue)); |
94a79942 LF |
1118 | return 0; |
1119 | } | |
1120 | } | |
1121 | return 1; | |
1122 | } | |
1123 | ||
c8d84191 | 1124 | static enum reset_type _rtl92e_tx_check_stuck(struct net_device *dev) |
94a79942 LF |
1125 | { |
1126 | struct r8192_priv *priv = rtllib_priv(dev); | |
1344ee25 | 1127 | u8 QueueID; |
1344ee25 | 1128 | bool bCheckFwTxCnt = false; |
94a79942 | 1129 | struct rtl8192_tx_ring *ring = NULL; |
1344ee25 LF |
1130 | struct sk_buff *skb = NULL; |
1131 | struct cb_desc *tcb_desc = NULL; | |
94a79942 LF |
1132 | unsigned long flags = 0; |
1133 | ||
1344ee25 LF |
1134 | switch (priv->rtllib->ps) { |
1135 | case RTLLIB_PS_DISABLED: | |
1344ee25 LF |
1136 | break; |
1137 | case (RTLLIB_PS_MBCAST|RTLLIB_PS_UNICAST): | |
1344ee25 LF |
1138 | break; |
1139 | default: | |
1344ee25 | 1140 | break; |
94a79942 | 1141 | } |
1344ee25 LF |
1142 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
1143 | for (QueueID = 0; QueueID < MAX_TX_QUEUE; QueueID++) { | |
94a79942 LF |
1144 | if (QueueID == TXCMD_QUEUE) |
1145 | continue; | |
1146 | ||
1147 | if (QueueID == BEACON_QUEUE) | |
1148 | continue; | |
1149 | ||
1150 | ring = &priv->tx_ring[QueueID]; | |
1151 | ||
1344ee25 | 1152 | if (skb_queue_len(&ring->queue) == 0) { |
94a79942 | 1153 | continue; |
1344ee25 | 1154 | } else { |
94a79942 | 1155 | skb = (&ring->queue)->next; |
1344ee25 LF |
1156 | tcb_desc = (struct cb_desc *)(skb->cb + |
1157 | MAX_DEV_ADDR_SIZE); | |
94a79942 LF |
1158 | tcb_desc->nStuckCount++; |
1159 | bCheckFwTxCnt = true; | |
1160 | if (tcb_desc->nStuckCount > 1) | |
d69d2054 MK |
1161 | netdev_info(dev, |
1162 | "%s: QueueID=%d tcb_desc->nStuckCount=%d\n", | |
1163 | __func__, QueueID, | |
1164 | tcb_desc->nStuckCount); | |
94a79942 LF |
1165 | } |
1166 | } | |
1344ee25 | 1167 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
1168 | |
1169 | if (bCheckFwTxCnt) { | |
1344ee25 | 1170 | if (priv->ops->TxCheckStuckHandler(dev)) { |
0822339b MK |
1171 | RT_TRACE(COMP_RESET, |
1172 | "TxCheckStuck(): Fw indicates no Tx condition!\n"); | |
94a79942 LF |
1173 | return RESET_TYPE_SILENT; |
1174 | } | |
1175 | } | |
1176 | ||
1177 | return RESET_TYPE_NORESET; | |
1178 | } | |
1179 | ||
ea2d7059 | 1180 | static enum reset_type _rtl92e_rx_check_stuck(struct net_device *dev) |
94a79942 LF |
1181 | { |
1182 | struct r8192_priv *priv = rtllib_priv(dev); | |
1183 | ||
1344ee25 | 1184 | if (priv->ops->RxCheckStuckHandler(dev)) { |
94a79942 LF |
1185 | RT_TRACE(COMP_RESET, "RxStuck Condition\n"); |
1186 | return RESET_TYPE_SILENT; | |
1187 | } | |
1188 | ||
1189 | return RESET_TYPE_NORESET; | |
1190 | } | |
1191 | ||
79fbe932 | 1192 | static enum reset_type _rtl92e_if_check_reset(struct net_device *dev) |
94a79942 LF |
1193 | { |
1194 | struct r8192_priv *priv = rtllib_priv(dev); | |
ab0d7cca LF |
1195 | enum reset_type TxResetType = RESET_TYPE_NORESET; |
1196 | enum reset_type RxResetType = RESET_TYPE_NORESET; | |
de7c885a | 1197 | enum rt_rf_power_state rfState; |
94a79942 LF |
1198 | |
1199 | rfState = priv->rtllib->eRFPowerState; | |
1200 | ||
1201 | if (rfState == eRfOn) | |
c8d84191 | 1202 | TxResetType = _rtl92e_tx_check_stuck(dev); |
94a79942 | 1203 | |
1344ee25 | 1204 | if (rfState == eRfOn && |
94a79942 | 1205 | (priv->rtllib->iw_mode == IW_MODE_INFRA) && |
1344ee25 | 1206 | (priv->rtllib->state == RTLLIB_LINKED)) |
ea2d7059 | 1207 | RxResetType = _rtl92e_rx_check_stuck(dev); |
94a79942 | 1208 | |
1344ee25 LF |
1209 | if (TxResetType == RESET_TYPE_NORMAL || |
1210 | RxResetType == RESET_TYPE_NORMAL) { | |
d69d2054 MK |
1211 | netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n", |
1212 | __func__, TxResetType, RxResetType); | |
94a79942 | 1213 | return RESET_TYPE_NORMAL; |
1344ee25 LF |
1214 | } else if (TxResetType == RESET_TYPE_SILENT || |
1215 | RxResetType == RESET_TYPE_SILENT) { | |
d69d2054 MK |
1216 | netdev_info(dev, "%s(): TxResetType is %d, RxResetType is %d\n", |
1217 | __func__, TxResetType, RxResetType); | |
94a79942 LF |
1218 | return RESET_TYPE_SILENT; |
1219 | } else { | |
1220 | return RESET_TYPE_NORESET; | |
1221 | } | |
1222 | ||
1223 | } | |
1224 | ||
5e177a9f | 1225 | static void _rtl92e_if_silent_reset(struct net_device *dev) |
94a79942 LF |
1226 | { |
1227 | struct r8192_priv *priv = rtllib_priv(dev); | |
1228 | u8 reset_times = 0; | |
1229 | int reset_status = 0; | |
1230 | struct rtllib_device *ieee = priv->rtllib; | |
1231 | unsigned long flag; | |
1232 | ||
1344ee25 | 1233 | if (priv->ResetProgress == RESET_TYPE_NORESET) { |
94a79942 | 1234 | |
1344ee25 | 1235 | RT_TRACE(COMP_RESET, "=========>Reset progress!!\n"); |
94a79942 LF |
1236 | |
1237 | priv->ResetProgress = RESET_TYPE_SILENT; | |
1238 | ||
1344ee25 LF |
1239 | spin_lock_irqsave(&priv->rf_ps_lock, flag); |
1240 | if (priv->RFChangeInProgress) { | |
1241 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); | |
94a79942 LF |
1242 | goto END; |
1243 | } | |
1244 | priv->RFChangeInProgress = true; | |
1245 | priv->bResetInProgress = true; | |
1344ee25 | 1246 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); |
94a79942 LF |
1247 | |
1248 | RESET_START: | |
1249 | ||
3044975f | 1250 | mutex_lock(&priv->wx_mutex); |
94a79942 LF |
1251 | |
1252 | if (priv->rtllib->state == RTLLIB_LINKED) | |
9c4a55d1 | 1253 | rtl92e_leisure_ps_leave(dev); |
94a79942 | 1254 | |
5dc42962 | 1255 | if (priv->up) { |
3b4140af MK |
1256 | netdev_info(dev, "%s():the driver is not up.\n", |
1257 | __func__); | |
3044975f | 1258 | mutex_unlock(&priv->wx_mutex); |
fe40a0b3 | 1259 | return; |
94a79942 LF |
1260 | } |
1261 | priv->up = 0; | |
1262 | ||
1344ee25 LF |
1263 | RT_TRACE(COMP_RESET, "%s():======>start to down the driver\n", |
1264 | __func__); | |
94a79942 | 1265 | mdelay(1000); |
0822339b MK |
1266 | RT_TRACE(COMP_RESET, |
1267 | "%s():111111111111111111111111======>start to down the driver\n", | |
1268 | __func__); | |
94a79942 LF |
1269 | |
1270 | if (!netif_queue_stopped(dev)) | |
1271 | netif_stop_queue(dev); | |
1272 | ||
b7b50d65 | 1273 | rtl92e_irq_disable(dev); |
94a79942 | 1274 | del_timer_sync(&priv->watch_dog_timer); |
4dba03a2 | 1275 | _rtl92e_cancel_deferred_work(priv); |
fd9e3171 | 1276 | rtl92e_dm_deinit(dev); |
94a79942 LF |
1277 | rtllib_stop_scan_syncro(ieee); |
1278 | ||
1279 | if (ieee->state == RTLLIB_LINKED) { | |
9afa9370 | 1280 | mutex_lock(&ieee->wx_mutex); |
d69d2054 | 1281 | netdev_info(dev, "ieee->state is RTLLIB_LINKED\n"); |
94a79942 LF |
1282 | rtllib_stop_send_beacons(priv->rtllib); |
1283 | del_timer_sync(&ieee->associate_timer); | |
1284 | cancel_delayed_work(&ieee->associate_retry_wq); | |
1285 | rtllib_stop_scan(ieee); | |
1286 | netif_carrier_off(dev); | |
9afa9370 | 1287 | mutex_unlock(&ieee->wx_mutex); |
94a79942 | 1288 | } else { |
d69d2054 | 1289 | netdev_info(dev, "ieee->state is NOT LINKED\n"); |
f6692285 | 1290 | rtllib_softmac_stop_protocol(priv->rtllib, 0, true); |
94a79942 LF |
1291 | } |
1292 | ||
090e8a4d | 1293 | rtl92e_dm_backup_state(dev); |
94a79942 | 1294 | |
3044975f | 1295 | mutex_unlock(&priv->wx_mutex); |
0822339b MK |
1296 | RT_TRACE(COMP_RESET, |
1297 | "%s():<==========down process is finished\n", | |
1298 | __func__); | |
94a79942 | 1299 | |
1344ee25 LF |
1300 | RT_TRACE(COMP_RESET, "%s():<===========up process start\n", |
1301 | __func__); | |
81524bbc | 1302 | reset_status = _rtl92e_up(dev, true); |
94a79942 | 1303 | |
0822339b MK |
1304 | RT_TRACE(COMP_RESET, |
1305 | "%s():<===========up process is finished\n", __func__); | |
94a79942 LF |
1306 | if (reset_status == -1) { |
1307 | if (reset_times < 3) { | |
1308 | reset_times++; | |
1309 | goto RESET_START; | |
1310 | } else { | |
3b4140af MK |
1311 | netdev_warn(dev, "%s(): Reset Failed\n", |
1312 | __func__); | |
94a79942 LF |
1313 | } |
1314 | } | |
1315 | ||
1316 | ieee->is_silent_reset = 1; | |
1317 | ||
1344ee25 | 1318 | spin_lock_irqsave(&priv->rf_ps_lock, flag); |
94a79942 | 1319 | priv->RFChangeInProgress = false; |
1344ee25 | 1320 | spin_unlock_irqrestore(&priv->rf_ps_lock, flag); |
94a79942 | 1321 | |
37420932 | 1322 | rtl92e_enable_hw_security_config(dev); |
94a79942 | 1323 | |
1344ee25 LF |
1324 | if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == |
1325 | IW_MODE_INFRA) { | |
1326 | ieee->set_chan(ieee->dev, | |
1327 | ieee->current_network.channel); | |
94a79942 | 1328 | |
354605f4 | 1329 | schedule_work(&ieee->associate_complete_wq); |
94a79942 | 1330 | |
1344ee25 LF |
1331 | } else if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == |
1332 | IW_MODE_ADHOC) { | |
1333 | ieee->set_chan(ieee->dev, | |
1334 | ieee->current_network.channel); | |
94a79942 LF |
1335 | ieee->link_change(ieee->dev); |
1336 | ||
1337 | notify_wx_assoc_event(ieee); | |
1338 | ||
1339 | rtllib_start_send_beacons(ieee); | |
1340 | ||
94a79942 | 1341 | netif_carrier_on(ieee->dev); |
94a79942 LF |
1342 | } |
1343 | ||
66497f02 | 1344 | rtl92e_cam_restore(dev); |
25c01ec3 | 1345 | rtl92e_dm_restore_state(dev); |
94a79942 LF |
1346 | END: |
1347 | priv->ResetProgress = RESET_TYPE_NORESET; | |
1348 | priv->reset_count++; | |
1349 | ||
1344ee25 | 1350 | priv->bForcedSilentReset = false; |
94a79942 LF |
1351 | priv->bResetInProgress = false; |
1352 | ||
d8ae1967 | 1353 | rtl92e_writeb(dev, UFWP, 1); |
1344ee25 LF |
1354 | RT_TRACE(COMP_RESET, "Reset finished!! ====>[%d]\n", |
1355 | priv->reset_count); | |
94a79942 LF |
1356 | } |
1357 | } | |
1358 | ||
c3b48165 | 1359 | static void _rtl92e_update_rxcounts(struct r8192_priv *priv, u32 *TotalRxBcnNum, |
49aab5fd | 1360 | u32 *TotalRxDataNum) |
94a79942 | 1361 | { |
1344ee25 LF |
1362 | u16 SlotIndex; |
1363 | u8 i; | |
94a79942 LF |
1364 | |
1365 | *TotalRxBcnNum = 0; | |
1366 | *TotalRxDataNum = 0; | |
1367 | ||
1344ee25 LF |
1368 | SlotIndex = (priv->rtllib->LinkDetectInfo.SlotIndex++) % |
1369 | (priv->rtllib->LinkDetectInfo.SlotNum); | |
1370 | priv->rtllib->LinkDetectInfo.RxBcnNum[SlotIndex] = | |
1371 | priv->rtllib->LinkDetectInfo.NumRecvBcnInPeriod; | |
1372 | priv->rtllib->LinkDetectInfo.RxDataNum[SlotIndex] = | |
1373 | priv->rtllib->LinkDetectInfo.NumRecvDataInPeriod; | |
94a79942 LF |
1374 | for (i = 0; i < priv->rtllib->LinkDetectInfo.SlotNum; i++) { |
1375 | *TotalRxBcnNum += priv->rtllib->LinkDetectInfo.RxBcnNum[i]; | |
1376 | *TotalRxDataNum += priv->rtllib->LinkDetectInfo.RxDataNum[i]; | |
1377 | } | |
1378 | } | |
1379 | ||
7e2d598a | 1380 | static void _rtl92e_watchdog_wq_cb(void *data) |
94a79942 | 1381 | { |
1344ee25 LF |
1382 | struct r8192_priv *priv = container_of_dwork_rsl(data, |
1383 | struct r8192_priv, watch_dog_wq); | |
94a79942 | 1384 | struct net_device *dev = priv->rtllib->dev; |
1344ee25 | 1385 | struct rtllib_device *ieee = priv->rtllib; |
ab0d7cca | 1386 | enum reset_type ResetType = RESET_TYPE_NORESET; |
1344ee25 | 1387 | static u8 check_reset_cnt; |
94a79942 | 1388 | unsigned long flags; |
1344ee25 LF |
1389 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) |
1390 | (&(priv->rtllib->PowerSaveControl)); | |
94a79942 LF |
1391 | bool bBusyTraffic = false; |
1392 | bool bHigherBusyTraffic = false; | |
1393 | bool bHigherBusyRxTraffic = false; | |
1394 | bool bEnterPS = false; | |
1395 | ||
5dc42962 | 1396 | if (!priv->up || priv->bHwRadioOff) |
94a79942 LF |
1397 | return; |
1398 | ||
1399 | if (priv->rtllib->state >= RTLLIB_LINKED) { | |
1344ee25 | 1400 | if (priv->rtllib->CntAfterLink < 2) |
94a79942 LF |
1401 | priv->rtllib->CntAfterLink++; |
1402 | } else { | |
1403 | priv->rtllib->CntAfterLink = 0; | |
1404 | } | |
1405 | ||
8e1e64bb | 1406 | rtl92e_dm_watchdog(dev); |
94a79942 | 1407 | |
1344ee25 LF |
1408 | if (rtllib_act_scanning(priv->rtllib, false) == false) { |
1409 | if ((ieee->iw_mode == IW_MODE_INFRA) && (ieee->state == | |
1410 | RTLLIB_NOLINK) && | |
1411 | (ieee->eRFPowerState == eRfOn) && !ieee->is_set_key && | |
1412 | (!ieee->proto_stoppping) && !ieee->wx_set_enc) { | |
1413 | if ((ieee->PowerSaveControl.ReturnPoint == | |
1414 | IPS_CALLBACK_NONE) && | |
1415 | (!ieee->bNetPromiscuousMode)) { | |
0822339b | 1416 | RT_TRACE(COMP_PS, |
410d6fc9 MK |
1417 | "====================>haha: rtl92e_ips_enter()\n"); |
1418 | rtl92e_ips_enter(dev); | |
94a79942 LF |
1419 | } |
1420 | } | |
1421 | } | |
1344ee25 LF |
1422 | if ((ieee->state == RTLLIB_LINKED) && (ieee->iw_mode == |
1423 | IW_MODE_INFRA) && (!ieee->bNetPromiscuousMode)) { | |
1424 | if (ieee->LinkDetectInfo.NumRxOkInPeriod > 100 || | |
1425 | ieee->LinkDetectInfo.NumTxOkInPeriod > 100) | |
1426 | bBusyTraffic = true; | |
94a79942 LF |
1427 | |
1428 | ||
1344ee25 LF |
1429 | if (ieee->LinkDetectInfo.NumRxOkInPeriod > 4000 || |
1430 | ieee->LinkDetectInfo.NumTxOkInPeriod > 4000) { | |
1431 | bHigherBusyTraffic = true; | |
1432 | if (ieee->LinkDetectInfo.NumRxOkInPeriod > 5000) | |
1433 | bHigherBusyRxTraffic = true; | |
94a79942 | 1434 | else |
1344ee25 LF |
1435 | bHigherBusyRxTraffic = false; |
1436 | } | |
94a79942 | 1437 | |
1344ee25 LF |
1438 | if (((ieee->LinkDetectInfo.NumRxUnicastOkInPeriod + |
1439 | ieee->LinkDetectInfo.NumTxOkInPeriod) > 8) || | |
1440 | (ieee->LinkDetectInfo.NumRxUnicastOkInPeriod > 2)) | |
1441 | bEnterPS = false; | |
1442 | else | |
1443 | bEnterPS = true; | |
94a79942 | 1444 | |
1344ee25 LF |
1445 | if (ieee->current_network.beacon_interval < 95) |
1446 | bEnterPS = false; | |
94a79942 | 1447 | |
1344ee25 | 1448 | if (bEnterPS) |
04197ef2 | 1449 | rtl92e_leisure_ps_enter(dev); |
1344ee25 | 1450 | else |
9c4a55d1 | 1451 | rtl92e_leisure_ps_leave(dev); |
94a79942 | 1452 | |
1344ee25 LF |
1453 | } else { |
1454 | RT_TRACE(COMP_LPS, "====>no link LPS leave\n"); | |
9c4a55d1 | 1455 | rtl92e_leisure_ps_leave(dev); |
1344ee25 | 1456 | } |
94a79942 | 1457 | |
1344ee25 LF |
1458 | ieee->LinkDetectInfo.NumRxOkInPeriod = 0; |
1459 | ieee->LinkDetectInfo.NumTxOkInPeriod = 0; | |
1460 | ieee->LinkDetectInfo.NumRxUnicastOkInPeriod = 0; | |
1461 | ieee->LinkDetectInfo.bBusyTraffic = bBusyTraffic; | |
94a79942 | 1462 | |
1344ee25 LF |
1463 | ieee->LinkDetectInfo.bHigherBusyTraffic = bHigherBusyTraffic; |
1464 | ieee->LinkDetectInfo.bHigherBusyRxTraffic = bHigherBusyRxTraffic; | |
94a79942 | 1465 | |
1344ee25 LF |
1466 | if (ieee->state == RTLLIB_LINKED && ieee->iw_mode == IW_MODE_INFRA) { |
1467 | u32 TotalRxBcnNum = 0; | |
1468 | u32 TotalRxDataNum = 0; | |
94a79942 | 1469 | |
c3b48165 | 1470 | _rtl92e_update_rxcounts(priv, &TotalRxBcnNum, &TotalRxDataNum); |
94a79942 | 1471 | |
1344ee25 LF |
1472 | if ((TotalRxBcnNum+TotalRxDataNum) == 0) |
1473 | priv->check_roaming_cnt++; | |
1474 | else | |
1475 | priv->check_roaming_cnt = 0; | |
94a79942 LF |
1476 | |
1477 | ||
1344ee25 LF |
1478 | if (priv->check_roaming_cnt > 0) { |
1479 | if (ieee->eRFPowerState == eRfOff) | |
3b4140af | 1480 | netdev_info(dev, "%s(): RF is off\n", __func__); |
94a79942 | 1481 | |
d69d2054 MK |
1482 | netdev_info(dev, |
1483 | "===>%s(): AP is power off, chan:%d, connect another one\n", | |
1484 | __func__, priv->chan); | |
94a79942 | 1485 | |
1344ee25 | 1486 | ieee->state = RTLLIB_ASSOCIATING; |
94a79942 | 1487 | |
1344ee25 LF |
1488 | RemovePeerTS(priv->rtllib, |
1489 | priv->rtllib->current_network.bssid); | |
1490 | ieee->is_roaming = true; | |
1491 | ieee->is_set_key = false; | |
1492 | ieee->link_change(dev); | |
1493 | if (ieee->LedControlHandler) | |
1494 | ieee->LedControlHandler(ieee->dev, | |
1495 | LED_CTL_START_TO_LINK); | |
94a79942 | 1496 | |
1344ee25 | 1497 | notify_wx_assoc_event(ieee); |
94a79942 | 1498 | |
1344ee25 LF |
1499 | if (!(ieee->rtllib_ap_sec_type(ieee) & |
1500 | (SEC_ALG_CCMP|SEC_ALG_TKIP))) | |
354605f4 | 1501 | schedule_delayed_work( |
1344ee25 | 1502 | &ieee->associate_procedure_wq, 0); |
94a79942 | 1503 | |
1344ee25 | 1504 | priv->check_roaming_cnt = 0; |
94a79942 | 1505 | } |
1344ee25 LF |
1506 | ieee->LinkDetectInfo.NumRecvBcnInPeriod = 0; |
1507 | ieee->LinkDetectInfo.NumRecvDataInPeriod = 0; | |
94a79942 LF |
1508 | |
1509 | } | |
1510 | ||
1344ee25 | 1511 | spin_lock_irqsave(&priv->tx_lock, flags); |
94a79942 | 1512 | if ((check_reset_cnt++ >= 3) && (!ieee->is_roaming) && |
1344ee25 | 1513 | (!priv->RFChangeInProgress) && (!pPSC->bSwRfProcessing)) { |
79fbe932 | 1514 | ResetType = _rtl92e_if_check_reset(dev); |
94a79942 LF |
1515 | check_reset_cnt = 3; |
1516 | } | |
1344ee25 | 1517 | spin_unlock_irqrestore(&priv->tx_lock, flags); |
94a79942 | 1518 | |
1344ee25 | 1519 | if (!priv->bDisableNormalResetCheck && ResetType == RESET_TYPE_NORMAL) { |
94a79942 | 1520 | priv->ResetProgress = RESET_TYPE_NORMAL; |
1344ee25 | 1521 | RT_TRACE(COMP_RESET, "%s(): NOMAL RESET\n", __func__); |
94a79942 LF |
1522 | return; |
1523 | } | |
1524 | ||
1344ee25 LF |
1525 | if (((priv->force_reset) || (!priv->bDisableNormalResetCheck && |
1526 | ResetType == RESET_TYPE_SILENT))) | |
5e177a9f | 1527 | _rtl92e_if_silent_reset(dev); |
94a79942 LF |
1528 | priv->force_reset = false; |
1529 | priv->bForcedSilentReset = false; | |
1530 | priv->bResetInProgress = false; | |
1531 | RT_TRACE(COMP_TRACE, " <==RtUsbCheckForHangWorkItemCallback()\n"); | |
1532 | } | |
1533 | ||
2cfc3758 | 1534 | static void _rtl92e_watchdog_timer_cb(unsigned long data) |
94a79942 | 1535 | { |
1344ee25 | 1536 | struct r8192_priv *priv = rtllib_priv((struct net_device *)data); |
3a6b70c3 | 1537 | |
ecfdd3a0 | 1538 | schedule_delayed_work(&priv->watch_dog_wq, 0); |
1344ee25 | 1539 | mod_timer(&priv->watch_dog_timer, jiffies + |
8b9733c1 | 1540 | msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME)); |
94a79942 LF |
1541 | } |
1542 | ||
1543 | /**************************************************************************** | |
1544 | ---------------------------- NIC TX/RX STUFF--------------------------- | |
1545 | *****************************************************************************/ | |
630268b7 | 1546 | void rtl92e_rx_enable(struct net_device *dev) |
94a79942 | 1547 | { |
a4eed41f | 1548 | struct r8192_priv *priv = rtllib_priv(dev); |
3a6b70c3 | 1549 | |
94a79942 LF |
1550 | priv->ops->rx_enable(dev); |
1551 | } | |
1552 | ||
94199b35 | 1553 | void rtl92e_tx_enable(struct net_device *dev) |
94a79942 | 1554 | { |
a4eed41f | 1555 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
1556 | |
1557 | priv->ops->tx_enable(dev); | |
1558 | ||
1344ee25 | 1559 | rtllib_reset_queue(priv->rtllib); |
94a79942 LF |
1560 | } |
1561 | ||
1562 | ||
694f9d30 | 1563 | static void _rtl92e_free_rx_ring(struct net_device *dev) |
94a79942 | 1564 | { |
1344ee25 LF |
1565 | struct r8192_priv *priv = rtllib_priv(dev); |
1566 | int i, rx_queue_idx; | |
94a79942 | 1567 | |
1344ee25 LF |
1568 | for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; |
1569 | rx_queue_idx++) { | |
1570 | for (i = 0; i < priv->rxringcount; i++) { | |
94a79942 | 1571 | struct sk_buff *skb = priv->rx_buf[rx_queue_idx][i]; |
3a6b70c3 | 1572 | |
1344ee25 LF |
1573 | if (!skb) |
1574 | continue; | |
94a79942 | 1575 | |
1344ee25 LF |
1576 | pci_unmap_single(priv->pdev, |
1577 | *((dma_addr_t *)skb->cb), | |
1578 | priv->rxbuffersize, PCI_DMA_FROMDEVICE); | |
1579 | kfree_skb(skb); | |
1580 | } | |
94a79942 | 1581 | |
1344ee25 LF |
1582 | pci_free_consistent(priv->pdev, |
1583 | sizeof(*priv->rx_ring[rx_queue_idx]) * | |
1584 | priv->rxringcount, | |
1585 | priv->rx_ring[rx_queue_idx], | |
1586 | priv->rx_ring_dma[rx_queue_idx]); | |
94a79942 LF |
1587 | priv->rx_ring[rx_queue_idx] = NULL; |
1588 | } | |
1589 | } | |
1590 | ||
ebc36ecd | 1591 | static void _rtl92e_free_tx_ring(struct net_device *dev, unsigned int prio) |
94a79942 | 1592 | { |
1344ee25 LF |
1593 | struct r8192_priv *priv = rtllib_priv(dev); |
1594 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; | |
94a79942 | 1595 | |
1344ee25 LF |
1596 | while (skb_queue_len(&ring->queue)) { |
1597 | struct tx_desc *entry = &ring->desc[ring->idx]; | |
1598 | struct sk_buff *skb = __skb_dequeue(&ring->queue); | |
94a79942 | 1599 | |
466bc7f2 | 1600 | pci_unmap_single(priv->pdev, entry->TxBuffAddr, |
1344ee25 LF |
1601 | skb->len, PCI_DMA_TODEVICE); |
1602 | kfree_skb(skb); | |
1603 | ring->idx = (ring->idx + 1) % ring->entries; | |
1604 | } | |
94a79942 | 1605 | |
1344ee25 LF |
1606 | pci_free_consistent(priv->pdev, sizeof(*ring->desc)*ring->entries, |
1607 | ring->desc, ring->dma); | |
1608 | ring->desc = NULL; | |
94a79942 LF |
1609 | } |
1610 | ||
52a74045 MK |
1611 | static void _rtl92e_hard_data_xmit(struct sk_buff *skb, struct net_device *dev, |
1612 | int rate) | |
94a79942 | 1613 | { |
a4eed41f | 1614 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 1615 | int ret; |
1344ee25 LF |
1616 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + |
1617 | MAX_DEV_ADDR_SIZE); | |
94a79942 LF |
1618 | u8 queue_index = tcb_desc->queue_index; |
1619 | ||
5dc42962 | 1620 | if ((priv->rtllib->eRFPowerState == eRfOff) || !priv->up || |
1344ee25 | 1621 | priv->bResetInProgress) { |
94a79942 LF |
1622 | kfree_skb(skb); |
1623 | return; | |
1624 | } | |
1625 | ||
435009bb MK |
1626 | if (queue_index == TXCMD_QUEUE) |
1627 | netdev_warn(dev, "%s(): queue index == TXCMD_QUEUE\n", | |
ca93dcba | 1628 | __func__); |
94a79942 | 1629 | |
1344ee25 | 1630 | memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); |
94a79942 | 1631 | skb_push(skb, priv->rtllib->tx_headroom); |
374a3c5a | 1632 | ret = _rtl92e_tx(dev, skb); |
a22526e4 | 1633 | if (ret != 0) |
94a79942 | 1634 | kfree_skb(skb); |
94a79942 | 1635 | |
1344ee25 LF |
1636 | if (queue_index != MGNT_QUEUE) { |
1637 | priv->rtllib->stats.tx_bytes += (skb->len - | |
1638 | priv->rtllib->tx_headroom); | |
94a79942 LF |
1639 | priv->rtllib->stats.tx_packets++; |
1640 | } | |
94a79942 LF |
1641 | } |
1642 | ||
3e49f3ec | 1643 | static int _rtl92e_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
94a79942 | 1644 | { |
a4eed41f | 1645 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 1646 | int ret; |
1344ee25 LF |
1647 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + |
1648 | MAX_DEV_ADDR_SIZE); | |
94a79942 LF |
1649 | u8 queue_index = tcb_desc->queue_index; |
1650 | ||
1344ee25 LF |
1651 | if (queue_index != TXCMD_QUEUE) { |
1652 | if ((priv->rtllib->eRFPowerState == eRfOff) || | |
5dc42962 | 1653 | !priv->up || priv->bResetInProgress) { |
94a79942 LF |
1654 | kfree_skb(skb); |
1655 | return 0; | |
1656 | } | |
1657 | } | |
1658 | ||
1344ee25 | 1659 | memcpy((unsigned char *)(skb->cb), &dev, sizeof(dev)); |
94a79942 | 1660 | if (queue_index == TXCMD_QUEUE) { |
98208f96 | 1661 | _rtl92e_tx_cmd(dev, skb); |
26e2fa76 | 1662 | return 0; |
94a79942 LF |
1663 | } |
1664 | ||
285b7c00 MK |
1665 | tcb_desc->RATRIndex = 7; |
1666 | tcb_desc->bTxDisableRateFallBack = 1; | |
1667 | tcb_desc->bTxUseDriverAssingedRate = 1; | |
1668 | tcb_desc->bTxEnableFwCalcDur = 1; | |
1669 | skb_push(skb, priv->rtllib->tx_headroom); | |
374a3c5a | 1670 | ret = _rtl92e_tx(dev, skb); |
285b7c00 MK |
1671 | if (ret != 0) |
1672 | kfree_skb(skb); | |
94a79942 | 1673 | return ret; |
94a79942 LF |
1674 | } |
1675 | ||
7effc87b | 1676 | static void _rtl92e_tx_isr(struct net_device *dev, int prio) |
94a79942 | 1677 | { |
a4eed41f | 1678 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 1679 | |
1344ee25 | 1680 | struct rtl8192_tx_ring *ring = &priv->tx_ring[prio]; |
94a79942 | 1681 | |
1344ee25 LF |
1682 | while (skb_queue_len(&ring->queue)) { |
1683 | struct tx_desc *entry = &ring->desc[ring->idx]; | |
1684 | struct sk_buff *skb; | |
94a79942 | 1685 | |
1344ee25 LF |
1686 | if (prio != BEACON_QUEUE) { |
1687 | if (entry->OWN) | |
1688 | return; | |
1689 | ring->idx = (ring->idx + 1) % ring->entries; | |
1690 | } | |
94a79942 | 1691 | |
1344ee25 | 1692 | skb = __skb_dequeue(&ring->queue); |
466bc7f2 | 1693 | pci_unmap_single(priv->pdev, entry->TxBuffAddr, |
1344ee25 | 1694 | skb->len, PCI_DMA_TODEVICE); |
94a79942 | 1695 | |
1344ee25 LF |
1696 | kfree_skb(skb); |
1697 | } | |
1698 | if (prio != BEACON_QUEUE) | |
1699 | tasklet_schedule(&priv->irq_tx_tasklet); | |
94a79942 LF |
1700 | } |
1701 | ||
98208f96 | 1702 | static void _rtl92e_tx_cmd(struct net_device *dev, struct sk_buff *skb) |
94a79942 | 1703 | { |
1344ee25 LF |
1704 | struct r8192_priv *priv = rtllib_priv(dev); |
1705 | struct rtl8192_tx_ring *ring; | |
1706 | struct tx_desc_cmd *entry; | |
1707 | unsigned int idx; | |
1708 | struct cb_desc *tcb_desc; | |
1709 | unsigned long flags; | |
94a79942 | 1710 | |
1344ee25 LF |
1711 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
1712 | ring = &priv->tx_ring[TXCMD_QUEUE]; | |
94a79942 | 1713 | |
1344ee25 LF |
1714 | idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; |
1715 | entry = (struct tx_desc_cmd *) &ring->desc[idx]; | |
94a79942 | 1716 | |
1344ee25 | 1717 | tcb_desc = (struct cb_desc *)(skb->cb + MAX_DEV_ADDR_SIZE); |
94a79942 | 1718 | |
1344ee25 | 1719 | priv->ops->tx_fill_cmd_descriptor(dev, entry, tcb_desc, skb); |
94a79942 | 1720 | |
1344ee25 LF |
1721 | __skb_queue_tail(&ring->queue, skb); |
1722 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); | |
94a79942 LF |
1723 | } |
1724 | ||
374a3c5a | 1725 | static short _rtl92e_tx(struct net_device *dev, struct sk_buff *skb) |
94a79942 LF |
1726 | { |
1727 | struct r8192_priv *priv = rtllib_priv(dev); | |
1728 | struct rtl8192_tx_ring *ring; | |
1729 | unsigned long flags; | |
1344ee25 LF |
1730 | struct cb_desc *tcb_desc = (struct cb_desc *)(skb->cb + |
1731 | MAX_DEV_ADDR_SIZE); | |
bc27e89b | 1732 | struct tx_desc *pdesc = NULL; |
1344ee25 LF |
1733 | struct rtllib_hdr_1addr *header = NULL; |
1734 | u16 fc = 0, type = 0, stype = 0; | |
1735 | bool multi_addr = false, broad_addr = false, uni_addr = false; | |
1736 | u8 *pda_addr = NULL; | |
94a79942 LF |
1737 | int idx; |
1738 | u32 fwinfo_size = 0; | |
1739 | ||
1344ee25 | 1740 | if (priv->bdisable_nic) { |
3b4140af MK |
1741 | netdev_warn(dev, "%s: Nic is disabled! Can't tx packet.\n", |
1742 | __func__); | |
1344ee25 | 1743 | return skb->len; |
94a79942 LF |
1744 | } |
1745 | ||
1746 | priv->rtllib->bAwakePktSent = true; | |
1747 | ||
a07dc3d1 | 1748 | fwinfo_size = sizeof(struct tx_fwinfo_8190pci); |
94a79942 | 1749 | |
1344ee25 | 1750 | header = (struct rtllib_hdr_1addr *)(((u8 *)skb->data) + fwinfo_size); |
34e987e6 | 1751 | fc = le16_to_cpu(header->frame_ctl); |
94a79942 LF |
1752 | type = WLAN_FC_GET_TYPE(fc); |
1753 | stype = WLAN_FC_GET_STYPE(fc); | |
1754 | pda_addr = header->addr1; | |
1755 | ||
14fc4235 | 1756 | if (is_broadcast_ether_addr(pda_addr)) |
94a79942 | 1757 | broad_addr = true; |
14fc4235 JP |
1758 | else if (is_multicast_ether_addr(pda_addr)) |
1759 | multi_addr = true; | |
1344ee25 | 1760 | else |
94a79942 | 1761 | uni_addr = true; |
94a79942 LF |
1762 | |
1763 | if (uni_addr) | |
1764 | priv->stats.txbytesunicast += skb->len - fwinfo_size; | |
1765 | else if (multi_addr) | |
1766 | priv->stats.txbytesmulticast += skb->len - fwinfo_size; | |
1767 | else | |
1768 | priv->stats.txbytesbroadcast += skb->len - fwinfo_size; | |
1769 | ||
1344ee25 | 1770 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
94a79942 | 1771 | ring = &priv->tx_ring[tcb_desc->queue_index]; |
1344ee25 | 1772 | if (tcb_desc->queue_index != BEACON_QUEUE) |
94a79942 | 1773 | idx = (ring->idx + skb_queue_len(&ring->queue)) % ring->entries; |
1344ee25 | 1774 | else |
94a79942 | 1775 | idx = 0; |
94a79942 LF |
1776 | |
1777 | pdesc = &ring->desc[idx]; | |
1778 | if ((pdesc->OWN == 1) && (tcb_desc->queue_index != BEACON_QUEUE)) { | |
3b4140af MK |
1779 | netdev_warn(dev, |
1780 | "No more TX desc@%d, ring->idx = %d, idx = %d, skblen = 0x%x queuelen=%d", | |
1781 | tcb_desc->queue_index, ring->idx, idx, skb->len, | |
1782 | skb_queue_len(&ring->queue)); | |
1344ee25 | 1783 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
1784 | return skb->len; |
1785 | } | |
1786 | ||
1344ee25 | 1787 | if (type == RTLLIB_FTYPE_DATA) { |
94a79942 LF |
1788 | if (priv->rtllib->LedControlHandler) |
1789 | priv->rtllib->LedControlHandler(dev, LED_CTL_TX); | |
1790 | } | |
1791 | priv->ops->tx_fill_descriptor(dev, pdesc, tcb_desc, skb); | |
1792 | __skb_queue_tail(&ring->queue, skb); | |
1793 | pdesc->OWN = 1; | |
1344ee25 | 1794 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
860e9538 | 1795 | netif_trans_update(dev); |
94a79942 | 1796 | |
6dee0c88 | 1797 | rtl92e_writew(dev, TPPoll, 0x01 << tcb_desc->queue_index); |
94a79942 LF |
1798 | return 0; |
1799 | } | |
1800 | ||
9d148965 | 1801 | static short _rtl92e_alloc_rx_ring(struct net_device *dev) |
94a79942 LF |
1802 | { |
1803 | struct r8192_priv *priv = rtllib_priv(dev); | |
4f534b36 | 1804 | struct rx_desc *entry = NULL; |
94a79942 LF |
1805 | int i, rx_queue_idx; |
1806 | ||
1344ee25 | 1807 | for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) { |
35e33b04 | 1808 | priv->rx_ring[rx_queue_idx] = pci_zalloc_consistent(priv->pdev, |
8b983be5 JP |
1809 | sizeof(*priv->rx_ring[rx_queue_idx]) * priv->rxringcount, |
1810 | &priv->rx_ring_dma[rx_queue_idx]); | |
1344ee25 LF |
1811 | if (!priv->rx_ring[rx_queue_idx] || |
1812 | (unsigned long)priv->rx_ring[rx_queue_idx] & 0xFF) { | |
3b4140af | 1813 | netdev_warn(dev, "Cannot allocate RX ring\n"); |
94a79942 LF |
1814 | return -ENOMEM; |
1815 | } | |
1816 | ||
94a79942 LF |
1817 | priv->rx_idx[rx_queue_idx] = 0; |
1818 | ||
1819 | for (i = 0; i < priv->rxringcount; i++) { | |
1820 | struct sk_buff *skb = dev_alloc_skb(priv->rxbuffersize); | |
1821 | dma_addr_t *mapping; | |
3a6b70c3 | 1822 | |
94a79942 LF |
1823 | entry = &priv->rx_ring[rx_queue_idx][i]; |
1824 | if (!skb) | |
1825 | return 0; | |
1826 | skb->dev = dev; | |
1827 | priv->rx_buf[rx_queue_idx][i] = skb; | |
1828 | mapping = (dma_addr_t *)skb->cb; | |
1344ee25 LF |
1829 | *mapping = pci_map_single(priv->pdev, |
1830 | skb_tail_pointer_rsl(skb), | |
1831 | priv->rxbuffersize, | |
1832 | PCI_DMA_FROMDEVICE); | |
2dcb4a29 LF |
1833 | if (pci_dma_mapping_error(priv->pdev, *mapping)) { |
1834 | dev_kfree_skb_any(skb); | |
1835 | return -1; | |
1836 | } | |
34e987e6 | 1837 | entry->BufferAddress = *mapping; |
94a79942 LF |
1838 | |
1839 | entry->Length = priv->rxbuffersize; | |
1840 | entry->OWN = 1; | |
1841 | } | |
1842 | ||
f6692285 | 1843 | if (entry) |
35f8673d | 1844 | entry->EOR = 1; |
94a79942 LF |
1845 | } |
1846 | return 0; | |
1847 | } | |
1848 | ||
bf1ddf24 MK |
1849 | static int _rtl92e_alloc_tx_ring(struct net_device *dev, unsigned int prio, |
1850 | unsigned int entries) | |
94a79942 | 1851 | { |
a4eed41f | 1852 | struct r8192_priv *priv = rtllib_priv(dev); |
1344ee25 LF |
1853 | struct tx_desc *ring; |
1854 | dma_addr_t dma; | |
1855 | int i; | |
94a79942 | 1856 | |
8b983be5 | 1857 | ring = pci_zalloc_consistent(priv->pdev, sizeof(*ring) * entries, &dma); |
1344ee25 | 1858 | if (!ring || (unsigned long)ring & 0xFF) { |
3b4140af | 1859 | netdev_warn(dev, "Cannot allocate TX ring (prio = %d)\n", prio); |
1344ee25 LF |
1860 | return -ENOMEM; |
1861 | } | |
94a79942 | 1862 | |
1344ee25 LF |
1863 | priv->tx_ring[prio].desc = ring; |
1864 | priv->tx_ring[prio].dma = dma; | |
1865 | priv->tx_ring[prio].idx = 0; | |
1866 | priv->tx_ring[prio].entries = entries; | |
1867 | skb_queue_head_init(&priv->tx_ring[prio].queue); | |
94a79942 | 1868 | |
1344ee25 LF |
1869 | for (i = 0; i < entries; i++) |
1870 | ring[i].NextDescAddress = | |
34e987e6 RK |
1871 | (u32)dma + ((i + 1) % entries) * |
1872 | sizeof(*ring); | |
94a79942 | 1873 | |
1344ee25 | 1874 | return 0; |
94a79942 LF |
1875 | } |
1876 | ||
197917a8 | 1877 | static short _rtl92e_pci_initdescring(struct net_device *dev) |
94a79942 | 1878 | { |
1344ee25 LF |
1879 | u32 ret; |
1880 | int i; | |
1881 | struct r8192_priv *priv = rtllib_priv(dev); | |
94a79942 | 1882 | |
9d148965 | 1883 | ret = _rtl92e_alloc_rx_ring(dev); |
1344ee25 LF |
1884 | if (ret) |
1885 | return ret; | |
94a79942 | 1886 | |
1344ee25 | 1887 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { |
bf1ddf24 | 1888 | ret = _rtl92e_alloc_tx_ring(dev, i, priv->txringcount); |
1344ee25 LF |
1889 | if (ret) |
1890 | goto err_free_rings; | |
1891 | } | |
94a79942 | 1892 | |
1344ee25 | 1893 | return 0; |
94a79942 LF |
1894 | |
1895 | err_free_rings: | |
694f9d30 | 1896 | _rtl92e_free_rx_ring(dev); |
1344ee25 LF |
1897 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) |
1898 | if (priv->tx_ring[i].desc) | |
ebc36ecd | 1899 | _rtl92e_free_tx_ring(dev, i); |
1344ee25 | 1900 | return 1; |
94a79942 LF |
1901 | } |
1902 | ||
36154dc3 | 1903 | void rtl92e_reset_desc_ring(struct net_device *dev) |
94a79942 | 1904 | { |
1344ee25 LF |
1905 | struct r8192_priv *priv = rtllib_priv(dev); |
1906 | int i, rx_queue_idx; | |
1907 | unsigned long flags = 0; | |
94a79942 | 1908 | |
1344ee25 | 1909 | for (rx_queue_idx = 0; rx_queue_idx < MAX_RX_QUEUE; rx_queue_idx++) { |
94a79942 | 1910 | if (priv->rx_ring[rx_queue_idx]) { |
4f534b36 | 1911 | struct rx_desc *entry = NULL; |
3a6b70c3 | 1912 | |
94a79942 LF |
1913 | for (i = 0; i < priv->rxringcount; i++) { |
1914 | entry = &priv->rx_ring[rx_queue_idx][i]; | |
1915 | entry->OWN = 1; | |
1916 | } | |
1917 | priv->rx_idx[rx_queue_idx] = 0; | |
1918 | } | |
1919 | } | |
1920 | ||
1344ee25 LF |
1921 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
1922 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) { | |
1923 | if (priv->tx_ring[i].desc) { | |
1924 | struct rtl8192_tx_ring *ring = &priv->tx_ring[i]; | |
94a79942 | 1925 | |
1344ee25 LF |
1926 | while (skb_queue_len(&ring->queue)) { |
1927 | struct tx_desc *entry = &ring->desc[ring->idx]; | |
1928 | struct sk_buff *skb = | |
1929 | __skb_dequeue(&ring->queue); | |
94a79942 | 1930 | |
1344ee25 | 1931 | pci_unmap_single(priv->pdev, |
466bc7f2 | 1932 | entry->TxBuffAddr, |
1344ee25 LF |
1933 | skb->len, PCI_DMA_TODEVICE); |
1934 | kfree_skb(skb); | |
1935 | ring->idx = (ring->idx + 1) % ring->entries; | |
1936 | } | |
1937 | ring->idx = 0; | |
1938 | } | |
1939 | } | |
1940 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); | |
94a79942 LF |
1941 | } |
1942 | ||
7879efc5 MK |
1943 | void rtl92e_update_rx_pkt_timestamp(struct net_device *dev, |
1944 | struct rtllib_rx_stats *stats) | |
94a79942 | 1945 | { |
a4eed41f | 1946 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 1947 | |
0dd56506 LF |
1948 | if (stats->bIsAMPDU && !stats->bFirstMPDU) |
1949 | stats->mac_time = priv->LastRxDescTSF; | |
1950 | else | |
1951 | priv->LastRxDescTSF = stats->mac_time; | |
94a79942 LF |
1952 | } |
1953 | ||
f54f10bf | 1954 | long rtl92e_translate_to_dbm(struct r8192_priv *priv, u8 signal_strength_index) |
94a79942 LF |
1955 | { |
1956 | long signal_power; | |
1957 | ||
1958 | signal_power = (long)((signal_strength_index + 1) >> 1); | |
1959 | signal_power -= 95; | |
1960 | ||
1961 | return signal_power; | |
1962 | } | |
1963 | ||
1964 | ||
97ef450b MK |
1965 | void rtl92e_update_rx_statistics(struct r8192_priv *priv, |
1966 | struct rtllib_rx_stats *pprevious_stats) | |
94a79942 LF |
1967 | { |
1968 | int weighting = 0; | |
1969 | ||
1970 | ||
1971 | if (priv->stats.recv_signal_power == 0) | |
1344ee25 LF |
1972 | priv->stats.recv_signal_power = |
1973 | pprevious_stats->RecvSignalPower; | |
94a79942 LF |
1974 | |
1975 | if (pprevious_stats->RecvSignalPower > priv->stats.recv_signal_power) | |
1976 | weighting = 5; | |
1344ee25 LF |
1977 | else if (pprevious_stats->RecvSignalPower < |
1978 | priv->stats.recv_signal_power) | |
94a79942 | 1979 | weighting = (-5); |
1344ee25 LF |
1980 | priv->stats.recv_signal_power = (priv->stats.recv_signal_power * 5 + |
1981 | pprevious_stats->RecvSignalPower + | |
1982 | weighting) / 6; | |
94a79942 LF |
1983 | } |
1984 | ||
5d5fd353 | 1985 | u8 rtl92e_rx_db_to_percent(s8 antpower) |
94a79942 LF |
1986 | { |
1987 | if ((antpower <= -100) || (antpower >= 20)) | |
94a79942 | 1988 | return 0; |
94a79942 | 1989 | else if (antpower >= 0) |
94a79942 | 1990 | return 100; |
94a79942 | 1991 | else |
1344ee25 | 1992 | return 100 + antpower; |
94a79942 LF |
1993 | |
1994 | } /* QueryRxPwrPercentage */ | |
1995 | ||
5d5fd353 | 1996 | u8 rtl92e_evm_db_to_percent(s8 value) |
94a79942 | 1997 | { |
5d5fd353 | 1998 | s8 ret_val; |
94a79942 LF |
1999 | |
2000 | ret_val = value; | |
2001 | ||
2002 | if (ret_val >= 0) | |
2003 | ret_val = 0; | |
2004 | if (ret_val <= -33) | |
2005 | ret_val = -33; | |
2006 | ret_val = 0 - ret_val; | |
1344ee25 | 2007 | ret_val *= 3; |
94a79942 LF |
2008 | if (ret_val == 99) |
2009 | ret_val = 100; | |
1344ee25 | 2010 | return ret_val; |
94a79942 LF |
2011 | } |
2012 | ||
e58701da MK |
2013 | void rtl92e_copy_mpdu_stats(struct rtllib_rx_stats *psrc_stats, |
2014 | struct rtllib_rx_stats *ptarget_stats) | |
94a79942 LF |
2015 | { |
2016 | ptarget_stats->bIsAMPDU = psrc_stats->bIsAMPDU; | |
2017 | ptarget_stats->bFirstMPDU = psrc_stats->bFirstMPDU; | |
2018 | } | |
2019 | ||
2020 | ||
2021 | ||
0ba8f7c0 | 2022 | static void _rtl92e_rx_normal(struct net_device *dev) |
94a79942 | 2023 | { |
a4eed41f | 2024 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
2025 | struct rtllib_hdr_1addr *rtllib_hdr = NULL; |
2026 | bool unicast_packet = false; | |
1344ee25 LF |
2027 | bool bLedBlinking = true; |
2028 | u16 fc = 0, type = 0; | |
94a79942 LF |
2029 | u32 skb_len = 0; |
2030 | int rx_queue_idx = RX_MPDU_QUEUE; | |
2031 | ||
2032 | struct rtllib_rx_stats stats = { | |
2033 | .signal = 0, | |
94e057d7 | 2034 | .noise = (u8) -98, |
94a79942 LF |
2035 | .rate = 0, |
2036 | .freq = RTLLIB_24GHZ_BAND, | |
2037 | }; | |
2038 | unsigned int count = priv->rxringcount; | |
2039 | ||
2040 | stats.nic_type = NIC_8192E; | |
2041 | ||
2042 | while (count--) { | |
1344ee25 LF |
2043 | struct rx_desc *pdesc = &priv->rx_ring[rx_queue_idx] |
2044 | [priv->rx_idx[rx_queue_idx]]; | |
2045 | struct sk_buff *skb = priv->rx_buf[rx_queue_idx] | |
2046 | [priv->rx_idx[rx_queue_idx]]; | |
285b7c00 | 2047 | struct sk_buff *new_skb; |
94a79942 | 2048 | |
285b7c00 | 2049 | if (pdesc->OWN) |
94a79942 | 2050 | return; |
285b7c00 MK |
2051 | if (!priv->ops->rx_query_status_descriptor(dev, &stats, |
2052 | pdesc, skb)) | |
2053 | goto done; | |
2054 | new_skb = dev_alloc_skb(priv->rxbuffersize); | |
2055 | /* if allocation of new skb failed - drop current packet | |
14b40d92 MK |
2056 | * and reuse skb |
2057 | */ | |
285b7c00 MK |
2058 | if (unlikely(!new_skb)) |
2059 | goto done; | |
2060 | ||
2061 | pci_unmap_single(priv->pdev, | |
2062 | *((dma_addr_t *)skb->cb), | |
2063 | priv->rxbuffersize, | |
2064 | PCI_DMA_FROMDEVICE); | |
2065 | ||
2066 | skb_put(skb, pdesc->Length); | |
2067 | skb_reserve(skb, stats.RxDrvInfoSize + | |
2068 | stats.RxBufShift); | |
2069 | skb_trim(skb, skb->len - 4/*sCrcLng*/); | |
2070 | rtllib_hdr = (struct rtllib_hdr_1addr *)skb->data; | |
2071 | if (!is_multicast_ether_addr(rtllib_hdr->addr1)) { | |
2072 | /* unicast packet */ | |
2073 | unicast_packet = true; | |
2074 | } | |
2075 | fc = le16_to_cpu(rtllib_hdr->frame_ctl); | |
2076 | type = WLAN_FC_GET_TYPE(fc); | |
2077 | if (type == RTLLIB_FTYPE_MGMT) | |
2078 | bLedBlinking = false; | |
2079 | ||
2080 | if (bLedBlinking) | |
2081 | if (priv->rtllib->LedControlHandler) | |
2082 | priv->rtllib->LedControlHandler(dev, | |
2083 | LED_CTL_RX); | |
2084 | ||
2085 | if (stats.bCRC) { | |
2086 | if (type != RTLLIB_FTYPE_MGMT) | |
2087 | priv->stats.rxdatacrcerr++; | |
2088 | else | |
2089 | priv->stats.rxmgmtcrcerr++; | |
2090 | } | |
94a79942 | 2091 | |
285b7c00 | 2092 | skb_len = skb->len; |
4f6807e8 | 2093 | |
285b7c00 MK |
2094 | if (!rtllib_rx(priv->rtllib, skb, &stats)) { |
2095 | dev_kfree_skb_any(skb); | |
2096 | } else { | |
2097 | priv->stats.rxok++; | |
2098 | if (unicast_packet) | |
2099 | priv->stats.rxbytesunicast += skb_len; | |
2100 | } | |
4f6807e8 | 2101 | |
285b7c00 MK |
2102 | skb = new_skb; |
2103 | skb->dev = dev; | |
2104 | ||
2105 | priv->rx_buf[rx_queue_idx][priv->rx_idx[rx_queue_idx]] = | |
2106 | skb; | |
2107 | *((dma_addr_t *) skb->cb) = pci_map_single(priv->pdev, | |
2108 | skb_tail_pointer_rsl(skb), | |
2109 | priv->rxbuffersize, | |
2110 | PCI_DMA_FROMDEVICE); | |
2111 | if (pci_dma_mapping_error(priv->pdev, | |
2112 | *((dma_addr_t *)skb->cb))) { | |
2113 | dev_kfree_skb_any(skb); | |
2114 | return; | |
94a79942 LF |
2115 | } |
2116 | done: | |
34e987e6 | 2117 | pdesc->BufferAddress = *((dma_addr_t *)skb->cb); |
94a79942 LF |
2118 | pdesc->OWN = 1; |
2119 | pdesc->Length = priv->rxbuffersize; | |
2120 | if (priv->rx_idx[rx_queue_idx] == priv->rxringcount-1) | |
2121 | pdesc->EOR = 1; | |
1344ee25 LF |
2122 | priv->rx_idx[rx_queue_idx] = (priv->rx_idx[rx_queue_idx] + 1) % |
2123 | priv->rxringcount; | |
94a79942 LF |
2124 | } |
2125 | ||
2126 | } | |
2127 | ||
a67c7904 | 2128 | static void _rtl92e_tx_resume(struct net_device *dev) |
94a79942 | 2129 | { |
a4eed41f | 2130 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
2131 | struct rtllib_device *ieee = priv->rtllib; |
2132 | struct sk_buff *skb; | |
2133 | int queue_index; | |
2134 | ||
1344ee25 LF |
2135 | for (queue_index = BK_QUEUE; |
2136 | queue_index < MAX_QUEUE_SIZE; queue_index++) { | |
2137 | while ((!skb_queue_empty(&ieee->skb_waitQ[queue_index])) && | |
2138 | (priv->rtllib->check_nic_enough_desc(dev, queue_index) > 0)) { | |
94a79942 | 2139 | skb = skb_dequeue(&ieee->skb_waitQ[queue_index]); |
1344ee25 | 2140 | ieee->softmac_data_hard_start_xmit(skb, dev, 0); |
94a79942 LF |
2141 | } |
2142 | } | |
2143 | } | |
2144 | ||
a2743b2c | 2145 | static void _rtl92e_irq_tx_tasklet(struct r8192_priv *priv) |
94a79942 | 2146 | { |
a67c7904 | 2147 | _rtl92e_tx_resume(priv->rtllib->dev); |
94a79942 LF |
2148 | } |
2149 | ||
2940405b | 2150 | static void _rtl92e_irq_rx_tasklet(struct r8192_priv *priv) |
94a79942 | 2151 | { |
0ba8f7c0 | 2152 | _rtl92e_rx_normal(priv->rtllib->dev); |
94a79942 | 2153 | |
8ea54100 MK |
2154 | rtl92e_writel(priv->rtllib->dev, INTA_MASK, |
2155 | rtl92e_readl(priv->rtllib->dev, INTA_MASK) | IMR_RDU); | |
94a79942 LF |
2156 | } |
2157 | ||
2158 | /**************************************************************************** | |
2159 | ---------------------------- NIC START/CLOSE STUFF--------------------------- | |
2160 | *****************************************************************************/ | |
4dba03a2 | 2161 | static void _rtl92e_cancel_deferred_work(struct r8192_priv *priv) |
94a79942 | 2162 | { |
ecfdd3a0 AKC |
2163 | cancel_delayed_work_sync(&priv->watch_dog_wq); |
2164 | cancel_delayed_work_sync(&priv->update_beacon_wq); | |
94a79942 | 2165 | cancel_delayed_work(&priv->rtllib->hw_sleep_wq); |
94a79942 LF |
2166 | cancel_work_sync(&priv->reset_wq); |
2167 | cancel_work_sync(&priv->qos_activate); | |
94a79942 LF |
2168 | } |
2169 | ||
81524bbc | 2170 | static int _rtl92e_up(struct net_device *dev, bool is_silent_reset) |
94a79942 | 2171 | { |
dba0e06f | 2172 | if (_rtl92e_sta_up(dev, is_silent_reset) == -1) |
94a79942 LF |
2173 | return -1; |
2174 | return 0; | |
2175 | } | |
2176 | ||
27d673b0 | 2177 | static int _rtl92e_open(struct net_device *dev) |
94a79942 LF |
2178 | { |
2179 | struct r8192_priv *priv = rtllib_priv(dev); | |
2180 | int ret; | |
2181 | ||
3044975f | 2182 | mutex_lock(&priv->wx_mutex); |
b1665a67 | 2183 | ret = _rtl92e_try_up(dev); |
3044975f | 2184 | mutex_unlock(&priv->wx_mutex); |
94a79942 LF |
2185 | return ret; |
2186 | ||
2187 | } | |
2188 | ||
b1665a67 | 2189 | static int _rtl92e_try_up(struct net_device *dev) |
94a79942 LF |
2190 | { |
2191 | struct r8192_priv *priv = rtllib_priv(dev); | |
2192 | ||
1344ee25 LF |
2193 | if (priv->up == 1) |
2194 | return -1; | |
81524bbc | 2195 | return _rtl92e_up(dev, false); |
94a79942 LF |
2196 | } |
2197 | ||
2198 | ||
27cbba60 | 2199 | static int _rtl92e_close(struct net_device *dev) |
94a79942 LF |
2200 | { |
2201 | struct r8192_priv *priv = rtllib_priv(dev); | |
2202 | int ret; | |
2203 | ||
2204 | if ((rtllib_act_scanning(priv->rtllib, false)) && | |
1344ee25 | 2205 | !(priv->rtllib->softmac_features & IEEE_SOFTMAC_SCAN)) { |
94a79942 LF |
2206 | rtllib_stop_scan(priv->rtllib); |
2207 | } | |
2208 | ||
3044975f | 2209 | mutex_lock(&priv->wx_mutex); |
94a79942 | 2210 | |
33bec9bd | 2211 | ret = _rtl92e_down(dev, true); |
94a79942 | 2212 | |
3044975f | 2213 | mutex_unlock(&priv->wx_mutex); |
94a79942 LF |
2214 | |
2215 | return ret; | |
2216 | ||
2217 | } | |
2218 | ||
33bec9bd | 2219 | static int _rtl92e_down(struct net_device *dev, bool shutdownrf) |
94a79942 | 2220 | { |
2b19e222 | 2221 | if (_rtl92e_sta_down(dev, shutdownrf) == -1) |
94a79942 LF |
2222 | return -1; |
2223 | ||
94a79942 LF |
2224 | return 0; |
2225 | } | |
2226 | ||
bc4f2cc9 | 2227 | void rtl92e_commit(struct net_device *dev) |
94a79942 LF |
2228 | { |
2229 | struct r8192_priv *priv = rtllib_priv(dev); | |
2230 | ||
1344ee25 LF |
2231 | if (priv->up == 0) |
2232 | return; | |
f6692285 | 2233 | rtllib_softmac_stop_protocol(priv->rtllib, 0, true); |
b7b50d65 | 2234 | rtl92e_irq_disable(dev); |
94a79942 | 2235 | priv->ops->stop_adapter(dev, true); |
81524bbc | 2236 | _rtl92e_up(dev, false); |
94a79942 LF |
2237 | } |
2238 | ||
78e67df3 | 2239 | static void _rtl92e_restart(void *data) |
94a79942 | 2240 | { |
1344ee25 LF |
2241 | struct r8192_priv *priv = container_of_work_rsl(data, struct r8192_priv, |
2242 | reset_wq); | |
94a79942 | 2243 | struct net_device *dev = priv->rtllib->dev; |
94a79942 | 2244 | |
3044975f | 2245 | mutex_lock(&priv->wx_mutex); |
94a79942 | 2246 | |
bc4f2cc9 | 2247 | rtl92e_commit(dev); |
94a79942 | 2248 | |
3044975f | 2249 | mutex_unlock(&priv->wx_mutex); |
94a79942 LF |
2250 | } |
2251 | ||
2002978d | 2252 | static void _rtl92e_set_multicast(struct net_device *dev) |
94a79942 LF |
2253 | { |
2254 | struct r8192_priv *priv = rtllib_priv(dev); | |
2255 | short promisc; | |
2256 | ||
1344ee25 | 2257 | promisc = (dev->flags & IFF_PROMISC) ? 1 : 0; |
94a79942 LF |
2258 | priv->promisc = promisc; |
2259 | ||
2260 | } | |
2261 | ||
2262 | ||
3ef7f1ee | 2263 | static int _rtl92e_set_mac_adr(struct net_device *dev, void *mac) |
94a79942 LF |
2264 | { |
2265 | struct r8192_priv *priv = rtllib_priv(dev); | |
2266 | struct sockaddr *addr = mac; | |
2267 | ||
3044975f | 2268 | mutex_lock(&priv->wx_mutex); |
94a79942 | 2269 | |
1f3aefb5 | 2270 | ether_addr_copy(dev->dev_addr, addr->sa_data); |
94a79942 | 2271 | |
94a79942 | 2272 | schedule_work(&priv->reset_wq); |
3044975f | 2273 | mutex_unlock(&priv->wx_mutex); |
94a79942 LF |
2274 | |
2275 | return 0; | |
2276 | } | |
2277 | ||
2278 | /* based on ipw2200 driver */ | |
09c26de7 | 2279 | static int _rtl92e_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
94a79942 | 2280 | { |
a4eed41f | 2281 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 2282 | struct iwreq *wrq = (struct iwreq *)rq; |
1344ee25 | 2283 | int ret = -1; |
94a79942 LF |
2284 | struct rtllib_device *ieee = priv->rtllib; |
2285 | u32 key[4]; | |
06c11107 | 2286 | const u8 broadcast_addr[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; |
94a79942 | 2287 | struct iw_point *p = &wrq->u.data; |
1344ee25 | 2288 | struct ieee_param *ipw = NULL; |
94a79942 | 2289 | |
3044975f | 2290 | mutex_lock(&priv->wx_mutex); |
94a79942 LF |
2291 | |
2292 | switch (cmd) { | |
1344ee25 LF |
2293 | case RTL_IOCTL_WPA_SUPPLICANT: |
2294 | if (p->length < sizeof(struct ieee_param) || !p->pointer) { | |
2295 | ret = -EINVAL; | |
2296 | goto out; | |
2297 | } | |
94a79942 | 2298 | |
21624981 TB |
2299 | ipw = memdup_user(p->pointer, p->length); |
2300 | if (IS_ERR(ipw)) { | |
2301 | ret = PTR_ERR(ipw); | |
1344ee25 LF |
2302 | goto out; |
2303 | } | |
94a79942 | 2304 | |
1344ee25 LF |
2305 | if (ipw->cmd == IEEE_CMD_SET_ENCRYPTION) { |
2306 | if (ipw->u.crypt.set_tx) { | |
2307 | if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) | |
2308 | ieee->pairwise_key_type = KEY_TYPE_CCMP; | |
2309 | else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) | |
2310 | ieee->pairwise_key_type = KEY_TYPE_TKIP; | |
2311 | else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) { | |
2312 | if (ipw->u.crypt.key_len == 13) | |
2313 | ieee->pairwise_key_type = | |
2314 | KEY_TYPE_WEP104; | |
2315 | else if (ipw->u.crypt.key_len == 5) | |
2316 | ieee->pairwise_key_type = | |
2317 | KEY_TYPE_WEP40; | |
2318 | } else { | |
2319 | ieee->pairwise_key_type = KEY_TYPE_NA; | |
94a79942 | 2320 | } |
1344ee25 LF |
2321 | |
2322 | if (ieee->pairwise_key_type) { | |
06c11107 | 2323 | if (is_zero_ether_addr(ieee->ap_mac_addr)) |
1344ee25 LF |
2324 | ieee->iw_mode = IW_MODE_ADHOC; |
2325 | memcpy((u8 *)key, ipw->u.crypt.key, 16); | |
37420932 | 2326 | rtl92e_enable_hw_security_config(dev); |
aae7e72e MK |
2327 | rtl92e_set_swcam(dev, 4, |
2328 | ipw->u.crypt.idx, | |
2329 | ieee->pairwise_key_type, | |
2330 | (u8 *)ieee->ap_mac_addr, | |
2331 | 0, key, 0); | |
408bd7b7 MK |
2332 | rtl92e_set_key(dev, 4, ipw->u.crypt.idx, |
2333 | ieee->pairwise_key_type, | |
2334 | (u8 *)ieee->ap_mac_addr, | |
2335 | 0, key); | |
1344ee25 | 2336 | if (ieee->iw_mode == IW_MODE_ADHOC) { |
aae7e72e MK |
2337 | rtl92e_set_swcam(dev, |
2338 | ipw->u.crypt.idx, | |
2339 | ipw->u.crypt.idx, | |
2340 | ieee->pairwise_key_type, | |
2341 | (u8 *)ieee->ap_mac_addr, | |
2342 | 0, key, 0); | |
408bd7b7 MK |
2343 | rtl92e_set_key(dev, |
2344 | ipw->u.crypt.idx, | |
2345 | ipw->u.crypt.idx, | |
2346 | ieee->pairwise_key_type, | |
2347 | (u8 *)ieee->ap_mac_addr, | |
2348 | 0, key); | |
94a79942 LF |
2349 | } |
2350 | } | |
1344ee25 LF |
2351 | if ((ieee->pairwise_key_type == KEY_TYPE_CCMP) |
2352 | && ieee->pHTInfo->bCurrentHTSupport) { | |
d8ae1967 | 2353 | rtl92e_writeb(dev, 0x173, 1); |
1344ee25 | 2354 | } |
22466983 | 2355 | |
1344ee25 LF |
2356 | } else { |
2357 | memcpy((u8 *)key, ipw->u.crypt.key, 16); | |
2358 | if (strcmp(ipw->u.crypt.alg, "CCMP") == 0) | |
2359 | ieee->group_key_type = KEY_TYPE_CCMP; | |
2360 | else if (strcmp(ipw->u.crypt.alg, "TKIP") == 0) | |
2361 | ieee->group_key_type = KEY_TYPE_TKIP; | |
2362 | else if (strcmp(ipw->u.crypt.alg, "WEP") == 0) { | |
2363 | if (ipw->u.crypt.key_len == 13) | |
2364 | ieee->group_key_type = | |
2365 | KEY_TYPE_WEP104; | |
2366 | else if (ipw->u.crypt.key_len == 5) | |
2367 | ieee->group_key_type = | |
2368 | KEY_TYPE_WEP40; | |
2369 | } else | |
2370 | ieee->group_key_type = KEY_TYPE_NA; | |
2371 | ||
2372 | if (ieee->group_key_type) { | |
aae7e72e MK |
2373 | rtl92e_set_swcam(dev, ipw->u.crypt.idx, |
2374 | ipw->u.crypt.idx, | |
2375 | ieee->group_key_type, | |
2376 | broadcast_addr, 0, key, | |
2377 | 0); | |
408bd7b7 MK |
2378 | rtl92e_set_key(dev, ipw->u.crypt.idx, |
2379 | ipw->u.crypt.idx, | |
2380 | ieee->group_key_type, | |
2381 | broadcast_addr, 0, key); | |
1344ee25 LF |
2382 | } |
2383 | } | |
94a79942 | 2384 | } |
1344ee25 LF |
2385 | |
2386 | ret = rtllib_wpa_supplicant_ioctl(priv->rtllib, &wrq->u.data, | |
2387 | 0); | |
2388 | kfree(ipw); | |
2389 | break; | |
2390 | default: | |
2391 | ret = -EOPNOTSUPP; | |
2392 | break; | |
94a79942 LF |
2393 | } |
2394 | ||
2395 | out: | |
3044975f | 2396 | mutex_unlock(&priv->wx_mutex); |
94a79942 LF |
2397 | |
2398 | return ret; | |
2399 | } | |
2400 | ||
94a79942 | 2401 | |
87e01f22 | 2402 | static irqreturn_t _rtl92e_irq(int irq, void *netdev) |
94a79942 | 2403 | { |
314e4be7 | 2404 | struct net_device *dev = netdev; |
a4eed41f | 2405 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 LF |
2406 | unsigned long flags; |
2407 | u32 inta; | |
2408 | u32 intb; | |
3a6b70c3 | 2409 | |
94a79942 LF |
2410 | intb = 0; |
2411 | ||
1344ee25 | 2412 | if (priv->irq_enabled == 0) |
94a79942 | 2413 | goto done; |
94a79942 | 2414 | |
1344ee25 | 2415 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
94a79942 LF |
2416 | |
2417 | priv->ops->interrupt_recognized(dev, &inta, &intb); | |
2418 | priv->stats.shints++; | |
2419 | ||
2420 | if (!inta) { | |
1344ee25 | 2421 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
2422 | goto done; |
2423 | } | |
2424 | ||
2425 | if (inta == 0xffff) { | |
1344ee25 | 2426 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
2427 | goto done; |
2428 | } | |
2429 | ||
2430 | priv->stats.ints++; | |
2431 | ||
2432 | if (!netif_running(dev)) { | |
1344ee25 | 2433 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
2434 | goto done; |
2435 | } | |
2436 | ||
1344ee25 | 2437 | if (inta & IMR_TBDOK) { |
94a79942 LF |
2438 | RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); |
2439 | priv->stats.txbeaconokint++; | |
2440 | } | |
2441 | ||
1344ee25 | 2442 | if (inta & IMR_TBDER) { |
94a79942 LF |
2443 | RT_TRACE(COMP_INTR, "beacon ok interrupt!\n"); |
2444 | priv->stats.txbeaconerr++; | |
2445 | } | |
94a79942 | 2446 | |
1344ee25 | 2447 | if (inta & IMR_BDOK) |
94a79942 | 2448 | RT_TRACE(COMP_INTR, "beacon interrupt!\n"); |
94a79942 | 2449 | |
1344ee25 | 2450 | if (inta & IMR_MGNTDOK) { |
94a79942 LF |
2451 | RT_TRACE(COMP_INTR, "Manage ok interrupt!\n"); |
2452 | priv->stats.txmanageokint++; | |
7effc87b | 2453 | _rtl92e_tx_isr(dev, MGNT_QUEUE); |
1344ee25 LF |
2454 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
2455 | if (priv->rtllib->ack_tx_to_ieee) { | |
6f8d4a7d | 2456 | if (_rtl92e_is_tx_queue_empty(dev)) { |
94a79942 LF |
2457 | priv->rtllib->ack_tx_to_ieee = 0; |
2458 | rtllib_ps_tx_ack(priv->rtllib, 1); | |
2459 | } | |
2460 | } | |
1344ee25 | 2461 | spin_lock_irqsave(&priv->irq_th_lock, flags); |
94a79942 LF |
2462 | } |
2463 | ||
94a79942 LF |
2464 | if (inta & IMR_COMDOK) { |
2465 | priv->stats.txcmdpktokint++; | |
7effc87b | 2466 | _rtl92e_tx_isr(dev, TXCMD_QUEUE); |
94a79942 | 2467 | } |
94a79942 | 2468 | |
1344ee25 | 2469 | if (inta & IMR_HIGHDOK) |
7effc87b | 2470 | _rtl92e_tx_isr(dev, HIGH_QUEUE); |
94a79942 | 2471 | |
1344ee25 | 2472 | if (inta & IMR_ROK) { |
94a79942 LF |
2473 | priv->stats.rxint++; |
2474 | priv->InterruptLog.nIMR_ROK++; | |
2475 | tasklet_schedule(&priv->irq_rx_tasklet); | |
2476 | } | |
2477 | ||
2478 | if (inta & IMR_BcnInt) { | |
2479 | RT_TRACE(COMP_INTR, "prepare beacon for interrupt!\n"); | |
94a79942 | 2480 | tasklet_schedule(&priv->irq_prepare_beacon_tasklet); |
94a79942 LF |
2481 | } |
2482 | ||
2483 | if (inta & IMR_RDU) { | |
2484 | RT_TRACE(COMP_INTR, "rx descriptor unavailable!\n"); | |
2485 | priv->stats.rxrdu++; | |
8ea54100 MK |
2486 | rtl92e_writel(dev, INTA_MASK, |
2487 | rtl92e_readl(dev, INTA_MASK) & ~IMR_RDU); | |
94a79942 LF |
2488 | tasklet_schedule(&priv->irq_rx_tasklet); |
2489 | } | |
2490 | ||
2491 | if (inta & IMR_RXFOVW) { | |
2492 | RT_TRACE(COMP_INTR, "rx overflow !\n"); | |
2493 | priv->stats.rxoverflow++; | |
2494 | tasklet_schedule(&priv->irq_rx_tasklet); | |
2495 | } | |
2496 | ||
1344ee25 LF |
2497 | if (inta & IMR_TXFOVW) |
2498 | priv->stats.txoverflow++; | |
94a79942 LF |
2499 | |
2500 | if (inta & IMR_BKDOK) { | |
2501 | RT_TRACE(COMP_INTR, "BK Tx OK interrupt!\n"); | |
2502 | priv->stats.txbkokint++; | |
2503 | priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++; | |
7effc87b | 2504 | _rtl92e_tx_isr(dev, BK_QUEUE); |
94a79942 LF |
2505 | } |
2506 | ||
2507 | if (inta & IMR_BEDOK) { | |
2508 | RT_TRACE(COMP_INTR, "BE TX OK interrupt!\n"); | |
2509 | priv->stats.txbeokint++; | |
2510 | priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++; | |
7effc87b | 2511 | _rtl92e_tx_isr(dev, BE_QUEUE); |
94a79942 LF |
2512 | } |
2513 | ||
2514 | if (inta & IMR_VIDOK) { | |
2515 | RT_TRACE(COMP_INTR, "VI TX OK interrupt!\n"); | |
2516 | priv->stats.txviokint++; | |
2517 | priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++; | |
7effc87b | 2518 | _rtl92e_tx_isr(dev, VI_QUEUE); |
94a79942 LF |
2519 | } |
2520 | ||
2521 | if (inta & IMR_VODOK) { | |
2522 | priv->stats.txvookint++; | |
2523 | RT_TRACE(COMP_INTR, "Vo TX OK interrupt!\n"); | |
2524 | priv->rtllib->LinkDetectInfo.NumTxOkInPeriod++; | |
7effc87b | 2525 | _rtl92e_tx_isr(dev, VO_QUEUE); |
94a79942 LF |
2526 | } |
2527 | ||
1344ee25 | 2528 | spin_unlock_irqrestore(&priv->irq_th_lock, flags); |
94a79942 LF |
2529 | |
2530 | done: | |
2531 | ||
94a79942 | 2532 | return IRQ_HANDLED; |
94a79942 LF |
2533 | } |
2534 | ||
2535 | ||
2536 | ||
2537 | /**************************************************************************** | |
1344ee25 | 2538 | ---------------------------- PCI_STUFF--------------------------- |
94a79942 | 2539 | *****************************************************************************/ |
94a79942 | 2540 | static const struct net_device_ops rtl8192_netdev_ops = { |
27d673b0 | 2541 | .ndo_open = _rtl92e_open, |
27cbba60 | 2542 | .ndo_stop = _rtl92e_close, |
ac392655 | 2543 | .ndo_tx_timeout = _rtl92e_tx_timeout, |
09c26de7 | 2544 | .ndo_do_ioctl = _rtl92e_ioctl, |
2002978d | 2545 | .ndo_set_rx_mode = _rtl92e_set_multicast, |
3ef7f1ee | 2546 | .ndo_set_mac_address = _rtl92e_set_mac_adr, |
94a79942 LF |
2547 | .ndo_validate_addr = eth_validate_addr, |
2548 | .ndo_change_mtu = eth_change_mtu, | |
2549 | .ndo_start_xmit = rtllib_xmit, | |
2550 | }; | |
94a79942 | 2551 | |
93cc57b5 MK |
2552 | static int _rtl92e_pci_probe(struct pci_dev *pdev, |
2553 | const struct pci_device_id *id) | |
94a79942 LF |
2554 | { |
2555 | unsigned long ioaddr = 0; | |
2556 | struct net_device *dev = NULL; | |
1344ee25 | 2557 | struct r8192_priv *priv = NULL; |
94a79942 | 2558 | struct rtl819x_ops *ops = (struct rtl819x_ops *)(id->driver_data); |
94a79942 | 2559 | unsigned long pmem_start, pmem_len, pmem_flags; |
35f8673d | 2560 | int err = -ENOMEM; |
1ec3e2f2 | 2561 | u8 revision_id; |
94a79942 | 2562 | |
1344ee25 | 2563 | RT_TRACE(COMP_INIT, "Configuring chip resources"); |
94a79942 | 2564 | |
1344ee25 | 2565 | if (pci_enable_device(pdev)) { |
3b4140af | 2566 | dev_err(&pdev->dev, "Failed to enable PCI device"); |
94a79942 LF |
2567 | return -EIO; |
2568 | } | |
2569 | ||
2570 | pci_set_master(pdev); | |
2571 | ||
1344ee25 LF |
2572 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { |
2573 | if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32))) { | |
d69d2054 MK |
2574 | dev_info(&pdev->dev, |
2575 | "Unable to obtain 32bit DMA for consistent allocations\n"); | |
35f8673d | 2576 | goto err_pci_disable; |
94a79942 LF |
2577 | } |
2578 | } | |
2579 | dev = alloc_rtllib(sizeof(struct r8192_priv)); | |
2580 | if (!dev) | |
35f8673d | 2581 | goto err_pci_disable; |
94a79942 | 2582 | |
35f8673d | 2583 | err = -ENODEV; |
94a79942 | 2584 | |
94a79942 | 2585 | pci_set_drvdata(pdev, dev); |
94a79942 | 2586 | SET_NETDEV_DEV(dev, &pdev->dev); |
94a79942 LF |
2587 | priv = rtllib_priv(dev); |
2588 | priv->rtllib = (struct rtllib_device *)netdev_priv_rsl(dev); | |
1344ee25 LF |
2589 | priv->pdev = pdev; |
2590 | priv->rtllib->pdev = pdev; | |
2591 | if ((pdev->subsystem_vendor == PCI_VENDOR_ID_DLINK) && | |
2592 | (pdev->subsystem_device == 0x3304)) | |
94a79942 | 2593 | priv->rtllib->bSupportRemoteWakeUp = 1; |
cb762154 | 2594 | else |
94a79942 | 2595 | priv->rtllib->bSupportRemoteWakeUp = 0; |
94a79942 | 2596 | |
94a79942 LF |
2597 | pmem_start = pci_resource_start(pdev, 1); |
2598 | pmem_len = pci_resource_len(pdev, 1); | |
1344ee25 | 2599 | pmem_flags = pci_resource_flags(pdev, 1); |
94a79942 LF |
2600 | |
2601 | if (!(pmem_flags & IORESOURCE_MEM)) { | |
3b4140af | 2602 | netdev_err(dev, "region #1 not a MMIO resource, aborting"); |
35f8673d | 2603 | goto err_rel_rtllib; |
94a79942 LF |
2604 | } |
2605 | ||
d69d2054 MK |
2606 | dev_info(&pdev->dev, "Memory mapped space start: 0x%08lx\n", |
2607 | pmem_start); | |
94a79942 | 2608 | if (!request_mem_region(pmem_start, pmem_len, DRV_NAME)) { |
3b4140af | 2609 | netdev_err(dev, "request_mem_region failed!"); |
35f8673d | 2610 | goto err_rel_rtllib; |
94a79942 LF |
2611 | } |
2612 | ||
2613 | ||
1344ee25 LF |
2614 | ioaddr = (unsigned long)ioremap_nocache(pmem_start, pmem_len); |
2615 | if (ioaddr == (unsigned long)NULL) { | |
3b4140af | 2616 | netdev_err(dev, "ioremap failed!"); |
35f8673d | 2617 | goto err_rel_mem; |
94a79942 LF |
2618 | } |
2619 | ||
2620 | dev->mem_start = ioaddr; | |
2621 | dev->mem_end = ioaddr + pci_resource_len(pdev, 0); | |
2622 | ||
1ec3e2f2 MM |
2623 | pci_read_config_byte(pdev, 0x08, &revision_id); |
2624 | /* If the revisionid is 0x10, the device uses rtl8192se. */ | |
2625 | if (pdev->device == 0x8192 && revision_id == 0x10) | |
948fa942 | 2626 | goto err_unmap; |
1ec3e2f2 | 2627 | |
94a79942 | 2628 | priv->ops = ops; |
94a79942 | 2629 | |
e250592e | 2630 | if (rtl92e_check_adapter(pdev, dev) == false) |
948fa942 | 2631 | goto err_unmap; |
94a79942 LF |
2632 | |
2633 | dev->irq = pdev->irq; | |
2634 | priv->irq = 0; | |
2635 | ||
94a79942 | 2636 | dev->netdev_ops = &rtl8192_netdev_ops; |
94a79942 | 2637 | |
5169af23 | 2638 | dev->wireless_handlers = &r8192_wx_handlers_def; |
94a79942 | 2639 | dev->ethtool_ops = &rtl819x_ethtool_ops; |
94a79942 LF |
2640 | |
2641 | dev->type = ARPHRD_ETHER; | |
1344ee25 | 2642 | dev->watchdog_timeo = HZ * 3; |
94a79942 | 2643 | |
1344ee25 | 2644 | if (dev_alloc_name(dev, ifname) < 0) { |
0822339b MK |
2645 | RT_TRACE(COMP_INIT, |
2646 | "Oops: devname already taken! Trying wlan%%d...\n"); | |
1344ee25 LF |
2647 | dev_alloc_name(dev, ifname); |
2648 | } | |
94a79942 LF |
2649 | |
2650 | RT_TRACE(COMP_INIT, "Driver probe completed1\n"); | |
6bd5e8e0 | 2651 | if (_rtl92e_init(dev) != 0) { |
3b4140af | 2652 | netdev_warn(dev, "Initialization failed"); |
35f8673d | 2653 | goto err_free_irq; |
94a79942 LF |
2654 | } |
2655 | ||
94a79942 LF |
2656 | netif_carrier_off(dev); |
2657 | netif_stop_queue(dev); | |
2658 | ||
4087641b KAM |
2659 | if (register_netdev(dev)) |
2660 | goto err_free_irq; | |
1344ee25 | 2661 | RT_TRACE(COMP_INIT, "dev name: %s\n", dev->name); |
80c0d83a | 2662 | |
1344ee25 | 2663 | if (priv->polling_timer_on == 0) |
a643d927 | 2664 | rtl92e_check_rfctrl_gpio_timer((unsigned long)dev); |
94a79942 | 2665 | |
94a79942 LF |
2666 | RT_TRACE(COMP_INIT, "Driver probe completed\n"); |
2667 | return 0; | |
2668 | ||
35f8673d LF |
2669 | err_free_irq: |
2670 | free_irq(dev->irq, dev); | |
2671 | priv->irq = 0; | |
948fa942 MK |
2672 | err_unmap: |
2673 | iounmap((void __iomem *)ioaddr); | |
35f8673d LF |
2674 | err_rel_mem: |
2675 | release_mem_region(pmem_start, pmem_len); | |
2676 | err_rel_rtllib: | |
2677 | free_rtllib(dev); | |
35f8673d LF |
2678 | err_pci_disable: |
2679 | pci_disable_device(pdev); | |
2680 | return err; | |
94a79942 LF |
2681 | } |
2682 | ||
4a851821 | 2683 | static void _rtl92e_pci_disconnect(struct pci_dev *pdev) |
94a79942 LF |
2684 | { |
2685 | struct net_device *dev = pci_get_drvdata(pdev); | |
dc986e3e | 2686 | struct r8192_priv *priv; |
1344ee25 LF |
2687 | u32 i; |
2688 | ||
2689 | if (dev) { | |
94a79942 LF |
2690 | unregister_netdev(dev); |
2691 | ||
2692 | priv = rtllib_priv(dev); | |
2693 | ||
94a79942 | 2694 | del_timer_sync(&priv->gpio_polling_timer); |
ecfdd3a0 | 2695 | cancel_delayed_work_sync(&priv->gpio_change_rf_wq); |
94a79942 | 2696 | priv->polling_timer_on = 0; |
33bec9bd | 2697 | _rtl92e_down(dev, true); |
fd9e3171 | 2698 | rtl92e_dm_deinit(dev); |
cb762154 | 2699 | if (priv->pFirmware) { |
94a79942 LF |
2700 | vfree(priv->pFirmware); |
2701 | priv->pFirmware = NULL; | |
2702 | } | |
694f9d30 | 2703 | _rtl92e_free_rx_ring(dev); |
1344ee25 | 2704 | for (i = 0; i < MAX_TX_QUEUE_COUNT; i++) |
ebc36ecd | 2705 | _rtl92e_free_tx_ring(dev, i); |
94a79942 | 2706 | |
1344ee25 | 2707 | if (priv->irq) { |
d69d2054 | 2708 | dev_info(&pdev->dev, "Freeing irq %d\n", dev->irq); |
94a79942 | 2709 | free_irq(dev->irq, dev); |
1344ee25 | 2710 | priv->irq = 0; |
94a79942 | 2711 | } |
94a79942 LF |
2712 | free_rtllib(dev); |
2713 | ||
66898177 | 2714 | if (dev->mem_start != 0) { |
49aab5fd | 2715 | iounmap((void __iomem *)dev->mem_start); |
66898177 | 2716 | release_mem_region(pci_resource_start(pdev, 1), |
1344ee25 | 2717 | pci_resource_len(pdev, 1)); |
66898177 | 2718 | } |
1344ee25 LF |
2719 | } else { |
2720 | priv = rtllib_priv(dev); | |
2721 | } | |
94a79942 LF |
2722 | |
2723 | pci_disable_device(pdev); | |
94a79942 LF |
2724 | RT_TRACE(COMP_DOWN, "wlan driver removed\n"); |
2725 | } | |
2726 | ||
502bd1d7 | 2727 | bool rtl92e_enable_nic(struct net_device *dev) |
94a79942 LF |
2728 | { |
2729 | bool init_status = true; | |
1344ee25 LF |
2730 | struct r8192_priv *priv = rtllib_priv(dev); |
2731 | struct rt_pwr_save_ctrl *pPSC = (struct rt_pwr_save_ctrl *) | |
2732 | (&(priv->rtllib->PowerSaveControl)); | |
94a79942 | 2733 | |
5dc42962 | 2734 | if (!priv->up) { |
3b4140af | 2735 | netdev_warn(dev, "%s(): Driver is already down!\n", __func__); |
94a79942 | 2736 | priv->bdisable_nic = false; |
7626e3d0 | 2737 | return false; |
94a79942 LF |
2738 | } |
2739 | ||
1344ee25 | 2740 | RT_TRACE(COMP_PS, "===========>%s()\n", __func__); |
94a79942 LF |
2741 | priv->bfirst_init = true; |
2742 | init_status = priv->ops->initialize_adapter(dev); | |
4bb01423 | 2743 | if (!init_status) { |
3b4140af | 2744 | netdev_warn(dev, "%s(): Initialization failed!\n", __func__); |
94a79942 | 2745 | priv->bdisable_nic = false; |
7626e3d0 | 2746 | return false; |
94a79942 LF |
2747 | } |
2748 | RT_TRACE(COMP_INIT, "start adapter finished\n"); | |
2749 | RT_CLEAR_PS_LEVEL(pPSC, RT_RF_OFF_LEVL_HALT_NIC); | |
2750 | priv->bfirst_init = false; | |
2751 | ||
b74299cd | 2752 | rtl92e_irq_enable(dev); |
94a79942 | 2753 | priv->bdisable_nic = false; |
1344ee25 | 2754 | RT_TRACE(COMP_PS, "<===========%s()\n", __func__); |
94a79942 LF |
2755 | return init_status; |
2756 | } | |
af002dc6 | 2757 | bool rtl92e_disable_nic(struct net_device *dev) |
94a79942 | 2758 | { |
1344ee25 | 2759 | struct r8192_priv *priv = rtllib_priv(dev); |
94a79942 | 2760 | u8 tmp_state = 0; |
3a6b70c3 | 2761 | |
1344ee25 | 2762 | RT_TRACE(COMP_PS, "=========>%s()\n", __func__); |
94a79942 LF |
2763 | priv->bdisable_nic = true; |
2764 | tmp_state = priv->rtllib->state; | |
2765 | rtllib_softmac_stop_protocol(priv->rtllib, 0, false); | |
2766 | priv->rtllib->state = tmp_state; | |
4dba03a2 | 2767 | _rtl92e_cancel_deferred_work(priv); |
b7b50d65 | 2768 | rtl92e_irq_disable(dev); |
94a79942 LF |
2769 | |
2770 | priv->ops->stop_adapter(dev, false); | |
1344ee25 | 2771 | RT_TRACE(COMP_PS, "<=========%s()\n", __func__); |
94a79942 | 2772 | |
e623d0f3 | 2773 | return true; |
94a79942 LF |
2774 | } |
2775 | ||
c1ccdddc | 2776 | module_pci_driver(rtl8192_pci_driver); |
94a79942 | 2777 | |
a643d927 | 2778 | void rtl92e_check_rfctrl_gpio_timer(unsigned long data) |
94a79942 | 2779 | { |
1344ee25 | 2780 | struct r8192_priv *priv = rtllib_priv((struct net_device *)data); |
94a79942 LF |
2781 | |
2782 | priv->polling_timer_on = 1; | |
2783 | ||
ecfdd3a0 | 2784 | schedule_delayed_work(&priv->gpio_change_rf_wq, 0); |
94a79942 | 2785 | |
1344ee25 | 2786 | mod_timer(&priv->gpio_polling_timer, jiffies + |
8b9733c1 | 2787 | msecs_to_jiffies(RTLLIB_WATCH_DOG_TIME)); |
94a79942 LF |
2788 | } |
2789 | ||
2790 | /*************************************************************************** | |
1344ee25 | 2791 | ------------------- module init / exit stubs ---------------- |
94a79942 | 2792 | ****************************************************************************/ |
94a79942 LF |
2793 | MODULE_DESCRIPTION("Linux driver for Realtek RTL819x WiFi cards"); |
2794 | MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR); | |
94a79942 | 2795 | MODULE_VERSION(DRV_VERSION); |
94a79942 | 2796 | MODULE_LICENSE("GPL"); |
7f34f412 TG |
2797 | MODULE_FIRMWARE(RTL8192E_BOOT_IMG_FW); |
2798 | MODULE_FIRMWARE(RTL8192E_MAIN_IMG_FW); | |
2799 | MODULE_FIRMWARE(RTL8192E_DATA_IMG_FW); | |
94a79942 | 2800 | |
1344ee25 LF |
2801 | module_param(ifname, charp, S_IRUGO|S_IWUSR); |
2802 | module_param(hwwep, int, S_IRUGO|S_IWUSR); | |
2803 | module_param(channels, int, S_IRUGO|S_IWUSR); | |
94a79942 | 2804 | |
1344ee25 LF |
2805 | MODULE_PARM_DESC(ifname, " Net interface name, wlan%d=default"); |
2806 | MODULE_PARM_DESC(hwwep, " Try to use hardware WEP support(default use hw. set 0 to use software security)"); | |
2807 | MODULE_PARM_DESC(channels, " Channel bitmask for specific locales. NYI"); |