main.c 72 KB

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