usb_intf.c 66 KB

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