iwl-4965.c 104 KB

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