mwl8k.c 136 KB

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