mwl8k.c 141 KB

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