mwl8k.c 119 KB

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