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
rtw_dev_shutdown(struct device * dev)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
RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor * epd)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
RT_usb_endpoint_num(const struct usb_endpoint_descriptor * epd)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
rtw_init_intf_priv(struct dvobj_priv * dvobj)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
rtw_deinit_intf_priv(struct dvobj_priv * dvobj)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 }
rtw_decide_chip_type_by_usb_info(struct dvobj_priv * pdvobjpriv,const struct usb_device_id * pdid)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
usb_dvobj_init(struct usb_interface * usb_intf,const struct usb_device_id * pdid)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
usb_dvobj_deinit(struct usb_interface * usb_intf)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
usb_reprobe_to_usb3(PADAPTER Adapter)611 static int usb_reprobe_to_usb3(PADAPTER Adapter)
612 {
613 struct registry_priv *registry_par = &Adapter->registrypriv;
614 int ret = _FALSE;
615
616 /* U2 to U3 */
617 if (registry_par->switch_usb3 == _TRUE) {
618 if (IS_HIGH_SPEED_USB(Adapter)) {
619 if ((rtw_read8(Adapter, 0x74) & (BIT(2)|BIT(3))) != BIT(3)) {
620 rtw_write8(Adapter, 0x74, 0x8);
621 rtw_write8(Adapter, 0x70, 0x2);
622 rtw_write8(Adapter, 0x3e, 0x1);
623 rtw_write8(Adapter, 0x3d, 0x3);
624 /* usb disconnect */
625 rtw_write8(Adapter, 0x5, 0x80);
626 ret = _TRUE;
627 }
628
629 } else if (IS_SUPER_SPEED_USB(Adapter)) {
630 rtw_write8(Adapter, 0x70, rtw_read8(Adapter, 0x70) & (~BIT(1)));
631 rtw_write8(Adapter, 0x3e, rtw_read8(Adapter, 0x3e) & (~BIT(0)));
632 }
633 } else {
634 /* U3 to U2 */
635 if (IS_SUPER_SPEED_USB(Adapter)) {
636 if ((rtw_read8(Adapter, 0x74) & (BIT(2)|BIT(3))) != BIT(2)) {
637 rtw_write8(Adapter, 0x74, 0x4);
638 rtw_write8(Adapter, 0x70, 0x2);
639 rtw_write8(Adapter, 0x3e, 0x1);
640 rtw_write8(Adapter, 0x3d, 0x3);
641 /* usb disconnect */
642 rtw_write8(Adapter, 0x5, 0x80);
643 ret = _TRUE;
644 }
645 } else if (IS_HIGH_SPEED_USB(Adapter)) {
646 rtw_write8(Adapter, 0x70, rtw_read8(Adapter, 0x70) & (~BIT(1)));
647 rtw_write8(Adapter, 0x3e, rtw_read8(Adapter, 0x3e) & (~BIT(0)));
648 }
649 }
650
651 return ret;
652 }
653
rtw_set_hal_ops(_adapter * padapter)654 u8 rtw_set_hal_ops(_adapter *padapter)
655 {
656 //alloc memory for HAL DATA
657 if (rtw_hal_data_init(padapter) == _FAIL)
658 return _FAIL;
659
660 #ifdef CONFIG_RTL8188E
661 if (rtw_get_chip_type(padapter) == RTL8188E)
662 rtl8188eu_set_hal_ops(padapter);
663 #endif
664
665 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
666 if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)
667 rtl8812au_set_hal_ops(padapter);
668 #endif
669
670 #ifdef CONFIG_RTL8192E
671 if (rtw_get_chip_type(padapter) == RTL8192E)
672 rtl8192eu_set_hal_ops(padapter);
673 #endif
674 #ifdef CONFIG_RTL8723B
675 if (rtw_get_chip_type(padapter) == RTL8723B)
676 rtl8723bu_set_hal_ops(padapter);
677 #endif
678 #ifdef CONFIG_RTL8814A
679 if (rtw_get_chip_type(padapter) == RTL8814A)
680 rtl8814au_set_hal_ops(padapter);
681 #endif /* CONFIG_RTL8814A */
682
683 #ifdef CONFIG_RTL8188F
684 if (rtw_get_chip_type(padapter) == RTL8188F)
685 rtl8188fu_set_hal_ops(padapter);
686 #endif
687
688 #ifdef CONFIG_RTL8703B
689 if (rtw_get_chip_type(padapter) == RTL8703B)
690 rtl8703bu_set_hal_ops(padapter);
691 #endif /* CONFIG_RTL8703B */
692
693 if (_FAIL == rtw_hal_ops_check(padapter) )
694 return _FAIL;
695
696 if (hal_spec_init(padapter) == _FAIL)
697 return _FAIL;
698
699 return _SUCCESS;
700 }
701
usb_set_intf_ops(_adapter * padapter,struct _io_ops * pops)702 void usb_set_intf_ops(_adapter *padapter,struct _io_ops *pops)
703 {
704 #ifdef CONFIG_RTL8188E
705 if (rtw_get_chip_type(padapter) == RTL8188E)
706 rtl8188eu_set_intf_ops(pops);
707 #endif
708
709 #if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)
710 if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)
711 rtl8812au_set_intf_ops(pops);
712 #endif
713
714 #ifdef CONFIG_RTL8192E
715 if (rtw_get_chip_type(padapter) == RTL8192E)
716 rtl8192eu_set_intf_ops(pops);
717 #endif
718
719 #ifdef CONFIG_RTL8723B
720 if (rtw_get_chip_type(padapter) == RTL8723B)
721 rtl8723bu_set_intf_ops(pops);
722 #endif
723
724 #ifdef CONFIG_RTL8814A
725 if (rtw_get_chip_type(padapter) == RTL8814A)
726 rtl8814au_set_intf_ops(pops);
727 #endif /* CONFIG_RTL8814A */
728
729 #ifdef CONFIG_RTL8188F
730 if (rtw_get_chip_type(padapter) == RTL8188F)
731 rtl8188fu_set_intf_ops(pops);
732 #endif
733
734 #ifdef CONFIG_RTL8703B
735 if (rtw_get_chip_type(padapter) == RTL8703B)
736 rtl8703bu_set_intf_ops(pops);
737 #endif /* CONFIG_RTL8703B */
738 }
739
740
usb_intf_start(_adapter * padapter)741 static void usb_intf_start(_adapter *padapter)
742 {
743
744 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_start\n"));
745
746 rtw_hal_inirp_init(padapter);
747
748 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_start\n"));
749
750 }
751
usb_intf_stop(_adapter * padapter)752 static void usb_intf_stop(_adapter *padapter)
753 {
754
755 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+usb_intf_stop\n"));
756
757 //disabel_hw_interrupt
758 if (!rtw_is_surprise_removed(padapter)) {
759 //device still exists, so driver can do i/o operation
760 //TODO:
761 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("SurpriseRemoved==_FALSE\n"));
762 }
763
764 //cancel in irp
765 rtw_hal_inirp_deinit(padapter);
766
767 //cancel out irp
768 rtw_write_port_cancel(padapter);
769
770 //todo:cancel other irps
771
772 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-usb_intf_stop\n"));
773
774 }
775
process_spec_devid(const struct usb_device_id * pdid)776 static void process_spec_devid(const struct usb_device_id *pdid)
777 {
778 u16 vid, pid;
779 u32 flags;
780 int i;
781 int num = sizeof(specific_device_id_tbl)/sizeof(struct specific_device_id);
782
783 for(i=0; i<num; i++)
784 {
785 vid = specific_device_id_tbl[i].idVendor;
786 pid = specific_device_id_tbl[i].idProduct;
787 flags = specific_device_id_tbl[i].flags;
788
789 #ifdef CONFIG_80211N_HT
790 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_DISABLE_HT))
791 {
792 rtw_ht_enable = 0;
793 rtw_bw_mode = 0;
794 rtw_ampdu_enable = 0;
795 }
796 #endif
797
798 #ifdef RTK_DMP_PLATFORM
799 // Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform.
800 // It is used to distinguish between normal and PC-side wifi dongle/module.
801 if((pdid->idVendor==vid) && (pdid->idProduct==pid) && (flags&SPEC_DEV_ID_ASSIGN_IFNAME))
802 {
803 extern char* ifname;
804 strncpy(ifname, "wlan10", 6);
805 //DBG_871X("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid);
806 }
807 #endif /* RTK_DMP_PLATFORM */
808
809 }
810 }
811
812 #ifdef SUPPORT_HW_RFOFF_DETECTED
rtw_hw_suspend(_adapter * padapter)813 int rtw_hw_suspend(_adapter *padapter )
814 {
815 struct pwrctrl_priv *pwrpriv;
816 struct usb_interface *pusb_intf;
817 struct net_device *pnetdev;
818
819 _func_enter_;
820 if(NULL==padapter)
821 goto error_exit;
822
823 if ((_FALSE == padapter->bup) || RTW_CANNOT_RUN(padapter)) {
824 DBG_871X("padapter->bup=%d bDriverStopped=%s bSurpriseRemoved = %s\n"
825 , padapter->bup
826 , rtw_is_drv_stopped(padapter)?"True":"False"
827 , rtw_is_surprise_removed(padapter)?"True":"False");
828 goto error_exit;
829 }
830
831 pwrpriv = adapter_to_pwrctl(padapter);
832 pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
833 pnetdev = padapter->pnetdev;
834
835 LeaveAllPowerSaveMode(padapter);
836
837 DBG_871X("==> rtw_hw_suspend\n");
838 _enter_pwrlock(&pwrpriv->lock);
839 pwrpriv->bips_processing = _TRUE;
840 //padapter->net_closed = _TRUE;
841 //s1.
842 if(pnetdev)
843 {
844 netif_carrier_off(pnetdev);
845 rtw_netif_stop_queue(pnetdev);
846 }
847
848 //s2.
849 rtw_disassoc_cmd(padapter, 500, _FALSE);
850
851 //s2-2. indicate disconnect to os
852 //rtw_indicate_disconnect(padapter);
853 {
854 struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
855 if(check_fwstate(pmlmepriv, _FW_LINKED))
856 {
857 _clr_fwstate_(pmlmepriv, _FW_LINKED);
858 rtw_led_control(padapter, LED_CTL_NO_LINK);
859
860 rtw_os_indicate_disconnect(padapter, 0, _FALSE);
861
862 #ifdef CONFIG_LPS
863 //donnot enqueue cmd
864 rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, 0);
865 #endif
866 }
867 }
868 //s2-3.
869 rtw_free_assoc_resources(padapter, 1);
870
871 //s2-4.
872 rtw_free_network_queue(padapter,_TRUE);
873 #ifdef CONFIG_IPS
874 rtw_ips_dev_unload(padapter);
875 #endif
876 pwrpriv->rf_pwrstate = rf_off;
877 pwrpriv->bips_processing = _FALSE;
878 _exit_pwrlock(&pwrpriv->lock);
879
880 _func_exit_;
881 return 0;
882
883 error_exit:
884 DBG_871X("%s, failed \n",__FUNCTION__);
885 return (-1);
886
887 }
888
rtw_hw_resume(_adapter * padapter)889 int rtw_hw_resume(_adapter *padapter)
890 {
891 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
892 struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;
893 struct net_device *pnetdev = padapter->pnetdev;
894
895 _func_enter_;
896 DBG_871X("==> rtw_hw_resume\n");
897 _enter_pwrlock(&pwrpriv->lock);
898 pwrpriv->bips_processing = _TRUE;
899 rtw_reset_drv_sw(padapter);
900
901 if(pm_netdev_open(pnetdev,_FALSE) != 0)
902 {
903 _exit_pwrlock(&pwrpriv->lock);
904 goto error_exit;
905 }
906
907 netif_device_attach(pnetdev);
908 netif_carrier_on(pnetdev);
909
910 rtw_netif_wake_queue(pnetdev);
911
912 pwrpriv->bkeepfwalive = _FALSE;
913 pwrpriv->brfoffbyhw = _FALSE;
914
915 pwrpriv->rf_pwrstate = rf_on;
916 pwrpriv->bips_processing = _FALSE;
917 _exit_pwrlock(&pwrpriv->lock);
918
919 _func_exit_;
920
921 return 0;
922 error_exit:
923 DBG_871X("%s, Open net dev failed \n",__FUNCTION__);
924 return (-1);
925 }
926 #endif
927
rtw_suspend(struct usb_interface * pusb_intf,pm_message_t message)928 static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)
929 {
930 struct dvobj_priv *dvobj;
931 struct pwrctrl_priv *pwrpriv;
932 struct debug_priv *pdbgpriv;
933 PADAPTER padapter;
934 int ret = 0;
935
936
937 dvobj = usb_get_intfdata(pusb_intf);
938 pwrpriv = dvobj_to_pwrctl(dvobj);
939 pdbgpriv = &dvobj->drv_dbg;
940 padapter = dvobj->padapters[IFACE_ID0];
941
942 if (pwrpriv->bInSuspend == _TRUE) {
943 DBG_871X("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
944 pdbgpriv->dbg_suspend_error_cnt++;
945 goto exit;
946 }
947
948 if ((padapter->bup) || !rtw_is_drv_stopped(padapter) || !rtw_is_surprise_removed(padapter)) {
949 #ifdef CONFIG_AUTOSUSPEND
950 if(pwrpriv->bInternalAutoSuspend ){
951
952 #ifdef SUPPORT_HW_RFOFF_DETECTED
953 // The FW command register update must after MAC and FW init ready.
954 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect ) && (padapter->registrypriv.usbss_enable ))
955 {
956 u8 bOpen = _TRUE;
957 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
958 }
959 #endif//SUPPORT_HW_RFOFF_DETECTED
960 }
961 #endif//CONFIG_AUTOSUSPEND
962 }
963
964 ret = rtw_suspend_common(padapter);
965
966 exit:
967 return ret;
968 }
969
rtw_resume_process(_adapter * padapter)970 int rtw_resume_process(_adapter *padapter)
971 {
972 int ret,pm_cnt = 0;
973 struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
974 struct dvobj_priv *pdvobj = padapter->dvobj;
975 struct debug_priv *pdbgpriv = &pdvobj->drv_dbg;
976
977
978 if (pwrpriv->bInSuspend == _FALSE)
979 {
980 pdbgpriv->dbg_resume_error_cnt++;
981 DBG_871X("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);
982 return -1;
983 }
984
985 #if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND) //add by amy for 8723as-vau
986 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
987 DBG_871X("%s...pm_usage_cnt(%d) pwrpriv->bAutoResume=%x. ....\n",__func__,atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)),pwrpriv->bAutoResume);
988 pm_cnt=atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));
989 #else // kernel < 2.6.32
990 DBG_871X("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);
991 pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;
992 #endif // kernel < 2.6.32
993
994 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
995 if( _TRUE == pwrpriv->bAutoResume ){
996 pwrpriv->bInternalAutoSuspend = _FALSE;
997 pwrpriv->bAutoResume=_FALSE;
998 DBG_871X("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
999
1000 }
1001 #endif //#ifdef CONFIG_BT_COEXIST &CONFIG_AUTOSUSPEND&
1002
1003 #if defined (CONFIG_WOWLAN) || defined (CONFIG_AP_WOWLAN)
1004 /*
1005 * Due to usb wow suspend flow will cancel read/write port via intf_stop and
1006 * bReadPortCancel and bWritePortCancel are set _TRUE in intf_stop.
1007 * But they will not be clear in intf_start during wow resume flow.
1008 * It should move to os_intf in the feature.
1009 */
1010 RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
1011 RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
1012 #endif
1013
1014 ret = rtw_resume_common(padapter);
1015
1016 #ifdef CONFIG_AUTOSUSPEND
1017 if(pwrpriv->bInternalAutoSuspend )
1018 {
1019 #ifdef SUPPORT_HW_RFOFF_DETECTED
1020 // The FW command register update must after MAC and FW init ready.
1021 if((padapter->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable ))
1022 {
1023 u8 bOpen = _FALSE;
1024 rtw_interface_ps_func(padapter,HAL_USB_SELECT_SUSPEND,&bOpen);
1025 }
1026 #endif
1027 #ifdef CONFIG_BT_COEXIST // for 8723as-vau
1028 DBG_871X("pwrpriv->bAutoResume (%x)\n",pwrpriv->bAutoResume );
1029 if( _TRUE == pwrpriv->bAutoResume ){
1030 pwrpriv->bInternalAutoSuspend = _FALSE;
1031 pwrpriv->bAutoResume=_FALSE;
1032 DBG_871X("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n",pwrpriv->bAutoResume,pwrpriv->bInternalAutoSuspend );
1033 }
1034
1035 #else //#ifdef CONFIG_BT_COEXIST
1036 pwrpriv->bInternalAutoSuspend = _FALSE;
1037 #endif //#ifdef CONFIG_BT_COEXIST
1038 pwrpriv->brfoffbyhw = _FALSE;
1039 }
1040 #endif//CONFIG_AUTOSUSPEND
1041
1042
1043 return ret;
1044 }
1045
rtw_resume(struct usb_interface * pusb_intf)1046 static int rtw_resume(struct usb_interface *pusb_intf)
1047 {
1048 struct dvobj_priv *dvobj;
1049 struct pwrctrl_priv *pwrpriv;
1050 struct debug_priv *pdbgpriv;
1051 PADAPTER padapter;
1052 struct mlme_ext_priv *pmlmeext;
1053 int ret = 0;
1054
1055
1056 dvobj = usb_get_intfdata(pusb_intf);
1057 pwrpriv = dvobj_to_pwrctl(dvobj);
1058 pdbgpriv = &dvobj->drv_dbg;
1059 padapter = dvobj->padapters[IFACE_ID0];
1060 pmlmeext = &padapter->mlmeextpriv;
1061
1062 DBG_871X("==> %s (%s:%d)\n", __FUNCTION__, current->comm, current->pid);
1063 pdbgpriv->dbg_resume_cnt++;
1064
1065 if(pwrpriv->bInternalAutoSuspend)
1066 {
1067 ret = rtw_resume_process(padapter);
1068 }
1069 else
1070 {
1071 if(pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode)
1072 {
1073 rtw_resume_lock_suspend();
1074 ret = rtw_resume_process(padapter);
1075 rtw_resume_unlock_suspend();
1076 }
1077 else
1078 {
1079 #ifdef CONFIG_RESUME_IN_WORKQUEUE
1080 rtw_resume_in_workqueue(pwrpriv);
1081 #else
1082 if (rtw_is_earlysuspend_registered(pwrpriv))
1083 {
1084 /* jeff: bypass resume here, do in late_resume */
1085 rtw_set_do_late_resume(pwrpriv, _TRUE);
1086 }
1087 else
1088 {
1089 rtw_resume_lock_suspend();
1090 ret = rtw_resume_process(padapter);
1091 rtw_resume_unlock_suspend();
1092 }
1093 #endif
1094 }
1095 }
1096
1097 pmlmeext->last_scan_time = rtw_get_current_time();
1098 DBG_871X("<======== %s return %d\n", __FUNCTION__, ret);
1099
1100 return ret;
1101 }
1102
1103
1104
1105 #ifdef CONFIG_AUTOSUSPEND
autosuspend_enter(_adapter * padapter)1106 void autosuspend_enter(_adapter* padapter)
1107 {
1108 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1109 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1110
1111 DBG_871X("==>autosuspend_enter...........\n");
1112
1113 pwrpriv->bInternalAutoSuspend = _TRUE;
1114 pwrpriv->bips_processing = _TRUE;
1115
1116 if(rf_off == pwrpriv->change_rfpwrstate )
1117 {
1118 #ifndef CONFIG_BT_COEXIST
1119 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1120 usb_enable_autosuspend(dvobj->pusbdev);
1121 #else
1122 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1123 #endif
1124
1125 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1126 usb_autopm_put_interface(dvobj->pusbintf);
1127 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1128 usb_autopm_enable(dvobj->pusbintf);
1129 #else
1130 usb_autosuspend_device(dvobj->pusbdev, 1);
1131 #endif
1132 #else //#ifndef CONFIG_BT_COEXIST
1133 if(1==pwrpriv->autopm_cnt){
1134 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1135 usb_enable_autosuspend(dvobj->pusbdev);
1136 #else
1137 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1138 #endif
1139
1140 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1141 usb_autopm_put_interface(dvobj->pusbintf);
1142 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1143 usb_autopm_enable(dvobj->pusbintf);
1144 #else
1145 usb_autosuspend_device(dvobj->pusbdev, 1);
1146 #endif
1147 pwrpriv->autopm_cnt --;
1148 }
1149 else
1150 DBG_871X("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_put_interface\n", pwrpriv->autopm_cnt);
1151
1152 #endif //#ifndef CONFIG_BT_COEXIST
1153 }
1154 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1155 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1156 #else
1157 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1158 #endif
1159
1160 }
1161
autoresume_enter(_adapter * padapter)1162 int autoresume_enter(_adapter* padapter)
1163 {
1164 int result = _SUCCESS;
1165 struct security_priv* psecuritypriv=&(padapter->securitypriv);
1166 struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1167 struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1168 struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);
1169 struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);
1170
1171 DBG_871X("====> autoresume_enter \n");
1172
1173 if(rf_off == pwrpriv->rf_pwrstate )
1174 {
1175 pwrpriv->ps_flag = _FALSE;
1176 #ifndef CONFIG_BT_COEXIST
1177 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1178 if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1179 {
1180 DBG_871X( "can't get autopm: %d\n", result);
1181 result = _FAIL;
1182 goto error_exit;
1183 }
1184 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1185 usb_autopm_disable(dvobj->pusbintf);
1186 #else
1187 usb_autoresume_device(dvobj->pusbdev, 1);
1188 #endif
1189
1190 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1191 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1192 #else
1193 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1194 #endif
1195 #else //#ifndef CONFIG_BT_COEXIST
1196 pwrpriv->bAutoResume=_TRUE;
1197 if(0==pwrpriv->autopm_cnt){
1198 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1199 if (usb_autopm_get_interface(dvobj->pusbintf) < 0)
1200 {
1201 DBG_871X( "can't get autopm: %d\n", result);
1202 result = _FAIL;
1203 goto error_exit;
1204 }
1205 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1206 usb_autopm_disable(dvobj->pusbintf);
1207 #else
1208 usb_autoresume_device(dvobj->pusbdev, 1);
1209 #endif
1210 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1211 DBG_871X("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));
1212 #else
1213 DBG_871X("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);
1214 #endif
1215 pwrpriv->autopm_cnt++;
1216 }
1217 else
1218 DBG_871X("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_get_interface\n",pwrpriv->autopm_cnt);
1219 #endif //#ifndef CONFIG_BT_COEXIST
1220 }
1221 DBG_871X("<==== autoresume_enter \n");
1222 error_exit:
1223
1224 return result;
1225 }
1226 #endif
1227
1228 #ifdef CONFIG_PLATFORM_RTD2880B
1229 extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);
1230 #endif
1231
1232 /*
1233 * drv_init() - a device potentially for us
1234 *
1235 * notes: drv_init() is called when the bus driver has located a card for us to support.
1236 * We accept the new device by returning 0.
1237 */
1238
1239 _adapter *rtw_sw_export = NULL;
1240
rtw_usb_if1_init(struct dvobj_priv * dvobj,struct usb_interface * pusb_intf)1241 _adapter *rtw_usb_if1_init(struct dvobj_priv *dvobj,
1242 struct usb_interface *pusb_intf)
1243 {
1244 _adapter *padapter = NULL;
1245 int status = _FAIL;
1246
1247 padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));
1248 if (padapter == NULL)
1249 goto exit;
1250
1251 if (loadparam(padapter) != _SUCCESS)
1252 goto free_adapter;
1253
1254 padapter->dvobj = dvobj;
1255
1256
1257 rtw_set_drv_stopped(padapter);/*init*/
1258
1259 dvobj->padapters[dvobj->iface_nums++] = padapter;
1260 padapter->iface_id = IFACE_ID0;
1261
1262 #if defined(CONFIG_CONCURRENT_MODE)
1263 //set adapter_type/iface type for primary padapter
1264 padapter->isprimary = _TRUE;
1265 padapter->adapter_type = PRIMARY_ADAPTER;
1266 #ifndef CONFIG_HWPORT_SWAP
1267 padapter->iface_type = IFACE_PORT0;
1268 #else
1269 padapter->iface_type = IFACE_PORT1;
1270 #endif
1271 #endif
1272
1273 //step 2. hook HalFunc, allocate HalData
1274 //hal_set_hal_ops(padapter);
1275 if(rtw_set_hal_ops(padapter) ==_FAIL)
1276 goto free_hal_data;
1277
1278
1279 padapter->intf_start=&usb_intf_start;
1280 padapter->intf_stop=&usb_intf_stop;
1281
1282 //step init_io_priv
1283 if( rtw_init_io_priv(padapter,usb_set_intf_ops) ==_FAIL)
1284 goto free_hal_data;
1285
1286 //step read_chip_version
1287 rtw_hal_read_chip_version(padapter);
1288
1289 //step usb endpoint mapping
1290 rtw_hal_chip_configure(padapter);
1291
1292 #ifdef CONFIG_BT_COEXIST
1293 rtw_btcoex_Initialize(padapter);
1294 #endif // CONFIG_BT_COEXIST
1295
1296 //step read efuse/eeprom data and get mac_addr
1297 rtw_hal_read_chip_info(padapter);
1298
1299 //step 5.
1300 if(rtw_init_drv_sw(padapter) ==_FAIL) {
1301 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("Initialize driver software resource Failed!\n"));
1302 goto free_hal_data;
1303 }
1304
1305 #ifdef CONFIG_PM
1306 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18))
1307 if(dvobj_to_pwrctl(dvobj)->bSupportRemoteWakeup)
1308 {
1309 dvobj->pusbdev->do_remote_wakeup=1;
1310 pusb_intf->needs_remote_wakeup = 1;
1311 device_init_wakeup(&pusb_intf->dev, 1);
1312 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");
1313 DBG_871X("pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n",device_may_wakeup(&pusb_intf->dev));
1314 }
1315 #endif
1316 #endif
1317
1318 #ifdef CONFIG_AUTOSUSPEND
1319 if( padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE )
1320 {
1321 if(padapter->registrypriv.usbss_enable ){ /* autosuspend (2s delay) */
1322 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,38))
1323 dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1324 #else
1325 dvobj->pusbdev->autosuspend_delay = 0 * HZ;//15 * HZ; idle-delay time
1326 #endif
1327
1328 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,35))
1329 usb_enable_autosuspend(dvobj->pusbdev);
1330 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,22) && LINUX_VERSION_CODE<=KERNEL_VERSION(2,6,34))
1331 padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;
1332 dvobj->pusbdev->autosuspend_disabled = 0;//autosuspend disabled by the user
1333 #endif
1334
1335 //usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf );//init pm_usage_cnt ,let it start from 1
1336
1337 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,32))
1338 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,atomic_read(&(dvobj->pusbintf ->pm_usage_cnt)));
1339 #else
1340 DBG_871X("%s...pm_usage_cnt(%d).....\n",__FUNCTION__,dvobj->pusbintf ->pm_usage_cnt);
1341 #endif
1342 }
1343 }
1344 #endif
1345 //2012-07-11 Move here to prevent the 8723AS-VAU BT auto suspend influence
1346 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1347 if (usb_autopm_get_interface(pusb_intf) < 0)
1348 {
1349 DBG_871X( "can't get autopm: \n");
1350 }
1351 #endif
1352 #ifdef CONFIG_BT_COEXIST
1353 dvobj_to_pwrctl(dvobj)->autopm_cnt=1;
1354 #endif
1355
1356 // set mac addr
1357 rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));
1358 #ifdef CONFIG_P2P
1359 rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));
1360 #endif // CONFIG_P2P
1361 DBG_871X("bDriverStopped:%s, bSurpriseRemoved:%s, bup:%d, hw_init_completed:%d\n"
1362 , rtw_is_drv_stopped(padapter)?"True":"False"
1363 , rtw_is_surprise_removed(padapter)?"True":"False"
1364 , padapter->bup
1365 , rtw_get_hw_init_completed(padapter)
1366 );
1367
1368 status = _SUCCESS;
1369
1370 free_hal_data:
1371 if (status != _SUCCESS && padapter->HalData)
1372 rtw_hal_free_data(padapter);
1373 free_adapter:
1374 if (status != _SUCCESS && padapter) {
1375 rtw_vmfree((u8 *)padapter, sizeof(*padapter));
1376 padapter = NULL;
1377 }
1378 exit:
1379 return padapter;
1380 }
1381
rtw_usb_if1_deinit(_adapter * if1)1382 static void rtw_usb_if1_deinit(_adapter *if1)
1383 {
1384 struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(if1);
1385 struct mlme_priv *pmlmepriv= &if1->mlmepriv;
1386
1387 if(check_fwstate(pmlmepriv, _FW_LINKED))
1388 rtw_disassoc_cmd(if1, 0, _FALSE);
1389
1390
1391 #ifdef CONFIG_AP_MODE
1392 free_mlme_ap_info(if1);
1393 #ifdef CONFIG_HOSTAPD_MLME
1394 hostapd_mode_unload(if1);
1395 #endif
1396 #endif
1397
1398 #ifdef CONFIG_WOWLAN
1399 pwrctl->wowlan_mode=_FALSE;
1400 #endif //CONFIG_WOWLAN
1401
1402 rtw_dev_unload(if1);
1403
1404 DBG_871X("+r871xu_dev_remove, hw_init_completed=%d\n", rtw_get_hw_init_completed(if1));
1405
1406 #ifdef CONFIG_BT_COEXIST
1407 if(1 == pwrctl->autopm_cnt){
1408 #if (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,33))
1409 usb_autopm_put_interface(adapter_to_dvobj(if1)->pusbintf);
1410 #elif (LINUX_VERSION_CODE>=KERNEL_VERSION(2,6,20))
1411 usb_autopm_enable(adapter_to_dvobj(if1)->pusbintf);
1412 #else
1413 usb_autosuspend_device(adapter_to_dvobj(if1)->pusbdev, 1);
1414 #endif
1415 pwrctl->autopm_cnt --;
1416 }
1417 #endif
1418
1419 rtw_free_drv_sw(if1);
1420
1421 /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1422 rtw_os_ndev_free(if1);
1423
1424 rtw_vmfree((u8 *)if1, sizeof(_adapter));
1425
1426 #ifdef CONFIG_PLATFORM_RTD2880B
1427 DBG_871X("wlan link down\n");
1428 rtd2885_wlan_netlink_sendMsg("linkdown", "8712");
1429 #endif
1430
1431 }
1432
rtw_drv_init(struct usb_interface * pusb_intf,const struct usb_device_id * pdid)1433 static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)
1434 {
1435 _adapter *if1 = NULL, *if2 = NULL;
1436 int status = _FAIL;
1437 struct dvobj_priv *dvobj;
1438 #ifdef CONFIG_MULTI_VIR_IFACES
1439 int i;
1440 #endif //CONFIG_MULTI_VIR_IFACES
1441
1442 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("+rtw_drv_init\n"));
1443 //DBG_871X("+rtw_drv_init\n");
1444
1445 //step 0.
1446 process_spec_devid(pdid);
1447
1448 /* Initialize dvobj_priv */
1449 if ((dvobj = usb_dvobj_init(pusb_intf, pdid)) == NULL) {
1450 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("initialize device object priv Failed!\n"));
1451 goto exit;
1452 }
1453
1454 if ((if1 = rtw_usb_if1_init(dvobj, pusb_intf)) == NULL) {
1455 DBG_871X("rtw_usb_if1_init Failed!\n");
1456 goto free_dvobj;
1457 }
1458
1459 if (usb_reprobe_to_usb3(if1) == _TRUE)
1460 goto free_if1;
1461
1462 #ifdef CONFIG_CONCURRENT_MODE
1463 if((if2 = rtw_drv_if2_init(if1, usb_set_intf_ops)) == NULL) {
1464 goto free_if1;
1465 }
1466 #ifdef CONFIG_MULTI_VIR_IFACES
1467 for(i=0; i<if1->registrypriv.ext_iface_num;i++)
1468 {
1469 if(rtw_drv_add_vir_if(if1, usb_set_intf_ops) == NULL)
1470 {
1471 DBG_871X("rtw_drv_add_iface failed! (%d)\n", i);
1472 goto free_if2;
1473 }
1474 }
1475 #endif //CONFIG_MULTI_VIR_IFACES
1476 #endif
1477
1478 #ifdef CONFIG_INTEL_PROXIM
1479 rtw_sw_export=if1;
1480 #endif
1481
1482 #ifdef CONFIG_GLOBAL_UI_PID
1483 if(ui_pid[1]!=0) {
1484 DBG_871X("ui_pid[1]:%d\n",ui_pid[1]);
1485 rtw_signal_process(ui_pid[1], SIGUSR2);
1486 }
1487 #endif
1488
1489 //dev_alloc_name && register_netdev
1490 if (rtw_os_ndevs_init(dvobj) != _SUCCESS)
1491 goto free_if2;
1492
1493 #ifdef CONFIG_HOSTAPD_MLME
1494 hostapd_mode_init(if1);
1495 #endif
1496
1497 #ifdef CONFIG_PLATFORM_RTD2880B
1498 DBG_871X("wlan link up\n");
1499 rtd2885_wlan_netlink_sendMsg("linkup", "8712");
1500 #endif
1501
1502 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-871x_drv - drv_init, success!\n"));
1503
1504 status = _SUCCESS;
1505
1506 #if 0 /* not used now */
1507 os_ndevs_deinit:
1508 if (status != _SUCCESS)
1509 rtw_os_ndevs_deinit(dvobj);
1510 #endif
1511 free_if2:
1512 if(status != _SUCCESS && if2) {
1513 #ifdef CONFIG_CONCURRENT_MODE
1514 rtw_drv_if2_stop(if2);
1515 rtw_drv_if2_free(if2);
1516 #endif
1517 }
1518 free_if1:
1519 if (status != _SUCCESS && if1) {
1520 rtw_usb_if1_deinit(if1);
1521 }
1522 free_dvobj:
1523 if (status != _SUCCESS)
1524 usb_dvobj_deinit(pusb_intf);
1525 exit:
1526 return status == _SUCCESS?0:-ENODEV;
1527 }
1528
1529 /*
1530 * dev_remove() - our device is being removed
1531 */
1532 //rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both
rtw_dev_remove(struct usb_interface * pusb_intf)1533 static void rtw_dev_remove(struct usb_interface *pusb_intf)
1534 {
1535 struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);
1536 struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);
1537 _adapter *padapter = dvobj->padapters[IFACE_ID0];
1538 struct net_device *pnetdev = padapter->pnetdev;
1539 struct mlme_priv *pmlmepriv= &padapter->mlmepriv;
1540
1541 _func_enter_;
1542
1543 DBG_871X("+rtw_dev_remove\n");
1544 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("+dev_remove()\n"));
1545
1546 dvobj->processing_dev_remove = _TRUE;
1547
1548 /* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */
1549 rtw_os_ndevs_unregister(dvobj);
1550
1551 if(usb_drv.drv_registered == _TRUE)
1552 {
1553 //DBG_871X("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n");
1554 rtw_set_surprise_removed(padapter);
1555 }
1556 /*else
1557 {
1558 //DBG_871X("r871xu_dev_remove():module removed\n");
1559 padapter->HalData->hw_init_completed = _FALSE;
1560 }*/
1561
1562
1563 #if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)
1564 rtw_unregister_early_suspend(pwrctl);
1565 #endif
1566
1567 if (padapter->bFWReady == _TRUE) {
1568 rtw_pm_set_ips(padapter, IPS_NONE);
1569 rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);
1570
1571 LeaveAllPowerSaveMode(padapter);
1572 }
1573 rtw_set_drv_stopped(padapter); /*for stop thread*/
1574
1575 /* stop cmd thread */
1576 rtw_stop_cmd_thread(padapter);
1577 #ifdef CONFIG_CONCURRENT_MODE
1578 #ifdef CONFIG_MULTI_VIR_IFACES
1579 rtw_drv_stop_vir_ifaces(dvobj);
1580 #endif //CONFIG_MULTI_VIR_IFACES
1581 rtw_drv_if2_stop(dvobj->padapters[IFACE_ID1]);
1582 #endif //CONFIG_CONCURRENT_MODE
1583
1584 #ifdef CONFIG_BT_COEXIST
1585 #ifdef CONFIG_BT_COEXIST_SOCKET_TRX
1586 if (GET_HAL_DATA(padapter)->EEPROMBluetoothCoexist)
1587 rtw_btcoex_close_socket(padapter);
1588 #endif
1589 rtw_btcoex_HaltNotify(padapter);
1590 #endif
1591
1592 rtw_usb_if1_deinit(padapter);
1593
1594 #ifdef CONFIG_CONCURRENT_MODE
1595 #ifdef CONFIG_MULTI_VIR_IFACES
1596 rtw_drv_free_vir_ifaces(dvobj);
1597 #endif //CONFIG_MULTI_VIR_IFACES
1598 rtw_drv_if2_free(dvobj->padapters[IFACE_ID1]);
1599 #endif //CONFIG_CONCURRENT_MODE
1600
1601 usb_dvobj_deinit(pusb_intf);
1602
1603 RT_TRACE(_module_hci_intfs_c_,_drv_err_,("-dev_remove()\n"));
1604 DBG_871X("-r871xu_dev_remove, done\n");
1605
1606
1607 #ifdef CONFIG_INTEL_PROXIM
1608 rtw_sw_export=NULL;
1609 #endif
1610
1611 _func_exit_;
1612
1613 return;
1614
1615 }
1616 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1617 extern int console_suspend_enabled;
1618 #endif
1619
rtw_drv_entry(void)1620 static int /*__init*/ rtw_drv_entry(void)
1621 {
1622 int ret = 0;
1623
1624 DBG_871X_LEVEL(_drv_always_, "module init start\n");
1625 dump_drv_version(RTW_DBGDUMP);
1626 #ifdef BTCOEXVERSION
1627 DBG_871X_LEVEL(_drv_always_, DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);
1628 #endif // BTCOEXVERSION
1629
1630 ret = platform_wifi_power_on();
1631 if(ret != 0)
1632 {
1633 DBG_871X("%s: power on failed!!(%d)\n", __FUNCTION__, ret);
1634 ret = -1;
1635 goto exit;
1636 }
1637 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24))
1638 //console_suspend_enabled=0;
1639 #endif
1640
1641 usb_drv.drv_registered = _TRUE;
1642 rtw_suspend_lock_init();
1643 rtw_drv_proc_init();
1644 rtw_ndev_notifier_register();
1645
1646 ret = usb_register(&usb_drv.usbdrv);
1647
1648 if (ret != 0) {
1649 usb_drv.drv_registered = _FALSE;
1650 rtw_suspend_lock_uninit();
1651 rtw_drv_proc_deinit();
1652 rtw_ndev_notifier_unregister();
1653 goto exit;
1654 }
1655
1656 exit:
1657 DBG_871X_LEVEL(_drv_always_, "module init ret=%d\n", ret);
1658 return ret;
1659 }
1660
rtw_drv_halt(void)1661 static void /*__exit*/ rtw_drv_halt(void)
1662 {
1663 DBG_871X_LEVEL(_drv_always_, "module exit start\n");
1664
1665 usb_drv.drv_registered = _FALSE;
1666
1667 usb_deregister(&usb_drv.usbdrv);
1668
1669 platform_wifi_power_off();
1670
1671 rtw_suspend_lock_uninit();
1672 rtw_drv_proc_deinit();
1673 rtw_ndev_notifier_unregister();
1674
1675 DBG_871X_LEVEL(_drv_always_, "module exit success\n");
1676
1677 rtw_mstat_dump(RTW_DBGDUMP);
1678 }
1679
1680 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
1681 #include <linux/rfkill-wlan.h>
1682 extern int get_wifi_chip_type(void);
1683 #else
1684 extern int rk29sdk_wifi_power(int on);
1685 #endif
1686
1687 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
rockchip_wifi_init_module_rtkwifi(void)1688 int rockchip_wifi_init_module_rtkwifi(void)
1689 #else
1690 int rockchip_wifi_init_module(void)
1691 #endif
1692 {
1693 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1694 int type = get_wifi_chip_type();
1695 if (type < WIFI_AP6XXX_SERIES || type == WIFI_ESP8089) return 0;
1696 #endif
1697 printk("\n");
1698 printk("=======================================================\n");
1699 printk("==== Launching Wi-Fi driver! (Powered by Rockchip) ====\n");
1700 printk("=======================================================\n");
1701 printk("Realtek 8723BU USB WiFi driver (Powered by Rockchip) init.\n");
1702 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
1703 rockchip_wifi_power(1);
1704 //rockchip_wifi_set_carddetect(1);
1705 #else
1706 rk29sdk_wifi_power(1);
1707 #endif
1708
1709 return rtw_drv_entry();
1710 }
1711
1712 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
rockchip_wifi_exit_module_rtkwifi(void)1713 void rockchip_wifi_exit_module_rtkwifi(void)
1714 #else
1715 void rockchip_wifi_exit_module(void)
1716 #endif
1717 {
1718 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1719 int type = get_wifi_chip_type();
1720 if (type < WIFI_AP6XXX_SERIES || type == WIFI_ESP8089) return;
1721 #endif
1722 printk("\n");
1723 printk("=======================================================\n");
1724 printk("==== Dislaunching Wi-Fi driver! (Powered by Rockchip) ====\n");
1725 printk("=======================================================\n");
1726 printk("Realtek 8723BU USB WiFi driver (Powered by Rockchip) init.\n");
1727 rtw_drv_halt();
1728 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
1729 //rockchip_wifi_set_carddetect(0);
1730 rockchip_wifi_power(0);
1731 #else
1732 rk29sdk_wifi_power(0);
1733 #endif
1734 }
1735
1736 #ifdef CONFIG_WIFI_BUILD_MODULE
1737 module_init(rockchip_wifi_init_module_rtkwifi);
1738 module_exit(rockchip_wifi_exit_module_rtkwifi);
1739 #else
1740 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 1, 0))
1741 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
1742 late_initcall(rockchip_wifi_init_module_rtkwifi);
1743 module_exit(rockchip_wifi_exit_module_rtkwifi);
1744 #else
1745 module_init(rockchip_wifi_init_module_rtkwifi);
1746 module_exit(rockchip_wifi_exit_module_rtkwifi);
1747 #endif
1748 #else
1749 #ifdef CONFIG_ANDROID_4_2
1750 module_init(rockchip_wifi_init_module);
1751 module_exit(rockchip_wifi_exit_module);
1752 #else
1753 EXPORT_SYMBOL(rockchip_wifi_init_module);
1754 EXPORT_SYMBOL(rockchip_wifi_exit_module);
1755 #endif
1756 #endif
1757 #endif
1758
1759 //module_init(rtw_drv_entry);
1760 //module_exit(rtw_drv_halt);
1761
1762 #ifdef CONFIG_INTEL_PROXIM
rtw_usb_get_sw_pointer(void)1763 _adapter *rtw_usb_get_sw_pointer(void)
1764 {
1765 return rtw_sw_export;
1766 }
1767 EXPORT_SYMBOL(rtw_usb_get_sw_pointer);
1768 #endif //CONFIG_INTEL_PROXIM
1769
1770