mwl8k.c 76 KB

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