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