core.c 46 KB

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