usb_intf.c 64 KB

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