usb_intf.c 64 KB

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