hw.c 112 KB

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