usb_intf.c 65 KB

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