main.c 71 KB

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