mwl8k.c 85 KB

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