mwl8k.c 86 KB

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