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