mwl8k.c 143 KB

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