mwl8k.c 84 KB

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