iwl-4965.c 103 KB

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