mwl8k.c 85 KB

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