mwl8k.c 137 KB

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