mwl8k.c 101 KB

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