hw.c 110 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357
  1. /*
  2. * Copyright (c) 2004-2007 Reyk Floeter <reyk@openbsd.org>
  3. * Copyright (c) 2006-2007 Nick Kossifidis <mickflemm@gmail.com>
  4. * Copyright (c) 2007 Matthew W. S. Bell <mentor@madwifi.org>
  5. * Copyright (c) 2007 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
  6. * Copyright (c) 2007 Pavel Roskin <proski@gnu.org>
  7. * Copyright (c) 2007 Jiri Slaby <jirislaby@gmail.com>
  8. *
  9. * Permission to use, copy, modify, and distribute this software for any
  10. * purpose with or without fee is hereby granted, provided that the above
  11. * copyright notice and this permission notice appear in all copies.
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  14. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  15. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  16. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  17. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  18. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  19. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  20. *
  21. */
  22. /*
  23. * HW related functions for Atheros Wireless LAN devices.
  24. */
  25. #include <linux/pci.h>
  26. #include <linux/delay.h>
  27. #include "reg.h"
  28. #include "base.h"
  29. #include "debug.h"
  30. /*Rate tables*/
  31. static const struct ath5k_rate_table ath5k_rt_11a = AR5K_RATES_11A;
  32. static const struct ath5k_rate_table ath5k_rt_11b = AR5K_RATES_11B;
  33. static const struct ath5k_rate_table ath5k_rt_11g = AR5K_RATES_11G;
  34. static const struct ath5k_rate_table ath5k_rt_turbo = AR5K_RATES_TURBO;
  35. static const struct ath5k_rate_table ath5k_rt_xr = AR5K_RATES_XR;
  36. /*Prototypes*/
  37. static int ath5k_hw_nic_reset(struct ath5k_hw *, u32);
  38. static int ath5k_hw_nic_wakeup(struct ath5k_hw *, int, bool);
  39. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  40. unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
  41. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  42. unsigned int, unsigned int);
  43. static int ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  44. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  45. unsigned int);
  46. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
  47. static int ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *, struct ath5k_desc *,
  48. unsigned int, unsigned int, enum ath5k_pkt_type, unsigned int,
  49. unsigned int, unsigned int, unsigned int, unsigned int, unsigned int,
  50. unsigned int, unsigned int);
  51. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *, struct ath5k_desc *);
  52. static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *, struct ath5k_desc *);
  53. static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *, struct ath5k_desc *);
  54. static int ath5k_hw_get_capabilities(struct ath5k_hw *);
  55. static int ath5k_eeprom_init(struct ath5k_hw *);
  56. static int ath5k_eeprom_read_mac(struct ath5k_hw *, u8 *);
  57. static int ath5k_hw_enable_pspoll(struct ath5k_hw *, u8 *, u16);
  58. static int ath5k_hw_disable_pspoll(struct ath5k_hw *);
  59. /*
  60. * Enable to overwrite the country code (use "00" for debug)
  61. */
  62. #if 0
  63. #define COUNTRYCODE "00"
  64. #endif
  65. /*******************\
  66. General Functions
  67. \*******************/
  68. /*
  69. * Functions used internaly
  70. */
  71. static inline unsigned int ath5k_hw_htoclock(unsigned int usec, bool turbo)
  72. {
  73. return turbo == true ? (usec * 80) : (usec * 40);
  74. }
  75. static inline unsigned int ath5k_hw_clocktoh(unsigned int clock, bool turbo)
  76. {
  77. return turbo == true ? (clock / 80) : (clock / 40);
  78. }
  79. /*
  80. * Check if a register write has been completed
  81. */
  82. int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
  83. bool is_set)
  84. {
  85. int i;
  86. u32 data;
  87. for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
  88. data = ath5k_hw_reg_read(ah, reg);
  89. if ((is_set == true) && (data & flag))
  90. break;
  91. else if ((data & flag) == val)
  92. break;
  93. udelay(15);
  94. }
  95. return (i <= 0) ? -EAGAIN : 0;
  96. }
  97. /***************************************\
  98. Attach/Detach Functions
  99. \***************************************/
  100. /*
  101. * Check if the device is supported and initialize the needed structs
  102. */
  103. struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
  104. {
  105. struct ath5k_hw *ah;
  106. u8 mac[ETH_ALEN];
  107. int ret;
  108. u32 srev;
  109. /*If we passed the test malloc a ath5k_hw struct*/
  110. ah = kzalloc(sizeof(struct ath5k_hw), GFP_KERNEL);
  111. if (ah == NULL) {
  112. ret = -ENOMEM;
  113. ATH5K_ERR(sc, "out of memory\n");
  114. goto err;
  115. }
  116. ah->ah_sc = sc;
  117. ah->ah_iobase = sc->iobase;
  118. /*
  119. * HW information
  120. */
  121. /* Get reg domain from eeprom */
  122. ath5k_get_regdomain(ah);
  123. ah->ah_op_mode = IEEE80211_IF_TYPE_STA;
  124. ah->ah_radar.r_enabled = AR5K_TUNE_RADAR_ALERT;
  125. ah->ah_turbo = false;
  126. ah->ah_txpower.txp_tpc = AR5K_TUNE_TPC_TXPOWER;
  127. ah->ah_imr = 0;
  128. ah->ah_atim_window = 0;
  129. ah->ah_aifs = AR5K_TUNE_AIFS;
  130. ah->ah_cw_min = AR5K_TUNE_CWMIN;
  131. ah->ah_limit_tx_retries = AR5K_INIT_TX_RETRY;
  132. ah->ah_software_retry = false;
  133. ah->ah_ant_diversity = AR5K_TUNE_ANT_DIVERSITY;
  134. /*
  135. * Set the mac revision based on the pci id
  136. */
  137. ah->ah_version = mac_version;
  138. /*Fill the ath5k_hw struct with the needed functions*/
  139. if (ah->ah_version == AR5K_AR5212)
  140. ah->ah_magic = AR5K_EEPROM_MAGIC_5212;
  141. else if (ah->ah_version == AR5K_AR5211)
  142. ah->ah_magic = AR5K_EEPROM_MAGIC_5211;
  143. if (ah->ah_version == AR5K_AR5212) {
  144. ah->ah_setup_tx_desc = ath5k_hw_setup_4word_tx_desc;
  145. ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
  146. ah->ah_proc_tx_desc = ath5k_hw_proc_4word_tx_status;
  147. } else {
  148. ah->ah_setup_tx_desc = ath5k_hw_setup_2word_tx_desc;
  149. ah->ah_setup_xtx_desc = ath5k_hw_setup_xr_tx_desc;
  150. ah->ah_proc_tx_desc = ath5k_hw_proc_2word_tx_status;
  151. }
  152. if (ah->ah_version == AR5K_AR5212)
  153. ah->ah_proc_rx_desc = ath5k_hw_proc_new_rx_status;
  154. else if (ah->ah_version <= AR5K_AR5211)
  155. ah->ah_proc_rx_desc = ath5k_hw_proc_old_rx_status;
  156. /* Bring device out of sleep and reset it's units */
  157. ret = ath5k_hw_nic_wakeup(ah, AR5K_INIT_MODE, true);
  158. if (ret)
  159. goto err_free;
  160. /* Get MAC, PHY and RADIO revisions */
  161. srev = ath5k_hw_reg_read(ah, AR5K_SREV);
  162. ah->ah_mac_srev = srev;
  163. ah->ah_mac_version = AR5K_REG_MS(srev, AR5K_SREV_VER);
  164. ah->ah_mac_revision = AR5K_REG_MS(srev, AR5K_SREV_REV);
  165. ah->ah_phy_revision = ath5k_hw_reg_read(ah, AR5K_PHY_CHIP_ID) &
  166. 0xffffffff;
  167. ah->ah_radio_5ghz_revision = ath5k_hw_radio_revision(ah,
  168. CHANNEL_5GHZ);
  169. if (ah->ah_version == AR5K_AR5210)
  170. ah->ah_radio_2ghz_revision = 0;
  171. else
  172. ah->ah_radio_2ghz_revision = ath5k_hw_radio_revision(ah,
  173. CHANNEL_2GHZ);
  174. /* Return on unsuported chips (unsupported eeprom etc) */
  175. if(srev >= AR5K_SREV_VER_AR5416){
  176. ATH5K_ERR(sc, "Device not yet supported.\n");
  177. ret = -ENODEV;
  178. goto err_free;
  179. }
  180. /* Identify single chip solutions */
  181. if((srev <= AR5K_SREV_VER_AR5414) &&
  182. (srev >= AR5K_SREV_VER_AR2424)) {
  183. ah->ah_single_chip = true;
  184. } else {
  185. ah->ah_single_chip = false;
  186. }
  187. /* Single chip radio */
  188. if (ah->ah_radio_2ghz_revision == ah->ah_radio_5ghz_revision)
  189. ah->ah_radio_2ghz_revision = 0;
  190. /* Identify the radio chip*/
  191. if (ah->ah_version == AR5K_AR5210) {
  192. ah->ah_radio = AR5K_RF5110;
  193. } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5112) {
  194. ah->ah_radio = AR5K_RF5111;
  195. } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC1) {
  196. ah->ah_radio = AR5K_RF5112;
  197. } else {
  198. ah->ah_radio = AR5K_RF5413;
  199. }
  200. ah->ah_phy = AR5K_PHY(0);
  201. /*
  202. * Get card capabilities, values, ...
  203. */
  204. ret = ath5k_eeprom_init(ah);
  205. if (ret) {
  206. ATH5K_ERR(sc, "unable to init EEPROM\n");
  207. goto err_free;
  208. }
  209. /* Get misc capabilities */
  210. ret = ath5k_hw_get_capabilities(ah);
  211. if (ret) {
  212. ATH5K_ERR(sc, "unable to get device capabilities: 0x%04x\n",
  213. sc->pdev->device);
  214. goto err_free;
  215. }
  216. /* Get MAC address */
  217. ret = ath5k_eeprom_read_mac(ah, mac);
  218. if (ret) {
  219. ATH5K_ERR(sc, "unable to read address from EEPROM: 0x%04x\n",
  220. sc->pdev->device);
  221. goto err_free;
  222. }
  223. ath5k_hw_set_lladdr(ah, mac);
  224. /* Set BSSID to bcast address: ff:ff:ff:ff:ff:ff for now */
  225. memset(ah->ah_bssid, 0xff, ETH_ALEN);
  226. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  227. ath5k_hw_set_opmode(ah);
  228. ath5k_hw_set_rfgain_opt(ah);
  229. return ah;
  230. err_free:
  231. kfree(ah);
  232. err:
  233. return ERR_PTR(ret);
  234. }
  235. /*
  236. * Bring up MAC + PHY Chips
  237. */
  238. static int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
  239. {
  240. u32 turbo, mode, clock;
  241. int ret;
  242. turbo = 0;
  243. mode = 0;
  244. clock = 0;
  245. ATH5K_TRACE(ah->ah_sc);
  246. /* Wakeup the device */
  247. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  248. if (ret) {
  249. ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
  250. return ret;
  251. }
  252. if (ah->ah_version != AR5K_AR5210) {
  253. /*
  254. * Get channel mode flags
  255. */
  256. if (ah->ah_radio >= AR5K_RF5112) {
  257. mode = AR5K_PHY_MODE_RAD_RF5112;
  258. clock = AR5K_PHY_PLL_RF5112;
  259. } else {
  260. mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
  261. clock = AR5K_PHY_PLL_RF5111; /*Zero*/
  262. }
  263. if (flags & CHANNEL_2GHZ) {
  264. mode |= AR5K_PHY_MODE_FREQ_2GHZ;
  265. clock |= AR5K_PHY_PLL_44MHZ;
  266. if (flags & CHANNEL_CCK) {
  267. mode |= AR5K_PHY_MODE_MOD_CCK;
  268. } else if (flags & CHANNEL_OFDM) {
  269. /* XXX Dynamic OFDM/CCK is not supported by the
  270. * AR5211 so we set MOD_OFDM for plain g (no
  271. * CCK headers) operation. We need to test
  272. * this, 5211 might support ofdm-only g after
  273. * all, there are also initial register values
  274. * in the code for g mode (see initvals.c). */
  275. if (ah->ah_version == AR5K_AR5211)
  276. mode |= AR5K_PHY_MODE_MOD_OFDM;
  277. else
  278. mode |= AR5K_PHY_MODE_MOD_DYN;
  279. } else {
  280. ATH5K_ERR(ah->ah_sc,
  281. "invalid radio modulation mode\n");
  282. return -EINVAL;
  283. }
  284. } else if (flags & CHANNEL_5GHZ) {
  285. mode |= AR5K_PHY_MODE_FREQ_5GHZ;
  286. clock |= AR5K_PHY_PLL_40MHZ;
  287. if (flags & CHANNEL_OFDM)
  288. mode |= AR5K_PHY_MODE_MOD_OFDM;
  289. else {
  290. ATH5K_ERR(ah->ah_sc,
  291. "invalid radio modulation mode\n");
  292. return -EINVAL;
  293. }
  294. } else {
  295. ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
  296. return -EINVAL;
  297. }
  298. if (flags & CHANNEL_TURBO)
  299. turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
  300. } else { /* Reset the device */
  301. /* ...enable Atheros turbo mode if requested */
  302. if (flags & CHANNEL_TURBO)
  303. ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
  304. AR5K_PHY_TURBO);
  305. }
  306. /* ...reset chipset and PCI device */
  307. if (ah->ah_single_chip == false && ath5k_hw_nic_reset(ah,
  308. AR5K_RESET_CTL_CHIP | AR5K_RESET_CTL_PCI)) {
  309. ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip + PCI\n");
  310. return -EIO;
  311. }
  312. if (ah->ah_version == AR5K_AR5210)
  313. udelay(2300);
  314. /* ...wakeup again!*/
  315. ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
  316. if (ret) {
  317. ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
  318. return ret;
  319. }
  320. /* ...final warm reset */
  321. if (ath5k_hw_nic_reset(ah, 0)) {
  322. ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
  323. return -EIO;
  324. }
  325. if (ah->ah_version != AR5K_AR5210) {
  326. /* ...set the PHY operating mode */
  327. ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
  328. udelay(300);
  329. ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
  330. ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
  331. }
  332. return 0;
  333. }
  334. /*
  335. * Get the rate table for a specific operation mode
  336. */
  337. const struct ath5k_rate_table *ath5k_hw_get_rate_table(struct ath5k_hw *ah,
  338. unsigned int mode)
  339. {
  340. ATH5K_TRACE(ah->ah_sc);
  341. if (!test_bit(mode, ah->ah_capabilities.cap_mode))
  342. return NULL;
  343. /* Get rate tables */
  344. switch (mode) {
  345. case MODE_IEEE80211A:
  346. return &ath5k_rt_11a;
  347. case MODE_ATHEROS_TURBO:
  348. return &ath5k_rt_turbo;
  349. case MODE_IEEE80211B:
  350. return &ath5k_rt_11b;
  351. case MODE_IEEE80211G:
  352. return &ath5k_rt_11g;
  353. case MODE_ATHEROS_TURBOG:
  354. return &ath5k_rt_xr;
  355. }
  356. return NULL;
  357. }
  358. /*
  359. * Free the ath5k_hw struct
  360. */
  361. void ath5k_hw_detach(struct ath5k_hw *ah)
  362. {
  363. ATH5K_TRACE(ah->ah_sc);
  364. if (ah->ah_rf_banks != NULL)
  365. kfree(ah->ah_rf_banks);
  366. /* assume interrupts are down */
  367. kfree(ah);
  368. }
  369. /****************************\
  370. Reset function and helpers
  371. \****************************/
  372. /**
  373. * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
  374. *
  375. * @ah: the &struct ath5k_hw
  376. * @channel: the currently set channel upon reset
  377. *
  378. * Write the OFDM timings for the AR5212 upon reset. This is a helper for
  379. * ath5k_hw_reset(). This seems to tune the PLL a specified frequency
  380. * depending on the bandwidth of the channel.
  381. *
  382. */
  383. static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
  384. struct ieee80211_channel *channel)
  385. {
  386. /* Get exponent and mantissa and set it */
  387. u32 coef_scaled, coef_exp, coef_man,
  388. ds_coef_exp, ds_coef_man, clock;
  389. if (!(ah->ah_version == AR5K_AR5212) ||
  390. !(channel->val & CHANNEL_OFDM))
  391. BUG();
  392. /* Seems there are two PLLs, one for baseband sampling and one
  393. * for tuning. Tuning basebands are 40 MHz or 80MHz when in
  394. * turbo. */
  395. clock = channel->val & CHANNEL_TURBO ? 80 : 40;
  396. coef_scaled = ((5 * (clock << 24)) / 2) /
  397. channel->freq;
  398. for (coef_exp = 31; coef_exp > 0; coef_exp--)
  399. if ((coef_scaled >> coef_exp) & 0x1)
  400. break;
  401. if (!coef_exp)
  402. return -EINVAL;
  403. coef_exp = 14 - (coef_exp - 24);
  404. coef_man = coef_scaled +
  405. (1 << (24 - coef_exp - 1));
  406. ds_coef_man = coef_man >> (24 - coef_exp);
  407. ds_coef_exp = coef_exp - 16;
  408. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  409. AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
  410. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
  411. AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
  412. return 0;
  413. }
  414. /**
  415. * ath5k_hw_write_rate_duration - set rate duration during hw resets
  416. *
  417. * @ah: the &struct ath5k_hw
  418. * @driver_mode: one of enum ieee80211_phymode or our one of our own
  419. * vendor modes
  420. *
  421. * Write the rate duration table for the current mode upon hw reset. This
  422. * is a helper for ath5k_hw_reset(). It seems all this is doing is setting
  423. * an ACK timeout for the hardware for the current mode for each rate. The
  424. * rates which are capable of short preamble (802.11b rates 2Mbps, 5.5Mbps,
  425. * and 11Mbps) have another register for the short preamble ACK timeout
  426. * calculation.
  427. *
  428. */
  429. static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
  430. unsigned int driver_mode)
  431. {
  432. struct ath5k_softc *sc = ah->ah_sc;
  433. const struct ath5k_rate_table *rt;
  434. unsigned int i;
  435. /* Get rate table for the current operating mode */
  436. rt = ath5k_hw_get_rate_table(ah,
  437. driver_mode);
  438. /* Write rate duration table */
  439. for (i = 0; i < rt->rate_count; i++) {
  440. const struct ath5k_rate *rate, *control_rate;
  441. u32 reg;
  442. u16 tx_time;
  443. rate = &rt->rates[i];
  444. control_rate = &rt->rates[rate->control_rate];
  445. /* Set ACK timeout */
  446. reg = AR5K_RATE_DUR(rate->rate_code);
  447. /* An ACK frame consists of 10 bytes. If you add the FCS,
  448. * which ieee80211_generic_frame_duration() adds,
  449. * its 14 bytes. Note we use the control rate and not the
  450. * actual rate for this rate. See mac80211 tx.c
  451. * ieee80211_duration() for a brief description of
  452. * what rate we should choose to TX ACKs. */
  453. tx_time = ieee80211_generic_frame_duration(sc->hw,
  454. sc->vif, 10, control_rate->rate_kbps/100);
  455. ath5k_hw_reg_write(ah, tx_time, reg);
  456. if (!HAS_SHPREAMBLE(i))
  457. continue;
  458. /*
  459. * We're not distinguishing short preamble here,
  460. * This is true, all we'll get is a longer value here
  461. * which is not necessarilly bad. We could use
  462. * export ieee80211_frame_duration() but that needs to be
  463. * fixed first to be properly used by mac802111 drivers:
  464. *
  465. * - remove erp stuff and let the routine figure ofdm
  466. * erp rates
  467. * - remove passing argument ieee80211_local as
  468. * drivers don't have access to it
  469. * - move drivers using ieee80211_generic_frame_duration()
  470. * to this
  471. */
  472. ath5k_hw_reg_write(ah, tx_time,
  473. reg + (AR5K_SET_SHORT_PREAMBLE << 2));
  474. }
  475. }
  476. /*
  477. * Main reset function
  478. */
  479. int ath5k_hw_reset(struct ath5k_hw *ah, enum ieee80211_if_types op_mode,
  480. struct ieee80211_channel *channel, bool change_channel)
  481. {
  482. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  483. u32 data, s_seq, s_ant, s_led[3];
  484. unsigned int i, mode, freq, ee_mode, ant[2], driver_mode = -1;
  485. int ret;
  486. ATH5K_TRACE(ah->ah_sc);
  487. s_seq = 0;
  488. s_ant = 0;
  489. ee_mode = 0;
  490. freq = 0;
  491. mode = 0;
  492. /*
  493. * Save some registers before a reset
  494. */
  495. /*DCU/Antenna selection not available on 5210*/
  496. if (ah->ah_version != AR5K_AR5210) {
  497. if (change_channel == true) {
  498. /* Seq number for queue 0 -do this for all queues ? */
  499. s_seq = ath5k_hw_reg_read(ah,
  500. AR5K_QUEUE_DFS_SEQNUM(0));
  501. /*Default antenna*/
  502. s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
  503. }
  504. }
  505. /*GPIOs*/
  506. s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) & AR5K_PCICFG_LEDSTATE;
  507. s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
  508. s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  509. if (change_channel == true && ah->ah_rf_banks != NULL)
  510. ath5k_hw_get_rf_gain(ah);
  511. /*Wakeup the device*/
  512. ret = ath5k_hw_nic_wakeup(ah, channel->val, false);
  513. if (ret)
  514. return ret;
  515. /*
  516. * Initialize operating mode
  517. */
  518. ah->ah_op_mode = op_mode;
  519. /*
  520. * 5111/5112 Settings
  521. * 5210 only comes with RF5110
  522. */
  523. if (ah->ah_version != AR5K_AR5210) {
  524. if (ah->ah_radio != AR5K_RF5111 &&
  525. ah->ah_radio != AR5K_RF5112 &&
  526. ah->ah_radio != AR5K_RF5413) {
  527. ATH5K_ERR(ah->ah_sc,
  528. "invalid phy radio: %u\n", ah->ah_radio);
  529. return -EINVAL;
  530. }
  531. switch (channel->val & CHANNEL_MODES) {
  532. case CHANNEL_A:
  533. mode = AR5K_INI_VAL_11A;
  534. freq = AR5K_INI_RFGAIN_5GHZ;
  535. ee_mode = AR5K_EEPROM_MODE_11A;
  536. driver_mode = MODE_IEEE80211A;
  537. break;
  538. case CHANNEL_G:
  539. mode = AR5K_INI_VAL_11G;
  540. freq = AR5K_INI_RFGAIN_2GHZ;
  541. ee_mode = AR5K_EEPROM_MODE_11G;
  542. driver_mode = MODE_IEEE80211G;
  543. break;
  544. case CHANNEL_B:
  545. mode = AR5K_INI_VAL_11B;
  546. freq = AR5K_INI_RFGAIN_2GHZ;
  547. ee_mode = AR5K_EEPROM_MODE_11B;
  548. driver_mode = MODE_IEEE80211B;
  549. break;
  550. case CHANNEL_T:
  551. mode = AR5K_INI_VAL_11A_TURBO;
  552. freq = AR5K_INI_RFGAIN_5GHZ;
  553. ee_mode = AR5K_EEPROM_MODE_11A;
  554. driver_mode = MODE_ATHEROS_TURBO;
  555. break;
  556. /*Is this ok on 5211 too ?*/
  557. case CHANNEL_TG:
  558. mode = AR5K_INI_VAL_11G_TURBO;
  559. freq = AR5K_INI_RFGAIN_2GHZ;
  560. ee_mode = AR5K_EEPROM_MODE_11G;
  561. driver_mode = MODE_ATHEROS_TURBOG;
  562. break;
  563. case CHANNEL_XR:
  564. if (ah->ah_version == AR5K_AR5211) {
  565. ATH5K_ERR(ah->ah_sc,
  566. "XR mode not available on 5211");
  567. return -EINVAL;
  568. }
  569. mode = AR5K_INI_VAL_XR;
  570. freq = AR5K_INI_RFGAIN_5GHZ;
  571. ee_mode = AR5K_EEPROM_MODE_11A;
  572. driver_mode = MODE_IEEE80211A;
  573. break;
  574. default:
  575. ATH5K_ERR(ah->ah_sc,
  576. "invalid channel: %d\n", channel->freq);
  577. return -EINVAL;
  578. }
  579. /* PHY access enable */
  580. ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
  581. }
  582. ret = ath5k_hw_write_initvals(ah, mode, change_channel);
  583. if (ret)
  584. return ret;
  585. /*
  586. * 5211/5212 Specific
  587. */
  588. if (ah->ah_version != AR5K_AR5210) {
  589. /*
  590. * Write initial RF gain settings
  591. * This should work for both 5111/5112
  592. */
  593. ret = ath5k_hw_rfgain(ah, freq);
  594. if (ret)
  595. return ret;
  596. mdelay(1);
  597. /*
  598. * Write some more initial register settings
  599. */
  600. if (ah->ah_version > AR5K_AR5211){ /* found on 5213+ */
  601. ath5k_hw_reg_write(ah, 0x0002a002, AR5K_PHY(11));
  602. if (channel->val == CHANNEL_G)
  603. ath5k_hw_reg_write(ah, 0x00f80d80, AR5K_PHY(83)); /* 0x00fc0ec0 */
  604. else
  605. ath5k_hw_reg_write(ah, 0x00000000, AR5K_PHY(83));
  606. ath5k_hw_reg_write(ah, 0x000001b5, 0xa228); /* 0x000009b5 */
  607. ath5k_hw_reg_write(ah, 0x000009b5, 0xa228);
  608. ath5k_hw_reg_write(ah, 0x0000000f, 0x8060);
  609. ath5k_hw_reg_write(ah, 0x00000000, 0xa254);
  610. ath5k_hw_reg_write(ah, 0x0000000e, AR5K_PHY_SCAL);
  611. }
  612. /* Fix for first revision of the RF5112 RF chipset */
  613. if (ah->ah_radio >= AR5K_RF5112 &&
  614. ah->ah_radio_5ghz_revision <
  615. AR5K_SREV_RAD_5112A) {
  616. ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
  617. AR5K_PHY_CCKTXCTL);
  618. if (channel->val & CHANNEL_5GHZ)
  619. data = 0xffb81020;
  620. else
  621. data = 0xffb80d20;
  622. ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
  623. }
  624. /*
  625. * Set TX power (FIXME)
  626. */
  627. ret = ath5k_hw_txpower(ah, channel, AR5K_TUNE_DEFAULT_TXPOWER);
  628. if (ret)
  629. return ret;
  630. /* Write rate duration table only on AR5212 and if
  631. * virtual interface has already been brought up
  632. * XXX: rethink this after new mode changes to
  633. * mac80211 are integrated */
  634. if (ah->ah_version == AR5K_AR5212 &&
  635. ah->ah_sc->vif != NULL)
  636. ath5k_hw_write_rate_duration(ah, driver_mode);
  637. /*
  638. * Write RF registers
  639. * TODO:Does this work on 5211 (5111) ?
  640. */
  641. ret = ath5k_hw_rfregs(ah, channel, mode);
  642. if (ret)
  643. return ret;
  644. /*
  645. * Configure additional registers
  646. */
  647. /* Write OFDM timings on 5212*/
  648. if (ah->ah_version == AR5K_AR5212 &&
  649. channel->val & CHANNEL_OFDM) {
  650. ret = ath5k_hw_write_ofdm_timings(ah, channel);
  651. if (ret)
  652. return ret;
  653. }
  654. /*Enable/disable 802.11b mode on 5111
  655. (enable 2111 frequency converter + CCK)*/
  656. if (ah->ah_radio == AR5K_RF5111) {
  657. if (driver_mode == MODE_IEEE80211B)
  658. AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
  659. AR5K_TXCFG_B_MODE);
  660. else
  661. AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
  662. AR5K_TXCFG_B_MODE);
  663. }
  664. /*
  665. * Set channel and calibrate the PHY
  666. */
  667. ret = ath5k_hw_channel(ah, channel);
  668. if (ret)
  669. return ret;
  670. /* Set antenna mode */
  671. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x44),
  672. ah->ah_antenna[ee_mode][0], 0xfffffc06);
  673. /*
  674. * In case a fixed antenna was set as default
  675. * write the same settings on both AR5K_PHY_ANT_SWITCH_TABLE
  676. * registers.
  677. */
  678. if (s_ant != 0){
  679. if (s_ant == AR5K_ANT_FIXED_A) /* 1 - Main */
  680. ant[0] = ant[1] = AR5K_ANT_FIXED_A;
  681. else /* 2 - Aux */
  682. ant[0] = ant[1] = AR5K_ANT_FIXED_B;
  683. } else {
  684. ant[0] = AR5K_ANT_FIXED_A;
  685. ant[1] = AR5K_ANT_FIXED_B;
  686. }
  687. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[0]],
  688. AR5K_PHY_ANT_SWITCH_TABLE_0);
  689. ath5k_hw_reg_write(ah, ah->ah_antenna[ee_mode][ant[1]],
  690. AR5K_PHY_ANT_SWITCH_TABLE_1);
  691. /* Commit values from EEPROM */
  692. if (ah->ah_radio == AR5K_RF5111)
  693. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_FRAME_CTL,
  694. AR5K_PHY_FRAME_CTL_TX_CLIP, ee->ee_tx_clip);
  695. ath5k_hw_reg_write(ah,
  696. AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
  697. AR5K_PHY(0x5a));
  698. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x11),
  699. (ee->ee_switch_settling[ee_mode] << 7) & 0x3f80,
  700. 0xffffc07f);
  701. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x12),
  702. (ee->ee_ant_tx_rx[ee_mode] << 12) & 0x3f000,
  703. 0xfffc0fff);
  704. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x14),
  705. (ee->ee_adc_desired_size[ee_mode] & 0x00ff) |
  706. ((ee->ee_pga_desired_size[ee_mode] << 8) & 0xff00),
  707. 0xffff0000);
  708. ath5k_hw_reg_write(ah,
  709. (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
  710. (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
  711. (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
  712. (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY(0x0d));
  713. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x0a),
  714. ee->ee_tx_end2xlna_enable[ee_mode] << 8, 0xffff00ff);
  715. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x19),
  716. (ee->ee_thr_62[ee_mode] << 12) & 0x7f000, 0xfff80fff);
  717. AR5K_REG_MASKED_BITS(ah, AR5K_PHY(0x49), 4, 0xffffff01);
  718. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  719. AR5K_PHY_IQ_CORR_ENABLE |
  720. (ee->ee_i_cal[ee_mode] << AR5K_PHY_IQ_CORR_Q_I_COFF_S) |
  721. ee->ee_q_cal[ee_mode]);
  722. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  723. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
  724. AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
  725. ee->ee_margin_tx_rx[ee_mode]);
  726. } else {
  727. mdelay(1);
  728. /* Disable phy and wait */
  729. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
  730. mdelay(1);
  731. }
  732. /*
  733. * Restore saved values
  734. */
  735. /*DCU/Antenna selection not available on 5210*/
  736. if (ah->ah_version != AR5K_AR5210) {
  737. ath5k_hw_reg_write(ah, s_seq, AR5K_QUEUE_DFS_SEQNUM(0));
  738. ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
  739. }
  740. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
  741. ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
  742. ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
  743. /*
  744. * Misc
  745. */
  746. /* XXX: add ah->aid once mac80211 gives this to us */
  747. ath5k_hw_set_associd(ah, ah->ah_bssid, 0);
  748. ath5k_hw_set_opmode(ah);
  749. /*PISR/SISR Not available on 5210*/
  750. if (ah->ah_version != AR5K_AR5210) {
  751. ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
  752. /* If we later allow tuning for this, store into sc structure */
  753. data = AR5K_TUNE_RSSI_THRES |
  754. AR5K_TUNE_BMISS_THRES << AR5K_RSSI_THR_BMISS_S;
  755. ath5k_hw_reg_write(ah, data, AR5K_RSSI_THR);
  756. }
  757. /*
  758. * Set Rx/Tx DMA Configuration
  759. *(passing dma size not available on 5210)
  760. */
  761. if (ah->ah_version != AR5K_AR5210) {
  762. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG, AR5K_TXCFG_SDMAMR,
  763. AR5K_DMASIZE_512B | AR5K_TXCFG_DMASIZE);
  764. AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_SDMAMW,
  765. AR5K_DMASIZE_512B);
  766. }
  767. /*
  768. * Enable the PHY and wait until completion
  769. */
  770. ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
  771. /*
  772. * 5111/5112 Specific
  773. */
  774. if (ah->ah_version != AR5K_AR5210) {
  775. data = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
  776. AR5K_PHY_RX_DELAY_M;
  777. data = (channel->val & CHANNEL_CCK) ?
  778. ((data << 2) / 22) : (data / 10);
  779. udelay(100 + data);
  780. } else {
  781. mdelay(1);
  782. }
  783. /*
  784. * Enable calibration and wait until completion
  785. */
  786. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
  787. AR5K_PHY_AGCCTL_CAL);
  788. if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
  789. AR5K_PHY_AGCCTL_CAL, 0, false)) {
  790. ATH5K_ERR(ah->ah_sc, "calibration timeout (%uMHz)\n",
  791. channel->freq);
  792. return -EAGAIN;
  793. }
  794. ret = ath5k_hw_noise_floor_calibration(ah, channel->freq);
  795. if (ret)
  796. return ret;
  797. ah->ah_calibration = false;
  798. /* A and G modes can use QAM modulation which requires enabling
  799. * I and Q calibration. Don't bother in B mode. */
  800. if (!(driver_mode == MODE_IEEE80211B)) {
  801. ah->ah_calibration = true;
  802. AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
  803. AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
  804. AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
  805. AR5K_PHY_IQ_RUN);
  806. }
  807. /*
  808. * Reset queues and start beacon timers at the end of the reset routine
  809. */
  810. for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
  811. /*No QCU on 5210*/
  812. if (ah->ah_version != AR5K_AR5210)
  813. AR5K_REG_WRITE_Q(ah, AR5K_QUEUE_QCUMASK(i), i);
  814. ret = ath5k_hw_reset_tx_queue(ah, i);
  815. if (ret) {
  816. ATH5K_ERR(ah->ah_sc,
  817. "failed to reset TX queue #%d\n", i);
  818. return ret;
  819. }
  820. }
  821. /* Pre-enable interrupts on 5211/5212*/
  822. if (ah->ah_version != AR5K_AR5210)
  823. ath5k_hw_set_intr(ah, AR5K_INT_RX | AR5K_INT_TX |
  824. AR5K_INT_FATAL);
  825. /*
  826. * Set RF kill flags if supported by the device (read from the EEPROM)
  827. * Disable gpio_intr for now since it results system hang.
  828. * TODO: Handle this in ath5k_intr
  829. */
  830. #if 0
  831. if (AR5K_EEPROM_HDR_RFKILL(ah->ah_capabilities.cap_eeprom.ee_header)) {
  832. ath5k_hw_set_gpio_input(ah, 0);
  833. ah->ah_gpio[0] = ath5k_hw_get_gpio(ah, 0);
  834. if (ah->ah_gpio[0] == 0)
  835. ath5k_hw_set_gpio_intr(ah, 0, 1);
  836. else
  837. ath5k_hw_set_gpio_intr(ah, 0, 0);
  838. }
  839. #endif
  840. /*
  841. * Set the 32MHz reference clock on 5212 phy clock sleep register
  842. */
  843. if (ah->ah_version == AR5K_AR5212) {
  844. ath5k_hw_reg_write(ah, AR5K_PHY_SCR_32MHZ, AR5K_PHY_SCR);
  845. ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
  846. ath5k_hw_reg_write(ah, AR5K_PHY_SCAL_32MHZ, AR5K_PHY_SCAL);
  847. ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
  848. ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
  849. ath5k_hw_reg_write(ah, ah->ah_radio == AR5K_RF5111 ?
  850. AR5K_PHY_SPENDING_RF5111 : AR5K_PHY_SPENDING_RF5112,
  851. AR5K_PHY_SPENDING);
  852. }
  853. /*
  854. * Disable beacons and reset the register
  855. */
  856. AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE |
  857. AR5K_BEACON_RESET_TSF);
  858. return 0;
  859. }
  860. /*
  861. * Reset chipset
  862. */
  863. static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
  864. {
  865. int ret;
  866. u32 mask = val ? val : ~0U;
  867. ATH5K_TRACE(ah->ah_sc);
  868. /* Read-and-clear RX Descriptor Pointer*/
  869. ath5k_hw_reg_read(ah, AR5K_RXDP);
  870. /*
  871. * Reset the device and wait until success
  872. */
  873. ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
  874. /* Wait at least 128 PCI clocks */
  875. udelay(15);
  876. if (ah->ah_version == AR5K_AR5210) {
  877. val &= AR5K_RESET_CTL_CHIP;
  878. mask &= AR5K_RESET_CTL_CHIP;
  879. } else {
  880. val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  881. mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
  882. }
  883. ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
  884. /*
  885. * Reset configuration register (for hw byte-swap). Note that this
  886. * is only set for big endian. We do the necessary magic in
  887. * AR5K_INIT_CFG.
  888. */
  889. if ((val & AR5K_RESET_CTL_PCU) == 0)
  890. ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
  891. return ret;
  892. }
  893. /*
  894. * Power management functions
  895. */
  896. /*
  897. * Sleep control
  898. */
  899. int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
  900. bool set_chip, u16 sleep_duration)
  901. {
  902. unsigned int i;
  903. u32 staid;
  904. ATH5K_TRACE(ah->ah_sc);
  905. staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
  906. switch (mode) {
  907. case AR5K_PM_AUTO:
  908. staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
  909. /* fallthrough */
  910. case AR5K_PM_NETWORK_SLEEP:
  911. if (set_chip == true)
  912. ath5k_hw_reg_write(ah,
  913. AR5K_SLEEP_CTL_SLE | sleep_duration,
  914. AR5K_SLEEP_CTL);
  915. staid |= AR5K_STA_ID1_PWR_SV;
  916. break;
  917. case AR5K_PM_FULL_SLEEP:
  918. if (set_chip == true)
  919. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
  920. AR5K_SLEEP_CTL);
  921. staid |= AR5K_STA_ID1_PWR_SV;
  922. break;
  923. case AR5K_PM_AWAKE:
  924. if (set_chip == false)
  925. goto commit;
  926. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
  927. AR5K_SLEEP_CTL);
  928. for (i = 5000; i > 0; i--) {
  929. /* Check if the chip did wake up */
  930. if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
  931. AR5K_PCICFG_SPWR_DN) == 0)
  932. break;
  933. /* Wait a bit and retry */
  934. udelay(200);
  935. ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_WAKE,
  936. AR5K_SLEEP_CTL);
  937. }
  938. /* Fail if the chip didn't wake up */
  939. if (i <= 0)
  940. return -EIO;
  941. staid &= ~AR5K_STA_ID1_PWR_SV;
  942. break;
  943. default:
  944. return -EINVAL;
  945. }
  946. commit:
  947. ah->ah_power_mode = mode;
  948. ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
  949. return 0;
  950. }
  951. /***********************\
  952. DMA Related Functions
  953. \***********************/
  954. /*
  955. * Receive functions
  956. */
  957. /*
  958. * Start DMA receive
  959. */
  960. void ath5k_hw_start_rx(struct ath5k_hw *ah)
  961. {
  962. ATH5K_TRACE(ah->ah_sc);
  963. ath5k_hw_reg_write(ah, AR5K_CR_RXE, AR5K_CR);
  964. }
  965. /*
  966. * Stop DMA receive
  967. */
  968. int ath5k_hw_stop_rx_dma(struct ath5k_hw *ah)
  969. {
  970. unsigned int i;
  971. ATH5K_TRACE(ah->ah_sc);
  972. ath5k_hw_reg_write(ah, AR5K_CR_RXD, AR5K_CR);
  973. /*
  974. * It may take some time to disable the DMA receive unit
  975. */
  976. for (i = 2000; i > 0 &&
  977. (ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_CR_RXE) != 0;
  978. i--)
  979. udelay(10);
  980. return i ? 0 : -EBUSY;
  981. }
  982. /*
  983. * Get the address of the RX Descriptor
  984. */
  985. u32 ath5k_hw_get_rx_buf(struct ath5k_hw *ah)
  986. {
  987. return ath5k_hw_reg_read(ah, AR5K_RXDP);
  988. }
  989. /*
  990. * Set the address of the RX Descriptor
  991. */
  992. void ath5k_hw_put_rx_buf(struct ath5k_hw *ah, u32 phys_addr)
  993. {
  994. ATH5K_TRACE(ah->ah_sc);
  995. /*TODO:Shouldn't we check if RX is enabled first ?*/
  996. ath5k_hw_reg_write(ah, phys_addr, AR5K_RXDP);
  997. }
  998. /*
  999. * Transmit functions
  1000. */
  1001. /*
  1002. * Start DMA transmit for a specific queue
  1003. * (see also QCU/DCU functions)
  1004. */
  1005. int ath5k_hw_tx_start(struct ath5k_hw *ah, unsigned int queue)
  1006. {
  1007. u32 tx_queue;
  1008. ATH5K_TRACE(ah->ah_sc);
  1009. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1010. /* Return if queue is declared inactive */
  1011. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  1012. return -EIO;
  1013. if (ah->ah_version == AR5K_AR5210) {
  1014. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  1015. /*
  1016. * Set the queue by type on 5210
  1017. */
  1018. switch (ah->ah_txq[queue].tqi_type) {
  1019. case AR5K_TX_QUEUE_DATA:
  1020. tx_queue |= AR5K_CR_TXE0 & ~AR5K_CR_TXD0;
  1021. break;
  1022. case AR5K_TX_QUEUE_BEACON:
  1023. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  1024. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  1025. AR5K_BSR);
  1026. break;
  1027. case AR5K_TX_QUEUE_CAB:
  1028. tx_queue |= AR5K_CR_TXE1 & ~AR5K_CR_TXD1;
  1029. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1FV | AR5K_BCR_TQ1V |
  1030. AR5K_BCR_BDMAE, AR5K_BSR);
  1031. break;
  1032. default:
  1033. return -EINVAL;
  1034. }
  1035. /* Start queue */
  1036. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  1037. } else {
  1038. /* Return if queue is disabled */
  1039. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXD, queue))
  1040. return -EIO;
  1041. /* Start queue */
  1042. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXE, queue);
  1043. }
  1044. return 0;
  1045. }
  1046. /*
  1047. * Stop DMA transmit for a specific queue
  1048. * (see also QCU/DCU functions)
  1049. */
  1050. int ath5k_hw_stop_tx_dma(struct ath5k_hw *ah, unsigned int queue)
  1051. {
  1052. unsigned int i = 100;
  1053. u32 tx_queue, pending;
  1054. ATH5K_TRACE(ah->ah_sc);
  1055. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1056. /* Return if queue is declared inactive */
  1057. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  1058. return -EIO;
  1059. if (ah->ah_version == AR5K_AR5210) {
  1060. tx_queue = ath5k_hw_reg_read(ah, AR5K_CR);
  1061. /*
  1062. * Set by queue type
  1063. */
  1064. switch (ah->ah_txq[queue].tqi_type) {
  1065. case AR5K_TX_QUEUE_DATA:
  1066. tx_queue |= AR5K_CR_TXD0 & ~AR5K_CR_TXE0;
  1067. break;
  1068. case AR5K_TX_QUEUE_BEACON:
  1069. case AR5K_TX_QUEUE_CAB:
  1070. /* XXX Fix me... */
  1071. tx_queue |= AR5K_CR_TXD1 & ~AR5K_CR_TXD1;
  1072. ath5k_hw_reg_write(ah, 0, AR5K_BSR);
  1073. break;
  1074. default:
  1075. return -EINVAL;
  1076. }
  1077. /* Stop queue */
  1078. ath5k_hw_reg_write(ah, tx_queue, AR5K_CR);
  1079. } else {
  1080. /*
  1081. * Schedule TX disable and wait until queue is empty
  1082. */
  1083. AR5K_REG_WRITE_Q(ah, AR5K_QCU_TXD, queue);
  1084. /*Check for pending frames*/
  1085. do {
  1086. pending = ath5k_hw_reg_read(ah,
  1087. AR5K_QUEUE_STATUS(queue)) &
  1088. AR5K_QCU_STS_FRMPENDCNT;
  1089. udelay(100);
  1090. } while (--i && pending);
  1091. /* Clear register */
  1092. ath5k_hw_reg_write(ah, 0, AR5K_QCU_TXD);
  1093. }
  1094. /* TODO: Check for success else return error */
  1095. return 0;
  1096. }
  1097. /*
  1098. * Get the address of the TX Descriptor for a specific queue
  1099. * (see also QCU/DCU functions)
  1100. */
  1101. u32 ath5k_hw_get_tx_buf(struct ath5k_hw *ah, unsigned int queue)
  1102. {
  1103. u16 tx_reg;
  1104. ATH5K_TRACE(ah->ah_sc);
  1105. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1106. /*
  1107. * Get the transmit queue descriptor pointer from the selected queue
  1108. */
  1109. /*5210 doesn't have QCU*/
  1110. if (ah->ah_version == AR5K_AR5210) {
  1111. switch (ah->ah_txq[queue].tqi_type) {
  1112. case AR5K_TX_QUEUE_DATA:
  1113. tx_reg = AR5K_NOQCU_TXDP0;
  1114. break;
  1115. case AR5K_TX_QUEUE_BEACON:
  1116. case AR5K_TX_QUEUE_CAB:
  1117. tx_reg = AR5K_NOQCU_TXDP1;
  1118. break;
  1119. default:
  1120. return 0xffffffff;
  1121. }
  1122. } else {
  1123. tx_reg = AR5K_QUEUE_TXDP(queue);
  1124. }
  1125. return ath5k_hw_reg_read(ah, tx_reg);
  1126. }
  1127. /*
  1128. * Set the address of the TX Descriptor for a specific queue
  1129. * (see also QCU/DCU functions)
  1130. */
  1131. int ath5k_hw_put_tx_buf(struct ath5k_hw *ah, unsigned int queue, u32 phys_addr)
  1132. {
  1133. u16 tx_reg;
  1134. ATH5K_TRACE(ah->ah_sc);
  1135. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  1136. /*
  1137. * Set the transmit queue descriptor pointer register by type
  1138. * on 5210
  1139. */
  1140. if (ah->ah_version == AR5K_AR5210) {
  1141. switch (ah->ah_txq[queue].tqi_type) {
  1142. case AR5K_TX_QUEUE_DATA:
  1143. tx_reg = AR5K_NOQCU_TXDP0;
  1144. break;
  1145. case AR5K_TX_QUEUE_BEACON:
  1146. case AR5K_TX_QUEUE_CAB:
  1147. tx_reg = AR5K_NOQCU_TXDP1;
  1148. break;
  1149. default:
  1150. return -EINVAL;
  1151. }
  1152. } else {
  1153. /*
  1154. * Set the transmit queue descriptor pointer for
  1155. * the selected queue on QCU for 5211+
  1156. * (this won't work if the queue is still active)
  1157. */
  1158. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, queue))
  1159. return -EIO;
  1160. tx_reg = AR5K_QUEUE_TXDP(queue);
  1161. }
  1162. /* Set descriptor pointer */
  1163. ath5k_hw_reg_write(ah, phys_addr, tx_reg);
  1164. return 0;
  1165. }
  1166. /*
  1167. * Update tx trigger level
  1168. */
  1169. int ath5k_hw_update_tx_triglevel(struct ath5k_hw *ah, bool increase)
  1170. {
  1171. u32 trigger_level, imr;
  1172. int ret = -EIO;
  1173. ATH5K_TRACE(ah->ah_sc);
  1174. /*
  1175. * Disable interrupts by setting the mask
  1176. */
  1177. imr = ath5k_hw_set_intr(ah, ah->ah_imr & ~AR5K_INT_GLOBAL);
  1178. /*TODO: Boundary check on trigger_level*/
  1179. trigger_level = AR5K_REG_MS(ath5k_hw_reg_read(ah, AR5K_TXCFG),
  1180. AR5K_TXCFG_TXFULL);
  1181. if (increase == false) {
  1182. if (--trigger_level < AR5K_TUNE_MIN_TX_FIFO_THRES)
  1183. goto done;
  1184. } else
  1185. trigger_level +=
  1186. ((AR5K_TUNE_MAX_TX_FIFO_THRES - trigger_level) / 2);
  1187. /*
  1188. * Update trigger level on success
  1189. */
  1190. if (ah->ah_version == AR5K_AR5210)
  1191. ath5k_hw_reg_write(ah, trigger_level, AR5K_TRIG_LVL);
  1192. else
  1193. AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
  1194. AR5K_TXCFG_TXFULL, trigger_level);
  1195. ret = 0;
  1196. done:
  1197. /*
  1198. * Restore interrupt mask
  1199. */
  1200. ath5k_hw_set_intr(ah, imr);
  1201. return ret;
  1202. }
  1203. /*
  1204. * Interrupt handling
  1205. */
  1206. /*
  1207. * Check if we have pending interrupts
  1208. */
  1209. bool ath5k_hw_is_intr_pending(struct ath5k_hw *ah)
  1210. {
  1211. ATH5K_TRACE(ah->ah_sc);
  1212. return ath5k_hw_reg_read(ah, AR5K_INTPEND);
  1213. }
  1214. /*
  1215. * Get interrupt mask (ISR)
  1216. */
  1217. int ath5k_hw_get_isr(struct ath5k_hw *ah, enum ath5k_int *interrupt_mask)
  1218. {
  1219. u32 data;
  1220. ATH5K_TRACE(ah->ah_sc);
  1221. /*
  1222. * Read interrupt status from the Interrupt Status register
  1223. * on 5210
  1224. */
  1225. if (ah->ah_version == AR5K_AR5210) {
  1226. data = ath5k_hw_reg_read(ah, AR5K_ISR);
  1227. if (unlikely(data == AR5K_INT_NOCARD)) {
  1228. *interrupt_mask = data;
  1229. return -ENODEV;
  1230. }
  1231. } else {
  1232. /*
  1233. * Read interrupt status from the Read-And-Clear shadow register
  1234. * Note: PISR/SISR Not available on 5210
  1235. */
  1236. data = ath5k_hw_reg_read(ah, AR5K_RAC_PISR);
  1237. }
  1238. /*
  1239. * Get abstract interrupt mask (driver-compatible)
  1240. */
  1241. *interrupt_mask = (data & AR5K_INT_COMMON) & ah->ah_imr;
  1242. if (unlikely(data == AR5K_INT_NOCARD))
  1243. return -ENODEV;
  1244. if (data & (AR5K_ISR_RXOK | AR5K_ISR_RXERR))
  1245. *interrupt_mask |= AR5K_INT_RX;
  1246. if (data & (AR5K_ISR_TXOK | AR5K_ISR_TXERR
  1247. | AR5K_ISR_TXDESC | AR5K_ISR_TXEOL))
  1248. *interrupt_mask |= AR5K_INT_TX;
  1249. if (ah->ah_version != AR5K_AR5210) {
  1250. /*HIU = Host Interface Unit (PCI etc)*/
  1251. if (unlikely(data & (AR5K_ISR_HIUERR)))
  1252. *interrupt_mask |= AR5K_INT_FATAL;
  1253. /*Beacon Not Ready*/
  1254. if (unlikely(data & (AR5K_ISR_BNR)))
  1255. *interrupt_mask |= AR5K_INT_BNR;
  1256. }
  1257. /*
  1258. * XXX: BMISS interrupts may occur after association.
  1259. * I found this on 5210 code but it needs testing. If this is
  1260. * true we should disable them before assoc and re-enable them
  1261. * after a successfull assoc + some jiffies.
  1262. */
  1263. #if 0
  1264. interrupt_mask &= ~AR5K_INT_BMISS;
  1265. #endif
  1266. /*
  1267. * In case we didn't handle anything,
  1268. * print the register value.
  1269. */
  1270. if (unlikely(*interrupt_mask == 0 && net_ratelimit()))
  1271. ATH5K_PRINTF("0x%08x\n", data);
  1272. return 0;
  1273. }
  1274. /*
  1275. * Set interrupt mask
  1276. */
  1277. enum ath5k_int ath5k_hw_set_intr(struct ath5k_hw *ah, enum ath5k_int new_mask)
  1278. {
  1279. enum ath5k_int old_mask, int_mask;
  1280. /*
  1281. * Disable card interrupts to prevent any race conditions
  1282. * (they will be re-enabled afterwards).
  1283. */
  1284. ath5k_hw_reg_write(ah, AR5K_IER_DISABLE, AR5K_IER);
  1285. old_mask = ah->ah_imr;
  1286. /*
  1287. * Add additional, chipset-dependent interrupt mask flags
  1288. * and write them to the IMR (interrupt mask register).
  1289. */
  1290. int_mask = new_mask & AR5K_INT_COMMON;
  1291. if (new_mask & AR5K_INT_RX)
  1292. int_mask |= AR5K_IMR_RXOK | AR5K_IMR_RXERR | AR5K_IMR_RXORN |
  1293. AR5K_IMR_RXDESC;
  1294. if (new_mask & AR5K_INT_TX)
  1295. int_mask |= AR5K_IMR_TXOK | AR5K_IMR_TXERR | AR5K_IMR_TXDESC |
  1296. AR5K_IMR_TXURN;
  1297. if (ah->ah_version != AR5K_AR5210) {
  1298. if (new_mask & AR5K_INT_FATAL) {
  1299. int_mask |= AR5K_IMR_HIUERR;
  1300. AR5K_REG_ENABLE_BITS(ah, AR5K_SIMR2, AR5K_SIMR2_MCABT |
  1301. AR5K_SIMR2_SSERR | AR5K_SIMR2_DPERR);
  1302. }
  1303. }
  1304. ath5k_hw_reg_write(ah, int_mask, AR5K_PIMR);
  1305. /* Store new interrupt mask */
  1306. ah->ah_imr = new_mask;
  1307. /* ..re-enable interrupts */
  1308. ath5k_hw_reg_write(ah, AR5K_IER_ENABLE, AR5K_IER);
  1309. return old_mask;
  1310. }
  1311. /*************************\
  1312. EEPROM access functions
  1313. \*************************/
  1314. /*
  1315. * Read from eeprom
  1316. */
  1317. static int ath5k_hw_eeprom_read(struct ath5k_hw *ah, u32 offset, u16 *data)
  1318. {
  1319. u32 status, timeout;
  1320. ATH5K_TRACE(ah->ah_sc);
  1321. /*
  1322. * Initialize EEPROM access
  1323. */
  1324. if (ah->ah_version == AR5K_AR5210) {
  1325. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
  1326. (void)ath5k_hw_reg_read(ah, AR5K_EEPROM_BASE + (4 * offset));
  1327. } else {
  1328. ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
  1329. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1330. AR5K_EEPROM_CMD_READ);
  1331. }
  1332. for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
  1333. status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
  1334. if (status & AR5K_EEPROM_STAT_RDDONE) {
  1335. if (status & AR5K_EEPROM_STAT_RDERR)
  1336. return -EIO;
  1337. *data = (u16)(ath5k_hw_reg_read(ah, AR5K_EEPROM_DATA) &
  1338. 0xffff);
  1339. return 0;
  1340. }
  1341. udelay(15);
  1342. }
  1343. return -ETIMEDOUT;
  1344. }
  1345. /*
  1346. * Write to eeprom - currently disabled, use at your own risk
  1347. */
  1348. static int ath5k_hw_eeprom_write(struct ath5k_hw *ah, u32 offset, u16 data)
  1349. {
  1350. #if 0
  1351. u32 status, timeout;
  1352. ATH5K_TRACE(ah->ah_sc);
  1353. /*
  1354. * Initialize eeprom access
  1355. */
  1356. if (ah->ah_version == AR5K_AR5210) {
  1357. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_EEAE);
  1358. } else {
  1359. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1360. AR5K_EEPROM_CMD_RESET);
  1361. }
  1362. /*
  1363. * Write data to data register
  1364. */
  1365. if (ah->ah_version == AR5K_AR5210) {
  1366. ath5k_hw_reg_write(ah, data, AR5K_EEPROM_BASE + (4 * offset));
  1367. } else {
  1368. ath5k_hw_reg_write(ah, offset, AR5K_EEPROM_BASE);
  1369. ath5k_hw_reg_write(ah, data, AR5K_EEPROM_DATA);
  1370. AR5K_REG_ENABLE_BITS(ah, AR5K_EEPROM_CMD,
  1371. AR5K_EEPROM_CMD_WRITE);
  1372. }
  1373. /*
  1374. * Check status
  1375. */
  1376. for (timeout = AR5K_TUNE_REGISTER_TIMEOUT; timeout > 0; timeout--) {
  1377. status = ath5k_hw_reg_read(ah, AR5K_EEPROM_STATUS);
  1378. if (status & AR5K_EEPROM_STAT_WRDONE) {
  1379. if (status & AR5K_EEPROM_STAT_WRERR)
  1380. return EIO;
  1381. return 0;
  1382. }
  1383. udelay(15);
  1384. }
  1385. #endif
  1386. ATH5K_ERR(ah->ah_sc, "EEPROM Write is disabled!");
  1387. return -EIO;
  1388. }
  1389. /*
  1390. * Translate binary channel representation in EEPROM to frequency
  1391. */
  1392. static u16 ath5k_eeprom_bin2freq(struct ath5k_hw *ah, u16 bin, unsigned int mode)
  1393. {
  1394. u16 val;
  1395. if (bin == AR5K_EEPROM_CHANNEL_DIS)
  1396. return bin;
  1397. if (mode == AR5K_EEPROM_MODE_11A) {
  1398. if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
  1399. val = (5 * bin) + 4800;
  1400. else
  1401. val = bin > 62 ? (10 * 62) + (5 * (bin - 62)) + 5100 :
  1402. (bin * 10) + 5100;
  1403. } else {
  1404. if (ah->ah_ee_version > AR5K_EEPROM_VERSION_3_2)
  1405. val = bin + 2300;
  1406. else
  1407. val = bin + 2400;
  1408. }
  1409. return val;
  1410. }
  1411. /*
  1412. * Read antenna infos from eeprom
  1413. */
  1414. static int ath5k_eeprom_read_ants(struct ath5k_hw *ah, u32 *offset,
  1415. unsigned int mode)
  1416. {
  1417. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1418. u32 o = *offset;
  1419. u16 val;
  1420. int ret, i = 0;
  1421. AR5K_EEPROM_READ(o++, val);
  1422. ee->ee_switch_settling[mode] = (val >> 8) & 0x7f;
  1423. ee->ee_ant_tx_rx[mode] = (val >> 2) & 0x3f;
  1424. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  1425. AR5K_EEPROM_READ(o++, val);
  1426. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  1427. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  1428. ee->ee_ant_control[mode][i++] = val & 0x3f;
  1429. AR5K_EEPROM_READ(o++, val);
  1430. ee->ee_ant_control[mode][i++] = (val >> 10) & 0x3f;
  1431. ee->ee_ant_control[mode][i++] = (val >> 4) & 0x3f;
  1432. ee->ee_ant_control[mode][i] = (val << 2) & 0x3f;
  1433. AR5K_EEPROM_READ(o++, val);
  1434. ee->ee_ant_control[mode][i++] |= (val >> 14) & 0x3;
  1435. ee->ee_ant_control[mode][i++] = (val >> 8) & 0x3f;
  1436. ee->ee_ant_control[mode][i++] = (val >> 2) & 0x3f;
  1437. ee->ee_ant_control[mode][i] = (val << 4) & 0x3f;
  1438. AR5K_EEPROM_READ(o++, val);
  1439. ee->ee_ant_control[mode][i++] |= (val >> 12) & 0xf;
  1440. ee->ee_ant_control[mode][i++] = (val >> 6) & 0x3f;
  1441. ee->ee_ant_control[mode][i++] = val & 0x3f;
  1442. /* Get antenna modes */
  1443. ah->ah_antenna[mode][0] =
  1444. (ee->ee_ant_control[mode][0] << 4) | 0x1;
  1445. ah->ah_antenna[mode][AR5K_ANT_FIXED_A] =
  1446. ee->ee_ant_control[mode][1] |
  1447. (ee->ee_ant_control[mode][2] << 6) |
  1448. (ee->ee_ant_control[mode][3] << 12) |
  1449. (ee->ee_ant_control[mode][4] << 18) |
  1450. (ee->ee_ant_control[mode][5] << 24);
  1451. ah->ah_antenna[mode][AR5K_ANT_FIXED_B] =
  1452. ee->ee_ant_control[mode][6] |
  1453. (ee->ee_ant_control[mode][7] << 6) |
  1454. (ee->ee_ant_control[mode][8] << 12) |
  1455. (ee->ee_ant_control[mode][9] << 18) |
  1456. (ee->ee_ant_control[mode][10] << 24);
  1457. /* return new offset */
  1458. *offset = o;
  1459. return 0;
  1460. }
  1461. /*
  1462. * Read supported modes from eeprom
  1463. */
  1464. static int ath5k_eeprom_read_modes(struct ath5k_hw *ah, u32 *offset,
  1465. unsigned int mode)
  1466. {
  1467. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1468. u32 o = *offset;
  1469. u16 val;
  1470. int ret;
  1471. AR5K_EEPROM_READ(o++, val);
  1472. ee->ee_tx_end2xlna_enable[mode] = (val >> 8) & 0xff;
  1473. ee->ee_thr_62[mode] = val & 0xff;
  1474. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  1475. ee->ee_thr_62[mode] = mode == AR5K_EEPROM_MODE_11A ? 15 : 28;
  1476. AR5K_EEPROM_READ(o++, val);
  1477. ee->ee_tx_end2xpa_disable[mode] = (val >> 8) & 0xff;
  1478. ee->ee_tx_frm2xpa_enable[mode] = val & 0xff;
  1479. AR5K_EEPROM_READ(o++, val);
  1480. ee->ee_pga_desired_size[mode] = (val >> 8) & 0xff;
  1481. if ((val & 0xff) & 0x80)
  1482. ee->ee_noise_floor_thr[mode] = -((((val & 0xff) ^ 0xff)) + 1);
  1483. else
  1484. ee->ee_noise_floor_thr[mode] = val & 0xff;
  1485. if (ah->ah_ee_version <= AR5K_EEPROM_VERSION_3_2)
  1486. ee->ee_noise_floor_thr[mode] =
  1487. mode == AR5K_EEPROM_MODE_11A ? -54 : -1;
  1488. AR5K_EEPROM_READ(o++, val);
  1489. ee->ee_xlna_gain[mode] = (val >> 5) & 0xff;
  1490. ee->ee_x_gain[mode] = (val >> 1) & 0xf;
  1491. ee->ee_xpd[mode] = val & 0x1;
  1492. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0)
  1493. ee->ee_fixed_bias[mode] = (val >> 13) & 0x1;
  1494. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_3_3) {
  1495. AR5K_EEPROM_READ(o++, val);
  1496. ee->ee_false_detect[mode] = (val >> 6) & 0x7f;
  1497. if (mode == AR5K_EEPROM_MODE_11A)
  1498. ee->ee_xr_power[mode] = val & 0x3f;
  1499. else {
  1500. ee->ee_ob[mode][0] = val & 0x7;
  1501. ee->ee_db[mode][0] = (val >> 3) & 0x7;
  1502. }
  1503. }
  1504. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_4) {
  1505. ee->ee_i_gain[mode] = AR5K_EEPROM_I_GAIN;
  1506. ee->ee_cck_ofdm_power_delta = AR5K_EEPROM_CCK_OFDM_DELTA;
  1507. } else {
  1508. ee->ee_i_gain[mode] = (val >> 13) & 0x7;
  1509. AR5K_EEPROM_READ(o++, val);
  1510. ee->ee_i_gain[mode] |= (val << 3) & 0x38;
  1511. if (mode == AR5K_EEPROM_MODE_11G)
  1512. ee->ee_cck_ofdm_power_delta = (val >> 3) & 0xff;
  1513. }
  1514. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0 &&
  1515. mode == AR5K_EEPROM_MODE_11A) {
  1516. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  1517. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  1518. }
  1519. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_6 &&
  1520. mode == AR5K_EEPROM_MODE_11G)
  1521. ee->ee_scaled_cck_delta = (val >> 11) & 0x1f;
  1522. /* return new offset */
  1523. *offset = o;
  1524. return 0;
  1525. }
  1526. /*
  1527. * Initialize eeprom & capabilities structs
  1528. */
  1529. static int ath5k_eeprom_init(struct ath5k_hw *ah)
  1530. {
  1531. struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
  1532. unsigned int mode, i;
  1533. int ret;
  1534. u32 offset;
  1535. u16 val;
  1536. /* Initial TX thermal adjustment values */
  1537. ee->ee_tx_clip = 4;
  1538. ee->ee_pwd_84 = ee->ee_pwd_90 = 1;
  1539. ee->ee_gain_select = 1;
  1540. /*
  1541. * Read values from EEPROM and store them in the capability structure
  1542. */
  1543. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MAGIC, ee_magic);
  1544. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_PROTECT, ee_protect);
  1545. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_REG_DOMAIN, ee_regdomain);
  1546. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_VERSION, ee_version);
  1547. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_HDR, ee_header);
  1548. /* Return if we have an old EEPROM */
  1549. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_0)
  1550. return 0;
  1551. #ifdef notyet
  1552. /*
  1553. * Validate the checksum of the EEPROM date. There are some
  1554. * devices with invalid EEPROMs.
  1555. */
  1556. for (cksum = 0, offset = 0; offset < AR5K_EEPROM_INFO_MAX; offset++) {
  1557. AR5K_EEPROM_READ(AR5K_EEPROM_INFO(offset), val);
  1558. cksum ^= val;
  1559. }
  1560. if (cksum != AR5K_EEPROM_INFO_CKSUM) {
  1561. ATH5K_ERR(ah->ah_sc, "Invalid EEPROM checksum 0x%04x\n", cksum);
  1562. return -EIO;
  1563. }
  1564. #endif
  1565. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_ANT_GAIN(ah->ah_ee_version),
  1566. ee_ant_gain);
  1567. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1568. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC0, ee_misc0);
  1569. AR5K_EEPROM_READ_HDR(AR5K_EEPROM_MISC1, ee_misc1);
  1570. }
  1571. if (ah->ah_ee_version < AR5K_EEPROM_VERSION_3_3) {
  1572. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB0_2GHZ, val);
  1573. ee->ee_ob[AR5K_EEPROM_MODE_11B][0] = val & 0x7;
  1574. ee->ee_db[AR5K_EEPROM_MODE_11B][0] = (val >> 3) & 0x7;
  1575. AR5K_EEPROM_READ(AR5K_EEPROM_OBDB1_2GHZ, val);
  1576. ee->ee_ob[AR5K_EEPROM_MODE_11G][0] = val & 0x7;
  1577. ee->ee_db[AR5K_EEPROM_MODE_11G][0] = (val >> 3) & 0x7;
  1578. }
  1579. /*
  1580. * Get conformance test limit values
  1581. */
  1582. offset = AR5K_EEPROM_CTL(ah->ah_ee_version);
  1583. ee->ee_ctls = AR5K_EEPROM_N_CTLS(ah->ah_ee_version);
  1584. for (i = 0; i < ee->ee_ctls; i++) {
  1585. AR5K_EEPROM_READ(offset++, val);
  1586. ee->ee_ctl[i] = (val >> 8) & 0xff;
  1587. ee->ee_ctl[i + 1] = val & 0xff;
  1588. }
  1589. /*
  1590. * Get values for 802.11a (5GHz)
  1591. */
  1592. mode = AR5K_EEPROM_MODE_11A;
  1593. ee->ee_turbo_max_power[mode] =
  1594. AR5K_EEPROM_HDR_T_5GHZ_DBM(ee->ee_header);
  1595. offset = AR5K_EEPROM_MODES_11A(ah->ah_ee_version);
  1596. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1597. if (ret)
  1598. return ret;
  1599. AR5K_EEPROM_READ(offset++, val);
  1600. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1601. ee->ee_ob[mode][3] = (val >> 5) & 0x7;
  1602. ee->ee_db[mode][3] = (val >> 2) & 0x7;
  1603. ee->ee_ob[mode][2] = (val << 1) & 0x7;
  1604. AR5K_EEPROM_READ(offset++, val);
  1605. ee->ee_ob[mode][2] |= (val >> 15) & 0x1;
  1606. ee->ee_db[mode][2] = (val >> 12) & 0x7;
  1607. ee->ee_ob[mode][1] = (val >> 9) & 0x7;
  1608. ee->ee_db[mode][1] = (val >> 6) & 0x7;
  1609. ee->ee_ob[mode][0] = (val >> 3) & 0x7;
  1610. ee->ee_db[mode][0] = val & 0x7;
  1611. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1612. if (ret)
  1613. return ret;
  1614. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1) {
  1615. AR5K_EEPROM_READ(offset++, val);
  1616. ee->ee_margin_tx_rx[mode] = val & 0x3f;
  1617. }
  1618. /*
  1619. * Get values for 802.11b (2.4GHz)
  1620. */
  1621. mode = AR5K_EEPROM_MODE_11B;
  1622. offset = AR5K_EEPROM_MODES_11B(ah->ah_ee_version);
  1623. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1624. if (ret)
  1625. return ret;
  1626. AR5K_EEPROM_READ(offset++, val);
  1627. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1628. ee->ee_ob[mode][1] = (val >> 4) & 0x7;
  1629. ee->ee_db[mode][1] = val & 0x7;
  1630. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1631. if (ret)
  1632. return ret;
  1633. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1634. AR5K_EEPROM_READ(offset++, val);
  1635. ee->ee_cal_pier[mode][0] =
  1636. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1637. ee->ee_cal_pier[mode][1] =
  1638. ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
  1639. AR5K_EEPROM_READ(offset++, val);
  1640. ee->ee_cal_pier[mode][2] =
  1641. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1642. }
  1643. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  1644. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  1645. /*
  1646. * Get values for 802.11g (2.4GHz)
  1647. */
  1648. mode = AR5K_EEPROM_MODE_11G;
  1649. offset = AR5K_EEPROM_MODES_11G(ah->ah_ee_version);
  1650. ret = ath5k_eeprom_read_ants(ah, &offset, mode);
  1651. if (ret)
  1652. return ret;
  1653. AR5K_EEPROM_READ(offset++, val);
  1654. ee->ee_adc_desired_size[mode] = (s8)((val >> 8) & 0xff);
  1655. ee->ee_ob[mode][1] = (val >> 4) & 0x7;
  1656. ee->ee_db[mode][1] = val & 0x7;
  1657. ret = ath5k_eeprom_read_modes(ah, &offset, mode);
  1658. if (ret)
  1659. return ret;
  1660. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
  1661. AR5K_EEPROM_READ(offset++, val);
  1662. ee->ee_cal_pier[mode][0] =
  1663. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1664. ee->ee_cal_pier[mode][1] =
  1665. ath5k_eeprom_bin2freq(ah, (val >> 8) & 0xff, mode);
  1666. AR5K_EEPROM_READ(offset++, val);
  1667. ee->ee_turbo_max_power[mode] = val & 0x7f;
  1668. ee->ee_xr_power[mode] = (val >> 7) & 0x3f;
  1669. AR5K_EEPROM_READ(offset++, val);
  1670. ee->ee_cal_pier[mode][2] =
  1671. ath5k_eeprom_bin2freq(ah, val & 0xff, mode);
  1672. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
  1673. ee->ee_margin_tx_rx[mode] = (val >> 8) & 0x3f;
  1674. AR5K_EEPROM_READ(offset++, val);
  1675. ee->ee_i_cal[mode] = (val >> 8) & 0x3f;
  1676. ee->ee_q_cal[mode] = (val >> 3) & 0x1f;
  1677. if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_2) {
  1678. AR5K_EEPROM_READ(offset++, val);
  1679. ee->ee_cck_ofdm_gain_delta = val & 0xff;
  1680. }
  1681. }
  1682. /*
  1683. * Read 5GHz EEPROM channels
  1684. */
  1685. return 0;
  1686. }
  1687. /*
  1688. * Read the MAC address from eeprom
  1689. */
  1690. static int ath5k_eeprom_read_mac(struct ath5k_hw *ah, u8 *mac)
  1691. {
  1692. u8 mac_d[ETH_ALEN];
  1693. u32 total, offset;
  1694. u16 data;
  1695. int octet, ret;
  1696. memset(mac, 0, ETH_ALEN);
  1697. memset(mac_d, 0, ETH_ALEN);
  1698. ret = ath5k_hw_eeprom_read(ah, 0x20, &data);
  1699. if (ret)
  1700. return ret;
  1701. for (offset = 0x1f, octet = 0, total = 0; offset >= 0x1d; offset--) {
  1702. ret = ath5k_hw_eeprom_read(ah, offset, &data);
  1703. if (ret)
  1704. return ret;
  1705. total += data;
  1706. mac_d[octet + 1] = data & 0xff;
  1707. mac_d[octet] = data >> 8;
  1708. octet += 2;
  1709. }
  1710. memcpy(mac, mac_d, ETH_ALEN);
  1711. if (!total || total == 3 * 0xffff)
  1712. return -EINVAL;
  1713. return 0;
  1714. }
  1715. /*
  1716. * Read/Write regulatory domain
  1717. */
  1718. static bool ath5k_eeprom_regulation_domain(struct ath5k_hw *ah, bool write,
  1719. enum ath5k_regdom *regdomain)
  1720. {
  1721. u16 ee_regdomain;
  1722. /* Read current value */
  1723. if (write != true) {
  1724. ee_regdomain = ah->ah_capabilities.cap_eeprom.ee_regdomain;
  1725. *regdomain = ath5k_regdom_to_ieee(ee_regdomain);
  1726. return true;
  1727. }
  1728. ee_regdomain = ath5k_regdom_from_ieee(*regdomain);
  1729. /* Try to write a new value */
  1730. if (ah->ah_capabilities.cap_eeprom.ee_protect &
  1731. AR5K_EEPROM_PROTECT_WR_128_191)
  1732. return false;
  1733. if (ath5k_hw_eeprom_write(ah, AR5K_EEPROM_REG_DOMAIN, ee_regdomain)!=0)
  1734. return false;
  1735. ah->ah_capabilities.cap_eeprom.ee_regdomain = ee_regdomain;
  1736. return true;
  1737. }
  1738. /*
  1739. * Use the above to write a new regulatory domain
  1740. */
  1741. int ath5k_hw_set_regdomain(struct ath5k_hw *ah, u16 regdomain)
  1742. {
  1743. enum ath5k_regdom ieee_regdomain;
  1744. ieee_regdomain = ath5k_regdom_to_ieee(regdomain);
  1745. if (ath5k_eeprom_regulation_domain(ah, true, &ieee_regdomain) == true)
  1746. return 0;
  1747. return -EIO;
  1748. }
  1749. /*
  1750. * Fill the capabilities struct
  1751. */
  1752. static int ath5k_hw_get_capabilities(struct ath5k_hw *ah)
  1753. {
  1754. u16 ee_header;
  1755. ATH5K_TRACE(ah->ah_sc);
  1756. /* Capabilities stored in the EEPROM */
  1757. ee_header = ah->ah_capabilities.cap_eeprom.ee_header;
  1758. if (ah->ah_version == AR5K_AR5210) {
  1759. /*
  1760. * Set radio capabilities
  1761. * (The AR5110 only supports the middle 5GHz band)
  1762. */
  1763. ah->ah_capabilities.cap_range.range_5ghz_min = 5120;
  1764. ah->ah_capabilities.cap_range.range_5ghz_max = 5430;
  1765. ah->ah_capabilities.cap_range.range_2ghz_min = 0;
  1766. ah->ah_capabilities.cap_range.range_2ghz_max = 0;
  1767. /* Set supported modes */
  1768. __set_bit(MODE_IEEE80211A, ah->ah_capabilities.cap_mode);
  1769. __set_bit(MODE_ATHEROS_TURBO, ah->ah_capabilities.cap_mode);
  1770. } else {
  1771. /*
  1772. * XXX The tranceiver supports frequencies from 4920 to 6100GHz
  1773. * XXX and from 2312 to 2732GHz. There are problems with the
  1774. * XXX current ieee80211 implementation because the IEEE
  1775. * XXX channel mapping does not support negative channel
  1776. * XXX numbers (2312MHz is channel -19). Of course, this
  1777. * XXX doesn't matter because these channels are out of range
  1778. * XXX but some regulation domains like MKK (Japan) will
  1779. * XXX support frequencies somewhere around 4.8GHz.
  1780. */
  1781. /*
  1782. * Set radio capabilities
  1783. */
  1784. if (AR5K_EEPROM_HDR_11A(ee_header)) {
  1785. ah->ah_capabilities.cap_range.range_5ghz_min = 5005; /* 4920 */
  1786. ah->ah_capabilities.cap_range.range_5ghz_max = 6100;
  1787. /* Set supported modes */
  1788. __set_bit(MODE_IEEE80211A,
  1789. ah->ah_capabilities.cap_mode);
  1790. __set_bit(MODE_ATHEROS_TURBO,
  1791. ah->ah_capabilities.cap_mode);
  1792. if (ah->ah_version == AR5K_AR5212)
  1793. __set_bit(MODE_ATHEROS_TURBOG,
  1794. ah->ah_capabilities.cap_mode);
  1795. }
  1796. /* Enable 802.11b if a 2GHz capable radio (2111/5112) is
  1797. * connected */
  1798. if (AR5K_EEPROM_HDR_11B(ee_header) ||
  1799. AR5K_EEPROM_HDR_11G(ee_header)) {
  1800. ah->ah_capabilities.cap_range.range_2ghz_min = 2412; /* 2312 */
  1801. ah->ah_capabilities.cap_range.range_2ghz_max = 2732;
  1802. if (AR5K_EEPROM_HDR_11B(ee_header))
  1803. __set_bit(MODE_IEEE80211B,
  1804. ah->ah_capabilities.cap_mode);
  1805. if (AR5K_EEPROM_HDR_11G(ee_header))
  1806. __set_bit(MODE_IEEE80211G,
  1807. ah->ah_capabilities.cap_mode);
  1808. }
  1809. }
  1810. /* GPIO */
  1811. ah->ah_gpio_npins = AR5K_NUM_GPIO;
  1812. /* Set number of supported TX queues */
  1813. if (ah->ah_version == AR5K_AR5210)
  1814. ah->ah_capabilities.cap_queues.q_tx_num =
  1815. AR5K_NUM_TX_QUEUES_NOQCU;
  1816. else
  1817. ah->ah_capabilities.cap_queues.q_tx_num = AR5K_NUM_TX_QUEUES;
  1818. return 0;
  1819. }
  1820. /*********************************\
  1821. Protocol Control Unit Functions
  1822. \*********************************/
  1823. /*
  1824. * Set Operation mode
  1825. */
  1826. int ath5k_hw_set_opmode(struct ath5k_hw *ah)
  1827. {
  1828. u32 pcu_reg, beacon_reg, low_id, high_id;
  1829. pcu_reg = 0;
  1830. beacon_reg = 0;
  1831. ATH5K_TRACE(ah->ah_sc);
  1832. switch (ah->ah_op_mode) {
  1833. case IEEE80211_IF_TYPE_IBSS:
  1834. pcu_reg |= AR5K_STA_ID1_ADHOC | AR5K_STA_ID1_DESC_ANTENNA |
  1835. (ah->ah_version == AR5K_AR5210 ?
  1836. AR5K_STA_ID1_NO_PSPOLL : 0);
  1837. beacon_reg |= AR5K_BCR_ADHOC;
  1838. break;
  1839. case IEEE80211_IF_TYPE_AP:
  1840. pcu_reg |= AR5K_STA_ID1_AP | AR5K_STA_ID1_RTS_DEF_ANTENNA |
  1841. (ah->ah_version == AR5K_AR5210 ?
  1842. AR5K_STA_ID1_NO_PSPOLL : 0);
  1843. beacon_reg |= AR5K_BCR_AP;
  1844. break;
  1845. case IEEE80211_IF_TYPE_STA:
  1846. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  1847. (ah->ah_version == AR5K_AR5210 ?
  1848. AR5K_STA_ID1_PWR_SV : 0);
  1849. case IEEE80211_IF_TYPE_MNTR:
  1850. pcu_reg |= AR5K_STA_ID1_DEFAULT_ANTENNA |
  1851. (ah->ah_version == AR5K_AR5210 ?
  1852. AR5K_STA_ID1_NO_PSPOLL : 0);
  1853. break;
  1854. default:
  1855. return -EINVAL;
  1856. }
  1857. /*
  1858. * Set PCU registers
  1859. */
  1860. low_id = AR5K_LOW_ID(ah->ah_sta_id);
  1861. high_id = AR5K_HIGH_ID(ah->ah_sta_id);
  1862. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  1863. ath5k_hw_reg_write(ah, pcu_reg | high_id, AR5K_STA_ID1);
  1864. /*
  1865. * Set Beacon Control Register on 5210
  1866. */
  1867. if (ah->ah_version == AR5K_AR5210)
  1868. ath5k_hw_reg_write(ah, beacon_reg, AR5K_BCR);
  1869. return 0;
  1870. }
  1871. /*
  1872. * BSSID Functions
  1873. */
  1874. /*
  1875. * Get station id
  1876. */
  1877. void ath5k_hw_get_lladdr(struct ath5k_hw *ah, u8 *mac)
  1878. {
  1879. ATH5K_TRACE(ah->ah_sc);
  1880. memcpy(mac, ah->ah_sta_id, ETH_ALEN);
  1881. }
  1882. /*
  1883. * Set station id
  1884. */
  1885. int ath5k_hw_set_lladdr(struct ath5k_hw *ah, const u8 *mac)
  1886. {
  1887. u32 low_id, high_id;
  1888. ATH5K_TRACE(ah->ah_sc);
  1889. /* Set new station ID */
  1890. memcpy(ah->ah_sta_id, mac, ETH_ALEN);
  1891. low_id = AR5K_LOW_ID(mac);
  1892. high_id = AR5K_HIGH_ID(mac);
  1893. ath5k_hw_reg_write(ah, low_id, AR5K_STA_ID0);
  1894. ath5k_hw_reg_write(ah, high_id, AR5K_STA_ID1);
  1895. return 0;
  1896. }
  1897. /*
  1898. * Set BSSID
  1899. */
  1900. void ath5k_hw_set_associd(struct ath5k_hw *ah, const u8 *bssid, u16 assoc_id)
  1901. {
  1902. u32 low_id, high_id;
  1903. u16 tim_offset = 0;
  1904. /*
  1905. * Set simple BSSID mask on 5212
  1906. */
  1907. if (ah->ah_version == AR5K_AR5212) {
  1908. ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM0);
  1909. ath5k_hw_reg_write(ah, 0xfffffff, AR5K_BSS_IDM1);
  1910. }
  1911. /*
  1912. * Set BSSID which triggers the "SME Join" operation
  1913. */
  1914. low_id = AR5K_LOW_ID(bssid);
  1915. high_id = AR5K_HIGH_ID(bssid);
  1916. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_ID0);
  1917. ath5k_hw_reg_write(ah, high_id | ((assoc_id & 0x3fff) <<
  1918. AR5K_BSS_ID1_AID_S), AR5K_BSS_ID1);
  1919. if (assoc_id == 0) {
  1920. ath5k_hw_disable_pspoll(ah);
  1921. return;
  1922. }
  1923. AR5K_REG_WRITE_BITS(ah, AR5K_BEACON, AR5K_BEACON_TIM,
  1924. tim_offset ? tim_offset + 4 : 0);
  1925. ath5k_hw_enable_pspoll(ah, NULL, 0);
  1926. }
  1927. /**
  1928. * ath5k_hw_set_bssid_mask - set common bits we should listen to
  1929. *
  1930. * The bssid_mask is a utility used by AR5212 hardware to inform the hardware
  1931. * which bits of the interface's MAC address should be looked at when trying
  1932. * to decide which packets to ACK. In station mode every bit matters. In AP
  1933. * mode with a single BSS every bit matters as well. In AP mode with
  1934. * multiple BSSes not every bit matters.
  1935. *
  1936. * @ah: the &struct ath5k_hw
  1937. * @mask: the bssid_mask, a u8 array of size ETH_ALEN
  1938. *
  1939. * Note that this is a simple filter and *does* not filter out all
  1940. * relevant frames. Some non-relevant frames will get through, probability
  1941. * jocks are welcomed to compute.
  1942. *
  1943. * When handling multiple BSSes (or VAPs) you can get the BSSID mask by
  1944. * computing the set of:
  1945. *
  1946. * ~ ( MAC XOR BSSID )
  1947. *
  1948. * When you do this you are essentially computing the common bits. Later it
  1949. * is assumed the harware will "and" (&) the BSSID mask with the MAC address
  1950. * to obtain the relevant bits which should match on the destination frame.
  1951. *
  1952. * Simple example: on your card you have have two BSSes you have created with
  1953. * BSSID-01 and BSSID-02. Lets assume BSSID-01 will not use the MAC address.
  1954. * There is another BSSID-03 but you are not part of it. For simplicity's sake,
  1955. * assuming only 4 bits for a mac address and for BSSIDs you can then have:
  1956. *
  1957. * \
  1958. * MAC: 0001 |
  1959. * BSSID-01: 0100 | --> Belongs to us
  1960. * BSSID-02: 1001 |
  1961. * /
  1962. * -------------------
  1963. * BSSID-03: 0110 | --> External
  1964. * -------------------
  1965. *
  1966. * Our bssid_mask would then be:
  1967. *
  1968. * On loop iteration for BSSID-01:
  1969. * ~(0001 ^ 0100) -> ~(0101)
  1970. * -> 1010
  1971. * bssid_mask = 1010
  1972. *
  1973. * On loop iteration for BSSID-02:
  1974. * bssid_mask &= ~(0001 ^ 1001)
  1975. * bssid_mask = (1010) & ~(0001 ^ 1001)
  1976. * bssid_mask = (1010) & ~(1001)
  1977. * bssid_mask = (1010) & (0110)
  1978. * bssid_mask = 0010
  1979. *
  1980. * A bssid_mask of 0010 means "only pay attention to the second least
  1981. * significant bit". This is because its the only bit common
  1982. * amongst the MAC and all BSSIDs we support. To findout what the real
  1983. * common bit is we can simply "&" the bssid_mask now with any BSSID we have
  1984. * or our MAC address (we assume the hardware uses the MAC address).
  1985. *
  1986. * Now, suppose there's an incoming frame for BSSID-03:
  1987. *
  1988. * IFRAME-01: 0110
  1989. *
  1990. * An easy eye-inspeciton of this already should tell you that this frame
  1991. * will not pass our check. This is beacuse the bssid_mask tells the
  1992. * hardware to only look at the second least significant bit and the
  1993. * common bit amongst the MAC and BSSIDs is 0, this frame has the 2nd LSB
  1994. * as 1, which does not match 0.
  1995. *
  1996. * So with IFRAME-01 we *assume* the hardware will do:
  1997. *
  1998. * allow = (IFRAME-01 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  1999. * --> allow = (0110 & 0010) == (0010 & 0001) ? 1 : 0;
  2000. * --> allow = (0010) == 0000 ? 1 : 0;
  2001. * --> allow = 0
  2002. *
  2003. * Lets now test a frame that should work:
  2004. *
  2005. * IFRAME-02: 0001 (we should allow)
  2006. *
  2007. * allow = (0001 & 1010) == 1010
  2008. *
  2009. * allow = (IFRAME-02 & bssid_mask) == (bssid_mask & MAC) ? 1 : 0;
  2010. * --> allow = (0001 & 0010) == (0010 & 0001) ? 1 :0;
  2011. * --> allow = (0010) == (0010)
  2012. * --> allow = 1
  2013. *
  2014. * Other examples:
  2015. *
  2016. * IFRAME-03: 0100 --> allowed
  2017. * IFRAME-04: 1001 --> allowed
  2018. * IFRAME-05: 1101 --> allowed but its not for us!!!
  2019. *
  2020. */
  2021. int ath5k_hw_set_bssid_mask(struct ath5k_hw *ah, const u8 *mask)
  2022. {
  2023. u32 low_id, high_id;
  2024. ATH5K_TRACE(ah->ah_sc);
  2025. if (ah->ah_version == AR5K_AR5212) {
  2026. low_id = AR5K_LOW_ID(mask);
  2027. high_id = AR5K_HIGH_ID(mask);
  2028. ath5k_hw_reg_write(ah, low_id, AR5K_BSS_IDM0);
  2029. ath5k_hw_reg_write(ah, high_id, AR5K_BSS_IDM1);
  2030. return 0;
  2031. }
  2032. return -EIO;
  2033. }
  2034. /*
  2035. * Receive start/stop functions
  2036. */
  2037. /*
  2038. * Start receive on PCU
  2039. */
  2040. void ath5k_hw_start_rx_pcu(struct ath5k_hw *ah)
  2041. {
  2042. ATH5K_TRACE(ah->ah_sc);
  2043. AR5K_REG_DISABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2044. }
  2045. /*
  2046. * Stop receive on PCU
  2047. */
  2048. void ath5k_hw_stop_pcu_recv(struct ath5k_hw *ah)
  2049. {
  2050. ATH5K_TRACE(ah->ah_sc);
  2051. AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW, AR5K_DIAG_SW_DIS_RX);
  2052. }
  2053. /*
  2054. * RX Filter functions
  2055. */
  2056. /*
  2057. * Set multicast filter
  2058. */
  2059. void ath5k_hw_set_mcast_filter(struct ath5k_hw *ah, u32 filter0, u32 filter1)
  2060. {
  2061. ATH5K_TRACE(ah->ah_sc);
  2062. /* Set the multicat filter */
  2063. ath5k_hw_reg_write(ah, filter0, AR5K_MCAST_FILTER0);
  2064. ath5k_hw_reg_write(ah, filter1, AR5K_MCAST_FILTER1);
  2065. }
  2066. /*
  2067. * Set multicast filter by index
  2068. */
  2069. int ath5k_hw_set_mcast_filterindex(struct ath5k_hw *ah, u32 index)
  2070. {
  2071. ATH5K_TRACE(ah->ah_sc);
  2072. if (index >= 64)
  2073. return -EINVAL;
  2074. else if (index >= 32)
  2075. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2076. (1 << (index - 32)));
  2077. else
  2078. AR5K_REG_ENABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2079. return 0;
  2080. }
  2081. /*
  2082. * Clear Multicast filter by index
  2083. */
  2084. int ath5k_hw_clear_mcast_filter_idx(struct ath5k_hw *ah, u32 index)
  2085. {
  2086. ATH5K_TRACE(ah->ah_sc);
  2087. if (index >= 64)
  2088. return -EINVAL;
  2089. else if (index >= 32)
  2090. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER1,
  2091. (1 << (index - 32)));
  2092. else
  2093. AR5K_REG_DISABLE_BITS(ah, AR5K_MCAST_FILTER0, (1 << index));
  2094. return 0;
  2095. }
  2096. /*
  2097. * Get current rx filter
  2098. */
  2099. u32 ath5k_hw_get_rx_filter(struct ath5k_hw *ah)
  2100. {
  2101. u32 data, filter = 0;
  2102. ATH5K_TRACE(ah->ah_sc);
  2103. filter = ath5k_hw_reg_read(ah, AR5K_RX_FILTER);
  2104. /*Radar detection for 5212*/
  2105. if (ah->ah_version == AR5K_AR5212) {
  2106. data = ath5k_hw_reg_read(ah, AR5K_PHY_ERR_FIL);
  2107. if (data & AR5K_PHY_ERR_FIL_RADAR)
  2108. filter |= AR5K_RX_FILTER_RADARERR;
  2109. if (data & (AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK))
  2110. filter |= AR5K_RX_FILTER_PHYERR;
  2111. }
  2112. return filter;
  2113. }
  2114. /*
  2115. * Set rx filter
  2116. */
  2117. void ath5k_hw_set_rx_filter(struct ath5k_hw *ah, u32 filter)
  2118. {
  2119. u32 data = 0;
  2120. ATH5K_TRACE(ah->ah_sc);
  2121. /* Set PHY error filter register on 5212*/
  2122. if (ah->ah_version == AR5K_AR5212) {
  2123. if (filter & AR5K_RX_FILTER_RADARERR)
  2124. data |= AR5K_PHY_ERR_FIL_RADAR;
  2125. if (filter & AR5K_RX_FILTER_PHYERR)
  2126. data |= AR5K_PHY_ERR_FIL_OFDM | AR5K_PHY_ERR_FIL_CCK;
  2127. }
  2128. /*
  2129. * The AR5210 uses promiscous mode to detect radar activity
  2130. */
  2131. if (ah->ah_version == AR5K_AR5210 &&
  2132. (filter & AR5K_RX_FILTER_RADARERR)) {
  2133. filter &= ~AR5K_RX_FILTER_RADARERR;
  2134. filter |= AR5K_RX_FILTER_PROM;
  2135. }
  2136. /*Zero length DMA*/
  2137. if (data)
  2138. AR5K_REG_ENABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2139. else
  2140. AR5K_REG_DISABLE_BITS(ah, AR5K_RXCFG, AR5K_RXCFG_ZLFDMA);
  2141. /*Write RX Filter register*/
  2142. ath5k_hw_reg_write(ah, filter & 0xff, AR5K_RX_FILTER);
  2143. /*Write PHY error filter register on 5212*/
  2144. if (ah->ah_version == AR5K_AR5212)
  2145. ath5k_hw_reg_write(ah, data, AR5K_PHY_ERR_FIL);
  2146. }
  2147. /*
  2148. * Beacon related functions
  2149. */
  2150. /*
  2151. * Get a 32bit TSF
  2152. */
  2153. u32 ath5k_hw_get_tsf32(struct ath5k_hw *ah)
  2154. {
  2155. ATH5K_TRACE(ah->ah_sc);
  2156. return ath5k_hw_reg_read(ah, AR5K_TSF_L32);
  2157. }
  2158. /*
  2159. * Get the full 64bit TSF
  2160. */
  2161. u64 ath5k_hw_get_tsf64(struct ath5k_hw *ah)
  2162. {
  2163. u64 tsf = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
  2164. ATH5K_TRACE(ah->ah_sc);
  2165. return ath5k_hw_reg_read(ah, AR5K_TSF_L32) | (tsf << 32);
  2166. }
  2167. /*
  2168. * Force a TSF reset
  2169. */
  2170. void ath5k_hw_reset_tsf(struct ath5k_hw *ah)
  2171. {
  2172. ATH5K_TRACE(ah->ah_sc);
  2173. AR5K_REG_ENABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_RESET_TSF);
  2174. }
  2175. /*
  2176. * Initialize beacon timers
  2177. */
  2178. void ath5k_hw_init_beacon(struct ath5k_hw *ah, u32 next_beacon, u32 interval)
  2179. {
  2180. u32 timer1, timer2, timer3;
  2181. ATH5K_TRACE(ah->ah_sc);
  2182. /*
  2183. * Set the additional timers by mode
  2184. */
  2185. switch (ah->ah_op_mode) {
  2186. case IEEE80211_IF_TYPE_STA:
  2187. if (ah->ah_version == AR5K_AR5210) {
  2188. timer1 = 0xffffffff;
  2189. timer2 = 0xffffffff;
  2190. } else {
  2191. timer1 = 0x0000ffff;
  2192. timer2 = 0x0007ffff;
  2193. }
  2194. break;
  2195. default:
  2196. timer1 = (next_beacon - AR5K_TUNE_DMA_BEACON_RESP) << 3;
  2197. timer2 = (next_beacon - AR5K_TUNE_SW_BEACON_RESP) << 3;
  2198. }
  2199. timer3 = next_beacon + (ah->ah_atim_window ? ah->ah_atim_window : 1);
  2200. /*
  2201. * Set the beacon register and enable all timers.
  2202. * (next beacon, DMA beacon, software beacon, ATIM window time)
  2203. */
  2204. ath5k_hw_reg_write(ah, next_beacon, AR5K_TIMER0);
  2205. ath5k_hw_reg_write(ah, timer1, AR5K_TIMER1);
  2206. ath5k_hw_reg_write(ah, timer2, AR5K_TIMER2);
  2207. ath5k_hw_reg_write(ah, timer3, AR5K_TIMER3);
  2208. ath5k_hw_reg_write(ah, interval & (AR5K_BEACON_PERIOD |
  2209. AR5K_BEACON_RESET_TSF | AR5K_BEACON_ENABLE),
  2210. AR5K_BEACON);
  2211. }
  2212. #if 0
  2213. /*
  2214. * Set beacon timers
  2215. */
  2216. int ath5k_hw_set_beacon_timers(struct ath5k_hw *ah,
  2217. const struct ath5k_beacon_state *state)
  2218. {
  2219. u32 cfp_period, next_cfp, dtim, interval, next_beacon;
  2220. /*
  2221. * TODO: should be changed through *state
  2222. * review struct ath5k_beacon_state struct
  2223. *
  2224. * XXX: These are used for cfp period bellow, are they
  2225. * ok ? Is it O.K. for tsf here to be 0 or should we use
  2226. * get_tsf ?
  2227. */
  2228. u32 dtim_count = 0; /* XXX */
  2229. u32 cfp_count = 0; /* XXX */
  2230. u32 tsf = 0; /* XXX */
  2231. ATH5K_TRACE(ah->ah_sc);
  2232. /* Return on an invalid beacon state */
  2233. if (state->bs_interval < 1)
  2234. return -EINVAL;
  2235. interval = state->bs_interval;
  2236. dtim = state->bs_dtim_period;
  2237. /*
  2238. * PCF support?
  2239. */
  2240. if (state->bs_cfp_period > 0) {
  2241. /*
  2242. * Enable PCF mode and set the CFP
  2243. * (Contention Free Period) and timer registers
  2244. */
  2245. cfp_period = state->bs_cfp_period * state->bs_dtim_period *
  2246. state->bs_interval;
  2247. next_cfp = (cfp_count * state->bs_dtim_period + dtim_count) *
  2248. state->bs_interval;
  2249. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  2250. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2251. AR5K_STA_ID1_PCF);
  2252. ath5k_hw_reg_write(ah, cfp_period, AR5K_CFP_PERIOD);
  2253. ath5k_hw_reg_write(ah, state->bs_cfp_max_duration,
  2254. AR5K_CFP_DUR);
  2255. ath5k_hw_reg_write(ah, (tsf + (next_cfp == 0 ? cfp_period :
  2256. next_cfp)) << 3, AR5K_TIMER2);
  2257. } else {
  2258. /* Disable PCF mode */
  2259. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2260. AR5K_STA_ID1_DEFAULT_ANTENNA |
  2261. AR5K_STA_ID1_PCF);
  2262. }
  2263. /*
  2264. * Enable the beacon timer register
  2265. */
  2266. ath5k_hw_reg_write(ah, state->bs_next_beacon, AR5K_TIMER0);
  2267. /*
  2268. * Start the beacon timers
  2269. */
  2270. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_BEACON) &~
  2271. (AR5K_BEACON_PERIOD | AR5K_BEACON_TIM)) |
  2272. AR5K_REG_SM(state->bs_tim_offset ? state->bs_tim_offset + 4 : 0,
  2273. AR5K_BEACON_TIM) | AR5K_REG_SM(state->bs_interval,
  2274. AR5K_BEACON_PERIOD), AR5K_BEACON);
  2275. /*
  2276. * Write new beacon miss threshold, if it appears to be valid
  2277. * XXX: Figure out right values for min <= bs_bmiss_threshold <= max
  2278. * and return if its not in range. We can test this by reading value and
  2279. * setting value to a largest value and seeing which values register.
  2280. */
  2281. AR5K_REG_WRITE_BITS(ah, AR5K_RSSI_THR, AR5K_RSSI_THR_BMISS,
  2282. state->bs_bmiss_threshold);
  2283. /*
  2284. * Set sleep control register
  2285. * XXX: Didn't find this in 5210 code but since this register
  2286. * exists also in ar5k's 5210 headers i leave it as common code.
  2287. */
  2288. AR5K_REG_WRITE_BITS(ah, AR5K_SLEEP_CTL, AR5K_SLEEP_CTL_SLDUR,
  2289. (state->bs_sleep_duration - 3) << 3);
  2290. /*
  2291. * Set enhanced sleep registers on 5212
  2292. */
  2293. if (ah->ah_version == AR5K_AR5212) {
  2294. if (state->bs_sleep_duration > state->bs_interval &&
  2295. roundup(state->bs_sleep_duration, interval) ==
  2296. state->bs_sleep_duration)
  2297. interval = state->bs_sleep_duration;
  2298. if (state->bs_sleep_duration > dtim && (dtim == 0 ||
  2299. roundup(state->bs_sleep_duration, dtim) ==
  2300. state->bs_sleep_duration))
  2301. dtim = state->bs_sleep_duration;
  2302. if (interval > dtim)
  2303. return -EINVAL;
  2304. next_beacon = interval == dtim ? state->bs_next_dtim :
  2305. state->bs_next_beacon;
  2306. ath5k_hw_reg_write(ah,
  2307. AR5K_REG_SM((state->bs_next_dtim - 3) << 3,
  2308. AR5K_SLEEP0_NEXT_DTIM) |
  2309. AR5K_REG_SM(10, AR5K_SLEEP0_CABTO) |
  2310. AR5K_SLEEP0_ENH_SLEEP_EN |
  2311. AR5K_SLEEP0_ASSUME_DTIM, AR5K_SLEEP0);
  2312. ath5k_hw_reg_write(ah, AR5K_REG_SM((next_beacon - 3) << 3,
  2313. AR5K_SLEEP1_NEXT_TIM) |
  2314. AR5K_REG_SM(10, AR5K_SLEEP1_BEACON_TO), AR5K_SLEEP1);
  2315. ath5k_hw_reg_write(ah,
  2316. AR5K_REG_SM(interval, AR5K_SLEEP2_TIM_PER) |
  2317. AR5K_REG_SM(dtim, AR5K_SLEEP2_DTIM_PER), AR5K_SLEEP2);
  2318. }
  2319. return 0;
  2320. }
  2321. /*
  2322. * Reset beacon timers
  2323. */
  2324. void ath5k_hw_reset_beacon(struct ath5k_hw *ah)
  2325. {
  2326. ATH5K_TRACE(ah->ah_sc);
  2327. /*
  2328. * Disable beacon timer
  2329. */
  2330. ath5k_hw_reg_write(ah, 0, AR5K_TIMER0);
  2331. /*
  2332. * Disable some beacon register values
  2333. */
  2334. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  2335. AR5K_STA_ID1_DEFAULT_ANTENNA | AR5K_STA_ID1_PCF);
  2336. ath5k_hw_reg_write(ah, AR5K_BEACON_PERIOD, AR5K_BEACON);
  2337. }
  2338. /*
  2339. * Wait for beacon queue to finish
  2340. */
  2341. int ath5k_hw_beaconq_finish(struct ath5k_hw *ah, unsigned long phys_addr)
  2342. {
  2343. unsigned int i;
  2344. int ret;
  2345. ATH5K_TRACE(ah->ah_sc);
  2346. /* 5210 doesn't have QCU*/
  2347. if (ah->ah_version == AR5K_AR5210) {
  2348. /*
  2349. * Wait for beaconn queue to finish by checking
  2350. * Control Register and Beacon Status Register.
  2351. */
  2352. for (i = AR5K_TUNE_BEACON_INTERVAL / 2; i > 0; i--) {
  2353. if (!(ath5k_hw_reg_read(ah, AR5K_BSR) & AR5K_BSR_TXQ1F)
  2354. ||
  2355. !(ath5k_hw_reg_read(ah, AR5K_CR) & AR5K_BSR_TXQ1F))
  2356. break;
  2357. udelay(10);
  2358. }
  2359. /* Timeout... */
  2360. if (i <= 0) {
  2361. /*
  2362. * Re-schedule the beacon queue
  2363. */
  2364. ath5k_hw_reg_write(ah, phys_addr, AR5K_NOQCU_TXDP1);
  2365. ath5k_hw_reg_write(ah, AR5K_BCR_TQ1V | AR5K_BCR_BDMAE,
  2366. AR5K_BCR);
  2367. return -EIO;
  2368. }
  2369. ret = 0;
  2370. } else {
  2371. /*5211/5212*/
  2372. ret = ath5k_hw_register_timeout(ah,
  2373. AR5K_QUEUE_STATUS(AR5K_TX_QUEUE_ID_BEACON),
  2374. AR5K_QCU_STS_FRMPENDCNT, 0, false);
  2375. if (AR5K_REG_READ_Q(ah, AR5K_QCU_TXE, AR5K_TX_QUEUE_ID_BEACON))
  2376. return -EIO;
  2377. }
  2378. return ret;
  2379. }
  2380. #endif
  2381. /*
  2382. * Update mib counters (statistics)
  2383. */
  2384. void ath5k_hw_update_mib_counters(struct ath5k_hw *ah,
  2385. struct ath5k_mib_stats *statistics)
  2386. {
  2387. ATH5K_TRACE(ah->ah_sc);
  2388. /* Read-And-Clear */
  2389. statistics->ackrcv_bad += ath5k_hw_reg_read(ah, AR5K_ACK_FAIL);
  2390. statistics->rts_bad += ath5k_hw_reg_read(ah, AR5K_RTS_FAIL);
  2391. statistics->rts_good += ath5k_hw_reg_read(ah, AR5K_RTS_OK);
  2392. statistics->fcs_bad += ath5k_hw_reg_read(ah, AR5K_FCS_FAIL);
  2393. statistics->beacons += ath5k_hw_reg_read(ah, AR5K_BEACON_CNT);
  2394. /* Reset profile count registers on 5212*/
  2395. if (ah->ah_version == AR5K_AR5212) {
  2396. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_TX);
  2397. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RX);
  2398. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_RXCLR);
  2399. ath5k_hw_reg_write(ah, 0, AR5K_PROFCNT_CYCLE);
  2400. }
  2401. }
  2402. /** ath5k_hw_set_ack_bitrate - set bitrate for ACKs
  2403. *
  2404. * @ah: the &struct ath5k_hw
  2405. * @high: determines if to use low bit rate or now
  2406. */
  2407. void ath5k_hw_set_ack_bitrate_high(struct ath5k_hw *ah, bool high)
  2408. {
  2409. if (ah->ah_version != AR5K_AR5212)
  2410. return;
  2411. else {
  2412. u32 val = AR5K_STA_ID1_BASE_RATE_11B | AR5K_STA_ID1_ACKCTS_6MB;
  2413. if (high)
  2414. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1, val);
  2415. else
  2416. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1, val);
  2417. }
  2418. }
  2419. /*
  2420. * ACK/CTS Timeouts
  2421. */
  2422. /*
  2423. * Set ACK timeout on PCU
  2424. */
  2425. int ath5k_hw_set_ack_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2426. {
  2427. ATH5K_TRACE(ah->ah_sc);
  2428. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_ACK),
  2429. ah->ah_turbo) <= timeout)
  2430. return -EINVAL;
  2431. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_ACK,
  2432. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2433. return 0;
  2434. }
  2435. /*
  2436. * Read the ACK timeout from PCU
  2437. */
  2438. unsigned int ath5k_hw_get_ack_timeout(struct ath5k_hw *ah)
  2439. {
  2440. ATH5K_TRACE(ah->ah_sc);
  2441. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2442. AR5K_TIME_OUT), AR5K_TIME_OUT_ACK), ah->ah_turbo);
  2443. }
  2444. /*
  2445. * Set CTS timeout on PCU
  2446. */
  2447. int ath5k_hw_set_cts_timeout(struct ath5k_hw *ah, unsigned int timeout)
  2448. {
  2449. ATH5K_TRACE(ah->ah_sc);
  2450. if (ath5k_hw_clocktoh(AR5K_REG_MS(0xffffffff, AR5K_TIME_OUT_CTS),
  2451. ah->ah_turbo) <= timeout)
  2452. return -EINVAL;
  2453. AR5K_REG_WRITE_BITS(ah, AR5K_TIME_OUT, AR5K_TIME_OUT_CTS,
  2454. ath5k_hw_htoclock(timeout, ah->ah_turbo));
  2455. return 0;
  2456. }
  2457. /*
  2458. * Read CTS timeout from PCU
  2459. */
  2460. unsigned int ath5k_hw_get_cts_timeout(struct ath5k_hw *ah)
  2461. {
  2462. ATH5K_TRACE(ah->ah_sc);
  2463. return ath5k_hw_clocktoh(AR5K_REG_MS(ath5k_hw_reg_read(ah,
  2464. AR5K_TIME_OUT), AR5K_TIME_OUT_CTS), ah->ah_turbo);
  2465. }
  2466. /*
  2467. * Key table (WEP) functions
  2468. */
  2469. int ath5k_hw_reset_key(struct ath5k_hw *ah, u16 entry)
  2470. {
  2471. unsigned int i;
  2472. ATH5K_TRACE(ah->ah_sc);
  2473. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2474. for (i = 0; i < AR5K_KEYCACHE_SIZE; i++)
  2475. ath5k_hw_reg_write(ah, 0, AR5K_KEYTABLE_OFF(entry, i));
  2476. /* Set NULL encryption on non-5210*/
  2477. if (ah->ah_version != AR5K_AR5210)
  2478. ath5k_hw_reg_write(ah, AR5K_KEYTABLE_TYPE_NULL,
  2479. AR5K_KEYTABLE_TYPE(entry));
  2480. return 0;
  2481. }
  2482. int ath5k_hw_is_key_valid(struct ath5k_hw *ah, u16 entry)
  2483. {
  2484. ATH5K_TRACE(ah->ah_sc);
  2485. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2486. /* Check the validation flag at the end of the entry */
  2487. return ath5k_hw_reg_read(ah, AR5K_KEYTABLE_MAC1(entry)) &
  2488. AR5K_KEYTABLE_VALID;
  2489. }
  2490. int ath5k_hw_set_key(struct ath5k_hw *ah, u16 entry,
  2491. const struct ieee80211_key_conf *key, const u8 *mac)
  2492. {
  2493. unsigned int i;
  2494. __le32 key_v[5] = {};
  2495. u32 keytype;
  2496. ATH5K_TRACE(ah->ah_sc);
  2497. /* key->keylen comes in from mac80211 in bytes */
  2498. if (key->keylen > AR5K_KEYTABLE_SIZE / 8)
  2499. return -EOPNOTSUPP;
  2500. switch (key->keylen) {
  2501. /* WEP 40-bit = 40-bit entered key + 24 bit IV = 64-bit */
  2502. case 40 / 8:
  2503. memcpy(&key_v[0], key->key, 5);
  2504. keytype = AR5K_KEYTABLE_TYPE_40;
  2505. break;
  2506. /* WEP 104-bit = 104-bit entered key + 24-bit IV = 128-bit */
  2507. case 104 / 8:
  2508. memcpy(&key_v[0], &key->key[0], 6);
  2509. memcpy(&key_v[2], &key->key[6], 6);
  2510. memcpy(&key_v[4], &key->key[12], 1);
  2511. keytype = AR5K_KEYTABLE_TYPE_104;
  2512. break;
  2513. /* WEP 128-bit = 128-bit entered key + 24 bit IV = 152-bit */
  2514. case 128 / 8:
  2515. memcpy(&key_v[0], &key->key[0], 6);
  2516. memcpy(&key_v[2], &key->key[6], 6);
  2517. memcpy(&key_v[4], &key->key[12], 4);
  2518. keytype = AR5K_KEYTABLE_TYPE_128;
  2519. break;
  2520. default:
  2521. return -EINVAL; /* shouldn't happen */
  2522. }
  2523. for (i = 0; i < ARRAY_SIZE(key_v); i++)
  2524. ath5k_hw_reg_write(ah, le32_to_cpu(key_v[i]),
  2525. AR5K_KEYTABLE_OFF(entry, i));
  2526. ath5k_hw_reg_write(ah, keytype, AR5K_KEYTABLE_TYPE(entry));
  2527. return ath5k_hw_set_key_lladdr(ah, entry, mac);
  2528. }
  2529. int ath5k_hw_set_key_lladdr(struct ath5k_hw *ah, u16 entry, const u8 *mac)
  2530. {
  2531. u32 low_id, high_id;
  2532. ATH5K_TRACE(ah->ah_sc);
  2533. /* Invalid entry (key table overflow) */
  2534. AR5K_ASSERT_ENTRY(entry, AR5K_KEYTABLE_SIZE);
  2535. /* MAC may be NULL if it's a broadcast key. In this case no need to
  2536. * to compute AR5K_LOW_ID and AR5K_HIGH_ID as we already know it. */
  2537. if (unlikely(mac == NULL)) {
  2538. low_id = 0xffffffff;
  2539. high_id = 0xffff | AR5K_KEYTABLE_VALID;
  2540. } else {
  2541. low_id = AR5K_LOW_ID(mac);
  2542. high_id = AR5K_HIGH_ID(mac) | AR5K_KEYTABLE_VALID;
  2543. }
  2544. ath5k_hw_reg_write(ah, low_id, AR5K_KEYTABLE_MAC0(entry));
  2545. ath5k_hw_reg_write(ah, high_id, AR5K_KEYTABLE_MAC1(entry));
  2546. return 0;
  2547. }
  2548. /********************************************\
  2549. Queue Control Unit, DFS Control Unit Functions
  2550. \********************************************/
  2551. /*
  2552. * Initialize a transmit queue
  2553. */
  2554. int ath5k_hw_setup_tx_queue(struct ath5k_hw *ah, enum ath5k_tx_queue queue_type,
  2555. struct ath5k_txq_info *queue_info)
  2556. {
  2557. unsigned int queue;
  2558. int ret;
  2559. ATH5K_TRACE(ah->ah_sc);
  2560. /*
  2561. * Get queue by type
  2562. */
  2563. /*5210 only has 2 queues*/
  2564. if (ah->ah_version == AR5K_AR5210) {
  2565. switch (queue_type) {
  2566. case AR5K_TX_QUEUE_DATA:
  2567. queue = AR5K_TX_QUEUE_ID_NOQCU_DATA;
  2568. break;
  2569. case AR5K_TX_QUEUE_BEACON:
  2570. case AR5K_TX_QUEUE_CAB:
  2571. queue = AR5K_TX_QUEUE_ID_NOQCU_BEACON;
  2572. break;
  2573. default:
  2574. return -EINVAL;
  2575. }
  2576. } else {
  2577. switch (queue_type) {
  2578. case AR5K_TX_QUEUE_DATA:
  2579. for (queue = AR5K_TX_QUEUE_ID_DATA_MIN;
  2580. ah->ah_txq[queue].tqi_type !=
  2581. AR5K_TX_QUEUE_INACTIVE; queue++) {
  2582. if (queue > AR5K_TX_QUEUE_ID_DATA_MAX)
  2583. return -EINVAL;
  2584. }
  2585. break;
  2586. case AR5K_TX_QUEUE_UAPSD:
  2587. queue = AR5K_TX_QUEUE_ID_UAPSD;
  2588. break;
  2589. case AR5K_TX_QUEUE_BEACON:
  2590. queue = AR5K_TX_QUEUE_ID_BEACON;
  2591. break;
  2592. case AR5K_TX_QUEUE_CAB:
  2593. queue = AR5K_TX_QUEUE_ID_CAB;
  2594. break;
  2595. case AR5K_TX_QUEUE_XR_DATA:
  2596. if (ah->ah_version != AR5K_AR5212)
  2597. ATH5K_ERR(ah->ah_sc,
  2598. "XR data queues only supported in"
  2599. " 5212!\n");
  2600. queue = AR5K_TX_QUEUE_ID_XR_DATA;
  2601. break;
  2602. default:
  2603. return -EINVAL;
  2604. }
  2605. }
  2606. /*
  2607. * Setup internal queue structure
  2608. */
  2609. memset(&ah->ah_txq[queue], 0, sizeof(struct ath5k_txq_info));
  2610. ah->ah_txq[queue].tqi_type = queue_type;
  2611. if (queue_info != NULL) {
  2612. queue_info->tqi_type = queue_type;
  2613. ret = ath5k_hw_setup_tx_queueprops(ah, queue, queue_info);
  2614. if (ret)
  2615. return ret;
  2616. }
  2617. /*
  2618. * We use ah_txq_status to hold a temp value for
  2619. * the Secondary interrupt mask registers on 5211+
  2620. * check out ath5k_hw_reset_tx_queue
  2621. */
  2622. AR5K_Q_ENABLE_BITS(ah->ah_txq_status, queue);
  2623. return queue;
  2624. }
  2625. /*
  2626. * Setup a transmit queue
  2627. */
  2628. int ath5k_hw_setup_tx_queueprops(struct ath5k_hw *ah, int queue,
  2629. const struct ath5k_txq_info *queue_info)
  2630. {
  2631. ATH5K_TRACE(ah->ah_sc);
  2632. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2633. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2634. return -EIO;
  2635. memcpy(&ah->ah_txq[queue], queue_info, sizeof(struct ath5k_txq_info));
  2636. /*XXX: Is this supported on 5210 ?*/
  2637. if ((queue_info->tqi_type == AR5K_TX_QUEUE_DATA &&
  2638. ((queue_info->tqi_subtype == AR5K_WME_AC_VI) ||
  2639. (queue_info->tqi_subtype == AR5K_WME_AC_VO))) ||
  2640. queue_info->tqi_type == AR5K_TX_QUEUE_UAPSD)
  2641. ah->ah_txq[queue].tqi_flags |= AR5K_TXQ_FLAG_POST_FR_BKOFF_DIS;
  2642. return 0;
  2643. }
  2644. /*
  2645. * Get properties for a specific transmit queue
  2646. */
  2647. int ath5k_hw_get_tx_queueprops(struct ath5k_hw *ah, int queue,
  2648. struct ath5k_txq_info *queue_info)
  2649. {
  2650. ATH5K_TRACE(ah->ah_sc);
  2651. memcpy(queue_info, &ah->ah_txq[queue], sizeof(struct ath5k_txq_info));
  2652. return 0;
  2653. }
  2654. /*
  2655. * Set a transmit queue inactive
  2656. */
  2657. void ath5k_hw_release_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2658. {
  2659. ATH5K_TRACE(ah->ah_sc);
  2660. if (WARN_ON(queue >= ah->ah_capabilities.cap_queues.q_tx_num))
  2661. return;
  2662. /* This queue will be skipped in further operations */
  2663. ah->ah_txq[queue].tqi_type = AR5K_TX_QUEUE_INACTIVE;
  2664. /*For SIMR setup*/
  2665. AR5K_Q_DISABLE_BITS(ah->ah_txq_status, queue);
  2666. }
  2667. /*
  2668. * Set DFS params for a transmit queue
  2669. */
  2670. int ath5k_hw_reset_tx_queue(struct ath5k_hw *ah, unsigned int queue)
  2671. {
  2672. u32 cw_min, cw_max, retry_lg, retry_sh;
  2673. struct ath5k_txq_info *tq = &ah->ah_txq[queue];
  2674. ATH5K_TRACE(ah->ah_sc);
  2675. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2676. tq = &ah->ah_txq[queue];
  2677. if (tq->tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2678. return 0;
  2679. if (ah->ah_version == AR5K_AR5210) {
  2680. /* Only handle data queues, others will be ignored */
  2681. if (tq->tqi_type != AR5K_TX_QUEUE_DATA)
  2682. return 0;
  2683. /* Set Slot time */
  2684. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2685. AR5K_INIT_SLOT_TIME_TURBO : AR5K_INIT_SLOT_TIME,
  2686. AR5K_SLOT_TIME);
  2687. /* Set ACK_CTS timeout */
  2688. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2689. AR5K_INIT_ACK_CTS_TIMEOUT_TURBO :
  2690. AR5K_INIT_ACK_CTS_TIMEOUT, AR5K_SLOT_TIME);
  2691. /* Set Transmit Latency */
  2692. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2693. AR5K_INIT_TRANSMIT_LATENCY_TURBO :
  2694. AR5K_INIT_TRANSMIT_LATENCY, AR5K_USEC_5210);
  2695. /* Set IFS0 */
  2696. if (ah->ah_turbo == true)
  2697. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS_TURBO +
  2698. (ah->ah_aifs + tq->tqi_aifs) *
  2699. AR5K_INIT_SLOT_TIME_TURBO) <<
  2700. AR5K_IFS0_DIFS_S) | AR5K_INIT_SIFS_TURBO,
  2701. AR5K_IFS0);
  2702. else
  2703. ath5k_hw_reg_write(ah, ((AR5K_INIT_SIFS +
  2704. (ah->ah_aifs + tq->tqi_aifs) *
  2705. AR5K_INIT_SLOT_TIME) << AR5K_IFS0_DIFS_S) |
  2706. AR5K_INIT_SIFS, AR5K_IFS0);
  2707. /* Set IFS1 */
  2708. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2709. AR5K_INIT_PROTO_TIME_CNTRL_TURBO :
  2710. AR5K_INIT_PROTO_TIME_CNTRL, AR5K_IFS1);
  2711. /* Set PHY register 0x9844 (??) */
  2712. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2713. (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x38 :
  2714. (ath5k_hw_reg_read(ah, AR5K_PHY(17)) & ~0x7F) | 0x1C,
  2715. AR5K_PHY(17));
  2716. /* Set Frame Control Register */
  2717. ath5k_hw_reg_write(ah, ah->ah_turbo == true ?
  2718. (AR5K_PHY_FRAME_CTL_INI | AR5K_PHY_TURBO_MODE |
  2719. AR5K_PHY_TURBO_SHORT | 0x2020) :
  2720. (AR5K_PHY_FRAME_CTL_INI | 0x1020),
  2721. AR5K_PHY_FRAME_CTL_5210);
  2722. }
  2723. /*
  2724. * Calculate cwmin/max by channel mode
  2725. */
  2726. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN;
  2727. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX;
  2728. ah->ah_aifs = AR5K_TUNE_AIFS;
  2729. /*XR is only supported on 5212*/
  2730. if (IS_CHAN_XR(ah->ah_current_channel) &&
  2731. ah->ah_version == AR5K_AR5212) {
  2732. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_XR;
  2733. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_XR;
  2734. ah->ah_aifs = AR5K_TUNE_AIFS_XR;
  2735. /*B mode is not supported on 5210*/
  2736. } else if (IS_CHAN_B(ah->ah_current_channel) &&
  2737. ah->ah_version != AR5K_AR5210) {
  2738. cw_min = ah->ah_cw_min = AR5K_TUNE_CWMIN_11B;
  2739. cw_max = ah->ah_cw_max = AR5K_TUNE_CWMAX_11B;
  2740. ah->ah_aifs = AR5K_TUNE_AIFS_11B;
  2741. }
  2742. cw_min = 1;
  2743. while (cw_min < ah->ah_cw_min)
  2744. cw_min = (cw_min << 1) | 1;
  2745. cw_min = tq->tqi_cw_min < 0 ? (cw_min >> (-tq->tqi_cw_min)) :
  2746. ((cw_min << tq->tqi_cw_min) + (1 << tq->tqi_cw_min) - 1);
  2747. cw_max = tq->tqi_cw_max < 0 ? (cw_max >> (-tq->tqi_cw_max)) :
  2748. ((cw_max << tq->tqi_cw_max) + (1 << tq->tqi_cw_max) - 1);
  2749. /*
  2750. * Calculate and set retry limits
  2751. */
  2752. if (ah->ah_software_retry == true) {
  2753. /* XXX Need to test this */
  2754. retry_lg = ah->ah_limit_tx_retries;
  2755. retry_sh = retry_lg = retry_lg > AR5K_DCU_RETRY_LMT_SH_RETRY ?
  2756. AR5K_DCU_RETRY_LMT_SH_RETRY : retry_lg;
  2757. } else {
  2758. retry_lg = AR5K_INIT_LG_RETRY;
  2759. retry_sh = AR5K_INIT_SH_RETRY;
  2760. }
  2761. /*No QCU/DCU [5210]*/
  2762. if (ah->ah_version == AR5K_AR5210) {
  2763. ath5k_hw_reg_write(ah,
  2764. (cw_min << AR5K_NODCU_RETRY_LMT_CW_MIN_S)
  2765. | AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2766. AR5K_NODCU_RETRY_LMT_SLG_RETRY)
  2767. | AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2768. AR5K_NODCU_RETRY_LMT_SSH_RETRY)
  2769. | AR5K_REG_SM(retry_lg, AR5K_NODCU_RETRY_LMT_LG_RETRY)
  2770. | AR5K_REG_SM(retry_sh, AR5K_NODCU_RETRY_LMT_SH_RETRY),
  2771. AR5K_NODCU_RETRY_LMT);
  2772. } else {
  2773. /*QCU/DCU [5211+]*/
  2774. ath5k_hw_reg_write(ah,
  2775. AR5K_REG_SM(AR5K_INIT_SLG_RETRY,
  2776. AR5K_DCU_RETRY_LMT_SLG_RETRY) |
  2777. AR5K_REG_SM(AR5K_INIT_SSH_RETRY,
  2778. AR5K_DCU_RETRY_LMT_SSH_RETRY) |
  2779. AR5K_REG_SM(retry_lg, AR5K_DCU_RETRY_LMT_LG_RETRY) |
  2780. AR5K_REG_SM(retry_sh, AR5K_DCU_RETRY_LMT_SH_RETRY),
  2781. AR5K_QUEUE_DFS_RETRY_LIMIT(queue));
  2782. /*===Rest is also for QCU/DCU only [5211+]===*/
  2783. /*
  2784. * Set initial content window (cw_min/cw_max)
  2785. * and arbitrated interframe space (aifs)...
  2786. */
  2787. ath5k_hw_reg_write(ah,
  2788. AR5K_REG_SM(cw_min, AR5K_DCU_LCL_IFS_CW_MIN) |
  2789. AR5K_REG_SM(cw_max, AR5K_DCU_LCL_IFS_CW_MAX) |
  2790. AR5K_REG_SM(ah->ah_aifs + tq->tqi_aifs,
  2791. AR5K_DCU_LCL_IFS_AIFS),
  2792. AR5K_QUEUE_DFS_LOCAL_IFS(queue));
  2793. /*
  2794. * Set misc registers
  2795. */
  2796. ath5k_hw_reg_write(ah, AR5K_QCU_MISC_DCU_EARLY,
  2797. AR5K_QUEUE_MISC(queue));
  2798. if (tq->tqi_cbr_period) {
  2799. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_cbr_period,
  2800. AR5K_QCU_CBRCFG_INTVAL) |
  2801. AR5K_REG_SM(tq->tqi_cbr_overflow_limit,
  2802. AR5K_QCU_CBRCFG_ORN_THRES),
  2803. AR5K_QUEUE_CBRCFG(queue));
  2804. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2805. AR5K_QCU_MISC_FRSHED_CBR);
  2806. if (tq->tqi_cbr_overflow_limit)
  2807. AR5K_REG_ENABLE_BITS(ah,
  2808. AR5K_QUEUE_MISC(queue),
  2809. AR5K_QCU_MISC_CBR_THRES_ENABLE);
  2810. }
  2811. if (tq->tqi_ready_time)
  2812. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_ready_time,
  2813. AR5K_QCU_RDYTIMECFG_INTVAL) |
  2814. AR5K_QCU_RDYTIMECFG_ENABLE,
  2815. AR5K_QUEUE_RDYTIMECFG(queue));
  2816. if (tq->tqi_burst_time) {
  2817. ath5k_hw_reg_write(ah, AR5K_REG_SM(tq->tqi_burst_time,
  2818. AR5K_DCU_CHAN_TIME_DUR) |
  2819. AR5K_DCU_CHAN_TIME_ENABLE,
  2820. AR5K_QUEUE_DFS_CHANNEL_TIME(queue));
  2821. if (tq->tqi_flags & AR5K_TXQ_FLAG_RDYTIME_EXP_POLICY_ENABLE)
  2822. AR5K_REG_ENABLE_BITS(ah,
  2823. AR5K_QUEUE_MISC(queue),
  2824. AR5K_QCU_MISC_TXE);
  2825. }
  2826. if (tq->tqi_flags & AR5K_TXQ_FLAG_BACKOFF_DISABLE)
  2827. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_POST_FR_BKOFF_DIS,
  2828. AR5K_QUEUE_DFS_MISC(queue));
  2829. if (tq->tqi_flags & AR5K_TXQ_FLAG_FRAG_BURST_BACKOFF_ENABLE)
  2830. ath5k_hw_reg_write(ah, AR5K_DCU_MISC_BACKOFF_FRAG,
  2831. AR5K_QUEUE_DFS_MISC(queue));
  2832. /*
  2833. * Set registers by queue type
  2834. */
  2835. switch (tq->tqi_type) {
  2836. case AR5K_TX_QUEUE_BEACON:
  2837. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2838. AR5K_QCU_MISC_FRSHED_DBA_GT |
  2839. AR5K_QCU_MISC_CBREXP_BCN |
  2840. AR5K_QCU_MISC_BCN_ENABLE);
  2841. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  2842. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  2843. AR5K_DCU_MISC_ARBLOCK_CTL_S) |
  2844. AR5K_DCU_MISC_POST_FR_BKOFF_DIS |
  2845. AR5K_DCU_MISC_BCN_ENABLE);
  2846. ath5k_hw_reg_write(ah, ((AR5K_TUNE_BEACON_INTERVAL -
  2847. (AR5K_TUNE_SW_BEACON_RESP -
  2848. AR5K_TUNE_DMA_BEACON_RESP) -
  2849. AR5K_TUNE_ADDITIONAL_SWBA_BACKOFF) * 1024) |
  2850. AR5K_QCU_RDYTIMECFG_ENABLE,
  2851. AR5K_QUEUE_RDYTIMECFG(queue));
  2852. break;
  2853. case AR5K_TX_QUEUE_CAB:
  2854. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2855. AR5K_QCU_MISC_FRSHED_DBA_GT |
  2856. AR5K_QCU_MISC_CBREXP |
  2857. AR5K_QCU_MISC_CBREXP_BCN);
  2858. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_DFS_MISC(queue),
  2859. (AR5K_DCU_MISC_ARBLOCK_CTL_GLOBAL <<
  2860. AR5K_DCU_MISC_ARBLOCK_CTL_S));
  2861. break;
  2862. case AR5K_TX_QUEUE_UAPSD:
  2863. AR5K_REG_ENABLE_BITS(ah, AR5K_QUEUE_MISC(queue),
  2864. AR5K_QCU_MISC_CBREXP);
  2865. break;
  2866. case AR5K_TX_QUEUE_DATA:
  2867. default:
  2868. break;
  2869. }
  2870. /*
  2871. * Enable interrupts for this tx queue
  2872. * in the secondary interrupt mask registers
  2873. */
  2874. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXOKINT_ENABLE)
  2875. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txok, queue);
  2876. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXERRINT_ENABLE)
  2877. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txerr, queue);
  2878. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXURNINT_ENABLE)
  2879. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txurn, queue);
  2880. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXDESCINT_ENABLE)
  2881. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txdesc, queue);
  2882. if (tq->tqi_flags & AR5K_TXQ_FLAG_TXEOLINT_ENABLE)
  2883. AR5K_Q_ENABLE_BITS(ah->ah_txq_imr_txeol, queue);
  2884. /* Update secondary interrupt mask registers */
  2885. ah->ah_txq_imr_txok &= ah->ah_txq_status;
  2886. ah->ah_txq_imr_txerr &= ah->ah_txq_status;
  2887. ah->ah_txq_imr_txurn &= ah->ah_txq_status;
  2888. ah->ah_txq_imr_txdesc &= ah->ah_txq_status;
  2889. ah->ah_txq_imr_txeol &= ah->ah_txq_status;
  2890. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txok,
  2891. AR5K_SIMR0_QCU_TXOK) |
  2892. AR5K_REG_SM(ah->ah_txq_imr_txdesc,
  2893. AR5K_SIMR0_QCU_TXDESC), AR5K_SIMR0);
  2894. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txerr,
  2895. AR5K_SIMR1_QCU_TXERR) |
  2896. AR5K_REG_SM(ah->ah_txq_imr_txeol,
  2897. AR5K_SIMR1_QCU_TXEOL), AR5K_SIMR1);
  2898. ath5k_hw_reg_write(ah, AR5K_REG_SM(ah->ah_txq_imr_txurn,
  2899. AR5K_SIMR2_QCU_TXURN), AR5K_SIMR2);
  2900. }
  2901. return 0;
  2902. }
  2903. /*
  2904. * Get number of pending frames
  2905. * for a specific queue [5211+]
  2906. */
  2907. u32 ath5k_hw_num_tx_pending(struct ath5k_hw *ah, unsigned int queue) {
  2908. ATH5K_TRACE(ah->ah_sc);
  2909. AR5K_ASSERT_ENTRY(queue, ah->ah_capabilities.cap_queues.q_tx_num);
  2910. /* Return if queue is declared inactive */
  2911. if (ah->ah_txq[queue].tqi_type == AR5K_TX_QUEUE_INACTIVE)
  2912. return false;
  2913. /* XXX: How about AR5K_CFG_TXCNT ? */
  2914. if (ah->ah_version == AR5K_AR5210)
  2915. return false;
  2916. return AR5K_QUEUE_STATUS(queue) & AR5K_QCU_STS_FRMPENDCNT;
  2917. }
  2918. /*
  2919. * Set slot time
  2920. */
  2921. int ath5k_hw_set_slot_time(struct ath5k_hw *ah, unsigned int slot_time)
  2922. {
  2923. ATH5K_TRACE(ah->ah_sc);
  2924. if (slot_time < AR5K_SLOT_TIME_9 || slot_time > AR5K_SLOT_TIME_MAX)
  2925. return -EINVAL;
  2926. if (ah->ah_version == AR5K_AR5210)
  2927. ath5k_hw_reg_write(ah, ath5k_hw_htoclock(slot_time,
  2928. ah->ah_turbo), AR5K_SLOT_TIME);
  2929. else
  2930. ath5k_hw_reg_write(ah, slot_time, AR5K_DCU_GBL_IFS_SLOT);
  2931. return 0;
  2932. }
  2933. /*
  2934. * Get slot time
  2935. */
  2936. unsigned int ath5k_hw_get_slot_time(struct ath5k_hw *ah)
  2937. {
  2938. ATH5K_TRACE(ah->ah_sc);
  2939. if (ah->ah_version == AR5K_AR5210)
  2940. return ath5k_hw_clocktoh(ath5k_hw_reg_read(ah,
  2941. AR5K_SLOT_TIME) & 0xffff, ah->ah_turbo);
  2942. else
  2943. return ath5k_hw_reg_read(ah, AR5K_DCU_GBL_IFS_SLOT) & 0xffff;
  2944. }
  2945. /******************************\
  2946. Hardware Descriptor Functions
  2947. \******************************/
  2948. /*
  2949. * TX Descriptor
  2950. */
  2951. /*
  2952. * Initialize the 2-word tx descriptor on 5210/5211
  2953. */
  2954. static int
  2955. ath5k_hw_setup_2word_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  2956. unsigned int pkt_len, unsigned int hdr_len, enum ath5k_pkt_type type,
  2957. unsigned int tx_power, unsigned int tx_rate0, unsigned int tx_tries0,
  2958. unsigned int key_index, unsigned int antenna_mode, unsigned int flags,
  2959. unsigned int rtscts_rate, unsigned int rtscts_duration)
  2960. {
  2961. u32 frame_type;
  2962. struct ath5k_hw_2w_tx_desc *tx_desc;
  2963. unsigned int frame_len;
  2964. tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
  2965. /*
  2966. * Validate input
  2967. * - Zero retries don't make sense.
  2968. * - A zero rate will put the HW into a mode where it continously sends
  2969. * noise on the channel, so it is important to avoid this.
  2970. */
  2971. if (unlikely(tx_tries0 == 0)) {
  2972. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  2973. WARN_ON(1);
  2974. return -EINVAL;
  2975. }
  2976. if (unlikely(tx_rate0 == 0)) {
  2977. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  2978. WARN_ON(1);
  2979. return -EINVAL;
  2980. }
  2981. /* Clear status descriptor */
  2982. memset(desc->ds_hw, 0, sizeof(struct ath5k_hw_tx_status));
  2983. /* Initialize control descriptor */
  2984. tx_desc->tx_control_0 = 0;
  2985. tx_desc->tx_control_1 = 0;
  2986. /* Setup control descriptor */
  2987. /* Verify and set frame length */
  2988. /* remove padding we might have added before */
  2989. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  2990. if (frame_len & ~AR5K_2W_TX_DESC_CTL0_FRAME_LEN)
  2991. return -EINVAL;
  2992. tx_desc->tx_control_0 = frame_len & AR5K_2W_TX_DESC_CTL0_FRAME_LEN;
  2993. /* Verify and set buffer length */
  2994. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  2995. if(type == AR5K_PKT_TYPE_BEACON)
  2996. pkt_len = roundup(pkt_len, 4);
  2997. if (pkt_len & ~AR5K_2W_TX_DESC_CTL1_BUF_LEN)
  2998. return -EINVAL;
  2999. tx_desc->tx_control_1 = pkt_len & AR5K_2W_TX_DESC_CTL1_BUF_LEN;
  3000. /*
  3001. * Verify and set header length
  3002. * XXX: I only found that on 5210 code, does it work on 5211 ?
  3003. */
  3004. if (ah->ah_version == AR5K_AR5210) {
  3005. if (hdr_len & ~AR5K_2W_TX_DESC_CTL0_HEADER_LEN)
  3006. return -EINVAL;
  3007. tx_desc->tx_control_0 |=
  3008. AR5K_REG_SM(hdr_len, AR5K_2W_TX_DESC_CTL0_HEADER_LEN);
  3009. }
  3010. /*Diferences between 5210-5211*/
  3011. if (ah->ah_version == AR5K_AR5210) {
  3012. switch (type) {
  3013. case AR5K_PKT_TYPE_BEACON:
  3014. case AR5K_PKT_TYPE_PROBE_RESP:
  3015. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_NO_DELAY;
  3016. case AR5K_PKT_TYPE_PIFS:
  3017. frame_type = AR5K_AR5210_TX_DESC_FRAME_TYPE_PIFS;
  3018. default:
  3019. frame_type = type /*<< 2 ?*/;
  3020. }
  3021. tx_desc->tx_control_0 |=
  3022. AR5K_REG_SM(frame_type, AR5K_2W_TX_DESC_CTL0_FRAME_TYPE) |
  3023. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  3024. } else {
  3025. tx_desc->tx_control_0 |=
  3026. AR5K_REG_SM(tx_rate0, AR5K_2W_TX_DESC_CTL0_XMIT_RATE) |
  3027. AR5K_REG_SM(antenna_mode, AR5K_2W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3028. tx_desc->tx_control_1 |=
  3029. AR5K_REG_SM(type, AR5K_2W_TX_DESC_CTL1_FRAME_TYPE);
  3030. }
  3031. #define _TX_FLAGS(_c, _flag) \
  3032. if (flags & AR5K_TXDESC_##_flag) \
  3033. tx_desc->tx_control_##_c |= \
  3034. AR5K_2W_TX_DESC_CTL##_c##_##_flag
  3035. _TX_FLAGS(0, CLRDMASK);
  3036. _TX_FLAGS(0, VEOL);
  3037. _TX_FLAGS(0, INTREQ);
  3038. _TX_FLAGS(0, RTSENA);
  3039. _TX_FLAGS(1, NOACK);
  3040. #undef _TX_FLAGS
  3041. /*
  3042. * WEP crap
  3043. */
  3044. if (key_index != AR5K_TXKEYIX_INVALID) {
  3045. tx_desc->tx_control_0 |=
  3046. AR5K_2W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3047. tx_desc->tx_control_1 |=
  3048. AR5K_REG_SM(key_index,
  3049. AR5K_2W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3050. }
  3051. /*
  3052. * RTS/CTS Duration [5210 ?]
  3053. */
  3054. if ((ah->ah_version == AR5K_AR5210) &&
  3055. (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)))
  3056. tx_desc->tx_control_1 |= rtscts_duration &
  3057. AR5K_2W_TX_DESC_CTL1_RTS_DURATION;
  3058. return 0;
  3059. }
  3060. /*
  3061. * Initialize the 4-word tx descriptor on 5212
  3062. */
  3063. static int ath5k_hw_setup_4word_tx_desc(struct ath5k_hw *ah,
  3064. struct ath5k_desc *desc, unsigned int pkt_len, unsigned int hdr_len,
  3065. enum ath5k_pkt_type type, unsigned int tx_power, unsigned int tx_rate0,
  3066. unsigned int tx_tries0, unsigned int key_index,
  3067. unsigned int antenna_mode, unsigned int flags, unsigned int rtscts_rate,
  3068. unsigned int rtscts_duration)
  3069. {
  3070. struct ath5k_hw_4w_tx_desc *tx_desc;
  3071. struct ath5k_hw_tx_status *tx_status;
  3072. unsigned int frame_len;
  3073. ATH5K_TRACE(ah->ah_sc);
  3074. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3075. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
  3076. /*
  3077. * Validate input
  3078. * - Zero retries don't make sense.
  3079. * - A zero rate will put the HW into a mode where it continously sends
  3080. * noise on the channel, so it is important to avoid this.
  3081. */
  3082. if (unlikely(tx_tries0 == 0)) {
  3083. ATH5K_ERR(ah->ah_sc, "zero retries\n");
  3084. WARN_ON(1);
  3085. return -EINVAL;
  3086. }
  3087. if (unlikely(tx_rate0 == 0)) {
  3088. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3089. WARN_ON(1);
  3090. return -EINVAL;
  3091. }
  3092. /* Clear status descriptor */
  3093. memset(tx_status, 0, sizeof(struct ath5k_hw_tx_status));
  3094. /* Initialize control descriptor */
  3095. tx_desc->tx_control_0 = 0;
  3096. tx_desc->tx_control_1 = 0;
  3097. tx_desc->tx_control_2 = 0;
  3098. tx_desc->tx_control_3 = 0;
  3099. /* Setup control descriptor */
  3100. /* Verify and set frame length */
  3101. /* remove padding we might have added before */
  3102. frame_len = pkt_len - (hdr_len & 3) + FCS_LEN;
  3103. if (frame_len & ~AR5K_4W_TX_DESC_CTL0_FRAME_LEN)
  3104. return -EINVAL;
  3105. tx_desc->tx_control_0 = frame_len & AR5K_4W_TX_DESC_CTL0_FRAME_LEN;
  3106. /* Verify and set buffer length */
  3107. /* NB: beacon's BufLen must be a multiple of 4 bytes */
  3108. if(type == AR5K_PKT_TYPE_BEACON)
  3109. pkt_len = roundup(pkt_len, 4);
  3110. if (pkt_len & ~AR5K_4W_TX_DESC_CTL1_BUF_LEN)
  3111. return -EINVAL;
  3112. tx_desc->tx_control_1 = pkt_len & AR5K_4W_TX_DESC_CTL1_BUF_LEN;
  3113. tx_desc->tx_control_0 |=
  3114. AR5K_REG_SM(tx_power, AR5K_4W_TX_DESC_CTL0_XMIT_POWER) |
  3115. AR5K_REG_SM(antenna_mode, AR5K_4W_TX_DESC_CTL0_ANT_MODE_XMIT);
  3116. tx_desc->tx_control_1 |= AR5K_REG_SM(type,
  3117. AR5K_4W_TX_DESC_CTL1_FRAME_TYPE);
  3118. tx_desc->tx_control_2 = AR5K_REG_SM(tx_tries0 + AR5K_TUNE_HWTXTRIES,
  3119. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES0);
  3120. tx_desc->tx_control_3 = tx_rate0 & AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3121. #define _TX_FLAGS(_c, _flag) \
  3122. if (flags & AR5K_TXDESC_##_flag) \
  3123. tx_desc->tx_control_##_c |= \
  3124. AR5K_4W_TX_DESC_CTL##_c##_##_flag
  3125. _TX_FLAGS(0, CLRDMASK);
  3126. _TX_FLAGS(0, VEOL);
  3127. _TX_FLAGS(0, INTREQ);
  3128. _TX_FLAGS(0, RTSENA);
  3129. _TX_FLAGS(0, CTSENA);
  3130. _TX_FLAGS(1, NOACK);
  3131. #undef _TX_FLAGS
  3132. /*
  3133. * WEP crap
  3134. */
  3135. if (key_index != AR5K_TXKEYIX_INVALID) {
  3136. tx_desc->tx_control_0 |= AR5K_4W_TX_DESC_CTL0_ENCRYPT_KEY_VALID;
  3137. tx_desc->tx_control_1 |= AR5K_REG_SM(key_index,
  3138. AR5K_4W_TX_DESC_CTL1_ENCRYPT_KEY_INDEX);
  3139. }
  3140. /*
  3141. * RTS/CTS
  3142. */
  3143. if (flags & (AR5K_TXDESC_RTSENA | AR5K_TXDESC_CTSENA)) {
  3144. if ((flags & AR5K_TXDESC_RTSENA) &&
  3145. (flags & AR5K_TXDESC_CTSENA))
  3146. return -EINVAL;
  3147. tx_desc->tx_control_2 |= rtscts_duration &
  3148. AR5K_4W_TX_DESC_CTL2_RTS_DURATION;
  3149. tx_desc->tx_control_3 |= AR5K_REG_SM(rtscts_rate,
  3150. AR5K_4W_TX_DESC_CTL3_RTS_CTS_RATE);
  3151. }
  3152. return 0;
  3153. }
  3154. /*
  3155. * Initialize a 4-word multirate tx descriptor on 5212
  3156. */
  3157. static int
  3158. ath5k_hw_setup_xr_tx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3159. unsigned int tx_rate1, u_int tx_tries1, u_int tx_rate2, u_int tx_tries2,
  3160. unsigned int tx_rate3, u_int tx_tries3)
  3161. {
  3162. struct ath5k_hw_4w_tx_desc *tx_desc;
  3163. /*
  3164. * Rates can be 0 as long as the retry count is 0 too.
  3165. * A zero rate and nonzero retry count will put the HW into a mode where
  3166. * it continously sends noise on the channel, so it is important to
  3167. * avoid this.
  3168. */
  3169. if (unlikely((tx_rate1 == 0 && tx_tries1 != 0) ||
  3170. (tx_rate2 == 0 && tx_tries2 != 0) ||
  3171. (tx_rate3 == 0 && tx_tries3 != 0))) {
  3172. ATH5K_ERR(ah->ah_sc, "zero rate\n");
  3173. WARN_ON(1);
  3174. return -EINVAL;
  3175. }
  3176. if (ah->ah_version == AR5K_AR5212) {
  3177. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3178. #define _XTX_TRIES(_n) \
  3179. if (tx_tries##_n) { \
  3180. tx_desc->tx_control_2 |= \
  3181. AR5K_REG_SM(tx_tries##_n, \
  3182. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES##_n); \
  3183. tx_desc->tx_control_3 |= \
  3184. AR5K_REG_SM(tx_rate##_n, \
  3185. AR5K_4W_TX_DESC_CTL3_XMIT_RATE##_n); \
  3186. }
  3187. _XTX_TRIES(1);
  3188. _XTX_TRIES(2);
  3189. _XTX_TRIES(3);
  3190. #undef _XTX_TRIES
  3191. return 1;
  3192. }
  3193. return 0;
  3194. }
  3195. /*
  3196. * Proccess the tx status descriptor on 5210/5211
  3197. */
  3198. static int ath5k_hw_proc_2word_tx_status(struct ath5k_hw *ah,
  3199. struct ath5k_desc *desc)
  3200. {
  3201. struct ath5k_hw_tx_status *tx_status;
  3202. struct ath5k_hw_2w_tx_desc *tx_desc;
  3203. tx_desc = (struct ath5k_hw_2w_tx_desc *)&desc->ds_ctl0;
  3204. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[0];
  3205. /* No frame has been send or error */
  3206. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3207. return -EINPROGRESS;
  3208. /*
  3209. * Get descriptor status
  3210. */
  3211. desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3212. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3213. desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3214. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3215. desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3216. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3217. /*TODO: desc->ds_us.tx.ts_virtcol + test*/
  3218. desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3219. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3220. desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3221. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3222. desc->ds_us.tx.ts_antenna = 1;
  3223. desc->ds_us.tx.ts_status = 0;
  3224. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_0,
  3225. AR5K_2W_TX_DESC_CTL0_XMIT_RATE);
  3226. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3227. if (tx_status->tx_status_0 &
  3228. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3229. desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
  3230. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3231. desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
  3232. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3233. desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
  3234. }
  3235. return 0;
  3236. }
  3237. /*
  3238. * Proccess a tx descriptor on 5212
  3239. */
  3240. static int ath5k_hw_proc_4word_tx_status(struct ath5k_hw *ah,
  3241. struct ath5k_desc *desc)
  3242. {
  3243. struct ath5k_hw_tx_status *tx_status;
  3244. struct ath5k_hw_4w_tx_desc *tx_desc;
  3245. ATH5K_TRACE(ah->ah_sc);
  3246. tx_desc = (struct ath5k_hw_4w_tx_desc *)&desc->ds_ctl0;
  3247. tx_status = (struct ath5k_hw_tx_status *)&desc->ds_hw[2];
  3248. /* No frame has been send or error */
  3249. if (unlikely((tx_status->tx_status_1 & AR5K_DESC_TX_STATUS1_DONE) == 0))
  3250. return -EINPROGRESS;
  3251. /*
  3252. * Get descriptor status
  3253. */
  3254. desc->ds_us.tx.ts_tstamp = AR5K_REG_MS(tx_status->tx_status_0,
  3255. AR5K_DESC_TX_STATUS0_SEND_TIMESTAMP);
  3256. desc->ds_us.tx.ts_shortretry = AR5K_REG_MS(tx_status->tx_status_0,
  3257. AR5K_DESC_TX_STATUS0_SHORT_RETRY_COUNT);
  3258. desc->ds_us.tx.ts_longretry = AR5K_REG_MS(tx_status->tx_status_0,
  3259. AR5K_DESC_TX_STATUS0_LONG_RETRY_COUNT);
  3260. desc->ds_us.tx.ts_seqnum = AR5K_REG_MS(tx_status->tx_status_1,
  3261. AR5K_DESC_TX_STATUS1_SEQ_NUM);
  3262. desc->ds_us.tx.ts_rssi = AR5K_REG_MS(tx_status->tx_status_1,
  3263. AR5K_DESC_TX_STATUS1_ACK_SIG_STRENGTH);
  3264. desc->ds_us.tx.ts_antenna = (tx_status->tx_status_1 &
  3265. AR5K_DESC_TX_STATUS1_XMIT_ANTENNA) ? 2 : 1;
  3266. desc->ds_us.tx.ts_status = 0;
  3267. switch (AR5K_REG_MS(tx_status->tx_status_1,
  3268. AR5K_DESC_TX_STATUS1_FINAL_TS_INDEX)) {
  3269. case 0:
  3270. desc->ds_us.tx.ts_rate = tx_desc->tx_control_3 &
  3271. AR5K_4W_TX_DESC_CTL3_XMIT_RATE0;
  3272. break;
  3273. case 1:
  3274. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3275. AR5K_4W_TX_DESC_CTL3_XMIT_RATE1);
  3276. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3277. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES1);
  3278. break;
  3279. case 2:
  3280. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3281. AR5K_4W_TX_DESC_CTL3_XMIT_RATE2);
  3282. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3283. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES2);
  3284. break;
  3285. case 3:
  3286. desc->ds_us.tx.ts_rate = AR5K_REG_MS(tx_desc->tx_control_3,
  3287. AR5K_4W_TX_DESC_CTL3_XMIT_RATE3);
  3288. desc->ds_us.tx.ts_longretry +=AR5K_REG_MS(tx_desc->tx_control_2,
  3289. AR5K_4W_TX_DESC_CTL2_XMIT_TRIES3);
  3290. break;
  3291. }
  3292. if ((tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FRAME_XMIT_OK) == 0){
  3293. if (tx_status->tx_status_0 &
  3294. AR5K_DESC_TX_STATUS0_EXCESSIVE_RETRIES)
  3295. desc->ds_us.tx.ts_status |= AR5K_TXERR_XRETRY;
  3296. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FIFO_UNDERRUN)
  3297. desc->ds_us.tx.ts_status |= AR5K_TXERR_FIFO;
  3298. if (tx_status->tx_status_0 & AR5K_DESC_TX_STATUS0_FILTERED)
  3299. desc->ds_us.tx.ts_status |= AR5K_TXERR_FILT;
  3300. }
  3301. return 0;
  3302. }
  3303. /*
  3304. * RX Descriptor
  3305. */
  3306. /*
  3307. * Initialize an rx descriptor
  3308. */
  3309. int ath5k_hw_setup_rx_desc(struct ath5k_hw *ah, struct ath5k_desc *desc,
  3310. u32 size, unsigned int flags)
  3311. {
  3312. struct ath5k_rx_desc *rx_desc;
  3313. ATH5K_TRACE(ah->ah_sc);
  3314. rx_desc = (struct ath5k_rx_desc *)&desc->ds_ctl0;
  3315. /*
  3316. *Clear ds_hw
  3317. * If we don't clean the status descriptor,
  3318. * while scanning we get too many results,
  3319. * most of them virtual, after some secs
  3320. * of scanning system hangs. M.F.
  3321. */
  3322. memset(desc->ds_hw, 0, sizeof(desc->ds_hw));
  3323. /*Initialize rx descriptor*/
  3324. rx_desc->rx_control_0 = 0;
  3325. rx_desc->rx_control_1 = 0;
  3326. /* Setup descriptor */
  3327. rx_desc->rx_control_1 = size & AR5K_DESC_RX_CTL1_BUF_LEN;
  3328. if (unlikely(rx_desc->rx_control_1 != size))
  3329. return -EINVAL;
  3330. if (flags & AR5K_RXDESC_INTREQ)
  3331. rx_desc->rx_control_1 |= AR5K_DESC_RX_CTL1_INTREQ;
  3332. return 0;
  3333. }
  3334. /*
  3335. * Proccess the rx status descriptor on 5210/5211
  3336. */
  3337. static int ath5k_hw_proc_old_rx_status(struct ath5k_hw *ah,
  3338. struct ath5k_desc *desc)
  3339. {
  3340. struct ath5k_hw_old_rx_status *rx_status;
  3341. rx_status = (struct ath5k_hw_old_rx_status *)&desc->ds_hw[0];
  3342. /* No frame received / not ready */
  3343. if (unlikely((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_DONE)
  3344. == 0))
  3345. return -EINPROGRESS;
  3346. /*
  3347. * Frame receive status
  3348. */
  3349. desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
  3350. AR5K_OLD_RX_DESC_STATUS0_DATA_LEN;
  3351. desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3352. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3353. desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3354. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_RATE);
  3355. desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
  3356. AR5K_OLD_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3357. desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
  3358. AR5K_OLD_RX_DESC_STATUS0_MORE;
  3359. desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3360. AR5K_OLD_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3361. desc->ds_us.rx.rs_status = 0;
  3362. /*
  3363. * Key table status
  3364. */
  3365. if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3366. desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3367. AR5K_OLD_RX_DESC_STATUS1_KEY_INDEX);
  3368. else
  3369. desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
  3370. /*
  3371. * Receive/descriptor errors
  3372. */
  3373. if ((rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_FRAME_RECEIVE_OK)
  3374. == 0) {
  3375. if (rx_status->rx_status_1 & AR5K_OLD_RX_DESC_STATUS1_CRC_ERROR)
  3376. desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
  3377. if (rx_status->rx_status_1 &
  3378. AR5K_OLD_RX_DESC_STATUS1_FIFO_OVERRUN)
  3379. desc->ds_us.rx.rs_status |= AR5K_RXERR_FIFO;
  3380. if (rx_status->rx_status_1 &
  3381. AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR) {
  3382. desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
  3383. desc->ds_us.rx.rs_phyerr =
  3384. AR5K_REG_MS(rx_status->rx_status_1,
  3385. AR5K_OLD_RX_DESC_STATUS1_PHY_ERROR);
  3386. }
  3387. if (rx_status->rx_status_1 &
  3388. AR5K_OLD_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3389. desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
  3390. }
  3391. return 0;
  3392. }
  3393. /*
  3394. * Proccess the rx status descriptor on 5212
  3395. */
  3396. static int ath5k_hw_proc_new_rx_status(struct ath5k_hw *ah,
  3397. struct ath5k_desc *desc)
  3398. {
  3399. struct ath5k_hw_new_rx_status *rx_status;
  3400. struct ath5k_hw_rx_error *rx_err;
  3401. ATH5K_TRACE(ah->ah_sc);
  3402. rx_status = (struct ath5k_hw_new_rx_status *)&desc->ds_hw[0];
  3403. /* Overlay on error */
  3404. rx_err = (struct ath5k_hw_rx_error *)&desc->ds_hw[0];
  3405. /* No frame received / not ready */
  3406. if (unlikely((rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_DONE)
  3407. == 0))
  3408. return -EINPROGRESS;
  3409. /*
  3410. * Frame receive status
  3411. */
  3412. desc->ds_us.rx.rs_datalen = rx_status->rx_status_0 &
  3413. AR5K_NEW_RX_DESC_STATUS0_DATA_LEN;
  3414. desc->ds_us.rx.rs_rssi = AR5K_REG_MS(rx_status->rx_status_0,
  3415. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_SIGNAL);
  3416. desc->ds_us.rx.rs_rate = AR5K_REG_MS(rx_status->rx_status_0,
  3417. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_RATE);
  3418. desc->ds_us.rx.rs_antenna = rx_status->rx_status_0 &
  3419. AR5K_NEW_RX_DESC_STATUS0_RECEIVE_ANTENNA;
  3420. desc->ds_us.rx.rs_more = rx_status->rx_status_0 &
  3421. AR5K_NEW_RX_DESC_STATUS0_MORE;
  3422. desc->ds_us.rx.rs_tstamp = AR5K_REG_MS(rx_status->rx_status_1,
  3423. AR5K_NEW_RX_DESC_STATUS1_RECEIVE_TIMESTAMP);
  3424. desc->ds_us.rx.rs_status = 0;
  3425. /*
  3426. * Key table status
  3427. */
  3428. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX_VALID)
  3429. desc->ds_us.rx.rs_keyix = AR5K_REG_MS(rx_status->rx_status_1,
  3430. AR5K_NEW_RX_DESC_STATUS1_KEY_INDEX);
  3431. else
  3432. desc->ds_us.rx.rs_keyix = AR5K_RXKEYIX_INVALID;
  3433. /*
  3434. * Receive/descriptor errors
  3435. */
  3436. if ((rx_status->rx_status_1 &
  3437. AR5K_NEW_RX_DESC_STATUS1_FRAME_RECEIVE_OK) == 0) {
  3438. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_CRC_ERROR)
  3439. desc->ds_us.rx.rs_status |= AR5K_RXERR_CRC;
  3440. if (rx_status->rx_status_1 &
  3441. AR5K_NEW_RX_DESC_STATUS1_PHY_ERROR) {
  3442. desc->ds_us.rx.rs_status |= AR5K_RXERR_PHY;
  3443. desc->ds_us.rx.rs_phyerr =
  3444. AR5K_REG_MS(rx_err->rx_error_1,
  3445. AR5K_RX_DESC_ERROR1_PHY_ERROR_CODE);
  3446. }
  3447. if (rx_status->rx_status_1 &
  3448. AR5K_NEW_RX_DESC_STATUS1_DECRYPT_CRC_ERROR)
  3449. desc->ds_us.rx.rs_status |= AR5K_RXERR_DECRYPT;
  3450. if (rx_status->rx_status_1 & AR5K_NEW_RX_DESC_STATUS1_MIC_ERROR)
  3451. desc->ds_us.rx.rs_status |= AR5K_RXERR_MIC;
  3452. }
  3453. return 0;
  3454. }
  3455. /****************\
  3456. GPIO Functions
  3457. \****************/
  3458. /*
  3459. * Set led state
  3460. */
  3461. void ath5k_hw_set_ledstate(struct ath5k_hw *ah, unsigned int state)
  3462. {
  3463. u32 led;
  3464. /*5210 has different led mode handling*/
  3465. u32 led_5210;
  3466. ATH5K_TRACE(ah->ah_sc);
  3467. /*Reset led status*/
  3468. if (ah->ah_version != AR5K_AR5210)
  3469. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
  3470. AR5K_PCICFG_LEDMODE | AR5K_PCICFG_LED);
  3471. else
  3472. AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG, AR5K_PCICFG_LED);
  3473. /*
  3474. * Some blinking values, define at your wish
  3475. */
  3476. switch (state) {
  3477. case AR5K_LED_SCAN:
  3478. case AR5K_LED_AUTH:
  3479. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_PEND;
  3480. led_5210 = AR5K_PCICFG_LED_PEND | AR5K_PCICFG_LED_BCTL;
  3481. break;
  3482. case AR5K_LED_INIT:
  3483. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_NONE;
  3484. led_5210 = AR5K_PCICFG_LED_PEND;
  3485. break;
  3486. case AR5K_LED_ASSOC:
  3487. case AR5K_LED_RUN:
  3488. led = AR5K_PCICFG_LEDMODE_PROP | AR5K_PCICFG_LED_ASSOC;
  3489. led_5210 = AR5K_PCICFG_LED_ASSOC;
  3490. break;
  3491. default:
  3492. led = AR5K_PCICFG_LEDMODE_PROM | AR5K_PCICFG_LED_NONE;
  3493. led_5210 = AR5K_PCICFG_LED_PEND;
  3494. break;
  3495. }
  3496. /*Write new status to the register*/
  3497. if (ah->ah_version != AR5K_AR5210)
  3498. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led);
  3499. else
  3500. AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, led_5210);
  3501. }
  3502. /*
  3503. * Set GPIO outputs
  3504. */
  3505. int ath5k_hw_set_gpio_output(struct ath5k_hw *ah, u32 gpio)
  3506. {
  3507. ATH5K_TRACE(ah->ah_sc);
  3508. if (gpio > AR5K_NUM_GPIO)
  3509. return -EINVAL;
  3510. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3511. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_OUT(gpio), AR5K_GPIOCR);
  3512. return 0;
  3513. }
  3514. /*
  3515. * Set GPIO inputs
  3516. */
  3517. int ath5k_hw_set_gpio_input(struct ath5k_hw *ah, u32 gpio)
  3518. {
  3519. ATH5K_TRACE(ah->ah_sc);
  3520. if (gpio > AR5K_NUM_GPIO)
  3521. return -EINVAL;
  3522. ath5k_hw_reg_write(ah, (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &~
  3523. AR5K_GPIOCR_OUT(gpio)) | AR5K_GPIOCR_IN(gpio), AR5K_GPIOCR);
  3524. return 0;
  3525. }
  3526. /*
  3527. * Get GPIO state
  3528. */
  3529. u32 ath5k_hw_get_gpio(struct ath5k_hw *ah, u32 gpio)
  3530. {
  3531. ATH5K_TRACE(ah->ah_sc);
  3532. if (gpio > AR5K_NUM_GPIO)
  3533. return 0xffffffff;
  3534. /* GPIO input magic */
  3535. return ((ath5k_hw_reg_read(ah, AR5K_GPIODI) & AR5K_GPIODI_M) >> gpio) &
  3536. 0x1;
  3537. }
  3538. /*
  3539. * Set GPIO state
  3540. */
  3541. int ath5k_hw_set_gpio(struct ath5k_hw *ah, u32 gpio, u32 val)
  3542. {
  3543. u32 data;
  3544. ATH5K_TRACE(ah->ah_sc);
  3545. if (gpio > AR5K_NUM_GPIO)
  3546. return -EINVAL;
  3547. /* GPIO output magic */
  3548. data = ath5k_hw_reg_read(ah, AR5K_GPIODO);
  3549. data &= ~(1 << gpio);
  3550. data |= (val & 1) << gpio;
  3551. ath5k_hw_reg_write(ah, data, AR5K_GPIODO);
  3552. return 0;
  3553. }
  3554. /*
  3555. * Initialize the GPIO interrupt (RFKill switch)
  3556. */
  3557. void ath5k_hw_set_gpio_intr(struct ath5k_hw *ah, unsigned int gpio,
  3558. u32 interrupt_level)
  3559. {
  3560. u32 data;
  3561. ATH5K_TRACE(ah->ah_sc);
  3562. if (gpio > AR5K_NUM_GPIO)
  3563. return;
  3564. /*
  3565. * Set the GPIO interrupt
  3566. */
  3567. data = (ath5k_hw_reg_read(ah, AR5K_GPIOCR) &
  3568. ~(AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_SELH |
  3569. AR5K_GPIOCR_INT_ENA | AR5K_GPIOCR_OUT(gpio))) |
  3570. (AR5K_GPIOCR_INT_SEL(gpio) | AR5K_GPIOCR_INT_ENA);
  3571. ath5k_hw_reg_write(ah, interrupt_level ? data :
  3572. (data | AR5K_GPIOCR_INT_SELH), AR5K_GPIOCR);
  3573. ah->ah_imr |= AR5K_IMR_GPIO;
  3574. /* Enable GPIO interrupts */
  3575. AR5K_REG_ENABLE_BITS(ah, AR5K_PIMR, AR5K_IMR_GPIO);
  3576. }
  3577. /*********************************\
  3578. Regulatory Domain/Channels Setup
  3579. \*********************************/
  3580. u16 ath5k_get_regdomain(struct ath5k_hw *ah)
  3581. {
  3582. u16 regdomain;
  3583. enum ath5k_regdom ieee_regdomain;
  3584. #ifdef COUNTRYCODE
  3585. u16 code;
  3586. #endif
  3587. ath5k_eeprom_regulation_domain(ah, false, &ieee_regdomain);
  3588. ah->ah_capabilities.cap_regdomain.reg_hw = ieee_regdomain;
  3589. #ifdef COUNTRYCODE
  3590. /*
  3591. * Get the regulation domain by country code. This will ignore
  3592. * the settings found in the EEPROM.
  3593. */
  3594. code = ieee80211_name2countrycode(COUNTRYCODE);
  3595. ieee_regdomain = ieee80211_countrycode2regdomain(code);
  3596. #endif
  3597. regdomain = ath5k_regdom_from_ieee(ieee_regdomain);
  3598. ah->ah_capabilities.cap_regdomain.reg_current = regdomain;
  3599. return regdomain;
  3600. }
  3601. /****************\
  3602. Misc functions
  3603. \****************/
  3604. int ath5k_hw_get_capability(struct ath5k_hw *ah,
  3605. enum ath5k_capability_type cap_type,
  3606. u32 capability, u32 *result)
  3607. {
  3608. ATH5K_TRACE(ah->ah_sc);
  3609. switch (cap_type) {
  3610. case AR5K_CAP_NUM_TXQUEUES:
  3611. if (result) {
  3612. if (ah->ah_version == AR5K_AR5210)
  3613. *result = AR5K_NUM_TX_QUEUES_NOQCU;
  3614. else
  3615. *result = AR5K_NUM_TX_QUEUES;
  3616. goto yes;
  3617. }
  3618. case AR5K_CAP_VEOL:
  3619. goto yes;
  3620. case AR5K_CAP_COMPRESSION:
  3621. if (ah->ah_version == AR5K_AR5212)
  3622. goto yes;
  3623. else
  3624. goto no;
  3625. case AR5K_CAP_BURST:
  3626. goto yes;
  3627. case AR5K_CAP_TPC:
  3628. goto yes;
  3629. case AR5K_CAP_BSSIDMASK:
  3630. if (ah->ah_version == AR5K_AR5212)
  3631. goto yes;
  3632. else
  3633. goto no;
  3634. case AR5K_CAP_XR:
  3635. if (ah->ah_version == AR5K_AR5212)
  3636. goto yes;
  3637. else
  3638. goto no;
  3639. default:
  3640. goto no;
  3641. }
  3642. no:
  3643. return -EINVAL;
  3644. yes:
  3645. return 0;
  3646. }
  3647. static int ath5k_hw_enable_pspoll(struct ath5k_hw *ah, u8 *bssid,
  3648. u16 assoc_id)
  3649. {
  3650. ATH5K_TRACE(ah->ah_sc);
  3651. if (ah->ah_version == AR5K_AR5210) {
  3652. AR5K_REG_DISABLE_BITS(ah, AR5K_STA_ID1,
  3653. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3654. return 0;
  3655. }
  3656. return -EIO;
  3657. }
  3658. static int ath5k_hw_disable_pspoll(struct ath5k_hw *ah)
  3659. {
  3660. ATH5K_TRACE(ah->ah_sc);
  3661. if (ah->ah_version == AR5K_AR5210) {
  3662. AR5K_REG_ENABLE_BITS(ah, AR5K_STA_ID1,
  3663. AR5K_STA_ID1_NO_PSPOLL | AR5K_STA_ID1_DEFAULT_ANTENNA);
  3664. return 0;
  3665. }
  3666. return -EIO;
  3667. }