mwl8k.c 87 KB

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