iwl-4965.c 103 KB

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