mwl8k.c 143 KB

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