usb_intf.c 64 KB

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