iwl-4965.c 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2008 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 <asm/unaligned.h>
  39. #include "iwl-eeprom.h"
  40. #include "iwl-4965.h"
  41. #include "iwl-core.h"
  42. #include "iwl-io.h"
  43. #include "iwl-helpers.h"
  44. #include "iwl-calib.h"
  45. /* module parameters */
  46. static struct iwl_mod_params iwl4965_mod_params = {
  47. .num_of_queues = IWL4965_MAX_NUM_QUEUES,
  48. .enable_qos = 1,
  49. .amsdu_size_8K = 1,
  50. /* the rest are 0 by default */
  51. };
  52. static void iwl4965_hw_card_show_info(struct iwl_priv *priv);
  53. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  54. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  55. IWL_RATE_SISO_##s##M_PLCP, \
  56. IWL_RATE_MIMO_##s##M_PLCP, \
  57. IWL_RATE_##r##M_IEEE, \
  58. IWL_RATE_##ip##M_INDEX, \
  59. IWL_RATE_##in##M_INDEX, \
  60. IWL_RATE_##rp##M_INDEX, \
  61. IWL_RATE_##rn##M_INDEX, \
  62. IWL_RATE_##pp##M_INDEX, \
  63. IWL_RATE_##np##M_INDEX }
  64. /*
  65. * Parameter order:
  66. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  67. *
  68. * If there isn't a valid next or previous rate then INV is used which
  69. * maps to IWL_RATE_INVALID
  70. *
  71. */
  72. const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
  73. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  74. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  75. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  76. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  77. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  78. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  79. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  80. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  81. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  82. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  83. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  84. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  85. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  86. };
  87. #ifdef CONFIG_IWL4965_HT
  88. static const u16 default_tid_to_tx_fifo[] = {
  89. IWL_TX_FIFO_AC1,
  90. IWL_TX_FIFO_AC0,
  91. IWL_TX_FIFO_AC0,
  92. IWL_TX_FIFO_AC1,
  93. IWL_TX_FIFO_AC2,
  94. IWL_TX_FIFO_AC2,
  95. IWL_TX_FIFO_AC3,
  96. IWL_TX_FIFO_AC3,
  97. IWL_TX_FIFO_NONE,
  98. IWL_TX_FIFO_NONE,
  99. IWL_TX_FIFO_NONE,
  100. IWL_TX_FIFO_NONE,
  101. IWL_TX_FIFO_NONE,
  102. IWL_TX_FIFO_NONE,
  103. IWL_TX_FIFO_NONE,
  104. IWL_TX_FIFO_NONE,
  105. IWL_TX_FIFO_AC3
  106. };
  107. #endif /*CONFIG_IWL4965_HT */
  108. /* check contents of special bootstrap uCode SRAM */
  109. static int iwl4965_verify_bsm(struct iwl_priv *priv)
  110. {
  111. __le32 *image = priv->ucode_boot.v_addr;
  112. u32 len = priv->ucode_boot.len;
  113. u32 reg;
  114. u32 val;
  115. IWL_DEBUG_INFO("Begin verify bsm\n");
  116. /* verify BSM SRAM contents */
  117. val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
  118. for (reg = BSM_SRAM_LOWER_BOUND;
  119. reg < BSM_SRAM_LOWER_BOUND + len;
  120. reg += sizeof(u32), image++) {
  121. val = iwl_read_prph(priv, reg);
  122. if (val != le32_to_cpu(*image)) {
  123. IWL_ERROR("BSM uCode verification failed at "
  124. "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
  125. BSM_SRAM_LOWER_BOUND,
  126. reg - BSM_SRAM_LOWER_BOUND, len,
  127. val, le32_to_cpu(*image));
  128. return -EIO;
  129. }
  130. }
  131. IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
  132. return 0;
  133. }
  134. /**
  135. * iwl4965_load_bsm - Load bootstrap instructions
  136. *
  137. * BSM operation:
  138. *
  139. * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
  140. * in special SRAM that does not power down during RFKILL. When powering back
  141. * up after power-saving sleeps (or during initial uCode load), the BSM loads
  142. * the bootstrap program into the on-board processor, and starts it.
  143. *
  144. * The bootstrap program loads (via DMA) instructions and data for a new
  145. * program from host DRAM locations indicated by the host driver in the
  146. * BSM_DRAM_* registers. Once the new program is loaded, it starts
  147. * automatically.
  148. *
  149. * When initializing the NIC, the host driver points the BSM to the
  150. * "initialize" uCode image. This uCode sets up some internal data, then
  151. * notifies host via "initialize alive" that it is complete.
  152. *
  153. * The host then replaces the BSM_DRAM_* pointer values to point to the
  154. * normal runtime uCode instructions and a backup uCode data cache buffer
  155. * (filled initially with starting data values for the on-board processor),
  156. * then triggers the "initialize" uCode to load and launch the runtime uCode,
  157. * which begins normal operation.
  158. *
  159. * When doing a power-save shutdown, runtime uCode saves data SRAM into
  160. * the backup data cache in DRAM before SRAM is powered down.
  161. *
  162. * When powering back up, the BSM loads the bootstrap program. This reloads
  163. * the runtime uCode instructions and the backup data cache into SRAM,
  164. * and re-launches the runtime uCode from where it left off.
  165. */
  166. static int iwl4965_load_bsm(struct iwl_priv *priv)
  167. {
  168. __le32 *image = priv->ucode_boot.v_addr;
  169. u32 len = priv->ucode_boot.len;
  170. dma_addr_t pinst;
  171. dma_addr_t pdata;
  172. u32 inst_len;
  173. u32 data_len;
  174. int i;
  175. u32 done;
  176. u32 reg_offset;
  177. int ret;
  178. IWL_DEBUG_INFO("Begin load bsm\n");
  179. /* make sure bootstrap program is no larger than BSM's SRAM size */
  180. if (len > IWL_MAX_BSM_SIZE)
  181. return -EINVAL;
  182. /* Tell bootstrap uCode where to find the "Initialize" uCode
  183. * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
  184. * NOTE: iwl4965_initialize_alive_start() will replace these values,
  185. * after the "initialize" uCode has run, to point to
  186. * runtime/protocol instructions and backup data cache. */
  187. pinst = priv->ucode_init.p_addr >> 4;
  188. pdata = priv->ucode_init_data.p_addr >> 4;
  189. inst_len = priv->ucode_init.len;
  190. data_len = priv->ucode_init_data.len;
  191. ret = iwl_grab_nic_access(priv);
  192. if (ret)
  193. return ret;
  194. iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
  195. iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
  196. iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
  197. iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
  198. /* Fill BSM memory with bootstrap instructions */
  199. for (reg_offset = BSM_SRAM_LOWER_BOUND;
  200. reg_offset < BSM_SRAM_LOWER_BOUND + len;
  201. reg_offset += sizeof(u32), image++)
  202. _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
  203. ret = iwl4965_verify_bsm(priv);
  204. if (ret) {
  205. iwl_release_nic_access(priv);
  206. return ret;
  207. }
  208. /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
  209. iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
  210. iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
  211. iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
  212. /* Load bootstrap code into instruction SRAM now,
  213. * to prepare to load "initialize" uCode */
  214. iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
  215. /* Wait for load of bootstrap uCode to finish */
  216. for (i = 0; i < 100; i++) {
  217. done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
  218. if (!(done & BSM_WR_CTRL_REG_BIT_START))
  219. break;
  220. udelay(10);
  221. }
  222. if (i < 100)
  223. IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
  224. else {
  225. IWL_ERROR("BSM write did not complete!\n");
  226. return -EIO;
  227. }
  228. /* Enable future boot loads whenever power management unit triggers it
  229. * (e.g. when powering back up after power-save shutdown) */
  230. iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
  231. iwl_release_nic_access(priv);
  232. return 0;
  233. }
  234. static int iwl4965_init_drv(struct iwl_priv *priv)
  235. {
  236. int ret;
  237. int i;
  238. priv->antenna = (enum iwl4965_antenna)priv->cfg->mod_params->antenna;
  239. priv->retry_rate = 1;
  240. priv->ibss_beacon = NULL;
  241. spin_lock_init(&priv->lock);
  242. spin_lock_init(&priv->power_data.lock);
  243. spin_lock_init(&priv->sta_lock);
  244. spin_lock_init(&priv->hcmd_lock);
  245. spin_lock_init(&priv->lq_mngr.lock);
  246. priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
  247. sizeof(struct iwl4965_shared),
  248. &priv->shared_phys);
  249. if (!priv->shared_virt) {
  250. ret = -ENOMEM;
  251. goto err;
  252. }
  253. memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
  254. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  255. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  256. INIT_LIST_HEAD(&priv->free_frames);
  257. mutex_init(&priv->mutex);
  258. /* Clear the driver's (not device's) station table */
  259. iwlcore_clear_stations_table(priv);
  260. priv->data_retry_limit = -1;
  261. priv->ieee_channels = NULL;
  262. priv->ieee_rates = NULL;
  263. priv->band = IEEE80211_BAND_2GHZ;
  264. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  265. priv->use_ant_b_for_management_frame = 1; /* start with ant B */
  266. priv->valid_antenna = 0x7; /* assume all 3 connected */
  267. priv->ps_mode = IWL_MIMO_PS_NONE;
  268. /* Choose which receivers/antennas to use */
  269. iwl4965_set_rxon_chain(priv);
  270. iwlcore_reset_qos(priv);
  271. priv->qos_data.qos_active = 0;
  272. priv->qos_data.qos_cap.val = 0;
  273. iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  274. priv->rates_mask = IWL_RATES_MASK;
  275. /* If power management is turned on, default to AC mode */
  276. priv->power_mode = IWL_POWER_AC;
  277. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  278. ret = iwl_init_channel_map(priv);
  279. if (ret) {
  280. IWL_ERROR("initializing regulatory failed: %d\n", ret);
  281. goto err;
  282. }
  283. ret = iwl4965_init_geos(priv);
  284. if (ret) {
  285. IWL_ERROR("initializing geos failed: %d\n", ret);
  286. goto err_free_channel_map;
  287. }
  288. ret = ieee80211_register_hw(priv->hw);
  289. if (ret) {
  290. IWL_ERROR("Failed to register network device (error %d)\n",
  291. ret);
  292. goto err_free_geos;
  293. }
  294. priv->hw->conf.beacon_int = 100;
  295. priv->mac80211_registered = 1;
  296. return 0;
  297. err_free_geos:
  298. iwl4965_free_geos(priv);
  299. err_free_channel_map:
  300. iwl_free_channel_map(priv);
  301. err:
  302. return ret;
  303. }
  304. static int is_fat_channel(__le32 rxon_flags)
  305. {
  306. return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
  307. (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
  308. }
  309. static u8 is_single_stream(struct iwl_priv *priv)
  310. {
  311. #ifdef CONFIG_IWL4965_HT
  312. if (!priv->current_ht_config.is_ht ||
  313. (priv->current_ht_config.supp_mcs_set[1] == 0) ||
  314. (priv->ps_mode == IWL_MIMO_PS_STATIC))
  315. return 1;
  316. #else
  317. return 1;
  318. #endif /*CONFIG_IWL4965_HT */
  319. return 0;
  320. }
  321. int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
  322. {
  323. int idx = 0;
  324. /* 4965 HT rate format */
  325. if (rate_n_flags & RATE_MCS_HT_MSK) {
  326. idx = (rate_n_flags & 0xff);
  327. if (idx >= IWL_RATE_MIMO_6M_PLCP)
  328. idx = idx - IWL_RATE_MIMO_6M_PLCP;
  329. idx += IWL_FIRST_OFDM_RATE;
  330. /* skip 9M not supported in ht*/
  331. if (idx >= IWL_RATE_9M_INDEX)
  332. idx += 1;
  333. if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
  334. return idx;
  335. /* 4965 legacy rate format, search for match in table */
  336. } else {
  337. for (idx = 0; idx < ARRAY_SIZE(iwl4965_rates); idx++)
  338. if (iwl4965_rates[idx].plcp == (rate_n_flags & 0xFF))
  339. return idx;
  340. }
  341. return -1;
  342. }
  343. /**
  344. * translate ucode response to mac80211 tx status control values
  345. */
  346. void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
  347. struct ieee80211_tx_control *control)
  348. {
  349. int rate_index;
  350. control->antenna_sel_tx =
  351. ((rate_n_flags & RATE_MCS_ANT_AB_MSK) >> RATE_MCS_ANT_POS);
  352. if (rate_n_flags & RATE_MCS_HT_MSK)
  353. control->flags |= IEEE80211_TXCTL_OFDM_HT;
  354. if (rate_n_flags & RATE_MCS_GF_MSK)
  355. control->flags |= IEEE80211_TXCTL_GREEN_FIELD;
  356. if (rate_n_flags & RATE_MCS_FAT_MSK)
  357. control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH;
  358. if (rate_n_flags & RATE_MCS_DUP_MSK)
  359. control->flags |= IEEE80211_TXCTL_DUP_DATA;
  360. if (rate_n_flags & RATE_MCS_SGI_MSK)
  361. control->flags |= IEEE80211_TXCTL_SHORT_GI;
  362. /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use
  363. * IEEE80211_BAND_2GHZ band as it contains all the rates */
  364. rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
  365. if (rate_index == -1)
  366. control->tx_rate = NULL;
  367. else
  368. control->tx_rate =
  369. &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
  370. }
  371. /*
  372. * Determine how many receiver/antenna chains to use.
  373. * More provides better reception via diversity. Fewer saves power.
  374. * MIMO (dual stream) requires at least 2, but works better with 3.
  375. * This does not determine *which* chains to use, just how many.
  376. */
  377. static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv,
  378. u8 *idle_state, u8 *rx_state)
  379. {
  380. u8 is_single = is_single_stream(priv);
  381. u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
  382. /* # of Rx chains to use when expecting MIMO. */
  383. if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
  384. *rx_state = 2;
  385. else
  386. *rx_state = 3;
  387. /* # Rx chains when idling and maybe trying to save power */
  388. switch (priv->ps_mode) {
  389. case IWL_MIMO_PS_STATIC:
  390. case IWL_MIMO_PS_DYNAMIC:
  391. *idle_state = (is_cam) ? 2 : 1;
  392. break;
  393. case IWL_MIMO_PS_NONE:
  394. *idle_state = (is_cam) ? *rx_state : 1;
  395. break;
  396. default:
  397. *idle_state = 1;
  398. break;
  399. }
  400. return 0;
  401. }
  402. int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
  403. {
  404. int rc;
  405. unsigned long flags;
  406. spin_lock_irqsave(&priv->lock, flags);
  407. rc = iwl_grab_nic_access(priv);
  408. if (rc) {
  409. spin_unlock_irqrestore(&priv->lock, flags);
  410. return rc;
  411. }
  412. /* stop Rx DMA */
  413. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  414. rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
  415. (1 << 24), 1000);
  416. if (rc < 0)
  417. IWL_ERROR("Can't stop Rx DMA.\n");
  418. iwl_release_nic_access(priv);
  419. spin_unlock_irqrestore(&priv->lock, flags);
  420. return 0;
  421. }
  422. u8 iwl4965_hw_find_station(struct iwl_priv *priv, const u8 *addr)
  423. {
  424. int i;
  425. int start = 0;
  426. int ret = IWL_INVALID_STATION;
  427. unsigned long flags;
  428. DECLARE_MAC_BUF(mac);
  429. if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) ||
  430. (priv->iw_mode == IEEE80211_IF_TYPE_AP))
  431. start = IWL_STA_ID;
  432. if (is_broadcast_ether_addr(addr))
  433. return priv->hw_params.bcast_sta_id;
  434. spin_lock_irqsave(&priv->sta_lock, flags);
  435. for (i = start; i < priv->hw_params.max_stations; i++)
  436. if ((priv->stations[i].used) &&
  437. (!compare_ether_addr
  438. (priv->stations[i].sta.sta.addr, addr))) {
  439. ret = i;
  440. goto out;
  441. }
  442. IWL_DEBUG_ASSOC_LIMIT("can not find STA %s total %d\n",
  443. print_mac(mac, addr), priv->num_stations);
  444. out:
  445. spin_unlock_irqrestore(&priv->sta_lock, flags);
  446. return ret;
  447. }
  448. static int iwl4965_nic_set_pwr_src(struct iwl_priv *priv, int pwr_max)
  449. {
  450. int ret;
  451. unsigned long flags;
  452. spin_lock_irqsave(&priv->lock, flags);
  453. ret = iwl_grab_nic_access(priv);
  454. if (ret) {
  455. spin_unlock_irqrestore(&priv->lock, flags);
  456. return ret;
  457. }
  458. if (!pwr_max) {
  459. u32 val;
  460. ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
  461. &val);
  462. if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
  463. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  464. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  465. ~APMG_PS_CTRL_MSK_PWR_SRC);
  466. } else
  467. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  468. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  469. ~APMG_PS_CTRL_MSK_PWR_SRC);
  470. iwl_release_nic_access(priv);
  471. spin_unlock_irqrestore(&priv->lock, flags);
  472. return ret;
  473. }
  474. static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
  475. {
  476. int ret;
  477. unsigned long flags;
  478. unsigned int rb_size;
  479. spin_lock_irqsave(&priv->lock, flags);
  480. ret = iwl_grab_nic_access(priv);
  481. if (ret) {
  482. spin_unlock_irqrestore(&priv->lock, flags);
  483. return ret;
  484. }
  485. if (priv->cfg->mod_params->amsdu_size_8K)
  486. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
  487. else
  488. rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
  489. /* Stop Rx DMA */
  490. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
  491. /* Reset driver's Rx queue write index */
  492. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
  493. /* Tell device where to find RBD circular buffer in DRAM */
  494. iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
  495. rxq->dma_addr >> 8);
  496. /* Tell device where in DRAM to update its Rx status */
  497. iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
  498. (priv->shared_phys +
  499. offsetof(struct iwl4965_shared, rb_closed)) >> 4);
  500. /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */
  501. iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
  502. FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
  503. FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
  504. rb_size |
  505. /* 0x10 << 4 | */
  506. (RX_QUEUE_SIZE_LOG <<
  507. FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
  508. /*
  509. * iwl_write32(priv,CSR_INT_COAL_REG,0);
  510. */
  511. iwl_release_nic_access(priv);
  512. spin_unlock_irqrestore(&priv->lock, flags);
  513. return 0;
  514. }
  515. /* Tell 4965 where to find the "keep warm" buffer */
  516. static int iwl4965_kw_init(struct iwl_priv *priv)
  517. {
  518. unsigned long flags;
  519. int rc;
  520. spin_lock_irqsave(&priv->lock, flags);
  521. rc = iwl_grab_nic_access(priv);
  522. if (rc)
  523. goto out;
  524. iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
  525. priv->kw.dma_addr >> 4);
  526. iwl_release_nic_access(priv);
  527. out:
  528. spin_unlock_irqrestore(&priv->lock, flags);
  529. return rc;
  530. }
  531. static int iwl4965_kw_alloc(struct iwl_priv *priv)
  532. {
  533. struct pci_dev *dev = priv->pci_dev;
  534. struct iwl4965_kw *kw = &priv->kw;
  535. kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */
  536. kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
  537. if (!kw->v_addr)
  538. return -ENOMEM;
  539. return 0;
  540. }
  541. /**
  542. * iwl4965_kw_free - Free the "keep warm" buffer
  543. */
  544. static void iwl4965_kw_free(struct iwl_priv *priv)
  545. {
  546. struct pci_dev *dev = priv->pci_dev;
  547. struct iwl4965_kw *kw = &priv->kw;
  548. if (kw->v_addr) {
  549. pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
  550. memset(kw, 0, sizeof(*kw));
  551. }
  552. }
  553. /**
  554. * iwl4965_txq_ctx_reset - Reset TX queue context
  555. * Destroys all DMA structures and initialise them again
  556. *
  557. * @param priv
  558. * @return error code
  559. */
  560. static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
  561. {
  562. int rc = 0;
  563. int txq_id, slots_num;
  564. unsigned long flags;
  565. iwl4965_kw_free(priv);
  566. /* Free all tx/cmd queues and keep-warm buffer */
  567. iwl4965_hw_txq_ctx_free(priv);
  568. /* Alloc keep-warm buffer */
  569. rc = iwl4965_kw_alloc(priv);
  570. if (rc) {
  571. IWL_ERROR("Keep Warm allocation failed");
  572. goto error_kw;
  573. }
  574. spin_lock_irqsave(&priv->lock, flags);
  575. rc = iwl_grab_nic_access(priv);
  576. if (unlikely(rc)) {
  577. IWL_ERROR("TX reset failed");
  578. spin_unlock_irqrestore(&priv->lock, flags);
  579. goto error_reset;
  580. }
  581. /* Turn off all Tx DMA channels */
  582. iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
  583. iwl_release_nic_access(priv);
  584. spin_unlock_irqrestore(&priv->lock, flags);
  585. /* Tell 4965 where to find the keep-warm buffer */
  586. rc = iwl4965_kw_init(priv);
  587. if (rc) {
  588. IWL_ERROR("kw_init failed\n");
  589. goto error_reset;
  590. }
  591. /* Alloc and init all (default 16) Tx queues,
  592. * including the command queue (#4) */
  593. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
  594. slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
  595. TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
  596. rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
  597. txq_id);
  598. if (rc) {
  599. IWL_ERROR("Tx %d queue init failed\n", txq_id);
  600. goto error;
  601. }
  602. }
  603. return rc;
  604. error:
  605. iwl4965_hw_txq_ctx_free(priv);
  606. error_reset:
  607. iwl4965_kw_free(priv);
  608. error_kw:
  609. return rc;
  610. }
  611. int iwl4965_hw_nic_init(struct iwl_priv *priv)
  612. {
  613. int rc;
  614. unsigned long flags;
  615. struct iwl4965_rx_queue *rxq = &priv->rxq;
  616. u8 rev_id;
  617. u32 val;
  618. u8 val_link;
  619. iwl4965_power_init_handle(priv);
  620. /* nic_init */
  621. spin_lock_irqsave(&priv->lock, flags);
  622. iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
  623. CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
  624. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  625. rc = iwl_poll_bit(priv, CSR_GP_CNTRL,
  626. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  627. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
  628. if (rc < 0) {
  629. spin_unlock_irqrestore(&priv->lock, flags);
  630. IWL_DEBUG_INFO("Failed to init the card\n");
  631. return rc;
  632. }
  633. rc = iwl_grab_nic_access(priv);
  634. if (rc) {
  635. spin_unlock_irqrestore(&priv->lock, flags);
  636. return rc;
  637. }
  638. iwl_read_prph(priv, APMG_CLK_CTRL_REG);
  639. iwl_write_prph(priv, APMG_CLK_CTRL_REG,
  640. APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
  641. iwl_read_prph(priv, APMG_CLK_CTRL_REG);
  642. udelay(20);
  643. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  644. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  645. iwl_release_nic_access(priv);
  646. iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
  647. spin_unlock_irqrestore(&priv->lock, flags);
  648. /* Determine HW type */
  649. rc = pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &rev_id);
  650. if (rc)
  651. return rc;
  652. IWL_DEBUG_INFO("HW Revision ID = 0x%X\n", rev_id);
  653. iwl4965_nic_set_pwr_src(priv, 1);
  654. spin_lock_irqsave(&priv->lock, flags);
  655. if ((rev_id & 0x80) == 0x80 && (rev_id & 0x7f) < 8) {
  656. pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
  657. /* Enable No Snoop field */
  658. pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
  659. val & ~(1 << 11));
  660. }
  661. spin_unlock_irqrestore(&priv->lock, flags);
  662. if (priv->eeprom.calib_version < EEPROM_TX_POWER_VERSION_NEW) {
  663. IWL_ERROR("Older EEPROM detected! Aborting.\n");
  664. return -EINVAL;
  665. }
  666. pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
  667. /* disable L1 entry -- workaround for pre-B1 */
  668. pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
  669. spin_lock_irqsave(&priv->lock, flags);
  670. /* set CSR_HW_CONFIG_REG for uCode use */
  671. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  672. CSR49_HW_IF_CONFIG_REG_BIT_4965_R |
  673. CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  674. CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
  675. rc = iwl_grab_nic_access(priv);
  676. if (rc < 0) {
  677. spin_unlock_irqrestore(&priv->lock, flags);
  678. IWL_DEBUG_INFO("Failed to init the card\n");
  679. return rc;
  680. }
  681. iwl_read_prph(priv, APMG_PS_CTRL_REG);
  682. iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
  683. udelay(5);
  684. iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
  685. iwl_release_nic_access(priv);
  686. spin_unlock_irqrestore(&priv->lock, flags);
  687. iwl4965_hw_card_show_info(priv);
  688. /* end nic_init */
  689. /* Allocate the RX queue, or reset if it is already allocated */
  690. if (!rxq->bd) {
  691. rc = iwl4965_rx_queue_alloc(priv);
  692. if (rc) {
  693. IWL_ERROR("Unable to initialize Rx queue\n");
  694. return -ENOMEM;
  695. }
  696. } else
  697. iwl4965_rx_queue_reset(priv, rxq);
  698. iwl4965_rx_replenish(priv);
  699. iwl4965_rx_init(priv, rxq);
  700. spin_lock_irqsave(&priv->lock, flags);
  701. rxq->need_update = 1;
  702. iwl4965_rx_queue_update_write_ptr(priv, rxq);
  703. spin_unlock_irqrestore(&priv->lock, flags);
  704. /* Allocate and init all Tx and Command queues */
  705. rc = iwl4965_txq_ctx_reset(priv);
  706. if (rc)
  707. return rc;
  708. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_SW_RF_KILL_ENABLE)
  709. IWL_DEBUG_RF_KILL("SW RF KILL supported in EEPROM.\n");
  710. if (priv->eeprom.sku_cap & EEPROM_SKU_CAP_HW_RF_KILL_ENABLE)
  711. IWL_DEBUG_RF_KILL("HW RF KILL supported in EEPROM.\n");
  712. set_bit(STATUS_INIT, &priv->status);
  713. return 0;
  714. }
  715. int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
  716. {
  717. int rc = 0;
  718. u32 reg_val;
  719. unsigned long flags;
  720. spin_lock_irqsave(&priv->lock, flags);
  721. /* set stop master bit */
  722. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
  723. reg_val = iwl_read32(priv, CSR_GP_CNTRL);
  724. if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
  725. (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
  726. IWL_DEBUG_INFO("Card in power save, master is already "
  727. "stopped\n");
  728. else {
  729. rc = iwl_poll_bit(priv, CSR_RESET,
  730. CSR_RESET_REG_FLAG_MASTER_DISABLED,
  731. CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
  732. if (rc < 0) {
  733. spin_unlock_irqrestore(&priv->lock, flags);
  734. return rc;
  735. }
  736. }
  737. spin_unlock_irqrestore(&priv->lock, flags);
  738. IWL_DEBUG_INFO("stop master\n");
  739. return rc;
  740. }
  741. /**
  742. * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
  743. */
  744. void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
  745. {
  746. int txq_id;
  747. unsigned long flags;
  748. /* Stop each Tx DMA channel, and wait for it to be idle */
  749. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
  750. spin_lock_irqsave(&priv->lock, flags);
  751. if (iwl_grab_nic_access(priv)) {
  752. spin_unlock_irqrestore(&priv->lock, flags);
  753. continue;
  754. }
  755. iwl_write_direct32(priv,
  756. IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
  757. iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG,
  758. IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
  759. (txq_id), 200);
  760. iwl_release_nic_access(priv);
  761. spin_unlock_irqrestore(&priv->lock, flags);
  762. }
  763. /* Deallocate memory for all Tx queues */
  764. iwl4965_hw_txq_ctx_free(priv);
  765. }
  766. int iwl4965_hw_nic_reset(struct iwl_priv *priv)
  767. {
  768. int rc = 0;
  769. unsigned long flags;
  770. iwl4965_hw_nic_stop_master(priv);
  771. spin_lock_irqsave(&priv->lock, flags);
  772. iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
  773. udelay(10);
  774. iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
  775. rc = iwl_poll_bit(priv, CSR_RESET,
  776. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
  777. CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
  778. udelay(10);
  779. rc = iwl_grab_nic_access(priv);
  780. if (!rc) {
  781. iwl_write_prph(priv, APMG_CLK_EN_REG,
  782. APMG_CLK_VAL_DMA_CLK_RQT |
  783. APMG_CLK_VAL_BSM_CLK_RQT);
  784. udelay(10);
  785. iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
  786. APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
  787. iwl_release_nic_access(priv);
  788. }
  789. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  790. wake_up_interruptible(&priv->wait_command_queue);
  791. spin_unlock_irqrestore(&priv->lock, flags);
  792. return rc;
  793. }
  794. #define REG_RECALIB_PERIOD (60)
  795. /**
  796. * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  797. *
  798. * This callback is provided in order to send a statistics request.
  799. *
  800. * This timer function is continually reset to execute within
  801. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  802. * was received. We need to ensure we receive the statistics in order
  803. * to update the temperature used for calibrating the TXPOWER.
  804. */
  805. static void iwl4965_bg_statistics_periodic(unsigned long data)
  806. {
  807. struct iwl_priv *priv = (struct iwl_priv *)data;
  808. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  809. return;
  810. iwl_send_statistics_request(priv, CMD_ASYNC);
  811. }
  812. #define CT_LIMIT_CONST 259
  813. #define TM_CT_KILL_THRESHOLD 110
  814. void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
  815. {
  816. struct iwl4965_ct_kill_config cmd;
  817. u32 R1, R2, R3;
  818. u32 temp_th;
  819. u32 crit_temperature;
  820. unsigned long flags;
  821. int ret = 0;
  822. spin_lock_irqsave(&priv->lock, flags);
  823. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  824. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  825. spin_unlock_irqrestore(&priv->lock, flags);
  826. if (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK) {
  827. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  828. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  829. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  830. } else {
  831. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  832. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  833. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  834. }
  835. temp_th = CELSIUS_TO_KELVIN(TM_CT_KILL_THRESHOLD);
  836. crit_temperature = ((temp_th * (R3-R1))/CT_LIMIT_CONST) + R2;
  837. cmd.critical_temperature_R = cpu_to_le32(crit_temperature);
  838. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  839. sizeof(cmd), &cmd);
  840. if (ret)
  841. IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
  842. else
  843. IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded\n");
  844. }
  845. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  846. /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
  847. * Called after every association, but this runs only once!
  848. * ... once chain noise is calibrated the first time, it's good forever. */
  849. static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
  850. {
  851. struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
  852. if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
  853. struct iwl4965_calibration_cmd cmd;
  854. memset(&cmd, 0, sizeof(cmd));
  855. cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
  856. cmd.diff_gain_a = 0;
  857. cmd.diff_gain_b = 0;
  858. cmd.diff_gain_c = 0;
  859. if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  860. sizeof(cmd), &cmd))
  861. IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
  862. data->state = IWL_CHAIN_NOISE_ACCUMULATE;
  863. IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
  864. }
  865. }
  866. static void iwl4965_gain_computation(struct iwl_priv *priv,
  867. u32 *average_noise,
  868. u16 min_average_noise_antenna_i,
  869. u32 min_average_noise)
  870. {
  871. int i, ret;
  872. struct iwl_chain_noise_data *data = &priv->chain_noise_data;
  873. data->delta_gain_code[min_average_noise_antenna_i] = 0;
  874. for (i = 0; i < NUM_RX_CHAINS; i++) {
  875. s32 delta_g = 0;
  876. if (!(data->disconn_array[i]) &&
  877. (data->delta_gain_code[i] ==
  878. CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
  879. delta_g = average_noise[i] - min_average_noise;
  880. data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
  881. data->delta_gain_code[i] =
  882. min(data->delta_gain_code[i],
  883. (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
  884. data->delta_gain_code[i] =
  885. (data->delta_gain_code[i] | (1 << 2));
  886. } else {
  887. data->delta_gain_code[i] = 0;
  888. }
  889. }
  890. IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
  891. data->delta_gain_code[0],
  892. data->delta_gain_code[1],
  893. data->delta_gain_code[2]);
  894. /* Differential gain gets sent to uCode only once */
  895. if (!data->radio_write) {
  896. struct iwl4965_calibration_cmd cmd;
  897. data->radio_write = 1;
  898. memset(&cmd, 0, sizeof(cmd));
  899. cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
  900. cmd.diff_gain_a = data->delta_gain_code[0];
  901. cmd.diff_gain_b = data->delta_gain_code[1];
  902. cmd.diff_gain_c = data->delta_gain_code[2];
  903. ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
  904. sizeof(cmd), &cmd);
  905. if (ret)
  906. IWL_DEBUG_CALIB("fail sending cmd "
  907. "REPLY_PHY_CALIBRATION_CMD \n");
  908. /* TODO we might want recalculate
  909. * rx_chain in rxon cmd */
  910. /* Mark so we run this algo only once! */
  911. data->state = IWL_CHAIN_NOISE_CALIBRATED;
  912. }
  913. data->chain_noise_a = 0;
  914. data->chain_noise_b = 0;
  915. data->chain_noise_c = 0;
  916. data->chain_signal_a = 0;
  917. data->chain_signal_b = 0;
  918. data->chain_signal_c = 0;
  919. data->beacon_count = 0;
  920. }
  921. static void iwl4965_bg_sensitivity_work(struct work_struct *work)
  922. {
  923. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  924. sensitivity_work);
  925. mutex_lock(&priv->mutex);
  926. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  927. test_bit(STATUS_SCANNING, &priv->status)) {
  928. mutex_unlock(&priv->mutex);
  929. return;
  930. }
  931. if (priv->start_calib) {
  932. iwl_chain_noise_calibration(priv, &priv->statistics);
  933. iwl_sensitivity_calibration(priv, &priv->statistics);
  934. }
  935. mutex_unlock(&priv->mutex);
  936. return;
  937. }
  938. #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
  939. static void iwl4965_bg_txpower_work(struct work_struct *work)
  940. {
  941. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  942. txpower_work);
  943. /* If a scan happened to start before we got here
  944. * then just return; the statistics notification will
  945. * kick off another scheduled work to compensate for
  946. * any temperature delta we missed here. */
  947. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  948. test_bit(STATUS_SCANNING, &priv->status))
  949. return;
  950. mutex_lock(&priv->mutex);
  951. /* Regardless of if we are assocaited, we must reconfigure the
  952. * TX power since frames can be sent on non-radar channels while
  953. * not associated */
  954. iwl4965_hw_reg_send_txpower(priv);
  955. /* Update last_temperature to keep is_calib_needed from running
  956. * when it isn't needed... */
  957. priv->last_temperature = priv->temperature;
  958. mutex_unlock(&priv->mutex);
  959. }
  960. /*
  961. * Acquire priv->lock before calling this function !
  962. */
  963. static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
  964. {
  965. iwl_write_direct32(priv, HBUS_TARG_WRPTR,
  966. (index & 0xff) | (txq_id << 8));
  967. iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
  968. }
  969. /**
  970. * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
  971. * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
  972. * @scd_retry: (1) Indicates queue will be used in aggregation mode
  973. *
  974. * NOTE: Acquire priv->lock before calling this function !
  975. */
  976. static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
  977. struct iwl4965_tx_queue *txq,
  978. int tx_fifo_id, int scd_retry)
  979. {
  980. int txq_id = txq->q.id;
  981. /* Find out whether to activate Tx queue */
  982. int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
  983. /* Set up and activate */
  984. iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
  985. (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  986. (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
  987. (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) |
  988. (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  989. SCD_QUEUE_STTS_REG_MSK);
  990. txq->sched_retry = scd_retry;
  991. IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
  992. active ? "Activate" : "Deactivate",
  993. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  994. }
  995. static const u16 default_queue_to_tx_fifo[] = {
  996. IWL_TX_FIFO_AC3,
  997. IWL_TX_FIFO_AC2,
  998. IWL_TX_FIFO_AC1,
  999. IWL_TX_FIFO_AC0,
  1000. IWL_CMD_FIFO_NUM,
  1001. IWL_TX_FIFO_HCCA_1,
  1002. IWL_TX_FIFO_HCCA_2
  1003. };
  1004. static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
  1005. {
  1006. set_bit(txq_id, &priv->txq_ctx_active_msk);
  1007. }
  1008. static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
  1009. {
  1010. clear_bit(txq_id, &priv->txq_ctx_active_msk);
  1011. }
  1012. int iwl4965_alive_notify(struct iwl_priv *priv)
  1013. {
  1014. u32 a;
  1015. int i = 0;
  1016. unsigned long flags;
  1017. int ret;
  1018. spin_lock_irqsave(&priv->lock, flags);
  1019. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  1020. memset(&(priv->sensitivity_data), 0,
  1021. sizeof(struct iwl_sensitivity_data));
  1022. memset(&(priv->chain_noise_data), 0,
  1023. sizeof(struct iwl_chain_noise_data));
  1024. for (i = 0; i < NUM_RX_CHAINS; i++)
  1025. priv->chain_noise_data.delta_gain_code[i] =
  1026. CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
  1027. #endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/
  1028. ret = iwl_grab_nic_access(priv);
  1029. if (ret) {
  1030. spin_unlock_irqrestore(&priv->lock, flags);
  1031. return ret;
  1032. }
  1033. /* Clear 4965's internal Tx Scheduler data base */
  1034. priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
  1035. a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET;
  1036. for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  1037. iwl_write_targ_mem(priv, a, 0);
  1038. for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4)
  1039. iwl_write_targ_mem(priv, a, 0);
  1040. for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
  1041. iwl_write_targ_mem(priv, a, 0);
  1042. /* Tel 4965 where to find Tx byte count tables */
  1043. iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
  1044. (priv->shared_phys +
  1045. offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
  1046. /* Disable chain mode for all queues */
  1047. iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
  1048. /* Initialize each Tx queue (including the command queue) */
  1049. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  1050. /* TFD circular buffer read/write indexes */
  1051. iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
  1052. iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  1053. /* Max Tx Window size for Scheduler-ACK mode */
  1054. iwl_write_targ_mem(priv, priv->scd_base_addr +
  1055. SCD_CONTEXT_QUEUE_OFFSET(i),
  1056. (SCD_WIN_SIZE <<
  1057. SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1058. SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1059. /* Frame limit */
  1060. iwl_write_targ_mem(priv, priv->scd_base_addr +
  1061. SCD_CONTEXT_QUEUE_OFFSET(i) +
  1062. sizeof(u32),
  1063. (SCD_FRAME_LIMIT <<
  1064. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1065. SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1066. }
  1067. iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
  1068. (1 << priv->hw_params.max_txq_num) - 1);
  1069. /* Activate all Tx DMA/FIFO channels */
  1070. iwl_write_prph(priv, IWL49_SCD_TXFACT,
  1071. SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
  1072. iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
  1073. /* Map each Tx/cmd queue to its corresponding fifo */
  1074. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  1075. int ac = default_queue_to_tx_fifo[i];
  1076. iwl4965_txq_ctx_activate(priv, i);
  1077. iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  1078. }
  1079. iwl_release_nic_access(priv);
  1080. spin_unlock_irqrestore(&priv->lock, flags);
  1081. /* Ask for statistics now, the uCode will send statistics notification
  1082. * periodically after association */
  1083. iwl_send_statistics_request(priv, CMD_ASYNC);
  1084. return ret;
  1085. }
  1086. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  1087. static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
  1088. .min_nrg_cck = 97,
  1089. .max_nrg_cck = 0,
  1090. .auto_corr_min_ofdm = 85,
  1091. .auto_corr_min_ofdm_mrc = 170,
  1092. .auto_corr_min_ofdm_x1 = 105,
  1093. .auto_corr_min_ofdm_mrc_x1 = 220,
  1094. .auto_corr_max_ofdm = 120,
  1095. .auto_corr_max_ofdm_mrc = 210,
  1096. .auto_corr_max_ofdm_x1 = 140,
  1097. .auto_corr_max_ofdm_mrc_x1 = 270,
  1098. .auto_corr_min_cck = 125,
  1099. .auto_corr_max_cck = 200,
  1100. .auto_corr_min_cck_mrc = 200,
  1101. .auto_corr_max_cck_mrc = 400,
  1102. .nrg_th_cck = 100,
  1103. .nrg_th_ofdm = 100,
  1104. };
  1105. #endif
  1106. /**
  1107. * iwl4965_hw_set_hw_params
  1108. *
  1109. * Called when initializing driver
  1110. */
  1111. int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
  1112. {
  1113. if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) ||
  1114. (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
  1115. IWL_ERROR("invalid queues_num, should be between %d and %d\n",
  1116. IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES);
  1117. return -EINVAL;
  1118. }
  1119. priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
  1120. priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
  1121. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  1122. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  1123. if (priv->cfg->mod_params->amsdu_size_8K)
  1124. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  1125. else
  1126. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  1127. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  1128. priv->hw_params.max_stations = IWL4965_STATION_COUNT;
  1129. priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
  1130. priv->hw_params.tx_chains_num = 2;
  1131. priv->hw_params.rx_chains_num = 2;
  1132. priv->hw_params.valid_tx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX);
  1133. priv->hw_params.valid_rx_ant = (IWL_ANTENNA_MAIN | IWL_ANTENNA_AUX);
  1134. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  1135. priv->hw_params.sens = &iwl4965_sensitivity;
  1136. #endif
  1137. return 0;
  1138. }
  1139. /**
  1140. * iwl4965_hw_txq_ctx_free - Free TXQ Context
  1141. *
  1142. * Destroy all TX DMA queues and structures
  1143. */
  1144. void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv)
  1145. {
  1146. int txq_id;
  1147. /* Tx queues */
  1148. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
  1149. iwl4965_tx_queue_free(priv, &priv->txq[txq_id]);
  1150. /* Keep-warm buffer */
  1151. iwl4965_kw_free(priv);
  1152. }
  1153. /**
  1154. * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  1155. *
  1156. * Does NOT advance any TFD circular buffer read/write indexes
  1157. * Does NOT free the TFD itself (which is within circular buffer)
  1158. */
  1159. int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
  1160. {
  1161. struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0];
  1162. struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
  1163. struct pci_dev *dev = priv->pci_dev;
  1164. int i;
  1165. int counter = 0;
  1166. int index, is_odd;
  1167. /* Host command buffers stay mapped in memory, nothing to clean */
  1168. if (txq->q.id == IWL_CMD_QUEUE_NUM)
  1169. return 0;
  1170. /* Sanity check on number of chunks */
  1171. counter = IWL_GET_BITS(*bd, num_tbs);
  1172. if (counter > MAX_NUM_OF_TBS) {
  1173. IWL_ERROR("Too many chunks: %i\n", counter);
  1174. /* @todo issue fatal error, it is quite serious situation */
  1175. return 0;
  1176. }
  1177. /* Unmap chunks, if any.
  1178. * TFD info for odd chunks is different format than for even chunks. */
  1179. for (i = 0; i < counter; i++) {
  1180. index = i / 2;
  1181. is_odd = i & 0x1;
  1182. if (is_odd)
  1183. pci_unmap_single(
  1184. dev,
  1185. IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
  1186. (IWL_GET_BITS(bd->pa[index],
  1187. tb2_addr_hi20) << 16),
  1188. IWL_GET_BITS(bd->pa[index], tb2_len),
  1189. PCI_DMA_TODEVICE);
  1190. else if (i > 0)
  1191. pci_unmap_single(dev,
  1192. le32_to_cpu(bd->pa[index].tb1_addr),
  1193. IWL_GET_BITS(bd->pa[index], tb1_len),
  1194. PCI_DMA_TODEVICE);
  1195. /* Free SKB, if any, for this chunk */
  1196. if (txq->txb[txq->q.read_ptr].skb[i]) {
  1197. struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
  1198. dev_kfree_skb(skb);
  1199. txq->txb[txq->q.read_ptr].skb[i] = NULL;
  1200. }
  1201. }
  1202. return 0;
  1203. }
  1204. int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
  1205. {
  1206. IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
  1207. return -EINVAL;
  1208. }
  1209. static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
  1210. {
  1211. s32 sign = 1;
  1212. if (num < 0) {
  1213. sign = -sign;
  1214. num = -num;
  1215. }
  1216. if (denom < 0) {
  1217. sign = -sign;
  1218. denom = -denom;
  1219. }
  1220. *res = 1;
  1221. *res = ((num * 2 + denom) / (denom * 2)) * sign;
  1222. return 1;
  1223. }
  1224. /**
  1225. * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
  1226. *
  1227. * Determines power supply voltage compensation for txpower calculations.
  1228. * Returns number of 1/2-dB steps to subtract from gain table index,
  1229. * to compensate for difference between power supply voltage during
  1230. * factory measurements, vs. current power supply voltage.
  1231. *
  1232. * Voltage indication is higher for lower voltage.
  1233. * Lower voltage requires more gain (lower gain table index).
  1234. */
  1235. static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
  1236. s32 current_voltage)
  1237. {
  1238. s32 comp = 0;
  1239. if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
  1240. (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
  1241. return 0;
  1242. iwl4965_math_div_round(current_voltage - eeprom_voltage,
  1243. TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
  1244. if (current_voltage > eeprom_voltage)
  1245. comp *= 2;
  1246. if ((comp < -2) || (comp > 2))
  1247. comp = 0;
  1248. return comp;
  1249. }
  1250. static const struct iwl_channel_info *
  1251. iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
  1252. enum ieee80211_band band, u16 channel)
  1253. {
  1254. const struct iwl_channel_info *ch_info;
  1255. ch_info = iwl_get_channel_info(priv, band, channel);
  1256. if (!is_channel_valid(ch_info))
  1257. return NULL;
  1258. return ch_info;
  1259. }
  1260. static s32 iwl4965_get_tx_atten_grp(u16 channel)
  1261. {
  1262. if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
  1263. channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
  1264. return CALIB_CH_GROUP_5;
  1265. if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
  1266. channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
  1267. return CALIB_CH_GROUP_1;
  1268. if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
  1269. channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
  1270. return CALIB_CH_GROUP_2;
  1271. if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
  1272. channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
  1273. return CALIB_CH_GROUP_3;
  1274. if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
  1275. channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
  1276. return CALIB_CH_GROUP_4;
  1277. IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
  1278. return -1;
  1279. }
  1280. static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
  1281. {
  1282. s32 b = -1;
  1283. for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
  1284. if (priv->eeprom.calib_info.band_info[b].ch_from == 0)
  1285. continue;
  1286. if ((channel >= priv->eeprom.calib_info.band_info[b].ch_from)
  1287. && (channel <= priv->eeprom.calib_info.band_info[b].ch_to))
  1288. break;
  1289. }
  1290. return b;
  1291. }
  1292. static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
  1293. {
  1294. s32 val;
  1295. if (x2 == x1)
  1296. return y1;
  1297. else {
  1298. iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
  1299. return val + y2;
  1300. }
  1301. }
  1302. /**
  1303. * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
  1304. *
  1305. * Interpolates factory measurements from the two sample channels within a
  1306. * sub-band, to apply to channel of interest. Interpolation is proportional to
  1307. * differences in channel frequencies, which is proportional to differences
  1308. * in channel number.
  1309. */
  1310. static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
  1311. struct iwl4965_eeprom_calib_ch_info *chan_info)
  1312. {
  1313. s32 s = -1;
  1314. u32 c;
  1315. u32 m;
  1316. const struct iwl4965_eeprom_calib_measure *m1;
  1317. const struct iwl4965_eeprom_calib_measure *m2;
  1318. struct iwl4965_eeprom_calib_measure *omeas;
  1319. u32 ch_i1;
  1320. u32 ch_i2;
  1321. s = iwl4965_get_sub_band(priv, channel);
  1322. if (s >= EEPROM_TX_POWER_BANDS) {
  1323. IWL_ERROR("Tx Power can not find channel %d ", channel);
  1324. return -1;
  1325. }
  1326. ch_i1 = priv->eeprom.calib_info.band_info[s].ch1.ch_num;
  1327. ch_i2 = priv->eeprom.calib_info.band_info[s].ch2.ch_num;
  1328. chan_info->ch_num = (u8) channel;
  1329. IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
  1330. channel, s, ch_i1, ch_i2);
  1331. for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
  1332. for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
  1333. m1 = &(priv->eeprom.calib_info.band_info[s].ch1.
  1334. measurements[c][m]);
  1335. m2 = &(priv->eeprom.calib_info.band_info[s].ch2.
  1336. measurements[c][m]);
  1337. omeas = &(chan_info->measurements[c][m]);
  1338. omeas->actual_pow =
  1339. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1340. m1->actual_pow,
  1341. ch_i2,
  1342. m2->actual_pow);
  1343. omeas->gain_idx =
  1344. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1345. m1->gain_idx, ch_i2,
  1346. m2->gain_idx);
  1347. omeas->temperature =
  1348. (u8) iwl4965_interpolate_value(channel, ch_i1,
  1349. m1->temperature,
  1350. ch_i2,
  1351. m2->temperature);
  1352. omeas->pa_det =
  1353. (s8) iwl4965_interpolate_value(channel, ch_i1,
  1354. m1->pa_det, ch_i2,
  1355. m2->pa_det);
  1356. IWL_DEBUG_TXPOWER
  1357. ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
  1358. m1->actual_pow, m2->actual_pow, omeas->actual_pow);
  1359. IWL_DEBUG_TXPOWER
  1360. ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
  1361. m1->gain_idx, m2->gain_idx, omeas->gain_idx);
  1362. IWL_DEBUG_TXPOWER
  1363. ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
  1364. m1->pa_det, m2->pa_det, omeas->pa_det);
  1365. IWL_DEBUG_TXPOWER
  1366. ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
  1367. m1->temperature, m2->temperature,
  1368. omeas->temperature);
  1369. }
  1370. }
  1371. return 0;
  1372. }
  1373. /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
  1374. * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
  1375. static s32 back_off_table[] = {
  1376. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
  1377. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
  1378. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
  1379. 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
  1380. 10 /* CCK */
  1381. };
  1382. /* Thermal compensation values for txpower for various frequency ranges ...
  1383. * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
  1384. static struct iwl4965_txpower_comp_entry {
  1385. s32 degrees_per_05db_a;
  1386. s32 degrees_per_05db_a_denom;
  1387. } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
  1388. {9, 2}, /* group 0 5.2, ch 34-43 */
  1389. {4, 1}, /* group 1 5.2, ch 44-70 */
  1390. {4, 1}, /* group 2 5.2, ch 71-124 */
  1391. {4, 1}, /* group 3 5.2, ch 125-200 */
  1392. {3, 1} /* group 4 2.4, ch all */
  1393. };
  1394. static s32 get_min_power_index(s32 rate_power_index, u32 band)
  1395. {
  1396. if (!band) {
  1397. if ((rate_power_index & 7) <= 4)
  1398. return MIN_TX_GAIN_INDEX_52GHZ_EXT;
  1399. }
  1400. return MIN_TX_GAIN_INDEX;
  1401. }
  1402. struct gain_entry {
  1403. u8 dsp;
  1404. u8 radio;
  1405. };
  1406. static const struct gain_entry gain_table[2][108] = {
  1407. /* 5.2GHz power gain index table */
  1408. {
  1409. {123, 0x3F}, /* highest txpower */
  1410. {117, 0x3F},
  1411. {110, 0x3F},
  1412. {104, 0x3F},
  1413. {98, 0x3F},
  1414. {110, 0x3E},
  1415. {104, 0x3E},
  1416. {98, 0x3E},
  1417. {110, 0x3D},
  1418. {104, 0x3D},
  1419. {98, 0x3D},
  1420. {110, 0x3C},
  1421. {104, 0x3C},
  1422. {98, 0x3C},
  1423. {110, 0x3B},
  1424. {104, 0x3B},
  1425. {98, 0x3B},
  1426. {110, 0x3A},
  1427. {104, 0x3A},
  1428. {98, 0x3A},
  1429. {110, 0x39},
  1430. {104, 0x39},
  1431. {98, 0x39},
  1432. {110, 0x38},
  1433. {104, 0x38},
  1434. {98, 0x38},
  1435. {110, 0x37},
  1436. {104, 0x37},
  1437. {98, 0x37},
  1438. {110, 0x36},
  1439. {104, 0x36},
  1440. {98, 0x36},
  1441. {110, 0x35},
  1442. {104, 0x35},
  1443. {98, 0x35},
  1444. {110, 0x34},
  1445. {104, 0x34},
  1446. {98, 0x34},
  1447. {110, 0x33},
  1448. {104, 0x33},
  1449. {98, 0x33},
  1450. {110, 0x32},
  1451. {104, 0x32},
  1452. {98, 0x32},
  1453. {110, 0x31},
  1454. {104, 0x31},
  1455. {98, 0x31},
  1456. {110, 0x30},
  1457. {104, 0x30},
  1458. {98, 0x30},
  1459. {110, 0x25},
  1460. {104, 0x25},
  1461. {98, 0x25},
  1462. {110, 0x24},
  1463. {104, 0x24},
  1464. {98, 0x24},
  1465. {110, 0x23},
  1466. {104, 0x23},
  1467. {98, 0x23},
  1468. {110, 0x22},
  1469. {104, 0x18},
  1470. {98, 0x18},
  1471. {110, 0x17},
  1472. {104, 0x17},
  1473. {98, 0x17},
  1474. {110, 0x16},
  1475. {104, 0x16},
  1476. {98, 0x16},
  1477. {110, 0x15},
  1478. {104, 0x15},
  1479. {98, 0x15},
  1480. {110, 0x14},
  1481. {104, 0x14},
  1482. {98, 0x14},
  1483. {110, 0x13},
  1484. {104, 0x13},
  1485. {98, 0x13},
  1486. {110, 0x12},
  1487. {104, 0x08},
  1488. {98, 0x08},
  1489. {110, 0x07},
  1490. {104, 0x07},
  1491. {98, 0x07},
  1492. {110, 0x06},
  1493. {104, 0x06},
  1494. {98, 0x06},
  1495. {110, 0x05},
  1496. {104, 0x05},
  1497. {98, 0x05},
  1498. {110, 0x04},
  1499. {104, 0x04},
  1500. {98, 0x04},
  1501. {110, 0x03},
  1502. {104, 0x03},
  1503. {98, 0x03},
  1504. {110, 0x02},
  1505. {104, 0x02},
  1506. {98, 0x02},
  1507. {110, 0x01},
  1508. {104, 0x01},
  1509. {98, 0x01},
  1510. {110, 0x00},
  1511. {104, 0x00},
  1512. {98, 0x00},
  1513. {93, 0x00},
  1514. {88, 0x00},
  1515. {83, 0x00},
  1516. {78, 0x00},
  1517. },
  1518. /* 2.4GHz power gain index table */
  1519. {
  1520. {110, 0x3f}, /* highest txpower */
  1521. {104, 0x3f},
  1522. {98, 0x3f},
  1523. {110, 0x3e},
  1524. {104, 0x3e},
  1525. {98, 0x3e},
  1526. {110, 0x3d},
  1527. {104, 0x3d},
  1528. {98, 0x3d},
  1529. {110, 0x3c},
  1530. {104, 0x3c},
  1531. {98, 0x3c},
  1532. {110, 0x3b},
  1533. {104, 0x3b},
  1534. {98, 0x3b},
  1535. {110, 0x3a},
  1536. {104, 0x3a},
  1537. {98, 0x3a},
  1538. {110, 0x39},
  1539. {104, 0x39},
  1540. {98, 0x39},
  1541. {110, 0x38},
  1542. {104, 0x38},
  1543. {98, 0x38},
  1544. {110, 0x37},
  1545. {104, 0x37},
  1546. {98, 0x37},
  1547. {110, 0x36},
  1548. {104, 0x36},
  1549. {98, 0x36},
  1550. {110, 0x35},
  1551. {104, 0x35},
  1552. {98, 0x35},
  1553. {110, 0x34},
  1554. {104, 0x34},
  1555. {98, 0x34},
  1556. {110, 0x33},
  1557. {104, 0x33},
  1558. {98, 0x33},
  1559. {110, 0x32},
  1560. {104, 0x32},
  1561. {98, 0x32},
  1562. {110, 0x31},
  1563. {104, 0x31},
  1564. {98, 0x31},
  1565. {110, 0x30},
  1566. {104, 0x30},
  1567. {98, 0x30},
  1568. {110, 0x6},
  1569. {104, 0x6},
  1570. {98, 0x6},
  1571. {110, 0x5},
  1572. {104, 0x5},
  1573. {98, 0x5},
  1574. {110, 0x4},
  1575. {104, 0x4},
  1576. {98, 0x4},
  1577. {110, 0x3},
  1578. {104, 0x3},
  1579. {98, 0x3},
  1580. {110, 0x2},
  1581. {104, 0x2},
  1582. {98, 0x2},
  1583. {110, 0x1},
  1584. {104, 0x1},
  1585. {98, 0x1},
  1586. {110, 0x0},
  1587. {104, 0x0},
  1588. {98, 0x0},
  1589. {97, 0},
  1590. {96, 0},
  1591. {95, 0},
  1592. {94, 0},
  1593. {93, 0},
  1594. {92, 0},
  1595. {91, 0},
  1596. {90, 0},
  1597. {89, 0},
  1598. {88, 0},
  1599. {87, 0},
  1600. {86, 0},
  1601. {85, 0},
  1602. {84, 0},
  1603. {83, 0},
  1604. {82, 0},
  1605. {81, 0},
  1606. {80, 0},
  1607. {79, 0},
  1608. {78, 0},
  1609. {77, 0},
  1610. {76, 0},
  1611. {75, 0},
  1612. {74, 0},
  1613. {73, 0},
  1614. {72, 0},
  1615. {71, 0},
  1616. {70, 0},
  1617. {69, 0},
  1618. {68, 0},
  1619. {67, 0},
  1620. {66, 0},
  1621. {65, 0},
  1622. {64, 0},
  1623. {63, 0},
  1624. {62, 0},
  1625. {61, 0},
  1626. {60, 0},
  1627. {59, 0},
  1628. }
  1629. };
  1630. static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
  1631. u8 is_fat, u8 ctrl_chan_high,
  1632. struct iwl4965_tx_power_db *tx_power_tbl)
  1633. {
  1634. u8 saturation_power;
  1635. s32 target_power;
  1636. s32 user_target_power;
  1637. s32 power_limit;
  1638. s32 current_temp;
  1639. s32 reg_limit;
  1640. s32 current_regulatory;
  1641. s32 txatten_grp = CALIB_CH_GROUP_MAX;
  1642. int i;
  1643. int c;
  1644. const struct iwl_channel_info *ch_info = NULL;
  1645. struct iwl4965_eeprom_calib_ch_info ch_eeprom_info;
  1646. const struct iwl4965_eeprom_calib_measure *measurement;
  1647. s16 voltage;
  1648. s32 init_voltage;
  1649. s32 voltage_compensation;
  1650. s32 degrees_per_05db_num;
  1651. s32 degrees_per_05db_denom;
  1652. s32 factory_temp;
  1653. s32 temperature_comp[2];
  1654. s32 factory_gain_index[2];
  1655. s32 factory_actual_pwr[2];
  1656. s32 power_index;
  1657. /* Sanity check requested level (dBm) */
  1658. if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
  1659. IWL_WARNING("Requested user TXPOWER %d below limit.\n",
  1660. priv->user_txpower_limit);
  1661. return -EINVAL;
  1662. }
  1663. if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
  1664. IWL_WARNING("Requested user TXPOWER %d above limit.\n",
  1665. priv->user_txpower_limit);
  1666. return -EINVAL;
  1667. }
  1668. /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
  1669. * are used for indexing into txpower table) */
  1670. user_target_power = 2 * priv->user_txpower_limit;
  1671. /* Get current (RXON) channel, band, width */
  1672. ch_info =
  1673. iwl4965_get_channel_txpower_info(priv, priv->band, channel);
  1674. IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
  1675. is_fat);
  1676. if (!ch_info)
  1677. return -EINVAL;
  1678. /* get txatten group, used to select 1) thermal txpower adjustment
  1679. * and 2) mimo txpower balance between Tx chains. */
  1680. txatten_grp = iwl4965_get_tx_atten_grp(channel);
  1681. if (txatten_grp < 0)
  1682. return -EINVAL;
  1683. IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
  1684. channel, txatten_grp);
  1685. if (is_fat) {
  1686. if (ctrl_chan_high)
  1687. channel -= 2;
  1688. else
  1689. channel += 2;
  1690. }
  1691. /* hardware txpower limits ...
  1692. * saturation (clipping distortion) txpowers are in half-dBm */
  1693. if (band)
  1694. saturation_power = priv->eeprom.calib_info.saturation_power24;
  1695. else
  1696. saturation_power = priv->eeprom.calib_info.saturation_power52;
  1697. if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
  1698. saturation_power > IWL_TX_POWER_SATURATION_MAX) {
  1699. if (band)
  1700. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
  1701. else
  1702. saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
  1703. }
  1704. /* regulatory txpower limits ... reg_limit values are in half-dBm,
  1705. * max_power_avg values are in dBm, convert * 2 */
  1706. if (is_fat)
  1707. reg_limit = ch_info->fat_max_power_avg * 2;
  1708. else
  1709. reg_limit = ch_info->max_power_avg * 2;
  1710. if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
  1711. (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
  1712. if (band)
  1713. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
  1714. else
  1715. reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
  1716. }
  1717. /* Interpolate txpower calibration values for this channel,
  1718. * based on factory calibration tests on spaced channels. */
  1719. iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
  1720. /* calculate tx gain adjustment based on power supply voltage */
  1721. voltage = priv->eeprom.calib_info.voltage;
  1722. init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
  1723. voltage_compensation =
  1724. iwl4965_get_voltage_compensation(voltage, init_voltage);
  1725. IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
  1726. init_voltage,
  1727. voltage, voltage_compensation);
  1728. /* get current temperature (Celsius) */
  1729. current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
  1730. current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
  1731. current_temp = KELVIN_TO_CELSIUS(current_temp);
  1732. /* select thermal txpower adjustment params, based on channel group
  1733. * (same frequency group used for mimo txatten adjustment) */
  1734. degrees_per_05db_num =
  1735. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
  1736. degrees_per_05db_denom =
  1737. tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
  1738. /* get per-chain txpower values from factory measurements */
  1739. for (c = 0; c < 2; c++) {
  1740. measurement = &ch_eeprom_info.measurements[c][1];
  1741. /* txgain adjustment (in half-dB steps) based on difference
  1742. * between factory and current temperature */
  1743. factory_temp = measurement->temperature;
  1744. iwl4965_math_div_round((current_temp - factory_temp) *
  1745. degrees_per_05db_denom,
  1746. degrees_per_05db_num,
  1747. &temperature_comp[c]);
  1748. factory_gain_index[c] = measurement->gain_idx;
  1749. factory_actual_pwr[c] = measurement->actual_pow;
  1750. IWL_DEBUG_TXPOWER("chain = %d\n", c);
  1751. IWL_DEBUG_TXPOWER("fctry tmp %d, "
  1752. "curr tmp %d, comp %d steps\n",
  1753. factory_temp, current_temp,
  1754. temperature_comp[c]);
  1755. IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
  1756. factory_gain_index[c],
  1757. factory_actual_pwr[c]);
  1758. }
  1759. /* for each of 33 bit-rates (including 1 for CCK) */
  1760. for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
  1761. u8 is_mimo_rate;
  1762. union iwl4965_tx_power_dual_stream tx_power;
  1763. /* for mimo, reduce each chain's txpower by half
  1764. * (3dB, 6 steps), so total output power is regulatory
  1765. * compliant. */
  1766. if (i & 0x8) {
  1767. current_regulatory = reg_limit -
  1768. IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
  1769. is_mimo_rate = 1;
  1770. } else {
  1771. current_regulatory = reg_limit;
  1772. is_mimo_rate = 0;
  1773. }
  1774. /* find txpower limit, either hardware or regulatory */
  1775. power_limit = saturation_power - back_off_table[i];
  1776. if (power_limit > current_regulatory)
  1777. power_limit = current_regulatory;
  1778. /* reduce user's txpower request if necessary
  1779. * for this rate on this channel */
  1780. target_power = user_target_power;
  1781. if (target_power > power_limit)
  1782. target_power = power_limit;
  1783. IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
  1784. i, saturation_power - back_off_table[i],
  1785. current_regulatory, user_target_power,
  1786. target_power);
  1787. /* for each of 2 Tx chains (radio transmitters) */
  1788. for (c = 0; c < 2; c++) {
  1789. s32 atten_value;
  1790. if (is_mimo_rate)
  1791. atten_value =
  1792. (s32)le32_to_cpu(priv->card_alive_init.
  1793. tx_atten[txatten_grp][c]);
  1794. else
  1795. atten_value = 0;
  1796. /* calculate index; higher index means lower txpower */
  1797. power_index = (u8) (factory_gain_index[c] -
  1798. (target_power -
  1799. factory_actual_pwr[c]) -
  1800. temperature_comp[c] -
  1801. voltage_compensation +
  1802. atten_value);
  1803. /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
  1804. power_index); */
  1805. if (power_index < get_min_power_index(i, band))
  1806. power_index = get_min_power_index(i, band);
  1807. /* adjust 5 GHz index to support negative indexes */
  1808. if (!band)
  1809. power_index += 9;
  1810. /* CCK, rate 32, reduce txpower for CCK */
  1811. if (i == POWER_TABLE_CCK_ENTRY)
  1812. power_index +=
  1813. IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
  1814. /* stay within the table! */
  1815. if (power_index > 107) {
  1816. IWL_WARNING("txpower index %d > 107\n",
  1817. power_index);
  1818. power_index = 107;
  1819. }
  1820. if (power_index < 0) {
  1821. IWL_WARNING("txpower index %d < 0\n",
  1822. power_index);
  1823. power_index = 0;
  1824. }
  1825. /* fill txpower command for this rate/chain */
  1826. tx_power.s.radio_tx_gain[c] =
  1827. gain_table[band][power_index].radio;
  1828. tx_power.s.dsp_predis_atten[c] =
  1829. gain_table[band][power_index].dsp;
  1830. IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
  1831. "gain 0x%02x dsp %d\n",
  1832. c, atten_value, power_index,
  1833. tx_power.s.radio_tx_gain[c],
  1834. tx_power.s.dsp_predis_atten[c]);
  1835. }/* for each chain */
  1836. tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
  1837. }/* for each rate */
  1838. return 0;
  1839. }
  1840. /**
  1841. * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
  1842. *
  1843. * Uses the active RXON for channel, band, and characteristics (fat, high)
  1844. * The power limit is taken from priv->user_txpower_limit.
  1845. */
  1846. int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
  1847. {
  1848. struct iwl4965_txpowertable_cmd cmd = { 0 };
  1849. int ret;
  1850. u8 band = 0;
  1851. u8 is_fat = 0;
  1852. u8 ctrl_chan_high = 0;
  1853. if (test_bit(STATUS_SCANNING, &priv->status)) {
  1854. /* If this gets hit a lot, switch it to a BUG() and catch
  1855. * the stack trace to find out who is calling this during
  1856. * a scan. */
  1857. IWL_WARNING("TX Power requested while scanning!\n");
  1858. return -EAGAIN;
  1859. }
  1860. band = priv->band == IEEE80211_BAND_2GHZ;
  1861. is_fat = is_fat_channel(priv->active_rxon.flags);
  1862. if (is_fat &&
  1863. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1864. ctrl_chan_high = 1;
  1865. cmd.band = band;
  1866. cmd.channel = priv->active_rxon.channel;
  1867. ret = iwl4965_fill_txpower_tbl(priv, band,
  1868. le16_to_cpu(priv->active_rxon.channel),
  1869. is_fat, ctrl_chan_high, &cmd.tx_power);
  1870. if (ret)
  1871. goto out;
  1872. ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
  1873. out:
  1874. return ret;
  1875. }
  1876. static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
  1877. {
  1878. int ret = 0;
  1879. struct iwl4965_rxon_assoc_cmd rxon_assoc;
  1880. const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
  1881. const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
  1882. if ((rxon1->flags == rxon2->flags) &&
  1883. (rxon1->filter_flags == rxon2->filter_flags) &&
  1884. (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
  1885. (rxon1->ofdm_ht_single_stream_basic_rates ==
  1886. rxon2->ofdm_ht_single_stream_basic_rates) &&
  1887. (rxon1->ofdm_ht_dual_stream_basic_rates ==
  1888. rxon2->ofdm_ht_dual_stream_basic_rates) &&
  1889. (rxon1->rx_chain == rxon2->rx_chain) &&
  1890. (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
  1891. IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
  1892. return 0;
  1893. }
  1894. rxon_assoc.flags = priv->staging_rxon.flags;
  1895. rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
  1896. rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
  1897. rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
  1898. rxon_assoc.reserved = 0;
  1899. rxon_assoc.ofdm_ht_single_stream_basic_rates =
  1900. priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
  1901. rxon_assoc.ofdm_ht_dual_stream_basic_rates =
  1902. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
  1903. rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
  1904. ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
  1905. sizeof(rxon_assoc), &rxon_assoc, NULL);
  1906. if (ret)
  1907. return ret;
  1908. return ret;
  1909. }
  1910. int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
  1911. {
  1912. int rc;
  1913. u8 band = 0;
  1914. u8 is_fat = 0;
  1915. u8 ctrl_chan_high = 0;
  1916. struct iwl4965_channel_switch_cmd cmd = { 0 };
  1917. const struct iwl_channel_info *ch_info;
  1918. band = priv->band == IEEE80211_BAND_2GHZ;
  1919. ch_info = iwl_get_channel_info(priv, priv->band, channel);
  1920. is_fat = is_fat_channel(priv->staging_rxon.flags);
  1921. if (is_fat &&
  1922. (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
  1923. ctrl_chan_high = 1;
  1924. cmd.band = band;
  1925. cmd.expect_beacon = 0;
  1926. cmd.channel = cpu_to_le16(channel);
  1927. cmd.rxon_flags = priv->active_rxon.flags;
  1928. cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
  1929. cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
  1930. if (ch_info)
  1931. cmd.expect_beacon = is_channel_radar(ch_info);
  1932. else
  1933. cmd.expect_beacon = 1;
  1934. rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
  1935. ctrl_chan_high, &cmd.tx_power);
  1936. if (rc) {
  1937. IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
  1938. return rc;
  1939. }
  1940. rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
  1941. return rc;
  1942. }
  1943. #define RTS_HCCA_RETRY_LIMIT 3
  1944. #define RTS_DFAULT_RETRY_LIMIT 60
  1945. void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
  1946. struct iwl_cmd *cmd,
  1947. struct ieee80211_tx_control *ctrl,
  1948. struct ieee80211_hdr *hdr, int sta_id,
  1949. int is_hcca)
  1950. {
  1951. struct iwl4965_tx_cmd *tx = &cmd->cmd.tx;
  1952. u8 rts_retry_limit = 0;
  1953. u8 data_retry_limit = 0;
  1954. u16 fc = le16_to_cpu(hdr->frame_control);
  1955. u8 rate_plcp;
  1956. u16 rate_flags = 0;
  1957. int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
  1958. rate_plcp = iwl4965_rates[rate_idx].plcp;
  1959. rts_retry_limit = (is_hcca) ?
  1960. RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
  1961. if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
  1962. rate_flags |= RATE_MCS_CCK_MSK;
  1963. if (ieee80211_is_probe_response(fc)) {
  1964. data_retry_limit = 3;
  1965. if (data_retry_limit < rts_retry_limit)
  1966. rts_retry_limit = data_retry_limit;
  1967. } else
  1968. data_retry_limit = IWL_DEFAULT_TX_RETRY;
  1969. if (priv->data_retry_limit != -1)
  1970. data_retry_limit = priv->data_retry_limit;
  1971. if (ieee80211_is_data(fc)) {
  1972. tx->initial_rate_index = 0;
  1973. tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
  1974. } else {
  1975. switch (fc & IEEE80211_FCTL_STYPE) {
  1976. case IEEE80211_STYPE_AUTH:
  1977. case IEEE80211_STYPE_DEAUTH:
  1978. case IEEE80211_STYPE_ASSOC_REQ:
  1979. case IEEE80211_STYPE_REASSOC_REQ:
  1980. if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) {
  1981. tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
  1982. tx->tx_flags |= TX_CMD_FLG_CTS_MSK;
  1983. }
  1984. break;
  1985. default:
  1986. break;
  1987. }
  1988. /* Alternate between antenna A and B for successive frames */
  1989. if (priv->use_ant_b_for_management_frame) {
  1990. priv->use_ant_b_for_management_frame = 0;
  1991. rate_flags |= RATE_MCS_ANT_B_MSK;
  1992. } else {
  1993. priv->use_ant_b_for_management_frame = 1;
  1994. rate_flags |= RATE_MCS_ANT_A_MSK;
  1995. }
  1996. }
  1997. tx->rts_retry_limit = rts_retry_limit;
  1998. tx->data_retry_limit = data_retry_limit;
  1999. tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
  2000. }
  2001. int iwl4965_hw_get_rx_read(struct iwl_priv *priv)
  2002. {
  2003. struct iwl4965_shared *s = priv->shared_virt;
  2004. return le32_to_cpu(s->rb_closed) & 0xFFF;
  2005. }
  2006. int iwl4965_hw_get_temperature(struct iwl_priv *priv)
  2007. {
  2008. return priv->temperature;
  2009. }
  2010. unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
  2011. struct iwl4965_frame *frame, u8 rate)
  2012. {
  2013. struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
  2014. unsigned int frame_size;
  2015. tx_beacon_cmd = &frame->u.beacon;
  2016. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  2017. tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
  2018. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  2019. frame_size = iwl4965_fill_beacon_frame(priv,
  2020. tx_beacon_cmd->frame,
  2021. iwl4965_broadcast_addr,
  2022. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  2023. BUG_ON(frame_size > MAX_MPDU_SIZE);
  2024. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  2025. if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
  2026. tx_beacon_cmd->tx.rate_n_flags =
  2027. iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
  2028. else
  2029. tx_beacon_cmd->tx.rate_n_flags =
  2030. iwl4965_hw_set_rate_n_flags(rate, 0);
  2031. tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
  2032. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
  2033. return (sizeof(*tx_beacon_cmd) + frame_size);
  2034. }
  2035. /*
  2036. * Tell 4965 where to find circular buffer of Tx Frame Descriptors for
  2037. * given Tx queue, and enable the DMA channel used for that queue.
  2038. *
  2039. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  2040. * channels supported in hardware.
  2041. */
  2042. int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
  2043. {
  2044. int rc;
  2045. unsigned long flags;
  2046. int txq_id = txq->q.id;
  2047. spin_lock_irqsave(&priv->lock, flags);
  2048. rc = iwl_grab_nic_access(priv);
  2049. if (rc) {
  2050. spin_unlock_irqrestore(&priv->lock, flags);
  2051. return rc;
  2052. }
  2053. /* Circular buffer (TFD queue in DRAM) physical base address */
  2054. iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  2055. txq->q.dma_addr >> 8);
  2056. /* Enable DMA channel, using same id as for TFD queue */
  2057. iwl_write_direct32(
  2058. priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
  2059. IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  2060. IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
  2061. iwl_release_nic_access(priv);
  2062. spin_unlock_irqrestore(&priv->lock, flags);
  2063. return 0;
  2064. }
  2065. int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
  2066. dma_addr_t addr, u16 len)
  2067. {
  2068. int index, is_odd;
  2069. struct iwl4965_tfd_frame *tfd = ptr;
  2070. u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
  2071. /* Each TFD can point to a maximum 20 Tx buffers */
  2072. if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
  2073. IWL_ERROR("Error can not send more than %d chunks\n",
  2074. MAX_NUM_OF_TBS);
  2075. return -EINVAL;
  2076. }
  2077. index = num_tbs / 2;
  2078. is_odd = num_tbs & 0x1;
  2079. if (!is_odd) {
  2080. tfd->pa[index].tb1_addr = cpu_to_le32(addr);
  2081. IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
  2082. iwl_get_dma_hi_address(addr));
  2083. IWL_SET_BITS(tfd->pa[index], tb1_len, len);
  2084. } else {
  2085. IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
  2086. (u32) (addr & 0xffff));
  2087. IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
  2088. IWL_SET_BITS(tfd->pa[index], tb2_len, len);
  2089. }
  2090. IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
  2091. return 0;
  2092. }
  2093. static void iwl4965_hw_card_show_info(struct iwl_priv *priv)
  2094. {
  2095. u16 hw_version = priv->eeprom.board_revision_4965;
  2096. IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n",
  2097. ((hw_version >> 8) & 0x0F),
  2098. ((hw_version >> 8) >> 4), (hw_version & 0x00FF));
  2099. IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
  2100. priv->eeprom.board_pba_number_4965);
  2101. }
  2102. #define IWL_TX_CRC_SIZE 4
  2103. #define IWL_TX_DELIMITER_SIZE 4
  2104. /**
  2105. * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
  2106. */
  2107. static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
  2108. struct iwl4965_tx_queue *txq,
  2109. u16 byte_cnt)
  2110. {
  2111. int len;
  2112. int txq_id = txq->q.id;
  2113. struct iwl4965_shared *shared_data = priv->shared_virt;
  2114. len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
  2115. /* Set up byte count within first 256 entries */
  2116. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  2117. tfd_offset[txq->q.write_ptr], byte_cnt, len);
  2118. /* If within first 64 entries, duplicate at end */
  2119. if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE)
  2120. IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
  2121. tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr],
  2122. byte_cnt, len);
  2123. }
  2124. /**
  2125. * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  2126. *
  2127. * Selects how many and which Rx receivers/antennas/chains to use.
  2128. * This should not be used for scan command ... it puts data in wrong place.
  2129. */
  2130. void iwl4965_set_rxon_chain(struct iwl_priv *priv)
  2131. {
  2132. u8 is_single = is_single_stream(priv);
  2133. u8 idle_state, rx_state;
  2134. priv->staging_rxon.rx_chain = 0;
  2135. rx_state = idle_state = 3;
  2136. /* Tell uCode which antennas are actually connected.
  2137. * Before first association, we assume all antennas are connected.
  2138. * Just after first association, iwl_chain_noise_calibration()
  2139. * checks which antennas actually *are* connected. */
  2140. priv->staging_rxon.rx_chain |=
  2141. cpu_to_le16(priv->valid_antenna << RXON_RX_CHAIN_VALID_POS);
  2142. /* How many receivers should we use? */
  2143. iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
  2144. priv->staging_rxon.rx_chain |=
  2145. cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
  2146. priv->staging_rxon.rx_chain |=
  2147. cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
  2148. if (!is_single && (rx_state >= 2) &&
  2149. !test_bit(STATUS_POWER_PMI, &priv->status))
  2150. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  2151. else
  2152. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  2153. IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
  2154. }
  2155. /**
  2156. * sign_extend - Sign extend a value using specified bit as sign-bit
  2157. *
  2158. * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
  2159. * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
  2160. *
  2161. * @param oper value to sign extend
  2162. * @param index 0 based bit index (0<=index<32) to sign bit
  2163. */
  2164. static s32 sign_extend(u32 oper, int index)
  2165. {
  2166. u8 shift = 31 - index;
  2167. return (s32)(oper << shift) >> shift;
  2168. }
  2169. /**
  2170. * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
  2171. * @statistics: Provides the temperature reading from the uCode
  2172. *
  2173. * A return of <0 indicates bogus data in the statistics
  2174. */
  2175. int iwl4965_get_temperature(const struct iwl_priv *priv)
  2176. {
  2177. s32 temperature;
  2178. s32 vt;
  2179. s32 R1, R2, R3;
  2180. u32 R4;
  2181. if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
  2182. (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
  2183. IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
  2184. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
  2185. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
  2186. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
  2187. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
  2188. } else {
  2189. IWL_DEBUG_TEMP("Running temperature calibration\n");
  2190. R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
  2191. R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
  2192. R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
  2193. R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
  2194. }
  2195. /*
  2196. * Temperature is only 23 bits, so sign extend out to 32.
  2197. *
  2198. * NOTE If we haven't received a statistics notification yet
  2199. * with an updated temperature, use R4 provided to us in the
  2200. * "initialize" ALIVE response.
  2201. */
  2202. if (!test_bit(STATUS_TEMPERATURE, &priv->status))
  2203. vt = sign_extend(R4, 23);
  2204. else
  2205. vt = sign_extend(
  2206. le32_to_cpu(priv->statistics.general.temperature), 23);
  2207. IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
  2208. R1, R2, R3, vt);
  2209. if (R3 == R1) {
  2210. IWL_ERROR("Calibration conflict R1 == R3\n");
  2211. return -1;
  2212. }
  2213. /* Calculate temperature in degrees Kelvin, adjust by 97%.
  2214. * Add offset to center the adjustment around 0 degrees Centigrade. */
  2215. temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
  2216. temperature /= (R3 - R1);
  2217. temperature = (temperature * 97) / 100 +
  2218. TEMPERATURE_CALIB_KELVIN_OFFSET;
  2219. IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
  2220. KELVIN_TO_CELSIUS(temperature));
  2221. return temperature;
  2222. }
  2223. /* Adjust Txpower only if temperature variance is greater than threshold. */
  2224. #define IWL_TEMPERATURE_THRESHOLD 3
  2225. /**
  2226. * iwl4965_is_temp_calib_needed - determines if new calibration is needed
  2227. *
  2228. * If the temperature changed has changed sufficiently, then a recalibration
  2229. * is needed.
  2230. *
  2231. * Assumes caller will replace priv->last_temperature once calibration
  2232. * executed.
  2233. */
  2234. static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
  2235. {
  2236. int temp_diff;
  2237. if (!test_bit(STATUS_STATISTICS, &priv->status)) {
  2238. IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
  2239. return 0;
  2240. }
  2241. temp_diff = priv->temperature - priv->last_temperature;
  2242. /* get absolute value */
  2243. if (temp_diff < 0) {
  2244. IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
  2245. temp_diff = -temp_diff;
  2246. } else if (temp_diff == 0)
  2247. IWL_DEBUG_POWER("Same temp, \n");
  2248. else
  2249. IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
  2250. if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
  2251. IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
  2252. return 0;
  2253. }
  2254. IWL_DEBUG_POWER("Thermal txpower calib needed\n");
  2255. return 1;
  2256. }
  2257. /* Calculate noise level, based on measurements during network silence just
  2258. * before arriving beacon. This measurement can be done only if we know
  2259. * exactly when to expect beacons, therefore only when we're associated. */
  2260. static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
  2261. {
  2262. struct statistics_rx_non_phy *rx_info
  2263. = &(priv->statistics.rx.general);
  2264. int num_active_rx = 0;
  2265. int total_silence = 0;
  2266. int bcn_silence_a =
  2267. le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
  2268. int bcn_silence_b =
  2269. le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
  2270. int bcn_silence_c =
  2271. le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
  2272. if (bcn_silence_a) {
  2273. total_silence += bcn_silence_a;
  2274. num_active_rx++;
  2275. }
  2276. if (bcn_silence_b) {
  2277. total_silence += bcn_silence_b;
  2278. num_active_rx++;
  2279. }
  2280. if (bcn_silence_c) {
  2281. total_silence += bcn_silence_c;
  2282. num_active_rx++;
  2283. }
  2284. /* Average among active antennas */
  2285. if (num_active_rx)
  2286. priv->last_rx_noise = (total_silence / num_active_rx) - 107;
  2287. else
  2288. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  2289. IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
  2290. bcn_silence_a, bcn_silence_b, bcn_silence_c,
  2291. priv->last_rx_noise);
  2292. }
  2293. void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
  2294. {
  2295. struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
  2296. int change;
  2297. s32 temp;
  2298. IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
  2299. (int)sizeof(priv->statistics), pkt->len);
  2300. change = ((priv->statistics.general.temperature !=
  2301. pkt->u.stats.general.temperature) ||
  2302. ((priv->statistics.flag &
  2303. STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
  2304. (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
  2305. memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
  2306. set_bit(STATUS_STATISTICS, &priv->status);
  2307. /* Reschedule the statistics timer to occur in
  2308. * REG_RECALIB_PERIOD seconds to ensure we get a
  2309. * thermal update even if the uCode doesn't give
  2310. * us one */
  2311. mod_timer(&priv->statistics_periodic, jiffies +
  2312. msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
  2313. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  2314. (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
  2315. iwl4965_rx_calc_noise(priv);
  2316. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  2317. queue_work(priv->workqueue, &priv->sensitivity_work);
  2318. #endif
  2319. }
  2320. iwl_leds_background(priv);
  2321. /* If the hardware hasn't reported a change in
  2322. * temperature then don't bother computing a
  2323. * calibrated temperature value */
  2324. if (!change)
  2325. return;
  2326. temp = iwl4965_get_temperature(priv);
  2327. if (temp < 0)
  2328. return;
  2329. if (priv->temperature != temp) {
  2330. if (priv->temperature)
  2331. IWL_DEBUG_TEMP("Temperature changed "
  2332. "from %dC to %dC\n",
  2333. KELVIN_TO_CELSIUS(priv->temperature),
  2334. KELVIN_TO_CELSIUS(temp));
  2335. else
  2336. IWL_DEBUG_TEMP("Temperature "
  2337. "initialized to %dC\n",
  2338. KELVIN_TO_CELSIUS(temp));
  2339. }
  2340. priv->temperature = temp;
  2341. set_bit(STATUS_TEMPERATURE, &priv->status);
  2342. if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
  2343. iwl4965_is_temp_calib_needed(priv))
  2344. queue_work(priv->workqueue, &priv->txpower_work);
  2345. }
  2346. static void iwl4965_add_radiotap(struct iwl_priv *priv,
  2347. struct sk_buff *skb,
  2348. struct iwl4965_rx_phy_res *rx_start,
  2349. struct ieee80211_rx_status *stats,
  2350. u32 ampdu_status)
  2351. {
  2352. s8 signal = stats->ssi;
  2353. s8 noise = 0;
  2354. int rate = stats->rate_idx;
  2355. u64 tsf = stats->mactime;
  2356. __le16 antenna;
  2357. __le16 phy_flags_hw = rx_start->phy_flags;
  2358. struct iwl4965_rt_rx_hdr {
  2359. struct ieee80211_radiotap_header rt_hdr;
  2360. __le64 rt_tsf; /* TSF */
  2361. u8 rt_flags; /* radiotap packet flags */
  2362. u8 rt_rate; /* rate in 500kb/s */
  2363. __le16 rt_channelMHz; /* channel in MHz */
  2364. __le16 rt_chbitmask; /* channel bitfield */
  2365. s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
  2366. s8 rt_dbmnoise;
  2367. u8 rt_antenna; /* antenna number */
  2368. } __attribute__ ((packed)) *iwl4965_rt;
  2369. /* TODO: We won't have enough headroom for HT frames. Fix it later. */
  2370. if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
  2371. if (net_ratelimit())
  2372. printk(KERN_ERR "not enough headroom [%d] for "
  2373. "radiotap head [%zd]\n",
  2374. skb_headroom(skb), sizeof(*iwl4965_rt));
  2375. return;
  2376. }
  2377. /* put radiotap header in front of 802.11 header and data */
  2378. iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
  2379. /* initialise radiotap header */
  2380. iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
  2381. iwl4965_rt->rt_hdr.it_pad = 0;
  2382. /* total header + data */
  2383. put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
  2384. &iwl4965_rt->rt_hdr.it_len);
  2385. /* Indicate all the fields we add to the radiotap header */
  2386. put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
  2387. (1 << IEEE80211_RADIOTAP_FLAGS) |
  2388. (1 << IEEE80211_RADIOTAP_RATE) |
  2389. (1 << IEEE80211_RADIOTAP_CHANNEL) |
  2390. (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
  2391. (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
  2392. (1 << IEEE80211_RADIOTAP_ANTENNA)),
  2393. &iwl4965_rt->rt_hdr.it_present);
  2394. /* Zero the flags, we'll add to them as we go */
  2395. iwl4965_rt->rt_flags = 0;
  2396. put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
  2397. iwl4965_rt->rt_dbmsignal = signal;
  2398. iwl4965_rt->rt_dbmnoise = noise;
  2399. /* Convert the channel frequency and set the flags */
  2400. put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
  2401. if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
  2402. put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
  2403. IEEE80211_CHAN_5GHZ),
  2404. &iwl4965_rt->rt_chbitmask);
  2405. else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
  2406. put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
  2407. IEEE80211_CHAN_2GHZ),
  2408. &iwl4965_rt->rt_chbitmask);
  2409. else /* 802.11g */
  2410. put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
  2411. IEEE80211_CHAN_2GHZ),
  2412. &iwl4965_rt->rt_chbitmask);
  2413. if (rate == -1)
  2414. iwl4965_rt->rt_rate = 0;
  2415. else
  2416. iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
  2417. /*
  2418. * "antenna number"
  2419. *
  2420. * It seems that the antenna field in the phy flags value
  2421. * is actually a bitfield. This is undefined by radiotap,
  2422. * it wants an actual antenna number but I always get "7"
  2423. * for most legacy frames I receive indicating that the
  2424. * same frame was received on all three RX chains.
  2425. *
  2426. * I think this field should be removed in favour of a
  2427. * new 802.11n radiotap field "RX chains" that is defined
  2428. * as a bitmask.
  2429. */
  2430. antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
  2431. iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
  2432. /* set the preamble flag if appropriate */
  2433. if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
  2434. iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
  2435. stats->flag |= RX_FLAG_RADIOTAP;
  2436. }
  2437. static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
  2438. {
  2439. /* 0 - mgmt, 1 - cnt, 2 - data */
  2440. int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
  2441. priv->rx_stats[idx].cnt++;
  2442. priv->rx_stats[idx].bytes += len;
  2443. }
  2444. static u32 iwl4965_translate_rx_status(u32 decrypt_in)
  2445. {
  2446. u32 decrypt_out = 0;
  2447. if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
  2448. RX_RES_STATUS_STATION_FOUND)
  2449. decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
  2450. RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
  2451. decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
  2452. /* packet was not encrypted */
  2453. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  2454. RX_RES_STATUS_SEC_TYPE_NONE)
  2455. return decrypt_out;
  2456. /* packet was encrypted with unknown alg */
  2457. if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
  2458. RX_RES_STATUS_SEC_TYPE_ERR)
  2459. return decrypt_out;
  2460. /* decryption was not done in HW */
  2461. if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
  2462. RX_MPDU_RES_STATUS_DEC_DONE_MSK)
  2463. return decrypt_out;
  2464. switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
  2465. case RX_RES_STATUS_SEC_TYPE_CCMP:
  2466. /* alg is CCM: check MIC only */
  2467. if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
  2468. /* Bad MIC */
  2469. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  2470. else
  2471. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  2472. break;
  2473. case RX_RES_STATUS_SEC_TYPE_TKIP:
  2474. if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
  2475. /* Bad TTAK */
  2476. decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
  2477. break;
  2478. }
  2479. /* fall through if TTAK OK */
  2480. default:
  2481. if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
  2482. decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
  2483. else
  2484. decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
  2485. break;
  2486. };
  2487. IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
  2488. decrypt_in, decrypt_out);
  2489. return decrypt_out;
  2490. }
  2491. static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
  2492. int include_phy,
  2493. struct iwl4965_rx_mem_buffer *rxb,
  2494. struct ieee80211_rx_status *stats)
  2495. {
  2496. struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
  2497. struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
  2498. (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
  2499. struct ieee80211_hdr *hdr;
  2500. u16 len;
  2501. __le32 *rx_end;
  2502. unsigned int skblen;
  2503. u32 ampdu_status;
  2504. u32 ampdu_status_legacy;
  2505. if (!include_phy && priv->last_phy_res[0])
  2506. rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
  2507. if (!rx_start) {
  2508. IWL_ERROR("MPDU frame without a PHY data\n");
  2509. return;
  2510. }
  2511. if (include_phy) {
  2512. hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
  2513. rx_start->cfg_phy_cnt);
  2514. len = le16_to_cpu(rx_start->byte_count);
  2515. rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
  2516. sizeof(struct iwl4965_rx_phy_res) +
  2517. rx_start->cfg_phy_cnt + len);
  2518. } else {
  2519. struct iwl4965_rx_mpdu_res_start *amsdu =
  2520. (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  2521. hdr = (struct ieee80211_hdr *)(pkt->u.raw +
  2522. sizeof(struct iwl4965_rx_mpdu_res_start));
  2523. len = le16_to_cpu(amsdu->byte_count);
  2524. rx_start->byte_count = amsdu->byte_count;
  2525. rx_end = (__le32 *) (((u8 *) hdr) + len);
  2526. }
  2527. if (len > priv->hw_params.max_pkt_size || len < 16) {
  2528. IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
  2529. return;
  2530. }
  2531. ampdu_status = le32_to_cpu(*rx_end);
  2532. skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
  2533. if (!include_phy) {
  2534. /* New status scheme, need to translate */
  2535. ampdu_status_legacy = ampdu_status;
  2536. ampdu_status = iwl4965_translate_rx_status(ampdu_status);
  2537. }
  2538. /* start from MAC */
  2539. skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
  2540. skb_put(rxb->skb, len); /* end where data ends */
  2541. /* We only process data packets if the interface is open */
  2542. if (unlikely(!priv->is_open)) {
  2543. IWL_DEBUG_DROP_LIMIT
  2544. ("Dropping packet while interface is not open.\n");
  2545. return;
  2546. }
  2547. stats->flag = 0;
  2548. hdr = (struct ieee80211_hdr *)rxb->skb->data;
  2549. if (!priv->cfg->mod_params->sw_crypto)
  2550. iwl4965_set_decrypted_flag(priv, rxb->skb, ampdu_status, stats);
  2551. if (priv->add_radiotap)
  2552. iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
  2553. iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
  2554. ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
  2555. priv->alloc_rxb_skb--;
  2556. rxb->skb = NULL;
  2557. }
  2558. /* Calc max signal level (dBm) among 3 possible receivers */
  2559. static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
  2560. {
  2561. /* data from PHY/DSP regarding signal strength, etc.,
  2562. * contents are always there, not configurable by host. */
  2563. struct iwl4965_rx_non_cfg_phy *ncphy =
  2564. (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
  2565. u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
  2566. >> IWL_AGC_DB_POS;
  2567. u32 valid_antennae =
  2568. (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
  2569. >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
  2570. u8 max_rssi = 0;
  2571. u32 i;
  2572. /* Find max rssi among 3 possible receivers.
  2573. * These values are measured by the digital signal processor (DSP).
  2574. * They should stay fairly constant even as the signal strength varies,
  2575. * if the radio's automatic gain control (AGC) is working right.
  2576. * AGC value (see below) will provide the "interesting" info. */
  2577. for (i = 0; i < 3; i++)
  2578. if (valid_antennae & (1 << i))
  2579. max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
  2580. IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
  2581. ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
  2582. max_rssi, agc);
  2583. /* dBm = max_rssi dB - agc dB - constant.
  2584. * Higher AGC (higher radio gain) means lower signal. */
  2585. return (max_rssi - agc - IWL_RSSI_OFFSET);
  2586. }
  2587. #ifdef CONFIG_IWL4965_HT
  2588. void iwl4965_init_ht_hw_capab(struct iwl_priv *priv,
  2589. struct ieee80211_ht_info *ht_info,
  2590. enum ieee80211_band band)
  2591. {
  2592. ht_info->cap = 0;
  2593. memset(ht_info->supp_mcs_set, 0, 16);
  2594. ht_info->ht_supported = 1;
  2595. if (band == IEEE80211_BAND_5GHZ) {
  2596. ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
  2597. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
  2598. ht_info->supp_mcs_set[4] = 0x01;
  2599. }
  2600. ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
  2601. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
  2602. ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
  2603. (IWL_MIMO_PS_NONE << 2));
  2604. if (priv->cfg->mod_params->amsdu_size_8K)
  2605. ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
  2606. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  2607. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  2608. ht_info->supp_mcs_set[0] = 0xFF;
  2609. ht_info->supp_mcs_set[1] = 0xFF;
  2610. }
  2611. #endif /* CONFIG_IWL4965_HT */
  2612. static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
  2613. {
  2614. unsigned long flags;
  2615. spin_lock_irqsave(&priv->sta_lock, flags);
  2616. priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
  2617. priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
  2618. priv->stations[sta_id].sta.sta.modify_mask = 0;
  2619. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2620. spin_unlock_irqrestore(&priv->sta_lock, flags);
  2621. iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  2622. }
  2623. static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
  2624. {
  2625. /* FIXME: need locking over ps_status ??? */
  2626. u8 sta_id = iwl4965_hw_find_station(priv, addr);
  2627. if (sta_id != IWL_INVALID_STATION) {
  2628. u8 sta_awake = priv->stations[sta_id].
  2629. ps_status == STA_PS_STATUS_WAKE;
  2630. if (sta_awake && ps_bit)
  2631. priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
  2632. else if (!sta_awake && !ps_bit) {
  2633. iwl4965_sta_modify_ps_wake(priv, sta_id);
  2634. priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
  2635. }
  2636. }
  2637. }
  2638. #ifdef CONFIG_IWLWIFI_DEBUG
  2639. /**
  2640. * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
  2641. *
  2642. * You may hack this function to show different aspects of received frames,
  2643. * including selective frame dumps.
  2644. * group100 parameter selects whether to show 1 out of 100 good frames.
  2645. *
  2646. * TODO: This was originally written for 3945, need to audit for
  2647. * proper operation with 4965.
  2648. */
  2649. static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
  2650. struct iwl4965_rx_packet *pkt,
  2651. struct ieee80211_hdr *header, int group100)
  2652. {
  2653. u32 to_us;
  2654. u32 print_summary = 0;
  2655. u32 print_dump = 0; /* set to 1 to dump all frames' contents */
  2656. u32 hundred = 0;
  2657. u32 dataframe = 0;
  2658. u16 fc;
  2659. u16 seq_ctl;
  2660. u16 channel;
  2661. u16 phy_flags;
  2662. int rate_sym;
  2663. u16 length;
  2664. u16 status;
  2665. u16 bcn_tmr;
  2666. u32 tsf_low;
  2667. u64 tsf;
  2668. u8 rssi;
  2669. u8 agc;
  2670. u16 sig_avg;
  2671. u16 noise_diff;
  2672. struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
  2673. struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
  2674. struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
  2675. u8 *data = IWL_RX_DATA(pkt);
  2676. if (likely(!(iwl_debug_level & IWL_DL_RX)))
  2677. return;
  2678. /* MAC header */
  2679. fc = le16_to_cpu(header->frame_control);
  2680. seq_ctl = le16_to_cpu(header->seq_ctrl);
  2681. /* metadata */
  2682. channel = le16_to_cpu(rx_hdr->channel);
  2683. phy_flags = le16_to_cpu(rx_hdr->phy_flags);
  2684. rate_sym = rx_hdr->rate;
  2685. length = le16_to_cpu(rx_hdr->len);
  2686. /* end-of-frame status and timestamp */
  2687. status = le32_to_cpu(rx_end->status);
  2688. bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
  2689. tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
  2690. tsf = le64_to_cpu(rx_end->timestamp);
  2691. /* signal statistics */
  2692. rssi = rx_stats->rssi;
  2693. agc = rx_stats->agc;
  2694. sig_avg = le16_to_cpu(rx_stats->sig_avg);
  2695. noise_diff = le16_to_cpu(rx_stats->noise_diff);
  2696. to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
  2697. /* if data frame is to us and all is good,
  2698. * (optionally) print summary for only 1 out of every 100 */
  2699. if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
  2700. (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
  2701. dataframe = 1;
  2702. if (!group100)
  2703. print_summary = 1; /* print each frame */
  2704. else if (priv->framecnt_to_us < 100) {
  2705. priv->framecnt_to_us++;
  2706. print_summary = 0;
  2707. } else {
  2708. priv->framecnt_to_us = 0;
  2709. print_summary = 1;
  2710. hundred = 1;
  2711. }
  2712. } else {
  2713. /* print summary for all other frames */
  2714. print_summary = 1;
  2715. }
  2716. if (print_summary) {
  2717. char *title;
  2718. int rate_idx;
  2719. u32 bitrate;
  2720. if (hundred)
  2721. title = "100Frames";
  2722. else if (fc & IEEE80211_FCTL_RETRY)
  2723. title = "Retry";
  2724. else if (ieee80211_is_assoc_response(fc))
  2725. title = "AscRsp";
  2726. else if (ieee80211_is_reassoc_response(fc))
  2727. title = "RasRsp";
  2728. else if (ieee80211_is_probe_response(fc)) {
  2729. title = "PrbRsp";
  2730. print_dump = 1; /* dump frame contents */
  2731. } else if (ieee80211_is_beacon(fc)) {
  2732. title = "Beacon";
  2733. print_dump = 1; /* dump frame contents */
  2734. } else if (ieee80211_is_atim(fc))
  2735. title = "ATIM";
  2736. else if (ieee80211_is_auth(fc))
  2737. title = "Auth";
  2738. else if (ieee80211_is_deauth(fc))
  2739. title = "DeAuth";
  2740. else if (ieee80211_is_disassoc(fc))
  2741. title = "DisAssoc";
  2742. else
  2743. title = "Frame";
  2744. rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
  2745. if (unlikely(rate_idx == -1))
  2746. bitrate = 0;
  2747. else
  2748. bitrate = iwl4965_rates[rate_idx].ieee / 2;
  2749. /* print frame summary.
  2750. * MAC addresses show just the last byte (for brevity),
  2751. * but you can hack it to show more, if you'd like to. */
  2752. if (dataframe)
  2753. IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
  2754. "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
  2755. title, fc, header->addr1[5],
  2756. length, rssi, channel, bitrate);
  2757. else {
  2758. /* src/dst addresses assume managed mode */
  2759. IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
  2760. "src=0x%02x, rssi=%u, tim=%lu usec, "
  2761. "phy=0x%02x, chnl=%d\n",
  2762. title, fc, header->addr1[5],
  2763. header->addr3[5], rssi,
  2764. tsf_low - priv->scan_start_tsf,
  2765. phy_flags, channel);
  2766. }
  2767. }
  2768. if (print_dump)
  2769. iwl_print_hex_dump(IWL_DL_RX, data, length);
  2770. }
  2771. #else
  2772. static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
  2773. struct iwl4965_rx_packet *pkt,
  2774. struct ieee80211_hdr *header,
  2775. int group100)
  2776. {
  2777. }
  2778. #endif
  2779. /* Called for REPLY_RX (legacy ABG frames), or
  2780. * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
  2781. static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
  2782. struct iwl4965_rx_mem_buffer *rxb)
  2783. {
  2784. struct ieee80211_hdr *header;
  2785. struct ieee80211_rx_status rx_status;
  2786. struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
  2787. /* Use phy data (Rx signal strength, etc.) contained within
  2788. * this rx packet for legacy frames,
  2789. * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
  2790. int include_phy = (pkt->hdr.cmd == REPLY_RX);
  2791. struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
  2792. (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
  2793. (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
  2794. __le32 *rx_end;
  2795. unsigned int len = 0;
  2796. u16 fc;
  2797. u8 network_packet;
  2798. rx_status.mactime = le64_to_cpu(rx_start->timestamp);
  2799. rx_status.freq =
  2800. ieee80211_frequency_to_channel(le16_to_cpu(rx_start->channel));
  2801. rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
  2802. IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
  2803. rx_status.rate_idx =
  2804. iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
  2805. if (rx_status.band == IEEE80211_BAND_5GHZ)
  2806. rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
  2807. rx_status.antenna = 0;
  2808. rx_status.flag = 0;
  2809. if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
  2810. IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
  2811. rx_start->cfg_phy_cnt);
  2812. return;
  2813. }
  2814. if (!include_phy) {
  2815. if (priv->last_phy_res[0])
  2816. rx_start = (struct iwl4965_rx_phy_res *)
  2817. &priv->last_phy_res[1];
  2818. else
  2819. rx_start = NULL;
  2820. }
  2821. if (!rx_start) {
  2822. IWL_ERROR("MPDU frame without a PHY data\n");
  2823. return;
  2824. }
  2825. if (include_phy) {
  2826. header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
  2827. + rx_start->cfg_phy_cnt);
  2828. len = le16_to_cpu(rx_start->byte_count);
  2829. rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
  2830. sizeof(struct iwl4965_rx_phy_res) + len);
  2831. } else {
  2832. struct iwl4965_rx_mpdu_res_start *amsdu =
  2833. (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
  2834. header = (void *)(pkt->u.raw +
  2835. sizeof(struct iwl4965_rx_mpdu_res_start));
  2836. len = le16_to_cpu(amsdu->byte_count);
  2837. rx_end = (__le32 *) (pkt->u.raw +
  2838. sizeof(struct iwl4965_rx_mpdu_res_start) + len);
  2839. }
  2840. if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
  2841. !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
  2842. IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
  2843. le32_to_cpu(*rx_end));
  2844. return;
  2845. }
  2846. priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
  2847. /* Find max signal strength (dBm) among 3 antenna/receiver chains */
  2848. rx_status.ssi = iwl4965_calc_rssi(rx_start);
  2849. /* Meaningful noise values are available only from beacon statistics,
  2850. * which are gathered only when associated, and indicate noise
  2851. * only for the associated network channel ...
  2852. * Ignore these noise values while scanning (other channels) */
  2853. if (iwl_is_associated(priv) &&
  2854. !test_bit(STATUS_SCANNING, &priv->status)) {
  2855. rx_status.noise = priv->last_rx_noise;
  2856. rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi,
  2857. rx_status.noise);
  2858. } else {
  2859. rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  2860. rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi, 0);
  2861. }
  2862. /* Reset beacon noise level if not associated. */
  2863. if (!iwl_is_associated(priv))
  2864. priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
  2865. /* Set "1" to report good data frames in groups of 100 */
  2866. /* FIXME: need to optimze the call: */
  2867. iwl4965_dbg_report_frame(priv, pkt, header, 1);
  2868. IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
  2869. rx_status.ssi, rx_status.noise, rx_status.signal,
  2870. (unsigned long long)rx_status.mactime);
  2871. network_packet = iwl4965_is_network_packet(priv, header);
  2872. if (network_packet) {
  2873. priv->last_rx_rssi = rx_status.ssi;
  2874. priv->last_beacon_time = priv->ucode_beacon_time;
  2875. priv->last_tsf = le64_to_cpu(rx_start->timestamp);
  2876. }
  2877. fc = le16_to_cpu(header->frame_control);
  2878. switch (fc & IEEE80211_FCTL_FTYPE) {
  2879. case IEEE80211_FTYPE_MGMT:
  2880. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  2881. iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
  2882. header->addr2);
  2883. iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
  2884. break;
  2885. case IEEE80211_FTYPE_CTL:
  2886. #ifdef CONFIG_IWL4965_HT
  2887. switch (fc & IEEE80211_FCTL_STYPE) {
  2888. case IEEE80211_STYPE_BACK_REQ:
  2889. IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
  2890. iwl4965_handle_data_packet(priv, 0, include_phy,
  2891. rxb, &rx_status);
  2892. break;
  2893. default:
  2894. break;
  2895. }
  2896. #endif
  2897. break;
  2898. case IEEE80211_FTYPE_DATA: {
  2899. DECLARE_MAC_BUF(mac1);
  2900. DECLARE_MAC_BUF(mac2);
  2901. DECLARE_MAC_BUF(mac3);
  2902. if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
  2903. iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
  2904. header->addr2);
  2905. if (unlikely(!network_packet))
  2906. IWL_DEBUG_DROP("Dropping (non network): "
  2907. "%s, %s, %s\n",
  2908. print_mac(mac1, header->addr1),
  2909. print_mac(mac2, header->addr2),
  2910. print_mac(mac3, header->addr3));
  2911. else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
  2912. IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
  2913. print_mac(mac1, header->addr1),
  2914. print_mac(mac2, header->addr2),
  2915. print_mac(mac3, header->addr3));
  2916. else
  2917. iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
  2918. &rx_status);
  2919. break;
  2920. }
  2921. default:
  2922. break;
  2923. }
  2924. }
  2925. /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
  2926. * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
  2927. static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
  2928. struct iwl4965_rx_mem_buffer *rxb)
  2929. {
  2930. struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
  2931. priv->last_phy_res[0] = 1;
  2932. memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
  2933. sizeof(struct iwl4965_rx_phy_res));
  2934. }
  2935. static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
  2936. struct iwl4965_rx_mem_buffer *rxb)
  2937. {
  2938. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  2939. struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
  2940. struct iwl4965_missed_beacon_notif *missed_beacon;
  2941. missed_beacon = &pkt->u.missed_beacon;
  2942. if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
  2943. IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
  2944. le32_to_cpu(missed_beacon->consequtive_missed_beacons),
  2945. le32_to_cpu(missed_beacon->total_missed_becons),
  2946. le32_to_cpu(missed_beacon->num_recvd_beacons),
  2947. le32_to_cpu(missed_beacon->num_expected_beacons));
  2948. if (!test_bit(STATUS_SCANNING, &priv->status))
  2949. iwl_init_sensitivity(priv);
  2950. }
  2951. #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
  2952. }
  2953. #ifdef CONFIG_IWL4965_HT
  2954. /**
  2955. * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
  2956. */
  2957. static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
  2958. int sta_id, int tid)
  2959. {
  2960. unsigned long flags;
  2961. /* Remove "disable" flag, to enable Tx for this TID */
  2962. spin_lock_irqsave(&priv->sta_lock, flags);
  2963. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
  2964. priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
  2965. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  2966. spin_unlock_irqrestore(&priv->sta_lock, flags);
  2967. iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  2968. }
  2969. /**
  2970. * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
  2971. *
  2972. * Go through block-ack's bitmap of ACK'd frames, update driver's record of
  2973. * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
  2974. */
  2975. static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
  2976. struct iwl4965_ht_agg *agg,
  2977. struct iwl4965_compressed_ba_resp*
  2978. ba_resp)
  2979. {
  2980. int i, sh, ack;
  2981. u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
  2982. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  2983. u64 bitmap;
  2984. int successes = 0;
  2985. struct ieee80211_tx_status *tx_status;
  2986. if (unlikely(!agg->wait_for_ba)) {
  2987. IWL_ERROR("Received BA when not expected\n");
  2988. return -EINVAL;
  2989. }
  2990. /* Mark that the expected block-ack response arrived */
  2991. agg->wait_for_ba = 0;
  2992. IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
  2993. /* Calculate shift to align block-ack bits with our Tx window bits */
  2994. sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
  2995. if (sh < 0) /* tbw something is wrong with indices */
  2996. sh += 0x100;
  2997. /* don't use 64-bit values for now */
  2998. bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
  2999. if (agg->frame_count > (64 - sh)) {
  3000. IWL_DEBUG_TX_REPLY("more frames than bitmap size");
  3001. return -1;
  3002. }
  3003. /* check for success or failure according to the
  3004. * transmitted bitmap and block-ack bitmap */
  3005. bitmap &= agg->bitmap;
  3006. /* For each frame attempted in aggregation,
  3007. * update driver's record of tx frame's status. */
  3008. for (i = 0; i < agg->frame_count ; i++) {
  3009. ack = bitmap & (1 << i);
  3010. successes += !!ack;
  3011. IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
  3012. ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
  3013. agg->start_idx + i);
  3014. }
  3015. tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status;
  3016. tx_status->flags = IEEE80211_TX_STATUS_ACK;
  3017. tx_status->flags |= IEEE80211_TX_STATUS_AMPDU;
  3018. tx_status->ampdu_ack_map = successes;
  3019. tx_status->ampdu_ack_len = agg->frame_count;
  3020. iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags,
  3021. &tx_status->control);
  3022. IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
  3023. return 0;
  3024. }
  3025. /**
  3026. * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
  3027. */
  3028. static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
  3029. u16 txq_id)
  3030. {
  3031. /* Simply stop the queue, but don't change any configuration;
  3032. * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
  3033. iwl_write_prph(priv,
  3034. IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
  3035. (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
  3036. (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
  3037. }
  3038. /**
  3039. * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
  3040. * priv->lock must be held by the caller
  3041. */
  3042. static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
  3043. u16 ssn_idx, u8 tx_fifo)
  3044. {
  3045. int ret = 0;
  3046. if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
  3047. IWL_WARNING("queue number too small: %d, must be > %d\n",
  3048. txq_id, IWL_BACK_QUEUE_FIRST_ID);
  3049. return -EINVAL;
  3050. }
  3051. ret = iwl_grab_nic_access(priv);
  3052. if (ret)
  3053. return ret;
  3054. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  3055. iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  3056. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  3057. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  3058. /* supposes that ssn_idx is valid (!= 0xFFF) */
  3059. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  3060. iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  3061. iwl4965_txq_ctx_deactivate(priv, txq_id);
  3062. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
  3063. iwl_release_nic_access(priv);
  3064. return 0;
  3065. }
  3066. int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
  3067. u8 tid, int txq_id)
  3068. {
  3069. struct iwl4965_queue *q = &priv->txq[txq_id].q;
  3070. u8 *addr = priv->stations[sta_id].sta.sta.addr;
  3071. struct iwl4965_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
  3072. switch (priv->stations[sta_id].tid[tid].agg.state) {
  3073. case IWL_EMPTYING_HW_QUEUE_DELBA:
  3074. /* We are reclaiming the last packet of the */
  3075. /* aggregated HW queue */
  3076. if (txq_id == tid_data->agg.txq_id &&
  3077. q->read_ptr == q->write_ptr) {
  3078. u16 ssn = SEQ_TO_SN(tid_data->seq_number);
  3079. int tx_fifo = default_tid_to_tx_fifo[tid];
  3080. IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
  3081. iwl4965_tx_queue_agg_disable(priv, txq_id,
  3082. ssn, tx_fifo);
  3083. tid_data->agg.state = IWL_AGG_OFF;
  3084. ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
  3085. }
  3086. break;
  3087. case IWL_EMPTYING_HW_QUEUE_ADDBA:
  3088. /* We are reclaiming the last packet of the queue */
  3089. if (tid_data->tfds_in_queue == 0) {
  3090. IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
  3091. tid_data->agg.state = IWL_AGG_ON;
  3092. ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
  3093. }
  3094. break;
  3095. }
  3096. return 0;
  3097. }
  3098. /**
  3099. * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed
  3100. * @index -- current index
  3101. * @n_bd -- total number of entries in queue (s/b power of 2)
  3102. */
  3103. static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
  3104. {
  3105. return (index == 0) ? n_bd - 1 : index - 1;
  3106. }
  3107. /**
  3108. * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
  3109. *
  3110. * Handles block-acknowledge notification from device, which reports success
  3111. * of frames sent via aggregation.
  3112. */
  3113. static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
  3114. struct iwl4965_rx_mem_buffer *rxb)
  3115. {
  3116. struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
  3117. struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
  3118. int index;
  3119. struct iwl4965_tx_queue *txq = NULL;
  3120. struct iwl4965_ht_agg *agg;
  3121. DECLARE_MAC_BUF(mac);
  3122. /* "flow" corresponds to Tx queue */
  3123. u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
  3124. /* "ssn" is start of block-ack Tx window, corresponds to index
  3125. * (in Tx queue's circular buffer) of first TFD/frame in window */
  3126. u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
  3127. if (scd_flow >= priv->hw_params.max_txq_num) {
  3128. IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
  3129. return;
  3130. }
  3131. txq = &priv->txq[scd_flow];
  3132. agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
  3133. /* Find index just before block-ack window */
  3134. index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
  3135. /* TODO: Need to get this copy more safely - now good for debug */
  3136. IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
  3137. "sta_id = %d\n",
  3138. agg->wait_for_ba,
  3139. print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
  3140. ba_resp->sta_id);
  3141. IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
  3142. "%d, scd_ssn = %d\n",
  3143. ba_resp->tid,
  3144. ba_resp->seq_ctl,
  3145. (unsigned long long)le64_to_cpu(ba_resp->bitmap),
  3146. ba_resp->scd_flow,
  3147. ba_resp->scd_ssn);
  3148. IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
  3149. agg->start_idx,
  3150. (unsigned long long)agg->bitmap);
  3151. /* Update driver's record of ACK vs. not for each frame in window */
  3152. iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
  3153. /* Release all TFDs before the SSN, i.e. all TFDs in front of
  3154. * block-ack window (we assume that they've been successfully
  3155. * transmitted ... if not, it's too late anyway). */
  3156. if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
  3157. int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
  3158. priv->stations[ba_resp->sta_id].
  3159. tid[ba_resp->tid].tfds_in_queue -= freed;
  3160. if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
  3161. priv->mac80211_registered &&
  3162. agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
  3163. ieee80211_wake_queue(priv->hw, scd_flow);
  3164. iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
  3165. ba_resp->tid, scd_flow);
  3166. }
  3167. }
  3168. /**
  3169. * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
  3170. */
  3171. static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
  3172. u16 txq_id)
  3173. {
  3174. u32 tbl_dw_addr;
  3175. u32 tbl_dw;
  3176. u16 scd_q2ratid;
  3177. scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
  3178. tbl_dw_addr = priv->scd_base_addr +
  3179. SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
  3180. tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
  3181. if (txq_id & 0x1)
  3182. tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
  3183. else
  3184. tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
  3185. iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
  3186. return 0;
  3187. }
  3188. /**
  3189. * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
  3190. *
  3191. * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
  3192. * i.e. it must be one of the higher queues used for aggregation
  3193. */
  3194. static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
  3195. int tx_fifo, int sta_id, int tid,
  3196. u16 ssn_idx)
  3197. {
  3198. unsigned long flags;
  3199. int rc;
  3200. u16 ra_tid;
  3201. if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
  3202. IWL_WARNING("queue number too small: %d, must be > %d\n",
  3203. txq_id, IWL_BACK_QUEUE_FIRST_ID);
  3204. ra_tid = BUILD_RAxTID(sta_id, tid);
  3205. /* Modify device's station table to Tx this TID */
  3206. iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid);
  3207. spin_lock_irqsave(&priv->lock, flags);
  3208. rc = iwl_grab_nic_access(priv);
  3209. if (rc) {
  3210. spin_unlock_irqrestore(&priv->lock, flags);
  3211. return rc;
  3212. }
  3213. /* Stop this Tx queue before configuring it */
  3214. iwl4965_tx_queue_stop_scheduler(priv, txq_id);
  3215. /* Map receiver-address / traffic-ID to this queue */
  3216. iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
  3217. /* Set this queue as a chain-building queue */
  3218. iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
  3219. /* Place first TFD at index corresponding to start sequence number.
  3220. * Assumes that ssn_idx is valid (!= 0xFFF) */
  3221. priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
  3222. priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
  3223. iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
  3224. /* Set up Tx window size and frame limit for this queue */
  3225. iwl_write_targ_mem(priv,
  3226. priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id),
  3227. (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  3228. SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  3229. iwl_write_targ_mem(priv, priv->scd_base_addr +
  3230. SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
  3231. (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
  3232. & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  3233. iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
  3234. /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
  3235. iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
  3236. iwl_release_nic_access(priv);
  3237. spin_unlock_irqrestore(&priv->lock, flags);
  3238. return 0;
  3239. }
  3240. #endif /* CONFIG_IWL4965_HT */
  3241. /**
  3242. * iwl4965_add_station - Initialize a station's hardware rate table
  3243. *
  3244. * The uCode's station table contains a table of fallback rates
  3245. * for automatic fallback during transmission.
  3246. *
  3247. * NOTE: This sets up a default set of values. These will be replaced later
  3248. * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
  3249. * rc80211_simple.
  3250. *
  3251. * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
  3252. * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
  3253. * which requires station table entry to exist).
  3254. */
  3255. void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
  3256. {
  3257. int i, r;
  3258. struct iwl_link_quality_cmd link_cmd = {
  3259. .reserved1 = 0,
  3260. };
  3261. u16 rate_flags;
  3262. /* Set up the rate scaling to start at selected rate, fall back
  3263. * all the way down to 1M in IEEE order, and then spin on 1M */
  3264. if (is_ap)
  3265. r = IWL_RATE_54M_INDEX;
  3266. else if (priv->band == IEEE80211_BAND_5GHZ)
  3267. r = IWL_RATE_6M_INDEX;
  3268. else
  3269. r = IWL_RATE_1M_INDEX;
  3270. for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
  3271. rate_flags = 0;
  3272. if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
  3273. rate_flags |= RATE_MCS_CCK_MSK;
  3274. /* Use Tx antenna B only */
  3275. rate_flags |= RATE_MCS_ANT_B_MSK;
  3276. rate_flags &= ~RATE_MCS_ANT_A_MSK;
  3277. link_cmd.rs_table[i].rate_n_flags =
  3278. iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
  3279. r = iwl4965_get_prev_ieee_rate(r);
  3280. }
  3281. link_cmd.general_params.single_stream_ant_msk = 2;
  3282. link_cmd.general_params.dual_stream_ant_msk = 3;
  3283. link_cmd.agg_params.agg_dis_start_th = 3;
  3284. link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
  3285. /* Update the rate scaling for control frame Tx to AP */
  3286. link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
  3287. iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
  3288. sizeof(link_cmd), &link_cmd, NULL);
  3289. }
  3290. #ifdef CONFIG_IWL4965_HT
  3291. static u8 iwl4965_is_channel_extension(struct iwl_priv *priv,
  3292. enum ieee80211_band band,
  3293. u16 channel, u8 extension_chan_offset)
  3294. {
  3295. const struct iwl_channel_info *ch_info;
  3296. ch_info = iwl_get_channel_info(priv, band, channel);
  3297. if (!is_channel_valid(ch_info))
  3298. return 0;
  3299. if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
  3300. return 0;
  3301. if ((ch_info->fat_extension_channel == extension_chan_offset) ||
  3302. (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
  3303. return 1;
  3304. return 0;
  3305. }
  3306. static u8 iwl4965_is_fat_tx_allowed(struct iwl_priv *priv,
  3307. struct ieee80211_ht_info *sta_ht_inf)
  3308. {
  3309. struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
  3310. if ((!iwl_ht_conf->is_ht) ||
  3311. (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
  3312. (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE))
  3313. return 0;
  3314. if (sta_ht_inf) {
  3315. if ((!sta_ht_inf->ht_supported) ||
  3316. (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
  3317. return 0;
  3318. }
  3319. return (iwl4965_is_channel_extension(priv, priv->band,
  3320. iwl_ht_conf->control_channel,
  3321. iwl_ht_conf->extension_chan_offset));
  3322. }
  3323. void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
  3324. {
  3325. struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
  3326. u32 val;
  3327. if (!ht_info->is_ht)
  3328. return;
  3329. /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
  3330. if (iwl4965_is_fat_tx_allowed(priv, NULL))
  3331. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  3332. else
  3333. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  3334. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  3335. if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
  3336. IWL_DEBUG_ASSOC("control diff than current %d %d\n",
  3337. le16_to_cpu(rxon->channel),
  3338. ht_info->control_channel);
  3339. rxon->channel = cpu_to_le16(ht_info->control_channel);
  3340. return;
  3341. }
  3342. /* Note: control channel is opposite of extension channel */
  3343. switch (ht_info->extension_chan_offset) {
  3344. case IWL_EXT_CHANNEL_OFFSET_ABOVE:
  3345. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  3346. break;
  3347. case IWL_EXT_CHANNEL_OFFSET_BELOW:
  3348. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  3349. break;
  3350. case IWL_EXT_CHANNEL_OFFSET_NONE:
  3351. default:
  3352. rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  3353. break;
  3354. }
  3355. val = ht_info->ht_protection;
  3356. rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
  3357. iwl4965_set_rxon_chain(priv);
  3358. IWL_DEBUG_ASSOC("supported HT rate 0x%X %X "
  3359. "rxon flags 0x%X operation mode :0x%X "
  3360. "extension channel offset 0x%x "
  3361. "control chan %d\n",
  3362. ht_info->supp_mcs_set[0], ht_info->supp_mcs_set[1],
  3363. le32_to_cpu(rxon->flags), ht_info->ht_protection,
  3364. ht_info->extension_chan_offset,
  3365. ht_info->control_channel);
  3366. return;
  3367. }
  3368. void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
  3369. struct ieee80211_ht_info *sta_ht_inf)
  3370. {
  3371. __le32 sta_flags;
  3372. u8 mimo_ps_mode;
  3373. if (!sta_ht_inf || !sta_ht_inf->ht_supported)
  3374. goto done;
  3375. mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
  3376. sta_flags = priv->stations[index].sta.station_flags;
  3377. sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
  3378. switch (mimo_ps_mode) {
  3379. case WLAN_HT_CAP_MIMO_PS_STATIC:
  3380. sta_flags |= STA_FLG_MIMO_DIS_MSK;
  3381. break;
  3382. case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
  3383. sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
  3384. break;
  3385. case WLAN_HT_CAP_MIMO_PS_DISABLED:
  3386. break;
  3387. default:
  3388. IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
  3389. break;
  3390. }
  3391. sta_flags |= cpu_to_le32(
  3392. (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
  3393. sta_flags |= cpu_to_le32(
  3394. (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
  3395. if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf))
  3396. sta_flags |= STA_FLG_FAT_EN_MSK;
  3397. else
  3398. sta_flags &= ~STA_FLG_FAT_EN_MSK;
  3399. priv->stations[index].sta.station_flags = sta_flags;
  3400. done:
  3401. return;
  3402. }
  3403. static void iwl4965_sta_modify_add_ba_tid(struct iwl_priv *priv,
  3404. int sta_id, int tid, u16 ssn)
  3405. {
  3406. unsigned long flags;
  3407. spin_lock_irqsave(&priv->sta_lock, flags);
  3408. priv->stations[sta_id].sta.station_flags_msk = 0;
  3409. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
  3410. priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
  3411. priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
  3412. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3413. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3414. iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3415. }
  3416. static void iwl4965_sta_modify_del_ba_tid(struct iwl_priv *priv,
  3417. int sta_id, int tid)
  3418. {
  3419. unsigned long flags;
  3420. spin_lock_irqsave(&priv->sta_lock, flags);
  3421. priv->stations[sta_id].sta.station_flags_msk = 0;
  3422. priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
  3423. priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
  3424. priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
  3425. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3426. iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
  3427. }
  3428. /*
  3429. * Find first available (lowest unused) Tx Queue, mark it "active".
  3430. * Called only when finding queue for aggregation.
  3431. * Should never return anything < 7, because they should already
  3432. * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
  3433. */
  3434. static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
  3435. {
  3436. int txq_id;
  3437. for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
  3438. if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
  3439. return txq_id;
  3440. return -1;
  3441. }
  3442. static int iwl4965_mac_ht_tx_agg_start(struct ieee80211_hw *hw, const u8 *da,
  3443. u16 tid, u16 *start_seq_num)
  3444. {
  3445. struct iwl_priv *priv = hw->priv;
  3446. int sta_id;
  3447. int tx_fifo;
  3448. int txq_id;
  3449. int ssn = -1;
  3450. int ret = 0;
  3451. unsigned long flags;
  3452. struct iwl4965_tid_data *tid_data;
  3453. DECLARE_MAC_BUF(mac);
  3454. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  3455. tx_fifo = default_tid_to_tx_fifo[tid];
  3456. else
  3457. return -EINVAL;
  3458. IWL_WARNING("%s on da = %s tid = %d\n",
  3459. __func__, print_mac(mac, da), tid);
  3460. sta_id = iwl4965_hw_find_station(priv, da);
  3461. if (sta_id == IWL_INVALID_STATION)
  3462. return -ENXIO;
  3463. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
  3464. IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
  3465. return -ENXIO;
  3466. }
  3467. txq_id = iwl4965_txq_ctx_activate_free(priv);
  3468. if (txq_id == -1)
  3469. return -ENXIO;
  3470. spin_lock_irqsave(&priv->sta_lock, flags);
  3471. tid_data = &priv->stations[sta_id].tid[tid];
  3472. ssn = SEQ_TO_SN(tid_data->seq_number);
  3473. tid_data->agg.txq_id = txq_id;
  3474. spin_unlock_irqrestore(&priv->sta_lock, flags);
  3475. *start_seq_num = ssn;
  3476. ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
  3477. sta_id, tid, ssn);
  3478. if (ret)
  3479. return ret;
  3480. ret = 0;
  3481. if (tid_data->tfds_in_queue == 0) {
  3482. printk(KERN_ERR "HW queue is empty\n");
  3483. tid_data->agg.state = IWL_AGG_ON;
  3484. ieee80211_start_tx_ba_cb_irqsafe(hw, da, tid);
  3485. } else {
  3486. IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
  3487. tid_data->tfds_in_queue);
  3488. tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
  3489. }
  3490. return ret;
  3491. }
  3492. static int iwl4965_mac_ht_tx_agg_stop(struct ieee80211_hw *hw, const u8 *da,
  3493. u16 tid)
  3494. {
  3495. struct iwl_priv *priv = hw->priv;
  3496. int tx_fifo_id, txq_id, sta_id, ssn = -1;
  3497. struct iwl4965_tid_data *tid_data;
  3498. int ret, write_ptr, read_ptr;
  3499. unsigned long flags;
  3500. DECLARE_MAC_BUF(mac);
  3501. if (!da) {
  3502. IWL_ERROR("da = NULL\n");
  3503. return -EINVAL;
  3504. }
  3505. if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
  3506. tx_fifo_id = default_tid_to_tx_fifo[tid];
  3507. else
  3508. return -EINVAL;
  3509. sta_id = iwl4965_hw_find_station(priv, da);
  3510. if (sta_id == IWL_INVALID_STATION)
  3511. return -ENXIO;
  3512. if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
  3513. IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
  3514. tid_data = &priv->stations[sta_id].tid[tid];
  3515. ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
  3516. txq_id = tid_data->agg.txq_id;
  3517. write_ptr = priv->txq[txq_id].q.write_ptr;
  3518. read_ptr = priv->txq[txq_id].q.read_ptr;
  3519. /* The queue is not empty */
  3520. if (write_ptr != read_ptr) {
  3521. IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
  3522. priv->stations[sta_id].tid[tid].agg.state =
  3523. IWL_EMPTYING_HW_QUEUE_DELBA;
  3524. return 0;
  3525. }
  3526. IWL_DEBUG_HT("HW queue empty\n");;
  3527. priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
  3528. spin_lock_irqsave(&priv->lock, flags);
  3529. ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
  3530. spin_unlock_irqrestore(&priv->lock, flags);
  3531. if (ret)
  3532. return ret;
  3533. ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, da, tid);
  3534. IWL_DEBUG_INFO("iwl4965_mac_ht_tx_agg_stop on da=%s tid=%d\n",
  3535. print_mac(mac, da), tid);
  3536. return 0;
  3537. }
  3538. int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
  3539. enum ieee80211_ampdu_mlme_action action,
  3540. const u8 *addr, u16 tid, u16 *ssn)
  3541. {
  3542. struct iwl_priv *priv = hw->priv;
  3543. int sta_id;
  3544. DECLARE_MAC_BUF(mac);
  3545. IWL_DEBUG_HT("A-MPDU action on da=%s tid=%d ",
  3546. print_mac(mac, addr), tid);
  3547. sta_id = iwl4965_hw_find_station(priv, addr);
  3548. switch (action) {
  3549. case IEEE80211_AMPDU_RX_START:
  3550. IWL_DEBUG_HT("start Rx\n");
  3551. iwl4965_sta_modify_add_ba_tid(priv, sta_id, tid, *ssn);
  3552. break;
  3553. case IEEE80211_AMPDU_RX_STOP:
  3554. IWL_DEBUG_HT("stop Rx\n");
  3555. iwl4965_sta_modify_del_ba_tid(priv, sta_id, tid);
  3556. break;
  3557. case IEEE80211_AMPDU_TX_START:
  3558. IWL_DEBUG_HT("start Tx\n");
  3559. return iwl4965_mac_ht_tx_agg_start(hw, addr, tid, ssn);
  3560. case IEEE80211_AMPDU_TX_STOP:
  3561. IWL_DEBUG_HT("stop Tx\n");
  3562. return iwl4965_mac_ht_tx_agg_stop(hw, addr, tid);
  3563. default:
  3564. IWL_DEBUG_HT("unknown\n");
  3565. return -EINVAL;
  3566. break;
  3567. }
  3568. return 0;
  3569. }
  3570. #endif /* CONFIG_IWL4965_HT */
  3571. /* Set up 4965-specific Rx frame reply handlers */
  3572. void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv)
  3573. {
  3574. /* Legacy Rx frames */
  3575. priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
  3576. /* High-throughput (HT) Rx frames */
  3577. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  3578. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  3579. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  3580. iwl4965_rx_missed_beacon_notif;
  3581. #ifdef CONFIG_IWL4965_HT
  3582. priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
  3583. #endif /* CONFIG_IWL4965_HT */
  3584. }
  3585. void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
  3586. {
  3587. INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
  3588. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  3589. INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
  3590. #endif
  3591. init_timer(&priv->statistics_periodic);
  3592. priv->statistics_periodic.data = (unsigned long)priv;
  3593. priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
  3594. }
  3595. void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
  3596. {
  3597. del_timer_sync(&priv->statistics_periodic);
  3598. cancel_delayed_work(&priv->init_alive_start);
  3599. }
  3600. static struct iwl_hcmd_ops iwl4965_hcmd = {
  3601. .rxon_assoc = iwl4965_send_rxon_assoc,
  3602. };
  3603. static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
  3604. .enqueue_hcmd = iwl4965_enqueue_hcmd,
  3605. #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
  3606. .chain_noise_reset = iwl4965_chain_noise_reset,
  3607. .gain_computation = iwl4965_gain_computation,
  3608. #endif
  3609. };
  3610. static struct iwl_lib_ops iwl4965_lib = {
  3611. .init_drv = iwl4965_init_drv,
  3612. .set_hw_params = iwl4965_hw_set_hw_params,
  3613. .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
  3614. .hw_nic_init = iwl4965_hw_nic_init,
  3615. .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
  3616. .alive_notify = iwl4965_alive_notify,
  3617. .load_ucode = iwl4965_load_bsm,
  3618. .eeprom_ops = {
  3619. .verify_signature = iwlcore_eeprom_verify_signature,
  3620. .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
  3621. .release_semaphore = iwlcore_eeprom_release_semaphore,
  3622. },
  3623. .radio_kill_sw = iwl4965_radio_kill_sw,
  3624. };
  3625. static struct iwl_ops iwl4965_ops = {
  3626. .lib = &iwl4965_lib,
  3627. .hcmd = &iwl4965_hcmd,
  3628. .utils = &iwl4965_hcmd_utils,
  3629. };
  3630. struct iwl_cfg iwl4965_agn_cfg = {
  3631. .name = "4965AGN",
  3632. .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
  3633. .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
  3634. .ops = &iwl4965_ops,
  3635. .mod_params = &iwl4965_mod_params,
  3636. };
  3637. module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
  3638. MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
  3639. module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
  3640. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  3641. module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
  3642. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
  3643. module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
  3644. MODULE_PARM_DESC(debug, "debug output mask");
  3645. module_param_named(
  3646. disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
  3647. MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
  3648. module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
  3649. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  3650. /* QoS */
  3651. module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
  3652. MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
  3653. module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
  3654. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");