mwl8k.c 97 KB

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