mwl8k.c 83 KB

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