mwl8k.c 88 KB

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