mwl8k.c 138 KB

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