iwl-4965.c 129 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2007 Intel Corporation. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of version 2 of the GNU General Public License as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  17. *
  18. * The full GNU General Public License is included in this distribution in the
  19. * file called LICENSE.
  20. *
  21. * Contact Information:
  22. * James P. Ketrenos <ipw2100-admin@linux.intel.com>
  23. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  24. *
  25. *****************************************************************************/
  26. #include <linux/kernel.h>
  27. #include <linux/module.h>
  28. #include <linux/version.h>
  29. #include <linux/init.h>
  30. #include <linux/pci.h>
  31. #include <linux/dma-mapping.h>
  32. #include <linux/delay.h>
  33. #include <linux/skbuff.h>
  34. #include <linux/netdevice.h>
  35. #include <linux/wireless.h>
  36. #include <net/mac80211.h>
  37. #include <linux/etherdevice.h>
  38. #include "iwl-4965.h"
  39. #include "iwl-helpers.h"
  40. static void iwl_hw_card_show_info(struct iwl_priv *priv);
  41. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  42. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  43. IWL_RATE_SISO_##s##M_PLCP, \
  44. IWL_RATE_MIMO_##s##M_PLCP, \
  45. IWL_RATE_##r##M_IEEE, \
  46. IWL_RATE_##ip##M_INDEX, \
  47. IWL_RATE_##in##M_INDEX, \
  48. IWL_RATE_##rp##M_INDEX, \
  49. IWL_RATE_##rn##M_INDEX, \
  50. IWL_RATE_##pp##M_INDEX, \
  51. IWL_RATE_##np##M_INDEX }
  52. /*
  53. * Parameter order:
  54. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  55. *
  56. * If there isn't a valid next or previous rate then INV is used which
  57. * maps to IWL_RATE_INVALID
  58. *
  59. */
  60. const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
  61. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  62. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  63. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  64. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  65. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  66. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  67. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  68. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  69. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  70. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  71. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  72. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  73. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  74. };
  75. static int is_fat_channel(__le32 rxon_flags)
  76. {
  77. return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
  78. (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
  79. }
  80. static u8 is_single_stream(struct iwl_priv *priv)
  81. {
  82. #ifdef CONFIG_IWL4965_HT
  83. if (!priv->is_ht_enabled || !priv->current_assoc_ht.is_ht ||
  84. (priv->active_rate_ht[1] == 0) ||
  85. (priv->ps_mode == IWL_MIMO_PS_STATIC))
  86. return 1;
  87. #else
  88. return 1;
  89. #endif /*CONFIG_IWL4965_HT */
  90. return 0;
  91. }
  92. /*
  93. * Determine how many receiver/antenna chains to use.
  94. * More provides better reception via diversity. Fewer saves power.
  95. * MIMO (dual stream) requires at least 2, but works better with 3.
  96. * This does not determine *which* chains to use, just how many.
  97. */
  98. static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv,
  99. u8 *idle_state, u8 *rx_state)
  100. {
  101. u8 is_single = is_single_stream(priv);
  102. u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
  103. /* # of Rx chains to use when expecting MIMO. */
  104. if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
  105. *rx_state = 2;
  106. else
  107. *rx_state = 3;
  108. /* # Rx chains when idling and maybe trying to save power */
  109. switch (priv->ps_mode) {
  110. case IWL_MIMO_PS_STATIC:
  111. case IWL_MIMO_PS_DYNAMIC:
  112. *idle_state = (is_cam) ? 2 : 1;
  113. break;
  114. case IWL_MIMO_PS_NONE:
  115. *idle_state = (is_cam) ? *rx_state : 1;
  116. break;
  117. default:
  118. *idle_state = 1;
  119. break;
  120. }
  121. return 0;
  122. }
  123. int iwl_hw_rxq_stop(struct iwl_priv *priv)
  124. {
  125. int rc;
  126. unsigned long flags;
  127. spin_lock_irqsave(&priv->lock, flags);
  128. rc = iwl_grab_nic_access(priv);
  129. if (rc) {
  130. spin_unlock_irqrestore(&priv->lock, flags);
  131. return rc;
  132. }
  133. /* stop HW */
  134. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  135. rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  136. (1 << 24), 1000);
  137. if (rc < 0)
  138. IWL_ERROR("Can't stop Rx DMA.\n");
  139. iwl_release_nic_access(priv);
  140. spin_unlock_irqrestore(&priv->lock, flags);
  141. return 0;
  142. }
  143. u8 iwl_hw_find_station(struct iwl_priv *priv, const u8 *addr)
  144. {
  145. int i;
  146. int start = 0;
  147. int ret = IWL_INVALID_STATION;
  148. unsigned long flags;
  149. DECLARE_MAC_BUF(mac);
  150. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
  151. (priv->iw_mode == IEEE80211_IF_TYPE_AP))
  152. start = IWL_STA_ID;
  153. if (is_broadcast_ether_addr(addr))
  154. return IWL4965_BROADCAST_ID;
  155. spin_lock_irqsave(&priv->sta_lock, flags);
  156. for (i = start; i < priv->hw_setting.max_stations; i++)
  157. if ((priv->stations[i].used) &&
  158. (!compare_ether_addr
  159. (priv->stations[i].sta.sta.addr, addr))) {
  160. ret = i;
  161. goto out;
  162. }
  163. IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
  164. print_mac(mac, addr), priv->num_stations);
  165. out:
  166. spin_unlock_irqrestore(&priv->sta_lock, flags);
  167. return ret;
  168. }
  169. static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
  170. {
  171. int ret;
  172. unsigned long flags;
  173. spin_lock_irqsave(&priv->lock, flags);
  174. ret = iwl_grab_nic_access(priv);
  175. if (ret) {
  176. spin_unlock_irqrestore(&priv->lock, flags);
  177. return ret;
  178. }
  179. if (!pwr_max) {
  180. u32 val;
  181. ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
  182. &val);
  183. if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
  184. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  185. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  186. ~APMG_PS_CTRL_MSK_PWR_SRC);
  187. } else
  188. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  189. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  190. ~APMG_PS_CTRL_MSK_PWR_SRC);
  191. iwl_release_nic_access(priv);
  192. spin_unlock_irqrestore(&priv->lock, flags);
  193. return ret;
  194. }
  195. static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl_rx_queue *rxq)
  196. {
  197. int rc;
  198. unsigned long flags;
  199. spin_lock_irqsave(&priv->lock, flags);
  200. rc = iwl_grab_nic_access(priv);
  201. if (rc) {
  202. spin_unlock_irqrestore(&priv->lock, flags);
  203. return rc;
  204. }
  205. /* stop HW */
  206. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  207. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  208. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  209. rxq->dma_addr >> 8);
  210. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  211. (priv->hw_setting.shared_phys +
  212. offsetof(struct iwl_shared, val0)) >> 4);
  213. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  214. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  215. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  216. IWL_FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K |
  217. /*0x10 << 4 | */
  218. (RX_QUEUE_SIZE_LOG <<
  219. FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
  220. /*
  221. * iwl_write32(priv,CSR_INT_COAL_REG,0);
  222. */
  223. iwl_release_nic_access(priv);
  224. spin_unlock_irqrestore(&priv->lock, flags);
  225. return 0;
  226. }
  227. static int iwl4965_kw_init(struct iwl_priv *priv)
  228. {
  229. unsigned long flags;
  230. int rc;
  231. spin_lock_irqsave(&priv->lock, flags);
  232. rc = iwl_grab_nic_access(priv);
  233. if (rc)
  234. goto out;
  235. iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
  236. priv->kw.dma_addr >> 4);
  237. iwl_release_nic_access(priv);
  238. out:
  239. spin_unlock_irqrestore(&priv->lock, flags);
  240. return rc;
  241. }
  242. static int iwl4965_kw_alloc(struct iwl_priv *priv)
  243. {
  244. struct pci_dev *dev = priv->pci_dev;
  245. struct iwl_kw *kw = &priv->kw;
  246. kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */
  247. kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
  248. if (!kw->v_addr)
  249. return -ENOMEM;
  250. return 0;
  251. }
  252. #define CHECK_AND_PRINT(x) ((eeprom_ch->flags & EEPROM_CHANNEL_##x) \
  253. ? # x " " : "")
  254. int iwl4965_set_fat_chan_info(struct iwl_priv *priv, int phymode, u16 channel,
  255. const struct iwl_eeprom_channel *eeprom_ch,
  256. u8 fat_extension_channel)
  257. {
  258. struct iwl_channel_info *ch_info;
  259. ch_info = (struct iwl_channel_info *)
  260. iwl_get_channel_info(priv, phymode, channel);
  261. if (!is_channel_valid(ch_info))
  262. return -1;
  263. IWL_DEBUG_INFO("FAT Ch. %d [%sGHz] %s%s%s%s%s%s(0x%02x"
  264. " %ddBm): Ad-Hoc %ssupported\n",
  265. ch_info->channel,
  266. is_channel_a_band(ch_info) ?
  267. "5.2" : "2.4",
  268. CHECK_AND_PRINT(IBSS),
  269. CHECK_AND_PRINT(ACTIVE),
  270. CHECK_AND_PRINT(RADAR),
  271. CHECK_AND_PRINT(WIDE),
  272. CHECK_AND_PRINT(NARROW),
  273. CHECK_AND_PRINT(DFS),
  274. eeprom_ch->flags,
  275. eeprom_ch->max_power_avg,
  276. ((eeprom_ch->flags & EEPROM_CHANNEL_IBSS)
  277. && !(eeprom_ch->flags & EEPROM_CHANNEL_RADAR)) ?
  278. "" : "not ");
  279. ch_info->fat_eeprom = *eeprom_ch;
  280. ch_info->fat_max_power_avg = eeprom_ch->max_power_avg;
  281. ch_info->fat_curr_txpow = eeprom_ch->max_power_avg;
  282. ch_info->fat_min_power = 0;
  283. ch_info->fat_scan_power = eeprom_ch->max_power_avg;
  284. ch_info->fat_flags = eeprom_ch->flags;
  285. ch_info->fat_extension_channel = fat_extension_channel;
  286. return 0;
  287. }
  288. static void iwl4965_kw_free(struct iwl_priv *priv)
  289. {
  290. struct pci_dev *dev = priv->pci_dev;
  291. struct iwl_kw *kw = &priv->kw;
  292. if (kw->v_addr) {
  293. pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
  294. memset(kw, 0, sizeof(*kw));
  295. }
  296. }
  297. /**
  298. * iwl4965_txq_ctx_reset - Reset TX queue context
  299. * Destroys all DMA structures and initialise them again
  300. *
  301. * @param priv
  302. * @return error code
  303. */
  304. static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
  305. {
  306. int rc = 0;
  307. int txq_id, slots_num;
  308. unsigned long flags;
  309. iwl4965_kw_free(priv);
  310. iwl_hw_txq_ctx_free(priv);
  311. /* Tx CMD queue */
  312. rc = iwl4965_kw_alloc(priv);
  313. if (rc) {
  314. IWL_ERROR("Keep Warm allocation failed");
  315. goto error_kw;
  316. }
  317. spin_lock_irqsave(&priv->lock, flags);
  318. rc = iwl_grab_nic_access(priv);
  319. if (unlikely(rc)) {
  320. IWL_ERROR("TX reset failed");
  321. spin_unlock_irqrestore(&priv->lock, flags);
  322. goto error_reset;
  323. }
  324. iwl_write_prph(priv, KDR_SCD_TXFACT, 0);
  325. iwl_release_nic_access(priv);
  326. spin_unlock_irqrestore(&priv->lock, flags);
  327. rc = iwl4965_kw_init(priv);
  328. if (rc) {
  329. IWL_ERROR("kw_init failed\n");
  330. goto error_reset;
  331. }
  332. /* Tx queue(s) */
  333. for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) {
  334. slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
  335. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  336. rc = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
  337. txq_id);
  338. if (rc) {
  339. IWL_ERROR("Tx %d queue init failed\n", txq_id);
  340. goto error;
  341. }
  342. }
  343. return rc;
  344. error:
  345. iwl_hw_txq_ctx_free(priv);
  346. error_reset:
  347. iwl4965_kw_free(priv);
  348. error_kw:
  349. return rc;
  350. }
  351. int iwl_hw_nic_init(struct iwl_priv *priv)
  352. {
  353. int rc;
  354. unsigned long flags;
  355. struct iwl_rx_queue *rxq = &priv->rxq;
  356. u8 rev_id;
  357. u32 val;
  358. u8 val_link;
  359. iwl_power_init_handle(priv);
  360. /* nic_init */
  361. spin_lock_irqsave(&priv->lock, flags);
  362. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  363. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  364. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  365. rc = iwl_poll_bit(priv, CSR_GP_CNTRL,
  366. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  367. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  368. if (rc < 0) {
  369. spin_unlock_irqrestore(&priv->lock, flags);
  370. IWL_DEBUG_INFO("Failed to init the card\n");
  371. return rc;
  372. }
  373. rc = iwl_grab_nic_access(priv);
  374. if (rc) {
  375. spin_unlock_irqrestore(&priv->lock, flags);
  376. return rc;
  377. }
  378. iwl_read_prph(priv, APMG_CLK_CTRL_REG);
  379. iwl_write_prph(priv, APMG_CLK_CTRL_REG,
  380. APMG_CLK_VAL_DMA_CLK_RQT |
  381. APMG_CLK_VAL_BSM_CLK_RQT);
  382. iwl_read_prph(priv, APMG_CLK_CTRL_REG);
  383. udelay(20);
  384. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  385. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  386. iwl_release_nic_access(priv);
  387. iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
  388. spin_unlock_irqrestore(&priv->lock, flags);
  389. /* Determine HW type */
  390. rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
  391. if (rc)
  392. return rc;
  393. IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id);
  394. iwl4965_nic_set_pwr_src(priv, 1);
  395. spin_lock_irqsave(&priv->lock, flags);
  396. if ((rev_id & 0x80) == 0x80 && (rev_id & 0x7f) < 8) {
  397. pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
  398. /* Enable No Snoop field */
  399. pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
  400. val & ~(1 << 11));
  401. }
  402. spin_unlock_irqrestore(&priv->lock, flags);
  403. /* Read the EEPROM */
  404. rc = iwl_eeprom_init(priv);
  405. if (rc)
  406. return rc;
  407. if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) {
  408. IWL_ERROR("Older EEPROM detected! Aborting.\n");
  409. return -EINVAL;
  410. }
  411. pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
  412. /* disable L1 entry -- workaround for pre-B1 */
  413. pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
  414. spin_lock_irqsave(&priv->lock, flags);
  415. /* set CSR_HW_CONFIG_REG for uCode use */
  416. iwl_set_bit(priv, CSR_SW_VER, CSR_HW_IF_CONFIG_REG_BIT_KEDRON_R |
  417. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  418. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  419. rc = iwl_grab_nic_access(priv);
  420. if (rc < 0) {
  421. spin_unlock_irqrestore(&priv->lock, flags);
  422. IWL_DEBUG_INFO("Failed to init the card\n");
  423. return rc;
  424. }
  425. iwl_read_prph(priv, APMG_PS_CTRL_REG);
  426. iwl_set_bits_prph(priv, APMG_PS_CTRL_REG,
  427. APMG_PS_CTRL_VAL_RESET_REQ);
  428. udelay(5);
  429. iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG,
  430. APMG_PS_CTRL_VAL_RESET_REQ);
  431. iwl_release_nic_access(priv);
  432. spin_unlock_irqrestore(&priv->lock, flags);
  433. iwl_hw_card_show_info(priv);
  434. /* end nic_init */
  435. /* Allocate the RX queue, or reset if it is already allocated */
  436. if (!rxq->bd) {
  437. rc = iwl_rx_queue_alloc(priv);
  438. if (rc) {
  439. IWL_ERROR("Unable to initialize Rx queue\n");
  440. return -ENOMEM;
  441. }
  442. } else
  443. iwl_rx_queue_reset(priv, rxq);
  444. iwl_rx_replenish(priv);
  445. iwl4965_rx_init(priv, rxq);
  446. spin_lock_irqsave(&priv->lock, flags);
  447. rxq->need_update = 1;
  448. iwl_rx_queue_update_write_ptr(priv, rxq);
  449. spin_unlock_irqrestore(&priv->lock, flags);
  450. rc = iwl4965_txq_ctx_reset(priv);
  451. if (rc)
  452. return rc;
  453. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
  454. IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
  455. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
  456. IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
  457. set_bit(STATUS_INIT, &priv->status);
  458. return 0;
  459. }
  460. int iwl_hw_nic_stop_master(struct iwl_priv *priv)
  461. {
  462. int rc = 0;
  463. u32 reg_val;
  464. unsigned long flags;
  465. spin_lock_irqsave(&priv->lock, flags);
  466. /* set stop master bit */
  467. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  468. reg_val = iwl_read32(priv, CSR_GP_CNTRL);
  469. if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
  470. (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
  471. IWL_DEBUG_INFO("Card in power save, master is already "
  472. "stopped\n");
  473. else {
  474. rc = iwl_poll_bit(priv, CSR_RESET,
  475. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  476. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  477. if (rc < 0) {
  478. spin_unlock_irqrestore(&priv->lock, flags);
  479. return rc;
  480. }
  481. }
  482. spin_unlock_irqrestore(&priv->lock, flags);
  483. IWL_DEBUG_INFO("stop master\n");
  484. return rc;
  485. }
  486. void iwl_hw_txq_ctx_stop(struct iwl_priv *priv)
  487. {
  488. int txq_id;
  489. unsigned long flags;
  490. /* reset TFD queues */
  491. for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++) {
  492. spin_lock_irqsave(&priv->lock, flags);
  493. if (iwl_grab_nic_access(priv)) {
  494. spin_unlock_irqrestore(&priv->lock, flags);
  495. continue;
  496. }
  497. iwl_write_direct32(priv,
  498. IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
  499. 0x0);
  500. iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG,
  501. IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
  502. (txq_id), 200);
  503. iwl_release_nic_access(priv);
  504. spin_unlock_irqrestore(&priv->lock, flags);
  505. }
  506. iwl_hw_txq_ctx_free(priv);
  507. }
  508. int iwl_hw_nic_reset(struct iwl_priv *priv)
  509. {
  510. int rc = 0;
  511. unsigned long flags;
  512. iwl_hw_nic_stop_master(priv);
  513. spin_lock_irqsave(&priv->lock, flags);
  514. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  515. udelay(10);
  516. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  517. rc = iwl_poll_bit(priv, CSR_RESET,
  518. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  519. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
  520. udelay(10);
  521. rc = iwl_grab_nic_access(priv);
  522. if (!rc) {
  523. iwl_write_prph(priv, APMG_CLK_EN_REG,
  524. APMG_CLK_VAL_DMA_CLK_RQT |
  525. APMG_CLK_VAL_BSM_CLK_RQT);
  526. udelay(10);
  527. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  528. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  529. iwl_release_nic_access(priv);
  530. }
  531. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  532. wake_up_interruptible(&priv->wait_command_queue);
  533. spin_unlock_irqrestore(&priv->lock, flags);
  534. return rc;
  535. }
  536. #define REG_RECALIB_PERIOD (60)
  537. /**
  538. * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  539. *
  540. * This callback is provided in order to queue the statistics_work
  541. * in work_queue context (v. softirq)
  542. *
  543. * This timer function is continually reset to execute within
  544. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  545. * was received. We need to ensure we receive the statistics in order
  546. * to update the temperature used for calibrating the TXPOWER. However,
  547. * we can't send the statistics command from softirq context (which
  548. * is the context which timers run at) so we have to queue off the
  549. * statistics_work to actually send the command to the hardware.
  550. */
  551. static void iwl4965_bg_statistics_periodic(unsigned long data)
  552. {
  553. struct iwl_priv *priv = (struct iwl_priv *)data;
  554. queue_work(priv->workqueue, &priv->statistics_work);
  555. }
  556. /**
  557. * iwl4965_bg_statistics_work - Send the statistics request to the hardware.
  558. *
  559. * This is queued by iwl_bg_statistics_periodic.
  560. */
  561. static void iwl4965_bg_statistics_work(struct work_struct *work)
  562. {
  563. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  564. statistics_work);
  565. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  566. return;
  567. mutex_lock(&priv->mutex);
  568. iwl_send_statistics_request(priv);
  569. mutex_unlock(&priv->mutex);
  570. }
  571. #define CT_LIMIT_CONST 259
  572. #define TM_CT_KILL_THRESHOLD 110
  573. void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
  574. {
  575. struct iwl_ct_kill_config cmd;
  576. u32 R1, R2, R3;
  577. u32 temp_th;
  578. u32 crit_temperature;
  579. unsigned long flags;
  580. int rc = 0;
  581. spin_lock_irqsave(&priv->lock, flags);
  582. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  583. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  584. spin_unlock_irqrestore(&priv->lock, flags);
  585. if (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK) {
  586. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  587. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  588. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  589. } else {
  590. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  591. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  592. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  593. }
  594. temp_th = CELSIUS_TO_KELVIN(TM_CT_KILL_THRESHOLD);
  595. crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
  596. cmd.critical_temperature_R = cpu_to_le32(crit_temperature);
  597. rc = iwl_send_cmd_pdu(priv,
  598. REPLY_CT_KILL_CONFIG_CMD, sizeof(cmd), &cmd);
  599. if (rc)
  600. IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
  601. else
  602. IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n");
  603. }
  604. #ifdef CONFIG_IWL4965_SENSITIVITY
  605. /* "false alarms" are signals that our DSP tries to lock onto,
  606. * but then determines that they are either noise, or transmissions
  607. * from a distant wireless network (also "noise", really) that get
  608. * "stepped on" by stronger transmissions within our own network.
  609. * This algorithm attempts to set a sensitivity level that is high
  610. * enough to receive all of our own network traffic, but not so
  611. * high that our DSP gets too busy trying to lock onto non-network
  612. * activity/noise. */
  613. static int iwl4965_sens_energy_cck(struct iwl_priv *priv,
  614. u32 norm_fa,
  615. u32 rx_enable_time,
  616. struct statistics_general_data *rx_info)
  617. {
  618. u32 max_nrg_cck = 0;
  619. int i = 0;
  620. u8 max_silence_rssi = 0;
  621. u32 silence_ref = 0;
  622. u8 silence_rssi_a = 0;
  623. u8 silence_rssi_b = 0;
  624. u8 silence_rssi_c = 0;
  625. u32 val;
  626. /* "false_alarms" values below are cross-multiplications to assess the
  627. * numbers of false alarms within the measured period of actual Rx
  628. * (Rx is off when we're txing), vs the min/max expected false alarms
  629. * (some should be expected if rx is sensitive enough) in a
  630. * hypothetical listening period of 200 time units (TU), 204.8 msec:
  631. *
  632. * MIN_FA/fixed-time < false_alarms/actual-rx-time < MAX_FA/beacon-time
  633. *
  634. * */
  635. u32 false_alarms = norm_fa * 200 * 1024;
  636. u32 max_false_alarms = MAX_FA_CCK * rx_enable_time;
  637. u32 min_false_alarms = MIN_FA_CCK * rx_enable_time;
  638. struct iwl_sensitivity_data *data = NULL;
  639. data = &(priv->sensitivity_data);
  640. data->nrg_auto_corr_silence_diff = 0;
  641. /* Find max silence rssi among all 3 receivers.
  642. * This is background noise, which may include transmissions from other
  643. * networks, measured during silence before our network's beacon */
  644. silence_rssi_a = (u8)((rx_info->beacon_silence_rssi_a &
  645. ALL_BAND_FILTER)>>8);
  646. silence_rssi_b = (u8)((rx_info->beacon_silence_rssi_b &
  647. ALL_BAND_FILTER)>>8);
  648. silence_rssi_c = (u8)((rx_info->beacon_silence_rssi_c &
  649. ALL_BAND_FILTER)>>8);
  650. val = max(silence_rssi_b, silence_rssi_c);
  651. max_silence_rssi = max(silence_rssi_a, (u8) val);
  652. /* Store silence rssi in 20-beacon history table */
  653. data->nrg_silence_rssi[data->nrg_silence_idx] = max_silence_rssi;
  654. data->nrg_silence_idx++;
  655. if (data->nrg_silence_idx >= NRG_NUM_PREV_STAT_L)
  656. data->nrg_silence_idx = 0;
  657. /* Find max silence rssi across 20 beacon history */
  658. for (i = 0; i < NRG_NUM_PREV_STAT_L; i++) {
  659. val = data->nrg_silence_rssi[i];
  660. silence_ref = max(silence_ref, val);
  661. }
  662. IWL_DEBUG_CALIB("silence a %u, b %u, c %u, 20-bcn max %u\n",
  663. silence_rssi_a, silence_rssi_b, silence_rssi_c,
  664. silence_ref);
  665. /* Find max rx energy (min value!) among all 3 receivers,
  666. * measured during beacon frame.
  667. * Save it in 10-beacon history table. */
  668. i = data->nrg_energy_idx;
  669. val = min(rx_info->beacon_energy_b, rx_info->beacon_energy_c);
  670. data->nrg_value[i] = min(rx_info->beacon_energy_a, val);
  671. data->nrg_energy_idx++;
  672. if (data->nrg_energy_idx >= 10)
  673. data->nrg_energy_idx = 0;
  674. /* Find min rx energy (max value) across 10 beacon history.
  675. * This is the minimum signal level that we want to receive well.
  676. * Add backoff (margin so we don't miss slightly lower energy frames).
  677. * This establishes an upper bound (min value) for energy threshold. */
  678. max_nrg_cck = data->nrg_value[0];
  679. for (i = 1; i < 10; i++)
  680. max_nrg_cck = (u32) max(max_nrg_cck, (data->nrg_value[i]));
  681. max_nrg_cck += 6;
  682. IWL_DEBUG_CALIB("rx energy a %u, b %u, c %u, 10-bcn max/min %u\n",
  683. rx_info->beacon_energy_a, rx_info->beacon_energy_b,
  684. rx_info->beacon_energy_c, max_nrg_cck - 6);
  685. /* Count number of consecutive beacons with fewer-than-desired
  686. * false alarms. */
  687. if (false_alarms < min_false_alarms)
  688. data->num_in_cck_no_fa++;
  689. else
  690. data->num_in_cck_no_fa = 0;
  691. IWL_DEBUG_CALIB("consecutive bcns with few false alarms = %u\n",
  692. data->num_in_cck_no_fa);
  693. /* If we got too many false alarms this time, reduce sensitivity */
  694. if (false_alarms > max_false_alarms) {
  695. IWL_DEBUG_CALIB("norm FA %u > max FA %u\n",
  696. false_alarms, max_false_alarms);
  697. IWL_DEBUG_CALIB("... reducing sensitivity\n");
  698. data->nrg_curr_state = IWL_FA_TOO_MANY;
  699. if (data->auto_corr_cck > AUTO_CORR_MAX_TH_CCK) {
  700. /* Store for "fewer than desired" on later beacon */
  701. data->nrg_silence_ref = silence_ref;
  702. /* increase energy threshold (reduce nrg value)
  703. * to decrease sensitivity */
  704. if (data->nrg_th_cck > (NRG_MAX_CCK + NRG_STEP_CCK))
  705. data->nrg_th_cck = data->nrg_th_cck
  706. - NRG_STEP_CCK;
  707. }
  708. /* increase auto_corr values to decrease sensitivity */
  709. if (data->auto_corr_cck < AUTO_CORR_MAX_TH_CCK)
  710. data->auto_corr_cck = AUTO_CORR_MAX_TH_CCK + 1;
  711. else {
  712. val = data->auto_corr_cck + AUTO_CORR_STEP_CCK;
  713. data->auto_corr_cck = min((u32)AUTO_CORR_MAX_CCK, val);
  714. }
  715. val = data->auto_corr_cck_mrc + AUTO_CORR_STEP_CCK;
  716. data->auto_corr_cck_mrc = min((u32)AUTO_CORR_MAX_CCK_MRC, val);
  717. /* Else if we got fewer than desired, increase sensitivity */
  718. } else if (false_alarms < min_false_alarms) {
  719. data->nrg_curr_state = IWL_FA_TOO_FEW;
  720. /* Compare silence level with silence level for most recent
  721. * healthy number or too many false alarms */
  722. data->nrg_auto_corr_silence_diff = (s32)data->nrg_silence_ref -
  723. (s32)silence_ref;
  724. IWL_DEBUG_CALIB("norm FA %u < min FA %u, silence diff %d\n",
  725. false_alarms, min_false_alarms,
  726. data->nrg_auto_corr_silence_diff);
  727. /* Increase value to increase sensitivity, but only if:
  728. * 1a) previous beacon did *not* have *too many* false alarms
  729. * 1b) AND there's a significant difference in Rx levels
  730. * from a previous beacon with too many, or healthy # FAs
  731. * OR 2) We've seen a lot of beacons (100) with too few
  732. * false alarms */
  733. if ((data->nrg_prev_state != IWL_FA_TOO_MANY) &&
  734. ((data->nrg_auto_corr_silence_diff > NRG_DIFF) ||
  735. (data->num_in_cck_no_fa > MAX_NUMBER_CCK_NO_FA))) {
  736. IWL_DEBUG_CALIB("... increasing sensitivity\n");
  737. /* Increase nrg value to increase sensitivity */
  738. val = data->nrg_th_cck + NRG_STEP_CCK;
  739. data->nrg_th_cck = min((u32)NRG_MIN_CCK, val);
  740. /* Decrease auto_corr values to increase sensitivity */
  741. val = data->auto_corr_cck - AUTO_CORR_STEP_CCK;
  742. data->auto_corr_cck = max((u32)AUTO_CORR_MIN_CCK, val);
  743. val = data->auto_corr_cck_mrc - AUTO_CORR_STEP_CCK;
  744. data->auto_corr_cck_mrc =
  745. max((u32)AUTO_CORR_MIN_CCK_MRC, val);
  746. } else
  747. IWL_DEBUG_CALIB("... but not changing sensitivity\n");
  748. /* Else we got a healthy number of false alarms, keep status quo */
  749. } else {
  750. IWL_DEBUG_CALIB(" FA in safe zone\n");
  751. data->nrg_curr_state = IWL_FA_GOOD_RANGE;
  752. /* Store for use in "fewer than desired" with later beacon */
  753. data->nrg_silence_ref = silence_ref;
  754. /* If previous beacon had too many false alarms,
  755. * give it some extra margin by reducing sensitivity again
  756. * (but don't go below measured energy of desired Rx) */
  757. if (IWL_FA_TOO_MANY == data->nrg_prev_state) {
  758. IWL_DEBUG_CALIB("... increasing margin\n");
  759. data->nrg_th_cck -= NRG_MARGIN;
  760. }
  761. }
  762. /* Make sure the energy threshold does not go above the measured
  763. * energy of the desired Rx signals (reduced by backoff margin),
  764. * or else we might start missing Rx frames.
  765. * Lower value is higher energy, so we use max()!
  766. */
  767. data->nrg_th_cck = max(max_nrg_cck, data->nrg_th_cck);
  768. IWL_DEBUG_CALIB("new nrg_th_cck %u\n", data->nrg_th_cck);
  769. data->nrg_prev_state = data->nrg_curr_state;
  770. return 0;
  771. }
  772. static int iwl4965_sens_auto_corr_ofdm(struct iwl_priv *priv,
  773. u32 norm_fa,
  774. u32 rx_enable_time)
  775. {
  776. u32 val;
  777. u32 false_alarms = norm_fa * 200 * 1024;
  778. u32 max_false_alarms = MAX_FA_OFDM * rx_enable_time;
  779. u32 min_false_alarms = MIN_FA_OFDM * rx_enable_time;
  780. struct iwl_sensitivity_data *data = NULL;
  781. data = &(priv->sensitivity_data);
  782. /* If we got too many false alarms this time, reduce sensitivity */
  783. if (false_alarms > max_false_alarms) {
  784. IWL_DEBUG_CALIB("norm FA %u > max FA %u)\n",
  785. false_alarms, max_false_alarms);
  786. val = data->auto_corr_ofdm + AUTO_CORR_STEP_OFDM;
  787. data->auto_corr_ofdm =
  788. min((u32)AUTO_CORR_MAX_OFDM, val);
  789. val = data->auto_corr_ofdm_mrc + AUTO_CORR_STEP_OFDM;
  790. data->auto_corr_ofdm_mrc =
  791. min((u32)AUTO_CORR_MAX_OFDM_MRC, val);
  792. val = data->auto_corr_ofdm_x1 + AUTO_CORR_STEP_OFDM;
  793. data->auto_corr_ofdm_x1 =
  794. min((u32)AUTO_CORR_MAX_OFDM_X1, val);
  795. val = data->auto_corr_ofdm_mrc_x1 + AUTO_CORR_STEP_OFDM;
  796. data->auto_corr_ofdm_mrc_x1 =
  797. min((u32)AUTO_CORR_MAX_OFDM_MRC_X1, val);
  798. }
  799. /* Else if we got fewer than desired, increase sensitivity */
  800. else if (false_alarms < min_false_alarms) {
  801. IWL_DEBUG_CALIB("norm FA %u < min FA %u\n",
  802. false_alarms, min_false_alarms);
  803. val = data->auto_corr_ofdm - AUTO_CORR_STEP_OFDM;
  804. data->auto_corr_ofdm =
  805. max((u32)AUTO_CORR_MIN_OFDM, val);
  806. val = data->auto_corr_ofdm_mrc - AUTO_CORR_STEP_OFDM;
  807. data->auto_corr_ofdm_mrc =
  808. max((u32)AUTO_CORR_MIN_OFDM_MRC, val);
  809. val = data->auto_corr_ofdm_x1 - AUTO_CORR_STEP_OFDM;
  810. data->auto_corr_ofdm_x1 =
  811. max((u32)AUTO_CORR_MIN_OFDM_X1, val);
  812. val = data->auto_corr_ofdm_mrc_x1 - AUTO_CORR_STEP_OFDM;
  813. data->auto_corr_ofdm_mrc_x1 =
  814. max((u32)AUTO_CORR_MIN_OFDM_MRC_X1, val);
  815. }
  816. else
  817. IWL_DEBUG_CALIB("min FA %u < norm FA %u < max FA %u OK\n",
  818. min_false_alarms, false_alarms, max_false_alarms);
  819. return 0;
  820. }
  821. static int iwl_sensitivity_callback(struct iwl_priv *priv,
  822. struct iwl_cmd *cmd, struct sk_buff *skb)
  823. {
  824. /* We didn't cache the SKB; let the caller free it */
  825. return 1;
  826. }
  827. /* Prepare a SENSITIVITY_CMD, send to uCode if values have changed */
  828. static int iwl4965_sensitivity_write(struct iwl_priv *priv, u8 flags)
  829. {
  830. int rc = 0;
  831. struct iwl_sensitivity_cmd cmd ;
  832. struct iwl_sensitivity_data *data = NULL;
  833. struct iwl_host_cmd cmd_out = {
  834. .id = SENSITIVITY_CMD,
  835. .len = sizeof(struct iwl_sensitivity_cmd),
  836. .meta.flags = flags,
  837. .data = &cmd,
  838. };
  839. data = &(priv->sensitivity_data);
  840. memset(&cmd, 0, sizeof(cmd));
  841. cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_INDEX] =
  842. cpu_to_le16((u16)data->auto_corr_ofdm);
  843. cmd.table[HD_AUTO_CORR32_X4_TH_ADD_MIN_MRC_INDEX] =
  844. cpu_to_le16((u16)data->auto_corr_ofdm_mrc);
  845. cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_INDEX] =
  846. cpu_to_le16((u16)data->auto_corr_ofdm_x1);
  847. cmd.table[HD_AUTO_CORR32_X1_TH_ADD_MIN_MRC_INDEX] =
  848. cpu_to_le16((u16)data->auto_corr_ofdm_mrc_x1);
  849. cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_INDEX] =
  850. cpu_to_le16((u16)data->auto_corr_cck);
  851. cmd.table[HD_AUTO_CORR40_X4_TH_ADD_MIN_MRC_INDEX] =
  852. cpu_to_le16((u16)data->auto_corr_cck_mrc);
  853. cmd.table[HD_MIN_ENERGY_CCK_DET_INDEX] =
  854. cpu_to_le16((u16)data->nrg_th_cck);
  855. cmd.table[HD_MIN_ENERGY_OFDM_DET_INDEX] =
  856. cpu_to_le16((u16)data->nrg_th_ofdm);
  857. cmd.table[HD_BARKER_CORR_TH_ADD_MIN_INDEX] =
  858. __constant_cpu_to_le16(190);
  859. cmd.table[HD_BARKER_CORR_TH_ADD_MIN_MRC_INDEX] =
  860. __constant_cpu_to_le16(390);
  861. cmd.table[HD_OFDM_ENERGY_TH_IN_INDEX] =
  862. __constant_cpu_to_le16(62);
  863. IWL_DEBUG_CALIB("ofdm: ac %u mrc %u x1 %u mrc_x1 %u thresh %u\n",
  864. data->auto_corr_ofdm, data->auto_corr_ofdm_mrc,
  865. data->auto_corr_ofdm_x1, data->auto_corr_ofdm_mrc_x1,
  866. data->nrg_th_ofdm);
  867. IWL_DEBUG_CALIB("cck: ac %u mrc %u thresh %u\n",
  868. data->auto_corr_cck, data->auto_corr_cck_mrc,
  869. data->nrg_th_cck);
  870. cmd.control = SENSITIVITY_CMD_CONTROL_WORK_TABLE;
  871. if (flags & CMD_ASYNC)
  872. cmd_out.meta.u.callback = iwl_sensitivity_callback;
  873. /* Don't send command to uCode if nothing has changed */
  874. if (!memcmp(&cmd.table[0], &(priv->sensitivity_tbl[0]),
  875. sizeof(u16)*HD_TABLE_SIZE)) {
  876. IWL_DEBUG_CALIB("No change in SENSITIVITY_CMD\n");
  877. return 0;
  878. }
  879. /* Copy table for comparison next time */
  880. memcpy(&(priv->sensitivity_tbl[0]), &(cmd.table[0]),
  881. sizeof(u16)*HD_TABLE_SIZE);
  882. rc = iwl_send_cmd(priv, &cmd_out);
  883. if (!rc) {
  884. IWL_DEBUG_CALIB("SENSITIVITY_CMD succeeded\n");
  885. return rc;
  886. }
  887. return 0;
  888. }
  889. void iwl4965_init_sensitivity(struct iwl_priv *priv, u8 flags, u8 force)
  890. {
  891. int rc = 0;
  892. int i;
  893. struct iwl_sensitivity_data *data = NULL;
  894. IWL_DEBUG_CALIB("Start iwl4965_init_sensitivity\n");
  895. if (force)
  896. memset(&(priv->sensitivity_tbl[0]), 0,
  897. sizeof(u16)*HD_TABLE_SIZE);
  898. /* Clear driver's sensitivity algo data */
  899. data = &(priv->sensitivity_data);
  900. memset(data, 0, sizeof(struct iwl_sensitivity_data));
  901. data->num_in_cck_no_fa = 0;
  902. data->nrg_curr_state = IWL_FA_TOO_MANY;
  903. data->nrg_prev_state = IWL_FA_TOO_MANY;
  904. data->nrg_silence_ref = 0;
  905. data->nrg_silence_idx = 0;
  906. data->nrg_energy_idx = 0;
  907. for (i = 0; i < 10; i++)
  908. data->nrg_value[i] = 0;
  909. for (i = 0; i < NRG_NUM_PREV_STAT_L; i++)
  910. data->nrg_silence_rssi[i] = 0;
  911. data->auto_corr_ofdm = 90;
  912. data->auto_corr_ofdm_mrc = 170;
  913. data->auto_corr_ofdm_x1 = 105;
  914. data->auto_corr_ofdm_mrc_x1 = 220;
  915. data->auto_corr_cck = AUTO_CORR_CCK_MIN_VAL_DEF;
  916. data->auto_corr_cck_mrc = 200;
  917. data->nrg_th_cck = 100;
  918. data->nrg_th_ofdm = 100;
  919. data->last_bad_plcp_cnt_ofdm = 0;
  920. data->last_fa_cnt_ofdm = 0;
  921. data->last_bad_plcp_cnt_cck = 0;
  922. data->last_fa_cnt_cck = 0;
  923. /* Clear prior Sensitivity command data to force send to uCode */
  924. if (force)
  925. memset(&(priv->sensitivity_tbl[0]), 0,
  926. sizeof(u16)*HD_TABLE_SIZE);
  927. rc |= iwl4965_sensitivity_write(priv, flags);
  928. IWL_DEBUG_CALIB("<<return 0x%X\n", rc);
  929. return;
  930. }
  931. /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  932. * Called after every association, but this runs only once!
  933. * ... once chain noise is calibrated the first time, it's good forever. */
  934. void iwl4965_chain_noise_reset(struct iwl_priv *priv)
  935. {
  936. struct iwl_chain_noise_data *data = NULL;
  937. int rc = 0;
  938. data = &(priv->chain_noise_data);
  939. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  940. struct iwl_calibration_cmd cmd;
  941. memset(&cmd, 0, sizeof(cmd));
  942. cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
  943. cmd.diff_gain_a = 0;
  944. cmd.diff_gain_b = 0;
  945. cmd.diff_gain_c = 0;
  946. rc = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  947. sizeof(cmd), &cmd);
  948. msleep(4);
  949. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  950. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  951. }
  952. return;
  953. }
  954. /*
  955. * Accumulate 20 beacons of signal and noise statistics for each of
  956. * 3 receivers/antennas/rx-chains, then figure out:
  957. * 1) Which antennas are connected.
  958. * 2) Differential rx gain settings to balance the 3 receivers.
  959. */
  960. static void iwl4965_noise_calibration(struct iwl_priv *priv,
  961. struct iwl_notif_statistics *stat_resp)
  962. {
  963. struct iwl_chain_noise_data *data = NULL;
  964. int rc = 0;
  965. u32 chain_noise_a;
  966. u32 chain_noise_b;
  967. u32 chain_noise_c;
  968. u32 chain_sig_a;
  969. u32 chain_sig_b;
  970. u32 chain_sig_c;
  971. u32 average_sig[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
  972. u32 average_noise[NUM_RX_CHAINS] = {INITIALIZATION_VALUE};
  973. u32 max_average_sig;
  974. u16 max_average_sig_antenna_i;
  975. u32 min_average_noise = MIN_AVERAGE_NOISE_MAX_VALUE;
  976. u16 min_average_noise_antenna_i = INITIALIZATION_VALUE;
  977. u16 i = 0;
  978. u16 chan_num = INITIALIZATION_VALUE;
  979. u32 band = INITIALIZATION_VALUE;
  980. u32 active_chains = 0;
  981. unsigned long flags;
  982. struct statistics_rx_non_phy *rx_info = &(stat_resp->rx.general);
  983. data = &(priv->chain_noise_data);
  984. /* Accumulate just the first 20 beacons after the first association,
  985. * then we're done forever. */
  986. if (data->state != IWL_CHAIN_NOISE_ACCUMULATE) {
  987. if (data->state == IWL_CHAIN_NOISE_ALIVE)
  988. IWL_DEBUG_CALIB("Wait for noise calib reset\n");
  989. return;
  990. }
  991. spin_lock_irqsave(&priv->lock, flags);
  992. if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
  993. IWL_DEBUG_CALIB(" << Interference data unavailable\n");
  994. spin_unlock_irqrestore(&priv->lock, flags);
  995. return;
  996. }
  997. band = (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) ? 0 : 1;
  998. chan_num = le16_to_cpu(priv->staging_rxon.channel);
  999. /* Make sure we accumulate data for just the associated channel
  1000. * (even if scanning). */
  1001. if ((chan_num != (le32_to_cpu(stat_resp->flag) >> 16)) ||
  1002. ((STATISTICS_REPLY_FLG_BAND_24G_MSK ==
  1003. (stat_resp->flag & STATISTICS_REPLY_FLG_BAND_24G_MSK)) && band)) {
  1004. IWL_DEBUG_CALIB("Stats not from chan=%d, band=%d\n",
  1005. chan_num, band);
  1006. spin_unlock_irqrestore(&priv->lock, flags);
  1007. return;
  1008. }
  1009. /* Accumulate beacon statistics values across 20 beacons */
  1010. chain_noise_a = le32_to_cpu(rx_info->beacon_silence_rssi_a) &
  1011. IN_BAND_FILTER;
  1012. chain_noise_b = le32_to_cpu(rx_info->beacon_silence_rssi_b) &
  1013. IN_BAND_FILTER;
  1014. chain_noise_c = le32_to_cpu(rx_info->beacon_silence_rssi_c) &
  1015. IN_BAND_FILTER;
  1016. chain_sig_a = le32_to_cpu(rx_info->beacon_rssi_a) & IN_BAND_FILTER;
  1017. chain_sig_b = le32_to_cpu(rx_info->beacon_rssi_b) & IN_BAND_FILTER;
  1018. chain_sig_c = le32_to_cpu(rx_info->beacon_rssi_c) & IN_BAND_FILTER;
  1019. spin_unlock_irqrestore(&priv->lock, flags);
  1020. data->beacon_count++;
  1021. data->chain_noise_a = (chain_noise_a + data->chain_noise_a);
  1022. data->chain_noise_b = (chain_noise_b + data->chain_noise_b);
  1023. data->chain_noise_c = (chain_noise_c + data->chain_noise_c);
  1024. data->chain_signal_a = (chain_sig_a + data->chain_signal_a);
  1025. data->chain_signal_b = (chain_sig_b + data->chain_signal_b);
  1026. data->chain_signal_c = (chain_sig_c + data->chain_signal_c);
  1027. IWL_DEBUG_CALIB("chan=%d, band=%d, beacon=%d\n", chan_num, band,
  1028. data->beacon_count);
  1029. IWL_DEBUG_CALIB("chain_sig: a %d b %d c %d\n",
  1030. chain_sig_a, chain_sig_b, chain_sig_c);
  1031. IWL_DEBUG_CALIB("chain_noise: a %d b %d c %d\n",
  1032. chain_noise_a, chain_noise_b, chain_noise_c);
  1033. /* If this is the 20th beacon, determine:
  1034. * 1) Disconnected antennas (using signal strengths)
  1035. * 2) Differential gain (using silence noise) to balance receivers */
  1036. if (data->beacon_count == CAL_NUM_OF_BEACONS) {
  1037. /* Analyze signal for disconnected antenna */
  1038. average_sig[0] = (data->chain_signal_a) / CAL_NUM_OF_BEACONS;
  1039. average_sig[1] = (data->chain_signal_b) / CAL_NUM_OF_BEACONS;
  1040. average_sig[2] = (data->chain_signal_c) / CAL_NUM_OF_BEACONS;
  1041. if (average_sig[0] >= average_sig[1]) {
  1042. max_average_sig = average_sig[0];
  1043. max_average_sig_antenna_i = 0;
  1044. active_chains = (1 << max_average_sig_antenna_i);
  1045. } else {
  1046. max_average_sig = average_sig[1];
  1047. max_average_sig_antenna_i = 1;
  1048. active_chains = (1 << max_average_sig_antenna_i);
  1049. }
  1050. if (average_sig[2] >= max_average_sig) {
  1051. max_average_sig = average_sig[2];
  1052. max_average_sig_antenna_i = 2;
  1053. active_chains = (1 << max_average_sig_antenna_i);
  1054. }
  1055. IWL_DEBUG_CALIB("average_sig: a %d b %d c %d\n",
  1056. average_sig[0], average_sig[1], average_sig[2]);
  1057. IWL_DEBUG_CALIB("max_average_sig = %d, antenna %d\n",
  1058. max_average_sig, max_average_sig_antenna_i);
  1059. /* Compare signal strengths for all 3 receivers. */
  1060. for (i = 0; i < NUM_RX_CHAINS; i++) {
  1061. if (i != max_average_sig_antenna_i) {
  1062. s32 rssi_delta = (max_average_sig -
  1063. average_sig[i]);
  1064. /* If signal is very weak, compared with
  1065. * strongest, mark it as disconnected. */
  1066. if (rssi_delta > MAXIMUM_ALLOWED_PATHLOSS)
  1067. data->disconn_array[i] = 1;
  1068. else
  1069. active_chains |= (1 << i);
  1070. IWL_DEBUG_CALIB("i = %d rssiDelta = %d "
  1071. "disconn_array[i] = %d\n",
  1072. i, rssi_delta, data->disconn_array[i]);
  1073. }
  1074. }
  1075. /*If both chains A & B are disconnected -
  1076. * connect B and leave A as is */
  1077. if (data->disconn_array[CHAIN_A] &&
  1078. data->disconn_array[CHAIN_B]) {
  1079. data->disconn_array[CHAIN_B] = 0;
  1080. active_chains |= (1 << CHAIN_B);
  1081. IWL_DEBUG_CALIB("both A & B chains are disconnected! "
  1082. "W/A - declare B as connected\n");
  1083. }
  1084. IWL_DEBUG_CALIB("active_chains (bitwise) = 0x%x\n",
  1085. active_chains);
  1086. /* Save for use within RXON, TX, SCAN commands, etc. */
  1087. priv->valid_antenna = active_chains;
  1088. /* Analyze noise for rx balance */
  1089. average_noise[0] = ((data->chain_noise_a)/CAL_NUM_OF_BEACONS);
  1090. average_noise[1] = ((data->chain_noise_b)/CAL_NUM_OF_BEACONS);
  1091. average_noise[2] = ((data->chain_noise_c)/CAL_NUM_OF_BEACONS);
  1092. for (i = 0; i < NUM_RX_CHAINS; i++) {
  1093. if (!(data->disconn_array[i]) &&
  1094. (average_noise[i] <= min_average_noise)) {
  1095. /* This means that chain i is active and has
  1096. * lower noise values so far: */
  1097. min_average_noise = average_noise[i];
  1098. min_average_noise_antenna_i = i;
  1099. }
  1100. }
  1101. data->delta_gain_code[min_average_noise_antenna_i] = 0;
  1102. IWL_DEBUG_CALIB("average_noise: a %d b %d c %d\n",
  1103. average_noise[0], average_noise[1],
  1104. average_noise[2]);
  1105. IWL_DEBUG_CALIB("min_average_noise = %d, antenna %d\n",
  1106. min_average_noise, min_average_noise_antenna_i);
  1107. for (i = 0; i < NUM_RX_CHAINS; i++) {
  1108. s32 delta_g = 0;
  1109. if (!(data->disconn_array[i]) &&
  1110. (data->delta_gain_code[i] ==
  1111. CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
  1112. delta_g = average_noise[i] - min_average_noise;
  1113. data->delta_gain_code[i] = (u8)((delta_g *
  1114. 10) / 15);
  1115. if (CHAIN_NOISE_MAX_DELTA_GAIN_CODE <
  1116. data->delta_gain_code[i])
  1117. data->delta_gain_code[i] =
  1118. CHAIN_NOISE_MAX_DELTA_GAIN_CODE;
  1119. data->delta_gain_code[i] =
  1120. (data->delta_gain_code[i] | (1 << 2));
  1121. } else
  1122. data->delta_gain_code[i] = 0;
  1123. }
  1124. IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
  1125. data->delta_gain_code[0],
  1126. data->delta_gain_code[1],
  1127. data->delta_gain_code[2]);
  1128. /* Differential gain gets sent to uCode only once */
  1129. if (!data->radio_write) {
  1130. struct iwl_calibration_cmd cmd;
  1131. data->radio_write = 1;
  1132. memset(&cmd, 0, sizeof(cmd));
  1133. cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
  1134. cmd.diff_gain_a = data->delta_gain_code[0];
  1135. cmd.diff_gain_b = data->delta_gain_code[1];
  1136. cmd.diff_gain_c = data->delta_gain_code[2];
  1137. rc = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  1138. sizeof(cmd), &cmd);
  1139. if (rc)
  1140. IWL_DEBUG_CALIB("fail sending cmd "
  1141. "REPLY_PHY_CALIBRATION_CMD \n");
  1142. /* TODO we might want recalculate
  1143. * rx_chain in rxon cmd */
  1144. /* Mark so we run this algo only once! */
  1145. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  1146. }
  1147. data->chain_noise_a = 0;
  1148. data->chain_noise_b = 0;
  1149. data->chain_noise_c = 0;
  1150. data->chain_signal_a = 0;
  1151. data->chain_signal_b = 0;
  1152. data->chain_signal_c = 0;
  1153. data->beacon_count = 0;
  1154. }
  1155. return;
  1156. }
  1157. static void iwl4965_sensitivity_calibration(struct iwl_priv *priv,
  1158. struct iwl_notif_statistics *resp)
  1159. {
  1160. int rc = 0;
  1161. u32 rx_enable_time;
  1162. u32 fa_cck;
  1163. u32 fa_ofdm;
  1164. u32 bad_plcp_cck;
  1165. u32 bad_plcp_ofdm;
  1166. u32 norm_fa_ofdm;
  1167. u32 norm_fa_cck;
  1168. struct iwl_sensitivity_data *data = NULL;
  1169. struct statistics_rx_non_phy *rx_info = &(resp->rx.general);
  1170. struct statistics_rx *statistics = &(resp->rx);
  1171. unsigned long flags;
  1172. struct statistics_general_data statis;
  1173. data = &(priv->sensitivity_data);
  1174. if (!iwl_is_associated(priv)) {
  1175. IWL_DEBUG_CALIB("<< - not associated\n");
  1176. return;
  1177. }
  1178. spin_lock_irqsave(&priv->lock, flags);
  1179. if (rx_info->interference_data_flag != INTERFERENCE_DATA_AVAILABLE) {
  1180. IWL_DEBUG_CALIB("<< invalid data.\n");
  1181. spin_unlock_irqrestore(&priv->lock, flags);
  1182. return;
  1183. }
  1184. /* Extract Statistics: */
  1185. rx_enable_time = le32_to_cpu(rx_info->channel_load);
  1186. fa_cck = le32_to_cpu(statistics->cck.false_alarm_cnt);
  1187. fa_ofdm = le32_to_cpu(statistics->ofdm.false_alarm_cnt);
  1188. bad_plcp_cck = le32_to_cpu(statistics->cck.plcp_err);
  1189. bad_plcp_ofdm = le32_to_cpu(statistics->ofdm.plcp_err);
  1190. statis.beacon_silence_rssi_a =
  1191. le32_to_cpu(statistics->general.beacon_silence_rssi_a);
  1192. statis.beacon_silence_rssi_b =
  1193. le32_to_cpu(statistics->general.beacon_silence_rssi_b);
  1194. statis.beacon_silence_rssi_c =
  1195. le32_to_cpu(statistics->general.beacon_silence_rssi_c);
  1196. statis.beacon_energy_a =
  1197. le32_to_cpu(statistics->general.beacon_energy_a);
  1198. statis.beacon_energy_b =
  1199. le32_to_cpu(statistics->general.beacon_energy_b);
  1200. statis.beacon_energy_c =
  1201. le32_to_cpu(statistics->general.beacon_energy_c);
  1202. spin_unlock_irqrestore(&priv->lock, flags);
  1203. IWL_DEBUG_CALIB("rx_enable_time = %u usecs\n", rx_enable_time);
  1204. if (!rx_enable_time) {
  1205. IWL_DEBUG_CALIB("<< RX Enable Time == 0! \n");
  1206. return;
  1207. }
  1208. /* These statistics increase monotonically, and do not reset
  1209. * at each beacon. Calculate difference from last value, or just
  1210. * use the new statistics value if it has reset or wrapped around. */
  1211. if (data->last_bad_plcp_cnt_cck > bad_plcp_cck)
  1212. data->last_bad_plcp_cnt_cck = bad_plcp_cck;
  1213. else {
  1214. bad_plcp_cck -= data->last_bad_plcp_cnt_cck;
  1215. data->last_bad_plcp_cnt_cck += bad_plcp_cck;
  1216. }
  1217. if (data->last_bad_plcp_cnt_ofdm > bad_plcp_ofdm)
  1218. data->last_bad_plcp_cnt_ofdm = bad_plcp_ofdm;
  1219. else {
  1220. bad_plcp_ofdm -= data->last_bad_plcp_cnt_ofdm;
  1221. data->last_bad_plcp_cnt_ofdm += bad_plcp_ofdm;
  1222. }
  1223. if (data->last_fa_cnt_ofdm > fa_ofdm)
  1224. data->last_fa_cnt_ofdm = fa_ofdm;
  1225. else {
  1226. fa_ofdm -= data->last_fa_cnt_ofdm;
  1227. data->last_fa_cnt_ofdm += fa_ofdm;
  1228. }
  1229. if (data->last_fa_cnt_cck > fa_cck)
  1230. data->last_fa_cnt_cck = fa_cck;
  1231. else {
  1232. fa_cck -= data->last_fa_cnt_cck;
  1233. data->last_fa_cnt_cck += fa_cck;
  1234. }
  1235. /* Total aborted signal locks */
  1236. norm_fa_ofdm = fa_ofdm + bad_plcp_ofdm;
  1237. norm_fa_cck = fa_cck + bad_plcp_cck;
  1238. IWL_DEBUG_CALIB("cck: fa %u badp %u ofdm: fa %u badp %u\n", fa_cck,
  1239. bad_plcp_cck, fa_ofdm, bad_plcp_ofdm);
  1240. iwl4965_sens_auto_corr_ofdm(priv, norm_fa_ofdm, rx_enable_time);
  1241. iwl4965_sens_energy_cck(priv, norm_fa_cck, rx_enable_time, &statis);
  1242. rc |= iwl4965_sensitivity_write(priv, CMD_ASYNC);
  1243. return;
  1244. }
  1245. static void iwl4965_bg_sensitivity_work(struct work_struct *work)
  1246. {
  1247. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1248. sensitivity_work);
  1249. mutex_lock(&priv->mutex);
  1250. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  1251. test_bit(STATUS_SCANNING, &priv->status)) {
  1252. mutex_unlock(&priv->mutex);
  1253. return;
  1254. }
  1255. if (priv->start_calib) {
  1256. iwl4965_noise_calibration(priv, &priv->statistics);
  1257. if (priv->sensitivity_data.state ==
  1258. IWL_SENS_CALIB_NEED_REINIT) {
  1259. iwl4965_init_sensitivity(priv, CMD_ASYNC, 0);
  1260. priv->sensitivity_data.state = IWL_SENS_CALIB_ALLOWED;
  1261. } else
  1262. iwl4965_sensitivity_calibration(priv,
  1263. &priv->statistics);
  1264. }
  1265. mutex_unlock(&priv->mutex);
  1266. return;
  1267. }
  1268. #endif /*CONFIG_IWL4965_SENSITIVITY*/
  1269. static void iwl4965_bg_txpower_work(struct work_struct *work)
  1270. {
  1271. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1272. txpower_work);
  1273. /* If a scan happened to start before we got here
  1274. * then just return; the statistics notification will
  1275. * kick off another scheduled work to compensate for
  1276. * any temperature delta we missed here. */
  1277. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  1278. test_bit(STATUS_SCANNING, &priv->status))
  1279. return;
  1280. mutex_lock(&priv->mutex);
  1281. /* Regardless of if we are assocaited, we must reconfigure the
  1282. * TX power since frames can be sent on non-radar channels while
  1283. * not associated */
  1284. iwl_hw_reg_send_txpower(priv);
  1285. /* Update last_temperature to keep is_calib_needed from running
  1286. * when it isn't needed... */
  1287. priv->last_temperature = priv->temperature;
  1288. mutex_unlock(&priv->mutex);
  1289. }
  1290. /*
  1291. * Acquire priv->lock before calling this function !
  1292. */
  1293. static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
  1294. {
  1295. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  1296. (index & 0xff) | (txq_id << 8));
  1297. iwl_write_prph(priv, KDR_SCD_QUEUE_RDPTR(txq_id), index);
  1298. }
  1299. /*
  1300. * Acquire priv->lock before calling this function !
  1301. */
  1302. static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
  1303. struct iwl_tx_queue *txq,
  1304. int tx_fifo_id, int scd_retry)
  1305. {
  1306. int txq_id = txq->q.id;
  1307. int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
  1308. iwl_write_prph(priv, KDR_SCD_QUEUE_STATUS_BITS(txq_id),
  1309. (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  1310. (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
  1311. (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) |
  1312. (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  1313. SCD_QUEUE_STTS_REG_MSK);
  1314. txq->sched_retry = scd_retry;
  1315. IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
  1316. active ? "Activete" : "Deactivate",
  1317. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  1318. }
  1319. static const u16 default_queue_to_tx_fifo[] = {
  1320. IWL_TX_FIFO_AC3,
  1321. IWL_TX_FIFO_AC2,
  1322. IWL_TX_FIFO_AC1,
  1323. IWL_TX_FIFO_AC0,
  1324. IWL_CMD_FIFO_NUM,
  1325. IWL_TX_FIFO_HCCA_1,
  1326. IWL_TX_FIFO_HCCA_2
  1327. };
  1328. static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1329. {
  1330. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1331. }
  1332. static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1333. {
  1334. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1335. }
  1336. int iwl4965_alive_notify(struct iwl_priv *priv)
  1337. {
  1338. u32 a;
  1339. int i = 0;
  1340. unsigned long flags;
  1341. int rc;
  1342. spin_lock_irqsave(&priv->lock, flags);
  1343. #ifdef CONFIG_IWL4965_SENSITIVITY
  1344. memset(&(priv->sensitivity_data), 0,
  1345. sizeof(struct iwl_sensitivity_data));
  1346. memset(&(priv->chain_noise_data), 0,
  1347. sizeof(struct iwl_chain_noise_data));
  1348. for (i = 0; i < NUM_RX_CHAINS; i++)
  1349. priv->chain_noise_data.delta_gain_code[i] =
  1350. CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
  1351. #endif /* CONFIG_IWL4965_SENSITIVITY*/
  1352. rc = iwl_grab_nic_access(priv);
  1353. if (rc) {
  1354. spin_unlock_irqrestore(&priv->lock, flags);
  1355. return rc;
  1356. }
  1357. priv->scd_base_addr = iwl_read_prph(priv, KDR_SCD_SRAM_BASE_ADDR);
  1358. a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET;
  1359. for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  1360. iwl_write_targ_mem(priv, a, 0);
  1361. for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4)
  1362. iwl_write_targ_mem(priv, a, 0);
  1363. for (; a < sizeof(u16) * priv->hw_setting.max_txq_num; a += 4)
  1364. iwl_write_targ_mem(priv, a, 0);
  1365. iwl_write_prph(priv, KDR_SCD_DRAM_BASE_ADDR,
  1366. (priv->hw_setting.shared_phys +
  1367. offsetof(struct iwl_shared, queues_byte_cnt_tbls)) >> 10);
  1368. iwl_write_prph(priv, KDR_SCD_QUEUECHAIN_SEL, 0);
  1369. /* initiate the queues */
  1370. for (i = 0; i < priv->hw_setting.max_txq_num; i++) {
  1371. iwl_write_prph(priv, KDR_SCD_QUEUE_RDPTR(i), 0);
  1372. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  1373. iwl_write_targ_mem(priv, priv->scd_base_addr +
  1374. SCD_CONTEXT_QUEUE_OFFSET(i),
  1375. (SCD_WIN_SIZE <<
  1376. SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1377. SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1378. iwl_write_targ_mem(priv, priv->scd_base_addr +
  1379. SCD_CONTEXT_QUEUE_OFFSET(i) +
  1380. sizeof(u32),
  1381. (SCD_FRAME_LIMIT <<
  1382. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1383. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1384. }
  1385. iwl_write_prph(priv, KDR_SCD_INTERRUPT_MASK,
  1386. (1 << priv->hw_setting.max_txq_num) - 1);
  1387. iwl_write_prph(priv, KDR_SCD_TXFACT,
  1388. SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
  1389. iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  1390. /* map qos queues to fifos one-to-one */
  1391. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  1392. int ac = default_queue_to_tx_fifo[i];
  1393. iwl4965_txq_ctx_activate(priv, i);
  1394. iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  1395. }
  1396. iwl_release_nic_access(priv);
  1397. spin_unlock_irqrestore(&priv->lock, flags);
  1398. return 0;
  1399. }
  1400. int iwl_hw_set_hw_setting(struct iwl_priv *priv)
  1401. {
  1402. priv->hw_setting.shared_virt =
  1403. pci_alloc_consistent(priv->pci_dev,
  1404. sizeof(struct iwl_shared),
  1405. &priv->hw_setting.shared_phys);
  1406. if (!priv->hw_setting.shared_virt)
  1407. return -1;
  1408. memset(priv->hw_setting.shared_virt, 0, sizeof(struct iwl_shared));
  1409. priv->hw_setting.max_txq_num = iwl_param_queues_num;
  1410. priv->hw_setting.ac_queue_count = AC_NUM;
  1411. priv->hw_setting.tx_cmd_len = sizeof(struct iwl_tx_cmd);
  1412. priv->hw_setting.max_rxq_size = RX_QUEUE_SIZE;
  1413. priv->hw_setting.max_rxq_log = RX_QUEUE_SIZE_LOG;
  1414. priv->hw_setting.max_stations = IWL4965_STATION_COUNT;
  1415. priv->hw_setting.bcast_sta_id = IWL4965_BROADCAST_ID;
  1416. return 0;
  1417. }
  1418. /**
  1419. * iwl_hw_txq_ctx_free - Free TXQ Context
  1420. *
  1421. * Destroy all TX DMA queues and structures
  1422. */
  1423. void iwl_hw_txq_ctx_free(struct iwl_priv *priv)
  1424. {
  1425. int txq_id;
  1426. /* Tx queues */
  1427. for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++)
  1428. iwl_tx_queue_free(priv, &priv->txq[txq_id]);
  1429. iwl4965_kw_free(priv);
  1430. }
  1431. /**
  1432. * iwl_hw_txq_free_tfd - Free one TFD, those at index [txq->q.read_ptr]
  1433. *
  1434. * Does NOT advance any indexes
  1435. */
  1436. int iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  1437. {
  1438. struct iwl_tfd_frame *bd_tmp = (struct iwl_tfd_frame *)&txq->bd[0];
  1439. struct iwl_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
  1440. struct pci_dev *dev = priv->pci_dev;
  1441. int i;
  1442. int counter = 0;
  1443. int index, is_odd;
  1444. /* classify bd */
  1445. if (txq->q.id == IWL_CMD_QUEUE_NUM)
  1446. /* nothing to cleanup after for host commands */
  1447. return 0;
  1448. /* sanity check */
  1449. counter = IWL_GET_BITS(*bd, num_tbs);
  1450. if (counter > MAX_NUM_OF_TBS) {
  1451. IWL_ERROR("Too many chunks: %i\n", counter);
  1452. /* @todo issue fatal error, it is quite serious situation */
  1453. return 0;
  1454. }
  1455. /* unmap chunks if any */
  1456. for (i = 0; i < counter; i++) {
  1457. index = i / 2;
  1458. is_odd = i & 0x1;
  1459. if (is_odd)
  1460. pci_unmap_single(
  1461. dev,
  1462. IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
  1463. (IWL_GET_BITS(bd->pa[index],
  1464. tb2_addr_hi20) << 16),
  1465. IWL_GET_BITS(bd->pa[index], tb2_len),
  1466. PCI_DMA_TODEVICE);
  1467. else if (i > 0)
  1468. pci_unmap_single(dev,
  1469. le32_to_cpu(bd->pa[index].tb1_addr),
  1470. IWL_GET_BITS(bd->pa[index], tb1_len),
  1471. PCI_DMA_TODEVICE);
  1472. if (txq->txb[txq->q.read_ptr].skb[i]) {
  1473. struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
  1474. dev_kfree_skb(skb);
  1475. txq->txb[txq->q.read_ptr].skb[i] = NULL;
  1476. }
  1477. }
  1478. return 0;
  1479. }
  1480. int iwl_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
  1481. {
  1482. IWL_ERROR("TODO: Implement iwl_hw_reg_set_txpower!\n");
  1483. return -EINVAL;
  1484. }
  1485. static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
  1486. {
  1487. s32 sign = 1;
  1488. if (num < 0) {
  1489. sign = -sign;
  1490. num = -num;
  1491. }
  1492. if (denom < 0) {
  1493. sign = -sign;
  1494. denom = -denom;
  1495. }
  1496. *res = 1;
  1497. *res = ((num * 2 + denom) / (denom * 2)) * sign;
  1498. return 1;
  1499. }
  1500. static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
  1501. s32 current_voltage)
  1502. {
  1503. s32 comp = 0;
  1504. if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
  1505. (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
  1506. return 0;
  1507. iwl4965_math_div_round(current_voltage - eeprom_voltage,
  1508. TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
  1509. if (current_voltage > eeprom_voltage)
  1510. comp *= 2;
  1511. if ((comp < -2) || (comp > 2))
  1512. comp = 0;
  1513. return comp;
  1514. }
  1515. static const struct iwl_channel_info *
  1516. iwl4965_get_channel_txpower_info(struct iwl_priv *priv, u8 phymode, u16 channel)
  1517. {
  1518. const struct iwl_channel_info *ch_info;
  1519. ch_info = iwl_get_channel_info(priv, phymode, channel);
  1520. if (!is_channel_valid(ch_info))
  1521. return NULL;
  1522. return ch_info;
  1523. }
  1524. static s32 iwl4965_get_tx_atten_grp(u16 channel)
  1525. {
  1526. if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
  1527. channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
  1528. return CALIB_CH_GROUP_5;
  1529. if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
  1530. channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
  1531. return CALIB_CH_GROUP_1;
  1532. if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
  1533. channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
  1534. return CALIB_CH_GROUP_2;
  1535. if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
  1536. channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
  1537. return CALIB_CH_GROUP_3;
  1538. if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
  1539. channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
  1540. return CALIB_CH_GROUP_4;
  1541. IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
  1542. return -1;
  1543. }
  1544. static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
  1545. {
  1546. s32 b = -1;
  1547. for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
  1548. if (priv->eeprom.calib_info.band_info[b].ch_from == 0)
  1549. continue;
  1550. if ((channel >= priv->eeprom.calib_info.band_info[b].ch_from)
  1551. && (channel <= priv->eeprom.calib_info.band_info[b].ch_to))
  1552. break;
  1553. }
  1554. return b;
  1555. }
  1556. static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  1557. {
  1558. s32 val;
  1559. if (x2 == x1)
  1560. return y1;
  1561. else {
  1562. iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
  1563. return val + y2;
  1564. }
  1565. }
  1566. static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
  1567. struct iwl_eeprom_calib_ch_info *chan_info)
  1568. {
  1569. s32 s = -1;
  1570. u32 c;
  1571. u32 m;
  1572. const struct iwl_eeprom_calib_measure *m1;
  1573. const struct iwl_eeprom_calib_measure *m2;
  1574. struct iwl_eeprom_calib_measure *omeas;
  1575. u32 ch_i1;
  1576. u32 ch_i2;
  1577. s = iwl4965_get_sub_band(priv, channel);
  1578. if (s >= EEPROM_TX_POWER_BANDS) {
  1579. IWL_ERROR("Tx Power can not find channel %d ", channel);
  1580. return -1;
  1581. }
  1582. ch_i1 = priv->eeprom.calib_info.band_info[s].ch1.ch_num;
  1583. ch_i2 = priv->eeprom.calib_info.band_info[s].ch2.ch_num;
  1584. chan_info->ch_num = (u8) channel;
  1585. IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
  1586. channel, s, ch_i1, ch_i2);
  1587. for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
  1588. for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
  1589. m1 = &(priv->eeprom.calib_info.band_info[s].ch1.
  1590. measurements[c][m]);
  1591. m2 = &(priv->eeprom.calib_info.band_info[s].ch2.
  1592. measurements[c][m]);
  1593. omeas = &(chan_info->measurements[c][m]);
  1594. omeas->actual_pow =
  1595. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1596. m1->actual_pow,
  1597. ch_i2,
  1598. m2->actual_pow);
  1599. omeas->gain_idx =
  1600. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1601. m1->gain_idx, ch_i2,
  1602. m2->gain_idx);
  1603. omeas->temperature =
  1604. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1605. m1->temperature,
  1606. ch_i2,
  1607. m2->temperature);
  1608. omeas->pa_det =
  1609. (s8) iwl4965_interpolate_value(channel, ch_i1,
  1610. m1->pa_det, ch_i2,
  1611. m2->pa_det);
  1612. IWL_DEBUG_TXPOWER
  1613. ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
  1614. m1->actual_pow, m2->actual_pow, omeas->actual_pow);
  1615. IWL_DEBUG_TXPOWER
  1616. ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
  1617. m1->gain_idx, m2->gain_idx, omeas->gain_idx);
  1618. IWL_DEBUG_TXPOWER
  1619. ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
  1620. m1->pa_det, m2->pa_det, omeas->pa_det);
  1621. IWL_DEBUG_TXPOWER
  1622. ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
  1623. m1->temperature, m2->temperature,
  1624. omeas->temperature);
  1625. }
  1626. }
  1627. return 0;
  1628. }
  1629. /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
  1630. * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
  1631. static s32 back_off_table[] = {
  1632. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
  1633. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
  1634. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
  1635. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
  1636. 10 /* CCK */
  1637. };
  1638. /* Thermal compensation values for txpower for various frequency ranges ...
  1639. * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
  1640. static struct iwl_txpower_comp_entry {
  1641. s32 degrees_per_05db_a;
  1642. s32 degrees_per_05db_a_denom;
  1643. } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
  1644. {9, 2}, /* group 0 5.2, ch 34-43 */
  1645. {4, 1}, /* group 1 5.2, ch 44-70 */
  1646. {4, 1}, /* group 2 5.2, ch 71-124 */
  1647. {4, 1}, /* group 3 5.2, ch 125-200 */
  1648. {3, 1} /* group 4 2.4, ch all */
  1649. };
  1650. static s32 get_min_power_index(s32 rate_power_index, u32 band)
  1651. {
  1652. if (!band) {
  1653. if ((rate_power_index & 7) <= 4)
  1654. return MIN_TX_GAIN_INDEX_52GHZ_EXT;
  1655. }
  1656. return MIN_TX_GAIN_INDEX;
  1657. }
  1658. struct gain_entry {
  1659. u8 dsp;
  1660. u8 radio;
  1661. };
  1662. static const struct gain_entry gain_table[2][108] = {
  1663. /* 5.2GHz power gain index table */
  1664. {
  1665. {123, 0x3F}, /* highest txpower */
  1666. {117, 0x3F},
  1667. {110, 0x3F},
  1668. {104, 0x3F},
  1669. {98, 0x3F},
  1670. {110, 0x3E},
  1671. {104, 0x3E},
  1672. {98, 0x3E},
  1673. {110, 0x3D},
  1674. {104, 0x3D},
  1675. {98, 0x3D},
  1676. {110, 0x3C},
  1677. {104, 0x3C},
  1678. {98, 0x3C},
  1679. {110, 0x3B},
  1680. {104, 0x3B},
  1681. {98, 0x3B},
  1682. {110, 0x3A},
  1683. {104, 0x3A},
  1684. {98, 0x3A},
  1685. {110, 0x39},
  1686. {104, 0x39},
  1687. {98, 0x39},
  1688. {110, 0x38},
  1689. {104, 0x38},
  1690. {98, 0x38},
  1691. {110, 0x37},
  1692. {104, 0x37},
  1693. {98, 0x37},
  1694. {110, 0x36},
  1695. {104, 0x36},
  1696. {98, 0x36},
  1697. {110, 0x35},
  1698. {104, 0x35},
  1699. {98, 0x35},
  1700. {110, 0x34},
  1701. {104, 0x34},
  1702. {98, 0x34},
  1703. {110, 0x33},
  1704. {104, 0x33},
  1705. {98, 0x33},
  1706. {110, 0x32},
  1707. {104, 0x32},
  1708. {98, 0x32},
  1709. {110, 0x31},
  1710. {104, 0x31},
  1711. {98, 0x31},
  1712. {110, 0x30},
  1713. {104, 0x30},
  1714. {98, 0x30},
  1715. {110, 0x25},
  1716. {104, 0x25},
  1717. {98, 0x25},
  1718. {110, 0x24},
  1719. {104, 0x24},
  1720. {98, 0x24},
  1721. {110, 0x23},
  1722. {104, 0x23},
  1723. {98, 0x23},
  1724. {110, 0x22},
  1725. {104, 0x18},
  1726. {98, 0x18},
  1727. {110, 0x17},
  1728. {104, 0x17},
  1729. {98, 0x17},
  1730. {110, 0x16},
  1731. {104, 0x16},
  1732. {98, 0x16},
  1733. {110, 0x15},
  1734. {104, 0x15},
  1735. {98, 0x15},
  1736. {110, 0x14},
  1737. {104, 0x14},
  1738. {98, 0x14},
  1739. {110, 0x13},
  1740. {104, 0x13},
  1741. {98, 0x13},
  1742. {110, 0x12},
  1743. {104, 0x08},
  1744. {98, 0x08},
  1745. {110, 0x07},
  1746. {104, 0x07},
  1747. {98, 0x07},
  1748. {110, 0x06},
  1749. {104, 0x06},
  1750. {98, 0x06},
  1751. {110, 0x05},
  1752. {104, 0x05},
  1753. {98, 0x05},
  1754. {110, 0x04},
  1755. {104, 0x04},
  1756. {98, 0x04},
  1757. {110, 0x03},
  1758. {104, 0x03},
  1759. {98, 0x03},
  1760. {110, 0x02},
  1761. {104, 0x02},
  1762. {98, 0x02},
  1763. {110, 0x01},
  1764. {104, 0x01},
  1765. {98, 0x01},
  1766. {110, 0x00},
  1767. {104, 0x00},
  1768. {98, 0x00},
  1769. {93, 0x00},
  1770. {88, 0x00},
  1771. {83, 0x00},
  1772. {78, 0x00},
  1773. },
  1774. /* 2.4GHz power gain index table */
  1775. {
  1776. {110, 0x3f}, /* highest txpower */
  1777. {104, 0x3f},
  1778. {98, 0x3f},
  1779. {110, 0x3e},
  1780. {104, 0x3e},
  1781. {98, 0x3e},
  1782. {110, 0x3d},
  1783. {104, 0x3d},
  1784. {98, 0x3d},
  1785. {110, 0x3c},
  1786. {104, 0x3c},
  1787. {98, 0x3c},
  1788. {110, 0x3b},
  1789. {104, 0x3b},
  1790. {98, 0x3b},
  1791. {110, 0x3a},
  1792. {104, 0x3a},
  1793. {98, 0x3a},
  1794. {110, 0x39},
  1795. {104, 0x39},
  1796. {98, 0x39},
  1797. {110, 0x38},
  1798. {104, 0x38},
  1799. {98, 0x38},
  1800. {110, 0x37},
  1801. {104, 0x37},
  1802. {98, 0x37},
  1803. {110, 0x36},
  1804. {104, 0x36},
  1805. {98, 0x36},
  1806. {110, 0x35},
  1807. {104, 0x35},
  1808. {98, 0x35},
  1809. {110, 0x34},
  1810. {104, 0x34},
  1811. {98, 0x34},
  1812. {110, 0x33},
  1813. {104, 0x33},
  1814. {98, 0x33},
  1815. {110, 0x32},
  1816. {104, 0x32},
  1817. {98, 0x32},
  1818. {110, 0x31},
  1819. {104, 0x31},
  1820. {98, 0x31},
  1821. {110, 0x30},
  1822. {104, 0x30},
  1823. {98, 0x30},
  1824. {110, 0x6},
  1825. {104, 0x6},
  1826. {98, 0x6},
  1827. {110, 0x5},
  1828. {104, 0x5},
  1829. {98, 0x5},
  1830. {110, 0x4},
  1831. {104, 0x4},
  1832. {98, 0x4},
  1833. {110, 0x3},
  1834. {104, 0x3},
  1835. {98, 0x3},
  1836. {110, 0x2},
  1837. {104, 0x2},
  1838. {98, 0x2},
  1839. {110, 0x1},
  1840. {104, 0x1},
  1841. {98, 0x1},
  1842. {110, 0x0},
  1843. {104, 0x0},
  1844. {98, 0x0},
  1845. {97, 0},
  1846. {96, 0},
  1847. {95, 0},
  1848. {94, 0},
  1849. {93, 0},
  1850. {92, 0},
  1851. {91, 0},
  1852. {90, 0},
  1853. {89, 0},
  1854. {88, 0},
  1855. {87, 0},
  1856. {86, 0},
  1857. {85, 0},
  1858. {84, 0},
  1859. {83, 0},
  1860. {82, 0},
  1861. {81, 0},
  1862. {80, 0},
  1863. {79, 0},
  1864. {78, 0},
  1865. {77, 0},
  1866. {76, 0},
  1867. {75, 0},
  1868. {74, 0},
  1869. {73, 0},
  1870. {72, 0},
  1871. {71, 0},
  1872. {70, 0},
  1873. {69, 0},
  1874. {68, 0},
  1875. {67, 0},
  1876. {66, 0},
  1877. {65, 0},
  1878. {64, 0},
  1879. {63, 0},
  1880. {62, 0},
  1881. {61, 0},
  1882. {60, 0},
  1883. {59, 0},
  1884. }
  1885. };
  1886. static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
  1887. u8 is_fat, u8 ctrl_chan_high,
  1888. struct iwl_tx_power_db *tx_power_tbl)
  1889. {
  1890. u8 saturation_power;
  1891. s32 target_power;
  1892. s32 user_target_power;
  1893. s32 power_limit;
  1894. s32 current_temp;
  1895. s32 reg_limit;
  1896. s32 current_regulatory;
  1897. s32 txatten_grp = CALIB_CH_GROUP_MAX;
  1898. int i;
  1899. int c;
  1900. const struct iwl_channel_info *ch_info = NULL;
  1901. struct iwl_eeprom_calib_ch_info ch_eeprom_info;
  1902. const struct iwl_eeprom_calib_measure *measurement;
  1903. s16 voltage;
  1904. s32 init_voltage;
  1905. s32 voltage_compensation;
  1906. s32 degrees_per_05db_num;
  1907. s32 degrees_per_05db_denom;
  1908. s32 factory_temp;
  1909. s32 temperature_comp[2];
  1910. s32 factory_gain_index[2];
  1911. s32 factory_actual_pwr[2];
  1912. s32 power_index;
  1913. /* Sanity check requested level (dBm) */
  1914. if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
  1915. IWL_WARNING("Requested user TXPOWER %d below limit.\n",
  1916. priv->user_txpower_limit);
  1917. return -EINVAL;
  1918. }
  1919. if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
  1920. IWL_WARNING("Requested user TXPOWER %d above limit.\n",
  1921. priv->user_txpower_limit);
  1922. return -EINVAL;
  1923. }
  1924. /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
  1925. * are used for indexing into txpower table) */
  1926. user_target_power = 2 * priv->user_txpower_limit;
  1927. /* Get current (RXON) channel, band, width */
  1928. ch_info =
  1929. iwl4965_get_channel_txpower_info(priv, priv->phymode, channel);
  1930. IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
  1931. is_fat);
  1932. if (!ch_info)
  1933. return -EINVAL;
  1934. /* get txatten group, used to select 1) thermal txpower adjustment
  1935. * and 2) mimo txpower balance between Tx chains. */
  1936. txatten_grp = iwl4965_get_tx_atten_grp(channel);
  1937. if (txatten_grp < 0)
  1938. return -EINVAL;
  1939. IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
  1940. channel, txatten_grp);
  1941. if (is_fat) {
  1942. if (ctrl_chan_high)
  1943. channel -= 2;
  1944. else
  1945. channel += 2;
  1946. }
  1947. /* hardware txpower limits ...
  1948. * saturation (clipping distortion) txpowers are in half-dBm */
  1949. if (band)
  1950. saturation_power = priv->eeprom.calib_info.saturation_power24;
  1951. else
  1952. saturation_power = priv->eeprom.calib_info.saturation_power52;
  1953. if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
  1954. saturation_power > IWL_TX_POWER_SATURATION_MAX) {
  1955. if (band)
  1956. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
  1957. else
  1958. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
  1959. }
  1960. /* regulatory txpower limits ... reg_limit values are in half-dBm,
  1961. * max_power_avg values are in dBm, convert * 2 */
  1962. if (is_fat)
  1963. reg_limit = ch_info->fat_max_power_avg * 2;
  1964. else
  1965. reg_limit = ch_info->max_power_avg * 2;
  1966. if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
  1967. (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
  1968. if (band)
  1969. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
  1970. else
  1971. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
  1972. }
  1973. /* Interpolate txpower calibration values for this channel,
  1974. * based on factory calibration tests on spaced channels. */
  1975. iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
  1976. /* calculate tx gain adjustment based on power supply voltage */
  1977. voltage = priv->eeprom.calib_info.voltage;
  1978. init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
  1979. voltage_compensation =
  1980. iwl4965_get_voltage_compensation(voltage, init_voltage);
  1981. IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
  1982. init_voltage,
  1983. voltage, voltage_compensation);
  1984. /* get current temperature (Celsius) */
  1985. current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
  1986. current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
  1987. current_temp = KELVIN_TO_CELSIUS(current_temp);
  1988. /* select thermal txpower adjustment params, based on channel group
  1989. * (same frequency group used for mimo txatten adjustment) */
  1990. degrees_per_05db_num =
  1991. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
  1992. degrees_per_05db_denom =
  1993. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
  1994. /* get per-chain txpower values from factory measurements */
  1995. for (c = 0; c < 2; c++) {
  1996. measurement = &ch_eeprom_info.measurements[c][1];
  1997. /* txgain adjustment (in half-dB steps) based on difference
  1998. * between factory and current temperature */
  1999. factory_temp = measurement->temperature;
  2000. iwl4965_math_div_round((current_temp - factory_temp) *
  2001. degrees_per_05db_denom,
  2002. degrees_per_05db_num,
  2003. &temperature_comp[c]);
  2004. factory_gain_index[c] = measurement->gain_idx;
  2005. factory_actual_pwr[c] = measurement->actual_pow;
  2006. IWL_DEBUG_TXPOWER("chain = %d\n", c);
  2007. IWL_DEBUG_TXPOWER("fctry tmp %d, "
  2008. "curr tmp %d, comp %d steps\n",
  2009. factory_temp, current_temp,
  2010. temperature_comp[c]);
  2011. IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
  2012. factory_gain_index[c],
  2013. factory_actual_pwr[c]);
  2014. }
  2015. /* for each of 33 bit-rates (including 1 for CCK) */
  2016. for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
  2017. u8 is_mimo_rate;
  2018. union iwl_tx_power_dual_stream tx_power;
  2019. /* for mimo, reduce each chain's txpower by half
  2020. * (3dB, 6 steps), so total output power is regulatory
  2021. * compliant. */
  2022. if (i & 0x8) {
  2023. current_regulatory = reg_limit -
  2024. IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
  2025. is_mimo_rate = 1;
  2026. } else {
  2027. current_regulatory = reg_limit;
  2028. is_mimo_rate = 0;
  2029. }
  2030. /* find txpower limit, either hardware or regulatory */
  2031. power_limit = saturation_power - back_off_table[i];
  2032. if (power_limit > current_regulatory)
  2033. power_limit = current_regulatory;
  2034. /* reduce user's txpower request if necessary
  2035. * for this rate on this channel */
  2036. target_power = user_target_power;
  2037. if (target_power > power_limit)
  2038. target_power = power_limit;
  2039. IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
  2040. i, saturation_power - back_off_table[i],
  2041. current_regulatory, user_target_power,
  2042. target_power);
  2043. /* for each of 2 Tx chains (radio transmitters) */
  2044. for (c = 0; c < 2; c++) {
  2045. s32 atten_value;
  2046. if (is_mimo_rate)
  2047. atten_value =
  2048. (s32)le32_to_cpu(priv->card_alive_init.
  2049. tx_atten[txatten_grp][c]);
  2050. else
  2051. atten_value = 0;
  2052. /* calculate index; higher index means lower txpower */
  2053. power_index = (u8) (factory_gain_index[c] -
  2054. (target_power -
  2055. factory_actual_pwr[c]) -
  2056. temperature_comp[c] -
  2057. voltage_compensation +
  2058. atten_value);
  2059. /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
  2060. power_index); */
  2061. if (power_index < get_min_power_index(i, band))
  2062. power_index = get_min_power_index(i, band);
  2063. /* adjust 5 GHz index to support negative indexes */
  2064. if (!band)
  2065. power_index += 9;
  2066. /* CCK, rate 32, reduce txpower for CCK */
  2067. if (i == POWER_TABLE_CCK_ENTRY)
  2068. power_index +=
  2069. IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
  2070. /* stay within the table! */
  2071. if (power_index > 107) {
  2072. IWL_WARNING("txpower index %d > 107\n",
  2073. power_index);
  2074. power_index = 107;
  2075. }
  2076. if (power_index < 0) {
  2077. IWL_WARNING("txpower index %d < 0\n",
  2078. power_index);
  2079. power_index = 0;
  2080. }
  2081. /* fill txpower command for this rate/chain */
  2082. tx_power.s.radio_tx_gain[c] =
  2083. gain_table[band][power_index].radio;
  2084. tx_power.s.dsp_predis_atten[c] =
  2085. gain_table[band][power_index].dsp;
  2086. IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
  2087. "gain 0x%02x dsp %d\n",
  2088. c, atten_value, power_index,
  2089. tx_power.s.radio_tx_gain[c],
  2090. tx_power.s.dsp_predis_atten[c]);
  2091. }/* for each chain */
  2092. tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
  2093. }/* for each rate */
  2094. return 0;
  2095. }
  2096. /**
  2097. * iwl_hw_reg_send_txpower - Configure the TXPOWER level user limit
  2098. *
  2099. * Uses the active RXON for channel, band, and characteristics (fat, high)
  2100. * The power limit is taken from priv->user_txpower_limit.
  2101. */
  2102. int iwl_hw_reg_send_txpower(struct iwl_priv *priv)
  2103. {
  2104. struct iwl_txpowertable_cmd cmd = { 0 };
  2105. int rc = 0;
  2106. u8 band = 0;
  2107. u8 is_fat = 0;
  2108. u8 ctrl_chan_high = 0;
  2109. if (test_bit(STATUS_SCANNING, &priv->status)) {
  2110. /* If this gets hit a lot, switch it to a BUG() and catch
  2111. * the stack trace to find out who is calling this during
  2112. * a scan. */
  2113. IWL_WARNING("TX Power requested while scanning!\n");
  2114. return -EAGAIN;
  2115. }
  2116. band = ((priv->phymode == MODE_IEEE80211B) ||
  2117. (priv->phymode == MODE_IEEE80211G));
  2118. is_fat = is_fat_channel(priv->active_rxon.flags);
  2119. if (is_fat &&
  2120. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  2121. ctrl_chan_high = 1;
  2122. cmd.band = band;
  2123. cmd.channel = priv->active_rxon.channel;
  2124. rc = iwl4965_fill_txpower_tbl(priv, band,
  2125. le16_to_cpu(priv->active_rxon.channel),
  2126. is_fat, ctrl_chan_high, &cmd.tx_power);
  2127. if (rc)
  2128. return rc;
  2129. rc = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
  2130. return rc;
  2131. }
  2132. int iwl_hw_channel_switch(struct iwl_priv *priv, u16 channel)
  2133. {
  2134. int rc;
  2135. u8 band = 0;
  2136. u8 is_fat = 0;
  2137. u8 ctrl_chan_high = 0;
  2138. struct iwl_channel_switch_cmd cmd = { 0 };
  2139. const struct iwl_channel_info *ch_info;
  2140. band = ((priv->phymode == MODE_IEEE80211B) ||
  2141. (priv->phymode == MODE_IEEE80211G));
  2142. ch_info = iwl_get_channel_info(priv, priv->phymode, channel);
  2143. is_fat = is_fat_channel(priv->staging_rxon.flags);
  2144. if (is_fat &&
  2145. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  2146. ctrl_chan_high = 1;
  2147. cmd.band = band;
  2148. cmd.expect_beacon = 0;
  2149. cmd.channel = cpu_to_le16(channel);
  2150. cmd.rxon_flags = priv->active_rxon.flags;
  2151. cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
  2152. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  2153. if (ch_info)
  2154. cmd.expect_beacon = is_channel_radar(ch_info);
  2155. else
  2156. cmd.expect_beacon = 1;
  2157. rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
  2158. ctrl_chan_high, &cmd.tx_power);
  2159. if (rc) {
  2160. IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
  2161. return rc;
  2162. }
  2163. rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  2164. return rc;
  2165. }
  2166. #define RTS_HCCA_RETRY_LIMIT 3
  2167. #define RTS_DFAULT_RETRY_LIMIT 60
  2168. void iwl_hw_build_tx_cmd_rate(struct iwl_priv *priv,
  2169. struct iwl_cmd *cmd,
  2170. struct ieee80211_tx_control *ctrl,
  2171. struct ieee80211_hdr *hdr, int sta_id,
  2172. int is_hcca)
  2173. {
  2174. u8 rate;
  2175. u8 rts_retry_limit = 0;
  2176. u8 data_retry_limit = 0;
  2177. __le32 tx_flags;
  2178. u16 fc = le16_to_cpu(hdr->frame_control);
  2179. tx_flags = cmd->cmd.tx.tx_flags;
  2180. rate = iwl_rates[ctrl->tx_rate].plcp;
  2181. rts_retry_limit = (is_hcca) ?
  2182. RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
  2183. if (ieee80211_is_probe_response(fc)) {
  2184. data_retry_limit = 3;
  2185. if (data_retry_limit < rts_retry_limit)
  2186. rts_retry_limit = data_retry_limit;
  2187. } else
  2188. data_retry_limit = IWL_DEFAULT_TX_RETRY;
  2189. if (priv->data_retry_limit != -1)
  2190. data_retry_limit = priv->data_retry_limit;
  2191. if ((fc & IEEE80211_FCTL_FTYPE) == IEEE80211_FTYPE_MGMT) {
  2192. switch (fc & IEEE80211_FCTL_STYPE) {
  2193. case IEEE80211_STYPE_AUTH:
  2194. case IEEE80211_STYPE_DEAUTH:
  2195. case IEEE80211_STYPE_ASSOC_REQ:
  2196. case IEEE80211_STYPE_REASSOC_REQ:
  2197. if (tx_flags & TX_CMD_FLG_RTS_MSK) {
  2198. tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  2199. tx_flags |= TX_CMD_FLG_CTS_MSK;
  2200. }
  2201. break;
  2202. default:
  2203. break;
  2204. }
  2205. }
  2206. cmd->cmd.tx.rts_retry_limit = rts_retry_limit;
  2207. cmd->cmd.tx.data_retry_limit = data_retry_limit;
  2208. cmd->cmd.tx.rate_n_flags = iwl_hw_set_rate_n_flags(rate, 0);
  2209. cmd->cmd.tx.tx_flags = tx_flags;
  2210. }
  2211. int iwl_hw_get_rx_read(struct iwl_priv *priv)
  2212. {
  2213. struct iwl_shared *shared_data = priv->hw_setting.shared_virt;
  2214. return IWL_GET_BITS(*shared_data, rb_closed_stts_rb_num);
  2215. }
  2216. int iwl_hw_get_temperature(struct iwl_priv *priv)
  2217. {
  2218. return priv->temperature;
  2219. }
  2220. unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
  2221. struct iwl_frame *frame, u8 rate)
  2222. {
  2223. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  2224. unsigned int frame_size;
  2225. tx_beacon_cmd = &frame->u.beacon;
  2226. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2227. tx_beacon_cmd->tx.sta_id = IWL4965_BROADCAST_ID;
  2228. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2229. frame_size = iwl_fill_beacon_frame(priv,
  2230. tx_beacon_cmd->frame,
  2231. BROADCAST_ADDR,
  2232. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2233. BUG_ON(frame_size > MAX_MPDU_SIZE);
  2234. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  2235. if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
  2236. tx_beacon_cmd->tx.rate_n_flags =
  2237. iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
  2238. else
  2239. tx_beacon_cmd->tx.rate_n_flags =
  2240. iwl_hw_set_rate_n_flags(rate, 0);
  2241. tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
  2242. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
  2243. return (sizeof(*tx_beacon_cmd) + frame_size);
  2244. }
  2245. int iwl_hw_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  2246. {
  2247. int rc;
  2248. unsigned long flags;
  2249. int txq_id = txq->q.id;
  2250. spin_lock_irqsave(&priv->lock, flags);
  2251. rc = iwl_grab_nic_access(priv);
  2252. if (rc) {
  2253. spin_unlock_irqrestore(&priv->lock, flags);
  2254. return rc;
  2255. }
  2256. iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  2257. txq->q.dma_addr >> 8);
  2258. iwl_write_direct32(
  2259. priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
  2260. IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  2261. IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
  2262. iwl_release_nic_access(priv);
  2263. spin_unlock_irqrestore(&priv->lock, flags);
  2264. return 0;
  2265. }
  2266. static inline u8 iwl4965_get_dma_hi_address(dma_addr_t addr)
  2267. {
  2268. return sizeof(addr) > sizeof(u32) ? (addr >> 16) >> 16 : 0;
  2269. }
  2270. int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
  2271. dma_addr_t addr, u16 len)
  2272. {
  2273. int index, is_odd;
  2274. struct iwl_tfd_frame *tfd = ptr;
  2275. u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
  2276. if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
  2277. IWL_ERROR("Error can not send more than %d chunks\n",
  2278. MAX_NUM_OF_TBS);
  2279. return -EINVAL;
  2280. }
  2281. index = num_tbs / 2;
  2282. is_odd = num_tbs & 0x1;
  2283. if (!is_odd) {
  2284. tfd->pa[index].tb1_addr = cpu_to_le32(addr);
  2285. IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
  2286. iwl4965_get_dma_hi_address(addr));
  2287. IWL_SET_BITS(tfd->pa[index], tb1_len, len);
  2288. } else {
  2289. IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
  2290. (u32) (addr & 0xffff));
  2291. IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
  2292. IWL_SET_BITS(tfd->pa[index], tb2_len, len);
  2293. }
  2294. IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
  2295. return 0;
  2296. }
  2297. static void iwl_hw_card_show_info(struct iwl_priv *priv)
  2298. {
  2299. u16 hw_version = priv->eeprom.board_revision_4965;
  2300. IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n",
  2301. ((hw_version >> 8) & 0x0F),
  2302. ((hw_version >> 8) >> 4), (hw_version & 0x00FF));
  2303. IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
  2304. priv->eeprom.board_pba_number_4965);
  2305. }
  2306. #define IWL_TX_CRC_SIZE 4
  2307. #define IWL_TX_DELIMITER_SIZE 4
  2308. int iwl4965_tx_queue_update_wr_ptr(struct iwl_priv *priv,
  2309. struct iwl_tx_queue *txq, u16 byte_cnt)
  2310. {
  2311. int len;
  2312. int txq_id = txq->q.id;
  2313. struct iwl_shared *shared_data = priv->hw_setting.shared_virt;
  2314. if (txq->need_update == 0)
  2315. return 0;
  2316. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  2317. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  2318. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  2319. if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE)
  2320. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  2321. tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr],
  2322. byte_cnt, len);
  2323. return 0;
  2324. }
  2325. /* Set up Rx receiver/antenna/chain usage in "staging" RXON image.
  2326. * This should not be used for scan command ... it puts data in wrong place. */
  2327. void iwl4965_set_rxon_chain(struct iwl_priv *priv)
  2328. {
  2329. u8 is_single = is_single_stream(priv);
  2330. u8 idle_state, rx_state;
  2331. priv->staging_rxon.rx_chain = 0;
  2332. rx_state = idle_state = 3;
  2333. /* Tell uCode which antennas are actually connected.
  2334. * Before first association, we assume all antennas are connected.
  2335. * Just after first association, iwl4965_noise_calibration()
  2336. * checks which antennas actually *are* connected. */
  2337. priv->staging_rxon.rx_chain |=
  2338. cpu_to_le16(priv->valid_antenna << RXON_RX_CHAIN_VALID_POS);
  2339. /* How many receivers should we use? */
  2340. iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
  2341. priv->staging_rxon.rx_chain |=
  2342. cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
  2343. priv->staging_rxon.rx_chain |=
  2344. cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
  2345. if (!is_single && (rx_state >= 2) &&
  2346. !test_bit(STATUS_POWER_PMI, &priv->status))
  2347. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  2348. else
  2349. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  2350. IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
  2351. }
  2352. #ifdef CONFIG_IWL4965_HT
  2353. #ifdef CONFIG_IWL4965_HT_AGG
  2354. /*
  2355. get the traffic load value for tid
  2356. */
  2357. static u32 iwl4965_tl_get_load(struct iwl_priv *priv, u8 tid)
  2358. {
  2359. u32 load = 0;
  2360. u32 current_time = jiffies_to_msecs(jiffies);
  2361. u32 time_diff;
  2362. s32 index;
  2363. unsigned long flags;
  2364. struct iwl_traffic_load *tid_ptr = NULL;
  2365. if (tid >= TID_MAX_LOAD_COUNT)
  2366. return 0;
  2367. tid_ptr = &(priv->lq_mngr.agg_ctrl.traffic_load[tid]);
  2368. current_time -= current_time % TID_ROUND_VALUE;
  2369. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2370. if (!(tid_ptr->queue_count))
  2371. goto out;
  2372. time_diff = TIME_WRAP_AROUND(tid_ptr->time_stamp, current_time);
  2373. index = time_diff / TID_QUEUE_CELL_SPACING;
  2374. if (index >= TID_QUEUE_MAX_SIZE) {
  2375. u32 oldest_time = current_time - TID_MAX_TIME_DIFF;
  2376. while (tid_ptr->queue_count &&
  2377. (tid_ptr->time_stamp < oldest_time)) {
  2378. tid_ptr->total -= tid_ptr->packet_count[tid_ptr->head];
  2379. tid_ptr->packet_count[tid_ptr->head] = 0;
  2380. tid_ptr->time_stamp += TID_QUEUE_CELL_SPACING;
  2381. tid_ptr->queue_count--;
  2382. tid_ptr->head++;
  2383. if (tid_ptr->head >= TID_QUEUE_MAX_SIZE)
  2384. tid_ptr->head = 0;
  2385. }
  2386. }
  2387. load = tid_ptr->total;
  2388. out:
  2389. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2390. return load;
  2391. }
  2392. /*
  2393. increment traffic load value for tid and also remove
  2394. any old values if passed the certian time period
  2395. */
  2396. static void iwl4965_tl_add_packet(struct iwl_priv *priv, u8 tid)
  2397. {
  2398. u32 current_time = jiffies_to_msecs(jiffies);
  2399. u32 time_diff;
  2400. s32 index;
  2401. unsigned long flags;
  2402. struct iwl_traffic_load *tid_ptr = NULL;
  2403. if (tid >= TID_MAX_LOAD_COUNT)
  2404. return;
  2405. tid_ptr = &(priv->lq_mngr.agg_ctrl.traffic_load[tid]);
  2406. current_time -= current_time % TID_ROUND_VALUE;
  2407. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2408. if (!(tid_ptr->queue_count)) {
  2409. tid_ptr->total = 1;
  2410. tid_ptr->time_stamp = current_time;
  2411. tid_ptr->queue_count = 1;
  2412. tid_ptr->head = 0;
  2413. tid_ptr->packet_count[0] = 1;
  2414. goto out;
  2415. }
  2416. time_diff = TIME_WRAP_AROUND(tid_ptr->time_stamp, current_time);
  2417. index = time_diff / TID_QUEUE_CELL_SPACING;
  2418. if (index >= TID_QUEUE_MAX_SIZE) {
  2419. u32 oldest_time = current_time - TID_MAX_TIME_DIFF;
  2420. while (tid_ptr->queue_count &&
  2421. (tid_ptr->time_stamp < oldest_time)) {
  2422. tid_ptr->total -= tid_ptr->packet_count[tid_ptr->head];
  2423. tid_ptr->packet_count[tid_ptr->head] = 0;
  2424. tid_ptr->time_stamp += TID_QUEUE_CELL_SPACING;
  2425. tid_ptr->queue_count--;
  2426. tid_ptr->head++;
  2427. if (tid_ptr->head >= TID_QUEUE_MAX_SIZE)
  2428. tid_ptr->head = 0;
  2429. }
  2430. }
  2431. index = (tid_ptr->head + index) % TID_QUEUE_MAX_SIZE;
  2432. tid_ptr->packet_count[index] = tid_ptr->packet_count[index] + 1;
  2433. tid_ptr->total = tid_ptr->total + 1;
  2434. if ((index + 1) > tid_ptr->queue_count)
  2435. tid_ptr->queue_count = index + 1;
  2436. out:
  2437. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2438. }
  2439. #define MMAC_SCHED_MAX_NUMBER_OF_HT_BACK_FLOWS 7
  2440. enum HT_STATUS {
  2441. BA_STATUS_FAILURE = 0,
  2442. BA_STATUS_INITIATOR_DELBA,
  2443. BA_STATUS_RECIPIENT_DELBA,
  2444. BA_STATUS_RENEW_ADDBA_REQUEST,
  2445. BA_STATUS_ACTIVE,
  2446. };
  2447. static u8 iwl4964_tl_ba_avail(struct iwl_priv *priv)
  2448. {
  2449. int i;
  2450. struct iwl_lq_mngr *lq;
  2451. u8 count = 0;
  2452. u16 msk;
  2453. lq = (struct iwl_lq_mngr *)&(priv->lq_mngr);
  2454. for (i = 0; i < TID_MAX_LOAD_COUNT ; i++) {
  2455. msk = 1 << i;
  2456. if ((lq->agg_ctrl.granted_ba & msk) ||
  2457. (lq->agg_ctrl.wait_for_agg_status & msk))
  2458. count++;
  2459. }
  2460. if (count < MMAC_SCHED_MAX_NUMBER_OF_HT_BACK_FLOWS)
  2461. return 1;
  2462. return 0;
  2463. }
  2464. static void iwl4965_ba_status(struct iwl_priv *priv,
  2465. u8 tid, enum HT_STATUS status);
  2466. static int iwl4965_perform_addba(struct iwl_priv *priv, u8 tid, u32 length,
  2467. u32 ba_timeout)
  2468. {
  2469. int rc;
  2470. rc = ieee80211_start_BA_session(priv->hw, priv->bssid, tid);
  2471. if (rc)
  2472. iwl4965_ba_status(priv, tid, BA_STATUS_FAILURE);
  2473. return rc;
  2474. }
  2475. static int iwl4965_perform_delba(struct iwl_priv *priv, u8 tid)
  2476. {
  2477. int rc;
  2478. rc = ieee80211_stop_BA_session(priv->hw, priv->bssid, tid);
  2479. if (rc)
  2480. iwl4965_ba_status(priv, tid, BA_STATUS_FAILURE);
  2481. return rc;
  2482. }
  2483. static void iwl4965_turn_on_agg_for_tid(struct iwl_priv *priv,
  2484. struct iwl_lq_mngr *lq,
  2485. u8 auto_agg, u8 tid)
  2486. {
  2487. u32 tid_msk = (1 << tid);
  2488. unsigned long flags;
  2489. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2490. /*
  2491. if ((auto_agg) && (!lq->enable_counter)){
  2492. lq->agg_ctrl.next_retry = 0;
  2493. lq->agg_ctrl.tid_retry = 0;
  2494. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2495. return;
  2496. }
  2497. */
  2498. if (!(lq->agg_ctrl.granted_ba & tid_msk) &&
  2499. (lq->agg_ctrl.requested_ba & tid_msk)) {
  2500. u8 available_queues;
  2501. u32 load;
  2502. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2503. available_queues = iwl4964_tl_ba_avail(priv);
  2504. load = iwl4965_tl_get_load(priv, tid);
  2505. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2506. if (!available_queues) {
  2507. if (auto_agg)
  2508. lq->agg_ctrl.tid_retry |= tid_msk;
  2509. else {
  2510. lq->agg_ctrl.requested_ba &= ~tid_msk;
  2511. lq->agg_ctrl.wait_for_agg_status &= ~tid_msk;
  2512. }
  2513. } else if ((auto_agg) &&
  2514. ((load <= lq->agg_ctrl.tid_traffic_load_threshold) ||
  2515. ((lq->agg_ctrl.wait_for_agg_status & tid_msk))))
  2516. lq->agg_ctrl.tid_retry |= tid_msk;
  2517. else {
  2518. lq->agg_ctrl.wait_for_agg_status |= tid_msk;
  2519. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2520. iwl4965_perform_addba(priv, tid, 0x40,
  2521. lq->agg_ctrl.ba_timeout);
  2522. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2523. }
  2524. }
  2525. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2526. }
  2527. static void iwl4965_turn_on_agg(struct iwl_priv *priv, u8 tid)
  2528. {
  2529. struct iwl_lq_mngr *lq;
  2530. unsigned long flags;
  2531. lq = (struct iwl_lq_mngr *)&(priv->lq_mngr);
  2532. if ((tid < TID_MAX_LOAD_COUNT))
  2533. iwl4965_turn_on_agg_for_tid(priv, lq, lq->agg_ctrl.auto_agg,
  2534. tid);
  2535. else if (tid == TID_ALL_SPECIFIED) {
  2536. if (lq->agg_ctrl.requested_ba) {
  2537. for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++)
  2538. iwl4965_turn_on_agg_for_tid(priv, lq,
  2539. lq->agg_ctrl.auto_agg, tid);
  2540. } else {
  2541. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2542. lq->agg_ctrl.tid_retry = 0;
  2543. lq->agg_ctrl.next_retry = 0;
  2544. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2545. }
  2546. }
  2547. }
  2548. void iwl4965_turn_off_agg(struct iwl_priv *priv, u8 tid)
  2549. {
  2550. u32 tid_msk;
  2551. struct iwl_lq_mngr *lq;
  2552. unsigned long flags;
  2553. lq = (struct iwl_lq_mngr *)&(priv->lq_mngr);
  2554. if ((tid < TID_MAX_LOAD_COUNT)) {
  2555. tid_msk = 1 << tid;
  2556. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2557. lq->agg_ctrl.wait_for_agg_status |= tid_msk;
  2558. lq->agg_ctrl.requested_ba &= ~tid_msk;
  2559. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2560. iwl4965_perform_delba(priv, tid);
  2561. } else if (tid == TID_ALL_SPECIFIED) {
  2562. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2563. for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++) {
  2564. tid_msk = 1 << tid;
  2565. lq->agg_ctrl.wait_for_agg_status |= tid_msk;
  2566. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2567. iwl4965_perform_delba(priv, tid);
  2568. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2569. }
  2570. lq->agg_ctrl.requested_ba = 0;
  2571. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2572. }
  2573. }
  2574. static void iwl4965_ba_status(struct iwl_priv *priv,
  2575. u8 tid, enum HT_STATUS status)
  2576. {
  2577. struct iwl_lq_mngr *lq;
  2578. u32 tid_msk = (1 << tid);
  2579. unsigned long flags;
  2580. lq = (struct iwl_lq_mngr *)&(priv->lq_mngr);
  2581. if ((tid >= TID_MAX_LOAD_COUNT))
  2582. goto out;
  2583. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2584. switch (status) {
  2585. case BA_STATUS_ACTIVE:
  2586. if (!(lq->agg_ctrl.granted_ba & tid_msk))
  2587. lq->agg_ctrl.granted_ba |= tid_msk;
  2588. break;
  2589. default:
  2590. if ((lq->agg_ctrl.granted_ba & tid_msk))
  2591. lq->agg_ctrl.granted_ba &= ~tid_msk;
  2592. break;
  2593. }
  2594. lq->agg_ctrl.wait_for_agg_status &= ~tid_msk;
  2595. if (status != BA_STATUS_ACTIVE) {
  2596. if (lq->agg_ctrl.auto_agg) {
  2597. lq->agg_ctrl.tid_retry |= tid_msk;
  2598. lq->agg_ctrl.next_retry =
  2599. jiffies + msecs_to_jiffies(500);
  2600. } else
  2601. lq->agg_ctrl.requested_ba &= ~tid_msk;
  2602. }
  2603. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2604. out:
  2605. return;
  2606. }
  2607. static void iwl4965_bg_agg_work(struct work_struct *work)
  2608. {
  2609. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2610. agg_work);
  2611. u32 tid;
  2612. u32 retry_tid;
  2613. u32 tid_msk;
  2614. unsigned long flags;
  2615. struct iwl_lq_mngr *lq = (struct iwl_lq_mngr *)&(priv->lq_mngr);
  2616. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2617. retry_tid = lq->agg_ctrl.tid_retry;
  2618. lq->agg_ctrl.tid_retry = 0;
  2619. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2620. if (retry_tid == TID_ALL_SPECIFIED)
  2621. iwl4965_turn_on_agg(priv, TID_ALL_SPECIFIED);
  2622. else {
  2623. for (tid = 0; tid < TID_MAX_LOAD_COUNT; tid++) {
  2624. tid_msk = (1 << tid);
  2625. if (retry_tid & tid_msk)
  2626. iwl4965_turn_on_agg(priv, tid);
  2627. }
  2628. }
  2629. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2630. if (lq->agg_ctrl.tid_retry)
  2631. lq->agg_ctrl.next_retry = jiffies + msecs_to_jiffies(500);
  2632. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2633. return;
  2634. }
  2635. #endif /*CONFIG_IWL4965_HT_AGG */
  2636. #endif /* CONFIG_IWL4965_HT */
  2637. int iwl4965_tx_cmd(struct iwl_priv *priv, struct iwl_cmd *out_cmd,
  2638. u8 sta_id, dma_addr_t txcmd_phys,
  2639. struct ieee80211_hdr *hdr, u8 hdr_len,
  2640. struct ieee80211_tx_control *ctrl, void *sta_in)
  2641. {
  2642. struct iwl_tx_cmd cmd;
  2643. struct iwl_tx_cmd *tx = (struct iwl_tx_cmd *)&out_cmd->cmd.payload[0];
  2644. dma_addr_t scratch_phys;
  2645. u8 unicast = 0;
  2646. u8 is_data = 1;
  2647. u16 fc;
  2648. u16 rate_flags;
  2649. int rate_index = min(ctrl->tx_rate & 0xffff, IWL_RATE_COUNT - 1);
  2650. #ifdef CONFIG_IWL4965_HT
  2651. #ifdef CONFIG_IWL4965_HT_AGG
  2652. __le16 *qc;
  2653. #endif /*CONFIG_IWL4965_HT_AGG */
  2654. #endif /* CONFIG_IWL4965_HT */
  2655. unicast = !is_multicast_ether_addr(hdr->addr1);
  2656. fc = le16_to_cpu(hdr->frame_control);
  2657. if ((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA)
  2658. is_data = 0;
  2659. memcpy(&cmd, &(out_cmd->cmd.tx), sizeof(struct iwl_tx_cmd));
  2660. memset(tx, 0, sizeof(struct iwl_tx_cmd));
  2661. memcpy(tx->hdr, hdr, hdr_len);
  2662. tx->len = cmd.len;
  2663. tx->driver_txop = cmd.driver_txop;
  2664. tx->stop_time.life_time = cmd.stop_time.life_time;
  2665. tx->tx_flags = cmd.tx_flags;
  2666. tx->sta_id = cmd.sta_id;
  2667. tx->tid_tspec = cmd.tid_tspec;
  2668. tx->timeout.pm_frame_timeout = cmd.timeout.pm_frame_timeout;
  2669. tx->next_frame_len = cmd.next_frame_len;
  2670. tx->sec_ctl = cmd.sec_ctl;
  2671. memcpy(&(tx->key[0]), &(cmd.key[0]), 16);
  2672. tx->tx_flags = cmd.tx_flags;
  2673. tx->rts_retry_limit = cmd.rts_retry_limit;
  2674. tx->data_retry_limit = cmd.data_retry_limit;
  2675. scratch_phys = txcmd_phys + sizeof(struct iwl_cmd_header) +
  2676. offsetof(struct iwl_tx_cmd, scratch);
  2677. tx->dram_lsb_ptr = cpu_to_le32(scratch_phys);
  2678. tx->dram_msb_ptr = iwl4965_get_dma_hi_address(scratch_phys);
  2679. /* Hard coded to start at the highest retry fallback position
  2680. * until the 4965 specific rate control algorithm is tied in */
  2681. tx->initial_rate_index = LINK_QUAL_MAX_RETRY_NUM - 1;
  2682. /* Alternate between antenna A and B for successive frames */
  2683. if (priv->use_ant_b_for_management_frame) {
  2684. priv->use_ant_b_for_management_frame = 0;
  2685. rate_flags = RATE_MCS_ANT_B_MSK;
  2686. } else {
  2687. priv->use_ant_b_for_management_frame = 1;
  2688. rate_flags = RATE_MCS_ANT_A_MSK;
  2689. }
  2690. if (!unicast || !is_data) {
  2691. if ((rate_index >= IWL_FIRST_CCK_RATE) &&
  2692. (rate_index <= IWL_LAST_CCK_RATE))
  2693. rate_flags |= RATE_MCS_CCK_MSK;
  2694. } else {
  2695. tx->initial_rate_index = 0;
  2696. tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  2697. }
  2698. tx->rate_n_flags = iwl_hw_set_rate_n_flags(iwl_rates[rate_index].plcp,
  2699. rate_flags);
  2700. if (ieee80211_is_back_request(fc))
  2701. tx->tx_flags |= TX_CMD_FLG_ACK_MSK |
  2702. TX_CMD_FLG_IMM_BA_RSP_MASK;
  2703. #ifdef CONFIG_IWL4965_HT
  2704. #ifdef CONFIG_IWL4965_HT_AGG
  2705. qc = ieee80211_get_qos_ctrl(hdr);
  2706. if (qc &&
  2707. (priv->iw_mode != IEEE80211_IF_TYPE_IBSS)) {
  2708. u8 tid = 0;
  2709. tid = (u8) (le16_to_cpu(*qc) & 0xF);
  2710. if (tid < TID_MAX_LOAD_COUNT)
  2711. iwl4965_tl_add_packet(priv, tid);
  2712. }
  2713. if (priv->lq_mngr.agg_ctrl.next_retry &&
  2714. (time_after(priv->lq_mngr.agg_ctrl.next_retry, jiffies))) {
  2715. unsigned long flags;
  2716. spin_lock_irqsave(&priv->lq_mngr.lock, flags);
  2717. priv->lq_mngr.agg_ctrl.next_retry = 0;
  2718. spin_unlock_irqrestore(&priv->lq_mngr.lock, flags);
  2719. schedule_work(&priv->agg_work);
  2720. }
  2721. #endif
  2722. #endif
  2723. return 0;
  2724. }
  2725. /**
  2726. * sign_extend - Sign extend a value using specified bit as sign-bit
  2727. *
  2728. * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
  2729. * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
  2730. *
  2731. * @param oper value to sign extend
  2732. * @param index 0 based bit index (0<=index<32) to sign bit
  2733. */
  2734. static s32 sign_extend(u32 oper, int index)
  2735. {
  2736. u8 shift = 31 - index;
  2737. return (s32)(oper << shift) >> shift;
  2738. }
  2739. /**
  2740. * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
  2741. * @statistics: Provides the temperature reading from the uCode
  2742. *
  2743. * A return of <0 indicates bogus data in the statistics
  2744. */
  2745. int iwl4965_get_temperature(const struct iwl_priv *priv)
  2746. {
  2747. s32 temperature;
  2748. s32 vt;
  2749. s32 R1, R2, R3;
  2750. u32 R4;
  2751. if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
  2752. (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
  2753. IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
  2754. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  2755. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  2756. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  2757. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
  2758. } else {
  2759. IWL_DEBUG_TEMP("Running temperature calibration\n");
  2760. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  2761. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  2762. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  2763. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
  2764. }
  2765. /*
  2766. * Temperature is only 23 bits so sign extend out to 32
  2767. *
  2768. * NOTE If we haven't received a statistics notification yet
  2769. * with an updated temperature, use R4 provided to us in the
  2770. * ALIVE response. */
  2771. if (!test_bit(STATUS_TEMPERATURE, &priv->status))
  2772. vt = sign_extend(R4, 23);
  2773. else
  2774. vt = sign_extend(
  2775. le32_to_cpu(priv->statistics.general.temperature), 23);
  2776. IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
  2777. R1, R2, R3, vt);
  2778. if (R3 == R1) {
  2779. IWL_ERROR("Calibration conflict R1 == R3\n");
  2780. return -1;
  2781. }
  2782. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  2783. * Add offset to center the adjustment around 0 degrees Centigrade. */
  2784. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  2785. temperature /= (R3 - R1);
  2786. temperature = (temperature * 97) / 100 +
  2787. TEMPERATURE_CALIB_KELVIN_OFFSET;
  2788. IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
  2789. KELVIN_TO_CELSIUS(temperature));
  2790. return temperature;
  2791. }
  2792. /* Adjust Txpower only if temperature variance is greater than threshold. */
  2793. #define IWL_TEMPERATURE_THRESHOLD 3
  2794. /**
  2795. * iwl4965_is_temp_calib_needed - determines if new calibration is needed
  2796. *
  2797. * If the temperature changed has changed sufficiently, then a recalibration
  2798. * is needed.
  2799. *
  2800. * Assumes caller will replace priv->last_temperature once calibration
  2801. * executed.
  2802. */
  2803. static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
  2804. {
  2805. int temp_diff;
  2806. if (!test_bit(STATUS_STATISTICS, &priv->status)) {
  2807. IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
  2808. return 0;
  2809. }
  2810. temp_diff = priv->temperature - priv->last_temperature;
  2811. /* get absolute value */
  2812. if (temp_diff < 0) {
  2813. IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
  2814. temp_diff = -temp_diff;
  2815. } else if (temp_diff == 0)
  2816. IWL_DEBUG_POWER("Same temp, \n");
  2817. else
  2818. IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
  2819. if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
  2820. IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
  2821. return 0;
  2822. }
  2823. IWL_DEBUG_POWER("Thermal txpower calib needed\n");
  2824. return 1;
  2825. }
  2826. /* Calculate noise level, based on measurements during network silence just
  2827. * before arriving beacon. This measurement can be done only if we know
  2828. * exactly when to expect beacons, therefore only when we're associated. */
  2829. static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
  2830. {
  2831. struct statistics_rx_non_phy *rx_info
  2832. = &(priv->statistics.rx.general);
  2833. int num_active_rx = 0;
  2834. int total_silence = 0;
  2835. int bcn_silence_a =
  2836. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  2837. int bcn_silence_b =
  2838. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  2839. int bcn_silence_c =
  2840. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  2841. if (bcn_silence_a) {
  2842. total_silence += bcn_silence_a;
  2843. num_active_rx++;
  2844. }
  2845. if (bcn_silence_b) {
  2846. total_silence += bcn_silence_b;
  2847. num_active_rx++;
  2848. }
  2849. if (bcn_silence_c) {
  2850. total_silence += bcn_silence_c;
  2851. num_active_rx++;
  2852. }
  2853. /* Average among active antennas */
  2854. if (num_active_rx)
  2855. priv->last_rx_noise = (total_silence / num_active_rx) - 107;
  2856. else
  2857. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  2858. IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
  2859. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  2860. priv->last_rx_noise);
  2861. }
  2862. void iwl_hw_rx_statistics(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  2863. {
  2864. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  2865. int change;
  2866. s32 temp;
  2867. IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
  2868. (int)sizeof(priv->statistics), pkt->len);
  2869. change = ((priv->statistics.general.temperature !=
  2870. pkt->u.stats.general.temperature) ||
  2871. ((priv->statistics.flag &
  2872. STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
  2873. (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
  2874. memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
  2875. set_bit(STATUS_STATISTICS, &priv->status);
  2876. /* Reschedule the statistics timer to occur in
  2877. * REG_RECALIB_PERIOD seconds to ensure we get a
  2878. * thermal update even if the uCode doesn't give
  2879. * us one */
  2880. mod_timer(&priv->statistics_periodic, jiffies +
  2881. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  2882. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  2883. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  2884. iwl4965_rx_calc_noise(priv);
  2885. #ifdef CONFIG_IWL4965_SENSITIVITY
  2886. queue_work(priv->workqueue, &priv->sensitivity_work);
  2887. #endif
  2888. }
  2889. /* If the hardware hasn't reported a change in
  2890. * temperature then don't bother computing a
  2891. * calibrated temperature value */
  2892. if (!change)
  2893. return;
  2894. temp = iwl4965_get_temperature(priv);
  2895. if (temp < 0)
  2896. return;
  2897. if (priv->temperature != temp) {
  2898. if (priv->temperature)
  2899. IWL_DEBUG_TEMP("Temperature changed "
  2900. "from %dC to %dC\n",
  2901. KELVIN_TO_CELSIUS(priv->temperature),
  2902. KELVIN_TO_CELSIUS(temp));
  2903. else
  2904. IWL_DEBUG_TEMP("Temperature "
  2905. "initialized to %dC\n",
  2906. KELVIN_TO_CELSIUS(temp));
  2907. }
  2908. priv->temperature = temp;
  2909. set_bit(STATUS_TEMPERATURE, &priv->status);
  2910. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  2911. iwl4965_is_temp_calib_needed(priv))
  2912. queue_work(priv->workqueue, &priv->txpower_work);
  2913. }
  2914. static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
  2915. int include_phy,
  2916. struct iwl_rx_mem_buffer *rxb,
  2917. struct ieee80211_rx_status *stats)
  2918. {
  2919. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  2920. struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
  2921. (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
  2922. struct ieee80211_hdr *hdr;
  2923. u16 len;
  2924. __le32 *rx_end;
  2925. unsigned int skblen;
  2926. u32 ampdu_status;
  2927. if (!include_phy && priv->last_phy_res[0])
  2928. rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
  2929. if (!rx_start) {
  2930. IWL_ERROR("MPDU frame without a PHY data\n");
  2931. return;
  2932. }
  2933. if (include_phy) {
  2934. hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
  2935. rx_start->cfg_phy_cnt);
  2936. len = le16_to_cpu(rx_start->byte_count);
  2937. rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
  2938. sizeof(struct iwl4965_rx_phy_res) +
  2939. rx_start->cfg_phy_cnt + len);
  2940. } else {
  2941. struct iwl4965_rx_mpdu_res_start *amsdu =
  2942. (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  2943. hdr = (struct ieee80211_hdr *)(pkt->u.raw +
  2944. sizeof(struct iwl4965_rx_mpdu_res_start));
  2945. len = le16_to_cpu(amsdu->byte_count);
  2946. rx_start->byte_count = amsdu->byte_count;
  2947. rx_end = (__le32 *) (((u8 *) hdr) + len);
  2948. }
  2949. if (len > IWL_RX_BUF_SIZE || len < 16) {
  2950. IWL_WARNING("byte count out of range [16,4K]"
  2951. " : %d\n", len);
  2952. return;
  2953. }
  2954. ampdu_status = le32_to_cpu(*rx_end);
  2955. skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
  2956. /* start from MAC */
  2957. skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
  2958. skb_put(rxb->skb, len); /* end where data ends */
  2959. /* We only process data packets if the interface is open */
  2960. if (unlikely(!priv->is_open)) {
  2961. IWL_DEBUG_DROP_LIMIT
  2962. ("Dropping packet while interface is not open.\n");
  2963. return;
  2964. }
  2965. if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
  2966. if (iwl_param_hwcrypto)
  2967. iwl_set_decrypted_flag(priv, rxb->skb,
  2968. ampdu_status, stats);
  2969. iwl_handle_data_packet_monitor(priv, rxb, hdr, len, stats, 0);
  2970. return;
  2971. }
  2972. stats->flag = 0;
  2973. hdr = (struct ieee80211_hdr *)rxb->skb->data;
  2974. if (iwl_param_hwcrypto)
  2975. iwl_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats);
  2976. ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
  2977. priv->alloc_rxb_skb--;
  2978. rxb->skb = NULL;
  2979. #ifdef LED
  2980. priv->led_packets += len;
  2981. iwl_setup_activity_timer(priv);
  2982. #endif
  2983. }
  2984. /* Calc max signal level (dBm) among 3 possible receivers */
  2985. static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
  2986. {
  2987. /* data from PHY/DSP regarding signal strength, etc.,
  2988. * contents are always there, not configurable by host. */
  2989. struct iwl4965_rx_non_cfg_phy *ncphy =
  2990. (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
  2991. u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
  2992. >> IWL_AGC_DB_POS;
  2993. u32 valid_antennae =
  2994. (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
  2995. >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
  2996. u8 max_rssi = 0;
  2997. u32 i;
  2998. /* Find max rssi among 3 possible receivers.
  2999. * These values are measured by the digital signal processor (DSP).
  3000. * They should stay fairly constant even as the signal strength varies,
  3001. * if the radio's automatic gain control (AGC) is working right.
  3002. * AGC value (see below) will provide the "interesting" info. */
  3003. for (i = 0; i < 3; i++)
  3004. if (valid_antennae & (1 << i))
  3005. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  3006. IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  3007. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  3008. max_rssi, agc);
  3009. /* dBm = max_rssi dB - agc dB - constant.
  3010. * Higher AGC (higher radio gain) means lower signal. */
  3011. return (max_rssi - agc - IWL_RSSI_OFFSET);
  3012. }
  3013. #ifdef CONFIG_IWL4965_HT
  3014. /* Parsed Information Elements */
  3015. struct ieee802_11_elems {
  3016. u8 *ds_params;
  3017. u8 ds_params_len;
  3018. u8 *tim;
  3019. u8 tim_len;
  3020. u8 *ibss_params;
  3021. u8 ibss_params_len;
  3022. u8 *erp_info;
  3023. u8 erp_info_len;
  3024. u8 *ht_cap_param;
  3025. u8 ht_cap_param_len;
  3026. u8 *ht_extra_param;
  3027. u8 ht_extra_param_len;
  3028. };
  3029. static int parse_elems(u8 *start, size_t len, struct ieee802_11_elems *elems)
  3030. {
  3031. size_t left = len;
  3032. u8 *pos = start;
  3033. int unknown = 0;
  3034. memset(elems, 0, sizeof(*elems));
  3035. while (left >= 2) {
  3036. u8 id, elen;
  3037. id = *pos++;
  3038. elen = *pos++;
  3039. left -= 2;
  3040. if (elen > left)
  3041. return -1;
  3042. switch (id) {
  3043. case WLAN_EID_DS_PARAMS:
  3044. elems->ds_params = pos;
  3045. elems->ds_params_len = elen;
  3046. break;
  3047. case WLAN_EID_TIM:
  3048. elems->tim = pos;
  3049. elems->tim_len = elen;
  3050. break;
  3051. case WLAN_EID_IBSS_PARAMS:
  3052. elems->ibss_params = pos;
  3053. elems->ibss_params_len = elen;
  3054. break;
  3055. case WLAN_EID_ERP_INFO:
  3056. elems->erp_info = pos;
  3057. elems->erp_info_len = elen;
  3058. break;
  3059. case WLAN_EID_HT_CAPABILITY:
  3060. elems->ht_cap_param = pos;
  3061. elems->ht_cap_param_len = elen;
  3062. break;
  3063. case WLAN_EID_HT_EXTRA_INFO:
  3064. elems->ht_extra_param = pos;
  3065. elems->ht_extra_param_len = elen;
  3066. break;
  3067. default:
  3068. unknown++;
  3069. break;
  3070. }
  3071. left -= elen;
  3072. pos += elen;
  3073. }
  3074. return 0;
  3075. }
  3076. #endif /* CONFIG_IWL4965_HT */
  3077. static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  3078. {
  3079. unsigned long flags;
  3080. spin_lock_irqsave(&priv->sta_lock, flags);
  3081. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  3082. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  3083. priv->stations[sta_id].sta.sta.modify_mask = 0;
  3084. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3085. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3086. iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3087. }
  3088. static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  3089. {
  3090. /* FIXME: need locking over ps_status ??? */
  3091. u8 sta_id = iwl_hw_find_station(priv, addr);
  3092. if (sta_id != IWL_INVALID_STATION) {
  3093. u8 sta_awake = priv->stations[sta_id].
  3094. ps_status == STA_PS_STATUS_WAKE;
  3095. if (sta_awake && ps_bit)
  3096. priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
  3097. else if (!sta_awake && !ps_bit) {
  3098. iwl4965_sta_modify_ps_wake(priv, sta_id);
  3099. priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
  3100. }
  3101. }
  3102. }
  3103. /* Called for REPLY_4965_RX (legacy ABG frames), or
  3104. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  3105. static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
  3106. struct iwl_rx_mem_buffer *rxb)
  3107. {
  3108. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  3109. /* Use phy data (Rx signal strength, etc.) contained within
  3110. * this rx packet for legacy frames,
  3111. * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
  3112. int include_phy = (pkt->hdr.cmd == REPLY_4965_RX);
  3113. struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
  3114. (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
  3115. (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
  3116. __le32 *rx_end;
  3117. unsigned int len = 0;
  3118. struct ieee80211_hdr *header;
  3119. u16 fc;
  3120. struct ieee80211_rx_status stats = {
  3121. .mactime = le64_to_cpu(rx_start->timestamp),
  3122. .channel = le16_to_cpu(rx_start->channel),
  3123. .phymode =
  3124. (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  3125. MODE_IEEE80211G : MODE_IEEE80211A,
  3126. .antenna = 0,
  3127. .rate = iwl_hw_get_rate(rx_start->rate_n_flags),
  3128. .flag = 0,
  3129. #ifdef CONFIG_IWL4965_HT_AGG
  3130. .ordered = 0
  3131. #endif /* CONFIG_IWL4965_HT_AGG */
  3132. };
  3133. u8 network_packet;
  3134. if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
  3135. IWL_DEBUG_DROP
  3136. ("dsp size out of range [0,20]: "
  3137. "%d/n", rx_start->cfg_phy_cnt);
  3138. return;
  3139. }
  3140. if (!include_phy) {
  3141. if (priv->last_phy_res[0])
  3142. rx_start = (struct iwl4965_rx_phy_res *)
  3143. &priv->last_phy_res[1];
  3144. else
  3145. rx_start = NULL;
  3146. }
  3147. if (!rx_start) {
  3148. IWL_ERROR("MPDU frame without a PHY data\n");
  3149. return;
  3150. }
  3151. if (include_phy) {
  3152. header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
  3153. + rx_start->cfg_phy_cnt);
  3154. len = le16_to_cpu(rx_start->byte_count);
  3155. rx_end = (__le32 *) (pkt->u.raw + rx_start->cfg_phy_cnt +
  3156. sizeof(struct iwl4965_rx_phy_res) + len);
  3157. } else {
  3158. struct iwl4965_rx_mpdu_res_start *amsdu =
  3159. (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  3160. header = (void *)(pkt->u.raw +
  3161. sizeof(struct iwl4965_rx_mpdu_res_start));
  3162. len = le16_to_cpu(amsdu->byte_count);
  3163. rx_end = (__le32 *) (pkt->u.raw +
  3164. sizeof(struct iwl4965_rx_mpdu_res_start) + len);
  3165. }
  3166. if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
  3167. !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  3168. IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
  3169. le32_to_cpu(*rx_end));
  3170. return;
  3171. }
  3172. priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
  3173. stats.freq = ieee80211chan2mhz(stats.channel);
  3174. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  3175. stats.ssi = iwl4965_calc_rssi(rx_start);
  3176. /* Meaningful noise values are available only from beacon statistics,
  3177. * which are gathered only when associated, and indicate noise
  3178. * only for the associated network channel ...
  3179. * Ignore these noise values while scanning (other channels) */
  3180. if (iwl_is_associated(priv) &&
  3181. !test_bit(STATUS_SCANNING, &priv->status)) {
  3182. stats.noise = priv->last_rx_noise;
  3183. stats.signal = iwl_calc_sig_qual(stats.ssi, stats.noise);
  3184. } else {
  3185. stats.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  3186. stats.signal = iwl_calc_sig_qual(stats.ssi, 0);
  3187. }
  3188. /* Reset beacon noise level if not associated. */
  3189. if (!iwl_is_associated(priv))
  3190. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  3191. #ifdef CONFIG_IWL4965_DEBUG
  3192. /* TODO: Parts of iwl_report_frame are broken for 4965 */
  3193. if (iwl_debug_level & (IWL_DL_RX))
  3194. /* Set "1" to report good data frames in groups of 100 */
  3195. iwl_report_frame(priv, pkt, header, 1);
  3196. if (iwl_debug_level & (IWL_DL_RX | IWL_DL_STATS))
  3197. IWL_DEBUG_RX("Rssi %d, noise %d, qual %d, TSF %lu\n",
  3198. stats.ssi, stats.noise, stats.signal,
  3199. (long unsigned int)le64_to_cpu(rx_start->timestamp));
  3200. #endif
  3201. network_packet = iwl_is_network_packet(priv, header);
  3202. if (network_packet) {
  3203. priv->last_rx_rssi = stats.ssi;
  3204. priv->last_beacon_time = priv->ucode_beacon_time;
  3205. priv->last_tsf = le64_to_cpu(rx_start->timestamp);
  3206. }
  3207. fc = le16_to_cpu(header->frame_control);
  3208. switch (fc & IEEE80211_FCTL_FTYPE) {
  3209. case IEEE80211_FTYPE_MGMT:
  3210. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3211. iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
  3212. header->addr2);
  3213. switch (fc & IEEE80211_FCTL_STYPE) {
  3214. case IEEE80211_STYPE_PROBE_RESP:
  3215. case IEEE80211_STYPE_BEACON:
  3216. if ((priv->iw_mode == IEEE80211_IF_TYPE_STA &&
  3217. !compare_ether_addr(header->addr2, priv->bssid)) ||
  3218. (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
  3219. !compare_ether_addr(header->addr3, priv->bssid))) {
  3220. struct ieee80211_mgmt *mgmt =
  3221. (struct ieee80211_mgmt *)header;
  3222. u64 timestamp =
  3223. le64_to_cpu(mgmt->u.beacon.timestamp);
  3224. priv->timestamp0 = timestamp & 0xFFFFFFFF;
  3225. priv->timestamp1 =
  3226. (timestamp >> 32) & 0xFFFFFFFF;
  3227. priv->beacon_int = le16_to_cpu(
  3228. mgmt->u.beacon.beacon_int);
  3229. if (priv->call_post_assoc_from_beacon &&
  3230. (priv->iw_mode == IEEE80211_IF_TYPE_STA)) {
  3231. priv->call_post_assoc_from_beacon = 0;
  3232. queue_work(priv->workqueue,
  3233. &priv->post_associate.work);
  3234. }
  3235. }
  3236. break;
  3237. case IEEE80211_STYPE_ACTION:
  3238. break;
  3239. /*
  3240. * TODO: There is no callback function from upper
  3241. * stack to inform us when associated status. this
  3242. * work around to sniff assoc_resp management frame
  3243. * and finish the association process.
  3244. */
  3245. case IEEE80211_STYPE_ASSOC_RESP:
  3246. case IEEE80211_STYPE_REASSOC_RESP:
  3247. if (network_packet) {
  3248. #ifdef CONFIG_IWL4965_HT
  3249. u8 *pos = NULL;
  3250. struct ieee802_11_elems elems;
  3251. #endif /*CONFIG_IWL4965_HT */
  3252. struct ieee80211_mgmt *mgnt =
  3253. (struct ieee80211_mgmt *)header;
  3254. priv->assoc_id = (~((1 << 15) | (1 << 14))
  3255. & le16_to_cpu(mgnt->u.assoc_resp.aid));
  3256. priv->assoc_capability =
  3257. le16_to_cpu(
  3258. mgnt->u.assoc_resp.capab_info);
  3259. #ifdef CONFIG_IWL4965_HT
  3260. pos = mgnt->u.assoc_resp.variable;
  3261. if (!parse_elems(pos,
  3262. len - (pos - (u8 *) mgnt),
  3263. &elems)) {
  3264. if (elems.ht_extra_param &&
  3265. elems.ht_cap_param)
  3266. break;
  3267. }
  3268. #endif /*CONFIG_IWL4965_HT */
  3269. /* assoc_id is 0 no association */
  3270. if (!priv->assoc_id)
  3271. break;
  3272. if (priv->beacon_int)
  3273. queue_work(priv->workqueue,
  3274. &priv->post_associate.work);
  3275. else
  3276. priv->call_post_assoc_from_beacon = 1;
  3277. }
  3278. break;
  3279. case IEEE80211_STYPE_PROBE_REQ:
  3280. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
  3281. !iwl_is_associated(priv)) {
  3282. DECLARE_MAC_BUF(mac1);
  3283. DECLARE_MAC_BUF(mac2);
  3284. DECLARE_MAC_BUF(mac3);
  3285. IWL_DEBUG_DROP("Dropping (non network): "
  3286. "%s, %s, %s\n",
  3287. print_mac(mac1, header->addr1),
  3288. print_mac(mac2, header->addr2),
  3289. print_mac(mac3, header->addr3));
  3290. return;
  3291. }
  3292. }
  3293. iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &stats);
  3294. break;
  3295. case IEEE80211_FTYPE_CTL:
  3296. #ifdef CONFIG_IWL4965_HT_AGG
  3297. switch (fc & IEEE80211_FCTL_STYPE) {
  3298. case IEEE80211_STYPE_BACK_REQ:
  3299. IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
  3300. iwl4965_handle_data_packet(priv, 0, include_phy,
  3301. rxb, &stats);
  3302. break;
  3303. default:
  3304. break;
  3305. }
  3306. #endif
  3307. break;
  3308. case IEEE80211_FTYPE_DATA: {
  3309. DECLARE_MAC_BUF(mac1);
  3310. DECLARE_MAC_BUF(mac2);
  3311. DECLARE_MAC_BUF(mac3);
  3312. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  3313. iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
  3314. header->addr2);
  3315. if (unlikely(!network_packet))
  3316. IWL_DEBUG_DROP("Dropping (non network): "
  3317. "%s, %s, %s\n",
  3318. print_mac(mac1, header->addr1),
  3319. print_mac(mac2, header->addr2),
  3320. print_mac(mac3, header->addr3));
  3321. else if (unlikely(is_duplicate_packet(priv, header)))
  3322. IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
  3323. print_mac(mac1, header->addr1),
  3324. print_mac(mac2, header->addr2),
  3325. print_mac(mac3, header->addr3));
  3326. else
  3327. iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
  3328. &stats);
  3329. break;
  3330. }
  3331. default:
  3332. break;
  3333. }
  3334. }
  3335. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  3336. * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  3337. static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
  3338. struct iwl_rx_mem_buffer *rxb)
  3339. {
  3340. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  3341. priv->last_phy_res[0] = 1;
  3342. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  3343. sizeof(struct iwl4965_rx_phy_res));
  3344. }
  3345. static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
  3346. struct iwl_rx_mem_buffer *rxb)
  3347. {
  3348. #ifdef CONFIG_IWL4965_SENSITIVITY
  3349. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  3350. struct iwl_missed_beacon_notif *missed_beacon;
  3351. missed_beacon = &pkt->u.missed_beacon;
  3352. if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
  3353. IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  3354. le32_to_cpu(missed_beacon->consequtive_missed_beacons),
  3355. le32_to_cpu(missed_beacon->total_missed_becons),
  3356. le32_to_cpu(missed_beacon->num_recvd_beacons),
  3357. le32_to_cpu(missed_beacon->num_expected_beacons));
  3358. priv->sensitivity_data.state = IWL_SENS_CALIB_NEED_REINIT;
  3359. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)))
  3360. queue_work(priv->workqueue, &priv->sensitivity_work);
  3361. }
  3362. #endif /*CONFIG_IWL4965_SENSITIVITY*/
  3363. }
  3364. #ifdef CONFIG_IWL4965_HT
  3365. #ifdef CONFIG_IWL4965_HT_AGG
  3366. static void iwl4965_set_tx_status(struct iwl_priv *priv, int txq_id, int idx,
  3367. u32 status, u32 retry_count, u32 rate)
  3368. {
  3369. struct ieee80211_tx_status *tx_status =
  3370. &(priv->txq[txq_id].txb[idx].status);
  3371. tx_status->flags = status ? IEEE80211_TX_STATUS_ACK : 0;
  3372. tx_status->retry_count += retry_count;
  3373. tx_status->control.tx_rate = rate;
  3374. }
  3375. static void iwl_sta_modify_enable_tid_tx(struct iwl_priv *priv,
  3376. int sta_id, int tid)
  3377. {
  3378. unsigned long flags;
  3379. spin_lock_irqsave(&priv->sta_lock, flags);
  3380. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  3381. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  3382. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3383. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3384. iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3385. }
  3386. static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
  3387. struct iwl_ht_agg *agg,
  3388. struct iwl_compressed_ba_resp*
  3389. ba_resp)
  3390. {
  3391. int i, sh, ack;
  3392. u16 ba_seq_ctl = le16_to_cpu(ba_resp->ba_seq_ctl);
  3393. u32 bitmap0, bitmap1;
  3394. u32 resp_bitmap0 = le32_to_cpu(ba_resp->ba_bitmap0);
  3395. u32 resp_bitmap1 = le32_to_cpu(ba_resp->ba_bitmap1);
  3396. if (unlikely(!agg->wait_for_ba)) {
  3397. IWL_ERROR("Received BA when not expected\n");
  3398. return -EINVAL;
  3399. }
  3400. agg->wait_for_ba = 0;
  3401. IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->ba_seq_ctl);
  3402. sh = agg->start_idx - SEQ_TO_INDEX(ba_seq_ctl>>4);
  3403. if (sh < 0) /* tbw something is wrong with indices */
  3404. sh += 0x100;
  3405. /* don't use 64 bits for now */
  3406. bitmap0 = resp_bitmap0 >> sh;
  3407. bitmap1 = resp_bitmap1 >> sh;
  3408. bitmap0 |= (resp_bitmap1 & ((1<<sh)|((1<<sh)-1))) << (32 - sh);
  3409. if (agg->frame_count > (64 - sh)) {
  3410. IWL_DEBUG_TX_REPLY("more frames than bitmap size");
  3411. return -1;
  3412. }
  3413. /* check for success or failure according to the
  3414. * transmitted bitmap and back bitmap */
  3415. bitmap0 &= agg->bitmap0;
  3416. bitmap1 &= agg->bitmap1;
  3417. for (i = 0; i < agg->frame_count ; i++) {
  3418. int idx = (agg->start_idx + i) & 0xff;
  3419. ack = bitmap0 & (1 << i);
  3420. IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
  3421. ack? "ACK":"NACK", i, idx, agg->start_idx + i);
  3422. iwl4965_set_tx_status(priv, agg->txq_id, idx, ack, 0,
  3423. agg->rate_n_flags);
  3424. }
  3425. IWL_DEBUG_TX_REPLY("Bitmap %x%x\n", bitmap0, bitmap1);
  3426. return 0;
  3427. }
  3428. static inline int iwl_queue_dec_wrap(int index, int n_bd)
  3429. {
  3430. return (index == 0) ? n_bd - 1 : index - 1;
  3431. }
  3432. static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
  3433. struct iwl_rx_mem_buffer *rxb)
  3434. {
  3435. struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
  3436. struct iwl_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  3437. int index;
  3438. struct iwl_tx_queue *txq = NULL;
  3439. struct iwl_ht_agg *agg;
  3440. u16 ba_resp_scd_flow = le16_to_cpu(ba_resp->scd_flow);
  3441. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  3442. if (ba_resp_scd_flow >= ARRAY_SIZE(priv->txq)) {
  3443. IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
  3444. return;
  3445. }
  3446. txq = &priv->txq[ba_resp_scd_flow];
  3447. agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
  3448. index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  3449. /* TODO: Need to get this copy more safely - now good for debug */
  3450. /*
  3451. {
  3452. DECLARE_MAC_BUF(mac);
  3453. IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
  3454. "sta_id = %d\n",
  3455. agg->wait_for_ba,
  3456. print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
  3457. ba_resp->sta_id);
  3458. IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%X%X, scd_flow = "
  3459. "%d, scd_ssn = %d\n",
  3460. ba_resp->tid,
  3461. ba_resp->ba_seq_ctl,
  3462. ba_resp->ba_bitmap1,
  3463. ba_resp->ba_bitmap0,
  3464. ba_resp->scd_flow,
  3465. ba_resp->scd_ssn);
  3466. IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%X%X \n",
  3467. agg->start_idx,
  3468. agg->bitmap1,
  3469. agg->bitmap0);
  3470. }
  3471. */
  3472. iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
  3473. /* releases all the TFDs until the SSN */
  3474. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff))
  3475. iwl_tx_queue_reclaim(priv, ba_resp_scd_flow, index);
  3476. }
  3477. static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv, u16 txq_id)
  3478. {
  3479. iwl_write_prph(priv,
  3480. KDR_SCD_QUEUE_STATUS_BITS(txq_id),
  3481. (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  3482. (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  3483. }
  3484. static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  3485. u16 txq_id)
  3486. {
  3487. u32 tbl_dw_addr;
  3488. u32 tbl_dw;
  3489. u16 scd_q2ratid;
  3490. scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  3491. tbl_dw_addr = priv->scd_base_addr +
  3492. SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  3493. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  3494. if (txq_id & 0x1)
  3495. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  3496. else
  3497. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  3498. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  3499. return 0;
  3500. }
  3501. /**
  3502. * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
  3503. */
  3504. static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
  3505. int tx_fifo, int sta_id, int tid,
  3506. u16 ssn_idx)
  3507. {
  3508. unsigned long flags;
  3509. int rc;
  3510. u16 ra_tid;
  3511. if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
  3512. IWL_WARNING("queue number too small: %d, must be > %d\n",
  3513. txq_id, IWL_BACK_QUEUE_FIRST_ID);
  3514. ra_tid = BUILD_RAxTID(sta_id, tid);
  3515. iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
  3516. spin_lock_irqsave(&priv->lock, flags);
  3517. rc = iwl_grab_nic_access(priv);
  3518. if (rc) {
  3519. spin_unlock_irqrestore(&priv->lock, flags);
  3520. return rc;
  3521. }
  3522. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  3523. iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  3524. iwl_set_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1<<txq_id));
  3525. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  3526. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  3527. /* supposes that ssn_idx is valid (!= 0xFFF) */
  3528. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  3529. iwl_write_targ_mem(priv,
  3530. priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  3531. (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  3532. SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  3533. iwl_write_targ_mem(priv, priv->scd_base_addr +
  3534. SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  3535. (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
  3536. & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  3537. iwl_set_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id));
  3538. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  3539. iwl_release_nic_access(priv);
  3540. spin_unlock_irqrestore(&priv->lock, flags);
  3541. return 0;
  3542. }
  3543. /**
  3544. * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
  3545. */
  3546. static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
  3547. u16 ssn_idx, u8 tx_fifo)
  3548. {
  3549. unsigned long flags;
  3550. int rc;
  3551. if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
  3552. IWL_WARNING("queue number too small: %d, must be > %d\n",
  3553. txq_id, IWL_BACK_QUEUE_FIRST_ID);
  3554. return -EINVAL;
  3555. }
  3556. spin_lock_irqsave(&priv->lock, flags);
  3557. rc = iwl_grab_nic_access(priv);
  3558. if (rc) {
  3559. spin_unlock_irqrestore(&priv->lock, flags);
  3560. return rc;
  3561. }
  3562. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  3563. iwl_clear_bits_prph(priv, KDR_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  3564. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  3565. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  3566. /* supposes that ssn_idx is valid (!= 0xFFF) */
  3567. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  3568. iwl_clear_bits_prph(priv, KDR_SCD_INTERRUPT_MASK, (1 << txq_id));
  3569. iwl4965_txq_ctx_deactivate(priv, txq_id);
  3570. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  3571. iwl_release_nic_access(priv);
  3572. spin_unlock_irqrestore(&priv->lock, flags);
  3573. return 0;
  3574. }
  3575. #endif/* CONFIG_IWL4965_HT_AGG */
  3576. #endif /* CONFIG_IWL4965_HT */
  3577. /*
  3578. * RATE SCALE CODE
  3579. */
  3580. int iwl4965_init_hw_rates(struct iwl_priv *priv, struct ieee80211_rate *rates)
  3581. {
  3582. return 0;
  3583. }
  3584. /**
  3585. * iwl4965_add_station - Initialize a station's hardware rate table
  3586. *
  3587. * The uCode contains a table of fallback rates and retries per rate
  3588. * for automatic fallback during transmission.
  3589. *
  3590. * NOTE: This initializes the table for a single retry per data rate
  3591. * which is not optimal. Setting up an intelligent retry per rate
  3592. * requires feedback from transmission, which isn't exposed through
  3593. * rc80211_simple which is what this driver is currently using.
  3594. *
  3595. */
  3596. void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  3597. {
  3598. int i, r;
  3599. struct iwl_link_quality_cmd link_cmd = {
  3600. .reserved1 = 0,
  3601. };
  3602. u16 rate_flags;
  3603. /* Set up the rate scaling to start at 54M and fallback
  3604. * all the way to 1M in IEEE order and then spin on IEEE */
  3605. if (is_ap)
  3606. r = IWL_RATE_54M_INDEX;
  3607. else if (priv->phymode == MODE_IEEE80211A)
  3608. r = IWL_RATE_6M_INDEX;
  3609. else
  3610. r = IWL_RATE_1M_INDEX;
  3611. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  3612. rate_flags = 0;
  3613. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  3614. rate_flags |= RATE_MCS_CCK_MSK;
  3615. rate_flags |= RATE_MCS_ANT_B_MSK;
  3616. rate_flags &= ~RATE_MCS_ANT_A_MSK;
  3617. link_cmd.rs_table[i].rate_n_flags =
  3618. iwl_hw_set_rate_n_flags(iwl_rates[r].plcp, rate_flags);
  3619. r = iwl_get_prev_ieee_rate(r);
  3620. }
  3621. link_cmd.general_params.single_stream_ant_msk = 2;
  3622. link_cmd.general_params.dual_stream_ant_msk = 3;
  3623. link_cmd.agg_params.agg_dis_start_th = 3;
  3624. link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
  3625. /* Update the rate scaling for control frame Tx to AP */
  3626. link_cmd.sta_id = is_ap ? IWL_AP_ID : IWL4965_BROADCAST_ID;
  3627. iwl_send_cmd_pdu(priv, REPLY_TX_LINK_QUALITY_CMD, sizeof(link_cmd),
  3628. &link_cmd);
  3629. }
  3630. #ifdef CONFIG_IWL4965_HT
  3631. static u8 iwl_is_channel_extension(struct iwl_priv *priv, int phymode,
  3632. u16 channel, u8 extension_chan_offset)
  3633. {
  3634. const struct iwl_channel_info *ch_info;
  3635. ch_info = iwl_get_channel_info(priv, phymode, channel);
  3636. if (!is_channel_valid(ch_info))
  3637. return 0;
  3638. if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_AUTO)
  3639. return 0;
  3640. if ((ch_info->fat_extension_channel == extension_chan_offset) ||
  3641. (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
  3642. return 1;
  3643. return 0;
  3644. }
  3645. static u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
  3646. const struct sta_ht_info *ht_info)
  3647. {
  3648. if (priv->channel_width != IWL_CHANNEL_WIDTH_40MHZ)
  3649. return 0;
  3650. if (ht_info->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ)
  3651. return 0;
  3652. if (ht_info->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_AUTO)
  3653. return 0;
  3654. /* no fat tx allowed on 2.4GHZ */
  3655. if (priv->phymode != MODE_IEEE80211A)
  3656. return 0;
  3657. return (iwl_is_channel_extension(priv, priv->phymode,
  3658. ht_info->control_channel,
  3659. ht_info->extension_chan_offset));
  3660. }
  3661. void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct sta_ht_info *ht_info)
  3662. {
  3663. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  3664. u32 val;
  3665. if (!ht_info->is_ht)
  3666. return;
  3667. if (iwl_is_fat_tx_allowed(priv, ht_info))
  3668. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  3669. else
  3670. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  3671. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  3672. if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
  3673. IWL_DEBUG_ASSOC("control diff than current %d %d\n",
  3674. le16_to_cpu(rxon->channel),
  3675. ht_info->control_channel);
  3676. rxon->channel = cpu_to_le16(ht_info->control_channel);
  3677. return;
  3678. }
  3679. /* Note: control channel is oposit to extension channel */
  3680. switch (ht_info->extension_chan_offset) {
  3681. case IWL_EXT_CHANNEL_OFFSET_ABOVE:
  3682. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  3683. break;
  3684. case IWL_EXT_CHANNEL_OFFSET_BELOW:
  3685. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  3686. break;
  3687. case IWL_EXT_CHANNEL_OFFSET_AUTO:
  3688. rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  3689. break;
  3690. default:
  3691. rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  3692. break;
  3693. }
  3694. val = ht_info->operating_mode;
  3695. rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
  3696. priv->active_rate_ht[0] = ht_info->supp_rates[0];
  3697. priv->active_rate_ht[1] = ht_info->supp_rates[1];
  3698. iwl4965_set_rxon_chain(priv);
  3699. IWL_DEBUG_ASSOC("supported HT rate 0x%X %X "
  3700. "rxon flags 0x%X operation mode :0x%X "
  3701. "extension channel offset 0x%x "
  3702. "control chan %d\n",
  3703. priv->active_rate_ht[0], priv->active_rate_ht[1],
  3704. le32_to_cpu(rxon->flags), ht_info->operating_mode,
  3705. ht_info->extension_chan_offset,
  3706. ht_info->control_channel);
  3707. return;
  3708. }
  3709. void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index)
  3710. {
  3711. __le32 sta_flags;
  3712. struct sta_ht_info *ht_info = &priv->current_assoc_ht;
  3713. priv->current_channel_width = IWL_CHANNEL_WIDTH_20MHZ;
  3714. if (!ht_info->is_ht)
  3715. goto done;
  3716. sta_flags = priv->stations[index].sta.station_flags;
  3717. if (ht_info->tx_mimo_ps_mode == IWL_MIMO_PS_DYNAMIC)
  3718. sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
  3719. else
  3720. sta_flags &= ~STA_FLG_RTS_MIMO_PROT_MSK;
  3721. sta_flags |= cpu_to_le32(
  3722. (u32)ht_info->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
  3723. sta_flags |= cpu_to_le32(
  3724. (u32)ht_info->mpdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
  3725. sta_flags &= (~STA_FLG_FAT_EN_MSK);
  3726. ht_info->tx_chan_width = IWL_CHANNEL_WIDTH_20MHZ;
  3727. ht_info->chan_width_cap = IWL_CHANNEL_WIDTH_20MHZ;
  3728. if (iwl_is_fat_tx_allowed(priv, ht_info)) {
  3729. sta_flags |= STA_FLG_FAT_EN_MSK;
  3730. ht_info->chan_width_cap = IWL_CHANNEL_WIDTH_40MHZ;
  3731. if (ht_info->supported_chan_width == IWL_CHANNEL_WIDTH_40MHZ)
  3732. ht_info->tx_chan_width = IWL_CHANNEL_WIDTH_40MHZ;
  3733. }
  3734. priv->current_channel_width = ht_info->tx_chan_width;
  3735. priv->stations[index].sta.station_flags = sta_flags;
  3736. done:
  3737. return;
  3738. }
  3739. #ifdef CONFIG_IWL4965_HT_AGG
  3740. static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv,
  3741. int sta_id, int tid, u16 ssn)
  3742. {
  3743. unsigned long flags;
  3744. spin_lock_irqsave(&priv->sta_lock, flags);
  3745. priv->stations[sta_id].sta.station_flags_msk = 0;
  3746. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  3747. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  3748. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  3749. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3750. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3751. iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3752. }
  3753. static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv,
  3754. int sta_id, int tid)
  3755. {
  3756. unsigned long flags;
  3757. spin_lock_irqsave(&priv->sta_lock, flags);
  3758. priv->stations[sta_id].sta.station_flags_msk = 0;
  3759. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  3760. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  3761. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3762. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3763. iwl_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3764. }
  3765. static const u16 default_tid_to_tx_fifo[] = {
  3766. IWL_TX_FIFO_AC1,
  3767. IWL_TX_FIFO_AC0,
  3768. IWL_TX_FIFO_AC0,
  3769. IWL_TX_FIFO_AC1,
  3770. IWL_TX_FIFO_AC2,
  3771. IWL_TX_FIFO_AC2,
  3772. IWL_TX_FIFO_AC3,
  3773. IWL_TX_FIFO_AC3,
  3774. IWL_TX_FIFO_NONE,
  3775. IWL_TX_FIFO_NONE,
  3776. IWL_TX_FIFO_NONE,
  3777. IWL_TX_FIFO_NONE,
  3778. IWL_TX_FIFO_NONE,
  3779. IWL_TX_FIFO_NONE,
  3780. IWL_TX_FIFO_NONE,
  3781. IWL_TX_FIFO_NONE,
  3782. IWL_TX_FIFO_AC3
  3783. };
  3784. static int iwl_txq_ctx_activate_free(struct iwl_priv *priv)
  3785. {
  3786. int txq_id;
  3787. for (txq_id = 0; txq_id < priv->hw_setting.max_txq_num; txq_id++)
  3788. if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
  3789. return txq_id;
  3790. return -1;
  3791. }
  3792. int iwl_mac_ht_tx_agg_start(struct ieee80211_hw *hw, u8 *da, u16 tid,
  3793. u16 *start_seq_num)
  3794. {
  3795. struct iwl_priv *priv = hw->priv;
  3796. int sta_id;
  3797. int tx_fifo;
  3798. int txq_id;
  3799. int ssn = -1;
  3800. unsigned long flags;
  3801. struct iwl_tid_data *tid_data;
  3802. DECLARE_MAC_BUF(mac);
  3803. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  3804. tx_fifo = default_tid_to_tx_fifo[tid];
  3805. else
  3806. return -EINVAL;
  3807. IWL_WARNING("iwl-AGG iwl_mac_ht_tx_agg_start on da=%s"
  3808. " tid=%d\n", print_mac(mac, da), tid);
  3809. sta_id = iwl_hw_find_station(priv, da);
  3810. if (sta_id == IWL_INVALID_STATION)
  3811. return -ENXIO;
  3812. txq_id = iwl_txq_ctx_activate_free(priv);
  3813. if (txq_id == -1)
  3814. return -ENXIO;
  3815. spin_lock_irqsave(&priv->sta_lock, flags);
  3816. tid_data = &priv->stations[sta_id].tid[tid];
  3817. ssn = SEQ_TO_SN(tid_data->seq_number);
  3818. tid_data->agg.txq_id = txq_id;
  3819. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3820. *start_seq_num = ssn;
  3821. iwl4965_ba_status(priv, tid, BA_STATUS_ACTIVE);
  3822. return iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
  3823. sta_id, tid, ssn);
  3824. }
  3825. int iwl_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, u8 *da, u16 tid,
  3826. int generator)
  3827. {
  3828. struct iwl_priv *priv = hw->priv;
  3829. int tx_fifo_id, txq_id, sta_id, ssn = -1;
  3830. struct iwl_tid_data *tid_data;
  3831. int rc;
  3832. DECLARE_MAC_BUF(mac);
  3833. if (!da) {
  3834. IWL_ERROR("%s: da = NULL\n", __func__);
  3835. return -EINVAL;
  3836. }
  3837. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  3838. tx_fifo_id = default_tid_to_tx_fifo[tid];
  3839. else
  3840. return -EINVAL;
  3841. sta_id = iwl_hw_find_station(priv, da);
  3842. if (sta_id == IWL_INVALID_STATION)
  3843. return -ENXIO;
  3844. tid_data = &priv->stations[sta_id].tid[tid];
  3845. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  3846. txq_id = tid_data->agg.txq_id;
  3847. rc = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
  3848. /* FIXME: need more safe way to handle error condition */
  3849. if (rc)
  3850. return rc;
  3851. iwl4965_ba_status(priv, tid, BA_STATUS_INITIATOR_DELBA);
  3852. IWL_DEBUG_INFO("iwl_mac_ht_tx_agg_stop on da=%s tid=%d\n",
  3853. print_mac(mac, da), tid);
  3854. return 0;
  3855. }
  3856. int iwl_mac_ht_rx_agg_start(struct ieee80211_hw *hw, u8 *da,
  3857. u16 tid, u16 start_seq_num)
  3858. {
  3859. struct iwl_priv *priv = hw->priv;
  3860. int sta_id;
  3861. DECLARE_MAC_BUF(mac);
  3862. IWL_WARNING("iwl-AGG iwl_mac_ht_rx_agg_start on da=%s"
  3863. " tid=%d\n", print_mac(mac, da), tid);
  3864. sta_id = iwl_hw_find_station(priv, da);
  3865. iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, start_seq_num);
  3866. return 0;
  3867. }
  3868. int iwl_mac_ht_rx_agg_stop(struct ieee80211_hw *hw, u8 *da,
  3869. u16 tid, int generator)
  3870. {
  3871. struct iwl_priv *priv = hw->priv;
  3872. int sta_id;
  3873. DECLARE_MAC_BUF(mac);
  3874. IWL_WARNING("iwl-AGG iwl_mac_ht_rx_agg_stop on da=%s tid=%d\n",
  3875. print_mac(mac, da), tid);
  3876. sta_id = iwl_hw_find_station(priv, da);
  3877. iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid);
  3878. return 0;
  3879. }
  3880. #endif /* CONFIG_IWL4965_HT_AGG */
  3881. #endif /* CONFIG_IWL4965_HT */
  3882. /* Set up 4965-specific Rx frame reply handlers */
  3883. void iwl_hw_rx_handler_setup(struct iwl_priv *priv)
  3884. {
  3885. /* Legacy Rx frames */
  3886. priv->rx_handlers[REPLY_4965_RX] = iwl4965_rx_reply_rx;
  3887. /* High-throughput (HT) Rx frames */
  3888. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  3889. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  3890. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  3891. iwl4965_rx_missed_beacon_notif;
  3892. #ifdef CONFIG_IWL4965_HT
  3893. #ifdef CONFIG_IWL4965_HT_AGG
  3894. priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
  3895. #endif /* CONFIG_IWL4965_HT_AGG */
  3896. #endif /* CONFIG_IWL4965_HT */
  3897. }
  3898. void iwl_hw_setup_deferred_work(struct iwl_priv *priv)
  3899. {
  3900. INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
  3901. INIT_WORK(&priv->statistics_work, iwl4965_bg_statistics_work);
  3902. #ifdef CONFIG_IWL4965_SENSITIVITY
  3903. INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
  3904. #endif
  3905. #ifdef CONFIG_IWL4965_HT
  3906. #ifdef CONFIG_IWL4965_HT_AGG
  3907. INIT_WORK(&priv->agg_work, iwl4965_bg_agg_work);
  3908. #endif /* CONFIG_IWL4965_AGG */
  3909. #endif /* CONFIG_IWL4965_HT */
  3910. init_timer(&priv->statistics_periodic);
  3911. priv->statistics_periodic.data = (unsigned long)priv;
  3912. priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
  3913. }
  3914. void iwl_hw_cancel_deferred_work(struct iwl_priv *priv)
  3915. {
  3916. del_timer_sync(&priv->statistics_periodic);
  3917. cancel_delayed_work(&priv->init_alive_start);
  3918. }
  3919. struct pci_device_id iwl_hw_card_ids[] = {
  3920. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4229)},
  3921. {PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x4230)},
  3922. {0}
  3923. };
  3924. int iwl_eeprom_acquire_semaphore(struct iwl_priv *priv)
  3925. {
  3926. u16 count;
  3927. int rc;
  3928. for (count = 0; count < EEPROM_SEM_RETRY_LIMIT; count++) {
  3929. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  3930. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  3931. rc = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  3932. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  3933. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM,
  3934. EEPROM_SEM_TIMEOUT);
  3935. if (rc >= 0) {
  3936. IWL_DEBUG_IO("Acquired semaphore after %d tries.\n",
  3937. count+1);
  3938. return rc;
  3939. }
  3940. }
  3941. return rc;
  3942. }
  3943. inline void iwl_eeprom_release_semaphore(struct iwl_priv *priv)
  3944. {
  3945. iwl_clear_bit(priv, CSR_HW_IF_CONFIG_REG,
  3946. CSR_HW_IF_CONFIG_REG_BIT_EEPROM_OWN_SEM);
  3947. }
  3948. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);