mwl8k.c 156 KB

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