mwl8k.c 78 KB

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