mwl8k.c 85 KB

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