core.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841
  1. /*
  2. * Copyright (c) 2008, 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. /* Implementation of the main "ATH" layer. */
  17. #include "core.h"
  18. #include "regd.h"
  19. static int ath_outdoor; /* enable outdoor use */
  20. static u32 ath_chainmask_sel_up_rssi_thres =
  21. ATH_CHAINMASK_SEL_UP_RSSI_THRES;
  22. static u32 ath_chainmask_sel_down_rssi_thres =
  23. ATH_CHAINMASK_SEL_DOWN_RSSI_THRES;
  24. static u32 ath_chainmask_sel_period =
  25. ATH_CHAINMASK_SEL_TIMEOUT;
  26. /* return bus cachesize in 4B word units */
  27. static void bus_read_cachesize(struct ath_softc *sc, int *csz)
  28. {
  29. u8 u8tmp;
  30. pci_read_config_byte(sc->pdev, PCI_CACHE_LINE_SIZE, (u8 *)&u8tmp);
  31. *csz = (int)u8tmp;
  32. /*
  33. * This check was put in to avoid "unplesant" consequences if
  34. * the bootrom has not fully initialized all PCI devices.
  35. * Sometimes the cache line size register is not set
  36. */
  37. if (*csz == 0)
  38. *csz = DEFAULT_CACHELINE >> 2; /* Use the default size */
  39. }
  40. /*
  41. * Set current operating mode
  42. *
  43. * This function initializes and fills the rate table in the ATH object based
  44. * on the operating mode. The blink rates are also set up here, although
  45. * they have been superceeded by the ath_led module.
  46. */
  47. static void ath_setcurmode(struct ath_softc *sc, enum wireless_mode mode)
  48. {
  49. const struct ath9k_rate_table *rt;
  50. int i;
  51. memset(sc->sc_rixmap, 0xff, sizeof(sc->sc_rixmap));
  52. rt = ath9k_hw_getratetable(sc->sc_ah, mode);
  53. BUG_ON(!rt);
  54. for (i = 0; i < rt->rateCount; i++)
  55. sc->sc_rixmap[rt->info[i].rateCode] = (u8) i;
  56. memzero(sc->sc_hwmap, sizeof(sc->sc_hwmap));
  57. for (i = 0; i < 256; i++) {
  58. u8 ix = rt->rateCodeToIndex[i];
  59. if (ix == 0xff)
  60. continue;
  61. sc->sc_hwmap[i].ieeerate =
  62. rt->info[ix].dot11Rate & IEEE80211_RATE_VAL;
  63. sc->sc_hwmap[i].rateKbps = rt->info[ix].rateKbps;
  64. if (rt->info[ix].shortPreamble ||
  65. rt->info[ix].phy == PHY_OFDM) {
  66. /* XXX: Handle this */
  67. }
  68. /* NB: this uses the last entry if the rate isn't found */
  69. /* XXX beware of overlow */
  70. }
  71. sc->sc_currates = rt;
  72. sc->sc_curmode = mode;
  73. /*
  74. * All protection frames are transmited at 2Mb/s for
  75. * 11g, otherwise at 1Mb/s.
  76. * XXX select protection rate index from rate table.
  77. */
  78. sc->sc_protrix = (mode == ATH9K_MODE_11G ? 1 : 0);
  79. }
  80. /*
  81. * Set up rate table (legacy rates)
  82. */
  83. static void ath_setup_rates(struct ath_softc *sc, enum ieee80211_band band)
  84. {
  85. struct ath_hal *ah = sc->sc_ah;
  86. const struct ath9k_rate_table *rt = NULL;
  87. struct ieee80211_supported_band *sband;
  88. struct ieee80211_rate *rate;
  89. int i, maxrates;
  90. switch (band) {
  91. case IEEE80211_BAND_2GHZ:
  92. rt = ath9k_hw_getratetable(ah, ATH9K_MODE_11G);
  93. break;
  94. case IEEE80211_BAND_5GHZ:
  95. rt = ath9k_hw_getratetable(ah, ATH9K_MODE_11A);
  96. break;
  97. default:
  98. break;
  99. }
  100. if (rt == NULL)
  101. return;
  102. sband = &sc->sbands[band];
  103. rate = sc->rates[band];
  104. if (rt->rateCount > ATH_RATE_MAX)
  105. maxrates = ATH_RATE_MAX;
  106. else
  107. maxrates = rt->rateCount;
  108. for (i = 0; i < maxrates; i++) {
  109. rate[i].bitrate = rt->info[i].rateKbps / 100;
  110. rate[i].hw_value = rt->info[i].rateCode;
  111. sband->n_bitrates++;
  112. DPRINTF(sc, ATH_DBG_CONFIG,
  113. "%s: Rate: %2dMbps, ratecode: %2d\n",
  114. __func__,
  115. rate[i].bitrate / 10,
  116. rate[i].hw_value);
  117. }
  118. }
  119. /*
  120. * Set up channel list
  121. */
  122. static int ath_setup_channels(struct ath_softc *sc)
  123. {
  124. struct ath_hal *ah = sc->sc_ah;
  125. int nchan, i, a = 0, b = 0;
  126. u8 regclassids[ATH_REGCLASSIDS_MAX];
  127. u32 nregclass = 0;
  128. struct ieee80211_supported_band *band_2ghz;
  129. struct ieee80211_supported_band *band_5ghz;
  130. struct ieee80211_channel *chan_2ghz;
  131. struct ieee80211_channel *chan_5ghz;
  132. struct ath9k_channel *c;
  133. /* Fill in ah->ah_channels */
  134. if (!ath9k_regd_init_channels(ah,
  135. ATH_CHAN_MAX,
  136. (u32 *)&nchan,
  137. regclassids,
  138. ATH_REGCLASSIDS_MAX,
  139. &nregclass,
  140. CTRY_DEFAULT,
  141. false,
  142. 1)) {
  143. u32 rd = ah->ah_currentRD;
  144. DPRINTF(sc, ATH_DBG_FATAL,
  145. "%s: unable to collect channel list; "
  146. "regdomain likely %u country code %u\n",
  147. __func__, rd, CTRY_DEFAULT);
  148. return -EINVAL;
  149. }
  150. band_2ghz = &sc->sbands[IEEE80211_BAND_2GHZ];
  151. band_5ghz = &sc->sbands[IEEE80211_BAND_5GHZ];
  152. chan_2ghz = sc->channels[IEEE80211_BAND_2GHZ];
  153. chan_5ghz = sc->channels[IEEE80211_BAND_5GHZ];
  154. for (i = 0; i < nchan; i++) {
  155. c = &ah->ah_channels[i];
  156. if (IS_CHAN_2GHZ(c)) {
  157. chan_2ghz[a].band = IEEE80211_BAND_2GHZ;
  158. chan_2ghz[a].center_freq = c->channel;
  159. chan_2ghz[a].max_power = c->maxTxPower;
  160. if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
  161. chan_2ghz[a].flags |=
  162. IEEE80211_CHAN_NO_IBSS;
  163. if (c->channelFlags & CHANNEL_PASSIVE)
  164. chan_2ghz[a].flags |=
  165. IEEE80211_CHAN_PASSIVE_SCAN;
  166. band_2ghz->n_channels = ++a;
  167. DPRINTF(sc, ATH_DBG_CONFIG,
  168. "%s: 2MHz channel: %d, "
  169. "channelFlags: 0x%x\n",
  170. __func__,
  171. c->channel,
  172. c->channelFlags);
  173. } else if (IS_CHAN_5GHZ(c)) {
  174. chan_5ghz[b].band = IEEE80211_BAND_5GHZ;
  175. chan_5ghz[b].center_freq = c->channel;
  176. chan_5ghz[b].max_power = c->maxTxPower;
  177. if (c->privFlags & CHANNEL_DISALLOW_ADHOC)
  178. chan_5ghz[b].flags |=
  179. IEEE80211_CHAN_NO_IBSS;
  180. if (c->channelFlags & CHANNEL_PASSIVE)
  181. chan_5ghz[b].flags |=
  182. IEEE80211_CHAN_PASSIVE_SCAN;
  183. band_5ghz->n_channels = ++b;
  184. DPRINTF(sc, ATH_DBG_CONFIG,
  185. "%s: 5MHz channel: %d, "
  186. "channelFlags: 0x%x\n",
  187. __func__,
  188. c->channel,
  189. c->channelFlags);
  190. }
  191. }
  192. return 0;
  193. }
  194. /*
  195. * Determine mode from channel flags
  196. *
  197. * This routine will provide the enumerated WIRELESSS_MODE value based
  198. * on the settings of the channel flags. If ho valid set of flags
  199. * exist, the lowest mode (11b) is selected.
  200. */
  201. static enum wireless_mode ath_chan2mode(struct ath9k_channel *chan)
  202. {
  203. if (chan->chanmode == CHANNEL_A)
  204. return ATH9K_MODE_11A;
  205. else if (chan->chanmode == CHANNEL_G)
  206. return ATH9K_MODE_11G;
  207. else if (chan->chanmode == CHANNEL_B)
  208. return ATH9K_MODE_11B;
  209. else if (chan->chanmode == CHANNEL_A_HT20)
  210. return ATH9K_MODE_11NA_HT20;
  211. else if (chan->chanmode == CHANNEL_G_HT20)
  212. return ATH9K_MODE_11NG_HT20;
  213. else if (chan->chanmode == CHANNEL_A_HT40PLUS)
  214. return ATH9K_MODE_11NA_HT40PLUS;
  215. else if (chan->chanmode == CHANNEL_A_HT40MINUS)
  216. return ATH9K_MODE_11NA_HT40MINUS;
  217. else if (chan->chanmode == CHANNEL_G_HT40PLUS)
  218. return ATH9K_MODE_11NG_HT40PLUS;
  219. else if (chan->chanmode == CHANNEL_G_HT40MINUS)
  220. return ATH9K_MODE_11NG_HT40MINUS;
  221. /* NB: should not get here */
  222. return ATH9K_MODE_11B;
  223. }
  224. /*
  225. * Stop the device, grabbing the top-level lock to protect
  226. * against concurrent entry through ath_init (which can happen
  227. * if another thread does a system call and the thread doing the
  228. * stop is preempted).
  229. */
  230. static int ath_stop(struct ath_softc *sc)
  231. {
  232. struct ath_hal *ah = sc->sc_ah;
  233. DPRINTF(sc, ATH_DBG_CONFIG, "%s: invalid %ld\n",
  234. __func__, sc->sc_flags & SC_OP_INVALID);
  235. /*
  236. * Shutdown the hardware and driver:
  237. * stop output from above
  238. * reset 802.11 state machine
  239. * (sends station deassoc/deauth frames)
  240. * turn off timers
  241. * disable interrupts
  242. * clear transmit machinery
  243. * clear receive machinery
  244. * turn off the radio
  245. * reclaim beacon resources
  246. *
  247. * Note that some of this work is not possible if the
  248. * hardware is gone (invalid).
  249. */
  250. if (!(sc->sc_flags & SC_OP_INVALID))
  251. ath9k_hw_set_interrupts(ah, 0);
  252. ath_draintxq(sc, false);
  253. if (!(sc->sc_flags & SC_OP_INVALID)) {
  254. ath_stoprecv(sc);
  255. ath9k_hw_phy_disable(ah);
  256. } else
  257. sc->sc_rxlink = NULL;
  258. return 0;
  259. }
  260. /*
  261. * Set the current channel
  262. *
  263. * Set/change channels. If the channel is really being changed, it's done
  264. * by reseting the chip. To accomplish this we must first cleanup any pending
  265. * DMA, then restart stuff after a la ath_init.
  266. */
  267. int ath_set_channel(struct ath_softc *sc, struct ath9k_channel *hchan)
  268. {
  269. struct ath_hal *ah = sc->sc_ah;
  270. bool fastcc = true, stopped;
  271. enum ath9k_ht_macmode ht_macmode;
  272. if (sc->sc_flags & SC_OP_INVALID) /* the device is invalid or removed */
  273. return -EIO;
  274. DPRINTF(sc, ATH_DBG_CONFIG,
  275. "%s: %u (%u MHz) -> %u (%u MHz), cflags:%x\n",
  276. __func__,
  277. ath9k_hw_mhz2ieee(ah, sc->sc_ah->ah_curchan->channel,
  278. sc->sc_ah->ah_curchan->channelFlags),
  279. sc->sc_ah->ah_curchan->channel,
  280. ath9k_hw_mhz2ieee(ah, hchan->channel, hchan->channelFlags),
  281. hchan->channel, hchan->channelFlags);
  282. ht_macmode = ath_cwm_macmode(sc);
  283. if (hchan->channel != sc->sc_ah->ah_curchan->channel ||
  284. hchan->channelFlags != sc->sc_ah->ah_curchan->channelFlags ||
  285. (sc->sc_flags & SC_OP_CHAINMASK_UPDATE) ||
  286. (sc->sc_flags & SC_OP_FULL_RESET)) {
  287. int status;
  288. /*
  289. * This is only performed if the channel settings have
  290. * actually changed.
  291. *
  292. * To switch channels clear any pending DMA operations;
  293. * wait long enough for the RX fifo to drain, reset the
  294. * hardware at the new frequency, and then re-enable
  295. * the relevant bits of the h/w.
  296. */
  297. ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
  298. ath_draintxq(sc, false); /* clear pending tx frames */
  299. stopped = ath_stoprecv(sc); /* turn off frame recv */
  300. /* XXX: do not flush receive queue here. We don't want
  301. * to flush data frames already in queue because of
  302. * changing channel. */
  303. if (!stopped || (sc->sc_flags & SC_OP_FULL_RESET))
  304. fastcc = false;
  305. spin_lock_bh(&sc->sc_resetlock);
  306. if (!ath9k_hw_reset(ah, hchan,
  307. ht_macmode, sc->sc_tx_chainmask,
  308. sc->sc_rx_chainmask,
  309. sc->sc_ht_extprotspacing,
  310. fastcc, &status)) {
  311. DPRINTF(sc, ATH_DBG_FATAL,
  312. "%s: unable to reset channel %u (%uMhz) "
  313. "flags 0x%x hal status %u\n", __func__,
  314. ath9k_hw_mhz2ieee(ah, hchan->channel,
  315. hchan->channelFlags),
  316. hchan->channel, hchan->channelFlags, status);
  317. spin_unlock_bh(&sc->sc_resetlock);
  318. return -EIO;
  319. }
  320. spin_unlock_bh(&sc->sc_resetlock);
  321. sc->sc_flags &= ~SC_OP_CHAINMASK_UPDATE;
  322. sc->sc_flags &= ~SC_OP_FULL_RESET;
  323. /* Re-enable rx framework */
  324. if (ath_startrecv(sc) != 0) {
  325. DPRINTF(sc, ATH_DBG_FATAL,
  326. "%s: unable to restart recv logic\n", __func__);
  327. return -EIO;
  328. }
  329. /*
  330. * Change channels and update the h/w rate map
  331. * if we're switching; e.g. 11a to 11b/g.
  332. */
  333. ath_setcurmode(sc, ath_chan2mode(hchan));
  334. ath_update_txpow(sc); /* update tx power state */
  335. /*
  336. * Re-enable interrupts.
  337. */
  338. ath9k_hw_set_interrupts(ah, sc->sc_imask);
  339. }
  340. return 0;
  341. }
  342. /**********************/
  343. /* Chainmask Handling */
  344. /**********************/
  345. static void ath_chainmask_sel_timertimeout(unsigned long data)
  346. {
  347. struct ath_chainmask_sel *cm = (struct ath_chainmask_sel *)data;
  348. cm->switch_allowed = 1;
  349. }
  350. /* Start chainmask select timer */
  351. static void ath_chainmask_sel_timerstart(struct ath_chainmask_sel *cm)
  352. {
  353. cm->switch_allowed = 0;
  354. mod_timer(&cm->timer, ath_chainmask_sel_period);
  355. }
  356. /* Stop chainmask select timer */
  357. static void ath_chainmask_sel_timerstop(struct ath_chainmask_sel *cm)
  358. {
  359. cm->switch_allowed = 0;
  360. del_timer_sync(&cm->timer);
  361. }
  362. static void ath_chainmask_sel_init(struct ath_softc *sc, struct ath_node *an)
  363. {
  364. struct ath_chainmask_sel *cm = &an->an_chainmask_sel;
  365. memzero(cm, sizeof(struct ath_chainmask_sel));
  366. cm->cur_tx_mask = sc->sc_tx_chainmask;
  367. cm->cur_rx_mask = sc->sc_rx_chainmask;
  368. cm->tx_avgrssi = ATH_RSSI_DUMMY_MARKER;
  369. setup_timer(&cm->timer,
  370. ath_chainmask_sel_timertimeout, (unsigned long) cm);
  371. }
  372. int ath_chainmask_sel_logic(struct ath_softc *sc, struct ath_node *an)
  373. {
  374. struct ath_chainmask_sel *cm = &an->an_chainmask_sel;
  375. /*
  376. * Disable auto-swtiching in one of the following if conditions.
  377. * sc_chainmask_auto_sel is used for internal global auto-switching
  378. * enabled/disabled setting
  379. */
  380. if (sc->sc_ah->ah_caps.tx_chainmask != ATH_CHAINMASK_SEL_3X3) {
  381. cm->cur_tx_mask = sc->sc_tx_chainmask;
  382. return cm->cur_tx_mask;
  383. }
  384. if (cm->tx_avgrssi == ATH_RSSI_DUMMY_MARKER)
  385. return cm->cur_tx_mask;
  386. if (cm->switch_allowed) {
  387. /* Switch down from tx 3 to tx 2. */
  388. if (cm->cur_tx_mask == ATH_CHAINMASK_SEL_3X3 &&
  389. ATH_RSSI_OUT(cm->tx_avgrssi) >=
  390. ath_chainmask_sel_down_rssi_thres) {
  391. cm->cur_tx_mask = sc->sc_tx_chainmask;
  392. /* Don't let another switch happen until
  393. * this timer expires */
  394. ath_chainmask_sel_timerstart(cm);
  395. }
  396. /* Switch up from tx 2 to 3. */
  397. else if (cm->cur_tx_mask == sc->sc_tx_chainmask &&
  398. ATH_RSSI_OUT(cm->tx_avgrssi) <=
  399. ath_chainmask_sel_up_rssi_thres) {
  400. cm->cur_tx_mask = ATH_CHAINMASK_SEL_3X3;
  401. /* Don't let another switch happen
  402. * until this timer expires */
  403. ath_chainmask_sel_timerstart(cm);
  404. }
  405. }
  406. return cm->cur_tx_mask;
  407. }
  408. /*
  409. * Update tx/rx chainmask. For legacy association,
  410. * hard code chainmask to 1x1, for 11n association, use
  411. * the chainmask configuration.
  412. */
  413. void ath_update_chainmask(struct ath_softc *sc, int is_ht)
  414. {
  415. sc->sc_flags |= SC_OP_CHAINMASK_UPDATE;
  416. if (is_ht) {
  417. sc->sc_tx_chainmask = sc->sc_ah->ah_caps.tx_chainmask;
  418. sc->sc_rx_chainmask = sc->sc_ah->ah_caps.rx_chainmask;
  419. } else {
  420. sc->sc_tx_chainmask = 1;
  421. sc->sc_rx_chainmask = 1;
  422. }
  423. DPRINTF(sc, ATH_DBG_CONFIG, "%s: tx chmask: %d, rx chmask: %d\n",
  424. __func__, sc->sc_tx_chainmask, sc->sc_rx_chainmask);
  425. }
  426. /******************/
  427. /* VAP management */
  428. /******************/
  429. /*
  430. * VAP in Listen mode
  431. *
  432. * This routine brings the VAP out of the down state into a "listen" state
  433. * where it waits for association requests. This is used in AP and AdHoc
  434. * modes.
  435. */
  436. int ath_vap_listen(struct ath_softc *sc, int if_id)
  437. {
  438. struct ath_hal *ah = sc->sc_ah;
  439. struct ath_vap *avp;
  440. u32 rfilt = 0;
  441. DECLARE_MAC_BUF(mac);
  442. avp = sc->sc_vaps[if_id];
  443. if (avp == NULL) {
  444. DPRINTF(sc, ATH_DBG_FATAL, "%s: invalid interface id %u\n",
  445. __func__, if_id);
  446. return -EINVAL;
  447. }
  448. #ifdef CONFIG_SLOW_ANT_DIV
  449. ath_slow_ant_div_stop(&sc->sc_antdiv);
  450. #endif
  451. /* update ratectrl about the new state */
  452. ath_rate_newstate(sc, avp);
  453. rfilt = ath_calcrxfilter(sc);
  454. ath9k_hw_setrxfilter(ah, rfilt);
  455. if (sc->sc_ah->ah_opmode == ATH9K_M_STA ||
  456. sc->sc_ah->ah_opmode == ATH9K_M_IBSS) {
  457. memcpy(sc->sc_curbssid, ath_bcast_mac, ETH_ALEN);
  458. ath9k_hw_write_associd(ah, sc->sc_curbssid, sc->sc_curaid);
  459. } else
  460. sc->sc_curaid = 0;
  461. DPRINTF(sc, ATH_DBG_CONFIG,
  462. "%s: RX filter 0x%x bssid %s aid 0x%x\n",
  463. __func__, rfilt, print_mac(mac,
  464. sc->sc_curbssid), sc->sc_curaid);
  465. /*
  466. * XXXX
  467. * Disable BMISS interrupt when we're not associated
  468. */
  469. if (sc->sc_ah->ah_opmode == ATH9K_M_HOSTAP) {
  470. ath9k_hw_set_interrupts(ah, sc->sc_imask & ~ATH9K_INT_BMISS);
  471. sc->sc_imask &= ~ATH9K_INT_BMISS;
  472. } else {
  473. ath9k_hw_set_interrupts(
  474. ah,
  475. sc->sc_imask & ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS));
  476. sc->sc_imask &= ~(ATH9K_INT_SWBA | ATH9K_INT_BMISS);
  477. }
  478. /* need to reconfigure the beacons when it moves to RUN */
  479. sc->sc_flags &= ~SC_OP_BEACONS;
  480. return 0;
  481. }
  482. int ath_vap_attach(struct ath_softc *sc,
  483. int if_id,
  484. struct ieee80211_vif *if_data,
  485. enum ath9k_opmode opmode)
  486. {
  487. struct ath_vap *avp;
  488. if (if_id >= ATH_BCBUF || sc->sc_vaps[if_id] != NULL) {
  489. DPRINTF(sc, ATH_DBG_FATAL,
  490. "%s: Invalid interface id = %u\n", __func__, if_id);
  491. return -EINVAL;
  492. }
  493. switch (opmode) {
  494. case ATH9K_M_STA:
  495. case ATH9K_M_IBSS:
  496. case ATH9K_M_MONITOR:
  497. break;
  498. case ATH9K_M_HOSTAP:
  499. /* XXX not right, beacon buffer is allocated on RUN trans */
  500. if (list_empty(&sc->sc_bbuf))
  501. return -ENOMEM;
  502. break;
  503. default:
  504. return -EINVAL;
  505. }
  506. /* create ath_vap */
  507. avp = kmalloc(sizeof(struct ath_vap), GFP_KERNEL);
  508. if (avp == NULL)
  509. return -ENOMEM;
  510. memzero(avp, sizeof(struct ath_vap));
  511. avp->av_if_data = if_data;
  512. /* Set the VAP opmode */
  513. avp->av_opmode = opmode;
  514. avp->av_bslot = -1;
  515. INIT_LIST_HEAD(&avp->av_mcastq.axq_q);
  516. INIT_LIST_HEAD(&avp->av_mcastq.axq_acq);
  517. spin_lock_init(&avp->av_mcastq.axq_lock);
  518. ath9k_hw_set_tsfadjust(sc->sc_ah, 1);
  519. sc->sc_vaps[if_id] = avp;
  520. sc->sc_nvaps++;
  521. /* Set the device opmode */
  522. sc->sc_ah->ah_opmode = opmode;
  523. /* default VAP configuration */
  524. avp->av_config.av_fixed_rateset = IEEE80211_FIXED_RATE_NONE;
  525. avp->av_config.av_fixed_retryset = 0x03030303;
  526. return 0;
  527. }
  528. int ath_vap_detach(struct ath_softc *sc, int if_id)
  529. {
  530. struct ath_hal *ah = sc->sc_ah;
  531. struct ath_vap *avp;
  532. avp = sc->sc_vaps[if_id];
  533. if (avp == NULL) {
  534. DPRINTF(sc, ATH_DBG_FATAL, "%s: invalid interface id %u\n",
  535. __func__, if_id);
  536. return -EINVAL;
  537. }
  538. /*
  539. * Quiesce the hardware while we remove the vap. In
  540. * particular we need to reclaim all references to the
  541. * vap state by any frames pending on the tx queues.
  542. *
  543. * XXX can we do this w/o affecting other vap's?
  544. */
  545. ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
  546. ath_draintxq(sc, false); /* stop xmit side */
  547. ath_stoprecv(sc); /* stop recv side */
  548. ath_flushrecv(sc); /* flush recv queue */
  549. /* Reclaim any pending mcast bufs on the vap. */
  550. ath_tx_draintxq(sc, &avp->av_mcastq, false);
  551. kfree(avp);
  552. sc->sc_vaps[if_id] = NULL;
  553. sc->sc_nvaps--;
  554. return 0;
  555. }
  556. int ath_vap_config(struct ath_softc *sc,
  557. int if_id, struct ath_vap_config *if_config)
  558. {
  559. struct ath_vap *avp;
  560. if (if_id >= ATH_BCBUF) {
  561. DPRINTF(sc, ATH_DBG_FATAL,
  562. "%s: Invalid interface id = %u\n", __func__, if_id);
  563. return -EINVAL;
  564. }
  565. avp = sc->sc_vaps[if_id];
  566. ASSERT(avp != NULL);
  567. if (avp)
  568. memcpy(&avp->av_config, if_config, sizeof(avp->av_config));
  569. return 0;
  570. }
  571. /********/
  572. /* Core */
  573. /********/
  574. int ath_open(struct ath_softc *sc, struct ath9k_channel *initial_chan)
  575. {
  576. struct ath_hal *ah = sc->sc_ah;
  577. int status;
  578. int error = 0;
  579. enum ath9k_ht_macmode ht_macmode = ath_cwm_macmode(sc);
  580. DPRINTF(sc, ATH_DBG_CONFIG, "%s: mode %d\n",
  581. __func__, sc->sc_ah->ah_opmode);
  582. /*
  583. * Stop anything previously setup. This is safe
  584. * whether this is the first time through or not.
  585. */
  586. ath_stop(sc);
  587. /* Initialize chanmask selection */
  588. sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
  589. sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
  590. /* Reset SERDES registers */
  591. ath9k_hw_configpcipowersave(ah, 0);
  592. /*
  593. * The basic interface to setting the hardware in a good
  594. * state is ``reset''. On return the hardware is known to
  595. * be powered up and with interrupts disabled. This must
  596. * be followed by initialization of the appropriate bits
  597. * and then setup of the interrupt mask.
  598. */
  599. spin_lock_bh(&sc->sc_resetlock);
  600. if (!ath9k_hw_reset(ah, initial_chan, ht_macmode,
  601. sc->sc_tx_chainmask, sc->sc_rx_chainmask,
  602. sc->sc_ht_extprotspacing, false, &status)) {
  603. DPRINTF(sc, ATH_DBG_FATAL,
  604. "%s: unable to reset hardware; hal status %u "
  605. "(freq %u flags 0x%x)\n", __func__, status,
  606. initial_chan->channel, initial_chan->channelFlags);
  607. error = -EIO;
  608. spin_unlock_bh(&sc->sc_resetlock);
  609. goto done;
  610. }
  611. spin_unlock_bh(&sc->sc_resetlock);
  612. /*
  613. * This is needed only to setup initial state
  614. * but it's best done after a reset.
  615. */
  616. ath_update_txpow(sc);
  617. /*
  618. * Setup the hardware after reset:
  619. * The receive engine is set going.
  620. * Frame transmit is handled entirely
  621. * in the frame output path; there's nothing to do
  622. * here except setup the interrupt mask.
  623. */
  624. if (ath_startrecv(sc) != 0) {
  625. DPRINTF(sc, ATH_DBG_FATAL,
  626. "%s: unable to start recv logic\n", __func__);
  627. error = -EIO;
  628. goto done;
  629. }
  630. /* Setup our intr mask. */
  631. sc->sc_imask = ATH9K_INT_RX | ATH9K_INT_TX
  632. | ATH9K_INT_RXEOL | ATH9K_INT_RXORN
  633. | ATH9K_INT_FATAL | ATH9K_INT_GLOBAL;
  634. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_GTT)
  635. sc->sc_imask |= ATH9K_INT_GTT;
  636. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT)
  637. sc->sc_imask |= ATH9K_INT_CST;
  638. /*
  639. * Enable MIB interrupts when there are hardware phy counters.
  640. * Note we only do this (at the moment) for station mode.
  641. */
  642. if (ath9k_hw_phycounters(ah) &&
  643. ((sc->sc_ah->ah_opmode == ATH9K_M_STA) ||
  644. (sc->sc_ah->ah_opmode == ATH9K_M_IBSS)))
  645. sc->sc_imask |= ATH9K_INT_MIB;
  646. /*
  647. * Some hardware processes the TIM IE and fires an
  648. * interrupt when the TIM bit is set. For hardware
  649. * that does, if not overridden by configuration,
  650. * enable the TIM interrupt when operating as station.
  651. */
  652. if ((ah->ah_caps.hw_caps & ATH9K_HW_CAP_ENHANCEDPM) &&
  653. (sc->sc_ah->ah_opmode == ATH9K_M_STA) &&
  654. !sc->sc_config.swBeaconProcess)
  655. sc->sc_imask |= ATH9K_INT_TIM;
  656. /*
  657. * Don't enable interrupts here as we've not yet built our
  658. * vap and node data structures, which will be needed as soon
  659. * as we start receiving.
  660. */
  661. ath_setcurmode(sc, ath_chan2mode(initial_chan));
  662. /* XXX: we must make sure h/w is ready and clear invalid flag
  663. * before turning on interrupt. */
  664. sc->sc_flags &= ~SC_OP_INVALID;
  665. done:
  666. return error;
  667. }
  668. int ath_reset(struct ath_softc *sc, bool retry_tx)
  669. {
  670. struct ath_hal *ah = sc->sc_ah;
  671. int status;
  672. int error = 0;
  673. enum ath9k_ht_macmode ht_macmode = ath_cwm_macmode(sc);
  674. ath9k_hw_set_interrupts(ah, 0); /* disable interrupts */
  675. ath_draintxq(sc, retry_tx); /* stop xmit */
  676. ath_stoprecv(sc); /* stop recv */
  677. ath_flushrecv(sc); /* flush recv queue */
  678. /* Reset chip */
  679. spin_lock_bh(&sc->sc_resetlock);
  680. if (!ath9k_hw_reset(ah, sc->sc_ah->ah_curchan,
  681. ht_macmode,
  682. sc->sc_tx_chainmask, sc->sc_rx_chainmask,
  683. sc->sc_ht_extprotspacing, false, &status)) {
  684. DPRINTF(sc, ATH_DBG_FATAL,
  685. "%s: unable to reset hardware; hal status %u\n",
  686. __func__, status);
  687. error = -EIO;
  688. }
  689. spin_unlock_bh(&sc->sc_resetlock);
  690. if (ath_startrecv(sc) != 0) /* restart recv */
  691. DPRINTF(sc, ATH_DBG_FATAL,
  692. "%s: unable to start recv logic\n", __func__);
  693. /*
  694. * We may be doing a reset in response to a request
  695. * that changes the channel so update any state that
  696. * might change as a result.
  697. */
  698. ath_setcurmode(sc, ath_chan2mode(sc->sc_ah->ah_curchan));
  699. ath_update_txpow(sc);
  700. if (sc->sc_flags & SC_OP_BEACONS)
  701. ath_beacon_config(sc, ATH_IF_ID_ANY); /* restart beacons */
  702. ath9k_hw_set_interrupts(ah, sc->sc_imask);
  703. /* Restart the txq */
  704. if (retry_tx) {
  705. int i;
  706. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++) {
  707. if (ATH_TXQ_SETUP(sc, i)) {
  708. spin_lock_bh(&sc->sc_txq[i].axq_lock);
  709. ath_txq_schedule(sc, &sc->sc_txq[i]);
  710. spin_unlock_bh(&sc->sc_txq[i].axq_lock);
  711. }
  712. }
  713. }
  714. return error;
  715. }
  716. int ath_suspend(struct ath_softc *sc)
  717. {
  718. struct ath_hal *ah = sc->sc_ah;
  719. /* No I/O if device has been surprise removed */
  720. if (sc->sc_flags & SC_OP_INVALID)
  721. return -EIO;
  722. /* Shut off the interrupt before setting sc->sc_invalid to '1' */
  723. ath9k_hw_set_interrupts(ah, 0);
  724. /* XXX: we must make sure h/w will not generate any interrupt
  725. * before setting the invalid flag. */
  726. sc->sc_flags |= SC_OP_INVALID;
  727. /* disable HAL and put h/w to sleep */
  728. ath9k_hw_disable(sc->sc_ah);
  729. ath9k_hw_configpcipowersave(sc->sc_ah, 1);
  730. return 0;
  731. }
  732. /* Interrupt handler. Most of the actual processing is deferred.
  733. * It's the caller's responsibility to ensure the chip is awake. */
  734. irqreturn_t ath_isr(int irq, void *dev)
  735. {
  736. struct ath_softc *sc = dev;
  737. struct ath_hal *ah = sc->sc_ah;
  738. enum ath9k_int status;
  739. bool sched = false;
  740. do {
  741. if (sc->sc_flags & SC_OP_INVALID) {
  742. /*
  743. * The hardware is not ready/present, don't
  744. * touch anything. Note this can happen early
  745. * on if the IRQ is shared.
  746. */
  747. return IRQ_NONE;
  748. }
  749. if (!ath9k_hw_intrpend(ah)) { /* shared irq, not for us */
  750. return IRQ_NONE;
  751. }
  752. /*
  753. * Figure out the reason(s) for the interrupt. Note
  754. * that the hal returns a pseudo-ISR that may include
  755. * bits we haven't explicitly enabled so we mask the
  756. * value to insure we only process bits we requested.
  757. */
  758. ath9k_hw_getisr(ah, &status); /* NB: clears ISR too */
  759. status &= sc->sc_imask; /* discard unasked-for bits */
  760. /*
  761. * If there are no status bits set, then this interrupt was not
  762. * for me (should have been caught above).
  763. */
  764. if (!status)
  765. return IRQ_NONE;
  766. sc->sc_intrstatus = status;
  767. if (status & ATH9K_INT_FATAL) {
  768. /* need a chip reset */
  769. sched = true;
  770. } else if (status & ATH9K_INT_RXORN) {
  771. /* need a chip reset */
  772. sched = true;
  773. } else {
  774. if (status & ATH9K_INT_SWBA) {
  775. /* schedule a tasklet for beacon handling */
  776. tasklet_schedule(&sc->bcon_tasklet);
  777. }
  778. if (status & ATH9K_INT_RXEOL) {
  779. /*
  780. * NB: the hardware should re-read the link when
  781. * RXE bit is written, but it doesn't work
  782. * at least on older hardware revs.
  783. */
  784. sched = true;
  785. }
  786. if (status & ATH9K_INT_TXURN)
  787. /* bump tx trigger level */
  788. ath9k_hw_updatetxtriglevel(ah, true);
  789. /* XXX: optimize this */
  790. if (status & ATH9K_INT_RX)
  791. sched = true;
  792. if (status & ATH9K_INT_TX)
  793. sched = true;
  794. if (status & ATH9K_INT_BMISS)
  795. sched = true;
  796. /* carrier sense timeout */
  797. if (status & ATH9K_INT_CST)
  798. sched = true;
  799. if (status & ATH9K_INT_MIB) {
  800. /*
  801. * Disable interrupts until we service the MIB
  802. * interrupt; otherwise it will continue to
  803. * fire.
  804. */
  805. ath9k_hw_set_interrupts(ah, 0);
  806. /*
  807. * Let the hal handle the event. We assume
  808. * it will clear whatever condition caused
  809. * the interrupt.
  810. */
  811. ath9k_hw_procmibevent(ah, &sc->sc_halstats);
  812. ath9k_hw_set_interrupts(ah, sc->sc_imask);
  813. }
  814. if (status & ATH9K_INT_TIM_TIMER) {
  815. if (!(ah->ah_caps.hw_caps &
  816. ATH9K_HW_CAP_AUTOSLEEP)) {
  817. /* Clear RxAbort bit so that we can
  818. * receive frames */
  819. ath9k_hw_setrxabort(ah, 0);
  820. sched = true;
  821. }
  822. }
  823. }
  824. } while (0);
  825. if (sched) {
  826. /* turn off every interrupt except SWBA */
  827. ath9k_hw_set_interrupts(ah, (sc->sc_imask & ATH9K_INT_SWBA));
  828. tasklet_schedule(&sc->intr_tq);
  829. }
  830. return IRQ_HANDLED;
  831. }
  832. /* Deferred interrupt processing */
  833. static void ath9k_tasklet(unsigned long data)
  834. {
  835. struct ath_softc *sc = (struct ath_softc *)data;
  836. u32 status = sc->sc_intrstatus;
  837. if (status & ATH9K_INT_FATAL) {
  838. /* need a chip reset */
  839. ath_reset(sc, false);
  840. return;
  841. } else {
  842. if (status &
  843. (ATH9K_INT_RX | ATH9K_INT_RXEOL | ATH9K_INT_RXORN)) {
  844. /* XXX: fill me in */
  845. /*
  846. if (status & ATH9K_INT_RXORN) {
  847. }
  848. if (status & ATH9K_INT_RXEOL) {
  849. }
  850. */
  851. spin_lock_bh(&sc->sc_rxflushlock);
  852. ath_rx_tasklet(sc, 0);
  853. spin_unlock_bh(&sc->sc_rxflushlock);
  854. }
  855. /* XXX: optimize this */
  856. if (status & ATH9K_INT_TX)
  857. ath_tx_tasklet(sc);
  858. /* XXX: fill me in */
  859. /*
  860. if (status & ATH9K_INT_BMISS) {
  861. }
  862. if (status & (ATH9K_INT_TIM | ATH9K_INT_DTIMSYNC)) {
  863. if (status & ATH9K_INT_TIM) {
  864. }
  865. if (status & ATH9K_INT_DTIMSYNC) {
  866. }
  867. }
  868. */
  869. }
  870. /* re-enable hardware interrupt */
  871. ath9k_hw_set_interrupts(sc->sc_ah, sc->sc_imask);
  872. }
  873. int ath_init(u16 devid, struct ath_softc *sc)
  874. {
  875. struct ath_hal *ah = NULL;
  876. int status;
  877. int error = 0, i;
  878. int csz = 0;
  879. u32 rd;
  880. /* XXX: hardware will not be ready until ath_open() being called */
  881. sc->sc_flags |= SC_OP_INVALID;
  882. sc->sc_debug = DBG_DEFAULT;
  883. DPRINTF(sc, ATH_DBG_CONFIG, "%s: devid 0x%x\n", __func__, devid);
  884. /* Initialize tasklet */
  885. tasklet_init(&sc->intr_tq, ath9k_tasklet, (unsigned long)sc);
  886. tasklet_init(&sc->bcon_tasklet, ath9k_beacon_tasklet,
  887. (unsigned long)sc);
  888. /*
  889. * Cache line size is used to size and align various
  890. * structures used to communicate with the hardware.
  891. */
  892. bus_read_cachesize(sc, &csz);
  893. /* XXX assert csz is non-zero */
  894. sc->sc_cachelsz = csz << 2; /* convert to bytes */
  895. spin_lock_init(&sc->sc_resetlock);
  896. ah = ath9k_hw_attach(devid, sc, sc->mem, &status);
  897. if (ah == NULL) {
  898. DPRINTF(sc, ATH_DBG_FATAL,
  899. "%s: unable to attach hardware; HAL status %u\n",
  900. __func__, status);
  901. error = -ENXIO;
  902. goto bad;
  903. }
  904. sc->sc_ah = ah;
  905. /* Get the hardware key cache size. */
  906. sc->sc_keymax = ah->ah_caps.keycache_size;
  907. if (sc->sc_keymax > ATH_KEYMAX) {
  908. DPRINTF(sc, ATH_DBG_KEYCACHE,
  909. "%s: Warning, using only %u entries in %u key cache\n",
  910. __func__, ATH_KEYMAX, sc->sc_keymax);
  911. sc->sc_keymax = ATH_KEYMAX;
  912. }
  913. /*
  914. * Reset the key cache since some parts do not
  915. * reset the contents on initial power up.
  916. */
  917. for (i = 0; i < sc->sc_keymax; i++)
  918. ath9k_hw_keyreset(ah, (u16) i);
  919. /*
  920. * Mark key cache slots associated with global keys
  921. * as in use. If we knew TKIP was not to be used we
  922. * could leave the +32, +64, and +32+64 slots free.
  923. * XXX only for splitmic.
  924. */
  925. for (i = 0; i < IEEE80211_WEP_NKID; i++) {
  926. set_bit(i, sc->sc_keymap);
  927. set_bit(i + 32, sc->sc_keymap);
  928. set_bit(i + 64, sc->sc_keymap);
  929. set_bit(i + 32 + 64, sc->sc_keymap);
  930. }
  931. /*
  932. * Collect the channel list using the default country
  933. * code and including outdoor channels. The 802.11 layer
  934. * is resposible for filtering this list based on settings
  935. * like the phy mode.
  936. */
  937. rd = ah->ah_currentRD;
  938. error = ath_setup_channels(sc);
  939. if (error)
  940. goto bad;
  941. /* default to STA mode */
  942. sc->sc_ah->ah_opmode = ATH9K_M_MONITOR;
  943. /* Setup rate tables */
  944. ath_setup_rates(sc, IEEE80211_BAND_2GHZ);
  945. ath_setup_rates(sc, IEEE80211_BAND_5GHZ);
  946. /* NB: setup here so ath_rate_update is happy */
  947. ath_setcurmode(sc, ATH9K_MODE_11A);
  948. /*
  949. * Allocate hardware transmit queues: one queue for
  950. * beacon frames and one data queue for each QoS
  951. * priority. Note that the hal handles reseting
  952. * these queues at the needed time.
  953. */
  954. sc->sc_bhalq = ath_beaconq_setup(ah);
  955. if (sc->sc_bhalq == -1) {
  956. DPRINTF(sc, ATH_DBG_FATAL,
  957. "%s: unable to setup a beacon xmit queue\n", __func__);
  958. error = -EIO;
  959. goto bad2;
  960. }
  961. sc->sc_cabq = ath_txq_setup(sc, ATH9K_TX_QUEUE_CAB, 0);
  962. if (sc->sc_cabq == NULL) {
  963. DPRINTF(sc, ATH_DBG_FATAL,
  964. "%s: unable to setup CAB xmit queue\n", __func__);
  965. error = -EIO;
  966. goto bad2;
  967. }
  968. sc->sc_config.cabqReadytime = ATH_CABQ_READY_TIME;
  969. ath_cabq_update(sc);
  970. for (i = 0; i < ARRAY_SIZE(sc->sc_haltype2q); i++)
  971. sc->sc_haltype2q[i] = -1;
  972. /* Setup data queues */
  973. /* NB: ensure BK queue is the lowest priority h/w queue */
  974. if (!ath_tx_setup(sc, ATH9K_WME_AC_BK)) {
  975. DPRINTF(sc, ATH_DBG_FATAL,
  976. "%s: unable to setup xmit queue for BK traffic\n",
  977. __func__);
  978. error = -EIO;
  979. goto bad2;
  980. }
  981. if (!ath_tx_setup(sc, ATH9K_WME_AC_BE)) {
  982. DPRINTF(sc, ATH_DBG_FATAL,
  983. "%s: unable to setup xmit queue for BE traffic\n",
  984. __func__);
  985. error = -EIO;
  986. goto bad2;
  987. }
  988. if (!ath_tx_setup(sc, ATH9K_WME_AC_VI)) {
  989. DPRINTF(sc, ATH_DBG_FATAL,
  990. "%s: unable to setup xmit queue for VI traffic\n",
  991. __func__);
  992. error = -EIO;
  993. goto bad2;
  994. }
  995. if (!ath_tx_setup(sc, ATH9K_WME_AC_VO)) {
  996. DPRINTF(sc, ATH_DBG_FATAL,
  997. "%s: unable to setup xmit queue for VO traffic\n",
  998. __func__);
  999. error = -EIO;
  1000. goto bad2;
  1001. }
  1002. sc->sc_rc = ath_rate_attach(ah);
  1003. if (sc->sc_rc == NULL) {
  1004. error = EIO;
  1005. goto bad2;
  1006. }
  1007. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1008. ATH9K_CIPHER_TKIP, NULL)) {
  1009. /*
  1010. * Whether we should enable h/w TKIP MIC.
  1011. * XXX: if we don't support WME TKIP MIC, then we wouldn't
  1012. * report WMM capable, so it's always safe to turn on
  1013. * TKIP MIC in this case.
  1014. */
  1015. ath9k_hw_setcapability(sc->sc_ah, ATH9K_CAP_TKIP_MIC,
  1016. 0, 1, NULL);
  1017. }
  1018. /*
  1019. * Check whether the separate key cache entries
  1020. * are required to handle both tx+rx MIC keys.
  1021. * With split mic keys the number of stations is limited
  1022. * to 27 otherwise 59.
  1023. */
  1024. if (ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1025. ATH9K_CIPHER_TKIP, NULL)
  1026. && ath9k_hw_getcapability(ah, ATH9K_CAP_CIPHER,
  1027. ATH9K_CIPHER_MIC, NULL)
  1028. && ath9k_hw_getcapability(ah, ATH9K_CAP_TKIP_SPLIT,
  1029. 0, NULL))
  1030. sc->sc_splitmic = 1;
  1031. /* turn on mcast key search if possible */
  1032. if (!ath9k_hw_getcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 0, NULL))
  1033. (void)ath9k_hw_setcapability(ah, ATH9K_CAP_MCAST_KEYSRCH, 1,
  1034. 1, NULL);
  1035. sc->sc_config.txpowlimit = ATH_TXPOWER_MAX;
  1036. sc->sc_config.txpowlimit_override = 0;
  1037. /* 11n Capabilities */
  1038. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_HT) {
  1039. sc->sc_flags |= SC_OP_TXAGGR;
  1040. sc->sc_flags |= SC_OP_RXAGGR;
  1041. }
  1042. sc->sc_tx_chainmask = ah->ah_caps.tx_chainmask;
  1043. sc->sc_rx_chainmask = ah->ah_caps.rx_chainmask;
  1044. ath9k_hw_setcapability(ah, ATH9K_CAP_DIVERSITY, 1, true, NULL);
  1045. sc->sc_defant = ath9k_hw_getdefantenna(ah);
  1046. ath9k_hw_getmac(ah, sc->sc_myaddr);
  1047. if (ah->ah_caps.hw_caps & ATH9K_HW_CAP_BSSIDMASK) {
  1048. ath9k_hw_getbssidmask(ah, sc->sc_bssidmask);
  1049. ATH_SET_VAP_BSSID_MASK(sc->sc_bssidmask);
  1050. ath9k_hw_setbssidmask(ah, sc->sc_bssidmask);
  1051. }
  1052. sc->sc_slottime = ATH9K_SLOT_TIME_9; /* default to short slot time */
  1053. /* initialize beacon slots */
  1054. for (i = 0; i < ARRAY_SIZE(sc->sc_bslot); i++)
  1055. sc->sc_bslot[i] = ATH_IF_ID_ANY;
  1056. /* save MISC configurations */
  1057. sc->sc_config.swBeaconProcess = 1;
  1058. #ifdef CONFIG_SLOW_ANT_DIV
  1059. /* range is 40 - 255, we use something in the middle */
  1060. ath_slow_ant_div_init(&sc->sc_antdiv, sc, 0x127);
  1061. #endif
  1062. return 0;
  1063. bad2:
  1064. /* cleanup tx queues */
  1065. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1066. if (ATH_TXQ_SETUP(sc, i))
  1067. ath_tx_cleanupq(sc, &sc->sc_txq[i]);
  1068. bad:
  1069. if (ah)
  1070. ath9k_hw_detach(ah);
  1071. return error;
  1072. }
  1073. void ath_deinit(struct ath_softc *sc)
  1074. {
  1075. struct ath_hal *ah = sc->sc_ah;
  1076. int i;
  1077. DPRINTF(sc, ATH_DBG_CONFIG, "%s\n", __func__);
  1078. ath_stop(sc);
  1079. if (!(sc->sc_flags & SC_OP_INVALID))
  1080. ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
  1081. ath_rate_detach(sc->sc_rc);
  1082. /* cleanup tx queues */
  1083. for (i = 0; i < ATH9K_NUM_TX_QUEUES; i++)
  1084. if (ATH_TXQ_SETUP(sc, i))
  1085. ath_tx_cleanupq(sc, &sc->sc_txq[i]);
  1086. ath9k_hw_detach(ah);
  1087. }
  1088. /*******************/
  1089. /* Node Management */
  1090. /*******************/
  1091. struct ath_node *ath_node_attach(struct ath_softc *sc, u8 *addr, int if_id)
  1092. {
  1093. struct ath_vap *avp;
  1094. struct ath_node *an;
  1095. DECLARE_MAC_BUF(mac);
  1096. avp = sc->sc_vaps[if_id];
  1097. ASSERT(avp != NULL);
  1098. /* mac80211 sta_notify callback is from an IRQ context, so no sleep */
  1099. an = kmalloc(sizeof(struct ath_node), GFP_ATOMIC);
  1100. if (an == NULL)
  1101. return NULL;
  1102. memzero(an, sizeof(*an));
  1103. an->an_sc = sc;
  1104. memcpy(an->an_addr, addr, ETH_ALEN);
  1105. atomic_set(&an->an_refcnt, 1);
  1106. /* set up per-node tx/rx state */
  1107. ath_tx_node_init(sc, an);
  1108. ath_rx_node_init(sc, an);
  1109. ath_chainmask_sel_init(sc, an);
  1110. ath_chainmask_sel_timerstart(&an->an_chainmask_sel);
  1111. list_add(&an->list, &sc->node_list);
  1112. return an;
  1113. }
  1114. void ath_node_detach(struct ath_softc *sc, struct ath_node *an, bool bh_flag)
  1115. {
  1116. unsigned long flags;
  1117. DECLARE_MAC_BUF(mac);
  1118. ath_chainmask_sel_timerstop(&an->an_chainmask_sel);
  1119. an->an_flags |= ATH_NODE_CLEAN;
  1120. ath_tx_node_cleanup(sc, an, bh_flag);
  1121. ath_rx_node_cleanup(sc, an);
  1122. ath_tx_node_free(sc, an);
  1123. ath_rx_node_free(sc, an);
  1124. spin_lock_irqsave(&sc->node_lock, flags);
  1125. list_del(&an->list);
  1126. spin_unlock_irqrestore(&sc->node_lock, flags);
  1127. kfree(an);
  1128. }
  1129. /* Finds a node and increases the refcnt if found */
  1130. struct ath_node *ath_node_get(struct ath_softc *sc, u8 *addr)
  1131. {
  1132. struct ath_node *an = NULL, *an_found = NULL;
  1133. if (list_empty(&sc->node_list)) /* FIXME */
  1134. goto out;
  1135. list_for_each_entry(an, &sc->node_list, list) {
  1136. if (!compare_ether_addr(an->an_addr, addr)) {
  1137. atomic_inc(&an->an_refcnt);
  1138. an_found = an;
  1139. break;
  1140. }
  1141. }
  1142. out:
  1143. return an_found;
  1144. }
  1145. /* Decrements the refcnt and if it drops to zero, detach the node */
  1146. void ath_node_put(struct ath_softc *sc, struct ath_node *an, bool bh_flag)
  1147. {
  1148. if (atomic_dec_and_test(&an->an_refcnt))
  1149. ath_node_detach(sc, an, bh_flag);
  1150. }
  1151. /* Finds a node, doesn't increment refcnt. Caller must hold sc->node_lock */
  1152. struct ath_node *ath_node_find(struct ath_softc *sc, u8 *addr)
  1153. {
  1154. struct ath_node *an = NULL, *an_found = NULL;
  1155. if (list_empty(&sc->node_list))
  1156. return NULL;
  1157. list_for_each_entry(an, &sc->node_list, list)
  1158. if (!compare_ether_addr(an->an_addr, addr)) {
  1159. an_found = an;
  1160. break;
  1161. }
  1162. return an_found;
  1163. }
  1164. /*
  1165. * Set up New Node
  1166. *
  1167. * Setup driver-specific state for a newly associated node. This routine
  1168. * really only applies if compression or XR are enabled, there is no code
  1169. * covering any other cases.
  1170. */
  1171. void ath_newassoc(struct ath_softc *sc,
  1172. struct ath_node *an, int isnew, int isuapsd)
  1173. {
  1174. int tidno;
  1175. /* if station reassociates, tear down the aggregation state. */
  1176. if (!isnew) {
  1177. for (tidno = 0; tidno < WME_NUM_TID; tidno++) {
  1178. if (sc->sc_flags & SC_OP_TXAGGR)
  1179. ath_tx_aggr_teardown(sc, an, tidno);
  1180. if (sc->sc_flags & SC_OP_RXAGGR)
  1181. ath_rx_aggr_teardown(sc, an, tidno);
  1182. }
  1183. }
  1184. an->an_flags = 0;
  1185. }
  1186. /**************/
  1187. /* Encryption */
  1188. /**************/
  1189. void ath_key_reset(struct ath_softc *sc, u16 keyix, int freeslot)
  1190. {
  1191. ath9k_hw_keyreset(sc->sc_ah, keyix);
  1192. if (freeslot)
  1193. clear_bit(keyix, sc->sc_keymap);
  1194. }
  1195. int ath_keyset(struct ath_softc *sc,
  1196. u16 keyix,
  1197. struct ath9k_keyval *hk,
  1198. const u8 mac[ETH_ALEN])
  1199. {
  1200. bool status;
  1201. status = ath9k_hw_set_keycache_entry(sc->sc_ah,
  1202. keyix, hk, mac, false);
  1203. return status != false;
  1204. }
  1205. /***********************/
  1206. /* TX Power/Regulatory */
  1207. /***********************/
  1208. /*
  1209. * Set Transmit power in HAL
  1210. *
  1211. * This routine makes the actual HAL calls to set the new transmit power
  1212. * limit.
  1213. */
  1214. void ath_update_txpow(struct ath_softc *sc)
  1215. {
  1216. struct ath_hal *ah = sc->sc_ah;
  1217. u32 txpow;
  1218. if (sc->sc_curtxpow != sc->sc_config.txpowlimit) {
  1219. ath9k_hw_set_txpowerlimit(ah, sc->sc_config.txpowlimit);
  1220. /* read back in case value is clamped */
  1221. ath9k_hw_getcapability(ah, ATH9K_CAP_TXPOW, 1, &txpow);
  1222. sc->sc_curtxpow = txpow;
  1223. }
  1224. }
  1225. /* Return the current country and domain information */
  1226. void ath_get_currentCountry(struct ath_softc *sc,
  1227. struct ath9k_country_entry *ctry)
  1228. {
  1229. ath9k_regd_get_current_country(sc->sc_ah, ctry);
  1230. /* If HAL not specific yet, since it is band dependent,
  1231. * use the one we passed in. */
  1232. if (ctry->countryCode == CTRY_DEFAULT) {
  1233. ctry->iso[0] = 0;
  1234. ctry->iso[1] = 0;
  1235. } else if (ctry->iso[0] && ctry->iso[1]) {
  1236. if (!ctry->iso[2]) {
  1237. if (ath_outdoor)
  1238. ctry->iso[2] = 'O';
  1239. else
  1240. ctry->iso[2] = 'I';
  1241. }
  1242. }
  1243. }
  1244. /**************************/
  1245. /* Slow Antenna Diversity */
  1246. /**************************/
  1247. void ath_slow_ant_div_init(struct ath_antdiv *antdiv,
  1248. struct ath_softc *sc,
  1249. int32_t rssitrig)
  1250. {
  1251. int trig;
  1252. /* antdivf_rssitrig can range from 40 - 0xff */
  1253. trig = (rssitrig > 0xff) ? 0xff : rssitrig;
  1254. trig = (rssitrig < 40) ? 40 : rssitrig;
  1255. antdiv->antdiv_sc = sc;
  1256. antdiv->antdivf_rssitrig = trig;
  1257. }
  1258. void ath_slow_ant_div_start(struct ath_antdiv *antdiv,
  1259. u8 num_antcfg,
  1260. const u8 *bssid)
  1261. {
  1262. antdiv->antdiv_num_antcfg =
  1263. num_antcfg < ATH_ANT_DIV_MAX_CFG ?
  1264. num_antcfg : ATH_ANT_DIV_MAX_CFG;
  1265. antdiv->antdiv_state = ATH_ANT_DIV_IDLE;
  1266. antdiv->antdiv_curcfg = 0;
  1267. antdiv->antdiv_bestcfg = 0;
  1268. antdiv->antdiv_laststatetsf = 0;
  1269. memcpy(antdiv->antdiv_bssid, bssid, sizeof(antdiv->antdiv_bssid));
  1270. antdiv->antdiv_start = 1;
  1271. }
  1272. void ath_slow_ant_div_stop(struct ath_antdiv *antdiv)
  1273. {
  1274. antdiv->antdiv_start = 0;
  1275. }
  1276. static int32_t ath_find_max_val(int32_t *val,
  1277. u8 num_val, u8 *max_index)
  1278. {
  1279. u32 MaxVal = *val++;
  1280. u32 cur_index = 0;
  1281. *max_index = 0;
  1282. while (++cur_index < num_val) {
  1283. if (*val > MaxVal) {
  1284. MaxVal = *val;
  1285. *max_index = cur_index;
  1286. }
  1287. val++;
  1288. }
  1289. return MaxVal;
  1290. }
  1291. void ath_slow_ant_div(struct ath_antdiv *antdiv,
  1292. struct ieee80211_hdr *hdr,
  1293. struct ath_rx_status *rx_stats)
  1294. {
  1295. struct ath_softc *sc = antdiv->antdiv_sc;
  1296. struct ath_hal *ah = sc->sc_ah;
  1297. u64 curtsf = 0;
  1298. u8 bestcfg, curcfg = antdiv->antdiv_curcfg;
  1299. __le16 fc = hdr->frame_control;
  1300. if (antdiv->antdiv_start && ieee80211_is_beacon(fc)
  1301. && !compare_ether_addr(hdr->addr3, antdiv->antdiv_bssid)) {
  1302. antdiv->antdiv_lastbrssi[curcfg] = rx_stats->rs_rssi;
  1303. antdiv->antdiv_lastbtsf[curcfg] = ath9k_hw_gettsf64(sc->sc_ah);
  1304. curtsf = antdiv->antdiv_lastbtsf[curcfg];
  1305. } else {
  1306. return;
  1307. }
  1308. switch (antdiv->antdiv_state) {
  1309. case ATH_ANT_DIV_IDLE:
  1310. if ((antdiv->antdiv_lastbrssi[curcfg] <
  1311. antdiv->antdivf_rssitrig)
  1312. && ((curtsf - antdiv->antdiv_laststatetsf) >
  1313. ATH_ANT_DIV_MIN_IDLE_US)) {
  1314. curcfg++;
  1315. if (curcfg == antdiv->antdiv_num_antcfg)
  1316. curcfg = 0;
  1317. if (!ath9k_hw_select_antconfig(ah, curcfg)) {
  1318. antdiv->antdiv_bestcfg = antdiv->antdiv_curcfg;
  1319. antdiv->antdiv_curcfg = curcfg;
  1320. antdiv->antdiv_laststatetsf = curtsf;
  1321. antdiv->antdiv_state = ATH_ANT_DIV_SCAN;
  1322. }
  1323. }
  1324. break;
  1325. case ATH_ANT_DIV_SCAN:
  1326. if ((curtsf - antdiv->antdiv_laststatetsf) <
  1327. ATH_ANT_DIV_MIN_SCAN_US)
  1328. break;
  1329. curcfg++;
  1330. if (curcfg == antdiv->antdiv_num_antcfg)
  1331. curcfg = 0;
  1332. if (curcfg == antdiv->antdiv_bestcfg) {
  1333. ath_find_max_val(antdiv->antdiv_lastbrssi,
  1334. antdiv->antdiv_num_antcfg, &bestcfg);
  1335. if (!ath9k_hw_select_antconfig(ah, bestcfg)) {
  1336. antdiv->antdiv_bestcfg = bestcfg;
  1337. antdiv->antdiv_curcfg = bestcfg;
  1338. antdiv->antdiv_laststatetsf = curtsf;
  1339. antdiv->antdiv_state = ATH_ANT_DIV_IDLE;
  1340. }
  1341. } else {
  1342. if (!ath9k_hw_select_antconfig(ah, curcfg)) {
  1343. antdiv->antdiv_curcfg = curcfg;
  1344. antdiv->antdiv_laststatetsf = curtsf;
  1345. antdiv->antdiv_state = ATH_ANT_DIV_SCAN;
  1346. }
  1347. }
  1348. break;
  1349. }
  1350. }
  1351. /***********************/
  1352. /* Descriptor Handling */
  1353. /***********************/
  1354. /*
  1355. * Set up DMA descriptors
  1356. *
  1357. * This function will allocate both the DMA descriptor structure, and the
  1358. * buffers it contains. These are used to contain the descriptors used
  1359. * by the system.
  1360. */
  1361. int ath_descdma_setup(struct ath_softc *sc,
  1362. struct ath_descdma *dd,
  1363. struct list_head *head,
  1364. const char *name,
  1365. int nbuf,
  1366. int ndesc)
  1367. {
  1368. #define DS2PHYS(_dd, _ds) \
  1369. ((_dd)->dd_desc_paddr + ((caddr_t)(_ds) - (caddr_t)(_dd)->dd_desc))
  1370. #define ATH_DESC_4KB_BOUND_CHECK(_daddr) ((((_daddr) & 0xFFF) > 0xF7F) ? 1 : 0)
  1371. #define ATH_DESC_4KB_BOUND_NUM_SKIPPED(_len) ((_len) / 4096)
  1372. struct ath_desc *ds;
  1373. struct ath_buf *bf;
  1374. int i, bsize, error;
  1375. DPRINTF(sc, ATH_DBG_CONFIG, "%s: %s DMA: %u buffers %u desc/buf\n",
  1376. __func__, name, nbuf, ndesc);
  1377. /* ath_desc must be a multiple of DWORDs */
  1378. if ((sizeof(struct ath_desc) % 4) != 0) {
  1379. DPRINTF(sc, ATH_DBG_FATAL, "%s: ath_desc not DWORD aligned\n",
  1380. __func__);
  1381. ASSERT((sizeof(struct ath_desc) % 4) == 0);
  1382. error = -ENOMEM;
  1383. goto fail;
  1384. }
  1385. dd->dd_name = name;
  1386. dd->dd_desc_len = sizeof(struct ath_desc) * nbuf * ndesc;
  1387. /*
  1388. * Need additional DMA memory because we can't use
  1389. * descriptors that cross the 4K page boundary. Assume
  1390. * one skipped descriptor per 4K page.
  1391. */
  1392. if (!(sc->sc_ah->ah_caps.hw_caps & ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1393. u32 ndesc_skipped =
  1394. ATH_DESC_4KB_BOUND_NUM_SKIPPED(dd->dd_desc_len);
  1395. u32 dma_len;
  1396. while (ndesc_skipped) {
  1397. dma_len = ndesc_skipped * sizeof(struct ath_desc);
  1398. dd->dd_desc_len += dma_len;
  1399. ndesc_skipped = ATH_DESC_4KB_BOUND_NUM_SKIPPED(dma_len);
  1400. };
  1401. }
  1402. /* allocate descriptors */
  1403. dd->dd_desc = pci_alloc_consistent(sc->pdev,
  1404. dd->dd_desc_len,
  1405. &dd->dd_desc_paddr);
  1406. if (dd->dd_desc == NULL) {
  1407. error = -ENOMEM;
  1408. goto fail;
  1409. }
  1410. ds = dd->dd_desc;
  1411. DPRINTF(sc, ATH_DBG_CONFIG, "%s: %s DMA map: %p (%u) -> %llx (%u)\n",
  1412. __func__, dd->dd_name, ds, (u32) dd->dd_desc_len,
  1413. ito64(dd->dd_desc_paddr), /*XXX*/(u32) dd->dd_desc_len);
  1414. /* allocate buffers */
  1415. bsize = sizeof(struct ath_buf) * nbuf;
  1416. bf = kmalloc(bsize, GFP_KERNEL);
  1417. if (bf == NULL) {
  1418. error = -ENOMEM;
  1419. goto fail2;
  1420. }
  1421. memzero(bf, bsize);
  1422. dd->dd_bufptr = bf;
  1423. INIT_LIST_HEAD(head);
  1424. for (i = 0; i < nbuf; i++, bf++, ds += ndesc) {
  1425. bf->bf_desc = ds;
  1426. bf->bf_daddr = DS2PHYS(dd, ds);
  1427. if (!(sc->sc_ah->ah_caps.hw_caps &
  1428. ATH9K_HW_CAP_4KB_SPLITTRANS)) {
  1429. /*
  1430. * Skip descriptor addresses which can cause 4KB
  1431. * boundary crossing (addr + length) with a 32 dword
  1432. * descriptor fetch.
  1433. */
  1434. while (ATH_DESC_4KB_BOUND_CHECK(bf->bf_daddr)) {
  1435. ASSERT((caddr_t) bf->bf_desc <
  1436. ((caddr_t) dd->dd_desc +
  1437. dd->dd_desc_len));
  1438. ds += ndesc;
  1439. bf->bf_desc = ds;
  1440. bf->bf_daddr = DS2PHYS(dd, ds);
  1441. }
  1442. }
  1443. list_add_tail(&bf->list, head);
  1444. }
  1445. return 0;
  1446. fail2:
  1447. pci_free_consistent(sc->pdev,
  1448. dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
  1449. fail:
  1450. memzero(dd, sizeof(*dd));
  1451. return error;
  1452. #undef ATH_DESC_4KB_BOUND_CHECK
  1453. #undef ATH_DESC_4KB_BOUND_NUM_SKIPPED
  1454. #undef DS2PHYS
  1455. }
  1456. /*
  1457. * Cleanup DMA descriptors
  1458. *
  1459. * This function will free the DMA block that was allocated for the descriptor
  1460. * pool. Since this was allocated as one "chunk", it is freed in the same
  1461. * manner.
  1462. */
  1463. void ath_descdma_cleanup(struct ath_softc *sc,
  1464. struct ath_descdma *dd,
  1465. struct list_head *head)
  1466. {
  1467. /* Free memory associated with descriptors */
  1468. pci_free_consistent(sc->pdev,
  1469. dd->dd_desc_len, dd->dd_desc, dd->dd_desc_paddr);
  1470. INIT_LIST_HEAD(head);
  1471. kfree(dd->dd_bufptr);
  1472. memzero(dd, sizeof(*dd));
  1473. }
  1474. /*************/
  1475. /* Utilities */
  1476. /*************/
  1477. int ath_get_hal_qnum(u16 queue, struct ath_softc *sc)
  1478. {
  1479. int qnum;
  1480. switch (queue) {
  1481. case 0:
  1482. qnum = sc->sc_haltype2q[ATH9K_WME_AC_VO];
  1483. break;
  1484. case 1:
  1485. qnum = sc->sc_haltype2q[ATH9K_WME_AC_VI];
  1486. break;
  1487. case 2:
  1488. qnum = sc->sc_haltype2q[ATH9K_WME_AC_BE];
  1489. break;
  1490. case 3:
  1491. qnum = sc->sc_haltype2q[ATH9K_WME_AC_BK];
  1492. break;
  1493. default:
  1494. qnum = sc->sc_haltype2q[ATH9K_WME_AC_BE];
  1495. break;
  1496. }
  1497. return qnum;
  1498. }
  1499. int ath_get_mac80211_qnum(u32 queue, struct ath_softc *sc)
  1500. {
  1501. int qnum;
  1502. switch (queue) {
  1503. case ATH9K_WME_AC_VO:
  1504. qnum = 0;
  1505. break;
  1506. case ATH9K_WME_AC_VI:
  1507. qnum = 1;
  1508. break;
  1509. case ATH9K_WME_AC_BE:
  1510. qnum = 2;
  1511. break;
  1512. case ATH9K_WME_AC_BK:
  1513. qnum = 3;
  1514. break;
  1515. default:
  1516. qnum = -1;
  1517. break;
  1518. }
  1519. return qnum;
  1520. }
  1521. /*
  1522. * Expand time stamp to TSF
  1523. *
  1524. * Extend 15-bit time stamp from rx descriptor to
  1525. * a full 64-bit TSF using the current h/w TSF.
  1526. */
  1527. u64 ath_extend_tsf(struct ath_softc *sc, u32 rstamp)
  1528. {
  1529. u64 tsf;
  1530. tsf = ath9k_hw_gettsf64(sc->sc_ah);
  1531. if ((tsf & 0x7fff) < rstamp)
  1532. tsf -= 0x8000;
  1533. return (tsf & ~0x7fff) | rstamp;
  1534. }
  1535. /*
  1536. * Set Default Antenna
  1537. *
  1538. * Call into the HAL to set the default antenna to use. Not really valid for
  1539. * MIMO technology.
  1540. */
  1541. void ath_setdefantenna(void *context, u32 antenna)
  1542. {
  1543. struct ath_softc *sc = (struct ath_softc *)context;
  1544. struct ath_hal *ah = sc->sc_ah;
  1545. /* XXX block beacon interrupts */
  1546. ath9k_hw_setantenna(ah, antenna);
  1547. sc->sc_defant = antenna;
  1548. sc->sc_rxotherant = 0;
  1549. }
  1550. /*
  1551. * Set Slot Time
  1552. *
  1553. * This will wake up the chip if required, and set the slot time for the
  1554. * frame (maximum transmit time). Slot time is assumed to be already set
  1555. * in the ATH object member sc_slottime
  1556. */
  1557. void ath_setslottime(struct ath_softc *sc)
  1558. {
  1559. ath9k_hw_setslottime(sc->sc_ah, sc->sc_slottime);
  1560. sc->sc_updateslot = OK;
  1561. }