mwl8k.c 87 KB

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