main.c 71 KB

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