Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
nu11secur1ty
GitHub Repository: nu11secur1ty/Kali-Linux
Path: blob/master/ALFA-W1F1/RTL8814AU/os_dep/linux/usb_intf.c
1307 views
1
/******************************************************************************
2
*
3
* Copyright(c) 2007 - 2017 Realtek Corporation.
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms of version 2 of the GNU General Public License as
7
* published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
*****************************************************************************/
15
#define _HCI_INTF_C_
16
17
#include <drv_types.h>
18
#include <hal_data.h>
19
20
#include <platform_ops.h>
21
22
#ifndef CONFIG_USB_HCI
23
#error "CONFIG_USB_HCI shall be on!\n"
24
#endif
25
26
#ifdef CONFIG_80211N_HT
27
extern int rtw_ht_enable;
28
extern int rtw_bw_mode;
29
extern int rtw_ampdu_enable;/* for enable tx_ampdu */
30
#endif
31
32
#ifdef CONFIG_GLOBAL_UI_PID
33
int ui_pid[3] = {0, 0, 0};
34
#endif
35
36
extern int pm_netdev_open(struct net_device *pnetdev, u8 bnormal);
37
static int rtw_suspend(struct usb_interface *intf, pm_message_t message);
38
static int rtw_resume(struct usb_interface *intf);
39
40
static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid);
41
static void rtw_dev_remove(struct usb_interface *pusb_intf);
42
43
static void rtw_dev_shutdown(struct device *dev)
44
{
45
struct usb_interface *usb_intf = container_of(dev, struct usb_interface, dev);
46
struct dvobj_priv *dvobj = NULL;
47
_adapter *adapter = NULL;
48
49
RTW_INFO("%s\n", __func__);
50
51
if (usb_intf) {
52
dvobj = usb_get_intfdata(usb_intf);
53
if (dvobj) {
54
adapter = dvobj_get_primary_adapter(dvobj);
55
if (adapter) {
56
if (!rtw_is_surprise_removed(adapter)) {
57
#ifdef CONFIG_WOWLAN
58
struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(adapter);
59
60
#ifdef CONFIG_GPIO_WAKEUP
61
/*default wake up pin change to BT*/
62
RTW_INFO("%s:default wake up pin change to BT\n", __FUNCTION__);
63
rtw_hal_switch_gpio_wl_ctrl(adapter, WAKEUP_GPIO_IDX, _FALSE);
64
#endif /* CONFIG_GPIO_WAKEUP */
65
66
if (pwrctl->wowlan_mode == _TRUE)
67
RTW_PRINT("%s wowlan_mode ==_TRUE do not run rtw_hal_deinit()\n", __FUNCTION__);
68
else
69
#endif
70
{
71
rtw_hal_deinit(adapter);
72
rtw_set_surprise_removed(adapter);
73
}
74
}
75
}
76
ATOMIC_SET(&dvobj->continual_io_error, MAX_CONTINUAL_IO_ERR + 1);
77
}
78
}
79
}
80
81
#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23))
82
/* Some useful macros to use to create struct usb_device_id */
83
#define USB_DEVICE_ID_MATCH_VENDOR 0x0001
84
#define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
85
#define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
86
#define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
87
#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
88
#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
89
#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
90
#define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
91
#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
92
#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
93
#define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
94
95
#define USB_DEVICE_ID_MATCH_INT_INFO \
96
(USB_DEVICE_ID_MATCH_INT_CLASS | \
97
USB_DEVICE_ID_MATCH_INT_SUBCLASS | \
98
USB_DEVICE_ID_MATCH_INT_PROTOCOL)
99
100
#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \
101
.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
102
| USB_DEVICE_ID_MATCH_DEVICE, \
103
.idVendor = (vend), \
104
.idProduct = (prod), \
105
.bInterfaceClass = (cl), \
106
.bInterfaceSubClass = (sc), \
107
.bInterfaceProtocol = (pr)
108
109
/**
110
* USB_VENDOR_AND_INTERFACE_INFO - describe a specific usb vendor with a class of usb interfaces
111
* @vend: the 16 bit USB Vendor ID
112
* @cl: bInterfaceClass value
113
* @sc: bInterfaceSubClass value
114
* @pr: bInterfaceProtocol value
115
*
116
* This macro is used to create a struct usb_device_id that matches a
117
* specific vendor with a specific class of interfaces.
118
*
119
* This is especially useful when explicitly matching devices that have
120
* vendor specific bDeviceClass values, but standards-compliant interfaces.
121
*/
122
#define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \
123
.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
124
| USB_DEVICE_ID_MATCH_VENDOR, \
125
.idVendor = (vend), \
126
.bInterfaceClass = (cl), \
127
.bInterfaceSubClass = (sc), \
128
.bInterfaceProtocol = (pr)
129
130
/* ----------------------------------------------------------------------- */
131
#endif
132
133
#define USB_VENDER_ID_REALTEK 0x0BDA
134
135
/* DID_USB_v916_20130116 */
136
static struct usb_device_id rtw_usb_id_tbl[] = {
137
#ifdef CONFIG_RTL8188E
138
/*=== Realtek demoboard ===*/
139
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179), .driver_info = RTL8188E}, /* 8188EUS */
140
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179), .driver_info = RTL8188E}, /* 8188ETV */
141
/*=== Customer ID ===*/
142
/****** 8188EUS ********/
143
{USB_DEVICE(0x07B8, 0x8179), .driver_info = RTL8188E}, /* Abocom - Abocom */
144
#endif
145
146
#ifdef CONFIG_RTL8812A
147
/*=== Realtek demoboard ===*/
148
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8812), .driver_info = RTL8812}, /* Default ID */
149
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881A), .driver_info = RTL8812}, /* Default ID */
150
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881B), .driver_info = RTL8812}, /* Default ID */
151
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881C), .driver_info = RTL8812}, /* Default ID */
152
/*=== Customer ID ===*/
153
{USB_DEVICE(0x050D, 0x1106), .driver_info = RTL8812}, /* Belkin - sercomm */
154
{USB_DEVICE(0x7392, 0xA822), .driver_info = RTL8812}, /* Edimax - EW-7822UAC */
155
{USB_DEVICE(0x0DF6, 0x0074), .driver_info = RTL8812}, /* Sitecom - Edimax */
156
{USB_DEVICE(0x04BB, 0x0952), .driver_info = RTL8812}, /* I-O DATA - Edimax */
157
{USB_DEVICE(0x0789, 0x016E), .driver_info = RTL8812}, /* Logitec - Edimax */
158
{USB_DEVICE(0x0409, 0x0408), .driver_info = RTL8812}, /* NEC - */
159
{USB_DEVICE(0x0B05, 0x17D2), .driver_info = RTL8812}, /* ASUS - Edimax */
160
{USB_DEVICE(0x0E66, 0x0022), .driver_info = RTL8812}, /* HAWKING - Edimax */
161
{USB_DEVICE(0x0586, 0x3426), .driver_info = RTL8812}, /* ZyXEL - */
162
{USB_DEVICE(0x2001, 0x3313), .driver_info = RTL8812}, /* D-Link - ALPHA */
163
{USB_DEVICE(0x1058, 0x0632), .driver_info = RTL8812}, /* WD - Cybertan*/
164
{USB_DEVICE(0x1740, 0x0100), .driver_info = RTL8812}, /* EnGenius - EnGenius */
165
{USB_DEVICE(0x2019, 0xAB30), .driver_info = RTL8812}, /* Planex - Abocom */
166
{USB_DEVICE(0x07B8, 0x8812), .driver_info = RTL8812}, /* Abocom - Abocom */
167
{USB_DEVICE(0x0846, 0x9051), .driver_info = RTL8812}, /* Netgear A6200 v2 */
168
{USB_DEVICE(0x2001, 0x330E), .driver_info = RTL8812}, /* D-Link - ALPHA */
169
{USB_DEVICE(0x2001, 0x3313), .driver_info = RTL8812}, /* D-Link - ALPHA */
170
{USB_DEVICE(0x2001, 0x3315), .driver_info = RTL8812}, /* D-Link - D-Link DWA-182 (Rev. C1) */
171
{USB_DEVICE(0x2001, 0x3316), .driver_info = RTL8812}, /* D-Link - Cameo */
172
{USB_DEVICE(0x13B1, 0x003F), .driver_info = RTL8812}, /* Linksys - WUSB6300 */
173
{USB_DEVICE(0x2357, 0x0101), .driver_info = RTL8812}, /* TP-Link - Archer T4U AC1200 */
174
{USB_DEVICE(0x2357, 0x0103), .driver_info = RTL8812}, /* TP-Link - T4UH */
175
{USB_DEVICE(0x2357, 0x010D), .driver_info = RTL8812}, /* TP-Link - Archer T4U AC1300 */
176
{USB_DEVICE(0x2357, 0x010E), .driver_info = RTL8812}, /* TP-Link - Archer T4UH AC1300 */
177
{USB_DEVICE(0x2357, 0x010F), .driver_info = RTL8812}, /* TP-Link - T4UHP */
178
{USB_DEVICE(0x2357, 0x0122), .driver_info = RTL8812}, /* TP-Link - T4UHP (other) */
179
{USB_DEVICE(0x20F4, 0x805B), .driver_info = RTL8812}, /* TRENDnet - TEW-805UB */
180
{USB_DEVICE(0x0411, 0x025D), .driver_info = RTL8812}, /* Buffalo - WI-U3-866D */
181
{USB_DEVICE(0x050D, 0x1109), .driver_info = RTL8812}, /* Belkin F9L1109 - SerComm */
182
{USB_DEVICE(0x148F, 0x9097), .driver_info = RTL8812}, /* Amped Wireless ACA1 */
183
{USB_DEVICE(0x2604, 0x0012), .driver_info = RTL8812}, /* Tenda U12 */
184
#endif
185
186
#ifdef CONFIG_RTL8821A
187
/*=== Realtek demoboard ===*/
188
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0811), .driver_info = RTL8821}, /* Default ID */
189
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0821), .driver_info = RTL8821}, /* Default ID */
190
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8822), .driver_info = RTL8821}, /* Default ID */
191
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xA811) , .driver_info = RTL8821},/* Default ID */
192
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0820, 0xff, 0xff, 0xff), .driver_info = RTL8821}, /* 8821AU */
193
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0823, 0xff, 0xff, 0xff), .driver_info = RTL8821}, /* 8821AU */
194
/*=== Customer ID ===*/
195
{USB_DEVICE(0x7392, 0xA811), .driver_info = RTL8821}, /* Edimax - Edimax */
196
{USB_DEVICE(0x7392, 0xA812), .driver_info = RTL8821}, /* Edimax - EW-7811UTC */
197
{USB_DEVICE(0x7392, 0xA813), .driver_info = RTL8821}, /* Edimax - EW-7811UAC */
198
{USB_DEVICE(0x7392, 0xB611), .driver_info = RTL8821}, /* Edimax - EW-7811UCB */
199
{USB_DEVICE(0x04BB, 0x0953), .driver_info = RTL8821}, /* I-O DATA - Edimax */
200
{USB_DEVICE(0x2001, 0x3314), .driver_info = RTL8821}, /* D-Link - Cameo */
201
{USB_DEVICE(0x2001, 0x3318), .driver_info = RTL8821}, /* D-Link - Cameo */
202
{USB_DEVICE(0x0E66, 0x0023), .driver_info = RTL8821}, /* HAWKING - Edimax */
203
{USB_DEVICE(0x056E, 0x400E), .driver_info = RTL8821}, /* ELECOM - ELECOM */
204
{USB_DEVICE(0x056E, 0x400F), .driver_info = RTL8821}, /* ELECOM - ELECOM */
205
{USB_DEVICE(0x0411, 0x0242), .driver_info = RTL8821}, /* ELECOM - WDC-433DU2H */
206
{USB_DEVICE(0x2019, 0xAB32), .driver_info = RTL8821}, /* Planex - GW-450S */
207
{USB_DEVICE(0x0846, 0x9052), .driver_info = RTL8821}, /* Netgear - A6100 */
208
{USB_DEVICE(0x0411, 0x029B), .driver_info = RTL8821}, /* Buffalo - WI-U2-433DHP */
209
{USB_DEVICE(0x056E, 0x4007), .driver_info = RTL8821}, /* Elecom - WDC-433DU2HBK */
210
{USB_DEVICE(0x0BDA, 0xA811), .driver_info = RTL8821}, /* GMYLE - AC450 */
211
{USB_DEVICE(0x3823, 0x6249), .driver_info = RTL8821}, /* Obihai - OBiWiFi */
212
{USB_DEVICE(0x2357, 0x011E), .driver_info = RTL8821}, /* TP Link - T2U Nano */
213
{USB_DEVICE(0x2357, 0x0122), .driver_info = RTL8821}, /* TP Link - T2U Nano */
214
{USB_DEVICE(0x2357, 0x0120), .driver_info = RTL8821}, /* TP Link - T2U Plus */
215
{USB_DEVICE(0x2357, 0x011F), .driver_info = RTL8821}, /* TP-Link - Archer AC600 T2U Nano */
216
{USB_DEVICE(0x20f4, 0x804b), .driver_info = RTL8821}, /* TRENDnet */
217
#endif
218
219
#ifdef CONFIG_RTL8192E
220
/*=== Realtek demoboard ===*/
221
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818B, 0xff, 0xff, 0xff), .driver_info = RTL8192E}, /* Default ID */
222
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818C, 0xff, 0xff, 0xff), .driver_info = RTL8192E}, /* Default ID */
223
#endif
224
225
#ifdef CONFIG_RTL8723B
226
/* === Realtek demoboard === */
227
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB720, 0xff, 0xff, 0xff), .driver_info = RTL8723B}, /* 8723BU 1*1 */
228
/* {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB720),.driver_info = RTL8723B}, 8723BU */
229
#endif
230
231
#ifdef CONFIG_RTL8703B
232
/*=== Realtek demoboard ===*/
233
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB703, 0xff, 0xff, 0xff), .driver_info = RTL8703B}, /* 8723CU 1*1 */
234
/* {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB703), .driver_info = RTL723C}, */ /* 8723CU 1*1 */
235
#endif /* CONFIG_RTL8703B */
236
237
#ifdef CONFIG_RTL8814A
238
{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8813), .driver_info = RTL8814A},
239
/*=== Customer ID ===*/
240
{USB_DEVICE(0x2001, 0x331A), .driver_info = RTL8814A}, /* D-Link - D-Link */
241
{USB_DEVICE(0x0B05, 0x1817), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */
242
{USB_DEVICE(0x0B05, 0x1852), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */
243
{USB_DEVICE(0x0B05, 0x1853), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */
244
{USB_DEVICE(0x056E, 0x400B), .driver_info = RTL8814A}, /* ELECOM - ELECOM */
245
{USB_DEVICE(0x056E, 0x400D), .driver_info = RTL8814A}, /* ELECOM - ELECOM */
246
{USB_DEVICE(0x7392, 0xA834), .driver_info = RTL8814A}, /* Edimax - Edimax */
247
{USB_DEVICE(0x7392, 0xA833), .driver_info = RTL8814A}, /* Edimax - AC1750 */
248
{USB_DEVICE(0x0BDA, 0x8813), .driver_info = RTL8814A}, /* Edimax - EDUP Adapters */
249
{USB_DEVICE(0x0e66, 0x0026), .driver_info = RTL8814A}, /* Hawking Technologies - HW17ACU*/
250
{USB_DEVICE(0x2357, 0x0106), .driver_info = RTL8814A}, /* TP-LINK Archer T9UH */
251
{USB_DEVICE(0x20F4, 0x809A), .driver_info = RTL8814A}, /* TRENDnet - TRENDnet */
252
{USB_DEVICE(0x20F4, 0x809B), .driver_info = RTL8814A}, /* TRENDnet TEW-809UB */
253
{USB_DEVICE(0x0846, 0x9054), .driver_info = RTL8814A}, /* Netgear A7000 */
254
255
#endif /* CONFIG_RTL8814A */
256
257
#ifdef CONFIG_RTL8188F
258
/*=== Realtek demoboard ===*/
259
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xF179, 0xff, 0xff, 0xff), .driver_info = RTL8188F}, /* 8188FU 1*1 */
260
#endif
261
262
#ifdef CONFIG_RTL8188GTV
263
/*=== Realtek demoboard ===*/
264
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x018C, 0xff, 0xff, 0xff), .driver_info = RTL8188GTV}, /* 8188GTV 1*1 */
265
#endif
266
267
#ifdef CONFIG_RTL8822B
268
/*=== Realtek demoboard ===*/
269
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB82C, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Default ID for USB multi-function */
270
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB812, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Default ID for USB Single-function, WiFi only */
271
/*=== Customer ID ===*/
272
{USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Alpha - Alpha*/
273
{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x1841, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* ASUS AC1300 USB-AC55 B1 */
274
{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x184C, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* ASUS U2*/
275
{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xB822, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Edimax EW-7822ULC */
276
{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xC822, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Edimax EW-7822UTC */
277
{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331e, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Dlink - DWA-181*/
278
{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331c, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Dlink - DWA-182*/
279
{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9055, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* NetGear A6150 */
280
{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x012D, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T3U */
281
{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0138, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T3U Plus */
282
{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0115, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T4U V3 */
283
{USB_DEVICE_AND_INTERFACE_INFO(0x20F4, 0x808A, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TRENDnet TEW-808UBM */
284
#endif /* CONFIG_RTL8822B */
285
286
#ifdef CONFIG_RTL8723D
287
/*=== Realtek demoboard ===*/
288
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD723, 0xff, 0xff, 0xff), .driver_info = RTL8723D}, /* 8723DU 1*1 */
289
#endif
290
291
#ifdef CONFIG_RTL8192F
292
/*=== Realtek demoboard ===*/
293
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xF192, 0xff, 0xff, 0xff), .driver_info = RTL8192F}, /* 8192FU 2*2 */
294
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xA725, 0xff, 0xff, 0xff), .driver_info = RTL8192F}, /* 8725AU 2*2 */
295
#endif
296
297
#ifdef CONFIG_RTL8821C
298
/*=== Realtek demoboard ===*/
299
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xb82b, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
300
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xb820, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
301
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC821, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
302
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC820, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
303
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82A, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
304
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82B, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */
305
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC811, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8811CU */
306
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x8811, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8811CU */
307
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x2006, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* TOTOLINK A650UA v3 */
308
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x8731, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8731AU */
309
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC80C, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CUH */
310
/*=== Customer ID ===*/
311
{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331d, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* D-Link - DWA-171C */
312
#endif
313
314
#ifdef CONFIG_RTL8710B
315
/*=== Realtek dongle ===*/
316
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB711, 0xff, 0xff, 0xff), .driver_info = RTL8710B}, /* 8710B = 8188GU 1*1 */
317
#endif
318
319
#ifdef CONFIG_RTL8822C
320
/*=== Realtek demoboard ===*/
321
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82C, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB multi-function */
322
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82E, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB multi-function */
323
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC812, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB Single-function, WiFi only */
324
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD820, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* 21D USB multi-fuction*/
325
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD82B, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* 21D USB Single-fuction, WiFi only*/
326
/*=== Customer ID ===*/
327
{USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Alpha - Alpha*/
328
#endif /* CONFIG_RTL8822C */
329
330
#ifdef CONFIG_RTL8814B
331
/*=== Realtek demoboard ===*/
332
{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB814, 0xff, 0xff, 0xff), .driver_info = RTL8814B}, /* Default ID for USB multi-function */
333
#endif /* CONFIG_RTL8814B */
334
335
{} /* Terminating entry */
336
};
337
338
MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);
339
340
int const rtw_usb_id_len = sizeof(rtw_usb_id_tbl) / sizeof(struct usb_device_id);
341
342
static struct specific_device_id specific_device_id_tbl[] = {
343
{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x8177, .flags = SPEC_DEV_ID_DISABLE_HT}, /* 8188cu 1*1 dongole, (b/g mode only) */
344
{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x817E, .flags = SPEC_DEV_ID_DISABLE_HT}, /* 8188CE-VAU USB minCard (b/g mode only) */
345
{.idVendor = 0x0b05, .idProduct = 0x1791, .flags = SPEC_DEV_ID_DISABLE_HT},
346
{.idVendor = 0x13D3, .idProduct = 0x3311, .flags = SPEC_DEV_ID_DISABLE_HT},
347
{.idVendor = 0x13D3, .idProduct = 0x3359, .flags = SPEC_DEV_ID_DISABLE_HT}, /* Russian customer -Azwave (8188CE-VAU g mode) */
348
#ifdef RTK_DMP_PLATFORM
349
{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x8111, .flags = SPEC_DEV_ID_ASSIGN_IFNAME}, /* Realtek 5G dongle for WiFi Display */
350
{.idVendor = 0x2019, .idProduct = 0xAB2D, .flags = SPEC_DEV_ID_ASSIGN_IFNAME}, /* PCI-Abocom 5G dongle for WiFi Display */
351
#endif /* RTK_DMP_PLATFORM */
352
{}
353
};
354
355
struct rtw_usb_drv {
356
struct usb_driver usbdrv;
357
int drv_registered;
358
u8 hw_type;
359
};
360
361
struct rtw_usb_drv usb_drv = {
362
.usbdrv.name = (char *)DRV_NAME,
363
.usbdrv.probe = rtw_drv_init,
364
.usbdrv.disconnect = rtw_dev_remove,
365
.usbdrv.id_table = rtw_usb_id_tbl,
366
.usbdrv.suspend = rtw_suspend,
367
.usbdrv.resume = rtw_resume,
368
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))
369
.usbdrv.reset_resume = rtw_resume,
370
#endif
371
#ifdef CONFIG_AUTOSUSPEND
372
.usbdrv.supports_autosuspend = 1,
373
#endif
374
375
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))
376
.usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,
377
#else
378
.usbdrv.driver.shutdown = rtw_dev_shutdown,
379
#endif
380
};
381
382
static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)
383
{
384
return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN;
385
}
386
387
static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)
388
{
389
return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT;
390
}
391
392
static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)
393
{
394
return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT;
395
}
396
397
static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)
398
{
399
return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK;
400
}
401
402
static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)
403
{
404
return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd);
405
}
406
407
static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)
408
{
409
return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd);
410
}
411
412
static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)
413
{
414
return RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd);
415
}
416
417
static inline int RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)
418
{
419
return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;
420
}
421
422
static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)
423
{
424
u8 rst = _SUCCESS;
425
426
#ifdef CONFIG_USB_VENDOR_REQ_MUTEX
427
_rtw_mutex_init(&dvobj->usb_vendor_req_mutex);
428
#endif
429
430
431
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
432
dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);
433
if (dvobj->usb_alloc_vendor_req_buf == NULL) {
434
RTW_INFO("alloc usb_vendor_req_buf failed... /n");
435
rst = _FAIL;
436
goto exit;
437
}
438
dvobj->usb_vendor_req_buf =
439
(u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(dvobj->usb_alloc_vendor_req_buf), ALIGNMENT_UNIT);
440
exit:
441
#endif
442
443
return rst;
444
445
}
446
447
static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)
448
{
449
u8 rst = _SUCCESS;
450
451
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC
452
if (dvobj->usb_vendor_req_buf)
453
rtw_mfree(dvobj->usb_alloc_vendor_req_buf, MAX_USB_IO_CTL_SIZE);
454
#endif
455
456
#ifdef CONFIG_USB_VENDOR_REQ_MUTEX
457
_rtw_mutex_free(&dvobj->usb_vendor_req_mutex);
458
#endif
459
460
return rst;
461
}
462
static void rtw_decide_chip_type_by_usb_info(struct dvobj_priv *pdvobjpriv, const struct usb_device_id *pdid)
463
{
464
pdvobjpriv->chip_type = pdid->driver_info;
465
466
#ifdef CONFIG_RTL8188E
467
if (pdvobjpriv->chip_type == RTL8188E)
468
rtl8188eu_set_hw_type(pdvobjpriv);
469
#endif
470
471
#if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
472
if (pdvobjpriv->chip_type == RTL8812 || pdvobjpriv->chip_type == RTL8821)
473
rtl8812au_set_hw_type(pdvobjpriv);
474
#endif
475
476
#ifdef CONFIG_RTL8192E
477
if (pdvobjpriv->chip_type == RTL8192E)
478
rtl8192eu_set_hw_type(pdvobjpriv);
479
#endif
480
481
#ifdef CONFIG_RTL8723B
482
if (pdvobjpriv->chip_type == RTL8723B)
483
rtl8723bu_set_hw_type(pdvobjpriv);
484
#endif
485
486
#ifdef CONFIG_RTL8814A
487
if (pdvobjpriv->chip_type == RTL8814A)
488
rtl8814au_set_hw_type(pdvobjpriv);
489
#endif /* CONFIG_RTL8814A */
490
491
#ifdef CONFIG_RTL8188F
492
if (pdvobjpriv->chip_type == RTL8188F)
493
rtl8188fu_set_hw_type(pdvobjpriv);
494
#endif
495
496
#ifdef CONFIG_RTL8188GTV
497
if (pdvobjpriv->chip_type == RTL8188GTV)
498
rtl8188gtvu_set_hw_type(pdvobjpriv);
499
#endif
500
501
#ifdef CONFIG_RTL8703B
502
if (pdvobjpriv->chip_type == RTL8703B)
503
rtl8703bu_set_hw_type(pdvobjpriv);
504
#endif /* CONFIG_RTL8703B */
505
506
#ifdef CONFIG_RTL8822B
507
if (pdvobjpriv->chip_type == RTL8822B)
508
rtl8822bu_set_hw_type(pdvobjpriv);
509
#endif /* CONFIG_RTL8822B */
510
511
#ifdef CONFIG_RTL8723D
512
if (pdvobjpriv->chip_type == RTL8723D)
513
rtl8723du_set_hw_type(pdvobjpriv);
514
#endif /* CONFIG_RTL8723D */
515
516
#ifdef CONFIG_RTL8821C
517
if (pdvobjpriv->chip_type == RTL8821C)
518
rtl8821cu_set_hw_type(pdvobjpriv);
519
#endif /* CONFIG_RTL8821C */
520
521
#ifdef CONFIG_RTL8710B
522
if (pdvobjpriv->chip_type == RTL8710B)
523
rtl8710bu_set_hw_type(pdvobjpriv);
524
#endif /* CONFIG_RTL8710B */
525
526
#ifdef CONFIG_RTL8192F
527
if (pdvobjpriv->chip_type == RTL8192F)
528
rtl8192fu_set_hw_type(pdvobjpriv);
529
#endif /* CONFIG_RTL8192F */
530
531
#ifdef CONFIG_RTL8822C
532
if (pdvobjpriv->chip_type == RTL8822C)
533
rtl8822cu_set_hw_type(pdvobjpriv);
534
#endif /* CONFIG_RTL8822C */
535
536
#ifdef CONFIG_RTL8814B
537
if (pdvobjpriv->chip_type == RTL8814B)
538
rtl8814bu_set_hw_type(pdvobjpriv);
539
#endif /* CONFIG_RTL8814B */
540
}
541
542
static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf, const struct usb_device_id *pdid)
543
{
544
int i;
545
int status = _FAIL;
546
struct dvobj_priv *pdvobjpriv;
547
struct usb_device_descriptor *pdev_desc;
548
struct usb_host_config *phost_conf;
549
struct usb_config_descriptor *pconf_desc;
550
struct usb_host_interface *phost_iface;
551
struct usb_interface_descriptor *piface_desc;
552
struct usb_host_endpoint *phost_endp;
553
struct usb_endpoint_descriptor *pendp_desc;
554
struct usb_device *pusbd;
555
556
557
558
pdvobjpriv = devobj_init();
559
if (pdvobjpriv == NULL)
560
goto exit;
561
562
563
pdvobjpriv->pusbintf = usb_intf ;
564
pusbd = pdvobjpriv->pusbdev = interface_to_usbdev(usb_intf);
565
usb_set_intfdata(usb_intf, pdvobjpriv);
566
567
pdvobjpriv->RtNumInPipes = 0;
568
pdvobjpriv->RtNumOutPipes = 0;
569
570
/* padapter->EepromAddressSize = 6; */
571
/* pdvobjpriv->nr_endpoint = 6; */
572
573
pdev_desc = &pusbd->descriptor;
574
575
#if 0
576
RTW_INFO("\n8712_usb_device_descriptor:\n");
577
RTW_INFO("bLength=%x\n", pdev_desc->bLength);
578
RTW_INFO("bDescriptorType=%x\n", pdev_desc->bDescriptorType);
579
RTW_INFO("bcdUSB=%x\n", pdev_desc->bcdUSB);
580
RTW_INFO("bDeviceClass=%x\n", pdev_desc->bDeviceClass);
581
RTW_INFO("bDeviceSubClass=%x\n", pdev_desc->bDeviceSubClass);
582
RTW_INFO("bDeviceProtocol=%x\n", pdev_desc->bDeviceProtocol);
583
RTW_INFO("bMaxPacketSize0=%x\n", pdev_desc->bMaxPacketSize0);
584
RTW_INFO("idVendor=%x\n", pdev_desc->idVendor);
585
RTW_INFO("idProduct=%x\n", pdev_desc->idProduct);
586
RTW_INFO("bcdDevice=%x\n", pdev_desc->bcdDevice);
587
RTW_INFO("iManufacturer=%x\n", pdev_desc->iManufacturer);
588
RTW_INFO("iProduct=%x\n", pdev_desc->iProduct);
589
RTW_INFO("iSerialNumber=%x\n", pdev_desc->iSerialNumber);
590
RTW_INFO("bNumConfigurations=%x\n", pdev_desc->bNumConfigurations);
591
#endif
592
593
phost_conf = pusbd->actconfig;
594
pconf_desc = &phost_conf->desc;
595
596
597
/* RTW_INFO("\n***** num of altsetting = (%d) *****\n", pusb_interface->num_altsetting); */
598
599
phost_iface = &usb_intf->altsetting[0];
600
piface_desc = &phost_iface->desc;
601
602
pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;
603
604
/* RTW_INFO("\ndump usb_endpoint_descriptor:\n"); */
605
606
for (i = 0; i < pdvobjpriv->nr_endpoint; i++) {
607
phost_endp = phost_iface->endpoint + i;
608
if (phost_endp) {
609
pendp_desc = &phost_endp->desc;
610
611
RTW_INFO("usb_endpoint_descriptor(%d):\n", i);
612
RTW_INFO("bLength=%x\n", pendp_desc->bLength);
613
RTW_INFO("bDescriptorType=%x\n", pendp_desc->bDescriptorType);
614
RTW_INFO("bEndpointAddress=%x\n", pendp_desc->bEndpointAddress);
615
/* RTW_INFO("bmAttributes=%x\n",pendp_desc->bmAttributes); */
616
RTW_INFO("wMaxPacketSize=%d\n", le16_to_cpu(pendp_desc->wMaxPacketSize));
617
RTW_INFO("bInterval=%x\n", pendp_desc->bInterval);
618
/* RTW_INFO("bRefresh=%x\n",pendp_desc->bRefresh); */
619
/* RTW_INFO("bSynchAddress=%x\n",pendp_desc->bSynchAddress); */
620
621
if (RT_usb_endpoint_is_bulk_in(pendp_desc)) {
622
RTW_INFO("RT_usb_endpoint_is_bulk_in = %x\n", RT_usb_endpoint_num(pendp_desc));
623
pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
624
pdvobjpriv->RtNumInPipes++;
625
} else if (RT_usb_endpoint_is_int_in(pendp_desc)) {
626
RTW_INFO("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", RT_usb_endpoint_num(pendp_desc), pendp_desc->bInterval);
627
pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);
628
pdvobjpriv->RtNumInPipes++;
629
} else if (RT_usb_endpoint_is_bulk_out(pendp_desc)) {
630
RTW_INFO("RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));
631
pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = RT_usb_endpoint_num(pendp_desc);
632
pdvobjpriv->RtNumOutPipes++;
633
}
634
pdvobjpriv->ep_num[i] = RT_usb_endpoint_num(pendp_desc);
635
}
636
}
637
638
RTW_INFO("nr_endpoint=%d, in_num=%d, out_num=%d\n", pdvobjpriv->nr_endpoint, pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);
639
640
switch (pusbd->speed) {
641
case USB_SPEED_LOW:
642
RTW_INFO("USB_SPEED_LOW\n");
643
pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
644
break;
645
case USB_SPEED_FULL:
646
RTW_INFO("USB_SPEED_FULL\n");
647
pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;
648
break;
649
case USB_SPEED_HIGH:
650
RTW_INFO("USB_SPEED_HIGH\n");
651
pdvobjpriv->usb_speed = RTW_USB_SPEED_2;
652
break;
653
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))
654
case USB_SPEED_SUPER:
655
RTW_INFO("USB_SPEED_SUPER\n");
656
pdvobjpriv->usb_speed = RTW_USB_SPEED_3;
657
break;
658
#endif
659
default:
660
RTW_INFO("USB_SPEED_UNKNOWN(%x)\n", pusbd->speed);
661
pdvobjpriv->usb_speed = RTW_USB_SPEED_UNKNOWN;
662
break;
663
}
664
665
if (pdvobjpriv->usb_speed == RTW_USB_SPEED_UNKNOWN) {
666
RTW_INFO("UNKNOWN USB SPEED MODE, ERROR !!!\n");
667
goto free_dvobj;
668
}
669
670
if (rtw_init_intf_priv(pdvobjpriv) == _FAIL) {
671
goto free_dvobj;
672
}
673
674
/*step 1-1., decide the chip_type via driver_info*/
675
pdvobjpriv->interface_type = RTW_USB;
676
rtw_decide_chip_type_by_usb_info(pdvobjpriv, pdid);
677
678
/* .3 misc */
679
_rtw_init_sema(&(pdvobjpriv->usb_suspend_sema), 0);
680
rtw_reset_continual_io_error(pdvobjpriv);
681
682
usb_get_dev(pusbd);
683
684
status = _SUCCESS;
685
686
free_dvobj:
687
if (status != _SUCCESS && pdvobjpriv) {
688
usb_set_intfdata(usb_intf, NULL);
689
690
devobj_deinit(pdvobjpriv);
691
692
pdvobjpriv = NULL;
693
}
694
exit:
695
return pdvobjpriv;
696
}
697
698
static void usb_dvobj_deinit(struct usb_interface *usb_intf)
699
{
700
struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);
701
702
703
usb_set_intfdata(usb_intf, NULL);
704
if (dvobj) {
705
rtw_deinit_intf_priv(dvobj);
706
devobj_deinit(dvobj);
707
}
708
709
/* RTW_INFO("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount)); */
710
usb_put_dev(interface_to_usbdev(usb_intf));
711
712
}
713
714
static int usb_reprobe_switch_usb_mode(PADAPTER Adapter)
715
{
716
struct registry_priv *registry_par = &Adapter->registrypriv;
717
HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);
718
u8 ret = _FALSE;
719
720
/* efuse not allow driver to switch usb mode */
721
if (pHalData->EEPROMUsbSwitch == _FALSE)
722
goto exit;
723
724
/* registry not allow driver to switch usb mode */
725
if (registry_par->switch_usb_mode == 0)
726
goto exit;
727
728
rtw_hal_set_hwreg(Adapter, HW_VAR_USB_MODE, &ret);
729
730
exit:
731
return ret;
732
}
733
734
u8 rtw_set_hal_ops(_adapter *padapter)
735
{
736
/* alloc memory for HAL DATA */
737
if (rtw_hal_data_init(padapter) == _FAIL)
738
return _FAIL;
739
740
#ifdef CONFIG_RTL8188E
741
if (rtw_get_chip_type(padapter) == RTL8188E)
742
rtl8188eu_set_hal_ops(padapter);
743
#endif
744
745
#if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
746
if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)
747
rtl8812au_set_hal_ops(padapter);
748
#endif
749
750
#ifdef CONFIG_RTL8192E
751
if (rtw_get_chip_type(padapter) == RTL8192E)
752
rtl8192eu_set_hal_ops(padapter);
753
#endif
754
#ifdef CONFIG_RTL8723B
755
if (rtw_get_chip_type(padapter) == RTL8723B)
756
rtl8723bu_set_hal_ops(padapter);
757
#endif
758
#ifdef CONFIG_RTL8814A
759
if (rtw_get_chip_type(padapter) == RTL8814A)
760
rtl8814au_set_hal_ops(padapter);
761
#endif /* CONFIG_RTL8814A */
762
763
#ifdef CONFIG_RTL8188F
764
if (rtw_get_chip_type(padapter) == RTL8188F)
765
rtl8188fu_set_hal_ops(padapter);
766
#endif
767
768
#ifdef CONFIG_RTL8188GTV
769
if (rtw_get_chip_type(padapter) == RTL8188GTV)
770
rtl8188gtvu_set_hal_ops(padapter);
771
#endif
772
773
#ifdef CONFIG_RTL8703B
774
if (rtw_get_chip_type(padapter) == RTL8703B)
775
rtl8703bu_set_hal_ops(padapter);
776
#endif /* CONFIG_RTL8703B */
777
778
#ifdef CONFIG_RTL8822B
779
if (rtw_get_chip_type(padapter) == RTL8822B)
780
rtl8822bu_set_hal_ops(padapter);
781
#endif /* CONFIG_RTL8822B */
782
783
#ifdef CONFIG_RTL8723D
784
if (rtw_get_chip_type(padapter) == RTL8723D)
785
rtl8723du_set_hal_ops(padapter);
786
#endif /* CONFIG_RTL8723D */
787
788
789
#ifdef CONFIG_RTL8821C
790
if (rtw_get_chip_type(padapter) == RTL8821C) {
791
if (rtl8821cu_set_hal_ops(padapter) == _FAIL)
792
return _FAIL;
793
}
794
#endif
795
796
#ifdef CONFIG_RTL8710B
797
if (rtw_get_chip_type(padapter) == RTL8710B)
798
rtl8710bu_set_hal_ops(padapter);
799
#endif /* CONFIG_RTL8710B */
800
801
802
#ifdef CONFIG_RTL8192F
803
if (rtw_get_chip_type(padapter) == RTL8192F)
804
rtl8192fu_set_hal_ops(padapter);
805
#endif
806
807
#ifdef CONFIG_RTL8822C
808
if (rtw_get_chip_type(padapter) == RTL8822C)
809
rtl8822cu_set_hal_ops(padapter);
810
#endif /* CONFIG_RTL8822C */
811
812
#ifdef CONFIG_RTL8814B
813
if (rtw_get_chip_type(padapter) == RTL8814B)
814
rtl8814bu_set_hal_ops(padapter);
815
#endif /* CONFIG_RTL8814B */
816
817
818
if (_FAIL == rtw_hal_ops_check(padapter))
819
return _FAIL;
820
821
if (hal_spec_init(padapter) == _FAIL)
822
return _FAIL;
823
824
return _SUCCESS;
825
}
826
827
static void usb_intf_start(_adapter *padapter)
828
{
829
PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);
830
831
rtw_hal_inirp_init(padapter);
832
hal->usb_intf_start = _TRUE;
833
834
835
}
836
837
static void usb_intf_stop(_adapter *padapter)
838
{
839
PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);
840
841
/* disabel_hw_interrupt */
842
if (!rtw_is_surprise_removed(padapter)) {
843
/* device still exists, so driver can do i/o operation */
844
/* TODO: */
845
}
846
847
/* cancel in irp */
848
rtw_hal_inirp_deinit(padapter);
849
850
/* cancel out irp */
851
rtw_write_port_cancel(padapter);
852
853
/* todo:cancel other irps */
854
855
hal->usb_intf_start = _FALSE;
856
857
}
858
859
static void process_spec_devid(const struct usb_device_id *pdid)
860
{
861
u16 vid, pid;
862
u32 flags;
863
int i;
864
int num = sizeof(specific_device_id_tbl) / sizeof(struct specific_device_id);
865
866
for (i = 0; i < num; i++) {
867
vid = specific_device_id_tbl[i].idVendor;
868
pid = specific_device_id_tbl[i].idProduct;
869
flags = specific_device_id_tbl[i].flags;
870
871
#ifdef CONFIG_80211N_HT
872
if ((pdid->idVendor == vid) && (pdid->idProduct == pid) && (flags & SPEC_DEV_ID_DISABLE_HT)) {
873
rtw_ht_enable = 0;
874
rtw_bw_mode = 0;
875
rtw_ampdu_enable = 0;
876
}
877
#endif
878
879
#ifdef RTK_DMP_PLATFORM
880
/* Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform. */
881
/* It is used to distinguish between normal and PC-side wifi dongle/module. */
882
if ((pdid->idVendor == vid) && (pdid->idProduct == pid) && (flags & SPEC_DEV_ID_ASSIGN_IFNAME)) {
883
extern char *ifname;
884
strncpy(ifname, "wlan10", 6);
885
/* RTW_INFO("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid); */
886
}
887
#endif /* RTK_DMP_PLATFORM */
888
889
}
890
}
891
892
#ifdef SUPPORT_HW_RFOFF_DETECTED
893
int rtw_hw_suspend(_adapter *padapter)
894
{
895
struct pwrctrl_priv *pwrpriv;
896
struct usb_interface *pusb_intf;
897
struct net_device *pnetdev;
898
899
if (NULL == padapter)
900
goto error_exit;
901
902
if ((_FALSE == padapter->bup) || RTW_CANNOT_RUN(padapter)) {
903
RTW_INFO("padapter->bup=%d bDriverStopped=%s bSurpriseRemoved = %s\n"
904
, padapter->bup
905
, rtw_is_drv_stopped(padapter) ? "True" : "False"
906
, rtw_is_surprise_removed(padapter) ? "True" : "False");
907
goto error_exit;
908
}
909
910
pwrpriv = adapter_to_pwrctl(padapter);
911
pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
912
pnetdev = padapter->pnetdev;
913
914
LeaveAllPowerSaveMode(padapter);
915
916
RTW_INFO("==> rtw_hw_suspend\n");
917
_enter_pwrlock(&pwrpriv->lock);
918
pwrpriv->bips_processing = _TRUE;
919
/* padapter->net_closed = _TRUE; */
920
/* s1. */
921
if (pnetdev) {
922
rtw_netif_carrier_off(pnetdev);
923
rtw_netif_stop_queue(pnetdev);
924
}
925
926
/* s2. */
927
rtw_disassoc_cmd(padapter, 500, RTW_CMDF_DIRECTLY);
928
929
/* s2-2. indicate disconnect to os */
930
/* rtw_indicate_disconnect(padapter); */
931
{
932
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
933
if (check_fwstate(pmlmepriv, _FW_LINKED)) {
934
_clr_fwstate_(pmlmepriv, _FW_LINKED);
935
rtw_led_control(padapter, LED_CTL_NO_LINK);
936
937
rtw_os_indicate_disconnect(padapter, 0, _FALSE);
938
939
#ifdef CONFIG_LPS
940
/* donnot enqueue cmd */
941
rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, RTW_CMDF_DIRECTLY);
942
#endif
943
}
944
}
945
/* s2-3. */
946
rtw_free_assoc_resources(padapter, _TRUE);
947
948
/* s2-4. */
949
rtw_free_network_queue(padapter, _TRUE);
950
#ifdef CONFIG_IPS
951
rtw_ips_dev_unload(padapter);
952
#endif
953
pwrpriv->rf_pwrstate = rf_off;
954
pwrpriv->bips_processing = _FALSE;
955
_exit_pwrlock(&pwrpriv->lock);
956
957
return 0;
958
959
error_exit:
960
RTW_INFO("%s, failed\n", __FUNCTION__);
961
return -1;
962
963
}
964
965
int rtw_hw_resume(_adapter *padapter)
966
{
967
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
968
struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
969
struct net_device *pnetdev = padapter->pnetdev;
970
971
RTW_INFO("==> rtw_hw_resume\n");
972
_enter_pwrlock(&pwrpriv->lock);
973
pwrpriv->bips_processing = _TRUE;
974
rtw_reset_drv_sw(padapter);
975
976
if (pm_netdev_open(pnetdev, _FALSE) != 0) {
977
_exit_pwrlock(&pwrpriv->lock);
978
goto error_exit;
979
}
980
rtw_netif_device_attach(pnetdev);
981
rtw_netif_carrier_on(pnetdev);
982
983
rtw_netif_wake_queue(pnetdev);
984
985
pwrpriv->bkeepfwalive = _FALSE;
986
pwrpriv->brfoffbyhw = _FALSE;
987
988
pwrpriv->rf_pwrstate = rf_on;
989
pwrpriv->bips_processing = _FALSE;
990
_exit_pwrlock(&pwrpriv->lock);
991
992
993
return 0;
994
error_exit:
995
RTW_INFO("%s, Open net dev failed\n", __FUNCTION__);
996
return -1;
997
}
998
#endif
999
1000
static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
1001
{
1002
struct dvobj_priv *dvobj;
1003
struct pwrctrl_priv *pwrpriv;
1004
struct debug_priv *pdbgpriv;
1005
PADAPTER padapter;
1006
int ret = 0;
1007
1008
1009
dvobj = usb_get_intfdata(pusb_intf);
1010
pwrpriv = dvobj_to_pwrctl(dvobj);
1011
pdbgpriv = &dvobj->drv_dbg;
1012
padapter = dvobj_get_primary_adapter(dvobj);
1013
1014
if (pwrpriv->bInSuspend == _TRUE) {
1015
RTW_INFO("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
1016
pdbgpriv->dbg_suspend_error_cnt++;
1017
goto exit;
1018
}
1019
1020
if ((padapter->bup) || !rtw_is_drv_stopped(padapter) || !rtw_is_surprise_removed(padapter)) {
1021
#ifdef CONFIG_AUTOSUSPEND
1022
if (pwrpriv->bInternalAutoSuspend) {
1023
1024
#ifdef SUPPORT_HW_RFOFF_DETECTED
1025
/* The FW command register update must after MAC and FW init ready. */
1026
if ((GET_HAL_DATA(padapter)->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable)) {
1027
u8 bOpen = _TRUE;
1028
rtw_interface_ps_func(padapter, HAL_USB_SELECT_SUSPEND, &bOpen);
1029
}
1030
#endif/* SUPPORT_HW_RFOFF_DETECTED */
1031
}
1032
#endif/* CONFIG_AUTOSUSPEND */
1033
}
1034
1035
ret = rtw_suspend_common(padapter);
1036
1037
exit:
1038
return ret;
1039
}
1040
1041
int rtw_resume_process(_adapter *padapter)
1042
{
1043
int ret;
1044
#if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND)
1045
int pm_cnt = 0;
1046
#endif
1047
struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1048
struct dvobj_priv *pdvobj = padapter->dvobj;
1049
struct debug_priv *pdbgpriv = &pdvobj->drv_dbg;
1050
1051
1052
if (pwrpriv->bInSuspend == _FALSE) {
1053
pdbgpriv->dbg_resume_error_cnt++;
1054
RTW_INFO("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
1055
return -1;
1056
}
1057
1058
#if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND) /* add by amy for 8723as-vau */
1059
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1060
RTW_INFO("%s...pm_usage_cnt(%d) pwrpriv->bAutoResume=%x. ....\n", __func__, atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)), pwrpriv->bAutoResume);
1061
pm_cnt = atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));
1062
#else /* kernel < 2.6.32 */
1063
RTW_INFO("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);
1064
pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;
1065
#endif /* kernel < 2.6.32 */
1066
1067
RTW_INFO("pwrpriv->bAutoResume (%x)\n", pwrpriv->bAutoResume);
1068
if (_TRUE == pwrpriv->bAutoResume) {
1069
pwrpriv->bInternalAutoSuspend = _FALSE;
1070
pwrpriv->bAutoResume = _FALSE;
1071
RTW_INFO("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n", pwrpriv->bAutoResume, pwrpriv->bInternalAutoSuspend);
1072
1073
}
1074
#endif /* #ifdef CONFIG_BT_COEXIST &CONFIG_AUTOSUSPEND& */
1075
1076
/*
1077
* Due to usb wow suspend flow will cancel read/write port via intf_stop and
1078
* bReadPortCancel and bWritePortCancel are set _TRUE in intf_stop.
1079
* But they will not be clear in intf_start during wow resume flow.
1080
* It should move to os_intf in the feature.
1081
*/
1082
RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
1083
RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
1084
1085
ret = rtw_resume_common(padapter);
1086
1087
#ifdef CONFIG_AUTOSUSPEND
1088
if (pwrpriv->bInternalAutoSuspend) {
1089
#ifdef SUPPORT_HW_RFOFF_DETECTED
1090
/* The FW command register update must after MAC and FW init ready. */
1091
if ((GET_HAL_DATA(padapter)->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable)) {
1092
u8 bOpen = _FALSE;
1093
rtw_interface_ps_func(padapter, HAL_USB_SELECT_SUSPEND, &bOpen);
1094
}
1095
#endif
1096
#ifdef CONFIG_BT_COEXIST /* for 8723as-vau */
1097
RTW_INFO("pwrpriv->bAutoResume (%x)\n", pwrpriv->bAutoResume);
1098
if (_TRUE == pwrpriv->bAutoResume) {
1099
pwrpriv->bInternalAutoSuspend = _FALSE;
1100
pwrpriv->bAutoResume = _FALSE;
1101
RTW_INFO("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n", pwrpriv->bAutoResume, pwrpriv->bInternalAutoSuspend);
1102
}
1103
1104
#else /* #ifdef CONFIG_BT_COEXIST */
1105
pwrpriv->bInternalAutoSuspend = _FALSE;
1106
#endif /* #ifdef CONFIG_BT_COEXIST */
1107
pwrpriv->brfoffbyhw = _FALSE;
1108
}
1109
#endif/* CONFIG_AUTOSUSPEND */
1110
1111
1112
return ret;
1113
}
1114
1115
static int rtw_resume(struct usb_interface *pusb_intf)
1116
{
1117
struct dvobj_priv *dvobj;
1118
struct pwrctrl_priv *pwrpriv;
1119
struct debug_priv *pdbgpriv;
1120
PADAPTER padapter;
1121
struct mlme_ext_priv *pmlmeext;
1122
int ret = 0;
1123
1124
1125
dvobj = usb_get_intfdata(pusb_intf);
1126
pwrpriv = dvobj_to_pwrctl(dvobj);
1127
pdbgpriv = &dvobj->drv_dbg;
1128
padapter = dvobj_get_primary_adapter(dvobj);
1129
pmlmeext = &padapter->mlmeextpriv;
1130
1131
RTW_INFO("==> %s (%s:%d)\n", __FUNCTION__, current->comm, current->pid);
1132
pdbgpriv->dbg_resume_cnt++;
1133
1134
#ifdef CONFIG_AUTOSUSPEND
1135
if (pwrpriv->bInternalAutoSuspend)
1136
ret = rtw_resume_process(padapter);
1137
else
1138
#endif
1139
{
1140
if (pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode) {
1141
rtw_resume_lock_suspend();
1142
ret = rtw_resume_process(padapter);
1143
rtw_resume_unlock_suspend();
1144
} else {
1145
#ifdef CONFIG_RESUME_IN_WORKQUEUE
1146
rtw_resume_in_workqueue(pwrpriv);
1147
#else
1148
if (rtw_is_earlysuspend_registered(pwrpriv)) {
1149
/* jeff: bypass resume here, do in late_resume */
1150
rtw_set_do_late_resume(pwrpriv, _TRUE);
1151
} else {
1152
rtw_resume_lock_suspend();
1153
ret = rtw_resume_process(padapter);
1154
rtw_resume_unlock_suspend();
1155
}
1156
#endif
1157
}
1158
}
1159
1160
pmlmeext->last_scan_time = rtw_get_current_time();
1161
RTW_INFO("<======== %s return %d\n", __FUNCTION__, ret);
1162
1163
return ret;
1164
}
1165
1166
1167
1168
#ifdef CONFIG_AUTOSUSPEND
1169
void autosuspend_enter(_adapter *padapter)
1170
{
1171
struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1172
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1173
1174
RTW_INFO("==>autosuspend_enter...........\n");
1175
1176
pwrpriv->bInternalAutoSuspend = _TRUE;
1177
pwrpriv->bips_processing = _TRUE;
1178
1179
if (rf_off == pwrpriv->change_rfpwrstate) {
1180
#ifndef CONFIG_BT_COEXIST
1181
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
1182
usb_enable_autosuspend(dvobj->pusbdev);
1183
#else
1184
dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */
1185
#endif
1186
1187
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1188
usb_autopm_put_interface(dvobj->pusbintf);
1189
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1190
usb_autopm_enable(dvobj->pusbintf);
1191
#else
1192
usb_autosuspend_device(dvobj->pusbdev, 1);
1193
#endif
1194
#else /* #ifndef CONFIG_BT_COEXIST */
1195
if (1 == pwrpriv->autopm_cnt) {
1196
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
1197
usb_enable_autosuspend(dvobj->pusbdev);
1198
#else
1199
dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */
1200
#endif
1201
1202
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1203
usb_autopm_put_interface(dvobj->pusbintf);
1204
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1205
usb_autopm_enable(dvobj->pusbintf);
1206
#else
1207
usb_autosuspend_device(dvobj->pusbdev, 1);
1208
#endif
1209
pwrpriv->autopm_cnt--;
1210
} else
1211
RTW_INFO("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_put_interface\n", pwrpriv->autopm_cnt);
1212
1213
#endif /* #ifndef CONFIG_BT_COEXIST */
1214
}
1215
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1216
RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1217
#else
1218
RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1219
#endif
1220
1221
}
1222
1223
int autoresume_enter(_adapter *padapter)
1224
{
1225
int result = _SUCCESS;
1226
struct security_priv *psecuritypriv = &(padapter->securitypriv);
1227
struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1228
struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1229
struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1230
struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1231
1232
RTW_INFO("====> autoresume_enter\n");
1233
1234
if (rf_off == pwrpriv->rf_pwrstate) {
1235
pwrpriv->ps_flag = _FALSE;
1236
#ifndef CONFIG_BT_COEXIST
1237
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1238
if (usb_autopm_get_interface(dvobj->pusbintf) < 0) {
1239
RTW_INFO("can't get autopm: %d\n", result);
1240
result = _FAIL;
1241
goto error_exit;
1242
}
1243
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1244
usb_autopm_disable(dvobj->pusbintf);
1245
#else
1246
usb_autoresume_device(dvobj->pusbdev, 1);
1247
#endif
1248
1249
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1250
RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1251
#else
1252
RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1253
#endif
1254
#else /* #ifndef CONFIG_BT_COEXIST */
1255
pwrpriv->bAutoResume = _TRUE;
1256
if (0 == pwrpriv->autopm_cnt) {
1257
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1258
if (usb_autopm_get_interface(dvobj->pusbintf) < 0) {
1259
RTW_INFO("can't get autopm: %d\n", result);
1260
result = _FAIL;
1261
goto error_exit;
1262
}
1263
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1264
usb_autopm_disable(dvobj->pusbintf);
1265
#else
1266
usb_autoresume_device(dvobj->pusbdev, 1);
1267
#endif
1268
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1269
RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1270
#else
1271
RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1272
#endif
1273
pwrpriv->autopm_cnt++;
1274
} else
1275
RTW_INFO("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_get_interface\n", pwrpriv->autopm_cnt);
1276
#endif /* #ifndef CONFIG_BT_COEXIST */
1277
}
1278
RTW_INFO("<==== autoresume_enter\n");
1279
error_exit:
1280
1281
return result;
1282
}
1283
#endif
1284
1285
#ifdef CONFIG_PLATFORM_RTD2880B
1286
extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);
1287
#endif
1288
1289
/*
1290
* drv_init() - a device potentially for us
1291
*
1292
* notes: drv_init() is called when the bus driver has located a card for us to support.
1293
* We accept the new device by returning 0.
1294
*/
1295
_adapter *rtw_usb_primary_adapter_init(struct dvobj_priv *dvobj,
1296
struct usb_interface *pusb_intf)
1297
{
1298
_adapter *padapter = NULL;
1299
int status = _FAIL;
1300
1301
padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));
1302
if (padapter == NULL)
1303
goto exit;
1304
1305
if (loadparam(padapter) != _SUCCESS)
1306
goto free_adapter;
1307
1308
padapter->dvobj = dvobj;
1309
1310
1311
rtw_set_drv_stopped(padapter);/*init*/
1312
1313
dvobj->padapters[dvobj->iface_nums++] = padapter;
1314
padapter->iface_id = IFACE_ID0;
1315
1316
/* set adapter_type/iface type for primary padapter */
1317
padapter->isprimary = _TRUE;
1318
padapter->adapter_type = PRIMARY_ADAPTER;
1319
#ifdef CONFIG_MI_WITH_MBSSID_CAM/*Configure all IFACE to PORT0-MBSSID*/
1320
padapter->hw_port = HW_PORT0;
1321
#else
1322
padapter->hw_port = HW_PORT0;
1323
#endif
1324
1325
/* step init_io_priv */
1326
if (rtw_init_io_priv(padapter, usb_set_intf_ops) == _FAIL)
1327
goto free_adapter;
1328
1329
/* step 2. hook HalFunc, allocate HalData */
1330
if (rtw_set_hal_ops(padapter) == _FAIL)
1331
goto free_hal_data;
1332
1333
1334
padapter->intf_start = &usb_intf_start;
1335
padapter->intf_stop = &usb_intf_stop;
1336
1337
/* step read_chip_version */
1338
rtw_hal_read_chip_version(padapter);
1339
1340
/* step usb endpoint mapping */
1341
rtw_hal_chip_configure(padapter);
1342
1343
#ifdef CONFIG_BT_COEXIST
1344
rtw_btcoex_Initialize(padapter);
1345
#endif
1346
rtw_btcoex_wifionly_initialize(padapter);
1347
1348
/* step read efuse/eeprom data and get mac_addr */
1349
if (rtw_hal_read_chip_info(padapter) == _FAIL)
1350
goto free_hal_data;
1351
1352
/* step 5. */
1353
if (rtw_init_drv_sw(padapter) == _FAIL) {
1354
goto free_hal_data;
1355
}
1356
1357
#ifdef CONFIG_PM
1358
#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))
1359
if (dvobj_to_pwrctl(dvobj)->bSupportRemoteWakeup) {
1360
dvobj->pusbdev->do_remote_wakeup = 1;
1361
pusb_intf->needs_remote_wakeup = 1;
1362
device_init_wakeup(&pusb_intf->dev, 1);
1363
RTW_INFO("pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
1364
RTW_INFO("pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n", device_may_wakeup(&pusb_intf->dev));
1365
}
1366
#endif
1367
#endif
1368
1369
#ifdef CONFIG_AUTOSUSPEND
1370
if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) {
1371
if (padapter->registrypriv.usbss_enable) { /* autosuspend (2s delay) */
1372
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))
1373
dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;/* 15 * HZ; idle-delay time */
1374
#else
1375
dvobj->pusbdev->autosuspend_delay = 0 * HZ;/* 15 * HZ; idle-delay time */
1376
#endif
1377
1378
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))
1379
usb_enable_autosuspend(dvobj->pusbdev);
1380
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 34))
1381
padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;
1382
dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */
1383
#endif
1384
1385
/* usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf ); */ /* init pm_usage_cnt ,let it start from 1 */
1386
1387
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))
1388
RTW_INFO("%s...pm_usage_cnt(%d).....\n", __FUNCTION__, atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1389
#else
1390
RTW_INFO("%s...pm_usage_cnt(%d).....\n", __FUNCTION__, dvobj->pusbintf->pm_usage_cnt);
1391
#endif
1392
}
1393
}
1394
#endif
1395
/* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto suspend influence */
1396
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1397
if (usb_autopm_get_interface(pusb_intf) < 0)
1398
RTW_INFO("can't get autopm:\n");
1399
#endif
1400
#ifdef CONFIG_BT_COEXIST
1401
dvobj_to_pwrctl(dvobj)->autopm_cnt = 1;
1402
#endif
1403
1404
/* set mac addr */
1405
rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));
1406
#ifdef CONFIG_MI_WITH_MBSSID_CAM
1407
rtw_mbid_camid_alloc(padapter, adapter_mac_addr(padapter));
1408
#endif
1409
1410
#ifdef CONFIG_P2P
1411
rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
1412
#endif /* CONFIG_P2P */
1413
RTW_INFO("bDriverStopped:%s, bSurpriseRemoved:%s, bup:%d, hw_init_completed:%d\n"
1414
, rtw_is_drv_stopped(padapter) ? "True" : "False"
1415
, rtw_is_surprise_removed(padapter) ? "True" : "False"
1416
, padapter->bup
1417
, rtw_get_hw_init_completed(padapter)
1418
);
1419
1420
status = _SUCCESS;
1421
1422
free_hal_data:
1423
if (status != _SUCCESS && padapter->HalData)
1424
rtw_hal_free_data(padapter);
1425
free_adapter:
1426
if (status != _SUCCESS && padapter) {
1427
#ifdef RTW_HALMAC
1428
rtw_halmac_deinit_adapter(dvobj);
1429
#endif
1430
rtw_vmfree((u8 *)padapter, sizeof(*padapter));
1431
padapter = NULL;
1432
}
1433
exit:
1434
return padapter;
1435
}
1436
1437
static void rtw_usb_primary_adapter_deinit(_adapter *padapter)
1438
{
1439
#if defined(CONFIG_WOWLAN) || defined(CONFIG_BT_COEXIST)
1440
struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1441
#endif
1442
struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1443
1444
RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));
1445
1446
if (check_fwstate(pmlmepriv, _FW_LINKED))
1447
rtw_disassoc_cmd(padapter, 0, RTW_CMDF_DIRECTLY);
1448
1449
#ifdef CONFIG_AP_MODE
1450
if (MLME_IS_AP(padapter) || MLME_IS_MESH(padapter)) {
1451
free_mlme_ap_info(padapter);
1452
#ifdef CONFIG_HOSTAPD_MLME
1453
hostapd_mode_unload(padapter);
1454
#endif
1455
}
1456
#endif
1457
1458
/*rtw_cancel_all_timer(if1);*/
1459
1460
#ifdef CONFIG_WOWLAN
1461
pwrctl->wowlan_mode = _FALSE;
1462
#endif /* CONFIG_WOWLAN */
1463
1464
rtw_dev_unload(padapter);
1465
1466
RTW_INFO("+r871xu_dev_remove, hw_init_completed=%d\n", rtw_get_hw_init_completed(padapter));
1467
1468
#ifdef CONFIG_BT_COEXIST
1469
if (1 == pwrctl->autopm_cnt) {
1470
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))
1471
usb_autopm_put_interface(adapter_to_dvobj(padapter)->pusbintf);
1472
#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))
1473
usb_autopm_enable(adapter_to_dvobj(padapter)->pusbintf);
1474
#else
1475
usb_autosuspend_device(adapter_to_dvobj(padapter)->pusbdev, 1);
1476
#endif
1477
pwrctl->autopm_cnt--;
1478
}
1479
#endif
1480
1481
rtw_free_drv_sw(padapter);
1482
1483
/* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1484
rtw_os_ndev_free(padapter);
1485
1486
#ifdef RTW_HALMAC
1487
rtw_halmac_deinit_adapter(adapter_to_dvobj(padapter));
1488
#endif /* RTW_HALMAC */
1489
1490
rtw_vmfree((u8 *)padapter, sizeof(_adapter));
1491
1492
#ifdef CONFIG_PLATFORM_RTD2880B
1493
RTW_INFO("wlan link down\n");
1494
rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
1495
#endif
1496
1497
}
1498
1499
static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1500
{
1501
_adapter *padapter = NULL;
1502
int status = _FAIL;
1503
struct dvobj_priv *dvobj;
1504
#ifdef CONFIG_CONCURRENT_MODE
1505
int i;
1506
#endif
1507
1508
/* RTW_INFO("+rtw_drv_init\n"); */
1509
1510
/* step 0. */
1511
process_spec_devid(pdid);
1512
1513
/* Initialize dvobj_priv */
1514
dvobj = usb_dvobj_init(pusb_intf, pdid);
1515
if (dvobj == NULL) {
1516
goto exit;
1517
}
1518
1519
padapter = rtw_usb_primary_adapter_init(dvobj, pusb_intf);
1520
if (padapter == NULL) {
1521
RTW_INFO("rtw_usb_primary_adapter_init Failed!\n");
1522
goto free_dvobj;
1523
}
1524
1525
if (usb_reprobe_switch_usb_mode(padapter) == _TRUE)
1526
goto free_if_prim;
1527
1528
#ifdef CONFIG_CONCURRENT_MODE
1529
if (padapter->registrypriv.virtual_iface_num > (CONFIG_IFACE_NUMBER - 1))
1530
padapter->registrypriv.virtual_iface_num = (CONFIG_IFACE_NUMBER - 1);
1531
1532
for (i = 0; i < padapter->registrypriv.virtual_iface_num; i++) {
1533
if (rtw_drv_add_vir_if(padapter, usb_set_intf_ops) == NULL) {
1534
RTW_INFO("rtw_drv_add_iface failed! (%d)\n", i);
1535
goto free_if_vir;
1536
}
1537
}
1538
#endif
1539
1540
#ifdef CONFIG_GLOBAL_UI_PID
1541
if (ui_pid[1] != 0) {
1542
RTW_INFO("ui_pid[1]:%d\n", ui_pid[1]);
1543
rtw_signal_process(ui_pid[1], SIGUSR2);
1544
}
1545
#endif
1546
1547
/* dev_alloc_name && register_netdev */
1548
if (rtw_os_ndevs_init(dvobj) != _SUCCESS)
1549
goto free_if_vir;
1550
1551
#ifdef CONFIG_HOSTAPD_MLME
1552
hostapd_mode_init(padapter);
1553
#endif
1554
1555
#ifdef CONFIG_PLATFORM_RTD2880B
1556
RTW_INFO("wlan link up\n");
1557
rtd2885_wlan_netlink_sendMsg("linkup", "8712");
1558
#endif
1559
1560
1561
status = _SUCCESS;
1562
1563
#if 0 /* not used now */
1564
os_ndevs_deinit:
1565
if (status != _SUCCESS)
1566
rtw_os_ndevs_deinit(dvobj);
1567
#endif
1568
free_if_vir:
1569
if (status != _SUCCESS) {
1570
#ifdef CONFIG_CONCURRENT_MODE
1571
rtw_drv_stop_vir_ifaces(dvobj);
1572
rtw_drv_free_vir_ifaces(dvobj);
1573
#endif
1574
}
1575
1576
free_if_prim:
1577
if (status != _SUCCESS && padapter)
1578
rtw_usb_primary_adapter_deinit(padapter);
1579
1580
free_dvobj:
1581
if (status != _SUCCESS)
1582
usb_dvobj_deinit(pusb_intf);
1583
exit:
1584
return status == _SUCCESS ? 0 : -ENODEV;
1585
}
1586
1587
/*
1588
* dev_remove() - our device is being removed
1589
*/
1590
/* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */
1591
static void rtw_dev_remove(struct usb_interface *pusb_intf)
1592
{
1593
struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1594
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1595
struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
1596
#endif
1597
_adapter *padapter = dvobj_get_primary_adapter(dvobj);
1598
1599
RTW_INFO("+rtw_dev_remove\n");
1600
1601
dvobj->processing_dev_remove = _TRUE;
1602
1603
/* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1604
rtw_os_ndevs_unregister(dvobj);
1605
1606
if (usb_drv.drv_registered == _TRUE) {
1607
/* RTW_INFO("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n"); */
1608
rtw_set_surprise_removed(padapter);
1609
}
1610
/*else
1611
{
1612
1613
rtw_set_hw_init_completed(padapter, _FALSE);
1614
}*/
1615
1616
1617
#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1618
rtw_unregister_early_suspend(pwrctl);
1619
#endif
1620
1621
if (GET_HAL_DATA(padapter)->bFWReady == _TRUE) {
1622
rtw_pm_set_ips(padapter, IPS_NONE);
1623
rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
1624
1625
LeaveAllPowerSaveMode(padapter);
1626
}
1627
rtw_set_drv_stopped(padapter); /*for stop thread*/
1628
rtw_stop_cmd_thread(padapter);
1629
#ifdef CONFIG_CONCURRENT_MODE
1630
rtw_drv_stop_vir_ifaces(dvobj);
1631
#endif /* CONFIG_CONCURRENT_MODE */
1632
1633
#ifdef CONFIG_BT_COEXIST
1634
#ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1635
if (GET_HAL_DATA(padapter)->EEPROMBluetoothCoexist)
1636
rtw_btcoex_close_socket(padapter);
1637
#endif
1638
rtw_btcoex_HaltNotify(padapter);
1639
#endif
1640
1641
rtw_usb_primary_adapter_deinit(padapter);
1642
1643
#ifdef CONFIG_CONCURRENT_MODE
1644
rtw_drv_free_vir_ifaces(dvobj);
1645
#endif /* CONFIG_CONCURRENT_MODE */
1646
1647
usb_dvobj_deinit(pusb_intf);
1648
1649
// RTW_INFO("-r871xu_dev_remove, done\n");
1650
1651
return;
1652
1653
}
1654
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
1655
extern int console_suspend_enabled;
1656
#endif
1657
1658
static int __init rtw_drv_entry(void)
1659
{
1660
int ret = 0;
1661
1662
RTW_PRINT("module init start\n");
1663
dump_drv_version(RTW_DBGDUMP);
1664
#ifdef BTCOEXVERSION
1665
RTW_PRINT(DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);
1666
#endif /* BTCOEXVERSION */
1667
1668
ret = platform_wifi_power_on();
1669
if (ret != 0) {
1670
RTW_INFO("%s: power on failed!!(%d)\n", __FUNCTION__, ret);
1671
ret = -1;
1672
goto exit;
1673
}
1674
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))
1675
/* console_suspend_enabled=0; */
1676
#endif
1677
1678
usb_drv.drv_registered = _TRUE;
1679
rtw_suspend_lock_init();
1680
rtw_drv_proc_init();
1681
rtw_ndev_notifier_register();
1682
rtw_inetaddr_notifier_register();
1683
1684
ret = usb_register(&usb_drv.usbdrv);
1685
1686
if (ret != 0) {
1687
usb_drv.drv_registered = _FALSE;
1688
rtw_suspend_lock_uninit();
1689
rtw_drv_proc_deinit();
1690
rtw_ndev_notifier_unregister();
1691
rtw_inetaddr_notifier_unregister();
1692
goto exit;
1693
}
1694
1695
exit:
1696
RTW_PRINT("module init ret=%d\n", ret);
1697
return ret;
1698
}
1699
1700
static void __exit rtw_drv_halt(void)
1701
{
1702
RTW_PRINT("module exit start\n");
1703
1704
usb_drv.drv_registered = _FALSE;
1705
1706
usb_deregister(&usb_drv.usbdrv);
1707
1708
platform_wifi_power_off();
1709
1710
rtw_suspend_lock_uninit();
1711
rtw_drv_proc_deinit();
1712
rtw_ndev_notifier_unregister();
1713
rtw_inetaddr_notifier_unregister();
1714
1715
RTW_PRINT("module exit success\n");
1716
1717
rtw_mstat_dump(RTW_DBGDUMP);
1718
}
1719
1720
module_init(rtw_drv_entry);
1721
module_exit(rtw_drv_halt);
1722
1723