base.c 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392
  1. /*-
  2. * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
  3. * Copyright (c) 2004-2005 Atheros Communications, Inc.
  4. * Copyright (c) 2006 Devicescape Software, Inc.
  5. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  6. * Copyright (c) 2007 Luis R. Rodriguez <mcgrof@winlab.rutgers.edu>
  7. *
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
  18. * redistribution must be conditioned upon including a substantially
  19. * similar Disclaimer requirement for further binary redistribution.
  20. * 3. Neither the names of the above-listed copyright holders nor the names
  21. * of any contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * Alternatively, this software may be distributed under the terms of the
  25. * GNU General Public License ("GPL") version 2 as published by the Free
  26. * Software Foundation.
  27. *
  28. * NO WARRANTY
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
  32. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  33. * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
  34. * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  37. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  39. * THE POSSIBILITY OF SUCH DAMAGES.
  40. *
  41. */
  42. #include <linux/module.h>
  43. #include <linux/delay.h>
  44. #include <linux/hardirq.h>
  45. #include <linux/if.h>
  46. #include <linux/io.h>
  47. #include <linux/netdevice.h>
  48. #include <linux/cache.h>
  49. #include <linux/pci.h>
  50. #include <linux/ethtool.h>
  51. #include <linux/uaccess.h>
  52. #include <linux/slab.h>
  53. #include <net/ieee80211_radiotap.h>
  54. #include <asm/unaligned.h>
  55. #include "base.h"
  56. #include "reg.h"
  57. #include "debug.h"
  58. static u8 ath5k_calinterval = 10; /* Calibrate PHY every 10 secs (TODO: Fixme) */
  59. static int modparam_nohwcrypt;
  60. module_param_named(nohwcrypt, modparam_nohwcrypt, bool, S_IRUGO);
  61. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
  62. static int modparam_all_channels;
  63. module_param_named(all_channels, modparam_all_channels, bool, S_IRUGO);
  64. MODULE_PARM_DESC(all_channels, "Expose all channels the device can use.");
  65. /******************\
  66. * Internal defines *
  67. \******************/
  68. /* Module info */
  69. MODULE_AUTHOR("Jiri Slaby");
  70. MODULE_AUTHOR("Nick Kossifidis");
  71. MODULE_DESCRIPTION("Support for 5xxx series of Atheros 802.11 wireless LAN cards.");
  72. MODULE_SUPPORTED_DEVICE("Atheros 5xxx WLAN cards");
  73. MODULE_LICENSE("Dual BSD/GPL");
  74. MODULE_VERSION("0.6.0 (EXPERIMENTAL)");
  75. /* Known PCI ids */
  76. static DEFINE_PCI_DEVICE_TABLE(ath5k_pci_id_table) = {
  77. { PCI_VDEVICE(ATHEROS, 0x0207) }, /* 5210 early */
  78. { PCI_VDEVICE(ATHEROS, 0x0007) }, /* 5210 */
  79. { PCI_VDEVICE(ATHEROS, 0x0011) }, /* 5311 - this is on AHB bus !*/
  80. { PCI_VDEVICE(ATHEROS, 0x0012) }, /* 5211 */
  81. { PCI_VDEVICE(ATHEROS, 0x0013) }, /* 5212 */
  82. { PCI_VDEVICE(3COM_2, 0x0013) }, /* 3com 5212 */
  83. { PCI_VDEVICE(3COM, 0x0013) }, /* 3com 3CRDAG675 5212 */
  84. { PCI_VDEVICE(ATHEROS, 0x1014) }, /* IBM minipci 5212 */
  85. { PCI_VDEVICE(ATHEROS, 0x0014) }, /* 5212 combatible */
  86. { PCI_VDEVICE(ATHEROS, 0x0015) }, /* 5212 combatible */
  87. { PCI_VDEVICE(ATHEROS, 0x0016) }, /* 5212 combatible */
  88. { PCI_VDEVICE(ATHEROS, 0x0017) }, /* 5212 combatible */
  89. { PCI_VDEVICE(ATHEROS, 0x0018) }, /* 5212 combatible */
  90. { PCI_VDEVICE(ATHEROS, 0x0019) }, /* 5212 combatible */
  91. { PCI_VDEVICE(ATHEROS, 0x001a) }, /* 2413 Griffin-lite */
  92. { PCI_VDEVICE(ATHEROS, 0x001b) }, /* 5413 Eagle */
  93. { PCI_VDEVICE(ATHEROS, 0x001c) }, /* PCI-E cards */
  94. { PCI_VDEVICE(ATHEROS, 0x001d) }, /* 2417 Nala */
  95. { 0 }
  96. };
  97. MODULE_DEVICE_TABLE(pci, ath5k_pci_id_table);
  98. /* Known SREVs */
  99. static const struct ath5k_srev_name srev_names[] = {
  100. { "5210", AR5K_VERSION_MAC, AR5K_SREV_AR5210 },
  101. { "5311", AR5K_VERSION_MAC, AR5K_SREV_AR5311 },
  102. { "5311A", AR5K_VERSION_MAC, AR5K_SREV_AR5311A },
  103. { "5311B", AR5K_VERSION_MAC, AR5K_SREV_AR5311B },
  104. { "5211", AR5K_VERSION_MAC, AR5K_SREV_AR5211 },
  105. { "5212", AR5K_VERSION_MAC, AR5K_SREV_AR5212 },
  106. { "5213", AR5K_VERSION_MAC, AR5K_SREV_AR5213 },
  107. { "5213A", AR5K_VERSION_MAC, AR5K_SREV_AR5213A },
  108. { "2413", AR5K_VERSION_MAC, AR5K_SREV_AR2413 },
  109. { "2414", AR5K_VERSION_MAC, AR5K_SREV_AR2414 },
  110. { "5424", AR5K_VERSION_MAC, AR5K_SREV_AR5424 },
  111. { "5413", AR5K_VERSION_MAC, AR5K_SREV_AR5413 },
  112. { "5414", AR5K_VERSION_MAC, AR5K_SREV_AR5414 },
  113. { "2415", AR5K_VERSION_MAC, AR5K_SREV_AR2415 },
  114. { "5416", AR5K_VERSION_MAC, AR5K_SREV_AR5416 },
  115. { "5418", AR5K_VERSION_MAC, AR5K_SREV_AR5418 },
  116. { "2425", AR5K_VERSION_MAC, AR5K_SREV_AR2425 },
  117. { "2417", AR5K_VERSION_MAC, AR5K_SREV_AR2417 },
  118. { "xxxxx", AR5K_VERSION_MAC, AR5K_SREV_UNKNOWN },
  119. { "5110", AR5K_VERSION_RAD, AR5K_SREV_RAD_5110 },
  120. { "5111", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111 },
  121. { "5111A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5111A },
  122. { "2111", AR5K_VERSION_RAD, AR5K_SREV_RAD_2111 },
  123. { "5112", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112 },
  124. { "5112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112A },
  125. { "5112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_5112B },
  126. { "2112", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112 },
  127. { "2112A", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112A },
  128. { "2112B", AR5K_VERSION_RAD, AR5K_SREV_RAD_2112B },
  129. { "2413", AR5K_VERSION_RAD, AR5K_SREV_RAD_2413 },
  130. { "5413", AR5K_VERSION_RAD, AR5K_SREV_RAD_5413 },
  131. { "2316", AR5K_VERSION_RAD, AR5K_SREV_RAD_2316 },
  132. { "2317", AR5K_VERSION_RAD, AR5K_SREV_RAD_2317 },
  133. { "5424", AR5K_VERSION_RAD, AR5K_SREV_RAD_5424 },
  134. { "5133", AR5K_VERSION_RAD, AR5K_SREV_RAD_5133 },
  135. { "xxxxx", AR5K_VERSION_RAD, AR5K_SREV_UNKNOWN },
  136. };
  137. static const struct ieee80211_rate ath5k_rates[] = {
  138. { .bitrate = 10,
  139. .hw_value = ATH5K_RATE_CODE_1M, },
  140. { .bitrate = 20,
  141. .hw_value = ATH5K_RATE_CODE_2M,
  142. .hw_value_short = ATH5K_RATE_CODE_2M | AR5K_SET_SHORT_PREAMBLE,
  143. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  144. { .bitrate = 55,
  145. .hw_value = ATH5K_RATE_CODE_5_5M,
  146. .hw_value_short = ATH5K_RATE_CODE_5_5M | AR5K_SET_SHORT_PREAMBLE,
  147. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  148. { .bitrate = 110,
  149. .hw_value = ATH5K_RATE_CODE_11M,
  150. .hw_value_short = ATH5K_RATE_CODE_11M | AR5K_SET_SHORT_PREAMBLE,
  151. .flags = IEEE80211_RATE_SHORT_PREAMBLE },
  152. { .bitrate = 60,
  153. .hw_value = ATH5K_RATE_CODE_6M,
  154. .flags = 0 },
  155. { .bitrate = 90,
  156. .hw_value = ATH5K_RATE_CODE_9M,
  157. .flags = 0 },
  158. { .bitrate = 120,
  159. .hw_value = ATH5K_RATE_CODE_12M,
  160. .flags = 0 },
  161. { .bitrate = 180,
  162. .hw_value = ATH5K_RATE_CODE_18M,
  163. .flags = 0 },
  164. { .bitrate = 240,
  165. .hw_value = ATH5K_RATE_CODE_24M,
  166. .flags = 0 },
  167. { .bitrate = 360,
  168. .hw_value = ATH5K_RATE_CODE_36M,
  169. .flags = 0 },
  170. { .bitrate = 480,
  171. .hw_value = ATH5K_RATE_CODE_48M,
  172. .flags = 0 },
  173. { .bitrate = 540,
  174. .hw_value = ATH5K_RATE_CODE_54M,
  175. .flags = 0 },
  176. /* XR missing */
  177. };
  178. /*
  179. * Prototypes - PCI stack related functions
  180. */
  181. static int __devinit ath5k_pci_probe(struct pci_dev *pdev,
  182. const struct pci_device_id *id);
  183. static void __devexit ath5k_pci_remove(struct pci_dev *pdev);
  184. #ifdef CONFIG_PM
  185. static int ath5k_pci_suspend(struct device *dev);
  186. static int ath5k_pci_resume(struct device *dev);
  187. static SIMPLE_DEV_PM_OPS(ath5k_pm_ops, ath5k_pci_suspend, ath5k_pci_resume);
  188. #define ATH5K_PM_OPS (&ath5k_pm_ops)
  189. #else
  190. #define ATH5K_PM_OPS NULL
  191. #endif /* CONFIG_PM */
  192. static struct pci_driver ath5k_pci_driver = {
  193. .name = KBUILD_MODNAME,
  194. .id_table = ath5k_pci_id_table,
  195. .probe = ath5k_pci_probe,
  196. .remove = __devexit_p(ath5k_pci_remove),
  197. .driver.pm = ATH5K_PM_OPS,
  198. };
  199. /*
  200. * Prototypes - MAC 802.11 stack related functions
  201. */
  202. static int ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb);
  203. static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
  204. struct ath5k_txq *txq);
  205. static int ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan);
  206. static int ath5k_reset_wake(struct ath5k_softc *sc);
  207. static int ath5k_start(struct ieee80211_hw *hw);
  208. static void ath5k_stop(struct ieee80211_hw *hw);
  209. static int ath5k_add_interface(struct ieee80211_hw *hw,
  210. struct ieee80211_vif *vif);
  211. static void ath5k_remove_interface(struct ieee80211_hw *hw,
  212. struct ieee80211_vif *vif);
  213. static int ath5k_config(struct ieee80211_hw *hw, u32 changed);
  214. static u64 ath5k_prepare_multicast(struct ieee80211_hw *hw,
  215. struct netdev_hw_addr_list *mc_list);
  216. static void ath5k_configure_filter(struct ieee80211_hw *hw,
  217. unsigned int changed_flags,
  218. unsigned int *new_flags,
  219. u64 multicast);
  220. static int ath5k_set_key(struct ieee80211_hw *hw,
  221. enum set_key_cmd cmd,
  222. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  223. struct ieee80211_key_conf *key);
  224. static int ath5k_get_stats(struct ieee80211_hw *hw,
  225. struct ieee80211_low_level_stats *stats);
  226. static u64 ath5k_get_tsf(struct ieee80211_hw *hw);
  227. static void ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf);
  228. static void ath5k_reset_tsf(struct ieee80211_hw *hw);
  229. static int ath5k_beacon_update(struct ieee80211_hw *hw,
  230. struct ieee80211_vif *vif);
  231. static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
  232. struct ieee80211_vif *vif,
  233. struct ieee80211_bss_conf *bss_conf,
  234. u32 changes);
  235. static void ath5k_sw_scan_start(struct ieee80211_hw *hw);
  236. static void ath5k_sw_scan_complete(struct ieee80211_hw *hw);
  237. static void ath5k_set_coverage_class(struct ieee80211_hw *hw,
  238. u8 coverage_class);
  239. static const struct ieee80211_ops ath5k_hw_ops = {
  240. .tx = ath5k_tx,
  241. .start = ath5k_start,
  242. .stop = ath5k_stop,
  243. .add_interface = ath5k_add_interface,
  244. .remove_interface = ath5k_remove_interface,
  245. .config = ath5k_config,
  246. .prepare_multicast = ath5k_prepare_multicast,
  247. .configure_filter = ath5k_configure_filter,
  248. .set_key = ath5k_set_key,
  249. .get_stats = ath5k_get_stats,
  250. .conf_tx = NULL,
  251. .get_tsf = ath5k_get_tsf,
  252. .set_tsf = ath5k_set_tsf,
  253. .reset_tsf = ath5k_reset_tsf,
  254. .bss_info_changed = ath5k_bss_info_changed,
  255. .sw_scan_start = ath5k_sw_scan_start,
  256. .sw_scan_complete = ath5k_sw_scan_complete,
  257. .set_coverage_class = ath5k_set_coverage_class,
  258. };
  259. /*
  260. * Prototypes - Internal functions
  261. */
  262. /* Attach detach */
  263. static int ath5k_attach(struct pci_dev *pdev,
  264. struct ieee80211_hw *hw);
  265. static void ath5k_detach(struct pci_dev *pdev,
  266. struct ieee80211_hw *hw);
  267. /* Channel/mode setup */
  268. static inline short ath5k_ieee2mhz(short chan);
  269. static unsigned int ath5k_copy_channels(struct ath5k_hw *ah,
  270. struct ieee80211_channel *channels,
  271. unsigned int mode,
  272. unsigned int max);
  273. static int ath5k_setup_bands(struct ieee80211_hw *hw);
  274. static int ath5k_chan_set(struct ath5k_softc *sc,
  275. struct ieee80211_channel *chan);
  276. static void ath5k_setcurmode(struct ath5k_softc *sc,
  277. unsigned int mode);
  278. static void ath5k_mode_setup(struct ath5k_softc *sc);
  279. /* Descriptor setup */
  280. static int ath5k_desc_alloc(struct ath5k_softc *sc,
  281. struct pci_dev *pdev);
  282. static void ath5k_desc_free(struct ath5k_softc *sc,
  283. struct pci_dev *pdev);
  284. /* Buffers setup */
  285. static int ath5k_rxbuf_setup(struct ath5k_softc *sc,
  286. struct ath5k_buf *bf);
  287. static int ath5k_txbuf_setup(struct ath5k_softc *sc,
  288. struct ath5k_buf *bf,
  289. struct ath5k_txq *txq, int padsize);
  290. static inline void ath5k_txbuf_free(struct ath5k_softc *sc,
  291. struct ath5k_buf *bf)
  292. {
  293. BUG_ON(!bf);
  294. if (!bf->skb)
  295. return;
  296. pci_unmap_single(sc->pdev, bf->skbaddr, bf->skb->len,
  297. PCI_DMA_TODEVICE);
  298. dev_kfree_skb_any(bf->skb);
  299. bf->skb = NULL;
  300. }
  301. static inline void ath5k_rxbuf_free(struct ath5k_softc *sc,
  302. struct ath5k_buf *bf)
  303. {
  304. struct ath5k_hw *ah = sc->ah;
  305. struct ath_common *common = ath5k_hw_common(ah);
  306. BUG_ON(!bf);
  307. if (!bf->skb)
  308. return;
  309. pci_unmap_single(sc->pdev, bf->skbaddr, common->rx_bufsize,
  310. PCI_DMA_FROMDEVICE);
  311. dev_kfree_skb_any(bf->skb);
  312. bf->skb = NULL;
  313. }
  314. /* Queues setup */
  315. static struct ath5k_txq *ath5k_txq_setup(struct ath5k_softc *sc,
  316. int qtype, int subtype);
  317. static int ath5k_beaconq_setup(struct ath5k_hw *ah);
  318. static int ath5k_beaconq_config(struct ath5k_softc *sc);
  319. static void ath5k_txq_drainq(struct ath5k_softc *sc,
  320. struct ath5k_txq *txq);
  321. static void ath5k_txq_cleanup(struct ath5k_softc *sc);
  322. static void ath5k_txq_release(struct ath5k_softc *sc);
  323. /* Rx handling */
  324. static int ath5k_rx_start(struct ath5k_softc *sc);
  325. static void ath5k_rx_stop(struct ath5k_softc *sc);
  326. static unsigned int ath5k_rx_decrypted(struct ath5k_softc *sc,
  327. struct ath5k_desc *ds,
  328. struct sk_buff *skb,
  329. struct ath5k_rx_status *rs);
  330. static void ath5k_tasklet_rx(unsigned long data);
  331. /* Tx handling */
  332. static void ath5k_tx_processq(struct ath5k_softc *sc,
  333. struct ath5k_txq *txq);
  334. static void ath5k_tasklet_tx(unsigned long data);
  335. /* Beacon handling */
  336. static int ath5k_beacon_setup(struct ath5k_softc *sc,
  337. struct ath5k_buf *bf);
  338. static void ath5k_beacon_send(struct ath5k_softc *sc);
  339. static void ath5k_beacon_config(struct ath5k_softc *sc);
  340. static void ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf);
  341. static void ath5k_tasklet_beacon(unsigned long data);
  342. static inline u64 ath5k_extend_tsf(struct ath5k_hw *ah, u32 rstamp)
  343. {
  344. u64 tsf = ath5k_hw_get_tsf64(ah);
  345. if ((tsf & 0x7fff) < rstamp)
  346. tsf -= 0x8000;
  347. return (tsf & ~0x7fff) | rstamp;
  348. }
  349. /* Interrupt handling */
  350. static int ath5k_init(struct ath5k_softc *sc);
  351. static int ath5k_stop_locked(struct ath5k_softc *sc);
  352. static int ath5k_stop_hw(struct ath5k_softc *sc);
  353. static irqreturn_t ath5k_intr(int irq, void *dev_id);
  354. static void ath5k_tasklet_reset(unsigned long data);
  355. static void ath5k_tasklet_calibrate(unsigned long data);
  356. /*
  357. * Module init/exit functions
  358. */
  359. static int __init
  360. init_ath5k_pci(void)
  361. {
  362. int ret;
  363. ath5k_debug_init();
  364. ret = pci_register_driver(&ath5k_pci_driver);
  365. if (ret) {
  366. printk(KERN_ERR "ath5k_pci: can't register pci driver\n");
  367. return ret;
  368. }
  369. return 0;
  370. }
  371. static void __exit
  372. exit_ath5k_pci(void)
  373. {
  374. pci_unregister_driver(&ath5k_pci_driver);
  375. ath5k_debug_finish();
  376. }
  377. module_init(init_ath5k_pci);
  378. module_exit(exit_ath5k_pci);
  379. /********************\
  380. * PCI Initialization *
  381. \********************/
  382. static const char *
  383. ath5k_chip_name(enum ath5k_srev_type type, u_int16_t val)
  384. {
  385. const char *name = "xxxxx";
  386. unsigned int i;
  387. for (i = 0; i < ARRAY_SIZE(srev_names); i++) {
  388. if (srev_names[i].sr_type != type)
  389. continue;
  390. if ((val & 0xf0) == srev_names[i].sr_val)
  391. name = srev_names[i].sr_name;
  392. if ((val & 0xff) == srev_names[i].sr_val) {
  393. name = srev_names[i].sr_name;
  394. break;
  395. }
  396. }
  397. return name;
  398. }
  399. static unsigned int ath5k_ioread32(void *hw_priv, u32 reg_offset)
  400. {
  401. struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
  402. return ath5k_hw_reg_read(ah, reg_offset);
  403. }
  404. static void ath5k_iowrite32(void *hw_priv, u32 val, u32 reg_offset)
  405. {
  406. struct ath5k_hw *ah = (struct ath5k_hw *) hw_priv;
  407. ath5k_hw_reg_write(ah, val, reg_offset);
  408. }
  409. static const struct ath_ops ath5k_common_ops = {
  410. .read = ath5k_ioread32,
  411. .write = ath5k_iowrite32,
  412. };
  413. static int __devinit
  414. ath5k_pci_probe(struct pci_dev *pdev,
  415. const struct pci_device_id *id)
  416. {
  417. void __iomem *mem;
  418. struct ath5k_softc *sc;
  419. struct ath_common *common;
  420. struct ieee80211_hw *hw;
  421. int ret;
  422. u8 csz;
  423. ret = pci_enable_device(pdev);
  424. if (ret) {
  425. dev_err(&pdev->dev, "can't enable device\n");
  426. goto err;
  427. }
  428. /* XXX 32-bit addressing only */
  429. ret = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  430. if (ret) {
  431. dev_err(&pdev->dev, "32-bit DMA not available\n");
  432. goto err_dis;
  433. }
  434. /*
  435. * Cache line size is used to size and align various
  436. * structures used to communicate with the hardware.
  437. */
  438. pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &csz);
  439. if (csz == 0) {
  440. /*
  441. * Linux 2.4.18 (at least) writes the cache line size
  442. * register as a 16-bit wide register which is wrong.
  443. * We must have this setup properly for rx buffer
  444. * DMA to work so force a reasonable value here if it
  445. * comes up zero.
  446. */
  447. csz = L1_CACHE_BYTES >> 2;
  448. pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, csz);
  449. }
  450. /*
  451. * The default setting of latency timer yields poor results,
  452. * set it to the value used by other systems. It may be worth
  453. * tweaking this setting more.
  454. */
  455. pci_write_config_byte(pdev, PCI_LATENCY_TIMER, 0xa8);
  456. /* Enable bus mastering */
  457. pci_set_master(pdev);
  458. /*
  459. * Disable the RETRY_TIMEOUT register (0x41) to keep
  460. * PCI Tx retries from interfering with C3 CPU state.
  461. */
  462. pci_write_config_byte(pdev, 0x41, 0);
  463. ret = pci_request_region(pdev, 0, "ath5k");
  464. if (ret) {
  465. dev_err(&pdev->dev, "cannot reserve PCI memory region\n");
  466. goto err_dis;
  467. }
  468. mem = pci_iomap(pdev, 0, 0);
  469. if (!mem) {
  470. dev_err(&pdev->dev, "cannot remap PCI memory region\n") ;
  471. ret = -EIO;
  472. goto err_reg;
  473. }
  474. /*
  475. * Allocate hw (mac80211 main struct)
  476. * and hw->priv (driver private data)
  477. */
  478. hw = ieee80211_alloc_hw(sizeof(*sc), &ath5k_hw_ops);
  479. if (hw == NULL) {
  480. dev_err(&pdev->dev, "cannot allocate ieee80211_hw\n");
  481. ret = -ENOMEM;
  482. goto err_map;
  483. }
  484. dev_info(&pdev->dev, "registered as '%s'\n", wiphy_name(hw->wiphy));
  485. /* Initialize driver private data */
  486. SET_IEEE80211_DEV(hw, &pdev->dev);
  487. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  488. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  489. IEEE80211_HW_SIGNAL_DBM |
  490. IEEE80211_HW_NOISE_DBM;
  491. hw->wiphy->interface_modes =
  492. BIT(NL80211_IFTYPE_AP) |
  493. BIT(NL80211_IFTYPE_STATION) |
  494. BIT(NL80211_IFTYPE_ADHOC) |
  495. BIT(NL80211_IFTYPE_MESH_POINT);
  496. hw->extra_tx_headroom = 2;
  497. hw->channel_change_time = 5000;
  498. sc = hw->priv;
  499. sc->hw = hw;
  500. sc->pdev = pdev;
  501. ath5k_debug_init_device(sc);
  502. /*
  503. * Mark the device as detached to avoid processing
  504. * interrupts until setup is complete.
  505. */
  506. __set_bit(ATH_STAT_INVALID, sc->status);
  507. sc->iobase = mem; /* So we can unmap it on detach */
  508. sc->opmode = NL80211_IFTYPE_STATION;
  509. sc->bintval = 1000;
  510. mutex_init(&sc->lock);
  511. spin_lock_init(&sc->rxbuflock);
  512. spin_lock_init(&sc->txbuflock);
  513. spin_lock_init(&sc->block);
  514. /* Set private data */
  515. pci_set_drvdata(pdev, hw);
  516. /* Setup interrupt handler */
  517. ret = request_irq(pdev->irq, ath5k_intr, IRQF_SHARED, "ath", sc);
  518. if (ret) {
  519. ATH5K_ERR(sc, "request_irq failed\n");
  520. goto err_free;
  521. }
  522. /*If we passed the test malloc a ath5k_hw struct*/
  523. sc->ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
  524. if (!sc->ah) {
  525. ret = -ENOMEM;
  526. ATH5K_ERR(sc, "out of memory\n");
  527. goto err_irq;
  528. }
  529. sc->ah->ah_sc = sc;
  530. sc->ah->ah_iobase = sc->iobase;
  531. common = ath5k_hw_common(sc->ah);
  532. common->ops = &ath5k_common_ops;
  533. common->ah = sc->ah;
  534. common->hw = hw;
  535. common->cachelsz = csz << 2; /* convert to bytes */
  536. /* Initialize device */
  537. ret = ath5k_hw_attach(sc);
  538. if (ret) {
  539. goto err_free_ah;
  540. }
  541. /* set up multi-rate retry capabilities */
  542. if (sc->ah->ah_version == AR5K_AR5212) {
  543. hw->max_rates = 4;
  544. hw->max_rate_tries = 11;
  545. }
  546. /* Finish private driver data initialization */
  547. ret = ath5k_attach(pdev, hw);
  548. if (ret)
  549. goto err_ah;
  550. ATH5K_INFO(sc, "Atheros AR%s chip found (MAC: 0x%x, PHY: 0x%x)\n",
  551. ath5k_chip_name(AR5K_VERSION_MAC, sc->ah->ah_mac_srev),
  552. sc->ah->ah_mac_srev,
  553. sc->ah->ah_phy_revision);
  554. if (!sc->ah->ah_single_chip) {
  555. /* Single chip radio (!RF5111) */
  556. if (sc->ah->ah_radio_5ghz_revision &&
  557. !sc->ah->ah_radio_2ghz_revision) {
  558. /* No 5GHz support -> report 2GHz radio */
  559. if (!test_bit(AR5K_MODE_11A,
  560. sc->ah->ah_capabilities.cap_mode)) {
  561. ATH5K_INFO(sc, "RF%s 2GHz radio found (0x%x)\n",
  562. ath5k_chip_name(AR5K_VERSION_RAD,
  563. sc->ah->ah_radio_5ghz_revision),
  564. sc->ah->ah_radio_5ghz_revision);
  565. /* No 2GHz support (5110 and some
  566. * 5Ghz only cards) -> report 5Ghz radio */
  567. } else if (!test_bit(AR5K_MODE_11B,
  568. sc->ah->ah_capabilities.cap_mode)) {
  569. ATH5K_INFO(sc, "RF%s 5GHz radio found (0x%x)\n",
  570. ath5k_chip_name(AR5K_VERSION_RAD,
  571. sc->ah->ah_radio_5ghz_revision),
  572. sc->ah->ah_radio_5ghz_revision);
  573. /* Multiband radio */
  574. } else {
  575. ATH5K_INFO(sc, "RF%s multiband radio found"
  576. " (0x%x)\n",
  577. ath5k_chip_name(AR5K_VERSION_RAD,
  578. sc->ah->ah_radio_5ghz_revision),
  579. sc->ah->ah_radio_5ghz_revision);
  580. }
  581. }
  582. /* Multi chip radio (RF5111 - RF2111) ->
  583. * report both 2GHz/5GHz radios */
  584. else if (sc->ah->ah_radio_5ghz_revision &&
  585. sc->ah->ah_radio_2ghz_revision){
  586. ATH5K_INFO(sc, "RF%s 5GHz radio found (0x%x)\n",
  587. ath5k_chip_name(AR5K_VERSION_RAD,
  588. sc->ah->ah_radio_5ghz_revision),
  589. sc->ah->ah_radio_5ghz_revision);
  590. ATH5K_INFO(sc, "RF%s 2GHz radio found (0x%x)\n",
  591. ath5k_chip_name(AR5K_VERSION_RAD,
  592. sc->ah->ah_radio_2ghz_revision),
  593. sc->ah->ah_radio_2ghz_revision);
  594. }
  595. }
  596. /* ready to process interrupts */
  597. __clear_bit(ATH_STAT_INVALID, sc->status);
  598. return 0;
  599. err_ah:
  600. ath5k_hw_detach(sc->ah);
  601. err_irq:
  602. free_irq(pdev->irq, sc);
  603. err_free_ah:
  604. kfree(sc->ah);
  605. err_free:
  606. ieee80211_free_hw(hw);
  607. err_map:
  608. pci_iounmap(pdev, mem);
  609. err_reg:
  610. pci_release_region(pdev, 0);
  611. err_dis:
  612. pci_disable_device(pdev);
  613. err:
  614. return ret;
  615. }
  616. static void __devexit
  617. ath5k_pci_remove(struct pci_dev *pdev)
  618. {
  619. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  620. struct ath5k_softc *sc = hw->priv;
  621. ath5k_debug_finish_device(sc);
  622. ath5k_detach(pdev, hw);
  623. ath5k_hw_detach(sc->ah);
  624. kfree(sc->ah);
  625. free_irq(pdev->irq, sc);
  626. pci_iounmap(pdev, sc->iobase);
  627. pci_release_region(pdev, 0);
  628. pci_disable_device(pdev);
  629. ieee80211_free_hw(hw);
  630. }
  631. #ifdef CONFIG_PM
  632. static int ath5k_pci_suspend(struct device *dev)
  633. {
  634. struct ieee80211_hw *hw = pci_get_drvdata(to_pci_dev(dev));
  635. struct ath5k_softc *sc = hw->priv;
  636. ath5k_led_off(sc);
  637. return 0;
  638. }
  639. static int ath5k_pci_resume(struct device *dev)
  640. {
  641. struct pci_dev *pdev = to_pci_dev(dev);
  642. struct ieee80211_hw *hw = pci_get_drvdata(pdev);
  643. struct ath5k_softc *sc = hw->priv;
  644. /*
  645. * Suspend/Resume resets the PCI configuration space, so we have to
  646. * re-disable the RETRY_TIMEOUT register (0x41) to keep
  647. * PCI Tx retries from interfering with C3 CPU state
  648. */
  649. pci_write_config_byte(pdev, 0x41, 0);
  650. ath5k_led_enable(sc);
  651. return 0;
  652. }
  653. #endif /* CONFIG_PM */
  654. /***********************\
  655. * Driver Initialization *
  656. \***********************/
  657. static int ath5k_reg_notifier(struct wiphy *wiphy, struct regulatory_request *request)
  658. {
  659. struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
  660. struct ath5k_softc *sc = hw->priv;
  661. struct ath_regulatory *regulatory = ath5k_hw_regulatory(sc->ah);
  662. return ath_reg_notifier_apply(wiphy, request, regulatory);
  663. }
  664. static int
  665. ath5k_attach(struct pci_dev *pdev, struct ieee80211_hw *hw)
  666. {
  667. struct ath5k_softc *sc = hw->priv;
  668. struct ath5k_hw *ah = sc->ah;
  669. struct ath_regulatory *regulatory = ath5k_hw_regulatory(ah);
  670. u8 mac[ETH_ALEN] = {};
  671. int ret;
  672. ATH5K_DBG(sc, ATH5K_DEBUG_ANY, "devid 0x%x\n", pdev->device);
  673. /*
  674. * Check if the MAC has multi-rate retry support.
  675. * We do this by trying to setup a fake extended
  676. * descriptor. MAC's that don't have support will
  677. * return false w/o doing anything. MAC's that do
  678. * support it will return true w/o doing anything.
  679. */
  680. ret = ah->ah_setup_mrr_tx_desc(ah, NULL, 0, 0, 0, 0, 0, 0);
  681. if (ret < 0)
  682. goto err;
  683. if (ret > 0)
  684. __set_bit(ATH_STAT_MRRETRY, sc->status);
  685. /*
  686. * Collect the channel list. The 802.11 layer
  687. * is resposible for filtering this list based
  688. * on settings like the phy mode and regulatory
  689. * domain restrictions.
  690. */
  691. ret = ath5k_setup_bands(hw);
  692. if (ret) {
  693. ATH5K_ERR(sc, "can't get channels\n");
  694. goto err;
  695. }
  696. /* NB: setup here so ath5k_rate_update is happy */
  697. if (test_bit(AR5K_MODE_11A, ah->ah_modes))
  698. ath5k_setcurmode(sc, AR5K_MODE_11A);
  699. else
  700. ath5k_setcurmode(sc, AR5K_MODE_11B);
  701. /*
  702. * Allocate tx+rx descriptors and populate the lists.
  703. */
  704. ret = ath5k_desc_alloc(sc, pdev);
  705. if (ret) {
  706. ATH5K_ERR(sc, "can't allocate descriptors\n");
  707. goto err;
  708. }
  709. /*
  710. * Allocate hardware transmit queues: one queue for
  711. * beacon frames and one data queue for each QoS
  712. * priority. Note that hw functions handle reseting
  713. * these queues at the needed time.
  714. */
  715. ret = ath5k_beaconq_setup(ah);
  716. if (ret < 0) {
  717. ATH5K_ERR(sc, "can't setup a beacon xmit queue\n");
  718. goto err_desc;
  719. }
  720. sc->bhalq = ret;
  721. sc->cabq = ath5k_txq_setup(sc, AR5K_TX_QUEUE_CAB, 0);
  722. if (IS_ERR(sc->cabq)) {
  723. ATH5K_ERR(sc, "can't setup cab queue\n");
  724. ret = PTR_ERR(sc->cabq);
  725. goto err_bhal;
  726. }
  727. sc->txq = ath5k_txq_setup(sc, AR5K_TX_QUEUE_DATA, AR5K_WME_AC_BK);
  728. if (IS_ERR(sc->txq)) {
  729. ATH5K_ERR(sc, "can't setup xmit queue\n");
  730. ret = PTR_ERR(sc->txq);
  731. goto err_queues;
  732. }
  733. tasklet_init(&sc->rxtq, ath5k_tasklet_rx, (unsigned long)sc);
  734. tasklet_init(&sc->txtq, ath5k_tasklet_tx, (unsigned long)sc);
  735. tasklet_init(&sc->restq, ath5k_tasklet_reset, (unsigned long)sc);
  736. tasklet_init(&sc->calib, ath5k_tasklet_calibrate, (unsigned long)sc);
  737. tasklet_init(&sc->beacontq, ath5k_tasklet_beacon, (unsigned long)sc);
  738. ret = ath5k_eeprom_read_mac(ah, mac);
  739. if (ret) {
  740. ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
  741. sc->pdev->device);
  742. goto err_queues;
  743. }
  744. SET_IEEE80211_PERM_ADDR(hw, mac);
  745. /* All MAC address bits matter for ACKs */
  746. memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
  747. ath5k_hw_set_bssid_mask(sc->ah, sc->bssidmask);
  748. regulatory->current_rd = ah->ah_capabilities.cap_eeprom.ee_regdomain;
  749. ret = ath_regd_init(regulatory, hw->wiphy, ath5k_reg_notifier);
  750. if (ret) {
  751. ATH5K_ERR(sc, "can't initialize regulatory system\n");
  752. goto err_queues;
  753. }
  754. ret = ieee80211_register_hw(hw);
  755. if (ret) {
  756. ATH5K_ERR(sc, "can't register ieee80211 hw\n");
  757. goto err_queues;
  758. }
  759. if (!ath_is_world_regd(regulatory))
  760. regulatory_hint(hw->wiphy, regulatory->alpha2);
  761. ath5k_init_leds(sc);
  762. return 0;
  763. err_queues:
  764. ath5k_txq_release(sc);
  765. err_bhal:
  766. ath5k_hw_release_tx_queue(ah, sc->bhalq);
  767. err_desc:
  768. ath5k_desc_free(sc, pdev);
  769. err:
  770. return ret;
  771. }
  772. static void
  773. ath5k_detach(struct pci_dev *pdev, struct ieee80211_hw *hw)
  774. {
  775. struct ath5k_softc *sc = hw->priv;
  776. /*
  777. * NB: the order of these is important:
  778. * o call the 802.11 layer before detaching ath5k_hw to
  779. * insure callbacks into the driver to delete global
  780. * key cache entries can be handled
  781. * o reclaim the tx queue data structures after calling
  782. * the 802.11 layer as we'll get called back to reclaim
  783. * node state and potentially want to use them
  784. * o to cleanup the tx queues the hal is called, so detach
  785. * it last
  786. * XXX: ??? detach ath5k_hw ???
  787. * Other than that, it's straightforward...
  788. */
  789. ieee80211_unregister_hw(hw);
  790. ath5k_desc_free(sc, pdev);
  791. ath5k_txq_release(sc);
  792. ath5k_hw_release_tx_queue(sc->ah, sc->bhalq);
  793. ath5k_unregister_leds(sc);
  794. /*
  795. * NB: can't reclaim these until after ieee80211_ifdetach
  796. * returns because we'll get called back to reclaim node
  797. * state and potentially want to use them.
  798. */
  799. }
  800. /********************\
  801. * Channel/mode setup *
  802. \********************/
  803. /*
  804. * Convert IEEE channel number to MHz frequency.
  805. */
  806. static inline short
  807. ath5k_ieee2mhz(short chan)
  808. {
  809. if (chan <= 14 || chan >= 27)
  810. return ieee80211chan2mhz(chan);
  811. else
  812. return 2212 + chan * 20;
  813. }
  814. /*
  815. * Returns true for the channel numbers used without all_channels modparam.
  816. */
  817. static bool ath5k_is_standard_channel(short chan)
  818. {
  819. return ((chan <= 14) ||
  820. /* UNII 1,2 */
  821. ((chan & 3) == 0 && chan >= 36 && chan <= 64) ||
  822. /* midband */
  823. ((chan & 3) == 0 && chan >= 100 && chan <= 140) ||
  824. /* UNII-3 */
  825. ((chan & 3) == 1 && chan >= 149 && chan <= 165));
  826. }
  827. static unsigned int
  828. ath5k_copy_channels(struct ath5k_hw *ah,
  829. struct ieee80211_channel *channels,
  830. unsigned int mode,
  831. unsigned int max)
  832. {
  833. unsigned int i, count, size, chfreq, freq, ch;
  834. if (!test_bit(mode, ah->ah_modes))
  835. return 0;
  836. switch (mode) {
  837. case AR5K_MODE_11A:
  838. case AR5K_MODE_11A_TURBO:
  839. /* 1..220, but 2GHz frequencies are filtered by check_channel */
  840. size = 220 ;
  841. chfreq = CHANNEL_5GHZ;
  842. break;
  843. case AR5K_MODE_11B:
  844. case AR5K_MODE_11G:
  845. case AR5K_MODE_11G_TURBO:
  846. size = 26;
  847. chfreq = CHANNEL_2GHZ;
  848. break;
  849. default:
  850. ATH5K_WARN(ah->ah_sc, "bad mode, not copying channels\n");
  851. return 0;
  852. }
  853. for (i = 0, count = 0; i < size && max > 0; i++) {
  854. ch = i + 1 ;
  855. freq = ath5k_ieee2mhz(ch);
  856. /* Check if channel is supported by the chipset */
  857. if (!ath5k_channel_ok(ah, freq, chfreq))
  858. continue;
  859. if (!modparam_all_channels && !ath5k_is_standard_channel(ch))
  860. continue;
  861. /* Write channel info and increment counter */
  862. channels[count].center_freq = freq;
  863. channels[count].band = (chfreq == CHANNEL_2GHZ) ?
  864. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  865. switch (mode) {
  866. case AR5K_MODE_11A:
  867. case AR5K_MODE_11G:
  868. channels[count].hw_value = chfreq | CHANNEL_OFDM;
  869. break;
  870. case AR5K_MODE_11A_TURBO:
  871. case AR5K_MODE_11G_TURBO:
  872. channels[count].hw_value = chfreq |
  873. CHANNEL_OFDM | CHANNEL_TURBO;
  874. break;
  875. case AR5K_MODE_11B:
  876. channels[count].hw_value = CHANNEL_B;
  877. }
  878. count++;
  879. max--;
  880. }
  881. return count;
  882. }
  883. static void
  884. ath5k_setup_rate_idx(struct ath5k_softc *sc, struct ieee80211_supported_band *b)
  885. {
  886. u8 i;
  887. for (i = 0; i < AR5K_MAX_RATES; i++)
  888. sc->rate_idx[b->band][i] = -1;
  889. for (i = 0; i < b->n_bitrates; i++) {
  890. sc->rate_idx[b->band][b->bitrates[i].hw_value] = i;
  891. if (b->bitrates[i].hw_value_short)
  892. sc->rate_idx[b->band][b->bitrates[i].hw_value_short] = i;
  893. }
  894. }
  895. static int
  896. ath5k_setup_bands(struct ieee80211_hw *hw)
  897. {
  898. struct ath5k_softc *sc = hw->priv;
  899. struct ath5k_hw *ah = sc->ah;
  900. struct ieee80211_supported_band *sband;
  901. int max_c, count_c = 0;
  902. int i;
  903. BUILD_BUG_ON(ARRAY_SIZE(sc->sbands) < IEEE80211_NUM_BANDS);
  904. max_c = ARRAY_SIZE(sc->channels);
  905. /* 2GHz band */
  906. sband = &sc->sbands[IEEE80211_BAND_2GHZ];
  907. sband->band = IEEE80211_BAND_2GHZ;
  908. sband->bitrates = &sc->rates[IEEE80211_BAND_2GHZ][0];
  909. if (test_bit(AR5K_MODE_11G, sc->ah->ah_capabilities.cap_mode)) {
  910. /* G mode */
  911. memcpy(sband->bitrates, &ath5k_rates[0],
  912. sizeof(struct ieee80211_rate) * 12);
  913. sband->n_bitrates = 12;
  914. sband->channels = sc->channels;
  915. sband->n_channels = ath5k_copy_channels(ah, sband->channels,
  916. AR5K_MODE_11G, max_c);
  917. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  918. count_c = sband->n_channels;
  919. max_c -= count_c;
  920. } else if (test_bit(AR5K_MODE_11B, sc->ah->ah_capabilities.cap_mode)) {
  921. /* B mode */
  922. memcpy(sband->bitrates, &ath5k_rates[0],
  923. sizeof(struct ieee80211_rate) * 4);
  924. sband->n_bitrates = 4;
  925. /* 5211 only supports B rates and uses 4bit rate codes
  926. * (e.g normally we have 0x1B for 1M, but on 5211 we have 0x0B)
  927. * fix them up here:
  928. */
  929. if (ah->ah_version == AR5K_AR5211) {
  930. for (i = 0; i < 4; i++) {
  931. sband->bitrates[i].hw_value =
  932. sband->bitrates[i].hw_value & 0xF;
  933. sband->bitrates[i].hw_value_short =
  934. sband->bitrates[i].hw_value_short & 0xF;
  935. }
  936. }
  937. sband->channels = sc->channels;
  938. sband->n_channels = ath5k_copy_channels(ah, sband->channels,
  939. AR5K_MODE_11B, max_c);
  940. hw->wiphy->bands[IEEE80211_BAND_2GHZ] = sband;
  941. count_c = sband->n_channels;
  942. max_c -= count_c;
  943. }
  944. ath5k_setup_rate_idx(sc, sband);
  945. /* 5GHz band, A mode */
  946. if (test_bit(AR5K_MODE_11A, sc->ah->ah_capabilities.cap_mode)) {
  947. sband = &sc->sbands[IEEE80211_BAND_5GHZ];
  948. sband->band = IEEE80211_BAND_5GHZ;
  949. sband->bitrates = &sc->rates[IEEE80211_BAND_5GHZ][0];
  950. memcpy(sband->bitrates, &ath5k_rates[4],
  951. sizeof(struct ieee80211_rate) * 8);
  952. sband->n_bitrates = 8;
  953. sband->channels = &sc->channels[count_c];
  954. sband->n_channels = ath5k_copy_channels(ah, sband->channels,
  955. AR5K_MODE_11A, max_c);
  956. hw->wiphy->bands[IEEE80211_BAND_5GHZ] = sband;
  957. }
  958. ath5k_setup_rate_idx(sc, sband);
  959. ath5k_debug_dump_bands(sc);
  960. return 0;
  961. }
  962. /*
  963. * Set/change channels. We always reset the chip.
  964. * To accomplish this we must first cleanup any pending DMA,
  965. * then restart stuff after a la ath5k_init.
  966. *
  967. * Called with sc->lock.
  968. */
  969. static int
  970. ath5k_chan_set(struct ath5k_softc *sc, struct ieee80211_channel *chan)
  971. {
  972. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "(%u MHz) -> (%u MHz)\n",
  973. sc->curchan->center_freq, chan->center_freq);
  974. /*
  975. * To switch channels clear any pending DMA operations;
  976. * wait long enough for the RX fifo to drain, reset the
  977. * hardware at the new frequency, and then re-enable
  978. * the relevant bits of the h/w.
  979. */
  980. return ath5k_reset(sc, chan);
  981. }
  982. static void
  983. ath5k_setcurmode(struct ath5k_softc *sc, unsigned int mode)
  984. {
  985. sc->curmode = mode;
  986. if (mode == AR5K_MODE_11A) {
  987. sc->curband = &sc->sbands[IEEE80211_BAND_5GHZ];
  988. } else {
  989. sc->curband = &sc->sbands[IEEE80211_BAND_2GHZ];
  990. }
  991. }
  992. static void
  993. ath5k_mode_setup(struct ath5k_softc *sc)
  994. {
  995. struct ath5k_hw *ah = sc->ah;
  996. u32 rfilt;
  997. /* configure rx filter */
  998. rfilt = sc->filter_flags;
  999. ath5k_hw_set_rx_filter(ah, rfilt);
  1000. if (ath5k_hw_hasbssidmask(ah))
  1001. ath5k_hw_set_bssid_mask(ah, sc->bssidmask);
  1002. /* configure operational mode */
  1003. ath5k_hw_set_opmode(ah, sc->opmode);
  1004. ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "mode setup opmode %d\n", sc->opmode);
  1005. ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "RX filter 0x%x\n", rfilt);
  1006. }
  1007. static inline int
  1008. ath5k_hw_to_driver_rix(struct ath5k_softc *sc, int hw_rix)
  1009. {
  1010. int rix;
  1011. /* return base rate on errors */
  1012. if (WARN(hw_rix < 0 || hw_rix >= AR5K_MAX_RATES,
  1013. "hw_rix out of bounds: %x\n", hw_rix))
  1014. return 0;
  1015. rix = sc->rate_idx[sc->curband->band][hw_rix];
  1016. if (WARN(rix < 0, "invalid hw_rix: %x\n", hw_rix))
  1017. rix = 0;
  1018. return rix;
  1019. }
  1020. /***************\
  1021. * Buffers setup *
  1022. \***************/
  1023. static
  1024. struct sk_buff *ath5k_rx_skb_alloc(struct ath5k_softc *sc, dma_addr_t *skb_addr)
  1025. {
  1026. struct ath_common *common = ath5k_hw_common(sc->ah);
  1027. struct sk_buff *skb;
  1028. /*
  1029. * Allocate buffer with headroom_needed space for the
  1030. * fake physical layer header at the start.
  1031. */
  1032. skb = ath_rxbuf_alloc(common,
  1033. common->rx_bufsize,
  1034. GFP_ATOMIC);
  1035. if (!skb) {
  1036. ATH5K_ERR(sc, "can't alloc skbuff of size %u\n",
  1037. common->rx_bufsize);
  1038. return NULL;
  1039. }
  1040. *skb_addr = pci_map_single(sc->pdev,
  1041. skb->data, common->rx_bufsize,
  1042. PCI_DMA_FROMDEVICE);
  1043. if (unlikely(pci_dma_mapping_error(sc->pdev, *skb_addr))) {
  1044. ATH5K_ERR(sc, "%s: DMA mapping failed\n", __func__);
  1045. dev_kfree_skb(skb);
  1046. return NULL;
  1047. }
  1048. return skb;
  1049. }
  1050. static int
  1051. ath5k_rxbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
  1052. {
  1053. struct ath5k_hw *ah = sc->ah;
  1054. struct sk_buff *skb = bf->skb;
  1055. struct ath5k_desc *ds;
  1056. if (!skb) {
  1057. skb = ath5k_rx_skb_alloc(sc, &bf->skbaddr);
  1058. if (!skb)
  1059. return -ENOMEM;
  1060. bf->skb = skb;
  1061. }
  1062. /*
  1063. * Setup descriptors. For receive we always terminate
  1064. * the descriptor list with a self-linked entry so we'll
  1065. * not get overrun under high load (as can happen with a
  1066. * 5212 when ANI processing enables PHY error frames).
  1067. *
  1068. * To insure the last descriptor is self-linked we create
  1069. * each descriptor as self-linked and add it to the end. As
  1070. * each additional descriptor is added the previous self-linked
  1071. * entry is ``fixed'' naturally. This should be safe even
  1072. * if DMA is happening. When processing RX interrupts we
  1073. * never remove/process the last, self-linked, entry on the
  1074. * descriptor list. This insures the hardware always has
  1075. * someplace to write a new frame.
  1076. */
  1077. ds = bf->desc;
  1078. ds->ds_link = bf->daddr; /* link to self */
  1079. ds->ds_data = bf->skbaddr;
  1080. ah->ah_setup_rx_desc(ah, ds,
  1081. skb_tailroom(skb), /* buffer size */
  1082. 0);
  1083. if (sc->rxlink != NULL)
  1084. *sc->rxlink = bf->daddr;
  1085. sc->rxlink = &ds->ds_link;
  1086. return 0;
  1087. }
  1088. static enum ath5k_pkt_type get_hw_packet_type(struct sk_buff *skb)
  1089. {
  1090. struct ieee80211_hdr *hdr;
  1091. enum ath5k_pkt_type htype;
  1092. __le16 fc;
  1093. hdr = (struct ieee80211_hdr *)skb->data;
  1094. fc = hdr->frame_control;
  1095. if (ieee80211_is_beacon(fc))
  1096. htype = AR5K_PKT_TYPE_BEACON;
  1097. else if (ieee80211_is_probe_resp(fc))
  1098. htype = AR5K_PKT_TYPE_PROBE_RESP;
  1099. else if (ieee80211_is_atim(fc))
  1100. htype = AR5K_PKT_TYPE_ATIM;
  1101. else if (ieee80211_is_pspoll(fc))
  1102. htype = AR5K_PKT_TYPE_PSPOLL;
  1103. else
  1104. htype = AR5K_PKT_TYPE_NORMAL;
  1105. return htype;
  1106. }
  1107. static int
  1108. ath5k_txbuf_setup(struct ath5k_softc *sc, struct ath5k_buf *bf,
  1109. struct ath5k_txq *txq, int padsize)
  1110. {
  1111. struct ath5k_hw *ah = sc->ah;
  1112. struct ath5k_desc *ds = bf->desc;
  1113. struct sk_buff *skb = bf->skb;
  1114. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1115. unsigned int pktlen, flags, keyidx = AR5K_TXKEYIX_INVALID;
  1116. struct ieee80211_rate *rate;
  1117. unsigned int mrr_rate[3], mrr_tries[3];
  1118. int i, ret;
  1119. u16 hw_rate;
  1120. u16 cts_rate = 0;
  1121. u16 duration = 0;
  1122. u8 rc_flags;
  1123. flags = AR5K_TXDESC_INTREQ | AR5K_TXDESC_CLRDMASK;
  1124. /* XXX endianness */
  1125. bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len,
  1126. PCI_DMA_TODEVICE);
  1127. rate = ieee80211_get_tx_rate(sc->hw, info);
  1128. if (info->flags & IEEE80211_TX_CTL_NO_ACK)
  1129. flags |= AR5K_TXDESC_NOACK;
  1130. rc_flags = info->control.rates[0].flags;
  1131. hw_rate = (rc_flags & IEEE80211_TX_RC_USE_SHORT_PREAMBLE) ?
  1132. rate->hw_value_short : rate->hw_value;
  1133. pktlen = skb->len;
  1134. /* FIXME: If we are in g mode and rate is a CCK rate
  1135. * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
  1136. * from tx power (value is in dB units already) */
  1137. if (info->control.hw_key) {
  1138. keyidx = info->control.hw_key->hw_key_idx;
  1139. pktlen += info->control.hw_key->icv_len;
  1140. }
  1141. if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
  1142. flags |= AR5K_TXDESC_RTSENA;
  1143. cts_rate = ieee80211_get_rts_cts_rate(sc->hw, info)->hw_value;
  1144. duration = le16_to_cpu(ieee80211_rts_duration(sc->hw,
  1145. sc->vif, pktlen, info));
  1146. }
  1147. if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
  1148. flags |= AR5K_TXDESC_CTSENA;
  1149. cts_rate = ieee80211_get_rts_cts_rate(sc->hw, info)->hw_value;
  1150. duration = le16_to_cpu(ieee80211_ctstoself_duration(sc->hw,
  1151. sc->vif, pktlen, info));
  1152. }
  1153. ret = ah->ah_setup_tx_desc(ah, ds, pktlen,
  1154. ieee80211_get_hdrlen_from_skb(skb), padsize,
  1155. get_hw_packet_type(skb),
  1156. (sc->power_level * 2),
  1157. hw_rate,
  1158. info->control.rates[0].count, keyidx, ah->ah_tx_ant, flags,
  1159. cts_rate, duration);
  1160. if (ret)
  1161. goto err_unmap;
  1162. memset(mrr_rate, 0, sizeof(mrr_rate));
  1163. memset(mrr_tries, 0, sizeof(mrr_tries));
  1164. for (i = 0; i < 3; i++) {
  1165. rate = ieee80211_get_alt_retry_rate(sc->hw, info, i);
  1166. if (!rate)
  1167. break;
  1168. mrr_rate[i] = rate->hw_value;
  1169. mrr_tries[i] = info->control.rates[i + 1].count;
  1170. }
  1171. ah->ah_setup_mrr_tx_desc(ah, ds,
  1172. mrr_rate[0], mrr_tries[0],
  1173. mrr_rate[1], mrr_tries[1],
  1174. mrr_rate[2], mrr_tries[2]);
  1175. ds->ds_link = 0;
  1176. ds->ds_data = bf->skbaddr;
  1177. spin_lock_bh(&txq->lock);
  1178. list_add_tail(&bf->list, &txq->q);
  1179. if (txq->link == NULL) /* is this first packet? */
  1180. ath5k_hw_set_txdp(ah, txq->qnum, bf->daddr);
  1181. else /* no, so only link it */
  1182. *txq->link = bf->daddr;
  1183. txq->link = &ds->ds_link;
  1184. ath5k_hw_start_tx_dma(ah, txq->qnum);
  1185. mmiowb();
  1186. spin_unlock_bh(&txq->lock);
  1187. return 0;
  1188. err_unmap:
  1189. pci_unmap_single(sc->pdev, bf->skbaddr, skb->len, PCI_DMA_TODEVICE);
  1190. return ret;
  1191. }
  1192. /*******************\
  1193. * Descriptors setup *
  1194. \*******************/
  1195. static int
  1196. ath5k_desc_alloc(struct ath5k_softc *sc, struct pci_dev *pdev)
  1197. {
  1198. struct ath5k_desc *ds;
  1199. struct ath5k_buf *bf;
  1200. dma_addr_t da;
  1201. unsigned int i;
  1202. int ret;
  1203. /* allocate descriptors */
  1204. sc->desc_len = sizeof(struct ath5k_desc) *
  1205. (ATH_TXBUF + ATH_RXBUF + ATH_BCBUF + 1);
  1206. sc->desc = pci_alloc_consistent(pdev, sc->desc_len, &sc->desc_daddr);
  1207. if (sc->desc == NULL) {
  1208. ATH5K_ERR(sc, "can't allocate descriptors\n");
  1209. ret = -ENOMEM;
  1210. goto err;
  1211. }
  1212. ds = sc->desc;
  1213. da = sc->desc_daddr;
  1214. ATH5K_DBG(sc, ATH5K_DEBUG_ANY, "DMA map: %p (%zu) -> %llx\n",
  1215. ds, sc->desc_len, (unsigned long long)sc->desc_daddr);
  1216. bf = kcalloc(1 + ATH_TXBUF + ATH_RXBUF + ATH_BCBUF,
  1217. sizeof(struct ath5k_buf), GFP_KERNEL);
  1218. if (bf == NULL) {
  1219. ATH5K_ERR(sc, "can't allocate bufptr\n");
  1220. ret = -ENOMEM;
  1221. goto err_free;
  1222. }
  1223. sc->bufptr = bf;
  1224. INIT_LIST_HEAD(&sc->rxbuf);
  1225. for (i = 0; i < ATH_RXBUF; i++, bf++, ds++, da += sizeof(*ds)) {
  1226. bf->desc = ds;
  1227. bf->daddr = da;
  1228. list_add_tail(&bf->list, &sc->rxbuf);
  1229. }
  1230. INIT_LIST_HEAD(&sc->txbuf);
  1231. sc->txbuf_len = ATH_TXBUF;
  1232. for (i = 0; i < ATH_TXBUF; i++, bf++, ds++,
  1233. da += sizeof(*ds)) {
  1234. bf->desc = ds;
  1235. bf->daddr = da;
  1236. list_add_tail(&bf->list, &sc->txbuf);
  1237. }
  1238. /* beacon buffer */
  1239. bf->desc = ds;
  1240. bf->daddr = da;
  1241. sc->bbuf = bf;
  1242. return 0;
  1243. err_free:
  1244. pci_free_consistent(pdev, sc->desc_len, sc->desc, sc->desc_daddr);
  1245. err:
  1246. sc->desc = NULL;
  1247. return ret;
  1248. }
  1249. static void
  1250. ath5k_desc_free(struct ath5k_softc *sc, struct pci_dev *pdev)
  1251. {
  1252. struct ath5k_buf *bf;
  1253. ath5k_txbuf_free(sc, sc->bbuf);
  1254. list_for_each_entry(bf, &sc->txbuf, list)
  1255. ath5k_txbuf_free(sc, bf);
  1256. list_for_each_entry(bf, &sc->rxbuf, list)
  1257. ath5k_rxbuf_free(sc, bf);
  1258. /* Free memory associated with all descriptors */
  1259. pci_free_consistent(pdev, sc->desc_len, sc->desc, sc->desc_daddr);
  1260. kfree(sc->bufptr);
  1261. sc->bufptr = NULL;
  1262. }
  1263. /**************\
  1264. * Queues setup *
  1265. \**************/
  1266. static struct ath5k_txq *
  1267. ath5k_txq_setup(struct ath5k_softc *sc,
  1268. int qtype, int subtype)
  1269. {
  1270. struct ath5k_hw *ah = sc->ah;
  1271. struct ath5k_txq *txq;
  1272. struct ath5k_txq_info qi = {
  1273. .tqi_subtype = subtype,
  1274. .tqi_aifs = AR5K_TXQ_USEDEFAULT,
  1275. .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
  1276. .tqi_cw_max = AR5K_TXQ_USEDEFAULT
  1277. };
  1278. int qnum;
  1279. /*
  1280. * Enable interrupts only for EOL and DESC conditions.
  1281. * We mark tx descriptors to receive a DESC interrupt
  1282. * when a tx queue gets deep; otherwise waiting for the
  1283. * EOL to reap descriptors. Note that this is done to
  1284. * reduce interrupt load and this only defers reaping
  1285. * descriptors, never transmitting frames. Aside from
  1286. * reducing interrupts this also permits more concurrency.
  1287. * The only potential downside is if the tx queue backs
  1288. * up in which case the top half of the kernel may backup
  1289. * due to a lack of tx descriptors.
  1290. */
  1291. qi.tqi_flags = AR5K_TXQ_FLAG_TXEOLINT_ENABLE |
  1292. AR5K_TXQ_FLAG_TXDESCINT_ENABLE;
  1293. qnum = ath5k_hw_setup_tx_queue(ah, qtype, &qi);
  1294. if (qnum < 0) {
  1295. /*
  1296. * NB: don't print a message, this happens
  1297. * normally on parts with too few tx queues
  1298. */
  1299. return ERR_PTR(qnum);
  1300. }
  1301. if (qnum >= ARRAY_SIZE(sc->txqs)) {
  1302. ATH5K_ERR(sc, "hw qnum %u out of range, max %tu!\n",
  1303. qnum, ARRAY_SIZE(sc->txqs));
  1304. ath5k_hw_release_tx_queue(ah, qnum);
  1305. return ERR_PTR(-EINVAL);
  1306. }
  1307. txq = &sc->txqs[qnum];
  1308. if (!txq->setup) {
  1309. txq->qnum = qnum;
  1310. txq->link = NULL;
  1311. INIT_LIST_HEAD(&txq->q);
  1312. spin_lock_init(&txq->lock);
  1313. txq->setup = true;
  1314. }
  1315. return &sc->txqs[qnum];
  1316. }
  1317. static int
  1318. ath5k_beaconq_setup(struct ath5k_hw *ah)
  1319. {
  1320. struct ath5k_txq_info qi = {
  1321. .tqi_aifs = AR5K_TXQ_USEDEFAULT,
  1322. .tqi_cw_min = AR5K_TXQ_USEDEFAULT,
  1323. .tqi_cw_max = AR5K_TXQ_USEDEFAULT,
  1324. /* NB: for dynamic turbo, don't enable any other interrupts */
  1325. .tqi_flags = AR5K_TXQ_FLAG_TXDESCINT_ENABLE
  1326. };
  1327. return ath5k_hw_setup_tx_queue(ah, AR5K_TX_QUEUE_BEACON, &qi);
  1328. }
  1329. static int
  1330. ath5k_beaconq_config(struct ath5k_softc *sc)
  1331. {
  1332. struct ath5k_hw *ah = sc->ah;
  1333. struct ath5k_txq_info qi;
  1334. int ret;
  1335. ret = ath5k_hw_get_tx_queueprops(ah, sc->bhalq, &qi);
  1336. if (ret)
  1337. goto err;
  1338. if (sc->opmode == NL80211_IFTYPE_AP ||
  1339. sc->opmode == NL80211_IFTYPE_MESH_POINT) {
  1340. /*
  1341. * Always burst out beacon and CAB traffic
  1342. * (aifs = cwmin = cwmax = 0)
  1343. */
  1344. qi.tqi_aifs = 0;
  1345. qi.tqi_cw_min = 0;
  1346. qi.tqi_cw_max = 0;
  1347. } else if (sc->opmode == NL80211_IFTYPE_ADHOC) {
  1348. /*
  1349. * Adhoc mode; backoff between 0 and (2 * cw_min).
  1350. */
  1351. qi.tqi_aifs = 0;
  1352. qi.tqi_cw_min = 0;
  1353. qi.tqi_cw_max = 2 * ah->ah_cw_min;
  1354. }
  1355. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
  1356. "beacon queueprops tqi_aifs:%d tqi_cw_min:%d tqi_cw_max:%d\n",
  1357. qi.tqi_aifs, qi.tqi_cw_min, qi.tqi_cw_max);
  1358. ret = ath5k_hw_set_tx_queueprops(ah, sc->bhalq, &qi);
  1359. if (ret) {
  1360. ATH5K_ERR(sc, "%s: unable to update parameters for beacon "
  1361. "hardware queue!\n", __func__);
  1362. goto err;
  1363. }
  1364. ret = ath5k_hw_reset_tx_queue(ah, sc->bhalq); /* push to h/w */
  1365. if (ret)
  1366. goto err;
  1367. /* reconfigure cabq with ready time to 80% of beacon_interval */
  1368. ret = ath5k_hw_get_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi);
  1369. if (ret)
  1370. goto err;
  1371. qi.tqi_ready_time = (sc->bintval * 80) / 100;
  1372. ret = ath5k_hw_set_tx_queueprops(ah, AR5K_TX_QUEUE_ID_CAB, &qi);
  1373. if (ret)
  1374. goto err;
  1375. ret = ath5k_hw_reset_tx_queue(ah, AR5K_TX_QUEUE_ID_CAB);
  1376. err:
  1377. return ret;
  1378. }
  1379. static void
  1380. ath5k_txq_drainq(struct ath5k_softc *sc, struct ath5k_txq *txq)
  1381. {
  1382. struct ath5k_buf *bf, *bf0;
  1383. /*
  1384. * NB: this assumes output has been stopped and
  1385. * we do not need to block ath5k_tx_tasklet
  1386. */
  1387. spin_lock_bh(&txq->lock);
  1388. list_for_each_entry_safe(bf, bf0, &txq->q, list) {
  1389. ath5k_debug_printtxbuf(sc, bf);
  1390. ath5k_txbuf_free(sc, bf);
  1391. spin_lock_bh(&sc->txbuflock);
  1392. list_move_tail(&bf->list, &sc->txbuf);
  1393. sc->txbuf_len++;
  1394. spin_unlock_bh(&sc->txbuflock);
  1395. }
  1396. txq->link = NULL;
  1397. spin_unlock_bh(&txq->lock);
  1398. }
  1399. /*
  1400. * Drain the transmit queues and reclaim resources.
  1401. */
  1402. static void
  1403. ath5k_txq_cleanup(struct ath5k_softc *sc)
  1404. {
  1405. struct ath5k_hw *ah = sc->ah;
  1406. unsigned int i;
  1407. /* XXX return value */
  1408. if (likely(!test_bit(ATH_STAT_INVALID, sc->status))) {
  1409. /* don't touch the hardware if marked invalid */
  1410. ath5k_hw_stop_tx_dma(ah, sc->bhalq);
  1411. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "beacon queue %x\n",
  1412. ath5k_hw_get_txdp(ah, sc->bhalq));
  1413. for (i = 0; i < ARRAY_SIZE(sc->txqs); i++)
  1414. if (sc->txqs[i].setup) {
  1415. ath5k_hw_stop_tx_dma(ah, sc->txqs[i].qnum);
  1416. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "txq [%u] %x, "
  1417. "link %p\n",
  1418. sc->txqs[i].qnum,
  1419. ath5k_hw_get_txdp(ah,
  1420. sc->txqs[i].qnum),
  1421. sc->txqs[i].link);
  1422. }
  1423. }
  1424. ieee80211_wake_queues(sc->hw); /* XXX move to callers */
  1425. for (i = 0; i < ARRAY_SIZE(sc->txqs); i++)
  1426. if (sc->txqs[i].setup)
  1427. ath5k_txq_drainq(sc, &sc->txqs[i]);
  1428. }
  1429. static void
  1430. ath5k_txq_release(struct ath5k_softc *sc)
  1431. {
  1432. struct ath5k_txq *txq = sc->txqs;
  1433. unsigned int i;
  1434. for (i = 0; i < ARRAY_SIZE(sc->txqs); i++, txq++)
  1435. if (txq->setup) {
  1436. ath5k_hw_release_tx_queue(sc->ah, txq->qnum);
  1437. txq->setup = false;
  1438. }
  1439. }
  1440. /*************\
  1441. * RX Handling *
  1442. \*************/
  1443. /*
  1444. * Enable the receive h/w following a reset.
  1445. */
  1446. static int
  1447. ath5k_rx_start(struct ath5k_softc *sc)
  1448. {
  1449. struct ath5k_hw *ah = sc->ah;
  1450. struct ath_common *common = ath5k_hw_common(ah);
  1451. struct ath5k_buf *bf;
  1452. int ret;
  1453. common->rx_bufsize = roundup(IEEE80211_MAX_LEN, common->cachelsz);
  1454. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "cachelsz %u rx_bufsize %u\n",
  1455. common->cachelsz, common->rx_bufsize);
  1456. spin_lock_bh(&sc->rxbuflock);
  1457. sc->rxlink = NULL;
  1458. list_for_each_entry(bf, &sc->rxbuf, list) {
  1459. ret = ath5k_rxbuf_setup(sc, bf);
  1460. if (ret != 0) {
  1461. spin_unlock_bh(&sc->rxbuflock);
  1462. goto err;
  1463. }
  1464. }
  1465. bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list);
  1466. ath5k_hw_set_rxdp(ah, bf->daddr);
  1467. spin_unlock_bh(&sc->rxbuflock);
  1468. ath5k_hw_start_rx_dma(ah); /* enable recv descriptors */
  1469. ath5k_mode_setup(sc); /* set filters, etc. */
  1470. ath5k_hw_start_rx_pcu(ah); /* re-enable PCU/DMA engine */
  1471. return 0;
  1472. err:
  1473. return ret;
  1474. }
  1475. /*
  1476. * Disable the receive h/w in preparation for a reset.
  1477. */
  1478. static void
  1479. ath5k_rx_stop(struct ath5k_softc *sc)
  1480. {
  1481. struct ath5k_hw *ah = sc->ah;
  1482. ath5k_hw_stop_rx_pcu(ah); /* disable PCU */
  1483. ath5k_hw_set_rx_filter(ah, 0); /* clear recv filter */
  1484. ath5k_hw_stop_rx_dma(ah); /* disable DMA engine */
  1485. ath5k_debug_printrxbuffs(sc, ah);
  1486. sc->rxlink = NULL; /* just in case */
  1487. }
  1488. static unsigned int
  1489. ath5k_rx_decrypted(struct ath5k_softc *sc, struct ath5k_desc *ds,
  1490. struct sk_buff *skb, struct ath5k_rx_status *rs)
  1491. {
  1492. struct ath5k_hw *ah = sc->ah;
  1493. struct ath_common *common = ath5k_hw_common(ah);
  1494. struct ieee80211_hdr *hdr = (void *)skb->data;
  1495. unsigned int keyix, hlen;
  1496. if (!(rs->rs_status & AR5K_RXERR_DECRYPT) &&
  1497. rs->rs_keyix != AR5K_RXKEYIX_INVALID)
  1498. return RX_FLAG_DECRYPTED;
  1499. /* Apparently when a default key is used to decrypt the packet
  1500. the hw does not set the index used to decrypt. In such cases
  1501. get the index from the packet. */
  1502. hlen = ieee80211_hdrlen(hdr->frame_control);
  1503. if (ieee80211_has_protected(hdr->frame_control) &&
  1504. !(rs->rs_status & AR5K_RXERR_DECRYPT) &&
  1505. skb->len >= hlen + 4) {
  1506. keyix = skb->data[hlen + 3] >> 6;
  1507. if (test_bit(keyix, common->keymap))
  1508. return RX_FLAG_DECRYPTED;
  1509. }
  1510. return 0;
  1511. }
  1512. static void
  1513. ath5k_check_ibss_tsf(struct ath5k_softc *sc, struct sk_buff *skb,
  1514. struct ieee80211_rx_status *rxs)
  1515. {
  1516. struct ath_common *common = ath5k_hw_common(sc->ah);
  1517. u64 tsf, bc_tstamp;
  1518. u32 hw_tu;
  1519. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)skb->data;
  1520. if (ieee80211_is_beacon(mgmt->frame_control) &&
  1521. le16_to_cpu(mgmt->u.beacon.capab_info) & WLAN_CAPABILITY_IBSS &&
  1522. memcmp(mgmt->bssid, common->curbssid, ETH_ALEN) == 0) {
  1523. /*
  1524. * Received an IBSS beacon with the same BSSID. Hardware *must*
  1525. * have updated the local TSF. We have to work around various
  1526. * hardware bugs, though...
  1527. */
  1528. tsf = ath5k_hw_get_tsf64(sc->ah);
  1529. bc_tstamp = le64_to_cpu(mgmt->u.beacon.timestamp);
  1530. hw_tu = TSF_TO_TU(tsf);
  1531. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  1532. "beacon %llx mactime %llx (diff %lld) tsf now %llx\n",
  1533. (unsigned long long)bc_tstamp,
  1534. (unsigned long long)rxs->mactime,
  1535. (unsigned long long)(rxs->mactime - bc_tstamp),
  1536. (unsigned long long)tsf);
  1537. /*
  1538. * Sometimes the HW will give us a wrong tstamp in the rx
  1539. * status, causing the timestamp extension to go wrong.
  1540. * (This seems to happen especially with beacon frames bigger
  1541. * than 78 byte (incl. FCS))
  1542. * But we know that the receive timestamp must be later than the
  1543. * timestamp of the beacon since HW must have synced to that.
  1544. *
  1545. * NOTE: here we assume mactime to be after the frame was
  1546. * received, not like mac80211 which defines it at the start.
  1547. */
  1548. if (bc_tstamp > rxs->mactime) {
  1549. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  1550. "fixing mactime from %llx to %llx\n",
  1551. (unsigned long long)rxs->mactime,
  1552. (unsigned long long)tsf);
  1553. rxs->mactime = tsf;
  1554. }
  1555. /*
  1556. * Local TSF might have moved higher than our beacon timers,
  1557. * in that case we have to update them to continue sending
  1558. * beacons. This also takes care of synchronizing beacon sending
  1559. * times with other stations.
  1560. */
  1561. if (hw_tu >= sc->nexttbtt)
  1562. ath5k_beacon_update_timers(sc, bc_tstamp);
  1563. }
  1564. }
  1565. /*
  1566. * Compute padding position. skb must contains an IEEE 802.11 frame
  1567. */
  1568. static int ath5k_common_padpos(struct sk_buff *skb)
  1569. {
  1570. struct ieee80211_hdr * hdr = (struct ieee80211_hdr *)skb->data;
  1571. __le16 frame_control = hdr->frame_control;
  1572. int padpos = 24;
  1573. if (ieee80211_has_a4(frame_control)) {
  1574. padpos += ETH_ALEN;
  1575. }
  1576. if (ieee80211_is_data_qos(frame_control)) {
  1577. padpos += IEEE80211_QOS_CTL_LEN;
  1578. }
  1579. return padpos;
  1580. }
  1581. /*
  1582. * This function expects a 802.11 frame and returns the number of
  1583. * bytes added, or -1 if we don't have enought header room.
  1584. */
  1585. static int ath5k_add_padding(struct sk_buff *skb)
  1586. {
  1587. int padpos = ath5k_common_padpos(skb);
  1588. int padsize = padpos & 3;
  1589. if (padsize && skb->len>padpos) {
  1590. if (skb_headroom(skb) < padsize)
  1591. return -1;
  1592. skb_push(skb, padsize);
  1593. memmove(skb->data, skb->data+padsize, padpos);
  1594. return padsize;
  1595. }
  1596. return 0;
  1597. }
  1598. /*
  1599. * This function expects a 802.11 frame and returns the number of
  1600. * bytes removed
  1601. */
  1602. static int ath5k_remove_padding(struct sk_buff *skb)
  1603. {
  1604. int padpos = ath5k_common_padpos(skb);
  1605. int padsize = padpos & 3;
  1606. if (padsize && skb->len>=padpos+padsize) {
  1607. memmove(skb->data + padsize, skb->data, padpos);
  1608. skb_pull(skb, padsize);
  1609. return padsize;
  1610. }
  1611. return 0;
  1612. }
  1613. static void
  1614. ath5k_tasklet_rx(unsigned long data)
  1615. {
  1616. struct ieee80211_rx_status *rxs;
  1617. struct ath5k_rx_status rs = {};
  1618. struct sk_buff *skb, *next_skb;
  1619. dma_addr_t next_skb_addr;
  1620. struct ath5k_softc *sc = (void *)data;
  1621. struct ath5k_hw *ah = sc->ah;
  1622. struct ath_common *common = ath5k_hw_common(ah);
  1623. struct ath5k_buf *bf;
  1624. struct ath5k_desc *ds;
  1625. int ret;
  1626. int rx_flag;
  1627. spin_lock(&sc->rxbuflock);
  1628. if (list_empty(&sc->rxbuf)) {
  1629. ATH5K_WARN(sc, "empty rx buf pool\n");
  1630. goto unlock;
  1631. }
  1632. do {
  1633. rx_flag = 0;
  1634. bf = list_first_entry(&sc->rxbuf, struct ath5k_buf, list);
  1635. BUG_ON(bf->skb == NULL);
  1636. skb = bf->skb;
  1637. ds = bf->desc;
  1638. /* bail if HW is still using self-linked descriptor */
  1639. if (ath5k_hw_get_rxdp(sc->ah) == bf->daddr)
  1640. break;
  1641. ret = sc->ah->ah_proc_rx_desc(sc->ah, ds, &rs);
  1642. if (unlikely(ret == -EINPROGRESS))
  1643. break;
  1644. else if (unlikely(ret)) {
  1645. ATH5K_ERR(sc, "error in processing rx descriptor\n");
  1646. sc->stats.rxerr_proc++;
  1647. spin_unlock(&sc->rxbuflock);
  1648. return;
  1649. }
  1650. sc->stats.rx_all_count++;
  1651. if (unlikely(rs.rs_more)) {
  1652. ATH5K_WARN(sc, "unsupported jumbo\n");
  1653. sc->stats.rxerr_jumbo++;
  1654. goto next;
  1655. }
  1656. if (unlikely(rs.rs_status)) {
  1657. if (rs.rs_status & AR5K_RXERR_CRC)
  1658. sc->stats.rxerr_crc++;
  1659. if (rs.rs_status & AR5K_RXERR_FIFO)
  1660. sc->stats.rxerr_fifo++;
  1661. if (rs.rs_status & AR5K_RXERR_PHY) {
  1662. sc->stats.rxerr_phy++;
  1663. goto next;
  1664. }
  1665. if (rs.rs_status & AR5K_RXERR_DECRYPT) {
  1666. /*
  1667. * Decrypt error. If the error occurred
  1668. * because there was no hardware key, then
  1669. * let the frame through so the upper layers
  1670. * can process it. This is necessary for 5210
  1671. * parts which have no way to setup a ``clear''
  1672. * key cache entry.
  1673. *
  1674. * XXX do key cache faulting
  1675. */
  1676. sc->stats.rxerr_decrypt++;
  1677. if (rs.rs_keyix == AR5K_RXKEYIX_INVALID &&
  1678. !(rs.rs_status & AR5K_RXERR_CRC))
  1679. goto accept;
  1680. }
  1681. if (rs.rs_status & AR5K_RXERR_MIC) {
  1682. rx_flag |= RX_FLAG_MMIC_ERROR;
  1683. sc->stats.rxerr_mic++;
  1684. goto accept;
  1685. }
  1686. /* let crypto-error packets fall through in MNTR */
  1687. if ((rs.rs_status &
  1688. ~(AR5K_RXERR_DECRYPT|AR5K_RXERR_MIC)) ||
  1689. sc->opmode != NL80211_IFTYPE_MONITOR)
  1690. goto next;
  1691. }
  1692. accept:
  1693. next_skb = ath5k_rx_skb_alloc(sc, &next_skb_addr);
  1694. /*
  1695. * If we can't replace bf->skb with a new skb under memory
  1696. * pressure, just skip this packet
  1697. */
  1698. if (!next_skb)
  1699. goto next;
  1700. pci_unmap_single(sc->pdev, bf->skbaddr, common->rx_bufsize,
  1701. PCI_DMA_FROMDEVICE);
  1702. skb_put(skb, rs.rs_datalen);
  1703. /* The MAC header is padded to have 32-bit boundary if the
  1704. * packet payload is non-zero. The general calculation for
  1705. * padsize would take into account odd header lengths:
  1706. * padsize = (4 - hdrlen % 4) % 4; However, since only
  1707. * even-length headers are used, padding can only be 0 or 2
  1708. * bytes and we can optimize this a bit. In addition, we must
  1709. * not try to remove padding from short control frames that do
  1710. * not have payload. */
  1711. ath5k_remove_padding(skb);
  1712. rxs = IEEE80211_SKB_RXCB(skb);
  1713. /*
  1714. * always extend the mac timestamp, since this information is
  1715. * also needed for proper IBSS merging.
  1716. *
  1717. * XXX: it might be too late to do it here, since rs_tstamp is
  1718. * 15bit only. that means TSF extension has to be done within
  1719. * 32768usec (about 32ms). it might be necessary to move this to
  1720. * the interrupt handler, like it is done in madwifi.
  1721. *
  1722. * Unfortunately we don't know when the hardware takes the rx
  1723. * timestamp (beginning of phy frame, data frame, end of rx?).
  1724. * The only thing we know is that it is hardware specific...
  1725. * On AR5213 it seems the rx timestamp is at the end of the
  1726. * frame, but i'm not sure.
  1727. *
  1728. * NOTE: mac80211 defines mactime at the beginning of the first
  1729. * data symbol. Since we don't have any time references it's
  1730. * impossible to comply to that. This affects IBSS merge only
  1731. * right now, so it's not too bad...
  1732. */
  1733. rxs->mactime = ath5k_extend_tsf(sc->ah, rs.rs_tstamp);
  1734. rxs->flag = rx_flag | RX_FLAG_TSFT;
  1735. rxs->freq = sc->curchan->center_freq;
  1736. rxs->band = sc->curband->band;
  1737. rxs->noise = sc->ah->ah_noise_floor;
  1738. rxs->signal = rxs->noise + rs.rs_rssi;
  1739. rxs->antenna = rs.rs_antenna;
  1740. if (rs.rs_antenna > 0 && rs.rs_antenna < 5)
  1741. sc->stats.antenna_rx[rs.rs_antenna]++;
  1742. else
  1743. sc->stats.antenna_rx[0]++; /* invalid */
  1744. rxs->rate_idx = ath5k_hw_to_driver_rix(sc, rs.rs_rate);
  1745. rxs->flag |= ath5k_rx_decrypted(sc, ds, skb, &rs);
  1746. if (rxs->rate_idx >= 0 && rs.rs_rate ==
  1747. sc->curband->bitrates[rxs->rate_idx].hw_value_short)
  1748. rxs->flag |= RX_FLAG_SHORTPRE;
  1749. ath5k_debug_dump_skb(sc, skb, "RX ", 0);
  1750. /* check beacons in IBSS mode */
  1751. if (sc->opmode == NL80211_IFTYPE_ADHOC)
  1752. ath5k_check_ibss_tsf(sc, skb, rxs);
  1753. ieee80211_rx(sc->hw, skb);
  1754. bf->skb = next_skb;
  1755. bf->skbaddr = next_skb_addr;
  1756. next:
  1757. list_move_tail(&bf->list, &sc->rxbuf);
  1758. } while (ath5k_rxbuf_setup(sc, bf) == 0);
  1759. unlock:
  1760. spin_unlock(&sc->rxbuflock);
  1761. }
  1762. /*************\
  1763. * TX Handling *
  1764. \*************/
  1765. static void
  1766. ath5k_tx_processq(struct ath5k_softc *sc, struct ath5k_txq *txq)
  1767. {
  1768. struct ath5k_tx_status ts = {};
  1769. struct ath5k_buf *bf, *bf0;
  1770. struct ath5k_desc *ds;
  1771. struct sk_buff *skb;
  1772. struct ieee80211_tx_info *info;
  1773. int i, ret;
  1774. spin_lock(&txq->lock);
  1775. list_for_each_entry_safe(bf, bf0, &txq->q, list) {
  1776. ds = bf->desc;
  1777. ret = sc->ah->ah_proc_tx_desc(sc->ah, ds, &ts);
  1778. if (unlikely(ret == -EINPROGRESS))
  1779. break;
  1780. else if (unlikely(ret)) {
  1781. ATH5K_ERR(sc, "error %d while processing queue %u\n",
  1782. ret, txq->qnum);
  1783. break;
  1784. }
  1785. sc->stats.tx_all_count++;
  1786. skb = bf->skb;
  1787. info = IEEE80211_SKB_CB(skb);
  1788. bf->skb = NULL;
  1789. pci_unmap_single(sc->pdev, bf->skbaddr, skb->len,
  1790. PCI_DMA_TODEVICE);
  1791. ieee80211_tx_info_clear_status(info);
  1792. for (i = 0; i < 4; i++) {
  1793. struct ieee80211_tx_rate *r =
  1794. &info->status.rates[i];
  1795. if (ts.ts_rate[i]) {
  1796. r->idx = ath5k_hw_to_driver_rix(sc, ts.ts_rate[i]);
  1797. r->count = ts.ts_retry[i];
  1798. } else {
  1799. r->idx = -1;
  1800. r->count = 0;
  1801. }
  1802. }
  1803. /* count the successful attempt as well */
  1804. info->status.rates[ts.ts_final_idx].count++;
  1805. if (unlikely(ts.ts_status)) {
  1806. sc->ll_stats.dot11ACKFailureCount++;
  1807. if (ts.ts_status & AR5K_TXERR_FILT) {
  1808. info->flags |= IEEE80211_TX_STAT_TX_FILTERED;
  1809. sc->stats.txerr_filt++;
  1810. }
  1811. if (ts.ts_status & AR5K_TXERR_XRETRY)
  1812. sc->stats.txerr_retry++;
  1813. if (ts.ts_status & AR5K_TXERR_FIFO)
  1814. sc->stats.txerr_fifo++;
  1815. } else {
  1816. info->flags |= IEEE80211_TX_STAT_ACK;
  1817. info->status.ack_signal = ts.ts_rssi;
  1818. }
  1819. /*
  1820. * Remove MAC header padding before giving the frame
  1821. * back to mac80211.
  1822. */
  1823. ath5k_remove_padding(skb);
  1824. if (ts.ts_antenna > 0 && ts.ts_antenna < 5)
  1825. sc->stats.antenna_tx[ts.ts_antenna]++;
  1826. else
  1827. sc->stats.antenna_tx[0]++; /* invalid */
  1828. ieee80211_tx_status(sc->hw, skb);
  1829. spin_lock(&sc->txbuflock);
  1830. list_move_tail(&bf->list, &sc->txbuf);
  1831. sc->txbuf_len++;
  1832. spin_unlock(&sc->txbuflock);
  1833. }
  1834. if (likely(list_empty(&txq->q)))
  1835. txq->link = NULL;
  1836. spin_unlock(&txq->lock);
  1837. if (sc->txbuf_len > ATH_TXBUF / 5)
  1838. ieee80211_wake_queues(sc->hw);
  1839. }
  1840. static void
  1841. ath5k_tasklet_tx(unsigned long data)
  1842. {
  1843. int i;
  1844. struct ath5k_softc *sc = (void *)data;
  1845. for (i=0; i < AR5K_NUM_TX_QUEUES; i++)
  1846. if (sc->txqs[i].setup && (sc->ah->ah_txq_isr & BIT(i)))
  1847. ath5k_tx_processq(sc, &sc->txqs[i]);
  1848. }
  1849. /*****************\
  1850. * Beacon handling *
  1851. \*****************/
  1852. /*
  1853. * Setup the beacon frame for transmit.
  1854. */
  1855. static int
  1856. ath5k_beacon_setup(struct ath5k_softc *sc, struct ath5k_buf *bf)
  1857. {
  1858. struct sk_buff *skb = bf->skb;
  1859. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1860. struct ath5k_hw *ah = sc->ah;
  1861. struct ath5k_desc *ds;
  1862. int ret = 0;
  1863. u8 antenna;
  1864. u32 flags;
  1865. const int padsize = 0;
  1866. bf->skbaddr = pci_map_single(sc->pdev, skb->data, skb->len,
  1867. PCI_DMA_TODEVICE);
  1868. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "skb %p [data %p len %u] "
  1869. "skbaddr %llx\n", skb, skb->data, skb->len,
  1870. (unsigned long long)bf->skbaddr);
  1871. if (pci_dma_mapping_error(sc->pdev, bf->skbaddr)) {
  1872. ATH5K_ERR(sc, "beacon DMA mapping failed\n");
  1873. return -EIO;
  1874. }
  1875. ds = bf->desc;
  1876. antenna = ah->ah_tx_ant;
  1877. flags = AR5K_TXDESC_NOACK;
  1878. if (sc->opmode == NL80211_IFTYPE_ADHOC && ath5k_hw_hasveol(ah)) {
  1879. ds->ds_link = bf->daddr; /* self-linked */
  1880. flags |= AR5K_TXDESC_VEOL;
  1881. } else
  1882. ds->ds_link = 0;
  1883. /*
  1884. * If we use multiple antennas on AP and use
  1885. * the Sectored AP scenario, switch antenna every
  1886. * 4 beacons to make sure everybody hears our AP.
  1887. * When a client tries to associate, hw will keep
  1888. * track of the tx antenna to be used for this client
  1889. * automaticaly, based on ACKed packets.
  1890. *
  1891. * Note: AP still listens and transmits RTS on the
  1892. * default antenna which is supposed to be an omni.
  1893. *
  1894. * Note2: On sectored scenarios it's possible to have
  1895. * multiple antennas (1omni -the default- and 14 sectors)
  1896. * so if we choose to actually support this mode we need
  1897. * to allow user to set how many antennas we have and tweak
  1898. * the code below to send beacons on all of them.
  1899. */
  1900. if (ah->ah_ant_mode == AR5K_ANTMODE_SECTOR_AP)
  1901. antenna = sc->bsent & 4 ? 2 : 1;
  1902. /* FIXME: If we are in g mode and rate is a CCK rate
  1903. * subtract ah->ah_txpower.txp_cck_ofdm_pwr_delta
  1904. * from tx power (value is in dB units already) */
  1905. ds->ds_data = bf->skbaddr;
  1906. ret = ah->ah_setup_tx_desc(ah, ds, skb->len,
  1907. ieee80211_get_hdrlen_from_skb(skb), padsize,
  1908. AR5K_PKT_TYPE_BEACON, (sc->power_level * 2),
  1909. ieee80211_get_tx_rate(sc->hw, info)->hw_value,
  1910. 1, AR5K_TXKEYIX_INVALID,
  1911. antenna, flags, 0, 0);
  1912. if (ret)
  1913. goto err_unmap;
  1914. return 0;
  1915. err_unmap:
  1916. pci_unmap_single(sc->pdev, bf->skbaddr, skb->len, PCI_DMA_TODEVICE);
  1917. return ret;
  1918. }
  1919. /*
  1920. * Transmit a beacon frame at SWBA. Dynamic updates to the
  1921. * frame contents are done as needed and the slot time is
  1922. * also adjusted based on current state.
  1923. *
  1924. * This is called from software irq context (beacontq or restq
  1925. * tasklets) or user context from ath5k_beacon_config.
  1926. */
  1927. static void
  1928. ath5k_beacon_send(struct ath5k_softc *sc)
  1929. {
  1930. struct ath5k_buf *bf = sc->bbuf;
  1931. struct ath5k_hw *ah = sc->ah;
  1932. struct sk_buff *skb;
  1933. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "in beacon_send\n");
  1934. if (unlikely(bf->skb == NULL || sc->opmode == NL80211_IFTYPE_STATION ||
  1935. sc->opmode == NL80211_IFTYPE_MONITOR)) {
  1936. ATH5K_WARN(sc, "bf=%p bf_skb=%p\n", bf, bf ? bf->skb : NULL);
  1937. return;
  1938. }
  1939. /*
  1940. * Check if the previous beacon has gone out. If
  1941. * not don't don't try to post another, skip this
  1942. * period and wait for the next. Missed beacons
  1943. * indicate a problem and should not occur. If we
  1944. * miss too many consecutive beacons reset the device.
  1945. */
  1946. if (unlikely(ath5k_hw_num_tx_pending(ah, sc->bhalq) != 0)) {
  1947. sc->bmisscount++;
  1948. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
  1949. "missed %u consecutive beacons\n", sc->bmisscount);
  1950. if (sc->bmisscount > 10) { /* NB: 10 is a guess */
  1951. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
  1952. "stuck beacon time (%u missed)\n",
  1953. sc->bmisscount);
  1954. tasklet_schedule(&sc->restq);
  1955. }
  1956. return;
  1957. }
  1958. if (unlikely(sc->bmisscount != 0)) {
  1959. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
  1960. "resume beacon xmit after %u misses\n",
  1961. sc->bmisscount);
  1962. sc->bmisscount = 0;
  1963. }
  1964. /*
  1965. * Stop any current dma and put the new frame on the queue.
  1966. * This should never fail since we check above that no frames
  1967. * are still pending on the queue.
  1968. */
  1969. if (unlikely(ath5k_hw_stop_tx_dma(ah, sc->bhalq))) {
  1970. ATH5K_WARN(sc, "beacon queue %u didn't start/stop ?\n", sc->bhalq);
  1971. /* NB: hw still stops DMA, so proceed */
  1972. }
  1973. /* refresh the beacon for AP mode */
  1974. if (sc->opmode == NL80211_IFTYPE_AP)
  1975. ath5k_beacon_update(sc->hw, sc->vif);
  1976. ath5k_hw_set_txdp(ah, sc->bhalq, bf->daddr);
  1977. ath5k_hw_start_tx_dma(ah, sc->bhalq);
  1978. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON, "TXDP[%u] = %llx (%p)\n",
  1979. sc->bhalq, (unsigned long long)bf->daddr, bf->desc);
  1980. skb = ieee80211_get_buffered_bc(sc->hw, sc->vif);
  1981. while (skb) {
  1982. ath5k_tx_queue(sc->hw, skb, sc->cabq);
  1983. skb = ieee80211_get_buffered_bc(sc->hw, sc->vif);
  1984. }
  1985. sc->bsent++;
  1986. }
  1987. /**
  1988. * ath5k_beacon_update_timers - update beacon timers
  1989. *
  1990. * @sc: struct ath5k_softc pointer we are operating on
  1991. * @bc_tsf: the timestamp of the beacon. 0 to reset the TSF. -1 to perform a
  1992. * beacon timer update based on the current HW TSF.
  1993. *
  1994. * Calculate the next target beacon transmit time (TBTT) based on the timestamp
  1995. * of a received beacon or the current local hardware TSF and write it to the
  1996. * beacon timer registers.
  1997. *
  1998. * This is called in a variety of situations, e.g. when a beacon is received,
  1999. * when a TSF update has been detected, but also when an new IBSS is created or
  2000. * when we otherwise know we have to update the timers, but we keep it in this
  2001. * function to have it all together in one place.
  2002. */
  2003. static void
  2004. ath5k_beacon_update_timers(struct ath5k_softc *sc, u64 bc_tsf)
  2005. {
  2006. struct ath5k_hw *ah = sc->ah;
  2007. u32 nexttbtt, intval, hw_tu, bc_tu;
  2008. u64 hw_tsf;
  2009. intval = sc->bintval & AR5K_BEACON_PERIOD;
  2010. if (WARN_ON(!intval))
  2011. return;
  2012. /* beacon TSF converted to TU */
  2013. bc_tu = TSF_TO_TU(bc_tsf);
  2014. /* current TSF converted to TU */
  2015. hw_tsf = ath5k_hw_get_tsf64(ah);
  2016. hw_tu = TSF_TO_TU(hw_tsf);
  2017. #define FUDGE 3
  2018. /* we use FUDGE to make sure the next TBTT is ahead of the current TU */
  2019. if (bc_tsf == -1) {
  2020. /*
  2021. * no beacons received, called internally.
  2022. * just need to refresh timers based on HW TSF.
  2023. */
  2024. nexttbtt = roundup(hw_tu + FUDGE, intval);
  2025. } else if (bc_tsf == 0) {
  2026. /*
  2027. * no beacon received, probably called by ath5k_reset_tsf().
  2028. * reset TSF to start with 0.
  2029. */
  2030. nexttbtt = intval;
  2031. intval |= AR5K_BEACON_RESET_TSF;
  2032. } else if (bc_tsf > hw_tsf) {
  2033. /*
  2034. * beacon received, SW merge happend but HW TSF not yet updated.
  2035. * not possible to reconfigure timers yet, but next time we
  2036. * receive a beacon with the same BSSID, the hardware will
  2037. * automatically update the TSF and then we need to reconfigure
  2038. * the timers.
  2039. */
  2040. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  2041. "need to wait for HW TSF sync\n");
  2042. return;
  2043. } else {
  2044. /*
  2045. * most important case for beacon synchronization between STA.
  2046. *
  2047. * beacon received and HW TSF has been already updated by HW.
  2048. * update next TBTT based on the TSF of the beacon, but make
  2049. * sure it is ahead of our local TSF timer.
  2050. */
  2051. nexttbtt = bc_tu + roundup(hw_tu + FUDGE - bc_tu, intval);
  2052. }
  2053. #undef FUDGE
  2054. sc->nexttbtt = nexttbtt;
  2055. intval |= AR5K_BEACON_ENA;
  2056. ath5k_hw_init_beacon(ah, nexttbtt, intval);
  2057. /*
  2058. * debugging output last in order to preserve the time critical aspect
  2059. * of this function
  2060. */
  2061. if (bc_tsf == -1)
  2062. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  2063. "reconfigured timers based on HW TSF\n");
  2064. else if (bc_tsf == 0)
  2065. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  2066. "reset HW TSF and timers\n");
  2067. else
  2068. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  2069. "updated timers based on beacon TSF\n");
  2070. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON,
  2071. "bc_tsf %llx hw_tsf %llx bc_tu %u hw_tu %u nexttbtt %u\n",
  2072. (unsigned long long) bc_tsf,
  2073. (unsigned long long) hw_tsf, bc_tu, hw_tu, nexttbtt);
  2074. ATH5K_DBG_UNLIMIT(sc, ATH5K_DEBUG_BEACON, "intval %u %s %s\n",
  2075. intval & AR5K_BEACON_PERIOD,
  2076. intval & AR5K_BEACON_ENA ? "AR5K_BEACON_ENA" : "",
  2077. intval & AR5K_BEACON_RESET_TSF ? "AR5K_BEACON_RESET_TSF" : "");
  2078. }
  2079. /**
  2080. * ath5k_beacon_config - Configure the beacon queues and interrupts
  2081. *
  2082. * @sc: struct ath5k_softc pointer we are operating on
  2083. *
  2084. * In IBSS mode we use a self-linked tx descriptor if possible. We enable SWBA
  2085. * interrupts to detect TSF updates only.
  2086. */
  2087. static void
  2088. ath5k_beacon_config(struct ath5k_softc *sc)
  2089. {
  2090. struct ath5k_hw *ah = sc->ah;
  2091. unsigned long flags;
  2092. spin_lock_irqsave(&sc->block, flags);
  2093. sc->bmisscount = 0;
  2094. sc->imask &= ~(AR5K_INT_BMISS | AR5K_INT_SWBA);
  2095. if (sc->enable_beacon) {
  2096. /*
  2097. * In IBSS mode we use a self-linked tx descriptor and let the
  2098. * hardware send the beacons automatically. We have to load it
  2099. * only once here.
  2100. * We use the SWBA interrupt only to keep track of the beacon
  2101. * timers in order to detect automatic TSF updates.
  2102. */
  2103. ath5k_beaconq_config(sc);
  2104. sc->imask |= AR5K_INT_SWBA;
  2105. if (sc->opmode == NL80211_IFTYPE_ADHOC) {
  2106. if (ath5k_hw_hasveol(ah))
  2107. ath5k_beacon_send(sc);
  2108. } else
  2109. ath5k_beacon_update_timers(sc, -1);
  2110. } else {
  2111. ath5k_hw_stop_tx_dma(sc->ah, sc->bhalq);
  2112. }
  2113. ath5k_hw_set_imr(ah, sc->imask);
  2114. mmiowb();
  2115. spin_unlock_irqrestore(&sc->block, flags);
  2116. }
  2117. static void ath5k_tasklet_beacon(unsigned long data)
  2118. {
  2119. struct ath5k_softc *sc = (struct ath5k_softc *) data;
  2120. /*
  2121. * Software beacon alert--time to send a beacon.
  2122. *
  2123. * In IBSS mode we use this interrupt just to
  2124. * keep track of the next TBTT (target beacon
  2125. * transmission time) in order to detect wether
  2126. * automatic TSF updates happened.
  2127. */
  2128. if (sc->opmode == NL80211_IFTYPE_ADHOC) {
  2129. /* XXX: only if VEOL suppported */
  2130. u64 tsf = ath5k_hw_get_tsf64(sc->ah);
  2131. sc->nexttbtt += sc->bintval;
  2132. ATH5K_DBG(sc, ATH5K_DEBUG_BEACON,
  2133. "SWBA nexttbtt: %x hw_tu: %x "
  2134. "TSF: %llx\n",
  2135. sc->nexttbtt,
  2136. TSF_TO_TU(tsf),
  2137. (unsigned long long) tsf);
  2138. } else {
  2139. spin_lock(&sc->block);
  2140. ath5k_beacon_send(sc);
  2141. spin_unlock(&sc->block);
  2142. }
  2143. }
  2144. /********************\
  2145. * Interrupt handling *
  2146. \********************/
  2147. static int
  2148. ath5k_init(struct ath5k_softc *sc)
  2149. {
  2150. struct ath5k_hw *ah = sc->ah;
  2151. int ret, i;
  2152. mutex_lock(&sc->lock);
  2153. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "mode %d\n", sc->opmode);
  2154. /*
  2155. * Stop anything previously setup. This is safe
  2156. * no matter this is the first time through or not.
  2157. */
  2158. ath5k_stop_locked(sc);
  2159. /* Set PHY calibration interval */
  2160. ah->ah_cal_intval = ath5k_calinterval;
  2161. /*
  2162. * The basic interface to setting the hardware in a good
  2163. * state is ``reset''. On return the hardware is known to
  2164. * be powered up and with interrupts disabled. This must
  2165. * be followed by initialization of the appropriate bits
  2166. * and then setup of the interrupt mask.
  2167. */
  2168. sc->curchan = sc->hw->conf.channel;
  2169. sc->curband = &sc->sbands[sc->curchan->band];
  2170. sc->imask = AR5K_INT_RXOK | AR5K_INT_RXERR | AR5K_INT_RXEOL |
  2171. AR5K_INT_RXORN | AR5K_INT_TXDESC | AR5K_INT_TXEOL |
  2172. AR5K_INT_FATAL | AR5K_INT_GLOBAL | AR5K_INT_SWI;
  2173. ret = ath5k_reset(sc, NULL);
  2174. if (ret)
  2175. goto done;
  2176. ath5k_rfkill_hw_start(ah);
  2177. /*
  2178. * Reset the key cache since some parts do not reset the
  2179. * contents on initial power up or resume from suspend.
  2180. */
  2181. for (i = 0; i < AR5K_KEYTABLE_SIZE; i++)
  2182. ath5k_hw_reset_key(ah, i);
  2183. /* Set ack to be sent at low bit-rates */
  2184. ath5k_hw_set_ack_bitrate_high(ah, false);
  2185. ret = 0;
  2186. done:
  2187. mmiowb();
  2188. mutex_unlock(&sc->lock);
  2189. return ret;
  2190. }
  2191. static int
  2192. ath5k_stop_locked(struct ath5k_softc *sc)
  2193. {
  2194. struct ath5k_hw *ah = sc->ah;
  2195. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "invalid %u\n",
  2196. test_bit(ATH_STAT_INVALID, sc->status));
  2197. /*
  2198. * Shutdown the hardware and driver:
  2199. * stop output from above
  2200. * disable interrupts
  2201. * turn off timers
  2202. * turn off the radio
  2203. * clear transmit machinery
  2204. * clear receive machinery
  2205. * drain and release tx queues
  2206. * reclaim beacon resources
  2207. * power down hardware
  2208. *
  2209. * Note that some of this work is not possible if the
  2210. * hardware is gone (invalid).
  2211. */
  2212. ieee80211_stop_queues(sc->hw);
  2213. if (!test_bit(ATH_STAT_INVALID, sc->status)) {
  2214. ath5k_led_off(sc);
  2215. ath5k_hw_set_imr(ah, 0);
  2216. synchronize_irq(sc->pdev->irq);
  2217. }
  2218. ath5k_txq_cleanup(sc);
  2219. if (!test_bit(ATH_STAT_INVALID, sc->status)) {
  2220. ath5k_rx_stop(sc);
  2221. ath5k_hw_phy_disable(ah);
  2222. } else
  2223. sc->rxlink = NULL;
  2224. return 0;
  2225. }
  2226. /*
  2227. * Stop the device, grabbing the top-level lock to protect
  2228. * against concurrent entry through ath5k_init (which can happen
  2229. * if another thread does a system call and the thread doing the
  2230. * stop is preempted).
  2231. */
  2232. static int
  2233. ath5k_stop_hw(struct ath5k_softc *sc)
  2234. {
  2235. int ret;
  2236. mutex_lock(&sc->lock);
  2237. ret = ath5k_stop_locked(sc);
  2238. if (ret == 0 && !test_bit(ATH_STAT_INVALID, sc->status)) {
  2239. /*
  2240. * Don't set the card in full sleep mode!
  2241. *
  2242. * a) When the device is in this state it must be carefully
  2243. * woken up or references to registers in the PCI clock
  2244. * domain may freeze the bus (and system). This varies
  2245. * by chip and is mostly an issue with newer parts
  2246. * (madwifi sources mentioned srev >= 0x78) that go to
  2247. * sleep more quickly.
  2248. *
  2249. * b) On older chips full sleep results a weird behaviour
  2250. * during wakeup. I tested various cards with srev < 0x78
  2251. * and they don't wake up after module reload, a second
  2252. * module reload is needed to bring the card up again.
  2253. *
  2254. * Until we figure out what's going on don't enable
  2255. * full chip reset on any chip (this is what Legacy HAL
  2256. * and Sam's HAL do anyway). Instead Perform a full reset
  2257. * on the device (same as initial state after attach) and
  2258. * leave it idle (keep MAC/BB on warm reset) */
  2259. ret = ath5k_hw_on_hold(sc->ah);
  2260. ATH5K_DBG(sc, ATH5K_DEBUG_RESET,
  2261. "putting device to sleep\n");
  2262. }
  2263. ath5k_txbuf_free(sc, sc->bbuf);
  2264. mmiowb();
  2265. mutex_unlock(&sc->lock);
  2266. tasklet_kill(&sc->rxtq);
  2267. tasklet_kill(&sc->txtq);
  2268. tasklet_kill(&sc->restq);
  2269. tasklet_kill(&sc->calib);
  2270. tasklet_kill(&sc->beacontq);
  2271. ath5k_rfkill_hw_stop(sc->ah);
  2272. return ret;
  2273. }
  2274. static irqreturn_t
  2275. ath5k_intr(int irq, void *dev_id)
  2276. {
  2277. struct ath5k_softc *sc = dev_id;
  2278. struct ath5k_hw *ah = sc->ah;
  2279. enum ath5k_int status;
  2280. unsigned int counter = 1000;
  2281. if (unlikely(test_bit(ATH_STAT_INVALID, sc->status) ||
  2282. !ath5k_hw_is_intr_pending(ah)))
  2283. return IRQ_NONE;
  2284. do {
  2285. ath5k_hw_get_isr(ah, &status); /* NB: clears IRQ too */
  2286. ATH5K_DBG(sc, ATH5K_DEBUG_INTR, "status 0x%x/0x%x\n",
  2287. status, sc->imask);
  2288. if (unlikely(status & AR5K_INT_FATAL)) {
  2289. /*
  2290. * Fatal errors are unrecoverable.
  2291. * Typically these are caused by DMA errors.
  2292. */
  2293. tasklet_schedule(&sc->restq);
  2294. } else if (unlikely(status & AR5K_INT_RXORN)) {
  2295. tasklet_schedule(&sc->restq);
  2296. } else {
  2297. if (status & AR5K_INT_SWBA) {
  2298. tasklet_hi_schedule(&sc->beacontq);
  2299. }
  2300. if (status & AR5K_INT_RXEOL) {
  2301. /*
  2302. * NB: the hardware should re-read the link when
  2303. * RXE bit is written, but it doesn't work at
  2304. * least on older hardware revs.
  2305. */
  2306. sc->rxlink = NULL;
  2307. }
  2308. if (status & AR5K_INT_TXURN) {
  2309. /* bump tx trigger level */
  2310. ath5k_hw_update_tx_triglevel(ah, true);
  2311. }
  2312. if (status & (AR5K_INT_RXOK | AR5K_INT_RXERR))
  2313. tasklet_schedule(&sc->rxtq);
  2314. if (status & (AR5K_INT_TXOK | AR5K_INT_TXDESC
  2315. | AR5K_INT_TXERR | AR5K_INT_TXEOL))
  2316. tasklet_schedule(&sc->txtq);
  2317. if (status & AR5K_INT_BMISS) {
  2318. /* TODO */
  2319. }
  2320. if (status & AR5K_INT_SWI) {
  2321. tasklet_schedule(&sc->calib);
  2322. }
  2323. if (status & AR5K_INT_MIB) {
  2324. /*
  2325. * These stats are also used for ANI i think
  2326. * so how about updating them more often ?
  2327. */
  2328. ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
  2329. }
  2330. if (status & AR5K_INT_GPIO)
  2331. tasklet_schedule(&sc->rf_kill.toggleq);
  2332. }
  2333. } while (ath5k_hw_is_intr_pending(ah) && --counter > 0);
  2334. if (unlikely(!counter))
  2335. ATH5K_WARN(sc, "too many interrupts, giving up for now\n");
  2336. ath5k_hw_calibration_poll(ah);
  2337. return IRQ_HANDLED;
  2338. }
  2339. static void
  2340. ath5k_tasklet_reset(unsigned long data)
  2341. {
  2342. struct ath5k_softc *sc = (void *)data;
  2343. ath5k_reset_wake(sc);
  2344. }
  2345. /*
  2346. * Periodically recalibrate the PHY to account
  2347. * for temperature/environment changes.
  2348. */
  2349. static void
  2350. ath5k_tasklet_calibrate(unsigned long data)
  2351. {
  2352. struct ath5k_softc *sc = (void *)data;
  2353. struct ath5k_hw *ah = sc->ah;
  2354. /* Only full calibration for now */
  2355. if (ah->ah_swi_mask != AR5K_SWI_FULL_CALIBRATION)
  2356. return;
  2357. /* Stop queues so that calibration
  2358. * doesn't interfere with tx */
  2359. ieee80211_stop_queues(sc->hw);
  2360. ATH5K_DBG(sc, ATH5K_DEBUG_CALIBRATE, "channel %u/%x\n",
  2361. ieee80211_frequency_to_channel(sc->curchan->center_freq),
  2362. sc->curchan->hw_value);
  2363. if (ath5k_hw_gainf_calibrate(ah) == AR5K_RFGAIN_NEED_CHANGE) {
  2364. /*
  2365. * Rfgain is out of bounds, reset the chip
  2366. * to load new gain values.
  2367. */
  2368. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "calibration, resetting\n");
  2369. ath5k_reset_wake(sc);
  2370. }
  2371. if (ath5k_hw_phy_calibrate(ah, sc->curchan))
  2372. ATH5K_ERR(sc, "calibration of channel %u failed\n",
  2373. ieee80211_frequency_to_channel(
  2374. sc->curchan->center_freq));
  2375. ah->ah_swi_mask = 0;
  2376. /* Wake queues */
  2377. ieee80211_wake_queues(sc->hw);
  2378. }
  2379. /********************\
  2380. * Mac80211 functions *
  2381. \********************/
  2382. static int
  2383. ath5k_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2384. {
  2385. struct ath5k_softc *sc = hw->priv;
  2386. return ath5k_tx_queue(hw, skb, sc->txq);
  2387. }
  2388. static int ath5k_tx_queue(struct ieee80211_hw *hw, struct sk_buff *skb,
  2389. struct ath5k_txq *txq)
  2390. {
  2391. struct ath5k_softc *sc = hw->priv;
  2392. struct ath5k_buf *bf;
  2393. unsigned long flags;
  2394. int padsize;
  2395. ath5k_debug_dump_skb(sc, skb, "TX ", 1);
  2396. if (sc->opmode == NL80211_IFTYPE_MONITOR)
  2397. ATH5K_DBG(sc, ATH5K_DEBUG_XMIT, "tx in monitor (scan?)\n");
  2398. /*
  2399. * the hardware expects the header padded to 4 byte boundaries
  2400. * if this is not the case we add the padding after the header
  2401. */
  2402. padsize = ath5k_add_padding(skb);
  2403. if (padsize < 0) {
  2404. ATH5K_ERR(sc, "tx hdrlen not %%4: not enough"
  2405. " headroom to pad");
  2406. goto drop_packet;
  2407. }
  2408. spin_lock_irqsave(&sc->txbuflock, flags);
  2409. if (list_empty(&sc->txbuf)) {
  2410. ATH5K_ERR(sc, "no further txbuf available, dropping packet\n");
  2411. spin_unlock_irqrestore(&sc->txbuflock, flags);
  2412. ieee80211_stop_queue(hw, skb_get_queue_mapping(skb));
  2413. goto drop_packet;
  2414. }
  2415. bf = list_first_entry(&sc->txbuf, struct ath5k_buf, list);
  2416. list_del(&bf->list);
  2417. sc->txbuf_len--;
  2418. if (list_empty(&sc->txbuf))
  2419. ieee80211_stop_queues(hw);
  2420. spin_unlock_irqrestore(&sc->txbuflock, flags);
  2421. bf->skb = skb;
  2422. if (ath5k_txbuf_setup(sc, bf, txq, padsize)) {
  2423. bf->skb = NULL;
  2424. spin_lock_irqsave(&sc->txbuflock, flags);
  2425. list_add_tail(&bf->list, &sc->txbuf);
  2426. sc->txbuf_len++;
  2427. spin_unlock_irqrestore(&sc->txbuflock, flags);
  2428. goto drop_packet;
  2429. }
  2430. return NETDEV_TX_OK;
  2431. drop_packet:
  2432. dev_kfree_skb_any(skb);
  2433. return NETDEV_TX_OK;
  2434. }
  2435. /*
  2436. * Reset the hardware. If chan is not NULL, then also pause rx/tx
  2437. * and change to the given channel.
  2438. */
  2439. static int
  2440. ath5k_reset(struct ath5k_softc *sc, struct ieee80211_channel *chan)
  2441. {
  2442. struct ath5k_hw *ah = sc->ah;
  2443. int ret;
  2444. ATH5K_DBG(sc, ATH5K_DEBUG_RESET, "resetting\n");
  2445. if (chan) {
  2446. ath5k_hw_set_imr(ah, 0);
  2447. ath5k_txq_cleanup(sc);
  2448. ath5k_rx_stop(sc);
  2449. sc->curchan = chan;
  2450. sc->curband = &sc->sbands[chan->band];
  2451. }
  2452. ret = ath5k_hw_reset(ah, sc->opmode, sc->curchan, chan != NULL);
  2453. if (ret) {
  2454. ATH5K_ERR(sc, "can't reset hardware (%d)\n", ret);
  2455. goto err;
  2456. }
  2457. ret = ath5k_rx_start(sc);
  2458. if (ret) {
  2459. ATH5K_ERR(sc, "can't start recv logic\n");
  2460. goto err;
  2461. }
  2462. /*
  2463. * Change channels and update the h/w rate map if we're switching;
  2464. * e.g. 11a to 11b/g.
  2465. *
  2466. * We may be doing a reset in response to an ioctl that changes the
  2467. * channel so update any state that might change as a result.
  2468. *
  2469. * XXX needed?
  2470. */
  2471. /* ath5k_chan_change(sc, c); */
  2472. ath5k_beacon_config(sc);
  2473. /* intrs are enabled by ath5k_beacon_config */
  2474. return 0;
  2475. err:
  2476. return ret;
  2477. }
  2478. static int
  2479. ath5k_reset_wake(struct ath5k_softc *sc)
  2480. {
  2481. int ret;
  2482. ret = ath5k_reset(sc, sc->curchan);
  2483. if (!ret)
  2484. ieee80211_wake_queues(sc->hw);
  2485. return ret;
  2486. }
  2487. static int ath5k_start(struct ieee80211_hw *hw)
  2488. {
  2489. return ath5k_init(hw->priv);
  2490. }
  2491. static void ath5k_stop(struct ieee80211_hw *hw)
  2492. {
  2493. ath5k_stop_hw(hw->priv);
  2494. }
  2495. static int ath5k_add_interface(struct ieee80211_hw *hw,
  2496. struct ieee80211_vif *vif)
  2497. {
  2498. struct ath5k_softc *sc = hw->priv;
  2499. int ret;
  2500. mutex_lock(&sc->lock);
  2501. if (sc->vif) {
  2502. ret = 0;
  2503. goto end;
  2504. }
  2505. sc->vif = vif;
  2506. switch (vif->type) {
  2507. case NL80211_IFTYPE_AP:
  2508. case NL80211_IFTYPE_STATION:
  2509. case NL80211_IFTYPE_ADHOC:
  2510. case NL80211_IFTYPE_MESH_POINT:
  2511. case NL80211_IFTYPE_MONITOR:
  2512. sc->opmode = vif->type;
  2513. break;
  2514. default:
  2515. ret = -EOPNOTSUPP;
  2516. goto end;
  2517. }
  2518. ATH5K_DBG(sc, ATH5K_DEBUG_MODE, "add interface mode %d\n", sc->opmode);
  2519. ath5k_hw_set_lladdr(sc->ah, vif->addr);
  2520. ath5k_mode_setup(sc);
  2521. ret = 0;
  2522. end:
  2523. mutex_unlock(&sc->lock);
  2524. return ret;
  2525. }
  2526. static void
  2527. ath5k_remove_interface(struct ieee80211_hw *hw,
  2528. struct ieee80211_vif *vif)
  2529. {
  2530. struct ath5k_softc *sc = hw->priv;
  2531. u8 mac[ETH_ALEN] = {};
  2532. mutex_lock(&sc->lock);
  2533. if (sc->vif != vif)
  2534. goto end;
  2535. ath5k_hw_set_lladdr(sc->ah, mac);
  2536. sc->vif = NULL;
  2537. end:
  2538. mutex_unlock(&sc->lock);
  2539. }
  2540. /*
  2541. * TODO: Phy disable/diversity etc
  2542. */
  2543. static int
  2544. ath5k_config(struct ieee80211_hw *hw, u32 changed)
  2545. {
  2546. struct ath5k_softc *sc = hw->priv;
  2547. struct ath5k_hw *ah = sc->ah;
  2548. struct ieee80211_conf *conf = &hw->conf;
  2549. int ret = 0;
  2550. mutex_lock(&sc->lock);
  2551. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  2552. ret = ath5k_chan_set(sc, conf->channel);
  2553. if (ret < 0)
  2554. goto unlock;
  2555. }
  2556. if ((changed & IEEE80211_CONF_CHANGE_POWER) &&
  2557. (sc->power_level != conf->power_level)) {
  2558. sc->power_level = conf->power_level;
  2559. /* Half dB steps */
  2560. ath5k_hw_set_txpower_limit(ah, (conf->power_level * 2));
  2561. }
  2562. /* TODO:
  2563. * 1) Move this on config_interface and handle each case
  2564. * separately eg. when we have only one STA vif, use
  2565. * AR5K_ANTMODE_SINGLE_AP
  2566. *
  2567. * 2) Allow the user to change antenna mode eg. when only
  2568. * one antenna is present
  2569. *
  2570. * 3) Allow the user to set default/tx antenna when possible
  2571. *
  2572. * 4) Default mode should handle 90% of the cases, together
  2573. * with fixed a/b and single AP modes we should be able to
  2574. * handle 99%. Sectored modes are extreme cases and i still
  2575. * haven't found a usage for them. If we decide to support them,
  2576. * then we must allow the user to set how many tx antennas we
  2577. * have available
  2578. */
  2579. ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
  2580. unlock:
  2581. mutex_unlock(&sc->lock);
  2582. return ret;
  2583. }
  2584. static u64 ath5k_prepare_multicast(struct ieee80211_hw *hw,
  2585. struct netdev_hw_addr_list *mc_list)
  2586. {
  2587. u32 mfilt[2], val;
  2588. u8 pos;
  2589. struct netdev_hw_addr *ha;
  2590. mfilt[0] = 0;
  2591. mfilt[1] = 1;
  2592. netdev_hw_addr_list_for_each(ha, mc_list) {
  2593. /* calculate XOR of eight 6-bit values */
  2594. val = get_unaligned_le32(ha->addr + 0);
  2595. pos = (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  2596. val = get_unaligned_le32(ha->addr + 3);
  2597. pos ^= (val >> 18) ^ (val >> 12) ^ (val >> 6) ^ val;
  2598. pos &= 0x3f;
  2599. mfilt[pos / 32] |= (1 << (pos % 32));
  2600. /* XXX: we might be able to just do this instead,
  2601. * but not sure, needs testing, if we do use this we'd
  2602. * neet to inform below to not reset the mcast */
  2603. /* ath5k_hw_set_mcast_filterindex(ah,
  2604. * ha->addr[5]); */
  2605. }
  2606. return ((u64)(mfilt[1]) << 32) | mfilt[0];
  2607. }
  2608. #define SUPPORTED_FIF_FLAGS \
  2609. FIF_PROMISC_IN_BSS | FIF_ALLMULTI | FIF_FCSFAIL | \
  2610. FIF_PLCPFAIL | FIF_CONTROL | FIF_OTHER_BSS | \
  2611. FIF_BCN_PRBRESP_PROMISC
  2612. /*
  2613. * o always accept unicast, broadcast, and multicast traffic
  2614. * o multicast traffic for all BSSIDs will be enabled if mac80211
  2615. * says it should be
  2616. * o maintain current state of phy ofdm or phy cck error reception.
  2617. * If the hardware detects any of these type of errors then
  2618. * ath5k_hw_get_rx_filter() will pass to us the respective
  2619. * hardware filters to be able to receive these type of frames.
  2620. * o probe request frames are accepted only when operating in
  2621. * hostap, adhoc, or monitor modes
  2622. * o enable promiscuous mode according to the interface state
  2623. * o accept beacons:
  2624. * - when operating in adhoc mode so the 802.11 layer creates
  2625. * node table entries for peers,
  2626. * - when operating in station mode for collecting rssi data when
  2627. * the station is otherwise quiet, or
  2628. * - when scanning
  2629. */
  2630. static void ath5k_configure_filter(struct ieee80211_hw *hw,
  2631. unsigned int changed_flags,
  2632. unsigned int *new_flags,
  2633. u64 multicast)
  2634. {
  2635. struct ath5k_softc *sc = hw->priv;
  2636. struct ath5k_hw *ah = sc->ah;
  2637. u32 mfilt[2], rfilt;
  2638. mutex_lock(&sc->lock);
  2639. mfilt[0] = multicast;
  2640. mfilt[1] = multicast >> 32;
  2641. /* Only deal with supported flags */
  2642. changed_flags &= SUPPORTED_FIF_FLAGS;
  2643. *new_flags &= SUPPORTED_FIF_FLAGS;
  2644. /* If HW detects any phy or radar errors, leave those filters on.
  2645. * Also, always enable Unicast, Broadcasts and Multicast
  2646. * XXX: move unicast, bssid broadcasts and multicast to mac80211 */
  2647. rfilt = (ath5k_hw_get_rx_filter(ah) & (AR5K_RX_FILTER_PHYERR)) |
  2648. (AR5K_RX_FILTER_UCAST | AR5K_RX_FILTER_BCAST |
  2649. AR5K_RX_FILTER_MCAST);
  2650. if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
  2651. if (*new_flags & FIF_PROMISC_IN_BSS) {
  2652. rfilt |= AR5K_RX_FILTER_PROM;
  2653. __set_bit(ATH_STAT_PROMISC, sc->status);
  2654. } else {
  2655. __clear_bit(ATH_STAT_PROMISC, sc->status);
  2656. }
  2657. }
  2658. /* Note, AR5K_RX_FILTER_MCAST is already enabled */
  2659. if (*new_flags & FIF_ALLMULTI) {
  2660. mfilt[0] = ~0;
  2661. mfilt[1] = ~0;
  2662. }
  2663. /* This is the best we can do */
  2664. if (*new_flags & (FIF_FCSFAIL | FIF_PLCPFAIL))
  2665. rfilt |= AR5K_RX_FILTER_PHYERR;
  2666. /* FIF_BCN_PRBRESP_PROMISC really means to enable beacons
  2667. * and probes for any BSSID, this needs testing */
  2668. if (*new_flags & FIF_BCN_PRBRESP_PROMISC)
  2669. rfilt |= AR5K_RX_FILTER_BEACON | AR5K_RX_FILTER_PROBEREQ;
  2670. /* FIF_CONTROL doc says that if FIF_PROMISC_IN_BSS is not
  2671. * set we should only pass on control frames for this
  2672. * station. This needs testing. I believe right now this
  2673. * enables *all* control frames, which is OK.. but
  2674. * but we should see if we can improve on granularity */
  2675. if (*new_flags & FIF_CONTROL)
  2676. rfilt |= AR5K_RX_FILTER_CONTROL;
  2677. /* Additional settings per mode -- this is per ath5k */
  2678. /* XXX move these to mac80211, and add a beacon IFF flag to mac80211 */
  2679. switch (sc->opmode) {
  2680. case NL80211_IFTYPE_MESH_POINT:
  2681. case NL80211_IFTYPE_MONITOR:
  2682. rfilt |= AR5K_RX_FILTER_CONTROL |
  2683. AR5K_RX_FILTER_BEACON |
  2684. AR5K_RX_FILTER_PROBEREQ |
  2685. AR5K_RX_FILTER_PROM;
  2686. break;
  2687. case NL80211_IFTYPE_AP:
  2688. case NL80211_IFTYPE_ADHOC:
  2689. rfilt |= AR5K_RX_FILTER_PROBEREQ |
  2690. AR5K_RX_FILTER_BEACON;
  2691. break;
  2692. case NL80211_IFTYPE_STATION:
  2693. if (sc->assoc)
  2694. rfilt |= AR5K_RX_FILTER_BEACON;
  2695. default:
  2696. break;
  2697. }
  2698. /* Set filters */
  2699. ath5k_hw_set_rx_filter(ah, rfilt);
  2700. /* Set multicast bits */
  2701. ath5k_hw_set_mcast_filter(ah, mfilt[0], mfilt[1]);
  2702. /* Set the cached hw filter flags, this will alter actually
  2703. * be set in HW */
  2704. sc->filter_flags = rfilt;
  2705. mutex_unlock(&sc->lock);
  2706. }
  2707. static int
  2708. ath5k_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2709. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  2710. struct ieee80211_key_conf *key)
  2711. {
  2712. struct ath5k_softc *sc = hw->priv;
  2713. struct ath5k_hw *ah = sc->ah;
  2714. struct ath_common *common = ath5k_hw_common(ah);
  2715. int ret = 0;
  2716. if (modparam_nohwcrypt)
  2717. return -EOPNOTSUPP;
  2718. if (sc->opmode == NL80211_IFTYPE_AP)
  2719. return -EOPNOTSUPP;
  2720. switch (key->alg) {
  2721. case ALG_WEP:
  2722. case ALG_TKIP:
  2723. break;
  2724. case ALG_CCMP:
  2725. if (sc->ah->ah_aes_support)
  2726. break;
  2727. return -EOPNOTSUPP;
  2728. default:
  2729. WARN_ON(1);
  2730. return -EINVAL;
  2731. }
  2732. mutex_lock(&sc->lock);
  2733. switch (cmd) {
  2734. case SET_KEY:
  2735. ret = ath5k_hw_set_key(sc->ah, key->keyidx, key,
  2736. sta ? sta->addr : NULL);
  2737. if (ret) {
  2738. ATH5K_ERR(sc, "can't set the key\n");
  2739. goto unlock;
  2740. }
  2741. __set_bit(key->keyidx, common->keymap);
  2742. key->hw_key_idx = key->keyidx;
  2743. key->flags |= (IEEE80211_KEY_FLAG_GENERATE_IV |
  2744. IEEE80211_KEY_FLAG_GENERATE_MMIC);
  2745. break;
  2746. case DISABLE_KEY:
  2747. ath5k_hw_reset_key(sc->ah, key->keyidx);
  2748. __clear_bit(key->keyidx, common->keymap);
  2749. break;
  2750. default:
  2751. ret = -EINVAL;
  2752. goto unlock;
  2753. }
  2754. unlock:
  2755. mmiowb();
  2756. mutex_unlock(&sc->lock);
  2757. return ret;
  2758. }
  2759. static int
  2760. ath5k_get_stats(struct ieee80211_hw *hw,
  2761. struct ieee80211_low_level_stats *stats)
  2762. {
  2763. struct ath5k_softc *sc = hw->priv;
  2764. struct ath5k_hw *ah = sc->ah;
  2765. /* Force update */
  2766. ath5k_hw_update_mib_counters(ah, &sc->ll_stats);
  2767. memcpy(stats, &sc->ll_stats, sizeof(sc->ll_stats));
  2768. return 0;
  2769. }
  2770. static u64
  2771. ath5k_get_tsf(struct ieee80211_hw *hw)
  2772. {
  2773. struct ath5k_softc *sc = hw->priv;
  2774. return ath5k_hw_get_tsf64(sc->ah);
  2775. }
  2776. static void
  2777. ath5k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  2778. {
  2779. struct ath5k_softc *sc = hw->priv;
  2780. ath5k_hw_set_tsf64(sc->ah, tsf);
  2781. }
  2782. static void
  2783. ath5k_reset_tsf(struct ieee80211_hw *hw)
  2784. {
  2785. struct ath5k_softc *sc = hw->priv;
  2786. /*
  2787. * in IBSS mode we need to update the beacon timers too.
  2788. * this will also reset the TSF if we call it with 0
  2789. */
  2790. if (sc->opmode == NL80211_IFTYPE_ADHOC)
  2791. ath5k_beacon_update_timers(sc, 0);
  2792. else
  2793. ath5k_hw_reset_tsf(sc->ah);
  2794. }
  2795. /*
  2796. * Updates the beacon that is sent by ath5k_beacon_send. For adhoc,
  2797. * this is called only once at config_bss time, for AP we do it every
  2798. * SWBA interrupt so that the TIM will reflect buffered frames.
  2799. *
  2800. * Called with the beacon lock.
  2801. */
  2802. static int
  2803. ath5k_beacon_update(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
  2804. {
  2805. int ret;
  2806. struct ath5k_softc *sc = hw->priv;
  2807. struct sk_buff *skb;
  2808. if (WARN_ON(!vif)) {
  2809. ret = -EINVAL;
  2810. goto out;
  2811. }
  2812. skb = ieee80211_beacon_get(hw, vif);
  2813. if (!skb) {
  2814. ret = -ENOMEM;
  2815. goto out;
  2816. }
  2817. ath5k_debug_dump_skb(sc, skb, "BC ", 1);
  2818. ath5k_txbuf_free(sc, sc->bbuf);
  2819. sc->bbuf->skb = skb;
  2820. ret = ath5k_beacon_setup(sc, sc->bbuf);
  2821. if (ret)
  2822. sc->bbuf->skb = NULL;
  2823. out:
  2824. return ret;
  2825. }
  2826. static void
  2827. set_beacon_filter(struct ieee80211_hw *hw, bool enable)
  2828. {
  2829. struct ath5k_softc *sc = hw->priv;
  2830. struct ath5k_hw *ah = sc->ah;
  2831. u32 rfilt;
  2832. rfilt = ath5k_hw_get_rx_filter(ah);
  2833. if (enable)
  2834. rfilt |= AR5K_RX_FILTER_BEACON;
  2835. else
  2836. rfilt &= ~AR5K_RX_FILTER_BEACON;
  2837. ath5k_hw_set_rx_filter(ah, rfilt);
  2838. sc->filter_flags = rfilt;
  2839. }
  2840. static void ath5k_bss_info_changed(struct ieee80211_hw *hw,
  2841. struct ieee80211_vif *vif,
  2842. struct ieee80211_bss_conf *bss_conf,
  2843. u32 changes)
  2844. {
  2845. struct ath5k_softc *sc = hw->priv;
  2846. struct ath5k_hw *ah = sc->ah;
  2847. struct ath_common *common = ath5k_hw_common(ah);
  2848. unsigned long flags;
  2849. mutex_lock(&sc->lock);
  2850. if (WARN_ON(sc->vif != vif))
  2851. goto unlock;
  2852. if (changes & BSS_CHANGED_BSSID) {
  2853. /* Cache for later use during resets */
  2854. memcpy(common->curbssid, bss_conf->bssid, ETH_ALEN);
  2855. common->curaid = 0;
  2856. ath5k_hw_set_associd(ah);
  2857. mmiowb();
  2858. }
  2859. if (changes & BSS_CHANGED_BEACON_INT)
  2860. sc->bintval = bss_conf->beacon_int;
  2861. if (changes & BSS_CHANGED_ASSOC) {
  2862. sc->assoc = bss_conf->assoc;
  2863. if (sc->opmode == NL80211_IFTYPE_STATION)
  2864. set_beacon_filter(hw, sc->assoc);
  2865. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  2866. AR5K_LED_ASSOC : AR5K_LED_INIT);
  2867. if (bss_conf->assoc) {
  2868. ATH5K_DBG(sc, ATH5K_DEBUG_ANY,
  2869. "Bss Info ASSOC %d, bssid: %pM\n",
  2870. bss_conf->aid, common->curbssid);
  2871. common->curaid = bss_conf->aid;
  2872. ath5k_hw_set_associd(ah);
  2873. /* Once ANI is available you would start it here */
  2874. }
  2875. }
  2876. if (changes & BSS_CHANGED_BEACON) {
  2877. spin_lock_irqsave(&sc->block, flags);
  2878. ath5k_beacon_update(hw, vif);
  2879. spin_unlock_irqrestore(&sc->block, flags);
  2880. }
  2881. if (changes & BSS_CHANGED_BEACON_ENABLED)
  2882. sc->enable_beacon = bss_conf->enable_beacon;
  2883. if (changes & (BSS_CHANGED_BEACON | BSS_CHANGED_BEACON_ENABLED |
  2884. BSS_CHANGED_BEACON_INT))
  2885. ath5k_beacon_config(sc);
  2886. unlock:
  2887. mutex_unlock(&sc->lock);
  2888. }
  2889. static void ath5k_sw_scan_start(struct ieee80211_hw *hw)
  2890. {
  2891. struct ath5k_softc *sc = hw->priv;
  2892. if (!sc->assoc)
  2893. ath5k_hw_set_ledstate(sc->ah, AR5K_LED_SCAN);
  2894. }
  2895. static void ath5k_sw_scan_complete(struct ieee80211_hw *hw)
  2896. {
  2897. struct ath5k_softc *sc = hw->priv;
  2898. ath5k_hw_set_ledstate(sc->ah, sc->assoc ?
  2899. AR5K_LED_ASSOC : AR5K_LED_INIT);
  2900. }
  2901. /**
  2902. * ath5k_set_coverage_class - Set IEEE 802.11 coverage class
  2903. *
  2904. * @hw: struct ieee80211_hw pointer
  2905. * @coverage_class: IEEE 802.11 coverage class number
  2906. *
  2907. * Mac80211 callback. Sets slot time, ACK timeout and CTS timeout for given
  2908. * coverage class. The values are persistent, they are restored after device
  2909. * reset.
  2910. */
  2911. static void ath5k_set_coverage_class(struct ieee80211_hw *hw, u8 coverage_class)
  2912. {
  2913. struct ath5k_softc *sc = hw->priv;
  2914. mutex_lock(&sc->lock);
  2915. ath5k_hw_set_coverage_class(sc->ah, coverage_class);
  2916. mutex_unlock(&sc->lock);
  2917. }