1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3 *
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
5 *
6 ******************************************************************************/
7 #define _OS_INTFS_C_
8
9 #include <drv_types.h>
10 #include <rtw_debug.h>
11 #include <hal_data.h>
12
13 MODULE_LICENSE("GPL");
14 MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
15 MODULE_AUTHOR("Realtek Semiconductor Corp.");
16 MODULE_VERSION(DRIVERVERSION);
17
18 /* module param defaults */
19 static int rtw_chip_version;
20 static int rtw_rfintfs = HWPI;
21 static int rtw_lbkmode;/* RTL8712_AIR_TRX; */
22
23
24 static int rtw_network_mode = Ndis802_11IBSS;/* Ndis802_11Infrastructure;infra, ad-hoc, auto */
25 /* struct ndis_802_11_ssid ssid; */
26 static int rtw_channel = 1;/* ad-hoc support requirement */
27 static int rtw_wireless_mode = WIRELESS_MODE_MAX;
28 static int rtw_vrtl_carrier_sense = AUTO_VCS;
29 static int rtw_vcs_type = RTS_CTS;/* */
30 static int rtw_rts_thresh = 2347;/* */
31 static int rtw_frag_thresh = 2346;/* */
32 static int rtw_preamble = PREAMBLE_LONG;/* long, short, auto */
33 static int rtw_scan_mode = 1;/* active, passive */
34 static int rtw_adhoc_tx_pwr = 1;
35 static int rtw_soft_ap;
36 /* int smart_ps = 1; */
37 static int rtw_power_mgnt = 1;
38 static int rtw_ips_mode = IPS_NORMAL;
39 module_param(rtw_ips_mode, int, 0644);
40 MODULE_PARM_DESC(rtw_ips_mode, "The default IPS mode");
41
42 static int rtw_smart_ps = 2;
43
44 static int rtw_check_fw_ps = 1;
45
46 static int rtw_usb_rxagg_mode = 2;/* USB_RX_AGG_DMA = 1, USB_RX_AGG_USB =2 */
47 module_param(rtw_usb_rxagg_mode, int, 0644);
48
49 static int rtw_radio_enable = 1;
50 static int rtw_long_retry_lmt = 7;
51 static int rtw_short_retry_lmt = 7;
52 static int rtw_busy_thresh = 40;
53 /* int qos_enable = 0; */
54 static int rtw_ack_policy = NORMAL_ACK;
55
56 static int rtw_software_encrypt;
57 static int rtw_software_decrypt;
58
59 static int rtw_acm_method;/* 0:By SW 1:By HW. */
60
61 static int rtw_wmm_enable = 1;/* default is set to enable the wmm. */
62 static int rtw_uapsd_enable;
63 static int rtw_uapsd_max_sp = NO_LIMIT;
64 static int rtw_uapsd_acbk_en;
65 static int rtw_uapsd_acbe_en;
66 static int rtw_uapsd_acvi_en;
67 static int rtw_uapsd_acvo_en;
68
69 int rtw_ht_enable = 1;
70 /* 0: 20 MHz, 1: 40 MHz, 2: 80 MHz, 3: 160MHz, 4: 80+80MHz */
71 /* 2.4G use bit 0 ~ 3, 5G use bit 4 ~ 7 */
72 /* 0x21 means enable 2.4G 40MHz & 5G 80MHz */
73 static int rtw_bw_mode = 0x21;
74 static int rtw_ampdu_enable = 1;/* for enable tx_ampdu ,0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec) */
75 static int rtw_rx_stbc = 1;/* 0: disable, 1:enable 2.4g */
76 static int rtw_ampdu_amsdu;/* 0: disabled, 1:enabled, 2:auto . There is an IOT issu with DLINK DIR-629 when the flag turn on */
77 /* Short GI support Bit Map */
78 /* BIT0 - 20MHz, 0: non-support, 1: support */
79 /* BIT1 - 40MHz, 0: non-support, 1: support */
80 /* BIT2 - 80MHz, 0: non-support, 1: support */
81 /* BIT3 - 160MHz, 0: non-support, 1: support */
82 static int rtw_short_gi = 0xf;
83 /* BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */
84 static int rtw_ldpc_cap = 0x33;
85 /* BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */
86 static int rtw_stbc_cap = 0x13;
87 /* BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee */
88 static int rtw_beamform_cap = 0x2;
89
90 static int rtw_lowrate_two_xmit = 1;/* Use 2 path Tx to transmit MCS0~7 and legacy mode */
91
92 /* int rf_config = RF_1T2R; 1T2R */
93 static int rtw_rf_config = RF_MAX_TYPE; /* auto */
94 static int rtw_low_power;
95 static int rtw_wifi_spec;
96 static int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX;
97
98 static int rtw_btcoex_enable = 1;
99 module_param(rtw_btcoex_enable, int, 0644);
100 MODULE_PARM_DESC(rtw_btcoex_enable, "Enable BT co-existence mechanism");
101 static int rtw_bt_iso = 2;/* 0:Low, 1:High, 2:From Efuse */
102 static int rtw_bt_sco = 3;/* 0:Idle, 1:None-SCO, 2:SCO, 3:From Counter, 4.Busy, 5.OtherBusy */
103 static int rtw_bt_ampdu = 1 ;/* 0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
104 static int rtw_ant_num = -1; /* <0: undefined, >0: Antenna number */
105 module_param(rtw_ant_num, int, 0644);
106 MODULE_PARM_DESC(rtw_ant_num, "Antenna number setting");
107
108 static int rtw_antdiv_cfg = 1; /* 0:OFF , 1:ON, 2:decide by Efuse config */
109 static int rtw_antdiv_type; /* 0:decide by efuse 1: for 88EE, 1Tx and 1RxCG are diversity.(2 Ant with SPDT), 2: for 88EE, 1Tx and 2Rx are diversity.(2 Ant, Tx and RxCG are both on aux port, RxCS is on main port), 3: for 88EE, 1Tx and 1RxCG are fixed.(1Ant, Tx and RxCG are both on aux port) */
110
111
112 static int rtw_enusbss;/* 0:disable, 1:enable */
113
114 static int rtw_hwpdn_mode = 2;/* 0:disable, 1:enable, 2: by EFUSE config */
115
116 #ifdef CONFIG_HW_PWRP_DETECTION
117 static int rtw_hwpwrp_detect = 1;
118 #else
119 static int rtw_hwpwrp_detect; /* HW power ping detect 0:disable , 1:enable */
120 #endif
121
122 static int rtw_hw_wps_pbc;
123
124 int rtw_mc2u_disable = 0;
125
126 static int rtw_80211d;
127
128 #ifdef CONFIG_QOS_OPTIMIZATION
129 static int rtw_qos_opt_enable = 1;/* 0: disable, 1:enable */
130 #else
131 static int rtw_qos_opt_enable;/* 0: disable, 1:enable */
132 #endif
133 module_param(rtw_qos_opt_enable, int, 0644);
134
135 static char *ifname = "wlan%d";
136 module_param(ifname, charp, 0644);
137 MODULE_PARM_DESC(ifname, "The default name to allocate for first interface");
138
139 char *rtw_initmac = NULL; /* temp mac address if users want to use instead of the mac address in Efuse */
140
141 module_param(rtw_initmac, charp, 0644);
142 module_param(rtw_channel_plan, int, 0644);
143 module_param(rtw_chip_version, int, 0644);
144 module_param(rtw_rfintfs, int, 0644);
145 module_param(rtw_lbkmode, int, 0644);
146 module_param(rtw_network_mode, int, 0644);
147 module_param(rtw_channel, int, 0644);
148 module_param(rtw_wmm_enable, int, 0644);
149 module_param(rtw_vrtl_carrier_sense, int, 0644);
150 module_param(rtw_vcs_type, int, 0644);
151 module_param(rtw_busy_thresh, int, 0644);
152
153 module_param(rtw_ht_enable, int, 0644);
154 module_param(rtw_bw_mode, int, 0644);
155 module_param(rtw_ampdu_enable, int, 0644);
156 module_param(rtw_rx_stbc, int, 0644);
157 module_param(rtw_ampdu_amsdu, int, 0644);
158
159 module_param(rtw_lowrate_two_xmit, int, 0644);
160
161 module_param(rtw_rf_config, int, 0644);
162 module_param(rtw_power_mgnt, int, 0644);
163 module_param(rtw_smart_ps, int, 0644);
164 module_param(rtw_low_power, int, 0644);
165 module_param(rtw_wifi_spec, int, 0644);
166
167 module_param(rtw_antdiv_cfg, int, 0644);
168 module_param(rtw_antdiv_type, int, 0644);
169
170 module_param(rtw_enusbss, int, 0644);
171 module_param(rtw_hwpdn_mode, int, 0644);
172 module_param(rtw_hwpwrp_detect, int, 0644);
173
174 module_param(rtw_hw_wps_pbc, int, 0644);
175
176 static uint rtw_max_roaming_times = 2;
177 module_param(rtw_max_roaming_times, uint, 0644);
178 MODULE_PARM_DESC(rtw_max_roaming_times, "The max roaming times to try");
179
180 module_param(rtw_mc2u_disable, int, 0644);
181
182 module_param(rtw_80211d, int, 0644);
183 MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism");
184
185 static uint rtw_notch_filter;
186 module_param(rtw_notch_filter, uint, 0644);
187 MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P");
188
189 #define CONFIG_RTW_HIQ_FILTER 1
190
191 static uint rtw_hiq_filter = CONFIG_RTW_HIQ_FILTER;
192 module_param(rtw_hiq_filter, uint, 0644);
193 MODULE_PARM_DESC(rtw_hiq_filter, "0:allow all, 1:allow special, 2:deny all");
194
195 static int rtw_tx_pwr_lmt_enable;
196 static int rtw_tx_pwr_by_rate;
197
198 module_param(rtw_tx_pwr_lmt_enable, int, 0644);
199 MODULE_PARM_DESC(rtw_tx_pwr_lmt_enable, "0:Disable, 1:Enable, 2: Depend on efuse");
200
201 module_param(rtw_tx_pwr_by_rate, int, 0644);
202 MODULE_PARM_DESC(rtw_tx_pwr_by_rate, "0:Disable, 1:Enable, 2: Depend on efuse");
203
204 int _netdev_open(struct net_device *pnetdev);
205 int netdev_open(struct net_device *pnetdev);
206 static int netdev_close(struct net_device *pnetdev);
207
loadparam(struct adapter * padapter,_nic_hdl pnetdev)208 static void loadparam(struct adapter *padapter, _nic_hdl pnetdev)
209 {
210 struct registry_priv *registry_par = &padapter->registrypriv;
211
212 registry_par->chip_version = (u8)rtw_chip_version;
213 registry_par->rfintfs = (u8)rtw_rfintfs;
214 registry_par->lbkmode = (u8)rtw_lbkmode;
215 /* registry_par->hci = (u8)hci; */
216 registry_par->network_mode = (u8)rtw_network_mode;
217
218 memcpy(registry_par->ssid.Ssid, "ANY", 3);
219 registry_par->ssid.SsidLength = 3;
220
221 registry_par->channel = (u8)rtw_channel;
222 registry_par->wireless_mode = (u8)rtw_wireless_mode;
223
224 registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense;
225 registry_par->vcs_type = (u8)rtw_vcs_type;
226 registry_par->rts_thresh = (u16)rtw_rts_thresh;
227 registry_par->frag_thresh = (u16)rtw_frag_thresh;
228 registry_par->preamble = (u8)rtw_preamble;
229 registry_par->scan_mode = (u8)rtw_scan_mode;
230 registry_par->adhoc_tx_pwr = (u8)rtw_adhoc_tx_pwr;
231 registry_par->soft_ap = (u8)rtw_soft_ap;
232 registry_par->smart_ps = (u8)rtw_smart_ps;
233 registry_par->check_fw_ps = (u8)rtw_check_fw_ps;
234 registry_par->power_mgnt = (u8)rtw_power_mgnt;
235 registry_par->ips_mode = (u8)rtw_ips_mode;
236 registry_par->radio_enable = (u8)rtw_radio_enable;
237 registry_par->long_retry_lmt = (u8)rtw_long_retry_lmt;
238 registry_par->short_retry_lmt = (u8)rtw_short_retry_lmt;
239 registry_par->busy_thresh = (u16)rtw_busy_thresh;
240 /* registry_par->qos_enable = (u8)rtw_qos_enable; */
241 registry_par->ack_policy = (u8)rtw_ack_policy;
242 registry_par->software_encrypt = (u8)rtw_software_encrypt;
243 registry_par->software_decrypt = (u8)rtw_software_decrypt;
244
245 registry_par->acm_method = (u8)rtw_acm_method;
246 registry_par->usb_rxagg_mode = (u8)rtw_usb_rxagg_mode;
247
248 /* UAPSD */
249 registry_par->wmm_enable = (u8)rtw_wmm_enable;
250 registry_par->uapsd_enable = (u8)rtw_uapsd_enable;
251 registry_par->uapsd_max_sp = (u8)rtw_uapsd_max_sp;
252 registry_par->uapsd_acbk_en = (u8)rtw_uapsd_acbk_en;
253 registry_par->uapsd_acbe_en = (u8)rtw_uapsd_acbe_en;
254 registry_par->uapsd_acvi_en = (u8)rtw_uapsd_acvi_en;
255 registry_par->uapsd_acvo_en = (u8)rtw_uapsd_acvo_en;
256
257 registry_par->ht_enable = (u8)rtw_ht_enable;
258 registry_par->bw_mode = (u8)rtw_bw_mode;
259 registry_par->ampdu_enable = (u8)rtw_ampdu_enable;
260 registry_par->rx_stbc = (u8)rtw_rx_stbc;
261 registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu;
262 registry_par->short_gi = (u8)rtw_short_gi;
263 registry_par->ldpc_cap = (u8)rtw_ldpc_cap;
264 registry_par->stbc_cap = (u8)rtw_stbc_cap;
265 registry_par->beamform_cap = (u8)rtw_beamform_cap;
266
267 registry_par->lowrate_two_xmit = (u8)rtw_lowrate_two_xmit;
268 registry_par->rf_config = (u8)rtw_rf_config;
269 registry_par->low_power = (u8)rtw_low_power;
270
271
272 registry_par->wifi_spec = (u8)rtw_wifi_spec;
273
274 registry_par->channel_plan = (u8)rtw_channel_plan;
275
276 registry_par->btcoex = (u8)rtw_btcoex_enable;
277 registry_par->bt_iso = (u8)rtw_bt_iso;
278 registry_par->bt_sco = (u8)rtw_bt_sco;
279 registry_par->bt_ampdu = (u8)rtw_bt_ampdu;
280 registry_par->ant_num = (s8)rtw_ant_num;
281
282 registry_par->accept_addba_req = true;
283
284 registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg;
285 registry_par->antdiv_type = (u8)rtw_antdiv_type;
286
287 registry_par->hw_wps_pbc = (u8)rtw_hw_wps_pbc;
288
289 registry_par->max_roaming_times = (u8)rtw_max_roaming_times;
290
291 registry_par->enable80211d = (u8)rtw_80211d;
292
293 snprintf(registry_par->ifname, 16, "%s", ifname);
294
295 registry_par->notch_filter = (u8)rtw_notch_filter;
296
297 registry_par->RegEnableTxPowerLimit = (u8)rtw_tx_pwr_lmt_enable;
298 registry_par->RegEnableTxPowerByRate = (u8)rtw_tx_pwr_by_rate;
299
300 registry_par->RegPowerBase = 14;
301 registry_par->TxBBSwing_2G = 0xFF;
302 registry_par->TxBBSwing_5G = 0xFF;
303 registry_par->bEn_RFE = 1;
304 registry_par->RFE_Type = 64;
305
306 registry_par->qos_opt_enable = (u8)rtw_qos_opt_enable;
307
308 registry_par->hiq_filter = (u8)rtw_hiq_filter;
309 }
310
rtw_net_set_mac_address(struct net_device * pnetdev,void * p)311 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
312 {
313 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
314 struct sockaddr *addr = p;
315
316 if (!padapter->bup) {
317 /* DBG_871X("r8711_net_set_mac_address(), MAC =%x:%x:%x:%x:%x:%x\n", addr->sa_data[0], addr->sa_data[1], addr->sa_data[2], addr->sa_data[3], */
318 /* addr->sa_data[4], addr->sa_data[5]); */
319 memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN);
320 /* memcpy(pnetdev->dev_addr, addr->sa_data, ETH_ALEN); */
321 /* padapter->bset_hwaddr = true; */
322 }
323
324 return 0;
325 }
326
rtw_net_get_stats(struct net_device * pnetdev)327 static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev)
328 {
329 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
330 struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
331 struct recv_priv *precvpriv = &(padapter->recvpriv);
332
333 padapter->stats.tx_packets = pxmitpriv->tx_pkts;/* pxmitpriv->tx_pkts++; */
334 padapter->stats.rx_packets = precvpriv->rx_pkts;/* precvpriv->rx_pkts++; */
335 padapter->stats.tx_dropped = pxmitpriv->tx_drop;
336 padapter->stats.rx_dropped = precvpriv->rx_drop;
337 padapter->stats.tx_bytes = pxmitpriv->tx_bytes;
338 padapter->stats.rx_bytes = precvpriv->rx_bytes;
339
340 return &padapter->stats;
341 }
342
343 /*
344 * AC to queue mapping
345 *
346 * AC_VO -> queue 0
347 * AC_VI -> queue 1
348 * AC_BE -> queue 2
349 * AC_BK -> queue 3
350 */
351 static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
352
353 /* Given a data frame determine the 802.1p/1d tag to use. */
rtw_classify8021d(struct sk_buff * skb)354 static unsigned int rtw_classify8021d(struct sk_buff *skb)
355 {
356 unsigned int dscp;
357
358 /* skb->priority values from 256->263 are magic values to
359 * directly indicate a specific 802.1d priority. This is used
360 * to allow 802.1d priority to be passed directly in from VLAN
361 * tags, etc.
362 */
363 if (skb->priority >= 256 && skb->priority <= 263)
364 return skb->priority - 256;
365
366 switch (skb->protocol) {
367 case htons(ETH_P_IP):
368 dscp = ip_hdr(skb)->tos & 0xfc;
369 break;
370 default:
371 return 0;
372 }
373
374 return dscp >> 5;
375 }
376
377
rtw_select_queue(struct net_device * dev,struct sk_buff * skb,struct net_device * sb_dev)378 static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
379 struct net_device *sb_dev)
380 {
381 struct adapter *padapter = rtw_netdev_priv(dev);
382 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
383
384 skb->priority = rtw_classify8021d(skb);
385
386 if (pmlmepriv->acm_mask != 0)
387 skb->priority = qos_acm(pmlmepriv->acm_mask, skb->priority);
388
389 return rtw_1d_to_queue[skb->priority];
390 }
391
rtw_recv_select_queue(struct sk_buff * skb)392 u16 rtw_recv_select_queue(struct sk_buff *skb)
393 {
394 struct iphdr *piphdr;
395 unsigned int dscp;
396 __be16 eth_type;
397 u32 priority;
398 u8 *pdata = skb->data;
399
400 memcpy(ð_type, pdata + (ETH_ALEN << 1), 2);
401
402 switch (be16_to_cpu(eth_type)) {
403 case ETH_P_IP:
404
405 piphdr = (struct iphdr *)(pdata + ETH_HLEN);
406
407 dscp = piphdr->tos & 0xfc;
408
409 priority = dscp >> 5;
410
411 break;
412 default:
413 priority = 0;
414 }
415
416 return rtw_1d_to_queue[priority];
417 }
418
rtw_ndev_notifier_call(struct notifier_block * nb,unsigned long state,void * ptr)419 static int rtw_ndev_notifier_call(struct notifier_block *nb, unsigned long state, void *ptr)
420 {
421 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
422
423 if (dev->netdev_ops->ndo_do_ioctl != rtw_ioctl)
424 return NOTIFY_DONE;
425
426 DBG_871X_LEVEL(_drv_info_, FUNC_NDEV_FMT " state:%lu\n", FUNC_NDEV_ARG(dev), state);
427
428 return NOTIFY_DONE;
429 }
430
431 static struct notifier_block rtw_ndev_notifier = {
432 .notifier_call = rtw_ndev_notifier_call,
433 };
434
rtw_ndev_notifier_register(void)435 int rtw_ndev_notifier_register(void)
436 {
437 return register_netdevice_notifier(&rtw_ndev_notifier);
438 }
439
rtw_ndev_notifier_unregister(void)440 void rtw_ndev_notifier_unregister(void)
441 {
442 unregister_netdevice_notifier(&rtw_ndev_notifier);
443 }
444
445
rtw_ndev_init(struct net_device * dev)446 static int rtw_ndev_init(struct net_device *dev)
447 {
448 struct adapter *adapter = rtw_netdev_priv(dev);
449
450 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
451 strncpy(adapter->old_ifname, dev->name, IFNAMSIZ);
452
453 return 0;
454 }
455
rtw_ndev_uninit(struct net_device * dev)456 static void rtw_ndev_uninit(struct net_device *dev)
457 {
458 struct adapter *adapter = rtw_netdev_priv(dev);
459
460 DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
461 }
462
463 static const struct net_device_ops rtw_netdev_ops = {
464 .ndo_init = rtw_ndev_init,
465 .ndo_uninit = rtw_ndev_uninit,
466 .ndo_open = netdev_open,
467 .ndo_stop = netdev_close,
468 .ndo_start_xmit = rtw_xmit_entry,
469 .ndo_select_queue = rtw_select_queue,
470 .ndo_set_mac_address = rtw_net_set_mac_address,
471 .ndo_get_stats = rtw_net_get_stats,
472 .ndo_do_ioctl = rtw_ioctl,
473 };
474
rtw_init_netdev_name(struct net_device * pnetdev,const char * ifname)475 int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname)
476 {
477 if (dev_alloc_name(pnetdev, ifname) < 0) {
478 pr_err("dev_alloc_name, fail for %s\n", ifname);
479 return 1;
480 }
481 netif_carrier_off(pnetdev);
482 /* rtw_netif_stop_queue(pnetdev); */
483
484 return 0;
485 }
486
rtw_init_netdev(struct adapter * old_padapter)487 struct net_device *rtw_init_netdev(struct adapter *old_padapter)
488 {
489 struct adapter *padapter;
490 struct net_device *pnetdev;
491
492 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+init_net_dev\n"));
493
494 if (old_padapter != NULL)
495 pnetdev = rtw_alloc_etherdev_with_old_priv(sizeof(struct adapter), (void *)old_padapter);
496 else
497 pnetdev = rtw_alloc_etherdev(sizeof(struct adapter));
498
499 pr_info("pnetdev = %p\n", pnetdev);
500 if (!pnetdev)
501 return NULL;
502
503 padapter = rtw_netdev_priv(pnetdev);
504 padapter->pnetdev = pnetdev;
505
506 /* pnetdev->init = NULL; */
507
508 DBG_871X("register rtw_netdev_ops to netdev_ops\n");
509 pnetdev->netdev_ops = &rtw_netdev_ops;
510
511 /* pnetdev->tx_timeout = NULL; */
512 pnetdev->watchdog_timeo = HZ * 3; /* 3 second timeout */
513 pnetdev->wireless_handlers = (struct iw_handler_def *)&rtw_handlers_def;
514
515 /* step 2. */
516 loadparam(padapter, pnetdev);
517
518 return pnetdev;
519 }
520
rtw_unregister_netdevs(struct dvobj_priv * dvobj)521 void rtw_unregister_netdevs(struct dvobj_priv *dvobj)
522 {
523 struct adapter *padapter = NULL;
524 struct net_device *pnetdev = NULL;
525
526 padapter = dvobj->padapters;
527
528 if (padapter == NULL)
529 return;
530
531 pnetdev = padapter->pnetdev;
532
533 if ((padapter->DriverState != DRIVER_DISAPPEAR) && pnetdev)
534 unregister_netdev(pnetdev); /* will call netdev_close() */
535 rtw_wdev_unregister(padapter->rtw_wdev);
536 }
537
rtw_start_drv_threads(struct adapter * padapter)538 u32 rtw_start_drv_threads(struct adapter *padapter)
539 {
540 u32 _status = _SUCCESS;
541
542 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_start_drv_threads\n"));
543 padapter->xmitThread = kthread_run(rtw_xmit_thread, padapter, "RTW_XMIT_THREAD");
544 if (IS_ERR(padapter->xmitThread))
545 _status = _FAIL;
546
547 padapter->cmdThread = kthread_run(rtw_cmd_thread, padapter, "RTW_CMD_THREAD");
548 if (IS_ERR(padapter->cmdThread))
549 _status = _FAIL;
550 else
551 wait_for_completion(&padapter->cmdpriv.terminate_cmdthread_comp); /* wait for cmd_thread to run */
552
553 rtw_hal_start_thread(padapter);
554 return _status;
555 }
556
rtw_stop_drv_threads(struct adapter * padapter)557 void rtw_stop_drv_threads(struct adapter *padapter)
558 {
559 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
560
561 rtw_stop_cmd_thread(padapter);
562
563 /* Below is to termindate tx_thread... */
564 complete(&padapter->xmitpriv.xmit_comp);
565 wait_for_completion(&padapter->xmitpriv.terminate_xmitthread_comp);
566 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("\n drv_halt: rtw_xmit_thread can be terminated !\n"));
567
568 rtw_hal_stop_thread(padapter);
569 }
570
rtw_init_default_value(struct adapter * padapter)571 static void rtw_init_default_value(struct adapter *padapter)
572 {
573 struct registry_priv *pregistrypriv = &padapter->registrypriv;
574 struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
575 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
576 struct security_priv *psecuritypriv = &padapter->securitypriv;
577
578 /* xmit_priv */
579 pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
580 pxmitpriv->vcs = pregistrypriv->vcs_type;
581 pxmitpriv->vcs_type = pregistrypriv->vcs_type;
582 /* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */
583 pxmitpriv->frag_len = pregistrypriv->frag_thresh;
584
585 /* recv_priv */
586
587 /* mlme_priv */
588 pmlmepriv->scan_mode = SCAN_ACTIVE;
589
590 /* qos_priv */
591 /* pmlmepriv->qospriv.qos_option = pregistrypriv->wmm_enable; */
592
593 /* ht_priv */
594 pmlmepriv->htpriv.ampdu_enable = false;/* set to disabled */
595
596 /* security_priv */
597 /* rtw_get_encrypt_decrypt_from_registrypriv(padapter); */
598 psecuritypriv->binstallGrpkey = _FAIL;
599 #ifdef CONFIG_GTK_OL
600 psecuritypriv->binstallKCK_KEK = _FAIL;
601 #endif /* CONFIG_GTK_OL */
602 psecuritypriv->sw_encrypt = pregistrypriv->software_encrypt;
603 psecuritypriv->sw_decrypt = pregistrypriv->software_decrypt;
604
605 psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
606 psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
607
608 psecuritypriv->dot11PrivacyKeyIndex = 0;
609
610 psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
611 psecuritypriv->dot118021XGrpKeyid = 1;
612
613 psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
614 psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled;
615
616 /* registry_priv */
617 rtw_init_registrypriv_dev_network(padapter);
618 rtw_update_registrypriv_dev_network(padapter);
619
620 /* hal_priv */
621 rtw_hal_def_value_init(padapter);
622
623 /* misc. */
624 RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
625 RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
626 padapter->bLinkInfoDump = 0;
627 padapter->bNotifyChannelChange = 0;
628
629 /* for debug purpose */
630 padapter->fix_rate = 0xFF;
631 padapter->driver_ampdu_spacing = 0xFF;
632 padapter->driver_rx_ampdu_factor = 0xFF;
633
634 }
635
devobj_init(void)636 struct dvobj_priv *devobj_init(void)
637 {
638 struct dvobj_priv *pdvobj = NULL;
639
640 pdvobj = rtw_zmalloc(sizeof(*pdvobj));
641 if (pdvobj == NULL)
642 return NULL;
643
644 mutex_init(&pdvobj->hw_init_mutex);
645 mutex_init(&pdvobj->h2c_fwcmd_mutex);
646 mutex_init(&pdvobj->setch_mutex);
647 mutex_init(&pdvobj->setbw_mutex);
648
649 spin_lock_init(&pdvobj->lock);
650
651 pdvobj->macid[1] = true; /* macid = 1 for bc/mc stainfo */
652
653 pdvobj->processing_dev_remove = false;
654
655 atomic_set(&pdvobj->disable_func, 0);
656
657 spin_lock_init(&pdvobj->cam_ctl.lock);
658
659 return pdvobj;
660 }
661
devobj_deinit(struct dvobj_priv * pdvobj)662 void devobj_deinit(struct dvobj_priv *pdvobj)
663 {
664 if (!pdvobj)
665 return;
666
667 mutex_destroy(&pdvobj->hw_init_mutex);
668 mutex_destroy(&pdvobj->h2c_fwcmd_mutex);
669 mutex_destroy(&pdvobj->setch_mutex);
670 mutex_destroy(&pdvobj->setbw_mutex);
671
672 kfree(pdvobj);
673 }
674
rtw_reset_drv_sw(struct adapter * padapter)675 void rtw_reset_drv_sw(struct adapter *padapter)
676 {
677 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
678 struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
679
680 /* hal_priv */
681 if (is_primary_adapter(padapter))
682 rtw_hal_def_value_init(padapter);
683
684 RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
685 RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
686 padapter->bLinkInfoDump = 0;
687
688 padapter->xmitpriv.tx_pkts = 0;
689 padapter->recvpriv.rx_pkts = 0;
690
691 pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
692
693 /* pmlmepriv->LinkDetectInfo.TrafficBusyState = false; */
694 pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
695 pmlmepriv->LinkDetectInfo.LowPowerTransitionCount = 0;
696
697 _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING);
698
699 pwrctrlpriv->pwr_state_check_cnts = 0;
700
701 /* mlmeextpriv */
702 padapter->mlmeextpriv.sitesurvey_res.state = SCAN_DISABLE;
703
704 rtw_set_signal_stat_timer(&padapter->recvpriv);
705
706 }
707
708
rtw_init_drv_sw(struct adapter * padapter)709 u8 rtw_init_drv_sw(struct adapter *padapter)
710 {
711 u8 ret8 = _SUCCESS;
712
713 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw\n"));
714
715 rtw_init_default_value(padapter);
716
717 rtw_init_hal_com_default_value(padapter);
718
719 if (rtw_init_cmd_priv(&padapter->cmdpriv)) {
720 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
721 ret8 = _FAIL;
722 goto exit;
723 }
724
725 padapter->cmdpriv.padapter = padapter;
726
727 if (rtw_init_evt_priv(&padapter->evtpriv)) {
728 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init evt_priv\n"));
729 ret8 = _FAIL;
730 goto exit;
731 }
732
733
734 if (rtw_init_mlme_priv(padapter) == _FAIL) {
735 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init mlme_priv\n"));
736 ret8 = _FAIL;
737 goto exit;
738 }
739
740 init_mlme_ext_priv(padapter);
741
742 if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
743 DBG_871X("Can't _rtw_init_xmit_priv\n");
744 ret8 = _FAIL;
745 goto exit;
746 }
747
748 if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
749 DBG_871X("Can't _rtw_init_recv_priv\n");
750 ret8 = _FAIL;
751 goto exit;
752 }
753 /* add for CONFIG_IEEE80211W, none 11w also can use */
754 spin_lock_init(&padapter->security_key_mutex);
755
756 /* We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
757 /* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */
758
759 if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
760 DBG_871X("Can't _rtw_init_sta_priv\n");
761 ret8 = _FAIL;
762 goto exit;
763 }
764
765 padapter->stapriv.padapter = padapter;
766 padapter->setband = GHZ24_50;
767 padapter->fix_rate = 0xFF;
768 rtw_init_bcmc_stainfo(padapter);
769
770 rtw_init_pwrctrl_priv(padapter);
771
772 rtw_hal_dm_init(padapter);
773
774 exit:
775
776 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_init_drv_sw\n"));
777
778 return ret8;
779 }
780
rtw_cancel_all_timer(struct adapter * padapter)781 void rtw_cancel_all_timer(struct adapter *padapter)
782 {
783 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_cancel_all_timer\n"));
784
785 del_timer_sync(&padapter->mlmepriv.assoc_timer);
786 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel association timer complete!\n"));
787
788 del_timer_sync(&padapter->mlmepriv.scan_to_timer);
789 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel scan_to_timer!\n"));
790
791 del_timer_sync(&padapter->mlmepriv.dynamic_chk_timer);
792 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel dynamic_chk_timer!\n"));
793
794 del_timer_sync(&(adapter_to_pwrctl(padapter)->pwr_state_check_timer));
795
796 del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer);
797 rtw_clear_scan_deny(padapter);
798 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel set_scan_deny_timer!\n"));
799
800 del_timer_sync(&padapter->recvpriv.signal_stat_timer);
801
802 /* cancel dm timer */
803 rtw_hal_dm_deinit(padapter);
804 }
805
rtw_free_drv_sw(struct adapter * padapter)806 u8 rtw_free_drv_sw(struct adapter *padapter)
807 {
808 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>rtw_free_drv_sw"));
809
810 free_mlme_ext_priv(&padapter->mlmeextpriv);
811
812 rtw_free_cmd_priv(&padapter->cmdpriv);
813
814 rtw_free_evt_priv(&padapter->evtpriv);
815
816 rtw_free_mlme_priv(&padapter->mlmepriv);
817
818 /* free_io_queue(padapter); */
819
820 _rtw_free_xmit_priv(&padapter->xmitpriv);
821
822 _rtw_free_sta_priv(&padapter->stapriv); /* will free bcmc_stainfo here */
823
824 _rtw_free_recv_priv(&padapter->recvpriv);
825
826 rtw_free_pwrctrl_priv(padapter);
827
828 /* kfree((void *)padapter); */
829
830 rtw_hal_free_data(padapter);
831
832 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("<==rtw_free_drv_sw\n"));
833
834 /* free the old_pnetdev */
835 if (padapter->rereg_nd_name_priv.old_pnetdev) {
836 free_netdev(padapter->rereg_nd_name_priv.old_pnetdev);
837 padapter->rereg_nd_name_priv.old_pnetdev = NULL;
838 }
839
840 /* clear pbuddystruct adapter to avoid access wrong pointer. */
841 if (padapter->pbuddy_adapter != NULL)
842 padapter->pbuddy_adapter->pbuddy_adapter = NULL;
843
844 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_free_drv_sw\n"));
845
846 return _SUCCESS;
847 }
848
_rtw_drv_register_netdev(struct adapter * padapter,char * name)849 static int _rtw_drv_register_netdev(struct adapter *padapter, char *name)
850 {
851 int ret = _SUCCESS;
852 struct net_device *pnetdev = padapter->pnetdev;
853
854 /* alloc netdev name */
855 if (rtw_init_netdev_name(pnetdev, name))
856 return _FAIL;
857
858 memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
859
860 /* Tell the network stack we exist */
861 if (register_netdev(pnetdev) != 0) {
862 DBG_871X(FUNC_NDEV_FMT "Failed!\n", FUNC_NDEV_ARG(pnetdev));
863 ret = _FAIL;
864 goto error_register_netdev;
865 }
866
867 DBG_871X("%s, MAC Address (if%d) = " MAC_FMT "\n", __func__, (padapter->iface_id + 1), MAC_ARG(pnetdev->dev_addr));
868
869 return ret;
870
871 error_register_netdev:
872
873 rtw_free_drv_sw(padapter);
874
875 rtw_free_netdev(pnetdev);
876
877 return ret;
878 }
879
rtw_drv_register_netdev(struct adapter * if1)880 int rtw_drv_register_netdev(struct adapter *if1)
881 {
882 struct dvobj_priv *dvobj = if1->dvobj;
883 struct adapter *padapter = dvobj->padapters;
884 char *name = if1->registrypriv.ifname;
885
886 return _rtw_drv_register_netdev(padapter, name);
887 }
888
_netdev_open(struct net_device * pnetdev)889 int _netdev_open(struct net_device *pnetdev)
890 {
891 uint status;
892 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
893 struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
894
895 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - dev_open\n"));
896 DBG_871X("+871x_drv - drv_open, bup =%d\n", padapter->bup);
897
898 padapter->netif_up = true;
899
900 if (pwrctrlpriv->ps_flag) {
901 padapter->net_closed = false;
902 goto netdev_open_normal_process;
903 }
904
905 if (!padapter->bup) {
906 padapter->bDriverStopped = false;
907 padapter->bSurpriseRemoved = false;
908 padapter->bCardDisableWOHSM = false;
909
910 status = rtw_hal_init(padapter);
911 if (status == _FAIL) {
912 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("rtl871x_hal_init(): Can't init h/w!\n"));
913 goto netdev_open_error;
914 }
915
916 DBG_871X("MAC Address = " MAC_FMT "\n", MAC_ARG(pnetdev->dev_addr));
917
918 status = rtw_start_drv_threads(padapter);
919 if (status == _FAIL) {
920 DBG_871X("Initialize driver software resource Failed!\n");
921 goto netdev_open_error;
922 }
923
924 if (padapter->intf_start)
925 padapter->intf_start(padapter);
926
927 rtw_cfg80211_init_wiphy(padapter);
928
929 padapter->bup = true;
930 pwrctrlpriv->bips_processing = false;
931 }
932 padapter->net_closed = false;
933
934 _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
935
936 if (!rtw_netif_queue_stopped(pnetdev))
937 rtw_netif_start_queue(pnetdev);
938 else
939 rtw_netif_wake_queue(pnetdev);
940
941 netdev_open_normal_process:
942
943 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - dev_open\n"));
944 DBG_871X("-871x_drv - drv_open, bup =%d\n", padapter->bup);
945
946 return 0;
947
948 netdev_open_error:
949
950 padapter->bup = false;
951
952 netif_carrier_off(pnetdev);
953 rtw_netif_stop_queue(pnetdev);
954
955 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("-871x_drv - dev_open, fail!\n"));
956 DBG_871X("-871x_drv - drv_open fail, bup =%d\n", padapter->bup);
957
958 return (-1);
959 }
960
netdev_open(struct net_device * pnetdev)961 int netdev_open(struct net_device *pnetdev)
962 {
963 int ret;
964 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
965 struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
966
967 if (pwrctrlpriv->bInSuspend) {
968 DBG_871X("+871x_drv - drv_open, bInSuspend =%d\n", pwrctrlpriv->bInSuspend);
969 return 0;
970 }
971
972 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex)))
973 return -1;
974
975 ret = _netdev_open(pnetdev);
976 mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex));
977
978 return ret;
979 }
980
ips_netdrv_open(struct adapter * padapter)981 static int ips_netdrv_open(struct adapter *padapter)
982 {
983 int status = _SUCCESS;
984 /* struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); */
985
986 padapter->net_closed = false;
987
988 DBG_871X("===> %s.........\n", __func__);
989
990
991 padapter->bDriverStopped = false;
992 padapter->bCardDisableWOHSM = false;
993 /* padapter->bup = true; */
994
995 status = rtw_hal_init(padapter);
996 if (status == _FAIL) {
997 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("ips_netdrv_open(): Can't init h/w!\n"));
998 goto netdev_open_error;
999 }
1000
1001 if (padapter->intf_start)
1002 padapter->intf_start(padapter);
1003
1004 _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1005
1006 return _SUCCESS;
1007
1008 netdev_open_error:
1009 /* padapter->bup = false; */
1010 DBG_871X("-ips_netdrv_open - drv_open failure, bup =%d\n", padapter->bup);
1011
1012 return _FAIL;
1013 }
1014
1015
rtw_ips_pwr_up(struct adapter * padapter)1016 int rtw_ips_pwr_up(struct adapter *padapter)
1017 {
1018 int result;
1019 DBG_871X("===> rtw_ips_pwr_up..............\n");
1020
1021 result = ips_netdrv_open(padapter);
1022
1023 DBG_871X("<=== rtw_ips_pwr_up..............\n");
1024 return result;
1025 }
1026
rtw_ips_pwr_down(struct adapter * padapter)1027 void rtw_ips_pwr_down(struct adapter *padapter)
1028 {
1029 DBG_871X("===> rtw_ips_pwr_down...................\n");
1030
1031 padapter->bCardDisableWOHSM = true;
1032 padapter->net_closed = true;
1033
1034 rtw_ips_dev_unload(padapter);
1035 padapter->bCardDisableWOHSM = false;
1036 DBG_871X("<=== rtw_ips_pwr_down.....................\n");
1037 }
1038
rtw_ips_dev_unload(struct adapter * padapter)1039 void rtw_ips_dev_unload(struct adapter *padapter)
1040 {
1041 DBG_871X("====> %s...\n", __func__);
1042
1043
1044 if (!padapter->bSurpriseRemoved)
1045 rtw_hal_deinit(padapter);
1046 }
1047
1048
pm_netdev_open(struct net_device * pnetdev,u8 bnormal)1049 static int pm_netdev_open(struct net_device *pnetdev, u8 bnormal)
1050 {
1051 int status = -1;
1052
1053 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
1054
1055 if (bnormal) {
1056 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex)) == 0) {
1057 status = _netdev_open(pnetdev);
1058 mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex));
1059 }
1060 } else {
1061 status = (_SUCCESS == ips_netdrv_open(padapter)) ? (0) : (-1);
1062 }
1063
1064 return status;
1065 }
1066
netdev_close(struct net_device * pnetdev)1067 static int netdev_close(struct net_device *pnetdev)
1068 {
1069 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
1070 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1071
1072 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - drv_close\n"));
1073
1074 if (pwrctl->bInternalAutoSuspend) {
1075 /* rtw_pwr_wakeup(padapter); */
1076 if (pwrctl->rf_pwrstate == rf_off)
1077 pwrctl->ps_flag = true;
1078 }
1079 padapter->net_closed = true;
1080 padapter->netif_up = false;
1081
1082 /*if (!padapter->hw_init_completed)
1083 {
1084 DBG_871X("(1)871x_drv - drv_close, bup =%d, hw_init_completed =%d\n", padapter->bup, padapter->hw_init_completed);
1085
1086 padapter->bDriverStopped = true;
1087
1088 rtw_dev_unload(padapter);
1089 }
1090 else*/
1091 if (pwrctl->rf_pwrstate == rf_on) {
1092 DBG_871X("(2)871x_drv - drv_close, bup =%d, hw_init_completed =%d\n", padapter->bup, padapter->hw_init_completed);
1093
1094 /* s1. */
1095 if (pnetdev) {
1096 if (!rtw_netif_queue_stopped(pnetdev))
1097 rtw_netif_stop_queue(pnetdev);
1098 }
1099
1100 /* s2. */
1101 LeaveAllPowerSaveMode(padapter);
1102 rtw_disassoc_cmd(padapter, 500, false);
1103 /* s2-2. indicate disconnect to os */
1104 rtw_indicate_disconnect(padapter);
1105 /* s2-3. */
1106 rtw_free_assoc_resources(padapter, 1);
1107 /* s2-4. */
1108 rtw_free_network_queue(padapter, true);
1109 }
1110
1111 rtw_scan_abort(padapter);
1112 adapter_wdev_data(padapter)->bandroid_scan = false;
1113
1114 RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - drv_close\n"));
1115 DBG_871X("-871x_drv - drv_close, bup =%d\n", padapter->bup);
1116
1117 return 0;
1118 }
1119
rtw_ndev_destructor(struct net_device * ndev)1120 void rtw_ndev_destructor(struct net_device *ndev)
1121 {
1122 DBG_871X(FUNC_NDEV_FMT "\n", FUNC_NDEV_ARG(ndev));
1123
1124 kfree(ndev->ieee80211_ptr);
1125 }
1126
rtw_dev_unload(struct adapter * padapter)1127 void rtw_dev_unload(struct adapter *padapter)
1128 {
1129 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1130 struct dvobj_priv *pobjpriv = padapter->dvobj;
1131 struct debug_priv *pdbgpriv = &pobjpriv->drv_dbg;
1132 struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1133 u8 cnt = 0;
1134
1135 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+%s\n", __func__));
1136
1137 if (padapter->bup) {
1138 DBG_871X("===> %s\n", __func__);
1139
1140 padapter->bDriverStopped = true;
1141 if (padapter->xmitpriv.ack_tx)
1142 rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
1143
1144 if (padapter->intf_stop)
1145 padapter->intf_stop(padapter);
1146
1147 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop intf complete!\n"));
1148
1149 if (!pwrctl->bInternalAutoSuspend)
1150 rtw_stop_drv_threads(padapter);
1151
1152 while (atomic_read(&pcmdpriv->cmdthd_running)) {
1153 if (cnt > 5) {
1154 DBG_871X("stop cmdthd timeout\n");
1155 break;
1156 } else {
1157 cnt++;
1158 DBG_871X("cmdthd is running(%d)\n", cnt);
1159 msleep(10);
1160 }
1161 }
1162
1163 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ %s: stop thread complete!\n", __func__));
1164
1165 /* check the status of IPS */
1166 if (rtw_hal_check_ips_status(padapter) || pwrctl->rf_pwrstate == rf_off) {
1167 /* check HW status and SW state */
1168 DBG_871X_LEVEL(_drv_always_, "%s: driver in IPS-FWLPS\n", __func__);
1169 pdbgpriv->dbg_dev_unload_inIPS_cnt++;
1170 LeaveAllPowerSaveMode(padapter);
1171 } else {
1172 DBG_871X_LEVEL(_drv_always_, "%s: driver not in IPS\n", __func__);
1173 }
1174
1175 if (!padapter->bSurpriseRemoved) {
1176 hal_btcoex_IpsNotify(padapter, pwrctl->ips_mode_req);
1177 #ifdef CONFIG_WOWLAN
1178 if (pwrctl->bSupportRemoteWakeup && pwrctl->wowlan_mode) {
1179 DBG_871X_LEVEL(_drv_always_, "%s bSupportRemoteWakeup ==true do not run rtw_hal_deinit()\n", __func__);
1180 }
1181 else
1182 #endif
1183 {
1184 /* amy modify 20120221 for power seq is different between driver open and ips */
1185 rtw_hal_deinit(padapter);
1186 }
1187 padapter->bSurpriseRemoved = true;
1188 }
1189 RT_TRACE(_module_hci_intfs_c_, _drv_notice_,
1190 ("@ %s: deinit hal complete!\n", __func__));
1191
1192 padapter->bup = false;
1193
1194 DBG_871X("<=== %s\n", __func__);
1195 } else {
1196 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("%s: bup ==false\n", __func__));
1197 DBG_871X("%s: bup ==false\n", __func__);
1198 }
1199
1200 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-%s\n", __func__));
1201 }
1202
rtw_suspend_free_assoc_resource(struct adapter * padapter)1203 static int rtw_suspend_free_assoc_resource(struct adapter *padapter)
1204 {
1205 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1206
1207 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1208
1209 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1210 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
1211 && check_fwstate(pmlmepriv, _FW_LINKED)) {
1212 DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n", __func__,
1213 pmlmepriv->cur_network.network.Ssid.Ssid,
1214 MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
1215 pmlmepriv->cur_network.network.Ssid.SsidLength,
1216 pmlmepriv->assoc_ssid.SsidLength);
1217 rtw_set_to_roam(padapter, 1);
1218 }
1219 }
1220
1221 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED)) {
1222 rtw_disassoc_cmd(padapter, 0, false);
1223 /* s2-2. indicate disconnect to os */
1224 rtw_indicate_disconnect(padapter);
1225 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1226 rtw_sta_flush(padapter);
1227 }
1228
1229 /* s2-3. */
1230 rtw_free_assoc_resources(padapter, 1);
1231
1232 /* s2-4. */
1233 rtw_free_network_queue(padapter, true);
1234
1235 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1236 rtw_indicate_scan_done(padapter, 1);
1237
1238 if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING)) {
1239 DBG_871X_LEVEL(_drv_always_, "%s: fw_under_linking\n", __func__);
1240 rtw_indicate_disconnect(padapter);
1241 }
1242
1243 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1244 return _SUCCESS;
1245 }
1246
1247 #ifdef CONFIG_WOWLAN
rtw_suspend_wow(struct adapter * padapter)1248 void rtw_suspend_wow(struct adapter *padapter)
1249 {
1250 u8 ch, bw, offset;
1251 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1252 struct net_device *pnetdev = padapter->pnetdev;
1253 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1254 struct wowlan_ioctl_param poidparam;
1255
1256 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1257
1258
1259 DBG_871X("wowlan_mode: %d\n", pwrpriv->wowlan_mode);
1260 DBG_871X("wowlan_pno_enable: %d\n", pwrpriv->wowlan_pno_enable);
1261
1262 if (pwrpriv->wowlan_mode) {
1263 if (pnetdev)
1264 rtw_netif_stop_queue(pnetdev);
1265 /* 1. stop thread */
1266 padapter->bDriverStopped = true; /* for stop thread */
1267 rtw_stop_drv_threads(padapter);
1268 padapter->bDriverStopped = false; /* for 32k command */
1269
1270 /* 2. disable interrupt */
1271 if (padapter->intf_stop)
1272 padapter->intf_stop(padapter);
1273
1274 /* 2.1 clean interrupt */
1275 if (padapter->HalFunc.clear_interrupt)
1276 padapter->HalFunc.clear_interrupt(padapter);
1277
1278 /* 2.2 free irq */
1279 /* sdio_free_irq(adapter_to_dvobj(padapter)); */
1280 if (padapter->intf_free_irq)
1281 padapter->intf_free_irq(adapter_to_dvobj(padapter));
1282
1283 poidparam.subcode = WOWLAN_ENABLE;
1284 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_WOWLAN, (u8 *)&poidparam);
1285 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1286 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED)) {
1287 DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n", __func__,
1288 pmlmepriv->cur_network.network.Ssid.Ssid,
1289 MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
1290 pmlmepriv->cur_network.network.Ssid.SsidLength,
1291 pmlmepriv->assoc_ssid.SsidLength);
1292
1293 rtw_set_to_roam(padapter, 0);
1294 }
1295 }
1296
1297 DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__);
1298
1299 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY)) {
1300 DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__);
1301 rtw_indicate_scan_done(padapter, 1);
1302 clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
1303 }
1304
1305 if (rtw_get_ch_setting_union(padapter, &ch, &bw, &offset) != 0) {
1306 DBG_871X(FUNC_ADPT_FMT " back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
1307 FUNC_ADPT_ARG(padapter), ch, bw, offset);
1308 set_channel_bwmode(padapter, ch, offset, bw);
1309 }
1310
1311 if (pwrpriv->wowlan_pno_enable)
1312 DBG_871X_LEVEL(_drv_always_, "%s: pno: %d\n", __func__, pwrpriv->wowlan_pno_enable);
1313 else
1314 rtw_set_ps_mode(padapter, PS_MODE_DTIM, 0, 0, "WOWLAN");
1315 } else {
1316 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR ### wowlan_mode =%d\n", __func__, pwrpriv->wowlan_mode);
1317 }
1318 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1319 }
1320 #endif /* ifdef CONFIG_WOWLAN */
1321
1322 #ifdef CONFIG_AP_WOWLAN
rtw_suspend_ap_wow(struct adapter * padapter)1323 void rtw_suspend_ap_wow(struct adapter *padapter)
1324 {
1325 u8 ch, bw, offset;
1326 struct net_device *pnetdev = padapter->pnetdev;
1327 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1328 struct wowlan_ioctl_param poidparam;
1329
1330 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1331
1332 pwrpriv->wowlan_ap_mode = true;
1333
1334 DBG_871X("wowlan_ap_mode: %d\n", pwrpriv->wowlan_ap_mode);
1335
1336 if (pnetdev)
1337 rtw_netif_stop_queue(pnetdev);
1338 /* 1. stop thread */
1339 padapter->bDriverStopped = true; /* for stop thread */
1340 rtw_stop_drv_threads(padapter);
1341 padapter->bDriverStopped = false; /* for 32k command */
1342
1343 /* 2. disable interrupt */
1344 rtw_hal_disable_interrupt(padapter); /* It need wait for leaving 32K. */
1345
1346 /* 2.1 clean interrupt */
1347 if (padapter->HalFunc.clear_interrupt)
1348 padapter->HalFunc.clear_interrupt(padapter);
1349
1350 /* 2.2 free irq */
1351 /* sdio_free_irq(adapter_to_dvobj(padapter)); */
1352 if (padapter->intf_free_irq)
1353 padapter->intf_free_irq(adapter_to_dvobj(padapter));
1354
1355 poidparam.subcode = WOWLAN_AP_ENABLE;
1356 padapter->HalFunc.SetHwRegHandler(padapter,
1357 HW_VAR_AP_WOWLAN, (u8 *)&poidparam);
1358
1359 DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__);
1360
1361 if (rtw_get_ch_setting_union(padapter, &ch, &bw, &offset) != 0) {
1362 DBG_871X(FUNC_ADPT_FMT " back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
1363 FUNC_ADPT_ARG(padapter), ch, bw, offset);
1364 set_channel_bwmode(padapter, ch, offset, bw);
1365 }
1366
1367 rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0, "AP-WOWLAN");
1368
1369 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1370 }
1371 #endif /* ifdef CONFIG_AP_WOWLAN */
1372
1373
rtw_suspend_normal(struct adapter * padapter)1374 static void rtw_suspend_normal(struct adapter *padapter)
1375 {
1376 struct net_device *pnetdev = padapter->pnetdev;
1377
1378 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1379 if (pnetdev) {
1380 netif_carrier_off(pnetdev);
1381 rtw_netif_stop_queue(pnetdev);
1382 }
1383
1384 rtw_suspend_free_assoc_resource(padapter);
1385
1386 if ((rtw_hal_check_ips_status(padapter)) || (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off))
1387 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR #### driver in IPS ####ERROR###!!!\n", __func__);
1388
1389 rtw_dev_unload(padapter);
1390
1391 /* sdio_deinit(adapter_to_dvobj(padapter)); */
1392 if (padapter->intf_deinit)
1393 padapter->intf_deinit(adapter_to_dvobj(padapter));
1394
1395 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1396 }
1397
rtw_suspend_common(struct adapter * padapter)1398 int rtw_suspend_common(struct adapter *padapter)
1399 {
1400 struct dvobj_priv *psdpriv = padapter->dvobj;
1401 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1402 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv);
1403 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1404
1405 int ret = 0;
1406 unsigned long start_time = jiffies;
1407
1408 DBG_871X_LEVEL(_drv_always_, " suspend start\n");
1409 DBG_871X("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
1410 pdbgpriv->dbg_suspend_cnt++;
1411
1412 pwrpriv->bInSuspend = true;
1413
1414 while (pwrpriv->bips_processing)
1415 msleep(1);
1416
1417 if ((!padapter->bup) || (padapter->bDriverStopped) || (padapter->bSurpriseRemoved)) {
1418 DBG_871X("%s bup =%d bDriverStopped =%d bSurpriseRemoved = %d\n", __func__
1419 , padapter->bup, padapter->bDriverStopped, padapter->bSurpriseRemoved);
1420 pdbgpriv->dbg_suspend_error_cnt++;
1421 goto exit;
1422 }
1423 rtw_ps_deny(padapter, PS_DENY_SUSPEND);
1424
1425 rtw_cancel_all_timer(padapter);
1426
1427 LeaveAllPowerSaveModeDirect(padapter);
1428
1429 rtw_stop_cmd_thread(padapter);
1430
1431 /* wait for the latest FW to remove this condition. */
1432 if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1433 hal_btcoex_SuspendNotify(padapter, 0);
1434 DBG_871X("WIFI_AP_STATE\n");
1435 } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1436 hal_btcoex_SuspendNotify(padapter, 1);
1437 DBG_871X("STATION\n");
1438 }
1439
1440 rtw_ps_deny_cancel(padapter, PS_DENY_SUSPEND);
1441
1442 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1443 #ifdef CONFIG_WOWLAN
1444 if (check_fwstate(pmlmepriv, _FW_LINKED))
1445 pwrpriv->wowlan_mode = true;
1446 else if (pwrpriv->wowlan_pno_enable)
1447 pwrpriv->wowlan_mode |= pwrpriv->wowlan_pno_enable;
1448
1449 if (pwrpriv->wowlan_mode)
1450 rtw_suspend_wow(padapter);
1451 else
1452 rtw_suspend_normal(padapter);
1453
1454 #else /* CONFIG_WOWLAN */
1455 rtw_suspend_normal(padapter);
1456 #endif /* CONFIG_WOWLAN */
1457 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1458 #ifdef CONFIG_AP_WOWLAN
1459 rtw_suspend_ap_wow(padapter);
1460 #else
1461 rtw_suspend_normal(padapter);
1462 #endif /* CONFIG_AP_WOWLAN */
1463 } else {
1464 rtw_suspend_normal(padapter);
1465 }
1466
1467 DBG_871X_LEVEL(_drv_always_, "rtw suspend success in %d ms\n",
1468 jiffies_to_msecs(jiffies - start_time));
1469
1470 exit:
1471 DBG_871X("<=== %s return %d.............. in %dms\n", __func__
1472 , ret, jiffies_to_msecs(jiffies - start_time));
1473
1474 return ret;
1475 }
1476
1477 #ifdef CONFIG_WOWLAN
rtw_resume_process_wow(struct adapter * padapter)1478 int rtw_resume_process_wow(struct adapter *padapter)
1479 {
1480 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1481 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1482 struct net_device *pnetdev = padapter->pnetdev;
1483 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1484 struct dvobj_priv *psdpriv = padapter->dvobj;
1485 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1486 struct wowlan_ioctl_param poidparam;
1487 struct sta_info *psta = NULL;
1488 int ret = _SUCCESS;
1489
1490 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1491
1492 if (padapter) {
1493 pnetdev = padapter->pnetdev;
1494 pwrpriv = adapter_to_pwrctl(padapter);
1495 } else {
1496 pdbgpriv->dbg_resume_error_cnt++;
1497 ret = -1;
1498 goto exit;
1499 }
1500
1501 if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
1502 DBG_871X("%s pdapter %p bDriverStopped %d bSurpriseRemoved %d\n",
1503 __func__, padapter, padapter->bDriverStopped,
1504 padapter->bSurpriseRemoved);
1505 goto exit;
1506 }
1507
1508 #ifdef CONFIG_PNO_SUPPORT
1509 pwrpriv->pno_in_resume = true;
1510 #endif
1511
1512 if (pwrpriv->wowlan_mode) {
1513 rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "WOWLAN");
1514
1515 pwrpriv->bFwCurrentInPSMode = false;
1516
1517 if (padapter->intf_stop)
1518 padapter->intf_stop(padapter);
1519
1520 if (padapter->HalFunc.clear_interrupt)
1521 padapter->HalFunc.clear_interrupt(padapter);
1522
1523 /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { */
1524 if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1525 ret = -1;
1526 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1527 goto exit;
1528 }
1529
1530 /* Disable WOW, set H2C command */
1531 poidparam.subcode = WOWLAN_DISABLE;
1532 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_WOWLAN, (u8 *)&poidparam);
1533
1534 psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
1535 if (psta)
1536 set_sta_rate(padapter, psta);
1537
1538 padapter->bDriverStopped = false;
1539 DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped);
1540 rtw_start_drv_threads(padapter);
1541
1542 if (padapter->intf_start)
1543 padapter->intf_start(padapter);
1544
1545 /* start netif queue */
1546 if (pnetdev) {
1547 if (!rtw_netif_queue_stopped(pnetdev))
1548 rtw_netif_start_queue(pnetdev);
1549 else
1550 rtw_netif_wake_queue(pnetdev);
1551 }
1552 } else {
1553 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR ### wowlan_mode =%d\n", __func__, pwrpriv->wowlan_mode);
1554 }
1555
1556 if (padapter->pid[1] != 0) {
1557 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1558 rtw_signal_process(padapter->pid[1], SIGUSR2);
1559 }
1560
1561 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1562 if (pwrpriv->wowlan_wake_reason == FWDecisionDisconnect ||
1563 pwrpriv->wowlan_wake_reason == Rx_DisAssoc ||
1564 pwrpriv->wowlan_wake_reason == Rx_DeAuth) {
1565 DBG_871X("%s: disconnect reason: %02x\n", __func__,
1566 pwrpriv->wowlan_wake_reason);
1567 rtw_indicate_disconnect(padapter);
1568
1569 rtw_sta_media_status_rpt(padapter,
1570 rtw_get_stainfo(&padapter->stapriv,
1571 get_bssid(&padapter->mlmepriv)), 0);
1572
1573 rtw_free_assoc_resources(padapter, 1);
1574 pmlmeinfo->state = WIFI_FW_NULL_STATE;
1575
1576 } else {
1577 DBG_871X("%s: do roaming\n", __func__);
1578 rtw_roaming(padapter, NULL);
1579 }
1580 }
1581
1582 if (pwrpriv->wowlan_mode) {
1583 pwrpriv->bips_processing = false;
1584 _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1585 } else {
1586 DBG_871X_LEVEL(_drv_always_, "do not reset timer\n");
1587 }
1588
1589 pwrpriv->wowlan_mode = false;
1590
1591 /* clean driver side wake up reason. */
1592 pwrpriv->wowlan_wake_reason = 0;
1593 exit:
1594 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1595 return ret;
1596 }
1597 #endif /* ifdef CONFIG_WOWLAN */
1598
1599 #ifdef CONFIG_AP_WOWLAN
rtw_resume_process_ap_wow(struct adapter * padapter)1600 int rtw_resume_process_ap_wow(struct adapter *padapter)
1601 {
1602 struct net_device *pnetdev = padapter->pnetdev;
1603 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1604 struct dvobj_priv *psdpriv = padapter->dvobj;
1605 struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1606 struct wowlan_ioctl_param poidparam;
1607 int ret = _SUCCESS;
1608
1609 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1610
1611 if (padapter) {
1612 pnetdev = padapter->pnetdev;
1613 pwrpriv = adapter_to_pwrctl(padapter);
1614 } else {
1615 pdbgpriv->dbg_resume_error_cnt++;
1616 ret = -1;
1617 goto exit;
1618 }
1619
1620 rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "AP-WOWLAN");
1621
1622 pwrpriv->bFwCurrentInPSMode = false;
1623
1624 rtw_hal_disable_interrupt(padapter);
1625
1626 if (padapter->HalFunc.clear_interrupt)
1627 padapter->HalFunc.clear_interrupt(padapter);
1628
1629 /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { */
1630 if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1631 ret = -1;
1632 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1633 goto exit;
1634 }
1635
1636 /* Disable WOW, set H2C command */
1637 poidparam.subcode = WOWLAN_AP_DISABLE;
1638 padapter->HalFunc.SetHwRegHandler(padapter,
1639 HW_VAR_AP_WOWLAN, (u8 *)&poidparam);
1640 pwrpriv->wowlan_ap_mode = false;
1641
1642 padapter->bDriverStopped = false;
1643 DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped);
1644 rtw_start_drv_threads(padapter);
1645
1646 if (padapter->intf_start)
1647 padapter->intf_start(padapter);
1648
1649 /* start netif queue */
1650 if (pnetdev) {
1651 if (!rtw_netif_queue_stopped(pnetdev))
1652 rtw_netif_start_queue(pnetdev);
1653 else
1654 rtw_netif_wake_queue(pnetdev);
1655 }
1656
1657 if (padapter->pid[1] != 0) {
1658 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1659 rtw_signal_process(padapter->pid[1], SIGUSR2);
1660 }
1661
1662 pwrpriv->bips_processing = false;
1663 _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1664
1665 /* clean driver side wake up reason. */
1666 pwrpriv->wowlan_wake_reason = 0;
1667 exit:
1668 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1669 return ret;
1670 }
1671 #endif /* ifdef CONFIG_APWOWLAN */
1672
rtw_resume_process_normal(struct adapter * padapter)1673 static int rtw_resume_process_normal(struct adapter *padapter)
1674 {
1675 struct net_device *pnetdev;
1676 struct pwrctrl_priv *pwrpriv;
1677 struct mlme_priv *pmlmepriv;
1678 struct dvobj_priv *psdpriv;
1679 struct debug_priv *pdbgpriv;
1680
1681 int ret = _SUCCESS;
1682
1683 if (!padapter) {
1684 ret = -1;
1685 goto exit;
1686 }
1687
1688 pnetdev = padapter->pnetdev;
1689 pwrpriv = adapter_to_pwrctl(padapter);
1690 pmlmepriv = &padapter->mlmepriv;
1691 psdpriv = padapter->dvobj;
1692 pdbgpriv = &psdpriv->drv_dbg;
1693
1694 DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1695 /* interface init */
1696 /* if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) */
1697 if ((padapter->intf_init) && (padapter->intf_init(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1698 ret = -1;
1699 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __func__));
1700 goto exit;
1701 }
1702 rtw_hal_disable_interrupt(padapter);
1703 /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) */
1704 if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1705 ret = -1;
1706 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1707 goto exit;
1708 }
1709
1710 rtw_reset_drv_sw(padapter);
1711 pwrpriv->bkeepfwalive = false;
1712
1713 DBG_871X("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
1714 if (pm_netdev_open(pnetdev, true) != 0) {
1715 ret = -1;
1716 pdbgpriv->dbg_resume_error_cnt++;
1717 goto exit;
1718 }
1719
1720 netif_device_attach(pnetdev);
1721 netif_carrier_on(pnetdev);
1722
1723 if (padapter->pid[1] != 0) {
1724 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1725 rtw_signal_process(padapter->pid[1], SIGUSR2);
1726 }
1727
1728 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1729 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_STATION_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1730
1731 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME))
1732 rtw_roaming(padapter, NULL);
1733
1734 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1735 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_AP_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1736 rtw_ap_restore_network(padapter);
1737 } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1738 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_ADHOC_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1739 } else {
1740 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - ???\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1741 }
1742
1743 DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1744
1745 exit:
1746 return ret;
1747 }
1748
rtw_resume_common(struct adapter * padapter)1749 int rtw_resume_common(struct adapter *padapter)
1750 {
1751 int ret = 0;
1752 unsigned long start_time = jiffies;
1753 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1754 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1755
1756 DBG_871X_LEVEL(_drv_always_, "resume start\n");
1757 DBG_871X("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
1758
1759 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1760 #ifdef CONFIG_WOWLAN
1761 if (pwrpriv->wowlan_mode)
1762 rtw_resume_process_wow(padapter);
1763 else
1764 rtw_resume_process_normal(padapter);
1765 #else
1766 rtw_resume_process_normal(padapter);
1767 #endif
1768
1769 } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1770 #ifdef CONFIG_AP_WOWLAN
1771 rtw_resume_process_ap_wow(padapter);
1772 #else
1773 rtw_resume_process_normal(padapter);
1774 #endif /* CONFIG_AP_WOWLAN */
1775 } else {
1776 rtw_resume_process_normal(padapter);
1777 }
1778
1779 hal_btcoex_SuspendNotify(padapter, 0);
1780
1781 if (pwrpriv) {
1782 pwrpriv->bInSuspend = false;
1783 #ifdef CONFIG_PNO_SUPPORT
1784 pwrpriv->pno_in_resume = false;
1785 #endif
1786 }
1787 DBG_871X_LEVEL(_drv_always_, "%s:%d in %d ms\n", __func__, ret,
1788 jiffies_to_msecs(jiffies - start_time));
1789
1790 return ret;
1791 }
1792