usb_intf.c 65 KB

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