mwl8k.c 85 KB

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