core.c 46 KB

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