mwl8k.c 100 KB

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