mwl8k.c 86 KB

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