main.c 71 KB

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