iwl-4965.c 104 KB

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