mwl8k.c 82 KB

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