mwl8k.c 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789
  1. /*
  2. * drivers/net/wireless/mwl8k.c driver for Marvell TOPDOG 802.11 Wireless cards
  3. *
  4. * Copyright (C) 2008 Marvell Semiconductor Inc.
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/kernel.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/list.h>
  15. #include <linux/pci.h>
  16. #include <linux/delay.h>
  17. #include <linux/completion.h>
  18. #include <linux/etherdevice.h>
  19. #include <net/mac80211.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/firmware.h>
  22. #include <linux/workqueue.h>
  23. #define MWL8K_DESC "Marvell TOPDOG(R) 802.11 Wireless Network Driver"
  24. #define MWL8K_NAME KBUILD_MODNAME
  25. #define MWL8K_VERSION "0.9.1"
  26. MODULE_DESCRIPTION(MWL8K_DESC);
  27. MODULE_VERSION(MWL8K_VERSION);
  28. MODULE_AUTHOR("Lennert Buytenhek <buytenh@marvell.com>");
  29. MODULE_LICENSE("GPL");
  30. static DEFINE_PCI_DEVICE_TABLE(mwl8k_table) = {
  31. { PCI_VDEVICE(MARVELL, 0x2a2b), .driver_data = 8687, },
  32. { PCI_VDEVICE(MARVELL, 0x2a30), .driver_data = 8687, },
  33. { }
  34. };
  35. MODULE_DEVICE_TABLE(pci, mwl8k_table);
  36. #define IEEE80211_ADDR_LEN ETH_ALEN
  37. /* Register definitions */
  38. #define MWL8K_HIU_GEN_PTR 0x00000c10
  39. #define MWL8K_MODE_STA 0x0000005a
  40. #define MWL8K_MODE_AP 0x000000a5
  41. #define MWL8K_HIU_INT_CODE 0x00000c14
  42. #define MWL8K_FWSTA_READY 0xf0f1f2f4
  43. #define MWL8K_FWAP_READY 0xf1f2f4a5
  44. #define MWL8K_INT_CODE_CMD_FINISHED 0x00000005
  45. #define MWL8K_HIU_SCRATCH 0x00000c40
  46. /* Host->device communications */
  47. #define MWL8K_HIU_H2A_INTERRUPT_EVENTS 0x00000c18
  48. #define MWL8K_HIU_H2A_INTERRUPT_STATUS 0x00000c1c
  49. #define MWL8K_HIU_H2A_INTERRUPT_MASK 0x00000c20
  50. #define MWL8K_HIU_H2A_INTERRUPT_CLEAR_SEL 0x00000c24
  51. #define MWL8K_HIU_H2A_INTERRUPT_STATUS_MASK 0x00000c28
  52. #define MWL8K_H2A_INT_DUMMY (1 << 20)
  53. #define MWL8K_H2A_INT_RESET (1 << 15)
  54. #define MWL8K_H2A_INT_PS (1 << 2)
  55. #define MWL8K_H2A_INT_DOORBELL (1 << 1)
  56. #define MWL8K_H2A_INT_PPA_READY (1 << 0)
  57. /* Device->host communications */
  58. #define MWL8K_HIU_A2H_INTERRUPT_EVENTS 0x00000c2c
  59. #define MWL8K_HIU_A2H_INTERRUPT_STATUS 0x00000c30
  60. #define MWL8K_HIU_A2H_INTERRUPT_MASK 0x00000c34
  61. #define MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL 0x00000c38
  62. #define MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK 0x00000c3c
  63. #define MWL8K_A2H_INT_DUMMY (1 << 20)
  64. #define MWL8K_A2H_INT_CHNL_SWITCHED (1 << 11)
  65. #define MWL8K_A2H_INT_QUEUE_EMPTY (1 << 10)
  66. #define MWL8K_A2H_INT_RADAR_DETECT (1 << 7)
  67. #define MWL8K_A2H_INT_RADIO_ON (1 << 6)
  68. #define MWL8K_A2H_INT_RADIO_OFF (1 << 5)
  69. #define MWL8K_A2H_INT_MAC_EVENT (1 << 3)
  70. #define MWL8K_A2H_INT_OPC_DONE (1 << 2)
  71. #define MWL8K_A2H_INT_RX_READY (1 << 1)
  72. #define MWL8K_A2H_INT_TX_DONE (1 << 0)
  73. #define MWL8K_A2H_EVENTS (MWL8K_A2H_INT_DUMMY | \
  74. MWL8K_A2H_INT_CHNL_SWITCHED | \
  75. MWL8K_A2H_INT_QUEUE_EMPTY | \
  76. MWL8K_A2H_INT_RADAR_DETECT | \
  77. MWL8K_A2H_INT_RADIO_ON | \
  78. MWL8K_A2H_INT_RADIO_OFF | \
  79. MWL8K_A2H_INT_MAC_EVENT | \
  80. MWL8K_A2H_INT_OPC_DONE | \
  81. MWL8K_A2H_INT_RX_READY | \
  82. MWL8K_A2H_INT_TX_DONE)
  83. /* WME stream classes */
  84. #define WME_AC_BE 0 /* best effort */
  85. #define WME_AC_BK 1 /* background */
  86. #define WME_AC_VI 2 /* video */
  87. #define WME_AC_VO 3 /* voice */
  88. #define MWL8K_RX_QUEUES 1
  89. #define MWL8K_TX_QUEUES 4
  90. struct mwl8k_rx_queue {
  91. int rx_desc_count;
  92. /* hw receives here */
  93. int rx_head;
  94. /* refill descs here */
  95. int rx_tail;
  96. struct mwl8k_rx_desc *rx_desc_area;
  97. dma_addr_t rx_desc_dma;
  98. struct sk_buff **rx_skb;
  99. };
  100. struct mwl8k_skb {
  101. /*
  102. * The DMA engine requires a modification to the payload.
  103. * If the skbuff is shared/cloned, it needs to be unshared.
  104. * This method is used to ensure the stack always gets back
  105. * the skbuff it sent for transmission.
  106. */
  107. struct sk_buff *clone;
  108. struct sk_buff *skb;
  109. };
  110. struct mwl8k_tx_queue {
  111. /* hw transmits here */
  112. int tx_head;
  113. /* sw appends here */
  114. int tx_tail;
  115. struct ieee80211_tx_queue_stats tx_stats;
  116. struct mwl8k_tx_desc *tx_desc_area;
  117. dma_addr_t tx_desc_dma;
  118. struct mwl8k_skb *tx_skb;
  119. };
  120. /* Pointers to the firmware data and meta information about it. */
  121. struct mwl8k_firmware {
  122. /* Microcode */
  123. struct firmware *ucode;
  124. /* Boot helper code */
  125. struct firmware *helper;
  126. };
  127. struct mwl8k_priv {
  128. void __iomem *regs;
  129. struct ieee80211_hw *hw;
  130. struct pci_dev *pdev;
  131. u8 name[16];
  132. /* firmware access lock */
  133. spinlock_t fw_lock;
  134. /* firmware files and meta data */
  135. struct mwl8k_firmware fw;
  136. u32 part_num;
  137. /* lock held over TX and TX reap */
  138. spinlock_t tx_lock;
  139. u32 int_mask;
  140. struct ieee80211_vif *vif;
  141. struct list_head vif_list;
  142. struct ieee80211_channel *current_channel;
  143. /* power management status cookie from firmware */
  144. u32 *cookie;
  145. dma_addr_t cookie_dma;
  146. u16 num_mcaddrs;
  147. u16 region_code;
  148. u8 hw_rev;
  149. __le32 fw_rev;
  150. u32 wep_enabled;
  151. /*
  152. * Running count of TX packets in flight, to avoid
  153. * iterating over the transmit rings each time.
  154. */
  155. int pending_tx_pkts;
  156. struct mwl8k_rx_queue rxq[MWL8K_RX_QUEUES];
  157. struct mwl8k_tx_queue txq[MWL8K_TX_QUEUES];
  158. /* PHY parameters */
  159. struct ieee80211_supported_band band;
  160. struct ieee80211_channel channels[14];
  161. struct ieee80211_rate rates[12];
  162. /* RF preamble: Short, Long or Auto */
  163. u8 radio_preamble;
  164. u8 radio_state;
  165. /* WMM MODE 1 for enabled; 0 for disabled */
  166. bool wmm_mode;
  167. /* Set if PHY config is in progress */
  168. bool inconfig;
  169. /* XXX need to convert this to handle multiple interfaces */
  170. bool capture_beacon;
  171. u8 capture_bssid[IEEE80211_ADDR_LEN];
  172. struct sk_buff *beacon_skb;
  173. /*
  174. * This FJ worker has to be global as it is scheduled from the
  175. * RX handler. At this point we don't know which interface it
  176. * belongs to until the list of bssids waiting to complete join
  177. * is checked.
  178. */
  179. struct work_struct finalize_join_worker;
  180. /* Tasklet to reclaim TX descriptors and buffers after tx */
  181. struct tasklet_struct tx_reclaim_task;
  182. /* Work thread to serialize configuration requests */
  183. struct workqueue_struct *config_wq;
  184. struct completion *hostcmd_wait;
  185. struct completion *tx_wait;
  186. };
  187. /* Per interface specific private data */
  188. struct mwl8k_vif {
  189. struct list_head node;
  190. /* backpointer to parent config block */
  191. struct mwl8k_priv *priv;
  192. /* BSS config of AP or IBSS from mac80211*/
  193. struct ieee80211_bss_conf bss_info;
  194. /* BSSID of AP or IBSS */
  195. u8 bssid[IEEE80211_ADDR_LEN];
  196. u8 mac_addr[IEEE80211_ADDR_LEN];
  197. /*
  198. * Subset of supported legacy rates.
  199. * Intersection of AP and STA supported rates.
  200. */
  201. struct ieee80211_rate legacy_rates[12];
  202. /* number of supported legacy rates */
  203. u8 legacy_nrates;
  204. /* Number of supported MCS rates. Work in progress */
  205. u8 mcs_nrates;
  206. /* Index into station database.Returned by update_sta_db call */
  207. u8 peer_id;
  208. /* Non AMPDU sequence number assigned by driver */
  209. u16 seqno;
  210. /* Note:There is no channel info,
  211. * refer to the master channel info in priv
  212. */
  213. };
  214. #define MWL8K_VIF(_vif) (struct mwl8k_vif *)(&((_vif)->drv_priv))
  215. static const struct ieee80211_channel mwl8k_channels[] = {
  216. { .center_freq = 2412, .hw_value = 1, },
  217. { .center_freq = 2417, .hw_value = 2, },
  218. { .center_freq = 2422, .hw_value = 3, },
  219. { .center_freq = 2427, .hw_value = 4, },
  220. { .center_freq = 2432, .hw_value = 5, },
  221. { .center_freq = 2437, .hw_value = 6, },
  222. { .center_freq = 2442, .hw_value = 7, },
  223. { .center_freq = 2447, .hw_value = 8, },
  224. { .center_freq = 2452, .hw_value = 9, },
  225. { .center_freq = 2457, .hw_value = 10, },
  226. { .center_freq = 2462, .hw_value = 11, },
  227. };
  228. static const struct ieee80211_rate mwl8k_rates[] = {
  229. { .bitrate = 10, .hw_value = 2, },
  230. { .bitrate = 20, .hw_value = 4, },
  231. { .bitrate = 55, .hw_value = 11, },
  232. { .bitrate = 60, .hw_value = 12, },
  233. { .bitrate = 90, .hw_value = 18, },
  234. { .bitrate = 110, .hw_value = 22, },
  235. { .bitrate = 120, .hw_value = 24, },
  236. { .bitrate = 180, .hw_value = 36, },
  237. { .bitrate = 240, .hw_value = 48, },
  238. { .bitrate = 360, .hw_value = 72, },
  239. { .bitrate = 480, .hw_value = 96, },
  240. { .bitrate = 540, .hw_value = 108, },
  241. };
  242. /* Radio settings */
  243. #define MWL8K_RADIO_FORCE 0x2
  244. #define MWL8K_RADIO_ENABLE 0x1
  245. #define MWL8K_RADIO_DISABLE 0x0
  246. #define MWL8K_RADIO_AUTO_PREAMBLE 0x0005
  247. #define MWL8K_RADIO_SHORT_PREAMBLE 0x0003
  248. #define MWL8K_RADIO_LONG_PREAMBLE 0x0001
  249. /* WMM */
  250. #define MWL8K_WMM_ENABLE 1
  251. #define MWL8K_WMM_DISABLE 0
  252. #define MWL8K_RADIO_DEFAULT_PREAMBLE MWL8K_RADIO_LONG_PREAMBLE
  253. /* Slot time */
  254. /* Short Slot: 9us slot time */
  255. #define MWL8K_SHORT_SLOTTIME 1
  256. /* Long slot: 20us slot time */
  257. #define MWL8K_LONG_SLOTTIME 0
  258. /* Set or get info from Firmware */
  259. #define MWL8K_CMD_SET 0x0001
  260. #define MWL8K_CMD_GET 0x0000
  261. /* Firmware command codes */
  262. #define MWL8K_CMD_CODE_DNLD 0x0001
  263. #define MWL8K_CMD_GET_HW_SPEC 0x0003
  264. #define MWL8K_CMD_MAC_MULTICAST_ADR 0x0010
  265. #define MWL8K_CMD_GET_STAT 0x0014
  266. #define MWL8K_CMD_RADIO_CONTROL 0x001C
  267. #define MWL8K_CMD_RF_TX_POWER 0x001E
  268. #define MWL8K_CMD_SET_PRE_SCAN 0x0107
  269. #define MWL8K_CMD_SET_POST_SCAN 0x0108
  270. #define MWL8K_CMD_SET_RF_CHANNEL 0x010A
  271. #define MWL8K_CMD_SET_SLOT 0x0114
  272. #define MWL8K_CMD_MIMO_CONFIG 0x0125
  273. #define MWL8K_CMD_ENABLE_SNIFFER 0x0150
  274. #define MWL8K_CMD_SET_WMM_MODE 0x0123
  275. #define MWL8K_CMD_SET_EDCA_PARAMS 0x0115
  276. #define MWL8K_CMD_SET_FINALIZE_JOIN 0x0111
  277. #define MWL8K_CMD_UPDATE_STADB 0x1123
  278. #define MWL8K_CMD_SET_RATEADAPT_MODE 0x0203
  279. #define MWL8K_CMD_SET_LINKADAPT_MODE 0x0129
  280. #define MWL8K_CMD_SET_AID 0x010d
  281. #define MWL8K_CMD_SET_RATE 0x0110
  282. #define MWL8K_CMD_USE_FIXED_RATE 0x0126
  283. #define MWL8K_CMD_RTS_THRESHOLD 0x0113
  284. #define MWL8K_CMD_ENCRYPTION 0x1122
  285. static const char *mwl8k_cmd_name(u16 cmd, char *buf, int bufsize)
  286. {
  287. #define MWL8K_CMDNAME(x) case MWL8K_CMD_##x: do {\
  288. snprintf(buf, bufsize, "%s", #x);\
  289. return buf;\
  290. } while (0)
  291. switch (cmd & (~0x8000)) {
  292. MWL8K_CMDNAME(CODE_DNLD);
  293. MWL8K_CMDNAME(GET_HW_SPEC);
  294. MWL8K_CMDNAME(MAC_MULTICAST_ADR);
  295. MWL8K_CMDNAME(GET_STAT);
  296. MWL8K_CMDNAME(RADIO_CONTROL);
  297. MWL8K_CMDNAME(RF_TX_POWER);
  298. MWL8K_CMDNAME(SET_PRE_SCAN);
  299. MWL8K_CMDNAME(SET_POST_SCAN);
  300. MWL8K_CMDNAME(SET_RF_CHANNEL);
  301. MWL8K_CMDNAME(SET_SLOT);
  302. MWL8K_CMDNAME(MIMO_CONFIG);
  303. MWL8K_CMDNAME(ENABLE_SNIFFER);
  304. MWL8K_CMDNAME(SET_WMM_MODE);
  305. MWL8K_CMDNAME(SET_EDCA_PARAMS);
  306. MWL8K_CMDNAME(SET_FINALIZE_JOIN);
  307. MWL8K_CMDNAME(UPDATE_STADB);
  308. MWL8K_CMDNAME(SET_RATEADAPT_MODE);
  309. MWL8K_CMDNAME(SET_LINKADAPT_MODE);
  310. MWL8K_CMDNAME(SET_AID);
  311. MWL8K_CMDNAME(SET_RATE);
  312. MWL8K_CMDNAME(USE_FIXED_RATE);
  313. MWL8K_CMDNAME(RTS_THRESHOLD);
  314. MWL8K_CMDNAME(ENCRYPTION);
  315. default:
  316. snprintf(buf, bufsize, "0x%x", cmd);
  317. }
  318. #undef MWL8K_CMDNAME
  319. return buf;
  320. }
  321. /* Hardware and firmware reset */
  322. static void mwl8k_hw_reset(struct mwl8k_priv *priv)
  323. {
  324. iowrite32(MWL8K_H2A_INT_RESET,
  325. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  326. iowrite32(MWL8K_H2A_INT_RESET,
  327. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  328. msleep(20);
  329. }
  330. /* Release fw image */
  331. static void mwl8k_release_fw(struct firmware **fw)
  332. {
  333. if (*fw == NULL)
  334. return;
  335. release_firmware(*fw);
  336. *fw = NULL;
  337. }
  338. static void mwl8k_release_firmware(struct mwl8k_priv *priv)
  339. {
  340. mwl8k_release_fw(&priv->fw.ucode);
  341. mwl8k_release_fw(&priv->fw.helper);
  342. }
  343. /* Request fw image */
  344. static int mwl8k_request_fw(struct mwl8k_priv *priv,
  345. const char *fname, struct firmware **fw)
  346. {
  347. /* release current image */
  348. if (*fw != NULL)
  349. mwl8k_release_fw(fw);
  350. return request_firmware((const struct firmware **)fw,
  351. fname, &priv->pdev->dev);
  352. }
  353. static int mwl8k_request_firmware(struct mwl8k_priv *priv, u32 part_num)
  354. {
  355. u8 filename[64];
  356. int rc;
  357. priv->part_num = part_num;
  358. snprintf(filename, sizeof(filename),
  359. "mwl8k/helper_%u.fw", priv->part_num);
  360. rc = mwl8k_request_fw(priv, filename, &priv->fw.helper);
  361. if (rc) {
  362. printk(KERN_ERR
  363. "%s Error requesting helper firmware file %s\n",
  364. pci_name(priv->pdev), filename);
  365. return rc;
  366. }
  367. snprintf(filename, sizeof(filename),
  368. "mwl8k/fmimage_%u.fw", priv->part_num);
  369. rc = mwl8k_request_fw(priv, filename, &priv->fw.ucode);
  370. if (rc) {
  371. printk(KERN_ERR "%s Error requesting firmware file %s\n",
  372. pci_name(priv->pdev), filename);
  373. mwl8k_release_fw(&priv->fw.helper);
  374. return rc;
  375. }
  376. return 0;
  377. }
  378. struct mwl8k_cmd_pkt {
  379. __le16 code;
  380. __le16 length;
  381. __le16 seq_num;
  382. __le16 result;
  383. char payload[0];
  384. } __attribute__((packed));
  385. /*
  386. * Firmware loading.
  387. */
  388. static int
  389. mwl8k_send_fw_load_cmd(struct mwl8k_priv *priv, void *data, int length)
  390. {
  391. void __iomem *regs = priv->regs;
  392. dma_addr_t dma_addr;
  393. int rc;
  394. int loops;
  395. dma_addr = pci_map_single(priv->pdev, data, length, PCI_DMA_TODEVICE);
  396. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  397. return -ENOMEM;
  398. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  399. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  400. iowrite32(MWL8K_H2A_INT_DOORBELL,
  401. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  402. iowrite32(MWL8K_H2A_INT_DUMMY,
  403. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  404. rc = -ETIMEDOUT;
  405. loops = 1000;
  406. do {
  407. u32 int_code;
  408. int_code = ioread32(regs + MWL8K_HIU_INT_CODE);
  409. if (int_code == MWL8K_INT_CODE_CMD_FINISHED) {
  410. iowrite32(0, regs + MWL8K_HIU_INT_CODE);
  411. rc = 0;
  412. break;
  413. }
  414. udelay(1);
  415. } while (--loops);
  416. pci_unmap_single(priv->pdev, dma_addr, length, PCI_DMA_TODEVICE);
  417. /*
  418. * Clear 'command done' interrupt bit.
  419. */
  420. loops = 1000;
  421. do {
  422. u32 status;
  423. status = ioread32(priv->regs +
  424. MWL8K_HIU_A2H_INTERRUPT_STATUS);
  425. if (status & MWL8K_A2H_INT_OPC_DONE) {
  426. iowrite32(~MWL8K_A2H_INT_OPC_DONE,
  427. priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  428. ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  429. break;
  430. }
  431. udelay(1);
  432. } while (--loops);
  433. return rc;
  434. }
  435. static int mwl8k_load_fw_image(struct mwl8k_priv *priv,
  436. const u8 *data, size_t length)
  437. {
  438. struct mwl8k_cmd_pkt *cmd;
  439. int done;
  440. int rc = 0;
  441. cmd = kmalloc(sizeof(*cmd) + 256, GFP_KERNEL);
  442. if (cmd == NULL)
  443. return -ENOMEM;
  444. cmd->code = cpu_to_le16(MWL8K_CMD_CODE_DNLD);
  445. cmd->seq_num = 0;
  446. cmd->result = 0;
  447. done = 0;
  448. while (length) {
  449. int block_size = length > 256 ? 256 : length;
  450. memcpy(cmd->payload, data + done, block_size);
  451. cmd->length = cpu_to_le16(block_size);
  452. rc = mwl8k_send_fw_load_cmd(priv, cmd,
  453. sizeof(*cmd) + block_size);
  454. if (rc)
  455. break;
  456. done += block_size;
  457. length -= block_size;
  458. }
  459. if (!rc) {
  460. cmd->length = 0;
  461. rc = mwl8k_send_fw_load_cmd(priv, cmd, sizeof(*cmd));
  462. }
  463. kfree(cmd);
  464. return rc;
  465. }
  466. static int mwl8k_feed_fw_image(struct mwl8k_priv *priv,
  467. const u8 *data, size_t length)
  468. {
  469. unsigned char *buffer;
  470. int may_continue, rc = 0;
  471. u32 done, prev_block_size;
  472. buffer = kmalloc(1024, GFP_KERNEL);
  473. if (buffer == NULL)
  474. return -ENOMEM;
  475. done = 0;
  476. prev_block_size = 0;
  477. may_continue = 1000;
  478. while (may_continue > 0) {
  479. u32 block_size;
  480. block_size = ioread32(priv->regs + MWL8K_HIU_SCRATCH);
  481. if (block_size & 1) {
  482. block_size &= ~1;
  483. may_continue--;
  484. } else {
  485. done += prev_block_size;
  486. length -= prev_block_size;
  487. }
  488. if (block_size > 1024 || block_size > length) {
  489. rc = -EOVERFLOW;
  490. break;
  491. }
  492. if (length == 0) {
  493. rc = 0;
  494. break;
  495. }
  496. if (block_size == 0) {
  497. rc = -EPROTO;
  498. may_continue--;
  499. udelay(1);
  500. continue;
  501. }
  502. prev_block_size = block_size;
  503. memcpy(buffer, data + done, block_size);
  504. rc = mwl8k_send_fw_load_cmd(priv, buffer, block_size);
  505. if (rc)
  506. break;
  507. }
  508. if (!rc && length != 0)
  509. rc = -EREMOTEIO;
  510. kfree(buffer);
  511. return rc;
  512. }
  513. static int mwl8k_load_firmware(struct mwl8k_priv *priv)
  514. {
  515. int loops, rc;
  516. const u8 *ucode = priv->fw.ucode->data;
  517. size_t ucode_len = priv->fw.ucode->size;
  518. const u8 *helper = priv->fw.helper->data;
  519. size_t helper_len = priv->fw.helper->size;
  520. if (!memcmp(ucode, "\x01\x00\x00\x00", 4)) {
  521. rc = mwl8k_load_fw_image(priv, helper, helper_len);
  522. if (rc) {
  523. printk(KERN_ERR "%s: unable to load firmware "
  524. "helper image\n", pci_name(priv->pdev));
  525. return rc;
  526. }
  527. msleep(1);
  528. rc = mwl8k_feed_fw_image(priv, ucode, ucode_len);
  529. } else {
  530. rc = mwl8k_load_fw_image(priv, ucode, ucode_len);
  531. }
  532. if (rc) {
  533. printk(KERN_ERR "%s: unable to load firmware data\n",
  534. pci_name(priv->pdev));
  535. return rc;
  536. }
  537. iowrite32(MWL8K_MODE_STA, priv->regs + MWL8K_HIU_GEN_PTR);
  538. msleep(1);
  539. loops = 200000;
  540. do {
  541. if (ioread32(priv->regs + MWL8K_HIU_INT_CODE)
  542. == MWL8K_FWSTA_READY)
  543. break;
  544. udelay(1);
  545. } while (--loops);
  546. return loops ? 0 : -ETIMEDOUT;
  547. }
  548. /*
  549. * Defines shared between transmission and reception.
  550. */
  551. /* HT control fields for firmware */
  552. struct ewc_ht_info {
  553. __le16 control1;
  554. __le16 control2;
  555. __le16 control3;
  556. } __attribute__((packed));
  557. /* Firmware Station database operations */
  558. #define MWL8K_STA_DB_ADD_ENTRY 0
  559. #define MWL8K_STA_DB_MODIFY_ENTRY 1
  560. #define MWL8K_STA_DB_DEL_ENTRY 2
  561. #define MWL8K_STA_DB_FLUSH 3
  562. /* Peer Entry flags - used to define the type of the peer node */
  563. #define MWL8K_PEER_TYPE_ACCESSPOINT 2
  564. #define MWL8K_PEER_TYPE_ADHOC_STATION 4
  565. #define MWL8K_IEEE_LEGACY_DATA_RATES 12
  566. #define MWL8K_MCS_BITMAP_SIZE 16
  567. #define pad_size 16
  568. struct peer_capability_info {
  569. /* Peer type - AP vs. STA. */
  570. __u8 peer_type;
  571. /* Basic 802.11 capabilities from assoc resp. */
  572. __le16 basic_caps;
  573. /* Set if peer supports 802.11n high throughput (HT). */
  574. __u8 ht_support;
  575. /* Valid if HT is supported. */
  576. __le16 ht_caps;
  577. __u8 extended_ht_caps;
  578. struct ewc_ht_info ewc_info;
  579. /* Legacy rate table. Intersection of our rates and peer rates. */
  580. __u8 legacy_rates[MWL8K_IEEE_LEGACY_DATA_RATES];
  581. /* HT rate table. Intersection of our rates and peer rates. */
  582. __u8 ht_rates[MWL8K_MCS_BITMAP_SIZE];
  583. __u8 pad[pad_size];
  584. /* If set, interoperability mode, no proprietary extensions. */
  585. __u8 interop;
  586. __u8 pad2;
  587. __u8 station_id;
  588. __le16 amsdu_enabled;
  589. } __attribute__((packed));
  590. /* Inline functions to manipulate QoS field in data descriptor. */
  591. static inline u16 mwl8k_qos_setbit_tid(u16 qos, u8 tid)
  592. {
  593. u16 val_mask = 0x000f;
  594. u16 qos_mask = ~val_mask;
  595. /* TID bits 0-3 */
  596. return (qos & qos_mask) | (tid & val_mask);
  597. }
  598. static inline u16 mwl8k_qos_setbit_eosp(u16 qos)
  599. {
  600. u16 val_mask = 1 << 4;
  601. /* End of Service Period Bit 4 */
  602. return qos | val_mask;
  603. }
  604. static inline u16 mwl8k_qos_setbit_ack(u16 qos, u8 ack_policy)
  605. {
  606. u16 val_mask = 0x3;
  607. u8 shift = 5;
  608. u16 qos_mask = ~(val_mask << shift);
  609. /* Ack Policy Bit 5-6 */
  610. return (qos & qos_mask) | ((ack_policy & val_mask) << shift);
  611. }
  612. static inline u16 mwl8k_qos_setbit_amsdu(u16 qos)
  613. {
  614. u16 val_mask = 1 << 7;
  615. /* AMSDU present Bit 7 */
  616. return qos | val_mask;
  617. }
  618. static inline u16 mwl8k_qos_setbit_qlen(u16 qos, u8 len)
  619. {
  620. u16 val_mask = 0xff;
  621. u8 shift = 8;
  622. u16 qos_mask = ~(val_mask << shift);
  623. /* Queue Length Bits 8-15 */
  624. return (qos & qos_mask) | ((len & val_mask) << shift);
  625. }
  626. /* DMA header used by firmware and hardware. */
  627. struct mwl8k_dma_data {
  628. __le16 fwlen;
  629. struct ieee80211_hdr wh;
  630. } __attribute__((packed));
  631. /* Routines to add/remove DMA header from skb. */
  632. static inline int mwl8k_remove_dma_header(struct sk_buff *skb)
  633. {
  634. struct mwl8k_dma_data *tr = (struct mwl8k_dma_data *)(skb->data);
  635. void *dst, *src = &tr->wh;
  636. __le16 fc = tr->wh.frame_control;
  637. int hdrlen = ieee80211_hdrlen(fc);
  638. u16 space = sizeof(struct mwl8k_dma_data) - hdrlen;
  639. dst = (void *)tr + space;
  640. if (dst != src) {
  641. memmove(dst, src, hdrlen);
  642. skb_pull(skb, space);
  643. }
  644. return 0;
  645. }
  646. static inline struct sk_buff *mwl8k_add_dma_header(struct sk_buff *skb)
  647. {
  648. struct ieee80211_hdr *wh;
  649. u32 hdrlen, pktlen;
  650. struct mwl8k_dma_data *tr;
  651. wh = (struct ieee80211_hdr *)skb->data;
  652. hdrlen = ieee80211_hdrlen(wh->frame_control);
  653. pktlen = skb->len;
  654. /*
  655. * Copy up/down the 802.11 header; the firmware requires
  656. * we present a 2-byte payload length followed by a
  657. * 4-address header (w/o QoS), followed (optionally) by
  658. * any WEP/ExtIV header (but only filled in for CCMP).
  659. */
  660. if (hdrlen != sizeof(struct mwl8k_dma_data))
  661. skb_push(skb, sizeof(struct mwl8k_dma_data) - hdrlen);
  662. tr = (struct mwl8k_dma_data *)skb->data;
  663. if (wh != &tr->wh)
  664. memmove(&tr->wh, wh, hdrlen);
  665. /* Clear addr4 */
  666. memset(tr->wh.addr4, 0, IEEE80211_ADDR_LEN);
  667. /*
  668. * Firmware length is the length of the fully formed "802.11
  669. * payload". That is, everything except for the 802.11 header.
  670. * This includes all crypto material including the MIC.
  671. */
  672. tr->fwlen = cpu_to_le16(pktlen - hdrlen);
  673. return skb;
  674. }
  675. /*
  676. * Packet reception.
  677. */
  678. #define MWL8K_RX_CTRL_KEY_INDEX_MASK 0x30
  679. #define MWL8K_RX_CTRL_OWNED_BY_HOST 0x02
  680. #define MWL8K_RX_CTRL_AMPDU 0x01
  681. struct mwl8k_rx_desc {
  682. __le16 pkt_len;
  683. __u8 link_quality;
  684. __u8 noise_level;
  685. __le32 pkt_phys_addr;
  686. __le32 next_rx_desc_phys_addr;
  687. __le16 qos_control;
  688. __le16 rate_info;
  689. __le32 pad0[4];
  690. __u8 rssi;
  691. __u8 channel;
  692. __le16 pad1;
  693. __u8 rx_ctrl;
  694. __u8 rx_status;
  695. __u8 pad2[2];
  696. } __attribute__((packed));
  697. #define MWL8K_RX_DESCS 256
  698. #define MWL8K_RX_MAXSZ 3800
  699. static int mwl8k_rxq_init(struct ieee80211_hw *hw, int index)
  700. {
  701. struct mwl8k_priv *priv = hw->priv;
  702. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  703. int size;
  704. int i;
  705. rxq->rx_desc_count = 0;
  706. rxq->rx_head = 0;
  707. rxq->rx_tail = 0;
  708. size = MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc);
  709. rxq->rx_desc_area =
  710. pci_alloc_consistent(priv->pdev, size, &rxq->rx_desc_dma);
  711. if (rxq->rx_desc_area == NULL) {
  712. printk(KERN_ERR "%s: failed to alloc RX descriptors\n",
  713. priv->name);
  714. return -ENOMEM;
  715. }
  716. memset(rxq->rx_desc_area, 0, size);
  717. rxq->rx_skb = kmalloc(MWL8K_RX_DESCS *
  718. sizeof(*rxq->rx_skb), GFP_KERNEL);
  719. if (rxq->rx_skb == NULL) {
  720. printk(KERN_ERR "%s: failed to alloc RX skbuff list\n",
  721. priv->name);
  722. pci_free_consistent(priv->pdev, size,
  723. rxq->rx_desc_area, rxq->rx_desc_dma);
  724. return -ENOMEM;
  725. }
  726. memset(rxq->rx_skb, 0, MWL8K_RX_DESCS * sizeof(*rxq->rx_skb));
  727. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  728. struct mwl8k_rx_desc *rx_desc;
  729. int nexti;
  730. rx_desc = rxq->rx_desc_area + i;
  731. nexti = (i + 1) % MWL8K_RX_DESCS;
  732. rx_desc->next_rx_desc_phys_addr =
  733. cpu_to_le32(rxq->rx_desc_dma
  734. + nexti * sizeof(*rx_desc));
  735. rx_desc->rx_ctrl =
  736. cpu_to_le32(MWL8K_RX_CTRL_OWNED_BY_HOST);
  737. }
  738. return 0;
  739. }
  740. static int rxq_refill(struct ieee80211_hw *hw, int index, int limit)
  741. {
  742. struct mwl8k_priv *priv = hw->priv;
  743. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  744. int refilled;
  745. refilled = 0;
  746. while (rxq->rx_desc_count < MWL8K_RX_DESCS && limit--) {
  747. struct sk_buff *skb;
  748. int rx;
  749. skb = dev_alloc_skb(MWL8K_RX_MAXSZ);
  750. if (skb == NULL)
  751. break;
  752. rxq->rx_desc_count++;
  753. rx = rxq->rx_tail;
  754. rxq->rx_tail = (rx + 1) % MWL8K_RX_DESCS;
  755. rxq->rx_desc_area[rx].pkt_phys_addr =
  756. cpu_to_le32(pci_map_single(priv->pdev, skb->data,
  757. MWL8K_RX_MAXSZ, DMA_FROM_DEVICE));
  758. rxq->rx_desc_area[rx].pkt_len = cpu_to_le16(MWL8K_RX_MAXSZ);
  759. rxq->rx_skb[rx] = skb;
  760. wmb();
  761. rxq->rx_desc_area[rx].rx_ctrl = 0;
  762. refilled++;
  763. }
  764. return refilled;
  765. }
  766. /* Must be called only when the card's reception is completely halted */
  767. static void mwl8k_rxq_deinit(struct ieee80211_hw *hw, int index)
  768. {
  769. struct mwl8k_priv *priv = hw->priv;
  770. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  771. int i;
  772. for (i = 0; i < MWL8K_RX_DESCS; i++) {
  773. if (rxq->rx_skb[i] != NULL) {
  774. unsigned long addr;
  775. addr = le32_to_cpu(rxq->rx_desc_area[i].pkt_phys_addr);
  776. pci_unmap_single(priv->pdev, addr, MWL8K_RX_MAXSZ,
  777. PCI_DMA_FROMDEVICE);
  778. kfree_skb(rxq->rx_skb[i]);
  779. rxq->rx_skb[i] = NULL;
  780. }
  781. }
  782. kfree(rxq->rx_skb);
  783. rxq->rx_skb = NULL;
  784. pci_free_consistent(priv->pdev,
  785. MWL8K_RX_DESCS * sizeof(struct mwl8k_rx_desc),
  786. rxq->rx_desc_area, rxq->rx_desc_dma);
  787. rxq->rx_desc_area = NULL;
  788. }
  789. /*
  790. * Scan a list of BSSIDs to process for finalize join.
  791. * Allows for extension to process multiple BSSIDs.
  792. */
  793. static inline int
  794. mwl8k_capture_bssid(struct mwl8k_priv *priv, struct ieee80211_hdr *wh)
  795. {
  796. return priv->capture_beacon &&
  797. ieee80211_is_beacon(wh->frame_control) &&
  798. !compare_ether_addr(wh->addr3, priv->capture_bssid);
  799. }
  800. static inline void mwl8k_save_beacon(struct mwl8k_priv *priv,
  801. struct sk_buff *skb)
  802. {
  803. priv->capture_beacon = false;
  804. memset(priv->capture_bssid, 0, IEEE80211_ADDR_LEN);
  805. /*
  806. * Use GFP_ATOMIC as rxq_process is called from
  807. * the primary interrupt handler, memory allocation call
  808. * must not sleep.
  809. */
  810. priv->beacon_skb = skb_copy(skb, GFP_ATOMIC);
  811. if (priv->beacon_skb != NULL)
  812. queue_work(priv->config_wq,
  813. &priv->finalize_join_worker);
  814. }
  815. static int rxq_process(struct ieee80211_hw *hw, int index, int limit)
  816. {
  817. struct mwl8k_priv *priv = hw->priv;
  818. struct mwl8k_rx_queue *rxq = priv->rxq + index;
  819. int processed;
  820. processed = 0;
  821. while (rxq->rx_desc_count && limit--) {
  822. struct mwl8k_rx_desc *rx_desc;
  823. struct sk_buff *skb;
  824. struct ieee80211_rx_status status;
  825. unsigned long addr;
  826. struct ieee80211_hdr *wh;
  827. rx_desc = rxq->rx_desc_area + rxq->rx_head;
  828. if (!(rx_desc->rx_ctrl & MWL8K_RX_CTRL_OWNED_BY_HOST))
  829. break;
  830. rmb();
  831. skb = rxq->rx_skb[rxq->rx_head];
  832. rxq->rx_skb[rxq->rx_head] = NULL;
  833. rxq->rx_head = (rxq->rx_head + 1) % MWL8K_RX_DESCS;
  834. rxq->rx_desc_count--;
  835. addr = le32_to_cpu(rx_desc->pkt_phys_addr);
  836. pci_unmap_single(priv->pdev, addr,
  837. MWL8K_RX_MAXSZ, PCI_DMA_FROMDEVICE);
  838. skb_put(skb, le16_to_cpu(rx_desc->pkt_len));
  839. if (mwl8k_remove_dma_header(skb)) {
  840. dev_kfree_skb(skb);
  841. continue;
  842. }
  843. wh = (struct ieee80211_hdr *)skb->data;
  844. /*
  845. * Check for pending join operation. save a copy of
  846. * the beacon and schedule a tasklet to send finalize
  847. * join command to the firmware.
  848. */
  849. if (mwl8k_capture_bssid(priv, wh))
  850. mwl8k_save_beacon(priv, skb);
  851. memset(&status, 0, sizeof(status));
  852. status.mactime = 0;
  853. status.signal = -rx_desc->rssi;
  854. status.noise = -rx_desc->noise_level;
  855. status.qual = rx_desc->link_quality;
  856. status.antenna = 1;
  857. status.rate_idx = 1;
  858. status.flag = 0;
  859. status.band = IEEE80211_BAND_2GHZ;
  860. status.freq = ieee80211_channel_to_frequency(rx_desc->channel);
  861. ieee80211_rx_irqsafe(hw, skb, &status);
  862. processed++;
  863. }
  864. return processed;
  865. }
  866. /*
  867. * Packet transmission.
  868. */
  869. /* Transmit queue assignment. */
  870. enum {
  871. MWL8K_WME_AC_BK = 0, /* background access */
  872. MWL8K_WME_AC_BE = 1, /* best effort access */
  873. MWL8K_WME_AC_VI = 2, /* video access */
  874. MWL8K_WME_AC_VO = 3, /* voice access */
  875. };
  876. /* Transmit packet ACK policy */
  877. #define MWL8K_TXD_ACK_POLICY_NORMAL 0
  878. #define MWL8K_TXD_ACK_POLICY_NONE 1
  879. #define MWL8K_TXD_ACK_POLICY_NO_EXPLICIT 2
  880. #define MWL8K_TXD_ACK_POLICY_BLOCKACK 3
  881. #define GET_TXQ(_ac) (\
  882. ((_ac) == WME_AC_VO) ? MWL8K_WME_AC_VO : \
  883. ((_ac) == WME_AC_VI) ? MWL8K_WME_AC_VI : \
  884. ((_ac) == WME_AC_BK) ? MWL8K_WME_AC_BK : \
  885. MWL8K_WME_AC_BE)
  886. #define MWL8K_TXD_STATUS_IDLE 0x00000000
  887. #define MWL8K_TXD_STATUS_USED 0x00000001
  888. #define MWL8K_TXD_STATUS_OK 0x00000001
  889. #define MWL8K_TXD_STATUS_OK_RETRY 0x00000002
  890. #define MWL8K_TXD_STATUS_OK_MORE_RETRY 0x00000004
  891. #define MWL8K_TXD_STATUS_MULTICAST_TX 0x00000008
  892. #define MWL8K_TXD_STATUS_BROADCAST_TX 0x00000010
  893. #define MWL8K_TXD_STATUS_FAILED_LINK_ERROR 0x00000020
  894. #define MWL8K_TXD_STATUS_FAILED_EXCEED_LIMIT 0x00000040
  895. #define MWL8K_TXD_STATUS_FAILED_AGING 0x00000080
  896. #define MWL8K_TXD_STATUS_HOST_CMD 0x40000000
  897. #define MWL8K_TXD_STATUS_FW_OWNED 0x80000000
  898. #define MWL8K_TXD_SOFTSTALE 0x80
  899. #define MWL8K_TXD_SOFTSTALE_MGMT_RETRY 0x01
  900. struct mwl8k_tx_desc {
  901. __le32 status;
  902. __u8 data_rate;
  903. __u8 tx_priority;
  904. __le16 qos_control;
  905. __le32 pkt_phys_addr;
  906. __le16 pkt_len;
  907. __u8 dest_MAC_addr[IEEE80211_ADDR_LEN];
  908. __le32 next_tx_desc_phys_addr;
  909. __le32 reserved;
  910. __le16 rate_info;
  911. __u8 peer_id;
  912. __u8 tx_frag_cnt;
  913. } __attribute__((packed));
  914. #define MWL8K_TX_DESCS 128
  915. static int mwl8k_txq_init(struct ieee80211_hw *hw, int index)
  916. {
  917. struct mwl8k_priv *priv = hw->priv;
  918. struct mwl8k_tx_queue *txq = priv->txq + index;
  919. int size;
  920. int i;
  921. memset(&txq->tx_stats, 0,
  922. sizeof(struct ieee80211_tx_queue_stats));
  923. txq->tx_stats.limit = MWL8K_TX_DESCS;
  924. txq->tx_head = 0;
  925. txq->tx_tail = 0;
  926. size = MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc);
  927. txq->tx_desc_area =
  928. pci_alloc_consistent(priv->pdev, size, &txq->tx_desc_dma);
  929. if (txq->tx_desc_area == NULL) {
  930. printk(KERN_ERR "%s: failed to alloc TX descriptors\n",
  931. priv->name);
  932. return -ENOMEM;
  933. }
  934. memset(txq->tx_desc_area, 0, size);
  935. txq->tx_skb = kmalloc(MWL8K_TX_DESCS * sizeof(*txq->tx_skb),
  936. GFP_KERNEL);
  937. if (txq->tx_skb == NULL) {
  938. printk(KERN_ERR "%s: failed to alloc TX skbuff list\n",
  939. priv->name);
  940. pci_free_consistent(priv->pdev, size,
  941. txq->tx_desc_area, txq->tx_desc_dma);
  942. return -ENOMEM;
  943. }
  944. memset(txq->tx_skb, 0, MWL8K_TX_DESCS * sizeof(*txq->tx_skb));
  945. for (i = 0; i < MWL8K_TX_DESCS; i++) {
  946. struct mwl8k_tx_desc *tx_desc;
  947. int nexti;
  948. tx_desc = txq->tx_desc_area + i;
  949. nexti = (i + 1) % MWL8K_TX_DESCS;
  950. tx_desc->status = 0;
  951. tx_desc->next_tx_desc_phys_addr =
  952. cpu_to_le32(txq->tx_desc_dma +
  953. nexti * sizeof(*tx_desc));
  954. }
  955. return 0;
  956. }
  957. static inline void mwl8k_tx_start(struct mwl8k_priv *priv)
  958. {
  959. iowrite32(MWL8K_H2A_INT_PPA_READY,
  960. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  961. iowrite32(MWL8K_H2A_INT_DUMMY,
  962. priv->regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  963. ioread32(priv->regs + MWL8K_HIU_INT_CODE);
  964. }
  965. static inline int mwl8k_txq_busy(struct mwl8k_priv *priv)
  966. {
  967. return priv->pending_tx_pkts;
  968. }
  969. struct mwl8k_txq_info {
  970. u32 fw_owned;
  971. u32 drv_owned;
  972. u32 unused;
  973. u32 len;
  974. u32 head;
  975. u32 tail;
  976. };
  977. static int mwl8k_scan_tx_ring(struct mwl8k_priv *priv,
  978. struct mwl8k_txq_info txinfo[],
  979. u32 num_queues)
  980. {
  981. int count, desc, status;
  982. struct mwl8k_tx_queue *txq;
  983. struct mwl8k_tx_desc *tx_desc;
  984. int ndescs = 0;
  985. memset(txinfo, 0, num_queues * sizeof(struct mwl8k_txq_info));
  986. spin_lock_bh(&priv->tx_lock);
  987. for (count = 0; count < num_queues; count++) {
  988. txq = priv->txq + count;
  989. txinfo[count].len = txq->tx_stats.len;
  990. txinfo[count].head = txq->tx_head;
  991. txinfo[count].tail = txq->tx_tail;
  992. for (desc = 0; desc < MWL8K_TX_DESCS; desc++) {
  993. tx_desc = txq->tx_desc_area + desc;
  994. status = le32_to_cpu(tx_desc->status);
  995. if (status & MWL8K_TXD_STATUS_FW_OWNED)
  996. txinfo[count].fw_owned++;
  997. else
  998. txinfo[count].drv_owned++;
  999. if (tx_desc->pkt_len == 0)
  1000. txinfo[count].unused++;
  1001. }
  1002. }
  1003. spin_unlock_bh(&priv->tx_lock);
  1004. return ndescs;
  1005. }
  1006. static int mwl8k_tx_wait_empty(struct ieee80211_hw *hw, u32 delay_ms)
  1007. {
  1008. u32 count = 0;
  1009. unsigned long timeout = 0;
  1010. struct mwl8k_priv *priv = hw->priv;
  1011. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1012. might_sleep();
  1013. if (priv->tx_wait != NULL)
  1014. printk(KERN_ERR "WARNING Previous TXWaitEmpty instance\n");
  1015. spin_lock_bh(&priv->tx_lock);
  1016. count = mwl8k_txq_busy(priv);
  1017. if (count) {
  1018. priv->tx_wait = &cmd_wait;
  1019. if (priv->radio_state)
  1020. mwl8k_tx_start(priv);
  1021. }
  1022. spin_unlock_bh(&priv->tx_lock);
  1023. if (count) {
  1024. struct mwl8k_txq_info txinfo[4];
  1025. int index;
  1026. int newcount;
  1027. timeout = wait_for_completion_timeout(&cmd_wait,
  1028. msecs_to_jiffies(delay_ms));
  1029. if (timeout)
  1030. return 0;
  1031. spin_lock_bh(&priv->tx_lock);
  1032. priv->tx_wait = NULL;
  1033. newcount = mwl8k_txq_busy(priv);
  1034. spin_unlock_bh(&priv->tx_lock);
  1035. printk(KERN_ERR "%s(%u) TIMEDOUT:%ums Pend:%u-->%u\n",
  1036. __func__, __LINE__, delay_ms, count, newcount);
  1037. mwl8k_scan_tx_ring(priv, txinfo, 4);
  1038. for (index = 0 ; index < 4; index++)
  1039. printk(KERN_ERR
  1040. "TXQ:%u L:%u H:%u T:%u FW:%u DRV:%u U:%u\n",
  1041. index,
  1042. txinfo[index].len,
  1043. txinfo[index].head,
  1044. txinfo[index].tail,
  1045. txinfo[index].fw_owned,
  1046. txinfo[index].drv_owned,
  1047. txinfo[index].unused);
  1048. return -ETIMEDOUT;
  1049. }
  1050. return 0;
  1051. }
  1052. #define MWL8K_TXD_OK (MWL8K_TXD_STATUS_OK | \
  1053. MWL8K_TXD_STATUS_OK_RETRY | \
  1054. MWL8K_TXD_STATUS_OK_MORE_RETRY)
  1055. #define MWL8K_TXD_SUCCESS(stat) ((stat) & MWL8K_TXD_OK)
  1056. #define MWL8K_TXD_FAIL_RETRY(stat) \
  1057. ((stat) & (MWL8K_TXD_STATUS_FAILED_EXCEED_LIMIT))
  1058. static void mwl8k_txq_reclaim(struct ieee80211_hw *hw, int index, int force)
  1059. {
  1060. struct mwl8k_priv *priv = hw->priv;
  1061. struct mwl8k_tx_queue *txq = priv->txq + index;
  1062. int wake = 0;
  1063. while (txq->tx_stats.len > 0) {
  1064. int tx;
  1065. int rc;
  1066. struct mwl8k_tx_desc *tx_desc;
  1067. unsigned long addr;
  1068. size_t size;
  1069. struct sk_buff *skb;
  1070. struct ieee80211_tx_info *info;
  1071. u32 status;
  1072. rc = 0;
  1073. tx = txq->tx_head;
  1074. tx_desc = txq->tx_desc_area + tx;
  1075. status = le32_to_cpu(tx_desc->status);
  1076. if (status & MWL8K_TXD_STATUS_FW_OWNED) {
  1077. if (!force)
  1078. break;
  1079. tx_desc->status &=
  1080. ~cpu_to_le32(MWL8K_TXD_STATUS_FW_OWNED);
  1081. }
  1082. txq->tx_head = (tx + 1) % MWL8K_TX_DESCS;
  1083. BUG_ON(txq->tx_stats.len == 0);
  1084. txq->tx_stats.len--;
  1085. priv->pending_tx_pkts--;
  1086. addr = le32_to_cpu(tx_desc->pkt_phys_addr);
  1087. size = (u32)(le16_to_cpu(tx_desc->pkt_len));
  1088. skb = txq->tx_skb[tx].skb;
  1089. txq->tx_skb[tx].skb = NULL;
  1090. BUG_ON(skb == NULL);
  1091. pci_unmap_single(priv->pdev, addr, size, PCI_DMA_TODEVICE);
  1092. rc = mwl8k_remove_dma_header(skb);
  1093. /* Mark descriptor as unused */
  1094. tx_desc->pkt_phys_addr = 0;
  1095. tx_desc->pkt_len = 0;
  1096. if (txq->tx_skb[tx].clone) {
  1097. /* Replace with original skb
  1098. * before returning to stack
  1099. * as buffer has been cloned
  1100. */
  1101. dev_kfree_skb(skb);
  1102. skb = txq->tx_skb[tx].clone;
  1103. txq->tx_skb[tx].clone = NULL;
  1104. }
  1105. if (rc) {
  1106. /* Something has gone wrong here.
  1107. * Failed to remove DMA header.
  1108. * Print error message and drop packet.
  1109. */
  1110. printk(KERN_ERR "%s: Error removing DMA header from "
  1111. "tx skb 0x%p.\n", priv->name, skb);
  1112. dev_kfree_skb(skb);
  1113. continue;
  1114. }
  1115. info = IEEE80211_SKB_CB(skb);
  1116. ieee80211_tx_info_clear_status(info);
  1117. /* Convert firmware status stuff into tx_status */
  1118. if (MWL8K_TXD_SUCCESS(status)) {
  1119. /* Transmit OK */
  1120. info->flags |= IEEE80211_TX_STAT_ACK;
  1121. }
  1122. ieee80211_tx_status_irqsafe(hw, skb);
  1123. wake = !priv->inconfig && priv->radio_state;
  1124. }
  1125. if (wake)
  1126. ieee80211_wake_queue(hw, index);
  1127. }
  1128. /* must be called only when the card's transmit is completely halted */
  1129. static void mwl8k_txq_deinit(struct ieee80211_hw *hw, int index)
  1130. {
  1131. struct mwl8k_priv *priv = hw->priv;
  1132. struct mwl8k_tx_queue *txq = priv->txq + index;
  1133. mwl8k_txq_reclaim(hw, index, 1);
  1134. kfree(txq->tx_skb);
  1135. txq->tx_skb = NULL;
  1136. pci_free_consistent(priv->pdev,
  1137. MWL8K_TX_DESCS * sizeof(struct mwl8k_tx_desc),
  1138. txq->tx_desc_area, txq->tx_desc_dma);
  1139. txq->tx_desc_area = NULL;
  1140. }
  1141. static int
  1142. mwl8k_txq_xmit(struct ieee80211_hw *hw, int index, struct sk_buff *skb)
  1143. {
  1144. struct mwl8k_priv *priv = hw->priv;
  1145. struct ieee80211_tx_info *tx_info;
  1146. struct ieee80211_hdr *wh;
  1147. struct mwl8k_tx_queue *txq;
  1148. struct mwl8k_tx_desc *tx;
  1149. struct mwl8k_dma_data *tr;
  1150. struct mwl8k_vif *mwl8k_vif;
  1151. struct sk_buff *org_skb = skb;
  1152. dma_addr_t dma;
  1153. u16 qos = 0;
  1154. bool qosframe = false, ampduframe = false;
  1155. bool mcframe = false, eapolframe = false;
  1156. bool amsduframe = false;
  1157. __le16 fc;
  1158. txq = priv->txq + index;
  1159. tx = txq->tx_desc_area + txq->tx_tail;
  1160. BUG_ON(txq->tx_skb[txq->tx_tail].skb != NULL);
  1161. /*
  1162. * Append HW DMA header to start of packet. Drop packet if
  1163. * there is not enough space or a failure to unshare/unclone
  1164. * the skb.
  1165. */
  1166. skb = mwl8k_add_dma_header(skb);
  1167. if (skb == NULL) {
  1168. printk(KERN_DEBUG "%s: failed to prepend HW DMA "
  1169. "header, dropping TX frame.\n", priv->name);
  1170. dev_kfree_skb(org_skb);
  1171. return NETDEV_TX_OK;
  1172. }
  1173. tx_info = IEEE80211_SKB_CB(skb);
  1174. mwl8k_vif = MWL8K_VIF(tx_info->control.vif);
  1175. tr = (struct mwl8k_dma_data *)skb->data;
  1176. wh = &tr->wh;
  1177. fc = wh->frame_control;
  1178. qosframe = ieee80211_is_data_qos(fc);
  1179. mcframe = is_multicast_ether_addr(wh->addr1);
  1180. ampduframe = !!(tx_info->flags & IEEE80211_TX_CTL_AMPDU);
  1181. if (tx_info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1182. u16 seqno = mwl8k_vif->seqno;
  1183. wh->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1184. wh->seq_ctrl |= cpu_to_le16(seqno << 4);
  1185. mwl8k_vif->seqno = seqno++ % 4096;
  1186. }
  1187. if (qosframe)
  1188. qos = le16_to_cpu(*((__le16 *)ieee80211_get_qos_ctl(wh)));
  1189. dma = pci_map_single(priv->pdev, skb->data,
  1190. skb->len, PCI_DMA_TODEVICE);
  1191. if (pci_dma_mapping_error(priv->pdev, dma)) {
  1192. printk(KERN_DEBUG "%s: failed to dma map skb, "
  1193. "dropping TX frame.\n", priv->name);
  1194. if (org_skb != NULL)
  1195. dev_kfree_skb(org_skb);
  1196. if (skb != NULL)
  1197. dev_kfree_skb(skb);
  1198. return NETDEV_TX_OK;
  1199. }
  1200. /* Set desc header, cpu bit order. */
  1201. tx->status = 0;
  1202. tx->data_rate = 0;
  1203. tx->tx_priority = index;
  1204. tx->qos_control = 0;
  1205. tx->rate_info = 0;
  1206. tx->peer_id = mwl8k_vif->peer_id;
  1207. amsduframe = !!(qos & IEEE80211_QOS_CONTROL_A_MSDU_PRESENT);
  1208. /* Setup firmware control bit fields for each frame type. */
  1209. if (ieee80211_is_mgmt(fc) || ieee80211_is_ctl(fc)) {
  1210. tx->data_rate = 0;
  1211. qos = mwl8k_qos_setbit_eosp(qos);
  1212. /* Set Queue size to unspecified */
  1213. qos = mwl8k_qos_setbit_qlen(qos, 0xff);
  1214. } else if (ieee80211_is_data(fc)) {
  1215. tx->data_rate = 1;
  1216. if (mcframe)
  1217. tx->status |= MWL8K_TXD_STATUS_MULTICAST_TX;
  1218. /*
  1219. * Tell firmware to not send EAPOL pkts in an
  1220. * aggregate. Verify against mac80211 tx path. If
  1221. * stack turns off AMPDU for an EAPOL frame this
  1222. * check will be removed.
  1223. */
  1224. if (eapolframe) {
  1225. qos = mwl8k_qos_setbit_ack(qos,
  1226. MWL8K_TXD_ACK_POLICY_NORMAL);
  1227. } else {
  1228. /* Send pkt in an aggregate if AMPDU frame. */
  1229. if (ampduframe)
  1230. qos = mwl8k_qos_setbit_ack(qos,
  1231. MWL8K_TXD_ACK_POLICY_BLOCKACK);
  1232. else
  1233. qos = mwl8k_qos_setbit_ack(qos,
  1234. MWL8K_TXD_ACK_POLICY_NORMAL);
  1235. if (amsduframe)
  1236. qos = mwl8k_qos_setbit_amsdu(qos);
  1237. }
  1238. }
  1239. /* Convert to little endian */
  1240. tx->qos_control = cpu_to_le16(qos);
  1241. tx->status = cpu_to_le32(tx->status);
  1242. tx->pkt_phys_addr = cpu_to_le32(dma);
  1243. tx->pkt_len = cpu_to_le16(skb->len);
  1244. txq->tx_skb[txq->tx_tail].skb = skb;
  1245. txq->tx_skb[txq->tx_tail].clone =
  1246. skb == org_skb ? NULL : org_skb;
  1247. spin_lock_bh(&priv->tx_lock);
  1248. tx->status = cpu_to_le32(MWL8K_TXD_STATUS_OK |
  1249. MWL8K_TXD_STATUS_FW_OWNED);
  1250. wmb();
  1251. txq->tx_stats.len++;
  1252. priv->pending_tx_pkts++;
  1253. txq->tx_stats.count++;
  1254. txq->tx_tail++;
  1255. if (txq->tx_tail == MWL8K_TX_DESCS)
  1256. txq->tx_tail = 0;
  1257. if (txq->tx_head == txq->tx_tail)
  1258. ieee80211_stop_queue(hw, index);
  1259. if (priv->inconfig) {
  1260. /*
  1261. * Silently queue packet when we are in the middle of
  1262. * a config cycle. Notify firmware only if we are
  1263. * waiting for TXQs to empty. If a packet is sent
  1264. * before .config() is complete, perhaps it is better
  1265. * to drop the packet, as the channel is being changed
  1266. * and the packet will end up on the wrong channel.
  1267. */
  1268. printk(KERN_ERR "%s(): WARNING TX activity while "
  1269. "in config\n", __func__);
  1270. if (priv->tx_wait != NULL)
  1271. mwl8k_tx_start(priv);
  1272. } else
  1273. mwl8k_tx_start(priv);
  1274. spin_unlock_bh(&priv->tx_lock);
  1275. return NETDEV_TX_OK;
  1276. }
  1277. /*
  1278. * Command processing.
  1279. */
  1280. /* Timeout firmware commands after 2000ms */
  1281. #define MWL8K_CMD_TIMEOUT_MS 2000
  1282. static int mwl8k_post_cmd(struct ieee80211_hw *hw, struct mwl8k_cmd_pkt *cmd)
  1283. {
  1284. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  1285. struct mwl8k_priv *priv = hw->priv;
  1286. void __iomem *regs = priv->regs;
  1287. dma_addr_t dma_addr;
  1288. unsigned int dma_size;
  1289. int rc;
  1290. u16 __iomem *result;
  1291. unsigned long timeout = 0;
  1292. u8 buf[32];
  1293. cmd->result = 0xFFFF;
  1294. dma_size = le16_to_cpu(cmd->length);
  1295. dma_addr = pci_map_single(priv->pdev, cmd, dma_size,
  1296. PCI_DMA_BIDIRECTIONAL);
  1297. if (pci_dma_mapping_error(priv->pdev, dma_addr))
  1298. return -ENOMEM;
  1299. if (priv->hostcmd_wait != NULL)
  1300. printk(KERN_ERR "WARNING host command in progress\n");
  1301. spin_lock_irq(&priv->fw_lock);
  1302. priv->hostcmd_wait = &cmd_wait;
  1303. iowrite32(dma_addr, regs + MWL8K_HIU_GEN_PTR);
  1304. iowrite32(MWL8K_H2A_INT_DOORBELL,
  1305. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1306. iowrite32(MWL8K_H2A_INT_DUMMY,
  1307. regs + MWL8K_HIU_H2A_INTERRUPT_EVENTS);
  1308. spin_unlock_irq(&priv->fw_lock);
  1309. timeout = wait_for_completion_timeout(&cmd_wait,
  1310. msecs_to_jiffies(MWL8K_CMD_TIMEOUT_MS));
  1311. result = &cmd->result;
  1312. if (!timeout) {
  1313. spin_lock_irq(&priv->fw_lock);
  1314. priv->hostcmd_wait = NULL;
  1315. spin_unlock_irq(&priv->fw_lock);
  1316. printk(KERN_ERR "%s: Command %s timeout after %u ms\n",
  1317. priv->name,
  1318. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1319. MWL8K_CMD_TIMEOUT_MS);
  1320. rc = -ETIMEDOUT;
  1321. } else {
  1322. rc = *result ? -EINVAL : 0;
  1323. if (rc)
  1324. printk(KERN_ERR "%s: Command %s error 0x%x\n",
  1325. priv->name,
  1326. mwl8k_cmd_name(cmd->code, buf, sizeof(buf)),
  1327. *result);
  1328. }
  1329. pci_unmap_single(priv->pdev, dma_addr, dma_size,
  1330. PCI_DMA_BIDIRECTIONAL);
  1331. return rc;
  1332. }
  1333. /*
  1334. * GET_HW_SPEC.
  1335. */
  1336. struct mwl8k_cmd_get_hw_spec {
  1337. struct mwl8k_cmd_pkt header;
  1338. __u8 hw_rev;
  1339. __u8 host_interface;
  1340. __le16 num_mcaddrs;
  1341. __u8 perm_addr[IEEE80211_ADDR_LEN];
  1342. __le16 region_code;
  1343. __le32 fw_rev;
  1344. __le32 ps_cookie;
  1345. __le32 caps;
  1346. __u8 mcs_bitmap[16];
  1347. __le32 rx_queue_ptr;
  1348. __le32 num_tx_queues;
  1349. __le32 tx_queue_ptrs[MWL8K_TX_QUEUES];
  1350. __le32 caps2;
  1351. __le32 num_tx_desc_per_queue;
  1352. __le32 total_rx_desc;
  1353. } __attribute__((packed));
  1354. static int mwl8k_cmd_get_hw_spec(struct ieee80211_hw *hw)
  1355. {
  1356. struct mwl8k_priv *priv = hw->priv;
  1357. struct mwl8k_cmd_get_hw_spec *cmd;
  1358. int rc;
  1359. int i;
  1360. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1361. if (cmd == NULL)
  1362. return -ENOMEM;
  1363. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_HW_SPEC);
  1364. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1365. memset(cmd->perm_addr, 0xff, sizeof(cmd->perm_addr));
  1366. cmd->ps_cookie = cpu_to_le32(priv->cookie_dma);
  1367. cmd->rx_queue_ptr = cpu_to_le32(priv->rxq[0].rx_desc_dma);
  1368. cmd->num_tx_queues = MWL8K_TX_QUEUES;
  1369. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  1370. cmd->tx_queue_ptrs[i] = cpu_to_le32(priv->txq[i].tx_desc_dma);
  1371. cmd->num_tx_desc_per_queue = MWL8K_TX_DESCS;
  1372. cmd->total_rx_desc = MWL8K_RX_DESCS;
  1373. rc = mwl8k_post_cmd(hw, &cmd->header);
  1374. if (!rc) {
  1375. SET_IEEE80211_PERM_ADDR(hw, cmd->perm_addr);
  1376. priv->num_mcaddrs = le16_to_cpu(cmd->num_mcaddrs);
  1377. priv->fw_rev = cmd->fw_rev;
  1378. priv->hw_rev = cmd->hw_rev;
  1379. priv->region_code = le16_to_cpu(cmd->region_code);
  1380. }
  1381. kfree(cmd);
  1382. return rc;
  1383. }
  1384. /*
  1385. * CMD_MAC_MULTICAST_ADR.
  1386. */
  1387. struct mwl8k_cmd_mac_multicast_adr {
  1388. struct mwl8k_cmd_pkt header;
  1389. __le16 action;
  1390. __le16 numaddr;
  1391. __u8 addr[1][IEEE80211_ADDR_LEN];
  1392. };
  1393. #define MWL8K_ENABLE_RX_MULTICAST 0x000F
  1394. static int mwl8k_cmd_mac_multicast_adr(struct ieee80211_hw *hw,
  1395. int mc_count,
  1396. struct dev_addr_list *mclist)
  1397. {
  1398. struct mwl8k_cmd_mac_multicast_adr *cmd;
  1399. int index = 0;
  1400. int rc;
  1401. int size = sizeof(*cmd) + ((mc_count - 1) * IEEE80211_ADDR_LEN);
  1402. cmd = kzalloc(size, GFP_KERNEL);
  1403. if (cmd == NULL)
  1404. return -ENOMEM;
  1405. cmd->header.code = cpu_to_le16(MWL8K_CMD_MAC_MULTICAST_ADR);
  1406. cmd->header.length = cpu_to_le16(size);
  1407. cmd->action = cpu_to_le16(MWL8K_ENABLE_RX_MULTICAST);
  1408. cmd->numaddr = cpu_to_le16(mc_count);
  1409. while ((index < mc_count) && mclist) {
  1410. if (mclist->da_addrlen != IEEE80211_ADDR_LEN) {
  1411. rc = -EINVAL;
  1412. goto mwl8k_cmd_mac_multicast_adr_exit;
  1413. }
  1414. memcpy(cmd->addr[index], mclist->da_addr, IEEE80211_ADDR_LEN);
  1415. index++;
  1416. mclist = mclist->next;
  1417. }
  1418. rc = mwl8k_post_cmd(hw, &cmd->header);
  1419. mwl8k_cmd_mac_multicast_adr_exit:
  1420. kfree(cmd);
  1421. return rc;
  1422. }
  1423. /*
  1424. * CMD_802_11_GET_STAT.
  1425. */
  1426. struct mwl8k_cmd_802_11_get_stat {
  1427. struct mwl8k_cmd_pkt header;
  1428. __le16 action;
  1429. __le32 stats[64];
  1430. } __attribute__((packed));
  1431. #define MWL8K_STAT_ACK_FAILURE 9
  1432. #define MWL8K_STAT_RTS_FAILURE 12
  1433. #define MWL8K_STAT_FCS_ERROR 24
  1434. #define MWL8K_STAT_RTS_SUCCESS 11
  1435. static int mwl8k_cmd_802_11_get_stat(struct ieee80211_hw *hw,
  1436. struct ieee80211_low_level_stats *stats)
  1437. {
  1438. struct mwl8k_cmd_802_11_get_stat *cmd;
  1439. int rc;
  1440. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1441. if (cmd == NULL)
  1442. return -ENOMEM;
  1443. cmd->header.code = cpu_to_le16(MWL8K_CMD_GET_STAT);
  1444. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1445. cmd->action = cpu_to_le16(MWL8K_CMD_GET);
  1446. rc = mwl8k_post_cmd(hw, &cmd->header);
  1447. if (!rc) {
  1448. stats->dot11ACKFailureCount =
  1449. le32_to_cpu(cmd->stats[MWL8K_STAT_ACK_FAILURE]);
  1450. stats->dot11RTSFailureCount =
  1451. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_FAILURE]);
  1452. stats->dot11FCSErrorCount =
  1453. le32_to_cpu(cmd->stats[MWL8K_STAT_FCS_ERROR]);
  1454. stats->dot11RTSSuccessCount =
  1455. le32_to_cpu(cmd->stats[MWL8K_STAT_RTS_SUCCESS]);
  1456. }
  1457. kfree(cmd);
  1458. return rc;
  1459. }
  1460. /*
  1461. * CMD_802_11_RADIO_CONTROL.
  1462. */
  1463. struct mwl8k_cmd_802_11_radio_control {
  1464. struct mwl8k_cmd_pkt header;
  1465. __le16 action;
  1466. __le16 control;
  1467. __le16 radio_on;
  1468. } __attribute__((packed));
  1469. static int mwl8k_cmd_802_11_radio_control(struct ieee80211_hw *hw, int enable)
  1470. {
  1471. struct mwl8k_priv *priv = hw->priv;
  1472. struct mwl8k_cmd_802_11_radio_control *cmd;
  1473. int rc;
  1474. if (((enable & MWL8K_RADIO_ENABLE) == priv->radio_state) &&
  1475. !(enable & MWL8K_RADIO_FORCE))
  1476. return 0;
  1477. enable &= MWL8K_RADIO_ENABLE;
  1478. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1479. if (cmd == NULL)
  1480. return -ENOMEM;
  1481. cmd->header.code = cpu_to_le16(MWL8K_CMD_RADIO_CONTROL);
  1482. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1483. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1484. cmd->control = cpu_to_le16(priv->radio_preamble);
  1485. cmd->radio_on = cpu_to_le16(enable ? 0x0001 : 0x0000);
  1486. rc = mwl8k_post_cmd(hw, &cmd->header);
  1487. kfree(cmd);
  1488. if (!rc)
  1489. priv->radio_state = enable;
  1490. return rc;
  1491. }
  1492. static int
  1493. mwl8k_set_radio_preamble(struct ieee80211_hw *hw, bool short_preamble)
  1494. {
  1495. struct mwl8k_priv *priv;
  1496. if (hw == NULL || hw->priv == NULL)
  1497. return -EINVAL;
  1498. priv = hw->priv;
  1499. priv->radio_preamble = (short_preamble ?
  1500. MWL8K_RADIO_SHORT_PREAMBLE :
  1501. MWL8K_RADIO_LONG_PREAMBLE);
  1502. return mwl8k_cmd_802_11_radio_control(hw,
  1503. MWL8K_RADIO_ENABLE | MWL8K_RADIO_FORCE);
  1504. }
  1505. /*
  1506. * CMD_802_11_RF_TX_POWER.
  1507. */
  1508. #define MWL8K_TX_POWER_LEVEL_TOTAL 8
  1509. struct mwl8k_cmd_802_11_rf_tx_power {
  1510. struct mwl8k_cmd_pkt header;
  1511. __le16 action;
  1512. __le16 support_level;
  1513. __le16 current_level;
  1514. __le16 reserved;
  1515. __le16 power_level_list[MWL8K_TX_POWER_LEVEL_TOTAL];
  1516. } __attribute__((packed));
  1517. static int mwl8k_cmd_802_11_rf_tx_power(struct ieee80211_hw *hw, int dBm)
  1518. {
  1519. struct mwl8k_cmd_802_11_rf_tx_power *cmd;
  1520. int rc;
  1521. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1522. if (cmd == NULL)
  1523. return -ENOMEM;
  1524. cmd->header.code = cpu_to_le16(MWL8K_CMD_RF_TX_POWER);
  1525. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1526. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1527. cmd->support_level = cpu_to_le16(dBm);
  1528. rc = mwl8k_post_cmd(hw, &cmd->header);
  1529. kfree(cmd);
  1530. return rc;
  1531. }
  1532. /*
  1533. * CMD_SET_PRE_SCAN.
  1534. */
  1535. struct mwl8k_cmd_set_pre_scan {
  1536. struct mwl8k_cmd_pkt header;
  1537. } __attribute__((packed));
  1538. static int mwl8k_cmd_set_pre_scan(struct ieee80211_hw *hw)
  1539. {
  1540. struct mwl8k_cmd_set_pre_scan *cmd;
  1541. int rc;
  1542. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1543. if (cmd == NULL)
  1544. return -ENOMEM;
  1545. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_PRE_SCAN);
  1546. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1547. rc = mwl8k_post_cmd(hw, &cmd->header);
  1548. kfree(cmd);
  1549. return rc;
  1550. }
  1551. /*
  1552. * CMD_SET_POST_SCAN.
  1553. */
  1554. struct mwl8k_cmd_set_post_scan {
  1555. struct mwl8k_cmd_pkt header;
  1556. __le32 isibss;
  1557. __u8 bssid[IEEE80211_ADDR_LEN];
  1558. } __attribute__((packed));
  1559. static int
  1560. mwl8k_cmd_set_post_scan(struct ieee80211_hw *hw, __u8 mac[IEEE80211_ADDR_LEN])
  1561. {
  1562. struct mwl8k_cmd_set_post_scan *cmd;
  1563. int rc;
  1564. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1565. if (cmd == NULL)
  1566. return -ENOMEM;
  1567. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_POST_SCAN);
  1568. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1569. cmd->isibss = 0;
  1570. memcpy(cmd->bssid, mac, IEEE80211_ADDR_LEN);
  1571. rc = mwl8k_post_cmd(hw, &cmd->header);
  1572. kfree(cmd);
  1573. return rc;
  1574. }
  1575. /*
  1576. * CMD_SET_RF_CHANNEL.
  1577. */
  1578. struct mwl8k_cmd_set_rf_channel {
  1579. struct mwl8k_cmd_pkt header;
  1580. __le16 action;
  1581. __u8 current_channel;
  1582. __le32 channel_flags;
  1583. } __attribute__((packed));
  1584. static int mwl8k_cmd_set_rf_channel(struct ieee80211_hw *hw,
  1585. struct ieee80211_channel *channel)
  1586. {
  1587. struct mwl8k_cmd_set_rf_channel *cmd;
  1588. int rc;
  1589. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1590. if (cmd == NULL)
  1591. return -ENOMEM;
  1592. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RF_CHANNEL);
  1593. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1594. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1595. cmd->current_channel = channel->hw_value;
  1596. if (channel->band == IEEE80211_BAND_2GHZ)
  1597. cmd->channel_flags = cpu_to_le32(0x00000081);
  1598. else
  1599. cmd->channel_flags = cpu_to_le32(0x00000000);
  1600. rc = mwl8k_post_cmd(hw, &cmd->header);
  1601. kfree(cmd);
  1602. return rc;
  1603. }
  1604. /*
  1605. * CMD_SET_SLOT.
  1606. */
  1607. struct mwl8k_cmd_set_slot {
  1608. struct mwl8k_cmd_pkt header;
  1609. __le16 action;
  1610. __u8 short_slot;
  1611. } __attribute__((packed));
  1612. static int mwl8k_cmd_set_slot(struct ieee80211_hw *hw, int slot_time)
  1613. {
  1614. struct mwl8k_cmd_set_slot *cmd;
  1615. int rc;
  1616. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1617. if (cmd == NULL)
  1618. return -ENOMEM;
  1619. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_SLOT);
  1620. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1621. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1622. cmd->short_slot = slot_time == MWL8K_SHORT_SLOTTIME ? 1 : 0;
  1623. rc = mwl8k_post_cmd(hw, &cmd->header);
  1624. kfree(cmd);
  1625. return rc;
  1626. }
  1627. /*
  1628. * CMD_MIMO_CONFIG.
  1629. */
  1630. struct mwl8k_cmd_mimo_config {
  1631. struct mwl8k_cmd_pkt header;
  1632. __le32 action;
  1633. __u8 rx_antenna_map;
  1634. __u8 tx_antenna_map;
  1635. } __attribute__((packed));
  1636. static int mwl8k_cmd_mimo_config(struct ieee80211_hw *hw, __u8 rx, __u8 tx)
  1637. {
  1638. struct mwl8k_cmd_mimo_config *cmd;
  1639. int rc;
  1640. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1641. if (cmd == NULL)
  1642. return -ENOMEM;
  1643. cmd->header.code = cpu_to_le16(MWL8K_CMD_MIMO_CONFIG);
  1644. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1645. cmd->action = cpu_to_le32((u32)MWL8K_CMD_SET);
  1646. cmd->rx_antenna_map = rx;
  1647. cmd->tx_antenna_map = tx;
  1648. rc = mwl8k_post_cmd(hw, &cmd->header);
  1649. kfree(cmd);
  1650. return rc;
  1651. }
  1652. /*
  1653. * CMD_ENABLE_SNIFFER.
  1654. */
  1655. struct mwl8k_cmd_enable_sniffer {
  1656. struct mwl8k_cmd_pkt header;
  1657. __le32 action;
  1658. } __attribute__((packed));
  1659. static int mwl8k_enable_sniffer(struct ieee80211_hw *hw, bool enable)
  1660. {
  1661. struct mwl8k_cmd_enable_sniffer *cmd;
  1662. int rc;
  1663. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1664. if (cmd == NULL)
  1665. return -ENOMEM;
  1666. cmd->header.code = cpu_to_le16(MWL8K_CMD_ENABLE_SNIFFER);
  1667. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1668. cmd->action = enable ? cpu_to_le32((u32)MWL8K_CMD_SET) : 0;
  1669. rc = mwl8k_post_cmd(hw, &cmd->header);
  1670. kfree(cmd);
  1671. return rc;
  1672. }
  1673. /*
  1674. * CMD_SET_RATE_ADAPT_MODE.
  1675. */
  1676. struct mwl8k_cmd_set_rate_adapt_mode {
  1677. struct mwl8k_cmd_pkt header;
  1678. __le16 action;
  1679. __le16 mode;
  1680. } __attribute__((packed));
  1681. static int mwl8k_cmd_setrateadaptmode(struct ieee80211_hw *hw, __u16 mode)
  1682. {
  1683. struct mwl8k_cmd_set_rate_adapt_mode *cmd;
  1684. int rc;
  1685. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1686. if (cmd == NULL)
  1687. return -ENOMEM;
  1688. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATEADAPT_MODE);
  1689. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1690. cmd->action = cpu_to_le16(MWL8K_CMD_SET);
  1691. cmd->mode = cpu_to_le16(mode);
  1692. rc = mwl8k_post_cmd(hw, &cmd->header);
  1693. kfree(cmd);
  1694. return rc;
  1695. }
  1696. /*
  1697. * CMD_SET_WMM_MODE.
  1698. */
  1699. struct mwl8k_cmd_set_wmm {
  1700. struct mwl8k_cmd_pkt header;
  1701. __le16 action;
  1702. } __attribute__((packed));
  1703. static int mwl8k_set_wmm(struct ieee80211_hw *hw, bool enable)
  1704. {
  1705. struct mwl8k_priv *priv = hw->priv;
  1706. struct mwl8k_cmd_set_wmm *cmd;
  1707. int rc;
  1708. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1709. if (cmd == NULL)
  1710. return -ENOMEM;
  1711. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_WMM_MODE);
  1712. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1713. cmd->action = enable ? cpu_to_le16(MWL8K_CMD_SET) : 0;
  1714. rc = mwl8k_post_cmd(hw, &cmd->header);
  1715. kfree(cmd);
  1716. if (!rc)
  1717. priv->wmm_mode = enable;
  1718. return rc;
  1719. }
  1720. /*
  1721. * CMD_SET_RTS_THRESHOLD.
  1722. */
  1723. struct mwl8k_cmd_rts_threshold {
  1724. struct mwl8k_cmd_pkt header;
  1725. __le16 action;
  1726. __le16 threshold;
  1727. } __attribute__((packed));
  1728. static int mwl8k_rts_threshold(struct ieee80211_hw *hw,
  1729. u16 action, u16 *threshold)
  1730. {
  1731. struct mwl8k_cmd_rts_threshold *cmd;
  1732. int rc;
  1733. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1734. if (cmd == NULL)
  1735. return -ENOMEM;
  1736. cmd->header.code = cpu_to_le16(MWL8K_CMD_RTS_THRESHOLD);
  1737. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1738. cmd->action = cpu_to_le16(action);
  1739. cmd->threshold = cpu_to_le16(*threshold);
  1740. rc = mwl8k_post_cmd(hw, &cmd->header);
  1741. kfree(cmd);
  1742. return rc;
  1743. }
  1744. /*
  1745. * CMD_SET_EDCA_PARAMS.
  1746. */
  1747. struct mwl8k_cmd_set_edca_params {
  1748. struct mwl8k_cmd_pkt header;
  1749. /* See MWL8K_SET_EDCA_XXX below */
  1750. __le16 action;
  1751. /* TX opportunity in units of 32 us */
  1752. __le16 txop;
  1753. /* Log exponent of max contention period: 0...15*/
  1754. __u8 log_cw_max;
  1755. /* Log exponent of min contention period: 0...15 */
  1756. __u8 log_cw_min;
  1757. /* Adaptive interframe spacing in units of 32us */
  1758. __u8 aifs;
  1759. /* TX queue to configure */
  1760. __u8 txq;
  1761. } __attribute__((packed));
  1762. #define MWL8K_GET_EDCA_ALL 0
  1763. #define MWL8K_SET_EDCA_CW 0x01
  1764. #define MWL8K_SET_EDCA_TXOP 0x02
  1765. #define MWL8K_SET_EDCA_AIFS 0x04
  1766. #define MWL8K_SET_EDCA_ALL (MWL8K_SET_EDCA_CW | \
  1767. MWL8K_SET_EDCA_TXOP | \
  1768. MWL8K_SET_EDCA_AIFS)
  1769. static int
  1770. mwl8k_set_edca_params(struct ieee80211_hw *hw, __u8 qnum,
  1771. __u16 cw_min, __u16 cw_max,
  1772. __u8 aifs, __u16 txop)
  1773. {
  1774. struct mwl8k_cmd_set_edca_params *cmd;
  1775. u32 log_cw_min, log_cw_max;
  1776. int rc;
  1777. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1778. if (cmd == NULL)
  1779. return -ENOMEM;
  1780. log_cw_min = ilog2(cw_min+1);
  1781. log_cw_max = ilog2(cw_max+1);
  1782. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_EDCA_PARAMS);
  1783. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1784. cmd->action = cpu_to_le16(MWL8K_SET_EDCA_ALL);
  1785. cmd->txop = cpu_to_le16(txop);
  1786. cmd->log_cw_max = (u8)log_cw_max;
  1787. cmd->log_cw_min = (u8)log_cw_min;
  1788. cmd->aifs = aifs;
  1789. cmd->txq = qnum;
  1790. rc = mwl8k_post_cmd(hw, &cmd->header);
  1791. kfree(cmd);
  1792. return rc;
  1793. }
  1794. /*
  1795. * CMD_FINALIZE_JOIN.
  1796. */
  1797. /* FJ beacon buffer size is compiled into the firmware. */
  1798. #define MWL8K_FJ_BEACON_MAXLEN 128
  1799. struct mwl8k_cmd_finalize_join {
  1800. struct mwl8k_cmd_pkt header;
  1801. __le32 sleep_interval; /* Number of beacon periods to sleep */
  1802. __u8 beacon_data[MWL8K_FJ_BEACON_MAXLEN];
  1803. } __attribute__((packed));
  1804. static int mwl8k_finalize_join(struct ieee80211_hw *hw, void *frame,
  1805. __u16 framelen, __u16 dtim)
  1806. {
  1807. struct mwl8k_cmd_finalize_join *cmd;
  1808. struct ieee80211_mgmt *payload = frame;
  1809. u16 hdrlen;
  1810. u32 payload_len;
  1811. int rc;
  1812. if (frame == NULL)
  1813. return -EINVAL;
  1814. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1815. if (cmd == NULL)
  1816. return -ENOMEM;
  1817. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_FINALIZE_JOIN);
  1818. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1819. if (dtim)
  1820. cmd->sleep_interval = cpu_to_le32(dtim);
  1821. else
  1822. cmd->sleep_interval = cpu_to_le32(1);
  1823. hdrlen = ieee80211_hdrlen(payload->frame_control);
  1824. payload_len = framelen > hdrlen ? framelen - hdrlen : 0;
  1825. /* XXX TBD Might just have to abort and return an error */
  1826. if (payload_len > MWL8K_FJ_BEACON_MAXLEN)
  1827. printk(KERN_ERR "%s(): WARNING: Incomplete beacon "
  1828. "sent to firmware. Sz=%u MAX=%u\n", __func__,
  1829. payload_len, MWL8K_FJ_BEACON_MAXLEN);
  1830. payload_len = payload_len > MWL8K_FJ_BEACON_MAXLEN ?
  1831. MWL8K_FJ_BEACON_MAXLEN : payload_len;
  1832. if (payload && payload_len)
  1833. memcpy(cmd->beacon_data, &payload->u.beacon, payload_len);
  1834. rc = mwl8k_post_cmd(hw, &cmd->header);
  1835. kfree(cmd);
  1836. return rc;
  1837. }
  1838. /*
  1839. * CMD_UPDATE_STADB.
  1840. */
  1841. struct mwl8k_cmd_update_sta_db {
  1842. struct mwl8k_cmd_pkt header;
  1843. /* See STADB_ACTION_TYPE */
  1844. __le32 action;
  1845. /* Peer MAC address */
  1846. __u8 peer_addr[IEEE80211_ADDR_LEN];
  1847. __le32 reserved;
  1848. /* Peer info - valid during add/update. */
  1849. struct peer_capability_info peer_info;
  1850. } __attribute__((packed));
  1851. static int mwl8k_cmd_update_sta_db(struct ieee80211_hw *hw,
  1852. struct ieee80211_vif *vif, __u32 action)
  1853. {
  1854. struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
  1855. struct ieee80211_bss_conf *info = &mv_vif->bss_info;
  1856. struct mwl8k_cmd_update_sta_db *cmd;
  1857. struct peer_capability_info *peer_info;
  1858. struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
  1859. DECLARE_MAC_BUF(mac);
  1860. int rc;
  1861. __u8 count, *rates;
  1862. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1863. if (cmd == NULL)
  1864. return -ENOMEM;
  1865. cmd->header.code = cpu_to_le16(MWL8K_CMD_UPDATE_STADB);
  1866. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1867. cmd->action = cpu_to_le32(action);
  1868. peer_info = &cmd->peer_info;
  1869. memcpy(cmd->peer_addr, mv_vif->bssid, IEEE80211_ADDR_LEN);
  1870. switch (action) {
  1871. case MWL8K_STA_DB_ADD_ENTRY:
  1872. case MWL8K_STA_DB_MODIFY_ENTRY:
  1873. /* Build peer_info block */
  1874. peer_info->peer_type = MWL8K_PEER_TYPE_ACCESSPOINT;
  1875. peer_info->basic_caps = cpu_to_le16(info->assoc_capability);
  1876. peer_info->interop = 1;
  1877. peer_info->amsdu_enabled = 0;
  1878. rates = peer_info->legacy_rates;
  1879. for (count = 0 ; count < mv_vif->legacy_nrates; count++)
  1880. rates[count] = bitrates[count].hw_value;
  1881. rc = mwl8k_post_cmd(hw, &cmd->header);
  1882. if (rc == 0)
  1883. mv_vif->peer_id = peer_info->station_id;
  1884. break;
  1885. case MWL8K_STA_DB_DEL_ENTRY:
  1886. case MWL8K_STA_DB_FLUSH:
  1887. default:
  1888. rc = mwl8k_post_cmd(hw, &cmd->header);
  1889. if (rc == 0)
  1890. mv_vif->peer_id = 0;
  1891. break;
  1892. }
  1893. kfree(cmd);
  1894. return rc;
  1895. }
  1896. /*
  1897. * CMD_SET_AID.
  1898. */
  1899. #define IEEE80211_OPMODE_DISABLED 0x00
  1900. #define IEEE80211_OPMODE_NON_MEMBER_PROT_MODE 0x01
  1901. #define IEEE80211_OPMODE_ONE_20MHZ_STA_PROT_MODE 0x02
  1902. #define IEEE80211_OPMODE_HTMIXED_PROT_MODE 0x03
  1903. #define MWL8K_RATE_INDEX_MAX_ARRAY 14
  1904. #define MWL8K_FRAME_PROT_DISABLED 0x00
  1905. #define MWL8K_FRAME_PROT_11G 0x07
  1906. #define MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY 0x02
  1907. #define MWL8K_FRAME_PROT_11N_HT_ALL 0x06
  1908. #define MWL8K_FRAME_PROT_MASK 0x07
  1909. struct mwl8k_cmd_update_set_aid {
  1910. struct mwl8k_cmd_pkt header;
  1911. __le16 aid;
  1912. /* AP's MAC address (BSSID) */
  1913. __u8 bssid[IEEE80211_ADDR_LEN];
  1914. __le16 protection_mode;
  1915. __u8 supp_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
  1916. } __attribute__((packed));
  1917. static int mwl8k_cmd_set_aid(struct ieee80211_hw *hw,
  1918. struct ieee80211_vif *vif)
  1919. {
  1920. struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
  1921. struct ieee80211_bss_conf *info = &mv_vif->bss_info;
  1922. struct mwl8k_cmd_update_set_aid *cmd;
  1923. struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
  1924. int count;
  1925. u16 prot_mode;
  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_AID);
  1931. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1932. cmd->aid = cpu_to_le16(info->aid);
  1933. memcpy(cmd->bssid, mv_vif->bssid, IEEE80211_ADDR_LEN);
  1934. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  1935. if (info->use_cts_prot) {
  1936. prot_mode = MWL8K_FRAME_PROT_11G;
  1937. } else {
  1938. switch (info->ht.operation_mode &
  1939. IEEE80211_HT_OP_MODE_PROTECTION) {
  1940. case IEEE80211_HT_OP_MODE_PROTECTION_20MHZ:
  1941. prot_mode = MWL8K_FRAME_PROT_11N_HT_40MHZ_ONLY;
  1942. break;
  1943. case IEEE80211_HT_OP_MODE_PROTECTION_NONHT_MIXED:
  1944. prot_mode = MWL8K_FRAME_PROT_11N_HT_ALL;
  1945. break;
  1946. default:
  1947. prot_mode = MWL8K_FRAME_PROT_DISABLED;
  1948. break;
  1949. }
  1950. }
  1951. cmd->protection_mode = cpu_to_le16(prot_mode);
  1952. for (count = 0; count < mv_vif->legacy_nrates; count++)
  1953. cmd->supp_rates[count] = bitrates[count].hw_value;
  1954. rc = mwl8k_post_cmd(hw, &cmd->header);
  1955. kfree(cmd);
  1956. return rc;
  1957. }
  1958. /*
  1959. * CMD_SET_RATE.
  1960. */
  1961. struct mwl8k_cmd_update_rateset {
  1962. struct mwl8k_cmd_pkt header;
  1963. __u8 legacy_rates[MWL8K_RATE_INDEX_MAX_ARRAY];
  1964. /* Bitmap for supported MCS codes. */
  1965. __u8 mcs_set[MWL8K_IEEE_LEGACY_DATA_RATES];
  1966. __u8 reserved[MWL8K_IEEE_LEGACY_DATA_RATES];
  1967. } __attribute__((packed));
  1968. static int mwl8k_update_rateset(struct ieee80211_hw *hw,
  1969. struct ieee80211_vif *vif)
  1970. {
  1971. struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
  1972. struct mwl8k_cmd_update_rateset *cmd;
  1973. struct ieee80211_rate *bitrates = mv_vif->legacy_rates;
  1974. int count;
  1975. int rc;
  1976. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  1977. if (cmd == NULL)
  1978. return -ENOMEM;
  1979. cmd->header.code = cpu_to_le16(MWL8K_CMD_SET_RATE);
  1980. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  1981. for (count = 0; count < mv_vif->legacy_nrates; count++)
  1982. cmd->legacy_rates[count] = bitrates[count].hw_value;
  1983. rc = mwl8k_post_cmd(hw, &cmd->header);
  1984. kfree(cmd);
  1985. return rc;
  1986. }
  1987. /*
  1988. * CMD_USE_FIXED_RATE.
  1989. */
  1990. #define MWL8K_RATE_TABLE_SIZE 8
  1991. #define MWL8K_UCAST_RATE 0
  1992. #define MWL8K_MCAST_RATE 1
  1993. #define MWL8K_BCAST_RATE 2
  1994. #define MWL8K_USE_FIXED_RATE 0x0001
  1995. #define MWL8K_USE_AUTO_RATE 0x0002
  1996. struct mwl8k_rate_entry {
  1997. /* Set to 1 if HT rate, 0 if legacy. */
  1998. __le32 is_ht_rate;
  1999. /* Set to 1 to use retry_count field. */
  2000. __le32 enable_retry;
  2001. /* Specified legacy rate or MCS. */
  2002. __le32 rate;
  2003. /* Number of allowed retries. */
  2004. __le32 retry_count;
  2005. } __attribute__((packed));
  2006. struct mwl8k_rate_table {
  2007. /* 1 to allow specified rate and below */
  2008. __le32 allow_rate_drop;
  2009. __le32 num_rates;
  2010. struct mwl8k_rate_entry rate_entry[MWL8K_RATE_TABLE_SIZE];
  2011. } __attribute__((packed));
  2012. struct mwl8k_cmd_use_fixed_rate {
  2013. struct mwl8k_cmd_pkt header;
  2014. __le32 action;
  2015. struct mwl8k_rate_table rate_table;
  2016. /* Unicast, Broadcast or Multicast */
  2017. __le32 rate_type;
  2018. __le32 reserved1;
  2019. __le32 reserved2;
  2020. } __attribute__((packed));
  2021. static int mwl8k_cmd_use_fixed_rate(struct ieee80211_hw *hw,
  2022. u32 action, u32 rate_type, struct mwl8k_rate_table *rate_table)
  2023. {
  2024. struct mwl8k_cmd_use_fixed_rate *cmd;
  2025. int count;
  2026. int rc;
  2027. cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
  2028. if (cmd == NULL)
  2029. return -ENOMEM;
  2030. cmd->header.code = cpu_to_le16(MWL8K_CMD_USE_FIXED_RATE);
  2031. cmd->header.length = cpu_to_le16(sizeof(*cmd));
  2032. cmd->action = cpu_to_le32(action);
  2033. cmd->rate_type = cpu_to_le32(rate_type);
  2034. if (rate_table != NULL) {
  2035. /* Copy over each field manually so
  2036. * that bitflipping can be done
  2037. */
  2038. cmd->rate_table.allow_rate_drop =
  2039. cpu_to_le32(rate_table->allow_rate_drop);
  2040. cmd->rate_table.num_rates =
  2041. cpu_to_le32(rate_table->num_rates);
  2042. for (count = 0; count < rate_table->num_rates; count++) {
  2043. struct mwl8k_rate_entry *dst =
  2044. &cmd->rate_table.rate_entry[count];
  2045. struct mwl8k_rate_entry *src =
  2046. &rate_table->rate_entry[count];
  2047. dst->is_ht_rate = cpu_to_le32(src->is_ht_rate);
  2048. dst->enable_retry = cpu_to_le32(src->enable_retry);
  2049. dst->rate = cpu_to_le32(src->rate);
  2050. dst->retry_count = cpu_to_le32(src->retry_count);
  2051. }
  2052. }
  2053. rc = mwl8k_post_cmd(hw, &cmd->header);
  2054. kfree(cmd);
  2055. return rc;
  2056. }
  2057. /*
  2058. * Interrupt handling.
  2059. */
  2060. static irqreturn_t mwl8k_interrupt(int irq, void *dev_id)
  2061. {
  2062. struct ieee80211_hw *hw = dev_id;
  2063. struct mwl8k_priv *priv = hw->priv;
  2064. u32 status;
  2065. status = ioread32(priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  2066. iowrite32(~status, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  2067. status &= priv->int_mask;
  2068. if (!status)
  2069. return IRQ_NONE;
  2070. if (status & MWL8K_A2H_INT_TX_DONE)
  2071. tasklet_schedule(&priv->tx_reclaim_task);
  2072. if (status & MWL8K_A2H_INT_RX_READY) {
  2073. while (rxq_process(hw, 0, 1))
  2074. rxq_refill(hw, 0, 1);
  2075. }
  2076. if (status & MWL8K_A2H_INT_OPC_DONE) {
  2077. if (priv->hostcmd_wait != NULL) {
  2078. complete(priv->hostcmd_wait);
  2079. priv->hostcmd_wait = NULL;
  2080. }
  2081. }
  2082. if (status & MWL8K_A2H_INT_QUEUE_EMPTY) {
  2083. if (!priv->inconfig &&
  2084. priv->radio_state &&
  2085. mwl8k_txq_busy(priv))
  2086. mwl8k_tx_start(priv);
  2087. }
  2088. return IRQ_HANDLED;
  2089. }
  2090. /*
  2091. * Core driver operations.
  2092. */
  2093. static int mwl8k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2094. {
  2095. struct mwl8k_priv *priv = hw->priv;
  2096. int index = skb_get_queue_mapping(skb);
  2097. int rc;
  2098. if (priv->current_channel == NULL) {
  2099. printk(KERN_DEBUG "%s: dropped TX frame since radio "
  2100. "disabled\n", priv->name);
  2101. dev_kfree_skb(skb);
  2102. return NETDEV_TX_OK;
  2103. }
  2104. rc = mwl8k_txq_xmit(hw, index, skb);
  2105. return rc;
  2106. }
  2107. struct mwl8k_work_struct {
  2108. /* Initialized by mwl8k_queue_work(). */
  2109. struct work_struct wt;
  2110. /* Required field passed in to mwl8k_queue_work(). */
  2111. struct ieee80211_hw *hw;
  2112. /* Required field passed in to mwl8k_queue_work(). */
  2113. int (*wfunc)(struct work_struct *w);
  2114. /* Initialized by mwl8k_queue_work(). */
  2115. struct completion *cmd_wait;
  2116. /* Result code. */
  2117. int rc;
  2118. /*
  2119. * Optional field. Refer to explanation of MWL8K_WQ_XXX_XXX
  2120. * flags for explanation. Defaults to MWL8K_WQ_DEFAULT_OPTIONS.
  2121. */
  2122. u32 options;
  2123. /* Optional field. Defaults to MWL8K_CONFIG_TIMEOUT_MS. */
  2124. unsigned long timeout_ms;
  2125. /* Optional field. Defaults to MWL8K_WQ_TXWAIT_ATTEMPTS. */
  2126. u32 txwait_attempts;
  2127. /* Optional field. Defaults to MWL8K_TXWAIT_MS. */
  2128. u32 tx_timeout_ms;
  2129. u32 step;
  2130. };
  2131. /* Flags controlling behavior of config queue requests */
  2132. /* Caller spins while waiting for completion. */
  2133. #define MWL8K_WQ_SPIN 0x00000001
  2134. /* Wait for TX queues to empty before proceeding with configuration. */
  2135. #define MWL8K_WQ_TX_WAIT_EMPTY 0x00000002
  2136. /* Queue request and return immediately. */
  2137. #define MWL8K_WQ_POST_REQUEST 0x00000004
  2138. /*
  2139. * Caller sleeps and waits for task complete notification.
  2140. * Do not use in atomic context.
  2141. */
  2142. #define MWL8K_WQ_SLEEP 0x00000008
  2143. /* Free work struct when task is done. */
  2144. #define MWL8K_WQ_FREE_WORKSTRUCT 0x00000010
  2145. /*
  2146. * Config request is queued and returns to caller imediately. Use
  2147. * this in atomic context. Work struct is freed by mwl8k_queue_work()
  2148. * when this flag is set.
  2149. */
  2150. #define MWL8K_WQ_QUEUE_ONLY (MWL8K_WQ_POST_REQUEST | \
  2151. MWL8K_WQ_FREE_WORKSTRUCT)
  2152. /* Default work queue behavior is to sleep and wait for tx completion. */
  2153. #define MWL8K_WQ_DEFAULT_OPTIONS (MWL8K_WQ_SLEEP | MWL8K_WQ_TX_WAIT_EMPTY)
  2154. /*
  2155. * Default config request timeout. Add adjustments to make sure the
  2156. * config thread waits long enough for both tx wait and cmd wait before
  2157. * timing out.
  2158. */
  2159. /* Time to wait for all TXQs to drain. TX Doorbell is pressed each time. */
  2160. #define MWL8K_TXWAIT_TIMEOUT_MS 1000
  2161. /* Default number of TX wait attempts. */
  2162. #define MWL8K_WQ_TXWAIT_ATTEMPTS 4
  2163. /* Total time to wait for TXQ to drain. */
  2164. #define MWL8K_TXWAIT_MS (MWL8K_TXWAIT_TIMEOUT_MS * \
  2165. MWL8K_WQ_TXWAIT_ATTEMPTS)
  2166. /* Scheduling slop. */
  2167. #define MWL8K_OS_SCHEDULE_OVERHEAD_MS 200
  2168. #define MWL8K_CONFIG_TIMEOUT_MS (MWL8K_CMD_TIMEOUT_MS + \
  2169. MWL8K_TXWAIT_MS + \
  2170. MWL8K_OS_SCHEDULE_OVERHEAD_MS)
  2171. static void mwl8k_config_thread(struct work_struct *wt)
  2172. {
  2173. struct mwl8k_work_struct *worker = (struct mwl8k_work_struct *)wt;
  2174. struct ieee80211_hw *hw = worker->hw;
  2175. struct mwl8k_priv *priv = hw->priv;
  2176. int rc = 0;
  2177. spin_lock_irq(&priv->tx_lock);
  2178. priv->inconfig = true;
  2179. spin_unlock_irq(&priv->tx_lock);
  2180. ieee80211_stop_queues(hw);
  2181. /*
  2182. * Wait for host queues to drain before doing PHY
  2183. * reconfiguration. This avoids interrupting any in-flight
  2184. * DMA transfers to the hardware.
  2185. */
  2186. if (worker->options & MWL8K_WQ_TX_WAIT_EMPTY) {
  2187. u32 timeout;
  2188. u32 time_remaining;
  2189. u32 iter;
  2190. u32 tx_wait_attempts = worker->txwait_attempts;
  2191. time_remaining = worker->tx_timeout_ms;
  2192. if (!tx_wait_attempts)
  2193. tx_wait_attempts = 1;
  2194. timeout = worker->tx_timeout_ms/tx_wait_attempts;
  2195. if (!timeout)
  2196. timeout = 1;
  2197. iter = tx_wait_attempts;
  2198. do {
  2199. int wait_time;
  2200. if (time_remaining > timeout) {
  2201. time_remaining -= timeout;
  2202. wait_time = timeout;
  2203. } else
  2204. wait_time = time_remaining;
  2205. if (!wait_time)
  2206. wait_time = 1;
  2207. rc = mwl8k_tx_wait_empty(hw, wait_time);
  2208. if (rc)
  2209. printk(KERN_ERR "%s() txwait timeout=%ums "
  2210. "Retry:%u/%u\n", __func__, timeout,
  2211. tx_wait_attempts - iter + 1,
  2212. tx_wait_attempts);
  2213. } while (rc && --iter);
  2214. rc = iter ? 0 : -ETIMEDOUT;
  2215. }
  2216. if (!rc)
  2217. rc = worker->wfunc(wt);
  2218. spin_lock_irq(&priv->tx_lock);
  2219. priv->inconfig = false;
  2220. if (priv->pending_tx_pkts && priv->radio_state)
  2221. mwl8k_tx_start(priv);
  2222. spin_unlock_irq(&priv->tx_lock);
  2223. ieee80211_wake_queues(hw);
  2224. worker->rc = rc;
  2225. if (worker->options & MWL8K_WQ_SLEEP)
  2226. complete(worker->cmd_wait);
  2227. if (worker->options & MWL8K_WQ_FREE_WORKSTRUCT)
  2228. kfree(wt);
  2229. }
  2230. static int mwl8k_queue_work(struct ieee80211_hw *hw,
  2231. struct mwl8k_work_struct *worker,
  2232. struct workqueue_struct *wqueue,
  2233. int (*wfunc)(struct work_struct *w))
  2234. {
  2235. unsigned long timeout = 0;
  2236. int rc = 0;
  2237. DECLARE_COMPLETION_ONSTACK(cmd_wait);
  2238. if (!worker->timeout_ms)
  2239. worker->timeout_ms = MWL8K_CONFIG_TIMEOUT_MS;
  2240. if (!worker->options)
  2241. worker->options = MWL8K_WQ_DEFAULT_OPTIONS;
  2242. if (!worker->txwait_attempts)
  2243. worker->txwait_attempts = MWL8K_WQ_TXWAIT_ATTEMPTS;
  2244. if (!worker->tx_timeout_ms)
  2245. worker->tx_timeout_ms = MWL8K_TXWAIT_MS;
  2246. worker->hw = hw;
  2247. worker->cmd_wait = &cmd_wait;
  2248. worker->rc = 1;
  2249. worker->wfunc = wfunc;
  2250. INIT_WORK(&worker->wt, mwl8k_config_thread);
  2251. queue_work(wqueue, &worker->wt);
  2252. if (worker->options & MWL8K_WQ_POST_REQUEST) {
  2253. rc = 0;
  2254. } else {
  2255. if (worker->options & MWL8K_WQ_SPIN) {
  2256. timeout = worker->timeout_ms;
  2257. while (timeout && (worker->rc > 0)) {
  2258. mdelay(1);
  2259. timeout--;
  2260. }
  2261. } else if (worker->options & MWL8K_WQ_SLEEP)
  2262. timeout = wait_for_completion_timeout(&cmd_wait,
  2263. msecs_to_jiffies(worker->timeout_ms));
  2264. if (timeout)
  2265. rc = worker->rc;
  2266. else {
  2267. cancel_work_sync(&worker->wt);
  2268. rc = -ETIMEDOUT;
  2269. }
  2270. }
  2271. return rc;
  2272. }
  2273. struct mwl8k_start_worker {
  2274. struct mwl8k_work_struct header;
  2275. };
  2276. static int mwl8k_start_wt(struct work_struct *wt)
  2277. {
  2278. struct mwl8k_start_worker *worker = (struct mwl8k_start_worker *)wt;
  2279. struct ieee80211_hw *hw = worker->header.hw;
  2280. struct mwl8k_priv *priv = hw->priv;
  2281. int rc = 0;
  2282. if (priv->vif != NULL) {
  2283. rc = -EIO;
  2284. goto mwl8k_start_exit;
  2285. }
  2286. /* Turn on radio */
  2287. if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
  2288. rc = -EIO;
  2289. goto mwl8k_start_exit;
  2290. }
  2291. /* Purge TX/RX HW queues */
  2292. if (mwl8k_cmd_set_pre_scan(hw)) {
  2293. rc = -EIO;
  2294. goto mwl8k_start_exit;
  2295. }
  2296. if (mwl8k_cmd_set_post_scan(hw, "\x00\x00\x00\x00\x00\x00")) {
  2297. rc = -EIO;
  2298. goto mwl8k_start_exit;
  2299. }
  2300. /* Enable firmware rate adaptation */
  2301. if (mwl8k_cmd_setrateadaptmode(hw, 0)) {
  2302. rc = -EIO;
  2303. goto mwl8k_start_exit;
  2304. }
  2305. /* Disable WMM. WMM gets enabled when stack sends WMM parms */
  2306. if (mwl8k_set_wmm(hw, MWL8K_WMM_DISABLE)) {
  2307. rc = -EIO;
  2308. goto mwl8k_start_exit;
  2309. }
  2310. /* Disable sniffer mode */
  2311. if (mwl8k_enable_sniffer(hw, 0))
  2312. rc = -EIO;
  2313. mwl8k_start_exit:
  2314. return rc;
  2315. }
  2316. static int mwl8k_start(struct ieee80211_hw *hw)
  2317. {
  2318. struct mwl8k_start_worker *worker;
  2319. struct mwl8k_priv *priv = hw->priv;
  2320. int rc;
  2321. /* Enable tx reclaim tasklet */
  2322. tasklet_enable(&priv->tx_reclaim_task);
  2323. rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
  2324. IRQF_SHARED, MWL8K_NAME, hw);
  2325. if (rc) {
  2326. printk(KERN_ERR "%s: failed to register IRQ handler\n",
  2327. priv->name);
  2328. rc = -EIO;
  2329. goto mwl8k_start_disable_tasklet;
  2330. }
  2331. /* Enable interrupts */
  2332. iowrite32(priv->int_mask, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2333. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2334. if (worker == NULL) {
  2335. rc = -ENOMEM;
  2336. goto mwl8k_start_disable_irq;
  2337. }
  2338. rc = mwl8k_queue_work(hw, &worker->header,
  2339. priv->config_wq, mwl8k_start_wt);
  2340. kfree(worker);
  2341. if (!rc)
  2342. return rc;
  2343. if (rc == -ETIMEDOUT)
  2344. printk(KERN_ERR "%s() timed out\n", __func__);
  2345. rc = -EIO;
  2346. mwl8k_start_disable_irq:
  2347. spin_lock_irq(&priv->tx_lock);
  2348. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2349. spin_unlock_irq(&priv->tx_lock);
  2350. free_irq(priv->pdev->irq, hw);
  2351. mwl8k_start_disable_tasklet:
  2352. tasklet_disable(&priv->tx_reclaim_task);
  2353. return rc;
  2354. }
  2355. struct mwl8k_stop_worker {
  2356. struct mwl8k_work_struct header;
  2357. };
  2358. static int mwl8k_stop_wt(struct work_struct *wt)
  2359. {
  2360. struct mwl8k_stop_worker *worker = (struct mwl8k_stop_worker *)wt;
  2361. struct ieee80211_hw *hw = worker->header.hw;
  2362. int rc;
  2363. rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
  2364. return rc;
  2365. }
  2366. static void mwl8k_stop(struct ieee80211_hw *hw)
  2367. {
  2368. int rc;
  2369. struct mwl8k_stop_worker *worker;
  2370. struct mwl8k_priv *priv = hw->priv;
  2371. int i;
  2372. if (priv->vif != NULL)
  2373. return;
  2374. ieee80211_stop_queues(hw);
  2375. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2376. if (worker == NULL)
  2377. return;
  2378. rc = mwl8k_queue_work(hw, &worker->header,
  2379. priv->config_wq, mwl8k_stop_wt);
  2380. kfree(worker);
  2381. if (rc == -ETIMEDOUT)
  2382. printk(KERN_ERR "%s() timed out\n", __func__);
  2383. /* Disable interrupts */
  2384. spin_lock_irq(&priv->tx_lock);
  2385. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2386. spin_unlock_irq(&priv->tx_lock);
  2387. free_irq(priv->pdev->irq, hw);
  2388. /* Stop finalize join worker */
  2389. cancel_work_sync(&priv->finalize_join_worker);
  2390. if (priv->beacon_skb != NULL)
  2391. dev_kfree_skb(priv->beacon_skb);
  2392. /* Stop tx reclaim tasklet */
  2393. tasklet_disable(&priv->tx_reclaim_task);
  2394. /* Stop config thread */
  2395. flush_workqueue(priv->config_wq);
  2396. /* Return all skbs to mac80211 */
  2397. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  2398. mwl8k_txq_reclaim(hw, i, 1);
  2399. }
  2400. static int mwl8k_add_interface(struct ieee80211_hw *hw,
  2401. struct ieee80211_if_init_conf *conf)
  2402. {
  2403. struct mwl8k_priv *priv = hw->priv;
  2404. struct mwl8k_vif *mwl8k_vif;
  2405. /*
  2406. * We only support one active interface at a time.
  2407. */
  2408. if (priv->vif != NULL)
  2409. return -EBUSY;
  2410. /*
  2411. * We only support managed interfaces for now.
  2412. */
  2413. if (conf->type != NL80211_IFTYPE_STATION &&
  2414. conf->type != NL80211_IFTYPE_MONITOR)
  2415. return -EINVAL;
  2416. /* Clean out driver private area */
  2417. mwl8k_vif = MWL8K_VIF(conf->vif);
  2418. memset(mwl8k_vif, 0, sizeof(*mwl8k_vif));
  2419. /* Save the mac address */
  2420. memcpy(mwl8k_vif->mac_addr, conf->mac_addr, IEEE80211_ADDR_LEN);
  2421. /* Back pointer to parent config block */
  2422. mwl8k_vif->priv = priv;
  2423. /* Setup initial PHY parameters */
  2424. memcpy(mwl8k_vif->legacy_rates ,
  2425. priv->rates, sizeof(mwl8k_vif->legacy_rates));
  2426. mwl8k_vif->legacy_nrates = ARRAY_SIZE(priv->rates);
  2427. /* Set Initial sequence number to zero */
  2428. mwl8k_vif->seqno = 0;
  2429. priv->vif = conf->vif;
  2430. priv->current_channel = NULL;
  2431. return 0;
  2432. }
  2433. static void mwl8k_remove_interface(struct ieee80211_hw *hw,
  2434. struct ieee80211_if_init_conf *conf)
  2435. {
  2436. struct mwl8k_priv *priv = hw->priv;
  2437. if (priv->vif == NULL)
  2438. return;
  2439. priv->vif = NULL;
  2440. }
  2441. struct mwl8k_config_worker {
  2442. struct mwl8k_work_struct header;
  2443. u32 changed;
  2444. };
  2445. static int mwl8k_config_wt(struct work_struct *wt)
  2446. {
  2447. struct mwl8k_config_worker *worker =
  2448. (struct mwl8k_config_worker *)wt;
  2449. struct ieee80211_hw *hw = worker->header.hw;
  2450. struct ieee80211_conf *conf = &hw->conf;
  2451. struct mwl8k_priv *priv = hw->priv;
  2452. int rc = 0;
  2453. if (!conf->radio_enabled) {
  2454. mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
  2455. priv->current_channel = NULL;
  2456. rc = 0;
  2457. goto mwl8k_config_exit;
  2458. }
  2459. if (mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_ENABLE)) {
  2460. rc = -EINVAL;
  2461. goto mwl8k_config_exit;
  2462. }
  2463. priv->current_channel = conf->channel;
  2464. if (mwl8k_cmd_set_rf_channel(hw, conf->channel)) {
  2465. rc = -EINVAL;
  2466. goto mwl8k_config_exit;
  2467. }
  2468. if (conf->power_level > 18)
  2469. conf->power_level = 18;
  2470. if (mwl8k_cmd_802_11_rf_tx_power(hw, conf->power_level)) {
  2471. rc = -EINVAL;
  2472. goto mwl8k_config_exit;
  2473. }
  2474. if (mwl8k_cmd_mimo_config(hw, 0x7, 0x7))
  2475. rc = -EINVAL;
  2476. mwl8k_config_exit:
  2477. return rc;
  2478. }
  2479. static int mwl8k_config(struct ieee80211_hw *hw, u32 changed)
  2480. {
  2481. int rc = 0;
  2482. struct mwl8k_config_worker *worker;
  2483. struct mwl8k_priv *priv = hw->priv;
  2484. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2485. if (worker == NULL)
  2486. return -ENOMEM;
  2487. worker->changed = changed;
  2488. rc = mwl8k_queue_work(hw, &worker->header,
  2489. priv->config_wq, mwl8k_config_wt);
  2490. if (rc == -ETIMEDOUT) {
  2491. printk(KERN_ERR "%s() timed out.\n", __func__);
  2492. rc = -EINVAL;
  2493. }
  2494. kfree(worker);
  2495. /*
  2496. * mac80211 will crash on anything other than -EINVAL on
  2497. * error. Looks like wireless extensions which calls mac80211
  2498. * may be the actual culprit...
  2499. */
  2500. return rc ? -EINVAL : 0;
  2501. }
  2502. static int mwl8k_config_interface(struct ieee80211_hw *hw,
  2503. struct ieee80211_vif *vif,
  2504. struct ieee80211_if_conf *conf)
  2505. {
  2506. struct mwl8k_vif *mv_vif = MWL8K_VIF(vif);
  2507. u32 changed = conf->changed;
  2508. if (changed & IEEE80211_IFCC_BSSID)
  2509. memcpy(mv_vif->bssid, conf->bssid, IEEE80211_ADDR_LEN);
  2510. return 0;
  2511. }
  2512. struct mwl8k_bss_info_changed_worker {
  2513. struct mwl8k_work_struct header;
  2514. struct ieee80211_vif *vif;
  2515. struct ieee80211_bss_conf *info;
  2516. u32 changed;
  2517. };
  2518. static int mwl8k_bss_info_changed_wt(struct work_struct *wt)
  2519. {
  2520. struct mwl8k_bss_info_changed_worker *worker =
  2521. (struct mwl8k_bss_info_changed_worker *)wt;
  2522. struct ieee80211_hw *hw = worker->header.hw;
  2523. struct ieee80211_vif *vif = worker->vif;
  2524. struct ieee80211_bss_conf *info = worker->info;
  2525. u32 changed;
  2526. int rc;
  2527. struct mwl8k_priv *priv = hw->priv;
  2528. struct mwl8k_vif *mwl8k_vif = MWL8K_VIF(vif);
  2529. changed = worker->changed;
  2530. priv->capture_beacon = false;
  2531. if (info->assoc) {
  2532. memcpy(&mwl8k_vif->bss_info, info,
  2533. sizeof(struct ieee80211_bss_conf));
  2534. /* Install rates */
  2535. if (mwl8k_update_rateset(hw, vif))
  2536. goto mwl8k_bss_info_changed_exit;
  2537. /* Turn on rate adaptation */
  2538. if (mwl8k_cmd_use_fixed_rate(hw, MWL8K_USE_AUTO_RATE,
  2539. MWL8K_UCAST_RATE, NULL))
  2540. goto mwl8k_bss_info_changed_exit;
  2541. /* Set radio preamble */
  2542. if (mwl8k_set_radio_preamble(hw,
  2543. info->use_short_preamble))
  2544. goto mwl8k_bss_info_changed_exit;
  2545. /* Set slot time */
  2546. if (mwl8k_cmd_set_slot(hw, info->use_short_slot ?
  2547. MWL8K_SHORT_SLOTTIME : MWL8K_LONG_SLOTTIME))
  2548. goto mwl8k_bss_info_changed_exit;
  2549. /* Update peer rate info */
  2550. if (mwl8k_cmd_update_sta_db(hw, vif,
  2551. MWL8K_STA_DB_MODIFY_ENTRY))
  2552. goto mwl8k_bss_info_changed_exit;
  2553. /* Set AID */
  2554. if (mwl8k_cmd_set_aid(hw, vif))
  2555. goto mwl8k_bss_info_changed_exit;
  2556. /*
  2557. * Finalize the join. Tell rx handler to process
  2558. * next beacon from our BSSID.
  2559. */
  2560. memcpy(priv->capture_bssid,
  2561. mwl8k_vif->bssid, IEEE80211_ADDR_LEN);
  2562. priv->capture_beacon = true;
  2563. } else {
  2564. mwl8k_cmd_update_sta_db(hw, vif, MWL8K_STA_DB_DEL_ENTRY);
  2565. memset(&mwl8k_vif->bss_info, 0,
  2566. sizeof(struct ieee80211_bss_conf));
  2567. memset(mwl8k_vif->bssid, 0, IEEE80211_ADDR_LEN);
  2568. }
  2569. mwl8k_bss_info_changed_exit:
  2570. rc = 0;
  2571. return rc;
  2572. }
  2573. static void mwl8k_bss_info_changed(struct ieee80211_hw *hw,
  2574. struct ieee80211_vif *vif,
  2575. struct ieee80211_bss_conf *info,
  2576. u32 changed)
  2577. {
  2578. struct mwl8k_bss_info_changed_worker *worker;
  2579. struct mwl8k_priv *priv = hw->priv;
  2580. int rc;
  2581. if ((changed & BSS_CHANGED_ASSOC) == 0)
  2582. return;
  2583. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2584. if (worker == NULL)
  2585. return;
  2586. worker->vif = vif;
  2587. worker->info = info;
  2588. worker->changed = changed;
  2589. rc = mwl8k_queue_work(hw, &worker->header,
  2590. priv->config_wq,
  2591. mwl8k_bss_info_changed_wt);
  2592. kfree(worker);
  2593. if (rc == -ETIMEDOUT)
  2594. printk(KERN_ERR "%s() timed out\n", __func__);
  2595. }
  2596. struct mwl8k_configure_filter_worker {
  2597. struct mwl8k_work_struct header;
  2598. unsigned int changed_flags;
  2599. unsigned int *total_flags;
  2600. int mc_count;
  2601. struct dev_addr_list *mclist;
  2602. };
  2603. #define MWL8K_SUPPORTED_IF_FLAGS FIF_BCN_PRBRESP_PROMISC
  2604. static int mwl8k_configure_filter_wt(struct work_struct *wt)
  2605. {
  2606. struct mwl8k_configure_filter_worker *worker =
  2607. (struct mwl8k_configure_filter_worker *)wt;
  2608. struct ieee80211_hw *hw = worker->header.hw;
  2609. unsigned int changed_flags = worker->changed_flags;
  2610. unsigned int *total_flags = worker->total_flags;
  2611. int mc_count = worker->mc_count;
  2612. struct dev_addr_list *mclist = worker->mclist;
  2613. struct mwl8k_priv *priv = hw->priv;
  2614. struct mwl8k_vif *mv_vif;
  2615. int rc = 0;
  2616. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  2617. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  2618. rc = mwl8k_cmd_set_pre_scan(hw);
  2619. else {
  2620. mv_vif = MWL8K_VIF(priv->vif);
  2621. rc = mwl8k_cmd_set_post_scan(hw, mv_vif->bssid);
  2622. }
  2623. }
  2624. if (rc)
  2625. goto mwl8k_configure_filter_exit;
  2626. if (mc_count) {
  2627. mc_count = mc_count < priv->num_mcaddrs ?
  2628. mc_count : priv->num_mcaddrs;
  2629. rc = mwl8k_cmd_mac_multicast_adr(hw, mc_count, mclist);
  2630. if (rc)
  2631. printk(KERN_ERR
  2632. "%s()Error setting multicast addresses\n",
  2633. __func__);
  2634. }
  2635. mwl8k_configure_filter_exit:
  2636. return rc;
  2637. }
  2638. static void mwl8k_configure_filter(struct ieee80211_hw *hw,
  2639. unsigned int changed_flags,
  2640. unsigned int *total_flags,
  2641. int mc_count,
  2642. struct dev_addr_list *mclist)
  2643. {
  2644. struct mwl8k_configure_filter_worker *worker;
  2645. struct mwl8k_priv *priv = hw->priv;
  2646. /* Clear unsupported feature flags */
  2647. *total_flags &= MWL8K_SUPPORTED_IF_FLAGS;
  2648. if (!(changed_flags & MWL8K_SUPPORTED_IF_FLAGS) && !mc_count)
  2649. return;
  2650. worker = kzalloc(sizeof(*worker), GFP_ATOMIC);
  2651. if (worker == NULL)
  2652. return;
  2653. worker->header.options = MWL8K_WQ_QUEUE_ONLY | MWL8K_WQ_TX_WAIT_EMPTY;
  2654. worker->changed_flags = changed_flags;
  2655. worker->total_flags = total_flags;
  2656. worker->mc_count = mc_count;
  2657. worker->mclist = mclist;
  2658. mwl8k_queue_work(hw, &worker->header, priv->config_wq,
  2659. mwl8k_configure_filter_wt);
  2660. }
  2661. struct mwl8k_set_rts_threshold_worker {
  2662. struct mwl8k_work_struct header;
  2663. u32 value;
  2664. };
  2665. static int mwl8k_set_rts_threshold_wt(struct work_struct *wt)
  2666. {
  2667. struct mwl8k_set_rts_threshold_worker *worker =
  2668. (struct mwl8k_set_rts_threshold_worker *)wt;
  2669. struct ieee80211_hw *hw = worker->header.hw;
  2670. u16 threshold = (u16)(worker->value);
  2671. int rc;
  2672. rc = mwl8k_rts_threshold(hw, MWL8K_CMD_SET, &threshold);
  2673. return rc;
  2674. }
  2675. static int mwl8k_set_rts_threshold(struct ieee80211_hw *hw, u32 value)
  2676. {
  2677. int rc;
  2678. struct mwl8k_set_rts_threshold_worker *worker;
  2679. struct mwl8k_priv *priv = hw->priv;
  2680. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2681. if (worker == NULL)
  2682. return -ENOMEM;
  2683. worker->value = value;
  2684. rc = mwl8k_queue_work(hw, &worker->header,
  2685. priv->config_wq,
  2686. mwl8k_set_rts_threshold_wt);
  2687. kfree(worker);
  2688. if (rc == -ETIMEDOUT) {
  2689. printk(KERN_ERR "%s() timed out\n", __func__);
  2690. rc = -EINVAL;
  2691. }
  2692. return rc;
  2693. }
  2694. struct mwl8k_conf_tx_worker {
  2695. struct mwl8k_work_struct header;
  2696. u16 queue;
  2697. const struct ieee80211_tx_queue_params *params;
  2698. };
  2699. static int mwl8k_conf_tx_wt(struct work_struct *wt)
  2700. {
  2701. struct mwl8k_conf_tx_worker *worker =
  2702. (struct mwl8k_conf_tx_worker *)wt;
  2703. struct ieee80211_hw *hw = worker->header.hw;
  2704. u16 queue = worker->queue;
  2705. const struct ieee80211_tx_queue_params *params = worker->params;
  2706. struct mwl8k_priv *priv = hw->priv;
  2707. int rc = 0;
  2708. if (priv->wmm_mode == MWL8K_WMM_DISABLE)
  2709. if (mwl8k_set_wmm(hw, MWL8K_WMM_ENABLE)) {
  2710. rc = -EINVAL;
  2711. goto mwl8k_conf_tx_exit;
  2712. }
  2713. if (mwl8k_set_edca_params(hw, GET_TXQ(queue), params->cw_min,
  2714. params->cw_max, params->aifs, params->txop))
  2715. rc = -EINVAL;
  2716. mwl8k_conf_tx_exit:
  2717. return rc;
  2718. }
  2719. static int mwl8k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  2720. const struct ieee80211_tx_queue_params *params)
  2721. {
  2722. int rc;
  2723. struct mwl8k_conf_tx_worker *worker;
  2724. struct mwl8k_priv *priv = hw->priv;
  2725. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2726. if (worker == NULL)
  2727. return -ENOMEM;
  2728. worker->queue = queue;
  2729. worker->params = params;
  2730. rc = mwl8k_queue_work(hw, &worker->header,
  2731. priv->config_wq, mwl8k_conf_tx_wt);
  2732. kfree(worker);
  2733. if (rc == -ETIMEDOUT) {
  2734. printk(KERN_ERR "%s() timed out\n", __func__);
  2735. rc = -EINVAL;
  2736. }
  2737. return rc;
  2738. }
  2739. static int mwl8k_get_tx_stats(struct ieee80211_hw *hw,
  2740. struct ieee80211_tx_queue_stats *stats)
  2741. {
  2742. struct mwl8k_priv *priv = hw->priv;
  2743. struct mwl8k_tx_queue *txq;
  2744. int index;
  2745. spin_lock_bh(&priv->tx_lock);
  2746. for (index = 0; index < MWL8K_TX_QUEUES; index++) {
  2747. txq = priv->txq + index;
  2748. memcpy(&stats[index], &txq->tx_stats,
  2749. sizeof(struct ieee80211_tx_queue_stats));
  2750. }
  2751. spin_unlock_bh(&priv->tx_lock);
  2752. return 0;
  2753. }
  2754. struct mwl8k_get_stats_worker {
  2755. struct mwl8k_work_struct header;
  2756. struct ieee80211_low_level_stats *stats;
  2757. };
  2758. static int mwl8k_get_stats_wt(struct work_struct *wt)
  2759. {
  2760. struct mwl8k_get_stats_worker *worker =
  2761. (struct mwl8k_get_stats_worker *)wt;
  2762. return mwl8k_cmd_802_11_get_stat(worker->header.hw, worker->stats);
  2763. }
  2764. static int mwl8k_get_stats(struct ieee80211_hw *hw,
  2765. struct ieee80211_low_level_stats *stats)
  2766. {
  2767. int rc;
  2768. struct mwl8k_get_stats_worker *worker;
  2769. struct mwl8k_priv *priv = hw->priv;
  2770. worker = kzalloc(sizeof(*worker), GFP_KERNEL);
  2771. if (worker == NULL)
  2772. return -ENOMEM;
  2773. worker->stats = stats;
  2774. rc = mwl8k_queue_work(hw, &worker->header,
  2775. priv->config_wq, mwl8k_get_stats_wt);
  2776. kfree(worker);
  2777. if (rc == -ETIMEDOUT) {
  2778. printk(KERN_ERR "%s() timed out\n", __func__);
  2779. rc = -EINVAL;
  2780. }
  2781. return rc;
  2782. }
  2783. static const struct ieee80211_ops mwl8k_ops = {
  2784. .tx = mwl8k_tx,
  2785. .start = mwl8k_start,
  2786. .stop = mwl8k_stop,
  2787. .add_interface = mwl8k_add_interface,
  2788. .remove_interface = mwl8k_remove_interface,
  2789. .config = mwl8k_config,
  2790. .config_interface = mwl8k_config_interface,
  2791. .bss_info_changed = mwl8k_bss_info_changed,
  2792. .configure_filter = mwl8k_configure_filter,
  2793. .set_rts_threshold = mwl8k_set_rts_threshold,
  2794. .conf_tx = mwl8k_conf_tx,
  2795. .get_tx_stats = mwl8k_get_tx_stats,
  2796. .get_stats = mwl8k_get_stats,
  2797. };
  2798. static void mwl8k_tx_reclaim_handler(unsigned long data)
  2799. {
  2800. int i;
  2801. struct ieee80211_hw *hw = (struct ieee80211_hw *) data;
  2802. struct mwl8k_priv *priv = hw->priv;
  2803. spin_lock_bh(&priv->tx_lock);
  2804. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  2805. mwl8k_txq_reclaim(hw, i, 0);
  2806. if (priv->tx_wait != NULL) {
  2807. int count = mwl8k_txq_busy(priv);
  2808. if (count == 0) {
  2809. complete(priv->tx_wait);
  2810. priv->tx_wait = NULL;
  2811. }
  2812. }
  2813. spin_unlock_bh(&priv->tx_lock);
  2814. }
  2815. static void mwl8k_finalize_join_worker(struct work_struct *work)
  2816. {
  2817. struct mwl8k_priv *priv =
  2818. container_of(work, struct mwl8k_priv, finalize_join_worker);
  2819. struct sk_buff *skb = priv->beacon_skb;
  2820. u8 dtim = (MWL8K_VIF(priv->vif))->bss_info.dtim_period;
  2821. mwl8k_finalize_join(priv->hw, skb->data, skb->len, dtim);
  2822. dev_kfree_skb(skb);
  2823. priv->beacon_skb = NULL;
  2824. }
  2825. static int __devinit mwl8k_probe(struct pci_dev *pdev,
  2826. const struct pci_device_id *id)
  2827. {
  2828. struct ieee80211_hw *hw;
  2829. struct mwl8k_priv *priv;
  2830. DECLARE_MAC_BUF(mac);
  2831. int rc;
  2832. int i;
  2833. u8 *fw;
  2834. rc = pci_enable_device(pdev);
  2835. if (rc) {
  2836. printk(KERN_ERR "%s: Cannot enable new PCI device\n",
  2837. MWL8K_NAME);
  2838. return rc;
  2839. }
  2840. rc = pci_request_regions(pdev, MWL8K_NAME);
  2841. if (rc) {
  2842. printk(KERN_ERR "%s: Cannot obtain PCI resources\n",
  2843. MWL8K_NAME);
  2844. return rc;
  2845. }
  2846. pci_set_master(pdev);
  2847. hw = ieee80211_alloc_hw(sizeof(*priv), &mwl8k_ops);
  2848. if (hw == NULL) {
  2849. printk(KERN_ERR "%s: ieee80211 alloc failed\n", MWL8K_NAME);
  2850. rc = -ENOMEM;
  2851. goto err_free_reg;
  2852. }
  2853. priv = hw->priv;
  2854. priv->hw = hw;
  2855. priv->pdev = pdev;
  2856. priv->hostcmd_wait = NULL;
  2857. priv->tx_wait = NULL;
  2858. priv->inconfig = false;
  2859. priv->wep_enabled = 0;
  2860. priv->wmm_mode = false;
  2861. priv->pending_tx_pkts = 0;
  2862. strncpy(priv->name, MWL8K_NAME, sizeof(priv->name));
  2863. spin_lock_init(&priv->fw_lock);
  2864. SET_IEEE80211_DEV(hw, &pdev->dev);
  2865. pci_set_drvdata(pdev, hw);
  2866. priv->regs = pci_iomap(pdev, 1, 0x10000);
  2867. if (priv->regs == NULL) {
  2868. printk(KERN_ERR "%s: Cannot map device memory\n", priv->name);
  2869. goto err_iounmap;
  2870. }
  2871. memcpy(priv->channels, mwl8k_channels, sizeof(mwl8k_channels));
  2872. priv->band.band = IEEE80211_BAND_2GHZ;
  2873. priv->band.channels = priv->channels;
  2874. priv->band.n_channels = ARRAY_SIZE(mwl8k_channels);
  2875. priv->band.bitrates = priv->rates;
  2876. priv->band.n_bitrates = ARRAY_SIZE(mwl8k_rates);
  2877. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = &priv->band;
  2878. BUILD_BUG_ON(sizeof(priv->rates) != sizeof(mwl8k_rates));
  2879. memcpy(priv->rates, mwl8k_rates, sizeof(mwl8k_rates));
  2880. /*
  2881. * Extra headroom is the size of the required DMA header
  2882. * minus the size of the smallest 802.11 frame (CTS frame).
  2883. */
  2884. hw->extra_tx_headroom =
  2885. sizeof(struct mwl8k_dma_data) - sizeof(struct ieee80211_cts);
  2886. hw->channel_change_time = 10;
  2887. hw->queues = MWL8K_TX_QUEUES;
  2888. hw->wiphy->interface_modes =
  2889. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_MONITOR);
  2890. /* Set rssi and noise values to dBm */
  2891. hw->flags |= (IEEE80211_HW_SIGNAL_DBM | IEEE80211_HW_NOISE_DBM);
  2892. hw->vif_data_size = sizeof(struct mwl8k_vif);
  2893. priv->vif = NULL;
  2894. /* Set default radio state and preamble */
  2895. priv->radio_preamble = MWL8K_RADIO_DEFAULT_PREAMBLE;
  2896. priv->radio_state = MWL8K_RADIO_DISABLE;
  2897. /* Finalize join worker */
  2898. INIT_WORK(&priv->finalize_join_worker, mwl8k_finalize_join_worker);
  2899. /* TX reclaim tasklet */
  2900. tasklet_init(&priv->tx_reclaim_task,
  2901. mwl8k_tx_reclaim_handler, (unsigned long)hw);
  2902. tasklet_disable(&priv->tx_reclaim_task);
  2903. /* Config workthread */
  2904. priv->config_wq = create_singlethread_workqueue("mwl8k_config");
  2905. if (priv->config_wq == NULL)
  2906. goto err_iounmap;
  2907. /* Power management cookie */
  2908. priv->cookie = pci_alloc_consistent(priv->pdev, 4, &priv->cookie_dma);
  2909. if (priv->cookie == NULL)
  2910. goto err_iounmap;
  2911. rc = mwl8k_rxq_init(hw, 0);
  2912. if (rc)
  2913. goto err_iounmap;
  2914. rxq_refill(hw, 0, INT_MAX);
  2915. spin_lock_init(&priv->tx_lock);
  2916. for (i = 0; i < MWL8K_TX_QUEUES; i++) {
  2917. rc = mwl8k_txq_init(hw, i);
  2918. if (rc)
  2919. goto err_free_queues;
  2920. }
  2921. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS);
  2922. priv->int_mask = 0;
  2923. iowrite32(priv->int_mask, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2924. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_CLEAR_SEL);
  2925. iowrite32(0xffffffff, priv->regs + MWL8K_HIU_A2H_INTERRUPT_STATUS_MASK);
  2926. rc = request_irq(priv->pdev->irq, &mwl8k_interrupt,
  2927. IRQF_SHARED, MWL8K_NAME, hw);
  2928. if (rc) {
  2929. printk(KERN_ERR "%s: failed to register IRQ handler\n",
  2930. priv->name);
  2931. goto err_free_queues;
  2932. }
  2933. /* Reset firmware and hardware */
  2934. mwl8k_hw_reset(priv);
  2935. /* Ask userland hotplug daemon for the device firmware */
  2936. rc = mwl8k_request_firmware(priv, (u32)id->driver_data);
  2937. if (rc) {
  2938. printk(KERN_ERR "%s: Firmware files not found\n", priv->name);
  2939. goto err_free_irq;
  2940. }
  2941. /* Load firmware into hardware */
  2942. rc = mwl8k_load_firmware(priv);
  2943. if (rc) {
  2944. printk(KERN_ERR "%s: Cannot start firmware\n", priv->name);
  2945. goto err_stop_firmware;
  2946. }
  2947. /* Reclaim memory once firmware is successfully loaded */
  2948. mwl8k_release_firmware(priv);
  2949. /*
  2950. * Temporarily enable interrupts. Initial firmware host
  2951. * commands use interrupts and avoids polling. Disable
  2952. * interrupts when done.
  2953. */
  2954. priv->int_mask |= MWL8K_A2H_EVENTS;
  2955. iowrite32(priv->int_mask, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2956. /* Get config data, mac addrs etc */
  2957. rc = mwl8k_cmd_get_hw_spec(hw);
  2958. if (rc) {
  2959. printk(KERN_ERR "%s: Cannot initialise firmware\n", priv->name);
  2960. goto err_stop_firmware;
  2961. }
  2962. /* Turn radio off */
  2963. rc = mwl8k_cmd_802_11_radio_control(hw, MWL8K_RADIO_DISABLE);
  2964. if (rc) {
  2965. printk(KERN_ERR "%s: Cannot disable\n", priv->name);
  2966. goto err_stop_firmware;
  2967. }
  2968. /* Disable interrupts */
  2969. spin_lock_irq(&priv->tx_lock);
  2970. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2971. spin_unlock_irq(&priv->tx_lock);
  2972. free_irq(priv->pdev->irq, hw);
  2973. rc = ieee80211_register_hw(hw);
  2974. if (rc) {
  2975. printk(KERN_ERR "%s: Cannot register device\n", priv->name);
  2976. goto err_stop_firmware;
  2977. }
  2978. fw = (u8 *)&priv->fw_rev;
  2979. printk(KERN_INFO "%s: 88W%u %s\n", priv->name, priv->part_num,
  2980. MWL8K_DESC);
  2981. printk(KERN_INFO "%s: Driver Ver:%s Firmware Ver:%u.%u.%u.%u\n",
  2982. priv->name, MWL8K_VERSION, fw[3], fw[2], fw[1], fw[0]);
  2983. printk(KERN_INFO "%s: MAC Address: %s\n", priv->name,
  2984. print_mac(mac, hw->wiphy->perm_addr));
  2985. return 0;
  2986. err_stop_firmware:
  2987. mwl8k_hw_reset(priv);
  2988. mwl8k_release_firmware(priv);
  2989. err_free_irq:
  2990. spin_lock_irq(&priv->tx_lock);
  2991. iowrite32(0, priv->regs + MWL8K_HIU_A2H_INTERRUPT_MASK);
  2992. spin_unlock_irq(&priv->tx_lock);
  2993. free_irq(priv->pdev->irq, hw);
  2994. err_free_queues:
  2995. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  2996. mwl8k_txq_deinit(hw, i);
  2997. mwl8k_rxq_deinit(hw, 0);
  2998. err_iounmap:
  2999. if (priv->cookie != NULL)
  3000. pci_free_consistent(priv->pdev, 4,
  3001. priv->cookie, priv->cookie_dma);
  3002. if (priv->regs != NULL)
  3003. pci_iounmap(pdev, priv->regs);
  3004. if (priv->config_wq != NULL)
  3005. destroy_workqueue(priv->config_wq);
  3006. pci_set_drvdata(pdev, NULL);
  3007. ieee80211_free_hw(hw);
  3008. err_free_reg:
  3009. pci_release_regions(pdev);
  3010. pci_disable_device(pdev);
  3011. return rc;
  3012. }
  3013. static void __devexit mwl8k_remove(struct pci_dev *pdev)
  3014. {
  3015. printk(KERN_ERR "===>%s(%u)\n", __func__, __LINE__);
  3016. }
  3017. static void __devexit mwl8k_shutdown(struct pci_dev *pdev)
  3018. {
  3019. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  3020. struct mwl8k_priv *priv;
  3021. int i;
  3022. if (hw == NULL)
  3023. return;
  3024. priv = hw->priv;
  3025. ieee80211_stop_queues(hw);
  3026. /* Remove tx reclaim tasklet */
  3027. tasklet_kill(&priv->tx_reclaim_task);
  3028. /* Stop config thread */
  3029. destroy_workqueue(priv->config_wq);
  3030. /* Stop hardware */
  3031. mwl8k_hw_reset(priv);
  3032. /* Return all skbs to mac80211 */
  3033. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3034. mwl8k_txq_reclaim(hw, i, 1);
  3035. ieee80211_unregister_hw(hw);
  3036. for (i = 0; i < MWL8K_TX_QUEUES; i++)
  3037. mwl8k_txq_deinit(hw, i);
  3038. mwl8k_rxq_deinit(hw, 0);
  3039. pci_free_consistent(priv->pdev, 4,
  3040. priv->cookie, priv->cookie_dma);
  3041. pci_iounmap(pdev, priv->regs);
  3042. pci_set_drvdata(pdev, NULL);
  3043. ieee80211_free_hw(hw);
  3044. pci_release_regions(pdev);
  3045. pci_disable_device(pdev);
  3046. }
  3047. static struct pci_driver mwl8k_driver = {
  3048. .name = MWL8K_NAME,
  3049. .id_table = mwl8k_table,
  3050. .probe = mwl8k_probe,
  3051. .remove = __devexit_p(mwl8k_remove),
  3052. .shutdown = __devexit_p(mwl8k_shutdown),
  3053. };
  3054. static int __init mwl8k_init(void)
  3055. {
  3056. return pci_register_driver(&mwl8k_driver);
  3057. }
  3058. static void __exit mwl8k_exit(void)
  3059. {
  3060. pci_unregister_driver(&mwl8k_driver);
  3061. }
  3062. module_init(mwl8k_init);
  3063. module_exit(mwl8k_exit);