mwl8k.c 100 KB

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