mwl8k.c 119 KB

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