mwl8k.c 84 KB

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