iwl-4965.c 104 KB

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