usb_intf.c 65 KB

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