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