mwl8k.c 83 KB

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