gl_init.c 113 KB

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