mwl8k.c 85 KB

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