iwl4965-base.c 102 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  30. #include <linux/kernel.h>
  31. #include <linux/module.h>
  32. #include <linux/init.h>
  33. #include <linux/pci.h>
  34. #include <linux/pci-aspm.h>
  35. #include <linux/slab.h>
  36. #include <linux/dma-mapping.h>
  37. #include <linux/delay.h>
  38. #include <linux/sched.h>
  39. #include <linux/skbuff.h>
  40. #include <linux/netdevice.h>
  41. #include <linux/wireless.h>
  42. #include <linux/firmware.h>
  43. #include <linux/etherdevice.h>
  44. #include <linux/if_arp.h>
  45. #include <net/mac80211.h>
  46. #include <asm/div64.h>
  47. #define DRV_NAME "iwl4965"
  48. #include "iwl-eeprom.h"
  49. #include "iwl-dev.h"
  50. #include "iwl-core.h"
  51. #include "iwl-io.h"
  52. #include "iwl-helpers.h"
  53. #include "iwl-sta.h"
  54. #include "iwl-4965-calib.h"
  55. #include "iwl-4965.h"
  56. #include "iwl-4965-led.h"
  57. /******************************************************************************
  58. *
  59. * module boiler plate
  60. *
  61. ******************************************************************************/
  62. /*
  63. * module name, copyright, version, etc.
  64. */
  65. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi 4965 driver for Linux"
  66. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  67. #define VD "d"
  68. #else
  69. #define VD
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD
  72. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  73. MODULE_VERSION(DRV_VERSION);
  74. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  75. MODULE_LICENSE("GPL");
  76. MODULE_ALIAS("iwl4965");
  77. void iwl4965_update_chain_flags(struct iwl_priv *priv)
  78. {
  79. struct iwl_rxon_context *ctx;
  80. if (priv->cfg->ops->hcmd->set_rxon_chain) {
  81. for_each_context(priv, ctx) {
  82. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  83. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  84. iwl_legacy_commit_rxon(priv, ctx);
  85. }
  86. }
  87. }
  88. static void iwl4965_clear_free_frames(struct iwl_priv *priv)
  89. {
  90. struct list_head *element;
  91. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  92. priv->frames_count);
  93. while (!list_empty(&priv->free_frames)) {
  94. element = priv->free_frames.next;
  95. list_del(element);
  96. kfree(list_entry(element, struct iwl_frame, list));
  97. priv->frames_count--;
  98. }
  99. if (priv->frames_count) {
  100. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  101. priv->frames_count);
  102. priv->frames_count = 0;
  103. }
  104. }
  105. static struct iwl_frame *iwl4965_get_free_frame(struct iwl_priv *priv)
  106. {
  107. struct iwl_frame *frame;
  108. struct list_head *element;
  109. if (list_empty(&priv->free_frames)) {
  110. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  111. if (!frame) {
  112. IWL_ERR(priv, "Could not allocate frame!\n");
  113. return NULL;
  114. }
  115. priv->frames_count++;
  116. return frame;
  117. }
  118. element = priv->free_frames.next;
  119. list_del(element);
  120. return list_entry(element, struct iwl_frame, list);
  121. }
  122. static void iwl4965_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  123. {
  124. memset(frame, 0, sizeof(*frame));
  125. list_add(&frame->list, &priv->free_frames);
  126. }
  127. static u32 iwl4965_fill_beacon_frame(struct iwl_priv *priv,
  128. struct ieee80211_hdr *hdr,
  129. int left)
  130. {
  131. lockdep_assert_held(&priv->mutex);
  132. if (!priv->beacon_skb)
  133. return 0;
  134. if (priv->beacon_skb->len > left)
  135. return 0;
  136. memcpy(hdr, priv->beacon_skb->data, priv->beacon_skb->len);
  137. return priv->beacon_skb->len;
  138. }
  139. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  140. static void iwl4965_set_beacon_tim(struct iwl_priv *priv,
  141. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  142. u8 *beacon, u32 frame_size)
  143. {
  144. u16 tim_idx;
  145. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  146. /*
  147. * The index is relative to frame start but we start looking at the
  148. * variable-length part of the beacon.
  149. */
  150. tim_idx = mgmt->u.beacon.variable - beacon;
  151. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  152. while ((tim_idx < (frame_size - 2)) &&
  153. (beacon[tim_idx] != WLAN_EID_TIM))
  154. tim_idx += beacon[tim_idx+1] + 2;
  155. /* If TIM field was found, set variables */
  156. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  157. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  158. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  159. } else
  160. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  161. }
  162. static unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
  163. struct iwl_frame *frame)
  164. {
  165. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  166. u32 frame_size;
  167. u32 rate_flags;
  168. u32 rate;
  169. /*
  170. * We have to set up the TX command, the TX Beacon command, and the
  171. * beacon contents.
  172. */
  173. lockdep_assert_held(&priv->mutex);
  174. if (!priv->beacon_ctx) {
  175. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  176. return 0;
  177. }
  178. /* Initialize memory */
  179. tx_beacon_cmd = &frame->u.beacon;
  180. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  181. /* Set up TX beacon contents */
  182. frame_size = iwl4965_fill_beacon_frame(priv, tx_beacon_cmd->frame,
  183. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  184. if (WARN_ON_ONCE(frame_size > MAX_MPDU_SIZE))
  185. return 0;
  186. if (!frame_size)
  187. return 0;
  188. /* Set up TX command fields */
  189. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  190. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  191. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  192. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  193. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  194. /* Set up TX beacon command fields */
  195. iwl4965_set_beacon_tim(priv, tx_beacon_cmd, (u8 *)tx_beacon_cmd->frame,
  196. frame_size);
  197. /* Set up packet rate and flags */
  198. rate = iwl_legacy_get_lowest_plcp(priv, priv->beacon_ctx);
  199. priv->mgmt_tx_ant = iwl4965_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  200. priv->hw_params.valid_tx_ant);
  201. rate_flags = iwl4965_ant_idx_to_flags(priv->mgmt_tx_ant);
  202. if ((rate >= IWL_FIRST_CCK_RATE) && (rate <= IWL_LAST_CCK_RATE))
  203. rate_flags |= RATE_MCS_CCK_MSK;
  204. tx_beacon_cmd->tx.rate_n_flags = iwl4965_hw_set_rate_n_flags(rate,
  205. rate_flags);
  206. return sizeof(*tx_beacon_cmd) + frame_size;
  207. }
  208. int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
  209. {
  210. struct iwl_frame *frame;
  211. unsigned int frame_size;
  212. int rc;
  213. frame = iwl4965_get_free_frame(priv);
  214. if (!frame) {
  215. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  216. "command.\n");
  217. return -ENOMEM;
  218. }
  219. frame_size = iwl4965_hw_get_beacon_cmd(priv, frame);
  220. if (!frame_size) {
  221. IWL_ERR(priv, "Error configuring the beacon command\n");
  222. iwl4965_free_frame(priv, frame);
  223. return -EINVAL;
  224. }
  225. rc = iwl_legacy_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  226. &frame->u.cmd[0]);
  227. iwl4965_free_frame(priv, frame);
  228. return rc;
  229. }
  230. static inline dma_addr_t iwl4965_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
  231. {
  232. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  233. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  234. if (sizeof(dma_addr_t) > sizeof(u32))
  235. addr |=
  236. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  237. return addr;
  238. }
  239. static inline u16 iwl4965_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  240. {
  241. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  242. return le16_to_cpu(tb->hi_n_len) >> 4;
  243. }
  244. static inline void iwl4965_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
  245. dma_addr_t addr, u16 len)
  246. {
  247. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  248. u16 hi_n_len = len << 4;
  249. put_unaligned_le32(addr, &tb->lo);
  250. if (sizeof(dma_addr_t) > sizeof(u32))
  251. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  252. tb->hi_n_len = cpu_to_le16(hi_n_len);
  253. tfd->num_tbs = idx + 1;
  254. }
  255. static inline u8 iwl4965_tfd_get_num_tbs(struct iwl_tfd *tfd)
  256. {
  257. return tfd->num_tbs & 0x1f;
  258. }
  259. /**
  260. * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  261. * @priv - driver private data
  262. * @txq - tx queue
  263. *
  264. * Does NOT advance any TFD circular buffer read/write indexes
  265. * Does NOT free the TFD itself (which is within circular buffer)
  266. */
  267. void iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  268. {
  269. struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
  270. struct iwl_tfd *tfd;
  271. struct pci_dev *dev = priv->pci_dev;
  272. int index = txq->q.read_ptr;
  273. int i;
  274. int num_tbs;
  275. tfd = &tfd_tmp[index];
  276. /* Sanity check on number of chunks */
  277. num_tbs = iwl4965_tfd_get_num_tbs(tfd);
  278. if (num_tbs >= IWL_NUM_OF_TBS) {
  279. IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
  280. /* @todo issue fatal error, it is quite serious situation */
  281. return;
  282. }
  283. /* Unmap tx_cmd */
  284. if (num_tbs)
  285. pci_unmap_single(dev,
  286. dma_unmap_addr(&txq->meta[index], mapping),
  287. dma_unmap_len(&txq->meta[index], len),
  288. PCI_DMA_BIDIRECTIONAL);
  289. /* Unmap chunks, if any. */
  290. for (i = 1; i < num_tbs; i++)
  291. pci_unmap_single(dev, iwl4965_tfd_tb_get_addr(tfd, i),
  292. iwl4965_tfd_tb_get_len(tfd, i),
  293. PCI_DMA_TODEVICE);
  294. /* free SKB */
  295. if (txq->txb) {
  296. struct sk_buff *skb;
  297. skb = txq->txb[txq->q.read_ptr].skb;
  298. /* can be called from irqs-disabled context */
  299. if (skb) {
  300. dev_kfree_skb_any(skb);
  301. txq->txb[txq->q.read_ptr].skb = NULL;
  302. }
  303. }
  304. }
  305. int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
  306. struct iwl_tx_queue *txq,
  307. dma_addr_t addr, u16 len,
  308. u8 reset, u8 pad)
  309. {
  310. struct iwl_queue *q;
  311. struct iwl_tfd *tfd, *tfd_tmp;
  312. u32 num_tbs;
  313. q = &txq->q;
  314. tfd_tmp = (struct iwl_tfd *)txq->tfds;
  315. tfd = &tfd_tmp[q->write_ptr];
  316. if (reset)
  317. memset(tfd, 0, sizeof(*tfd));
  318. num_tbs = iwl4965_tfd_get_num_tbs(tfd);
  319. /* Each TFD can point to a maximum 20 Tx buffers */
  320. if (num_tbs >= IWL_NUM_OF_TBS) {
  321. IWL_ERR(priv, "Error can not send more than %d chunks\n",
  322. IWL_NUM_OF_TBS);
  323. return -EINVAL;
  324. }
  325. BUG_ON(addr & ~DMA_BIT_MASK(36));
  326. if (unlikely(addr & ~IWL_TX_DMA_MASK))
  327. IWL_ERR(priv, "Unaligned address = %llx\n",
  328. (unsigned long long)addr);
  329. iwl4965_tfd_set_tb(tfd, num_tbs, addr, len);
  330. return 0;
  331. }
  332. /*
  333. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  334. * given Tx queue, and enable the DMA channel used for that queue.
  335. *
  336. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  337. * channels supported in hardware.
  338. */
  339. int iwl4965_hw_tx_queue_init(struct iwl_priv *priv,
  340. struct iwl_tx_queue *txq)
  341. {
  342. int txq_id = txq->q.id;
  343. /* Circular buffer (TFD queue in DRAM) physical base address */
  344. iwl_legacy_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  345. txq->q.dma_addr >> 8);
  346. return 0;
  347. }
  348. /******************************************************************************
  349. *
  350. * Generic RX handler implementations
  351. *
  352. ******************************************************************************/
  353. static void iwl4965_rx_reply_alive(struct iwl_priv *priv,
  354. struct iwl_rx_mem_buffer *rxb)
  355. {
  356. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  357. struct iwl_alive_resp *palive;
  358. struct delayed_work *pwork;
  359. palive = &pkt->u.alive_frame;
  360. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  361. "0x%01X 0x%01X\n",
  362. palive->is_valid, palive->ver_type,
  363. palive->ver_subtype);
  364. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  365. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  366. memcpy(&priv->card_alive_init,
  367. &pkt->u.alive_frame,
  368. sizeof(struct iwl_init_alive_resp));
  369. pwork = &priv->init_alive_start;
  370. } else {
  371. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  372. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  373. sizeof(struct iwl_alive_resp));
  374. pwork = &priv->alive_start;
  375. }
  376. /* We delay the ALIVE response by 5ms to
  377. * give the HW RF Kill time to activate... */
  378. if (palive->is_valid == UCODE_VALID_OK)
  379. queue_delayed_work(priv->workqueue, pwork,
  380. msecs_to_jiffies(5));
  381. else
  382. IWL_WARN(priv, "uCode did not respond OK.\n");
  383. }
  384. /**
  385. * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
  386. *
  387. * This callback is provided in order to send a statistics request.
  388. *
  389. * This timer function is continually reset to execute within
  390. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  391. * was received. We need to ensure we receive the statistics in order
  392. * to update the temperature used for calibrating the TXPOWER.
  393. */
  394. static void iwl4965_bg_statistics_periodic(unsigned long data)
  395. {
  396. struct iwl_priv *priv = (struct iwl_priv *)data;
  397. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  398. return;
  399. /* dont send host command if rf-kill is on */
  400. if (!iwl_legacy_is_ready_rf(priv))
  401. return;
  402. iwl_legacy_send_statistics_request(priv, CMD_ASYNC, false);
  403. }
  404. static void iwl4965_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  405. u32 start_idx, u32 num_events,
  406. u32 mode)
  407. {
  408. u32 i;
  409. u32 ptr; /* SRAM byte address of log data */
  410. u32 ev, time, data; /* event log data */
  411. unsigned long reg_flags;
  412. if (mode == 0)
  413. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  414. else
  415. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  416. /* Make sure device is powered up for SRAM reads */
  417. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  418. if (iwl_grab_nic_access(priv)) {
  419. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  420. return;
  421. }
  422. /* Set starting address; reads will auto-increment */
  423. _iwl_legacy_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  424. rmb();
  425. /*
  426. * "time" is actually "data" for mode 0 (no timestamp).
  427. * place event id # at far right for easier visual parsing.
  428. */
  429. for (i = 0; i < num_events; i++) {
  430. ev = _iwl_legacy_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  431. time = _iwl_legacy_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  432. if (mode == 0) {
  433. trace_iwlwifi_legacy_dev_ucode_cont_event(priv,
  434. 0, time, ev);
  435. } else {
  436. data = _iwl_legacy_read_direct32(priv,
  437. HBUS_TARG_MEM_RDAT);
  438. trace_iwlwifi_legacy_dev_ucode_cont_event(priv,
  439. time, data, ev);
  440. }
  441. }
  442. /* Allow device to power down */
  443. iwl_release_nic_access(priv);
  444. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  445. }
  446. static void iwl4965_continuous_event_trace(struct iwl_priv *priv)
  447. {
  448. u32 capacity; /* event log capacity in # entries */
  449. u32 base; /* SRAM byte address of event log header */
  450. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  451. u32 num_wraps; /* # times uCode wrapped to top of log */
  452. u32 next_entry; /* index of next entry to be written by uCode */
  453. if (priv->ucode_type == UCODE_INIT)
  454. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  455. else
  456. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  457. if (priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  458. capacity = iwl_legacy_read_targ_mem(priv, base);
  459. num_wraps = iwl_legacy_read_targ_mem(priv,
  460. base + (2 * sizeof(u32)));
  461. mode = iwl_legacy_read_targ_mem(priv, base + (1 * sizeof(u32)));
  462. next_entry = iwl_legacy_read_targ_mem(priv,
  463. base + (3 * sizeof(u32)));
  464. } else
  465. return;
  466. if (num_wraps == priv->event_log.num_wraps) {
  467. iwl4965_print_cont_event_trace(priv,
  468. base, priv->event_log.next_entry,
  469. next_entry - priv->event_log.next_entry,
  470. mode);
  471. priv->event_log.non_wraps_count++;
  472. } else {
  473. if ((num_wraps - priv->event_log.num_wraps) > 1)
  474. priv->event_log.wraps_more_count++;
  475. else
  476. priv->event_log.wraps_once_count++;
  477. trace_iwlwifi_legacy_dev_ucode_wrap_event(priv,
  478. num_wraps - priv->event_log.num_wraps,
  479. next_entry, priv->event_log.next_entry);
  480. if (next_entry < priv->event_log.next_entry) {
  481. iwl4965_print_cont_event_trace(priv, base,
  482. priv->event_log.next_entry,
  483. capacity - priv->event_log.next_entry,
  484. mode);
  485. iwl4965_print_cont_event_trace(priv, base, 0,
  486. next_entry, mode);
  487. } else {
  488. iwl4965_print_cont_event_trace(priv, base,
  489. next_entry, capacity - next_entry,
  490. mode);
  491. iwl4965_print_cont_event_trace(priv, base, 0,
  492. next_entry, mode);
  493. }
  494. }
  495. priv->event_log.num_wraps = num_wraps;
  496. priv->event_log.next_entry = next_entry;
  497. }
  498. /**
  499. * iwl4965_bg_ucode_trace - Timer callback to log ucode event
  500. *
  501. * The timer is continually set to execute every
  502. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  503. * this function is to perform continuous uCode event logging operation
  504. * if enabled
  505. */
  506. static void iwl4965_bg_ucode_trace(unsigned long data)
  507. {
  508. struct iwl_priv *priv = (struct iwl_priv *)data;
  509. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  510. return;
  511. if (priv->event_log.ucode_trace) {
  512. iwl4965_continuous_event_trace(priv);
  513. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  514. mod_timer(&priv->ucode_trace,
  515. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  516. }
  517. }
  518. static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
  519. struct iwl_rx_mem_buffer *rxb)
  520. {
  521. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  522. struct iwl4965_beacon_notif *beacon =
  523. (struct iwl4965_beacon_notif *)pkt->u.raw;
  524. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  525. u8 rate = iwl4965_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  526. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  527. "tsf %d %d rate %d\n",
  528. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  529. beacon->beacon_notify_hdr.failure_frame,
  530. le32_to_cpu(beacon->ibss_mgr_status),
  531. le32_to_cpu(beacon->high_tsf),
  532. le32_to_cpu(beacon->low_tsf), rate);
  533. #endif
  534. priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
  535. }
  536. static void iwl4965_perform_ct_kill_task(struct iwl_priv *priv)
  537. {
  538. unsigned long flags;
  539. IWL_DEBUG_POWER(priv, "Stop all queues\n");
  540. if (priv->mac80211_registered)
  541. ieee80211_stop_queues(priv->hw);
  542. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  543. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  544. iwl_read32(priv, CSR_UCODE_DRV_GP1);
  545. spin_lock_irqsave(&priv->reg_lock, flags);
  546. if (!iwl_grab_nic_access(priv))
  547. iwl_release_nic_access(priv);
  548. spin_unlock_irqrestore(&priv->reg_lock, flags);
  549. }
  550. /* Handle notification from uCode that card's power state is changing
  551. * due to software, hardware, or critical temperature RFKILL */
  552. static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
  553. struct iwl_rx_mem_buffer *rxb)
  554. {
  555. struct iwl_rx_packet *pkt = rxb_addr(rxb);
  556. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  557. unsigned long status = priv->status;
  558. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s CT:%s\n",
  559. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  560. (flags & SW_CARD_DISABLED) ? "Kill" : "On",
  561. (flags & CT_CARD_DISABLED) ?
  562. "Reached" : "Not reached");
  563. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  564. CT_CARD_DISABLED)) {
  565. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  566. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  567. iwl_legacy_write_direct32(priv, HBUS_TARG_MBX_C,
  568. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  569. if (!(flags & RXON_CARD_DISABLED)) {
  570. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  571. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  572. iwl_legacy_write_direct32(priv, HBUS_TARG_MBX_C,
  573. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  574. }
  575. }
  576. if (flags & CT_CARD_DISABLED)
  577. iwl4965_perform_ct_kill_task(priv);
  578. if (flags & HW_CARD_DISABLED)
  579. set_bit(STATUS_RF_KILL_HW, &priv->status);
  580. else
  581. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  582. if (!(flags & RXON_CARD_DISABLED))
  583. iwl_legacy_scan_cancel(priv);
  584. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  585. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  586. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  587. test_bit(STATUS_RF_KILL_HW, &priv->status));
  588. else
  589. wake_up_interruptible(&priv->wait_command_queue);
  590. }
  591. /**
  592. * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
  593. *
  594. * Setup the RX handlers for each of the reply types sent from the uCode
  595. * to the host.
  596. *
  597. * This function chains into the hardware specific files for them to setup
  598. * any hardware specific handlers as well.
  599. */
  600. static void iwl4965_setup_rx_handlers(struct iwl_priv *priv)
  601. {
  602. priv->rx_handlers[REPLY_ALIVE] = iwl4965_rx_reply_alive;
  603. priv->rx_handlers[REPLY_ERROR] = iwl_legacy_rx_reply_error;
  604. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_legacy_rx_csa;
  605. priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
  606. iwl_legacy_rx_spectrum_measure_notif;
  607. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_legacy_rx_pm_sleep_notif;
  608. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  609. iwl_legacy_rx_pm_debug_statistics_notif;
  610. priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
  611. /*
  612. * The same handler is used for both the REPLY to a discrete
  613. * statistics request from the host as well as for the periodic
  614. * statistics notifications (after received beacons) from the uCode.
  615. */
  616. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl4965_reply_statistics;
  617. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl4965_rx_statistics;
  618. iwl_legacy_setup_rx_scan_handlers(priv);
  619. /* status change handler */
  620. priv->rx_handlers[CARD_STATE_NOTIFICATION] =
  621. iwl4965_rx_card_state_notif;
  622. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  623. iwl4965_rx_missed_beacon_notif;
  624. /* Rx handlers */
  625. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
  626. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
  627. /* block ack */
  628. priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
  629. /* Set up hardware specific Rx handlers */
  630. priv->cfg->ops->lib->rx_handler_setup(priv);
  631. }
  632. /**
  633. * iwl4965_rx_handle - Main entry function for receiving responses from uCode
  634. *
  635. * Uses the priv->rx_handlers callback function array to invoke
  636. * the appropriate handlers, including command responses,
  637. * frame-received notifications, and other notifications.
  638. */
  639. void iwl4965_rx_handle(struct iwl_priv *priv)
  640. {
  641. struct iwl_rx_mem_buffer *rxb;
  642. struct iwl_rx_packet *pkt;
  643. struct iwl_rx_queue *rxq = &priv->rxq;
  644. u32 r, i;
  645. int reclaim;
  646. unsigned long flags;
  647. u8 fill_rx = 0;
  648. u32 count = 8;
  649. int total_empty;
  650. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  651. * buffer that the driver may process (last buffer filled by ucode). */
  652. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  653. i = rxq->read;
  654. /* Rx interrupt, but nothing sent from uCode */
  655. if (i == r)
  656. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  657. /* calculate total frames need to be restock after handling RX */
  658. total_empty = r - rxq->write_actual;
  659. if (total_empty < 0)
  660. total_empty += RX_QUEUE_SIZE;
  661. if (total_empty > (RX_QUEUE_SIZE / 2))
  662. fill_rx = 1;
  663. while (i != r) {
  664. int len;
  665. rxb = rxq->queue[i];
  666. /* If an RXB doesn't have a Rx queue slot associated with it,
  667. * then a bug has been introduced in the queue refilling
  668. * routines -- catch it here */
  669. BUG_ON(rxb == NULL);
  670. rxq->queue[i] = NULL;
  671. pci_unmap_page(priv->pci_dev, rxb->page_dma,
  672. PAGE_SIZE << priv->hw_params.rx_page_order,
  673. PCI_DMA_FROMDEVICE);
  674. pkt = rxb_addr(rxb);
  675. len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
  676. len += sizeof(u32); /* account for status word */
  677. trace_iwlwifi_legacy_dev_rx(priv, pkt, len);
  678. /* Reclaim a command buffer only if this packet is a response
  679. * to a (driver-originated) command.
  680. * If the packet (e.g. Rx frame) originated from uCode,
  681. * there is no command buffer to reclaim.
  682. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  683. * but apparently a few don't get set; catch them here. */
  684. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  685. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  686. (pkt->hdr.cmd != REPLY_RX) &&
  687. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  688. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  689. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  690. (pkt->hdr.cmd != REPLY_TX);
  691. /* Based on type of command response or notification,
  692. * handle those that need handling via function in
  693. * rx_handlers table. See iwl4965_setup_rx_handlers() */
  694. if (priv->rx_handlers[pkt->hdr.cmd]) {
  695. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
  696. i, iwl_legacy_get_cmd_string(pkt->hdr.cmd),
  697. pkt->hdr.cmd);
  698. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  699. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  700. } else {
  701. /* No handling needed */
  702. IWL_DEBUG_RX(priv,
  703. "r %d i %d No handler needed for %s, 0x%02x\n",
  704. r, i, iwl_legacy_get_cmd_string(pkt->hdr.cmd),
  705. pkt->hdr.cmd);
  706. }
  707. /*
  708. * XXX: After here, we should always check rxb->page
  709. * against NULL before touching it or its virtual
  710. * memory (pkt). Because some rx_handler might have
  711. * already taken or freed the pages.
  712. */
  713. if (reclaim) {
  714. /* Invoke any callbacks, transfer the buffer to caller,
  715. * and fire off the (possibly) blocking iwl_legacy_send_cmd()
  716. * as we reclaim the driver command queue */
  717. if (rxb->page)
  718. iwl_legacy_tx_cmd_complete(priv, rxb);
  719. else
  720. IWL_WARN(priv, "Claim null rxb?\n");
  721. }
  722. /* Reuse the page if possible. For notification packets and
  723. * SKBs that fail to Rx correctly, add them back into the
  724. * rx_free list for reuse later. */
  725. spin_lock_irqsave(&rxq->lock, flags);
  726. if (rxb->page != NULL) {
  727. rxb->page_dma = pci_map_page(priv->pci_dev, rxb->page,
  728. 0, PAGE_SIZE << priv->hw_params.rx_page_order,
  729. PCI_DMA_FROMDEVICE);
  730. list_add_tail(&rxb->list, &rxq->rx_free);
  731. rxq->free_count++;
  732. } else
  733. list_add_tail(&rxb->list, &rxq->rx_used);
  734. spin_unlock_irqrestore(&rxq->lock, flags);
  735. i = (i + 1) & RX_QUEUE_MASK;
  736. /* If there are a lot of unused frames,
  737. * restock the Rx queue so ucode wont assert. */
  738. if (fill_rx) {
  739. count++;
  740. if (count >= 8) {
  741. rxq->read = i;
  742. iwl4965_rx_replenish_now(priv);
  743. count = 0;
  744. }
  745. }
  746. }
  747. /* Backtrack one entry */
  748. rxq->read = i;
  749. if (fill_rx)
  750. iwl4965_rx_replenish_now(priv);
  751. else
  752. iwl4965_rx_queue_restock(priv);
  753. }
  754. /* call this function to flush any scheduled tasklet */
  755. static inline void iwl4965_synchronize_irq(struct iwl_priv *priv)
  756. {
  757. /* wait to make sure we flush pending tasklet*/
  758. synchronize_irq(priv->pci_dev->irq);
  759. tasklet_kill(&priv->irq_tasklet);
  760. }
  761. static void iwl4965_irq_tasklet(struct iwl_priv *priv)
  762. {
  763. u32 inta, handled = 0;
  764. u32 inta_fh;
  765. unsigned long flags;
  766. u32 i;
  767. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  768. u32 inta_mask;
  769. #endif
  770. spin_lock_irqsave(&priv->lock, flags);
  771. /* Ack/clear/reset pending uCode interrupts.
  772. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  773. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  774. inta = iwl_read32(priv, CSR_INT);
  775. iwl_write32(priv, CSR_INT, inta);
  776. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  777. * Any new interrupts that happen after this, either while we're
  778. * in this tasklet, or later, will show up in next ISR/tasklet. */
  779. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  780. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  781. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  782. if (iwl_legacy_get_debug_level(priv) & IWL_DL_ISR) {
  783. /* just for debug */
  784. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  785. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  786. inta, inta_mask, inta_fh);
  787. }
  788. #endif
  789. spin_unlock_irqrestore(&priv->lock, flags);
  790. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  791. * atomic, make sure that inta covers all the interrupts that
  792. * we've discovered, even if FH interrupt came in just after
  793. * reading CSR_INT. */
  794. if (inta_fh & CSR49_FH_INT_RX_MASK)
  795. inta |= CSR_INT_BIT_FH_RX;
  796. if (inta_fh & CSR49_FH_INT_TX_MASK)
  797. inta |= CSR_INT_BIT_FH_TX;
  798. /* Now service all interrupt bits discovered above. */
  799. if (inta & CSR_INT_BIT_HW_ERR) {
  800. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  801. /* Tell the device to stop sending interrupts */
  802. iwl_legacy_disable_interrupts(priv);
  803. priv->isr_stats.hw++;
  804. iwl_legacy_irq_handle_error(priv);
  805. handled |= CSR_INT_BIT_HW_ERR;
  806. return;
  807. }
  808. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  809. if (iwl_legacy_get_debug_level(priv) & (IWL_DL_ISR)) {
  810. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  811. if (inta & CSR_INT_BIT_SCD) {
  812. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  813. "the frame/frames.\n");
  814. priv->isr_stats.sch++;
  815. }
  816. /* Alive notification via Rx interrupt will do the real work */
  817. if (inta & CSR_INT_BIT_ALIVE) {
  818. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  819. priv->isr_stats.alive++;
  820. }
  821. }
  822. #endif
  823. /* Safely ignore these bits for debug checks below */
  824. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  825. /* HW RF KILL switch toggled */
  826. if (inta & CSR_INT_BIT_RF_KILL) {
  827. int hw_rf_kill = 0;
  828. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  829. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  830. hw_rf_kill = 1;
  831. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  832. hw_rf_kill ? "disable radio" : "enable radio");
  833. priv->isr_stats.rfkill++;
  834. /* driver only loads ucode once setting the interface up.
  835. * the driver allows loading the ucode even if the radio
  836. * is killed. Hence update the killswitch state here. The
  837. * rfkill handler will care about restarting if needed.
  838. */
  839. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  840. if (hw_rf_kill)
  841. set_bit(STATUS_RF_KILL_HW, &priv->status);
  842. else
  843. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  844. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  845. }
  846. handled |= CSR_INT_BIT_RF_KILL;
  847. }
  848. /* Chip got too hot and stopped itself */
  849. if (inta & CSR_INT_BIT_CT_KILL) {
  850. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  851. priv->isr_stats.ctkill++;
  852. handled |= CSR_INT_BIT_CT_KILL;
  853. }
  854. /* Error detected by uCode */
  855. if (inta & CSR_INT_BIT_SW_ERR) {
  856. IWL_ERR(priv, "Microcode SW error detected. "
  857. " Restarting 0x%X.\n", inta);
  858. priv->isr_stats.sw++;
  859. iwl_legacy_irq_handle_error(priv);
  860. handled |= CSR_INT_BIT_SW_ERR;
  861. }
  862. /*
  863. * uCode wakes up after power-down sleep.
  864. * Tell device about any new tx or host commands enqueued,
  865. * and about any Rx buffers made available while asleep.
  866. */
  867. if (inta & CSR_INT_BIT_WAKEUP) {
  868. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  869. iwl_legacy_rx_queue_update_write_ptr(priv, &priv->rxq);
  870. for (i = 0; i < priv->hw_params.max_txq_num; i++)
  871. iwl_legacy_txq_update_write_ptr(priv, &priv->txq[i]);
  872. priv->isr_stats.wakeup++;
  873. handled |= CSR_INT_BIT_WAKEUP;
  874. }
  875. /* All uCode command responses, including Tx command responses,
  876. * Rx "responses" (frame-received notification), and other
  877. * notifications from uCode come through here*/
  878. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  879. iwl4965_rx_handle(priv);
  880. priv->isr_stats.rx++;
  881. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  882. }
  883. /* This "Tx" DMA channel is used only for loading uCode */
  884. if (inta & CSR_INT_BIT_FH_TX) {
  885. IWL_DEBUG_ISR(priv, "uCode load interrupt\n");
  886. priv->isr_stats.tx++;
  887. handled |= CSR_INT_BIT_FH_TX;
  888. /* Wake up uCode load routine, now that load is complete */
  889. priv->ucode_write_complete = 1;
  890. wake_up_interruptible(&priv->wait_command_queue);
  891. }
  892. if (inta & ~handled) {
  893. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  894. priv->isr_stats.unhandled++;
  895. }
  896. if (inta & ~(priv->inta_mask)) {
  897. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  898. inta & ~priv->inta_mask);
  899. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  900. }
  901. /* Re-enable all interrupts */
  902. /* only Re-enable if diabled by irq */
  903. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  904. iwl_legacy_enable_interrupts(priv);
  905. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  906. if (iwl_legacy_get_debug_level(priv) & (IWL_DL_ISR)) {
  907. inta = iwl_read32(priv, CSR_INT);
  908. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  909. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  910. IWL_DEBUG_ISR(priv,
  911. "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  912. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  913. }
  914. #endif
  915. }
  916. /*****************************************************************************
  917. *
  918. * sysfs attributes
  919. *
  920. *****************************************************************************/
  921. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  922. /*
  923. * The following adds a new attribute to the sysfs representation
  924. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  925. * used for controlling the debug level.
  926. *
  927. * See the level definitions in iwl for details.
  928. *
  929. * The debug_level being managed using sysfs below is a per device debug
  930. * level that is used instead of the global debug level if it (the per
  931. * device debug level) is set.
  932. */
  933. static ssize_t iwl4965_show_debug_level(struct device *d,
  934. struct device_attribute *attr, char *buf)
  935. {
  936. struct iwl_priv *priv = dev_get_drvdata(d);
  937. return sprintf(buf, "0x%08X\n", iwl_legacy_get_debug_level(priv));
  938. }
  939. static ssize_t iwl4965_store_debug_level(struct device *d,
  940. struct device_attribute *attr,
  941. const char *buf, size_t count)
  942. {
  943. struct iwl_priv *priv = dev_get_drvdata(d);
  944. unsigned long val;
  945. int ret;
  946. ret = strict_strtoul(buf, 0, &val);
  947. if (ret)
  948. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  949. else {
  950. priv->debug_level = val;
  951. if (iwl_legacy_alloc_traffic_mem(priv))
  952. IWL_ERR(priv,
  953. "Not enough memory to generate traffic log\n");
  954. }
  955. return strnlen(buf, count);
  956. }
  957. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  958. iwl4965_show_debug_level, iwl4965_store_debug_level);
  959. #endif /* CONFIG_IWLWIFI_LEGACY_DEBUG */
  960. static ssize_t iwl4965_show_temperature(struct device *d,
  961. struct device_attribute *attr, char *buf)
  962. {
  963. struct iwl_priv *priv = dev_get_drvdata(d);
  964. if (!iwl_legacy_is_alive(priv))
  965. return -EAGAIN;
  966. return sprintf(buf, "%d\n", priv->temperature);
  967. }
  968. static DEVICE_ATTR(temperature, S_IRUGO, iwl4965_show_temperature, NULL);
  969. static ssize_t iwl4965_show_tx_power(struct device *d,
  970. struct device_attribute *attr, char *buf)
  971. {
  972. struct iwl_priv *priv = dev_get_drvdata(d);
  973. if (!iwl_legacy_is_ready_rf(priv))
  974. return sprintf(buf, "off\n");
  975. else
  976. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  977. }
  978. static ssize_t iwl4965_store_tx_power(struct device *d,
  979. struct device_attribute *attr,
  980. const char *buf, size_t count)
  981. {
  982. struct iwl_priv *priv = dev_get_drvdata(d);
  983. unsigned long val;
  984. int ret;
  985. ret = strict_strtoul(buf, 10, &val);
  986. if (ret)
  987. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  988. else {
  989. ret = iwl_legacy_set_tx_power(priv, val, false);
  990. if (ret)
  991. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  992. ret);
  993. else
  994. ret = count;
  995. }
  996. return ret;
  997. }
  998. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO,
  999. iwl4965_show_tx_power, iwl4965_store_tx_power);
  1000. static struct attribute *iwl_sysfs_entries[] = {
  1001. &dev_attr_temperature.attr,
  1002. &dev_attr_tx_power.attr,
  1003. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  1004. &dev_attr_debug_level.attr,
  1005. #endif
  1006. NULL
  1007. };
  1008. static struct attribute_group iwl_attribute_group = {
  1009. .name = NULL, /* put in device directory */
  1010. .attrs = iwl_sysfs_entries,
  1011. };
  1012. /******************************************************************************
  1013. *
  1014. * uCode download functions
  1015. *
  1016. ******************************************************************************/
  1017. static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
  1018. {
  1019. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1020. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1021. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1022. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1023. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1024. iwl_legacy_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1025. }
  1026. static void iwl4965_nic_start(struct iwl_priv *priv)
  1027. {
  1028. /* Remove all resets to allow NIC to operate */
  1029. iwl_write32(priv, CSR_RESET, 0);
  1030. }
  1031. static void iwl4965_ucode_callback(const struct firmware *ucode_raw,
  1032. void *context);
  1033. static int iwl4965_mac_setup_register(struct iwl_priv *priv,
  1034. u32 max_probe_length);
  1035. static int __must_check iwl4965_request_firmware(struct iwl_priv *priv, bool first)
  1036. {
  1037. const char *name_pre = priv->cfg->fw_name_pre;
  1038. char tag[8];
  1039. if (first) {
  1040. priv->fw_index = priv->cfg->ucode_api_max;
  1041. sprintf(tag, "%d", priv->fw_index);
  1042. } else {
  1043. priv->fw_index--;
  1044. sprintf(tag, "%d", priv->fw_index);
  1045. }
  1046. if (priv->fw_index < priv->cfg->ucode_api_min) {
  1047. IWL_ERR(priv, "no suitable firmware found!\n");
  1048. return -ENOENT;
  1049. }
  1050. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  1051. IWL_DEBUG_INFO(priv, "attempting to load firmware '%s'\n",
  1052. priv->firmware_name);
  1053. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  1054. &priv->pci_dev->dev, GFP_KERNEL, priv,
  1055. iwl4965_ucode_callback);
  1056. }
  1057. struct iwl4965_firmware_pieces {
  1058. const void *inst, *data, *init, *init_data, *boot;
  1059. size_t inst_size, data_size, init_size, init_data_size, boot_size;
  1060. };
  1061. static int iwl4965_load_firmware(struct iwl_priv *priv,
  1062. const struct firmware *ucode_raw,
  1063. struct iwl4965_firmware_pieces *pieces)
  1064. {
  1065. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  1066. u32 api_ver, hdr_size;
  1067. const u8 *src;
  1068. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1069. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1070. switch (api_ver) {
  1071. default:
  1072. case 0:
  1073. case 1:
  1074. case 2:
  1075. hdr_size = 24;
  1076. if (ucode_raw->size < hdr_size) {
  1077. IWL_ERR(priv, "File size too small!\n");
  1078. return -EINVAL;
  1079. }
  1080. pieces->inst_size = le32_to_cpu(ucode->v1.inst_size);
  1081. pieces->data_size = le32_to_cpu(ucode->v1.data_size);
  1082. pieces->init_size = le32_to_cpu(ucode->v1.init_size);
  1083. pieces->init_data_size =
  1084. le32_to_cpu(ucode->v1.init_data_size);
  1085. pieces->boot_size = le32_to_cpu(ucode->v1.boot_size);
  1086. src = ucode->v1.data;
  1087. break;
  1088. }
  1089. /* Verify size of file vs. image size info in file's header */
  1090. if (ucode_raw->size != hdr_size + pieces->inst_size +
  1091. pieces->data_size + pieces->init_size +
  1092. pieces->init_data_size + pieces->boot_size) {
  1093. IWL_ERR(priv,
  1094. "uCode file size %d does not match expected size\n",
  1095. (int)ucode_raw->size);
  1096. return -EINVAL;
  1097. }
  1098. pieces->inst = src;
  1099. src += pieces->inst_size;
  1100. pieces->data = src;
  1101. src += pieces->data_size;
  1102. pieces->init = src;
  1103. src += pieces->init_size;
  1104. pieces->init_data = src;
  1105. src += pieces->init_data_size;
  1106. pieces->boot = src;
  1107. src += pieces->boot_size;
  1108. return 0;
  1109. }
  1110. /**
  1111. * iwl4965_ucode_callback - callback when firmware was loaded
  1112. *
  1113. * If loaded successfully, copies the firmware into buffers
  1114. * for the card to fetch (via DMA).
  1115. */
  1116. static void
  1117. iwl4965_ucode_callback(const struct firmware *ucode_raw, void *context)
  1118. {
  1119. struct iwl_priv *priv = context;
  1120. struct iwl_ucode_header *ucode;
  1121. int err;
  1122. struct iwl4965_firmware_pieces pieces;
  1123. const unsigned int api_max = priv->cfg->ucode_api_max;
  1124. const unsigned int api_min = priv->cfg->ucode_api_min;
  1125. u32 api_ver;
  1126. u32 max_probe_length = 200;
  1127. u32 standard_phy_calibration_size =
  1128. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1129. memset(&pieces, 0, sizeof(pieces));
  1130. if (!ucode_raw) {
  1131. if (priv->fw_index <= priv->cfg->ucode_api_max)
  1132. IWL_ERR(priv,
  1133. "request for firmware file '%s' failed.\n",
  1134. priv->firmware_name);
  1135. goto try_again;
  1136. }
  1137. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  1138. priv->firmware_name, ucode_raw->size);
  1139. /* Make sure that we got at least the API version number */
  1140. if (ucode_raw->size < 4) {
  1141. IWL_ERR(priv, "File size way too small!\n");
  1142. goto try_again;
  1143. }
  1144. /* Data from ucode file: header followed by uCode images */
  1145. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1146. err = iwl4965_load_firmware(priv, ucode_raw, &pieces);
  1147. if (err)
  1148. goto try_again;
  1149. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1150. /*
  1151. * api_ver should match the api version forming part of the
  1152. * firmware filename ... but we don't check for that and only rely
  1153. * on the API version read from firmware header from here on forward
  1154. */
  1155. if (api_ver < api_min || api_ver > api_max) {
  1156. IWL_ERR(priv,
  1157. "Driver unable to support your firmware API. "
  1158. "Driver supports v%u, firmware is v%u.\n",
  1159. api_max, api_ver);
  1160. goto try_again;
  1161. }
  1162. if (api_ver != api_max)
  1163. IWL_ERR(priv,
  1164. "Firmware has old API version. Expected v%u, "
  1165. "got v%u. New firmware can be obtained "
  1166. "from http://www.intellinuxwireless.org.\n",
  1167. api_max, api_ver);
  1168. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  1169. IWL_UCODE_MAJOR(priv->ucode_ver),
  1170. IWL_UCODE_MINOR(priv->ucode_ver),
  1171. IWL_UCODE_API(priv->ucode_ver),
  1172. IWL_UCODE_SERIAL(priv->ucode_ver));
  1173. snprintf(priv->hw->wiphy->fw_version,
  1174. sizeof(priv->hw->wiphy->fw_version),
  1175. "%u.%u.%u.%u",
  1176. IWL_UCODE_MAJOR(priv->ucode_ver),
  1177. IWL_UCODE_MINOR(priv->ucode_ver),
  1178. IWL_UCODE_API(priv->ucode_ver),
  1179. IWL_UCODE_SERIAL(priv->ucode_ver));
  1180. /*
  1181. * For any of the failures below (before allocating pci memory)
  1182. * we will try to load a version with a smaller API -- maybe the
  1183. * user just got a corrupted version of the latest API.
  1184. */
  1185. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1186. priv->ucode_ver);
  1187. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  1188. pieces.inst_size);
  1189. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  1190. pieces.data_size);
  1191. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  1192. pieces.init_size);
  1193. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  1194. pieces.init_data_size);
  1195. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %Zd\n",
  1196. pieces.boot_size);
  1197. /* Verify that uCode images will fit in card's SRAM */
  1198. if (pieces.inst_size > priv->hw_params.max_inst_size) {
  1199. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  1200. pieces.inst_size);
  1201. goto try_again;
  1202. }
  1203. if (pieces.data_size > priv->hw_params.max_data_size) {
  1204. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  1205. pieces.data_size);
  1206. goto try_again;
  1207. }
  1208. if (pieces.init_size > priv->hw_params.max_inst_size) {
  1209. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  1210. pieces.init_size);
  1211. goto try_again;
  1212. }
  1213. if (pieces.init_data_size > priv->hw_params.max_data_size) {
  1214. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  1215. pieces.init_data_size);
  1216. goto try_again;
  1217. }
  1218. if (pieces.boot_size > priv->hw_params.max_bsm_size) {
  1219. IWL_ERR(priv, "uCode boot instr len %Zd too large to fit in\n",
  1220. pieces.boot_size);
  1221. goto try_again;
  1222. }
  1223. /* Allocate ucode buffers for card's bus-master loading ... */
  1224. /* Runtime instructions and 2 copies of data:
  1225. * 1) unmodified from disk
  1226. * 2) backup cache for save/restore during power-downs */
  1227. priv->ucode_code.len = pieces.inst_size;
  1228. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1229. priv->ucode_data.len = pieces.data_size;
  1230. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1231. priv->ucode_data_backup.len = pieces.data_size;
  1232. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1233. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  1234. !priv->ucode_data_backup.v_addr)
  1235. goto err_pci_alloc;
  1236. /* Initialization instructions and data */
  1237. if (pieces.init_size && pieces.init_data_size) {
  1238. priv->ucode_init.len = pieces.init_size;
  1239. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1240. priv->ucode_init_data.len = pieces.init_data_size;
  1241. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1242. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1243. goto err_pci_alloc;
  1244. }
  1245. /* Bootstrap (instructions only, no data) */
  1246. if (pieces.boot_size) {
  1247. priv->ucode_boot.len = pieces.boot_size;
  1248. iwl_legacy_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1249. if (!priv->ucode_boot.v_addr)
  1250. goto err_pci_alloc;
  1251. }
  1252. /* Now that we can no longer fail, copy information */
  1253. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1254. /* Copy images into buffers for card's bus-master reads ... */
  1255. /* Runtime instructions (first block of data in file) */
  1256. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n",
  1257. pieces.inst_size);
  1258. memcpy(priv->ucode_code.v_addr, pieces.inst, pieces.inst_size);
  1259. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1260. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1261. /*
  1262. * Runtime data
  1263. * NOTE: Copy into backup buffer will be done in iwl_up()
  1264. */
  1265. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n",
  1266. pieces.data_size);
  1267. memcpy(priv->ucode_data.v_addr, pieces.data, pieces.data_size);
  1268. memcpy(priv->ucode_data_backup.v_addr, pieces.data, pieces.data_size);
  1269. /* Initialization instructions */
  1270. if (pieces.init_size) {
  1271. IWL_DEBUG_INFO(priv,
  1272. "Copying (but not loading) init instr len %Zd\n",
  1273. pieces.init_size);
  1274. memcpy(priv->ucode_init.v_addr, pieces.init, pieces.init_size);
  1275. }
  1276. /* Initialization data */
  1277. if (pieces.init_data_size) {
  1278. IWL_DEBUG_INFO(priv,
  1279. "Copying (but not loading) init data len %Zd\n",
  1280. pieces.init_data_size);
  1281. memcpy(priv->ucode_init_data.v_addr, pieces.init_data,
  1282. pieces.init_data_size);
  1283. }
  1284. /* Bootstrap instructions */
  1285. IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n",
  1286. pieces.boot_size);
  1287. memcpy(priv->ucode_boot.v_addr, pieces.boot, pieces.boot_size);
  1288. /*
  1289. * figure out the offset of chain noise reset and gain commands
  1290. * base on the size of standard phy calibration commands table size
  1291. */
  1292. priv->_4965.phy_calib_chain_noise_reset_cmd =
  1293. standard_phy_calibration_size;
  1294. priv->_4965.phy_calib_chain_noise_gain_cmd =
  1295. standard_phy_calibration_size + 1;
  1296. /**************************************************
  1297. * This is still part of probe() in a sense...
  1298. *
  1299. * 9. Setup and register with mac80211 and debugfs
  1300. **************************************************/
  1301. err = iwl4965_mac_setup_register(priv, max_probe_length);
  1302. if (err)
  1303. goto out_unbind;
  1304. err = iwl_legacy_dbgfs_register(priv, DRV_NAME);
  1305. if (err)
  1306. IWL_ERR(priv,
  1307. "failed to create debugfs files. Ignoring error: %d\n", err);
  1308. err = sysfs_create_group(&priv->pci_dev->dev.kobj,
  1309. &iwl_attribute_group);
  1310. if (err) {
  1311. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  1312. goto out_unbind;
  1313. }
  1314. /* We have our copies now, allow OS release its copies */
  1315. release_firmware(ucode_raw);
  1316. complete(&priv->_4965.firmware_loading_complete);
  1317. return;
  1318. try_again:
  1319. /* try next, if any */
  1320. if (iwl4965_request_firmware(priv, false))
  1321. goto out_unbind;
  1322. release_firmware(ucode_raw);
  1323. return;
  1324. err_pci_alloc:
  1325. IWL_ERR(priv, "failed to allocate pci memory\n");
  1326. iwl4965_dealloc_ucode_pci(priv);
  1327. out_unbind:
  1328. complete(&priv->_4965.firmware_loading_complete);
  1329. device_release_driver(&priv->pci_dev->dev);
  1330. release_firmware(ucode_raw);
  1331. }
  1332. static const char * const desc_lookup_text[] = {
  1333. "OK",
  1334. "FAIL",
  1335. "BAD_PARAM",
  1336. "BAD_CHECKSUM",
  1337. "NMI_INTERRUPT_WDG",
  1338. "SYSASSERT",
  1339. "FATAL_ERROR",
  1340. "BAD_COMMAND",
  1341. "HW_ERROR_TUNE_LOCK",
  1342. "HW_ERROR_TEMPERATURE",
  1343. "ILLEGAL_CHAN_FREQ",
  1344. "VCC_NOT_STABLE",
  1345. "FH_ERROR",
  1346. "NMI_INTERRUPT_HOST",
  1347. "NMI_INTERRUPT_ACTION_PT",
  1348. "NMI_INTERRUPT_UNKNOWN",
  1349. "UCODE_VERSION_MISMATCH",
  1350. "HW_ERROR_ABS_LOCK",
  1351. "HW_ERROR_CAL_LOCK_FAIL",
  1352. "NMI_INTERRUPT_INST_ACTION_PT",
  1353. "NMI_INTERRUPT_DATA_ACTION_PT",
  1354. "NMI_TRM_HW_ER",
  1355. "NMI_INTERRUPT_TRM",
  1356. "NMI_INTERRUPT_BREAK_POINT"
  1357. "DEBUG_0",
  1358. "DEBUG_1",
  1359. "DEBUG_2",
  1360. "DEBUG_3",
  1361. };
  1362. static struct { char *name; u8 num; } advanced_lookup[] = {
  1363. { "NMI_INTERRUPT_WDG", 0x34 },
  1364. { "SYSASSERT", 0x35 },
  1365. { "UCODE_VERSION_MISMATCH", 0x37 },
  1366. { "BAD_COMMAND", 0x38 },
  1367. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1368. { "FATAL_ERROR", 0x3D },
  1369. { "NMI_TRM_HW_ERR", 0x46 },
  1370. { "NMI_INTERRUPT_TRM", 0x4C },
  1371. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1372. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1373. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1374. { "NMI_INTERRUPT_HOST", 0x66 },
  1375. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1376. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1377. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1378. { "ADVANCED_SYSASSERT", 0 },
  1379. };
  1380. static const char *iwl4965_desc_lookup(u32 num)
  1381. {
  1382. int i;
  1383. int max = ARRAY_SIZE(desc_lookup_text);
  1384. if (num < max)
  1385. return desc_lookup_text[num];
  1386. max = ARRAY_SIZE(advanced_lookup) - 1;
  1387. for (i = 0; i < max; i++) {
  1388. if (advanced_lookup[i].num == num)
  1389. break;
  1390. }
  1391. return advanced_lookup[i].name;
  1392. }
  1393. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1394. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1395. void iwl4965_dump_nic_error_log(struct iwl_priv *priv)
  1396. {
  1397. u32 data2, line;
  1398. u32 desc, time, count, base, data1;
  1399. u32 blink1, blink2, ilink1, ilink2;
  1400. u32 pc, hcmd;
  1401. if (priv->ucode_type == UCODE_INIT) {
  1402. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  1403. } else {
  1404. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1405. }
  1406. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1407. IWL_ERR(priv,
  1408. "Not valid error log pointer 0x%08X for %s uCode\n",
  1409. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  1410. return;
  1411. }
  1412. count = iwl_legacy_read_targ_mem(priv, base);
  1413. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1414. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1415. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1416. priv->status, count);
  1417. }
  1418. desc = iwl_legacy_read_targ_mem(priv, base + 1 * sizeof(u32));
  1419. priv->isr_stats.err_code = desc;
  1420. pc = iwl_legacy_read_targ_mem(priv, base + 2 * sizeof(u32));
  1421. blink1 = iwl_legacy_read_targ_mem(priv, base + 3 * sizeof(u32));
  1422. blink2 = iwl_legacy_read_targ_mem(priv, base + 4 * sizeof(u32));
  1423. ilink1 = iwl_legacy_read_targ_mem(priv, base + 5 * sizeof(u32));
  1424. ilink2 = iwl_legacy_read_targ_mem(priv, base + 6 * sizeof(u32));
  1425. data1 = iwl_legacy_read_targ_mem(priv, base + 7 * sizeof(u32));
  1426. data2 = iwl_legacy_read_targ_mem(priv, base + 8 * sizeof(u32));
  1427. line = iwl_legacy_read_targ_mem(priv, base + 9 * sizeof(u32));
  1428. time = iwl_legacy_read_targ_mem(priv, base + 11 * sizeof(u32));
  1429. hcmd = iwl_legacy_read_targ_mem(priv, base + 22 * sizeof(u32));
  1430. trace_iwlwifi_legacy_dev_ucode_error(priv, desc,
  1431. time, data1, data2, line,
  1432. blink1, blink2, ilink1, ilink2);
  1433. IWL_ERR(priv, "Desc Time "
  1434. "data1 data2 line\n");
  1435. IWL_ERR(priv, "%-28s (0x%04X) %010u 0x%08X 0x%08X %u\n",
  1436. iwl4965_desc_lookup(desc), desc, time, data1, data2, line);
  1437. IWL_ERR(priv, "pc blink1 blink2 ilink1 ilink2 hcmd\n");
  1438. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X 0x%05X 0x%05X\n",
  1439. pc, blink1, blink2, ilink1, ilink2, hcmd);
  1440. }
  1441. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1442. /**
  1443. * iwl4965_print_event_log - Dump error event log to syslog
  1444. *
  1445. */
  1446. static int iwl4965_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1447. u32 num_events, u32 mode,
  1448. int pos, char **buf, size_t bufsz)
  1449. {
  1450. u32 i;
  1451. u32 base; /* SRAM byte address of event log header */
  1452. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1453. u32 ptr; /* SRAM byte address of log data */
  1454. u32 ev, time, data; /* event log data */
  1455. unsigned long reg_flags;
  1456. if (num_events == 0)
  1457. return pos;
  1458. if (priv->ucode_type == UCODE_INIT) {
  1459. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1460. } else {
  1461. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1462. }
  1463. if (mode == 0)
  1464. event_size = 2 * sizeof(u32);
  1465. else
  1466. event_size = 3 * sizeof(u32);
  1467. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1468. /* Make sure device is powered up for SRAM reads */
  1469. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1470. iwl_grab_nic_access(priv);
  1471. /* Set starting address; reads will auto-increment */
  1472. _iwl_legacy_write_direct32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1473. rmb();
  1474. /* "time" is actually "data" for mode 0 (no timestamp).
  1475. * place event id # at far right for easier visual parsing. */
  1476. for (i = 0; i < num_events; i++) {
  1477. ev = _iwl_legacy_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1478. time = _iwl_legacy_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1479. if (mode == 0) {
  1480. /* data, ev */
  1481. if (bufsz) {
  1482. pos += scnprintf(*buf + pos, bufsz - pos,
  1483. "EVT_LOG:0x%08x:%04u\n",
  1484. time, ev);
  1485. } else {
  1486. trace_iwlwifi_legacy_dev_ucode_event(priv, 0,
  1487. time, ev);
  1488. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1489. time, ev);
  1490. }
  1491. } else {
  1492. data = _iwl_legacy_read_direct32(priv,
  1493. HBUS_TARG_MEM_RDAT);
  1494. if (bufsz) {
  1495. pos += scnprintf(*buf + pos, bufsz - pos,
  1496. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1497. time, data, ev);
  1498. } else {
  1499. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1500. time, data, ev);
  1501. trace_iwlwifi_legacy_dev_ucode_event(priv, time,
  1502. data, ev);
  1503. }
  1504. }
  1505. }
  1506. /* Allow device to power down */
  1507. iwl_release_nic_access(priv);
  1508. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1509. return pos;
  1510. }
  1511. /**
  1512. * iwl4965_print_last_event_logs - Dump the newest # of event log to syslog
  1513. */
  1514. static int iwl4965_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1515. u32 num_wraps, u32 next_entry,
  1516. u32 size, u32 mode,
  1517. int pos, char **buf, size_t bufsz)
  1518. {
  1519. /*
  1520. * display the newest DEFAULT_LOG_ENTRIES entries
  1521. * i.e the entries just before the next ont that uCode would fill.
  1522. */
  1523. if (num_wraps) {
  1524. if (next_entry < size) {
  1525. pos = iwl4965_print_event_log(priv,
  1526. capacity - (size - next_entry),
  1527. size - next_entry, mode,
  1528. pos, buf, bufsz);
  1529. pos = iwl4965_print_event_log(priv, 0,
  1530. next_entry, mode,
  1531. pos, buf, bufsz);
  1532. } else
  1533. pos = iwl4965_print_event_log(priv, next_entry - size,
  1534. size, mode, pos, buf, bufsz);
  1535. } else {
  1536. if (next_entry < size) {
  1537. pos = iwl4965_print_event_log(priv, 0, next_entry,
  1538. mode, pos, buf, bufsz);
  1539. } else {
  1540. pos = iwl4965_print_event_log(priv, next_entry - size,
  1541. size, mode, pos, buf, bufsz);
  1542. }
  1543. }
  1544. return pos;
  1545. }
  1546. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1547. int iwl4965_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1548. char **buf, bool display)
  1549. {
  1550. u32 base; /* SRAM byte address of event log header */
  1551. u32 capacity; /* event log capacity in # entries */
  1552. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1553. u32 num_wraps; /* # times uCode wrapped to top of log */
  1554. u32 next_entry; /* index of next entry to be written by uCode */
  1555. u32 size; /* # entries that we'll print */
  1556. int pos = 0;
  1557. size_t bufsz = 0;
  1558. if (priv->ucode_type == UCODE_INIT) {
  1559. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1560. } else {
  1561. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1562. }
  1563. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1564. IWL_ERR(priv,
  1565. "Invalid event log pointer 0x%08X for %s uCode\n",
  1566. base, (priv->ucode_type == UCODE_INIT) ? "Init" : "RT");
  1567. return -EINVAL;
  1568. }
  1569. /* event log header */
  1570. capacity = iwl_legacy_read_targ_mem(priv, base);
  1571. mode = iwl_legacy_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1572. num_wraps = iwl_legacy_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1573. next_entry = iwl_legacy_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1574. size = num_wraps ? capacity : next_entry;
  1575. /* bail out if nothing in log */
  1576. if (size == 0) {
  1577. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1578. return pos;
  1579. }
  1580. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  1581. if (!(iwl_legacy_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1582. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1583. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1584. #else
  1585. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1586. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1587. #endif
  1588. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1589. size);
  1590. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  1591. if (display) {
  1592. if (full_log)
  1593. bufsz = capacity * 48;
  1594. else
  1595. bufsz = size * 48;
  1596. *buf = kmalloc(bufsz, GFP_KERNEL);
  1597. if (!*buf)
  1598. return -ENOMEM;
  1599. }
  1600. if ((iwl_legacy_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1601. /*
  1602. * if uCode has wrapped back to top of log,
  1603. * start at the oldest entry,
  1604. * i.e the next one that uCode would fill.
  1605. */
  1606. if (num_wraps)
  1607. pos = iwl4965_print_event_log(priv, next_entry,
  1608. capacity - next_entry, mode,
  1609. pos, buf, bufsz);
  1610. /* (then/else) start at top of log */
  1611. pos = iwl4965_print_event_log(priv, 0,
  1612. next_entry, mode, pos, buf, bufsz);
  1613. } else
  1614. pos = iwl4965_print_last_event_logs(priv, capacity, num_wraps,
  1615. next_entry, size, mode,
  1616. pos, buf, bufsz);
  1617. #else
  1618. pos = iwl4965_print_last_event_logs(priv, capacity, num_wraps,
  1619. next_entry, size, mode,
  1620. pos, buf, bufsz);
  1621. #endif
  1622. return pos;
  1623. }
  1624. static void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
  1625. {
  1626. struct iwl_ct_kill_config cmd;
  1627. unsigned long flags;
  1628. int ret = 0;
  1629. spin_lock_irqsave(&priv->lock, flags);
  1630. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1631. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1632. spin_unlock_irqrestore(&priv->lock, flags);
  1633. cmd.critical_temperature_R =
  1634. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1635. ret = iwl_legacy_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1636. sizeof(cmd), &cmd);
  1637. if (ret)
  1638. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1639. else
  1640. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1641. "succeeded, "
  1642. "critical temperature is %d\n",
  1643. priv->hw_params.ct_kill_threshold);
  1644. }
  1645. static const s8 default_queue_to_tx_fifo[] = {
  1646. IWL_TX_FIFO_VO,
  1647. IWL_TX_FIFO_VI,
  1648. IWL_TX_FIFO_BE,
  1649. IWL_TX_FIFO_BK,
  1650. IWL49_CMD_FIFO_NUM,
  1651. IWL_TX_FIFO_UNUSED,
  1652. IWL_TX_FIFO_UNUSED,
  1653. };
  1654. static int iwl4965_alive_notify(struct iwl_priv *priv)
  1655. {
  1656. u32 a;
  1657. unsigned long flags;
  1658. int i, chan;
  1659. u32 reg_val;
  1660. spin_lock_irqsave(&priv->lock, flags);
  1661. /* Clear 4965's internal Tx Scheduler data base */
  1662. priv->scd_base_addr = iwl_legacy_read_prph(priv,
  1663. IWL49_SCD_SRAM_BASE_ADDR);
  1664. a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
  1665. for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
  1666. iwl_legacy_write_targ_mem(priv, a, 0);
  1667. for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
  1668. iwl_legacy_write_targ_mem(priv, a, 0);
  1669. for (; a < priv->scd_base_addr +
  1670. IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(priv->hw_params.max_txq_num); a += 4)
  1671. iwl_legacy_write_targ_mem(priv, a, 0);
  1672. /* Tel 4965 where to find Tx byte count tables */
  1673. iwl_legacy_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
  1674. priv->scd_bc_tbls.dma >> 10);
  1675. /* Enable DMA channel */
  1676. for (chan = 0; chan < FH49_TCSR_CHNL_NUM ; chan++)
  1677. iwl_legacy_write_direct32(priv,
  1678. FH_TCSR_CHNL_TX_CONFIG_REG(chan),
  1679. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
  1680. FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE);
  1681. /* Update FH chicken bits */
  1682. reg_val = iwl_legacy_read_direct32(priv, FH_TX_CHICKEN_BITS_REG);
  1683. iwl_legacy_write_direct32(priv, FH_TX_CHICKEN_BITS_REG,
  1684. reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
  1685. /* Disable chain mode for all queues */
  1686. iwl_legacy_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
  1687. /* Initialize each Tx queue (including the command queue) */
  1688. for (i = 0; i < priv->hw_params.max_txq_num; i++) {
  1689. /* TFD circular buffer read/write indexes */
  1690. iwl_legacy_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
  1691. iwl_legacy_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
  1692. /* Max Tx Window size for Scheduler-ACK mode */
  1693. iwl_legacy_write_targ_mem(priv, priv->scd_base_addr +
  1694. IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
  1695. (SCD_WIN_SIZE <<
  1696. IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
  1697. IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
  1698. /* Frame limit */
  1699. iwl_legacy_write_targ_mem(priv, priv->scd_base_addr +
  1700. IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
  1701. sizeof(u32),
  1702. (SCD_FRAME_LIMIT <<
  1703. IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
  1704. IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
  1705. }
  1706. iwl_legacy_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
  1707. (1 << priv->hw_params.max_txq_num) - 1);
  1708. /* Activate all Tx DMA/FIFO channels */
  1709. iwl4965_txq_set_sched(priv, IWL_MASK(0, 6));
  1710. iwl4965_set_wr_ptrs(priv, IWL_DEFAULT_CMD_QUEUE_NUM, 0);
  1711. /* make sure all queue are not stopped */
  1712. memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
  1713. for (i = 0; i < 4; i++)
  1714. atomic_set(&priv->queue_stop_count[i], 0);
  1715. /* reset to 0 to enable all the queue first */
  1716. priv->txq_ctx_active_msk = 0;
  1717. /* Map each Tx/cmd queue to its corresponding fifo */
  1718. BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
  1719. for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
  1720. int ac = default_queue_to_tx_fifo[i];
  1721. iwl_txq_ctx_activate(priv, i);
  1722. if (ac == IWL_TX_FIFO_UNUSED)
  1723. continue;
  1724. iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
  1725. }
  1726. spin_unlock_irqrestore(&priv->lock, flags);
  1727. return 0;
  1728. }
  1729. /**
  1730. * iwl4965_alive_start - called after REPLY_ALIVE notification received
  1731. * from protocol/runtime uCode (initialization uCode's
  1732. * Alive gets handled by iwl_init_alive_start()).
  1733. */
  1734. static void iwl4965_alive_start(struct iwl_priv *priv)
  1735. {
  1736. int ret = 0;
  1737. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1738. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1739. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  1740. /* We had an error bringing up the hardware, so take it
  1741. * all the way back down so we can try again */
  1742. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  1743. goto restart;
  1744. }
  1745. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  1746. * This is a paranoid check, because we would not have gotten the
  1747. * "runtime" alive if code weren't properly loaded. */
  1748. if (iwl4965_verify_ucode(priv)) {
  1749. /* Runtime instruction load was bad;
  1750. * take it all the way back down so we can try again */
  1751. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  1752. goto restart;
  1753. }
  1754. ret = iwl4965_alive_notify(priv);
  1755. if (ret) {
  1756. IWL_WARN(priv,
  1757. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  1758. goto restart;
  1759. }
  1760. /* After the ALIVE response, we can send host commands to the uCode */
  1761. set_bit(STATUS_ALIVE, &priv->status);
  1762. /* Enable watchdog to monitor the driver tx queues */
  1763. iwl_legacy_setup_watchdog(priv);
  1764. if (iwl_legacy_is_rfkill(priv))
  1765. return;
  1766. ieee80211_wake_queues(priv->hw);
  1767. priv->active_rate = IWL_RATES_MASK;
  1768. if (iwl_legacy_is_associated_ctx(ctx)) {
  1769. struct iwl_legacy_rxon_cmd *active_rxon =
  1770. (struct iwl_legacy_rxon_cmd *)&ctx->active;
  1771. /* apply any changes in staging */
  1772. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1773. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1774. } else {
  1775. struct iwl_rxon_context *tmp;
  1776. /* Initialize our rx_config data */
  1777. for_each_context(priv, tmp)
  1778. iwl_legacy_connection_init_rx_config(priv, tmp);
  1779. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1780. priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
  1781. }
  1782. /* Configure bluetooth coexistence if enabled */
  1783. iwl_legacy_send_bt_config(priv);
  1784. iwl4965_reset_run_time_calib(priv);
  1785. set_bit(STATUS_READY, &priv->status);
  1786. /* Configure the adapter for unassociated operation */
  1787. iwl_legacy_commit_rxon(priv, ctx);
  1788. /* At this point, the NIC is initialized and operational */
  1789. iwl4965_rf_kill_ct_config(priv);
  1790. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1791. wake_up_interruptible(&priv->wait_command_queue);
  1792. iwl_legacy_power_update_mode(priv, true);
  1793. IWL_DEBUG_INFO(priv, "Updated power mode\n");
  1794. return;
  1795. restart:
  1796. queue_work(priv->workqueue, &priv->restart);
  1797. }
  1798. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv);
  1799. static void __iwl4965_down(struct iwl_priv *priv)
  1800. {
  1801. unsigned long flags;
  1802. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  1803. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1804. iwl_legacy_scan_cancel_timeout(priv, 200);
  1805. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  1806. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1807. * to prevent rearm timer */
  1808. del_timer_sync(&priv->watchdog);
  1809. iwl_legacy_clear_ucode_stations(priv, NULL);
  1810. iwl_legacy_dealloc_bcast_stations(priv);
  1811. iwl_legacy_clear_driver_stations(priv);
  1812. /* Unblock any waiting calls */
  1813. wake_up_interruptible_all(&priv->wait_command_queue);
  1814. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1815. * exiting the module */
  1816. if (!exit_pending)
  1817. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1818. /* stop and reset the on-board processor */
  1819. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1820. /* tell the device to stop sending interrupts */
  1821. spin_lock_irqsave(&priv->lock, flags);
  1822. iwl_legacy_disable_interrupts(priv);
  1823. spin_unlock_irqrestore(&priv->lock, flags);
  1824. iwl4965_synchronize_irq(priv);
  1825. if (priv->mac80211_registered)
  1826. ieee80211_stop_queues(priv->hw);
  1827. /* If we have not previously called iwl_init() then
  1828. * clear all bits but the RF Kill bit and return */
  1829. if (!iwl_legacy_is_init(priv)) {
  1830. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1831. STATUS_RF_KILL_HW |
  1832. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1833. STATUS_GEO_CONFIGURED |
  1834. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  1835. STATUS_EXIT_PENDING;
  1836. goto exit;
  1837. }
  1838. /* ...otherwise clear out all the status bits but the RF Kill
  1839. * bit and continue taking the NIC down. */
  1840. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1841. STATUS_RF_KILL_HW |
  1842. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1843. STATUS_GEO_CONFIGURED |
  1844. test_bit(STATUS_FW_ERROR, &priv->status) <<
  1845. STATUS_FW_ERROR |
  1846. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  1847. STATUS_EXIT_PENDING;
  1848. iwl4965_txq_ctx_stop(priv);
  1849. iwl4965_rxq_stop(priv);
  1850. /* Power-down device's busmaster DMA clocks */
  1851. iwl_legacy_write_prph(priv, APMG_CLK_DIS_REG, APMG_CLK_VAL_DMA_CLK_RQT);
  1852. udelay(5);
  1853. /* Make sure (redundant) we've released our request to stay awake */
  1854. iwl_legacy_clear_bit(priv, CSR_GP_CNTRL,
  1855. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1856. /* Stop the device, and put it in low power state */
  1857. iwl_legacy_apm_stop(priv);
  1858. exit:
  1859. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  1860. dev_kfree_skb(priv->beacon_skb);
  1861. priv->beacon_skb = NULL;
  1862. /* clear out any free frames */
  1863. iwl4965_clear_free_frames(priv);
  1864. }
  1865. static void iwl4965_down(struct iwl_priv *priv)
  1866. {
  1867. mutex_lock(&priv->mutex);
  1868. __iwl4965_down(priv);
  1869. mutex_unlock(&priv->mutex);
  1870. iwl4965_cancel_deferred_work(priv);
  1871. }
  1872. #define HW_READY_TIMEOUT (50)
  1873. static int iwl4965_set_hw_ready(struct iwl_priv *priv)
  1874. {
  1875. int ret = 0;
  1876. iwl_legacy_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1877. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  1878. /* See if we got it */
  1879. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  1880. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1881. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1882. HW_READY_TIMEOUT);
  1883. if (ret != -ETIMEDOUT)
  1884. priv->hw_ready = true;
  1885. else
  1886. priv->hw_ready = false;
  1887. IWL_DEBUG_INFO(priv, "hardware %s\n",
  1888. (priv->hw_ready == 1) ? "ready" : "not ready");
  1889. return ret;
  1890. }
  1891. static int iwl4965_prepare_card_hw(struct iwl_priv *priv)
  1892. {
  1893. int ret = 0;
  1894. IWL_DEBUG_INFO(priv, "iwl4965_prepare_card_hw enter\n");
  1895. ret = iwl4965_set_hw_ready(priv);
  1896. if (priv->hw_ready)
  1897. return ret;
  1898. /* If HW is not ready, prepare the conditions to check again */
  1899. iwl_legacy_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1900. CSR_HW_IF_CONFIG_REG_PREPARE);
  1901. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  1902. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  1903. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  1904. /* HW should be ready by now, check again. */
  1905. if (ret != -ETIMEDOUT)
  1906. iwl4965_set_hw_ready(priv);
  1907. return ret;
  1908. }
  1909. #define MAX_HW_RESTARTS 5
  1910. static int __iwl4965_up(struct iwl_priv *priv)
  1911. {
  1912. struct iwl_rxon_context *ctx;
  1913. int i;
  1914. int ret;
  1915. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1916. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  1917. return -EIO;
  1918. }
  1919. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  1920. IWL_ERR(priv, "ucode not available for device bringup\n");
  1921. return -EIO;
  1922. }
  1923. for_each_context(priv, ctx) {
  1924. ret = iwl4965_alloc_bcast_station(priv, ctx);
  1925. if (ret) {
  1926. iwl_legacy_dealloc_bcast_stations(priv);
  1927. return ret;
  1928. }
  1929. }
  1930. iwl4965_prepare_card_hw(priv);
  1931. if (!priv->hw_ready) {
  1932. IWL_WARN(priv, "Exit HW not ready\n");
  1933. return -EIO;
  1934. }
  1935. /* If platform's RF_KILL switch is NOT set to KILL */
  1936. if (iwl_read32(priv,
  1937. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1938. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1939. else
  1940. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1941. if (iwl_legacy_is_rfkill(priv)) {
  1942. wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
  1943. iwl_legacy_enable_interrupts(priv);
  1944. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  1945. return 0;
  1946. }
  1947. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1948. /* must be initialised before iwl_hw_nic_init */
  1949. priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1950. ret = iwl4965_hw_nic_init(priv);
  1951. if (ret) {
  1952. IWL_ERR(priv, "Unable to init nic\n");
  1953. return ret;
  1954. }
  1955. /* make sure rfkill handshake bits are cleared */
  1956. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1957. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1958. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1959. /* clear (again), then enable host interrupts */
  1960. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1961. iwl_legacy_enable_interrupts(priv);
  1962. /* really make sure rfkill handshake bits are cleared */
  1963. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1964. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1965. /* Copy original ucode data image from disk into backup cache.
  1966. * This will be used to initialize the on-board processor's
  1967. * data SRAM for a clean start when the runtime program first loads. */
  1968. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  1969. priv->ucode_data.len);
  1970. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  1971. /* load bootstrap state machine,
  1972. * load bootstrap program into processor's memory,
  1973. * prepare to load the "initialize" uCode */
  1974. ret = priv->cfg->ops->lib->load_ucode(priv);
  1975. if (ret) {
  1976. IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
  1977. ret);
  1978. continue;
  1979. }
  1980. /* start card; "initialize" will load runtime ucode */
  1981. iwl4965_nic_start(priv);
  1982. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  1983. return 0;
  1984. }
  1985. set_bit(STATUS_EXIT_PENDING, &priv->status);
  1986. __iwl4965_down(priv);
  1987. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1988. /* tried to restart and config the device for as long as our
  1989. * patience could withstand */
  1990. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  1991. return -EIO;
  1992. }
  1993. /*****************************************************************************
  1994. *
  1995. * Workqueue callbacks
  1996. *
  1997. *****************************************************************************/
  1998. static void iwl4965_bg_init_alive_start(struct work_struct *data)
  1999. {
  2000. struct iwl_priv *priv =
  2001. container_of(data, struct iwl_priv, init_alive_start.work);
  2002. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2003. return;
  2004. mutex_lock(&priv->mutex);
  2005. priv->cfg->ops->lib->init_alive_start(priv);
  2006. mutex_unlock(&priv->mutex);
  2007. }
  2008. static void iwl4965_bg_alive_start(struct work_struct *data)
  2009. {
  2010. struct iwl_priv *priv =
  2011. container_of(data, struct iwl_priv, alive_start.work);
  2012. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2013. return;
  2014. mutex_lock(&priv->mutex);
  2015. iwl4965_alive_start(priv);
  2016. mutex_unlock(&priv->mutex);
  2017. }
  2018. static void iwl4965_bg_run_time_calib_work(struct work_struct *work)
  2019. {
  2020. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2021. run_time_calib_work);
  2022. mutex_lock(&priv->mutex);
  2023. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2024. test_bit(STATUS_SCANNING, &priv->status)) {
  2025. mutex_unlock(&priv->mutex);
  2026. return;
  2027. }
  2028. if (priv->start_calib) {
  2029. iwl4965_chain_noise_calibration(priv,
  2030. (void *)&priv->_4965.statistics);
  2031. iwl4965_sensitivity_calibration(priv,
  2032. (void *)&priv->_4965.statistics);
  2033. }
  2034. mutex_unlock(&priv->mutex);
  2035. }
  2036. static void iwl4965_bg_restart(struct work_struct *data)
  2037. {
  2038. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  2039. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2040. return;
  2041. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  2042. struct iwl_rxon_context *ctx;
  2043. mutex_lock(&priv->mutex);
  2044. for_each_context(priv, ctx)
  2045. ctx->vif = NULL;
  2046. priv->is_open = 0;
  2047. __iwl4965_down(priv);
  2048. mutex_unlock(&priv->mutex);
  2049. iwl4965_cancel_deferred_work(priv);
  2050. ieee80211_restart_hw(priv->hw);
  2051. } else {
  2052. iwl4965_down(priv);
  2053. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2054. return;
  2055. mutex_lock(&priv->mutex);
  2056. __iwl4965_up(priv);
  2057. mutex_unlock(&priv->mutex);
  2058. }
  2059. }
  2060. static void iwl4965_bg_rx_replenish(struct work_struct *data)
  2061. {
  2062. struct iwl_priv *priv =
  2063. container_of(data, struct iwl_priv, rx_replenish);
  2064. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2065. return;
  2066. mutex_lock(&priv->mutex);
  2067. iwl4965_rx_replenish(priv);
  2068. mutex_unlock(&priv->mutex);
  2069. }
  2070. /*****************************************************************************
  2071. *
  2072. * mac80211 entry point functions
  2073. *
  2074. *****************************************************************************/
  2075. #define UCODE_READY_TIMEOUT (4 * HZ)
  2076. /*
  2077. * Not a mac80211 entry point function, but it fits in with all the
  2078. * other mac80211 functions grouped here.
  2079. */
  2080. static int iwl4965_mac_setup_register(struct iwl_priv *priv,
  2081. u32 max_probe_length)
  2082. {
  2083. int ret;
  2084. struct ieee80211_hw *hw = priv->hw;
  2085. struct iwl_rxon_context *ctx;
  2086. hw->rate_control_algorithm = "iwl-4965-rs";
  2087. /* Tell mac80211 our characteristics */
  2088. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  2089. IEEE80211_HW_AMPDU_AGGREGATION |
  2090. IEEE80211_HW_NEED_DTIM_PERIOD |
  2091. IEEE80211_HW_SPECTRUM_MGMT |
  2092. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  2093. if (priv->cfg->sku & IWL_SKU_N)
  2094. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  2095. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  2096. hw->sta_data_size = sizeof(struct iwl_station_priv);
  2097. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  2098. for_each_context(priv, ctx) {
  2099. hw->wiphy->interface_modes |= ctx->interface_modes;
  2100. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  2101. }
  2102. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  2103. WIPHY_FLAG_DISABLE_BEACON_HINTS;
  2104. /*
  2105. * For now, disable PS by default because it affects
  2106. * RX performance significantly.
  2107. */
  2108. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  2109. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  2110. /* we create the 802.11 header and a zero-length SSID element */
  2111. hw->wiphy->max_scan_ie_len = max_probe_length - 24 - 2;
  2112. /* Default value; 4 EDCA QOS priorities */
  2113. hw->queues = 4;
  2114. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  2115. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  2116. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  2117. &priv->bands[IEEE80211_BAND_2GHZ];
  2118. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  2119. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  2120. &priv->bands[IEEE80211_BAND_5GHZ];
  2121. iwl_legacy_leds_init(priv);
  2122. ret = ieee80211_register_hw(priv->hw);
  2123. if (ret) {
  2124. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  2125. return ret;
  2126. }
  2127. priv->mac80211_registered = 1;
  2128. return 0;
  2129. }
  2130. int iwl4965_mac_start(struct ieee80211_hw *hw)
  2131. {
  2132. struct iwl_priv *priv = hw->priv;
  2133. int ret;
  2134. IWL_DEBUG_MAC80211(priv, "enter\n");
  2135. /* we should be verifying the device is ready to be opened */
  2136. mutex_lock(&priv->mutex);
  2137. ret = __iwl4965_up(priv);
  2138. mutex_unlock(&priv->mutex);
  2139. if (ret)
  2140. return ret;
  2141. if (iwl_legacy_is_rfkill(priv))
  2142. goto out;
  2143. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  2144. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  2145. * mac80211 will not be run successfully. */
  2146. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  2147. test_bit(STATUS_READY, &priv->status),
  2148. UCODE_READY_TIMEOUT);
  2149. if (!ret) {
  2150. if (!test_bit(STATUS_READY, &priv->status)) {
  2151. IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
  2152. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  2153. return -ETIMEDOUT;
  2154. }
  2155. }
  2156. iwl4965_led_enable(priv);
  2157. out:
  2158. priv->is_open = 1;
  2159. IWL_DEBUG_MAC80211(priv, "leave\n");
  2160. return 0;
  2161. }
  2162. void iwl4965_mac_stop(struct ieee80211_hw *hw)
  2163. {
  2164. struct iwl_priv *priv = hw->priv;
  2165. IWL_DEBUG_MAC80211(priv, "enter\n");
  2166. if (!priv->is_open)
  2167. return;
  2168. priv->is_open = 0;
  2169. iwl4965_down(priv);
  2170. flush_workqueue(priv->workqueue);
  2171. /* enable interrupts again in order to receive rfkill changes */
  2172. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  2173. iwl_legacy_enable_interrupts(priv);
  2174. IWL_DEBUG_MAC80211(priv, "leave\n");
  2175. }
  2176. void iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2177. {
  2178. struct iwl_priv *priv = hw->priv;
  2179. IWL_DEBUG_MACDUMP(priv, "enter\n");
  2180. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2181. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2182. if (iwl4965_tx_skb(priv, skb))
  2183. dev_kfree_skb_any(skb);
  2184. IWL_DEBUG_MACDUMP(priv, "leave\n");
  2185. }
  2186. void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
  2187. struct ieee80211_vif *vif,
  2188. struct ieee80211_key_conf *keyconf,
  2189. struct ieee80211_sta *sta,
  2190. u32 iv32, u16 *phase1key)
  2191. {
  2192. struct iwl_priv *priv = hw->priv;
  2193. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2194. IWL_DEBUG_MAC80211(priv, "enter\n");
  2195. iwl4965_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
  2196. iv32, phase1key);
  2197. IWL_DEBUG_MAC80211(priv, "leave\n");
  2198. }
  2199. int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2200. struct ieee80211_vif *vif, struct ieee80211_sta *sta,
  2201. struct ieee80211_key_conf *key)
  2202. {
  2203. struct iwl_priv *priv = hw->priv;
  2204. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2205. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2206. int ret;
  2207. u8 sta_id;
  2208. bool is_default_wep_key = false;
  2209. IWL_DEBUG_MAC80211(priv, "enter\n");
  2210. if (priv->cfg->mod_params->sw_crypto) {
  2211. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2212. return -EOPNOTSUPP;
  2213. }
  2214. sta_id = iwl_legacy_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
  2215. if (sta_id == IWL_INVALID_STATION)
  2216. return -EINVAL;
  2217. mutex_lock(&priv->mutex);
  2218. iwl_legacy_scan_cancel_timeout(priv, 100);
  2219. /*
  2220. * If we are getting WEP group key and we didn't receive any key mapping
  2221. * so far, we are in legacy wep mode (group key only), otherwise we are
  2222. * in 1X mode.
  2223. * In legacy wep mode, we use another host command to the uCode.
  2224. */
  2225. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2226. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  2227. !sta) {
  2228. if (cmd == SET_KEY)
  2229. is_default_wep_key = !ctx->key_mapping_keys;
  2230. else
  2231. is_default_wep_key =
  2232. (key->hw_key_idx == HW_KEY_DEFAULT);
  2233. }
  2234. switch (cmd) {
  2235. case SET_KEY:
  2236. if (is_default_wep_key)
  2237. ret = iwl4965_set_default_wep_key(priv,
  2238. vif_priv->ctx, key);
  2239. else
  2240. ret = iwl4965_set_dynamic_key(priv, vif_priv->ctx,
  2241. key, sta_id);
  2242. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2243. break;
  2244. case DISABLE_KEY:
  2245. if (is_default_wep_key)
  2246. ret = iwl4965_remove_default_wep_key(priv, ctx, key);
  2247. else
  2248. ret = iwl4965_remove_dynamic_key(priv, ctx,
  2249. key, sta_id);
  2250. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2251. break;
  2252. default:
  2253. ret = -EINVAL;
  2254. }
  2255. mutex_unlock(&priv->mutex);
  2256. IWL_DEBUG_MAC80211(priv, "leave\n");
  2257. return ret;
  2258. }
  2259. int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
  2260. struct ieee80211_vif *vif,
  2261. enum ieee80211_ampdu_mlme_action action,
  2262. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  2263. u8 buf_size)
  2264. {
  2265. struct iwl_priv *priv = hw->priv;
  2266. int ret = -EINVAL;
  2267. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2268. sta->addr, tid);
  2269. if (!(priv->cfg->sku & IWL_SKU_N))
  2270. return -EACCES;
  2271. mutex_lock(&priv->mutex);
  2272. switch (action) {
  2273. case IEEE80211_AMPDU_RX_START:
  2274. IWL_DEBUG_HT(priv, "start Rx\n");
  2275. ret = iwl4965_sta_rx_agg_start(priv, sta, tid, *ssn);
  2276. break;
  2277. case IEEE80211_AMPDU_RX_STOP:
  2278. IWL_DEBUG_HT(priv, "stop Rx\n");
  2279. ret = iwl4965_sta_rx_agg_stop(priv, sta, tid);
  2280. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2281. ret = 0;
  2282. break;
  2283. case IEEE80211_AMPDU_TX_START:
  2284. IWL_DEBUG_HT(priv, "start Tx\n");
  2285. ret = iwl4965_tx_agg_start(priv, vif, sta, tid, ssn);
  2286. if (ret == 0) {
  2287. priv->_4965.agg_tids_count++;
  2288. IWL_DEBUG_HT(priv, "priv->_4965.agg_tids_count = %u\n",
  2289. priv->_4965.agg_tids_count);
  2290. }
  2291. break;
  2292. case IEEE80211_AMPDU_TX_STOP:
  2293. IWL_DEBUG_HT(priv, "stop Tx\n");
  2294. ret = iwl4965_tx_agg_stop(priv, vif, sta, tid);
  2295. if ((ret == 0) && (priv->_4965.agg_tids_count > 0)) {
  2296. priv->_4965.agg_tids_count--;
  2297. IWL_DEBUG_HT(priv, "priv->_4965.agg_tids_count = %u\n",
  2298. priv->_4965.agg_tids_count);
  2299. }
  2300. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2301. ret = 0;
  2302. break;
  2303. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2304. ret = 0;
  2305. break;
  2306. }
  2307. mutex_unlock(&priv->mutex);
  2308. return ret;
  2309. }
  2310. int iwl4965_mac_sta_add(struct ieee80211_hw *hw,
  2311. struct ieee80211_vif *vif,
  2312. struct ieee80211_sta *sta)
  2313. {
  2314. struct iwl_priv *priv = hw->priv;
  2315. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  2316. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2317. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2318. int ret;
  2319. u8 sta_id;
  2320. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2321. sta->addr);
  2322. mutex_lock(&priv->mutex);
  2323. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2324. sta->addr);
  2325. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2326. atomic_set(&sta_priv->pending_frames, 0);
  2327. ret = iwl_legacy_add_station_common(priv, vif_priv->ctx, sta->addr,
  2328. is_ap, sta, &sta_id);
  2329. if (ret) {
  2330. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2331. sta->addr, ret);
  2332. /* Should we return success if return code is EEXIST ? */
  2333. mutex_unlock(&priv->mutex);
  2334. return ret;
  2335. }
  2336. sta_priv->common.sta_id = sta_id;
  2337. /* Initialize rate scaling */
  2338. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2339. sta->addr);
  2340. iwl4965_rs_rate_init(priv, sta, sta_id);
  2341. mutex_unlock(&priv->mutex);
  2342. return 0;
  2343. }
  2344. void iwl4965_mac_channel_switch(struct ieee80211_hw *hw,
  2345. struct ieee80211_channel_switch *ch_switch)
  2346. {
  2347. struct iwl_priv *priv = hw->priv;
  2348. const struct iwl_channel_info *ch_info;
  2349. struct ieee80211_conf *conf = &hw->conf;
  2350. struct ieee80211_channel *channel = ch_switch->channel;
  2351. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  2352. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2353. u16 ch;
  2354. unsigned long flags = 0;
  2355. IWL_DEBUG_MAC80211(priv, "enter\n");
  2356. if (iwl_legacy_is_rfkill(priv))
  2357. goto out_exit;
  2358. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2359. test_bit(STATUS_SCANNING, &priv->status))
  2360. goto out_exit;
  2361. if (!iwl_legacy_is_associated_ctx(ctx))
  2362. goto out_exit;
  2363. /* channel switch in progress */
  2364. if (priv->switch_rxon.switch_in_progress == true)
  2365. goto out_exit;
  2366. mutex_lock(&priv->mutex);
  2367. if (priv->cfg->ops->lib->set_channel_switch) {
  2368. ch = channel->hw_value;
  2369. if (le16_to_cpu(ctx->active.channel) != ch) {
  2370. ch_info = iwl_legacy_get_channel_info(priv,
  2371. channel->band,
  2372. ch);
  2373. if (!iwl_legacy_is_channel_valid(ch_info)) {
  2374. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  2375. goto out;
  2376. }
  2377. spin_lock_irqsave(&priv->lock, flags);
  2378. priv->current_ht_config.smps = conf->smps_mode;
  2379. /* Configure HT40 channels */
  2380. ctx->ht.enabled = conf_is_ht(conf);
  2381. if (ctx->ht.enabled) {
  2382. if (conf_is_ht40_minus(conf)) {
  2383. ctx->ht.extension_chan_offset =
  2384. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2385. ctx->ht.is_40mhz = true;
  2386. } else if (conf_is_ht40_plus(conf)) {
  2387. ctx->ht.extension_chan_offset =
  2388. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2389. ctx->ht.is_40mhz = true;
  2390. } else {
  2391. ctx->ht.extension_chan_offset =
  2392. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2393. ctx->ht.is_40mhz = false;
  2394. }
  2395. } else
  2396. ctx->ht.is_40mhz = false;
  2397. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2398. ctx->staging.flags = 0;
  2399. iwl_legacy_set_rxon_channel(priv, channel, ctx);
  2400. iwl_legacy_set_rxon_ht(priv, ht_conf);
  2401. iwl_legacy_set_flags_for_band(priv, ctx, channel->band,
  2402. ctx->vif);
  2403. spin_unlock_irqrestore(&priv->lock, flags);
  2404. iwl_legacy_set_rate(priv);
  2405. /*
  2406. * at this point, staging_rxon has the
  2407. * configuration for channel switch
  2408. */
  2409. if (priv->cfg->ops->lib->set_channel_switch(priv,
  2410. ch_switch))
  2411. priv->switch_rxon.switch_in_progress = false;
  2412. }
  2413. }
  2414. out:
  2415. mutex_unlock(&priv->mutex);
  2416. out_exit:
  2417. if (!priv->switch_rxon.switch_in_progress)
  2418. ieee80211_chswitch_done(ctx->vif, false);
  2419. IWL_DEBUG_MAC80211(priv, "leave\n");
  2420. }
  2421. void iwl4965_configure_filter(struct ieee80211_hw *hw,
  2422. unsigned int changed_flags,
  2423. unsigned int *total_flags,
  2424. u64 multicast)
  2425. {
  2426. struct iwl_priv *priv = hw->priv;
  2427. __le32 filter_or = 0, filter_nand = 0;
  2428. struct iwl_rxon_context *ctx;
  2429. #define CHK(test, flag) do { \
  2430. if (*total_flags & (test)) \
  2431. filter_or |= (flag); \
  2432. else \
  2433. filter_nand |= (flag); \
  2434. } while (0)
  2435. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2436. changed_flags, *total_flags);
  2437. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2438. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2439. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2440. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2441. #undef CHK
  2442. mutex_lock(&priv->mutex);
  2443. for_each_context(priv, ctx) {
  2444. ctx->staging.filter_flags &= ~filter_nand;
  2445. ctx->staging.filter_flags |= filter_or;
  2446. /*
  2447. * Not committing directly because hardware can perform a scan,
  2448. * but we'll eventually commit the filter flags change anyway.
  2449. */
  2450. }
  2451. mutex_unlock(&priv->mutex);
  2452. /*
  2453. * Receiving all multicast frames is always enabled by the
  2454. * default flags setup in iwl_legacy_connection_init_rx_config()
  2455. * since we currently do not support programming multicast
  2456. * filters into the device.
  2457. */
  2458. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2459. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2460. }
  2461. /*****************************************************************************
  2462. *
  2463. * driver setup and teardown
  2464. *
  2465. *****************************************************************************/
  2466. static void iwl4965_bg_txpower_work(struct work_struct *work)
  2467. {
  2468. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2469. txpower_work);
  2470. /* If a scan happened to start before we got here
  2471. * then just return; the statistics notification will
  2472. * kick off another scheduled work to compensate for
  2473. * any temperature delta we missed here. */
  2474. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2475. test_bit(STATUS_SCANNING, &priv->status))
  2476. return;
  2477. mutex_lock(&priv->mutex);
  2478. /* Regardless of if we are associated, we must reconfigure the
  2479. * TX power since frames can be sent on non-radar channels while
  2480. * not associated */
  2481. priv->cfg->ops->lib->send_tx_power(priv);
  2482. /* Update last_temperature to keep is_calib_needed from running
  2483. * when it isn't needed... */
  2484. priv->last_temperature = priv->temperature;
  2485. mutex_unlock(&priv->mutex);
  2486. }
  2487. static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
  2488. {
  2489. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  2490. init_waitqueue_head(&priv->wait_command_queue);
  2491. INIT_WORK(&priv->restart, iwl4965_bg_restart);
  2492. INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
  2493. INIT_WORK(&priv->run_time_calib_work, iwl4965_bg_run_time_calib_work);
  2494. INIT_DELAYED_WORK(&priv->init_alive_start, iwl4965_bg_init_alive_start);
  2495. INIT_DELAYED_WORK(&priv->alive_start, iwl4965_bg_alive_start);
  2496. iwl_legacy_setup_scan_deferred_work(priv);
  2497. INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
  2498. init_timer(&priv->statistics_periodic);
  2499. priv->statistics_periodic.data = (unsigned long)priv;
  2500. priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
  2501. init_timer(&priv->ucode_trace);
  2502. priv->ucode_trace.data = (unsigned long)priv;
  2503. priv->ucode_trace.function = iwl4965_bg_ucode_trace;
  2504. init_timer(&priv->watchdog);
  2505. priv->watchdog.data = (unsigned long)priv;
  2506. priv->watchdog.function = iwl_legacy_bg_watchdog;
  2507. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  2508. iwl4965_irq_tasklet, (unsigned long)priv);
  2509. }
  2510. static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
  2511. {
  2512. cancel_work_sync(&priv->txpower_work);
  2513. cancel_delayed_work_sync(&priv->init_alive_start);
  2514. cancel_delayed_work(&priv->alive_start);
  2515. cancel_work_sync(&priv->run_time_calib_work);
  2516. iwl_legacy_cancel_scan_deferred_work(priv);
  2517. del_timer_sync(&priv->statistics_periodic);
  2518. del_timer_sync(&priv->ucode_trace);
  2519. }
  2520. static void iwl4965_init_hw_rates(struct iwl_priv *priv,
  2521. struct ieee80211_rate *rates)
  2522. {
  2523. int i;
  2524. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  2525. rates[i].bitrate = iwlegacy_rates[i].ieee * 5;
  2526. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2527. rates[i].hw_value_short = i;
  2528. rates[i].flags = 0;
  2529. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  2530. /*
  2531. * If CCK != 1M then set short preamble rate flag.
  2532. */
  2533. rates[i].flags |=
  2534. (iwlegacy_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  2535. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2536. }
  2537. }
  2538. }
  2539. /*
  2540. * Acquire priv->lock before calling this function !
  2541. */
  2542. void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
  2543. {
  2544. iwl_legacy_write_direct32(priv, HBUS_TARG_WRPTR,
  2545. (index & 0xff) | (txq_id << 8));
  2546. iwl_legacy_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
  2547. }
  2548. void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
  2549. struct iwl_tx_queue *txq,
  2550. int tx_fifo_id, int scd_retry)
  2551. {
  2552. int txq_id = txq->q.id;
  2553. /* Find out whether to activate Tx queue */
  2554. int active = test_bit(txq_id, &priv->txq_ctx_active_msk) ? 1 : 0;
  2555. /* Set up and activate */
  2556. iwl_legacy_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
  2557. (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
  2558. (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
  2559. (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
  2560. (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
  2561. IWL49_SCD_QUEUE_STTS_REG_MSK);
  2562. txq->sched_retry = scd_retry;
  2563. IWL_DEBUG_INFO(priv, "%s %s Queue %d on AC %d\n",
  2564. active ? "Activate" : "Deactivate",
  2565. scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
  2566. }
  2567. static int iwl4965_init_drv(struct iwl_priv *priv)
  2568. {
  2569. int ret;
  2570. spin_lock_init(&priv->sta_lock);
  2571. spin_lock_init(&priv->hcmd_lock);
  2572. INIT_LIST_HEAD(&priv->free_frames);
  2573. mutex_init(&priv->mutex);
  2574. mutex_init(&priv->sync_cmd_mutex);
  2575. priv->ieee_channels = NULL;
  2576. priv->ieee_rates = NULL;
  2577. priv->band = IEEE80211_BAND_2GHZ;
  2578. priv->iw_mode = NL80211_IFTYPE_STATION;
  2579. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2580. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  2581. priv->_4965.agg_tids_count = 0;
  2582. /* initialize force reset */
  2583. priv->force_reset[IWL_RF_RESET].reset_duration =
  2584. IWL_DELAY_NEXT_FORCE_RF_RESET;
  2585. priv->force_reset[IWL_FW_RESET].reset_duration =
  2586. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  2587. /* Choose which receivers/antennas to use */
  2588. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2589. priv->cfg->ops->hcmd->set_rxon_chain(priv,
  2590. &priv->contexts[IWL_RXON_CTX_BSS]);
  2591. iwl_legacy_init_scan_params(priv);
  2592. /* Set the tx_power_user_lmt to the lowest power level
  2593. * this value will get overwritten by channel max power avg
  2594. * from eeprom */
  2595. priv->tx_power_user_lmt = IWL4965_TX_POWER_TARGET_POWER_MIN;
  2596. priv->tx_power_next = IWL4965_TX_POWER_TARGET_POWER_MIN;
  2597. ret = iwl_legacy_init_channel_map(priv);
  2598. if (ret) {
  2599. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  2600. goto err;
  2601. }
  2602. ret = iwl_legacy_init_geos(priv);
  2603. if (ret) {
  2604. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  2605. goto err_free_channel_map;
  2606. }
  2607. iwl4965_init_hw_rates(priv, priv->ieee_rates);
  2608. return 0;
  2609. err_free_channel_map:
  2610. iwl_legacy_free_channel_map(priv);
  2611. err:
  2612. return ret;
  2613. }
  2614. static void iwl4965_uninit_drv(struct iwl_priv *priv)
  2615. {
  2616. iwl4965_calib_free_results(priv);
  2617. iwl_legacy_free_geos(priv);
  2618. iwl_legacy_free_channel_map(priv);
  2619. kfree(priv->scan_cmd);
  2620. }
  2621. static void iwl4965_hw_detect(struct iwl_priv *priv)
  2622. {
  2623. priv->hw_rev = _iwl_legacy_read32(priv, CSR_HW_REV);
  2624. priv->hw_wa_rev = _iwl_legacy_read32(priv, CSR_HW_REV_WA_REG);
  2625. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  2626. IWL_DEBUG_INFO(priv, "HW Revision ID = 0x%X\n", priv->rev_id);
  2627. }
  2628. static int iwl4965_set_hw_params(struct iwl_priv *priv)
  2629. {
  2630. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  2631. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2632. if (priv->cfg->mod_params->amsdu_size_8K)
  2633. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
  2634. else
  2635. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
  2636. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  2637. if (priv->cfg->mod_params->disable_11n)
  2638. priv->cfg->sku &= ~IWL_SKU_N;
  2639. /* Device-specific setup */
  2640. return priv->cfg->ops->lib->set_hw_params(priv);
  2641. }
  2642. static const u8 iwl4965_bss_ac_to_fifo[] = {
  2643. IWL_TX_FIFO_VO,
  2644. IWL_TX_FIFO_VI,
  2645. IWL_TX_FIFO_BE,
  2646. IWL_TX_FIFO_BK,
  2647. };
  2648. static const u8 iwl4965_bss_ac_to_queue[] = {
  2649. 0, 1, 2, 3,
  2650. };
  2651. static int
  2652. iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2653. {
  2654. int err = 0, i;
  2655. struct iwl_priv *priv;
  2656. struct ieee80211_hw *hw;
  2657. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  2658. unsigned long flags;
  2659. u16 pci_cmd;
  2660. /************************
  2661. * 1. Allocating HW data
  2662. ************************/
  2663. hw = iwl_legacy_alloc_all(cfg);
  2664. if (!hw) {
  2665. err = -ENOMEM;
  2666. goto out;
  2667. }
  2668. priv = hw->priv;
  2669. /* At this point both hw and priv are allocated. */
  2670. /*
  2671. * The default context is always valid,
  2672. * more may be discovered when firmware
  2673. * is loaded.
  2674. */
  2675. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  2676. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  2677. priv->contexts[i].ctxid = i;
  2678. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  2679. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  2680. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  2681. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  2682. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  2683. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  2684. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  2685. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  2686. priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwl4965_bss_ac_to_fifo;
  2687. priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwl4965_bss_ac_to_queue;
  2688. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  2689. BIT(NL80211_IFTYPE_ADHOC);
  2690. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  2691. BIT(NL80211_IFTYPE_STATION);
  2692. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  2693. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  2694. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  2695. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  2696. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 1);
  2697. SET_IEEE80211_DEV(hw, &pdev->dev);
  2698. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  2699. priv->cfg = cfg;
  2700. priv->pci_dev = pdev;
  2701. priv->inta_mask = CSR_INI_SET_MASK;
  2702. if (iwl_legacy_alloc_traffic_mem(priv))
  2703. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  2704. /**************************
  2705. * 2. Initializing PCI bus
  2706. **************************/
  2707. pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 |
  2708. PCIE_LINK_STATE_CLKPM);
  2709. if (pci_enable_device(pdev)) {
  2710. err = -ENODEV;
  2711. goto out_ieee80211_free_hw;
  2712. }
  2713. pci_set_master(pdev);
  2714. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  2715. if (!err)
  2716. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  2717. if (err) {
  2718. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2719. if (!err)
  2720. err = pci_set_consistent_dma_mask(pdev,
  2721. DMA_BIT_MASK(32));
  2722. /* both attempts failed: */
  2723. if (err) {
  2724. IWL_WARN(priv, "No suitable DMA available.\n");
  2725. goto out_pci_disable_device;
  2726. }
  2727. }
  2728. err = pci_request_regions(pdev, DRV_NAME);
  2729. if (err)
  2730. goto out_pci_disable_device;
  2731. pci_set_drvdata(pdev, priv);
  2732. /***********************
  2733. * 3. Read REV register
  2734. ***********************/
  2735. priv->hw_base = pci_iomap(pdev, 0, 0);
  2736. if (!priv->hw_base) {
  2737. err = -ENODEV;
  2738. goto out_pci_release_regions;
  2739. }
  2740. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  2741. (unsigned long long) pci_resource_len(pdev, 0));
  2742. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  2743. /* these spin locks will be used in apm_ops.init and EEPROM access
  2744. * we should init now
  2745. */
  2746. spin_lock_init(&priv->reg_lock);
  2747. spin_lock_init(&priv->lock);
  2748. /*
  2749. * stop and reset the on-board processor just in case it is in a
  2750. * strange state ... like being left stranded by a primary kernel
  2751. * and this is now the kdump kernel trying to start up
  2752. */
  2753. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  2754. iwl4965_hw_detect(priv);
  2755. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  2756. priv->cfg->name, priv->hw_rev);
  2757. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  2758. * PCI Tx retries from interfering with C3 CPU state */
  2759. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2760. iwl4965_prepare_card_hw(priv);
  2761. if (!priv->hw_ready) {
  2762. IWL_WARN(priv, "Failed, HW not ready\n");
  2763. goto out_iounmap;
  2764. }
  2765. /*****************
  2766. * 4. Read EEPROM
  2767. *****************/
  2768. /* Read the EEPROM */
  2769. err = iwl_legacy_eeprom_init(priv);
  2770. if (err) {
  2771. IWL_ERR(priv, "Unable to init EEPROM\n");
  2772. goto out_iounmap;
  2773. }
  2774. err = iwl4965_eeprom_check_version(priv);
  2775. if (err)
  2776. goto out_free_eeprom;
  2777. if (err)
  2778. goto out_free_eeprom;
  2779. /* extract MAC Address */
  2780. iwl4965_eeprom_get_mac(priv, priv->addresses[0].addr);
  2781. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  2782. priv->hw->wiphy->addresses = priv->addresses;
  2783. priv->hw->wiphy->n_addresses = 1;
  2784. /************************
  2785. * 5. Setup HW constants
  2786. ************************/
  2787. if (iwl4965_set_hw_params(priv)) {
  2788. IWL_ERR(priv, "failed to set hw parameters\n");
  2789. goto out_free_eeprom;
  2790. }
  2791. /*******************
  2792. * 6. Setup priv
  2793. *******************/
  2794. err = iwl4965_init_drv(priv);
  2795. if (err)
  2796. goto out_free_eeprom;
  2797. /* At this point both hw and priv are initialized. */
  2798. /********************
  2799. * 7. Setup services
  2800. ********************/
  2801. spin_lock_irqsave(&priv->lock, flags);
  2802. iwl_legacy_disable_interrupts(priv);
  2803. spin_unlock_irqrestore(&priv->lock, flags);
  2804. pci_enable_msi(priv->pci_dev);
  2805. err = request_irq(priv->pci_dev->irq, iwl_legacy_isr,
  2806. IRQF_SHARED, DRV_NAME, priv);
  2807. if (err) {
  2808. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  2809. goto out_disable_msi;
  2810. }
  2811. iwl4965_setup_deferred_work(priv);
  2812. iwl4965_setup_rx_handlers(priv);
  2813. /*********************************************
  2814. * 8. Enable interrupts and read RFKILL state
  2815. *********************************************/
  2816. /* enable interrupts if needed: hw bug w/a */
  2817. pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
  2818. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  2819. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  2820. pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
  2821. }
  2822. iwl_legacy_enable_interrupts(priv);
  2823. /* If platform's RF_KILL switch is NOT set to KILL */
  2824. if (iwl_read32(priv, CSR_GP_CNTRL) &
  2825. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2826. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2827. else
  2828. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2829. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  2830. test_bit(STATUS_RF_KILL_HW, &priv->status));
  2831. iwl_legacy_power_initialize(priv);
  2832. init_completion(&priv->_4965.firmware_loading_complete);
  2833. err = iwl4965_request_firmware(priv, true);
  2834. if (err)
  2835. goto out_destroy_workqueue;
  2836. return 0;
  2837. out_destroy_workqueue:
  2838. destroy_workqueue(priv->workqueue);
  2839. priv->workqueue = NULL;
  2840. free_irq(priv->pci_dev->irq, priv);
  2841. out_disable_msi:
  2842. pci_disable_msi(priv->pci_dev);
  2843. iwl4965_uninit_drv(priv);
  2844. out_free_eeprom:
  2845. iwl_legacy_eeprom_free(priv);
  2846. out_iounmap:
  2847. pci_iounmap(pdev, priv->hw_base);
  2848. out_pci_release_regions:
  2849. pci_set_drvdata(pdev, NULL);
  2850. pci_release_regions(pdev);
  2851. out_pci_disable_device:
  2852. pci_disable_device(pdev);
  2853. out_ieee80211_free_hw:
  2854. iwl_legacy_free_traffic_mem(priv);
  2855. ieee80211_free_hw(priv->hw);
  2856. out:
  2857. return err;
  2858. }
  2859. static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
  2860. {
  2861. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2862. unsigned long flags;
  2863. if (!priv)
  2864. return;
  2865. wait_for_completion(&priv->_4965.firmware_loading_complete);
  2866. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  2867. iwl_legacy_dbgfs_unregister(priv);
  2868. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  2869. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  2870. * to be called and iwl4965_down since we are removing the device
  2871. * we need to set STATUS_EXIT_PENDING bit.
  2872. */
  2873. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2874. iwl_legacy_leds_exit(priv);
  2875. if (priv->mac80211_registered) {
  2876. ieee80211_unregister_hw(priv->hw);
  2877. priv->mac80211_registered = 0;
  2878. } else {
  2879. iwl4965_down(priv);
  2880. }
  2881. /*
  2882. * Make sure device is reset to low power before unloading driver.
  2883. * This may be redundant with iwl4965_down(), but there are paths to
  2884. * run iwl4965_down() without calling apm_ops.stop(), and there are
  2885. * paths to avoid running iwl4965_down() at all before leaving driver.
  2886. * This (inexpensive) call *makes sure* device is reset.
  2887. */
  2888. iwl_legacy_apm_stop(priv);
  2889. /* make sure we flush any pending irq or
  2890. * tasklet for the driver
  2891. */
  2892. spin_lock_irqsave(&priv->lock, flags);
  2893. iwl_legacy_disable_interrupts(priv);
  2894. spin_unlock_irqrestore(&priv->lock, flags);
  2895. iwl4965_synchronize_irq(priv);
  2896. iwl4965_dealloc_ucode_pci(priv);
  2897. if (priv->rxq.bd)
  2898. iwl4965_rx_queue_free(priv, &priv->rxq);
  2899. iwl4965_hw_txq_ctx_free(priv);
  2900. iwl_legacy_eeprom_free(priv);
  2901. /*netif_stop_queue(dev); */
  2902. flush_workqueue(priv->workqueue);
  2903. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  2904. * priv->workqueue... so we can't take down the workqueue
  2905. * until now... */
  2906. destroy_workqueue(priv->workqueue);
  2907. priv->workqueue = NULL;
  2908. iwl_legacy_free_traffic_mem(priv);
  2909. free_irq(priv->pci_dev->irq, priv);
  2910. pci_disable_msi(priv->pci_dev);
  2911. pci_iounmap(pdev, priv->hw_base);
  2912. pci_release_regions(pdev);
  2913. pci_disable_device(pdev);
  2914. pci_set_drvdata(pdev, NULL);
  2915. iwl4965_uninit_drv(priv);
  2916. dev_kfree_skb(priv->beacon_skb);
  2917. ieee80211_free_hw(priv->hw);
  2918. }
  2919. /*
  2920. * Activate/Deactivate Tx DMA/FIFO channels according tx fifos mask
  2921. * must be called under priv->lock and mac access
  2922. */
  2923. void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
  2924. {
  2925. iwl_legacy_write_prph(priv, IWL49_SCD_TXFACT, mask);
  2926. }
  2927. /*****************************************************************************
  2928. *
  2929. * driver and module entry point
  2930. *
  2931. *****************************************************************************/
  2932. /* Hardware specific file defines the PCI IDs table for that hardware module */
  2933. static DEFINE_PCI_DEVICE_TABLE(iwl4965_hw_card_ids) = {
  2934. #if defined(CONFIG_IWL4965_MODULE) || defined(CONFIG_IWL4965)
  2935. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_cfg)},
  2936. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_cfg)},
  2937. #endif /* CONFIG_IWL4965 */
  2938. {0}
  2939. };
  2940. MODULE_DEVICE_TABLE(pci, iwl4965_hw_card_ids);
  2941. static struct pci_driver iwl4965_driver = {
  2942. .name = DRV_NAME,
  2943. .id_table = iwl4965_hw_card_ids,
  2944. .probe = iwl4965_pci_probe,
  2945. .remove = __devexit_p(iwl4965_pci_remove),
  2946. .driver.pm = IWL_LEGACY_PM_OPS,
  2947. };
  2948. static int __init iwl4965_init(void)
  2949. {
  2950. int ret;
  2951. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  2952. pr_info(DRV_COPYRIGHT "\n");
  2953. ret = iwl4965_rate_control_register();
  2954. if (ret) {
  2955. pr_err("Unable to register rate control algorithm: %d\n", ret);
  2956. return ret;
  2957. }
  2958. ret = pci_register_driver(&iwl4965_driver);
  2959. if (ret) {
  2960. pr_err("Unable to initialize PCI module\n");
  2961. goto error_register;
  2962. }
  2963. return ret;
  2964. error_register:
  2965. iwl4965_rate_control_unregister();
  2966. return ret;
  2967. }
  2968. static void __exit iwl4965_exit(void)
  2969. {
  2970. pci_unregister_driver(&iwl4965_driver);
  2971. iwl4965_rate_control_unregister();
  2972. }
  2973. module_exit(iwl4965_exit);
  2974. module_init(iwl4965_init);
  2975. #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
  2976. module_param_named(debug, iwlegacy_debug_level, uint, S_IRUGO | S_IWUSR);
  2977. MODULE_PARM_DESC(debug, "debug output mask");
  2978. #endif
  2979. module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, S_IRUGO);
  2980. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  2981. module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, S_IRUGO);
  2982. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  2983. module_param_named(11n_disable, iwl4965_mod_params.disable_11n, int, S_IRUGO);
  2984. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  2985. module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K,
  2986. int, S_IRUGO);
  2987. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  2988. module_param_named(fw_restart, iwl4965_mod_params.restart_fw, int, S_IRUGO);
  2989. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");