mwl8k.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161
  1. /*
  2. * drivers/net/wireless/mwl8k.c
  3. * Driver for Marvell TOPDOG 802.11 Wireless cards
  4. *
  5. * Copyright (C) 2008, 2009, 2010 Marvell Semiconductor Inc.
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/init.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/spinlock.h>
  17. #include <linux/list.h>
  18. #include <linux/pci.h>
  19. #include <linux/delay.h>
  20. #include <linux/completion.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/slab.h>
  23. #include <net/mac80211.h>
  24. #include <linux/moduleparam.h>
  25. #include <linux/firmware.h>
  26. #include <linux/workqueue.h>
  27. #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
  28. #define MWL8K_NAME KBUILD_MODNAME
  29. #define MWL8K_VERSION "0.13"
  30. /* Module parameters */
  31. static bool ap_mode_default;
  32. module_param(ap_mode_default, bool, 0);
  33. MODULE_PARM_DESC(ap_mode_default,
  34. "Set to 1 to make ap mode the default instead of sta mode");
  35. /* Register definitions */
  36. #define MWL8K_HIU_GEN_PTR 0x00000c10
  37. #define MWL8K_MODE_STA 0x0000005a
  38. #define MWL8K_MODE_AP 0x000000a5
  39. #define MWL8K_HIU_INT_CODE 0x00000c14
  40. #define MWL8K_FWSTA_READY 0xf0f1f2f4
  41. #define MWL8K_FWAP_READY 0xf1f2f4a5
  42. #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
  43. #define MWL8K_HIU_SCRATCH 0x00000c40
  44. /* Host->device communications */
  45. #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
  46. #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
  47. #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
  48. #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
  49. #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
  50. #define MWL8K_H2A_INT_DUMMY (1 << 20)
  51. #define MWL8K_H2A_INT_RESET (1 << 15)
  52. #define MWL8K_H2A_INT_DOORBELL (1 << 1)
  53. #define MWL8K_H2A_INT_PPA_READY (1 << 0)
  54. /* Device->host communications */
  55. #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
  56. #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
  57. #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
  58. #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
  59. #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
  60. #define MWL8K_A2H_INT_DUMMY (1 << 20)
  61. #define MWL8K_A2H_INT_BA_WATCHDOG (1 << 14)
  62. #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
  63. #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
  64. #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
  65. #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
  66. #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
  67. #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
  68. #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
  69. #define MWL8K_A2H_INT_RX_READY (1 << 1)
  70. #define MWL8K_A2H_INT_TX_DONE (1 << 0)
  71. /* HW micro second timer register
  72. * located at offset 0xA600. This
  73. * will be used to timestamp tx
  74. * packets.
  75. */
  76. #define MWL8K_HW_TIMER_REGISTER 0x0000a600
  77. #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
  78. MWL8K_A2H_INT_CHNL_SWITCHED | \
  79. MWL8K_A2H_INT_QUEUE_EMPTY | \
  80. MWL8K_A2H_INT_RADAR_DETECT | \
  81. MWL8K_A2H_INT_RADIO_ON | \
  82. MWL8K_A2H_INT_RADIO_OFF | \
  83. MWL8K_A2H_INT_MAC_EVENT | \
  84. MWL8K_A2H_INT_OPC_DONE | \
  85. MWL8K_A2H_INT_RX_READY | \
  86. MWL8K_A2H_INT_TX_DONE | \
  87. MWL8K_A2H_INT_BA_WATCHDOG)
  88. #define MWL8K_RX_QUEUES 1
  89. #define MWL8K_TX_WMM_QUEUES 4
  90. #define MWL8K_MAX_AMPDU_QUEUES 8
  91. #define MWL8K_MAX_TX_QUEUES (MWL8K_TX_WMM_QUEUES + MWL8K_MAX_AMPDU_QUEUES)
  92. #define mwl8k_tx_queues(priv) (MWL8K_TX_WMM_QUEUES + (priv)->num_ampdu_queues)
  93. /* txpriorities are mapped with hw queues.
  94. * Each hw queue has a txpriority.
  95. */
  96. #define TOTAL_HW_TX_QUEUES 8
  97. /* Each HW queue can have one AMPDU stream.
  98. * But, because one of the hw queue is reserved,
  99. * maximum AMPDU queues that can be created are
  100. * one short of total tx queues.
  101. */
  102. #define MWL8K_NUM_AMPDU_STREAMS (TOTAL_HW_TX_QUEUES - 1)
  103. struct rxd_ops {
  104. int rxd_size;
  105. void (*rxd_init)(void *rxd, dma_addr_t next_dma_addr);
  106. void (*rxd_refill)(void *rxd, dma_addr_t addr, int len);
  107. int (*rxd_process)(void *rxd, struct ieee80211_rx_status *status,
  108. __le16 *qos, s8 *noise);
  109. };
  110. struct mwl8k_device_info {
  111. char *part_name;
  112. char *helper_image;
  113. char *fw_image_sta;
  114. char *fw_image_ap;
  115. struct rxd_ops *ap_rxd_ops;
  116. u32 fw_api_ap;
  117. };
  118. struct mwl8k_rx_queue {
  119. int rxd_count;
  120. /* hw receives here */
  121. int head;
  122. /* refill descs here */
  123. int tail;
  124. void *rxd;
  125. dma_addr_t rxd_dma;
  126. struct {
  127. struct sk_buff *skb;
  128. DEFINE_DMA_UNMAP_ADDR(dma);
  129. } *buf;
  130. };
  131. struct mwl8k_tx_queue {
  132. /* hw transmits here */
  133. int head;
  134. /* sw appends here */
  135. int tail;
  136. unsigned int len;
  137. struct mwl8k_tx_desc *txd;
  138. dma_addr_t txd_dma;
  139. struct sk_buff **skb;
  140. };
  141. enum {
  142. AMPDU_NO_STREAM,
  143. AMPDU_STREAM_NEW,
  144. AMPDU_STREAM_IN_PROGRESS,
  145. AMPDU_STREAM_ACTIVE,
  146. };
  147. struct mwl8k_ampdu_stream {
  148. struct ieee80211_sta *sta;
  149. u8 tid;
  150. u8 state;
  151. u8 idx;
  152. };
  153. struct mwl8k_priv {
  154. struct ieee80211_hw *hw;
  155. struct pci_dev *pdev;
  156. int irq;
  157. struct mwl8k_device_info *device_info;
  158. void __iomem *sram;
  159. void __iomem *regs;
  160. /* firmware */
  161. const struct firmware *fw_helper;
  162. const struct firmware *fw_ucode;
  163. /* hardware/firmware parameters */
  164. bool ap_fw;
  165. struct rxd_ops *rxd_ops;
  166. struct ieee80211_supported_band band_24;
  167. struct ieee80211_channel channels_24[14];
  168. struct ieee80211_rate rates_24[13];
  169. struct ieee80211_supported_band band_50;
  170. struct ieee80211_channel channels_50[4];
  171. struct ieee80211_rate rates_50[8];
  172. u32 ap_macids_supported;
  173. u32 sta_macids_supported;
  174. /* Ampdu stream information */
  175. u8 num_ampdu_queues;
  176. spinlock_t stream_lock;
  177. struct mwl8k_ampdu_stream ampdu[MWL8K_MAX_AMPDU_QUEUES];
  178. struct work_struct watchdog_ba_handle;
  179. /* firmware access */
  180. struct mutex fw_mutex;
  181. struct task_struct *fw_mutex_owner;
  182. struct task_struct *hw_restart_owner;
  183. int fw_mutex_depth;
  184. struct completion *hostcmd_wait;
  185. atomic_t watchdog_event_pending;
  186. /* lock held over TX and TX reap */
  187. spinlock_t tx_lock;
  188. /* TX quiesce completion, protected by fw_mutex and tx_lock */
  189. struct completion *tx_wait;
  190. /* List of interfaces. */
  191. u32 macids_used;
  192. struct list_head vif_list;
  193. /* power management status cookie from firmware */
  194. u32 *cookie;
  195. dma_addr_t cookie_dma;
  196. u16 num_mcaddrs;
  197. u8 hw_rev;
  198. u32 fw_rev;
  199. u32 caps;
  200. /*
  201. * Running count of TX packets in flight, to avoid
  202. * iterating over the transmit rings each time.
  203. */
  204. int pending_tx_pkts;
  205. struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
  206. struct mwl8k_tx_queue txq[MWL8K_MAX_TX_QUEUES];
  207. u32 txq_offset[MWL8K_MAX_TX_QUEUES];
  208. bool radio_on;
  209. bool radio_short_preamble;
  210. bool sniffer_enabled;
  211. bool wmm_enabled;
  212. /* XXX need to convert this to handle multiple interfaces */
  213. bool capture_beacon;
  214. u8 capture_bssid[ETH_ALEN];
  215. struct sk_buff *beacon_skb;
  216. /*
  217. * This FJ worker has to be global as it is scheduled from the
  218. * RX handler. At this point we don't know which interface it
  219. * belongs to until the list of bssids waiting to complete join
  220. * is checked.
  221. */
  222. struct work_struct finalize_join_worker;
  223. /* Tasklet to perform TX reclaim. */
  224. struct tasklet_struct poll_tx_task;
  225. /* Tasklet to perform RX. */
  226. struct tasklet_struct poll_rx_task;
  227. /* Most recently reported noise in dBm */
  228. s8 noise;
  229. /*
  230. * preserve the queue configurations so they can be restored if/when
  231. * the firmware image is swapped.
  232. */
  233. struct ieee80211_tx_queue_params wmm_params[MWL8K_TX_WMM_QUEUES];
  234. /* To perform the task of reloading the firmware */
  235. struct work_struct fw_reload;
  236. bool hw_restart_in_progress;
  237. /* async firmware loading state */
  238. unsigned fw_state;
  239. char *fw_pref;
  240. char *fw_alt;
  241. bool is_8764;
  242. struct completion firmware_loading_complete;
  243. /* bitmap of running BSSes */
  244. u32 running_bsses;
  245. };
  246. #define MAX_WEP_KEY_LEN 13
  247. #define NUM_WEP_KEYS 4
  248. /* Per interface specific private data */
  249. struct mwl8k_vif {
  250. struct list_head list;
  251. struct ieee80211_vif *vif;
  252. /* Firmware macid for this vif. */
  253. int macid;
  254. /* Non AMPDU sequence number assigned by driver. */
  255. u16 seqno;
  256. /* Saved WEP keys */
  257. struct {
  258. u8 enabled;
  259. u8 key[sizeof(struct ieee80211_key_conf) + MAX_WEP_KEY_LEN];
  260. } wep_key_conf[NUM_WEP_KEYS];
  261. /* BSSID */
  262. u8 bssid[ETH_ALEN];
  263. /* A flag to indicate is HW crypto is enabled for this bssid */
  264. bool is_hw_crypto_enabled;
  265. };
  266. #define MWL8K_VIF(_vif) ((struct mwl8k_vif *)&((_vif)->drv_priv))
  267. #define IEEE80211_KEY_CONF(_u8) ((struct ieee80211_key_conf *)(_u8))
  268. struct tx_traffic_info {
  269. u32 start_time;
  270. u32 pkts;
  271. };
  272. #define MWL8K_MAX_TID 8
  273. struct mwl8k_sta {
  274. /* Index into station database. Returned by UPDATE_STADB. */
  275. u8 peer_id;
  276. u8 is_ampdu_allowed;
  277. struct tx_traffic_info tx_stats[MWL8K_MAX_TID];
  278. };
  279. #define MWL8K_STA(_sta) ((struct mwl8k_sta *)&((_sta)->drv_priv))
  280. static const struct ieee80211_channel mwl8k_channels_24[] = {
  281. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2412, .hw_value = 1, },
  282. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2417, .hw_value = 2, },
  283. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2422, .hw_value = 3, },
  284. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2427, .hw_value = 4, },
  285. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2432, .hw_value = 5, },
  286. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2437, .hw_value = 6, },
  287. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2442, .hw_value = 7, },
  288. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2447, .hw_value = 8, },
  289. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2452, .hw_value = 9, },
  290. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2457, .hw_value = 10, },
  291. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2462, .hw_value = 11, },
  292. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2467, .hw_value = 12, },
  293. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2472, .hw_value = 13, },
  294. { .band = IEEE80211_BAND_2GHZ, .center_freq = 2484, .hw_value = 14, },
  295. };
  296. static const struct ieee80211_rate mwl8k_rates_24[] = {
  297. { .bitrate = 10, .hw_value = 2, },
  298. { .bitrate = 20, .hw_value = 4, },
  299. { .bitrate = 55, .hw_value = 11, },
  300. { .bitrate = 110, .hw_value = 22, },
  301. { .bitrate = 220, .hw_value = 44, },
  302. { .bitrate = 60, .hw_value = 12, },
  303. { .bitrate = 90, .hw_value = 18, },
  304. { .bitrate = 120, .hw_value = 24, },
  305. { .bitrate = 180, .hw_value = 36, },
  306. { .bitrate = 240, .hw_value = 48, },
  307. { .bitrate = 360, .hw_value = 72, },
  308. { .bitrate = 480, .hw_value = 96, },
  309. { .bitrate = 540, .hw_value = 108, },
  310. };
  311. static const struct ieee80211_channel mwl8k_channels_50[] = {
  312. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5180, .hw_value = 36, },
  313. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5200, .hw_value = 40, },
  314. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5220, .hw_value = 44, },
  315. { .band = IEEE80211_BAND_5GHZ, .center_freq = 5240, .hw_value = 48, },
  316. };
  317. static const struct ieee80211_rate mwl8k_rates_50[] = {
  318. { .bitrate = 60, .hw_value = 12, },
  319. { .bitrate = 90, .hw_value = 18, },
  320. { .bitrate = 120, .hw_value = 24, },
  321. { .bitrate = 180, .hw_value = 36, },
  322. { .bitrate = 240, .hw_value = 48, },
  323. { .bitrate = 360, .hw_value = 72, },
  324. { .bitrate = 480, .hw_value = 96, },
  325. { .bitrate = 540, .hw_value = 108, },
  326. };
  327. /* Set or get info from Firmware */
  328. #define MWL8K_CMD_GET 0x0000
  329. #define MWL8K_CMD_SET 0x0001
  330. #define MWL8K_CMD_SET_LIST 0x0002
  331. /* Firmware command codes */
  332. #define MWL8K_CMD_CODE_DNLD 0x0001
  333. #define MWL8K_CMD_GET_HW_SPEC 0x0003
  334. #define MWL8K_CMD_SET_HW_SPEC 0x0004
  335. #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
  336. #define MWL8K_CMD_GET_STAT 0x0014
  337. #define MWL8K_CMD_RADIO_CONTROL 0x001c
  338. #define MWL8K_CMD_RF_TX_POWER 0x001e
  339. #define MWL8K_CMD_TX_POWER 0x001f
  340. #define MWL8K_CMD_RF_ANTENNA 0x0020
  341. #define MWL8K_CMD_SET_BEACON 0x0100 /* per-vif */
  342. #define MWL8K_CMD_SET_PRE_SCAN 0x0107
  343. #define MWL8K_CMD_SET_POST_SCAN 0x0108
  344. #define MWL8K_CMD_SET_RF_CHANNEL 0x010a
  345. #define MWL8K_CMD_SET_AID 0x010d
  346. #define MWL8K_CMD_SET_RATE 0x0110
  347. #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
  348. #define MWL8K_CMD_RTS_THRESHOLD 0x0113
  349. #define MWL8K_CMD_SET_SLOT 0x0114
  350. #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
  351. #define MWL8K_CMD_SET_WMM_MODE 0x0123
  352. #define MWL8K_CMD_MIMO_CONFIG 0x0125
  353. #define MWL8K_CMD_USE_FIXED_RATE 0x0126
  354. #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
  355. #define MWL8K_CMD_SET_MAC_ADDR 0x0202 /* per-vif */
  356. #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
  357. #define MWL8K_CMD_GET_WATCHDOG_BITMAP 0x0205
  358. #define MWL8K_CMD_DEL_MAC_ADDR 0x0206 /* per-vif */
  359. #define MWL8K_CMD_BSS_START 0x1100 /* per-vif */
  360. #define MWL8K_CMD_SET_NEW_STN 0x1111 /* per-vif */
  361. #define MWL8K_CMD_UPDATE_ENCRYPTION 0x1122 /* per-vif */
  362. #define MWL8K_CMD_UPDATE_STADB 0x1123
  363. #define MWL8K_CMD_BASTREAM 0x1125
  364. static const char *mwl8k_cmd_name(__le16 cmd, char *buf, int bufsize)
  365. {
  366. u16 command = le16_to_cpu(cmd);
  367. #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
  368. snprintf(buf, bufsize, "%s", #x);\
  369. return buf;\
  370. } while (0)
  371. switch (command & ~0x8000) {
  372. MWL8K_CMDNAME(CODE_DNLD);
  373. MWL8K_CMDNAME(GET_HW_SPEC);
  374. MWL8K_CMDNAME(SET_HW_SPEC);
  375. MWL8K_CMDNAME(MAC_MULTICAST_ADR);
  376. MWL8K_CMDNAME(GET_STAT);
  377. MWL8K_CMDNAME(RADIO_CONTROL);
  378. MWL8K_CMDNAME(RF_TX_POWER);
  379. MWL8K_CMDNAME(TX_POWER);
  380. MWL8K_CMDNAME(RF_ANTENNA);
  381. MWL8K_CMDNAME(SET_BEACON);
  382. MWL8K_CMDNAME(SET_PRE_SCAN);
  383. MWL8K_CMDNAME(SET_POST_SCAN);
  384. MWL8K_CMDNAME(SET_RF_CHANNEL);
  385. MWL8K_CMDNAME(SET_AID);
  386. MWL8K_CMDNAME(SET_RATE);
  387. MWL8K_CMDNAME(SET_FINALIZE_JOIN);
  388. MWL8K_CMDNAME(RTS_THRESHOLD);
  389. MWL8K_CMDNAME(SET_SLOT);
  390. MWL8K_CMDNAME(SET_EDCA_PARAMS);
  391. MWL8K_CMDNAME(SET_WMM_MODE);
  392. MWL8K_CMDNAME(MIMO_CONFIG);
  393. MWL8K_CMDNAME(USE_FIXED_RATE);
  394. MWL8K_CMDNAME(ENABLE_SNIFFER);
  395. MWL8K_CMDNAME(SET_MAC_ADDR);
  396. MWL8K_CMDNAME(SET_RATEADAPT_MODE);
  397. MWL8K_CMDNAME(BSS_START);
  398. MWL8K_CMDNAME(SET_NEW_STN);
  399. MWL8K_CMDNAME(UPDATE_ENCRYPTION);
  400. MWL8K_CMDNAME(UPDATE_STADB);
  401. MWL8K_CMDNAME(BASTREAM);
  402. MWL8K_CMDNAME(GET_WATCHDOG_BITMAP);
  403. default:
  404. snprintf(buf, bufsize, "0x%x", cmd);
  405. }
  406. #undef MWL8K_CMDNAME
  407. return buf;
  408. }
  409. /* Hardware and firmware reset */
  410. static void mwl8k_hw_reset(struct mwl8k_priv *priv)
  411. {
  412. iowrite32(MWL8K_H2A_INT_RESET,
  413. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  414. iowrite32(MWL8K_H2A_INT_RESET,
  415. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  416. msleep(20);
  417. }
  418. /* Release fw image */
  419. static void mwl8k_release_fw(const struct firmware **fw)
  420. {
  421. if (*fw == NULL)
  422. return;
  423. release_firmware(*fw);
  424. *fw = NULL;
  425. }
  426. static void mwl8k_release_firmware(struct mwl8k_priv *priv)
  427. {
  428. mwl8k_release_fw(&priv->fw_ucode);
  429. mwl8k_release_fw(&priv->fw_helper);
  430. }
  431. /* states for asynchronous f/w loading */
  432. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context);
  433. enum {
  434. FW_STATE_INIT = 0,
  435. FW_STATE_LOADING_PREF,
  436. FW_STATE_LOADING_ALT,
  437. FW_STATE_ERROR,
  438. };
  439. /* Request fw image */
  440. static int mwl8k_request_fw(struct mwl8k_priv *priv,
  441. const char *fname, const struct firmware **fw,
  442. bool nowait)
  443. {
  444. /* release current image */
  445. if (*fw != NULL)
  446. mwl8k_release_fw(fw);
  447. if (nowait)
  448. return request_firmware_nowait(THIS_MODULE, 1, fname,
  449. &priv->pdev->dev, GFP_KERNEL,
  450. priv, mwl8k_fw_state_machine);
  451. else
  452. return request_firmware(fw, fname, &priv->pdev->dev);
  453. }
  454. static int mwl8k_request_firmware(struct mwl8k_priv *priv, char *fw_image,
  455. bool nowait)
  456. {
  457. struct mwl8k_device_info *di = priv->device_info;
  458. int rc;
  459. if (di->helper_image != NULL) {
  460. if (nowait)
  461. rc = mwl8k_request_fw(priv, di->helper_image,
  462. &priv->fw_helper, true);
  463. else
  464. rc = mwl8k_request_fw(priv, di->helper_image,
  465. &priv->fw_helper, false);
  466. if (rc)
  467. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  468. pci_name(priv->pdev), di->helper_image);
  469. if (rc || nowait)
  470. return rc;
  471. }
  472. if (nowait) {
  473. /*
  474. * if we get here, no helper image is needed. Skip the
  475. * FW_STATE_INIT state.
  476. */
  477. priv->fw_state = FW_STATE_LOADING_PREF;
  478. rc = mwl8k_request_fw(priv, fw_image,
  479. &priv->fw_ucode,
  480. true);
  481. } else
  482. rc = mwl8k_request_fw(priv, fw_image,
  483. &priv->fw_ucode, false);
  484. if (rc) {
  485. printk(KERN_ERR "%s: Error requesting firmware file %s\n",
  486. pci_name(priv->pdev), fw_image);
  487. mwl8k_release_fw(&priv->fw_helper);
  488. return rc;
  489. }
  490. return 0;
  491. }
  492. struct mwl8k_cmd_pkt {
  493. __le16 code;
  494. __le16 length;
  495. __u8 seq_num;
  496. __u8 macid;
  497. __le16 result;
  498. char payload[0];
  499. } __packed;
  500. /*
  501. * Firmware loading.
  502. */
  503. static int
  504. mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
  505. {
  506. void __iomem *regs = priv->regs;
  507. dma_addr_t dma_addr;
  508. int loops;
  509. dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
  510. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  511. return -ENOMEM;
  512. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  513. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  514. iowrite32(MWL8K_H2A_INT_DOORBELL,
  515. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  516. iowrite32(MWL8K_H2A_INT_DUMMY,
  517. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  518. loops = 1000;
  519. do {
  520. u32 int_code;
  521. if (priv->is_8764) {
  522. int_code = ioread32(regs +
  523. MWL8K_HIU_H2A_INTERRUPT_STATUS);
  524. if (int_code == 0)
  525. break;
  526. } else {
  527. int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
  528. if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
  529. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  530. break;
  531. }
  532. }
  533. cond_resched();
  534. udelay(1);
  535. } while (--loops);
  536. pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
  537. return loops ? 0 : -ETIMEDOUT;
  538. }
  539. static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
  540. const u8 *data, size_t length)
  541. {
  542. struct mwl8k_cmd_pkt *cmd;
  543. int done;
  544. int rc = 0;
  545. cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
  546. if (cmd == NULL)
  547. return -ENOMEM;
  548. cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
  549. cmd->seq_num = 0;
  550. cmd->macid = 0;
  551. cmd->result = 0;
  552. done = 0;
  553. while (length) {
  554. int block_size = length > 256 ? 256 : length;
  555. memcpy(cmd->payload, data + done, block_size);
  556. cmd->length = cpu_to_le16(block_size);
  557. rc = mwl8k_send_fw_load_cmd(priv, cmd,
  558. sizeof(*cmd) + block_size);
  559. if (rc)
  560. break;
  561. done += block_size;
  562. length -= block_size;
  563. }
  564. if (!rc) {
  565. cmd->length = 0;
  566. rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
  567. }
  568. kfree(cmd);
  569. return rc;
  570. }
  571. static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
  572. const u8 *data, size_t length)
  573. {
  574. unsigned char *buffer;
  575. int may_continue, rc = 0;
  576. u32 done, prev_block_size;
  577. buffer = kmalloc(1024, GFP_KERNEL);
  578. if (buffer == NULL)
  579. return -ENOMEM;
  580. done = 0;
  581. prev_block_size = 0;
  582. may_continue = 1000;
  583. while (may_continue > 0) {
  584. u32 block_size;
  585. block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
  586. if (block_size & 1) {
  587. block_size &= ~1;
  588. may_continue--;
  589. } else {
  590. done += prev_block_size;
  591. length -= prev_block_size;
  592. }
  593. if (block_size > 1024 || block_size > length) {
  594. rc = -EOVERFLOW;
  595. break;
  596. }
  597. if (length == 0) {
  598. rc = 0;
  599. break;
  600. }
  601. if (block_size == 0) {
  602. rc = -EPROTO;
  603. may_continue--;
  604. udelay(1);
  605. continue;
  606. }
  607. prev_block_size = block_size;
  608. memcpy(buffer, data + done, block_size);
  609. rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
  610. if (rc)
  611. break;
  612. }
  613. if (!rc && length != 0)
  614. rc = -EREMOTEIO;
  615. kfree(buffer);
  616. return rc;
  617. }
  618. static int mwl8k_load_firmware(struct ieee80211_hw *hw)
  619. {
  620. struct mwl8k_priv *priv = hw->priv;
  621. const struct firmware *fw = priv->fw_ucode;
  622. int rc;
  623. int loops;
  624. if (!memcmp(fw->data, "\x01\x00\x00\x00", 4) && !priv->is_8764) {
  625. const struct firmware *helper = priv->fw_helper;
  626. if (helper == NULL) {
  627. printk(KERN_ERR "%s: helper image needed but none "
  628. "given\n", pci_name(priv->pdev));
  629. return -EINVAL;
  630. }
  631. rc = mwl8k_load_fw_image(priv, helper->data, helper->size);
  632. if (rc) {
  633. printk(KERN_ERR "%s: unable to load firmware "
  634. "helper image\n", pci_name(priv->pdev));
  635. return rc;
  636. }
  637. msleep(20);
  638. rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
  639. } else {
  640. if (priv->is_8764)
  641. rc = mwl8k_feed_fw_image(priv, fw->data, fw->size);
  642. else
  643. rc = mwl8k_load_fw_image(priv, fw->data, fw->size);
  644. }
  645. if (rc) {
  646. printk(KERN_ERR "%s: unable to load firmware image\n",
  647. pci_name(priv->pdev));
  648. return rc;
  649. }
  650. iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
  651. loops = 500000;
  652. do {
  653. u32 ready_code;
  654. ready_code = ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  655. if (ready_code == MWL8K_FWAP_READY) {
  656. priv->ap_fw = true;
  657. break;
  658. } else if (ready_code == MWL8K_FWSTA_READY) {
  659. priv->ap_fw = false;
  660. break;
  661. }
  662. cond_resched();
  663. udelay(1);
  664. } while (--loops);
  665. return loops ? 0 : -ETIMEDOUT;
  666. }
  667. /* DMA header used by firmware and hardware. */
  668. struct mwl8k_dma_data {
  669. __le16 fwlen;
  670. struct ieee80211_hdr wh;
  671. char data[0];
  672. } __packed;
  673. /* Routines to add/remove DMA header from skb. */
  674. static inline void mwl8k_remove_dma_header(struct sk_buff *skb, __le16 qos)
  675. {
  676. struct mwl8k_dma_data *tr;
  677. int hdrlen;
  678. tr = (struct mwl8k_dma_data *)skb->data;
  679. hdrlen = ieee80211_hdrlen(tr->wh.frame_control);
  680. if (hdrlen != sizeof(tr->wh)) {
  681. if (ieee80211_is_data_qos(tr->wh.frame_control)) {
  682. memmove(tr->data - hdrlen, &tr->wh, hdrlen - 2);
  683. *((__le16 *)(tr->data - 2)) = qos;
  684. } else {
  685. memmove(tr->data - hdrlen, &tr->wh, hdrlen);
  686. }
  687. }
  688. if (hdrlen != sizeof(*tr))
  689. skb_pull(skb, sizeof(*tr) - hdrlen);
  690. }
  691. #define REDUCED_TX_HEADROOM 8
  692. static void
  693. mwl8k_add_dma_header(struct mwl8k_priv *priv, struct sk_buff *skb,
  694. int head_pad, int tail_pad)
  695. {
  696. struct ieee80211_hdr *wh;
  697. int hdrlen;
  698. int reqd_hdrlen;
  699. struct mwl8k_dma_data *tr;
  700. /*
  701. * Add a firmware DMA header; the firmware requires that we
  702. * present a 2-byte payload length followed by a 4-address
  703. * header (without QoS field), followed (optionally) by any
  704. * WEP/ExtIV header (but only filled in for CCMP).
  705. */
  706. wh = (struct ieee80211_hdr *)skb->data;
  707. hdrlen = ieee80211_hdrlen(wh->frame_control);
  708. /*
  709. * Check if skb_resize is required because of
  710. * tx_headroom adjustment.
  711. */
  712. if (priv->ap_fw && (hdrlen < (sizeof(struct ieee80211_cts)
  713. + REDUCED_TX_HEADROOM))) {
  714. if (pskb_expand_head(skb, REDUCED_TX_HEADROOM, 0, GFP_ATOMIC)) {
  715. wiphy_err(priv->hw->wiphy,
  716. "Failed to reallocate TX buffer\n");
  717. return;
  718. }
  719. skb->truesize += REDUCED_TX_HEADROOM;
  720. }
  721. reqd_hdrlen = sizeof(*tr) + head_pad;
  722. if (hdrlen != reqd_hdrlen)
  723. skb_push(skb, reqd_hdrlen - hdrlen);
  724. if (ieee80211_is_data_qos(wh->frame_control))
  725. hdrlen -= IEEE80211_QOS_CTL_LEN;
  726. tr = (struct mwl8k_dma_data *)skb->data;
  727. if (wh != &tr->wh)
  728. memmove(&tr->wh, wh, hdrlen);
  729. if (hdrlen != sizeof(tr->wh))
  730. memset(((void *)&tr->wh) + hdrlen, 0, sizeof(tr->wh) - hdrlen);
  731. /*
  732. * Firmware length is the length of the fully formed "802.11
  733. * payload". That is, everything except for the 802.11 header.
  734. * This includes all crypto material including the MIC.
  735. */
  736. tr->fwlen = cpu_to_le16(skb->len - sizeof(*tr) + tail_pad);
  737. }
  738. static void mwl8k_encapsulate_tx_frame(struct mwl8k_priv *priv,
  739. struct sk_buff *skb)
  740. {
  741. struct ieee80211_hdr *wh;
  742. struct ieee80211_tx_info *tx_info;
  743. struct ieee80211_key_conf *key_conf;
  744. int data_pad;
  745. int head_pad = 0;
  746. wh = (struct ieee80211_hdr *)skb->data;
  747. tx_info = IEEE80211_SKB_CB(skb);
  748. key_conf = NULL;
  749. if (ieee80211_is_data(wh->frame_control))
  750. key_conf = tx_info->control.hw_key;
  751. /*
  752. * Make sure the packet header is in the DMA header format (4-address
  753. * without QoS), and add head & tail padding when HW crypto is enabled.
  754. *
  755. * We have the following trailer padding requirements:
  756. * - WEP: 4 trailer bytes (ICV)
  757. * - TKIP: 12 trailer bytes (8 MIC + 4 ICV)
  758. * - CCMP: 8 trailer bytes (MIC)
  759. */
  760. data_pad = 0;
  761. if (key_conf != NULL) {
  762. head_pad = key_conf->iv_len;
  763. switch (key_conf->cipher) {
  764. case WLAN_CIPHER_SUITE_WEP40:
  765. case WLAN_CIPHER_SUITE_WEP104:
  766. data_pad = 4;
  767. break;
  768. case WLAN_CIPHER_SUITE_TKIP:
  769. data_pad = 12;
  770. break;
  771. case WLAN_CIPHER_SUITE_CCMP:
  772. data_pad = 8;
  773. break;
  774. }
  775. }
  776. mwl8k_add_dma_header(priv, skb, head_pad, data_pad);
  777. }
  778. /*
  779. * Packet reception for 88w8366/88w8764 AP firmware.
  780. */
  781. struct mwl8k_rxd_ap {
  782. __le16 pkt_len;
  783. __u8 sq2;
  784. __u8 rate;
  785. __le32 pkt_phys_addr;
  786. __le32 next_rxd_phys_addr;
  787. __le16 qos_control;
  788. __le16 htsig2;
  789. __le32 hw_rssi_info;
  790. __le32 hw_noise_floor_info;
  791. __u8 noise_floor;
  792. __u8 pad0[3];
  793. __u8 rssi;
  794. __u8 rx_status;
  795. __u8 channel;
  796. __u8 rx_ctrl;
  797. } __packed;
  798. #define MWL8K_AP_RATE_INFO_MCS_FORMAT 0x80
  799. #define MWL8K_AP_RATE_INFO_40MHZ 0x40
  800. #define MWL8K_AP_RATE_INFO_RATEID(x) ((x) & 0x3f)
  801. #define MWL8K_AP_RX_CTRL_OWNED_BY_HOST 0x80
  802. /* 8366/8764 AP rx_status bits */
  803. #define MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK 0x80
  804. #define MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR 0xFF
  805. #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR 0x02
  806. #define MWL8K_AP_RXSTAT_WEP_DECRYPT_ICV_ERR 0x04
  807. #define MWL8K_AP_RXSTAT_TKIP_DECRYPT_ICV_ERR 0x08
  808. static void mwl8k_rxd_ap_init(void *_rxd, dma_addr_t next_dma_addr)
  809. {
  810. struct mwl8k_rxd_ap *rxd = _rxd;
  811. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  812. rxd->rx_ctrl = MWL8K_AP_RX_CTRL_OWNED_BY_HOST;
  813. }
  814. static void mwl8k_rxd_ap_refill(void *_rxd, dma_addr_t addr, int len)
  815. {
  816. struct mwl8k_rxd_ap *rxd = _rxd;
  817. rxd->pkt_len = cpu_to_le16(len);
  818. rxd->pkt_phys_addr = cpu_to_le32(addr);
  819. wmb();
  820. rxd->rx_ctrl = 0;
  821. }
  822. static int
  823. mwl8k_rxd_ap_process(void *_rxd, struct ieee80211_rx_status *status,
  824. __le16 *qos, s8 *noise)
  825. {
  826. struct mwl8k_rxd_ap *rxd = _rxd;
  827. if (!(rxd->rx_ctrl & MWL8K_AP_RX_CTRL_OWNED_BY_HOST))
  828. return -1;
  829. rmb();
  830. memset(status, 0, sizeof(*status));
  831. status->signal = -rxd->rssi;
  832. *noise = -rxd->noise_floor;
  833. if (rxd->rate & MWL8K_AP_RATE_INFO_MCS_FORMAT) {
  834. status->flag |= RX_FLAG_HT;
  835. if (rxd->rate & MWL8K_AP_RATE_INFO_40MHZ)
  836. status->flag |= RX_FLAG_40MHZ;
  837. status->rate_idx = MWL8K_AP_RATE_INFO_RATEID(rxd->rate);
  838. } else {
  839. int i;
  840. for (i = 0; i < ARRAY_SIZE(mwl8k_rates_24); i++) {
  841. if (mwl8k_rates_24[i].hw_value == rxd->rate) {
  842. status->rate_idx = i;
  843. break;
  844. }
  845. }
  846. }
  847. if (rxd->channel > 14) {
  848. status->band = IEEE80211_BAND_5GHZ;
  849. if (!(status->flag & RX_FLAG_HT))
  850. status->rate_idx -= 5;
  851. } else {
  852. status->band = IEEE80211_BAND_2GHZ;
  853. }
  854. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  855. status->band);
  856. *qos = rxd->qos_control;
  857. if ((rxd->rx_status != MWL8K_AP_RXSTAT_GENERAL_DECRYPT_ERR) &&
  858. (rxd->rx_status & MWL8K_AP_RXSTAT_DECRYPT_ERR_MASK) &&
  859. (rxd->rx_status & MWL8K_AP_RXSTAT_TKIP_DECRYPT_MIC_ERR))
  860. status->flag |= RX_FLAG_MMIC_ERROR;
  861. return le16_to_cpu(rxd->pkt_len);
  862. }
  863. static struct rxd_ops rxd_ap_ops = {
  864. .rxd_size = sizeof(struct mwl8k_rxd_ap),
  865. .rxd_init = mwl8k_rxd_ap_init,
  866. .rxd_refill = mwl8k_rxd_ap_refill,
  867. .rxd_process = mwl8k_rxd_ap_process,
  868. };
  869. /*
  870. * Packet reception for STA firmware.
  871. */
  872. struct mwl8k_rxd_sta {
  873. __le16 pkt_len;
  874. __u8 link_quality;
  875. __u8 noise_level;
  876. __le32 pkt_phys_addr;
  877. __le32 next_rxd_phys_addr;
  878. __le16 qos_control;
  879. __le16 rate_info;
  880. __le32 pad0[4];
  881. __u8 rssi;
  882. __u8 channel;
  883. __le16 pad1;
  884. __u8 rx_ctrl;
  885. __u8 rx_status;
  886. __u8 pad2[2];
  887. } __packed;
  888. #define MWL8K_STA_RATE_INFO_SHORTPRE 0x8000
  889. #define MWL8K_STA_RATE_INFO_ANTSELECT(x) (((x) >> 11) & 0x3)
  890. #define MWL8K_STA_RATE_INFO_RATEID(x) (((x) >> 3) & 0x3f)
  891. #define MWL8K_STA_RATE_INFO_40MHZ 0x0004
  892. #define MWL8K_STA_RATE_INFO_SHORTGI 0x0002
  893. #define MWL8K_STA_RATE_INFO_MCS_FORMAT 0x0001
  894. #define MWL8K_STA_RX_CTRL_OWNED_BY_HOST 0x02
  895. #define MWL8K_STA_RX_CTRL_DECRYPT_ERROR 0x04
  896. /* ICV=0 or MIC=1 */
  897. #define MWL8K_STA_RX_CTRL_DEC_ERR_TYPE 0x08
  898. /* Key is uploaded only in failure case */
  899. #define MWL8K_STA_RX_CTRL_KEY_INDEX 0x30
  900. static void mwl8k_rxd_sta_init(void *_rxd, dma_addr_t next_dma_addr)
  901. {
  902. struct mwl8k_rxd_sta *rxd = _rxd;
  903. rxd->next_rxd_phys_addr = cpu_to_le32(next_dma_addr);
  904. rxd->rx_ctrl = MWL8K_STA_RX_CTRL_OWNED_BY_HOST;
  905. }
  906. static void mwl8k_rxd_sta_refill(void *_rxd, dma_addr_t addr, int len)
  907. {
  908. struct mwl8k_rxd_sta *rxd = _rxd;
  909. rxd->pkt_len = cpu_to_le16(len);
  910. rxd->pkt_phys_addr = cpu_to_le32(addr);
  911. wmb();
  912. rxd->rx_ctrl = 0;
  913. }
  914. static int
  915. mwl8k_rxd_sta_process(void *_rxd, struct ieee80211_rx_status *status,
  916. __le16 *qos, s8 *noise)
  917. {
  918. struct mwl8k_rxd_sta *rxd = _rxd;
  919. u16 rate_info;
  920. if (!(rxd->rx_ctrl & MWL8K_STA_RX_CTRL_OWNED_BY_HOST))
  921. return -1;
  922. rmb();
  923. rate_info = le16_to_cpu(rxd->rate_info);
  924. memset(status, 0, sizeof(*status));
  925. status->signal = -rxd->rssi;
  926. *noise = -rxd->noise_level;
  927. status->antenna = MWL8K_STA_RATE_INFO_ANTSELECT(rate_info);
  928. status->rate_idx = MWL8K_STA_RATE_INFO_RATEID(rate_info);
  929. if (rate_info & MWL8K_STA_RATE_INFO_SHORTPRE)
  930. status->flag |= RX_FLAG_SHORTPRE;
  931. if (rate_info & MWL8K_STA_RATE_INFO_40MHZ)
  932. status->flag |= RX_FLAG_40MHZ;
  933. if (rate_info & MWL8K_STA_RATE_INFO_SHORTGI)
  934. status->flag |= RX_FLAG_SHORT_GI;
  935. if (rate_info & MWL8K_STA_RATE_INFO_MCS_FORMAT)
  936. status->flag |= RX_FLAG_HT;
  937. if (rxd->channel > 14) {
  938. status->band = IEEE80211_BAND_5GHZ;
  939. if (!(status->flag & RX_FLAG_HT))
  940. status->rate_idx -= 5;
  941. } else {
  942. status->band = IEEE80211_BAND_2GHZ;
  943. }
  944. status->freq = ieee80211_channel_to_frequency(rxd->channel,
  945. status->band);
  946. *qos = rxd->qos_control;
  947. if ((rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DECRYPT_ERROR) &&
  948. (rxd->rx_ctrl & MWL8K_STA_RX_CTRL_DEC_ERR_TYPE))
  949. status->flag |= RX_FLAG_MMIC_ERROR;
  950. return le16_to_cpu(rxd->pkt_len);
  951. }
  952. static struct rxd_ops rxd_sta_ops = {
  953. .rxd_size = sizeof(struct mwl8k_rxd_sta),
  954. .rxd_init = mwl8k_rxd_sta_init,
  955. .rxd_refill = mwl8k_rxd_sta_refill,
  956. .rxd_process = mwl8k_rxd_sta_process,
  957. };
  958. #define MWL8K_RX_DESCS 256
  959. #define MWL8K_RX_MAXSZ 3800
  960. static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
  961. {
  962. struct mwl8k_priv *priv = hw->priv;
  963. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  964. int size;
  965. int i;
  966. rxq->rxd_count = 0;
  967. rxq->head = 0;
  968. rxq->tail = 0;
  969. size = MWL8K_RX_DESCS * priv->rxd_ops->rxd_size;
  970. rxq->rxd = pci_alloc_consistent(priv->pdev, size, &rxq->rxd_dma);
  971. if (rxq->rxd == NULL) {
  972. wiphy_err(hw->wiphy, "failed to alloc RX descriptors\n");
  973. return -ENOMEM;
  974. }
  975. memset(rxq->rxd, 0, size);
  976. rxq->buf = kcalloc(MWL8K_RX_DESCS, sizeof(*rxq->buf), GFP_KERNEL);
  977. if (rxq->buf == NULL) {
  978. pci_free_consistent(priv->pdev, size, rxq->rxd, rxq->rxd_dma);
  979. return -ENOMEM;
  980. }
  981. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  982. int desc_size;
  983. void *rxd;
  984. int nexti;
  985. dma_addr_t next_dma_addr;
  986. desc_size = priv->rxd_ops->rxd_size;
  987. rxd = rxq->rxd + (i * priv->rxd_ops->rxd_size);
  988. nexti = i + 1;
  989. if (nexti == MWL8K_RX_DESCS)
  990. nexti = 0;
  991. next_dma_addr = rxq->rxd_dma + (nexti * desc_size);
  992. priv->rxd_ops->rxd_init(rxd, next_dma_addr);
  993. }
  994. return 0;
  995. }
  996. static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
  997. {
  998. struct mwl8k_priv *priv = hw->priv;
  999. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1000. int refilled;
  1001. refilled = 0;
  1002. while (rxq->rxd_count < MWL8K_RX_DESCS && limit--) {
  1003. struct sk_buff *skb;
  1004. dma_addr_t addr;
  1005. int rx;
  1006. void *rxd;
  1007. skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
  1008. if (skb == NULL)
  1009. break;
  1010. addr = pci_map_single(priv->pdev, skb->data,
  1011. MWL8K_RX_MAXSZ, DMA_FROM_DEVICE);
  1012. rxq->rxd_count++;
  1013. rx = rxq->tail++;
  1014. if (rxq->tail == MWL8K_RX_DESCS)
  1015. rxq->tail = 0;
  1016. rxq->buf[rx].skb = skb;
  1017. dma_unmap_addr_set(&rxq->buf[rx], dma, addr);
  1018. rxd = rxq->rxd + (rx * priv->rxd_ops->rxd_size);
  1019. priv->rxd_ops->rxd_refill(rxd, addr, MWL8K_RX_MAXSZ);
  1020. refilled++;
  1021. }
  1022. return refilled;
  1023. }
  1024. /* Must be called only when the card's reception is completely halted */
  1025. static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
  1026. {
  1027. struct mwl8k_priv *priv = hw->priv;
  1028. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1029. int i;
  1030. if (rxq->rxd == NULL)
  1031. return;
  1032. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  1033. if (rxq->buf[i].skb != NULL) {
  1034. pci_unmap_single(priv->pdev,
  1035. dma_unmap_addr(&rxq->buf[i], dma),
  1036. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1037. dma_unmap_addr_set(&rxq->buf[i], dma, 0);
  1038. kfree_skb(rxq->buf[i].skb);
  1039. rxq->buf[i].skb = NULL;
  1040. }
  1041. }
  1042. kfree(rxq->buf);
  1043. rxq->buf = NULL;
  1044. pci_free_consistent(priv->pdev,
  1045. MWL8K_RX_DESCS * priv->rxd_ops->rxd_size,
  1046. rxq->rxd, rxq->rxd_dma);
  1047. rxq->rxd = NULL;
  1048. }
  1049. /*
  1050. * Scan a list of BSSIDs to process for finalize join.
  1051. * Allows for extension to process multiple BSSIDs.
  1052. */
  1053. static inline int
  1054. mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
  1055. {
  1056. return priv->capture_beacon &&
  1057. ieee80211_is_beacon(wh->frame_control) &&
  1058. ether_addr_equal(wh->addr3, priv->capture_bssid);
  1059. }
  1060. static inline void mwl8k_save_beacon(struct ieee80211_hw *hw,
  1061. struct sk_buff *skb)
  1062. {
  1063. struct mwl8k_priv *priv = hw->priv;
  1064. priv->capture_beacon = false;
  1065. memset(priv->capture_bssid, 0, ETH_ALEN);
  1066. /*
  1067. * Use GFP_ATOMIC as rxq_process is called from
  1068. * the primary interrupt handler, memory allocation call
  1069. * must not sleep.
  1070. */
  1071. priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
  1072. if (priv->beacon_skb != NULL)
  1073. ieee80211_queue_work(hw, &priv->finalize_join_worker);
  1074. }
  1075. static inline struct mwl8k_vif *mwl8k_find_vif_bss(struct list_head *vif_list,
  1076. u8 *bssid)
  1077. {
  1078. struct mwl8k_vif *mwl8k_vif;
  1079. list_for_each_entry(mwl8k_vif,
  1080. vif_list, list) {
  1081. if (memcmp(bssid, mwl8k_vif->bssid,
  1082. ETH_ALEN) == 0)
  1083. return mwl8k_vif;
  1084. }
  1085. return NULL;
  1086. }
  1087. static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
  1088. {
  1089. struct mwl8k_priv *priv = hw->priv;
  1090. struct mwl8k_vif *mwl8k_vif = NULL;
  1091. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  1092. int processed;
  1093. processed = 0;
  1094. while (rxq->rxd_count && limit--) {
  1095. struct sk_buff *skb;
  1096. void *rxd;
  1097. int pkt_len;
  1098. struct ieee80211_rx_status status;
  1099. struct ieee80211_hdr *wh;
  1100. __le16 qos;
  1101. skb = rxq->buf[rxq->head].skb;
  1102. if (skb == NULL)
  1103. break;
  1104. rxd = rxq->rxd + (rxq->head * priv->rxd_ops->rxd_size);
  1105. pkt_len = priv->rxd_ops->rxd_process(rxd, &status, &qos,
  1106. &priv->noise);
  1107. if (pkt_len < 0)
  1108. break;
  1109. rxq->buf[rxq->head].skb = NULL;
  1110. pci_unmap_single(priv->pdev,
  1111. dma_unmap_addr(&rxq->buf[rxq->head], dma),
  1112. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  1113. dma_unmap_addr_set(&rxq->buf[rxq->head], dma, 0);
  1114. rxq->head++;
  1115. if (rxq->head == MWL8K_RX_DESCS)
  1116. rxq->head = 0;
  1117. rxq->rxd_count--;
  1118. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1119. /*
  1120. * Check for a pending join operation. Save a
  1121. * copy of the beacon and schedule a tasklet to
  1122. * send a FINALIZE_JOIN command to the firmware.
  1123. */
  1124. if (mwl8k_capture_bssid(priv, (void *)skb->data))
  1125. mwl8k_save_beacon(hw, skb);
  1126. if (ieee80211_has_protected(wh->frame_control)) {
  1127. /* Check if hw crypto has been enabled for
  1128. * this bss. If yes, set the status flags
  1129. * accordingly
  1130. */
  1131. mwl8k_vif = mwl8k_find_vif_bss(&priv->vif_list,
  1132. wh->addr1);
  1133. if (mwl8k_vif != NULL &&
  1134. mwl8k_vif->is_hw_crypto_enabled) {
  1135. /*
  1136. * When MMIC ERROR is encountered
  1137. * by the firmware, payload is
  1138. * dropped and only 32 bytes of
  1139. * mwl8k Firmware header is sent
  1140. * to the host.
  1141. *
  1142. * We need to add four bytes of
  1143. * key information. In it
  1144. * MAC80211 expects keyidx set to
  1145. * 0 for triggering Counter
  1146. * Measure of MMIC failure.
  1147. */
  1148. if (status.flag & RX_FLAG_MMIC_ERROR) {
  1149. struct mwl8k_dma_data *tr;
  1150. tr = (struct mwl8k_dma_data *)skb->data;
  1151. memset((void *)&(tr->data), 0, 4);
  1152. pkt_len += 4;
  1153. }
  1154. if (!ieee80211_is_auth(wh->frame_control))
  1155. status.flag |= RX_FLAG_IV_STRIPPED |
  1156. RX_FLAG_DECRYPTED |
  1157. RX_FLAG_MMIC_STRIPPED;
  1158. }
  1159. }
  1160. skb_put(skb, pkt_len);
  1161. mwl8k_remove_dma_header(skb, qos);
  1162. memcpy(IEEE80211_SKB_RXCB(skb), &status, sizeof(status));
  1163. ieee80211_rx_irqsafe(hw, skb);
  1164. processed++;
  1165. }
  1166. return processed;
  1167. }
  1168. /*
  1169. * Packet transmission.
  1170. */
  1171. #define MWL8K_TXD_STATUS_OK 0x00000001
  1172. #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
  1173. #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
  1174. #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
  1175. #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
  1176. #define MWL8K_QOS_QLEN_UNSPEC 0xff00
  1177. #define MWL8K_QOS_ACK_POLICY_MASK 0x0060
  1178. #define MWL8K_QOS_ACK_POLICY_NORMAL 0x0000
  1179. #define MWL8K_QOS_ACK_POLICY_BLOCKACK 0x0060
  1180. #define MWL8K_QOS_EOSP 0x0010
  1181. struct mwl8k_tx_desc {
  1182. __le32 status;
  1183. __u8 data_rate;
  1184. __u8 tx_priority;
  1185. __le16 qos_control;
  1186. __le32 pkt_phys_addr;
  1187. __le16 pkt_len;
  1188. __u8 dest_MAC_addr[ETH_ALEN];
  1189. __le32 next_txd_phys_addr;
  1190. __le32 timestamp;
  1191. __le16 rate_info;
  1192. __u8 peer_id;
  1193. __u8 tx_frag_cnt;
  1194. } __packed;
  1195. #define MWL8K_TX_DESCS 128
  1196. static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
  1197. {
  1198. struct mwl8k_priv *priv = hw->priv;
  1199. struct mwl8k_tx_queue *txq = priv->txq + index;
  1200. int size;
  1201. int i;
  1202. txq->len = 0;
  1203. txq->head = 0;
  1204. txq->tail = 0;
  1205. size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
  1206. txq->txd = pci_alloc_consistent(priv->pdev, size, &txq->txd_dma);
  1207. if (txq->txd == NULL) {
  1208. wiphy_err(hw->wiphy, "failed to alloc TX descriptors\n");
  1209. return -ENOMEM;
  1210. }
  1211. memset(txq->txd, 0, size);
  1212. txq->skb = kcalloc(MWL8K_TX_DESCS, sizeof(*txq->skb), GFP_KERNEL);
  1213. if (txq->skb == NULL) {
  1214. pci_free_consistent(priv->pdev, size, txq->txd, txq->txd_dma);
  1215. return -ENOMEM;
  1216. }
  1217. for (i = 0; i < MWL8K_TX_DESCS; i++) {
  1218. struct mwl8k_tx_desc *tx_desc;
  1219. int nexti;
  1220. tx_desc = txq->txd + i;
  1221. nexti = (i + 1) % MWL8K_TX_DESCS;
  1222. tx_desc->status = 0;
  1223. tx_desc->next_txd_phys_addr =
  1224. cpu_to_le32(txq->txd_dma + nexti * sizeof(*tx_desc));
  1225. }
  1226. return 0;
  1227. }
  1228. static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
  1229. {
  1230. iowrite32(MWL8K_H2A_INT_PPA_READY,
  1231. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1232. iowrite32(MWL8K_H2A_INT_DUMMY,
  1233. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1234. ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  1235. }
  1236. static void mwl8k_dump_tx_rings(struct ieee80211_hw *hw)
  1237. {
  1238. struct mwl8k_priv *priv = hw->priv;
  1239. int i;
  1240. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  1241. struct mwl8k_tx_queue *txq = priv->txq + i;
  1242. int fw_owned = 0;
  1243. int drv_owned = 0;
  1244. int unused = 0;
  1245. int desc;
  1246. for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
  1247. struct mwl8k_tx_desc *tx_desc = txq->txd + desc;
  1248. u32 status;
  1249. status = le32_to_cpu(tx_desc->status);
  1250. if (status & MWL8K_TXD_STATUS_FW_OWNED)
  1251. fw_owned++;
  1252. else
  1253. drv_owned++;
  1254. if (tx_desc->pkt_len == 0)
  1255. unused++;
  1256. }
  1257. wiphy_err(hw->wiphy,
  1258. "txq[%d] len=%d head=%d tail=%d "
  1259. "fw_owned=%d drv_owned=%d unused=%d\n",
  1260. i,
  1261. txq->len, txq->head, txq->tail,
  1262. fw_owned, drv_owned, unused);
  1263. }
  1264. }
  1265. /*
  1266. * Must be called with priv->fw_mutex held and tx queues stopped.
  1267. */
  1268. #define MWL8K_TX_WAIT_TIMEOUT_MS 5000
  1269. static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw)
  1270. {
  1271. struct mwl8k_priv *priv = hw->priv;
  1272. DECLARE_COMPLETION_ONSTACK(tx_wait);
  1273. int retry;
  1274. int rc;
  1275. might_sleep();
  1276. /* Since fw restart is in progress, allow only the firmware
  1277. * commands from the restart code and block the other
  1278. * commands since they are going to fail in any case since
  1279. * the firmware has crashed
  1280. */
  1281. if (priv->hw_restart_in_progress) {
  1282. if (priv->hw_restart_owner == current)
  1283. return 0;
  1284. else
  1285. return -EBUSY;
  1286. }
  1287. if (atomic_read(&priv->watchdog_event_pending))
  1288. return 0;
  1289. /*
  1290. * The TX queues are stopped at this point, so this test
  1291. * doesn't need to take ->tx_lock.
  1292. */
  1293. if (!priv->pending_tx_pkts)
  1294. return 0;
  1295. retry = 0;
  1296. rc = 0;
  1297. spin_lock_bh(&priv->tx_lock);
  1298. priv->tx_wait = &tx_wait;
  1299. while (!rc) {
  1300. int oldcount;
  1301. unsigned long timeout;
  1302. oldcount = priv->pending_tx_pkts;
  1303. spin_unlock_bh(&priv->tx_lock);
  1304. timeout = wait_for_completion_timeout(&tx_wait,
  1305. msecs_to_jiffies(MWL8K_TX_WAIT_TIMEOUT_MS));
  1306. if (atomic_read(&priv->watchdog_event_pending)) {
  1307. spin_lock_bh(&priv->tx_lock);
  1308. priv->tx_wait = NULL;
  1309. spin_unlock_bh(&priv->tx_lock);
  1310. return 0;
  1311. }
  1312. spin_lock_bh(&priv->tx_lock);
  1313. if (timeout) {
  1314. WARN_ON(priv->pending_tx_pkts);
  1315. if (retry)
  1316. wiphy_notice(hw->wiphy, "tx rings drained\n");
  1317. break;
  1318. }
  1319. if (priv->pending_tx_pkts < oldcount) {
  1320. wiphy_notice(hw->wiphy,
  1321. "waiting for tx rings to drain (%d -> %d pkts)\n",
  1322. oldcount, priv->pending_tx_pkts);
  1323. retry = 1;
  1324. continue;
  1325. }
  1326. priv->tx_wait = NULL;
  1327. wiphy_err(hw->wiphy, "tx rings stuck for %d ms\n",
  1328. MWL8K_TX_WAIT_TIMEOUT_MS);
  1329. mwl8k_dump_tx_rings(hw);
  1330. priv->hw_restart_in_progress = true;
  1331. ieee80211_queue_work(hw, &priv->fw_reload);
  1332. rc = -ETIMEDOUT;
  1333. }
  1334. priv->tx_wait = NULL;
  1335. spin_unlock_bh(&priv->tx_lock);
  1336. return rc;
  1337. }
  1338. #define MWL8K_TXD_SUCCESS(status) \
  1339. ((status) & (MWL8K_TXD_STATUS_OK | \
  1340. MWL8K_TXD_STATUS_OK_RETRY | \
  1341. MWL8K_TXD_STATUS_OK_MORE_RETRY))
  1342. static int mwl8k_tid_queue_mapping(u8 tid)
  1343. {
  1344. BUG_ON(tid > 7);
  1345. switch (tid) {
  1346. case 0:
  1347. case 3:
  1348. return IEEE80211_AC_BE;
  1349. break;
  1350. case 1:
  1351. case 2:
  1352. return IEEE80211_AC_BK;
  1353. break;
  1354. case 4:
  1355. case 5:
  1356. return IEEE80211_AC_VI;
  1357. break;
  1358. case 6:
  1359. case 7:
  1360. return IEEE80211_AC_VO;
  1361. break;
  1362. default:
  1363. return -1;
  1364. break;
  1365. }
  1366. }
  1367. /* The firmware will fill in the rate information
  1368. * for each packet that gets queued in the hardware
  1369. * and these macros will interpret that info.
  1370. */
  1371. #define RI_FORMAT(a) (a & 0x0001)
  1372. #define RI_RATE_ID_MCS(a) ((a & 0x01f8) >> 3)
  1373. static int
  1374. mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int limit, int force)
  1375. {
  1376. struct mwl8k_priv *priv = hw->priv;
  1377. struct mwl8k_tx_queue *txq = priv->txq + index;
  1378. int processed;
  1379. processed = 0;
  1380. while (txq->len > 0 && limit--) {
  1381. int tx;
  1382. struct mwl8k_tx_desc *tx_desc;
  1383. unsigned long addr;
  1384. int size;
  1385. struct sk_buff *skb;
  1386. struct ieee80211_tx_info *info;
  1387. u32 status;
  1388. struct ieee80211_sta *sta;
  1389. struct mwl8k_sta *sta_info = NULL;
  1390. u16 rate_info;
  1391. struct ieee80211_hdr *wh;
  1392. tx = txq->head;
  1393. tx_desc = txq->txd + tx;
  1394. status = le32_to_cpu(tx_desc->status);
  1395. if (status & MWL8K_TXD_STATUS_FW_OWNED) {
  1396. if (!force)
  1397. break;
  1398. tx_desc->status &=
  1399. ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
  1400. }
  1401. txq->head = (tx + 1) % MWL8K_TX_DESCS;
  1402. BUG_ON(txq->len == 0);
  1403. txq->len--;
  1404. priv->pending_tx_pkts--;
  1405. addr = le32_to_cpu(tx_desc->pkt_phys_addr);
  1406. size = le16_to_cpu(tx_desc->pkt_len);
  1407. skb = txq->skb[tx];
  1408. txq->skb[tx] = NULL;
  1409. BUG_ON(skb == NULL);
  1410. pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
  1411. mwl8k_remove_dma_header(skb, tx_desc->qos_control);
  1412. wh = (struct ieee80211_hdr *) skb->data;
  1413. /* Mark descriptor as unused */
  1414. tx_desc->pkt_phys_addr = 0;
  1415. tx_desc->pkt_len = 0;
  1416. info = IEEE80211_SKB_CB(skb);
  1417. if (ieee80211_is_data(wh->frame_control)) {
  1418. rcu_read_lock();
  1419. sta = ieee80211_find_sta_by_ifaddr(hw, wh->addr1,
  1420. wh->addr2);
  1421. if (sta) {
  1422. sta_info = MWL8K_STA(sta);
  1423. BUG_ON(sta_info == NULL);
  1424. rate_info = le16_to_cpu(tx_desc->rate_info);
  1425. /* If rate is < 6.5 Mpbs for an ht station
  1426. * do not form an ampdu. If the station is a
  1427. * legacy station (format = 0), do not form an
  1428. * ampdu
  1429. */
  1430. if (RI_RATE_ID_MCS(rate_info) < 1 ||
  1431. RI_FORMAT(rate_info) == 0) {
  1432. sta_info->is_ampdu_allowed = false;
  1433. } else {
  1434. sta_info->is_ampdu_allowed = true;
  1435. }
  1436. }
  1437. rcu_read_unlock();
  1438. }
  1439. ieee80211_tx_info_clear_status(info);
  1440. /* Rate control is happening in the firmware.
  1441. * Ensure no tx rate is being reported.
  1442. */
  1443. info->status.rates[0].idx = -1;
  1444. info->status.rates[0].count = 1;
  1445. if (MWL8K_TXD_SUCCESS(status))
  1446. info->flags |= IEEE80211_TX_STAT_ACK;
  1447. ieee80211_tx_status_irqsafe(hw, skb);
  1448. processed++;
  1449. }
  1450. return processed;
  1451. }
  1452. /* must be called only when the card's transmit is completely halted */
  1453. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1454. {
  1455. struct mwl8k_priv *priv = hw->priv;
  1456. struct mwl8k_tx_queue *txq = priv->txq + index;
  1457. if (txq->txd == NULL)
  1458. return;
  1459. mwl8k_txq_reclaim(hw, index, INT_MAX, 1);
  1460. kfree(txq->skb);
  1461. txq->skb = NULL;
  1462. pci_free_consistent(priv->pdev,
  1463. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1464. txq->txd, txq->txd_dma);
  1465. txq->txd = NULL;
  1466. }
  1467. /* caller must hold priv->stream_lock when calling the stream functions */
  1468. static struct mwl8k_ampdu_stream *
  1469. mwl8k_add_stream(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 tid)
  1470. {
  1471. struct mwl8k_ampdu_stream *stream;
  1472. struct mwl8k_priv *priv = hw->priv;
  1473. int i;
  1474. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1475. stream = &priv->ampdu[i];
  1476. if (stream->state == AMPDU_NO_STREAM) {
  1477. stream->sta = sta;
  1478. stream->state = AMPDU_STREAM_NEW;
  1479. stream->tid = tid;
  1480. stream->idx = i;
  1481. wiphy_debug(hw->wiphy, "Added a new stream for %pM %d",
  1482. sta->addr, tid);
  1483. return stream;
  1484. }
  1485. }
  1486. return NULL;
  1487. }
  1488. static int
  1489. mwl8k_start_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1490. {
  1491. int ret;
  1492. /* if the stream has already been started, don't start it again */
  1493. if (stream->state != AMPDU_STREAM_NEW)
  1494. return 0;
  1495. ret = ieee80211_start_tx_ba_session(stream->sta, stream->tid, 0);
  1496. if (ret)
  1497. wiphy_debug(hw->wiphy, "Failed to start stream for %pM %d: "
  1498. "%d\n", stream->sta->addr, stream->tid, ret);
  1499. else
  1500. wiphy_debug(hw->wiphy, "Started stream for %pM %d\n",
  1501. stream->sta->addr, stream->tid);
  1502. return ret;
  1503. }
  1504. static void
  1505. mwl8k_remove_stream(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream)
  1506. {
  1507. wiphy_debug(hw->wiphy, "Remove stream for %pM %d\n", stream->sta->addr,
  1508. stream->tid);
  1509. memset(stream, 0, sizeof(*stream));
  1510. }
  1511. static struct mwl8k_ampdu_stream *
  1512. mwl8k_lookup_stream(struct ieee80211_hw *hw, u8 *addr, u8 tid)
  1513. {
  1514. struct mwl8k_priv *priv = hw->priv;
  1515. int i;
  1516. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  1517. struct mwl8k_ampdu_stream *stream;
  1518. stream = &priv->ampdu[i];
  1519. if (stream->state == AMPDU_NO_STREAM)
  1520. continue;
  1521. if (!memcmp(stream->sta->addr, addr, ETH_ALEN) &&
  1522. stream->tid == tid)
  1523. return stream;
  1524. }
  1525. return NULL;
  1526. }
  1527. #define MWL8K_AMPDU_PACKET_THRESHOLD 64
  1528. static inline bool mwl8k_ampdu_allowed(struct ieee80211_sta *sta, u8 tid)
  1529. {
  1530. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1531. struct tx_traffic_info *tx_stats;
  1532. BUG_ON(tid >= MWL8K_MAX_TID);
  1533. tx_stats = &sta_info->tx_stats[tid];
  1534. return sta_info->is_ampdu_allowed &&
  1535. tx_stats->pkts > MWL8K_AMPDU_PACKET_THRESHOLD;
  1536. }
  1537. static inline void mwl8k_tx_count_packet(struct ieee80211_sta *sta, u8 tid)
  1538. {
  1539. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  1540. struct tx_traffic_info *tx_stats;
  1541. BUG_ON(tid >= MWL8K_MAX_TID);
  1542. tx_stats = &sta_info->tx_stats[tid];
  1543. if (tx_stats->start_time == 0)
  1544. tx_stats->start_time = jiffies;
  1545. /* reset the packet count after each second elapses. If the number of
  1546. * packets ever exceeds the ampdu_min_traffic threshold, we will allow
  1547. * an ampdu stream to be started.
  1548. */
  1549. if (jiffies - tx_stats->start_time > HZ) {
  1550. tx_stats->pkts = 0;
  1551. tx_stats->start_time = 0;
  1552. } else
  1553. tx_stats->pkts++;
  1554. }
  1555. /* The hardware ampdu queues start from 5.
  1556. * txpriorities for ampdu queues are
  1557. * 5 6 7 0 1 2 3 4 ie., queue 5 is highest
  1558. * and queue 3 is lowest (queue 4 is reserved)
  1559. */
  1560. #define BA_QUEUE 5
  1561. static void
  1562. mwl8k_txq_xmit(struct ieee80211_hw *hw,
  1563. int index,
  1564. struct ieee80211_sta *sta,
  1565. struct sk_buff *skb)
  1566. {
  1567. struct mwl8k_priv *priv = hw->priv;
  1568. struct ieee80211_tx_info *tx_info;
  1569. struct mwl8k_vif *mwl8k_vif;
  1570. struct ieee80211_hdr *wh;
  1571. struct mwl8k_tx_queue *txq;
  1572. struct mwl8k_tx_desc *tx;
  1573. dma_addr_t dma;
  1574. u32 txstatus;
  1575. u8 txdatarate;
  1576. u16 qos;
  1577. int txpriority;
  1578. u8 tid = 0;
  1579. struct mwl8k_ampdu_stream *stream = NULL;
  1580. bool start_ba_session = false;
  1581. bool mgmtframe = false;
  1582. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
  1583. bool eapol_frame = false;
  1584. wh = (struct ieee80211_hdr *)skb->data;
  1585. if (ieee80211_is_data_qos(wh->frame_control))
  1586. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1587. else
  1588. qos = 0;
  1589. if (skb->protocol == cpu_to_be16(ETH_P_PAE))
  1590. eapol_frame = true;
  1591. if (ieee80211_is_mgmt(wh->frame_control))
  1592. mgmtframe = true;
  1593. if (priv->ap_fw)
  1594. mwl8k_encapsulate_tx_frame(priv, skb);
  1595. else
  1596. mwl8k_add_dma_header(priv, skb, 0, 0);
  1597. wh = &((struct mwl8k_dma_data *)skb->data)->wh;
  1598. tx_info = IEEE80211_SKB_CB(skb);
  1599. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1600. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1601. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1602. wh->seq_ctrl |= cpu_to_le16(mwl8k_vif->seqno);
  1603. mwl8k_vif->seqno += 0x10;
  1604. }
  1605. /* Setup firmware control bit fields for each frame type. */
  1606. txstatus = 0;
  1607. txdatarate = 0;
  1608. if (ieee80211_is_mgmt(wh->frame_control) ||
  1609. ieee80211_is_ctl(wh->frame_control)) {
  1610. txdatarate = 0;
  1611. qos |= MWL8K_QOS_QLEN_UNSPEC | MWL8K_QOS_EOSP;
  1612. } else if (ieee80211_is_data(wh->frame_control)) {
  1613. txdatarate = 1;
  1614. if (is_multicast_ether_addr(wh->addr1))
  1615. txstatus |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1616. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1617. if (tx_info->flags & IEEE80211_TX_CTL_AMPDU)
  1618. qos |= MWL8K_QOS_ACK_POLICY_BLOCKACK;
  1619. else
  1620. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1621. }
  1622. /* Queue ADDBA request in the respective data queue. While setting up
  1623. * the ampdu stream, mac80211 queues further packets for that
  1624. * particular ra/tid pair. However, packets piled up in the hardware
  1625. * for that ra/tid pair will still go out. ADDBA request and the
  1626. * related data packets going out from different queues asynchronously
  1627. * will cause a shift in the receiver window which might result in
  1628. * ampdu packets getting dropped at the receiver after the stream has
  1629. * been setup.
  1630. */
  1631. if (unlikely(ieee80211_is_action(wh->frame_control) &&
  1632. mgmt->u.action.category == WLAN_CATEGORY_BACK &&
  1633. mgmt->u.action.u.addba_req.action_code == WLAN_ACTION_ADDBA_REQ &&
  1634. priv->ap_fw)) {
  1635. u16 capab = le16_to_cpu(mgmt->u.action.u.addba_req.capab);
  1636. tid = (capab & IEEE80211_ADDBA_PARAM_TID_MASK) >> 2;
  1637. index = mwl8k_tid_queue_mapping(tid);
  1638. }
  1639. txpriority = index;
  1640. if (priv->ap_fw && sta && sta->ht_cap.ht_supported && !eapol_frame &&
  1641. ieee80211_is_data_qos(wh->frame_control)) {
  1642. tid = qos & 0xf;
  1643. mwl8k_tx_count_packet(sta, tid);
  1644. spin_lock(&priv->stream_lock);
  1645. stream = mwl8k_lookup_stream(hw, sta->addr, tid);
  1646. if (stream != NULL) {
  1647. if (stream->state == AMPDU_STREAM_ACTIVE) {
  1648. WARN_ON(!(qos & MWL8K_QOS_ACK_POLICY_BLOCKACK));
  1649. txpriority = (BA_QUEUE + stream->idx) %
  1650. TOTAL_HW_TX_QUEUES;
  1651. if (stream->idx <= 1)
  1652. index = stream->idx +
  1653. MWL8K_TX_WMM_QUEUES;
  1654. } else if (stream->state == AMPDU_STREAM_NEW) {
  1655. /* We get here if the driver sends us packets
  1656. * after we've initiated a stream, but before
  1657. * our ampdu_action routine has been called
  1658. * with IEEE80211_AMPDU_TX_START to get the SSN
  1659. * for the ADDBA request. So this packet can
  1660. * go out with no risk of sequence number
  1661. * mismatch. No special handling is required.
  1662. */
  1663. } else {
  1664. /* Drop packets that would go out after the
  1665. * ADDBA request was sent but before the ADDBA
  1666. * response is received. If we don't do this,
  1667. * the recipient would probably receive it
  1668. * after the ADDBA request with SSN 0. This
  1669. * will cause the recipient's BA receive window
  1670. * to shift, which would cause the subsequent
  1671. * packets in the BA stream to be discarded.
  1672. * mac80211 queues our packets for us in this
  1673. * case, so this is really just a safety check.
  1674. */
  1675. wiphy_warn(hw->wiphy,
  1676. "Cannot send packet while ADDBA "
  1677. "dialog is underway.\n");
  1678. spin_unlock(&priv->stream_lock);
  1679. dev_kfree_skb(skb);
  1680. return;
  1681. }
  1682. } else {
  1683. /* Defer calling mwl8k_start_stream so that the current
  1684. * skb can go out before the ADDBA request. This
  1685. * prevents sequence number mismatch at the recepient
  1686. * as described above.
  1687. */
  1688. if (mwl8k_ampdu_allowed(sta, tid)) {
  1689. stream = mwl8k_add_stream(hw, sta, tid);
  1690. if (stream != NULL)
  1691. start_ba_session = true;
  1692. }
  1693. }
  1694. spin_unlock(&priv->stream_lock);
  1695. } else {
  1696. qos &= ~MWL8K_QOS_ACK_POLICY_MASK;
  1697. qos |= MWL8K_QOS_ACK_POLICY_NORMAL;
  1698. }
  1699. dma = pci_map_single(priv->pdev, skb->data,
  1700. skb->len, PCI_DMA_TODEVICE);
  1701. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1702. wiphy_debug(hw->wiphy,
  1703. "failed to dma map skb, dropping TX frame.\n");
  1704. if (start_ba_session) {
  1705. spin_lock(&priv->stream_lock);
  1706. mwl8k_remove_stream(hw, stream);
  1707. spin_unlock(&priv->stream_lock);
  1708. }
  1709. dev_kfree_skb(skb);
  1710. return;
  1711. }
  1712. spin_lock_bh(&priv->tx_lock);
  1713. txq = priv->txq + index;
  1714. /* Mgmt frames that go out frequently are probe
  1715. * responses. Other mgmt frames got out relatively
  1716. * infrequently. Hence reserve 2 buffers so that
  1717. * other mgmt frames do not get dropped due to an
  1718. * already queued probe response in one of the
  1719. * reserved buffers.
  1720. */
  1721. if (txq->len >= MWL8K_TX_DESCS - 2) {
  1722. if (!mgmtframe || txq->len == MWL8K_TX_DESCS) {
  1723. if (start_ba_session) {
  1724. spin_lock(&priv->stream_lock);
  1725. mwl8k_remove_stream(hw, stream);
  1726. spin_unlock(&priv->stream_lock);
  1727. }
  1728. spin_unlock_bh(&priv->tx_lock);
  1729. pci_unmap_single(priv->pdev, dma, skb->len,
  1730. PCI_DMA_TODEVICE);
  1731. dev_kfree_skb(skb);
  1732. return;
  1733. }
  1734. }
  1735. BUG_ON(txq->skb[txq->tail] != NULL);
  1736. txq->skb[txq->tail] = skb;
  1737. tx = txq->txd + txq->tail;
  1738. tx->data_rate = txdatarate;
  1739. tx->tx_priority = txpriority;
  1740. tx->qos_control = cpu_to_le16(qos);
  1741. tx->pkt_phys_addr = cpu_to_le32(dma);
  1742. tx->pkt_len = cpu_to_le16(skb->len);
  1743. tx->rate_info = 0;
  1744. if (!priv->ap_fw && sta != NULL)
  1745. tx->peer_id = MWL8K_STA(sta)->peer_id;
  1746. else
  1747. tx->peer_id = 0;
  1748. if (priv->ap_fw && ieee80211_is_data(wh->frame_control) && !eapol_frame)
  1749. tx->timestamp = cpu_to_le32(ioread32(priv->regs +
  1750. MWL8K_HW_TIMER_REGISTER));
  1751. else
  1752. tx->timestamp = 0;
  1753. wmb();
  1754. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED | txstatus);
  1755. txq->len++;
  1756. priv->pending_tx_pkts++;
  1757. txq->tail++;
  1758. if (txq->tail == MWL8K_TX_DESCS)
  1759. txq->tail = 0;
  1760. mwl8k_tx_start(priv);
  1761. spin_unlock_bh(&priv->tx_lock);
  1762. /* Initiate the ampdu session here */
  1763. if (start_ba_session) {
  1764. spin_lock(&priv->stream_lock);
  1765. if (mwl8k_start_stream(hw, stream))
  1766. mwl8k_remove_stream(hw, stream);
  1767. spin_unlock(&priv->stream_lock);
  1768. }
  1769. }
  1770. /*
  1771. * Firmware access.
  1772. *
  1773. * We have the following requirements for issuing firmware commands:
  1774. * - Some commands require that the packet transmit path is idle when
  1775. * the command is issued. (For simplicity, we'll just quiesce the
  1776. * transmit path for every command.)
  1777. * - There are certain sequences of commands that need to be issued to
  1778. * the hardware sequentially, with no other intervening commands.
  1779. *
  1780. * This leads to an implementation of a "firmware lock" as a mutex that
  1781. * can be taken recursively, and which is taken by both the low-level
  1782. * command submission function (mwl8k_post_cmd) as well as any users of
  1783. * that function that require issuing of an atomic sequence of commands,
  1784. * and quiesces the transmit path whenever it's taken.
  1785. */
  1786. static int mwl8k_fw_lock(struct ieee80211_hw *hw)
  1787. {
  1788. struct mwl8k_priv *priv = hw->priv;
  1789. if (priv->fw_mutex_owner != current) {
  1790. int rc;
  1791. mutex_lock(&priv->fw_mutex);
  1792. ieee80211_stop_queues(hw);
  1793. rc = mwl8k_tx_wait_empty(hw);
  1794. if (rc) {
  1795. if (!priv->hw_restart_in_progress)
  1796. ieee80211_wake_queues(hw);
  1797. mutex_unlock(&priv->fw_mutex);
  1798. return rc;
  1799. }
  1800. priv->fw_mutex_owner = current;
  1801. }
  1802. priv->fw_mutex_depth++;
  1803. return 0;
  1804. }
  1805. static void mwl8k_fw_unlock(struct ieee80211_hw *hw)
  1806. {
  1807. struct mwl8k_priv *priv = hw->priv;
  1808. if (!--priv->fw_mutex_depth) {
  1809. if (!priv->hw_restart_in_progress)
  1810. ieee80211_wake_queues(hw);
  1811. priv->fw_mutex_owner = NULL;
  1812. mutex_unlock(&priv->fw_mutex);
  1813. }
  1814. }
  1815. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable,
  1816. u32 bitmap);
  1817. /*
  1818. * Command processing.
  1819. */
  1820. /* Timeout firmware commands after 10s */
  1821. #define MWL8K_CMD_TIMEOUT_MS 10000
  1822. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1823. {
  1824. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1825. struct mwl8k_priv *priv = hw->priv;
  1826. void __iomem *regs = priv->regs;
  1827. dma_addr_t dma_addr;
  1828. unsigned int dma_size;
  1829. int rc;
  1830. unsigned long timeout = 0;
  1831. u8 buf[32];
  1832. u32 bitmap = 0;
  1833. wiphy_dbg(hw->wiphy, "Posting %s [%d]\n",
  1834. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)), cmd->macid);
  1835. /* Before posting firmware commands that could change the hardware
  1836. * characteristics, make sure that all BSSes are stopped temporary.
  1837. * Enable these stopped BSSes after completion of the commands
  1838. */
  1839. rc = mwl8k_fw_lock(hw);
  1840. if (rc)
  1841. return rc;
  1842. if (priv->ap_fw && priv->running_bsses) {
  1843. switch (le16_to_cpu(cmd->code)) {
  1844. case MWL8K_CMD_SET_RF_CHANNEL:
  1845. case MWL8K_CMD_RADIO_CONTROL:
  1846. case MWL8K_CMD_RF_TX_POWER:
  1847. case MWL8K_CMD_TX_POWER:
  1848. case MWL8K_CMD_RF_ANTENNA:
  1849. case MWL8K_CMD_RTS_THRESHOLD:
  1850. case MWL8K_CMD_MIMO_CONFIG:
  1851. bitmap = priv->running_bsses;
  1852. mwl8k_enable_bsses(hw, false, bitmap);
  1853. break;
  1854. }
  1855. }
  1856. cmd->result = (__force __le16) 0xffff;
  1857. dma_size = le16_to_cpu(cmd->length);
  1858. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1859. PCI_DMA_BIDIRECTIONAL);
  1860. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1861. return -ENOMEM;
  1862. priv->hostcmd_wait = &cmd_wait;
  1863. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1864. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1865. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1866. iowrite32(MWL8K_H2A_INT_DUMMY,
  1867. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1868. timeout = wait_for_completion_timeout(&cmd_wait,
  1869. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1870. priv->hostcmd_wait = NULL;
  1871. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1872. PCI_DMA_BIDIRECTIONAL);
  1873. if (!timeout) {
  1874. wiphy_err(hw->wiphy, "Command %s timeout after %u ms\n",
  1875. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1876. MWL8K_CMD_TIMEOUT_MS);
  1877. rc = -ETIMEDOUT;
  1878. } else {
  1879. int ms;
  1880. ms = MWL8K_CMD_TIMEOUT_MS - jiffies_to_msecs(timeout);
  1881. rc = cmd->result ? -EINVAL : 0;
  1882. if (rc)
  1883. wiphy_err(hw->wiphy, "Command %s error 0x%x\n",
  1884. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1885. le16_to_cpu(cmd->result));
  1886. else if (ms > 2000)
  1887. wiphy_notice(hw->wiphy, "Command %s took %d ms\n",
  1888. mwl8k_cmd_name(cmd->code,
  1889. buf, sizeof(buf)),
  1890. ms);
  1891. }
  1892. if (bitmap)
  1893. mwl8k_enable_bsses(hw, true, bitmap);
  1894. mwl8k_fw_unlock(hw);
  1895. return rc;
  1896. }
  1897. static int mwl8k_post_pervif_cmd(struct ieee80211_hw *hw,
  1898. struct ieee80211_vif *vif,
  1899. struct mwl8k_cmd_pkt *cmd)
  1900. {
  1901. if (vif != NULL)
  1902. cmd->macid = MWL8K_VIF(vif)->macid;
  1903. return mwl8k_post_cmd(hw, cmd);
  1904. }
  1905. /*
  1906. * Setup code shared between STA and AP firmware images.
  1907. */
  1908. static void mwl8k_setup_2ghz_band(struct ieee80211_hw *hw)
  1909. {
  1910. struct mwl8k_priv *priv = hw->priv;
  1911. BUILD_BUG_ON(sizeof(priv->channels_24) != sizeof(mwl8k_channels_24));
  1912. memcpy(priv->channels_24, mwl8k_channels_24, sizeof(mwl8k_channels_24));
  1913. BUILD_BUG_ON(sizeof(priv->rates_24) != sizeof(mwl8k_rates_24));
  1914. memcpy(priv->rates_24, mwl8k_rates_24, sizeof(mwl8k_rates_24));
  1915. priv->band_24.band = IEEE80211_BAND_2GHZ;
  1916. priv->band_24.channels = priv->channels_24;
  1917. priv->band_24.n_channels = ARRAY_SIZE(mwl8k_channels_24);
  1918. priv->band_24.bitrates = priv->rates_24;
  1919. priv->band_24.n_bitrates = ARRAY_SIZE(mwl8k_rates_24);
  1920. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band_24;
  1921. }
  1922. static void mwl8k_setup_5ghz_band(struct ieee80211_hw *hw)
  1923. {
  1924. struct mwl8k_priv *priv = hw->priv;
  1925. BUILD_BUG_ON(sizeof(priv->channels_50) != sizeof(mwl8k_channels_50));
  1926. memcpy(priv->channels_50, mwl8k_channels_50, sizeof(mwl8k_channels_50));
  1927. BUILD_BUG_ON(sizeof(priv->rates_50) != sizeof(mwl8k_rates_50));
  1928. memcpy(priv->rates_50, mwl8k_rates_50, sizeof(mwl8k_rates_50));
  1929. priv->band_50.band = IEEE80211_BAND_5GHZ;
  1930. priv->band_50.channels = priv->channels_50;
  1931. priv->band_50.n_channels = ARRAY_SIZE(mwl8k_channels_50);
  1932. priv->band_50.bitrates = priv->rates_50;
  1933. priv->band_50.n_bitrates = ARRAY_SIZE(mwl8k_rates_50);
  1934. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = &priv->band_50;
  1935. }
  1936. /*
  1937. * CMD_GET_HW_SPEC (STA version).
  1938. */
  1939. struct mwl8k_cmd_get_hw_spec_sta {
  1940. struct mwl8k_cmd_pkt header;
  1941. __u8 hw_rev;
  1942. __u8 host_interface;
  1943. __le16 num_mcaddrs;
  1944. __u8 perm_addr[ETH_ALEN];
  1945. __le16 region_code;
  1946. __le32 fw_rev;
  1947. __le32 ps_cookie;
  1948. __le32 caps;
  1949. __u8 mcs_bitmap[16];
  1950. __le32 rx_queue_ptr;
  1951. __le32 num_tx_queues;
  1952. __le32 tx_queue_ptrs[MWL8K_TX_WMM_QUEUES];
  1953. __le32 caps2;
  1954. __le32 num_tx_desc_per_queue;
  1955. __le32 total_rxd;
  1956. } __packed;
  1957. #define MWL8K_CAP_MAX_AMSDU 0x20000000
  1958. #define MWL8K_CAP_GREENFIELD 0x08000000
  1959. #define MWL8K_CAP_AMPDU 0x04000000
  1960. #define MWL8K_CAP_RX_STBC 0x01000000
  1961. #define MWL8K_CAP_TX_STBC 0x00800000
  1962. #define MWL8K_CAP_SHORTGI_40MHZ 0x00400000
  1963. #define MWL8K_CAP_SHORTGI_20MHZ 0x00200000
  1964. #define MWL8K_CAP_RX_ANTENNA_MASK 0x000e0000
  1965. #define MWL8K_CAP_TX_ANTENNA_MASK 0x0001c000
  1966. #define MWL8K_CAP_DELAY_BA 0x00003000
  1967. #define MWL8K_CAP_MIMO 0x00000200
  1968. #define MWL8K_CAP_40MHZ 0x00000100
  1969. #define MWL8K_CAP_BAND_MASK 0x00000007
  1970. #define MWL8K_CAP_5GHZ 0x00000004
  1971. #define MWL8K_CAP_2GHZ4 0x00000001
  1972. static void
  1973. mwl8k_set_ht_caps(struct ieee80211_hw *hw,
  1974. struct ieee80211_supported_band *band, u32 cap)
  1975. {
  1976. int rx_streams;
  1977. int tx_streams;
  1978. band->ht_cap.ht_supported = 1;
  1979. if (cap & MWL8K_CAP_MAX_AMSDU)
  1980. band->ht_cap.cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  1981. if (cap & MWL8K_CAP_GREENFIELD)
  1982. band->ht_cap.cap |= IEEE80211_HT_CAP_GRN_FLD;
  1983. if (cap & MWL8K_CAP_AMPDU) {
  1984. hw->flags |= IEEE80211_HW_AMPDU_AGGREGATION;
  1985. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  1986. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_NONE;
  1987. }
  1988. if (cap & MWL8K_CAP_RX_STBC)
  1989. band->ht_cap.cap |= IEEE80211_HT_CAP_RX_STBC;
  1990. if (cap & MWL8K_CAP_TX_STBC)
  1991. band->ht_cap.cap |= IEEE80211_HT_CAP_TX_STBC;
  1992. if (cap & MWL8K_CAP_SHORTGI_40MHZ)
  1993. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  1994. if (cap & MWL8K_CAP_SHORTGI_20MHZ)
  1995. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  1996. if (cap & MWL8K_CAP_DELAY_BA)
  1997. band->ht_cap.cap |= IEEE80211_HT_CAP_DELAY_BA;
  1998. if (cap & MWL8K_CAP_40MHZ)
  1999. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  2000. rx_streams = hweight32(cap & MWL8K_CAP_RX_ANTENNA_MASK);
  2001. tx_streams = hweight32(cap & MWL8K_CAP_TX_ANTENNA_MASK);
  2002. band->ht_cap.mcs.rx_mask[0] = 0xff;
  2003. if (rx_streams >= 2)
  2004. band->ht_cap.mcs.rx_mask[1] = 0xff;
  2005. if (rx_streams >= 3)
  2006. band->ht_cap.mcs.rx_mask[2] = 0xff;
  2007. band->ht_cap.mcs.rx_mask[4] = 0x01;
  2008. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  2009. if (rx_streams != tx_streams) {
  2010. band->ht_cap.mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  2011. band->ht_cap.mcs.tx_params |= (tx_streams - 1) <<
  2012. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
  2013. }
  2014. }
  2015. static void
  2016. mwl8k_set_caps(struct ieee80211_hw *hw, u32 caps)
  2017. {
  2018. struct mwl8k_priv *priv = hw->priv;
  2019. if (priv->caps)
  2020. return;
  2021. if ((caps & MWL8K_CAP_2GHZ4) || !(caps & MWL8K_CAP_BAND_MASK)) {
  2022. mwl8k_setup_2ghz_band(hw);
  2023. if (caps & MWL8K_CAP_MIMO)
  2024. mwl8k_set_ht_caps(hw, &priv->band_24, caps);
  2025. }
  2026. if (caps & MWL8K_CAP_5GHZ) {
  2027. mwl8k_setup_5ghz_band(hw);
  2028. if (caps & MWL8K_CAP_MIMO)
  2029. mwl8k_set_ht_caps(hw, &priv->band_50, caps);
  2030. }
  2031. priv->caps = caps;
  2032. }
  2033. static int mwl8k_cmd_get_hw_spec_sta(struct ieee80211_hw *hw)
  2034. {
  2035. struct mwl8k_priv *priv = hw->priv;
  2036. struct mwl8k_cmd_get_hw_spec_sta *cmd;
  2037. int rc;
  2038. int i;
  2039. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2040. if (cmd == NULL)
  2041. return -ENOMEM;
  2042. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2043. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2044. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2045. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2046. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2047. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2048. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  2049. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].txd_dma);
  2050. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2051. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2052. rc = mwl8k_post_cmd(hw, &cmd->header);
  2053. if (!rc) {
  2054. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2055. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2056. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2057. priv->hw_rev = cmd->hw_rev;
  2058. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2059. priv->ap_macids_supported = 0x00000000;
  2060. priv->sta_macids_supported = 0x00000001;
  2061. }
  2062. kfree(cmd);
  2063. return rc;
  2064. }
  2065. /*
  2066. * CMD_GET_HW_SPEC (AP version).
  2067. */
  2068. struct mwl8k_cmd_get_hw_spec_ap {
  2069. struct mwl8k_cmd_pkt header;
  2070. __u8 hw_rev;
  2071. __u8 host_interface;
  2072. __le16 num_wcb;
  2073. __le16 num_mcaddrs;
  2074. __u8 perm_addr[ETH_ALEN];
  2075. __le16 region_code;
  2076. __le16 num_antenna;
  2077. __le32 fw_rev;
  2078. __le32 wcbbase0;
  2079. __le32 rxwrptr;
  2080. __le32 rxrdptr;
  2081. __le32 ps_cookie;
  2082. __le32 wcbbase1;
  2083. __le32 wcbbase2;
  2084. __le32 wcbbase3;
  2085. __le32 fw_api_version;
  2086. __le32 caps;
  2087. __le32 num_of_ampdu_queues;
  2088. __le32 wcbbase_ampdu[MWL8K_MAX_AMPDU_QUEUES];
  2089. } __packed;
  2090. static int mwl8k_cmd_get_hw_spec_ap(struct ieee80211_hw *hw)
  2091. {
  2092. struct mwl8k_priv *priv = hw->priv;
  2093. struct mwl8k_cmd_get_hw_spec_ap *cmd;
  2094. int rc, i;
  2095. u32 api_version;
  2096. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2097. if (cmd == NULL)
  2098. return -ENOMEM;
  2099. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  2100. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2101. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  2102. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2103. rc = mwl8k_post_cmd(hw, &cmd->header);
  2104. if (!rc) {
  2105. int off;
  2106. api_version = le32_to_cpu(cmd->fw_api_version);
  2107. if (priv->device_info->fw_api_ap != api_version) {
  2108. printk(KERN_ERR "%s: Unsupported fw API version for %s."
  2109. " Expected %d got %d.\n", MWL8K_NAME,
  2110. priv->device_info->part_name,
  2111. priv->device_info->fw_api_ap,
  2112. api_version);
  2113. rc = -EINVAL;
  2114. goto done;
  2115. }
  2116. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  2117. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  2118. priv->fw_rev = le32_to_cpu(cmd->fw_rev);
  2119. priv->hw_rev = cmd->hw_rev;
  2120. mwl8k_set_caps(hw, le32_to_cpu(cmd->caps));
  2121. priv->ap_macids_supported = 0x000000ff;
  2122. priv->sta_macids_supported = 0x00000100;
  2123. priv->num_ampdu_queues = le32_to_cpu(cmd->num_of_ampdu_queues);
  2124. if (priv->num_ampdu_queues > MWL8K_MAX_AMPDU_QUEUES) {
  2125. wiphy_warn(hw->wiphy, "fw reported %d ampdu queues"
  2126. " but we only support %d.\n",
  2127. priv->num_ampdu_queues,
  2128. MWL8K_MAX_AMPDU_QUEUES);
  2129. priv->num_ampdu_queues = MWL8K_MAX_AMPDU_QUEUES;
  2130. }
  2131. off = le32_to_cpu(cmd->rxwrptr) & 0xffff;
  2132. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2133. off = le32_to_cpu(cmd->rxrdptr) & 0xffff;
  2134. iowrite32(priv->rxq[0].rxd_dma, priv->sram + off);
  2135. priv->txq_offset[0] = le32_to_cpu(cmd->wcbbase0) & 0xffff;
  2136. priv->txq_offset[1] = le32_to_cpu(cmd->wcbbase1) & 0xffff;
  2137. priv->txq_offset[2] = le32_to_cpu(cmd->wcbbase2) & 0xffff;
  2138. priv->txq_offset[3] = le32_to_cpu(cmd->wcbbase3) & 0xffff;
  2139. for (i = 0; i < priv->num_ampdu_queues; i++)
  2140. priv->txq_offset[i + MWL8K_TX_WMM_QUEUES] =
  2141. le32_to_cpu(cmd->wcbbase_ampdu[i]) & 0xffff;
  2142. }
  2143. done:
  2144. kfree(cmd);
  2145. return rc;
  2146. }
  2147. /*
  2148. * CMD_SET_HW_SPEC.
  2149. */
  2150. struct mwl8k_cmd_set_hw_spec {
  2151. struct mwl8k_cmd_pkt header;
  2152. __u8 hw_rev;
  2153. __u8 host_interface;
  2154. __le16 num_mcaddrs;
  2155. __u8 perm_addr[ETH_ALEN];
  2156. __le16 region_code;
  2157. __le32 fw_rev;
  2158. __le32 ps_cookie;
  2159. __le32 caps;
  2160. __le32 rx_queue_ptr;
  2161. __le32 num_tx_queues;
  2162. __le32 tx_queue_ptrs[MWL8K_MAX_TX_QUEUES];
  2163. __le32 flags;
  2164. __le32 num_tx_desc_per_queue;
  2165. __le32 total_rxd;
  2166. } __packed;
  2167. /* If enabled, MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY will cause
  2168. * packets to expire 500 ms after the timestamp in the tx descriptor. That is,
  2169. * the packets that are queued for more than 500ms, will be dropped in the
  2170. * hardware. This helps minimizing the issues caused due to head-of-line
  2171. * blocking where a slow client can hog the bandwidth and affect traffic to a
  2172. * faster client.
  2173. */
  2174. #define MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY 0x00000400
  2175. #define MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR 0x00000200
  2176. #define MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT 0x00000080
  2177. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP 0x00000020
  2178. #define MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON 0x00000010
  2179. static int mwl8k_cmd_set_hw_spec(struct ieee80211_hw *hw)
  2180. {
  2181. struct mwl8k_priv *priv = hw->priv;
  2182. struct mwl8k_cmd_set_hw_spec *cmd;
  2183. int rc;
  2184. int i;
  2185. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2186. if (cmd == NULL)
  2187. return -ENOMEM;
  2188. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_HW_SPEC);
  2189. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2190. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  2191. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rxd_dma);
  2192. cmd->num_tx_queues = cpu_to_le32(mwl8k_tx_queues(priv));
  2193. /*
  2194. * Mac80211 stack has Q0 as highest priority and Q3 as lowest in
  2195. * that order. Firmware has Q3 as highest priority and Q0 as lowest
  2196. * in that order. Map Q3 of mac80211 to Q0 of firmware so that the
  2197. * priority is interpreted the right way in firmware.
  2198. */
  2199. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  2200. int j = mwl8k_tx_queues(priv) - 1 - i;
  2201. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[j].txd_dma);
  2202. }
  2203. cmd->flags = cpu_to_le32(MWL8K_SET_HW_SPEC_FLAG_HOST_DECR_MGMT |
  2204. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_PROBERESP |
  2205. MWL8K_SET_HW_SPEC_FLAG_HOSTFORM_BEACON |
  2206. MWL8K_SET_HW_SPEC_FLAG_ENABLE_LIFE_TIME_EXPIRY |
  2207. MWL8K_SET_HW_SPEC_FLAG_GENERATE_CCMP_HDR);
  2208. cmd->num_tx_desc_per_queue = cpu_to_le32(MWL8K_TX_DESCS);
  2209. cmd->total_rxd = cpu_to_le32(MWL8K_RX_DESCS);
  2210. rc = mwl8k_post_cmd(hw, &cmd->header);
  2211. kfree(cmd);
  2212. return rc;
  2213. }
  2214. /*
  2215. * CMD_MAC_MULTICAST_ADR.
  2216. */
  2217. struct mwl8k_cmd_mac_multicast_adr {
  2218. struct mwl8k_cmd_pkt header;
  2219. __le16 action;
  2220. __le16 numaddr;
  2221. __u8 addr[0][ETH_ALEN];
  2222. };
  2223. #define MWL8K_ENABLE_RX_DIRECTED 0x0001
  2224. #define MWL8K_ENABLE_RX_MULTICAST 0x0002
  2225. #define MWL8K_ENABLE_RX_ALL_MULTICAST 0x0004
  2226. #define MWL8K_ENABLE_RX_BROADCAST 0x0008
  2227. static struct mwl8k_cmd_pkt *
  2228. __mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw, int allmulti,
  2229. struct netdev_hw_addr_list *mc_list)
  2230. {
  2231. struct mwl8k_priv *priv = hw->priv;
  2232. struct mwl8k_cmd_mac_multicast_adr *cmd;
  2233. int size;
  2234. int mc_count = 0;
  2235. if (mc_list)
  2236. mc_count = netdev_hw_addr_list_count(mc_list);
  2237. if (allmulti || mc_count > priv->num_mcaddrs) {
  2238. allmulti = 1;
  2239. mc_count = 0;
  2240. }
  2241. size = sizeof(*cmd) + mc_count * ETH_ALEN;
  2242. cmd = kzalloc(size, GFP_ATOMIC);
  2243. if (cmd == NULL)
  2244. return NULL;
  2245. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  2246. cmd->header.length = cpu_to_le16(size);
  2247. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_DIRECTED |
  2248. MWL8K_ENABLE_RX_BROADCAST);
  2249. if (allmulti) {
  2250. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_ALL_MULTICAST);
  2251. } else if (mc_count) {
  2252. struct netdev_hw_addr *ha;
  2253. int i = 0;
  2254. cmd->action |= cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  2255. cmd->numaddr = cpu_to_le16(mc_count);
  2256. netdev_hw_addr_list_for_each(ha, mc_list) {
  2257. memcpy(cmd->addr[i], ha->addr, ETH_ALEN);
  2258. }
  2259. }
  2260. return &cmd->header;
  2261. }
  2262. /*
  2263. * CMD_GET_STAT.
  2264. */
  2265. struct mwl8k_cmd_get_stat {
  2266. struct mwl8k_cmd_pkt header;
  2267. __le32 stats[64];
  2268. } __packed;
  2269. #define MWL8K_STAT_ACK_FAILURE 9
  2270. #define MWL8K_STAT_RTS_FAILURE 12
  2271. #define MWL8K_STAT_FCS_ERROR 24
  2272. #define MWL8K_STAT_RTS_SUCCESS 11
  2273. static int mwl8k_cmd_get_stat(struct ieee80211_hw *hw,
  2274. struct ieee80211_low_level_stats *stats)
  2275. {
  2276. struct mwl8k_cmd_get_stat *cmd;
  2277. int rc;
  2278. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2279. if (cmd == NULL)
  2280. return -ENOMEM;
  2281. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  2282. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2283. rc = mwl8k_post_cmd(hw, &cmd->header);
  2284. if (!rc) {
  2285. stats->dot11ACKFailureCount =
  2286. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  2287. stats->dot11RTSFailureCount =
  2288. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  2289. stats->dot11FCSErrorCount =
  2290. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  2291. stats->dot11RTSSuccessCount =
  2292. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  2293. }
  2294. kfree(cmd);
  2295. return rc;
  2296. }
  2297. /*
  2298. * CMD_RADIO_CONTROL.
  2299. */
  2300. struct mwl8k_cmd_radio_control {
  2301. struct mwl8k_cmd_pkt header;
  2302. __le16 action;
  2303. __le16 control;
  2304. __le16 radio_on;
  2305. } __packed;
  2306. static int
  2307. mwl8k_cmd_radio_control(struct ieee80211_hw *hw, bool enable, bool force)
  2308. {
  2309. struct mwl8k_priv *priv = hw->priv;
  2310. struct mwl8k_cmd_radio_control *cmd;
  2311. int rc;
  2312. if (enable == priv->radio_on && !force)
  2313. return 0;
  2314. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2315. if (cmd == NULL)
  2316. return -ENOMEM;
  2317. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  2318. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2319. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2320. cmd->control = cpu_to_le16(priv->radio_short_preamble ? 3 : 1);
  2321. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  2322. rc = mwl8k_post_cmd(hw, &cmd->header);
  2323. kfree(cmd);
  2324. if (!rc)
  2325. priv->radio_on = enable;
  2326. return rc;
  2327. }
  2328. static int mwl8k_cmd_radio_disable(struct ieee80211_hw *hw)
  2329. {
  2330. return mwl8k_cmd_radio_control(hw, 0, 0);
  2331. }
  2332. static int mwl8k_cmd_radio_enable(struct ieee80211_hw *hw)
  2333. {
  2334. return mwl8k_cmd_radio_control(hw, 1, 0);
  2335. }
  2336. static int
  2337. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  2338. {
  2339. struct mwl8k_priv *priv = hw->priv;
  2340. priv->radio_short_preamble = short_preamble;
  2341. return mwl8k_cmd_radio_control(hw, 1, 1);
  2342. }
  2343. /*
  2344. * CMD_RF_TX_POWER.
  2345. */
  2346. #define MWL8K_RF_TX_POWER_LEVEL_TOTAL 8
  2347. struct mwl8k_cmd_rf_tx_power {
  2348. struct mwl8k_cmd_pkt header;
  2349. __le16 action;
  2350. __le16 support_level;
  2351. __le16 current_level;
  2352. __le16 reserved;
  2353. __le16 power_level_list[MWL8K_RF_TX_POWER_LEVEL_TOTAL];
  2354. } __packed;
  2355. static int mwl8k_cmd_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  2356. {
  2357. struct mwl8k_cmd_rf_tx_power *cmd;
  2358. int rc;
  2359. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2360. if (cmd == NULL)
  2361. return -ENOMEM;
  2362. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  2363. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2364. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2365. cmd->support_level = cpu_to_le16(dBm);
  2366. rc = mwl8k_post_cmd(hw, &cmd->header);
  2367. kfree(cmd);
  2368. return rc;
  2369. }
  2370. /*
  2371. * CMD_TX_POWER.
  2372. */
  2373. #define MWL8K_TX_POWER_LEVEL_TOTAL 12
  2374. struct mwl8k_cmd_tx_power {
  2375. struct mwl8k_cmd_pkt header;
  2376. __le16 action;
  2377. __le16 band;
  2378. __le16 channel;
  2379. __le16 bw;
  2380. __le16 sub_ch;
  2381. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  2382. } __packed;
  2383. static int mwl8k_cmd_tx_power(struct ieee80211_hw *hw,
  2384. struct ieee80211_conf *conf,
  2385. unsigned short pwr)
  2386. {
  2387. struct ieee80211_channel *channel = conf->chandef.chan;
  2388. enum nl80211_channel_type channel_type =
  2389. cfg80211_get_chandef_type(&conf->chandef);
  2390. struct mwl8k_cmd_tx_power *cmd;
  2391. int rc;
  2392. int i;
  2393. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2394. if (cmd == NULL)
  2395. return -ENOMEM;
  2396. cmd->header.code = cpu_to_le16(MWL8K_CMD_TX_POWER);
  2397. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2398. cmd->action = cpu_to_le16(MWL8K_CMD_SET_LIST);
  2399. if (channel->band == IEEE80211_BAND_2GHZ)
  2400. cmd->band = cpu_to_le16(0x1);
  2401. else if (channel->band == IEEE80211_BAND_5GHZ)
  2402. cmd->band = cpu_to_le16(0x4);
  2403. cmd->channel = cpu_to_le16(channel->hw_value);
  2404. if (channel_type == NL80211_CHAN_NO_HT ||
  2405. channel_type == NL80211_CHAN_HT20) {
  2406. cmd->bw = cpu_to_le16(0x2);
  2407. } else {
  2408. cmd->bw = cpu_to_le16(0x4);
  2409. if (channel_type == NL80211_CHAN_HT40MINUS)
  2410. cmd->sub_ch = cpu_to_le16(0x3);
  2411. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2412. cmd->sub_ch = cpu_to_le16(0x1);
  2413. }
  2414. for (i = 0; i < MWL8K_TX_POWER_LEVEL_TOTAL; i++)
  2415. cmd->power_level_list[i] = cpu_to_le16(pwr);
  2416. rc = mwl8k_post_cmd(hw, &cmd->header);
  2417. kfree(cmd);
  2418. return rc;
  2419. }
  2420. /*
  2421. * CMD_RF_ANTENNA.
  2422. */
  2423. struct mwl8k_cmd_rf_antenna {
  2424. struct mwl8k_cmd_pkt header;
  2425. __le16 antenna;
  2426. __le16 mode;
  2427. } __packed;
  2428. #define MWL8K_RF_ANTENNA_RX 1
  2429. #define MWL8K_RF_ANTENNA_TX 2
  2430. static int
  2431. mwl8k_cmd_rf_antenna(struct ieee80211_hw *hw, int antenna, int mask)
  2432. {
  2433. struct mwl8k_cmd_rf_antenna *cmd;
  2434. int rc;
  2435. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2436. if (cmd == NULL)
  2437. return -ENOMEM;
  2438. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_ANTENNA);
  2439. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2440. cmd->antenna = cpu_to_le16(antenna);
  2441. cmd->mode = cpu_to_le16(mask);
  2442. rc = mwl8k_post_cmd(hw, &cmd->header);
  2443. kfree(cmd);
  2444. return rc;
  2445. }
  2446. /*
  2447. * CMD_SET_BEACON.
  2448. */
  2449. struct mwl8k_cmd_set_beacon {
  2450. struct mwl8k_cmd_pkt header;
  2451. __le16 beacon_len;
  2452. __u8 beacon[0];
  2453. };
  2454. static int mwl8k_cmd_set_beacon(struct ieee80211_hw *hw,
  2455. struct ieee80211_vif *vif, u8 *beacon, int len)
  2456. {
  2457. struct mwl8k_cmd_set_beacon *cmd;
  2458. int rc;
  2459. cmd = kzalloc(sizeof(*cmd) + len, GFP_KERNEL);
  2460. if (cmd == NULL)
  2461. return -ENOMEM;
  2462. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_BEACON);
  2463. cmd->header.length = cpu_to_le16(sizeof(*cmd) + len);
  2464. cmd->beacon_len = cpu_to_le16(len);
  2465. memcpy(cmd->beacon, beacon, len);
  2466. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2467. kfree(cmd);
  2468. return rc;
  2469. }
  2470. /*
  2471. * CMD_SET_PRE_SCAN.
  2472. */
  2473. struct mwl8k_cmd_set_pre_scan {
  2474. struct mwl8k_cmd_pkt header;
  2475. } __packed;
  2476. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  2477. {
  2478. struct mwl8k_cmd_set_pre_scan *cmd;
  2479. int rc;
  2480. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2481. if (cmd == NULL)
  2482. return -ENOMEM;
  2483. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  2484. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2485. rc = mwl8k_post_cmd(hw, &cmd->header);
  2486. kfree(cmd);
  2487. return rc;
  2488. }
  2489. /*
  2490. * CMD_SET_POST_SCAN.
  2491. */
  2492. struct mwl8k_cmd_set_post_scan {
  2493. struct mwl8k_cmd_pkt header;
  2494. __le32 isibss;
  2495. __u8 bssid[ETH_ALEN];
  2496. } __packed;
  2497. static int
  2498. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, const __u8 *mac)
  2499. {
  2500. struct mwl8k_cmd_set_post_scan *cmd;
  2501. int rc;
  2502. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2503. if (cmd == NULL)
  2504. return -ENOMEM;
  2505. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  2506. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2507. cmd->isibss = 0;
  2508. memcpy(cmd->bssid, mac, ETH_ALEN);
  2509. rc = mwl8k_post_cmd(hw, &cmd->header);
  2510. kfree(cmd);
  2511. return rc;
  2512. }
  2513. /*
  2514. * CMD_SET_RF_CHANNEL.
  2515. */
  2516. struct mwl8k_cmd_set_rf_channel {
  2517. struct mwl8k_cmd_pkt header;
  2518. __le16 action;
  2519. __u8 current_channel;
  2520. __le32 channel_flags;
  2521. } __packed;
  2522. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  2523. struct ieee80211_conf *conf)
  2524. {
  2525. struct ieee80211_channel *channel = conf->chandef.chan;
  2526. enum nl80211_channel_type channel_type =
  2527. cfg80211_get_chandef_type(&conf->chandef);
  2528. struct mwl8k_cmd_set_rf_channel *cmd;
  2529. int rc;
  2530. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2531. if (cmd == NULL)
  2532. return -ENOMEM;
  2533. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  2534. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2535. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2536. cmd->current_channel = channel->hw_value;
  2537. if (channel->band == IEEE80211_BAND_2GHZ)
  2538. cmd->channel_flags |= cpu_to_le32(0x00000001);
  2539. else if (channel->band == IEEE80211_BAND_5GHZ)
  2540. cmd->channel_flags |= cpu_to_le32(0x00000004);
  2541. if (channel_type == NL80211_CHAN_NO_HT ||
  2542. channel_type == NL80211_CHAN_HT20)
  2543. cmd->channel_flags |= cpu_to_le32(0x00000080);
  2544. else if (channel_type == NL80211_CHAN_HT40MINUS)
  2545. cmd->channel_flags |= cpu_to_le32(0x000001900);
  2546. else if (channel_type == NL80211_CHAN_HT40PLUS)
  2547. cmd->channel_flags |= cpu_to_le32(0x000000900);
  2548. rc = mwl8k_post_cmd(hw, &cmd->header);
  2549. kfree(cmd);
  2550. return rc;
  2551. }
  2552. /*
  2553. * CMD_SET_AID.
  2554. */
  2555. #define MWL8K_FRAME_PROT_DISABLED 0x00
  2556. #define MWL8K_FRAME_PROT_11G 0x07
  2557. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  2558. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  2559. struct mwl8k_cmd_update_set_aid {
  2560. struct mwl8k_cmd_pkt header;
  2561. __le16 aid;
  2562. /* AP's MAC address (BSSID) */
  2563. __u8 bssid[ETH_ALEN];
  2564. __le16 protection_mode;
  2565. __u8 supp_rates[14];
  2566. } __packed;
  2567. static void legacy_rate_mask_to_array(u8 *rates, u32 mask)
  2568. {
  2569. int i;
  2570. int j;
  2571. /*
  2572. * Clear nonstandard rate 4.
  2573. */
  2574. mask &= 0x1fef;
  2575. for (i = 0, j = 0; i < 13; i++) {
  2576. if (mask & (1 << i))
  2577. rates[j++] = mwl8k_rates_24[i].hw_value;
  2578. }
  2579. }
  2580. static int
  2581. mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  2582. struct ieee80211_vif *vif, u32 legacy_rate_mask)
  2583. {
  2584. struct mwl8k_cmd_update_set_aid *cmd;
  2585. u16 prot_mode;
  2586. int rc;
  2587. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2588. if (cmd == NULL)
  2589. return -ENOMEM;
  2590. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_AID);
  2591. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2592. cmd->aid = cpu_to_le16(vif->bss_conf.aid);
  2593. memcpy(cmd->bssid, vif->bss_conf.bssid, ETH_ALEN);
  2594. if (vif->bss_conf.use_cts_prot) {
  2595. prot_mode = MWL8K_FRAME_PROT_11G;
  2596. } else {
  2597. switch (vif->bss_conf.ht_operation_mode &
  2598. IEEE80211_HT_OP_MODE_PROTECTION) {
  2599. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  2600. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  2601. break;
  2602. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  2603. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  2604. break;
  2605. default:
  2606. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  2607. break;
  2608. }
  2609. }
  2610. cmd->protection_mode = cpu_to_le16(prot_mode);
  2611. legacy_rate_mask_to_array(cmd->supp_rates, legacy_rate_mask);
  2612. rc = mwl8k_post_cmd(hw, &cmd->header);
  2613. kfree(cmd);
  2614. return rc;
  2615. }
  2616. /*
  2617. * CMD_SET_RATE.
  2618. */
  2619. struct mwl8k_cmd_set_rate {
  2620. struct mwl8k_cmd_pkt header;
  2621. __u8 legacy_rates[14];
  2622. /* Bitmap for supported MCS codes. */
  2623. __u8 mcs_set[16];
  2624. __u8 reserved[16];
  2625. } __packed;
  2626. static int
  2627. mwl8k_cmd_set_rate(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  2628. u32 legacy_rate_mask, u8 *mcs_rates)
  2629. {
  2630. struct mwl8k_cmd_set_rate *cmd;
  2631. int rc;
  2632. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2633. if (cmd == NULL)
  2634. return -ENOMEM;
  2635. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  2636. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2637. legacy_rate_mask_to_array(cmd->legacy_rates, legacy_rate_mask);
  2638. memcpy(cmd->mcs_set, mcs_rates, 16);
  2639. rc = mwl8k_post_cmd(hw, &cmd->header);
  2640. kfree(cmd);
  2641. return rc;
  2642. }
  2643. /*
  2644. * CMD_FINALIZE_JOIN.
  2645. */
  2646. #define MWL8K_FJ_BEACON_MAXLEN 128
  2647. struct mwl8k_cmd_finalize_join {
  2648. struct mwl8k_cmd_pkt header;
  2649. __le32 sleep_interval; /* Number of beacon periods to sleep */
  2650. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  2651. } __packed;
  2652. static int mwl8k_cmd_finalize_join(struct ieee80211_hw *hw, void *frame,
  2653. int framelen, int dtim)
  2654. {
  2655. struct mwl8k_cmd_finalize_join *cmd;
  2656. struct ieee80211_mgmt *payload = frame;
  2657. int payload_len;
  2658. int rc;
  2659. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2660. if (cmd == NULL)
  2661. return -ENOMEM;
  2662. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  2663. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2664. cmd->sleep_interval = cpu_to_le32(dtim ? dtim : 1);
  2665. payload_len = framelen - ieee80211_hdrlen(payload->frame_control);
  2666. if (payload_len < 0)
  2667. payload_len = 0;
  2668. else if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  2669. payload_len = MWL8K_FJ_BEACON_MAXLEN;
  2670. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  2671. rc = mwl8k_post_cmd(hw, &cmd->header);
  2672. kfree(cmd);
  2673. return rc;
  2674. }
  2675. /*
  2676. * CMD_SET_RTS_THRESHOLD.
  2677. */
  2678. struct mwl8k_cmd_set_rts_threshold {
  2679. struct mwl8k_cmd_pkt header;
  2680. __le16 action;
  2681. __le16 threshold;
  2682. } __packed;
  2683. static int
  2684. mwl8k_cmd_set_rts_threshold(struct ieee80211_hw *hw, int rts_thresh)
  2685. {
  2686. struct mwl8k_cmd_set_rts_threshold *cmd;
  2687. int rc;
  2688. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2689. if (cmd == NULL)
  2690. return -ENOMEM;
  2691. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  2692. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2693. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2694. cmd->threshold = cpu_to_le16(rts_thresh);
  2695. rc = mwl8k_post_cmd(hw, &cmd->header);
  2696. kfree(cmd);
  2697. return rc;
  2698. }
  2699. /*
  2700. * CMD_SET_SLOT.
  2701. */
  2702. struct mwl8k_cmd_set_slot {
  2703. struct mwl8k_cmd_pkt header;
  2704. __le16 action;
  2705. __u8 short_slot;
  2706. } __packed;
  2707. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, bool short_slot_time)
  2708. {
  2709. struct mwl8k_cmd_set_slot *cmd;
  2710. int rc;
  2711. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2712. if (cmd == NULL)
  2713. return -ENOMEM;
  2714. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  2715. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2716. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  2717. cmd->short_slot = short_slot_time;
  2718. rc = mwl8k_post_cmd(hw, &cmd->header);
  2719. kfree(cmd);
  2720. return rc;
  2721. }
  2722. /*
  2723. * CMD_SET_EDCA_PARAMS.
  2724. */
  2725. struct mwl8k_cmd_set_edca_params {
  2726. struct mwl8k_cmd_pkt header;
  2727. /* See MWL8K_SET_EDCA_XXX below */
  2728. __le16 action;
  2729. /* TX opportunity in units of 32 us */
  2730. __le16 txop;
  2731. union {
  2732. struct {
  2733. /* Log exponent of max contention period: 0...15 */
  2734. __le32 log_cw_max;
  2735. /* Log exponent of min contention period: 0...15 */
  2736. __le32 log_cw_min;
  2737. /* Adaptive interframe spacing in units of 32us */
  2738. __u8 aifs;
  2739. /* TX queue to configure */
  2740. __u8 txq;
  2741. } ap;
  2742. struct {
  2743. /* Log exponent of max contention period: 0...15 */
  2744. __u8 log_cw_max;
  2745. /* Log exponent of min contention period: 0...15 */
  2746. __u8 log_cw_min;
  2747. /* Adaptive interframe spacing in units of 32us */
  2748. __u8 aifs;
  2749. /* TX queue to configure */
  2750. __u8 txq;
  2751. } sta;
  2752. };
  2753. } __packed;
  2754. #define MWL8K_SET_EDCA_CW 0x01
  2755. #define MWL8K_SET_EDCA_TXOP 0x02
  2756. #define MWL8K_SET_EDCA_AIFS 0x04
  2757. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  2758. MWL8K_SET_EDCA_TXOP | \
  2759. MWL8K_SET_EDCA_AIFS)
  2760. static int
  2761. mwl8k_cmd_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  2762. __u16 cw_min, __u16 cw_max,
  2763. __u8 aifs, __u16 txop)
  2764. {
  2765. struct mwl8k_priv *priv = hw->priv;
  2766. struct mwl8k_cmd_set_edca_params *cmd;
  2767. int rc;
  2768. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2769. if (cmd == NULL)
  2770. return -ENOMEM;
  2771. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  2772. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2773. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  2774. cmd->txop = cpu_to_le16(txop);
  2775. if (priv->ap_fw) {
  2776. cmd->ap.log_cw_max = cpu_to_le32(ilog2(cw_max + 1));
  2777. cmd->ap.log_cw_min = cpu_to_le32(ilog2(cw_min + 1));
  2778. cmd->ap.aifs = aifs;
  2779. cmd->ap.txq = qnum;
  2780. } else {
  2781. cmd->sta.log_cw_max = (u8)ilog2(cw_max + 1);
  2782. cmd->sta.log_cw_min = (u8)ilog2(cw_min + 1);
  2783. cmd->sta.aifs = aifs;
  2784. cmd->sta.txq = qnum;
  2785. }
  2786. rc = mwl8k_post_cmd(hw, &cmd->header);
  2787. kfree(cmd);
  2788. return rc;
  2789. }
  2790. /*
  2791. * CMD_SET_WMM_MODE.
  2792. */
  2793. struct mwl8k_cmd_set_wmm_mode {
  2794. struct mwl8k_cmd_pkt header;
  2795. __le16 action;
  2796. } __packed;
  2797. static int mwl8k_cmd_set_wmm_mode(struct ieee80211_hw *hw, bool enable)
  2798. {
  2799. struct mwl8k_priv *priv = hw->priv;
  2800. struct mwl8k_cmd_set_wmm_mode *cmd;
  2801. int rc;
  2802. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2803. if (cmd == NULL)
  2804. return -ENOMEM;
  2805. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  2806. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2807. cmd->action = cpu_to_le16(!!enable);
  2808. rc = mwl8k_post_cmd(hw, &cmd->header);
  2809. kfree(cmd);
  2810. if (!rc)
  2811. priv->wmm_enabled = enable;
  2812. return rc;
  2813. }
  2814. /*
  2815. * CMD_MIMO_CONFIG.
  2816. */
  2817. struct mwl8k_cmd_mimo_config {
  2818. struct mwl8k_cmd_pkt header;
  2819. __le32 action;
  2820. __u8 rx_antenna_map;
  2821. __u8 tx_antenna_map;
  2822. } __packed;
  2823. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  2824. {
  2825. struct mwl8k_cmd_mimo_config *cmd;
  2826. int rc;
  2827. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2828. if (cmd == NULL)
  2829. return -ENOMEM;
  2830. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  2831. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2832. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  2833. cmd->rx_antenna_map = rx;
  2834. cmd->tx_antenna_map = tx;
  2835. rc = mwl8k_post_cmd(hw, &cmd->header);
  2836. kfree(cmd);
  2837. return rc;
  2838. }
  2839. /*
  2840. * CMD_USE_FIXED_RATE (STA version).
  2841. */
  2842. struct mwl8k_cmd_use_fixed_rate_sta {
  2843. struct mwl8k_cmd_pkt header;
  2844. __le32 action;
  2845. __le32 allow_rate_drop;
  2846. __le32 num_rates;
  2847. struct {
  2848. __le32 is_ht_rate;
  2849. __le32 enable_retry;
  2850. __le32 rate;
  2851. __le32 retry_count;
  2852. } rate_entry[8];
  2853. __le32 rate_type;
  2854. __le32 reserved1;
  2855. __le32 reserved2;
  2856. } __packed;
  2857. #define MWL8K_USE_AUTO_RATE 0x0002
  2858. #define MWL8K_UCAST_RATE 0
  2859. static int mwl8k_cmd_use_fixed_rate_sta(struct ieee80211_hw *hw)
  2860. {
  2861. struct mwl8k_cmd_use_fixed_rate_sta *cmd;
  2862. int rc;
  2863. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2864. if (cmd == NULL)
  2865. return -ENOMEM;
  2866. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2867. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2868. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2869. cmd->rate_type = cpu_to_le32(MWL8K_UCAST_RATE);
  2870. rc = mwl8k_post_cmd(hw, &cmd->header);
  2871. kfree(cmd);
  2872. return rc;
  2873. }
  2874. /*
  2875. * CMD_USE_FIXED_RATE (AP version).
  2876. */
  2877. struct mwl8k_cmd_use_fixed_rate_ap {
  2878. struct mwl8k_cmd_pkt header;
  2879. __le32 action;
  2880. __le32 allow_rate_drop;
  2881. __le32 num_rates;
  2882. struct mwl8k_rate_entry_ap {
  2883. __le32 is_ht_rate;
  2884. __le32 enable_retry;
  2885. __le32 rate;
  2886. __le32 retry_count;
  2887. } rate_entry[4];
  2888. u8 multicast_rate;
  2889. u8 multicast_rate_type;
  2890. u8 management_rate;
  2891. } __packed;
  2892. static int
  2893. mwl8k_cmd_use_fixed_rate_ap(struct ieee80211_hw *hw, int mcast, int mgmt)
  2894. {
  2895. struct mwl8k_cmd_use_fixed_rate_ap *cmd;
  2896. int rc;
  2897. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2898. if (cmd == NULL)
  2899. return -ENOMEM;
  2900. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2901. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2902. cmd->action = cpu_to_le32(MWL8K_USE_AUTO_RATE);
  2903. cmd->multicast_rate = mcast;
  2904. cmd->management_rate = mgmt;
  2905. rc = mwl8k_post_cmd(hw, &cmd->header);
  2906. kfree(cmd);
  2907. return rc;
  2908. }
  2909. /*
  2910. * CMD_ENABLE_SNIFFER.
  2911. */
  2912. struct mwl8k_cmd_enable_sniffer {
  2913. struct mwl8k_cmd_pkt header;
  2914. __le32 action;
  2915. } __packed;
  2916. static int mwl8k_cmd_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  2917. {
  2918. struct mwl8k_cmd_enable_sniffer *cmd;
  2919. int rc;
  2920. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2921. if (cmd == NULL)
  2922. return -ENOMEM;
  2923. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  2924. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2925. cmd->action = cpu_to_le32(!!enable);
  2926. rc = mwl8k_post_cmd(hw, &cmd->header);
  2927. kfree(cmd);
  2928. return rc;
  2929. }
  2930. struct mwl8k_cmd_update_mac_addr {
  2931. struct mwl8k_cmd_pkt header;
  2932. union {
  2933. struct {
  2934. __le16 mac_type;
  2935. __u8 mac_addr[ETH_ALEN];
  2936. } mbss;
  2937. __u8 mac_addr[ETH_ALEN];
  2938. };
  2939. } __packed;
  2940. #define MWL8K_MAC_TYPE_PRIMARY_CLIENT 0
  2941. #define MWL8K_MAC_TYPE_SECONDARY_CLIENT 1
  2942. #define MWL8K_MAC_TYPE_PRIMARY_AP 2
  2943. #define MWL8K_MAC_TYPE_SECONDARY_AP 3
  2944. static int mwl8k_cmd_update_mac_addr(struct ieee80211_hw *hw,
  2945. struct ieee80211_vif *vif, u8 *mac, bool set)
  2946. {
  2947. struct mwl8k_priv *priv = hw->priv;
  2948. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2949. struct mwl8k_cmd_update_mac_addr *cmd;
  2950. int mac_type;
  2951. int rc;
  2952. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2953. if (vif != NULL && vif->type == NL80211_IFTYPE_STATION) {
  2954. if (mwl8k_vif->macid + 1 == ffs(priv->sta_macids_supported))
  2955. if (priv->ap_fw)
  2956. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2957. else
  2958. mac_type = MWL8K_MAC_TYPE_PRIMARY_CLIENT;
  2959. else
  2960. mac_type = MWL8K_MAC_TYPE_SECONDARY_CLIENT;
  2961. } else if (vif != NULL && vif->type == NL80211_IFTYPE_AP) {
  2962. if (mwl8k_vif->macid + 1 == ffs(priv->ap_macids_supported))
  2963. mac_type = MWL8K_MAC_TYPE_PRIMARY_AP;
  2964. else
  2965. mac_type = MWL8K_MAC_TYPE_SECONDARY_AP;
  2966. }
  2967. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2968. if (cmd == NULL)
  2969. return -ENOMEM;
  2970. if (set)
  2971. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_MAC_ADDR);
  2972. else
  2973. cmd->header.code = cpu_to_le16(MWL8K_CMD_DEL_MAC_ADDR);
  2974. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2975. if (priv->ap_fw) {
  2976. cmd->mbss.mac_type = cpu_to_le16(mac_type);
  2977. memcpy(cmd->mbss.mac_addr, mac, ETH_ALEN);
  2978. } else {
  2979. memcpy(cmd->mac_addr, mac, ETH_ALEN);
  2980. }
  2981. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  2982. kfree(cmd);
  2983. return rc;
  2984. }
  2985. /*
  2986. * MWL8K_CMD_SET_MAC_ADDR.
  2987. */
  2988. static inline int mwl8k_cmd_set_mac_addr(struct ieee80211_hw *hw,
  2989. struct ieee80211_vif *vif, u8 *mac)
  2990. {
  2991. return mwl8k_cmd_update_mac_addr(hw, vif, mac, true);
  2992. }
  2993. /*
  2994. * MWL8K_CMD_DEL_MAC_ADDR.
  2995. */
  2996. static inline int mwl8k_cmd_del_mac_addr(struct ieee80211_hw *hw,
  2997. struct ieee80211_vif *vif, u8 *mac)
  2998. {
  2999. return mwl8k_cmd_update_mac_addr(hw, vif, mac, false);
  3000. }
  3001. /*
  3002. * CMD_SET_RATEADAPT_MODE.
  3003. */
  3004. struct mwl8k_cmd_set_rate_adapt_mode {
  3005. struct mwl8k_cmd_pkt header;
  3006. __le16 action;
  3007. __le16 mode;
  3008. } __packed;
  3009. static int mwl8k_cmd_set_rateadapt_mode(struct ieee80211_hw *hw, __u16 mode)
  3010. {
  3011. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  3012. int rc;
  3013. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3014. if (cmd == NULL)
  3015. return -ENOMEM;
  3016. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  3017. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3018. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  3019. cmd->mode = cpu_to_le16(mode);
  3020. rc = mwl8k_post_cmd(hw, &cmd->header);
  3021. kfree(cmd);
  3022. return rc;
  3023. }
  3024. /*
  3025. * CMD_GET_WATCHDOG_BITMAP.
  3026. */
  3027. struct mwl8k_cmd_get_watchdog_bitmap {
  3028. struct mwl8k_cmd_pkt header;
  3029. u8 bitmap;
  3030. } __packed;
  3031. static int mwl8k_cmd_get_watchdog_bitmap(struct ieee80211_hw *hw, u8 *bitmap)
  3032. {
  3033. struct mwl8k_cmd_get_watchdog_bitmap *cmd;
  3034. int rc;
  3035. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3036. if (cmd == NULL)
  3037. return -ENOMEM;
  3038. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_WATCHDOG_BITMAP);
  3039. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3040. rc = mwl8k_post_cmd(hw, &cmd->header);
  3041. if (!rc)
  3042. *bitmap = cmd->bitmap;
  3043. kfree(cmd);
  3044. return rc;
  3045. }
  3046. #define MWL8K_WMM_QUEUE_NUMBER 3
  3047. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3048. u8 idx);
  3049. static void mwl8k_watchdog_ba_events(struct work_struct *work)
  3050. {
  3051. int rc;
  3052. u8 bitmap = 0, stream_index;
  3053. struct mwl8k_ampdu_stream *streams;
  3054. struct mwl8k_priv *priv =
  3055. container_of(work, struct mwl8k_priv, watchdog_ba_handle);
  3056. struct ieee80211_hw *hw = priv->hw;
  3057. int i;
  3058. u32 status = 0;
  3059. mwl8k_fw_lock(hw);
  3060. rc = mwl8k_cmd_get_watchdog_bitmap(priv->hw, &bitmap);
  3061. if (rc)
  3062. goto done;
  3063. spin_lock(&priv->stream_lock);
  3064. /* the bitmap is the hw queue number. Map it to the ampdu queue. */
  3065. for (i = 0; i < TOTAL_HW_TX_QUEUES; i++) {
  3066. if (bitmap & (1 << i)) {
  3067. stream_index = (i + MWL8K_WMM_QUEUE_NUMBER) %
  3068. TOTAL_HW_TX_QUEUES;
  3069. streams = &priv->ampdu[stream_index];
  3070. if (streams->state == AMPDU_STREAM_ACTIVE) {
  3071. ieee80211_stop_tx_ba_session(streams->sta,
  3072. streams->tid);
  3073. spin_unlock(&priv->stream_lock);
  3074. mwl8k_destroy_ba(hw, stream_index);
  3075. spin_lock(&priv->stream_lock);
  3076. }
  3077. }
  3078. }
  3079. spin_unlock(&priv->stream_lock);
  3080. done:
  3081. atomic_dec(&priv->watchdog_event_pending);
  3082. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3083. iowrite32((status | MWL8K_A2H_INT_BA_WATCHDOG),
  3084. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3085. mwl8k_fw_unlock(hw);
  3086. return;
  3087. }
  3088. /*
  3089. * CMD_BSS_START.
  3090. */
  3091. struct mwl8k_cmd_bss_start {
  3092. struct mwl8k_cmd_pkt header;
  3093. __le32 enable;
  3094. } __packed;
  3095. static int mwl8k_cmd_bss_start(struct ieee80211_hw *hw,
  3096. struct ieee80211_vif *vif, int enable)
  3097. {
  3098. struct mwl8k_cmd_bss_start *cmd;
  3099. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3100. struct mwl8k_priv *priv = hw->priv;
  3101. int rc;
  3102. if (enable && (priv->running_bsses & (1 << mwl8k_vif->macid)))
  3103. return 0;
  3104. if (!enable && !(priv->running_bsses & (1 << mwl8k_vif->macid)))
  3105. return 0;
  3106. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3107. if (cmd == NULL)
  3108. return -ENOMEM;
  3109. cmd->header.code = cpu_to_le16(MWL8K_CMD_BSS_START);
  3110. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3111. cmd->enable = cpu_to_le32(enable);
  3112. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3113. kfree(cmd);
  3114. if (!rc) {
  3115. if (enable)
  3116. priv->running_bsses |= (1 << mwl8k_vif->macid);
  3117. else
  3118. priv->running_bsses &= ~(1 << mwl8k_vif->macid);
  3119. }
  3120. return rc;
  3121. }
  3122. static void mwl8k_enable_bsses(struct ieee80211_hw *hw, bool enable, u32 bitmap)
  3123. {
  3124. struct mwl8k_priv *priv = hw->priv;
  3125. struct mwl8k_vif *mwl8k_vif, *tmp_vif;
  3126. struct ieee80211_vif *vif;
  3127. list_for_each_entry_safe(mwl8k_vif, tmp_vif, &priv->vif_list, list) {
  3128. vif = mwl8k_vif->vif;
  3129. if (!(bitmap & (1 << mwl8k_vif->macid)))
  3130. continue;
  3131. if (vif->type == NL80211_IFTYPE_AP)
  3132. mwl8k_cmd_bss_start(hw, vif, enable);
  3133. }
  3134. }
  3135. /*
  3136. * CMD_BASTREAM.
  3137. */
  3138. /*
  3139. * UPSTREAM is tx direction
  3140. */
  3141. #define BASTREAM_FLAG_DIRECTION_UPSTREAM 0x00
  3142. #define BASTREAM_FLAG_IMMEDIATE_TYPE 0x01
  3143. enum ba_stream_action_type {
  3144. MWL8K_BA_CREATE,
  3145. MWL8K_BA_UPDATE,
  3146. MWL8K_BA_DESTROY,
  3147. MWL8K_BA_FLUSH,
  3148. MWL8K_BA_CHECK,
  3149. };
  3150. struct mwl8k_create_ba_stream {
  3151. __le32 flags;
  3152. __le32 idle_thrs;
  3153. __le32 bar_thrs;
  3154. __le32 window_size;
  3155. u8 peer_mac_addr[6];
  3156. u8 dialog_token;
  3157. u8 tid;
  3158. u8 queue_id;
  3159. u8 param_info;
  3160. __le32 ba_context;
  3161. u8 reset_seq_no_flag;
  3162. __le16 curr_seq_no;
  3163. u8 sta_src_mac_addr[6];
  3164. } __packed;
  3165. struct mwl8k_destroy_ba_stream {
  3166. __le32 flags;
  3167. __le32 ba_context;
  3168. } __packed;
  3169. struct mwl8k_cmd_bastream {
  3170. struct mwl8k_cmd_pkt header;
  3171. __le32 action;
  3172. union {
  3173. struct mwl8k_create_ba_stream create_params;
  3174. struct mwl8k_destroy_ba_stream destroy_params;
  3175. };
  3176. } __packed;
  3177. static int
  3178. mwl8k_check_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3179. struct ieee80211_vif *vif)
  3180. {
  3181. struct mwl8k_cmd_bastream *cmd;
  3182. int rc;
  3183. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3184. if (cmd == NULL)
  3185. return -ENOMEM;
  3186. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3187. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3188. cmd->action = cpu_to_le32(MWL8K_BA_CHECK);
  3189. cmd->create_params.queue_id = stream->idx;
  3190. memcpy(&cmd->create_params.peer_mac_addr[0], stream->sta->addr,
  3191. ETH_ALEN);
  3192. cmd->create_params.tid = stream->tid;
  3193. cmd->create_params.flags =
  3194. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE) |
  3195. cpu_to_le32(BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3196. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3197. kfree(cmd);
  3198. return rc;
  3199. }
  3200. static int
  3201. mwl8k_create_ba(struct ieee80211_hw *hw, struct mwl8k_ampdu_stream *stream,
  3202. u8 buf_size, struct ieee80211_vif *vif)
  3203. {
  3204. struct mwl8k_cmd_bastream *cmd;
  3205. int rc;
  3206. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3207. if (cmd == NULL)
  3208. return -ENOMEM;
  3209. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3210. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3211. cmd->action = cpu_to_le32(MWL8K_BA_CREATE);
  3212. cmd->create_params.bar_thrs = cpu_to_le32((u32)buf_size);
  3213. cmd->create_params.window_size = cpu_to_le32((u32)buf_size);
  3214. cmd->create_params.queue_id = stream->idx;
  3215. memcpy(cmd->create_params.peer_mac_addr, stream->sta->addr, ETH_ALEN);
  3216. cmd->create_params.tid = stream->tid;
  3217. cmd->create_params.curr_seq_no = cpu_to_le16(0);
  3218. cmd->create_params.reset_seq_no_flag = 1;
  3219. cmd->create_params.param_info =
  3220. (stream->sta->ht_cap.ampdu_factor &
  3221. IEEE80211_HT_AMPDU_PARM_FACTOR) |
  3222. ((stream->sta->ht_cap.ampdu_density << 2) &
  3223. IEEE80211_HT_AMPDU_PARM_DENSITY);
  3224. cmd->create_params.flags =
  3225. cpu_to_le32(BASTREAM_FLAG_IMMEDIATE_TYPE |
  3226. BASTREAM_FLAG_DIRECTION_UPSTREAM);
  3227. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3228. wiphy_debug(hw->wiphy, "Created a BA stream for %pM : tid %d\n",
  3229. stream->sta->addr, stream->tid);
  3230. kfree(cmd);
  3231. return rc;
  3232. }
  3233. static void mwl8k_destroy_ba(struct ieee80211_hw *hw,
  3234. u8 idx)
  3235. {
  3236. struct mwl8k_cmd_bastream *cmd;
  3237. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3238. if (cmd == NULL)
  3239. return;
  3240. cmd->header.code = cpu_to_le16(MWL8K_CMD_BASTREAM);
  3241. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3242. cmd->action = cpu_to_le32(MWL8K_BA_DESTROY);
  3243. cmd->destroy_params.ba_context = cpu_to_le32(idx);
  3244. mwl8k_post_cmd(hw, &cmd->header);
  3245. wiphy_debug(hw->wiphy, "Deleted BA stream index %d\n", idx);
  3246. kfree(cmd);
  3247. }
  3248. /*
  3249. * CMD_SET_NEW_STN.
  3250. */
  3251. struct mwl8k_cmd_set_new_stn {
  3252. struct mwl8k_cmd_pkt header;
  3253. __le16 aid;
  3254. __u8 mac_addr[6];
  3255. __le16 stn_id;
  3256. __le16 action;
  3257. __le16 rsvd;
  3258. __le32 legacy_rates;
  3259. __u8 ht_rates[4];
  3260. __le16 cap_info;
  3261. __le16 ht_capabilities_info;
  3262. __u8 mac_ht_param_info;
  3263. __u8 rev;
  3264. __u8 control_channel;
  3265. __u8 add_channel;
  3266. __le16 op_mode;
  3267. __le16 stbc;
  3268. __u8 add_qos_info;
  3269. __u8 is_qos_sta;
  3270. __le32 fw_sta_ptr;
  3271. } __packed;
  3272. #define MWL8K_STA_ACTION_ADD 0
  3273. #define MWL8K_STA_ACTION_REMOVE 2
  3274. static int mwl8k_cmd_set_new_stn_add(struct ieee80211_hw *hw,
  3275. struct ieee80211_vif *vif,
  3276. struct ieee80211_sta *sta)
  3277. {
  3278. struct mwl8k_cmd_set_new_stn *cmd;
  3279. u32 rates;
  3280. int rc;
  3281. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3282. if (cmd == NULL)
  3283. return -ENOMEM;
  3284. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3285. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3286. cmd->aid = cpu_to_le16(sta->aid);
  3287. memcpy(cmd->mac_addr, sta->addr, ETH_ALEN);
  3288. cmd->stn_id = cpu_to_le16(sta->aid);
  3289. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_ADD);
  3290. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3291. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3292. else
  3293. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3294. cmd->legacy_rates = cpu_to_le32(rates);
  3295. if (sta->ht_cap.ht_supported) {
  3296. cmd->ht_rates[0] = sta->ht_cap.mcs.rx_mask[0];
  3297. cmd->ht_rates[1] = sta->ht_cap.mcs.rx_mask[1];
  3298. cmd->ht_rates[2] = sta->ht_cap.mcs.rx_mask[2];
  3299. cmd->ht_rates[3] = sta->ht_cap.mcs.rx_mask[3];
  3300. cmd->ht_capabilities_info = cpu_to_le16(sta->ht_cap.cap);
  3301. cmd->mac_ht_param_info = (sta->ht_cap.ampdu_factor & 3) |
  3302. ((sta->ht_cap.ampdu_density & 7) << 2);
  3303. cmd->is_qos_sta = 1;
  3304. }
  3305. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3306. kfree(cmd);
  3307. return rc;
  3308. }
  3309. static int mwl8k_cmd_set_new_stn_add_self(struct ieee80211_hw *hw,
  3310. struct ieee80211_vif *vif)
  3311. {
  3312. struct mwl8k_cmd_set_new_stn *cmd;
  3313. int rc;
  3314. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3315. if (cmd == NULL)
  3316. return -ENOMEM;
  3317. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3318. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3319. memcpy(cmd->mac_addr, vif->addr, ETH_ALEN);
  3320. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3321. kfree(cmd);
  3322. return rc;
  3323. }
  3324. static int mwl8k_cmd_set_new_stn_del(struct ieee80211_hw *hw,
  3325. struct ieee80211_vif *vif, u8 *addr)
  3326. {
  3327. struct mwl8k_cmd_set_new_stn *cmd;
  3328. struct mwl8k_priv *priv = hw->priv;
  3329. int rc, i;
  3330. u8 idx;
  3331. spin_lock(&priv->stream_lock);
  3332. /* Destroy any active ampdu streams for this sta */
  3333. for (i = 0; i < MWL8K_NUM_AMPDU_STREAMS; i++) {
  3334. struct mwl8k_ampdu_stream *s;
  3335. s = &priv->ampdu[i];
  3336. if (s->state != AMPDU_NO_STREAM) {
  3337. if (memcmp(s->sta->addr, addr, ETH_ALEN) == 0) {
  3338. if (s->state == AMPDU_STREAM_ACTIVE) {
  3339. idx = s->idx;
  3340. spin_unlock(&priv->stream_lock);
  3341. mwl8k_destroy_ba(hw, idx);
  3342. spin_lock(&priv->stream_lock);
  3343. } else if (s->state == AMPDU_STREAM_NEW) {
  3344. mwl8k_remove_stream(hw, s);
  3345. }
  3346. }
  3347. }
  3348. }
  3349. spin_unlock(&priv->stream_lock);
  3350. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3351. if (cmd == NULL)
  3352. return -ENOMEM;
  3353. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_NEW_STN);
  3354. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3355. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3356. cmd->action = cpu_to_le16(MWL8K_STA_ACTION_REMOVE);
  3357. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3358. kfree(cmd);
  3359. return rc;
  3360. }
  3361. /*
  3362. * CMD_UPDATE_ENCRYPTION.
  3363. */
  3364. #define MAX_ENCR_KEY_LENGTH 16
  3365. #define MIC_KEY_LENGTH 8
  3366. struct mwl8k_cmd_update_encryption {
  3367. struct mwl8k_cmd_pkt header;
  3368. __le32 action;
  3369. __le32 reserved;
  3370. __u8 mac_addr[6];
  3371. __u8 encr_type;
  3372. } __packed;
  3373. struct mwl8k_cmd_set_key {
  3374. struct mwl8k_cmd_pkt header;
  3375. __le32 action;
  3376. __le32 reserved;
  3377. __le16 length;
  3378. __le16 key_type_id;
  3379. __le32 key_info;
  3380. __le32 key_id;
  3381. __le16 key_len;
  3382. __u8 key_material[MAX_ENCR_KEY_LENGTH];
  3383. __u8 tkip_tx_mic_key[MIC_KEY_LENGTH];
  3384. __u8 tkip_rx_mic_key[MIC_KEY_LENGTH];
  3385. __le16 tkip_rsc_low;
  3386. __le32 tkip_rsc_high;
  3387. __le16 tkip_tsc_low;
  3388. __le32 tkip_tsc_high;
  3389. __u8 mac_addr[6];
  3390. } __packed;
  3391. enum {
  3392. MWL8K_ENCR_ENABLE,
  3393. MWL8K_ENCR_SET_KEY,
  3394. MWL8K_ENCR_REMOVE_KEY,
  3395. MWL8K_ENCR_SET_GROUP_KEY,
  3396. };
  3397. #define MWL8K_UPDATE_ENCRYPTION_TYPE_WEP 0
  3398. #define MWL8K_UPDATE_ENCRYPTION_TYPE_DISABLE 1
  3399. #define MWL8K_UPDATE_ENCRYPTION_TYPE_TKIP 4
  3400. #define MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED 7
  3401. #define MWL8K_UPDATE_ENCRYPTION_TYPE_AES 8
  3402. enum {
  3403. MWL8K_ALG_WEP,
  3404. MWL8K_ALG_TKIP,
  3405. MWL8K_ALG_CCMP,
  3406. };
  3407. #define MWL8K_KEY_FLAG_TXGROUPKEY 0x00000004
  3408. #define MWL8K_KEY_FLAG_PAIRWISE 0x00000008
  3409. #define MWL8K_KEY_FLAG_TSC_VALID 0x00000040
  3410. #define MWL8K_KEY_FLAG_WEP_TXKEY 0x01000000
  3411. #define MWL8K_KEY_FLAG_MICKEY_VALID 0x02000000
  3412. static int mwl8k_cmd_update_encryption_enable(struct ieee80211_hw *hw,
  3413. struct ieee80211_vif *vif,
  3414. u8 *addr,
  3415. u8 encr_type)
  3416. {
  3417. struct mwl8k_cmd_update_encryption *cmd;
  3418. int rc;
  3419. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3420. if (cmd == NULL)
  3421. return -ENOMEM;
  3422. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3423. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3424. cmd->action = cpu_to_le32(MWL8K_ENCR_ENABLE);
  3425. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3426. cmd->encr_type = encr_type;
  3427. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3428. kfree(cmd);
  3429. return rc;
  3430. }
  3431. static int mwl8k_encryption_set_cmd_info(struct mwl8k_cmd_set_key *cmd,
  3432. u8 *addr,
  3433. struct ieee80211_key_conf *key)
  3434. {
  3435. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_ENCRYPTION);
  3436. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3437. cmd->length = cpu_to_le16(sizeof(*cmd) -
  3438. offsetof(struct mwl8k_cmd_set_key, length));
  3439. cmd->key_id = cpu_to_le32(key->keyidx);
  3440. cmd->key_len = cpu_to_le16(key->keylen);
  3441. memcpy(cmd->mac_addr, addr, ETH_ALEN);
  3442. switch (key->cipher) {
  3443. case WLAN_CIPHER_SUITE_WEP40:
  3444. case WLAN_CIPHER_SUITE_WEP104:
  3445. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_WEP);
  3446. if (key->keyidx == 0)
  3447. cmd->key_info = cpu_to_le32(MWL8K_KEY_FLAG_WEP_TXKEY);
  3448. break;
  3449. case WLAN_CIPHER_SUITE_TKIP:
  3450. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_TKIP);
  3451. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3452. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3453. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3454. cmd->key_info |= cpu_to_le32(MWL8K_KEY_FLAG_MICKEY_VALID
  3455. | MWL8K_KEY_FLAG_TSC_VALID);
  3456. break;
  3457. case WLAN_CIPHER_SUITE_CCMP:
  3458. cmd->key_type_id = cpu_to_le16(MWL8K_ALG_CCMP);
  3459. cmd->key_info = (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3460. ? cpu_to_le32(MWL8K_KEY_FLAG_PAIRWISE)
  3461. : cpu_to_le32(MWL8K_KEY_FLAG_TXGROUPKEY);
  3462. break;
  3463. default:
  3464. return -ENOTSUPP;
  3465. }
  3466. return 0;
  3467. }
  3468. static int mwl8k_cmd_encryption_set_key(struct ieee80211_hw *hw,
  3469. struct ieee80211_vif *vif,
  3470. u8 *addr,
  3471. struct ieee80211_key_conf *key)
  3472. {
  3473. struct mwl8k_cmd_set_key *cmd;
  3474. int rc;
  3475. int keymlen;
  3476. u32 action;
  3477. u8 idx;
  3478. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3479. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3480. if (cmd == NULL)
  3481. return -ENOMEM;
  3482. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3483. if (rc < 0)
  3484. goto done;
  3485. idx = key->keyidx;
  3486. if (key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
  3487. action = MWL8K_ENCR_SET_KEY;
  3488. else
  3489. action = MWL8K_ENCR_SET_GROUP_KEY;
  3490. switch (key->cipher) {
  3491. case WLAN_CIPHER_SUITE_WEP40:
  3492. case WLAN_CIPHER_SUITE_WEP104:
  3493. if (!mwl8k_vif->wep_key_conf[idx].enabled) {
  3494. memcpy(mwl8k_vif->wep_key_conf[idx].key, key,
  3495. sizeof(*key) + key->keylen);
  3496. mwl8k_vif->wep_key_conf[idx].enabled = 1;
  3497. }
  3498. keymlen = key->keylen;
  3499. action = MWL8K_ENCR_SET_KEY;
  3500. break;
  3501. case WLAN_CIPHER_SUITE_TKIP:
  3502. keymlen = MAX_ENCR_KEY_LENGTH + 2 * MIC_KEY_LENGTH;
  3503. break;
  3504. case WLAN_CIPHER_SUITE_CCMP:
  3505. keymlen = key->keylen;
  3506. break;
  3507. default:
  3508. rc = -ENOTSUPP;
  3509. goto done;
  3510. }
  3511. memcpy(cmd->key_material, key->key, keymlen);
  3512. cmd->action = cpu_to_le32(action);
  3513. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3514. done:
  3515. kfree(cmd);
  3516. return rc;
  3517. }
  3518. static int mwl8k_cmd_encryption_remove_key(struct ieee80211_hw *hw,
  3519. struct ieee80211_vif *vif,
  3520. u8 *addr,
  3521. struct ieee80211_key_conf *key)
  3522. {
  3523. struct mwl8k_cmd_set_key *cmd;
  3524. int rc;
  3525. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3526. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3527. if (cmd == NULL)
  3528. return -ENOMEM;
  3529. rc = mwl8k_encryption_set_cmd_info(cmd, addr, key);
  3530. if (rc < 0)
  3531. goto done;
  3532. if (key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  3533. key->cipher == WLAN_CIPHER_SUITE_WEP104)
  3534. mwl8k_vif->wep_key_conf[key->keyidx].enabled = 0;
  3535. cmd->action = cpu_to_le32(MWL8K_ENCR_REMOVE_KEY);
  3536. rc = mwl8k_post_pervif_cmd(hw, vif, &cmd->header);
  3537. done:
  3538. kfree(cmd);
  3539. return rc;
  3540. }
  3541. static int mwl8k_set_key(struct ieee80211_hw *hw,
  3542. enum set_key_cmd cmd_param,
  3543. struct ieee80211_vif *vif,
  3544. struct ieee80211_sta *sta,
  3545. struct ieee80211_key_conf *key)
  3546. {
  3547. int rc = 0;
  3548. u8 encr_type;
  3549. u8 *addr;
  3550. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3551. struct mwl8k_priv *priv = hw->priv;
  3552. if (vif->type == NL80211_IFTYPE_STATION && !priv->ap_fw)
  3553. return -EOPNOTSUPP;
  3554. if (sta == NULL)
  3555. addr = vif->addr;
  3556. else
  3557. addr = sta->addr;
  3558. if (cmd_param == SET_KEY) {
  3559. rc = mwl8k_cmd_encryption_set_key(hw, vif, addr, key);
  3560. if (rc)
  3561. goto out;
  3562. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40)
  3563. || (key->cipher == WLAN_CIPHER_SUITE_WEP104))
  3564. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_WEP;
  3565. else
  3566. encr_type = MWL8K_UPDATE_ENCRYPTION_TYPE_MIXED;
  3567. rc = mwl8k_cmd_update_encryption_enable(hw, vif, addr,
  3568. encr_type);
  3569. if (rc)
  3570. goto out;
  3571. mwl8k_vif->is_hw_crypto_enabled = true;
  3572. } else {
  3573. rc = mwl8k_cmd_encryption_remove_key(hw, vif, addr, key);
  3574. if (rc)
  3575. goto out;
  3576. }
  3577. out:
  3578. return rc;
  3579. }
  3580. /*
  3581. * CMD_UPDATE_STADB.
  3582. */
  3583. struct ewc_ht_info {
  3584. __le16 control1;
  3585. __le16 control2;
  3586. __le16 control3;
  3587. } __packed;
  3588. struct peer_capability_info {
  3589. /* Peer type - AP vs. STA. */
  3590. __u8 peer_type;
  3591. /* Basic 802.11 capabilities from assoc resp. */
  3592. __le16 basic_caps;
  3593. /* Set if peer supports 802.11n high throughput (HT). */
  3594. __u8 ht_support;
  3595. /* Valid if HT is supported. */
  3596. __le16 ht_caps;
  3597. __u8 extended_ht_caps;
  3598. struct ewc_ht_info ewc_info;
  3599. /* Legacy rate table. Intersection of our rates and peer rates. */
  3600. __u8 legacy_rates[12];
  3601. /* HT rate table. Intersection of our rates and peer rates. */
  3602. __u8 ht_rates[16];
  3603. __u8 pad[16];
  3604. /* If set, interoperability mode, no proprietary extensions. */
  3605. __u8 interop;
  3606. __u8 pad2;
  3607. __u8 station_id;
  3608. __le16 amsdu_enabled;
  3609. } __packed;
  3610. struct mwl8k_cmd_update_stadb {
  3611. struct mwl8k_cmd_pkt header;
  3612. /* See STADB_ACTION_TYPE */
  3613. __le32 action;
  3614. /* Peer MAC address */
  3615. __u8 peer_addr[ETH_ALEN];
  3616. __le32 reserved;
  3617. /* Peer info - valid during add/update. */
  3618. struct peer_capability_info peer_info;
  3619. } __packed;
  3620. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  3621. #define MWL8K_STA_DB_DEL_ENTRY 2
  3622. /* Peer Entry flags - used to define the type of the peer node */
  3623. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  3624. static int mwl8k_cmd_update_stadb_add(struct ieee80211_hw *hw,
  3625. struct ieee80211_vif *vif,
  3626. struct ieee80211_sta *sta)
  3627. {
  3628. struct mwl8k_cmd_update_stadb *cmd;
  3629. struct peer_capability_info *p;
  3630. u32 rates;
  3631. int rc;
  3632. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3633. if (cmd == NULL)
  3634. return -ENOMEM;
  3635. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3636. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3637. cmd->action = cpu_to_le32(MWL8K_STA_DB_MODIFY_ENTRY);
  3638. memcpy(cmd->peer_addr, sta->addr, ETH_ALEN);
  3639. p = &cmd->peer_info;
  3640. p->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  3641. p->basic_caps = cpu_to_le16(vif->bss_conf.assoc_capability);
  3642. p->ht_support = sta->ht_cap.ht_supported;
  3643. p->ht_caps = cpu_to_le16(sta->ht_cap.cap);
  3644. p->extended_ht_caps = (sta->ht_cap.ampdu_factor & 3) |
  3645. ((sta->ht_cap.ampdu_density & 7) << 2);
  3646. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  3647. rates = sta->supp_rates[IEEE80211_BAND_2GHZ];
  3648. else
  3649. rates = sta->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  3650. legacy_rate_mask_to_array(p->legacy_rates, rates);
  3651. memcpy(p->ht_rates, sta->ht_cap.mcs.rx_mask, 16);
  3652. p->interop = 1;
  3653. p->amsdu_enabled = 0;
  3654. rc = mwl8k_post_cmd(hw, &cmd->header);
  3655. if (!rc)
  3656. rc = p->station_id;
  3657. kfree(cmd);
  3658. return rc;
  3659. }
  3660. static int mwl8k_cmd_update_stadb_del(struct ieee80211_hw *hw,
  3661. struct ieee80211_vif *vif, u8 *addr)
  3662. {
  3663. struct mwl8k_cmd_update_stadb *cmd;
  3664. int rc;
  3665. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  3666. if (cmd == NULL)
  3667. return -ENOMEM;
  3668. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  3669. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  3670. cmd->action = cpu_to_le32(MWL8K_STA_DB_DEL_ENTRY);
  3671. memcpy(cmd->peer_addr, addr, ETH_ALEN);
  3672. rc = mwl8k_post_cmd(hw, &cmd->header);
  3673. kfree(cmd);
  3674. return rc;
  3675. }
  3676. /*
  3677. * Interrupt handling.
  3678. */
  3679. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  3680. {
  3681. struct ieee80211_hw *hw = dev_id;
  3682. struct mwl8k_priv *priv = hw->priv;
  3683. u32 status;
  3684. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3685. if (!status)
  3686. return IRQ_NONE;
  3687. if (status & MWL8K_A2H_INT_TX_DONE) {
  3688. status &= ~MWL8K_A2H_INT_TX_DONE;
  3689. tasklet_schedule(&priv->poll_tx_task);
  3690. }
  3691. if (status & MWL8K_A2H_INT_RX_READY) {
  3692. status &= ~MWL8K_A2H_INT_RX_READY;
  3693. tasklet_schedule(&priv->poll_rx_task);
  3694. }
  3695. if (status & MWL8K_A2H_INT_BA_WATCHDOG) {
  3696. iowrite32(~MWL8K_A2H_INT_BA_WATCHDOG,
  3697. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3698. atomic_inc(&priv->watchdog_event_pending);
  3699. status &= ~MWL8K_A2H_INT_BA_WATCHDOG;
  3700. ieee80211_queue_work(hw, &priv->watchdog_ba_handle);
  3701. }
  3702. if (status)
  3703. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3704. if (status & MWL8K_A2H_INT_OPC_DONE) {
  3705. if (priv->hostcmd_wait != NULL)
  3706. complete(priv->hostcmd_wait);
  3707. }
  3708. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  3709. if (!mutex_is_locked(&priv->fw_mutex) &&
  3710. priv->radio_on && priv->pending_tx_pkts)
  3711. mwl8k_tx_start(priv);
  3712. }
  3713. return IRQ_HANDLED;
  3714. }
  3715. static void mwl8k_tx_poll(unsigned long data)
  3716. {
  3717. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3718. struct mwl8k_priv *priv = hw->priv;
  3719. int limit;
  3720. int i;
  3721. limit = 32;
  3722. spin_lock_bh(&priv->tx_lock);
  3723. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3724. limit -= mwl8k_txq_reclaim(hw, i, limit, 0);
  3725. if (!priv->pending_tx_pkts && priv->tx_wait != NULL) {
  3726. complete(priv->tx_wait);
  3727. priv->tx_wait = NULL;
  3728. }
  3729. spin_unlock_bh(&priv->tx_lock);
  3730. if (limit) {
  3731. writel(~MWL8K_A2H_INT_TX_DONE,
  3732. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3733. } else {
  3734. tasklet_schedule(&priv->poll_tx_task);
  3735. }
  3736. }
  3737. static void mwl8k_rx_poll(unsigned long data)
  3738. {
  3739. struct ieee80211_hw *hw = (struct ieee80211_hw *)data;
  3740. struct mwl8k_priv *priv = hw->priv;
  3741. int limit;
  3742. limit = 32;
  3743. limit -= rxq_process(hw, 0, limit);
  3744. limit -= rxq_refill(hw, 0, limit);
  3745. if (limit) {
  3746. writel(~MWL8K_A2H_INT_RX_READY,
  3747. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  3748. } else {
  3749. tasklet_schedule(&priv->poll_rx_task);
  3750. }
  3751. }
  3752. /*
  3753. * Core driver operations.
  3754. */
  3755. static void mwl8k_tx(struct ieee80211_hw *hw,
  3756. struct ieee80211_tx_control *control,
  3757. struct sk_buff *skb)
  3758. {
  3759. struct mwl8k_priv *priv = hw->priv;
  3760. int index = skb_get_queue_mapping(skb);
  3761. if (!priv->radio_on) {
  3762. wiphy_debug(hw->wiphy,
  3763. "dropped TX frame since radio disabled\n");
  3764. dev_kfree_skb(skb);
  3765. return;
  3766. }
  3767. mwl8k_txq_xmit(hw, index, control->sta, skb);
  3768. }
  3769. static int mwl8k_start(struct ieee80211_hw *hw)
  3770. {
  3771. struct mwl8k_priv *priv = hw->priv;
  3772. int rc;
  3773. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  3774. IRQF_SHARED, MWL8K_NAME, hw);
  3775. if (rc) {
  3776. priv->irq = -1;
  3777. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  3778. return -EIO;
  3779. }
  3780. priv->irq = priv->pdev->irq;
  3781. /* Enable TX reclaim and RX tasklets. */
  3782. tasklet_enable(&priv->poll_tx_task);
  3783. tasklet_enable(&priv->poll_rx_task);
  3784. /* Enable interrupts */
  3785. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3786. iowrite32(MWL8K_A2H_EVENTS,
  3787. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  3788. rc = mwl8k_fw_lock(hw);
  3789. if (!rc) {
  3790. rc = mwl8k_cmd_radio_enable(hw);
  3791. if (!priv->ap_fw) {
  3792. if (!rc)
  3793. rc = mwl8k_cmd_enable_sniffer(hw, 0);
  3794. if (!rc)
  3795. rc = mwl8k_cmd_set_pre_scan(hw);
  3796. if (!rc)
  3797. rc = mwl8k_cmd_set_post_scan(hw,
  3798. "\x00\x00\x00\x00\x00\x00");
  3799. }
  3800. if (!rc)
  3801. rc = mwl8k_cmd_set_rateadapt_mode(hw, 0);
  3802. if (!rc)
  3803. rc = mwl8k_cmd_set_wmm_mode(hw, 0);
  3804. mwl8k_fw_unlock(hw);
  3805. }
  3806. if (rc) {
  3807. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3808. free_irq(priv->pdev->irq, hw);
  3809. priv->irq = -1;
  3810. tasklet_disable(&priv->poll_tx_task);
  3811. tasklet_disable(&priv->poll_rx_task);
  3812. } else {
  3813. ieee80211_wake_queues(hw);
  3814. }
  3815. return rc;
  3816. }
  3817. static void mwl8k_stop(struct ieee80211_hw *hw)
  3818. {
  3819. struct mwl8k_priv *priv = hw->priv;
  3820. int i;
  3821. if (!priv->hw_restart_in_progress)
  3822. mwl8k_cmd_radio_disable(hw);
  3823. ieee80211_stop_queues(hw);
  3824. /* Disable interrupts */
  3825. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  3826. if (priv->irq != -1) {
  3827. free_irq(priv->pdev->irq, hw);
  3828. priv->irq = -1;
  3829. }
  3830. /* Stop finalize join worker */
  3831. cancel_work_sync(&priv->finalize_join_worker);
  3832. cancel_work_sync(&priv->watchdog_ba_handle);
  3833. if (priv->beacon_skb != NULL)
  3834. dev_kfree_skb(priv->beacon_skb);
  3835. /* Stop TX reclaim and RX tasklets. */
  3836. tasklet_disable(&priv->poll_tx_task);
  3837. tasklet_disable(&priv->poll_rx_task);
  3838. /* Return all skbs to mac80211 */
  3839. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  3840. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  3841. }
  3842. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image);
  3843. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  3844. struct ieee80211_vif *vif)
  3845. {
  3846. struct mwl8k_priv *priv = hw->priv;
  3847. struct mwl8k_vif *mwl8k_vif;
  3848. u32 macids_supported;
  3849. int macid, rc;
  3850. struct mwl8k_device_info *di;
  3851. /*
  3852. * Reject interface creation if sniffer mode is active, as
  3853. * STA operation is mutually exclusive with hardware sniffer
  3854. * mode. (Sniffer mode is only used on STA firmware.)
  3855. */
  3856. if (priv->sniffer_enabled) {
  3857. wiphy_info(hw->wiphy,
  3858. "unable to create STA interface because sniffer mode is enabled\n");
  3859. return -EINVAL;
  3860. }
  3861. di = priv->device_info;
  3862. switch (vif->type) {
  3863. case NL80211_IFTYPE_AP:
  3864. if (!priv->ap_fw && di->fw_image_ap) {
  3865. /* we must load the ap fw to meet this request */
  3866. if (!list_empty(&priv->vif_list))
  3867. return -EBUSY;
  3868. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3869. if (rc)
  3870. return rc;
  3871. }
  3872. macids_supported = priv->ap_macids_supported;
  3873. break;
  3874. case NL80211_IFTYPE_STATION:
  3875. if (priv->ap_fw && di->fw_image_sta) {
  3876. if (!list_empty(&priv->vif_list)) {
  3877. wiphy_warn(hw->wiphy, "AP interface is running.\n"
  3878. "Adding STA interface for WDS");
  3879. } else {
  3880. /* we must load the sta fw to
  3881. * meet this request.
  3882. */
  3883. rc = mwl8k_reload_firmware(hw,
  3884. di->fw_image_sta);
  3885. if (rc)
  3886. return rc;
  3887. }
  3888. }
  3889. macids_supported = priv->sta_macids_supported;
  3890. break;
  3891. default:
  3892. return -EINVAL;
  3893. }
  3894. macid = ffs(macids_supported & ~priv->macids_used);
  3895. if (!macid--)
  3896. return -EBUSY;
  3897. /* Setup driver private area. */
  3898. mwl8k_vif = MWL8K_VIF(vif);
  3899. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  3900. mwl8k_vif->vif = vif;
  3901. mwl8k_vif->macid = macid;
  3902. mwl8k_vif->seqno = 0;
  3903. memcpy(mwl8k_vif->bssid, vif->addr, ETH_ALEN);
  3904. mwl8k_vif->is_hw_crypto_enabled = false;
  3905. /* Set the mac address. */
  3906. mwl8k_cmd_set_mac_addr(hw, vif, vif->addr);
  3907. if (vif->type == NL80211_IFTYPE_AP)
  3908. mwl8k_cmd_set_new_stn_add_self(hw, vif);
  3909. priv->macids_used |= 1 << mwl8k_vif->macid;
  3910. list_add_tail(&mwl8k_vif->list, &priv->vif_list);
  3911. return 0;
  3912. }
  3913. static void mwl8k_remove_vif(struct mwl8k_priv *priv, struct mwl8k_vif *vif)
  3914. {
  3915. /* Has ieee80211_restart_hw re-added the removed interfaces? */
  3916. if (!priv->macids_used)
  3917. return;
  3918. priv->macids_used &= ~(1 << vif->macid);
  3919. list_del(&vif->list);
  3920. }
  3921. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  3922. struct ieee80211_vif *vif)
  3923. {
  3924. struct mwl8k_priv *priv = hw->priv;
  3925. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  3926. if (vif->type == NL80211_IFTYPE_AP)
  3927. mwl8k_cmd_set_new_stn_del(hw, vif, vif->addr);
  3928. mwl8k_cmd_del_mac_addr(hw, vif, vif->addr);
  3929. mwl8k_remove_vif(priv, mwl8k_vif);
  3930. }
  3931. static void mwl8k_hw_restart_work(struct work_struct *work)
  3932. {
  3933. struct mwl8k_priv *priv =
  3934. container_of(work, struct mwl8k_priv, fw_reload);
  3935. struct ieee80211_hw *hw = priv->hw;
  3936. struct mwl8k_device_info *di;
  3937. int rc;
  3938. /* If some command is waiting for a response, clear it */
  3939. if (priv->hostcmd_wait != NULL) {
  3940. complete(priv->hostcmd_wait);
  3941. priv->hostcmd_wait = NULL;
  3942. }
  3943. priv->hw_restart_owner = current;
  3944. di = priv->device_info;
  3945. mwl8k_fw_lock(hw);
  3946. if (priv->ap_fw)
  3947. rc = mwl8k_reload_firmware(hw, di->fw_image_ap);
  3948. else
  3949. rc = mwl8k_reload_firmware(hw, di->fw_image_sta);
  3950. if (rc)
  3951. goto fail;
  3952. priv->hw_restart_owner = NULL;
  3953. priv->hw_restart_in_progress = false;
  3954. /*
  3955. * This unlock will wake up the queues and
  3956. * also opens the command path for other
  3957. * commands
  3958. */
  3959. mwl8k_fw_unlock(hw);
  3960. ieee80211_restart_hw(hw);
  3961. wiphy_err(hw->wiphy, "Firmware restarted successfully\n");
  3962. return;
  3963. fail:
  3964. mwl8k_fw_unlock(hw);
  3965. wiphy_err(hw->wiphy, "Firmware restart failed\n");
  3966. }
  3967. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  3968. {
  3969. struct ieee80211_conf *conf = &hw->conf;
  3970. struct mwl8k_priv *priv = hw->priv;
  3971. int rc;
  3972. rc = mwl8k_fw_lock(hw);
  3973. if (rc)
  3974. return rc;
  3975. if (conf->flags & IEEE80211_CONF_IDLE)
  3976. rc = mwl8k_cmd_radio_disable(hw);
  3977. else
  3978. rc = mwl8k_cmd_radio_enable(hw);
  3979. if (rc)
  3980. goto out;
  3981. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  3982. rc = mwl8k_cmd_set_rf_channel(hw, conf);
  3983. if (rc)
  3984. goto out;
  3985. }
  3986. if (conf->power_level > 18)
  3987. conf->power_level = 18;
  3988. if (priv->ap_fw) {
  3989. if (conf->flags & IEEE80211_CONF_CHANGE_POWER) {
  3990. rc = mwl8k_cmd_tx_power(hw, conf, conf->power_level);
  3991. if (rc)
  3992. goto out;
  3993. }
  3994. } else {
  3995. rc = mwl8k_cmd_rf_tx_power(hw, conf->power_level);
  3996. if (rc)
  3997. goto out;
  3998. rc = mwl8k_cmd_mimo_config(hw, 0x7, 0x7);
  3999. }
  4000. out:
  4001. mwl8k_fw_unlock(hw);
  4002. return rc;
  4003. }
  4004. static void
  4005. mwl8k_bss_info_changed_sta(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4006. struct ieee80211_bss_conf *info, u32 changed)
  4007. {
  4008. struct mwl8k_priv *priv = hw->priv;
  4009. u32 ap_legacy_rates = 0;
  4010. u8 ap_mcs_rates[16];
  4011. int rc;
  4012. if (mwl8k_fw_lock(hw))
  4013. return;
  4014. /*
  4015. * No need to capture a beacon if we're no longer associated.
  4016. */
  4017. if ((changed & BSS_CHANGED_ASSOC) && !vif->bss_conf.assoc)
  4018. priv->capture_beacon = false;
  4019. /*
  4020. * Get the AP's legacy and MCS rates.
  4021. */
  4022. if (vif->bss_conf.assoc) {
  4023. struct ieee80211_sta *ap;
  4024. rcu_read_lock();
  4025. ap = ieee80211_find_sta(vif, vif->bss_conf.bssid);
  4026. if (ap == NULL) {
  4027. rcu_read_unlock();
  4028. goto out;
  4029. }
  4030. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ) {
  4031. ap_legacy_rates = ap->supp_rates[IEEE80211_BAND_2GHZ];
  4032. } else {
  4033. ap_legacy_rates =
  4034. ap->supp_rates[IEEE80211_BAND_5GHZ] << 5;
  4035. }
  4036. memcpy(ap_mcs_rates, ap->ht_cap.mcs.rx_mask, 16);
  4037. rcu_read_unlock();
  4038. }
  4039. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4040. !priv->ap_fw) {
  4041. rc = mwl8k_cmd_set_rate(hw, vif, ap_legacy_rates, ap_mcs_rates);
  4042. if (rc)
  4043. goto out;
  4044. rc = mwl8k_cmd_use_fixed_rate_sta(hw);
  4045. if (rc)
  4046. goto out;
  4047. } else {
  4048. if ((changed & BSS_CHANGED_ASSOC) && vif->bss_conf.assoc &&
  4049. priv->ap_fw) {
  4050. int idx;
  4051. int rate;
  4052. /* Use AP firmware specific rate command.
  4053. */
  4054. idx = ffs(vif->bss_conf.basic_rates);
  4055. if (idx)
  4056. idx--;
  4057. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4058. rate = mwl8k_rates_24[idx].hw_value;
  4059. else
  4060. rate = mwl8k_rates_50[idx].hw_value;
  4061. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4062. }
  4063. }
  4064. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4065. rc = mwl8k_set_radio_preamble(hw,
  4066. vif->bss_conf.use_short_preamble);
  4067. if (rc)
  4068. goto out;
  4069. }
  4070. if ((changed & BSS_CHANGED_ERP_SLOT) && !priv->ap_fw) {
  4071. rc = mwl8k_cmd_set_slot(hw, vif->bss_conf.use_short_slot);
  4072. if (rc)
  4073. goto out;
  4074. }
  4075. if (vif->bss_conf.assoc && !priv->ap_fw &&
  4076. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_ERP_CTS_PROT |
  4077. BSS_CHANGED_HT))) {
  4078. rc = mwl8k_cmd_set_aid(hw, vif, ap_legacy_rates);
  4079. if (rc)
  4080. goto out;
  4081. }
  4082. if (vif->bss_conf.assoc &&
  4083. (changed & (BSS_CHANGED_ASSOC | BSS_CHANGED_BEACON_INT))) {
  4084. /*
  4085. * Finalize the join. Tell rx handler to process
  4086. * next beacon from our BSSID.
  4087. */
  4088. memcpy(priv->capture_bssid, vif->bss_conf.bssid, ETH_ALEN);
  4089. priv->capture_beacon = true;
  4090. }
  4091. out:
  4092. mwl8k_fw_unlock(hw);
  4093. }
  4094. static void
  4095. mwl8k_bss_info_changed_ap(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4096. struct ieee80211_bss_conf *info, u32 changed)
  4097. {
  4098. int rc;
  4099. if (mwl8k_fw_lock(hw))
  4100. return;
  4101. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  4102. rc = mwl8k_set_radio_preamble(hw,
  4103. vif->bss_conf.use_short_preamble);
  4104. if (rc)
  4105. goto out;
  4106. }
  4107. if (changed & BSS_CHANGED_BASIC_RATES) {
  4108. int idx;
  4109. int rate;
  4110. /*
  4111. * Use lowest supported basic rate for multicasts
  4112. * and management frames (such as probe responses --
  4113. * beacons will always go out at 1 Mb/s).
  4114. */
  4115. idx = ffs(vif->bss_conf.basic_rates);
  4116. if (idx)
  4117. idx--;
  4118. if (hw->conf.chandef.chan->band == IEEE80211_BAND_2GHZ)
  4119. rate = mwl8k_rates_24[idx].hw_value;
  4120. else
  4121. rate = mwl8k_rates_50[idx].hw_value;
  4122. mwl8k_cmd_use_fixed_rate_ap(hw, rate, rate);
  4123. }
  4124. if (changed & (BSS_CHANGED_BEACON_INT | BSS_CHANGED_BEACON)) {
  4125. struct sk_buff *skb;
  4126. skb = ieee80211_beacon_get(hw, vif);
  4127. if (skb != NULL) {
  4128. mwl8k_cmd_set_beacon(hw, vif, skb->data, skb->len);
  4129. kfree_skb(skb);
  4130. }
  4131. }
  4132. if (changed & BSS_CHANGED_BEACON_ENABLED)
  4133. mwl8k_cmd_bss_start(hw, vif, info->enable_beacon);
  4134. out:
  4135. mwl8k_fw_unlock(hw);
  4136. }
  4137. static void
  4138. mwl8k_bss_info_changed(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4139. struct ieee80211_bss_conf *info, u32 changed)
  4140. {
  4141. if (vif->type == NL80211_IFTYPE_STATION)
  4142. mwl8k_bss_info_changed_sta(hw, vif, info, changed);
  4143. if (vif->type == NL80211_IFTYPE_AP)
  4144. mwl8k_bss_info_changed_ap(hw, vif, info, changed);
  4145. }
  4146. static u64 mwl8k_prepare_multicast(struct ieee80211_hw *hw,
  4147. struct netdev_hw_addr_list *mc_list)
  4148. {
  4149. struct mwl8k_cmd_pkt *cmd;
  4150. /*
  4151. * Synthesize and return a command packet that programs the
  4152. * hardware multicast address filter. At this point we don't
  4153. * know whether FIF_ALLMULTI is being requested, but if it is,
  4154. * we'll end up throwing this packet away and creating a new
  4155. * one in mwl8k_configure_filter().
  4156. */
  4157. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 0, mc_list);
  4158. return (unsigned long)cmd;
  4159. }
  4160. static int
  4161. mwl8k_configure_filter_sniffer(struct ieee80211_hw *hw,
  4162. unsigned int changed_flags,
  4163. unsigned int *total_flags)
  4164. {
  4165. struct mwl8k_priv *priv = hw->priv;
  4166. /*
  4167. * Hardware sniffer mode is mutually exclusive with STA
  4168. * operation, so refuse to enable sniffer mode if a STA
  4169. * interface is active.
  4170. */
  4171. if (!list_empty(&priv->vif_list)) {
  4172. if (net_ratelimit())
  4173. wiphy_info(hw->wiphy,
  4174. "not enabling sniffer mode because STA interface is active\n");
  4175. return 0;
  4176. }
  4177. if (!priv->sniffer_enabled) {
  4178. if (mwl8k_cmd_enable_sniffer(hw, 1))
  4179. return 0;
  4180. priv->sniffer_enabled = true;
  4181. }
  4182. *total_flags &= FIF_PROMISC_IN_BSS | FIF_ALLMULTI |
  4183. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL |
  4184. FIF_OTHER_BSS;
  4185. return 1;
  4186. }
  4187. static struct mwl8k_vif *mwl8k_first_vif(struct mwl8k_priv *priv)
  4188. {
  4189. if (!list_empty(&priv->vif_list))
  4190. return list_entry(priv->vif_list.next, struct mwl8k_vif, list);
  4191. return NULL;
  4192. }
  4193. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  4194. unsigned int changed_flags,
  4195. unsigned int *total_flags,
  4196. u64 multicast)
  4197. {
  4198. struct mwl8k_priv *priv = hw->priv;
  4199. struct mwl8k_cmd_pkt *cmd = (void *)(unsigned long)multicast;
  4200. /*
  4201. * AP firmware doesn't allow fine-grained control over
  4202. * the receive filter.
  4203. */
  4204. if (priv->ap_fw) {
  4205. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4206. kfree(cmd);
  4207. return;
  4208. }
  4209. /*
  4210. * Enable hardware sniffer mode if FIF_CONTROL or
  4211. * FIF_OTHER_BSS is requested.
  4212. */
  4213. if (*total_flags & (FIF_CONTROL | FIF_OTHER_BSS) &&
  4214. mwl8k_configure_filter_sniffer(hw, changed_flags, total_flags)) {
  4215. kfree(cmd);
  4216. return;
  4217. }
  4218. /* Clear unsupported feature flags */
  4219. *total_flags &= FIF_ALLMULTI | FIF_BCN_PRBRESP_PROMISC;
  4220. if (mwl8k_fw_lock(hw)) {
  4221. kfree(cmd);
  4222. return;
  4223. }
  4224. if (priv->sniffer_enabled) {
  4225. mwl8k_cmd_enable_sniffer(hw, 0);
  4226. priv->sniffer_enabled = false;
  4227. }
  4228. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  4229. if (*total_flags & FIF_BCN_PRBRESP_PROMISC) {
  4230. /*
  4231. * Disable the BSS filter.
  4232. */
  4233. mwl8k_cmd_set_pre_scan(hw);
  4234. } else {
  4235. struct mwl8k_vif *mwl8k_vif;
  4236. const u8 *bssid;
  4237. /*
  4238. * Enable the BSS filter.
  4239. *
  4240. * If there is an active STA interface, use that
  4241. * interface's BSSID, otherwise use a dummy one
  4242. * (where the OUI part needs to be nonzero for
  4243. * the BSSID to be accepted by POST_SCAN).
  4244. */
  4245. mwl8k_vif = mwl8k_first_vif(priv);
  4246. if (mwl8k_vif != NULL)
  4247. bssid = mwl8k_vif->vif->bss_conf.bssid;
  4248. else
  4249. bssid = "\x01\x00\x00\x00\x00\x00";
  4250. mwl8k_cmd_set_post_scan(hw, bssid);
  4251. }
  4252. }
  4253. /*
  4254. * If FIF_ALLMULTI is being requested, throw away the command
  4255. * packet that ->prepare_multicast() built and replace it with
  4256. * a command packet that enables reception of all multicast
  4257. * packets.
  4258. */
  4259. if (*total_flags & FIF_ALLMULTI) {
  4260. kfree(cmd);
  4261. cmd = __mwl8k_cmd_mac_multicast_adr(hw, 1, NULL);
  4262. }
  4263. if (cmd != NULL) {
  4264. mwl8k_post_cmd(hw, cmd);
  4265. kfree(cmd);
  4266. }
  4267. mwl8k_fw_unlock(hw);
  4268. }
  4269. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  4270. {
  4271. return mwl8k_cmd_set_rts_threshold(hw, value);
  4272. }
  4273. static int mwl8k_sta_remove(struct ieee80211_hw *hw,
  4274. struct ieee80211_vif *vif,
  4275. struct ieee80211_sta *sta)
  4276. {
  4277. struct mwl8k_priv *priv = hw->priv;
  4278. if (priv->ap_fw)
  4279. return mwl8k_cmd_set_new_stn_del(hw, vif, sta->addr);
  4280. else
  4281. return mwl8k_cmd_update_stadb_del(hw, vif, sta->addr);
  4282. }
  4283. static int mwl8k_sta_add(struct ieee80211_hw *hw,
  4284. struct ieee80211_vif *vif,
  4285. struct ieee80211_sta *sta)
  4286. {
  4287. struct mwl8k_priv *priv = hw->priv;
  4288. int ret;
  4289. int i;
  4290. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  4291. struct ieee80211_key_conf *key;
  4292. if (!priv->ap_fw) {
  4293. ret = mwl8k_cmd_update_stadb_add(hw, vif, sta);
  4294. if (ret >= 0) {
  4295. MWL8K_STA(sta)->peer_id = ret;
  4296. if (sta->ht_cap.ht_supported)
  4297. MWL8K_STA(sta)->is_ampdu_allowed = true;
  4298. ret = 0;
  4299. }
  4300. } else {
  4301. ret = mwl8k_cmd_set_new_stn_add(hw, vif, sta);
  4302. }
  4303. for (i = 0; i < NUM_WEP_KEYS; i++) {
  4304. key = IEEE80211_KEY_CONF(mwl8k_vif->wep_key_conf[i].key);
  4305. if (mwl8k_vif->wep_key_conf[i].enabled)
  4306. mwl8k_set_key(hw, SET_KEY, vif, sta, key);
  4307. }
  4308. return ret;
  4309. }
  4310. static int mwl8k_conf_tx(struct ieee80211_hw *hw,
  4311. struct ieee80211_vif *vif, u16 queue,
  4312. const struct ieee80211_tx_queue_params *params)
  4313. {
  4314. struct mwl8k_priv *priv = hw->priv;
  4315. int rc;
  4316. rc = mwl8k_fw_lock(hw);
  4317. if (!rc) {
  4318. BUG_ON(queue > MWL8K_TX_WMM_QUEUES - 1);
  4319. memcpy(&priv->wmm_params[queue], params, sizeof(*params));
  4320. if (!priv->wmm_enabled)
  4321. rc = mwl8k_cmd_set_wmm_mode(hw, 1);
  4322. if (!rc) {
  4323. int q = MWL8K_TX_WMM_QUEUES - 1 - queue;
  4324. rc = mwl8k_cmd_set_edca_params(hw, q,
  4325. params->cw_min,
  4326. params->cw_max,
  4327. params->aifs,
  4328. params->txop);
  4329. }
  4330. mwl8k_fw_unlock(hw);
  4331. }
  4332. return rc;
  4333. }
  4334. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  4335. struct ieee80211_low_level_stats *stats)
  4336. {
  4337. return mwl8k_cmd_get_stat(hw, stats);
  4338. }
  4339. static int mwl8k_get_survey(struct ieee80211_hw *hw, int idx,
  4340. struct survey_info *survey)
  4341. {
  4342. struct mwl8k_priv *priv = hw->priv;
  4343. struct ieee80211_conf *conf = &hw->conf;
  4344. if (idx != 0)
  4345. return -ENOENT;
  4346. survey->channel = conf->chandef.chan;
  4347. survey->filled = SURVEY_INFO_NOISE_DBM;
  4348. survey->noise = priv->noise;
  4349. return 0;
  4350. }
  4351. #define MAX_AMPDU_ATTEMPTS 5
  4352. static int
  4353. mwl8k_ampdu_action(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  4354. enum ieee80211_ampdu_mlme_action action,
  4355. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  4356. u8 buf_size)
  4357. {
  4358. int i, rc = 0;
  4359. struct mwl8k_priv *priv = hw->priv;
  4360. struct mwl8k_ampdu_stream *stream;
  4361. u8 *addr = sta->addr, idx;
  4362. struct mwl8k_sta *sta_info = MWL8K_STA(sta);
  4363. if (!(hw->flags & IEEE80211_HW_AMPDU_AGGREGATION))
  4364. return -ENOTSUPP;
  4365. spin_lock(&priv->stream_lock);
  4366. stream = mwl8k_lookup_stream(hw, addr, tid);
  4367. switch (action) {
  4368. case IEEE80211_AMPDU_RX_START:
  4369. case IEEE80211_AMPDU_RX_STOP:
  4370. break;
  4371. case IEEE80211_AMPDU_TX_START:
  4372. /* By the time we get here the hw queues may contain outgoing
  4373. * packets for this RA/TID that are not part of this BA
  4374. * session. The hw will assign sequence numbers to these
  4375. * packets as they go out. So if we query the hw for its next
  4376. * sequence number and use that for the SSN here, it may end up
  4377. * being wrong, which will lead to sequence number mismatch at
  4378. * the recipient. To avoid this, we reset the sequence number
  4379. * to O for the first MPDU in this BA stream.
  4380. */
  4381. *ssn = 0;
  4382. if (stream == NULL) {
  4383. /* This means that somebody outside this driver called
  4384. * ieee80211_start_tx_ba_session. This is unexpected
  4385. * because we do our own rate control. Just warn and
  4386. * move on.
  4387. */
  4388. wiphy_warn(hw->wiphy, "Unexpected call to %s. "
  4389. "Proceeding anyway.\n", __func__);
  4390. stream = mwl8k_add_stream(hw, sta, tid);
  4391. }
  4392. if (stream == NULL) {
  4393. wiphy_debug(hw->wiphy, "no free AMPDU streams\n");
  4394. rc = -EBUSY;
  4395. break;
  4396. }
  4397. stream->state = AMPDU_STREAM_IN_PROGRESS;
  4398. /* Release the lock before we do the time consuming stuff */
  4399. spin_unlock(&priv->stream_lock);
  4400. for (i = 0; i < MAX_AMPDU_ATTEMPTS; i++) {
  4401. /* Check if link is still valid */
  4402. if (!sta_info->is_ampdu_allowed) {
  4403. spin_lock(&priv->stream_lock);
  4404. mwl8k_remove_stream(hw, stream);
  4405. spin_unlock(&priv->stream_lock);
  4406. return -EBUSY;
  4407. }
  4408. rc = mwl8k_check_ba(hw, stream, vif);
  4409. /* If HW restart is in progress mwl8k_post_cmd will
  4410. * return -EBUSY. Avoid retrying mwl8k_check_ba in
  4411. * such cases
  4412. */
  4413. if (!rc || rc == -EBUSY)
  4414. break;
  4415. /*
  4416. * HW queues take time to be flushed, give them
  4417. * sufficient time
  4418. */
  4419. msleep(1000);
  4420. }
  4421. spin_lock(&priv->stream_lock);
  4422. if (rc) {
  4423. wiphy_err(hw->wiphy, "Stream for tid %d busy after %d"
  4424. " attempts\n", tid, MAX_AMPDU_ATTEMPTS);
  4425. mwl8k_remove_stream(hw, stream);
  4426. rc = -EBUSY;
  4427. break;
  4428. }
  4429. ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid);
  4430. break;
  4431. case IEEE80211_AMPDU_TX_STOP_CONT:
  4432. case IEEE80211_AMPDU_TX_STOP_FLUSH:
  4433. case IEEE80211_AMPDU_TX_STOP_FLUSH_CONT:
  4434. if (stream) {
  4435. if (stream->state == AMPDU_STREAM_ACTIVE) {
  4436. idx = stream->idx;
  4437. spin_unlock(&priv->stream_lock);
  4438. mwl8k_destroy_ba(hw, idx);
  4439. spin_lock(&priv->stream_lock);
  4440. }
  4441. mwl8k_remove_stream(hw, stream);
  4442. }
  4443. ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid);
  4444. break;
  4445. case IEEE80211_AMPDU_TX_OPERATIONAL:
  4446. BUG_ON(stream == NULL);
  4447. BUG_ON(stream->state != AMPDU_STREAM_IN_PROGRESS);
  4448. spin_unlock(&priv->stream_lock);
  4449. rc = mwl8k_create_ba(hw, stream, buf_size, vif);
  4450. spin_lock(&priv->stream_lock);
  4451. if (!rc)
  4452. stream->state = AMPDU_STREAM_ACTIVE;
  4453. else {
  4454. idx = stream->idx;
  4455. spin_unlock(&priv->stream_lock);
  4456. mwl8k_destroy_ba(hw, idx);
  4457. spin_lock(&priv->stream_lock);
  4458. wiphy_debug(hw->wiphy,
  4459. "Failed adding stream for sta %pM tid %d\n",
  4460. addr, tid);
  4461. mwl8k_remove_stream(hw, stream);
  4462. }
  4463. break;
  4464. default:
  4465. rc = -ENOTSUPP;
  4466. }
  4467. spin_unlock(&priv->stream_lock);
  4468. return rc;
  4469. }
  4470. static const struct ieee80211_ops mwl8k_ops = {
  4471. .tx = mwl8k_tx,
  4472. .start = mwl8k_start,
  4473. .stop = mwl8k_stop,
  4474. .add_interface = mwl8k_add_interface,
  4475. .remove_interface = mwl8k_remove_interface,
  4476. .config = mwl8k_config,
  4477. .bss_info_changed = mwl8k_bss_info_changed,
  4478. .prepare_multicast = mwl8k_prepare_multicast,
  4479. .configure_filter = mwl8k_configure_filter,
  4480. .set_key = mwl8k_set_key,
  4481. .set_rts_threshold = mwl8k_set_rts_threshold,
  4482. .sta_add = mwl8k_sta_add,
  4483. .sta_remove = mwl8k_sta_remove,
  4484. .conf_tx = mwl8k_conf_tx,
  4485. .get_stats = mwl8k_get_stats,
  4486. .get_survey = mwl8k_get_survey,
  4487. .ampdu_action = mwl8k_ampdu_action,
  4488. };
  4489. static void mwl8k_finalize_join_worker(struct work_struct *work)
  4490. {
  4491. struct mwl8k_priv *priv =
  4492. container_of(work, struct mwl8k_priv, finalize_join_worker);
  4493. struct sk_buff *skb = priv->beacon_skb;
  4494. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  4495. int len = skb->len - offsetof(struct ieee80211_mgmt, u.beacon.variable);
  4496. const u8 *tim = cfg80211_find_ie(WLAN_EID_TIM,
  4497. mgmt->u.beacon.variable, len);
  4498. int dtim_period = 1;
  4499. if (tim && tim[1] >= 2)
  4500. dtim_period = tim[3];
  4501. mwl8k_cmd_finalize_join(priv->hw, skb->data, skb->len, dtim_period);
  4502. dev_kfree_skb(skb);
  4503. priv->beacon_skb = NULL;
  4504. }
  4505. enum {
  4506. MWL8363 = 0,
  4507. MWL8687,
  4508. MWL8366,
  4509. MWL8764,
  4510. };
  4511. #define MWL8K_8366_AP_FW_API 3
  4512. #define _MWL8K_8366_AP_FW(api) "mwl8k/fmimage_8366_ap-" #api ".fw"
  4513. #define MWL8K_8366_AP_FW(api) _MWL8K_8366_AP_FW(api)
  4514. #define MWL8K_8764_AP_FW_API 1
  4515. #define _MWL8K_8764_AP_FW(api) "mwl8k/fmimage_8764_ap-" #api ".fw"
  4516. #define MWL8K_8764_AP_FW(api) _MWL8K_8764_AP_FW(api)
  4517. static struct mwl8k_device_info mwl8k_info_tbl[] = {
  4518. [MWL8363] = {
  4519. .part_name = "88w8363",
  4520. .helper_image = "mwl8k/helper_8363.fw",
  4521. .fw_image_sta = "mwl8k/fmimage_8363.fw",
  4522. },
  4523. [MWL8687] = {
  4524. .part_name = "88w8687",
  4525. .helper_image = "mwl8k/helper_8687.fw",
  4526. .fw_image_sta = "mwl8k/fmimage_8687.fw",
  4527. },
  4528. [MWL8366] = {
  4529. .part_name = "88w8366",
  4530. .helper_image = "mwl8k/helper_8366.fw",
  4531. .fw_image_sta = "mwl8k/fmimage_8366.fw",
  4532. .fw_image_ap = MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API),
  4533. .fw_api_ap = MWL8K_8366_AP_FW_API,
  4534. .ap_rxd_ops = &rxd_ap_ops,
  4535. },
  4536. [MWL8764] = {
  4537. .part_name = "88w8764",
  4538. .fw_image_ap = MWL8K_8764_AP_FW(MWL8K_8764_AP_FW_API),
  4539. .fw_api_ap = MWL8K_8764_AP_FW_API,
  4540. .ap_rxd_ops = &rxd_ap_ops,
  4541. },
  4542. };
  4543. MODULE_FIRMWARE("mwl8k/helper_8363.fw");
  4544. MODULE_FIRMWARE("mwl8k/fmimage_8363.fw");
  4545. MODULE_FIRMWARE("mwl8k/helper_8687.fw");
  4546. MODULE_FIRMWARE("mwl8k/fmimage_8687.fw");
  4547. MODULE_FIRMWARE("mwl8k/helper_8366.fw");
  4548. MODULE_FIRMWARE("mwl8k/fmimage_8366.fw");
  4549. MODULE_FIRMWARE(MWL8K_8366_AP_FW(MWL8K_8366_AP_FW_API));
  4550. static DEFINE_PCI_DEVICE_TABLE(mwl8k_pci_id_table) = {
  4551. { PCI_VDEVICE(MARVELL, 0x2a0a), .driver_data = MWL8363, },
  4552. { PCI_VDEVICE(MARVELL, 0x2a0c), .driver_data = MWL8363, },
  4553. { PCI_VDEVICE(MARVELL, 0x2a24), .driver_data = MWL8363, },
  4554. { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = MWL8687, },
  4555. { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = MWL8687, },
  4556. { PCI_VDEVICE(MARVELL, 0x2a40), .driver_data = MWL8366, },
  4557. { PCI_VDEVICE(MARVELL, 0x2a41), .driver_data = MWL8366, },
  4558. { PCI_VDEVICE(MARVELL, 0x2a42), .driver_data = MWL8366, },
  4559. { PCI_VDEVICE(MARVELL, 0x2a43), .driver_data = MWL8366, },
  4560. { PCI_VDEVICE(MARVELL, 0x2b36), .driver_data = MWL8764, },
  4561. { },
  4562. };
  4563. MODULE_DEVICE_TABLE(pci, mwl8k_pci_id_table);
  4564. static int mwl8k_request_alt_fw(struct mwl8k_priv *priv)
  4565. {
  4566. int rc;
  4567. printk(KERN_ERR "%s: Error requesting preferred fw %s.\n"
  4568. "Trying alternative firmware %s\n", pci_name(priv->pdev),
  4569. priv->fw_pref, priv->fw_alt);
  4570. rc = mwl8k_request_fw(priv, priv->fw_alt, &priv->fw_ucode, true);
  4571. if (rc) {
  4572. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4573. pci_name(priv->pdev), priv->fw_alt);
  4574. return rc;
  4575. }
  4576. return 0;
  4577. }
  4578. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv);
  4579. static void mwl8k_fw_state_machine(const struct firmware *fw, void *context)
  4580. {
  4581. struct mwl8k_priv *priv = context;
  4582. struct mwl8k_device_info *di = priv->device_info;
  4583. int rc;
  4584. switch (priv->fw_state) {
  4585. case FW_STATE_INIT:
  4586. if (!fw) {
  4587. printk(KERN_ERR "%s: Error requesting helper fw %s\n",
  4588. pci_name(priv->pdev), di->helper_image);
  4589. goto fail;
  4590. }
  4591. priv->fw_helper = fw;
  4592. rc = mwl8k_request_fw(priv, priv->fw_pref, &priv->fw_ucode,
  4593. true);
  4594. if (rc && priv->fw_alt) {
  4595. rc = mwl8k_request_alt_fw(priv);
  4596. if (rc)
  4597. goto fail;
  4598. priv->fw_state = FW_STATE_LOADING_ALT;
  4599. } else if (rc)
  4600. goto fail;
  4601. else
  4602. priv->fw_state = FW_STATE_LOADING_PREF;
  4603. break;
  4604. case FW_STATE_LOADING_PREF:
  4605. if (!fw) {
  4606. if (priv->fw_alt) {
  4607. rc = mwl8k_request_alt_fw(priv);
  4608. if (rc)
  4609. goto fail;
  4610. priv->fw_state = FW_STATE_LOADING_ALT;
  4611. } else
  4612. goto fail;
  4613. } else {
  4614. priv->fw_ucode = fw;
  4615. rc = mwl8k_firmware_load_success(priv);
  4616. if (rc)
  4617. goto fail;
  4618. else
  4619. complete(&priv->firmware_loading_complete);
  4620. }
  4621. break;
  4622. case FW_STATE_LOADING_ALT:
  4623. if (!fw) {
  4624. printk(KERN_ERR "%s: Error requesting alt fw %s\n",
  4625. pci_name(priv->pdev), di->helper_image);
  4626. goto fail;
  4627. }
  4628. priv->fw_ucode = fw;
  4629. rc = mwl8k_firmware_load_success(priv);
  4630. if (rc)
  4631. goto fail;
  4632. else
  4633. complete(&priv->firmware_loading_complete);
  4634. break;
  4635. default:
  4636. printk(KERN_ERR "%s: Unexpected firmware loading state: %d\n",
  4637. MWL8K_NAME, priv->fw_state);
  4638. BUG_ON(1);
  4639. }
  4640. return;
  4641. fail:
  4642. priv->fw_state = FW_STATE_ERROR;
  4643. complete(&priv->firmware_loading_complete);
  4644. device_release_driver(&priv->pdev->dev);
  4645. mwl8k_release_firmware(priv);
  4646. }
  4647. #define MAX_RESTART_ATTEMPTS 1
  4648. static int mwl8k_init_firmware(struct ieee80211_hw *hw, char *fw_image,
  4649. bool nowait)
  4650. {
  4651. struct mwl8k_priv *priv = hw->priv;
  4652. int rc;
  4653. int count = MAX_RESTART_ATTEMPTS;
  4654. retry:
  4655. /* Reset firmware and hardware */
  4656. mwl8k_hw_reset(priv);
  4657. /* Ask userland hotplug daemon for the device firmware */
  4658. rc = mwl8k_request_firmware(priv, fw_image, nowait);
  4659. if (rc) {
  4660. wiphy_err(hw->wiphy, "Firmware files not found\n");
  4661. return rc;
  4662. }
  4663. if (nowait)
  4664. return rc;
  4665. /* Load firmware into hardware */
  4666. rc = mwl8k_load_firmware(hw);
  4667. if (rc)
  4668. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4669. /* Reclaim memory once firmware is successfully loaded */
  4670. mwl8k_release_firmware(priv);
  4671. if (rc && count) {
  4672. /* FW did not start successfully;
  4673. * lets try one more time
  4674. */
  4675. count--;
  4676. wiphy_err(hw->wiphy, "Trying to reload the firmware again\n");
  4677. msleep(20);
  4678. goto retry;
  4679. }
  4680. return rc;
  4681. }
  4682. static int mwl8k_init_txqs(struct ieee80211_hw *hw)
  4683. {
  4684. struct mwl8k_priv *priv = hw->priv;
  4685. int rc = 0;
  4686. int i;
  4687. for (i = 0; i < mwl8k_tx_queues(priv); i++) {
  4688. rc = mwl8k_txq_init(hw, i);
  4689. if (rc)
  4690. break;
  4691. if (priv->ap_fw)
  4692. iowrite32(priv->txq[i].txd_dma,
  4693. priv->sram + priv->txq_offset[i]);
  4694. }
  4695. return rc;
  4696. }
  4697. /* initialize hw after successfully loading a firmware image */
  4698. static int mwl8k_probe_hw(struct ieee80211_hw *hw)
  4699. {
  4700. struct mwl8k_priv *priv = hw->priv;
  4701. int rc = 0;
  4702. int i;
  4703. if (priv->ap_fw) {
  4704. priv->rxd_ops = priv->device_info->ap_rxd_ops;
  4705. if (priv->rxd_ops == NULL) {
  4706. wiphy_err(hw->wiphy,
  4707. "Driver does not have AP firmware image support for this hardware\n");
  4708. rc = -ENOENT;
  4709. goto err_stop_firmware;
  4710. }
  4711. } else {
  4712. priv->rxd_ops = &rxd_sta_ops;
  4713. }
  4714. priv->sniffer_enabled = false;
  4715. priv->wmm_enabled = false;
  4716. priv->pending_tx_pkts = 0;
  4717. atomic_set(&priv->watchdog_event_pending, 0);
  4718. rc = mwl8k_rxq_init(hw, 0);
  4719. if (rc)
  4720. goto err_stop_firmware;
  4721. rxq_refill(hw, 0, INT_MAX);
  4722. /* For the sta firmware, we need to know the dma addresses of tx queues
  4723. * before sending MWL8K_CMD_GET_HW_SPEC. So we must initialize them
  4724. * prior to issuing this command. But for the AP case, we learn the
  4725. * total number of queues from the result CMD_GET_HW_SPEC, so for this
  4726. * case we must initialize the tx queues after.
  4727. */
  4728. priv->num_ampdu_queues = 0;
  4729. if (!priv->ap_fw) {
  4730. rc = mwl8k_init_txqs(hw);
  4731. if (rc)
  4732. goto err_free_queues;
  4733. }
  4734. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  4735. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4736. iowrite32(MWL8K_A2H_INT_TX_DONE|MWL8K_A2H_INT_RX_READY|
  4737. MWL8K_A2H_INT_BA_WATCHDOG,
  4738. priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
  4739. iowrite32(MWL8K_A2H_INT_OPC_DONE,
  4740. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  4741. rc = request_irq(priv->pdev->irq, mwl8k_interrupt,
  4742. IRQF_SHARED, MWL8K_NAME, hw);
  4743. if (rc) {
  4744. wiphy_err(hw->wiphy, "failed to register IRQ handler\n");
  4745. goto err_free_queues;
  4746. }
  4747. /*
  4748. * When hw restart is requested,
  4749. * mac80211 will take care of clearing
  4750. * the ampdu streams, so do not clear
  4751. * the ampdu state here
  4752. */
  4753. if (!priv->hw_restart_in_progress)
  4754. memset(priv->ampdu, 0, sizeof(priv->ampdu));
  4755. /*
  4756. * Temporarily enable interrupts. Initial firmware host
  4757. * commands use interrupts and avoid polling. Disable
  4758. * interrupts when done.
  4759. */
  4760. iowrite32(MWL8K_A2H_EVENTS, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4761. /* Get config data, mac addrs etc */
  4762. if (priv->ap_fw) {
  4763. rc = mwl8k_cmd_get_hw_spec_ap(hw);
  4764. if (!rc)
  4765. rc = mwl8k_init_txqs(hw);
  4766. if (!rc)
  4767. rc = mwl8k_cmd_set_hw_spec(hw);
  4768. } else {
  4769. rc = mwl8k_cmd_get_hw_spec_sta(hw);
  4770. }
  4771. if (rc) {
  4772. wiphy_err(hw->wiphy, "Cannot initialise firmware\n");
  4773. goto err_free_irq;
  4774. }
  4775. /* Turn radio off */
  4776. rc = mwl8k_cmd_radio_disable(hw);
  4777. if (rc) {
  4778. wiphy_err(hw->wiphy, "Cannot disable\n");
  4779. goto err_free_irq;
  4780. }
  4781. /* Clear MAC address */
  4782. rc = mwl8k_cmd_set_mac_addr(hw, NULL, "\x00\x00\x00\x00\x00\x00");
  4783. if (rc) {
  4784. wiphy_err(hw->wiphy, "Cannot clear MAC address\n");
  4785. goto err_free_irq;
  4786. }
  4787. /* Configure Antennas */
  4788. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_RX, 0x3);
  4789. if (rc)
  4790. wiphy_warn(hw->wiphy, "failed to set # of RX antennas");
  4791. rc = mwl8k_cmd_rf_antenna(hw, MWL8K_RF_ANTENNA_TX, 0x7);
  4792. if (rc)
  4793. wiphy_warn(hw->wiphy, "failed to set # of TX antennas");
  4794. /* Disable interrupts */
  4795. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4796. free_irq(priv->pdev->irq, hw);
  4797. wiphy_info(hw->wiphy, "%s v%d, %pm, %s firmware %u.%u.%u.%u\n",
  4798. priv->device_info->part_name,
  4799. priv->hw_rev, hw->wiphy->perm_addr,
  4800. priv->ap_fw ? "AP" : "STA",
  4801. (priv->fw_rev >> 24) & 0xff, (priv->fw_rev >> 16) & 0xff,
  4802. (priv->fw_rev >> 8) & 0xff, priv->fw_rev & 0xff);
  4803. return 0;
  4804. err_free_irq:
  4805. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  4806. free_irq(priv->pdev->irq, hw);
  4807. err_free_queues:
  4808. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4809. mwl8k_txq_deinit(hw, i);
  4810. mwl8k_rxq_deinit(hw, 0);
  4811. err_stop_firmware:
  4812. mwl8k_hw_reset(priv);
  4813. return rc;
  4814. }
  4815. /*
  4816. * invoke mwl8k_reload_firmware to change the firmware image after the device
  4817. * has already been registered
  4818. */
  4819. static int mwl8k_reload_firmware(struct ieee80211_hw *hw, char *fw_image)
  4820. {
  4821. int i, rc = 0;
  4822. struct mwl8k_priv *priv = hw->priv;
  4823. struct mwl8k_vif *vif, *tmp_vif;
  4824. mwl8k_stop(hw);
  4825. mwl8k_rxq_deinit(hw, 0);
  4826. /*
  4827. * All the existing interfaces are re-added by the ieee80211_reconfig;
  4828. * which means driver should remove existing interfaces before calling
  4829. * ieee80211_restart_hw
  4830. */
  4831. if (priv->hw_restart_in_progress)
  4832. list_for_each_entry_safe(vif, tmp_vif, &priv->vif_list, list)
  4833. mwl8k_remove_vif(priv, vif);
  4834. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4835. mwl8k_txq_deinit(hw, i);
  4836. rc = mwl8k_init_firmware(hw, fw_image, false);
  4837. if (rc)
  4838. goto fail;
  4839. rc = mwl8k_probe_hw(hw);
  4840. if (rc)
  4841. goto fail;
  4842. if (priv->hw_restart_in_progress)
  4843. return rc;
  4844. rc = mwl8k_start(hw);
  4845. if (rc)
  4846. goto fail;
  4847. rc = mwl8k_config(hw, ~0);
  4848. if (rc)
  4849. goto fail;
  4850. for (i = 0; i < MWL8K_TX_WMM_QUEUES; i++) {
  4851. rc = mwl8k_conf_tx(hw, NULL, i, &priv->wmm_params[i]);
  4852. if (rc)
  4853. goto fail;
  4854. }
  4855. return rc;
  4856. fail:
  4857. printk(KERN_WARNING "mwl8k: Failed to reload firmware image.\n");
  4858. return rc;
  4859. }
  4860. static const struct ieee80211_iface_limit ap_if_limits[] = {
  4861. { .max = 8, .types = BIT(NL80211_IFTYPE_AP) },
  4862. { .max = 1, .types = BIT(NL80211_IFTYPE_STATION) },
  4863. };
  4864. static const struct ieee80211_iface_combination ap_if_comb = {
  4865. .limits = ap_if_limits,
  4866. .n_limits = ARRAY_SIZE(ap_if_limits),
  4867. .max_interfaces = 8,
  4868. .num_different_channels = 1,
  4869. };
  4870. static int mwl8k_firmware_load_success(struct mwl8k_priv *priv)
  4871. {
  4872. struct ieee80211_hw *hw = priv->hw;
  4873. int i, rc;
  4874. rc = mwl8k_load_firmware(hw);
  4875. mwl8k_release_firmware(priv);
  4876. if (rc) {
  4877. wiphy_err(hw->wiphy, "Cannot start firmware\n");
  4878. return rc;
  4879. }
  4880. /*
  4881. * Extra headroom is the size of the required DMA header
  4882. * minus the size of the smallest 802.11 frame (CTS frame).
  4883. */
  4884. hw->extra_tx_headroom =
  4885. sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
  4886. hw->extra_tx_headroom -= priv->ap_fw ? REDUCED_TX_HEADROOM : 0;
  4887. hw->channel_change_time = 10;
  4888. hw->queues = MWL8K_TX_WMM_QUEUES;
  4889. /* Set rssi values to dBm */
  4890. hw->flags |= IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_HAS_RATE_CONTROL;
  4891. /*
  4892. * Ask mac80211 to not to trigger PS mode
  4893. * based on PM bit of incoming frames.
  4894. */
  4895. if (priv->ap_fw)
  4896. hw->flags |= IEEE80211_HW_AP_LINK_PS;
  4897. hw->vif_data_size = sizeof(struct mwl8k_vif);
  4898. hw->sta_data_size = sizeof(struct mwl8k_sta);
  4899. priv->macids_used = 0;
  4900. INIT_LIST_HEAD(&priv->vif_list);
  4901. /* Set default radio state and preamble */
  4902. priv->radio_on = false;
  4903. priv->radio_short_preamble = false;
  4904. /* Finalize join worker */
  4905. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  4906. /* Handle watchdog ba events */
  4907. INIT_WORK(&priv->watchdog_ba_handle, mwl8k_watchdog_ba_events);
  4908. /* To reload the firmware if it crashes */
  4909. INIT_WORK(&priv->fw_reload, mwl8k_hw_restart_work);
  4910. /* TX reclaim and RX tasklets. */
  4911. tasklet_init(&priv->poll_tx_task, mwl8k_tx_poll, (unsigned long)hw);
  4912. tasklet_disable(&priv->poll_tx_task);
  4913. tasklet_init(&priv->poll_rx_task, mwl8k_rx_poll, (unsigned long)hw);
  4914. tasklet_disable(&priv->poll_rx_task);
  4915. /* Power management cookie */
  4916. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  4917. if (priv->cookie == NULL)
  4918. return -ENOMEM;
  4919. mutex_init(&priv->fw_mutex);
  4920. priv->fw_mutex_owner = NULL;
  4921. priv->fw_mutex_depth = 0;
  4922. priv->hostcmd_wait = NULL;
  4923. spin_lock_init(&priv->tx_lock);
  4924. spin_lock_init(&priv->stream_lock);
  4925. priv->tx_wait = NULL;
  4926. rc = mwl8k_probe_hw(hw);
  4927. if (rc)
  4928. goto err_free_cookie;
  4929. hw->wiphy->interface_modes = 0;
  4930. if (priv->ap_macids_supported || priv->device_info->fw_image_ap) {
  4931. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP);
  4932. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  4933. hw->wiphy->iface_combinations = &ap_if_comb;
  4934. hw->wiphy->n_iface_combinations = 1;
  4935. }
  4936. if (priv->sta_macids_supported || priv->device_info->fw_image_sta)
  4937. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_STATION);
  4938. rc = ieee80211_register_hw(hw);
  4939. if (rc) {
  4940. wiphy_err(hw->wiphy, "Cannot register device\n");
  4941. goto err_unprobe_hw;
  4942. }
  4943. return 0;
  4944. err_unprobe_hw:
  4945. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  4946. mwl8k_txq_deinit(hw, i);
  4947. mwl8k_rxq_deinit(hw, 0);
  4948. err_free_cookie:
  4949. if (priv->cookie != NULL)
  4950. pci_free_consistent(priv->pdev, 4,
  4951. priv->cookie, priv->cookie_dma);
  4952. return rc;
  4953. }
  4954. static int mwl8k_probe(struct pci_dev *pdev,
  4955. const struct pci_device_id *id)
  4956. {
  4957. static int printed_version;
  4958. struct ieee80211_hw *hw;
  4959. struct mwl8k_priv *priv;
  4960. struct mwl8k_device_info *di;
  4961. int rc;
  4962. if (!printed_version) {
  4963. printk(KERN_INFO "%s version %s\n", MWL8K_DESC, MWL8K_VERSION);
  4964. printed_version = 1;
  4965. }
  4966. rc = pci_enable_device(pdev);
  4967. if (rc) {
  4968. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  4969. MWL8K_NAME);
  4970. return rc;
  4971. }
  4972. rc = pci_request_regions(pdev, MWL8K_NAME);
  4973. if (rc) {
  4974. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  4975. MWL8K_NAME);
  4976. goto err_disable_device;
  4977. }
  4978. pci_set_master(pdev);
  4979. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  4980. if (hw == NULL) {
  4981. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  4982. rc = -ENOMEM;
  4983. goto err_free_reg;
  4984. }
  4985. SET_IEEE80211_DEV(hw, &pdev->dev);
  4986. pci_set_drvdata(pdev, hw);
  4987. priv = hw->priv;
  4988. priv->hw = hw;
  4989. priv->pdev = pdev;
  4990. priv->device_info = &mwl8k_info_tbl[id->driver_data];
  4991. if (id->driver_data == MWL8764)
  4992. priv->is_8764 = true;
  4993. priv->sram = pci_iomap(pdev, 0, 0x10000);
  4994. if (priv->sram == NULL) {
  4995. wiphy_err(hw->wiphy, "Cannot map device SRAM\n");
  4996. rc = -EIO;
  4997. goto err_iounmap;
  4998. }
  4999. /*
  5000. * If BAR0 is a 32 bit BAR, the register BAR will be BAR1.
  5001. * If BAR0 is a 64 bit BAR, the register BAR will be BAR2.
  5002. */
  5003. priv->regs = pci_iomap(pdev, 1, 0x10000);
  5004. if (priv->regs == NULL) {
  5005. priv->regs = pci_iomap(pdev, 2, 0x10000);
  5006. if (priv->regs == NULL) {
  5007. wiphy_err(hw->wiphy, "Cannot map device registers\n");
  5008. rc = -EIO;
  5009. goto err_iounmap;
  5010. }
  5011. }
  5012. /*
  5013. * Choose the initial fw image depending on user input. If a second
  5014. * image is available, make it the alternative image that will be
  5015. * loaded if the first one fails.
  5016. */
  5017. init_completion(&priv->firmware_loading_complete);
  5018. di = priv->device_info;
  5019. if (ap_mode_default && di->fw_image_ap) {
  5020. priv->fw_pref = di->fw_image_ap;
  5021. priv->fw_alt = di->fw_image_sta;
  5022. } else if (!ap_mode_default && di->fw_image_sta) {
  5023. priv->fw_pref = di->fw_image_sta;
  5024. priv->fw_alt = di->fw_image_ap;
  5025. } else if (ap_mode_default && !di->fw_image_ap && di->fw_image_sta) {
  5026. printk(KERN_WARNING "AP fw is unavailable. Using STA fw.");
  5027. priv->fw_pref = di->fw_image_sta;
  5028. } else if (!ap_mode_default && !di->fw_image_sta && di->fw_image_ap) {
  5029. printk(KERN_WARNING "STA fw is unavailable. Using AP fw.");
  5030. priv->fw_pref = di->fw_image_ap;
  5031. }
  5032. rc = mwl8k_init_firmware(hw, priv->fw_pref, true);
  5033. if (rc)
  5034. goto err_stop_firmware;
  5035. priv->hw_restart_in_progress = false;
  5036. priv->running_bsses = 0;
  5037. return rc;
  5038. err_stop_firmware:
  5039. mwl8k_hw_reset(priv);
  5040. err_iounmap:
  5041. if (priv->regs != NULL)
  5042. pci_iounmap(pdev, priv->regs);
  5043. if (priv->sram != NULL)
  5044. pci_iounmap(pdev, priv->sram);
  5045. pci_set_drvdata(pdev, NULL);
  5046. ieee80211_free_hw(hw);
  5047. err_free_reg:
  5048. pci_release_regions(pdev);
  5049. err_disable_device:
  5050. pci_disable_device(pdev);
  5051. return rc;
  5052. }
  5053. static void mwl8k_remove(struct pci_dev *pdev)
  5054. {
  5055. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  5056. struct mwl8k_priv *priv;
  5057. int i;
  5058. if (hw == NULL)
  5059. return;
  5060. priv = hw->priv;
  5061. wait_for_completion(&priv->firmware_loading_complete);
  5062. if (priv->fw_state == FW_STATE_ERROR) {
  5063. mwl8k_hw_reset(priv);
  5064. goto unmap;
  5065. }
  5066. ieee80211_stop_queues(hw);
  5067. ieee80211_unregister_hw(hw);
  5068. /* Remove TX reclaim and RX tasklets. */
  5069. tasklet_kill(&priv->poll_tx_task);
  5070. tasklet_kill(&priv->poll_rx_task);
  5071. /* Stop hardware */
  5072. mwl8k_hw_reset(priv);
  5073. /* Return all skbs to mac80211 */
  5074. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5075. mwl8k_txq_reclaim(hw, i, INT_MAX, 1);
  5076. for (i = 0; i < mwl8k_tx_queues(priv); i++)
  5077. mwl8k_txq_deinit(hw, i);
  5078. mwl8k_rxq_deinit(hw, 0);
  5079. pci_free_consistent(priv->pdev, 4, priv->cookie, priv->cookie_dma);
  5080. unmap:
  5081. pci_iounmap(pdev, priv->regs);
  5082. pci_iounmap(pdev, priv->sram);
  5083. pci_set_drvdata(pdev, NULL);
  5084. ieee80211_free_hw(hw);
  5085. pci_release_regions(pdev);
  5086. pci_disable_device(pdev);
  5087. }
  5088. static struct pci_driver mwl8k_driver = {
  5089. .name = MWL8K_NAME,
  5090. .id_table = mwl8k_pci_id_table,
  5091. .probe = mwl8k_probe,
  5092. .remove = mwl8k_remove,
  5093. };
  5094. module_pci_driver(mwl8k_driver);
  5095. MODULE_DESCRIPTION(MWL8K_DESC);
  5096. MODULE_VERSION(MWL8K_VERSION);
  5097. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  5098. MODULE_LICENSE("GPL");