core.c 44 KB

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