usb_intf.c 64 KB

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