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