main.c 73 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903
  1. /*
  2. * Copyright (c) 2008-2009 Atheros Communications Inc.
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <linux/nl80211.h>
  17. #include "ath9k.h"
  18. #define ATH_PCI_VERSION "0.1"
  19. static char *dev_info = "ath9k";
  20. MODULE_AUTHOR("Atheros Communications");
  21. MODULE_DESCRIPTION("Support for Atheros 802.11n wireless LAN cards.");
  22. MODULE_SUPPORTED_DEVICE("Atheros 802.11n WLAN cards");
  23. MODULE_LICENSE("Dual BSD/GPL");
  24. static int modparam_nohwcrypt;
  25. module_param_named(nohwcrypt, modparam_nohwcrypt, int, 0444);
  26. MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption");
  27. /* We use the hw_value as an index into our private channel structure */
  28. #define CHAN2G(_freq, _idx) { \
  29. .center_freq = (_freq), \
  30. .hw_value = (_idx), \
  31. .max_power = 30, \
  32. }
  33. #define CHAN5G(_freq, _idx) { \
  34. .band = IEEE80211_BAND_5GHZ, \
  35. .center_freq = (_freq), \
  36. .hw_value = (_idx), \
  37. .max_power = 30, \
  38. }
  39. /* Some 2 GHz radios are actually tunable on 2312-2732
  40. * on 5 MHz steps, we support the channels which we know
  41. * we have calibration data for all cards though to make
  42. * this static */
  43. static struct ieee80211_channel ath9k_2ghz_chantable[] = {
  44. CHAN2G(2412, 0), /* Channel 1 */
  45. CHAN2G(2417, 1), /* Channel 2 */
  46. CHAN2G(2422, 2), /* Channel 3 */
  47. CHAN2G(2427, 3), /* Channel 4 */
  48. CHAN2G(2432, 4), /* Channel 5 */
  49. CHAN2G(2437, 5), /* Channel 6 */
  50. CHAN2G(2442, 6), /* Channel 7 */
  51. CHAN2G(2447, 7), /* Channel 8 */
  52. CHAN2G(2452, 8), /* Channel 9 */
  53. CHAN2G(2457, 9), /* Channel 10 */
  54. CHAN2G(2462, 10), /* Channel 11 */
  55. CHAN2G(2467, 11), /* Channel 12 */
  56. CHAN2G(2472, 12), /* Channel 13 */
  57. CHAN2G(2484, 13), /* Channel 14 */
  58. };
  59. /* Some 5 GHz radios are actually tunable on XXXX-YYYY
  60. * on 5 MHz steps, we support the channels which we know
  61. * we have calibration data for all cards though to make
  62. * this static */
  63. static struct ieee80211_channel ath9k_5ghz_chantable[] = {
  64. /* _We_ call this UNII 1 */
  65. CHAN5G(5180, 14), /* Channel 36 */
  66. CHAN5G(5200, 15), /* Channel 40 */
  67. CHAN5G(5220, 16), /* Channel 44 */
  68. CHAN5G(5240, 17), /* Channel 48 */
  69. /* _We_ call this UNII 2 */
  70. CHAN5G(5260, 18), /* Channel 52 */
  71. CHAN5G(5280, 19), /* Channel 56 */
  72. CHAN5G(5300, 20), /* Channel 60 */
  73. CHAN5G(5320, 21), /* Channel 64 */
  74. /* _We_ call this "Middle band" */
  75. CHAN5G(5500, 22), /* Channel 100 */
  76. CHAN5G(5520, 23), /* Channel 104 */
  77. CHAN5G(5540, 24), /* Channel 108 */
  78. CHAN5G(5560, 25), /* Channel 112 */
  79. CHAN5G(5580, 26), /* Channel 116 */
  80. CHAN5G(5600, 27), /* Channel 120 */
  81. CHAN5G(5620, 28), /* Channel 124 */
  82. CHAN5G(5640, 29), /* Channel 128 */
  83. CHAN5G(5660, 30), /* Channel 132 */
  84. CHAN5G(5680, 31), /* Channel 136 */
  85. CHAN5G(5700, 32), /* Channel 140 */
  86. /* _We_ call this UNII 3 */
  87. CHAN5G(5745, 33), /* Channel 149 */
  88. CHAN5G(5765, 34), /* Channel 153 */
  89. CHAN5G(5785, 35), /* Channel 157 */
  90. CHAN5G(5805, 36), /* Channel 161 */
  91. CHAN5G(5825, 37), /* Channel 165 */
  92. };
  93. static void ath_cache_conf_rate(struct ath_softc *sc,
  94. struct ieee80211_conf *conf)
  95. {
  96. switch (conf->channel->band) {
  97. case IEEE80211_BAND_2GHZ:
  98. if (conf_is_ht20(conf))
  99. sc->cur_rate_table =
  100. sc->hw_rate_table[ATH9K_MODE_11NG_HT20];
  101. else if (conf_is_ht40_minus(conf))
  102. sc->cur_rate_table =
  103. sc->hw_rate_table[ATH9K_MODE_11NG_HT40MINUS];
  104. else if (conf_is_ht40_plus(conf))
  105. sc->cur_rate_table =
  106. sc->hw_rate_table[ATH9K_MODE_11NG_HT40PLUS];
  107. else
  108. sc->cur_rate_table =
  109. sc->hw_rate_table[ATH9K_MODE_11G];
  110. break;
  111. case IEEE80211_BAND_5GHZ:
  112. if (conf_is_ht20(conf))
  113. sc->cur_rate_table =
  114. sc->hw_rate_table[ATH9K_MODE_11NA_HT20];
  115. else if (conf_is_ht40_minus(conf))
  116. sc->cur_rate_table =
  117. sc->hw_rate_table[ATH9K_MODE_11NA_HT40MINUS];
  118. else if (conf_is_ht40_plus(conf))
  119. sc->cur_rate_table =
  120. sc->hw_rate_table[ATH9K_MODE_11NA_HT40PLUS];
  121. else
  122. sc->cur_rate_table =
  123. sc->hw_rate_table[ATH9K_MODE_11A];
  124. break;
  125. default:
  126. BUG_ON(1);
  127. break;
  128. }
  129. }
  130. static void ath_update_txpow(struct ath_softc *sc)
  131. {
  132. struct ath_hw *ah = sc->sc_ah;
  133. u32 txpow;
  134. if (sc->curtxpow != sc->config.txpowlimit) {
  135. ath9k_hw_set_txpowerlimit(ah, sc->config.txpowlimit);
  136. /* read back in case value is clamped */
  137. ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
  138. sc->curtxpow = txpow;
  139. }
  140. }
  141. static u8 parse_mpdudensity(u8 mpdudensity)
  142. {
  143. /*
  144. * 802.11n D2.0 defined values for "Minimum MPDU Start Spacing":
  145. * 0 for no restriction
  146. * 1 for 1/4 us
  147. * 2 for 1/2 us
  148. * 3 for 1 us
  149. * 4 for 2 us
  150. * 5 for 4 us
  151. * 6 for 8 us
  152. * 7 for 16 us
  153. */
  154. switch (mpdudensity) {
  155. case 0:
  156. return 0;
  157. case 1:
  158. case 2:
  159. case 3:
  160. /* Our lower layer calculations limit our precision to
  161. 1 microsecond */
  162. return 1;
  163. case 4:
  164. return 2;
  165. case 5:
  166. return 4;
  167. case 6:
  168. return 8;
  169. case 7:
  170. return 16;
  171. default:
  172. return 0;
  173. }
  174. }
  175. static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
  176. {
  177. struct ath_rate_table *rate_table = NULL;
  178. struct ieee80211_supported_band *sband;
  179. struct ieee80211_rate *rate;
  180. int i, maxrates;
  181. switch (band) {
  182. case IEEE80211_BAND_2GHZ:
  183. rate_table = sc->hw_rate_table[ATH9K_MODE_11G];
  184. break;
  185. case IEEE80211_BAND_5GHZ:
  186. rate_table = sc->hw_rate_table[ATH9K_MODE_11A];
  187. break;
  188. default:
  189. break;
  190. }
  191. if (rate_table == NULL)
  192. return;
  193. sband = &sc->sbands[band];
  194. rate = sc->rates[band];
  195. if (rate_table->rate_cnt > ATH_RATE_MAX)
  196. maxrates = ATH_RATE_MAX;
  197. else
  198. maxrates = rate_table->rate_cnt;
  199. for (i = 0; i < maxrates; i++) {
  200. rate[i].bitrate = rate_table->info[i].ratekbps / 100;
  201. rate[i].hw_value = rate_table->info[i].ratecode;
  202. if (rate_table->info[i].short_preamble) {
  203. rate[i].hw_value_short = rate_table->info[i].ratecode |
  204. rate_table->info[i].short_preamble;
  205. rate[i].flags = IEEE80211_RATE_SHORT_PREAMBLE;
  206. }
  207. sband->n_bitrates++;
  208. DPRINTF(sc, ATH_DBG_CONFIG, "Rate: %2dMbps, ratecode: %2d\n",
  209. rate[i].bitrate / 10, rate[i].hw_value);
  210. }
  211. }
  212. /*
  213. * Set/change channels. If the channel is really being changed, it's done
  214. * by reseting the chip. To accomplish this we must first cleanup any pending
  215. * DMA, then restart stuff.
  216. */
  217. int ath_set_channel(struct ath_softc *sc, struct ieee80211_hw *hw,
  218. struct ath9k_channel *hchan)
  219. {
  220. struct ath_hw *ah = sc->sc_ah;
  221. bool fastcc = true, stopped;
  222. struct ieee80211_channel *channel = hw->conf.channel;
  223. int r;
  224. if (sc->sc_flags & SC_OP_INVALID)
  225. return -EIO;
  226. ath9k_ps_wakeup(sc);
  227. /*
  228. * This is only performed if the channel settings have
  229. * actually changed.
  230. *
  231. * To switch channels clear any pending DMA operations;
  232. * wait long enough for the RX fifo to drain, reset the
  233. * hardware at the new frequency, and then re-enable
  234. * the relevant bits of the h/w.
  235. */
  236. ath9k_hw_set_interrupts(ah, 0);
  237. ath_drain_all_txq(sc, false);
  238. stopped = ath_stoprecv(sc);
  239. /* XXX: do not flush receive queue here. We don't want
  240. * to flush data frames already in queue because of
  241. * changing channel. */
  242. if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
  243. fastcc = false;
  244. DPRINTF(sc, ATH_DBG_CONFIG,
  245. "(%u MHz) -> (%u MHz), chanwidth: %d\n",
  246. sc->sc_ah->curchan->channel,
  247. channel->center_freq, sc->tx_chan_width);
  248. spin_lock_bh(&sc->sc_resetlock);
  249. r = ath9k_hw_reset(ah, hchan, fastcc);
  250. if (r) {
  251. DPRINTF(sc, ATH_DBG_FATAL,
  252. "Unable to reset channel (%u Mhz) "
  253. "reset status %u\n",
  254. channel->center_freq, r);
  255. spin_unlock_bh(&sc->sc_resetlock);
  256. return r;
  257. }
  258. spin_unlock_bh(&sc->sc_resetlock);
  259. sc->sc_flags &= ~SC_OP_FULL_RESET;
  260. if (ath_startrecv(sc) != 0) {
  261. DPRINTF(sc, ATH_DBG_FATAL,
  262. "Unable to restart recv logic\n");
  263. return -EIO;
  264. }
  265. ath_cache_conf_rate(sc, &hw->conf);
  266. ath_update_txpow(sc);
  267. ath9k_hw_set_interrupts(ah, sc->imask);
  268. ath9k_ps_restore(sc);
  269. return 0;
  270. }
  271. /*
  272. * This routine performs the periodic noise floor calibration function
  273. * that is used to adjust and optimize the chip performance. This
  274. * takes environmental changes (location, temperature) into account.
  275. * When the task is complete, it reschedules itself depending on the
  276. * appropriate interval that was calculated.
  277. */
  278. static void ath_ani_calibrate(unsigned long data)
  279. {
  280. struct ath_softc *sc = (struct ath_softc *)data;
  281. struct ath_hw *ah = sc->sc_ah;
  282. bool longcal = false;
  283. bool shortcal = false;
  284. bool aniflag = false;
  285. unsigned int timestamp = jiffies_to_msecs(jiffies);
  286. u32 cal_interval, short_cal_interval;
  287. short_cal_interval = (ah->opmode == NL80211_IFTYPE_AP) ?
  288. ATH_AP_SHORT_CALINTERVAL : ATH_STA_SHORT_CALINTERVAL;
  289. /*
  290. * don't calibrate when we're scanning.
  291. * we are most likely not on our home channel.
  292. */
  293. if (sc->sc_flags & SC_OP_SCANNING)
  294. goto set_timer;
  295. /* Long calibration runs independently of short calibration. */
  296. if ((timestamp - sc->ani.longcal_timer) >= ATH_LONG_CALINTERVAL) {
  297. longcal = true;
  298. DPRINTF(sc, ATH_DBG_ANI, "longcal @%lu\n", jiffies);
  299. sc->ani.longcal_timer = timestamp;
  300. }
  301. /* Short calibration applies only while caldone is false */
  302. if (!sc->ani.caldone) {
  303. if ((timestamp - sc->ani.shortcal_timer) >= short_cal_interval) {
  304. shortcal = true;
  305. DPRINTF(sc, ATH_DBG_ANI, "shortcal @%lu\n", jiffies);
  306. sc->ani.shortcal_timer = timestamp;
  307. sc->ani.resetcal_timer = timestamp;
  308. }
  309. } else {
  310. if ((timestamp - sc->ani.resetcal_timer) >=
  311. ATH_RESTART_CALINTERVAL) {
  312. sc->ani.caldone = ath9k_hw_reset_calvalid(ah);
  313. if (sc->ani.caldone)
  314. sc->ani.resetcal_timer = timestamp;
  315. }
  316. }
  317. /* Verify whether we must check ANI */
  318. if ((timestamp - sc->ani.checkani_timer) >= ATH_ANI_POLLINTERVAL) {
  319. aniflag = true;
  320. sc->ani.checkani_timer = timestamp;
  321. }
  322. /* Skip all processing if there's nothing to do. */
  323. if (longcal || shortcal || aniflag) {
  324. /* Call ANI routine if necessary */
  325. if (aniflag)
  326. ath9k_hw_ani_monitor(ah, &sc->nodestats, ah->curchan);
  327. /* Perform calibration if necessary */
  328. if (longcal || shortcal) {
  329. bool iscaldone = false;
  330. if (ath9k_hw_calibrate(ah, ah->curchan,
  331. sc->rx_chainmask, longcal,
  332. &iscaldone)) {
  333. if (longcal)
  334. sc->ani.noise_floor =
  335. ath9k_hw_getchan_noise(ah,
  336. ah->curchan);
  337. DPRINTF(sc, ATH_DBG_ANI,
  338. "calibrate chan %u/%x nf: %d\n",
  339. ah->curchan->channel,
  340. ah->curchan->channelFlags,
  341. sc->ani.noise_floor);
  342. } else {
  343. DPRINTF(sc, ATH_DBG_ANY,
  344. "calibrate chan %u/%x failed\n",
  345. ah->curchan->channel,
  346. ah->curchan->channelFlags);
  347. }
  348. sc->ani.caldone = iscaldone;
  349. }
  350. }
  351. set_timer:
  352. /*
  353. * Set timer interval based on previous results.
  354. * The interval must be the shortest necessary to satisfy ANI,
  355. * short calibration and long calibration.
  356. */
  357. cal_interval = ATH_LONG_CALINTERVAL;
  358. if (sc->sc_ah->config.enable_ani)
  359. cal_interval = min(cal_interval, (u32)ATH_ANI_POLLINTERVAL);
  360. if (!sc->ani.caldone)
  361. cal_interval = min(cal_interval, (u32)short_cal_interval);
  362. mod_timer(&sc->ani.timer, jiffies + msecs_to_jiffies(cal_interval));
  363. }
  364. /*
  365. * Update tx/rx chainmask. For legacy association,
  366. * hard code chainmask to 1x1, for 11n association, use
  367. * the chainmask configuration, for bt coexistence, use
  368. * the chainmask configuration even in legacy mode.
  369. */
  370. void ath_update_chainmask(struct ath_softc *sc, int is_ht)
  371. {
  372. if (is_ht ||
  373. (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)) {
  374. sc->tx_chainmask = sc->sc_ah->caps.tx_chainmask;
  375. sc->rx_chainmask = sc->sc_ah->caps.rx_chainmask;
  376. } else {
  377. sc->tx_chainmask = 1;
  378. sc->rx_chainmask = 1;
  379. }
  380. DPRINTF(sc, ATH_DBG_CONFIG, "tx chmask: %d, rx chmask: %d\n",
  381. sc->tx_chainmask, sc->rx_chainmask);
  382. }
  383. static void ath_node_attach(struct ath_softc *sc, struct ieee80211_sta *sta)
  384. {
  385. struct ath_node *an;
  386. an = (struct ath_node *)sta->drv_priv;
  387. if (sc->sc_flags & SC_OP_TXAGGR)
  388. ath_tx_node_init(sc, an);
  389. an->maxampdu = 1 << (IEEE80211_HTCAP_MAXRXAMPDU_FACTOR +
  390. sta->ht_cap.ampdu_factor);
  391. an->mpdudensity = parse_mpdudensity(sta->ht_cap.ampdu_density);
  392. }
  393. static void ath_node_detach(struct ath_softc *sc, struct ieee80211_sta *sta)
  394. {
  395. struct ath_node *an = (struct ath_node *)sta->drv_priv;
  396. if (sc->sc_flags & SC_OP_TXAGGR)
  397. ath_tx_node_cleanup(sc, an);
  398. }
  399. static void ath9k_tasklet(unsigned long data)
  400. {
  401. struct ath_softc *sc = (struct ath_softc *)data;
  402. u32 status = sc->intrstatus;
  403. if (status & ATH9K_INT_FATAL) {
  404. /* need a chip reset */
  405. ath_reset(sc, false);
  406. return;
  407. } else {
  408. if (status &
  409. (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
  410. spin_lock_bh(&sc->rx.rxflushlock);
  411. ath_rx_tasklet(sc, 0);
  412. spin_unlock_bh(&sc->rx.rxflushlock);
  413. }
  414. /* XXX: optimize this */
  415. if (status & ATH9K_INT_TX)
  416. ath_tx_tasklet(sc);
  417. }
  418. /* re-enable hardware interrupt */
  419. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  420. }
  421. irqreturn_t ath_isr(int irq, void *dev)
  422. {
  423. struct ath_softc *sc = dev;
  424. struct ath_hw *ah = sc->sc_ah;
  425. enum ath9k_int status;
  426. bool sched = false;
  427. do {
  428. if (sc->sc_flags & SC_OP_INVALID) {
  429. /*
  430. * The hardware is not ready/present, don't
  431. * touch anything. Note this can happen early
  432. * on if the IRQ is shared.
  433. */
  434. return IRQ_NONE;
  435. }
  436. if (!ath9k_hw_intrpend(ah)) { /* shared irq, not for us */
  437. return IRQ_NONE;
  438. }
  439. /*
  440. * Figure out the reason(s) for the interrupt. Note
  441. * that the hal returns a pseudo-ISR that may include
  442. * bits we haven't explicitly enabled so we mask the
  443. * value to insure we only process bits we requested.
  444. */
  445. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  446. status &= sc->imask; /* discard unasked-for bits */
  447. /*
  448. * If there are no status bits set, then this interrupt was not
  449. * for me (should have been caught above).
  450. */
  451. if (!status)
  452. return IRQ_NONE;
  453. sc->intrstatus = status;
  454. ath9k_ps_wakeup(sc);
  455. if (status & ATH9K_INT_FATAL) {
  456. /* need a chip reset */
  457. sched = true;
  458. } else if (status & ATH9K_INT_RXORN) {
  459. /* need a chip reset */
  460. sched = true;
  461. } else {
  462. if (status & ATH9K_INT_SWBA) {
  463. /* schedule a tasklet for beacon handling */
  464. tasklet_schedule(&sc->bcon_tasklet);
  465. }
  466. if (status & ATH9K_INT_RXEOL) {
  467. /*
  468. * NB: the hardware should re-read the link when
  469. * RXE bit is written, but it doesn't work
  470. * at least on older hardware revs.
  471. */
  472. sched = true;
  473. }
  474. if (status & ATH9K_INT_TXURN)
  475. /* bump tx trigger level */
  476. ath9k_hw_updatetxtriglevel(ah, true);
  477. /* XXX: optimize this */
  478. if (status & ATH9K_INT_RX)
  479. sched = true;
  480. if (status & ATH9K_INT_TX)
  481. sched = true;
  482. if (status & ATH9K_INT_BMISS)
  483. sched = true;
  484. /* carrier sense timeout */
  485. if (status & ATH9K_INT_CST)
  486. sched = true;
  487. if (status & ATH9K_INT_MIB) {
  488. /*
  489. * Disable interrupts until we service the MIB
  490. * interrupt; otherwise it will continue to
  491. * fire.
  492. */
  493. ath9k_hw_set_interrupts(ah, 0);
  494. /*
  495. * Let the hal handle the event. We assume
  496. * it will clear whatever condition caused
  497. * the interrupt.
  498. */
  499. ath9k_hw_procmibevent(ah, &sc->nodestats);
  500. ath9k_hw_set_interrupts(ah, sc->imask);
  501. }
  502. if (status & ATH9K_INT_TIM_TIMER) {
  503. if (!(ah->caps.hw_caps &
  504. ATH9K_HW_CAP_AUTOSLEEP)) {
  505. /* Clear RxAbort bit so that we can
  506. * receive frames */
  507. ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
  508. ath9k_hw_setrxabort(ah, 0);
  509. sched = true;
  510. sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
  511. }
  512. }
  513. if (status & ATH9K_INT_TSFOOR) {
  514. /* FIXME: Handle this interrupt for power save */
  515. sched = true;
  516. }
  517. }
  518. ath9k_ps_restore(sc);
  519. } while (0);
  520. ath_debug_stat_interrupt(sc, status);
  521. if (sched) {
  522. /* turn off every interrupt except SWBA */
  523. ath9k_hw_set_interrupts(ah, (sc->imask & ATH9K_INT_SWBA));
  524. tasklet_schedule(&sc->intr_tq);
  525. }
  526. return IRQ_HANDLED;
  527. }
  528. static u32 ath_get_extchanmode(struct ath_softc *sc,
  529. struct ieee80211_channel *chan,
  530. enum nl80211_channel_type channel_type)
  531. {
  532. u32 chanmode = 0;
  533. switch (chan->band) {
  534. case IEEE80211_BAND_2GHZ:
  535. switch(channel_type) {
  536. case NL80211_CHAN_NO_HT:
  537. case NL80211_CHAN_HT20:
  538. chanmode = CHANNEL_G_HT20;
  539. break;
  540. case NL80211_CHAN_HT40PLUS:
  541. chanmode = CHANNEL_G_HT40PLUS;
  542. break;
  543. case NL80211_CHAN_HT40MINUS:
  544. chanmode = CHANNEL_G_HT40MINUS;
  545. break;
  546. }
  547. break;
  548. case IEEE80211_BAND_5GHZ:
  549. switch(channel_type) {
  550. case NL80211_CHAN_NO_HT:
  551. case NL80211_CHAN_HT20:
  552. chanmode = CHANNEL_A_HT20;
  553. break;
  554. case NL80211_CHAN_HT40PLUS:
  555. chanmode = CHANNEL_A_HT40PLUS;
  556. break;
  557. case NL80211_CHAN_HT40MINUS:
  558. chanmode = CHANNEL_A_HT40MINUS;
  559. break;
  560. }
  561. break;
  562. default:
  563. break;
  564. }
  565. return chanmode;
  566. }
  567. static int ath_setkey_tkip(struct ath_softc *sc, u16 keyix, const u8 *key,
  568. struct ath9k_keyval *hk, const u8 *addr,
  569. bool authenticator)
  570. {
  571. const u8 *key_rxmic;
  572. const u8 *key_txmic;
  573. key_txmic = key + NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY;
  574. key_rxmic = key + NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY;
  575. if (addr == NULL) {
  576. /*
  577. * Group key installation - only two key cache entries are used
  578. * regardless of splitmic capability since group key is only
  579. * used either for TX or RX.
  580. */
  581. if (authenticator) {
  582. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  583. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_mic));
  584. } else {
  585. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  586. memcpy(hk->kv_txmic, key_rxmic, sizeof(hk->kv_mic));
  587. }
  588. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
  589. }
  590. if (!sc->splitmic) {
  591. /* TX and RX keys share the same key cache entry. */
  592. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  593. memcpy(hk->kv_txmic, key_txmic, sizeof(hk->kv_txmic));
  594. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, addr);
  595. }
  596. /* Separate key cache entries for TX and RX */
  597. /* TX key goes at first index, RX key at +32. */
  598. memcpy(hk->kv_mic, key_txmic, sizeof(hk->kv_mic));
  599. if (!ath9k_hw_set_keycache_entry(sc->sc_ah, keyix, hk, NULL)) {
  600. /* TX MIC entry failed. No need to proceed further */
  601. DPRINTF(sc, ATH_DBG_FATAL,
  602. "Setting TX MIC Key Failed\n");
  603. return 0;
  604. }
  605. memcpy(hk->kv_mic, key_rxmic, sizeof(hk->kv_mic));
  606. /* XXX delete tx key on failure? */
  607. return ath9k_hw_set_keycache_entry(sc->sc_ah, keyix + 32, hk, addr);
  608. }
  609. static int ath_reserve_key_cache_slot_tkip(struct ath_softc *sc)
  610. {
  611. int i;
  612. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
  613. if (test_bit(i, sc->keymap) ||
  614. test_bit(i + 64, sc->keymap))
  615. continue; /* At least one part of TKIP key allocated */
  616. if (sc->splitmic &&
  617. (test_bit(i + 32, sc->keymap) ||
  618. test_bit(i + 64 + 32, sc->keymap)))
  619. continue; /* At least one part of TKIP key allocated */
  620. /* Found a free slot for a TKIP key */
  621. return i;
  622. }
  623. return -1;
  624. }
  625. static int ath_reserve_key_cache_slot(struct ath_softc *sc)
  626. {
  627. int i;
  628. /* First, try to find slots that would not be available for TKIP. */
  629. if (sc->splitmic) {
  630. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 4; i++) {
  631. if (!test_bit(i, sc->keymap) &&
  632. (test_bit(i + 32, sc->keymap) ||
  633. test_bit(i + 64, sc->keymap) ||
  634. test_bit(i + 64 + 32, sc->keymap)))
  635. return i;
  636. if (!test_bit(i + 32, sc->keymap) &&
  637. (test_bit(i, sc->keymap) ||
  638. test_bit(i + 64, sc->keymap) ||
  639. test_bit(i + 64 + 32, sc->keymap)))
  640. return i + 32;
  641. if (!test_bit(i + 64, sc->keymap) &&
  642. (test_bit(i , sc->keymap) ||
  643. test_bit(i + 32, sc->keymap) ||
  644. test_bit(i + 64 + 32, sc->keymap)))
  645. return i + 64;
  646. if (!test_bit(i + 64 + 32, sc->keymap) &&
  647. (test_bit(i, sc->keymap) ||
  648. test_bit(i + 32, sc->keymap) ||
  649. test_bit(i + 64, sc->keymap)))
  650. return i + 64 + 32;
  651. }
  652. } else {
  653. for (i = IEEE80211_WEP_NKID; i < sc->keymax / 2; i++) {
  654. if (!test_bit(i, sc->keymap) &&
  655. test_bit(i + 64, sc->keymap))
  656. return i;
  657. if (test_bit(i, sc->keymap) &&
  658. !test_bit(i + 64, sc->keymap))
  659. return i + 64;
  660. }
  661. }
  662. /* No partially used TKIP slots, pick any available slot */
  663. for (i = IEEE80211_WEP_NKID; i < sc->keymax; i++) {
  664. /* Do not allow slots that could be needed for TKIP group keys
  665. * to be used. This limitation could be removed if we know that
  666. * TKIP will not be used. */
  667. if (i >= 64 && i < 64 + IEEE80211_WEP_NKID)
  668. continue;
  669. if (sc->splitmic) {
  670. if (i >= 32 && i < 32 + IEEE80211_WEP_NKID)
  671. continue;
  672. if (i >= 64 + 32 && i < 64 + 32 + IEEE80211_WEP_NKID)
  673. continue;
  674. }
  675. if (!test_bit(i, sc->keymap))
  676. return i; /* Found a free slot for a key */
  677. }
  678. /* No free slot found */
  679. return -1;
  680. }
  681. static int ath_key_config(struct ath_softc *sc,
  682. struct ieee80211_vif *vif,
  683. struct ieee80211_sta *sta,
  684. struct ieee80211_key_conf *key)
  685. {
  686. struct ath9k_keyval hk;
  687. const u8 *mac = NULL;
  688. int ret = 0;
  689. int idx;
  690. memset(&hk, 0, sizeof(hk));
  691. switch (key->alg) {
  692. case ALG_WEP:
  693. hk.kv_type = ATH9K_CIPHER_WEP;
  694. break;
  695. case ALG_TKIP:
  696. hk.kv_type = ATH9K_CIPHER_TKIP;
  697. break;
  698. case ALG_CCMP:
  699. hk.kv_type = ATH9K_CIPHER_AES_CCM;
  700. break;
  701. default:
  702. return -EOPNOTSUPP;
  703. }
  704. hk.kv_len = key->keylen;
  705. memcpy(hk.kv_val, key->key, key->keylen);
  706. if (!(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  707. /* For now, use the default keys for broadcast keys. This may
  708. * need to change with virtual interfaces. */
  709. idx = key->keyidx;
  710. } else if (key->keyidx) {
  711. if (WARN_ON(!sta))
  712. return -EOPNOTSUPP;
  713. mac = sta->addr;
  714. if (vif->type != NL80211_IFTYPE_AP) {
  715. /* Only keyidx 0 should be used with unicast key, but
  716. * allow this for client mode for now. */
  717. idx = key->keyidx;
  718. } else
  719. return -EIO;
  720. } else {
  721. if (WARN_ON(!sta))
  722. return -EOPNOTSUPP;
  723. mac = sta->addr;
  724. if (key->alg == ALG_TKIP)
  725. idx = ath_reserve_key_cache_slot_tkip(sc);
  726. else
  727. idx = ath_reserve_key_cache_slot(sc);
  728. if (idx < 0)
  729. return -ENOSPC; /* no free key cache entries */
  730. }
  731. if (key->alg == ALG_TKIP)
  732. ret = ath_setkey_tkip(sc, idx, key->key, &hk, mac,
  733. vif->type == NL80211_IFTYPE_AP);
  734. else
  735. ret = ath9k_hw_set_keycache_entry(sc->sc_ah, idx, &hk, mac);
  736. if (!ret)
  737. return -EIO;
  738. set_bit(idx, sc->keymap);
  739. if (key->alg == ALG_TKIP) {
  740. set_bit(idx + 64, sc->keymap);
  741. if (sc->splitmic) {
  742. set_bit(idx + 32, sc->keymap);
  743. set_bit(idx + 64 + 32, sc->keymap);
  744. }
  745. }
  746. return idx;
  747. }
  748. static void ath_key_delete(struct ath_softc *sc, struct ieee80211_key_conf *key)
  749. {
  750. ath9k_hw_keyreset(sc->sc_ah, key->hw_key_idx);
  751. if (key->hw_key_idx < IEEE80211_WEP_NKID)
  752. return;
  753. clear_bit(key->hw_key_idx, sc->keymap);
  754. if (key->alg != ALG_TKIP)
  755. return;
  756. clear_bit(key->hw_key_idx + 64, sc->keymap);
  757. if (sc->splitmic) {
  758. clear_bit(key->hw_key_idx + 32, sc->keymap);
  759. clear_bit(key->hw_key_idx + 64 + 32, sc->keymap);
  760. }
  761. }
  762. static void setup_ht_cap(struct ath_softc *sc,
  763. struct ieee80211_sta_ht_cap *ht_info)
  764. {
  765. #define ATH9K_HT_CAP_MAXRXAMPDU_65536 0x3 /* 2 ^ 16 */
  766. #define ATH9K_HT_CAP_MPDUDENSITY_8 0x6 /* 8 usec */
  767. ht_info->ht_supported = true;
  768. ht_info->cap = IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  769. IEEE80211_HT_CAP_SM_PS |
  770. IEEE80211_HT_CAP_SGI_40 |
  771. IEEE80211_HT_CAP_DSSSCCK40;
  772. ht_info->ampdu_factor = ATH9K_HT_CAP_MAXRXAMPDU_65536;
  773. ht_info->ampdu_density = ATH9K_HT_CAP_MPDUDENSITY_8;
  774. /* set up supported mcs set */
  775. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  776. switch(sc->rx_chainmask) {
  777. case 1:
  778. ht_info->mcs.rx_mask[0] = 0xff;
  779. break;
  780. case 3:
  781. case 5:
  782. case 7:
  783. default:
  784. ht_info->mcs.rx_mask[0] = 0xff;
  785. ht_info->mcs.rx_mask[1] = 0xff;
  786. break;
  787. }
  788. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  789. }
  790. static void ath9k_bss_assoc_info(struct ath_softc *sc,
  791. struct ieee80211_vif *vif,
  792. struct ieee80211_bss_conf *bss_conf)
  793. {
  794. struct ath_vif *avp = (void *)vif->drv_priv;
  795. if (bss_conf->assoc) {
  796. DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info ASSOC %d, bssid: %pM\n",
  797. bss_conf->aid, sc->curbssid);
  798. /* New association, store aid */
  799. if (avp->av_opmode == NL80211_IFTYPE_STATION) {
  800. sc->curaid = bss_conf->aid;
  801. ath9k_hw_write_associd(sc);
  802. }
  803. /* Configure the beacon */
  804. ath_beacon_config(sc, vif);
  805. /* Reset rssi stats */
  806. sc->nodestats.ns_avgbrssi = ATH_RSSI_DUMMY_MARKER;
  807. sc->nodestats.ns_avgrssi = ATH_RSSI_DUMMY_MARKER;
  808. sc->nodestats.ns_avgtxrssi = ATH_RSSI_DUMMY_MARKER;
  809. sc->nodestats.ns_avgtxrate = ATH_RATE_DUMMY_MARKER;
  810. /* Start ANI */
  811. mod_timer(&sc->ani.timer,
  812. jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
  813. } else {
  814. DPRINTF(sc, ATH_DBG_CONFIG, "Bss Info DISASSOC\n");
  815. sc->curaid = 0;
  816. }
  817. }
  818. /********************************/
  819. /* LED functions */
  820. /********************************/
  821. static void ath_led_blink_work(struct work_struct *work)
  822. {
  823. struct ath_softc *sc = container_of(work, struct ath_softc,
  824. ath_led_blink_work.work);
  825. if (!(sc->sc_flags & SC_OP_LED_ASSOCIATED))
  826. return;
  827. if ((sc->led_on_duration == ATH_LED_ON_DURATION_IDLE) ||
  828. (sc->led_off_duration == ATH_LED_OFF_DURATION_IDLE))
  829. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
  830. else
  831. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
  832. (sc->sc_flags & SC_OP_LED_ON) ? 1 : 0);
  833. queue_delayed_work(sc->hw->workqueue, &sc->ath_led_blink_work,
  834. (sc->sc_flags & SC_OP_LED_ON) ?
  835. msecs_to_jiffies(sc->led_off_duration) :
  836. msecs_to_jiffies(sc->led_on_duration));
  837. sc->led_on_duration = sc->led_on_cnt ?
  838. max((ATH_LED_ON_DURATION_IDLE - sc->led_on_cnt), 25) :
  839. ATH_LED_ON_DURATION_IDLE;
  840. sc->led_off_duration = sc->led_off_cnt ?
  841. max((ATH_LED_OFF_DURATION_IDLE - sc->led_off_cnt), 10) :
  842. ATH_LED_OFF_DURATION_IDLE;
  843. sc->led_on_cnt = sc->led_off_cnt = 0;
  844. if (sc->sc_flags & SC_OP_LED_ON)
  845. sc->sc_flags &= ~SC_OP_LED_ON;
  846. else
  847. sc->sc_flags |= SC_OP_LED_ON;
  848. }
  849. static void ath_led_brightness(struct led_classdev *led_cdev,
  850. enum led_brightness brightness)
  851. {
  852. struct ath_led *led = container_of(led_cdev, struct ath_led, led_cdev);
  853. struct ath_softc *sc = led->sc;
  854. switch (brightness) {
  855. case LED_OFF:
  856. if (led->led_type == ATH_LED_ASSOC ||
  857. led->led_type == ATH_LED_RADIO) {
  858. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN,
  859. (led->led_type == ATH_LED_RADIO));
  860. sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
  861. if (led->led_type == ATH_LED_RADIO)
  862. sc->sc_flags &= ~SC_OP_LED_ON;
  863. } else {
  864. sc->led_off_cnt++;
  865. }
  866. break;
  867. case LED_FULL:
  868. if (led->led_type == ATH_LED_ASSOC) {
  869. sc->sc_flags |= SC_OP_LED_ASSOCIATED;
  870. queue_delayed_work(sc->hw->workqueue,
  871. &sc->ath_led_blink_work, 0);
  872. } else if (led->led_type == ATH_LED_RADIO) {
  873. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 0);
  874. sc->sc_flags |= SC_OP_LED_ON;
  875. } else {
  876. sc->led_on_cnt++;
  877. }
  878. break;
  879. default:
  880. break;
  881. }
  882. }
  883. static int ath_register_led(struct ath_softc *sc, struct ath_led *led,
  884. char *trigger)
  885. {
  886. int ret;
  887. led->sc = sc;
  888. led->led_cdev.name = led->name;
  889. led->led_cdev.default_trigger = trigger;
  890. led->led_cdev.brightness_set = ath_led_brightness;
  891. ret = led_classdev_register(wiphy_dev(sc->hw->wiphy), &led->led_cdev);
  892. if (ret)
  893. DPRINTF(sc, ATH_DBG_FATAL,
  894. "Failed to register led:%s", led->name);
  895. else
  896. led->registered = 1;
  897. return ret;
  898. }
  899. static void ath_unregister_led(struct ath_led *led)
  900. {
  901. if (led->registered) {
  902. led_classdev_unregister(&led->led_cdev);
  903. led->registered = 0;
  904. }
  905. }
  906. static void ath_deinit_leds(struct ath_softc *sc)
  907. {
  908. cancel_delayed_work_sync(&sc->ath_led_blink_work);
  909. ath_unregister_led(&sc->assoc_led);
  910. sc->sc_flags &= ~SC_OP_LED_ASSOCIATED;
  911. ath_unregister_led(&sc->tx_led);
  912. ath_unregister_led(&sc->rx_led);
  913. ath_unregister_led(&sc->radio_led);
  914. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
  915. }
  916. static void ath_init_leds(struct ath_softc *sc)
  917. {
  918. char *trigger;
  919. int ret;
  920. /* Configure gpio 1 for output */
  921. ath9k_hw_cfg_output(sc->sc_ah, ATH_LED_PIN,
  922. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  923. /* LED off, active low */
  924. ath9k_hw_set_gpio(sc->sc_ah, ATH_LED_PIN, 1);
  925. INIT_DELAYED_WORK(&sc->ath_led_blink_work, ath_led_blink_work);
  926. trigger = ieee80211_get_radio_led_name(sc->hw);
  927. snprintf(sc->radio_led.name, sizeof(sc->radio_led.name),
  928. "ath9k-%s::radio", wiphy_name(sc->hw->wiphy));
  929. ret = ath_register_led(sc, &sc->radio_led, trigger);
  930. sc->radio_led.led_type = ATH_LED_RADIO;
  931. if (ret)
  932. goto fail;
  933. trigger = ieee80211_get_assoc_led_name(sc->hw);
  934. snprintf(sc->assoc_led.name, sizeof(sc->assoc_led.name),
  935. "ath9k-%s::assoc", wiphy_name(sc->hw->wiphy));
  936. ret = ath_register_led(sc, &sc->assoc_led, trigger);
  937. sc->assoc_led.led_type = ATH_LED_ASSOC;
  938. if (ret)
  939. goto fail;
  940. trigger = ieee80211_get_tx_led_name(sc->hw);
  941. snprintf(sc->tx_led.name, sizeof(sc->tx_led.name),
  942. "ath9k-%s::tx", wiphy_name(sc->hw->wiphy));
  943. ret = ath_register_led(sc, &sc->tx_led, trigger);
  944. sc->tx_led.led_type = ATH_LED_TX;
  945. if (ret)
  946. goto fail;
  947. trigger = ieee80211_get_rx_led_name(sc->hw);
  948. snprintf(sc->rx_led.name, sizeof(sc->rx_led.name),
  949. "ath9k-%s::rx", wiphy_name(sc->hw->wiphy));
  950. ret = ath_register_led(sc, &sc->rx_led, trigger);
  951. sc->rx_led.led_type = ATH_LED_RX;
  952. if (ret)
  953. goto fail;
  954. return;
  955. fail:
  956. ath_deinit_leds(sc);
  957. }
  958. void ath_radio_enable(struct ath_softc *sc)
  959. {
  960. struct ath_hw *ah = sc->sc_ah;
  961. struct ieee80211_channel *channel = sc->hw->conf.channel;
  962. int r;
  963. ath9k_ps_wakeup(sc);
  964. spin_lock_bh(&sc->sc_resetlock);
  965. r = ath9k_hw_reset(ah, ah->curchan, false);
  966. if (r) {
  967. DPRINTF(sc, ATH_DBG_FATAL,
  968. "Unable to reset channel %u (%uMhz) ",
  969. "reset status %u\n",
  970. channel->center_freq, r);
  971. }
  972. spin_unlock_bh(&sc->sc_resetlock);
  973. ath_update_txpow(sc);
  974. if (ath_startrecv(sc) != 0) {
  975. DPRINTF(sc, ATH_DBG_FATAL,
  976. "Unable to restart recv logic\n");
  977. return;
  978. }
  979. if (sc->sc_flags & SC_OP_BEACONS)
  980. ath_beacon_config(sc, NULL); /* restart beacons */
  981. /* Re-Enable interrupts */
  982. ath9k_hw_set_interrupts(ah, sc->imask);
  983. /* Enable LED */
  984. ath9k_hw_cfg_output(ah, ATH_LED_PIN,
  985. AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
  986. ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
  987. ieee80211_wake_queues(sc->hw);
  988. ath9k_ps_restore(sc);
  989. }
  990. void ath_radio_disable(struct ath_softc *sc)
  991. {
  992. struct ath_hw *ah = sc->sc_ah;
  993. struct ieee80211_channel *channel = sc->hw->conf.channel;
  994. int r;
  995. ath9k_ps_wakeup(sc);
  996. ieee80211_stop_queues(sc->hw);
  997. /* Disable LED */
  998. ath9k_hw_set_gpio(ah, ATH_LED_PIN, 1);
  999. ath9k_hw_cfg_gpio_input(ah, ATH_LED_PIN);
  1000. /* Disable interrupts */
  1001. ath9k_hw_set_interrupts(ah, 0);
  1002. ath_drain_all_txq(sc, false); /* clear pending tx frames */
  1003. ath_stoprecv(sc); /* turn off frame recv */
  1004. ath_flushrecv(sc); /* flush recv queue */
  1005. spin_lock_bh(&sc->sc_resetlock);
  1006. r = ath9k_hw_reset(ah, ah->curchan, false);
  1007. if (r) {
  1008. DPRINTF(sc, ATH_DBG_FATAL,
  1009. "Unable to reset channel %u (%uMhz) "
  1010. "reset status %u\n",
  1011. channel->center_freq, r);
  1012. }
  1013. spin_unlock_bh(&sc->sc_resetlock);
  1014. ath9k_hw_phy_disable(ah);
  1015. ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
  1016. ath9k_ps_restore(sc);
  1017. }
  1018. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1019. /*******************/
  1020. /* Rfkill */
  1021. /*******************/
  1022. static bool ath_is_rfkill_set(struct ath_softc *sc)
  1023. {
  1024. struct ath_hw *ah = sc->sc_ah;
  1025. return ath9k_hw_gpio_get(ah, ah->rfkill_gpio) ==
  1026. ah->rfkill_polarity;
  1027. }
  1028. /* h/w rfkill poll function */
  1029. static void ath_rfkill_poll(struct work_struct *work)
  1030. {
  1031. struct ath_softc *sc = container_of(work, struct ath_softc,
  1032. rf_kill.rfkill_poll.work);
  1033. bool radio_on;
  1034. if (sc->sc_flags & SC_OP_INVALID)
  1035. return;
  1036. radio_on = !ath_is_rfkill_set(sc);
  1037. /*
  1038. * enable/disable radio only when there is a
  1039. * state change in RF switch
  1040. */
  1041. if (radio_on == !!(sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED)) {
  1042. enum rfkill_state state;
  1043. if (sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED) {
  1044. state = radio_on ? RFKILL_STATE_SOFT_BLOCKED
  1045. : RFKILL_STATE_HARD_BLOCKED;
  1046. } else if (radio_on) {
  1047. ath_radio_enable(sc);
  1048. state = RFKILL_STATE_UNBLOCKED;
  1049. } else {
  1050. ath_radio_disable(sc);
  1051. state = RFKILL_STATE_HARD_BLOCKED;
  1052. }
  1053. if (state == RFKILL_STATE_HARD_BLOCKED)
  1054. sc->sc_flags |= SC_OP_RFKILL_HW_BLOCKED;
  1055. else
  1056. sc->sc_flags &= ~SC_OP_RFKILL_HW_BLOCKED;
  1057. rfkill_force_state(sc->rf_kill.rfkill, state);
  1058. }
  1059. queue_delayed_work(sc->hw->workqueue, &sc->rf_kill.rfkill_poll,
  1060. msecs_to_jiffies(ATH_RFKILL_POLL_INTERVAL));
  1061. }
  1062. /* s/w rfkill handler */
  1063. static int ath_sw_toggle_radio(void *data, enum rfkill_state state)
  1064. {
  1065. struct ath_softc *sc = data;
  1066. switch (state) {
  1067. case RFKILL_STATE_SOFT_BLOCKED:
  1068. if (!(sc->sc_flags & (SC_OP_RFKILL_HW_BLOCKED |
  1069. SC_OP_RFKILL_SW_BLOCKED)))
  1070. ath_radio_disable(sc);
  1071. sc->sc_flags |= SC_OP_RFKILL_SW_BLOCKED;
  1072. return 0;
  1073. case RFKILL_STATE_UNBLOCKED:
  1074. if ((sc->sc_flags & SC_OP_RFKILL_SW_BLOCKED)) {
  1075. sc->sc_flags &= ~SC_OP_RFKILL_SW_BLOCKED;
  1076. if (sc->sc_flags & SC_OP_RFKILL_HW_BLOCKED) {
  1077. DPRINTF(sc, ATH_DBG_FATAL, "Can't turn on the"
  1078. "radio as it is disabled by h/w\n");
  1079. return -EPERM;
  1080. }
  1081. ath_radio_enable(sc);
  1082. }
  1083. return 0;
  1084. default:
  1085. return -EINVAL;
  1086. }
  1087. }
  1088. /* Init s/w rfkill */
  1089. static int ath_init_sw_rfkill(struct ath_softc *sc)
  1090. {
  1091. sc->rf_kill.rfkill = rfkill_allocate(wiphy_dev(sc->hw->wiphy),
  1092. RFKILL_TYPE_WLAN);
  1093. if (!sc->rf_kill.rfkill) {
  1094. DPRINTF(sc, ATH_DBG_FATAL, "Failed to allocate rfkill\n");
  1095. return -ENOMEM;
  1096. }
  1097. snprintf(sc->rf_kill.rfkill_name, sizeof(sc->rf_kill.rfkill_name),
  1098. "ath9k-%s::rfkill", wiphy_name(sc->hw->wiphy));
  1099. sc->rf_kill.rfkill->name = sc->rf_kill.rfkill_name;
  1100. sc->rf_kill.rfkill->data = sc;
  1101. sc->rf_kill.rfkill->toggle_radio = ath_sw_toggle_radio;
  1102. sc->rf_kill.rfkill->state = RFKILL_STATE_UNBLOCKED;
  1103. return 0;
  1104. }
  1105. /* Deinitialize rfkill */
  1106. static void ath_deinit_rfkill(struct ath_softc *sc)
  1107. {
  1108. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1109. cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
  1110. if (sc->sc_flags & SC_OP_RFKILL_REGISTERED) {
  1111. rfkill_unregister(sc->rf_kill.rfkill);
  1112. sc->sc_flags &= ~SC_OP_RFKILL_REGISTERED;
  1113. sc->rf_kill.rfkill = NULL;
  1114. }
  1115. }
  1116. static int ath_start_rfkill_poll(struct ath_softc *sc)
  1117. {
  1118. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1119. queue_delayed_work(sc->hw->workqueue,
  1120. &sc->rf_kill.rfkill_poll, 0);
  1121. if (!(sc->sc_flags & SC_OP_RFKILL_REGISTERED)) {
  1122. if (rfkill_register(sc->rf_kill.rfkill)) {
  1123. DPRINTF(sc, ATH_DBG_FATAL,
  1124. "Unable to register rfkill\n");
  1125. rfkill_free(sc->rf_kill.rfkill);
  1126. /* Deinitialize the device */
  1127. ath_cleanup(sc);
  1128. return -EIO;
  1129. } else {
  1130. sc->sc_flags |= SC_OP_RFKILL_REGISTERED;
  1131. }
  1132. }
  1133. return 0;
  1134. }
  1135. #endif /* CONFIG_RFKILL */
  1136. void ath_cleanup(struct ath_softc *sc)
  1137. {
  1138. ath_detach(sc);
  1139. free_irq(sc->irq, sc);
  1140. ath_bus_cleanup(sc);
  1141. kfree(sc->sec_wiphy);
  1142. ieee80211_free_hw(sc->hw);
  1143. }
  1144. void ath_detach(struct ath_softc *sc)
  1145. {
  1146. struct ieee80211_hw *hw = sc->hw;
  1147. int i = 0;
  1148. ath9k_ps_wakeup(sc);
  1149. DPRINTF(sc, ATH_DBG_CONFIG, "Detach ATH hw\n");
  1150. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1151. ath_deinit_rfkill(sc);
  1152. #endif
  1153. ath_deinit_leds(sc);
  1154. cancel_work_sync(&sc->chan_work);
  1155. cancel_delayed_work_sync(&sc->wiphy_work);
  1156. for (i = 0; i < sc->num_sec_wiphy; i++) {
  1157. struct ath_wiphy *aphy = sc->sec_wiphy[i];
  1158. if (aphy == NULL)
  1159. continue;
  1160. sc->sec_wiphy[i] = NULL;
  1161. ieee80211_unregister_hw(aphy->hw);
  1162. ieee80211_free_hw(aphy->hw);
  1163. }
  1164. ieee80211_unregister_hw(hw);
  1165. ath_rx_cleanup(sc);
  1166. ath_tx_cleanup(sc);
  1167. tasklet_kill(&sc->intr_tq);
  1168. tasklet_kill(&sc->bcon_tasklet);
  1169. if (!(sc->sc_flags & SC_OP_INVALID))
  1170. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  1171. /* cleanup tx queues */
  1172. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1173. if (ATH_TXQ_SETUP(sc, i))
  1174. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1175. ath9k_hw_detach(sc->sc_ah);
  1176. ath9k_exit_debug(sc);
  1177. ath9k_ps_restore(sc);
  1178. }
  1179. static int ath_init(u16 devid, struct ath_softc *sc)
  1180. {
  1181. struct ath_hw *ah = NULL;
  1182. int status;
  1183. int error = 0, i;
  1184. int csz = 0;
  1185. /* XXX: hardware will not be ready until ath_open() being called */
  1186. sc->sc_flags |= SC_OP_INVALID;
  1187. if (ath9k_init_debug(sc) < 0)
  1188. printk(KERN_ERR "Unable to create debugfs files\n");
  1189. spin_lock_init(&sc->wiphy_lock);
  1190. spin_lock_init(&sc->sc_resetlock);
  1191. spin_lock_init(&sc->sc_serial_rw);
  1192. mutex_init(&sc->mutex);
  1193. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  1194. tasklet_init(&sc->bcon_tasklet, ath_beacon_tasklet,
  1195. (unsigned long)sc);
  1196. /*
  1197. * Cache line size is used to size and align various
  1198. * structures used to communicate with the hardware.
  1199. */
  1200. ath_read_cachesize(sc, &csz);
  1201. /* XXX assert csz is non-zero */
  1202. sc->cachelsz = csz << 2; /* convert to bytes */
  1203. ah = ath9k_hw_attach(devid, sc, &status);
  1204. if (ah == NULL) {
  1205. DPRINTF(sc, ATH_DBG_FATAL,
  1206. "Unable to attach hardware; HAL status %d\n", status);
  1207. error = -ENXIO;
  1208. goto bad;
  1209. }
  1210. sc->sc_ah = ah;
  1211. /* Get the hardware key cache size. */
  1212. sc->keymax = ah->caps.keycache_size;
  1213. if (sc->keymax > ATH_KEYMAX) {
  1214. DPRINTF(sc, ATH_DBG_ANY,
  1215. "Warning, using only %u entries in %u key cache\n",
  1216. ATH_KEYMAX, sc->keymax);
  1217. sc->keymax = ATH_KEYMAX;
  1218. }
  1219. /*
  1220. * Reset the key cache since some parts do not
  1221. * reset the contents on initial power up.
  1222. */
  1223. for (i = 0; i < sc->keymax; i++)
  1224. ath9k_hw_keyreset(ah, (u16) i);
  1225. if (ath9k_regd_init(sc->sc_ah))
  1226. goto bad;
  1227. /* default to MONITOR mode */
  1228. sc->sc_ah->opmode = NL80211_IFTYPE_MONITOR;
  1229. /* Setup rate tables */
  1230. ath_rate_attach(sc);
  1231. ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
  1232. ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
  1233. /*
  1234. * Allocate hardware transmit queues: one queue for
  1235. * beacon frames and one data queue for each QoS
  1236. * priority. Note that the hal handles reseting
  1237. * these queues at the needed time.
  1238. */
  1239. sc->beacon.beaconq = ath_beaconq_setup(ah);
  1240. if (sc->beacon.beaconq == -1) {
  1241. DPRINTF(sc, ATH_DBG_FATAL,
  1242. "Unable to setup a beacon xmit queue\n");
  1243. error = -EIO;
  1244. goto bad2;
  1245. }
  1246. sc->beacon.cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  1247. if (sc->beacon.cabq == NULL) {
  1248. DPRINTF(sc, ATH_DBG_FATAL,
  1249. "Unable to setup CAB xmit queue\n");
  1250. error = -EIO;
  1251. goto bad2;
  1252. }
  1253. sc->config.cabqReadytime = ATH_CABQ_READY_TIME;
  1254. ath_cabq_update(sc);
  1255. for (i = 0; i < ARRAY_SIZE(sc->tx.hwq_map); i++)
  1256. sc->tx.hwq_map[i] = -1;
  1257. /* Setup data queues */
  1258. /* NB: ensure BK queue is the lowest priority h/w queue */
  1259. if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
  1260. DPRINTF(sc, ATH_DBG_FATAL,
  1261. "Unable to setup xmit queue for BK traffic\n");
  1262. error = -EIO;
  1263. goto bad2;
  1264. }
  1265. if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
  1266. DPRINTF(sc, ATH_DBG_FATAL,
  1267. "Unable to setup xmit queue for BE traffic\n");
  1268. error = -EIO;
  1269. goto bad2;
  1270. }
  1271. if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
  1272. DPRINTF(sc, ATH_DBG_FATAL,
  1273. "Unable to setup xmit queue for VI traffic\n");
  1274. error = -EIO;
  1275. goto bad2;
  1276. }
  1277. if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
  1278. DPRINTF(sc, ATH_DBG_FATAL,
  1279. "Unable to setup xmit queue for VO traffic\n");
  1280. error = -EIO;
  1281. goto bad2;
  1282. }
  1283. /* Initializes the noise floor to a reasonable default value.
  1284. * Later on this will be updated during ANI processing. */
  1285. sc->ani.noise_floor = ATH_DEFAULT_NOISE_FLOOR;
  1286. setup_timer(&sc->ani.timer, ath_ani_calibrate, (unsigned long)sc);
  1287. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1288. ATH9K_CIPHER_TKIP, NULL)) {
  1289. /*
  1290. * Whether we should enable h/w TKIP MIC.
  1291. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  1292. * report WMM capable, so it's always safe to turn on
  1293. * TKIP MIC in this case.
  1294. */
  1295. ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
  1296. 0, 1, NULL);
  1297. }
  1298. /*
  1299. * Check whether the separate key cache entries
  1300. * are required to handle both tx+rx MIC keys.
  1301. * With split mic keys the number of stations is limited
  1302. * to 27 otherwise 59.
  1303. */
  1304. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1305. ATH9K_CIPHER_TKIP, NULL)
  1306. && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1307. ATH9K_CIPHER_MIC, NULL)
  1308. && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
  1309. 0, NULL))
  1310. sc->splitmic = 1;
  1311. /* turn on mcast key search if possible */
  1312. if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  1313. (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
  1314. 1, NULL);
  1315. sc->config.txpowlimit = ATH_TXPOWER_MAX;
  1316. /* 11n Capabilities */
  1317. if (ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  1318. sc->sc_flags |= SC_OP_TXAGGR;
  1319. sc->sc_flags |= SC_OP_RXAGGR;
  1320. }
  1321. sc->tx_chainmask = ah->caps.tx_chainmask;
  1322. sc->rx_chainmask = ah->caps.rx_chainmask;
  1323. ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
  1324. sc->rx.defant = ath9k_hw_getdefantenna(ah);
  1325. if (ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1326. memcpy(sc->bssidmask, ath_bcast_mac, ETH_ALEN);
  1327. sc->beacon.slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
  1328. /* initialize beacon slots */
  1329. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1330. sc->beacon.bslot[i] = NULL;
  1331. sc->beacon.bslot_aphy[i] = NULL;
  1332. }
  1333. /* setup channels and rates */
  1334. sc->sbands[IEEE80211_BAND_2GHZ].channels = ath9k_2ghz_chantable;
  1335. sc->sbands[IEEE80211_BAND_2GHZ].bitrates =
  1336. sc->rates[IEEE80211_BAND_2GHZ];
  1337. sc->sbands[IEEE80211_BAND_2GHZ].band = IEEE80211_BAND_2GHZ;
  1338. sc->sbands[IEEE80211_BAND_2GHZ].n_channels =
  1339. ARRAY_SIZE(ath9k_2ghz_chantable);
  1340. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes)) {
  1341. sc->sbands[IEEE80211_BAND_5GHZ].channels = ath9k_5ghz_chantable;
  1342. sc->sbands[IEEE80211_BAND_5GHZ].bitrates =
  1343. sc->rates[IEEE80211_BAND_5GHZ];
  1344. sc->sbands[IEEE80211_BAND_5GHZ].band = IEEE80211_BAND_5GHZ;
  1345. sc->sbands[IEEE80211_BAND_5GHZ].n_channels =
  1346. ARRAY_SIZE(ath9k_5ghz_chantable);
  1347. }
  1348. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BT_COEX)
  1349. ath9k_hw_btcoex_enable(sc->sc_ah);
  1350. return 0;
  1351. bad2:
  1352. /* cleanup tx queues */
  1353. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1354. if (ATH_TXQ_SETUP(sc, i))
  1355. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1356. bad:
  1357. if (ah)
  1358. ath9k_hw_detach(ah);
  1359. ath9k_exit_debug(sc);
  1360. return error;
  1361. }
  1362. void ath_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
  1363. {
  1364. hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
  1365. IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
  1366. IEEE80211_HW_SIGNAL_DBM |
  1367. IEEE80211_HW_AMPDU_AGGREGATION |
  1368. IEEE80211_HW_SUPPORTS_PS |
  1369. IEEE80211_HW_PS_NULLFUNC_STACK |
  1370. IEEE80211_HW_SPECTRUM_MGMT;
  1371. if (AR_SREV_9160_10_OR_LATER(sc->sc_ah) || modparam_nohwcrypt)
  1372. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  1373. hw->wiphy->interface_modes =
  1374. BIT(NL80211_IFTYPE_AP) |
  1375. BIT(NL80211_IFTYPE_STATION) |
  1376. BIT(NL80211_IFTYPE_ADHOC) |
  1377. BIT(NL80211_IFTYPE_MESH_POINT);
  1378. hw->wiphy->reg_notifier = ath9k_reg_notifier;
  1379. hw->wiphy->strict_regulatory = true;
  1380. hw->queues = 4;
  1381. hw->max_rates = 4;
  1382. hw->channel_change_time = 5000;
  1383. hw->max_listen_interval = 10;
  1384. hw->max_rate_tries = ATH_11N_TXMAXTRY;
  1385. hw->sta_data_size = sizeof(struct ath_node);
  1386. hw->vif_data_size = sizeof(struct ath_vif);
  1387. hw->rate_control_algorithm = "ath9k_rate_control";
  1388. hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1389. &sc->sbands[IEEE80211_BAND_2GHZ];
  1390. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  1391. hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1392. &sc->sbands[IEEE80211_BAND_5GHZ];
  1393. }
  1394. int ath_attach(u16 devid, struct ath_softc *sc)
  1395. {
  1396. struct ieee80211_hw *hw = sc->hw;
  1397. const struct ieee80211_regdomain *regd;
  1398. int error = 0, i;
  1399. DPRINTF(sc, ATH_DBG_CONFIG, "Attach ATH hw\n");
  1400. error = ath_init(devid, sc);
  1401. if (error != 0)
  1402. return error;
  1403. /* get mac address from hardware and set in mac80211 */
  1404. SET_IEEE80211_PERM_ADDR(hw, sc->sc_ah->macaddr);
  1405. ath_set_hw_capab(sc, hw);
  1406. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
  1407. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
  1408. if (test_bit(ATH9K_MODE_11A, sc->sc_ah->caps.wireless_modes))
  1409. setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
  1410. }
  1411. /* initialize tx/rx engine */
  1412. error = ath_tx_init(sc, ATH_TXBUF);
  1413. if (error != 0)
  1414. goto error_attach;
  1415. error = ath_rx_init(sc, ATH_RXBUF);
  1416. if (error != 0)
  1417. goto error_attach;
  1418. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1419. /* Initialze h/w Rfkill */
  1420. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1421. INIT_DELAYED_WORK(&sc->rf_kill.rfkill_poll, ath_rfkill_poll);
  1422. /* Initialize s/w rfkill */
  1423. error = ath_init_sw_rfkill(sc);
  1424. if (error)
  1425. goto error_attach;
  1426. #endif
  1427. if (ath9k_is_world_regd(sc->sc_ah)) {
  1428. /* Anything applied here (prior to wiphy registration) gets
  1429. * saved on the wiphy orig_* parameters */
  1430. regd = ath9k_world_regdomain(sc->sc_ah);
  1431. hw->wiphy->custom_regulatory = true;
  1432. hw->wiphy->strict_regulatory = false;
  1433. } else {
  1434. /* This gets applied in the case of the absense of CRDA,
  1435. * it's our own custom world regulatory domain, similar to
  1436. * cfg80211's but we enable passive scanning */
  1437. regd = ath9k_default_world_regdomain();
  1438. }
  1439. wiphy_apply_custom_regulatory(hw->wiphy, regd);
  1440. ath9k_reg_apply_radar_flags(hw->wiphy);
  1441. ath9k_reg_apply_world_flags(hw->wiphy, NL80211_REGDOM_SET_BY_DRIVER);
  1442. INIT_WORK(&sc->chan_work, ath9k_wiphy_chan_work);
  1443. INIT_DELAYED_WORK(&sc->wiphy_work, ath9k_wiphy_work);
  1444. sc->wiphy_scheduler_int = msecs_to_jiffies(500);
  1445. error = ieee80211_register_hw(hw);
  1446. if (!ath9k_is_world_regd(sc->sc_ah)) {
  1447. error = regulatory_hint(hw->wiphy,
  1448. sc->sc_ah->regulatory.alpha2);
  1449. if (error)
  1450. goto error_attach;
  1451. }
  1452. /* Initialize LED control */
  1453. ath_init_leds(sc);
  1454. return 0;
  1455. error_attach:
  1456. /* cleanup tx queues */
  1457. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1458. if (ATH_TXQ_SETUP(sc, i))
  1459. ath_tx_cleanupq(sc, &sc->tx.txq[i]);
  1460. ath9k_hw_detach(sc->sc_ah);
  1461. ath9k_exit_debug(sc);
  1462. return error;
  1463. }
  1464. int ath_reset(struct ath_softc *sc, bool retry_tx)
  1465. {
  1466. struct ath_hw *ah = sc->sc_ah;
  1467. struct ieee80211_hw *hw = sc->hw;
  1468. int r;
  1469. ath9k_hw_set_interrupts(ah, 0);
  1470. ath_drain_all_txq(sc, retry_tx);
  1471. ath_stoprecv(sc);
  1472. ath_flushrecv(sc);
  1473. spin_lock_bh(&sc->sc_resetlock);
  1474. r = ath9k_hw_reset(ah, sc->sc_ah->curchan, false);
  1475. if (r)
  1476. DPRINTF(sc, ATH_DBG_FATAL,
  1477. "Unable to reset hardware; reset status %u\n", r);
  1478. spin_unlock_bh(&sc->sc_resetlock);
  1479. if (ath_startrecv(sc) != 0)
  1480. DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
  1481. /*
  1482. * We may be doing a reset in response to a request
  1483. * that changes the channel so update any state that
  1484. * might change as a result.
  1485. */
  1486. ath_cache_conf_rate(sc, &hw->conf);
  1487. ath_update_txpow(sc);
  1488. if (sc->sc_flags & SC_OP_BEACONS)
  1489. ath_beacon_config(sc, NULL); /* restart beacons */
  1490. ath9k_hw_set_interrupts(ah, sc->imask);
  1491. if (retry_tx) {
  1492. int i;
  1493. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  1494. if (ATH_TXQ_SETUP(sc, i)) {
  1495. spin_lock_bh(&sc->tx.txq[i].axq_lock);
  1496. ath_txq_schedule(sc, &sc->tx.txq[i]);
  1497. spin_unlock_bh(&sc->tx.txq[i].axq_lock);
  1498. }
  1499. }
  1500. }
  1501. return r;
  1502. }
  1503. /*
  1504. * This function will allocate both the DMA descriptor structure, and the
  1505. * buffers it contains. These are used to contain the descriptors used
  1506. * by the system.
  1507. */
  1508. int ath_descdma_setup(struct ath_softc *sc, struct ath_descdma *dd,
  1509. struct list_head *head, const char *name,
  1510. int nbuf, int ndesc)
  1511. {
  1512. #define DS2PHYS(_dd, _ds) \
  1513. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  1514. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  1515. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  1516. struct ath_desc *ds;
  1517. struct ath_buf *bf;
  1518. int i, bsize, error;
  1519. DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA: %u buffers %u desc/buf\n",
  1520. name, nbuf, ndesc);
  1521. INIT_LIST_HEAD(head);
  1522. /* ath_desc must be a multiple of DWORDs */
  1523. if ((sizeof(struct ath_desc) % 4) != 0) {
  1524. DPRINTF(sc, ATH_DBG_FATAL, "ath_desc not DWORD aligned\n");
  1525. ASSERT((sizeof(struct ath_desc) % 4) == 0);
  1526. error = -ENOMEM;
  1527. goto fail;
  1528. }
  1529. dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
  1530. /*
  1531. * Need additional DMA memory because we can't use
  1532. * descriptors that cross the 4K page boundary. Assume
  1533. * one skipped descriptor per 4K page.
  1534. */
  1535. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1536. u32 ndesc_skipped =
  1537. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  1538. u32 dma_len;
  1539. while (ndesc_skipped) {
  1540. dma_len = ndesc_skipped * sizeof(struct ath_desc);
  1541. dd->dd_desc_len += dma_len;
  1542. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  1543. };
  1544. }
  1545. /* allocate descriptors */
  1546. dd->dd_desc = dma_alloc_coherent(sc->dev, dd->dd_desc_len,
  1547. &dd->dd_desc_paddr, GFP_KERNEL);
  1548. if (dd->dd_desc == NULL) {
  1549. error = -ENOMEM;
  1550. goto fail;
  1551. }
  1552. ds = dd->dd_desc;
  1553. DPRINTF(sc, ATH_DBG_CONFIG, "%s DMA map: %p (%u) -> %llx (%u)\n",
  1554. name, ds, (u32) dd->dd_desc_len,
  1555. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  1556. /* allocate buffers */
  1557. bsize = sizeof(struct ath_buf) * nbuf;
  1558. bf = kzalloc(bsize, GFP_KERNEL);
  1559. if (bf == NULL) {
  1560. error = -ENOMEM;
  1561. goto fail2;
  1562. }
  1563. dd->dd_bufptr = bf;
  1564. for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
  1565. bf->bf_desc = ds;
  1566. bf->bf_daddr = DS2PHYS(dd, ds);
  1567. if (!(sc->sc_ah->caps.hw_caps &
  1568. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1569. /*
  1570. * Skip descriptor addresses which can cause 4KB
  1571. * boundary crossing (addr + length) with a 32 dword
  1572. * descriptor fetch.
  1573. */
  1574. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  1575. ASSERT((caddr_t) bf->bf_desc <
  1576. ((caddr_t) dd->dd_desc +
  1577. dd->dd_desc_len));
  1578. ds += ndesc;
  1579. bf->bf_desc = ds;
  1580. bf->bf_daddr = DS2PHYS(dd, ds);
  1581. }
  1582. }
  1583. list_add_tail(&bf->list, head);
  1584. }
  1585. return 0;
  1586. fail2:
  1587. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  1588. dd->dd_desc_paddr);
  1589. fail:
  1590. memset(dd, 0, sizeof(*dd));
  1591. return error;
  1592. #undef ATH_DESC_4KB_BOUND_CHECK
  1593. #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
  1594. #undef DS2PHYS
  1595. }
  1596. void ath_descdma_cleanup(struct ath_softc *sc,
  1597. struct ath_descdma *dd,
  1598. struct list_head *head)
  1599. {
  1600. dma_free_coherent(sc->dev, dd->dd_desc_len, dd->dd_desc,
  1601. dd->dd_desc_paddr);
  1602. INIT_LIST_HEAD(head);
  1603. kfree(dd->dd_bufptr);
  1604. memset(dd, 0, sizeof(*dd));
  1605. }
  1606. int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
  1607. {
  1608. int qnum;
  1609. switch (queue) {
  1610. case 0:
  1611. qnum = sc->tx.hwq_map[ATH9K_WME_AC_VO];
  1612. break;
  1613. case 1:
  1614. qnum = sc->tx.hwq_map[ATH9K_WME_AC_VI];
  1615. break;
  1616. case 2:
  1617. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
  1618. break;
  1619. case 3:
  1620. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BK];
  1621. break;
  1622. default:
  1623. qnum = sc->tx.hwq_map[ATH9K_WME_AC_BE];
  1624. break;
  1625. }
  1626. return qnum;
  1627. }
  1628. int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
  1629. {
  1630. int qnum;
  1631. switch (queue) {
  1632. case ATH9K_WME_AC_VO:
  1633. qnum = 0;
  1634. break;
  1635. case ATH9K_WME_AC_VI:
  1636. qnum = 1;
  1637. break;
  1638. case ATH9K_WME_AC_BE:
  1639. qnum = 2;
  1640. break;
  1641. case ATH9K_WME_AC_BK:
  1642. qnum = 3;
  1643. break;
  1644. default:
  1645. qnum = -1;
  1646. break;
  1647. }
  1648. return qnum;
  1649. }
  1650. /* XXX: Remove me once we don't depend on ath9k_channel for all
  1651. * this redundant data */
  1652. void ath9k_update_ichannel(struct ath_softc *sc, struct ieee80211_hw *hw,
  1653. struct ath9k_channel *ichan)
  1654. {
  1655. struct ieee80211_channel *chan = hw->conf.channel;
  1656. struct ieee80211_conf *conf = &hw->conf;
  1657. ichan->channel = chan->center_freq;
  1658. ichan->chan = chan;
  1659. if (chan->band == IEEE80211_BAND_2GHZ) {
  1660. ichan->chanmode = CHANNEL_G;
  1661. ichan->channelFlags = CHANNEL_2GHZ | CHANNEL_OFDM;
  1662. } else {
  1663. ichan->chanmode = CHANNEL_A;
  1664. ichan->channelFlags = CHANNEL_5GHZ | CHANNEL_OFDM;
  1665. }
  1666. sc->tx_chan_width = ATH9K_HT_MACMODE_20;
  1667. if (conf_is_ht(conf)) {
  1668. if (conf_is_ht40(conf))
  1669. sc->tx_chan_width = ATH9K_HT_MACMODE_2040;
  1670. ichan->chanmode = ath_get_extchanmode(sc, chan,
  1671. conf->channel_type);
  1672. }
  1673. }
  1674. /**********************/
  1675. /* mac80211 callbacks */
  1676. /**********************/
  1677. static int ath9k_start(struct ieee80211_hw *hw)
  1678. {
  1679. struct ath_wiphy *aphy = hw->priv;
  1680. struct ath_softc *sc = aphy->sc;
  1681. struct ieee80211_channel *curchan = hw->conf.channel;
  1682. struct ath9k_channel *init_channel;
  1683. int r, pos;
  1684. DPRINTF(sc, ATH_DBG_CONFIG, "Starting driver with "
  1685. "initial channel: %d MHz\n", curchan->center_freq);
  1686. mutex_lock(&sc->mutex);
  1687. if (ath9k_wiphy_started(sc)) {
  1688. if (sc->chan_idx == curchan->hw_value) {
  1689. /*
  1690. * Already on the operational channel, the new wiphy
  1691. * can be marked active.
  1692. */
  1693. aphy->state = ATH_WIPHY_ACTIVE;
  1694. ieee80211_wake_queues(hw);
  1695. } else {
  1696. /*
  1697. * Another wiphy is on another channel, start the new
  1698. * wiphy in paused state.
  1699. */
  1700. aphy->state = ATH_WIPHY_PAUSED;
  1701. ieee80211_stop_queues(hw);
  1702. }
  1703. mutex_unlock(&sc->mutex);
  1704. return 0;
  1705. }
  1706. aphy->state = ATH_WIPHY_ACTIVE;
  1707. /* setup initial channel */
  1708. pos = curchan->hw_value;
  1709. sc->chan_idx = pos;
  1710. init_channel = &sc->sc_ah->channels[pos];
  1711. ath9k_update_ichannel(sc, hw, init_channel);
  1712. /* Reset SERDES registers */
  1713. ath9k_hw_configpcipowersave(sc->sc_ah, 0);
  1714. /*
  1715. * The basic interface to setting the hardware in a good
  1716. * state is ``reset''. On return the hardware is known to
  1717. * be powered up and with interrupts disabled. This must
  1718. * be followed by initialization of the appropriate bits
  1719. * and then setup of the interrupt mask.
  1720. */
  1721. spin_lock_bh(&sc->sc_resetlock);
  1722. r = ath9k_hw_reset(sc->sc_ah, init_channel, false);
  1723. if (r) {
  1724. DPRINTF(sc, ATH_DBG_FATAL,
  1725. "Unable to reset hardware; reset status %u "
  1726. "(freq %u MHz)\n", r,
  1727. curchan->center_freq);
  1728. spin_unlock_bh(&sc->sc_resetlock);
  1729. goto mutex_unlock;
  1730. }
  1731. spin_unlock_bh(&sc->sc_resetlock);
  1732. /*
  1733. * This is needed only to setup initial state
  1734. * but it's best done after a reset.
  1735. */
  1736. ath_update_txpow(sc);
  1737. /*
  1738. * Setup the hardware after reset:
  1739. * The receive engine is set going.
  1740. * Frame transmit is handled entirely
  1741. * in the frame output path; there's nothing to do
  1742. * here except setup the interrupt mask.
  1743. */
  1744. if (ath_startrecv(sc) != 0) {
  1745. DPRINTF(sc, ATH_DBG_FATAL, "Unable to start recv logic\n");
  1746. r = -EIO;
  1747. goto mutex_unlock;
  1748. }
  1749. /* Setup our intr mask. */
  1750. sc->imask = ATH9K_INT_RX | ATH9K_INT_TX
  1751. | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
  1752. | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
  1753. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_GTT)
  1754. sc->imask |= ATH9K_INT_GTT;
  1755. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT)
  1756. sc->imask |= ATH9K_INT_CST;
  1757. ath_cache_conf_rate(sc, &hw->conf);
  1758. sc->sc_flags &= ~SC_OP_INVALID;
  1759. /* Disable BMISS interrupt when we're not associated */
  1760. sc->imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  1761. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  1762. ieee80211_wake_queues(hw);
  1763. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1764. r = ath_start_rfkill_poll(sc);
  1765. #endif
  1766. mutex_unlock:
  1767. mutex_unlock(&sc->mutex);
  1768. return r;
  1769. }
  1770. static int ath9k_tx(struct ieee80211_hw *hw,
  1771. struct sk_buff *skb)
  1772. {
  1773. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1774. struct ath_wiphy *aphy = hw->priv;
  1775. struct ath_softc *sc = aphy->sc;
  1776. struct ath_tx_control txctl;
  1777. int hdrlen, padsize;
  1778. if (aphy->state != ATH_WIPHY_ACTIVE && aphy->state != ATH_WIPHY_SCAN) {
  1779. printk(KERN_DEBUG "ath9k: %s: TX in unexpected wiphy state "
  1780. "%d\n", wiphy_name(hw->wiphy), aphy->state);
  1781. goto exit;
  1782. }
  1783. memset(&txctl, 0, sizeof(struct ath_tx_control));
  1784. /*
  1785. * As a temporary workaround, assign seq# here; this will likely need
  1786. * to be cleaned up to work better with Beacon transmission and virtual
  1787. * BSSes.
  1788. */
  1789. if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) {
  1790. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1791. if (info->flags & IEEE80211_TX_CTL_FIRST_FRAGMENT)
  1792. sc->tx.seq_no += 0x10;
  1793. hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
  1794. hdr->seq_ctrl |= cpu_to_le16(sc->tx.seq_no);
  1795. }
  1796. /* Add the padding after the header if this is not already done */
  1797. hdrlen = ieee80211_get_hdrlen_from_skb(skb);
  1798. if (hdrlen & 3) {
  1799. padsize = hdrlen % 4;
  1800. if (skb_headroom(skb) < padsize)
  1801. return -1;
  1802. skb_push(skb, padsize);
  1803. memmove(skb->data, skb->data + padsize, hdrlen);
  1804. }
  1805. /* Check if a tx queue is available */
  1806. txctl.txq = ath_test_get_txq(sc, skb);
  1807. if (!txctl.txq)
  1808. goto exit;
  1809. DPRINTF(sc, ATH_DBG_XMIT, "transmitting packet, skb: %p\n", skb);
  1810. if (ath_tx_start(hw, skb, &txctl) != 0) {
  1811. DPRINTF(sc, ATH_DBG_XMIT, "TX failed\n");
  1812. goto exit;
  1813. }
  1814. return 0;
  1815. exit:
  1816. dev_kfree_skb_any(skb);
  1817. return 0;
  1818. }
  1819. static void ath9k_stop(struct ieee80211_hw *hw)
  1820. {
  1821. struct ath_wiphy *aphy = hw->priv;
  1822. struct ath_softc *sc = aphy->sc;
  1823. aphy->state = ATH_WIPHY_INACTIVE;
  1824. if (sc->sc_flags & SC_OP_INVALID) {
  1825. DPRINTF(sc, ATH_DBG_ANY, "Device not present\n");
  1826. return;
  1827. }
  1828. mutex_lock(&sc->mutex);
  1829. ieee80211_stop_queues(hw);
  1830. if (ath9k_wiphy_started(sc)) {
  1831. mutex_unlock(&sc->mutex);
  1832. return; /* another wiphy still in use */
  1833. }
  1834. /* make sure h/w will not generate any interrupt
  1835. * before setting the invalid flag. */
  1836. ath9k_hw_set_interrupts(sc->sc_ah, 0);
  1837. if (!(sc->sc_flags & SC_OP_INVALID)) {
  1838. ath_drain_all_txq(sc, false);
  1839. ath_stoprecv(sc);
  1840. ath9k_hw_phy_disable(sc->sc_ah);
  1841. } else
  1842. sc->rx.rxlink = NULL;
  1843. #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
  1844. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_RFSILENT)
  1845. cancel_delayed_work_sync(&sc->rf_kill.rfkill_poll);
  1846. #endif
  1847. /* disable HAL and put h/w to sleep */
  1848. ath9k_hw_disable(sc->sc_ah);
  1849. ath9k_hw_configpcipowersave(sc->sc_ah, 1);
  1850. sc->sc_flags |= SC_OP_INVALID;
  1851. mutex_unlock(&sc->mutex);
  1852. DPRINTF(sc, ATH_DBG_CONFIG, "Driver halt\n");
  1853. }
  1854. static int ath9k_add_interface(struct ieee80211_hw *hw,
  1855. struct ieee80211_if_init_conf *conf)
  1856. {
  1857. struct ath_wiphy *aphy = hw->priv;
  1858. struct ath_softc *sc = aphy->sc;
  1859. struct ath_vif *avp = (void *)conf->vif->drv_priv;
  1860. enum nl80211_iftype ic_opmode = NL80211_IFTYPE_UNSPECIFIED;
  1861. int ret = 0;
  1862. mutex_lock(&sc->mutex);
  1863. if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) &&
  1864. sc->nvifs > 0) {
  1865. ret = -ENOBUFS;
  1866. goto out;
  1867. }
  1868. switch (conf->type) {
  1869. case NL80211_IFTYPE_STATION:
  1870. ic_opmode = NL80211_IFTYPE_STATION;
  1871. break;
  1872. case NL80211_IFTYPE_ADHOC:
  1873. case NL80211_IFTYPE_AP:
  1874. case NL80211_IFTYPE_MESH_POINT:
  1875. if (sc->nbcnvifs >= ATH_BCBUF) {
  1876. ret = -ENOBUFS;
  1877. goto out;
  1878. }
  1879. ic_opmode = conf->type;
  1880. break;
  1881. default:
  1882. DPRINTF(sc, ATH_DBG_FATAL,
  1883. "Interface type %d not yet supported\n", conf->type);
  1884. ret = -EOPNOTSUPP;
  1885. goto out;
  1886. }
  1887. DPRINTF(sc, ATH_DBG_CONFIG, "Attach a VIF of type: %d\n", ic_opmode);
  1888. /* Set the VIF opmode */
  1889. avp->av_opmode = ic_opmode;
  1890. avp->av_bslot = -1;
  1891. sc->nvifs++;
  1892. if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK)
  1893. ath9k_set_bssid_mask(hw);
  1894. if (sc->nvifs > 1)
  1895. goto out; /* skip global settings for secondary vif */
  1896. if (ic_opmode == NL80211_IFTYPE_AP) {
  1897. ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
  1898. sc->sc_flags |= SC_OP_TSF_RESET;
  1899. }
  1900. /* Set the device opmode */
  1901. sc->sc_ah->opmode = ic_opmode;
  1902. /*
  1903. * Enable MIB interrupts when there are hardware phy counters.
  1904. * Note we only do this (at the moment) for station mode.
  1905. */
  1906. if ((conf->type == NL80211_IFTYPE_STATION) ||
  1907. (conf->type == NL80211_IFTYPE_ADHOC) ||
  1908. (conf->type == NL80211_IFTYPE_MESH_POINT)) {
  1909. if (ath9k_hw_phycounters(sc->sc_ah))
  1910. sc->imask |= ATH9K_INT_MIB;
  1911. sc->imask |= ATH9K_INT_TSFOOR;
  1912. }
  1913. ath9k_hw_set_interrupts(sc->sc_ah, sc->imask);
  1914. if (conf->type == NL80211_IFTYPE_AP) {
  1915. /* TODO: is this a suitable place to start ANI for AP mode? */
  1916. /* Start ANI */
  1917. mod_timer(&sc->ani.timer,
  1918. jiffies + msecs_to_jiffies(ATH_ANI_POLLINTERVAL));
  1919. }
  1920. out:
  1921. mutex_unlock(&sc->mutex);
  1922. return ret;
  1923. }
  1924. static void ath9k_remove_interface(struct ieee80211_hw *hw,
  1925. struct ieee80211_if_init_conf *conf)
  1926. {
  1927. struct ath_wiphy *aphy = hw->priv;
  1928. struct ath_softc *sc = aphy->sc;
  1929. struct ath_vif *avp = (void *)conf->vif->drv_priv;
  1930. int i;
  1931. DPRINTF(sc, ATH_DBG_CONFIG, "Detach Interface\n");
  1932. mutex_lock(&sc->mutex);
  1933. /* Stop ANI */
  1934. del_timer_sync(&sc->ani.timer);
  1935. /* Reclaim beacon resources */
  1936. if ((sc->sc_ah->opmode == NL80211_IFTYPE_AP) ||
  1937. (sc->sc_ah->opmode == NL80211_IFTYPE_ADHOC) ||
  1938. (sc->sc_ah->opmode == NL80211_IFTYPE_MESH_POINT)) {
  1939. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  1940. ath_beacon_return(sc, avp);
  1941. }
  1942. sc->sc_flags &= ~SC_OP_BEACONS;
  1943. for (i = 0; i < ARRAY_SIZE(sc->beacon.bslot); i++) {
  1944. if (sc->beacon.bslot[i] == conf->vif) {
  1945. printk(KERN_DEBUG "%s: vif had allocated beacon "
  1946. "slot\n", __func__);
  1947. sc->beacon.bslot[i] = NULL;
  1948. sc->beacon.bslot_aphy[i] = NULL;
  1949. }
  1950. }
  1951. sc->nvifs--;
  1952. mutex_unlock(&sc->mutex);
  1953. }
  1954. static int ath9k_config(struct ieee80211_hw *hw, u32 changed)
  1955. {
  1956. struct ath_wiphy *aphy = hw->priv;
  1957. struct ath_softc *sc = aphy->sc;
  1958. struct ieee80211_conf *conf = &hw->conf;
  1959. struct ath_hw *ah = sc->sc_ah;
  1960. mutex_lock(&sc->mutex);
  1961. if (changed & IEEE80211_CONF_CHANGE_PS) {
  1962. if (conf->flags & IEEE80211_CONF_PS) {
  1963. if (!(ah->caps.hw_caps &
  1964. ATH9K_HW_CAP_AUTOSLEEP)) {
  1965. if ((sc->imask & ATH9K_INT_TIM_TIMER) == 0) {
  1966. sc->imask |= ATH9K_INT_TIM_TIMER;
  1967. ath9k_hw_set_interrupts(sc->sc_ah,
  1968. sc->imask);
  1969. }
  1970. ath9k_hw_setrxabort(sc->sc_ah, 1);
  1971. }
  1972. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
  1973. } else {
  1974. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  1975. if (!(ah->caps.hw_caps &
  1976. ATH9K_HW_CAP_AUTOSLEEP)) {
  1977. ath9k_hw_setrxabort(sc->sc_ah, 0);
  1978. sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
  1979. if (sc->imask & ATH9K_INT_TIM_TIMER) {
  1980. sc->imask &= ~ATH9K_INT_TIM_TIMER;
  1981. ath9k_hw_set_interrupts(sc->sc_ah,
  1982. sc->imask);
  1983. }
  1984. }
  1985. }
  1986. }
  1987. if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
  1988. struct ieee80211_channel *curchan = hw->conf.channel;
  1989. int pos = curchan->hw_value;
  1990. aphy->chan_idx = pos;
  1991. aphy->chan_is_ht = conf_is_ht(conf);
  1992. if (aphy->state == ATH_WIPHY_SCAN ||
  1993. aphy->state == ATH_WIPHY_ACTIVE)
  1994. ath9k_wiphy_pause_all_forced(sc, aphy);
  1995. else {
  1996. /*
  1997. * Do not change operational channel based on a paused
  1998. * wiphy changes.
  1999. */
  2000. goto skip_chan_change;
  2001. }
  2002. DPRINTF(sc, ATH_DBG_CONFIG, "Set channel: %d MHz\n",
  2003. curchan->center_freq);
  2004. /* XXX: remove me eventualy */
  2005. ath9k_update_ichannel(sc, hw, &sc->sc_ah->channels[pos]);
  2006. ath_update_chainmask(sc, conf_is_ht(conf));
  2007. if (ath_set_channel(sc, hw, &sc->sc_ah->channels[pos]) < 0) {
  2008. DPRINTF(sc, ATH_DBG_FATAL, "Unable to set channel\n");
  2009. mutex_unlock(&sc->mutex);
  2010. return -EINVAL;
  2011. }
  2012. }
  2013. skip_chan_change:
  2014. if (changed & IEEE80211_CONF_CHANGE_POWER)
  2015. sc->config.txpowlimit = 2 * conf->power_level;
  2016. /*
  2017. * The HW TSF has to be reset when the beacon interval changes.
  2018. * We set the flag here, and ath_beacon_config_ap() would take this
  2019. * into account when it gets called through the subsequent
  2020. * config_interface() call - with IFCC_BEACON in the changed field.
  2021. */
  2022. if (changed & IEEE80211_CONF_CHANGE_BEACON_INTERVAL)
  2023. sc->sc_flags |= SC_OP_TSF_RESET;
  2024. mutex_unlock(&sc->mutex);
  2025. return 0;
  2026. }
  2027. static int ath9k_config_interface(struct ieee80211_hw *hw,
  2028. struct ieee80211_vif *vif,
  2029. struct ieee80211_if_conf *conf)
  2030. {
  2031. struct ath_wiphy *aphy = hw->priv;
  2032. struct ath_softc *sc = aphy->sc;
  2033. struct ath_hw *ah = sc->sc_ah;
  2034. struct ath_vif *avp = (void *)vif->drv_priv;
  2035. u32 rfilt = 0;
  2036. int error, i;
  2037. mutex_lock(&sc->mutex);
  2038. /* TODO: Need to decide which hw opmode to use for multi-interface
  2039. * cases */
  2040. if (vif->type == NL80211_IFTYPE_AP &&
  2041. ah->opmode != NL80211_IFTYPE_AP) {
  2042. ah->opmode = NL80211_IFTYPE_STATION;
  2043. ath9k_hw_setopmode(ah);
  2044. memcpy(sc->curbssid, sc->sc_ah->macaddr, ETH_ALEN);
  2045. sc->curaid = 0;
  2046. ath9k_hw_write_associd(sc);
  2047. /* Request full reset to get hw opmode changed properly */
  2048. sc->sc_flags |= SC_OP_FULL_RESET;
  2049. }
  2050. if ((conf->changed & IEEE80211_IFCC_BSSID) &&
  2051. !is_zero_ether_addr(conf->bssid)) {
  2052. switch (vif->type) {
  2053. case NL80211_IFTYPE_STATION:
  2054. case NL80211_IFTYPE_ADHOC:
  2055. case NL80211_IFTYPE_MESH_POINT:
  2056. /* Set BSSID */
  2057. memcpy(sc->curbssid, conf->bssid, ETH_ALEN);
  2058. memcpy(avp->bssid, conf->bssid, ETH_ALEN);
  2059. sc->curaid = 0;
  2060. ath9k_hw_write_associd(sc);
  2061. /* Set aggregation protection mode parameters */
  2062. sc->config.ath_aggr_prot = 0;
  2063. DPRINTF(sc, ATH_DBG_CONFIG,
  2064. "RX filter 0x%x bssid %pM aid 0x%x\n",
  2065. rfilt, sc->curbssid, sc->curaid);
  2066. /* need to reconfigure the beacon */
  2067. sc->sc_flags &= ~SC_OP_BEACONS ;
  2068. break;
  2069. default:
  2070. break;
  2071. }
  2072. }
  2073. if ((vif->type == NL80211_IFTYPE_ADHOC) ||
  2074. (vif->type == NL80211_IFTYPE_AP) ||
  2075. (vif->type == NL80211_IFTYPE_MESH_POINT)) {
  2076. if ((conf->changed & IEEE80211_IFCC_BEACON) ||
  2077. (conf->changed & IEEE80211_IFCC_BEACON_ENABLED &&
  2078. conf->enable_beacon)) {
  2079. /*
  2080. * Allocate and setup the beacon frame.
  2081. *
  2082. * Stop any previous beacon DMA. This may be
  2083. * necessary, for example, when an ibss merge
  2084. * causes reconfiguration; we may be called
  2085. * with beacon transmission active.
  2086. */
  2087. ath9k_hw_stoptxdma(sc->sc_ah, sc->beacon.beaconq);
  2088. error = ath_beacon_alloc(aphy, vif);
  2089. if (error != 0) {
  2090. mutex_unlock(&sc->mutex);
  2091. return error;
  2092. }
  2093. ath_beacon_config(sc, vif);
  2094. }
  2095. }
  2096. /* Check for WLAN_CAPABILITY_PRIVACY ? */
  2097. if ((avp->av_opmode != NL80211_IFTYPE_STATION)) {
  2098. for (i = 0; i < IEEE80211_WEP_NKID; i++)
  2099. if (ath9k_hw_keyisvalid(sc->sc_ah, (u16)i))
  2100. ath9k_hw_keysetmac(sc->sc_ah,
  2101. (u16)i,
  2102. sc->curbssid);
  2103. }
  2104. /* Only legacy IBSS for now */
  2105. if (vif->type == NL80211_IFTYPE_ADHOC)
  2106. ath_update_chainmask(sc, 0);
  2107. mutex_unlock(&sc->mutex);
  2108. return 0;
  2109. }
  2110. #define SUPPORTED_FILTERS \
  2111. (FIF_PROMISC_IN_BSS | \
  2112. FIF_ALLMULTI | \
  2113. FIF_CONTROL | \
  2114. FIF_OTHER_BSS | \
  2115. FIF_BCN_PRBRESP_PROMISC | \
  2116. FIF_FCSFAIL)
  2117. /* FIXME: sc->sc_full_reset ? */
  2118. static void ath9k_configure_filter(struct ieee80211_hw *hw,
  2119. unsigned int changed_flags,
  2120. unsigned int *total_flags,
  2121. int mc_count,
  2122. struct dev_mc_list *mclist)
  2123. {
  2124. struct ath_wiphy *aphy = hw->priv;
  2125. struct ath_softc *sc = aphy->sc;
  2126. u32 rfilt;
  2127. changed_flags &= SUPPORTED_FILTERS;
  2128. *total_flags &= SUPPORTED_FILTERS;
  2129. sc->rx.rxfilter = *total_flags;
  2130. rfilt = ath_calcrxfilter(sc);
  2131. ath9k_hw_setrxfilter(sc->sc_ah, rfilt);
  2132. DPRINTF(sc, ATH_DBG_CONFIG, "Set HW RX filter: 0x%x\n", sc->rx.rxfilter);
  2133. }
  2134. static void ath9k_sta_notify(struct ieee80211_hw *hw,
  2135. struct ieee80211_vif *vif,
  2136. enum sta_notify_cmd cmd,
  2137. struct ieee80211_sta *sta)
  2138. {
  2139. struct ath_wiphy *aphy = hw->priv;
  2140. struct ath_softc *sc = aphy->sc;
  2141. switch (cmd) {
  2142. case STA_NOTIFY_ADD:
  2143. ath_node_attach(sc, sta);
  2144. break;
  2145. case STA_NOTIFY_REMOVE:
  2146. ath_node_detach(sc, sta);
  2147. break;
  2148. default:
  2149. break;
  2150. }
  2151. }
  2152. static int ath9k_conf_tx(struct ieee80211_hw *hw, u16 queue,
  2153. const struct ieee80211_tx_queue_params *params)
  2154. {
  2155. struct ath_wiphy *aphy = hw->priv;
  2156. struct ath_softc *sc = aphy->sc;
  2157. struct ath9k_tx_queue_info qi;
  2158. int ret = 0, qnum;
  2159. if (queue >= WME_NUM_AC)
  2160. return 0;
  2161. mutex_lock(&sc->mutex);
  2162. memset(&qi, 0, sizeof(struct ath9k_tx_queue_info));
  2163. qi.tqi_aifs = params->aifs;
  2164. qi.tqi_cwmin = params->cw_min;
  2165. qi.tqi_cwmax = params->cw_max;
  2166. qi.tqi_burstTime = params->txop;
  2167. qnum = ath_get_hal_qnum(queue, sc);
  2168. DPRINTF(sc, ATH_DBG_CONFIG,
  2169. "Configure tx [queue/halq] [%d/%d], "
  2170. "aifs: %d, cw_min: %d, cw_max: %d, txop: %d\n",
  2171. queue, qnum, params->aifs, params->cw_min,
  2172. params->cw_max, params->txop);
  2173. ret = ath_txq_update(sc, qnum, &qi);
  2174. if (ret)
  2175. DPRINTF(sc, ATH_DBG_FATAL, "TXQ Update failed\n");
  2176. mutex_unlock(&sc->mutex);
  2177. return ret;
  2178. }
  2179. static int ath9k_set_key(struct ieee80211_hw *hw,
  2180. enum set_key_cmd cmd,
  2181. struct ieee80211_vif *vif,
  2182. struct ieee80211_sta *sta,
  2183. struct ieee80211_key_conf *key)
  2184. {
  2185. struct ath_wiphy *aphy = hw->priv;
  2186. struct ath_softc *sc = aphy->sc;
  2187. int ret = 0;
  2188. if (modparam_nohwcrypt)
  2189. return -ENOSPC;
  2190. mutex_lock(&sc->mutex);
  2191. ath9k_ps_wakeup(sc);
  2192. DPRINTF(sc, ATH_DBG_CONFIG, "Set HW Key\n");
  2193. switch (cmd) {
  2194. case SET_KEY:
  2195. ret = ath_key_config(sc, vif, sta, key);
  2196. if (ret >= 0) {
  2197. key->hw_key_idx = ret;
  2198. /* push IV and Michael MIC generation to stack */
  2199. key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
  2200. if (key->alg == ALG_TKIP)
  2201. key->flags |= IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2202. if (sc->sc_ah->sw_mgmt_crypto && key->alg == ALG_CCMP)
  2203. key->flags |= IEEE80211_KEY_FLAG_SW_MGMT;
  2204. ret = 0;
  2205. }
  2206. break;
  2207. case DISABLE_KEY:
  2208. ath_key_delete(sc, key);
  2209. break;
  2210. default:
  2211. ret = -EINVAL;
  2212. }
  2213. ath9k_ps_restore(sc);
  2214. mutex_unlock(&sc->mutex);
  2215. return ret;
  2216. }
  2217. static void ath9k_bss_info_changed(struct ieee80211_hw *hw,
  2218. struct ieee80211_vif *vif,
  2219. struct ieee80211_bss_conf *bss_conf,
  2220. u32 changed)
  2221. {
  2222. struct ath_wiphy *aphy = hw->priv;
  2223. struct ath_softc *sc = aphy->sc;
  2224. mutex_lock(&sc->mutex);
  2225. if (changed & BSS_CHANGED_ERP_PREAMBLE) {
  2226. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed PREAMBLE %d\n",
  2227. bss_conf->use_short_preamble);
  2228. if (bss_conf->use_short_preamble)
  2229. sc->sc_flags |= SC_OP_PREAMBLE_SHORT;
  2230. else
  2231. sc->sc_flags &= ~SC_OP_PREAMBLE_SHORT;
  2232. }
  2233. if (changed & BSS_CHANGED_ERP_CTS_PROT) {
  2234. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed CTS PROT %d\n",
  2235. bss_conf->use_cts_prot);
  2236. if (bss_conf->use_cts_prot &&
  2237. hw->conf.channel->band != IEEE80211_BAND_5GHZ)
  2238. sc->sc_flags |= SC_OP_PROTECT_ENABLE;
  2239. else
  2240. sc->sc_flags &= ~SC_OP_PROTECT_ENABLE;
  2241. }
  2242. if (changed & BSS_CHANGED_ASSOC) {
  2243. DPRINTF(sc, ATH_DBG_CONFIG, "BSS Changed ASSOC %d\n",
  2244. bss_conf->assoc);
  2245. ath9k_bss_assoc_info(sc, vif, bss_conf);
  2246. }
  2247. mutex_unlock(&sc->mutex);
  2248. }
  2249. static u64 ath9k_get_tsf(struct ieee80211_hw *hw)
  2250. {
  2251. u64 tsf;
  2252. struct ath_wiphy *aphy = hw->priv;
  2253. struct ath_softc *sc = aphy->sc;
  2254. mutex_lock(&sc->mutex);
  2255. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  2256. mutex_unlock(&sc->mutex);
  2257. return tsf;
  2258. }
  2259. static void ath9k_set_tsf(struct ieee80211_hw *hw, u64 tsf)
  2260. {
  2261. struct ath_wiphy *aphy = hw->priv;
  2262. struct ath_softc *sc = aphy->sc;
  2263. mutex_lock(&sc->mutex);
  2264. ath9k_hw_settsf64(sc->sc_ah, tsf);
  2265. mutex_unlock(&sc->mutex);
  2266. }
  2267. static void ath9k_reset_tsf(struct ieee80211_hw *hw)
  2268. {
  2269. struct ath_wiphy *aphy = hw->priv;
  2270. struct ath_softc *sc = aphy->sc;
  2271. mutex_lock(&sc->mutex);
  2272. ath9k_hw_reset_tsf(sc->sc_ah);
  2273. mutex_unlock(&sc->mutex);
  2274. }
  2275. static int ath9k_ampdu_action(struct ieee80211_hw *hw,
  2276. enum ieee80211_ampdu_mlme_action action,
  2277. struct ieee80211_sta *sta,
  2278. u16 tid, u16 *ssn)
  2279. {
  2280. struct ath_wiphy *aphy = hw->priv;
  2281. struct ath_softc *sc = aphy->sc;
  2282. int ret = 0;
  2283. switch (action) {
  2284. case IEEE80211_AMPDU_RX_START:
  2285. if (!(sc->sc_flags & SC_OP_RXAGGR))
  2286. ret = -ENOTSUPP;
  2287. break;
  2288. case IEEE80211_AMPDU_RX_STOP:
  2289. break;
  2290. case IEEE80211_AMPDU_TX_START:
  2291. ret = ath_tx_aggr_start(sc, sta, tid, ssn);
  2292. if (ret < 0)
  2293. DPRINTF(sc, ATH_DBG_FATAL,
  2294. "Unable to start TX aggregation\n");
  2295. else
  2296. ieee80211_start_tx_ba_cb_irqsafe(hw, sta->addr, tid);
  2297. break;
  2298. case IEEE80211_AMPDU_TX_STOP:
  2299. ret = ath_tx_aggr_stop(sc, sta, tid);
  2300. if (ret < 0)
  2301. DPRINTF(sc, ATH_DBG_FATAL,
  2302. "Unable to stop TX aggregation\n");
  2303. ieee80211_stop_tx_ba_cb_irqsafe(hw, sta->addr, tid);
  2304. break;
  2305. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2306. ath_tx_aggr_resume(sc, sta, tid);
  2307. break;
  2308. default:
  2309. DPRINTF(sc, ATH_DBG_FATAL, "Unknown AMPDU action\n");
  2310. }
  2311. return ret;
  2312. }
  2313. static void ath9k_sw_scan_start(struct ieee80211_hw *hw)
  2314. {
  2315. struct ath_wiphy *aphy = hw->priv;
  2316. struct ath_softc *sc = aphy->sc;
  2317. if (ath9k_wiphy_scanning(sc)) {
  2318. printk(KERN_DEBUG "ath9k: Two wiphys trying to scan at the "
  2319. "same time\n");
  2320. /*
  2321. * Do not allow the concurrent scanning state for now. This
  2322. * could be improved with scanning control moved into ath9k.
  2323. */
  2324. return;
  2325. }
  2326. aphy->state = ATH_WIPHY_SCAN;
  2327. ath9k_wiphy_pause_all_forced(sc, aphy);
  2328. mutex_lock(&sc->mutex);
  2329. sc->sc_flags |= SC_OP_SCANNING;
  2330. mutex_unlock(&sc->mutex);
  2331. }
  2332. static void ath9k_sw_scan_complete(struct ieee80211_hw *hw)
  2333. {
  2334. struct ath_wiphy *aphy = hw->priv;
  2335. struct ath_softc *sc = aphy->sc;
  2336. mutex_lock(&sc->mutex);
  2337. aphy->state = ATH_WIPHY_ACTIVE;
  2338. sc->sc_flags &= ~SC_OP_SCANNING;
  2339. mutex_unlock(&sc->mutex);
  2340. }
  2341. struct ieee80211_ops ath9k_ops = {
  2342. .tx = ath9k_tx,
  2343. .start = ath9k_start,
  2344. .stop = ath9k_stop,
  2345. .add_interface = ath9k_add_interface,
  2346. .remove_interface = ath9k_remove_interface,
  2347. .config = ath9k_config,
  2348. .config_interface = ath9k_config_interface,
  2349. .configure_filter = ath9k_configure_filter,
  2350. .sta_notify = ath9k_sta_notify,
  2351. .conf_tx = ath9k_conf_tx,
  2352. .bss_info_changed = ath9k_bss_info_changed,
  2353. .set_key = ath9k_set_key,
  2354. .get_tsf = ath9k_get_tsf,
  2355. .set_tsf = ath9k_set_tsf,
  2356. .reset_tsf = ath9k_reset_tsf,
  2357. .ampdu_action = ath9k_ampdu_action,
  2358. .sw_scan_start = ath9k_sw_scan_start,
  2359. .sw_scan_complete = ath9k_sw_scan_complete,
  2360. };
  2361. static struct {
  2362. u32 version;
  2363. const char * name;
  2364. } ath_mac_bb_names[] = {
  2365. { AR_SREV_VERSION_5416_PCI, "5416" },
  2366. { AR_SREV_VERSION_5416_PCIE, "5418" },
  2367. { AR_SREV_VERSION_9100, "9100" },
  2368. { AR_SREV_VERSION_9160, "9160" },
  2369. { AR_SREV_VERSION_9280, "9280" },
  2370. { AR_SREV_VERSION_9285, "9285" }
  2371. };
  2372. static struct {
  2373. u16 version;
  2374. const char * name;
  2375. } ath_rf_names[] = {
  2376. { 0, "5133" },
  2377. { AR_RAD5133_SREV_MAJOR, "5133" },
  2378. { AR_RAD5122_SREV_MAJOR, "5122" },
  2379. { AR_RAD2133_SREV_MAJOR, "2133" },
  2380. { AR_RAD2122_SREV_MAJOR, "2122" }
  2381. };
  2382. /*
  2383. * Return the MAC/BB name. "????" is returned if the MAC/BB is unknown.
  2384. */
  2385. const char *
  2386. ath_mac_bb_name(u32 mac_bb_version)
  2387. {
  2388. int i;
  2389. for (i=0; i<ARRAY_SIZE(ath_mac_bb_names); i++) {
  2390. if (ath_mac_bb_names[i].version == mac_bb_version) {
  2391. return ath_mac_bb_names[i].name;
  2392. }
  2393. }
  2394. return "????";
  2395. }
  2396. /*
  2397. * Return the RF name. "????" is returned if the RF is unknown.
  2398. */
  2399. const char *
  2400. ath_rf_name(u16 rf_version)
  2401. {
  2402. int i;
  2403. for (i=0; i<ARRAY_SIZE(ath_rf_names); i++) {
  2404. if (ath_rf_names[i].version == rf_version) {
  2405. return ath_rf_names[i].name;
  2406. }
  2407. }
  2408. return "????";
  2409. }
  2410. static int __init ath9k_init(void)
  2411. {
  2412. int error;
  2413. /* Register rate control algorithm */
  2414. error = ath_rate_control_register();
  2415. if (error != 0) {
  2416. printk(KERN_ERR
  2417. "ath9k: Unable to register rate control "
  2418. "algorithm: %d\n",
  2419. error);
  2420. goto err_out;
  2421. }
  2422. error = ath9k_debug_create_root();
  2423. if (error) {
  2424. printk(KERN_ERR
  2425. "ath9k: Unable to create debugfs root: %d\n",
  2426. error);
  2427. goto err_rate_unregister;
  2428. }
  2429. error = ath_pci_init();
  2430. if (error < 0) {
  2431. printk(KERN_ERR
  2432. "ath9k: No PCI devices found, driver not installed.\n");
  2433. error = -ENODEV;
  2434. goto err_remove_root;
  2435. }
  2436. error = ath_ahb_init();
  2437. if (error < 0) {
  2438. error = -ENODEV;
  2439. goto err_pci_exit;
  2440. }
  2441. return 0;
  2442. err_pci_exit:
  2443. ath_pci_exit();
  2444. err_remove_root:
  2445. ath9k_debug_remove_root();
  2446. err_rate_unregister:
  2447. ath_rate_control_unregister();
  2448. err_out:
  2449. return error;
  2450. }
  2451. module_init(ath9k_init);
  2452. static void __exit ath9k_exit(void)
  2453. {
  2454. ath_ahb_exit();
  2455. ath_pci_exit();
  2456. ath9k_debug_remove_root();
  2457. ath_rate_control_unregister();
  2458. printk(KERN_INFO "%s: Driver unloaded\n", dev_info);
  2459. }
  2460. module_exit(ath9k_exit);