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