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