usb_intf.c 64 KB

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