mwl8k.c 142 KB

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