gl_init.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058
  1. /*
  2. ** Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/os/linux/gl_init.c#11
  3. */
  4. /*! \file gl_init.c
  5. \brief Main routines of Linux driver
  6. This file contains the main routines of Linux driver for MediaTek Inc. 802.11
  7. Wireless LAN Adapters.
  8. */
  9. /*
  10. ** Log: gl_init.c
  11. **
  12. ** 04 21 2014 eason.tsai
  13. ** [ALPS01514837] [SQC1][KK][Free Test][SIM management][KE]Kernel (KE),0,0,99,/data/core/,0,,KE at tx_thread,
  14. ** after tap"SIM mamagement"(0/5)
  15. ** fix race condition when wlanremove
  16. **
  17. ** 01 15 2014 eason.tsai
  18. ** [ALPS01070904] [Need Patch] [Volunteer Patch][MT6630][Driver]MT6630 Wi-Fi Patch
  19. ** Merging
  20. **
  21. ** //ALPS_SW/DEV/ALPS.JB2.MT6630.DEV/alps/mediatek/kernel/drivers/combo/drv_wlan/mt6630/wlan/...
  22. **
  23. ** to //ALPS_SW/TRUNK/KK/alps/mediatek/kernel/drivers/combo/drv_wlan/mt6630/wlan/...
  24. **
  25. ** 12 27 2013 eason.tsai
  26. ** [ALPS01070904] [Need Patch] [Volunteer Patch][MT6630][Driver]MT6630 Wi-Fi Patch
  27. ** update code for ICAP & nvram
  28. **
  29. ** 08 26 2013 jeffrey.chang
  30. ** [BORA00002710] [MT6630][Wi-Fi] PM driver development
  31. ** 1) Add SwCr for enable/disable ARP filter
  32. **
  33. ** 08 23 2013 wh.su
  34. ** [BORA00002446] [MT6630] [Wi-Fi] [Driver] Update the security function code
  35. ** Add GTK re-key driver handle function
  36. **
  37. ** 08 15 2013 cp.wu
  38. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  39. ** enlarge match_ssid_num to 16 for PNO support
  40. **
  41. ** 08 09 2013 cp.wu
  42. ** [BORA00002253] [MT6630 Wi-Fi][Driver][Firmware] Add NLO and timeout mechanism to SCN module
  43. ** 1. integrate scheduled scan functionality
  44. ** 2. condition compilation for linux-3.4 & linux-3.8 compatibility
  45. ** 3. correct CMD queue access to reduce lock scope
  46. **
  47. ** 08 02 2013 cp.wu
  48. ** [BORA00002725] [MT6630][Wi-Fi] Add MGMT TX/RX support for Linux port
  49. ** enable remain_on_channel support
  50. **
  51. ** 07 31 2013 yuche.tsai
  52. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  53. ** Change private data of net device.
  54. **
  55. ** 07 30 2013 yuche.tsai
  56. ** [BORA00002398] [MT6630][Volunteer Patch] P2P Driver Re-Design for Multiple BSS support
  57. ** Temp fix Hot-spot data path issue.
  58. **
  59. ** 07 29 2013 cp.wu
  60. ** [BORA00002725] [MT6630][Wi-Fi] Add MGMT TX/RX support for Linux port
  61. ** Preparation for porting remain_on_channel support
  62. **
  63. ** 07 26 2013 terry.wu
  64. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  65. ** 1. Set NoACK to BMC packet
  66. ** 2. Add kalGetEthAddr function for Tx frame
  67. ** 3. Update RxIndicatePackets
  68. **
  69. ** 07 26 2013 terry.wu
  70. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  71. ** 1. Reduce extra Tx frame header parsing
  72. ** 2. Add TX port control
  73. ** 3. Add net interface to BSS binding
  74. **
  75. ** 07 23 2013 cp.wu
  76. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  77. ** 1. build success for win32 port
  78. ** 2. add SDIO test read/write pattern for HQA tests (default off)
  79. **
  80. ** 07 04 2013 terry.wu
  81. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  82. ** Update for 1st Connection.
  83. **
  84. ** 03 13 2013 terry.wu
  85. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  86. ** .
  87. **
  88. ** 01 23 2013 terry.wu
  89. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  90. ** Refine net dev implementation
  91. **
  92. ** 01 21 2013 terry.wu
  93. ** [BORA00002207] [MT6630 Wi-Fi] TXM & MQM Implementation
  94. ** Update TX path based on new ucBssIndex modifications.
  95. **
  96. ** 01 17 2013 cm.chang
  97. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  98. ** Use ucBssIndex to replace eNetworkTypeIndex
  99. **
  100. ** 11 14 2012 cp.wu
  101. ** [BORA00002227] [MT6630 Wi-Fi][Driver] Update for Makefile and HIFSYS modifications
  102. ** add checksum offloading parameter.
  103. **
  104. ** 09 17 2012 cm.chang
  105. ** [BORA00002149] [MT6630 Wi-Fi] Initial software development
  106. ** Duplicate source from MT6620 v2.3 driver branch
  107. ** (Davinci label: MT6620_WIFI_Driver_V2_3_120913_1942_As_MT6630_Base)
  108. **
  109. ** 09 04 2012 cp.wu
  110. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  111. ** sync for NVRAM warning scan result generation for CFG80211.
  112. **
  113. ** 08 24 2012 cp.wu
  114. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  115. ** .
  116. **
  117. ** 08 24 2012 cp.wu
  118. ** [WCXRP00001269] [MT6620 Wi-Fi][Driver] cfg80211 porting merge back to DaVinci
  119. ** cfg80211 support merge back from ALPS.JB to DaVinci - MT6620 Driver v2.3 branch.
  120. *
  121. * 07 17 2012 yuche.tsai
  122. * NULL
  123. * Fix compile error.
  124. *
  125. * 07 17 2012 yuche.tsai
  126. * NULL
  127. * Fix compile error for JB.
  128. *
  129. * 07 17 2012 yuche.tsai
  130. * NULL
  131. * Let netdev bring up.
  132. *
  133. * 07 17 2012 yuche.tsai
  134. * NULL
  135. * Compile no error before trial run.
  136. *
  137. * 06 13 2012 yuche.tsai
  138. * NULL
  139. * Update maintrunk driver.
  140. * Add support for driver compose assoc request frame.
  141. *
  142. * 05 25 2012 yuche.tsai
  143. * NULL
  144. * Fix reset KE issue.
  145. *
  146. * 05 11 2012 cp.wu
  147. * [WCXRP00001237] [MT6620 Wi-Fi][Driver] Show MAC address and MAC address source for ACS's convenience
  148. * show MAC address & source while initiliazation
  149. *
  150. * 03 02 2012 terry.wu
  151. * NULL
  152. * EXPORT_SYMBOL(rsnParseCheckForWFAInfoElem);.
  153. *
  154. * 03 02 2012 terry.wu
  155. * NULL
  156. * Snc CFG80211 modification for ICS migration from branch 2.2.
  157. *
  158. * 03 02 2012 terry.wu
  159. * NULL
  160. * Sync CFG80211 modification from branch 2,2.
  161. *
  162. * 03 02 2012 terry.wu
  163. * NULL
  164. * Enable CFG80211 Support.
  165. *
  166. * 12 22 2011 george.huang
  167. * [WCXRP00000905] [MT6628 Wi-Fi][FW] Code refinement for ROM/ RAM module dependency
  168. * using global variable instead of stack for setting wlanoidSetNetworkAddress(), due to buffer may be released before
  169. * TX thread handling
  170. *
  171. * 11 18 2011 yuche.tsai
  172. * NULL
  173. * CONFIG P2P support RSSI query, default turned off.
  174. *
  175. * 11 14 2011 yuche.tsai
  176. * [WCXRP00001107] [Volunteer Patch][Driver] Large Network Type index assert in FW issue.
  177. * Fix large network type index assert in FW issue.
  178. *
  179. * 11 14 2011 cm.chang
  180. * NULL
  181. * Fix compiling warning
  182. *
  183. * 11 11 2011 yuche.tsai
  184. * NULL
  185. * Fix work thread cancel issue.
  186. *
  187. * 11 10 2011 cp.wu
  188. * [WCXRP00001098] [MT6620 Wi-Fi][Driver] Replace printk by DBG LOG macros in linux porting layer
  189. * 1. eliminaite direct calls to printk in porting layer.
  190. * 2. replaced by DBGLOG, which would be XLOG on ALPS platforms.
  191. *
  192. * 10 06 2011 eddie.chen
  193. * [WCXRP00001027] [MT6628 Wi-Fi][Firmware/Driver] Tx fragmentation
  194. * Add rlmDomainGetChnlList symbol.
  195. *
  196. * 09 22 2011 cm.chang
  197. * NULL
  198. * Safer writng stype to avoid unitialized regitry structure
  199. *
  200. * 09 21 2011 cm.chang
  201. * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
  202. * Avoid possible structure alignment problem
  203. *
  204. * 09 20 2011 chinglan.wang
  205. * [WCXRP00000989] [WiFi Direct] [Driver] Add a new io control API to start the formation for the sigma test.
  206. * .
  207. *
  208. * 09 08 2011 cm.chang
  209. * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
  210. * Use new fields ucChannelListMap and ucChannelListIndex in NVRAM
  211. *
  212. * 08 31 2011 cm.chang
  213. * [WCXRP00000969] [MT6620 Wi-Fi][Driver][FW] Channel list for 5G band based on country code
  214. * .
  215. *
  216. * 08 11 2011 cp.wu
  217. * [WCXRP00000830] [MT6620 Wi-Fi][Firmware] Use MDRDY counter to detect empty channel for shortening scan time
  218. * expose scnQuerySparseChannel() for P2P-FSM.
  219. *
  220. * 08 11 2011 cp.wu
  221. * [WCXRP00000830] [MT6620 Wi-Fi][Firmware] Use MDRDY counter to detect empty channel for shortening scan time
  222. * sparse channel detection:
  223. * driver: collect sparse channel information with scan-done event
  224. *
  225. * 08 02 2011 yuche.tsai
  226. * [WCXRP00000896] [Volunteer Patch][WiFi Direct][Driver] GO with multiple client, TX deauth to a disconnecting
  227. * device issue.
  228. * Fix GO send deauth frame issue.
  229. *
  230. * 07 07 2011 wh.su
  231. * [WCXRP00000839] [MT6620 Wi-Fi][Driver] Add the dumpMemory8 and dumpMemory32 EXPORT_SYMBOL
  232. * Add the dumpMemory8 symbol export for debug mode.
  233. *
  234. * 07 06 2011 terry.wu
  235. * [WCXRP00000735] [MT6620 Wi-Fi][BoW][FW/Driver] Protect BoW connection establishment
  236. * Improve BoW connection establishment speed.
  237. *
  238. * 07 05 2011 yuche.tsai
  239. * [WCXRP00000821] [Volunteer Patch][WiFi Direct][Driver] WiFi Direct Connection Speed Issue
  240. * Export one symbol for enhancement.
  241. *
  242. * 06 13 2011 eddie.chen
  243. * [WCXRP00000779] [MT6620 Wi-Fi][DRV] Add tx rx statistics in linux and use netif_rx_ni
  244. * Add tx rx statistics and netif_rx_ni.
  245. *
  246. * 05 27 2011 cp.wu
  247. * [WCXRP00000749] [MT6620 Wi-Fi][Driver] Add band edge tx power control to Wi-Fi NVRAM
  248. * invoke CMD_ID_SET_EDGE_TXPWR_LIMIT when there is valid data exist in NVRAM content.
  249. *
  250. * 05 18 2011 cp.wu
  251. * [WCXRP00000734] [MT6620 Wi-Fi][Driver] Pass PHY_PARAM in NVRAM to firmware domain
  252. * pass PHY_PARAM in NVRAM from driver to firmware.
  253. *
  254. * 05 09 2011 jeffrey.chang
  255. * [WCXRP00000710] [MT6620 Wi-Fi] Support pattern filter update function on IP address change
  256. * support ARP filter through kernel notifier
  257. *
  258. * 05 03 2011 chinghwa.yu
  259. * [WCXRP00000065] Update BoW design and settings
  260. * Use kalMemAlloc to allocate event buffer for kalIndicateBOWEvent.
  261. *
  262. * 04 27 2011 george.huang
  263. * [WCXRP00000684] [MT6620 Wi-Fi][Driver] Support P2P setting ARP filter
  264. * Support P2P ARP filter setting on early suspend/ late resume
  265. *
  266. * 04 18 2011 terry.wu
  267. * [WCXRP00000660] [MT6620 Wi-Fi][Driver] Remove flag CFG_WIFI_DIRECT_MOVED
  268. * Remove flag CFG_WIFI_DIRECT_MOVED.
  269. *
  270. * 04 15 2011 chinghwa.yu
  271. * [WCXRP00000065] Update BoW design and settings
  272. * Add BOW short range mode.
  273. *
  274. * 04 14 2011 yuche.tsai
  275. * [WCXRP00000646] [Volunteer Patch][MT6620][FW/Driver] Sigma Test Modification for some test case.
  276. * Modify some driver connection flow or behavior to pass Sigma test more easier..
  277. *
  278. * 04 12 2011 cm.chang
  279. * [WCXRP00000634] [MT6620 Wi-Fi][Driver][FW] 2nd BSS will not support 40MHz bandwidth for concurrency
  280. * .
  281. *
  282. * 04 11 2011 george.huang
  283. * [WCXRP00000621] [MT6620 Wi-Fi][Driver] Support P2P supplicant to set power mode
  284. * export wlan functions to p2p
  285. *
  286. * 04 08 2011 pat.lu
  287. * [WCXRP00000623] [MT6620 Wi-Fi][Driver] use ARCH define to distinguish PC Linux driver
  288. * Use CONFIG_X86 instead of PC_LINUX_DRIVER_USE option to have proper compile setting for PC Linux driver
  289. *
  290. * 04 08 2011 cp.wu
  291. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  292. * glBusFreeIrq() should use the same pvCookie as glBusSetIrq() or request_irq()/free_irq() won't work as a pair.
  293. *
  294. * 04 08 2011 eddie.chen
  295. * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
  296. * Fix for sigma
  297. *
  298. * 04 06 2011 cp.wu
  299. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  300. * 1. do not check for pvData inside wlanNetCreate() due to it is NULL for eHPI port
  301. * 2. update perm_addr as well for MAC address
  302. * 3. not calling check_mem_region() anymore for eHPI
  303. * 4. correct MSC_CS macro for 0-based notation
  304. *
  305. * 03 29 2011 cp.wu
  306. * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for
  307. * RESET_START and RESET_END events
  308. * fix typo.
  309. *
  310. * 03 29 2011 cp.wu
  311. * [WCXRP00000598] [MT6620 Wi-Fi][Driver] Implementation of interface for communicating with user space process for
  312. * RESET_START and RESET_END events
  313. * implement kernel-to-userspace communication via generic netlink socket for whole-chip resetting mechanism
  314. *
  315. * 03 23 2011 cp.wu
  316. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  317. * apply multi-queue operation only for linux kernel > 2.6.26
  318. *
  319. * 03 22 2011 pat.lu
  320. * [WCXRP00000592] [MT6620 Wi-Fi][Driver] Support PC Linux Environment Driver Build
  321. * Add a compiler option "PC_LINUX_DRIVER_USE" for building driver in PC Linux environment.
  322. *
  323. * 03 21 2011 cp.wu
  324. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  325. * portability for compatible with linux 2.6.12.
  326. *
  327. * 03 21 2011 cp.wu
  328. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  329. * improve portability for awareness of early version of linux kernel and wireless extension.
  330. *
  331. * 03 21 2011 cp.wu
  332. * [WCXRP00000540] [MT5931][Driver] Add eHPI8/eHPI16 support to Linux Glue Layer
  333. * portability improvement
  334. *
  335. * 03 18 2011 jeffrey.chang
  336. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  337. * remove early suspend functions
  338. *
  339. * 03 17 2011 cp.wu
  340. * [WCXRP00000562] [MT6620 Wi-Fi][Driver] I/O buffer pre-allocation to avoid physically continuous memory shortage
  341. * after system running for a long period
  342. * reverse order to prevent probing racing.
  343. *
  344. * 03 16 2011 cp.wu
  345. * [WCXRP00000562] [MT6620 Wi-Fi][Driver] I/O buffer pre-allocation to avoid physically continuous memory shortage
  346. * after system running for a long period
  347. * 1. pre-allocate physical continuous buffer while module is being loaded
  348. * 2. use pre-allocated physical continuous buffer for TX/RX DMA transfer
  349. *
  350. * The windows part remained the same as before, but added similar APIs to hide the difference.
  351. *
  352. * 03 15 2011 jeffrey.chang
  353. * [WCXRP00000558] [MT6620 Wi-Fi][MT6620 Wi-Fi][Driver] refine the queue selection algorithm for WMM
  354. * refine the queue_select function
  355. *
  356. * 03 10 2011 cp.wu
  357. * [WCXRP00000532] [MT6620 Wi-Fi][Driver] Migrate NVRAM configuration procedures from MT6620 E2 to MT6620 E3
  358. * deprecate configuration used by MT6620 E2
  359. *
  360. * 03 10 2011 terry.wu
  361. * [WCXRP00000505] [MT6620 Wi-Fi][Driver/FW] WiFi Direct Integration
  362. * Remove unnecessary assert and message.
  363. *
  364. * 03 08 2011 terry.wu
  365. * [WCXRP00000505] [MT6620 Wi-Fi][Driver/FW] WiFi Direct Integration
  366. * Export nicQmUpdateWmmParms.
  367. *
  368. * 03 03 2011 jeffrey.chang
  369. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  370. * support concurrent network
  371. *
  372. * 03 03 2011 jeffrey.chang
  373. * [WCXRP00000512] [MT6620 Wi-Fi][Driver] modify the net device relative functions to support the H/W multiple queue
  374. * modify net device relative functions to support multiple H/W queues
  375. *
  376. * 02 24 2011 george.huang
  377. * [WCXRP00000495] [MT6620 Wi-Fi][FW] Support pattern filter for unwanted ARP frames
  378. * Support ARP filter during suspended
  379. *
  380. * 02 21 2011 cp.wu
  381. * [WCXRP00000482] [MT6620 Wi-Fi][Driver] Simplify logic for checking NVRAM existence in driver domain
  382. * simplify logic for checking NVRAM existence only once.
  383. *
  384. * 02 17 2011 terry.wu
  385. * [WCXRP00000459] [MT6620 Wi-Fi][Driver] Fix deference null pointer problem in wlanRemove
  386. * Fix deference a null pointer problem in wlanRemove.
  387. *
  388. * 02 16 2011 jeffrey.chang
  389. * NULL
  390. * fix compilig error
  391. *
  392. * 02 16 2011 jeffrey.chang
  393. * NULL
  394. * Add query ipv4 and ipv6 address during early suspend and late resume
  395. *
  396. * 02 15 2011 jeffrey.chang
  397. * NULL
  398. * to support early suspend in android
  399. *
  400. * 02 11 2011 yuche.tsai
  401. * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
  402. * Add one more export symbol.
  403. *
  404. * 02 10 2011 yuche.tsai
  405. * [WCXRP00000431] [Volunteer Patch][MT6620][Driver] Add MLME support for deauthentication under AP(Hot-Spot) mode.
  406. * Add RX deauthentication & disassociation process under Hot-Spot mode.
  407. *
  408. * 02 09 2011 terry.wu
  409. * [WCXRP00000383] [MT6620 Wi-Fi][Driver] Separate WiFi and P2P driver into two modules
  410. * Halt p2p module init and exit until TxThread finished p2p register and unregister.
  411. *
  412. * 02 08 2011 george.huang
  413. * [WCXRP00000422] [MT6620 Wi-Fi][Driver] support query power mode OID handler
  414. * Support querying power mode OID.
  415. *
  416. * 02 08 2011 yuche.tsai
  417. * [WCXRP00000421] [Volunteer Patch][MT6620][Driver] Fix incorrect SSID length Issue
  418. * Export Deactivation Network.
  419. *
  420. * 02 01 2011 jeffrey.chang
  421. * [WCXRP00000414] KAL Timer is not unregistered when driver not loaded
  422. * Unregister the KAL timer during driver unloading
  423. *
  424. * 01 26 2011 cm.chang
  425. * [WCXRP00000395] [MT6620 Wi-Fi][Driver][FW] Search STA_REC with additional net type index argument
  426. * Allocate system RAM if fixed message or mgmt buffer is not available
  427. *
  428. * 01 19 2011 cp.wu
  429. * [WCXRP00000371] [MT6620 Wi-Fi][Driver] make linux glue layer portable for Android 2.3.1 with Linux 2.6.35.7
  430. * add compile option to check linux version 2.6.35 for different usage of system API to improve portability
  431. *
  432. * 01 12 2011 cp.wu
  433. * [WCXRP00000357] [MT6620 Wi-Fi][Driver][Bluetooth over Wi-Fi] add another net device interface for BT AMP
  434. * implementation of separate BT_OVER_WIFI data path.
  435. *
  436. * 01 10 2011 cp.wu
  437. * [WCXRP00000349] [MT6620 Wi-Fi][Driver] make kalIoctl() of linux port as a thread safe API to avoid potential issues
  438. * due to multiple access
  439. * use mutex to protect kalIoctl() for thread safe.
  440. *
  441. * 01 04 2011 cp.wu
  442. * [WCXRP00000338] [MT6620 Wi-Fi][Driver] Separate kalMemAlloc into kmalloc and vmalloc implementations to ease
  443. * physically continuous memory demands
  444. * separate kalMemAlloc() into virtually-continuous and physically-continuous type to ease slab system pressure
  445. *
  446. * 12 15 2010 cp.wu
  447. * [WCXRP00000265] [MT6620 Wi-Fi][Driver] Remove set_mac_address routine from legacy Wi-Fi Android driver
  448. * remove set MAC address. MAC address is always loaded from NVRAM instead.
  449. *
  450. * 12 10 2010 kevin.huang
  451. * [WCXRP00000128] [MT6620 Wi-Fi][Driver] Add proc support to Android Driver for debug and driver status check
  452. * Add Linux Proc Support
  453. *
  454. * 11 01 2010 yarco.yang
  455. * [WCXRP00000149] [MT6620 WI-Fi][Driver]Fine tune performance on MT6516 platform
  456. * Add GPIO debug function
  457. *
  458. * 11 01 2010 cp.wu
  459. * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000150] [MT6620 Wi-Fi][Driver]
  460. * Add implementation for querying current TX rate from firmware auto rate module
  461. * 1) Query link speed (TX rate) from firmware directly with buffering mechanism to reduce overhead
  462. * 2) Remove CNM CH-RECOVER event handling
  463. * 3) cfg read/write API renamed with kal prefix for unified naming rules.
  464. *
  465. * 10 26 2010 cp.wu
  466. * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000137] [MT6620 Wi-Fi] [FW]
  467. * Support NIC capability query command
  468. * 1) update NVRAM content template to ver 1.02
  469. * 2) add compile option for querying NIC capability (default: off)
  470. * 3) modify AIS 5GHz support to run-time option, which could be turned on by registry or NVRAM setting
  471. * 4) correct auto-rate compiler error under linux (treat warning as error)
  472. * 5) simplify usage of NVRAM and REG_INFO_T
  473. * 6) add version checking between driver and firmware
  474. *
  475. * 10 21 2010 chinghwa.yu
  476. * [WCXRP00000065] Update BoW design and settings
  477. * .
  478. *
  479. * 10 19 2010 jeffrey.chang
  480. * [WCXRP00000120] [MT6620 Wi-Fi][Driver] Refine linux kernel module to the license of MTK propietary and enable MTK
  481. * HIF by default
  482. * Refine linux kernel module to the license of MTK and enable MTK HIF
  483. *
  484. * 10 18 2010 jeffrey.chang
  485. * [WCXRP00000106] [MT6620 Wi-Fi][Driver] Enable setting multicast callback in Android
  486. * .
  487. *
  488. * 10 18 2010 cp.wu
  489. * [WCXRP00000056] [MT6620 Wi-Fi][Driver] NVRAM implementation with Version Check[WCXRP00000086] [MT6620 Wi-Fi][Driver]
  490. * The mac address is all zero at android
  491. * complete implementation of Android NVRAM access
  492. *
  493. * 09 27 2010 chinghwa.yu
  494. * [WCXRP00000063] Update BCM CoEx design and settings[WCXRP00000065] Update BoW design and settings
  495. * Update BCM/BoW design and settings.
  496. *
  497. * 09 23 2010 cp.wu
  498. * [WCXRP00000051] [MT6620 Wi-Fi][Driver] WHQL test fail in MAC address changed item
  499. * use firmware reported mac address right after wlanAdapterStart() as permanent address
  500. *
  501. * 09 21 2010 kevin.huang
  502. * [WCXRP00000052] [MT6620 Wi-Fi][Driver] Eliminate Linux Compile Warning
  503. * Eliminate Linux Compile Warning
  504. *
  505. * 09 03 2010 kevin.huang
  506. * NULL
  507. * Refine #include sequence and solve recursive/nested #include issue
  508. *
  509. * 09 01 2010 wh.su
  510. * NULL
  511. * adding the wapi support for integration test.
  512. *
  513. * 08 18 2010 yarco.yang
  514. * NULL
  515. * 1. Fixed HW checksum offload function not work under Linux issue.
  516. * 2. Add debug message.
  517. *
  518. * 08 16 2010 yarco.yang
  519. * NULL
  520. * Support Linux x86
  521. *
  522. * 08 02 2010 jeffrey.chang
  523. * NULL
  524. * 1) modify tx service thread to avoid busy looping
  525. * 2) add spin lock declartion for linux build
  526. *
  527. * 07 29 2010 jeffrey.chang
  528. * NULL
  529. * fix memory leak for module unloading
  530. *
  531. * 07 28 2010 jeffrey.chang
  532. * NULL
  533. * 1) remove unused spinlocks
  534. * 2) enable encyption ioctls
  535. * 3) fix scan ioctl which may cause supplicant to hang
  536. *
  537. * 07 23 2010 jeffrey.chang
  538. *
  539. * bug fix: allocate regInfo when disabling firmware download
  540. *
  541. * 07 23 2010 jeffrey.chang
  542. *
  543. * use glue layer api to decrease or increase counter atomically
  544. *
  545. * 07 22 2010 jeffrey.chang
  546. *
  547. * add new spinlock
  548. *
  549. * 07 19 2010 jeffrey.chang
  550. *
  551. * modify cmd/data path for new design
  552. *
  553. * 07 08 2010 cp.wu
  554. *
  555. * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
  556. *
  557. * 06 06 2010 kevin.huang
  558. * [WPD00003832][MT6620 5931] Create driver base
  559. * [MT6620 5931] Create driver base
  560. *
  561. * 05 26 2010 jeffrey.chang
  562. * [WPD00003826]Initial import for Linux port
  563. * 1) Modify set mac address code
  564. * 2) remove power management macro
  565. *
  566. * 05 10 2010 cp.wu
  567. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  568. * implement basic wi-fi direct framework
  569. *
  570. * 05 07 2010 jeffrey.chang
  571. * [WPD00003826]Initial import for Linux port
  572. * prevent supplicant accessing driver during resume
  573. *
  574. * 05 07 2010 cp.wu
  575. * [WPD00003831][MT6620 Wi-Fi] Add framework for Wi-Fi Direct support
  576. * add basic framework for implementating P2P driver hook.
  577. *
  578. * 04 27 2010 jeffrey.chang
  579. * [WPD00003826]Initial import for Linux port
  580. * 1) fix firmware download bug
  581. * 2) remove query statistics for acelerating firmware download
  582. *
  583. * 04 27 2010 jeffrey.chang
  584. * [WPD00003826]Initial import for Linux port
  585. * follow Linux's firmware framework, and remove unused kal API
  586. *
  587. * 04 21 2010 jeffrey.chang
  588. * [WPD00003826]Initial import for Linux port
  589. * add for private ioctl support
  590. *
  591. * 04 19 2010 jeffrey.chang
  592. * [WPD00003826]Initial import for Linux port
  593. * Query statistics from firmware
  594. *
  595. * 04 19 2010 jeffrey.chang
  596. * [WPD00003826]Initial import for Linux port
  597. * modify tcp/ip checksum offload flags
  598. *
  599. * 04 16 2010 jeffrey.chang
  600. * [WPD00003826]Initial import for Linux port
  601. * fix tcp/ip checksum offload bug
  602. *
  603. * 04 13 2010 cp.wu
  604. * [WPD00003823][MT6620 Wi-Fi] Add Bluetooth-over-Wi-Fi support
  605. * add framework for BT-over-Wi-Fi support.
  606. * * * * * * * * * * * * * * * * * 1) prPendingCmdInfo is replaced by queue for multiple handler
  607. * * * * * * * * * * * * * * * * * capability
  608. * * * * * * * * * * * * * * * * * 2) command sequence number is now increased atomically
  609. * * * * * * * * * * * * * * * * * 3) private data could be hold and taken use for other purpose
  610. *
  611. * 04 09 2010 jeffrey.chang
  612. * [WPD00003826]Initial import for Linux port
  613. * fix spinlock usage
  614. *
  615. * 04 07 2010 jeffrey.chang
  616. * [WPD00003826]Initial import for Linux port
  617. * Set MAC address from firmware
  618. *
  619. * 04 07 2010 cp.wu
  620. * [WPD00001943]Create WiFi test driver framework on WinXP
  621. * rWlanInfo should be placed at adapter rather than glue due to most operations
  622. * * * * * * are done in adapter layer.
  623. *
  624. * 04 07 2010 jeffrey.chang
  625. * [WPD00003826]Initial import for Linux port
  626. * (1)improve none-glue code portability
  627. * * (2) disable set Multicast address during atomic context
  628. *
  629. * 04 06 2010 jeffrey.chang
  630. * [WPD00003826]Initial import for Linux port
  631. * adding debug module
  632. *
  633. * 03 31 2010 wh.su
  634. * [WPD00003816][MT6620 Wi-Fi] Adding the security support
  635. * modify the wapi related code for new driver's design.
  636. *
  637. * 03 30 2010 jeffrey.chang
  638. * [WPD00003826]Initial import for Linux port
  639. * emulate NDIS Pending OID facility
  640. *
  641. * 03 26 2010 jeffrey.chang
  642. * [WPD00003826]Initial import for Linux port
  643. * fix f/w download start and load address by using config.h
  644. *
  645. * 03 26 2010 jeffrey.chang
  646. * [WPD00003826]Initial import for Linux port
  647. * [WPD00003826] Initial import for Linux port
  648. * adding firmware download support
  649. *
  650. * 03 24 2010 jeffrey.chang
  651. * [WPD00003826]Initial import for Linux port
  652. * initial import for Linux port
  653. ** \main\maintrunk.MT5921\52 2009-10-27 22:49:59 GMT mtk01090
  654. ** Fix compile error for Linux EHPI driver
  655. ** \main\maintrunk.MT5921\51 2009-10-20 17:38:22 GMT mtk01090
  656. ** Refine driver unloading and clean up procedure. Block requests, stop main thread and clean up queued requests,
  657. ** and then stop hw.
  658. ** \main\maintrunk.MT5921\50 2009-10-08 10:33:11 GMT mtk01090
  659. ** Avoid accessing private data of net_device directly. Replace with netdev_priv(). Add more checking for input
  660. ** parameters and pointers.
  661. ** \main\maintrunk.MT5921\49 2009-09-28 20:19:05 GMT mtk01090
  662. ** Add private ioctl to carry OID structures. Restructure public/private ioctl interfaces to Linux kernel.
  663. ** \main\maintrunk.MT5921\48 2009-09-03 13:58:46 GMT mtk01088
  664. ** remove non-used code
  665. ** \main\maintrunk.MT5921\47 2009-09-03 11:40:25 GMT mtk01088
  666. ** adding the module parameter for wapi
  667. ** \main\maintrunk.MT5921\46 2009-08-18 22:56:41 GMT mtk01090
  668. ** Add Linux SDIO (with mmc core) support.
  669. ** Add Linux 2.6.21, 2.6.25, 2.6.26.
  670. ** Fix compile warning in Linux.
  671. ** \main\maintrunk.MT5921\45 2009-07-06 20:53:00 GMT mtk01088
  672. ** adding the code to check the wapi 1x frame
  673. ** \main\maintrunk.MT5921\44 2009-06-23 23:18:55 GMT mtk01090
  674. ** Add build option BUILD_USE_EEPROM and compile option CFG_SUPPORT_EXT_CONFIG for NVRAM support
  675. ** \main\maintrunk.MT5921\43 2009-02-16 23:46:51 GMT mtk01461
  676. ** Revise the order of increasing u4TxPendingFrameNum because of CFG_TX_RET_TX_CTRL_EARLY
  677. ** \main\maintrunk.MT5921\42 2009-01-22 13:11:59 GMT mtk01088
  678. ** set the tid and 1x value at same packet reserved field
  679. ** \main\maintrunk.MT5921\41 2008-10-20 22:43:53 GMT mtk01104
  680. ** Fix wrong variable name "prDev" in wlanStop()
  681. ** \main\maintrunk.MT5921\40 2008-10-16 15:37:10 GMT mtk01461
  682. ** add handle WLAN_STATUS_SUCCESS in wlanHardStartXmit() for CFG_TX_RET_TX_CTRL_EARLY
  683. ** \main\maintrunk.MT5921\39 2008-09-25 15:56:21 GMT mtk01461
  684. ** Update driver for Code review
  685. ** \main\maintrunk.MT5921\38 2008-09-05 17:25:07 GMT mtk01461
  686. ** Update Driver for Code Review
  687. ** \main\maintrunk.MT5921\37 2008-09-02 10:57:06 GMT mtk01461
  688. ** Update driver for code review
  689. ** \main\maintrunk.MT5921\36 2008-08-05 01:53:28 GMT mtk01461
  690. ** Add support for linux statistics
  691. ** \main\maintrunk.MT5921\35 2008-08-04 16:52:58 GMT mtk01461
  692. ** Fix ASSERT if removing module in BG_SSID_SCAN state
  693. ** \main\maintrunk.MT5921\34 2008-06-13 22:52:24 GMT mtk01461
  694. ** Revise status code handling in wlanHardStartXmit() for WLAN_STATUS_SUCCESS
  695. ** \main\maintrunk.MT5921\33 2008-05-30 18:56:53 GMT mtk01461
  696. ** Not use wlanoidSetCurrentAddrForLinux()
  697. ** \main\maintrunk.MT5921\32 2008-05-30 14:39:40 GMT mtk01461
  698. ** Remove WMM Assoc Flag
  699. ** \main\maintrunk.MT5921\31 2008-05-23 10:26:40 GMT mtk01084
  700. ** modify wlanISR interface
  701. ** \main\maintrunk.MT5921\30 2008-05-03 18:52:36 GMT mtk01461
  702. ** Fix Unset Broadcast filter when setMulticast
  703. ** \main\maintrunk.MT5921\29 2008-05-03 15:17:26 GMT mtk01461
  704. ** Move Query Media Status to GLUE
  705. ** \main\maintrunk.MT5921\28 2008-04-24 22:48:21 GMT mtk01461
  706. ** Revise set multicast function by using windows oid style for LP own back
  707. ** \main\maintrunk.MT5921\27 2008-04-24 12:00:08 GMT mtk01461
  708. ** Fix multicast setting in Linux and add comment
  709. ** \main\maintrunk.MT5921\26 2008-03-28 10:40:22 GMT mtk01461
  710. ** Fix set mac address func in Linux
  711. ** \main\maintrunk.MT5921\25 2008-03-26 15:37:26 GMT mtk01461
  712. ** Add set MAC Address
  713. ** \main\maintrunk.MT5921\24 2008-03-26 14:24:53 GMT mtk01461
  714. ** For Linux, set net_device has feature with checksum offload by default
  715. ** \main\maintrunk.MT5921\23 2008-03-11 14:50:52 GMT mtk01461
  716. ** Fix typo
  717. ** \main\maintrunk.MT5921\22 2008-02-29 15:35:20 GMT mtk01088
  718. ** add 1x decide code for sw port control
  719. ** \main\maintrunk.MT5921\21 2008-02-21 15:01:54 GMT mtk01461
  720. ** Rearrange the set off place of GLUE spin lock in HardStartXmit
  721. ** \main\maintrunk.MT5921\20 2008-02-12 23:26:50 GMT mtk01461
  722. ** Add debug option - Packet Order for Linux and add debug level - Event
  723. ** \main\maintrunk.MT5921\19 2007-12-11 00:11:12 GMT mtk01461
  724. ** Fix SPIN_LOCK protection
  725. ** \main\maintrunk.MT5921\18 2007-11-30 17:02:25 GMT mtk01425
  726. ** 1. Set Rx multicast packets mode before setting the address list
  727. ** \main\maintrunk.MT5921\17 2007-11-26 19:44:24 GMT mtk01461
  728. ** Add OS_TIMESTAMP to packet
  729. ** \main\maintrunk.MT5921\16 2007-11-21 15:47:20 GMT mtk01088
  730. ** fixed the unload module issue
  731. ** \main\maintrunk.MT5921\15 2007-11-07 18:37:38 GMT mtk01461
  732. ** Fix compile warnning
  733. ** \main\maintrunk.MT5921\14 2007-11-02 01:03:19 GMT mtk01461
  734. ** Unify TX Path for Normal and IBSS Power Save + IBSS neighbor learning
  735. ** \main\maintrunk.MT5921\13 2007-10-30 10:42:33 GMT mtk01425
  736. ** 1. Refine for multicast list
  737. ** \main\maintrunk.MT5921\12 2007-10-25 18:08:13 GMT mtk01461
  738. ** Add VOIP SCAN Support & Refine Roaming
  739. ** Revision 1.4 2007/07/05 07:25:33 MTK01461
  740. ** Add Linux initial code, modify doc, add 11BB, RF init code
  741. **
  742. ** Revision 1.3 2007/06/27 02:18:50 MTK01461
  743. ** Update SCAN_FSM, Initial(Can Load Module), Proc(Can do Reg R/W), TX API
  744. **
  745. ** Revision 1.2 2007/06/25 06:16:24 MTK01461
  746. ** Update illustrations, gl_init.c, gl_kal.c, gl_kal.h, gl_os.h and RX API
  747. **
  748. */
  749. /*******************************************************************************
  750. * C O M P I L E R F L A G S
  751. ********************************************************************************
  752. */
  753. /*******************************************************************************
  754. * E X T E R N A L R E F E R E N C E S
  755. ********************************************************************************
  756. */
  757. #include "gl_os.h"
  758. #include "wlan_lib.h"
  759. #include "gl_wext.h"
  760. #include "gl_cfg80211.h"
  761. #include "precomp.h"
  762. #if CFG_SUPPORT_AGPS_ASSIST
  763. #include "gl_kal.h"
  764. #endif
  765. #include "gl_vendor.h"
  766. /*******************************************************************************
  767. * C O N S T A N T S
  768. ********************************************************************************
  769. */
  770. /* #define MAX_IOREQ_NUM 10 */
  771. struct semaphore g_halt_sem;
  772. int g_u4HaltFlag = 0;
  773. static struct wireless_dev *gprWdev;
  774. /*******************************************************************************
  775. * D A T A T Y P E S
  776. ********************************************************************************
  777. */
  778. /* Tasklet mechanism is like buttom-half in Linux. We just want to
  779. * send a signal to OS for interrupt defer processing. All resources
  780. * are NOT allowed reentry, so txPacket, ISR-DPC and ioctl must avoid preempty.
  781. */
  782. typedef struct _WLANDEV_INFO_T {
  783. struct net_device *prDev;
  784. } WLANDEV_INFO_T, *P_WLANDEV_INFO_T;
  785. /*******************************************************************************
  786. * P U B L I C D A T A
  787. ********************************************************************************
  788. */
  789. #define CHAN2G(_channel, _freq, _flags) \
  790. { \
  791. .band = IEEE80211_BAND_2GHZ, \
  792. .center_freq = (_freq), \
  793. .hw_value = (_channel), \
  794. .flags = (_flags), \
  795. .max_antenna_gain = 0, \
  796. .max_power = 30, \
  797. }
  798. static struct ieee80211_channel mtk_2ghz_channels[] = {
  799. CHAN2G(1, 2412, 0),
  800. CHAN2G(2, 2417, 0),
  801. CHAN2G(3, 2422, 0),
  802. CHAN2G(4, 2427, 0),
  803. CHAN2G(5, 2432, 0),
  804. CHAN2G(6, 2437, 0),
  805. CHAN2G(7, 2442, 0),
  806. CHAN2G(8, 2447, 0),
  807. CHAN2G(9, 2452, 0),
  808. CHAN2G(10, 2457, 0),
  809. CHAN2G(11, 2462, 0),
  810. CHAN2G(12, 2467, 0),
  811. CHAN2G(13, 2472, 0),
  812. CHAN2G(14, 2484, 0),
  813. };
  814. #define CHAN5G(_channel, _flags) \
  815. { \
  816. .band = IEEE80211_BAND_5GHZ, \
  817. .center_freq = 5000 + (5 * (_channel)), \
  818. .hw_value = (_channel), \
  819. .flags = (_flags), \
  820. .max_antenna_gain = 0, \
  821. .max_power = 30, \
  822. }
  823. static struct ieee80211_channel mtk_5ghz_channels[] = {
  824. CHAN5G(34, 0), CHAN5G(36, 0),
  825. CHAN5G(38, 0), CHAN5G(40, 0),
  826. CHAN5G(42, 0), CHAN5G(44, 0),
  827. CHAN5G(46, 0), CHAN5G(48, 0),
  828. CHAN5G(52, 0), CHAN5G(56, 0),
  829. CHAN5G(60, 0), CHAN5G(64, 0),
  830. CHAN5G(100, 0), CHAN5G(104, 0),
  831. CHAN5G(108, 0), CHAN5G(112, 0),
  832. CHAN5G(116, 0), CHAN5G(120, 0),
  833. CHAN5G(124, 0), CHAN5G(128, 0),
  834. CHAN5G(132, 0), CHAN5G(136, 0),
  835. CHAN5G(140, 0), CHAN5G(149, 0),
  836. CHAN5G(153, 0), CHAN5G(157, 0),
  837. CHAN5G(161, 0), CHAN5G(165, 0),
  838. CHAN5G(169, 0), CHAN5G(173, 0),
  839. CHAN5G(184, 0), CHAN5G(188, 0),
  840. CHAN5G(192, 0), CHAN5G(196, 0),
  841. CHAN5G(200, 0), CHAN5G(204, 0),
  842. CHAN5G(208, 0), CHAN5G(212, 0),
  843. CHAN5G(216, 0),
  844. };
  845. #define RATETAB_ENT(_rate, _rateid, _flags) \
  846. { \
  847. .bitrate = (_rate), \
  848. .hw_value = (_rateid), \
  849. .flags = (_flags), \
  850. }
  851. /* for cfg80211 - rate table */
  852. static struct ieee80211_rate mtk_rates[] = {
  853. RATETAB_ENT(10, 0x1000, 0),
  854. RATETAB_ENT(20, 0x1001, 0),
  855. RATETAB_ENT(55, 0x1002, 0),
  856. RATETAB_ENT(110, 0x1003, 0), /* 802.11b */
  857. RATETAB_ENT(60, 0x2000, 0),
  858. RATETAB_ENT(90, 0x2001, 0),
  859. RATETAB_ENT(120, 0x2002, 0),
  860. RATETAB_ENT(180, 0x2003, 0),
  861. RATETAB_ENT(240, 0x2004, 0),
  862. RATETAB_ENT(360, 0x2005, 0),
  863. RATETAB_ENT(480, 0x2006, 0),
  864. RATETAB_ENT(540, 0x2007, 0), /* 802.11a/g */
  865. };
  866. #define mtk_a_rates (mtk_rates + 4)
  867. #define mtk_a_rates_size (sizeof(mtk_rates) / sizeof(mtk_rates[0]) - 4)
  868. #define mtk_g_rates (mtk_rates + 0)
  869. #define mtk_g_rates_size (sizeof(mtk_rates) / sizeof(mtk_rates[0]) - 0)
  870. #define WLAN_MCS_INFO \
  871. { \
  872. .rx_mask = {0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0},\
  873. .rx_highest = 0, \
  874. .tx_params = IEEE80211_HT_MCS_TX_DEFINED, \
  875. }
  876. #define WLAN_HT_CAP \
  877. { \
  878. .ht_supported = true, \
  879. .cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 \
  880. | IEEE80211_HT_CAP_SM_PS \
  881. | IEEE80211_HT_CAP_GRN_FLD \
  882. | IEEE80211_HT_CAP_SGI_20 \
  883. | IEEE80211_HT_CAP_SGI_40, \
  884. .ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K, \
  885. .ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE, \
  886. .mcs = WLAN_MCS_INFO, \
  887. }
  888. /**********************************************************
  889. * Public for both legacy Wi-Fi and P2P to access
  890. **********************************************************/
  891. struct ieee80211_supported_band mtk_band_2ghz = {
  892. .band = IEEE80211_BAND_2GHZ,
  893. .channels = mtk_2ghz_channels,
  894. .n_channels = ARRAY_SIZE(mtk_2ghz_channels),
  895. .bitrates = mtk_g_rates,
  896. .n_bitrates = mtk_g_rates_size,
  897. .ht_cap = WLAN_HT_CAP,
  898. };
  899. /* public for both Legacy Wi-Fi / P2P access */
  900. struct ieee80211_supported_band mtk_band_5ghz = {
  901. .band = IEEE80211_BAND_5GHZ,
  902. .channels = mtk_5ghz_channels,
  903. .n_channels = ARRAY_SIZE(mtk_5ghz_channels),
  904. .bitrates = mtk_a_rates,
  905. .n_bitrates = mtk_a_rates_size,
  906. .ht_cap = WLAN_HT_CAP,
  907. };
  908. const UINT_32 mtk_cipher_suites[5] = {
  909. /* keep WEP first, it may be removed below */
  910. WLAN_CIPHER_SUITE_WEP40,
  911. WLAN_CIPHER_SUITE_WEP104,
  912. WLAN_CIPHER_SUITE_TKIP,
  913. WLAN_CIPHER_SUITE_CCMP,
  914. /* keep last -- depends on hw flags! */
  915. WLAN_CIPHER_SUITE_AES_CMAC
  916. };
  917. /*********************************************************/
  918. #define NIC_INF_NAME "wlan%d" /* interface name */
  919. #if CFG_SUPPORT_SNIFFER
  920. #define NIC_MONITOR_INF_NAME "radiotap%d"
  921. #endif
  922. UINT_8 aucDebugModule[DBG_MODULE_NUM];
  923. UINT_32 u4DebugModule = 0;
  924. /* 4 2007/06/26, mikewu, now we don't use this, we just fix the number of wlan device to 1 */
  925. static WLANDEV_INFO_T arWlanDevInfo[CFG_MAX_WLAN_DEVICES] = { {0} };
  926. static UINT_32 u4WlanDevNum; /* How many NICs coexist now */
  927. /**20150205 added work queue for sched_scan to avoid cfg80211 stop schedule scan dead loack**/
  928. struct delayed_work sched_workq;
  929. /*******************************************************************************
  930. * P R I V A T E D A T A
  931. ********************************************************************************
  932. */
  933. static struct cfg80211_ops mtk_wlan_ops = {
  934. .change_virtual_intf = mtk_cfg80211_change_iface,
  935. .add_key = mtk_cfg80211_add_key,
  936. .get_key = mtk_cfg80211_get_key,
  937. .del_key = mtk_cfg80211_del_key,
  938. .set_default_key = mtk_cfg80211_set_default_key,
  939. .get_station = mtk_cfg80211_get_station,
  940. #if CFG_SUPPORT_TDLS
  941. .change_station = mtk_cfg80211_change_station,
  942. .add_station = mtk_cfg80211_add_station,
  943. .del_station = mtk_cfg80211_del_station,
  944. #endif
  945. .scan = mtk_cfg80211_scan,
  946. .connect = mtk_cfg80211_connect,
  947. .disconnect = mtk_cfg80211_disconnect,
  948. .join_ibss = mtk_cfg80211_join_ibss,
  949. .leave_ibss = mtk_cfg80211_leave_ibss,
  950. .set_power_mgmt = mtk_cfg80211_set_power_mgmt,
  951. .set_pmksa = mtk_cfg80211_set_pmksa,
  952. .del_pmksa = mtk_cfg80211_del_pmksa,
  953. .flush_pmksa = mtk_cfg80211_flush_pmksa,
  954. #ifdef CONFIG_SUPPORT_GTK_REKEY
  955. .set_rekey_data = mtk_cfg80211_set_rekey_data,
  956. #endif
  957. .assoc = mtk_cfg80211_assoc,
  958. /* Action Frame TX/RX */
  959. .remain_on_channel = mtk_cfg80211_remain_on_channel,
  960. .cancel_remain_on_channel = mtk_cfg80211_cancel_remain_on_channel,
  961. .mgmt_tx = mtk_cfg80211_mgmt_tx,
  962. /* .mgmt_tx_cancel_wait = mtk_cfg80211_mgmt_tx_cancel_wait, */
  963. .mgmt_frame_register = mtk_cfg80211_mgmt_frame_register,
  964. #ifdef CONFIG_NL80211_TESTMODE
  965. .testmode_cmd = mtk_cfg80211_testmode_cmd,
  966. #endif
  967. #if 0 /* Remove schedule_scan because we need more verification for NLO */
  968. .sched_scan_start = mtk_cfg80211_sched_scan_start,
  969. .sched_scan_stop = mtk_cfg80211_sched_scan_stop,
  970. #endif
  971. #if CFG_SUPPORT_TDLS
  972. .tdls_oper = mtk_cfg80211_tdls_oper,
  973. .tdls_mgmt = mtk_cfg80211_tdls_mgmt,
  974. #endif
  975. };
  976. static const struct wiphy_vendor_command mtk_wlan_vendor_ops[] = {
  977. {
  978. {
  979. .vendor_id = GOOGLE_OUI,
  980. .subcmd = WIFI_SUBCMD_GET_CHANNEL_LIST
  981. },
  982. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  983. .doit = mtk_cfg80211_vendor_get_channel_list
  984. },
  985. {
  986. {
  987. .vendor_id = GOOGLE_OUI,
  988. .subcmd = WIFI_SUBCMD_SET_COUNTRY_CODE
  989. },
  990. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  991. .doit = mtk_cfg80211_vendor_set_country_code
  992. },
  993. /* GSCAN */
  994. {
  995. {
  996. .vendor_id = GOOGLE_OUI,
  997. .subcmd = GSCAN_SUBCMD_GET_CAPABILITIES
  998. },
  999. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1000. .doit = mtk_cfg80211_vendor_get_capabilities
  1001. },
  1002. {
  1003. {
  1004. .vendor_id = GOOGLE_OUI,
  1005. .subcmd = GSCAN_SUBCMD_SET_CONFIG
  1006. },
  1007. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1008. .doit = mtk_cfg80211_vendor_set_config
  1009. },
  1010. {
  1011. {
  1012. .vendor_id = GOOGLE_OUI,
  1013. .subcmd = GSCAN_SUBCMD_SET_SCAN_CONFIG
  1014. },
  1015. .flags = WIPHY_VENDOR_CMD_NEED_WDEV,
  1016. .doit = mtk_cfg80211_vendor_set_scan_config
  1017. },
  1018. {
  1019. {
  1020. .vendor_id = GOOGLE_OUI,
  1021. .subcmd = GSCAN_SUBCMD_ENABLE_GSCAN
  1022. },
  1023. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1024. .doit = mtk_cfg80211_vendor_enable_scan
  1025. },
  1026. {
  1027. {
  1028. .vendor_id = GOOGLE_OUI,
  1029. .subcmd = GSCAN_SUBCMD_ENABLE_FULL_SCAN_RESULTS
  1030. },
  1031. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1032. .doit = mtk_cfg80211_vendor_enable_full_scan_results
  1033. },
  1034. {
  1035. {
  1036. .vendor_id = GOOGLE_OUI,
  1037. .subcmd = GSCAN_SUBCMD_GET_SCAN_RESULTS
  1038. },
  1039. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1040. .doit = mtk_cfg80211_vendor_get_scan_results
  1041. },
  1042. {
  1043. {
  1044. .vendor_id = GOOGLE_OUI,
  1045. .subcmd = GSCAN_SUBCMD_SET_SIGNIFICANT_CHANGE_CONFIG
  1046. },
  1047. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1048. .doit = mtk_cfg80211_vendor_set_significant_change
  1049. },
  1050. {
  1051. {
  1052. .vendor_id = GOOGLE_OUI,
  1053. .subcmd = GSCAN_SUBCMD_SET_HOTLIST
  1054. },
  1055. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1056. .doit = mtk_cfg80211_vendor_set_hotlist
  1057. },
  1058. /*Link Layer Statistics */
  1059. /*{
  1060. {
  1061. .vendor_id = GOOGLE_OUI,
  1062. .subcmd = LSTATS_SUBCMD_GET_INFO
  1063. },
  1064. .flags = WIPHY_VENDOR_CMD_NEED_WDEV | WIPHY_VENDOR_CMD_NEED_NETDEV,
  1065. .doit = NULL; //mtk_cfg80211_vendor_llstats_get_info
  1066. }, */
  1067. };
  1068. static const struct nl80211_vendor_cmd_info mtk_wlan_vendor_events[] = {
  1069. {
  1070. .vendor_id = GOOGLE_OUI,
  1071. .subcmd = GSCAN_EVENT_SIGNIFICANT_CHANGE_RESULTS
  1072. },
  1073. {
  1074. .vendor_id = GOOGLE_OUI,
  1075. .subcmd = GSCAN_EVENT_HOTLIST_RESULTS_FOUND
  1076. },
  1077. {
  1078. .vendor_id = GOOGLE_OUI,
  1079. .subcmd = GSCAN_EVENT_SCAN_RESULTS_AVAILABLE
  1080. },
  1081. {
  1082. .vendor_id = GOOGLE_OUI,
  1083. .subcmd = GSCAN_EVENT_FULL_SCAN_RESULTS
  1084. },
  1085. {
  1086. .vendor_id = GOOGLE_OUI,
  1087. .subcmd = RTT_EVENT_COMPLETE
  1088. },
  1089. {
  1090. .vendor_id = GOOGLE_OUI,
  1091. .subcmd = GSCAN_EVENT_COMPLETE_SCAN
  1092. },
  1093. {
  1094. .vendor_id = GOOGLE_OUI,
  1095. .subcmd = GSCAN_EVENT_HOTLIST_RESULTS_LOST
  1096. },
  1097. };
  1098. /* There isn't a lot of sense in it, but you can transmit anything you like */
  1099. static const struct ieee80211_txrx_stypes
  1100. mtk_cfg80211_ais_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  1101. [NL80211_IFTYPE_ADHOC] = {
  1102. .tx = 0xffff,
  1103. .rx = BIT(IEEE80211_STYPE_ACTION >> 4)
  1104. },
  1105. [NL80211_IFTYPE_STATION] = {
  1106. .tx = 0xffff,
  1107. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1108. },
  1109. [NL80211_IFTYPE_AP] = {
  1110. .tx = 0xffff,
  1111. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  1112. },
  1113. [NL80211_IFTYPE_AP_VLAN] = {
  1114. /* copy AP */
  1115. .tx = 0xffff,
  1116. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  1117. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  1118. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  1119. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  1120. BIT(IEEE80211_STYPE_AUTH >> 4) |
  1121. BIT(IEEE80211_STYPE_DEAUTH >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  1122. },
  1123. [NL80211_IFTYPE_P2P_CLIENT] = {
  1124. .tx = 0xffff,
  1125. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) | BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  1126. },
  1127. [NL80211_IFTYPE_P2P_GO] = {
  1128. .tx = 0xffff,
  1129. .rx = BIT(IEEE80211_STYPE_PROBE_REQ >> 4) | BIT(IEEE80211_STYPE_ACTION >> 4)
  1130. }
  1131. };
  1132. #ifdef CONFIG_PM
  1133. static const struct wiphy_wowlan_support mtk_wlan_wowlan_support = {
  1134. .flags = WIPHY_WOWLAN_DISCONNECT | WIPHY_WOWLAN_ANY,
  1135. };
  1136. #endif
  1137. /*******************************************************************************
  1138. * M A C R O S
  1139. ********************************************************************************
  1140. */
  1141. /*******************************************************************************
  1142. * F U N C T I O N D E C L A R A T I O N S
  1143. ********************************************************************************
  1144. */
  1145. /*******************************************************************************
  1146. * F U N C T I O N S
  1147. ********************************************************************************
  1148. */
  1149. #if 0
  1150. /*----------------------------------------------------------------------------*/
  1151. /*!
  1152. * \brief Override the implementation of select queue
  1153. *
  1154. * \param[in] dev Pointer to struct net_device
  1155. * \param[in] skb Pointer to struct skb_buff
  1156. *
  1157. * \return (none)
  1158. */
  1159. /*----------------------------------------------------------------------------*/
  1160. unsigned int _cfg80211_classify8021d(struct sk_buff *skb)
  1161. {
  1162. unsigned int dscp = 0;
  1163. /* skb->priority values from 256->263 are magic values
  1164. * directly indicate a specific 802.1d priority. This is
  1165. * to allow 802.1d priority to be passed directly in from
  1166. * tags
  1167. */
  1168. if (skb->priority >= 256 && skb->priority <= 263)
  1169. return skb->priority - 256;
  1170. switch (skb->protocol) {
  1171. case htons(ETH_P_IP):
  1172. dscp = ip_hdr(skb)->tos & 0xfc;
  1173. break;
  1174. }
  1175. return dscp >> 5;
  1176. }
  1177. #endif
  1178. UINT_16 wlanSelectQueue(struct net_device *dev, struct sk_buff *skb,
  1179. void *accel_priv, select_queue_fallback_t fallback)
  1180. {
  1181. UINT_16 au16Wlan1dToQueueIdx[8] = { 1, 0, 0, 1, 2, 2, 3, 3 };
  1182. /* Use Linux wireless utility function */
  1183. skb->priority = cfg80211_classify8021d(skb, NULL);
  1184. return au16Wlan1dToQueueIdx[skb->priority];
  1185. }
  1186. /*----------------------------------------------------------------------------*/
  1187. /*!
  1188. * \brief Load NVRAM data and translate it into REG_INFO_T
  1189. *
  1190. * \param[in] prGlueInfo Pointer to struct GLUE_INFO_T
  1191. * \param[out] prRegInfo Pointer to struct REG_INFO_T
  1192. *
  1193. * \return (none)
  1194. */
  1195. /*----------------------------------------------------------------------------*/
  1196. static void glLoadNvram(IN P_GLUE_INFO_T prGlueInfo, OUT P_REG_INFO_T prRegInfo)
  1197. {
  1198. UINT_32 i, j;
  1199. UINT_8 aucTmp[2];
  1200. PUINT_8 pucDest;
  1201. ASSERT(prGlueInfo);
  1202. ASSERT(prRegInfo);
  1203. if ((!prGlueInfo) || (!prRegInfo))
  1204. return;
  1205. if (kalCfgDataRead16(prGlueInfo, sizeof(WIFI_CFG_PARAM_STRUCT) - sizeof(UINT_16), (PUINT_16) aucTmp) == TRUE) {
  1206. prGlueInfo->fgNvramAvailable = TRUE;
  1207. /* load MAC Address */
  1208. for (i = 0; i < PARAM_MAC_ADDR_LEN; i += sizeof(UINT_16)) {
  1209. kalCfgDataRead16(prGlueInfo,
  1210. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, aucMacAddress) + i,
  1211. (PUINT_16) (((PUINT_8) prRegInfo->aucMacAddr) + i));
  1212. }
  1213. /* load country code */
  1214. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, aucCountryCode[0]), (PUINT_16) aucTmp);
  1215. /* cast to wide characters */
  1216. prRegInfo->au2CountryCode[0] = (UINT_16) aucTmp[0];
  1217. prRegInfo->au2CountryCode[1] = (UINT_16) aucTmp[1];
  1218. /* load default normal TX power */
  1219. for (i = 0; i < sizeof(TX_PWR_PARAM_T); i += sizeof(UINT_16)) {
  1220. kalCfgDataRead16(prGlueInfo,
  1221. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, rTxPwr) + i,
  1222. (PUINT_16) (((PUINT_8) &(prRegInfo->rTxPwr)) + i));
  1223. }
  1224. /* load feature flags */
  1225. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, ucTxPwrValid), (PUINT_16) aucTmp);
  1226. prRegInfo->ucTxPwrValid = aucTmp[0];
  1227. prRegInfo->ucSupport5GBand = aucTmp[1];
  1228. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, uc2G4BwFixed20M), (PUINT_16) aucTmp);
  1229. prRegInfo->uc2G4BwFixed20M = aucTmp[0];
  1230. prRegInfo->uc5GBwFixed20M = aucTmp[1];
  1231. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, ucEnable5GBand), (PUINT_16) aucTmp);
  1232. prRegInfo->ucEnable5GBand = aucTmp[0];
  1233. prRegInfo->ucRxDiversity = aucTmp[1];
  1234. kalCfgDataRead16(prGlueInfo,
  1235. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, fgRssiCompensationVaildbit), (PUINT_16) aucTmp);
  1236. prRegInfo->ucRssiPathCompasationUsed = aucTmp[0];
  1237. prRegInfo->ucGpsDesense = aucTmp[1];
  1238. #if CFG_SUPPORT_NVRAM_5G
  1239. /* load EFUSE overriding part */
  1240. for (i = 0; i < sizeof(prRegInfo->aucEFUSE); i += sizeof(UINT_16)) {
  1241. kalCfgDataRead16(prGlueInfo,
  1242. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, EfuseMapping) + i,
  1243. (PUINT_16) (((PUINT_8) &(prRegInfo->aucEFUSE)) + i));
  1244. }
  1245. prRegInfo->prOldEfuseMapping = (P_NEW_EFUSE_MAPPING2NVRAM_T)&prRegInfo->aucEFUSE;
  1246. #else
  1247. /* load EFUSE overriding part */
  1248. for (i = 0; i < sizeof(prRegInfo->aucEFUSE); i += sizeof(UINT_16)) {
  1249. kalCfgDataRead16(prGlueInfo,
  1250. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, aucEFUSE) + i,
  1251. (PUINT_16) (((PUINT_8) &(prRegInfo->aucEFUSE)) + i));
  1252. }
  1253. #endif
  1254. /* load band edge tx power control */
  1255. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, fg2G4BandEdgePwrUsed), (PUINT_16) aucTmp);
  1256. prRegInfo->fg2G4BandEdgePwrUsed = (BOOLEAN) aucTmp[0];
  1257. if (aucTmp[0]) {
  1258. prRegInfo->cBandEdgeMaxPwrCCK = (INT_8) aucTmp[1];
  1259. kalCfgDataRead16(prGlueInfo,
  1260. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, cBandEdgeMaxPwrOFDM20), (PUINT_16) aucTmp);
  1261. prRegInfo->cBandEdgeMaxPwrOFDM20 = (INT_8) aucTmp[0];
  1262. prRegInfo->cBandEdgeMaxPwrOFDM40 = (INT_8) aucTmp[1];
  1263. }
  1264. /* load regulation subbands */
  1265. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, ucRegChannelListMap), (PUINT_16) aucTmp);
  1266. prRegInfo->eRegChannelListMap = (ENUM_REG_CH_MAP_T) aucTmp[0];
  1267. prRegInfo->ucRegChannelListIndex = aucTmp[1];
  1268. if (prRegInfo->eRegChannelListMap == REG_CH_MAP_CUSTOMIZED) {
  1269. for (i = 0; i < MAX_SUBBAND_NUM; i++) {
  1270. pucDest = (PUINT_8) &prRegInfo->rDomainInfo.rSubBand[i];
  1271. for (j = 0; j < 6; j += sizeof(UINT_16)) {
  1272. kalCfgDataRead16(prGlueInfo, OFFSET_OF(WIFI_CFG_PARAM_STRUCT, aucRegSubbandInfo)
  1273. + (i * 6 + j), (PUINT_16) aucTmp);
  1274. *pucDest++ = aucTmp[0];
  1275. *pucDest++ = aucTmp[1];
  1276. }
  1277. }
  1278. }
  1279. /* load rssiPathCompensation */
  1280. for (i = 0; i < sizeof(RSSI_PATH_COMPASATION_T); i += sizeof(UINT_16)) {
  1281. kalCfgDataRead16(prGlueInfo,
  1282. OFFSET_OF(WIFI_CFG_PARAM_STRUCT,
  1283. rRssiPathCompensation) + i,
  1284. (PUINT_16) (((PUINT_8) &(prRegInfo->rRssiPathCompasation))
  1285. + i));
  1286. }
  1287. #if 1
  1288. /* load full NVRAM */
  1289. for (i = 0; i < sizeof(WIFI_CFG_PARAM_STRUCT); i += sizeof(UINT_16)) {
  1290. kalCfgDataRead16(prGlueInfo,
  1291. OFFSET_OF(WIFI_CFG_PARAM_STRUCT, u2Part1OwnVersion) + i,
  1292. (PUINT_16) (((PUINT_8) &(prRegInfo->aucNvram)) + i));
  1293. }
  1294. prRegInfo->prNvramSettings = (P_WIFI_CFG_PARAM_STRUCT)&prRegInfo->aucNvram;
  1295. #endif
  1296. } else {
  1297. DBGLOG(INIT, INFO, "glLoadNvram fail\n");
  1298. prGlueInfo->fgNvramAvailable = FALSE;
  1299. }
  1300. }
  1301. /*----------------------------------------------------------------------------*/
  1302. /*!
  1303. * \brief Release prDev from wlandev_array and free tasklet object related to it.
  1304. *
  1305. * \param[in] prDev Pointer to struct net_device
  1306. *
  1307. * \return (none)
  1308. */
  1309. /*----------------------------------------------------------------------------*/
  1310. static void wlanClearDevIdx(struct net_device *prDev)
  1311. {
  1312. int i;
  1313. ASSERT(prDev);
  1314. for (i = 0; i < CFG_MAX_WLAN_DEVICES; i++) {
  1315. if (arWlanDevInfo[i].prDev == prDev) {
  1316. arWlanDevInfo[i].prDev = NULL;
  1317. u4WlanDevNum--;
  1318. }
  1319. }
  1320. } /* end of wlanClearDevIdx() */
  1321. /*----------------------------------------------------------------------------*/
  1322. /*!
  1323. * \brief Allocate an unique interface index, net_device::ifindex member for this
  1324. * wlan device. Store the net_device in wlandev_array, and initialize
  1325. * tasklet object related to it.
  1326. *
  1327. * \param[in] prDev Pointer to struct net_device
  1328. *
  1329. * \retval >= 0 The device number.
  1330. * \retval -1 Fail to get index.
  1331. */
  1332. /*----------------------------------------------------------------------------*/
  1333. static int wlanGetDevIdx(struct net_device *prDev)
  1334. {
  1335. int i;
  1336. ASSERT(prDev);
  1337. for (i = 0; i < CFG_MAX_WLAN_DEVICES; i++) {
  1338. if (arWlanDevInfo[i].prDev == (struct net_device *)NULL) {
  1339. /* Reserve 2 bytes space to store one digit of
  1340. * device number and NULL terminator.
  1341. */
  1342. arWlanDevInfo[i].prDev = prDev;
  1343. u4WlanDevNum++;
  1344. return i;
  1345. }
  1346. }
  1347. return -1;
  1348. } /* end of wlanGetDevIdx() */
  1349. /*----------------------------------------------------------------------------*/
  1350. /*!
  1351. * \brief A method of struct net_device, a primary SOCKET interface to configure
  1352. * the interface lively. Handle an ioctl call on one of our devices.
  1353. * Everything Linux ioctl specific is done here. Then we pass the contents
  1354. * of the ifr->data to the request message handler.
  1355. *
  1356. * \param[in] prDev Linux kernel netdevice
  1357. *
  1358. * \param[in] prIfReq Our private ioctl request structure, typed for the generic
  1359. * struct ifreq so we can use ptr to function
  1360. *
  1361. * \param[in] cmd Command ID
  1362. *
  1363. * \retval 0 The IOCTL command is executed successfully.
  1364. * \retval <0 The execution of IOCTL command is failed.
  1365. */
  1366. /*----------------------------------------------------------------------------*/
  1367. int wlanDoIOCTL(struct net_device *prDev, struct ifreq *prIfReq, int i4Cmd)
  1368. {
  1369. P_GLUE_INFO_T prGlueInfo = NULL;
  1370. int ret = 0;
  1371. /* Verify input parameters for the following functions */
  1372. ASSERT(prDev && prIfReq);
  1373. if (!prDev || !prIfReq) {
  1374. DBGLOG(INIT, ERROR, "Invalid input data\n");
  1375. return -EINVAL;
  1376. }
  1377. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1378. if (!prGlueInfo) {
  1379. DBGLOG(INIT, ERROR, "prGlueInfo is NULL\n");
  1380. return -EFAULT;
  1381. }
  1382. if (prGlueInfo->u4ReadyFlag == 0) {
  1383. DBGLOG(INIT, ERROR, "Adapter is not ready\n");
  1384. return -EINVAL;
  1385. }
  1386. if ((i4Cmd >= SIOCIWFIRST) && (i4Cmd < SIOCIWFIRSTPRIV)) {
  1387. /* 0x8B00 ~ 0x8BDF, wireless extension region */
  1388. ret = wext_support_ioctl(prDev, prIfReq, i4Cmd);
  1389. } else if ((i4Cmd >= SIOCIWFIRSTPRIV) && (i4Cmd < SIOCIWLASTPRIV)) {
  1390. /* 0x8BE0 ~ 0x8BFF, private ioctl region */
  1391. ret = priv_support_ioctl(prDev, prIfReq, i4Cmd);
  1392. } else if (i4Cmd == SIOCDEVPRIVATE + 1) {
  1393. ret = priv_support_driver_cmd(prDev, prIfReq, i4Cmd);
  1394. } else {
  1395. DBGLOG(INIT, WARN, "Unexpected ioctl command: 0x%04x\n", i4Cmd);
  1396. ret = -EOPNOTSUPP;
  1397. }
  1398. return ret;
  1399. } /* end of wlanDoIOCTL() */
  1400. /*----------------------------------------------------------------------------*/
  1401. /*!
  1402. * \brief Export wlan GLUE_INFO_T pointer to p2p module
  1403. *
  1404. * \param[in] prGlueInfo Pointer to struct GLUE_INFO_T
  1405. *
  1406. * \return TRUE: get GlueInfo pointer successfully
  1407. * FALSE: wlan is not started yet
  1408. */
  1409. /*---------------------------------------------------------------------------*/
  1410. P_GLUE_INFO_T wlanGetGlueInfo(VOID)
  1411. {
  1412. struct net_device *prDev = NULL;
  1413. P_GLUE_INFO_T prGlueInfo = NULL;
  1414. if (0 == u4WlanDevNum)
  1415. return NULL;
  1416. prDev = arWlanDevInfo[u4WlanDevNum - 1].prDev;
  1417. if (NULL == prDev)
  1418. return NULL;
  1419. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1420. return prGlueInfo;
  1421. }
  1422. /*----------------------------------------------------------------------------*/
  1423. /*!
  1424. * \brief This function is to set multicast list and set rx mode.
  1425. *
  1426. * \param[in] prDev Pointer to struct net_device
  1427. *
  1428. * \return (none)
  1429. */
  1430. /*----------------------------------------------------------------------------*/
  1431. static struct delayed_work workq;
  1432. static struct net_device *gPrDev;
  1433. static void wlanSetMulticastList(struct net_device *prDev)
  1434. {
  1435. gPrDev = prDev;
  1436. schedule_delayed_work(&workq, 0);
  1437. }
  1438. /* FIXME: Since we cannot sleep in the wlanSetMulticastList, we arrange
  1439. * another workqueue for sleeping. We don't want to block
  1440. * tx_thread, so we can't let tx_thread to do this */
  1441. static void wlanSetMulticastListWorkQueue(struct work_struct *work)
  1442. {
  1443. P_GLUE_INFO_T prGlueInfo = NULL;
  1444. UINT_32 u4PacketFilter = 0;
  1445. UINT_32 u4SetInfoLen;
  1446. struct net_device *prDev = gPrDev;
  1447. down(&g_halt_sem);
  1448. if (g_u4HaltFlag) {
  1449. up(&g_halt_sem);
  1450. return;
  1451. }
  1452. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1453. ASSERT(prDev);
  1454. ASSERT(prGlueInfo);
  1455. if (!prDev || !prGlueInfo) {
  1456. DBGLOG(INIT, WARN, "abnormal dev or skb: prDev(0x%p), prGlueInfo(0x%p)\n", prDev, prGlueInfo);
  1457. up(&g_halt_sem);
  1458. return;
  1459. }
  1460. if (prDev->flags & IFF_PROMISC)
  1461. u4PacketFilter |= PARAM_PACKET_FILTER_PROMISCUOUS;
  1462. if (prDev->flags & IFF_BROADCAST)
  1463. u4PacketFilter |= PARAM_PACKET_FILTER_BROADCAST;
  1464. if (prDev->flags & IFF_MULTICAST) {
  1465. if ((prDev->flags & IFF_ALLMULTI) || (netdev_mc_count(prDev) > MAX_NUM_GROUP_ADDR))
  1466. u4PacketFilter |= PARAM_PACKET_FILTER_ALL_MULTICAST;
  1467. else
  1468. u4PacketFilter |= PARAM_PACKET_FILTER_MULTICAST;
  1469. }
  1470. up(&g_halt_sem);
  1471. if (kalIoctl(prGlueInfo,
  1472. wlanoidSetCurrentPacketFilter,
  1473. &u4PacketFilter,
  1474. sizeof(u4PacketFilter), FALSE, FALSE, TRUE, &u4SetInfoLen) != WLAN_STATUS_SUCCESS) {
  1475. return;
  1476. }
  1477. if (u4PacketFilter & PARAM_PACKET_FILTER_MULTICAST) {
  1478. /* Prepare multicast address list */
  1479. struct netdev_hw_addr *ha;
  1480. PUINT_8 prMCAddrList = NULL;
  1481. UINT_32 i = 0;
  1482. down(&g_halt_sem);
  1483. if (g_u4HaltFlag) {
  1484. up(&g_halt_sem);
  1485. return;
  1486. }
  1487. prMCAddrList = kalMemAlloc(MAX_NUM_GROUP_ADDR * ETH_ALEN, VIR_MEM_TYPE);
  1488. netdev_for_each_mc_addr(ha, prDev) {
  1489. if (i < MAX_NUM_GROUP_ADDR) {
  1490. memcpy((prMCAddrList + i * ETH_ALEN), ha->addr, ETH_ALEN);
  1491. i++;
  1492. }
  1493. }
  1494. up(&g_halt_sem);
  1495. kalIoctl(prGlueInfo,
  1496. wlanoidSetMulticastList, prMCAddrList, (i * ETH_ALEN), FALSE, FALSE, TRUE, &u4SetInfoLen);
  1497. kalMemFree(prMCAddrList, VIR_MEM_TYPE, MAX_NUM_GROUP_ADDR * ETH_ALEN);
  1498. }
  1499. } /* end of wlanSetMulticastList() */
  1500. /*----------------------------------------------------------------------------*/
  1501. /*!
  1502. * \brief To indicate scheduled scan has been stopped
  1503. *
  1504. * \param[in]
  1505. * prGlueInfo
  1506. *
  1507. * \return
  1508. * None
  1509. */
  1510. /*----------------------------------------------------------------------------*/
  1511. VOID wlanSchedScanStoppedWorkQueue(struct work_struct *work)
  1512. {
  1513. P_GLUE_INFO_T prGlueInfo = NULL;
  1514. struct net_device *prDev = gPrDev;
  1515. DBGLOG(SCN, INFO, "wlanSchedScanStoppedWorkQueue\n");
  1516. prGlueInfo = (NULL != prDev) ? *((P_GLUE_INFO_T *) netdev_priv(prDev)) : NULL;
  1517. if (!prGlueInfo) {
  1518. DBGLOG(SCN, INFO, "prGlueInfo == NULL unexpected\n");
  1519. return;
  1520. }
  1521. /* 2. indication to cfg80211 */
  1522. /* 20150205 change cfg80211_sched_scan_stopped to work queue due to sched_scan_mtx dead lock issue */
  1523. cfg80211_sched_scan_stopped(priv_to_wiphy(prGlueInfo));
  1524. DBGLOG(SCN, INFO,
  1525. "cfg80211_sched_scan_stopped event send done WorkQueue thread return from wlanSchedScanStoppedWorkQueue\n");
  1526. return;
  1527. }
  1528. /*----------------------------------------------------------------------------*/
  1529. /*
  1530. * \brief This function is TX entry point of NET DEVICE.
  1531. *
  1532. * \param[in] prSkb Pointer of the sk_buff to be sent
  1533. * \param[in] prDev Pointer to struct net_device
  1534. *
  1535. * \retval NETDEV_TX_OK - on success.
  1536. * \retval NETDEV_TX_BUSY - on failure, packet will be discarded by upper layer.
  1537. */
  1538. /*----------------------------------------------------------------------------*/
  1539. int wlanHardStartXmit(struct sk_buff *prSkb, struct net_device *prDev)
  1540. {
  1541. P_NETDEV_PRIVATE_GLUE_INFO prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) NULL;
  1542. P_GLUE_INFO_T prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1543. UINT_8 ucBssIndex;
  1544. ASSERT(prSkb);
  1545. ASSERT(prDev);
  1546. ASSERT(prGlueInfo);
  1547. prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prDev);
  1548. ASSERT(prNetDevPrivate->prGlueInfo == prGlueInfo);
  1549. ucBssIndex = prNetDevPrivate->ucBssIdx;
  1550. #if CFG_SUPPORT_PASSPOINT
  1551. if (prGlueInfo->fgIsDad) {
  1552. /* kalPrint("[Passpoint R2] Due to ipv4_dad...TX is forbidden\n"); */
  1553. dev_kfree_skb(prSkb);
  1554. return NETDEV_TX_OK;
  1555. }
  1556. if (prGlueInfo->fgIs6Dad) {
  1557. /* kalPrint("[Passpoint R2] Due to ipv6_dad...TX is forbidden\n"); */
  1558. dev_kfree_skb(prSkb);
  1559. return NETDEV_TX_OK;
  1560. }
  1561. #endif /* CFG_SUPPORT_PASSPOINT */
  1562. kalResetPacket(prGlueInfo, (P_NATIVE_PACKET) prSkb);
  1563. if (kalHardStartXmit(prSkb, prDev, prGlueInfo, ucBssIndex) == WLAN_STATUS_SUCCESS) {
  1564. /* Successfully enqueue to Tx queue */
  1565. /* Successfully enqueue to Tx queue */
  1566. }
  1567. /* For Linux, we'll always return OK FLAG, because we'll free this skb by ourself */
  1568. return NETDEV_TX_OK;
  1569. } /* end of wlanHardStartXmit() */
  1570. /*----------------------------------------------------------------------------*/
  1571. /*!
  1572. * \brief A method of struct net_device, to get the network interface statistical
  1573. * information.
  1574. *
  1575. * Whenever an application needs to get statistics for the interface, this method
  1576. * is called. This happens, for example, when ifconfig or netstat -i is run.
  1577. *
  1578. * \param[in] prDev Pointer to struct net_device.
  1579. *
  1580. * \return net_device_stats buffer pointer.
  1581. */
  1582. /*----------------------------------------------------------------------------*/
  1583. struct net_device_stats *wlanGetStats(IN struct net_device *prDev)
  1584. {
  1585. return (struct net_device_stats *)kalGetStats(prDev);
  1586. } /* end of wlanGetStats() */
  1587. VOID wlanDebugInit(VOID)
  1588. {
  1589. UINT_8 i;
  1590. /* Set the initial DEBUG CLASS of each module */
  1591. #if DBG
  1592. for (i = 0; i < DBG_MODULE_NUM; i++)
  1593. aucDebugModule[i] = DBG_CLASS_MASK; /* enable all */
  1594. #else
  1595. /* Initial debug level is D1 */
  1596. for (i = 0; i < DBG_MODULE_NUM; i++) {
  1597. aucDebugModule[i] = DBG_CLASS_ERROR |
  1598. DBG_CLASS_WARN | DBG_CLASS_STATE | DBG_CLASS_EVENT | DBG_CLASS_INFO;
  1599. }
  1600. aucDebugModule[DBG_INTR_IDX] = 0;
  1601. #endif /* DBG */
  1602. LOG_FUNC("Reset ALL DBG module log level to DEFAULT!");
  1603. }
  1604. WLAN_STATUS wlanSetDebugLevel(IN UINT_32 u4DbgIdx, IN UINT_32 u4DbgMask)
  1605. {
  1606. UINT_32 u4Idx;
  1607. WLAN_STATUS fgStatus = WLAN_STATUS_SUCCESS;
  1608. if (u4DbgIdx == DBG_ALL_MODULE_IDX) {
  1609. for (u4Idx = 0; u4Idx < DBG_MODULE_NUM; u4Idx++)
  1610. aucDebugModule[u4Idx] = (UINT_8) u4DbgMask;
  1611. LOG_FUNC("Set ALL DBG module log level to [0x%02x]\n", u4DbgMask);
  1612. } else if (u4DbgIdx < DBG_MODULE_NUM) {
  1613. aucDebugModule[u4DbgIdx] = (UINT_8) u4DbgMask;
  1614. LOG_FUNC("Set DBG module[%u] log level to [0x%02x]\n", u4DbgIdx, u4DbgMask);
  1615. } else {
  1616. fgStatus = WLAN_STATUS_FAILURE;
  1617. }
  1618. return fgStatus;
  1619. }
  1620. WLAN_STATUS wlanGetDebugLevel(IN UINT_32 u4DbgIdx, OUT PUINT_32 pu4DbgMask)
  1621. {
  1622. if (u4DbgIdx < DBG_MODULE_NUM) {
  1623. *pu4DbgMask = aucDebugModule[u4DbgIdx];
  1624. return WLAN_STATUS_SUCCESS;
  1625. }
  1626. return WLAN_STATUS_FAILURE;
  1627. }
  1628. /*----------------------------------------------------------------------------*/
  1629. /*!
  1630. * \brief A function for prDev->init
  1631. *
  1632. * \param[in] prDev Pointer to struct net_device.
  1633. *
  1634. * \retval 0 The execution of wlanInit succeeds.
  1635. * \retval -ENXIO No such device.
  1636. */
  1637. /*----------------------------------------------------------------------------*/
  1638. static int wlanInit(struct net_device *prDev)
  1639. {
  1640. P_GLUE_INFO_T prGlueInfo = NULL;
  1641. if (!prDev)
  1642. return -ENXIO;
  1643. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1644. INIT_DELAYED_WORK(&workq, wlanSetMulticastListWorkQueue);
  1645. /* 20150205 work queue for sched_scan */
  1646. INIT_DELAYED_WORK(&sched_workq, wlanSchedScanStoppedWorkQueue);
  1647. return 0; /* success */
  1648. } /* end of wlanInit() */
  1649. /*----------------------------------------------------------------------------*/
  1650. /*!
  1651. * \brief A function for prDev->uninit
  1652. *
  1653. * \param[in] prDev Pointer to struct net_device.
  1654. *
  1655. * \return (none)
  1656. */
  1657. /*----------------------------------------------------------------------------*/
  1658. static void wlanUninit(struct net_device *prDev)
  1659. {
  1660. } /* end of wlanUninit() */
  1661. /*----------------------------------------------------------------------------*/
  1662. /*!
  1663. * \brief A function for prDev->open
  1664. *
  1665. * \param[in] prDev Pointer to struct net_device.
  1666. *
  1667. * \retval 0 The execution of wlanOpen succeeds.
  1668. * \retval < 0 The execution of wlanOpen failed.
  1669. */
  1670. /*----------------------------------------------------------------------------*/
  1671. static int wlanOpen(struct net_device *prDev)
  1672. {
  1673. ASSERT(prDev);
  1674. netif_tx_start_all_queues(prDev);
  1675. return 0; /* success */
  1676. } /* end of wlanOpen() */
  1677. /*----------------------------------------------------------------------------*/
  1678. /*!
  1679. * \brief A function for prDev->stop
  1680. *
  1681. * \param[in] prDev Pointer to struct net_device.
  1682. *
  1683. * \retval 0 The execution of wlanStop succeeds.
  1684. * \retval < 0 The execution of wlanStop failed.
  1685. */
  1686. /*----------------------------------------------------------------------------*/
  1687. static int wlanStop(struct net_device *prDev)
  1688. {
  1689. P_GLUE_INFO_T prGlueInfo = NULL;
  1690. struct cfg80211_scan_request *prScanRequest = NULL;
  1691. GLUE_SPIN_LOCK_DECLARATION();
  1692. ASSERT(prDev);
  1693. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  1694. /* CFG80211 down */
  1695. GLUE_ACQUIRE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1696. if (prGlueInfo->prScanRequest != NULL) {
  1697. prScanRequest = prGlueInfo->prScanRequest;
  1698. prGlueInfo->prScanRequest = NULL;
  1699. }
  1700. GLUE_RELEASE_SPIN_LOCK(prGlueInfo, SPIN_LOCK_NET_DEV);
  1701. if (prScanRequest)
  1702. cfg80211_scan_done(prScanRequest, TRUE);
  1703. netif_tx_stop_all_queues(prDev);
  1704. return 0; /* success */
  1705. } /* end of wlanStop() */
  1706. #if CFG_SUPPORT_SNIFFER
  1707. static int wlanMonOpen(struct net_device *prDev)
  1708. {
  1709. ASSERT(prDev);
  1710. netif_tx_start_all_queues(prDev);
  1711. return 0; /* success */
  1712. }
  1713. static int wlanMonStop(struct net_device *prDev)
  1714. {
  1715. ASSERT(prDev);
  1716. netif_tx_stop_all_queues(prDev);
  1717. return 0; /* success */
  1718. }
  1719. static const struct net_device_ops wlan_mon_netdev_ops = {
  1720. .ndo_open = wlanMonOpen,
  1721. .ndo_stop = wlanMonStop,
  1722. };
  1723. void wlanMonWorkHandler(struct work_struct *work)
  1724. {
  1725. P_GLUE_INFO_T prGlueInfo;
  1726. prGlueInfo = container_of(work, GLUE_INFO_T, monWork);
  1727. if (prGlueInfo->fgIsEnableMon) {
  1728. if (prGlueInfo->prMonDevHandler)
  1729. return;
  1730. prGlueInfo->prMonDevHandler =
  1731. alloc_netdev_mq(sizeof(NETDEV_PRIVATE_GLUE_INFO), NIC_MONITOR_INF_NAME,
  1732. NET_NAME_PREDICTABLE, ether_setup, CFG_MAX_TXQ_NUM);
  1733. if (prGlueInfo->prMonDevHandler == NULL) {
  1734. DBGLOG(INIT, ERROR, "wlanMonWorkHandler: Allocated prMonDevHandler context FAIL.\n");
  1735. return;
  1736. }
  1737. ((P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prGlueInfo->prMonDevHandler))->prGlueInfo = prGlueInfo;
  1738. prGlueInfo->prMonDevHandler->type = ARPHRD_IEEE80211_RADIOTAP;
  1739. prGlueInfo->prMonDevHandler->netdev_ops = &wlan_mon_netdev_ops;
  1740. netif_carrier_off(prGlueInfo->prMonDevHandler);
  1741. netif_tx_stop_all_queues(prGlueInfo->prMonDevHandler);
  1742. kalResetStats(prGlueInfo->prMonDevHandler);
  1743. if (register_netdev(prGlueInfo->prMonDevHandler) < 0) {
  1744. DBGLOG(INIT, ERROR, "wlanMonWorkHandler: Registered prMonDevHandler context FAIL.\n");
  1745. free_netdev(prGlueInfo->prMonDevHandler);
  1746. prGlueInfo->prMonDevHandler = NULL;
  1747. }
  1748. DBGLOG(INIT, INFO, "wlanMonWorkHandler: Registered prMonDevHandler context DONE.\n");
  1749. } else {
  1750. if (prGlueInfo->prMonDevHandler) {
  1751. unregister_netdev(prGlueInfo->prMonDevHandler);
  1752. prGlueInfo->prMonDevHandler = NULL;
  1753. DBGLOG(INIT, INFO, "wlanMonWorkHandler: unRegistered prMonDevHandler context DONE.\n");
  1754. }
  1755. }
  1756. }
  1757. #endif
  1758. /*----------------------------------------------------------------------------*/
  1759. /*!
  1760. * \brief Update channel table for cfg80211 based on current country domain
  1761. *
  1762. * \param[in] prGlueInfo Pointer to glue info
  1763. *
  1764. * \return none
  1765. */
  1766. /*----------------------------------------------------------------------------*/
  1767. VOID wlanUpdateChannelTable(P_GLUE_INFO_T prGlueInfo)
  1768. {
  1769. UINT_8 i, j;
  1770. UINT_8 ucNumOfChannel;
  1771. RF_CHANNEL_INFO_T aucChannelList[ARRAY_SIZE(mtk_2ghz_channels) + ARRAY_SIZE(mtk_5ghz_channels)];
  1772. /* 1. Disable all channels */
  1773. for (i = 0; i < ARRAY_SIZE(mtk_2ghz_channels); i++) {
  1774. mtk_2ghz_channels[i].flags |= IEEE80211_CHAN_DISABLED;
  1775. mtk_2ghz_channels[i].orig_flags |= IEEE80211_CHAN_DISABLED;
  1776. }
  1777. for (i = 0; i < ARRAY_SIZE(mtk_5ghz_channels); i++) {
  1778. mtk_5ghz_channels[i].flags |= IEEE80211_CHAN_DISABLED;
  1779. mtk_5ghz_channels[i].orig_flags |= IEEE80211_CHAN_DISABLED;
  1780. }
  1781. /* 2. Get current domain channel list */
  1782. rlmDomainGetChnlList(prGlueInfo->prAdapter,
  1783. BAND_NULL, FALSE,
  1784. ARRAY_SIZE(mtk_2ghz_channels) + ARRAY_SIZE(mtk_5ghz_channels),
  1785. &ucNumOfChannel, aucChannelList);
  1786. /* 3. Enable specific channel based on domain channel list */
  1787. for (i = 0; i < ucNumOfChannel; i++) {
  1788. switch (aucChannelList[i].eBand) {
  1789. case BAND_2G4:
  1790. for (j = 0; j < ARRAY_SIZE(mtk_2ghz_channels); j++) {
  1791. if (mtk_2ghz_channels[j].hw_value == aucChannelList[i].ucChannelNum) {
  1792. mtk_2ghz_channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
  1793. mtk_2ghz_channels[j].orig_flags &= ~IEEE80211_CHAN_DISABLED;
  1794. break;
  1795. }
  1796. }
  1797. break;
  1798. case BAND_5G:
  1799. for (j = 0; j < ARRAY_SIZE(mtk_5ghz_channels); j++) {
  1800. if (mtk_5ghz_channels[j].hw_value == aucChannelList[i].ucChannelNum) {
  1801. mtk_5ghz_channels[j].flags &= ~IEEE80211_CHAN_DISABLED;
  1802. mtk_5ghz_channels[j].orig_flags &= ~IEEE80211_CHAN_DISABLED;
  1803. break;
  1804. }
  1805. }
  1806. break;
  1807. default:
  1808. DBGLOG(INIT, WARN, "Unknown band %d\n", aucChannelList[i].eBand);
  1809. break;
  1810. }
  1811. }
  1812. }
  1813. /*----------------------------------------------------------------------------*/
  1814. /*!
  1815. * \brief Register the device to the kernel and return the index.
  1816. *
  1817. * \param[in] prDev Pointer to struct net_device.
  1818. *
  1819. * \retval 0 The execution of wlanNetRegister succeeds.
  1820. * \retval < 0 The execution of wlanNetRegister failed.
  1821. */
  1822. /*----------------------------------------------------------------------------*/
  1823. static INT_32 wlanNetRegister(struct wireless_dev *prWdev)
  1824. {
  1825. P_GLUE_INFO_T prGlueInfo;
  1826. INT_32 i4DevIdx = -1;
  1827. P_NETDEV_PRIVATE_GLUE_INFO prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) NULL;
  1828. ASSERT(prWdev);
  1829. do {
  1830. if (!prWdev)
  1831. break;
  1832. prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(prWdev->wiphy);
  1833. i4DevIdx = wlanGetDevIdx(prWdev->netdev);
  1834. if (i4DevIdx < 0) {
  1835. DBGLOG(INIT, ERROR, "wlanNetRegister: net_device number exceeds.\n");
  1836. break;
  1837. }
  1838. if (register_netdev(prWdev->netdev) < 0) {
  1839. DBGLOG(INIT, ERROR, "wlanNetRegister: net_device context is not registered.\n");
  1840. wlanClearDevIdx(prWdev->netdev);
  1841. i4DevIdx = -1;
  1842. }
  1843. #if 1
  1844. prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prGlueInfo->prDevHandler);
  1845. ASSERT(prNetDevPrivate->prGlueInfo == prGlueInfo);
  1846. prNetDevPrivate->ucBssIdx = prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex;
  1847. wlanBindBssIdxToNetInterface(prGlueInfo,
  1848. prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex, (PVOID) prWdev->netdev);
  1849. #else
  1850. wlanBindBssIdxToNetInterface(prGlueInfo,
  1851. prGlueInfo->prAdapter->prAisBssInfo->ucBssIndex, (PVOID) prWdev->netdev);
  1852. /* wlanBindNetInterface(prGlueInfo, NET_DEV_WLAN_IDX, (PVOID)prWdev->netdev); */
  1853. #endif
  1854. if (i4DevIdx != -1)
  1855. prGlueInfo->fgIsRegistered = TRUE;
  1856. } while (FALSE);
  1857. return i4DevIdx; /* success */
  1858. } /* end of wlanNetRegister() */
  1859. /*----------------------------------------------------------------------------*/
  1860. /*!
  1861. * \brief Unregister the device from the kernel
  1862. *
  1863. * \param[in] prWdev Pointer to struct net_device.
  1864. *
  1865. * \return (none)
  1866. */
  1867. /*----------------------------------------------------------------------------*/
  1868. static VOID wlanNetUnregister(struct wireless_dev *prWdev)
  1869. {
  1870. P_GLUE_INFO_T prGlueInfo;
  1871. if (!prWdev) {
  1872. DBGLOG(INIT, ERROR, "wlanNetUnregister: The device context is NULL\n");
  1873. return;
  1874. }
  1875. prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(prWdev->wiphy);
  1876. wlanClearDevIdx(prWdev->netdev);
  1877. unregister_netdev(prWdev->netdev);
  1878. prGlueInfo->fgIsRegistered = FALSE;
  1879. #if CFG_SUPPORT_SNIFFER
  1880. if (prGlueInfo->prMonDevHandler) {
  1881. unregister_netdev(prGlueInfo->prMonDevHandler);
  1882. prGlueInfo->prMonDevHandler = NULL;
  1883. }
  1884. prGlueInfo->fgIsEnableMon = FALSE;
  1885. #endif
  1886. } /* end of wlanNetUnregister() */
  1887. static const struct net_device_ops wlan_netdev_ops = {
  1888. .ndo_open = wlanOpen,
  1889. .ndo_stop = wlanStop,
  1890. .ndo_set_rx_mode = wlanSetMulticastList,
  1891. .ndo_get_stats = wlanGetStats,
  1892. .ndo_do_ioctl = wlanDoIOCTL,
  1893. .ndo_start_xmit = wlanHardStartXmit,
  1894. .ndo_init = wlanInit,
  1895. .ndo_uninit = wlanUninit,
  1896. .ndo_select_queue = wlanSelectQueue,
  1897. };
  1898. static void createWirelessDevice(void)
  1899. {
  1900. struct wiphy *prWiphy = NULL;
  1901. struct wireless_dev *prWdev = NULL;
  1902. /* 4 <1.1> Create wireless_dev */
  1903. prWdev = kzalloc(sizeof(struct wireless_dev), GFP_KERNEL);
  1904. if (!prWdev) {
  1905. DBGLOG(INIT, ERROR, "Allocating memory to wireless_dev context failed\n");
  1906. return;
  1907. }
  1908. /* 4 <1.2> Create wiphy */
  1909. prWiphy = wiphy_new(&mtk_wlan_ops, sizeof(GLUE_INFO_T));
  1910. if (!prWiphy) {
  1911. DBGLOG(INIT, ERROR, "Allocating memory to wiphy device failed\n");
  1912. goto free_wdev;
  1913. }
  1914. /* 4 <1.3> configure wireless_dev & wiphy */
  1915. prWdev->iftype = NL80211_IFTYPE_STATION;
  1916. prWiphy->max_scan_ssids = 1; /* FIXME: for combo scan */
  1917. prWiphy->max_scan_ie_len = 512;
  1918. prWiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_ADHOC);
  1919. prWiphy->bands[IEEE80211_BAND_2GHZ] = &mtk_band_2ghz;
  1920. /* always assign 5Ghz bands here, if the chip is not support 5Ghz,
  1921. bands[IEEE80211_BAND_5GHZ] will be assign to NULL */
  1922. prWiphy->bands[IEEE80211_BAND_5GHZ] = &mtk_band_5ghz;
  1923. prWiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1924. prWiphy->cipher_suites = mtk_cipher_suites;
  1925. prWiphy->n_cipher_suites = ARRAY_SIZE(mtk_cipher_suites);
  1926. prWiphy->flags = WIPHY_FLAG_SUPPORTS_FW_ROAM | WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  1927. prWiphy->regulatory_flags = REGULATORY_CUSTOM_REG;
  1928. #if CFG_SUPPORT_TDLS
  1929. TDLSEX_WIPHY_FLAGS_INIT(prWiphy->flags);
  1930. prWiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM |
  1931. WIPHY_FLAG_TDLS_EXTERNAL_SETUP | WIPHY_FLAG_SUPPORTS_TDLS;
  1932. #endif /* CFG_SUPPORT_TDLS */
  1933. prWiphy->max_remain_on_channel_duration = 5000;
  1934. prWiphy->mgmt_stypes = mtk_cfg80211_ais_default_mgmt_stypes;
  1935. prWiphy->vendor_commands = mtk_wlan_vendor_ops;
  1936. prWiphy->n_vendor_commands = sizeof(mtk_wlan_vendor_ops) / sizeof(struct wiphy_vendor_command);
  1937. prWiphy->vendor_events = mtk_wlan_vendor_events;
  1938. prWiphy->n_vendor_events = ARRAY_SIZE(mtk_wlan_vendor_events);
  1939. /* 4 <1.4> wowlan support */
  1940. #ifdef CONFIG_PM
  1941. prWiphy->wowlan = &mtk_wlan_wowlan_support;
  1942. #endif
  1943. #ifdef CONFIG_CFG80211_WEXT
  1944. /* 4 <1.5> Use wireless extension to replace IOCTL */
  1945. prWiphy->wext = &wext_handler_def;
  1946. #endif
  1947. if (wiphy_register(prWiphy) < 0) {
  1948. DBGLOG(INIT, ERROR, "wiphy_register error\n");
  1949. goto free_wiphy;
  1950. }
  1951. prWdev->wiphy = prWiphy;
  1952. gprWdev = prWdev;
  1953. DBGLOG(INIT, INFO, "create wireless device success\n");
  1954. return;
  1955. free_wiphy:
  1956. wiphy_free(prWiphy);
  1957. free_wdev:
  1958. kfree(prWdev);
  1959. }
  1960. static void destroyWirelessDevice(void)
  1961. {
  1962. wiphy_unregister(gprWdev->wiphy);
  1963. wiphy_free(gprWdev->wiphy);
  1964. kfree(gprWdev);
  1965. gprWdev = NULL;
  1966. }
  1967. VOID wlanWakeLockInit(P_GLUE_INFO_T prGlueInfo)
  1968. {
  1969. KAL_WAKE_LOCK_INIT(NULL, &prGlueInfo->rIntrWakeLock, "WLAN interrupt");
  1970. KAL_WAKE_LOCK_INIT(NULL, &prGlueInfo->rTimeoutWakeLock, "WLAN timeout");
  1971. }
  1972. VOID wlanWakeLockUninit(P_GLUE_INFO_T prGlueInfo)
  1973. {
  1974. if (KAL_WAKE_LOCK_ACTIVE(NULL, &prGlueInfo->rIntrWakeLock))
  1975. KAL_WAKE_UNLOCK(NULL, &prGlueInfo->rIntrWakeLock);
  1976. KAL_WAKE_LOCK_DESTROY(NULL, &prGlueInfo->rIntrWakeLock);
  1977. if (KAL_WAKE_LOCK_ACTIVE(NULL, &prGlueInfo->rTimeoutWakeLock))
  1978. KAL_WAKE_UNLOCK(NULL, &prGlueInfo->rTimeoutWakeLock);
  1979. KAL_WAKE_LOCK_DESTROY(NULL, &prGlueInfo->rTimeoutWakeLock);
  1980. }
  1981. /*----------------------------------------------------------------------------*/
  1982. /*!
  1983. * \brief A method for creating Linux NET4 struct net_device object and the
  1984. * private data(prGlueInfo and prAdapter). Setup the IO address to the HIF.
  1985. * Assign the function pointer to the net_device object
  1986. *
  1987. * \param[in] pvData Memory address for the device
  1988. *
  1989. * \retval Not null The wireless_dev object.
  1990. * \retval NULL Fail to create wireless_dev object
  1991. */
  1992. /*----------------------------------------------------------------------------*/
  1993. static struct lock_class_key rSpinKey[SPIN_LOCK_NUM];
  1994. static struct wireless_dev *wlanNetCreate(PVOID pvData)
  1995. {
  1996. struct wireless_dev *prWdev = gprWdev;
  1997. P_GLUE_INFO_T prGlueInfo = NULL;
  1998. P_ADAPTER_T prAdapter = NULL;
  1999. UINT_32 i;
  2000. struct device *prDev;
  2001. P_NETDEV_PRIVATE_GLUE_INFO prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) NULL;
  2002. if (prWdev == NULL) {
  2003. DBGLOG(INIT, ERROR, "No wireless dev exist, abort power on\n");
  2004. return NULL;
  2005. }
  2006. /* 4 <1.3> co-relate wiphy & prDev */
  2007. #if MTK_WCN_HIF_SDIO
  2008. mtk_wcn_hif_sdio_get_dev(*((MTK_WCN_HIF_SDIO_CLTCTX *) pvData), &prDev);
  2009. #else
  2010. prDev = &((struct sdio_func *)pvData)->dev;
  2011. #endif
  2012. if (!prDev)
  2013. DBGLOG(INIT, ERROR, "unable to get struct dev for wlan\n");
  2014. /* don't set prDev as parent of wiphy->dev, because we have done device_add
  2015. in driver init. if we set parent here, parent will be not able to know this child,
  2016. and may occurs a KE in device_shutdown, to free wiphy->dev, because his parent
  2017. has been freed. */
  2018. /*set_wiphy_dev(prWdev->wiphy, prDev); */
  2019. /* 4 <2> Create Glue structure */
  2020. prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(prWdev->wiphy);
  2021. kalMemZero(prGlueInfo, sizeof(GLUE_INFO_T));
  2022. /* 4 <3> Initial Glue structure */
  2023. /* 4 <3.1> create net device */
  2024. prGlueInfo->prDevHandler =
  2025. alloc_netdev_mq(sizeof(NETDEV_PRIVATE_GLUE_INFO), NIC_INF_NAME,
  2026. NET_NAME_PREDICTABLE, ether_setup, CFG_MAX_TXQ_NUM);
  2027. DBGLOG(INIT, INFO, "net_device prDev(0x%p) allocated\n", prGlueInfo->prDevHandler);
  2028. if (!prGlueInfo->prDevHandler) {
  2029. DBGLOG(INIT, ERROR, "Allocating memory to net_device context failed\n");
  2030. goto netcreate_err;
  2031. }
  2032. /* 4 <3.1.1> initialize net device varaiables */
  2033. #if 1
  2034. prNetDevPrivate = (P_NETDEV_PRIVATE_GLUE_INFO) netdev_priv(prGlueInfo->prDevHandler);
  2035. prNetDevPrivate->prGlueInfo = prGlueInfo;
  2036. #else
  2037. *((P_GLUE_INFO_T *) netdev_priv(prGlueInfo->prDevHandler)) = prGlueInfo;
  2038. #endif
  2039. prGlueInfo->prDevHandler->netdev_ops = &wlan_netdev_ops;
  2040. #ifdef CONFIG_WIRELESS_EXT
  2041. prGlueInfo->prDevHandler->wireless_handlers = &wext_handler_def;
  2042. #endif
  2043. netif_carrier_off(prGlueInfo->prDevHandler);
  2044. netif_tx_stop_all_queues(prGlueInfo->prDevHandler);
  2045. kalResetStats(prGlueInfo->prDevHandler);
  2046. #if CFG_SUPPORT_SNIFFER
  2047. INIT_WORK(&(prGlueInfo->monWork), wlanMonWorkHandler);
  2048. #endif
  2049. /* 4 <3.1.2> co-relate with wiphy bi-directionally */
  2050. prGlueInfo->prDevHandler->ieee80211_ptr = prWdev;
  2051. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  2052. prGlueInfo->prDevHandler->features = NETIF_F_HW_CSUM;
  2053. #endif
  2054. prWdev->netdev = prGlueInfo->prDevHandler;
  2055. /* 4 <3.1.3> co-relate net device & prDev */
  2056. SET_NETDEV_DEV(prGlueInfo->prDevHandler, prDev);
  2057. /* 4 <3.2> initiali glue variables */
  2058. prGlueInfo->eParamMediaStateIndicated = PARAM_MEDIA_STATE_DISCONNECTED;
  2059. prGlueInfo->ePowerState = ParamDeviceStateD0;
  2060. prGlueInfo->fgIsMacAddrOverride = FALSE;
  2061. prGlueInfo->fgIsRegistered = FALSE;
  2062. prGlueInfo->prScanRequest = NULL;
  2063. prGlueInfo->prSchedScanRequest = NULL;
  2064. #if CFG_SUPPORT_PASSPOINT
  2065. /* Init DAD */
  2066. prGlueInfo->fgIsDad = FALSE;
  2067. prGlueInfo->fgIs6Dad = FALSE;
  2068. kalMemZero(prGlueInfo->aucDADipv4, 4);
  2069. kalMemZero(prGlueInfo->aucDADipv6, 16);
  2070. #endif /* CFG_SUPPORT_PASSPOINT */
  2071. init_completion(&prGlueInfo->rScanComp);
  2072. init_completion(&prGlueInfo->rHaltComp);
  2073. init_completion(&prGlueInfo->rPendComp);
  2074. #if CFG_SUPPORT_MULTITHREAD
  2075. init_completion(&prGlueInfo->rHifHaltComp);
  2076. init_completion(&prGlueInfo->rRxHaltComp);
  2077. #endif
  2078. /* initialize timer for OID timeout checker */
  2079. kalOsTimerInitialize(prGlueInfo, kalTimeoutHandler);
  2080. for (i = 0; i < SPIN_LOCK_NUM; i++) {
  2081. spin_lock_init(&prGlueInfo->rSpinLock[i]);
  2082. lockdep_set_class(&prGlueInfo->rSpinLock[i], &rSpinKey[i]);
  2083. }
  2084. for (i = 0; i < MUTEX_NUM; i++)
  2085. mutex_init(&prGlueInfo->arMutex[i]);
  2086. /* initialize semaphore for ioctl */
  2087. sema_init(&prGlueInfo->ioctl_sem, 1);
  2088. #if CFG_SUPPORT_SDIO_READ_WRITE_PATTERN
  2089. /* initialize SDIO read-write pattern control */
  2090. prGlueInfo->fgEnSdioTestPattern = FALSE;
  2091. prGlueInfo->fgIsSdioTestInitialized = FALSE;
  2092. #endif
  2093. /* initialize semaphore for halt control */
  2094. sema_init(&g_halt_sem, 1);
  2095. /* 4 <8> Init Queues */
  2096. init_waitqueue_head(&prGlueInfo->waitq);
  2097. QUEUE_INITIALIZE(&prGlueInfo->rCmdQueue);
  2098. QUEUE_INITIALIZE(&prGlueInfo->rTxQueue);
  2099. glSetHifInfo(prGlueInfo, (ULONG) pvData);
  2100. /* Init wakelock */
  2101. wlanWakeLockInit(prGlueInfo);
  2102. /* main thread is created in this function */
  2103. #if CFG_SUPPORT_MULTITHREAD
  2104. init_waitqueue_head(&prGlueInfo->waitq_rx);
  2105. init_waitqueue_head(&prGlueInfo->waitq_hif);
  2106. prGlueInfo->u4TxThreadPid = 0xffffffff;
  2107. prGlueInfo->u4RxThreadPid = 0xffffffff;
  2108. prGlueInfo->u4HifThreadPid = 0xffffffff;
  2109. #endif
  2110. /* 4 <4> Create Adapter structure */
  2111. prAdapter = (P_ADAPTER_T) wlanAdapterCreate(prGlueInfo);
  2112. if (!prAdapter) {
  2113. DBGLOG(INIT, ERROR, "Allocating memory to adapter failed\n");
  2114. goto netcreate_err;
  2115. }
  2116. prGlueInfo->prAdapter = prAdapter;
  2117. goto netcreate_done;
  2118. netcreate_err:
  2119. if (NULL != prAdapter) {
  2120. wlanAdapterDestroy(prAdapter);
  2121. prAdapter = NULL;
  2122. }
  2123. if (NULL != prGlueInfo->prDevHandler) {
  2124. free_netdev(prGlueInfo->prDevHandler);
  2125. prGlueInfo->prDevHandler = NULL;
  2126. }
  2127. netcreate_done:
  2128. return prWdev;
  2129. } /* end of wlanNetCreate() */
  2130. /*----------------------------------------------------------------------------*/
  2131. /*!
  2132. * \brief Destroying the struct net_device object and the private data.
  2133. *
  2134. * \param[in] prWdev Pointer to struct wireless_dev.
  2135. *
  2136. * \return (none)
  2137. */
  2138. /*----------------------------------------------------------------------------*/
  2139. static VOID wlanNetDestroy(struct wireless_dev *prWdev)
  2140. {
  2141. P_GLUE_INFO_T prGlueInfo = NULL;
  2142. ASSERT(prWdev);
  2143. if (!prWdev) {
  2144. DBGLOG(INIT, ERROR, "wlanNetDestroy: The device context is NULL\n");
  2145. return;
  2146. }
  2147. /* prGlueInfo is allocated with net_device */
  2148. prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(prWdev->wiphy);
  2149. ASSERT(prGlueInfo);
  2150. /* destroy kal OS timer */
  2151. kalCancelTimer(prGlueInfo);
  2152. glClearHifInfo(prGlueInfo);
  2153. wlanAdapterDestroy(prGlueInfo->prAdapter);
  2154. prGlueInfo->prAdapter = NULL;
  2155. /* Free net_device and private data, which are allocated by alloc_netdev().
  2156. */
  2157. free_netdev(prWdev->netdev);
  2158. } /* end of wlanNetDestroy() */
  2159. VOID wlanSetSuspendMode(P_GLUE_INFO_T prGlueInfo, BOOLEAN fgEnable)
  2160. {
  2161. struct net_device *prDev = NULL;
  2162. if (!prGlueInfo)
  2163. return;
  2164. prDev = prGlueInfo->prDevHandler;
  2165. if (!prDev)
  2166. return;
  2167. kalSetNetAddressFromInterface(prGlueInfo, prDev, fgEnable);
  2168. }
  2169. #if CFG_ENABLE_EARLY_SUSPEND
  2170. static struct early_suspend wlan_early_suspend_desc = {
  2171. .level = EARLY_SUSPEND_LEVEL_BLANK_SCREEN,
  2172. };
  2173. static void wlan_early_suspend(struct early_suspend *h)
  2174. {
  2175. struct net_device *prDev = NULL;
  2176. P_GLUE_INFO_T prGlueInfo = NULL;
  2177. /* 4 <1> Sanity Check */
  2178. if ((u4WlanDevNum == 0) && (u4WlanDevNum > CFG_MAX_WLAN_DEVICES)) {
  2179. DBGLOG(INIT, ERROR, "wlanLateResume u4WlanDevNum==0 invalid!!\n");
  2180. return;
  2181. }
  2182. prDev = arWlanDevInfo[u4WlanDevNum - 1].prDev;
  2183. if (!prDev)
  2184. return;
  2185. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2186. if (!prGlueInfo)
  2187. return;
  2188. DBGLOG(INIT, INFO, "********<%s>********\n", __func__);
  2189. if (prGlueInfo->fgIsInSuspendMode == TRUE) {
  2190. DBGLOG(INIT, INFO, "%s: Already in suspend mode, SKIP!\n", __func__);
  2191. return;
  2192. }
  2193. prGlueInfo->fgIsInSuspendMode = TRUE;
  2194. wlanSetSuspendMode(prGlueInfo, TRUE);
  2195. p2pSetSuspendMode(prGlueInfo, TRUE);
  2196. }
  2197. static void wlan_late_resume(struct early_suspend *h)
  2198. {
  2199. struct net_device *prDev = NULL;
  2200. P_GLUE_INFO_T prGlueInfo = NULL;
  2201. /* 4 <1> Sanity Check */
  2202. if ((u4WlanDevNum == 0) && (u4WlanDevNum > CFG_MAX_WLAN_DEVICES)) {
  2203. DBGLOG(INIT, ERROR, "wlanLateResume u4WlanDevNum==0 invalid!!\n");
  2204. return;
  2205. }
  2206. prDev = arWlanDevInfo[u4WlanDevNum - 1].prDev;
  2207. if (!prDev)
  2208. return;
  2209. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2210. if (!prGlueInfo)
  2211. return;
  2212. DBGLOG(INIT, INFO, "********<%s>********\n", __func__);
  2213. if (prGlueInfo->fgIsInSuspendMode == FALSE) {
  2214. DBGLOG(INIT, INFO, "%s: Not in suspend mode, SKIP!\n", __func__);
  2215. return;
  2216. }
  2217. prGlueInfo->fgIsInSuspendMode = FALSE;
  2218. /* 4 <2> Set suspend mode for each network */
  2219. wlanSetSuspendMode(prGlueInfo, FALSE);
  2220. p2pSetSuspendMode(prGlueInfo, FALSE);
  2221. }
  2222. #endif
  2223. #if (MTK_WCN_HIF_SDIO && CFG_SUPPORT_MTK_ANDROID_KK)
  2224. int set_p2p_mode_handler(struct net_device *netdev, PARAM_CUSTOM_P2P_SET_STRUCT_T p2pmode)
  2225. {
  2226. P_GLUE_INFO_T prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(netdev));
  2227. PARAM_CUSTOM_P2P_SET_STRUCT_T rSetP2P;
  2228. WLAN_STATUS rWlanStatus = WLAN_STATUS_SUCCESS;
  2229. UINT_32 u4BufLen = 0;
  2230. rSetP2P.u4Enable = p2pmode.u4Enable;
  2231. rSetP2P.u4Mode = p2pmode.u4Mode;
  2232. if ((!rSetP2P.u4Enable) && (fgIsResetting == FALSE))
  2233. p2pNetUnregister(prGlueInfo, FALSE);
  2234. rWlanStatus = kalIoctl(prGlueInfo,
  2235. wlanoidSetP2pMode,
  2236. (PVOID) &rSetP2P, sizeof(PARAM_CUSTOM_P2P_SET_STRUCT_T), FALSE, FALSE, TRUE, &u4BufLen);
  2237. DBGLOG(INIT, TRACE, "set_p2p_mode_handler ret = 0x%08lx\n", (UINT_32) rWlanStatus);
  2238. /* Need to check fgIsP2PRegistered, in case of whole chip reset.
  2239. * in this case, kalIOCTL return success always,
  2240. * and prGlueInfo->prP2pInfo may be NULL */
  2241. if ((rSetP2P.u4Enable) && (prGlueInfo->prAdapter->fgIsP2PRegistered) && (fgIsResetting == FALSE))
  2242. p2pNetRegister(prGlueInfo, FALSE);
  2243. return 0;
  2244. }
  2245. void set_dbg_level_handler(unsigned char dbg_lvl[DBG_MODULE_NUM])
  2246. {
  2247. UINT_8 ucIdx;
  2248. DBGLOG(INIT, INFO, "Set DBG log level from set_dbg_level_handler!\n");
  2249. for (ucIdx = 0; ucIdx < DBG_MODULE_NUM; ucIdx++)
  2250. wlanSetDebugLevel(ucIdx, (UINT_32) dbg_lvl[ucIdx]);
  2251. /* kalMemCopy(aucDebugModule, dbg_lvl, sizeof(aucDebugModule)); */
  2252. }
  2253. #endif
  2254. /*----------------------------------------------------------------------------*/
  2255. /*!
  2256. * \brief Wlan probe function. This function probes and initializes the device.
  2257. *
  2258. * \param[in] pvData data passed by bus driver init function
  2259. * _HIF_EHPI: NULL
  2260. * _HIF_SDIO: sdio bus driver handle
  2261. *
  2262. * \retval 0 Success
  2263. * \retval negative value Failed
  2264. */
  2265. /*----------------------------------------------------------------------------*/
  2266. static INT_32 wlanProbe(PVOID pvData)
  2267. {
  2268. struct wireless_dev *prWdev = NULL;
  2269. P_WLANDEV_INFO_T prWlandevInfo = NULL;
  2270. INT_32 i4DevIdx = 0;
  2271. P_GLUE_INFO_T prGlueInfo = NULL;
  2272. P_ADAPTER_T prAdapter = NULL;
  2273. INT_32 i4Status = 0;
  2274. BOOL bRet = FALSE;
  2275. do {
  2276. /* 4 <1> Initialize the IO port of the interface */
  2277. /* GeorgeKuo: pData has different meaning for _HIF_XXX:
  2278. * _HIF_EHPI: pointer to memory base variable, which will be
  2279. * initialized by glBusInit().
  2280. * _HIF_SDIO: bus driver handle
  2281. */
  2282. bRet = glBusInit(pvData);
  2283. /* Cannot get IO address from interface */
  2284. if (FALSE == bRet) {
  2285. DBGLOG(INIT, ERROR, "wlanProbe: glBusInit() fail\n");
  2286. i4Status = -EIO;
  2287. break;
  2288. }
  2289. /* 4 <2> Create network device, Adapter, KalInfo, prDevHandler(netdev) */
  2290. prWdev = wlanNetCreate(pvData);
  2291. if (prWdev == NULL) {
  2292. DBGLOG(INIT, ERROR, "wlanProbe: No memory for dev and its private\n");
  2293. i4Status = -ENOMEM;
  2294. break;
  2295. }
  2296. /* 4 <2.5> Set the ioaddr to HIF Info */
  2297. prGlueInfo = (P_GLUE_INFO_T) wiphy_priv(prWdev->wiphy);
  2298. gPrDev = prGlueInfo->prDevHandler;
  2299. /* prGlueInfo->main_thread = kthread_run(tx_thread, prGlueInfo->prDevHandler, "tx_thread"); */
  2300. /* 4 <4> Setup IRQ */
  2301. prWlandevInfo = &arWlanDevInfo[i4DevIdx];
  2302. i4Status = glBusSetIrq(prWdev->netdev, NULL, prGlueInfo);
  2303. if (i4Status != WLAN_STATUS_SUCCESS) {
  2304. DBGLOG(INIT, ERROR, "wlanProbe: Set IRQ error\n");
  2305. break;
  2306. }
  2307. prGlueInfo->i4DevIdx = i4DevIdx;
  2308. prAdapter = prGlueInfo->prAdapter;
  2309. prGlueInfo->u4ReadyFlag = 0;
  2310. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  2311. prAdapter->u4CSUMFlags = (CSUM_OFFLOAD_EN_TX_TCP | CSUM_OFFLOAD_EN_TX_UDP | CSUM_OFFLOAD_EN_TX_IP);
  2312. #endif
  2313. #if CFG_SUPPORT_CFG_FILE
  2314. {
  2315. PUINT_8 pucConfigBuf;
  2316. UINT_32 u4ConfigReadLen;
  2317. wlanCfgInit(prAdapter, NULL, 0, 0);
  2318. pucConfigBuf = (PUINT_8) kalMemAlloc(WLAN_CFG_FILE_BUF_SIZE, VIR_MEM_TYPE);
  2319. u4ConfigReadLen = 0;
  2320. kalMemZero(pucConfigBuf, WLAN_CFG_FILE_BUF_SIZE);
  2321. if (pucConfigBuf) {
  2322. if (kalReadToFile("/storage/sdcard0/wifi.cfg", pucConfigBuf,
  2323. WLAN_CFG_FILE_BUF_SIZE, &u4ConfigReadLen) == 0) {
  2324. /* ToDo:: Nothing */
  2325. } else if (kalReadToFile("/data/misc/wifi.cfg", pucConfigBuf,
  2326. WLAN_CFG_FILE_BUF_SIZE, &u4ConfigReadLen) == 0) {
  2327. /* ToDo:: Nothing */
  2328. } else if (kalReadToFile("/data/misc/wifi/wifi.cfg", pucConfigBuf,
  2329. WLAN_CFG_FILE_BUF_SIZE, &u4ConfigReadLen) == 0) {
  2330. /* ToDo:: Nothing */
  2331. } else if (kalReadToFile("/etc/firmware/wifi.cfg", pucConfigBuf,
  2332. WLAN_CFG_FILE_BUF_SIZE, &u4ConfigReadLen) == 0) {
  2333. /* ToDo:: Nothing */
  2334. }
  2335. if (pucConfigBuf[0] != '\0' && u4ConfigReadLen > 0)
  2336. wlanCfgInit(prAdapter, pucConfigBuf, u4ConfigReadLen, 0);
  2337. kalMemFree(pucConfigBuf, VIR_MEM_TYPE, WLAN_CFG_FILE_BUF_SIZE);
  2338. } /* pucConfigBuf */
  2339. }
  2340. #endif
  2341. /* 4 <5> Start Device */
  2342. /* */
  2343. #if CFG_ENABLE_FW_DOWNLOAD
  2344. /* before start adapter, we need to open and load firmware */
  2345. {
  2346. UINT_32 u4FwSize = 0;
  2347. PVOID prFwBuffer = NULL;
  2348. P_REG_INFO_T prRegInfo = &prGlueInfo->rRegInfo;
  2349. /* P_REG_INFO_T prRegInfo = (P_REG_INFO_T) kmalloc(sizeof(REG_INFO_T), GFP_KERNEL); */
  2350. kalMemSet(prRegInfo, 0, sizeof(REG_INFO_T));
  2351. prRegInfo->u4StartAddress = CFG_FW_START_ADDRESS;
  2352. prRegInfo->u4LoadAddress = CFG_FW_LOAD_ADDRESS;
  2353. /* Trigger the action of switching Pwr state to drv_own */
  2354. prAdapter->fgIsFwOwn = TRUE;
  2355. nicPmTriggerDriverOwn(prAdapter);
  2356. /* Load NVRAM content to REG_INFO_T */
  2357. glLoadNvram(prGlueInfo, prRegInfo);
  2358. /* kalMemCopy(&prGlueInfo->rRegInfo, prRegInfo, sizeof(REG_INFO_T)); */
  2359. prRegInfo->u4PowerMode = CFG_INIT_POWER_SAVE_PROF;
  2360. prRegInfo->fgEnArpFilter = TRUE;
  2361. if (kalFirmwareImageMapping(prGlueInfo, &prFwBuffer, &u4FwSize) == NULL) {
  2362. i4Status = -EIO;
  2363. goto bailout;
  2364. } else {
  2365. if (wlanAdapterStart(prAdapter, prRegInfo, prFwBuffer, u4FwSize) != WLAN_STATUS_SUCCESS)
  2366. i4Status = -EIO;
  2367. }
  2368. kalFirmwareImageUnmapping(prGlueInfo, NULL, prFwBuffer);
  2369. bailout:
  2370. /* kfree(prRegInfo); */
  2371. if (i4Status < 0)
  2372. break;
  2373. }
  2374. #else
  2375. /* P_REG_INFO_T prRegInfo = (P_REG_INFO_T) kmalloc(sizeof(REG_INFO_T), GFP_KERNEL); */
  2376. kalMemSet(&prGlueInfo->rRegInfo, 0, sizeof(REG_INFO_T));
  2377. P_REG_INFO_T prRegInfo = &prGlueInfo->rRegInfo;
  2378. /* Load NVRAM content to REG_INFO_T */
  2379. glLoadNvram(prGlueInfo, prRegInfo);
  2380. prRegInfo->u4PowerMode = CFG_INIT_POWER_SAVE_PROF;
  2381. if (wlanAdapterStart(prAdapter, prRegInfo, NULL, 0) != WLAN_STATUS_SUCCESS) {
  2382. i4Status = -EIO;
  2383. break;
  2384. }
  2385. #endif
  2386. prGlueInfo->main_thread = kthread_run(tx_thread, prGlueInfo->prDevHandler, "tx_thread");
  2387. #if CFG_SUPPORT_MULTITHREAD
  2388. prGlueInfo->hif_thread = kthread_run(hif_thread, prGlueInfo->prDevHandler, "hif_thread");
  2389. prGlueInfo->rx_thread = kthread_run(rx_thread, prGlueInfo->prDevHandler, "rx_thread");
  2390. #endif
  2391. /* TODO the change schedule API shall be provided by OS glue layer */
  2392. /* Switch the Wi-Fi task priority to higher priority and change the scheduling method */
  2393. if (prGlueInfo->prAdapter->rWifiVar.ucThreadPriority > 0) {
  2394. struct sched_param param = {.sched_priority = prGlueInfo->prAdapter->rWifiVar.ucThreadPriority
  2395. };
  2396. sched_setscheduler(prGlueInfo->main_thread,
  2397. prGlueInfo->prAdapter->rWifiVar.ucThreadScheduling, &param);
  2398. #if CFG_SUPPORT_MULTITHREAD
  2399. sched_setscheduler(prGlueInfo->hif_thread,
  2400. prGlueInfo->prAdapter->rWifiVar.ucThreadScheduling, &param);
  2401. sched_setscheduler(prGlueInfo->rx_thread,
  2402. prGlueInfo->prAdapter->rWifiVar.ucThreadScheduling, &param);
  2403. #endif
  2404. DBGLOG(INIT, INFO,
  2405. "Set pri = %d, sched = %d\n",
  2406. prGlueInfo->prAdapter->rWifiVar.ucThreadPriority,
  2407. prGlueInfo->prAdapter->rWifiVar.ucThreadScheduling);
  2408. }
  2409. if (FALSE == prAdapter->fgEnable5GBand)
  2410. prWdev->wiphy->bands[IEEE80211_BAND_5GHZ] = NULL;
  2411. g_u4HaltFlag = 0;
  2412. /* set MAC address */
  2413. {
  2414. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  2415. struct sockaddr MacAddr;
  2416. UINT_32 u4SetInfoLen = 0;
  2417. rStatus = kalIoctl(prGlueInfo,
  2418. wlanoidQueryCurrentAddr,
  2419. &MacAddr.sa_data, PARAM_MAC_ADDR_LEN, TRUE, TRUE, TRUE, &u4SetInfoLen);
  2420. if (rStatus != WLAN_STATUS_SUCCESS) {
  2421. DBGLOG(INIT, WARN, "set MAC addr fail 0x%lx\n", rStatus);
  2422. prGlueInfo->u4ReadyFlag = 0;
  2423. } else {
  2424. ether_addr_copy(prGlueInfo->prDevHandler->dev_addr, MacAddr.sa_data);
  2425. ether_addr_copy(prGlueInfo->prDevHandler->perm_addr,
  2426. prGlueInfo->prDevHandler->dev_addr);
  2427. /* card is ready */
  2428. prGlueInfo->u4ReadyFlag = 1;
  2429. #if CFG_SHOW_MACADDR_SOURCE
  2430. DBGLOG(INIT, INFO, "MAC address: " MACSTR, MAC2STR(MacAddr.sa_data));
  2431. #endif
  2432. }
  2433. }
  2434. #if CFG_TCP_IP_CHKSUM_OFFLOAD
  2435. /* set HW checksum offload */
  2436. {
  2437. WLAN_STATUS rStatus = WLAN_STATUS_FAILURE;
  2438. UINT_32 u4CSUMFlags = CSUM_OFFLOAD_EN_ALL;
  2439. UINT_32 u4SetInfoLen = 0;
  2440. rStatus = kalIoctl(prGlueInfo,
  2441. wlanoidSetCSUMOffload,
  2442. (PVOID) &u4CSUMFlags, sizeof(UINT_32), FALSE, FALSE, TRUE, &u4SetInfoLen);
  2443. if (rStatus != WLAN_STATUS_SUCCESS)
  2444. DBGLOG(INIT, WARN, "set HW checksum offload fail 0x%lx\n", rStatus);
  2445. }
  2446. #endif
  2447. /* 4 <3> Register the card */
  2448. i4DevIdx = wlanNetRegister(prWdev);
  2449. if (i4DevIdx < 0) {
  2450. i4Status = -ENXIO;
  2451. DBGLOG(INIT, ERROR, "wlanProbe: Cannot register the net_device context to the kernel\n");
  2452. break;
  2453. }
  2454. /* 4 <4> Register early suspend callback */
  2455. #if CFG_ENABLE_EARLY_SUSPEND
  2456. glRegisterEarlySuspend(&wlan_early_suspend_desc, wlan_early_suspend, wlan_late_resume);
  2457. #endif
  2458. /* 4 <5> Register Notifier callback */
  2459. wlanRegisterNotifier();
  2460. /* 4 <6> Initialize /proc filesystem */
  2461. #ifdef WLAN_INCLUDE_PROC
  2462. i4Status = procCreateFsEntry(prGlueInfo);
  2463. if (i4Status < 0) {
  2464. DBGLOG(INIT, ERROR, "wlanProbe: init procfs failed\n");
  2465. break;
  2466. }
  2467. #endif /* WLAN_INCLUDE_PROC */
  2468. #if CFG_MET_PACKET_TRACE_SUPPORT
  2469. kalMetInit(prGlueInfo);
  2470. #endif
  2471. #if CFG_ENABLE_BT_OVER_WIFI
  2472. prGlueInfo->rBowInfo.fgIsNetRegistered = FALSE;
  2473. prGlueInfo->rBowInfo.fgIsRegistered = FALSE;
  2474. glRegisterAmpc(prGlueInfo);
  2475. #endif
  2476. #if (CFG_ENABLE_WIFI_DIRECT && MTK_WCN_HIF_SDIO && CFG_SUPPORT_MTK_ANDROID_KK)
  2477. register_set_p2p_mode_handler(set_p2p_mode_handler);
  2478. #endif
  2479. } while (FALSE);
  2480. if (i4Status == 0) {
  2481. #if CFG_SUPPORT_AGPS_ASSIST
  2482. kalIndicateAgpsNotify(prAdapter, AGPS_EVENT_WLAN_ON, NULL, 0);
  2483. #endif
  2484. DBGLOG(INIT, LOUD, "wlanProbe: probe success\n");
  2485. } else {
  2486. DBGLOG(INIT, LOUD, "wlanProbe: probe failed\n");
  2487. }
  2488. wlanCfgSetSwCtrl(prGlueInfo->prAdapter);
  2489. wlanCfgSetChip(prGlueInfo->prAdapter);
  2490. wlanCfgSetCountryCode(prGlueInfo->prAdapter);
  2491. #if (CFG_MET_PACKET_TRACE_SUPPORT == 1)
  2492. DBGLOG(INIT, TRACE, "init MET procfs...\n");
  2493. i4Status = kalMetInitProcfs(prGlueInfo);
  2494. if (i4Status < 0)
  2495. DBGLOG(INIT, ERROR, "wlanProbe: init MET procfs failed\n");
  2496. #endif
  2497. return i4Status;
  2498. } /* end of wlanProbe() */
  2499. /*----------------------------------------------------------------------------*/
  2500. /*!
  2501. * \brief A method to stop driver operation and release all resources. Following
  2502. * this call, no frame should go up or down through this interface.
  2503. *
  2504. * \return (none)
  2505. */
  2506. /*----------------------------------------------------------------------------*/
  2507. static VOID wlanRemove(VOID)
  2508. {
  2509. struct net_device *prDev = NULL;
  2510. P_WLANDEV_INFO_T prWlandevInfo = NULL;
  2511. P_GLUE_INFO_T prGlueInfo = NULL;
  2512. P_ADAPTER_T prAdapter = NULL;
  2513. DBGLOG(INIT, INFO, "Remove wlan!\n");
  2514. /* 4 <0> Sanity check */
  2515. ASSERT(u4WlanDevNum <= CFG_MAX_WLAN_DEVICES);
  2516. if (0 == u4WlanDevNum) {
  2517. DBGLOG(INIT, ERROR, "0 == u4WlanDevNum\n");
  2518. return;
  2519. }
  2520. #if (CFG_ENABLE_WIFI_DIRECT && MTK_WCN_HIF_SDIO && CFG_SUPPORT_MTK_ANDROID_KK)
  2521. register_set_p2p_mode_handler(NULL);
  2522. #endif
  2523. prDev = arWlanDevInfo[u4WlanDevNum - 1].prDev;
  2524. prWlandevInfo = &arWlanDevInfo[u4WlanDevNum - 1];
  2525. ASSERT(prDev);
  2526. if (NULL == prDev) {
  2527. DBGLOG(INIT, ERROR, "NULL == prDev\n");
  2528. return;
  2529. }
  2530. prGlueInfo = *((P_GLUE_INFO_T *) netdev_priv(prDev));
  2531. ASSERT(prGlueInfo);
  2532. if (NULL == prGlueInfo) {
  2533. DBGLOG(INIT, ERROR, "NULL == prGlueInfo\n");
  2534. free_netdev(prDev);
  2535. return;
  2536. }
  2537. #if CFG_ENABLE_BT_OVER_WIFI
  2538. if (prGlueInfo->rBowInfo.fgIsNetRegistered) {
  2539. bowNotifyAllLinkDisconnected(prGlueInfo->prAdapter);
  2540. /* wait 300ms for BoW module to send deauth */
  2541. kalMsleep(300);
  2542. }
  2543. #endif
  2544. flush_delayed_work(&workq);
  2545. /* 20150205 work queue for sched_scan */
  2546. flush_delayed_work(&sched_workq);
  2547. down(&g_halt_sem);
  2548. g_u4HaltFlag = 1;
  2549. /* 4 <2> Mark HALT, notify main thread to stop, and clean up queued requests */
  2550. set_bit(GLUE_FLAG_HALT_BIT, &prGlueInfo->ulFlag);
  2551. #if CFG_SUPPORT_MULTITHREAD
  2552. wake_up_interruptible(&prGlueInfo->waitq_hif);
  2553. wait_for_completion_interruptible(&prGlueInfo->rHifHaltComp);
  2554. wake_up_interruptible(&prGlueInfo->waitq_rx);
  2555. wait_for_completion_interruptible(&prGlueInfo->rRxHaltComp);
  2556. #endif
  2557. /* wake up main thread */
  2558. wake_up_interruptible(&prGlueInfo->waitq);
  2559. /* wait main thread stops */
  2560. wait_for_completion_interruptible(&prGlueInfo->rHaltComp);
  2561. DBGLOG(INIT, TRACE, "mtk_sdiod stopped\n");
  2562. /* prGlueInfo->rHifInfo.main_thread = NULL; */
  2563. prGlueInfo->main_thread = NULL;
  2564. #if CFG_SUPPORT_MULTITHREAD
  2565. prGlueInfo->hif_thread = NULL;
  2566. prGlueInfo->rx_thread = NULL;
  2567. prGlueInfo->u4TxThreadPid = 0xffffffff;
  2568. prGlueInfo->u4HifThreadPid = 0xffffffff;
  2569. #endif
  2570. /* Destroy wakelock */
  2571. wlanWakeLockUninit(prGlueInfo);
  2572. kalMemSet(&(prGlueInfo->prAdapter->rWlanInfo), 0, sizeof(WLAN_INFO_T));
  2573. #if CFG_ENABLE_WIFI_DIRECT
  2574. if (prGlueInfo->prAdapter->fgIsP2PRegistered) {
  2575. DBGLOG(INIT, TRACE, "p2pNetUnregister...\n");
  2576. p2pNetUnregister(prGlueInfo, FALSE);
  2577. DBGLOG(INIT, TRACE, "p2pRemove...\n");
  2578. /*p2pRemove must before wlanAdapterStop */
  2579. p2pRemove(prGlueInfo);
  2580. }
  2581. #endif
  2582. #if CFG_ENABLE_BT_OVER_WIFI
  2583. if (prGlueInfo->rBowInfo.fgIsRegistered)
  2584. glUnregisterAmpc(prGlueInfo);
  2585. #endif
  2586. /* 4 <3> Remove /proc filesystem. */
  2587. #ifdef WLAN_INCLUDE_PROC
  2588. procRemoveProcfs();
  2589. #endif /* WLAN_INCLUDE_PROC */
  2590. #if (CFG_MET_PACKET_TRACE_SUPPORT == 1)
  2591. kalMetRemoveProcfs();
  2592. #endif
  2593. /* 4 <4> wlanAdapterStop */
  2594. prAdapter = prGlueInfo->prAdapter;
  2595. #if CFG_SUPPORT_AGPS_ASSIST
  2596. kalIndicateAgpsNotify(prAdapter, AGPS_EVENT_WLAN_OFF, NULL, 0);
  2597. #endif
  2598. wlanAdapterStop(prAdapter);
  2599. DBGLOG(INIT, TRACE, "Number of Stalled Packets = %d\n", GLUE_GET_REF_CNT(prGlueInfo->i4TxPendingFrameNum));
  2600. /* 4 <x> Stopping handling interrupt and free IRQ */
  2601. glBusFreeIrq(prDev, prGlueInfo);
  2602. /* 4 <5> Release the Bus */
  2603. glBusRelease(prDev);
  2604. up(&g_halt_sem);
  2605. /* 4 <6> Unregister the card */
  2606. wlanNetUnregister(prDev->ieee80211_ptr);
  2607. /* 4 <7> Destroy the device */
  2608. wlanNetDestroy(prDev->ieee80211_ptr);
  2609. prDev = NULL;
  2610. /* 4 <8> Unregister early suspend callback */
  2611. #if CFG_ENABLE_EARLY_SUSPEND
  2612. glUnregisterEarlySuspend(&wlan_early_suspend_desc);
  2613. #endif
  2614. gprWdev->netdev = NULL;
  2615. /* 4 <9> Unregister notifier callback */
  2616. wlanUnregisterNotifier();
  2617. } /* end of wlanRemove() */
  2618. /*----------------------------------------------------------------------------*/
  2619. /*!
  2620. * \brief Driver entry point when the driver is configured as a Linux Module, and
  2621. * is called once at module load time, by the user-level modutils
  2622. * application: insmod or modprobe.
  2623. *
  2624. * \retval 0 Success
  2625. */
  2626. /*----------------------------------------------------------------------------*/
  2627. /* 1 Module Entry Point */
  2628. static int initWlan(void)
  2629. {
  2630. int ret = 0;
  2631. wlanDebugInit();
  2632. DBGLOG(INIT, INFO, "initWlan\n");
  2633. /* memory pre-allocation */
  2634. kalInitIOBuffer();
  2635. procInitFs();
  2636. createWirelessDevice();
  2637. if (gprWdev)
  2638. glP2pCreateWirelessDevice((P_GLUE_INFO_T) wiphy_priv(gprWdev->wiphy));
  2639. #if (MTK_WCN_HIF_SDIO && CFG_SUPPORT_MTK_ANDROID_KK)
  2640. register_set_dbg_level_handler(set_dbg_level_handler);
  2641. #endif
  2642. ret = ((glRegisterBus(wlanProbe, wlanRemove) == WLAN_STATUS_SUCCESS) ? 0 : -EIO);
  2643. if (ret == -EIO) {
  2644. kalUninitIOBuffer();
  2645. return ret;
  2646. }
  2647. #if (CFG_CHIP_RESET_SUPPORT)
  2648. glResetInit();
  2649. #endif
  2650. return ret;
  2651. } /* end of initWlan() */
  2652. /*----------------------------------------------------------------------------*/
  2653. /*!
  2654. * \brief Driver exit point when the driver as a Linux Module is removed. Called
  2655. * at module unload time, by the user level modutils application: rmmod.
  2656. * This is our last chance to clean up after ourselves.
  2657. *
  2658. * \return (none)
  2659. */
  2660. /*----------------------------------------------------------------------------*/
  2661. /* 1 Module Leave Point */
  2662. static VOID exitWlan(void)
  2663. {
  2664. #if CFG_CHIP_RESET_SUPPORT
  2665. glResetUninit();
  2666. #endif
  2667. glUnregisterBus(wlanRemove);
  2668. /* free pre-allocated memory */
  2669. kalUninitIOBuffer();
  2670. destroyWirelessDevice();
  2671. glP2pDestroyWirelessDevice();
  2672. procUninitProcFs();
  2673. DBGLOG(INIT, INFO, "exitWlan\n");
  2674. } /* end of exitWlan() */
  2675. #ifdef MTK_WCN_BUILT_IN_DRIVER
  2676. #if (MTK_WCN_HIF_SDIO == 1)
  2677. int mtk_wcn_wlan_gen3_init(void)
  2678. {
  2679. return initWlan();
  2680. }
  2681. EXPORT_SYMBOL(mtk_wcn_wlan_gen3_init);
  2682. void mtk_wcn_wlan_gen3_exit(void)
  2683. {
  2684. return exitWlan();
  2685. }
  2686. EXPORT_SYMBOL(mtk_wcn_wlan_gen3_exit);
  2687. #elif (MTK_WCN_HIF_SDIO == 0)
  2688. device_initcall(initWlan);
  2689. #endif
  2690. #else
  2691. module_init(initWlan);
  2692. module_exit(exitWlan);
  2693. #endif
  2694. MODULE_AUTHOR(NIC_AUTHOR);
  2695. MODULE_DESCRIPTION(NIC_DESC);
  2696. MODULE_SUPPORTED_DEVICE(NIC_NAME);
  2697. MODULE_LICENSE("GPL");