usb_intf.c 65 KB

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