iwl-4965.c 107 KB

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