Path: blob/master/ALFA-W1F1/RTL8814AU/os_dep/linux/usb_intf.c
1307 views
/******************************************************************************1*2* Copyright(c) 2007 - 2017 Realtek Corporation.3*4* This program is free software; you can redistribute it and/or modify it5* under the terms of version 2 of the GNU General Public License as6* published by the Free Software Foundation.7*8* This program is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for11* more details.12*13*****************************************************************************/14#define _HCI_INTF_C_1516#include <drv_types.h>17#include <hal_data.h>1819#include <platform_ops.h>2021#ifndef CONFIG_USB_HCI22#error "CONFIG_USB_HCI shall be on!\n"23#endif2425#ifdef CONFIG_80211N_HT26extern int rtw_ht_enable;27extern int rtw_bw_mode;28extern int rtw_ampdu_enable;/* for enable tx_ampdu */29#endif3031#ifdef CONFIG_GLOBAL_UI_PID32int ui_pid[3] = {0, 0, 0};33#endif3435extern int pm_netdev_open(struct net_device *pnetdev, u8 bnormal);36static int rtw_suspend(struct usb_interface *intf, pm_message_t message);37static int rtw_resume(struct usb_interface *intf);3839static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid);40static void rtw_dev_remove(struct usb_interface *pusb_intf);4142static void rtw_dev_shutdown(struct device *dev)43{44struct usb_interface *usb_intf = container_of(dev, struct usb_interface, dev);45struct dvobj_priv *dvobj = NULL;46_adapter *adapter = NULL;4748RTW_INFO("%s\n", __func__);4950if (usb_intf) {51dvobj = usb_get_intfdata(usb_intf);52if (dvobj) {53adapter = dvobj_get_primary_adapter(dvobj);54if (adapter) {55if (!rtw_is_surprise_removed(adapter)) {56#ifdef CONFIG_WOWLAN57struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(adapter);5859#ifdef CONFIG_GPIO_WAKEUP60/*default wake up pin change to BT*/61RTW_INFO("%s:default wake up pin change to BT\n", __FUNCTION__);62rtw_hal_switch_gpio_wl_ctrl(adapter, WAKEUP_GPIO_IDX, _FALSE);63#endif /* CONFIG_GPIO_WAKEUP */6465if (pwrctl->wowlan_mode == _TRUE)66RTW_PRINT("%s wowlan_mode ==_TRUE do not run rtw_hal_deinit()\n", __FUNCTION__);67else68#endif69{70rtw_hal_deinit(adapter);71rtw_set_surprise_removed(adapter);72}73}74}75ATOMIC_SET(&dvobj->continual_io_error, MAX_CONTINUAL_IO_ERR + 1);76}77}78}7980#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 23))81/* Some useful macros to use to create struct usb_device_id */82#define USB_DEVICE_ID_MATCH_VENDOR 0x000183#define USB_DEVICE_ID_MATCH_PRODUCT 0x000284#define USB_DEVICE_ID_MATCH_DEV_LO 0x000485#define USB_DEVICE_ID_MATCH_DEV_HI 0x000886#define USB_DEVICE_ID_MATCH_DEV_CLASS 0x001087#define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x002088#define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x004089#define USB_DEVICE_ID_MATCH_INT_CLASS 0x008090#define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x010091#define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x020092#define USB_DEVICE_ID_MATCH_INT_NUMBER 0x04009394#define USB_DEVICE_ID_MATCH_INT_INFO \95(USB_DEVICE_ID_MATCH_INT_CLASS | \96USB_DEVICE_ID_MATCH_INT_SUBCLASS | \97USB_DEVICE_ID_MATCH_INT_PROTOCOL)9899#define USB_DEVICE_AND_INTERFACE_INFO(vend, prod, cl, sc, pr) \100.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \101| USB_DEVICE_ID_MATCH_DEVICE, \102.idVendor = (vend), \103.idProduct = (prod), \104.bInterfaceClass = (cl), \105.bInterfaceSubClass = (sc), \106.bInterfaceProtocol = (pr)107108/**109* USB_VENDOR_AND_INTERFACE_INFO - describe a specific usb vendor with a class of usb interfaces110* @vend: the 16 bit USB Vendor ID111* @cl: bInterfaceClass value112* @sc: bInterfaceSubClass value113* @pr: bInterfaceProtocol value114*115* This macro is used to create a struct usb_device_id that matches a116* specific vendor with a specific class of interfaces.117*118* This is especially useful when explicitly matching devices that have119* vendor specific bDeviceClass values, but standards-compliant interfaces.120*/121#define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \122.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \123| USB_DEVICE_ID_MATCH_VENDOR, \124.idVendor = (vend), \125.bInterfaceClass = (cl), \126.bInterfaceSubClass = (sc), \127.bInterfaceProtocol = (pr)128129/* ----------------------------------------------------------------------- */130#endif131132#define USB_VENDER_ID_REALTEK 0x0BDA133134/* DID_USB_v916_20130116 */135static struct usb_device_id rtw_usb_id_tbl[] = {136#ifdef CONFIG_RTL8188E137/*=== Realtek demoboard ===*/138{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8179), .driver_info = RTL8188E}, /* 8188EUS */139{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0179), .driver_info = RTL8188E}, /* 8188ETV */140/*=== Customer ID ===*/141/****** 8188EUS ********/142{USB_DEVICE(0x07B8, 0x8179), .driver_info = RTL8188E}, /* Abocom - Abocom */143#endif144145#ifdef CONFIG_RTL8812A146/*=== Realtek demoboard ===*/147{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8812), .driver_info = RTL8812}, /* Default ID */148{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881A), .driver_info = RTL8812}, /* Default ID */149{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881B), .driver_info = RTL8812}, /* Default ID */150{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x881C), .driver_info = RTL8812}, /* Default ID */151/*=== Customer ID ===*/152{USB_DEVICE(0x050D, 0x1106), .driver_info = RTL8812}, /* Belkin - sercomm */153{USB_DEVICE(0x7392, 0xA822), .driver_info = RTL8812}, /* Edimax - EW-7822UAC */154{USB_DEVICE(0x0DF6, 0x0074), .driver_info = RTL8812}, /* Sitecom - Edimax */155{USB_DEVICE(0x04BB, 0x0952), .driver_info = RTL8812}, /* I-O DATA - Edimax */156{USB_DEVICE(0x0789, 0x016E), .driver_info = RTL8812}, /* Logitec - Edimax */157{USB_DEVICE(0x0409, 0x0408), .driver_info = RTL8812}, /* NEC - */158{USB_DEVICE(0x0B05, 0x17D2), .driver_info = RTL8812}, /* ASUS - Edimax */159{USB_DEVICE(0x0E66, 0x0022), .driver_info = RTL8812}, /* HAWKING - Edimax */160{USB_DEVICE(0x0586, 0x3426), .driver_info = RTL8812}, /* ZyXEL - */161{USB_DEVICE(0x2001, 0x3313), .driver_info = RTL8812}, /* D-Link - ALPHA */162{USB_DEVICE(0x1058, 0x0632), .driver_info = RTL8812}, /* WD - Cybertan*/163{USB_DEVICE(0x1740, 0x0100), .driver_info = RTL8812}, /* EnGenius - EnGenius */164{USB_DEVICE(0x2019, 0xAB30), .driver_info = RTL8812}, /* Planex - Abocom */165{USB_DEVICE(0x07B8, 0x8812), .driver_info = RTL8812}, /* Abocom - Abocom */166{USB_DEVICE(0x0846, 0x9051), .driver_info = RTL8812}, /* Netgear A6200 v2 */167{USB_DEVICE(0x2001, 0x330E), .driver_info = RTL8812}, /* D-Link - ALPHA */168{USB_DEVICE(0x2001, 0x3313), .driver_info = RTL8812}, /* D-Link - ALPHA */169{USB_DEVICE(0x2001, 0x3315), .driver_info = RTL8812}, /* D-Link - D-Link DWA-182 (Rev. C1) */170{USB_DEVICE(0x2001, 0x3316), .driver_info = RTL8812}, /* D-Link - Cameo */171{USB_DEVICE(0x13B1, 0x003F), .driver_info = RTL8812}, /* Linksys - WUSB6300 */172{USB_DEVICE(0x2357, 0x0101), .driver_info = RTL8812}, /* TP-Link - Archer T4U AC1200 */173{USB_DEVICE(0x2357, 0x0103), .driver_info = RTL8812}, /* TP-Link - T4UH */174{USB_DEVICE(0x2357, 0x010D), .driver_info = RTL8812}, /* TP-Link - Archer T4U AC1300 */175{USB_DEVICE(0x2357, 0x010E), .driver_info = RTL8812}, /* TP-Link - Archer T4UH AC1300 */176{USB_DEVICE(0x2357, 0x010F), .driver_info = RTL8812}, /* TP-Link - T4UHP */177{USB_DEVICE(0x2357, 0x0122), .driver_info = RTL8812}, /* TP-Link - T4UHP (other) */178{USB_DEVICE(0x20F4, 0x805B), .driver_info = RTL8812}, /* TRENDnet - TEW-805UB */179{USB_DEVICE(0x0411, 0x025D), .driver_info = RTL8812}, /* Buffalo - WI-U3-866D */180{USB_DEVICE(0x050D, 0x1109), .driver_info = RTL8812}, /* Belkin F9L1109 - SerComm */181{USB_DEVICE(0x148F, 0x9097), .driver_info = RTL8812}, /* Amped Wireless ACA1 */182{USB_DEVICE(0x2604, 0x0012), .driver_info = RTL8812}, /* Tenda U12 */183#endif184185#ifdef CONFIG_RTL8821A186/*=== Realtek demoboard ===*/187{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0811), .driver_info = RTL8821}, /* Default ID */188{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x0821), .driver_info = RTL8821}, /* Default ID */189{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8822), .driver_info = RTL8821}, /* Default ID */190{USB_DEVICE(USB_VENDER_ID_REALTEK, 0xA811) , .driver_info = RTL8821},/* Default ID */191{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0820, 0xff, 0xff, 0xff), .driver_info = RTL8821}, /* 8821AU */192{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x0823, 0xff, 0xff, 0xff), .driver_info = RTL8821}, /* 8821AU */193/*=== Customer ID ===*/194{USB_DEVICE(0x7392, 0xA811), .driver_info = RTL8821}, /* Edimax - Edimax */195{USB_DEVICE(0x7392, 0xA812), .driver_info = RTL8821}, /* Edimax - EW-7811UTC */196{USB_DEVICE(0x7392, 0xA813), .driver_info = RTL8821}, /* Edimax - EW-7811UAC */197{USB_DEVICE(0x7392, 0xB611), .driver_info = RTL8821}, /* Edimax - EW-7811UCB */198{USB_DEVICE(0x04BB, 0x0953), .driver_info = RTL8821}, /* I-O DATA - Edimax */199{USB_DEVICE(0x2001, 0x3314), .driver_info = RTL8821}, /* D-Link - Cameo */200{USB_DEVICE(0x2001, 0x3318), .driver_info = RTL8821}, /* D-Link - Cameo */201{USB_DEVICE(0x0E66, 0x0023), .driver_info = RTL8821}, /* HAWKING - Edimax */202{USB_DEVICE(0x056E, 0x400E), .driver_info = RTL8821}, /* ELECOM - ELECOM */203{USB_DEVICE(0x056E, 0x400F), .driver_info = RTL8821}, /* ELECOM - ELECOM */204{USB_DEVICE(0x0411, 0x0242), .driver_info = RTL8821}, /* ELECOM - WDC-433DU2H */205{USB_DEVICE(0x2019, 0xAB32), .driver_info = RTL8821}, /* Planex - GW-450S */206{USB_DEVICE(0x0846, 0x9052), .driver_info = RTL8821}, /* Netgear - A6100 */207{USB_DEVICE(0x0411, 0x029B), .driver_info = RTL8821}, /* Buffalo - WI-U2-433DHP */208{USB_DEVICE(0x056E, 0x4007), .driver_info = RTL8821}, /* Elecom - WDC-433DU2HBK */209{USB_DEVICE(0x0BDA, 0xA811), .driver_info = RTL8821}, /* GMYLE - AC450 */210{USB_DEVICE(0x3823, 0x6249), .driver_info = RTL8821}, /* Obihai - OBiWiFi */211{USB_DEVICE(0x2357, 0x011E), .driver_info = RTL8821}, /* TP Link - T2U Nano */212{USB_DEVICE(0x2357, 0x0122), .driver_info = RTL8821}, /* TP Link - T2U Nano */213{USB_DEVICE(0x2357, 0x0120), .driver_info = RTL8821}, /* TP Link - T2U Plus */214{USB_DEVICE(0x2357, 0x011F), .driver_info = RTL8821}, /* TP-Link - Archer AC600 T2U Nano */215{USB_DEVICE(0x20f4, 0x804b), .driver_info = RTL8821}, /* TRENDnet */216#endif217218#ifdef CONFIG_RTL8192E219/*=== Realtek demoboard ===*/220{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818B, 0xff, 0xff, 0xff), .driver_info = RTL8192E}, /* Default ID */221{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x818C, 0xff, 0xff, 0xff), .driver_info = RTL8192E}, /* Default ID */222#endif223224#ifdef CONFIG_RTL8723B225/* === Realtek demoboard === */226{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB720, 0xff, 0xff, 0xff), .driver_info = RTL8723B}, /* 8723BU 1*1 */227/* {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB720),.driver_info = RTL8723B}, 8723BU */228#endif229230#ifdef CONFIG_RTL8703B231/*=== Realtek demoboard ===*/232{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB703, 0xff, 0xff, 0xff), .driver_info = RTL8703B}, /* 8723CU 1*1 */233/* {USB_DEVICE(USB_VENDER_ID_REALTEK, 0xB703), .driver_info = RTL723C}, */ /* 8723CU 1*1 */234#endif /* CONFIG_RTL8703B */235236#ifdef CONFIG_RTL8814A237{USB_DEVICE(USB_VENDER_ID_REALTEK, 0x8813), .driver_info = RTL8814A},238/*=== Customer ID ===*/239{USB_DEVICE(0x2001, 0x331A), .driver_info = RTL8814A}, /* D-Link - D-Link */240{USB_DEVICE(0x0B05, 0x1817), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */241{USB_DEVICE(0x0B05, 0x1852), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */242{USB_DEVICE(0x0B05, 0x1853), .driver_info = RTL8814A}, /* ASUS - ASUSTeK */243{USB_DEVICE(0x056E, 0x400B), .driver_info = RTL8814A}, /* ELECOM - ELECOM */244{USB_DEVICE(0x056E, 0x400D), .driver_info = RTL8814A}, /* ELECOM - ELECOM */245{USB_DEVICE(0x7392, 0xA834), .driver_info = RTL8814A}, /* Edimax - Edimax */246{USB_DEVICE(0x7392, 0xA833), .driver_info = RTL8814A}, /* Edimax - AC1750 */247{USB_DEVICE(0x0BDA, 0x8813), .driver_info = RTL8814A}, /* Edimax - EDUP Adapters */248{USB_DEVICE(0x0e66, 0x0026), .driver_info = RTL8814A}, /* Hawking Technologies - HW17ACU*/249{USB_DEVICE(0x2357, 0x0106), .driver_info = RTL8814A}, /* TP-LINK Archer T9UH */250{USB_DEVICE(0x20F4, 0x809A), .driver_info = RTL8814A}, /* TRENDnet - TRENDnet */251{USB_DEVICE(0x20F4, 0x809B), .driver_info = RTL8814A}, /* TRENDnet TEW-809UB */252{USB_DEVICE(0x0846, 0x9054), .driver_info = RTL8814A}, /* Netgear A7000 */253254#endif /* CONFIG_RTL8814A */255256#ifdef CONFIG_RTL8188F257/*=== Realtek demoboard ===*/258{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xF179, 0xff, 0xff, 0xff), .driver_info = RTL8188F}, /* 8188FU 1*1 */259#endif260261#ifdef CONFIG_RTL8188GTV262/*=== Realtek demoboard ===*/263{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x018C, 0xff, 0xff, 0xff), .driver_info = RTL8188GTV}, /* 8188GTV 1*1 */264#endif265266#ifdef CONFIG_RTL8822B267/*=== Realtek demoboard ===*/268{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB82C, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Default ID for USB multi-function */269{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB812, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Default ID for USB Single-function, WiFi only */270/*=== Customer ID ===*/271{USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Alpha - Alpha*/272{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x1841, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* ASUS AC1300 USB-AC55 B1 */273{USB_DEVICE_AND_INTERFACE_INFO(0x0b05, 0x184C, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* ASUS U2*/274{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xB822, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Edimax EW-7822ULC */275{USB_DEVICE_AND_INTERFACE_INFO(0x7392, 0xC822, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Edimax EW-7822UTC */276{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331e, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Dlink - DWA-181*/277{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331c, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* Dlink - DWA-182*/278{USB_DEVICE_AND_INTERFACE_INFO(0x0846, 0x9055, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* NetGear A6150 */279{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x012D, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T3U */280{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0138, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T3U Plus */281{USB_DEVICE_AND_INTERFACE_INFO(0x2357, 0x0115, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TP-Link Archer T4U V3 */282{USB_DEVICE_AND_INTERFACE_INFO(0x20F4, 0x808A, 0xff, 0xff, 0xff), .driver_info = RTL8822B}, /* TRENDnet TEW-808UBM */283#endif /* CONFIG_RTL8822B */284285#ifdef CONFIG_RTL8723D286/*=== Realtek demoboard ===*/287{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD723, 0xff, 0xff, 0xff), .driver_info = RTL8723D}, /* 8723DU 1*1 */288#endif289290#ifdef CONFIG_RTL8192F291/*=== Realtek demoboard ===*/292{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xF192, 0xff, 0xff, 0xff), .driver_info = RTL8192F}, /* 8192FU 2*2 */293{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xA725, 0xff, 0xff, 0xff), .driver_info = RTL8192F}, /* 8725AU 2*2 */294#endif295296#ifdef CONFIG_RTL8821C297/*=== Realtek demoboard ===*/298{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xb82b, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */299{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xb820, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */300{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC821, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */301{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC820, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */302{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82A, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */303{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82B, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CU */304{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC811, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8811CU */305{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x8811, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8811CU */306{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x2006, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* TOTOLINK A650UA v3 */307{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0x8731, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8731AU */308{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC80C, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* 8821CUH */309/*=== Customer ID ===*/310{USB_DEVICE_AND_INTERFACE_INFO(0x2001, 0x331d, 0xff, 0xff, 0xff), .driver_info = RTL8821C}, /* D-Link - DWA-171C */311#endif312313#ifdef CONFIG_RTL8710B314/*=== Realtek dongle ===*/315{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB711, 0xff, 0xff, 0xff), .driver_info = RTL8710B}, /* 8710B = 8188GU 1*1 */316#endif317318#ifdef CONFIG_RTL8822C319/*=== Realtek demoboard ===*/320{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82C, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB multi-function */321{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC82E, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB multi-function */322{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xC812, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Default ID for USB Single-function, WiFi only */323{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD820, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* 21D USB multi-fuction*/324{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xD82B, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* 21D USB Single-fuction, WiFi only*/325/*=== Customer ID ===*/326{USB_DEVICE_AND_INTERFACE_INFO(0x13b1, 0x0043, 0xff, 0xff, 0xff), .driver_info = RTL8822C}, /* Alpha - Alpha*/327#endif /* CONFIG_RTL8822C */328329#ifdef CONFIG_RTL8814B330/*=== Realtek demoboard ===*/331{USB_DEVICE_AND_INTERFACE_INFO(USB_VENDER_ID_REALTEK, 0xB814, 0xff, 0xff, 0xff), .driver_info = RTL8814B}, /* Default ID for USB multi-function */332#endif /* CONFIG_RTL8814B */333334{} /* Terminating entry */335};336337MODULE_DEVICE_TABLE(usb, rtw_usb_id_tbl);338339int const rtw_usb_id_len = sizeof(rtw_usb_id_tbl) / sizeof(struct usb_device_id);340341static struct specific_device_id specific_device_id_tbl[] = {342{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x8177, .flags = SPEC_DEV_ID_DISABLE_HT}, /* 8188cu 1*1 dongole, (b/g mode only) */343{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x817E, .flags = SPEC_DEV_ID_DISABLE_HT}, /* 8188CE-VAU USB minCard (b/g mode only) */344{.idVendor = 0x0b05, .idProduct = 0x1791, .flags = SPEC_DEV_ID_DISABLE_HT},345{.idVendor = 0x13D3, .idProduct = 0x3311, .flags = SPEC_DEV_ID_DISABLE_HT},346{.idVendor = 0x13D3, .idProduct = 0x3359, .flags = SPEC_DEV_ID_DISABLE_HT}, /* Russian customer -Azwave (8188CE-VAU g mode) */347#ifdef RTK_DMP_PLATFORM348{.idVendor = USB_VENDER_ID_REALTEK, .idProduct = 0x8111, .flags = SPEC_DEV_ID_ASSIGN_IFNAME}, /* Realtek 5G dongle for WiFi Display */349{.idVendor = 0x2019, .idProduct = 0xAB2D, .flags = SPEC_DEV_ID_ASSIGN_IFNAME}, /* PCI-Abocom 5G dongle for WiFi Display */350#endif /* RTK_DMP_PLATFORM */351{}352};353354struct rtw_usb_drv {355struct usb_driver usbdrv;356int drv_registered;357u8 hw_type;358};359360struct rtw_usb_drv usb_drv = {361.usbdrv.name = (char *)DRV_NAME,362.usbdrv.probe = rtw_drv_init,363.usbdrv.disconnect = rtw_dev_remove,364.usbdrv.id_table = rtw_usb_id_tbl,365.usbdrv.suspend = rtw_suspend,366.usbdrv.resume = rtw_resume,367#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 22))368.usbdrv.reset_resume = rtw_resume,369#endif370#ifdef CONFIG_AUTOSUSPEND371.usbdrv.supports_autosuspend = 1,372#endif373374#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19))375.usbdrv.drvwrap.driver.shutdown = rtw_dev_shutdown,376#else377.usbdrv.driver.shutdown = rtw_dev_shutdown,378#endif379};380381static inline int RT_usb_endpoint_dir_in(const struct usb_endpoint_descriptor *epd)382{383return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_IN;384}385386static inline int RT_usb_endpoint_dir_out(const struct usb_endpoint_descriptor *epd)387{388return (epd->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT;389}390391static inline int RT_usb_endpoint_xfer_int(const struct usb_endpoint_descriptor *epd)392{393return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_INT;394}395396static inline int RT_usb_endpoint_xfer_bulk(const struct usb_endpoint_descriptor *epd)397{398return (epd->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) == USB_ENDPOINT_XFER_BULK;399}400401static inline int RT_usb_endpoint_is_bulk_in(const struct usb_endpoint_descriptor *epd)402{403return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_in(epd);404}405406static inline int RT_usb_endpoint_is_bulk_out(const struct usb_endpoint_descriptor *epd)407{408return RT_usb_endpoint_xfer_bulk(epd) && RT_usb_endpoint_dir_out(epd);409}410411static inline int RT_usb_endpoint_is_int_in(const struct usb_endpoint_descriptor *epd)412{413return RT_usb_endpoint_xfer_int(epd) && RT_usb_endpoint_dir_in(epd);414}415416static inline int RT_usb_endpoint_num(const struct usb_endpoint_descriptor *epd)417{418return epd->bEndpointAddress & USB_ENDPOINT_NUMBER_MASK;419}420421static u8 rtw_init_intf_priv(struct dvobj_priv *dvobj)422{423u8 rst = _SUCCESS;424425#ifdef CONFIG_USB_VENDOR_REQ_MUTEX426_rtw_mutex_init(&dvobj->usb_vendor_req_mutex);427#endif428429430#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC431dvobj->usb_alloc_vendor_req_buf = rtw_zmalloc(MAX_USB_IO_CTL_SIZE);432if (dvobj->usb_alloc_vendor_req_buf == NULL) {433RTW_INFO("alloc usb_vendor_req_buf failed... /n");434rst = _FAIL;435goto exit;436}437dvobj->usb_vendor_req_buf =438(u8 *)N_BYTE_ALIGMENT((SIZE_PTR)(dvobj->usb_alloc_vendor_req_buf), ALIGNMENT_UNIT);439exit:440#endif441442return rst;443444}445446static u8 rtw_deinit_intf_priv(struct dvobj_priv *dvobj)447{448u8 rst = _SUCCESS;449450#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_PREALLOC451if (dvobj->usb_vendor_req_buf)452rtw_mfree(dvobj->usb_alloc_vendor_req_buf, MAX_USB_IO_CTL_SIZE);453#endif454455#ifdef CONFIG_USB_VENDOR_REQ_MUTEX456_rtw_mutex_free(&dvobj->usb_vendor_req_mutex);457#endif458459return rst;460}461static void rtw_decide_chip_type_by_usb_info(struct dvobj_priv *pdvobjpriv, const struct usb_device_id *pdid)462{463pdvobjpriv->chip_type = pdid->driver_info;464465#ifdef CONFIG_RTL8188E466if (pdvobjpriv->chip_type == RTL8188E)467rtl8188eu_set_hw_type(pdvobjpriv);468#endif469470#if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)471if (pdvobjpriv->chip_type == RTL8812 || pdvobjpriv->chip_type == RTL8821)472rtl8812au_set_hw_type(pdvobjpriv);473#endif474475#ifdef CONFIG_RTL8192E476if (pdvobjpriv->chip_type == RTL8192E)477rtl8192eu_set_hw_type(pdvobjpriv);478#endif479480#ifdef CONFIG_RTL8723B481if (pdvobjpriv->chip_type == RTL8723B)482rtl8723bu_set_hw_type(pdvobjpriv);483#endif484485#ifdef CONFIG_RTL8814A486if (pdvobjpriv->chip_type == RTL8814A)487rtl8814au_set_hw_type(pdvobjpriv);488#endif /* CONFIG_RTL8814A */489490#ifdef CONFIG_RTL8188F491if (pdvobjpriv->chip_type == RTL8188F)492rtl8188fu_set_hw_type(pdvobjpriv);493#endif494495#ifdef CONFIG_RTL8188GTV496if (pdvobjpriv->chip_type == RTL8188GTV)497rtl8188gtvu_set_hw_type(pdvobjpriv);498#endif499500#ifdef CONFIG_RTL8703B501if (pdvobjpriv->chip_type == RTL8703B)502rtl8703bu_set_hw_type(pdvobjpriv);503#endif /* CONFIG_RTL8703B */504505#ifdef CONFIG_RTL8822B506if (pdvobjpriv->chip_type == RTL8822B)507rtl8822bu_set_hw_type(pdvobjpriv);508#endif /* CONFIG_RTL8822B */509510#ifdef CONFIG_RTL8723D511if (pdvobjpriv->chip_type == RTL8723D)512rtl8723du_set_hw_type(pdvobjpriv);513#endif /* CONFIG_RTL8723D */514515#ifdef CONFIG_RTL8821C516if (pdvobjpriv->chip_type == RTL8821C)517rtl8821cu_set_hw_type(pdvobjpriv);518#endif /* CONFIG_RTL8821C */519520#ifdef CONFIG_RTL8710B521if (pdvobjpriv->chip_type == RTL8710B)522rtl8710bu_set_hw_type(pdvobjpriv);523#endif /* CONFIG_RTL8710B */524525#ifdef CONFIG_RTL8192F526if (pdvobjpriv->chip_type == RTL8192F)527rtl8192fu_set_hw_type(pdvobjpriv);528#endif /* CONFIG_RTL8192F */529530#ifdef CONFIG_RTL8822C531if (pdvobjpriv->chip_type == RTL8822C)532rtl8822cu_set_hw_type(pdvobjpriv);533#endif /* CONFIG_RTL8822C */534535#ifdef CONFIG_RTL8814B536if (pdvobjpriv->chip_type == RTL8814B)537rtl8814bu_set_hw_type(pdvobjpriv);538#endif /* CONFIG_RTL8814B */539}540541static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf, const struct usb_device_id *pdid)542{543int i;544int status = _FAIL;545struct dvobj_priv *pdvobjpriv;546struct usb_device_descriptor *pdev_desc;547struct usb_host_config *phost_conf;548struct usb_config_descriptor *pconf_desc;549struct usb_host_interface *phost_iface;550struct usb_interface_descriptor *piface_desc;551struct usb_host_endpoint *phost_endp;552struct usb_endpoint_descriptor *pendp_desc;553struct usb_device *pusbd;554555556557pdvobjpriv = devobj_init();558if (pdvobjpriv == NULL)559goto exit;560561562pdvobjpriv->pusbintf = usb_intf ;563pusbd = pdvobjpriv->pusbdev = interface_to_usbdev(usb_intf);564usb_set_intfdata(usb_intf, pdvobjpriv);565566pdvobjpriv->RtNumInPipes = 0;567pdvobjpriv->RtNumOutPipes = 0;568569/* padapter->EepromAddressSize = 6; */570/* pdvobjpriv->nr_endpoint = 6; */571572pdev_desc = &pusbd->descriptor;573574#if 0575RTW_INFO("\n8712_usb_device_descriptor:\n");576RTW_INFO("bLength=%x\n", pdev_desc->bLength);577RTW_INFO("bDescriptorType=%x\n", pdev_desc->bDescriptorType);578RTW_INFO("bcdUSB=%x\n", pdev_desc->bcdUSB);579RTW_INFO("bDeviceClass=%x\n", pdev_desc->bDeviceClass);580RTW_INFO("bDeviceSubClass=%x\n", pdev_desc->bDeviceSubClass);581RTW_INFO("bDeviceProtocol=%x\n", pdev_desc->bDeviceProtocol);582RTW_INFO("bMaxPacketSize0=%x\n", pdev_desc->bMaxPacketSize0);583RTW_INFO("idVendor=%x\n", pdev_desc->idVendor);584RTW_INFO("idProduct=%x\n", pdev_desc->idProduct);585RTW_INFO("bcdDevice=%x\n", pdev_desc->bcdDevice);586RTW_INFO("iManufacturer=%x\n", pdev_desc->iManufacturer);587RTW_INFO("iProduct=%x\n", pdev_desc->iProduct);588RTW_INFO("iSerialNumber=%x\n", pdev_desc->iSerialNumber);589RTW_INFO("bNumConfigurations=%x\n", pdev_desc->bNumConfigurations);590#endif591592phost_conf = pusbd->actconfig;593pconf_desc = &phost_conf->desc;594595596/* RTW_INFO("\n***** num of altsetting = (%d) *****\n", pusb_interface->num_altsetting); */597598phost_iface = &usb_intf->altsetting[0];599piface_desc = &phost_iface->desc;600601pdvobjpriv->nr_endpoint = piface_desc->bNumEndpoints;602603/* RTW_INFO("\ndump usb_endpoint_descriptor:\n"); */604605for (i = 0; i < pdvobjpriv->nr_endpoint; i++) {606phost_endp = phost_iface->endpoint + i;607if (phost_endp) {608pendp_desc = &phost_endp->desc;609610RTW_INFO("usb_endpoint_descriptor(%d):\n", i);611RTW_INFO("bLength=%x\n", pendp_desc->bLength);612RTW_INFO("bDescriptorType=%x\n", pendp_desc->bDescriptorType);613RTW_INFO("bEndpointAddress=%x\n", pendp_desc->bEndpointAddress);614/* RTW_INFO("bmAttributes=%x\n",pendp_desc->bmAttributes); */615RTW_INFO("wMaxPacketSize=%d\n", le16_to_cpu(pendp_desc->wMaxPacketSize));616RTW_INFO("bInterval=%x\n", pendp_desc->bInterval);617/* RTW_INFO("bRefresh=%x\n",pendp_desc->bRefresh); */618/* RTW_INFO("bSynchAddress=%x\n",pendp_desc->bSynchAddress); */619620if (RT_usb_endpoint_is_bulk_in(pendp_desc)) {621RTW_INFO("RT_usb_endpoint_is_bulk_in = %x\n", RT_usb_endpoint_num(pendp_desc));622pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);623pdvobjpriv->RtNumInPipes++;624} else if (RT_usb_endpoint_is_int_in(pendp_desc)) {625RTW_INFO("RT_usb_endpoint_is_int_in = %x, Interval = %x\n", RT_usb_endpoint_num(pendp_desc), pendp_desc->bInterval);626pdvobjpriv->RtInPipe[pdvobjpriv->RtNumInPipes] = RT_usb_endpoint_num(pendp_desc);627pdvobjpriv->RtNumInPipes++;628} else if (RT_usb_endpoint_is_bulk_out(pendp_desc)) {629RTW_INFO("RT_usb_endpoint_is_bulk_out = %x\n", RT_usb_endpoint_num(pendp_desc));630pdvobjpriv->RtOutPipe[pdvobjpriv->RtNumOutPipes] = RT_usb_endpoint_num(pendp_desc);631pdvobjpriv->RtNumOutPipes++;632}633pdvobjpriv->ep_num[i] = RT_usb_endpoint_num(pendp_desc);634}635}636637RTW_INFO("nr_endpoint=%d, in_num=%d, out_num=%d\n", pdvobjpriv->nr_endpoint, pdvobjpriv->RtNumInPipes, pdvobjpriv->RtNumOutPipes);638639switch (pusbd->speed) {640case USB_SPEED_LOW:641RTW_INFO("USB_SPEED_LOW\n");642pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;643break;644case USB_SPEED_FULL:645RTW_INFO("USB_SPEED_FULL\n");646pdvobjpriv->usb_speed = RTW_USB_SPEED_1_1;647break;648case USB_SPEED_HIGH:649RTW_INFO("USB_SPEED_HIGH\n");650pdvobjpriv->usb_speed = RTW_USB_SPEED_2;651break;652#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31))653case USB_SPEED_SUPER:654RTW_INFO("USB_SPEED_SUPER\n");655pdvobjpriv->usb_speed = RTW_USB_SPEED_3;656break;657#endif658default:659RTW_INFO("USB_SPEED_UNKNOWN(%x)\n", pusbd->speed);660pdvobjpriv->usb_speed = RTW_USB_SPEED_UNKNOWN;661break;662}663664if (pdvobjpriv->usb_speed == RTW_USB_SPEED_UNKNOWN) {665RTW_INFO("UNKNOWN USB SPEED MODE, ERROR !!!\n");666goto free_dvobj;667}668669if (rtw_init_intf_priv(pdvobjpriv) == _FAIL) {670goto free_dvobj;671}672673/*step 1-1., decide the chip_type via driver_info*/674pdvobjpriv->interface_type = RTW_USB;675rtw_decide_chip_type_by_usb_info(pdvobjpriv, pdid);676677/* .3 misc */678_rtw_init_sema(&(pdvobjpriv->usb_suspend_sema), 0);679rtw_reset_continual_io_error(pdvobjpriv);680681usb_get_dev(pusbd);682683status = _SUCCESS;684685free_dvobj:686if (status != _SUCCESS && pdvobjpriv) {687usb_set_intfdata(usb_intf, NULL);688689devobj_deinit(pdvobjpriv);690691pdvobjpriv = NULL;692}693exit:694return pdvobjpriv;695}696697static void usb_dvobj_deinit(struct usb_interface *usb_intf)698{699struct dvobj_priv *dvobj = usb_get_intfdata(usb_intf);700701702usb_set_intfdata(usb_intf, NULL);703if (dvobj) {704rtw_deinit_intf_priv(dvobj);705devobj_deinit(dvobj);706}707708/* RTW_INFO("%s %d\n", __func__, ATOMIC_READ(&usb_intf->dev.kobj.kref.refcount)); */709usb_put_dev(interface_to_usbdev(usb_intf));710711}712713static int usb_reprobe_switch_usb_mode(PADAPTER Adapter)714{715struct registry_priv *registry_par = &Adapter->registrypriv;716HAL_DATA_TYPE *pHalData = GET_HAL_DATA(Adapter);717u8 ret = _FALSE;718719/* efuse not allow driver to switch usb mode */720if (pHalData->EEPROMUsbSwitch == _FALSE)721goto exit;722723/* registry not allow driver to switch usb mode */724if (registry_par->switch_usb_mode == 0)725goto exit;726727rtw_hal_set_hwreg(Adapter, HW_VAR_USB_MODE, &ret);728729exit:730return ret;731}732733u8 rtw_set_hal_ops(_adapter *padapter)734{735/* alloc memory for HAL DATA */736if (rtw_hal_data_init(padapter) == _FAIL)737return _FAIL;738739#ifdef CONFIG_RTL8188E740if (rtw_get_chip_type(padapter) == RTL8188E)741rtl8188eu_set_hal_ops(padapter);742#endif743744#if defined(CONFIG_RTL8812A) || defined(CONFIG_RTL8821A)745if (rtw_get_chip_type(padapter) == RTL8812 || rtw_get_chip_type(padapter) == RTL8821)746rtl8812au_set_hal_ops(padapter);747#endif748749#ifdef CONFIG_RTL8192E750if (rtw_get_chip_type(padapter) == RTL8192E)751rtl8192eu_set_hal_ops(padapter);752#endif753#ifdef CONFIG_RTL8723B754if (rtw_get_chip_type(padapter) == RTL8723B)755rtl8723bu_set_hal_ops(padapter);756#endif757#ifdef CONFIG_RTL8814A758if (rtw_get_chip_type(padapter) == RTL8814A)759rtl8814au_set_hal_ops(padapter);760#endif /* CONFIG_RTL8814A */761762#ifdef CONFIG_RTL8188F763if (rtw_get_chip_type(padapter) == RTL8188F)764rtl8188fu_set_hal_ops(padapter);765#endif766767#ifdef CONFIG_RTL8188GTV768if (rtw_get_chip_type(padapter) == RTL8188GTV)769rtl8188gtvu_set_hal_ops(padapter);770#endif771772#ifdef CONFIG_RTL8703B773if (rtw_get_chip_type(padapter) == RTL8703B)774rtl8703bu_set_hal_ops(padapter);775#endif /* CONFIG_RTL8703B */776777#ifdef CONFIG_RTL8822B778if (rtw_get_chip_type(padapter) == RTL8822B)779rtl8822bu_set_hal_ops(padapter);780#endif /* CONFIG_RTL8822B */781782#ifdef CONFIG_RTL8723D783if (rtw_get_chip_type(padapter) == RTL8723D)784rtl8723du_set_hal_ops(padapter);785#endif /* CONFIG_RTL8723D */786787788#ifdef CONFIG_RTL8821C789if (rtw_get_chip_type(padapter) == RTL8821C) {790if (rtl8821cu_set_hal_ops(padapter) == _FAIL)791return _FAIL;792}793#endif794795#ifdef CONFIG_RTL8710B796if (rtw_get_chip_type(padapter) == RTL8710B)797rtl8710bu_set_hal_ops(padapter);798#endif /* CONFIG_RTL8710B */799800801#ifdef CONFIG_RTL8192F802if (rtw_get_chip_type(padapter) == RTL8192F)803rtl8192fu_set_hal_ops(padapter);804#endif805806#ifdef CONFIG_RTL8822C807if (rtw_get_chip_type(padapter) == RTL8822C)808rtl8822cu_set_hal_ops(padapter);809#endif /* CONFIG_RTL8822C */810811#ifdef CONFIG_RTL8814B812if (rtw_get_chip_type(padapter) == RTL8814B)813rtl8814bu_set_hal_ops(padapter);814#endif /* CONFIG_RTL8814B */815816817if (_FAIL == rtw_hal_ops_check(padapter))818return _FAIL;819820if (hal_spec_init(padapter) == _FAIL)821return _FAIL;822823return _SUCCESS;824}825826static void usb_intf_start(_adapter *padapter)827{828PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);829830rtw_hal_inirp_init(padapter);831hal->usb_intf_start = _TRUE;832833834}835836static void usb_intf_stop(_adapter *padapter)837{838PHAL_DATA_TYPE hal = GET_HAL_DATA(padapter);839840/* disabel_hw_interrupt */841if (!rtw_is_surprise_removed(padapter)) {842/* device still exists, so driver can do i/o operation */843/* TODO: */844}845846/* cancel in irp */847rtw_hal_inirp_deinit(padapter);848849/* cancel out irp */850rtw_write_port_cancel(padapter);851852/* todo:cancel other irps */853854hal->usb_intf_start = _FALSE;855856}857858static void process_spec_devid(const struct usb_device_id *pdid)859{860u16 vid, pid;861u32 flags;862int i;863int num = sizeof(specific_device_id_tbl) / sizeof(struct specific_device_id);864865for (i = 0; i < num; i++) {866vid = specific_device_id_tbl[i].idVendor;867pid = specific_device_id_tbl[i].idProduct;868flags = specific_device_id_tbl[i].flags;869870#ifdef CONFIG_80211N_HT871if ((pdid->idVendor == vid) && (pdid->idProduct == pid) && (flags & SPEC_DEV_ID_DISABLE_HT)) {872rtw_ht_enable = 0;873rtw_bw_mode = 0;874rtw_ampdu_enable = 0;875}876#endif877878#ifdef RTK_DMP_PLATFORM879/* Change the ifname to wlan10 when PC side WFD dongle plugin on DMP platform. */880/* It is used to distinguish between normal and PC-side wifi dongle/module. */881if ((pdid->idVendor == vid) && (pdid->idProduct == pid) && (flags & SPEC_DEV_ID_ASSIGN_IFNAME)) {882extern char *ifname;883strncpy(ifname, "wlan10", 6);884/* RTW_INFO("%s()-%d: ifname=%s, vid=%04X, pid=%04X\n", __FUNCTION__, __LINE__, ifname, vid, pid); */885}886#endif /* RTK_DMP_PLATFORM */887888}889}890891#ifdef SUPPORT_HW_RFOFF_DETECTED892int rtw_hw_suspend(_adapter *padapter)893{894struct pwrctrl_priv *pwrpriv;895struct usb_interface *pusb_intf;896struct net_device *pnetdev;897898if (NULL == padapter)899goto error_exit;900901if ((_FALSE == padapter->bup) || RTW_CANNOT_RUN(padapter)) {902RTW_INFO("padapter->bup=%d bDriverStopped=%s bSurpriseRemoved = %s\n"903, padapter->bup904, rtw_is_drv_stopped(padapter) ? "True" : "False"905, rtw_is_surprise_removed(padapter) ? "True" : "False");906goto error_exit;907}908909pwrpriv = adapter_to_pwrctl(padapter);910pusb_intf = adapter_to_dvobj(padapter)->pusbintf;911pnetdev = padapter->pnetdev;912913LeaveAllPowerSaveMode(padapter);914915RTW_INFO("==> rtw_hw_suspend\n");916_enter_pwrlock(&pwrpriv->lock);917pwrpriv->bips_processing = _TRUE;918/* padapter->net_closed = _TRUE; */919/* s1. */920if (pnetdev) {921rtw_netif_carrier_off(pnetdev);922rtw_netif_stop_queue(pnetdev);923}924925/* s2. */926rtw_disassoc_cmd(padapter, 500, RTW_CMDF_DIRECTLY);927928/* s2-2. indicate disconnect to os */929/* rtw_indicate_disconnect(padapter); */930{931struct mlme_priv *pmlmepriv = &padapter->mlmepriv;932if (check_fwstate(pmlmepriv, _FW_LINKED)) {933_clr_fwstate_(pmlmepriv, _FW_LINKED);934rtw_led_control(padapter, LED_CTL_NO_LINK);935936rtw_os_indicate_disconnect(padapter, 0, _FALSE);937938#ifdef CONFIG_LPS939/* donnot enqueue cmd */940rtw_lps_ctrl_wk_cmd(padapter, LPS_CTRL_DISCONNECT, RTW_CMDF_DIRECTLY);941#endif942}943}944/* s2-3. */945rtw_free_assoc_resources(padapter, _TRUE);946947/* s2-4. */948rtw_free_network_queue(padapter, _TRUE);949#ifdef CONFIG_IPS950rtw_ips_dev_unload(padapter);951#endif952pwrpriv->rf_pwrstate = rf_off;953pwrpriv->bips_processing = _FALSE;954_exit_pwrlock(&pwrpriv->lock);955956return 0;957958error_exit:959RTW_INFO("%s, failed\n", __FUNCTION__);960return -1;961962}963964int rtw_hw_resume(_adapter *padapter)965{966struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);967struct usb_interface *pusb_intf = adapter_to_dvobj(padapter)->pusbintf;968struct net_device *pnetdev = padapter->pnetdev;969970RTW_INFO("==> rtw_hw_resume\n");971_enter_pwrlock(&pwrpriv->lock);972pwrpriv->bips_processing = _TRUE;973rtw_reset_drv_sw(padapter);974975if (pm_netdev_open(pnetdev, _FALSE) != 0) {976_exit_pwrlock(&pwrpriv->lock);977goto error_exit;978}979rtw_netif_device_attach(pnetdev);980rtw_netif_carrier_on(pnetdev);981982rtw_netif_wake_queue(pnetdev);983984pwrpriv->bkeepfwalive = _FALSE;985pwrpriv->brfoffbyhw = _FALSE;986987pwrpriv->rf_pwrstate = rf_on;988pwrpriv->bips_processing = _FALSE;989_exit_pwrlock(&pwrpriv->lock);990991992return 0;993error_exit:994RTW_INFO("%s, Open net dev failed\n", __FUNCTION__);995return -1;996}997#endif998999static int rtw_suspend(struct usb_interface *pusb_intf, pm_message_t message)1000{1001struct dvobj_priv *dvobj;1002struct pwrctrl_priv *pwrpriv;1003struct debug_priv *pdbgpriv;1004PADAPTER padapter;1005int ret = 0;100610071008dvobj = usb_get_intfdata(pusb_intf);1009pwrpriv = dvobj_to_pwrctl(dvobj);1010pdbgpriv = &dvobj->drv_dbg;1011padapter = dvobj_get_primary_adapter(dvobj);10121013if (pwrpriv->bInSuspend == _TRUE) {1014RTW_INFO("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);1015pdbgpriv->dbg_suspend_error_cnt++;1016goto exit;1017}10181019if ((padapter->bup) || !rtw_is_drv_stopped(padapter) || !rtw_is_surprise_removed(padapter)) {1020#ifdef CONFIG_AUTOSUSPEND1021if (pwrpriv->bInternalAutoSuspend) {10221023#ifdef SUPPORT_HW_RFOFF_DETECTED1024/* The FW command register update must after MAC and FW init ready. */1025if ((GET_HAL_DATA(padapter)->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable)) {1026u8 bOpen = _TRUE;1027rtw_interface_ps_func(padapter, HAL_USB_SELECT_SUSPEND, &bOpen);1028}1029#endif/* SUPPORT_HW_RFOFF_DETECTED */1030}1031#endif/* CONFIG_AUTOSUSPEND */1032}10331034ret = rtw_suspend_common(padapter);10351036exit:1037return ret;1038}10391040int rtw_resume_process(_adapter *padapter)1041{1042int ret;1043#if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND)1044int pm_cnt = 0;1045#endif1046struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);1047struct dvobj_priv *pdvobj = padapter->dvobj;1048struct debug_priv *pdbgpriv = &pdvobj->drv_dbg;104910501051if (pwrpriv->bInSuspend == _FALSE) {1052pdbgpriv->dbg_resume_error_cnt++;1053RTW_INFO("%s bInSuspend = %d\n", __FUNCTION__, pwrpriv->bInSuspend);1054return -1;1055}10561057#if defined(CONFIG_BT_COEXIST) && defined(CONFIG_AUTOSUSPEND) /* add by amy for 8723as-vau */1058#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))1059RTW_INFO("%s...pm_usage_cnt(%d) pwrpriv->bAutoResume=%x. ....\n", __func__, atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt)), pwrpriv->bAutoResume);1060pm_cnt = atomic_read(&(adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt));1061#else /* kernel < 2.6.32 */1062RTW_INFO("...pm_usage_cnt(%d).....\n", adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt);1063pm_cnt = adapter_to_dvobj(padapter)->pusbintf->pm_usage_cnt;1064#endif /* kernel < 2.6.32 */10651066RTW_INFO("pwrpriv->bAutoResume (%x)\n", pwrpriv->bAutoResume);1067if (_TRUE == pwrpriv->bAutoResume) {1068pwrpriv->bInternalAutoSuspend = _FALSE;1069pwrpriv->bAutoResume = _FALSE;1070RTW_INFO("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n", pwrpriv->bAutoResume, pwrpriv->bInternalAutoSuspend);10711072}1073#endif /* #ifdef CONFIG_BT_COEXIST &CONFIG_AUTOSUSPEND& */10741075/*1076* Due to usb wow suspend flow will cancel read/write port via intf_stop and1077* bReadPortCancel and bWritePortCancel are set _TRUE in intf_stop.1078* But they will not be clear in intf_start during wow resume flow.1079* It should move to os_intf in the feature.1080*/1081RTW_ENABLE_FUNC(padapter, DF_RX_BIT);1082RTW_ENABLE_FUNC(padapter, DF_TX_BIT);10831084ret = rtw_resume_common(padapter);10851086#ifdef CONFIG_AUTOSUSPEND1087if (pwrpriv->bInternalAutoSuspend) {1088#ifdef SUPPORT_HW_RFOFF_DETECTED1089/* The FW command register update must after MAC and FW init ready. */1090if ((GET_HAL_DATA(padapter)->bFWReady) && (pwrpriv->bHWPwrPindetect) && (padapter->registrypriv.usbss_enable)) {1091u8 bOpen = _FALSE;1092rtw_interface_ps_func(padapter, HAL_USB_SELECT_SUSPEND, &bOpen);1093}1094#endif1095#ifdef CONFIG_BT_COEXIST /* for 8723as-vau */1096RTW_INFO("pwrpriv->bAutoResume (%x)\n", pwrpriv->bAutoResume);1097if (_TRUE == pwrpriv->bAutoResume) {1098pwrpriv->bInternalAutoSuspend = _FALSE;1099pwrpriv->bAutoResume = _FALSE;1100RTW_INFO("pwrpriv->bAutoResume (%x) pwrpriv->bInternalAutoSuspend(%x)\n", pwrpriv->bAutoResume, pwrpriv->bInternalAutoSuspend);1101}11021103#else /* #ifdef CONFIG_BT_COEXIST */1104pwrpriv->bInternalAutoSuspend = _FALSE;1105#endif /* #ifdef CONFIG_BT_COEXIST */1106pwrpriv->brfoffbyhw = _FALSE;1107}1108#endif/* CONFIG_AUTOSUSPEND */110911101111return ret;1112}11131114static int rtw_resume(struct usb_interface *pusb_intf)1115{1116struct dvobj_priv *dvobj;1117struct pwrctrl_priv *pwrpriv;1118struct debug_priv *pdbgpriv;1119PADAPTER padapter;1120struct mlme_ext_priv *pmlmeext;1121int ret = 0;112211231124dvobj = usb_get_intfdata(pusb_intf);1125pwrpriv = dvobj_to_pwrctl(dvobj);1126pdbgpriv = &dvobj->drv_dbg;1127padapter = dvobj_get_primary_adapter(dvobj);1128pmlmeext = &padapter->mlmeextpriv;11291130RTW_INFO("==> %s (%s:%d)\n", __FUNCTION__, current->comm, current->pid);1131pdbgpriv->dbg_resume_cnt++;11321133#ifdef CONFIG_AUTOSUSPEND1134if (pwrpriv->bInternalAutoSuspend)1135ret = rtw_resume_process(padapter);1136else1137#endif1138{1139if (pwrpriv->wowlan_mode || pwrpriv->wowlan_ap_mode) {1140rtw_resume_lock_suspend();1141ret = rtw_resume_process(padapter);1142rtw_resume_unlock_suspend();1143} else {1144#ifdef CONFIG_RESUME_IN_WORKQUEUE1145rtw_resume_in_workqueue(pwrpriv);1146#else1147if (rtw_is_earlysuspend_registered(pwrpriv)) {1148/* jeff: bypass resume here, do in late_resume */1149rtw_set_do_late_resume(pwrpriv, _TRUE);1150} else {1151rtw_resume_lock_suspend();1152ret = rtw_resume_process(padapter);1153rtw_resume_unlock_suspend();1154}1155#endif1156}1157}11581159pmlmeext->last_scan_time = rtw_get_current_time();1160RTW_INFO("<======== %s return %d\n", __FUNCTION__, ret);11611162return ret;1163}1164116511661167#ifdef CONFIG_AUTOSUSPEND1168void autosuspend_enter(_adapter *padapter)1169{1170struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);1171struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);11721173RTW_INFO("==>autosuspend_enter...........\n");11741175pwrpriv->bInternalAutoSuspend = _TRUE;1176pwrpriv->bips_processing = _TRUE;11771178if (rf_off == pwrpriv->change_rfpwrstate) {1179#ifndef CONFIG_BT_COEXIST1180#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))1181usb_enable_autosuspend(dvobj->pusbdev);1182#else1183dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */1184#endif11851186#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1187usb_autopm_put_interface(dvobj->pusbintf);1188#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))1189usb_autopm_enable(dvobj->pusbintf);1190#else1191usb_autosuspend_device(dvobj->pusbdev, 1);1192#endif1193#else /* #ifndef CONFIG_BT_COEXIST */1194if (1 == pwrpriv->autopm_cnt) {1195#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))1196usb_enable_autosuspend(dvobj->pusbdev);1197#else1198dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */1199#endif12001201#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1202usb_autopm_put_interface(dvobj->pusbintf);1203#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))1204usb_autopm_enable(dvobj->pusbintf);1205#else1206usb_autosuspend_device(dvobj->pusbdev, 1);1207#endif1208pwrpriv->autopm_cnt--;1209} else1210RTW_INFO("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_put_interface\n", pwrpriv->autopm_cnt);12111212#endif /* #ifndef CONFIG_BT_COEXIST */1213}1214#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))1215RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));1216#else1217RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);1218#endif12191220}12211222int autoresume_enter(_adapter *padapter)1223{1224int result = _SUCCESS;1225struct security_priv *psecuritypriv = &(padapter->securitypriv);1226struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;1227struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);1228struct dvobj_priv *dvobj = adapter_to_dvobj(padapter);1229struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(dvobj);12301231RTW_INFO("====> autoresume_enter\n");12321233if (rf_off == pwrpriv->rf_pwrstate) {1234pwrpriv->ps_flag = _FALSE;1235#ifndef CONFIG_BT_COEXIST1236#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1237if (usb_autopm_get_interface(dvobj->pusbintf) < 0) {1238RTW_INFO("can't get autopm: %d\n", result);1239result = _FAIL;1240goto error_exit;1241}1242#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))1243usb_autopm_disable(dvobj->pusbintf);1244#else1245usb_autoresume_device(dvobj->pusbdev, 1);1246#endif12471248#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))1249RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));1250#else1251RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);1252#endif1253#else /* #ifndef CONFIG_BT_COEXIST */1254pwrpriv->bAutoResume = _TRUE;1255if (0 == pwrpriv->autopm_cnt) {1256#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1257if (usb_autopm_get_interface(dvobj->pusbintf) < 0) {1258RTW_INFO("can't get autopm: %d\n", result);1259result = _FAIL;1260goto error_exit;1261}1262#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))1263usb_autopm_disable(dvobj->pusbintf);1264#else1265usb_autoresume_device(dvobj->pusbdev, 1);1266#endif1267#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))1268RTW_INFO("...pm_usage_cnt(%d).....\n", atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));1269#else1270RTW_INFO("...pm_usage_cnt(%d).....\n", dvobj->pusbintf->pm_usage_cnt);1271#endif1272pwrpriv->autopm_cnt++;1273} else1274RTW_INFO("0!=pwrpriv->autopm_cnt[%d] didn't usb_autopm_get_interface\n", pwrpriv->autopm_cnt);1275#endif /* #ifndef CONFIG_BT_COEXIST */1276}1277RTW_INFO("<==== autoresume_enter\n");1278error_exit:12791280return result;1281}1282#endif12831284#ifdef CONFIG_PLATFORM_RTD2880B1285extern void rtd2885_wlan_netlink_sendMsg(char *action_string, char *name);1286#endif12871288/*1289* drv_init() - a device potentially for us1290*1291* notes: drv_init() is called when the bus driver has located a card for us to support.1292* We accept the new device by returning 0.1293*/1294_adapter *rtw_usb_primary_adapter_init(struct dvobj_priv *dvobj,1295struct usb_interface *pusb_intf)1296{1297_adapter *padapter = NULL;1298int status = _FAIL;12991300padapter = (_adapter *)rtw_zvmalloc(sizeof(*padapter));1301if (padapter == NULL)1302goto exit;13031304if (loadparam(padapter) != _SUCCESS)1305goto free_adapter;13061307padapter->dvobj = dvobj;130813091310rtw_set_drv_stopped(padapter);/*init*/13111312dvobj->padapters[dvobj->iface_nums++] = padapter;1313padapter->iface_id = IFACE_ID0;13141315/* set adapter_type/iface type for primary padapter */1316padapter->isprimary = _TRUE;1317padapter->adapter_type = PRIMARY_ADAPTER;1318#ifdef CONFIG_MI_WITH_MBSSID_CAM/*Configure all IFACE to PORT0-MBSSID*/1319padapter->hw_port = HW_PORT0;1320#else1321padapter->hw_port = HW_PORT0;1322#endif13231324/* step init_io_priv */1325if (rtw_init_io_priv(padapter, usb_set_intf_ops) == _FAIL)1326goto free_adapter;13271328/* step 2. hook HalFunc, allocate HalData */1329if (rtw_set_hal_ops(padapter) == _FAIL)1330goto free_hal_data;133113321333padapter->intf_start = &usb_intf_start;1334padapter->intf_stop = &usb_intf_stop;13351336/* step read_chip_version */1337rtw_hal_read_chip_version(padapter);13381339/* step usb endpoint mapping */1340rtw_hal_chip_configure(padapter);13411342#ifdef CONFIG_BT_COEXIST1343rtw_btcoex_Initialize(padapter);1344#endif1345rtw_btcoex_wifionly_initialize(padapter);13461347/* step read efuse/eeprom data and get mac_addr */1348if (rtw_hal_read_chip_info(padapter) == _FAIL)1349goto free_hal_data;13501351/* step 5. */1352if (rtw_init_drv_sw(padapter) == _FAIL) {1353goto free_hal_data;1354}13551356#ifdef CONFIG_PM1357#if (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 18))1358if (dvobj_to_pwrctl(dvobj)->bSupportRemoteWakeup) {1359dvobj->pusbdev->do_remote_wakeup = 1;1360pusb_intf->needs_remote_wakeup = 1;1361device_init_wakeup(&pusb_intf->dev, 1);1362RTW_INFO("pwrctrlpriv.bSupportRemoteWakeup~~~~~~\n");1363RTW_INFO("pwrctrlpriv.bSupportRemoteWakeup~~~[%d]~~~\n", device_may_wakeup(&pusb_intf->dev));1364}1365#endif1366#endif13671368#ifdef CONFIG_AUTOSUSPEND1369if (padapter->registrypriv.power_mgnt != PS_MODE_ACTIVE) {1370if (padapter->registrypriv.usbss_enable) { /* autosuspend (2s delay) */1371#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 38))1372dvobj->pusbdev->dev.power.autosuspend_delay = 0 * HZ;/* 15 * HZ; idle-delay time */1373#else1374dvobj->pusbdev->autosuspend_delay = 0 * HZ;/* 15 * HZ; idle-delay time */1375#endif13761377#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35))1378usb_enable_autosuspend(dvobj->pusbdev);1379#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22) && LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 34))1380padapter->bDisableAutosuspend = dvobj->pusbdev->autosuspend_disabled ;1381dvobj->pusbdev->autosuspend_disabled = 0;/* autosuspend disabled by the user */1382#endif13831384/* usb_autopm_get_interface(adapter_to_dvobj(padapter)->pusbintf ); */ /* init pm_usage_cnt ,let it start from 1 */13851386#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32))1387RTW_INFO("%s...pm_usage_cnt(%d).....\n", __FUNCTION__, atomic_read(&(dvobj->pusbintf->pm_usage_cnt)));1388#else1389RTW_INFO("%s...pm_usage_cnt(%d).....\n", __FUNCTION__, dvobj->pusbintf->pm_usage_cnt);1390#endif1391}1392}1393#endif1394/* 2012-07-11 Move here to prevent the 8723AS-VAU BT auto suspend influence */1395#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1396if (usb_autopm_get_interface(pusb_intf) < 0)1397RTW_INFO("can't get autopm:\n");1398#endif1399#ifdef CONFIG_BT_COEXIST1400dvobj_to_pwrctl(dvobj)->autopm_cnt = 1;1401#endif14021403/* set mac addr */1404rtw_macaddr_cfg(adapter_mac_addr(padapter), get_hal_mac_addr(padapter));1405#ifdef CONFIG_MI_WITH_MBSSID_CAM1406rtw_mbid_camid_alloc(padapter, adapter_mac_addr(padapter));1407#endif14081409#ifdef CONFIG_P2P1410rtw_init_wifidirect_addrs(padapter, adapter_mac_addr(padapter), adapter_mac_addr(padapter));1411#endif /* CONFIG_P2P */1412RTW_INFO("bDriverStopped:%s, bSurpriseRemoved:%s, bup:%d, hw_init_completed:%d\n"1413, rtw_is_drv_stopped(padapter) ? "True" : "False"1414, rtw_is_surprise_removed(padapter) ? "True" : "False"1415, padapter->bup1416, rtw_get_hw_init_completed(padapter)1417);14181419status = _SUCCESS;14201421free_hal_data:1422if (status != _SUCCESS && padapter->HalData)1423rtw_hal_free_data(padapter);1424free_adapter:1425if (status != _SUCCESS && padapter) {1426#ifdef RTW_HALMAC1427rtw_halmac_deinit_adapter(dvobj);1428#endif1429rtw_vmfree((u8 *)padapter, sizeof(*padapter));1430padapter = NULL;1431}1432exit:1433return padapter;1434}14351436static void rtw_usb_primary_adapter_deinit(_adapter *padapter)1437{1438#if defined(CONFIG_WOWLAN) || defined(CONFIG_BT_COEXIST)1439struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);1440#endif1441struct mlme_priv *pmlmepriv = &padapter->mlmepriv;14421443RTW_INFO(FUNC_ADPT_FMT"\n", FUNC_ADPT_ARG(padapter));14441445if (check_fwstate(pmlmepriv, _FW_LINKED))1446rtw_disassoc_cmd(padapter, 0, RTW_CMDF_DIRECTLY);14471448#ifdef CONFIG_AP_MODE1449if (MLME_IS_AP(padapter) || MLME_IS_MESH(padapter)) {1450free_mlme_ap_info(padapter);1451#ifdef CONFIG_HOSTAPD_MLME1452hostapd_mode_unload(padapter);1453#endif1454}1455#endif14561457/*rtw_cancel_all_timer(if1);*/14581459#ifdef CONFIG_WOWLAN1460pwrctl->wowlan_mode = _FALSE;1461#endif /* CONFIG_WOWLAN */14621463rtw_dev_unload(padapter);14641465RTW_INFO("+r871xu_dev_remove, hw_init_completed=%d\n", rtw_get_hw_init_completed(padapter));14661467#ifdef CONFIG_BT_COEXIST1468if (1 == pwrctl->autopm_cnt) {1469#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 33))1470usb_autopm_put_interface(adapter_to_dvobj(padapter)->pusbintf);1471#elif (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 20))1472usb_autopm_enable(adapter_to_dvobj(padapter)->pusbintf);1473#else1474usb_autosuspend_device(adapter_to_dvobj(padapter)->pusbdev, 1);1475#endif1476pwrctl->autopm_cnt--;1477}1478#endif14791480rtw_free_drv_sw(padapter);14811482/* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */1483rtw_os_ndev_free(padapter);14841485#ifdef RTW_HALMAC1486rtw_halmac_deinit_adapter(adapter_to_dvobj(padapter));1487#endif /* RTW_HALMAC */14881489rtw_vmfree((u8 *)padapter, sizeof(_adapter));14901491#ifdef CONFIG_PLATFORM_RTD2880B1492RTW_INFO("wlan link down\n");1493rtd2885_wlan_netlink_sendMsg("linkdown", "8712");1494#endif14951496}14971498static int rtw_drv_init(struct usb_interface *pusb_intf, const struct usb_device_id *pdid)1499{1500_adapter *padapter = NULL;1501int status = _FAIL;1502struct dvobj_priv *dvobj;1503#ifdef CONFIG_CONCURRENT_MODE1504int i;1505#endif15061507/* RTW_INFO("+rtw_drv_init\n"); */15081509/* step 0. */1510process_spec_devid(pdid);15111512/* Initialize dvobj_priv */1513dvobj = usb_dvobj_init(pusb_intf, pdid);1514if (dvobj == NULL) {1515goto exit;1516}15171518padapter = rtw_usb_primary_adapter_init(dvobj, pusb_intf);1519if (padapter == NULL) {1520RTW_INFO("rtw_usb_primary_adapter_init Failed!\n");1521goto free_dvobj;1522}15231524if (usb_reprobe_switch_usb_mode(padapter) == _TRUE)1525goto free_if_prim;15261527#ifdef CONFIG_CONCURRENT_MODE1528if (padapter->registrypriv.virtual_iface_num > (CONFIG_IFACE_NUMBER - 1))1529padapter->registrypriv.virtual_iface_num = (CONFIG_IFACE_NUMBER - 1);15301531for (i = 0; i < padapter->registrypriv.virtual_iface_num; i++) {1532if (rtw_drv_add_vir_if(padapter, usb_set_intf_ops) == NULL) {1533RTW_INFO("rtw_drv_add_iface failed! (%d)\n", i);1534goto free_if_vir;1535}1536}1537#endif15381539#ifdef CONFIG_GLOBAL_UI_PID1540if (ui_pid[1] != 0) {1541RTW_INFO("ui_pid[1]:%d\n", ui_pid[1]);1542rtw_signal_process(ui_pid[1], SIGUSR2);1543}1544#endif15451546/* dev_alloc_name && register_netdev */1547if (rtw_os_ndevs_init(dvobj) != _SUCCESS)1548goto free_if_vir;15491550#ifdef CONFIG_HOSTAPD_MLME1551hostapd_mode_init(padapter);1552#endif15531554#ifdef CONFIG_PLATFORM_RTD2880B1555RTW_INFO("wlan link up\n");1556rtd2885_wlan_netlink_sendMsg("linkup", "8712");1557#endif155815591560status = _SUCCESS;15611562#if 0 /* not used now */1563os_ndevs_deinit:1564if (status != _SUCCESS)1565rtw_os_ndevs_deinit(dvobj);1566#endif1567free_if_vir:1568if (status != _SUCCESS) {1569#ifdef CONFIG_CONCURRENT_MODE1570rtw_drv_stop_vir_ifaces(dvobj);1571rtw_drv_free_vir_ifaces(dvobj);1572#endif1573}15741575free_if_prim:1576if (status != _SUCCESS && padapter)1577rtw_usb_primary_adapter_deinit(padapter);15781579free_dvobj:1580if (status != _SUCCESS)1581usb_dvobj_deinit(pusb_intf);1582exit:1583return status == _SUCCESS ? 0 : -ENODEV;1584}15851586/*1587* dev_remove() - our device is being removed1588*/1589/* rmmod module & unplug(SurpriseRemoved) will call r871xu_dev_remove() => how to recognize both */1590static void rtw_dev_remove(struct usb_interface *pusb_intf)1591{1592struct dvobj_priv *dvobj = usb_get_intfdata(pusb_intf);1593#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)1594struct pwrctrl_priv *pwrctl = dvobj_to_pwrctl(dvobj);1595#endif1596_adapter *padapter = dvobj_get_primary_adapter(dvobj);15971598RTW_INFO("+rtw_dev_remove\n");15991600dvobj->processing_dev_remove = _TRUE;16011602/* TODO: use rtw_os_ndevs_deinit instead at the first stage of driver's dev deinit function */1603rtw_os_ndevs_unregister(dvobj);16041605if (usb_drv.drv_registered == _TRUE) {1606/* RTW_INFO("r871xu_dev_remove():padapter->bSurpriseRemoved == _TRUE\n"); */1607rtw_set_surprise_removed(padapter);1608}1609/*else1610{16111612rtw_set_hw_init_completed(padapter, _FALSE);1613}*/161416151616#if defined(CONFIG_HAS_EARLYSUSPEND) || defined(CONFIG_ANDROID_POWER)1617rtw_unregister_early_suspend(pwrctl);1618#endif16191620if (GET_HAL_DATA(padapter)->bFWReady == _TRUE) {1621rtw_pm_set_ips(padapter, IPS_NONE);1622rtw_pm_set_lps(padapter, PS_MODE_ACTIVE);16231624LeaveAllPowerSaveMode(padapter);1625}1626rtw_set_drv_stopped(padapter); /*for stop thread*/1627rtw_stop_cmd_thread(padapter);1628#ifdef CONFIG_CONCURRENT_MODE1629rtw_drv_stop_vir_ifaces(dvobj);1630#endif /* CONFIG_CONCURRENT_MODE */16311632#ifdef CONFIG_BT_COEXIST1633#ifdef CONFIG_BT_COEXIST_SOCKET_TRX1634if (GET_HAL_DATA(padapter)->EEPROMBluetoothCoexist)1635rtw_btcoex_close_socket(padapter);1636#endif1637rtw_btcoex_HaltNotify(padapter);1638#endif16391640rtw_usb_primary_adapter_deinit(padapter);16411642#ifdef CONFIG_CONCURRENT_MODE1643rtw_drv_free_vir_ifaces(dvobj);1644#endif /* CONFIG_CONCURRENT_MODE */16451646usb_dvobj_deinit(pusb_intf);16471648// RTW_INFO("-r871xu_dev_remove, done\n");16491650return;16511652}1653#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))1654extern int console_suspend_enabled;1655#endif16561657static int __init rtw_drv_entry(void)1658{1659int ret = 0;16601661RTW_PRINT("module init start\n");1662dump_drv_version(RTW_DBGDUMP);1663#ifdef BTCOEXVERSION1664RTW_PRINT(DRV_NAME" BT-Coex version = %s\n", BTCOEXVERSION);1665#endif /* BTCOEXVERSION */16661667ret = platform_wifi_power_on();1668if (ret != 0) {1669RTW_INFO("%s: power on failed!!(%d)\n", __FUNCTION__, ret);1670ret = -1;1671goto exit;1672}1673#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24))1674/* console_suspend_enabled=0; */1675#endif16761677usb_drv.drv_registered = _TRUE;1678rtw_suspend_lock_init();1679rtw_drv_proc_init();1680rtw_ndev_notifier_register();1681rtw_inetaddr_notifier_register();16821683ret = usb_register(&usb_drv.usbdrv);16841685if (ret != 0) {1686usb_drv.drv_registered = _FALSE;1687rtw_suspend_lock_uninit();1688rtw_drv_proc_deinit();1689rtw_ndev_notifier_unregister();1690rtw_inetaddr_notifier_unregister();1691goto exit;1692}16931694exit:1695RTW_PRINT("module init ret=%d\n", ret);1696return ret;1697}16981699static void __exit rtw_drv_halt(void)1700{1701RTW_PRINT("module exit start\n");17021703usb_drv.drv_registered = _FALSE;17041705usb_deregister(&usb_drv.usbdrv);17061707platform_wifi_power_off();17081709rtw_suspend_lock_uninit();1710rtw_drv_proc_deinit();1711rtw_ndev_notifier_unregister();1712rtw_inetaddr_notifier_unregister();17131714RTW_PRINT("module exit success\n");17151716rtw_mstat_dump(RTW_DBGDUMP);1717}17181719module_init(rtw_drv_entry);1720module_exit(rtw_drv_halt);172117221723