usb_intf.c 64 KB

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