iwl-4965.c 116 KB

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