mwl8k.c 149 KB

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