mwl8k.c 86 KB

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