mwl8k.c 135 KB

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