iwl-4965.c 116 KB

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