mwl8k.c 78 KB

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