iwl-agn.c 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2009 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. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/pci.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #define DRV_NAME "iwlagn"
  45. #include "iwl-eeprom.h"
  46. #include "iwl-dev.h"
  47. #include "iwl-core.h"
  48. #include "iwl-io.h"
  49. #include "iwl-helpers.h"
  50. #include "iwl-sta.h"
  51. #include "iwl-calib.h"
  52. /******************************************************************************
  53. *
  54. * module boiler plate
  55. *
  56. ******************************************************************************/
  57. /*
  58. * module name, copyright, version, etc.
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #ifdef CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT
  67. #define VS "s"
  68. #else
  69. #define VS
  70. #endif
  71. #define DRV_VERSION IWLWIFI_VERSION VD VS
  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. /*************** STATION TABLE MANAGEMENT ****
  78. * mac80211 should be examined to determine if sta_info is duplicating
  79. * the functionality provided here
  80. */
  81. /**************************************************************/
  82. /**
  83. * iwl_commit_rxon - commit staging_rxon to hardware
  84. *
  85. * The RXON command in staging_rxon is committed to the hardware and
  86. * the active_rxon structure is updated with the new data. This
  87. * function correctly transitions out of the RXON_ASSOC_MSK state if
  88. * a HW tune is required based on the RXON structure changes.
  89. */
  90. int iwl_commit_rxon(struct iwl_priv *priv)
  91. {
  92. /* cast away the const for active_rxon in this function */
  93. struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
  94. int ret;
  95. bool new_assoc =
  96. !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
  97. if (!iwl_is_alive(priv))
  98. return -EBUSY;
  99. /* always get timestamp with Rx frame */
  100. priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
  101. ret = iwl_check_rxon_cmd(priv);
  102. if (ret) {
  103. IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
  104. return -EINVAL;
  105. }
  106. /* If we don't need to send a full RXON, we can use
  107. * iwl_rxon_assoc_cmd which is used to reconfigure filter
  108. * and other flags for the current radio configuration. */
  109. if (!iwl_full_rxon_required(priv)) {
  110. ret = iwl_send_rxon_assoc(priv);
  111. if (ret) {
  112. IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
  113. return ret;
  114. }
  115. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  116. return 0;
  117. }
  118. /* station table will be cleared */
  119. priv->assoc_station_added = 0;
  120. /* If we are currently associated and the new config requires
  121. * an RXON_ASSOC and the new config wants the associated mask enabled,
  122. * we must clear the associated from the active configuration
  123. * before we apply the new config */
  124. if (iwl_is_associated(priv) && new_assoc) {
  125. IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
  126. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  127. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  128. sizeof(struct iwl_rxon_cmd),
  129. &priv->active_rxon);
  130. /* If the mask clearing failed then we set
  131. * active_rxon back to what it was previously */
  132. if (ret) {
  133. active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
  134. IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
  135. return ret;
  136. }
  137. }
  138. IWL_DEBUG_INFO(priv, "Sending RXON\n"
  139. "* with%s RXON_FILTER_ASSOC_MSK\n"
  140. "* channel = %d\n"
  141. "* bssid = %pM\n",
  142. (new_assoc ? "" : "out"),
  143. le16_to_cpu(priv->staging_rxon.channel),
  144. priv->staging_rxon.bssid_addr);
  145. iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto);
  146. /* Apply the new configuration
  147. * RXON unassoc clears the station table in uCode, send it before
  148. * we add the bcast station. If assoc bit is set, we will send RXON
  149. * after having added the bcast and bssid station.
  150. */
  151. if (!new_assoc) {
  152. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  153. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  154. if (ret) {
  155. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  156. return ret;
  157. }
  158. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  159. }
  160. iwl_clear_stations_table(priv);
  161. priv->start_calib = 0;
  162. /* Add the broadcast address so we can send broadcast frames */
  163. if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
  164. IWL_INVALID_STATION) {
  165. IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
  166. return -EIO;
  167. }
  168. /* If we have set the ASSOC_MSK and we are in BSS mode then
  169. * add the IWL_AP_ID to the station rate table */
  170. if (new_assoc) {
  171. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  172. ret = iwl_rxon_add_station(priv,
  173. priv->active_rxon.bssid_addr, 1);
  174. if (ret == IWL_INVALID_STATION) {
  175. IWL_ERR(priv,
  176. "Error adding AP address for TX.\n");
  177. return -EIO;
  178. }
  179. priv->assoc_station_added = 1;
  180. if (priv->default_wep_key &&
  181. iwl_send_static_wepkey_cmd(priv, 0))
  182. IWL_ERR(priv,
  183. "Could not send WEP static key.\n");
  184. }
  185. /*
  186. * allow CTS-to-self if possible for new association.
  187. * this is relevant only for 5000 series and up,
  188. * but will not damage 4965
  189. */
  190. priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
  191. /* Apply the new configuration
  192. * RXON assoc doesn't clear the station table in uCode,
  193. */
  194. ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
  195. sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
  196. if (ret) {
  197. IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
  198. return ret;
  199. }
  200. memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
  201. }
  202. iwl_init_sensitivity(priv);
  203. /* If we issue a new RXON command which required a tune then we must
  204. * send a new TXPOWER command or we won't be able to Tx any frames */
  205. ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
  206. if (ret) {
  207. IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
  208. return ret;
  209. }
  210. return 0;
  211. }
  212. void iwl_update_chain_flags(struct iwl_priv *priv)
  213. {
  214. if (priv->cfg->ops->hcmd->set_rxon_chain)
  215. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  216. iwlcore_commit_rxon(priv);
  217. }
  218. static void iwl_clear_free_frames(struct iwl_priv *priv)
  219. {
  220. struct list_head *element;
  221. IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
  222. priv->frames_count);
  223. while (!list_empty(&priv->free_frames)) {
  224. element = priv->free_frames.next;
  225. list_del(element);
  226. kfree(list_entry(element, struct iwl_frame, list));
  227. priv->frames_count--;
  228. }
  229. if (priv->frames_count) {
  230. IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
  231. priv->frames_count);
  232. priv->frames_count = 0;
  233. }
  234. }
  235. static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
  236. {
  237. struct iwl_frame *frame;
  238. struct list_head *element;
  239. if (list_empty(&priv->free_frames)) {
  240. frame = kzalloc(sizeof(*frame), GFP_KERNEL);
  241. if (!frame) {
  242. IWL_ERR(priv, "Could not allocate frame!\n");
  243. return NULL;
  244. }
  245. priv->frames_count++;
  246. return frame;
  247. }
  248. element = priv->free_frames.next;
  249. list_del(element);
  250. return list_entry(element, struct iwl_frame, list);
  251. }
  252. static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
  253. {
  254. memset(frame, 0, sizeof(*frame));
  255. list_add(&frame->list, &priv->free_frames);
  256. }
  257. static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
  258. struct ieee80211_hdr *hdr,
  259. int left)
  260. {
  261. if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
  262. ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
  263. (priv->iw_mode != NL80211_IFTYPE_AP)))
  264. return 0;
  265. if (priv->ibss_beacon->len > left)
  266. return 0;
  267. memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
  268. return priv->ibss_beacon->len;
  269. }
  270. static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
  271. struct iwl_frame *frame, u8 rate)
  272. {
  273. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  274. unsigned int frame_size;
  275. tx_beacon_cmd = &frame->u.beacon;
  276. memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
  277. tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
  278. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  279. frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
  280. sizeof(frame->u) - sizeof(*tx_beacon_cmd));
  281. BUG_ON(frame_size > MAX_MPDU_SIZE);
  282. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  283. if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
  284. tx_beacon_cmd->tx.rate_n_flags =
  285. iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
  286. else
  287. tx_beacon_cmd->tx.rate_n_flags =
  288. iwl_hw_set_rate_n_flags(rate, 0);
  289. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  290. TX_CMD_FLG_TSF_MSK |
  291. TX_CMD_FLG_STA_RATE_MSK;
  292. return sizeof(*tx_beacon_cmd) + frame_size;
  293. }
  294. static int iwl_send_beacon_cmd(struct iwl_priv *priv)
  295. {
  296. struct iwl_frame *frame;
  297. unsigned int frame_size;
  298. int rc;
  299. u8 rate;
  300. frame = iwl_get_free_frame(priv);
  301. if (!frame) {
  302. IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
  303. "command.\n");
  304. return -ENOMEM;
  305. }
  306. rate = iwl_rate_get_lowest_plcp(priv);
  307. frame_size = iwl_hw_get_beacon_cmd(priv, frame, rate);
  308. rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
  309. &frame->u.cmd[0]);
  310. iwl_free_frame(priv, frame);
  311. return rc;
  312. }
  313. static inline dma_addr_t iwl_tfd_tb_get_addr(struct iwl_tfd *tfd, u8 idx)
  314. {
  315. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  316. dma_addr_t addr = get_unaligned_le32(&tb->lo);
  317. if (sizeof(dma_addr_t) > sizeof(u32))
  318. addr |=
  319. ((dma_addr_t)(le16_to_cpu(tb->hi_n_len) & 0xF) << 16) << 16;
  320. return addr;
  321. }
  322. static inline u16 iwl_tfd_tb_get_len(struct iwl_tfd *tfd, u8 idx)
  323. {
  324. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  325. return le16_to_cpu(tb->hi_n_len) >> 4;
  326. }
  327. static inline void iwl_tfd_set_tb(struct iwl_tfd *tfd, u8 idx,
  328. dma_addr_t addr, u16 len)
  329. {
  330. struct iwl_tfd_tb *tb = &tfd->tbs[idx];
  331. u16 hi_n_len = len << 4;
  332. put_unaligned_le32(addr, &tb->lo);
  333. if (sizeof(dma_addr_t) > sizeof(u32))
  334. hi_n_len |= ((addr >> 16) >> 16) & 0xF;
  335. tb->hi_n_len = cpu_to_le16(hi_n_len);
  336. tfd->num_tbs = idx + 1;
  337. }
  338. static inline u8 iwl_tfd_get_num_tbs(struct iwl_tfd *tfd)
  339. {
  340. return tfd->num_tbs & 0x1f;
  341. }
  342. /**
  343. * iwl_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
  344. * @priv - driver private data
  345. * @txq - tx queue
  346. *
  347. * Does NOT advance any TFD circular buffer read/write indexes
  348. * Does NOT free the TFD itself (which is within circular buffer)
  349. */
  350. void iwl_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl_tx_queue *txq)
  351. {
  352. struct iwl_tfd *tfd_tmp = (struct iwl_tfd *)txq->tfds;
  353. struct iwl_tfd *tfd;
  354. struct pci_dev *dev = priv->pci_dev;
  355. int index = txq->q.read_ptr;
  356. int i;
  357. int num_tbs;
  358. tfd = &tfd_tmp[index];
  359. /* Sanity check on number of chunks */
  360. num_tbs = iwl_tfd_get_num_tbs(tfd);
  361. if (num_tbs >= IWL_NUM_OF_TBS) {
  362. IWL_ERR(priv, "Too many chunks: %i\n", num_tbs);
  363. /* @todo issue fatal error, it is quite serious situation */
  364. return;
  365. }
  366. /* Unmap tx_cmd */
  367. if (num_tbs)
  368. pci_unmap_single(dev,
  369. pci_unmap_addr(&txq->meta[index], mapping),
  370. pci_unmap_len(&txq->meta[index], len),
  371. PCI_DMA_BIDIRECTIONAL);
  372. /* Unmap chunks, if any. */
  373. for (i = 1; i < num_tbs; i++) {
  374. pci_unmap_single(dev, iwl_tfd_tb_get_addr(tfd, i),
  375. iwl_tfd_tb_get_len(tfd, i), PCI_DMA_TODEVICE);
  376. if (txq->txb) {
  377. dev_kfree_skb(txq->txb[txq->q.read_ptr].skb[i - 1]);
  378. txq->txb[txq->q.read_ptr].skb[i - 1] = NULL;
  379. }
  380. }
  381. }
  382. int iwl_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv,
  383. struct iwl_tx_queue *txq,
  384. dma_addr_t addr, u16 len,
  385. u8 reset, u8 pad)
  386. {
  387. struct iwl_queue *q;
  388. struct iwl_tfd *tfd, *tfd_tmp;
  389. u32 num_tbs;
  390. q = &txq->q;
  391. tfd_tmp = (struct iwl_tfd *)txq->tfds;
  392. tfd = &tfd_tmp[q->write_ptr];
  393. if (reset)
  394. memset(tfd, 0, sizeof(*tfd));
  395. num_tbs = iwl_tfd_get_num_tbs(tfd);
  396. /* Each TFD can point to a maximum 20 Tx buffers */
  397. if (num_tbs >= IWL_NUM_OF_TBS) {
  398. IWL_ERR(priv, "Error can not send more than %d chunks\n",
  399. IWL_NUM_OF_TBS);
  400. return -EINVAL;
  401. }
  402. BUG_ON(addr & ~DMA_BIT_MASK(36));
  403. if (unlikely(addr & ~IWL_TX_DMA_MASK))
  404. IWL_ERR(priv, "Unaligned address = %llx\n",
  405. (unsigned long long)addr);
  406. iwl_tfd_set_tb(tfd, num_tbs, addr, len);
  407. return 0;
  408. }
  409. /*
  410. * Tell nic where to find circular buffer of Tx Frame Descriptors for
  411. * given Tx queue, and enable the DMA channel used for that queue.
  412. *
  413. * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
  414. * channels supported in hardware.
  415. */
  416. int iwl_hw_tx_queue_init(struct iwl_priv *priv,
  417. struct iwl_tx_queue *txq)
  418. {
  419. int txq_id = txq->q.id;
  420. /* Circular buffer (TFD queue in DRAM) physical base address */
  421. iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
  422. txq->q.dma_addr >> 8);
  423. return 0;
  424. }
  425. /******************************************************************************
  426. *
  427. * Generic RX handler implementations
  428. *
  429. ******************************************************************************/
  430. static void iwl_rx_reply_alive(struct iwl_priv *priv,
  431. struct iwl_rx_mem_buffer *rxb)
  432. {
  433. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  434. struct iwl_alive_resp *palive;
  435. struct delayed_work *pwork;
  436. palive = &pkt->u.alive_frame;
  437. IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
  438. "0x%01X 0x%01X\n",
  439. palive->is_valid, palive->ver_type,
  440. palive->ver_subtype);
  441. if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
  442. IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
  443. memcpy(&priv->card_alive_init,
  444. &pkt->u.alive_frame,
  445. sizeof(struct iwl_init_alive_resp));
  446. pwork = &priv->init_alive_start;
  447. } else {
  448. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  449. memcpy(&priv->card_alive, &pkt->u.alive_frame,
  450. sizeof(struct iwl_alive_resp));
  451. pwork = &priv->alive_start;
  452. }
  453. /* We delay the ALIVE response by 5ms to
  454. * give the HW RF Kill time to activate... */
  455. if (palive->is_valid == UCODE_VALID_OK)
  456. queue_delayed_work(priv->workqueue, pwork,
  457. msecs_to_jiffies(5));
  458. else
  459. IWL_WARN(priv, "uCode did not respond OK.\n");
  460. }
  461. static void iwl_bg_beacon_update(struct work_struct *work)
  462. {
  463. struct iwl_priv *priv =
  464. container_of(work, struct iwl_priv, beacon_update);
  465. struct sk_buff *beacon;
  466. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  467. beacon = ieee80211_beacon_get(priv->hw, priv->vif);
  468. if (!beacon) {
  469. IWL_ERR(priv, "update beacon failed\n");
  470. return;
  471. }
  472. mutex_lock(&priv->mutex);
  473. /* new beacon skb is allocated every time; dispose previous.*/
  474. if (priv->ibss_beacon)
  475. dev_kfree_skb(priv->ibss_beacon);
  476. priv->ibss_beacon = beacon;
  477. mutex_unlock(&priv->mutex);
  478. iwl_send_beacon_cmd(priv);
  479. }
  480. /**
  481. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  482. *
  483. * This callback is provided in order to send a statistics request.
  484. *
  485. * This timer function is continually reset to execute within
  486. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  487. * was received. We need to ensure we receive the statistics in order
  488. * to update the temperature used for calibrating the TXPOWER.
  489. */
  490. static void iwl_bg_statistics_periodic(unsigned long data)
  491. {
  492. struct iwl_priv *priv = (struct iwl_priv *)data;
  493. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  494. return;
  495. /* dont send host command if rf-kill is on */
  496. if (!iwl_is_ready_rf(priv))
  497. return;
  498. iwl_send_statistics_request(priv, CMD_ASYNC);
  499. }
  500. static void iwl_rx_beacon_notif(struct iwl_priv *priv,
  501. struct iwl_rx_mem_buffer *rxb)
  502. {
  503. #ifdef CONFIG_IWLWIFI_DEBUG
  504. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  505. struct iwl4965_beacon_notif *beacon =
  506. (struct iwl4965_beacon_notif *)pkt->u.raw;
  507. u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
  508. IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
  509. "tsf %d %d rate %d\n",
  510. le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
  511. beacon->beacon_notify_hdr.failure_frame,
  512. le32_to_cpu(beacon->ibss_mgr_status),
  513. le32_to_cpu(beacon->high_tsf),
  514. le32_to_cpu(beacon->low_tsf), rate);
  515. #endif
  516. if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
  517. (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
  518. queue_work(priv->workqueue, &priv->beacon_update);
  519. }
  520. /* Handle notification from uCode that card's power state is changing
  521. * due to software, hardware, or critical temperature RFKILL */
  522. static void iwl_rx_card_state_notif(struct iwl_priv *priv,
  523. struct iwl_rx_mem_buffer *rxb)
  524. {
  525. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  526. u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
  527. unsigned long status = priv->status;
  528. IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
  529. (flags & HW_CARD_DISABLED) ? "Kill" : "On",
  530. (flags & SW_CARD_DISABLED) ? "Kill" : "On");
  531. if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
  532. RF_CARD_DISABLED)) {
  533. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  534. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  535. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  536. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  537. if (!(flags & RXON_CARD_DISABLED)) {
  538. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  539. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  540. iwl_write_direct32(priv, HBUS_TARG_MBX_C,
  541. HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
  542. }
  543. if (flags & RF_CARD_DISABLED)
  544. iwl_tt_enter_ct_kill(priv);
  545. }
  546. if (!(flags & RF_CARD_DISABLED))
  547. iwl_tt_exit_ct_kill(priv);
  548. if (flags & HW_CARD_DISABLED)
  549. set_bit(STATUS_RF_KILL_HW, &priv->status);
  550. else
  551. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  552. if (!(flags & RXON_CARD_DISABLED))
  553. iwl_scan_cancel(priv);
  554. if ((test_bit(STATUS_RF_KILL_HW, &status) !=
  555. test_bit(STATUS_RF_KILL_HW, &priv->status)))
  556. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  557. test_bit(STATUS_RF_KILL_HW, &priv->status));
  558. else
  559. wake_up_interruptible(&priv->wait_command_queue);
  560. }
  561. int iwl_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
  562. {
  563. if (src == IWL_PWR_SRC_VAUX) {
  564. if (pci_pme_capable(priv->pci_dev, PCI_D3cold))
  565. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  566. APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
  567. ~APMG_PS_CTRL_MSK_PWR_SRC);
  568. } else {
  569. iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
  570. APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
  571. ~APMG_PS_CTRL_MSK_PWR_SRC);
  572. }
  573. return 0;
  574. }
  575. /**
  576. * iwl_setup_rx_handlers - Initialize Rx handler callbacks
  577. *
  578. * Setup the RX handlers for each of the reply types sent from the uCode
  579. * to the host.
  580. *
  581. * This function chains into the hardware specific files for them to setup
  582. * any hardware specific handlers as well.
  583. */
  584. static void iwl_setup_rx_handlers(struct iwl_priv *priv)
  585. {
  586. priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
  587. priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
  588. priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
  589. priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
  590. priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
  591. iwl_rx_pm_debug_statistics_notif;
  592. priv->rx_handlers[BEACON_NOTIFICATION] = iwl_rx_beacon_notif;
  593. /*
  594. * The same handler is used for both the REPLY to a discrete
  595. * statistics request from the host as well as for the periodic
  596. * statistics notifications (after received beacons) from the uCode.
  597. */
  598. priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
  599. priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
  600. iwl_setup_spectrum_handlers(priv);
  601. iwl_setup_rx_scan_handlers(priv);
  602. /* status change handler */
  603. priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl_rx_card_state_notif;
  604. priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
  605. iwl_rx_missed_beacon_notif;
  606. /* Rx handlers */
  607. priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
  608. priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
  609. /* block ack */
  610. priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
  611. /* Set up hardware specific Rx handlers */
  612. priv->cfg->ops->lib->rx_handler_setup(priv);
  613. }
  614. /**
  615. * iwl_rx_handle - Main entry function for receiving responses from uCode
  616. *
  617. * Uses the priv->rx_handlers callback function array to invoke
  618. * the appropriate handlers, including command responses,
  619. * frame-received notifications, and other notifications.
  620. */
  621. void iwl_rx_handle(struct iwl_priv *priv)
  622. {
  623. struct iwl_rx_mem_buffer *rxb;
  624. struct iwl_rx_packet *pkt;
  625. struct iwl_rx_queue *rxq = &priv->rxq;
  626. u32 r, i;
  627. int reclaim;
  628. unsigned long flags;
  629. u8 fill_rx = 0;
  630. u32 count = 8;
  631. int total_empty;
  632. /* uCode's read index (stored in shared DRAM) indicates the last Rx
  633. * buffer that the driver may process (last buffer filled by ucode). */
  634. r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
  635. i = rxq->read;
  636. /* Rx interrupt, but nothing sent from uCode */
  637. if (i == r)
  638. IWL_DEBUG_RX(priv, "r = %d, i = %d\n", r, i);
  639. /* calculate total frames need to be restock after handling RX */
  640. total_empty = r - priv->rxq.write_actual;
  641. if (total_empty < 0)
  642. total_empty += RX_QUEUE_SIZE;
  643. if (total_empty > (RX_QUEUE_SIZE / 2))
  644. fill_rx = 1;
  645. while (i != r) {
  646. rxb = rxq->queue[i];
  647. /* If an RXB doesn't have a Rx queue slot associated with it,
  648. * then a bug has been introduced in the queue refilling
  649. * routines -- catch it here */
  650. BUG_ON(rxb == NULL);
  651. rxq->queue[i] = NULL;
  652. pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
  653. priv->hw_params.rx_buf_size + 256,
  654. PCI_DMA_FROMDEVICE);
  655. pkt = (struct iwl_rx_packet *)rxb->skb->data;
  656. /* Reclaim a command buffer only if this packet is a response
  657. * to a (driver-originated) command.
  658. * If the packet (e.g. Rx frame) originated from uCode,
  659. * there is no command buffer to reclaim.
  660. * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
  661. * but apparently a few don't get set; catch them here. */
  662. reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
  663. (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
  664. (pkt->hdr.cmd != REPLY_RX) &&
  665. (pkt->hdr.cmd != REPLY_RX_MPDU_CMD) &&
  666. (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
  667. (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
  668. (pkt->hdr.cmd != REPLY_TX);
  669. /* Based on type of command response or notification,
  670. * handle those that need handling via function in
  671. * rx_handlers table. See iwl_setup_rx_handlers() */
  672. if (priv->rx_handlers[pkt->hdr.cmd]) {
  673. IWL_DEBUG_RX(priv, "r = %d, i = %d, %s, 0x%02x\n", r,
  674. i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
  675. priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
  676. priv->isr_stats.rx_handlers[pkt->hdr.cmd]++;
  677. } else {
  678. /* No handling needed */
  679. IWL_DEBUG_RX(priv,
  680. "r %d i %d No handler needed for %s, 0x%02x\n",
  681. r, i, get_cmd_string(pkt->hdr.cmd),
  682. pkt->hdr.cmd);
  683. }
  684. if (reclaim) {
  685. /* Invoke any callbacks, transfer the skb to caller, and
  686. * fire off the (possibly) blocking iwl_send_cmd()
  687. * as we reclaim the driver command queue */
  688. if (rxb && rxb->skb)
  689. iwl_tx_cmd_complete(priv, rxb);
  690. else
  691. IWL_WARN(priv, "Claim null rxb?\n");
  692. }
  693. /* For now we just don't re-use anything. We can tweak this
  694. * later to try and re-use notification packets and SKBs that
  695. * fail to Rx correctly */
  696. if (rxb->skb != NULL) {
  697. priv->alloc_rxb_skb--;
  698. dev_kfree_skb_any(rxb->skb);
  699. rxb->skb = NULL;
  700. }
  701. spin_lock_irqsave(&rxq->lock, flags);
  702. list_add_tail(&rxb->list, &priv->rxq.rx_used);
  703. spin_unlock_irqrestore(&rxq->lock, flags);
  704. i = (i + 1) & RX_QUEUE_MASK;
  705. /* If there are a lot of unused frames,
  706. * restock the Rx queue so ucode wont assert. */
  707. if (fill_rx) {
  708. count++;
  709. if (count >= 8) {
  710. priv->rxq.read = i;
  711. iwl_rx_replenish_now(priv);
  712. count = 0;
  713. }
  714. }
  715. }
  716. /* Backtrack one entry */
  717. priv->rxq.read = i;
  718. if (fill_rx)
  719. iwl_rx_replenish_now(priv);
  720. else
  721. iwl_rx_queue_restock(priv);
  722. }
  723. /* call this function to flush any scheduled tasklet */
  724. static inline void iwl_synchronize_irq(struct iwl_priv *priv)
  725. {
  726. /* wait to make sure we flush pending tasklet*/
  727. synchronize_irq(priv->pci_dev->irq);
  728. tasklet_kill(&priv->irq_tasklet);
  729. }
  730. static void iwl_irq_tasklet_legacy(struct iwl_priv *priv)
  731. {
  732. u32 inta, handled = 0;
  733. u32 inta_fh;
  734. unsigned long flags;
  735. #ifdef CONFIG_IWLWIFI_DEBUG
  736. u32 inta_mask;
  737. #endif
  738. spin_lock_irqsave(&priv->lock, flags);
  739. /* Ack/clear/reset pending uCode interrupts.
  740. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  741. * and will clear only when CSR_FH_INT_STATUS gets cleared. */
  742. inta = iwl_read32(priv, CSR_INT);
  743. iwl_write32(priv, CSR_INT, inta);
  744. /* Ack/clear/reset pending flow-handler (DMA) interrupts.
  745. * Any new interrupts that happen after this, either while we're
  746. * in this tasklet, or later, will show up in next ISR/tasklet. */
  747. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  748. iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
  749. #ifdef CONFIG_IWLWIFI_DEBUG
  750. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  751. /* just for debug */
  752. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  753. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  754. inta, inta_mask, inta_fh);
  755. }
  756. #endif
  757. /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
  758. * atomic, make sure that inta covers all the interrupts that
  759. * we've discovered, even if FH interrupt came in just after
  760. * reading CSR_INT. */
  761. if (inta_fh & CSR49_FH_INT_RX_MASK)
  762. inta |= CSR_INT_BIT_FH_RX;
  763. if (inta_fh & CSR49_FH_INT_TX_MASK)
  764. inta |= CSR_INT_BIT_FH_TX;
  765. /* Now service all interrupt bits discovered above. */
  766. if (inta & CSR_INT_BIT_HW_ERR) {
  767. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  768. /* Tell the device to stop sending interrupts */
  769. iwl_disable_interrupts(priv);
  770. priv->isr_stats.hw++;
  771. iwl_irq_handle_error(priv);
  772. handled |= CSR_INT_BIT_HW_ERR;
  773. spin_unlock_irqrestore(&priv->lock, flags);
  774. return;
  775. }
  776. #ifdef CONFIG_IWLWIFI_DEBUG
  777. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  778. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  779. if (inta & CSR_INT_BIT_SCD) {
  780. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  781. "the frame/frames.\n");
  782. priv->isr_stats.sch++;
  783. }
  784. /* Alive notification via Rx interrupt will do the real work */
  785. if (inta & CSR_INT_BIT_ALIVE) {
  786. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  787. priv->isr_stats.alive++;
  788. }
  789. }
  790. #endif
  791. /* Safely ignore these bits for debug checks below */
  792. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  793. /* HW RF KILL switch toggled */
  794. if (inta & CSR_INT_BIT_RF_KILL) {
  795. int hw_rf_kill = 0;
  796. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  797. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  798. hw_rf_kill = 1;
  799. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  800. hw_rf_kill ? "disable radio" : "enable radio");
  801. priv->isr_stats.rfkill++;
  802. /* driver only loads ucode once setting the interface up.
  803. * the driver allows loading the ucode even if the radio
  804. * is killed. Hence update the killswitch state here. The
  805. * rfkill handler will care about restarting if needed.
  806. */
  807. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  808. if (hw_rf_kill)
  809. set_bit(STATUS_RF_KILL_HW, &priv->status);
  810. else
  811. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  812. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  813. }
  814. handled |= CSR_INT_BIT_RF_KILL;
  815. }
  816. /* Chip got too hot and stopped itself */
  817. if (inta & CSR_INT_BIT_CT_KILL) {
  818. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  819. priv->isr_stats.ctkill++;
  820. handled |= CSR_INT_BIT_CT_KILL;
  821. }
  822. /* Error detected by uCode */
  823. if (inta & CSR_INT_BIT_SW_ERR) {
  824. IWL_ERR(priv, "Microcode SW error detected. "
  825. " Restarting 0x%X.\n", inta);
  826. priv->isr_stats.sw++;
  827. priv->isr_stats.sw_err = inta;
  828. iwl_irq_handle_error(priv);
  829. handled |= CSR_INT_BIT_SW_ERR;
  830. }
  831. /* uCode wakes up after power-down sleep */
  832. if (inta & CSR_INT_BIT_WAKEUP) {
  833. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  834. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  835. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  836. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  837. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  838. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  839. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  840. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  841. priv->isr_stats.wakeup++;
  842. handled |= CSR_INT_BIT_WAKEUP;
  843. }
  844. /* All uCode command responses, including Tx command responses,
  845. * Rx "responses" (frame-received notification), and other
  846. * notifications from uCode come through here*/
  847. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  848. iwl_rx_handle(priv);
  849. priv->isr_stats.rx++;
  850. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  851. }
  852. if (inta & CSR_INT_BIT_FH_TX) {
  853. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  854. priv->isr_stats.tx++;
  855. handled |= CSR_INT_BIT_FH_TX;
  856. /* FH finished to write, send event */
  857. priv->ucode_write_complete = 1;
  858. wake_up_interruptible(&priv->wait_command_queue);
  859. }
  860. if (inta & ~handled) {
  861. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  862. priv->isr_stats.unhandled++;
  863. }
  864. if (inta & ~(priv->inta_mask)) {
  865. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  866. inta & ~priv->inta_mask);
  867. IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
  868. }
  869. /* Re-enable all interrupts */
  870. /* only Re-enable if diabled by irq */
  871. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  872. iwl_enable_interrupts(priv);
  873. #ifdef CONFIG_IWLWIFI_DEBUG
  874. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  875. inta = iwl_read32(priv, CSR_INT);
  876. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  877. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  878. IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
  879. "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
  880. }
  881. #endif
  882. spin_unlock_irqrestore(&priv->lock, flags);
  883. }
  884. /* tasklet for iwlagn interrupt */
  885. static void iwl_irq_tasklet(struct iwl_priv *priv)
  886. {
  887. u32 inta = 0;
  888. u32 handled = 0;
  889. unsigned long flags;
  890. #ifdef CONFIG_IWLWIFI_DEBUG
  891. u32 inta_mask;
  892. #endif
  893. spin_lock_irqsave(&priv->lock, flags);
  894. /* Ack/clear/reset pending uCode interrupts.
  895. * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
  896. */
  897. iwl_write32(priv, CSR_INT, priv->inta);
  898. inta = priv->inta;
  899. #ifdef CONFIG_IWLWIFI_DEBUG
  900. if (iwl_get_debug_level(priv) & IWL_DL_ISR) {
  901. /* just for debug */
  902. inta_mask = iwl_read32(priv, CSR_INT_MASK);
  903. IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x\n ",
  904. inta, inta_mask);
  905. }
  906. #endif
  907. /* saved interrupt in inta variable now we can reset priv->inta */
  908. priv->inta = 0;
  909. /* Now service all interrupt bits discovered above. */
  910. if (inta & CSR_INT_BIT_HW_ERR) {
  911. IWL_ERR(priv, "Hardware error detected. Restarting.\n");
  912. /* Tell the device to stop sending interrupts */
  913. iwl_disable_interrupts(priv);
  914. priv->isr_stats.hw++;
  915. iwl_irq_handle_error(priv);
  916. handled |= CSR_INT_BIT_HW_ERR;
  917. spin_unlock_irqrestore(&priv->lock, flags);
  918. return;
  919. }
  920. #ifdef CONFIG_IWLWIFI_DEBUG
  921. if (iwl_get_debug_level(priv) & (IWL_DL_ISR)) {
  922. /* NIC fires this, but we don't use it, redundant with WAKEUP */
  923. if (inta & CSR_INT_BIT_SCD) {
  924. IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
  925. "the frame/frames.\n");
  926. priv->isr_stats.sch++;
  927. }
  928. /* Alive notification via Rx interrupt will do the real work */
  929. if (inta & CSR_INT_BIT_ALIVE) {
  930. IWL_DEBUG_ISR(priv, "Alive interrupt\n");
  931. priv->isr_stats.alive++;
  932. }
  933. }
  934. #endif
  935. /* Safely ignore these bits for debug checks below */
  936. inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
  937. /* HW RF KILL switch toggled */
  938. if (inta & CSR_INT_BIT_RF_KILL) {
  939. int hw_rf_kill = 0;
  940. if (!(iwl_read32(priv, CSR_GP_CNTRL) &
  941. CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
  942. hw_rf_kill = 1;
  943. IWL_WARN(priv, "RF_KILL bit toggled to %s.\n",
  944. hw_rf_kill ? "disable radio" : "enable radio");
  945. priv->isr_stats.rfkill++;
  946. /* driver only loads ucode once setting the interface up.
  947. * the driver allows loading the ucode even if the radio
  948. * is killed. Hence update the killswitch state here. The
  949. * rfkill handler will care about restarting if needed.
  950. */
  951. if (!test_bit(STATUS_ALIVE, &priv->status)) {
  952. if (hw_rf_kill)
  953. set_bit(STATUS_RF_KILL_HW, &priv->status);
  954. else
  955. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  956. wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rf_kill);
  957. }
  958. handled |= CSR_INT_BIT_RF_KILL;
  959. }
  960. /* Chip got too hot and stopped itself */
  961. if (inta & CSR_INT_BIT_CT_KILL) {
  962. IWL_ERR(priv, "Microcode CT kill error detected.\n");
  963. priv->isr_stats.ctkill++;
  964. handled |= CSR_INT_BIT_CT_KILL;
  965. }
  966. /* Error detected by uCode */
  967. if (inta & CSR_INT_BIT_SW_ERR) {
  968. IWL_ERR(priv, "Microcode SW error detected. "
  969. " Restarting 0x%X.\n", inta);
  970. priv->isr_stats.sw++;
  971. priv->isr_stats.sw_err = inta;
  972. iwl_irq_handle_error(priv);
  973. handled |= CSR_INT_BIT_SW_ERR;
  974. }
  975. /* uCode wakes up after power-down sleep */
  976. if (inta & CSR_INT_BIT_WAKEUP) {
  977. IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
  978. iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
  979. iwl_txq_update_write_ptr(priv, &priv->txq[0]);
  980. iwl_txq_update_write_ptr(priv, &priv->txq[1]);
  981. iwl_txq_update_write_ptr(priv, &priv->txq[2]);
  982. iwl_txq_update_write_ptr(priv, &priv->txq[3]);
  983. iwl_txq_update_write_ptr(priv, &priv->txq[4]);
  984. iwl_txq_update_write_ptr(priv, &priv->txq[5]);
  985. priv->isr_stats.wakeup++;
  986. handled |= CSR_INT_BIT_WAKEUP;
  987. }
  988. /* All uCode command responses, including Tx command responses,
  989. * Rx "responses" (frame-received notification), and other
  990. * notifications from uCode come through here*/
  991. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX |
  992. CSR_INT_BIT_RX_PERIODIC)) {
  993. IWL_DEBUG_ISR(priv, "Rx interrupt\n");
  994. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
  995. handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
  996. iwl_write32(priv, CSR_FH_INT_STATUS,
  997. CSR49_FH_INT_RX_MASK);
  998. }
  999. if (inta & CSR_INT_BIT_RX_PERIODIC) {
  1000. handled |= CSR_INT_BIT_RX_PERIODIC;
  1001. iwl_write32(priv, CSR_INT, CSR_INT_BIT_RX_PERIODIC);
  1002. }
  1003. /* Sending RX interrupt require many steps to be done in the
  1004. * the device:
  1005. * 1- write interrupt to current index in ICT table.
  1006. * 2- dma RX frame.
  1007. * 3- update RX shared data to indicate last write index.
  1008. * 4- send interrupt.
  1009. * This could lead to RX race, driver could receive RX interrupt
  1010. * but the shared data changes does not reflect this.
  1011. * this could lead to RX race, RX periodic will solve this race
  1012. */
  1013. iwl_write32(priv, CSR_INT_PERIODIC_REG,
  1014. CSR_INT_PERIODIC_DIS);
  1015. iwl_rx_handle(priv);
  1016. /* Only set RX periodic if real RX is received. */
  1017. if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX))
  1018. iwl_write32(priv, CSR_INT_PERIODIC_REG,
  1019. CSR_INT_PERIODIC_ENA);
  1020. priv->isr_stats.rx++;
  1021. }
  1022. if (inta & CSR_INT_BIT_FH_TX) {
  1023. iwl_write32(priv, CSR_FH_INT_STATUS, CSR49_FH_INT_TX_MASK);
  1024. IWL_DEBUG_ISR(priv, "Tx interrupt\n");
  1025. priv->isr_stats.tx++;
  1026. handled |= CSR_INT_BIT_FH_TX;
  1027. /* FH finished to write, send event */
  1028. priv->ucode_write_complete = 1;
  1029. wake_up_interruptible(&priv->wait_command_queue);
  1030. }
  1031. if (inta & ~handled) {
  1032. IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1033. priv->isr_stats.unhandled++;
  1034. }
  1035. if (inta & ~(priv->inta_mask)) {
  1036. IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
  1037. inta & ~priv->inta_mask);
  1038. }
  1039. /* Re-enable all interrupts */
  1040. /* only Re-enable if diabled by irq */
  1041. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1042. iwl_enable_interrupts(priv);
  1043. spin_unlock_irqrestore(&priv->lock, flags);
  1044. }
  1045. /******************************************************************************
  1046. *
  1047. * uCode download functions
  1048. *
  1049. ******************************************************************************/
  1050. static void iwl_dealloc_ucode_pci(struct iwl_priv *priv)
  1051. {
  1052. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
  1053. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
  1054. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1055. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
  1056. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1057. iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1058. }
  1059. static void iwl_nic_start(struct iwl_priv *priv)
  1060. {
  1061. /* Remove all resets to allow NIC to operate */
  1062. iwl_write32(priv, CSR_RESET, 0);
  1063. }
  1064. /**
  1065. * iwl_read_ucode - Read uCode images from disk file.
  1066. *
  1067. * Copy into buffers for card to fetch via bus-mastering
  1068. */
  1069. static int iwl_read_ucode(struct iwl_priv *priv)
  1070. {
  1071. struct iwl_ucode_header *ucode;
  1072. int ret = -EINVAL, index;
  1073. const struct firmware *ucode_raw;
  1074. const char *name_pre = priv->cfg->fw_name_pre;
  1075. const unsigned int api_max = priv->cfg->ucode_api_max;
  1076. const unsigned int api_min = priv->cfg->ucode_api_min;
  1077. char buf[25];
  1078. u8 *src;
  1079. size_t len;
  1080. u32 api_ver, build;
  1081. u32 inst_size, data_size, init_size, init_data_size, boot_size;
  1082. u16 eeprom_ver;
  1083. /* Ask kernel firmware_class module to get the boot firmware off disk.
  1084. * request_firmware() is synchronous, file is in memory on return. */
  1085. for (index = api_max; index >= api_min; index--) {
  1086. sprintf(buf, "%s%d%s", name_pre, index, ".ucode");
  1087. ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
  1088. if (ret < 0) {
  1089. IWL_ERR(priv, "%s firmware file req failed: %d\n",
  1090. buf, ret);
  1091. if (ret == -ENOENT)
  1092. continue;
  1093. else
  1094. goto error;
  1095. } else {
  1096. if (index < api_max)
  1097. IWL_ERR(priv, "Loaded firmware %s, "
  1098. "which is deprecated. "
  1099. "Please use API v%u instead.\n",
  1100. buf, api_max);
  1101. IWL_DEBUG_INFO(priv, "Got firmware '%s' file (%zd bytes) from disk\n",
  1102. buf, ucode_raw->size);
  1103. break;
  1104. }
  1105. }
  1106. if (ret < 0)
  1107. goto error;
  1108. /* Make sure that we got at least the v1 header! */
  1109. if (ucode_raw->size < priv->cfg->ops->ucode->get_header_size(1)) {
  1110. IWL_ERR(priv, "File size way too small!\n");
  1111. ret = -EINVAL;
  1112. goto err_release;
  1113. }
  1114. /* Data from ucode file: header followed by uCode images */
  1115. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  1116. priv->ucode_ver = le32_to_cpu(ucode->ver);
  1117. api_ver = IWL_UCODE_API(priv->ucode_ver);
  1118. build = priv->cfg->ops->ucode->get_build(ucode, api_ver);
  1119. inst_size = priv->cfg->ops->ucode->get_inst_size(ucode, api_ver);
  1120. data_size = priv->cfg->ops->ucode->get_data_size(ucode, api_ver);
  1121. init_size = priv->cfg->ops->ucode->get_init_size(ucode, api_ver);
  1122. init_data_size =
  1123. priv->cfg->ops->ucode->get_init_data_size(ucode, api_ver);
  1124. boot_size = priv->cfg->ops->ucode->get_boot_size(ucode, api_ver);
  1125. src = priv->cfg->ops->ucode->get_data(ucode, api_ver);
  1126. /* api_ver should match the api version forming part of the
  1127. * firmware filename ... but we don't check for that and only rely
  1128. * on the API version read from firmware header from here on forward */
  1129. if (api_ver < api_min || api_ver > api_max) {
  1130. IWL_ERR(priv, "Driver unable to support your firmware API. "
  1131. "Driver supports v%u, firmware is v%u.\n",
  1132. api_max, api_ver);
  1133. priv->ucode_ver = 0;
  1134. ret = -EINVAL;
  1135. goto err_release;
  1136. }
  1137. if (api_ver != api_max)
  1138. IWL_ERR(priv, "Firmware has old API version. Expected v%u, "
  1139. "got v%u. New firmware can be obtained "
  1140. "from http://www.intellinuxwireless.org.\n",
  1141. api_max, api_ver);
  1142. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
  1143. IWL_UCODE_MAJOR(priv->ucode_ver),
  1144. IWL_UCODE_MINOR(priv->ucode_ver),
  1145. IWL_UCODE_API(priv->ucode_ver),
  1146. IWL_UCODE_SERIAL(priv->ucode_ver));
  1147. if (build)
  1148. IWL_DEBUG_INFO(priv, "Build %u\n", build);
  1149. eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
  1150. IWL_DEBUG_INFO(priv, "NVM Type: %s, version: 0x%x\n",
  1151. (priv->nvm_device_type == NVM_DEVICE_TYPE_OTP)
  1152. ? "OTP" : "EEPROM", eeprom_ver);
  1153. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  1154. priv->ucode_ver);
  1155. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
  1156. inst_size);
  1157. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
  1158. data_size);
  1159. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
  1160. init_size);
  1161. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
  1162. init_data_size);
  1163. IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
  1164. boot_size);
  1165. /* Verify size of file vs. image size info in file's header */
  1166. if (ucode_raw->size !=
  1167. priv->cfg->ops->ucode->get_header_size(api_ver) +
  1168. inst_size + data_size + init_size +
  1169. init_data_size + boot_size) {
  1170. IWL_DEBUG_INFO(priv,
  1171. "uCode file size %d does not match expected size\n",
  1172. (int)ucode_raw->size);
  1173. ret = -EINVAL;
  1174. goto err_release;
  1175. }
  1176. /* Verify that uCode images will fit in card's SRAM */
  1177. if (inst_size > priv->hw_params.max_inst_size) {
  1178. IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
  1179. inst_size);
  1180. ret = -EINVAL;
  1181. goto err_release;
  1182. }
  1183. if (data_size > priv->hw_params.max_data_size) {
  1184. IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
  1185. data_size);
  1186. ret = -EINVAL;
  1187. goto err_release;
  1188. }
  1189. if (init_size > priv->hw_params.max_inst_size) {
  1190. IWL_INFO(priv, "uCode init instr len %d too large to fit in\n",
  1191. init_size);
  1192. ret = -EINVAL;
  1193. goto err_release;
  1194. }
  1195. if (init_data_size > priv->hw_params.max_data_size) {
  1196. IWL_INFO(priv, "uCode init data len %d too large to fit in\n",
  1197. init_data_size);
  1198. ret = -EINVAL;
  1199. goto err_release;
  1200. }
  1201. if (boot_size > priv->hw_params.max_bsm_size) {
  1202. IWL_INFO(priv, "uCode boot instr len %d too large to fit in\n",
  1203. boot_size);
  1204. ret = -EINVAL;
  1205. goto err_release;
  1206. }
  1207. /* Allocate ucode buffers for card's bus-master loading ... */
  1208. /* Runtime instructions and 2 copies of data:
  1209. * 1) unmodified from disk
  1210. * 2) backup cache for save/restore during power-downs */
  1211. priv->ucode_code.len = inst_size;
  1212. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
  1213. priv->ucode_data.len = data_size;
  1214. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
  1215. priv->ucode_data_backup.len = data_size;
  1216. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
  1217. if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
  1218. !priv->ucode_data_backup.v_addr)
  1219. goto err_pci_alloc;
  1220. /* Initialization instructions and data */
  1221. if (init_size && init_data_size) {
  1222. priv->ucode_init.len = init_size;
  1223. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
  1224. priv->ucode_init_data.len = init_data_size;
  1225. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
  1226. if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
  1227. goto err_pci_alloc;
  1228. }
  1229. /* Bootstrap (instructions only, no data) */
  1230. if (boot_size) {
  1231. priv->ucode_boot.len = boot_size;
  1232. iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
  1233. if (!priv->ucode_boot.v_addr)
  1234. goto err_pci_alloc;
  1235. }
  1236. /* Copy images into buffers for card's bus-master reads ... */
  1237. /* Runtime instructions (first block of data in file) */
  1238. len = inst_size;
  1239. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode instr len %Zd\n", len);
  1240. memcpy(priv->ucode_code.v_addr, src, len);
  1241. src += len;
  1242. IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
  1243. priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
  1244. /* Runtime data (2nd block)
  1245. * NOTE: Copy into backup buffer will be done in iwl_up() */
  1246. len = data_size;
  1247. IWL_DEBUG_INFO(priv, "Copying (but not loading) uCode data len %Zd\n", len);
  1248. memcpy(priv->ucode_data.v_addr, src, len);
  1249. memcpy(priv->ucode_data_backup.v_addr, src, len);
  1250. src += len;
  1251. /* Initialization instructions (3rd block) */
  1252. if (init_size) {
  1253. len = init_size;
  1254. IWL_DEBUG_INFO(priv, "Copying (but not loading) init instr len %Zd\n",
  1255. len);
  1256. memcpy(priv->ucode_init.v_addr, src, len);
  1257. src += len;
  1258. }
  1259. /* Initialization data (4th block) */
  1260. if (init_data_size) {
  1261. len = init_data_size;
  1262. IWL_DEBUG_INFO(priv, "Copying (but not loading) init data len %Zd\n",
  1263. len);
  1264. memcpy(priv->ucode_init_data.v_addr, src, len);
  1265. src += len;
  1266. }
  1267. /* Bootstrap instructions (5th block) */
  1268. len = boot_size;
  1269. IWL_DEBUG_INFO(priv, "Copying (but not loading) boot instr len %Zd\n", len);
  1270. memcpy(priv->ucode_boot.v_addr, src, len);
  1271. /* We have our copies now, allow OS release its copies */
  1272. release_firmware(ucode_raw);
  1273. return 0;
  1274. err_pci_alloc:
  1275. IWL_ERR(priv, "failed to allocate pci memory\n");
  1276. ret = -ENOMEM;
  1277. iwl_dealloc_ucode_pci(priv);
  1278. err_release:
  1279. release_firmware(ucode_raw);
  1280. error:
  1281. return ret;
  1282. }
  1283. #ifdef CONFIG_IWLWIFI_DEBUG
  1284. static const char *desc_lookup_text[] = {
  1285. "OK",
  1286. "FAIL",
  1287. "BAD_PARAM",
  1288. "BAD_CHECKSUM",
  1289. "NMI_INTERRUPT_WDG",
  1290. "SYSASSERT",
  1291. "FATAL_ERROR",
  1292. "BAD_COMMAND",
  1293. "HW_ERROR_TUNE_LOCK",
  1294. "HW_ERROR_TEMPERATURE",
  1295. "ILLEGAL_CHAN_FREQ",
  1296. "VCC_NOT_STABLE",
  1297. "FH_ERROR",
  1298. "NMI_INTERRUPT_HOST",
  1299. "NMI_INTERRUPT_ACTION_PT",
  1300. "NMI_INTERRUPT_UNKNOWN",
  1301. "UCODE_VERSION_MISMATCH",
  1302. "HW_ERROR_ABS_LOCK",
  1303. "HW_ERROR_CAL_LOCK_FAIL",
  1304. "NMI_INTERRUPT_INST_ACTION_PT",
  1305. "NMI_INTERRUPT_DATA_ACTION_PT",
  1306. "NMI_TRM_HW_ER",
  1307. "NMI_INTERRUPT_TRM",
  1308. "NMI_INTERRUPT_BREAK_POINT"
  1309. "DEBUG_0",
  1310. "DEBUG_1",
  1311. "DEBUG_2",
  1312. "DEBUG_3",
  1313. "UNKNOWN"
  1314. };
  1315. static const char *desc_lookup(int i)
  1316. {
  1317. int max = ARRAY_SIZE(desc_lookup_text) - 1;
  1318. if (i < 0 || i > max)
  1319. i = max;
  1320. return desc_lookup_text[i];
  1321. }
  1322. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1323. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1324. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1325. {
  1326. u32 data2, line;
  1327. u32 desc, time, count, base, data1;
  1328. u32 blink1, blink2, ilink1, ilink2;
  1329. if (priv->ucode_type == UCODE_INIT)
  1330. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  1331. else
  1332. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1333. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1334. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1335. return;
  1336. }
  1337. count = iwl_read_targ_mem(priv, base);
  1338. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1339. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1340. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1341. priv->status, count);
  1342. }
  1343. desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
  1344. blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
  1345. blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
  1346. ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
  1347. ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
  1348. data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
  1349. data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
  1350. line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
  1351. time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
  1352. IWL_ERR(priv, "Desc Time "
  1353. "data1 data2 line\n");
  1354. IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
  1355. desc_lookup(desc), desc, time, data1, data2, line);
  1356. IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
  1357. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
  1358. ilink1, ilink2);
  1359. }
  1360. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1361. /**
  1362. * iwl_print_event_log - Dump error event log to syslog
  1363. *
  1364. */
  1365. static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1366. u32 num_events, u32 mode)
  1367. {
  1368. u32 i;
  1369. u32 base; /* SRAM byte address of event log header */
  1370. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1371. u32 ptr; /* SRAM byte address of log data */
  1372. u32 ev, time, data; /* event log data */
  1373. if (num_events == 0)
  1374. return;
  1375. if (priv->ucode_type == UCODE_INIT)
  1376. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1377. else
  1378. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1379. if (mode == 0)
  1380. event_size = 2 * sizeof(u32);
  1381. else
  1382. event_size = 3 * sizeof(u32);
  1383. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1384. /* "time" is actually "data" for mode 0 (no timestamp).
  1385. * place event id # at far right for easier visual parsing. */
  1386. for (i = 0; i < num_events; i++) {
  1387. ev = iwl_read_targ_mem(priv, ptr);
  1388. ptr += sizeof(u32);
  1389. time = iwl_read_targ_mem(priv, ptr);
  1390. ptr += sizeof(u32);
  1391. if (mode == 0) {
  1392. /* data, ev */
  1393. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
  1394. } else {
  1395. data = iwl_read_targ_mem(priv, ptr);
  1396. ptr += sizeof(u32);
  1397. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1398. time, data, ev);
  1399. }
  1400. }
  1401. }
  1402. void iwl_dump_nic_event_log(struct iwl_priv *priv)
  1403. {
  1404. u32 base; /* SRAM byte address of event log header */
  1405. u32 capacity; /* event log capacity in # entries */
  1406. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1407. u32 num_wraps; /* # times uCode wrapped to top of log */
  1408. u32 next_entry; /* index of next entry to be written by uCode */
  1409. u32 size; /* # entries that we'll print */
  1410. if (priv->ucode_type == UCODE_INIT)
  1411. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1412. else
  1413. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1414. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1415. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1416. return;
  1417. }
  1418. /* event log header */
  1419. capacity = iwl_read_targ_mem(priv, base);
  1420. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1421. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1422. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1423. size = num_wraps ? capacity : next_entry;
  1424. /* bail out if nothing in log */
  1425. if (size == 0) {
  1426. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1427. return;
  1428. }
  1429. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  1430. size, num_wraps);
  1431. /* if uCode has wrapped back to top of log, start at the oldest entry,
  1432. * i.e the next one that uCode would fill. */
  1433. if (num_wraps)
  1434. iwl_print_event_log(priv, next_entry,
  1435. capacity - next_entry, mode);
  1436. /* (then/else) start at top of log */
  1437. iwl_print_event_log(priv, 0, next_entry, mode);
  1438. }
  1439. #endif
  1440. /**
  1441. * iwl_alive_start - called after REPLY_ALIVE notification received
  1442. * from protocol/runtime uCode (initialization uCode's
  1443. * Alive gets handled by iwl_init_alive_start()).
  1444. */
  1445. static void iwl_alive_start(struct iwl_priv *priv)
  1446. {
  1447. int ret = 0;
  1448. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1449. if (priv->card_alive.is_valid != UCODE_VALID_OK) {
  1450. /* We had an error bringing up the hardware, so take it
  1451. * all the way back down so we can try again */
  1452. IWL_DEBUG_INFO(priv, "Alive failed.\n");
  1453. goto restart;
  1454. }
  1455. /* Initialize uCode has loaded Runtime uCode ... verify inst image.
  1456. * This is a paranoid check, because we would not have gotten the
  1457. * "runtime" alive if code weren't properly loaded. */
  1458. if (iwl_verify_ucode(priv)) {
  1459. /* Runtime instruction load was bad;
  1460. * take it all the way back down so we can try again */
  1461. IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
  1462. goto restart;
  1463. }
  1464. iwl_clear_stations_table(priv);
  1465. ret = priv->cfg->ops->lib->alive_notify(priv);
  1466. if (ret) {
  1467. IWL_WARN(priv,
  1468. "Could not complete ALIVE transition [ntf]: %d\n", ret);
  1469. goto restart;
  1470. }
  1471. /* After the ALIVE response, we can send host commands to the uCode */
  1472. set_bit(STATUS_ALIVE, &priv->status);
  1473. if (iwl_is_rfkill(priv))
  1474. return;
  1475. ieee80211_wake_queues(priv->hw);
  1476. priv->active_rate = priv->rates_mask;
  1477. priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
  1478. if (iwl_is_associated(priv)) {
  1479. struct iwl_rxon_cmd *active_rxon =
  1480. (struct iwl_rxon_cmd *)&priv->active_rxon;
  1481. /* apply any changes in staging */
  1482. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1483. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1484. } else {
  1485. /* Initialize our rx_config data */
  1486. iwl_connection_init_rx_config(priv, priv->iw_mode);
  1487. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1488. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1489. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1490. }
  1491. /* Configure Bluetooth device coexistence support */
  1492. iwl_send_bt_config(priv);
  1493. iwl_reset_run_time_calib(priv);
  1494. /* Configure the adapter for unassociated operation */
  1495. iwlcore_commit_rxon(priv);
  1496. /* At this point, the NIC is initialized and operational */
  1497. iwl_rf_kill_ct_config(priv);
  1498. iwl_leds_register(priv);
  1499. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1500. set_bit(STATUS_READY, &priv->status);
  1501. wake_up_interruptible(&priv->wait_command_queue);
  1502. iwl_power_update_mode(priv, true);
  1503. /* reassociate for ADHOC mode */
  1504. if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
  1505. struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
  1506. priv->vif);
  1507. if (beacon)
  1508. iwl_mac_beacon_update(priv->hw, beacon);
  1509. }
  1510. if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
  1511. iwl_set_mode(priv, priv->iw_mode);
  1512. return;
  1513. restart:
  1514. queue_work(priv->workqueue, &priv->restart);
  1515. }
  1516. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1517. static void __iwl_down(struct iwl_priv *priv)
  1518. {
  1519. unsigned long flags;
  1520. int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
  1521. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1522. if (!exit_pending)
  1523. set_bit(STATUS_EXIT_PENDING, &priv->status);
  1524. iwl_leds_unregister(priv);
  1525. iwl_clear_stations_table(priv);
  1526. /* Unblock any waiting calls */
  1527. wake_up_interruptible_all(&priv->wait_command_queue);
  1528. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1529. * exiting the module */
  1530. if (!exit_pending)
  1531. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1532. /* stop and reset the on-board processor */
  1533. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1534. /* tell the device to stop sending interrupts */
  1535. spin_lock_irqsave(&priv->lock, flags);
  1536. iwl_disable_interrupts(priv);
  1537. spin_unlock_irqrestore(&priv->lock, flags);
  1538. iwl_synchronize_irq(priv);
  1539. if (priv->mac80211_registered)
  1540. ieee80211_stop_queues(priv->hw);
  1541. /* If we have not previously called iwl_init() then
  1542. * clear all bits but the RF Kill bit and return */
  1543. if (!iwl_is_init(priv)) {
  1544. priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1545. STATUS_RF_KILL_HW |
  1546. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1547. STATUS_GEO_CONFIGURED |
  1548. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  1549. STATUS_EXIT_PENDING;
  1550. goto exit;
  1551. }
  1552. /* ...otherwise clear out all the status bits but the RF Kill
  1553. * bit and continue taking the NIC down. */
  1554. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1555. STATUS_RF_KILL_HW |
  1556. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1557. STATUS_GEO_CONFIGURED |
  1558. test_bit(STATUS_FW_ERROR, &priv->status) <<
  1559. STATUS_FW_ERROR |
  1560. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  1561. STATUS_EXIT_PENDING;
  1562. /* device going down, Stop using ICT table */
  1563. iwl_disable_ict(priv);
  1564. spin_lock_irqsave(&priv->lock, flags);
  1565. iwl_clear_bit(priv, CSR_GP_CNTRL,
  1566. CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
  1567. spin_unlock_irqrestore(&priv->lock, flags);
  1568. iwl_txq_ctx_stop(priv);
  1569. iwl_rxq_stop(priv);
  1570. iwl_write_prph(priv, APMG_CLK_DIS_REG,
  1571. APMG_CLK_VAL_DMA_CLK_RQT);
  1572. udelay(5);
  1573. /* FIXME: apm_ops.suspend(priv) */
  1574. if (exit_pending)
  1575. priv->cfg->ops->lib->apm_ops.stop(priv);
  1576. else
  1577. priv->cfg->ops->lib->apm_ops.reset(priv);
  1578. exit:
  1579. memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
  1580. if (priv->ibss_beacon)
  1581. dev_kfree_skb(priv->ibss_beacon);
  1582. priv->ibss_beacon = NULL;
  1583. /* clear out any free frames */
  1584. iwl_clear_free_frames(priv);
  1585. }
  1586. static void iwl_down(struct iwl_priv *priv)
  1587. {
  1588. mutex_lock(&priv->mutex);
  1589. __iwl_down(priv);
  1590. mutex_unlock(&priv->mutex);
  1591. iwl_cancel_deferred_work(priv);
  1592. }
  1593. #define HW_READY_TIMEOUT (50)
  1594. static int iwl_set_hw_ready(struct iwl_priv *priv)
  1595. {
  1596. int ret = 0;
  1597. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1598. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY);
  1599. /* See if we got it */
  1600. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  1601. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1602. CSR_HW_IF_CONFIG_REG_BIT_NIC_READY,
  1603. HW_READY_TIMEOUT);
  1604. if (ret != -ETIMEDOUT)
  1605. priv->hw_ready = true;
  1606. else
  1607. priv->hw_ready = false;
  1608. IWL_DEBUG_INFO(priv, "hardware %s\n",
  1609. (priv->hw_ready == 1) ? "ready" : "not ready");
  1610. return ret;
  1611. }
  1612. static int iwl_prepare_card_hw(struct iwl_priv *priv)
  1613. {
  1614. int ret = 0;
  1615. IWL_DEBUG_INFO(priv, "iwl_prepare_card_hw enter \n");
  1616. ret = iwl_set_hw_ready(priv);
  1617. if (priv->hw_ready)
  1618. return ret;
  1619. /* If HW is not ready, prepare the conditions to check again */
  1620. iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
  1621. CSR_HW_IF_CONFIG_REG_PREPARE);
  1622. ret = iwl_poll_bit(priv, CSR_HW_IF_CONFIG_REG,
  1623. ~CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE,
  1624. CSR_HW_IF_CONFIG_REG_BIT_NIC_PREPARE_DONE, 150000);
  1625. /* HW should be ready by now, check again. */
  1626. if (ret != -ETIMEDOUT)
  1627. iwl_set_hw_ready(priv);
  1628. return ret;
  1629. }
  1630. #define MAX_HW_RESTARTS 5
  1631. static int __iwl_up(struct iwl_priv *priv)
  1632. {
  1633. int i;
  1634. int ret;
  1635. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1636. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  1637. return -EIO;
  1638. }
  1639. if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
  1640. IWL_ERR(priv, "ucode not available for device bringup\n");
  1641. return -EIO;
  1642. }
  1643. iwl_prepare_card_hw(priv);
  1644. if (!priv->hw_ready) {
  1645. IWL_WARN(priv, "Exit HW not ready\n");
  1646. return -EIO;
  1647. }
  1648. /* If platform's RF_KILL switch is NOT set to KILL */
  1649. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1650. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1651. else
  1652. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1653. if (iwl_is_rfkill(priv)) {
  1654. wiphy_rfkill_set_hw_state(priv->hw->wiphy, true);
  1655. iwl_enable_interrupts(priv);
  1656. IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
  1657. return 0;
  1658. }
  1659. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1660. ret = iwl_hw_nic_init(priv);
  1661. if (ret) {
  1662. IWL_ERR(priv, "Unable to init nic\n");
  1663. return ret;
  1664. }
  1665. /* make sure rfkill handshake bits are cleared */
  1666. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1667. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1668. CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
  1669. /* clear (again), then enable host interrupts */
  1670. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1671. iwl_enable_interrupts(priv);
  1672. /* really make sure rfkill handshake bits are cleared */
  1673. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1674. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
  1675. /* Copy original ucode data image from disk into backup cache.
  1676. * This will be used to initialize the on-board processor's
  1677. * data SRAM for a clean start when the runtime program first loads. */
  1678. memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
  1679. priv->ucode_data.len);
  1680. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  1681. iwl_clear_stations_table(priv);
  1682. /* load bootstrap state machine,
  1683. * load bootstrap program into processor's memory,
  1684. * prepare to load the "initialize" uCode */
  1685. ret = priv->cfg->ops->lib->load_ucode(priv);
  1686. if (ret) {
  1687. IWL_ERR(priv, "Unable to set up bootstrap uCode: %d\n",
  1688. ret);
  1689. continue;
  1690. }
  1691. /* start card; "initialize" will load runtime ucode */
  1692. iwl_nic_start(priv);
  1693. IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
  1694. return 0;
  1695. }
  1696. set_bit(STATUS_EXIT_PENDING, &priv->status);
  1697. __iwl_down(priv);
  1698. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1699. /* tried to restart and config the device for as long as our
  1700. * patience could withstand */
  1701. IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
  1702. return -EIO;
  1703. }
  1704. /*****************************************************************************
  1705. *
  1706. * Workqueue callbacks
  1707. *
  1708. *****************************************************************************/
  1709. static void iwl_bg_init_alive_start(struct work_struct *data)
  1710. {
  1711. struct iwl_priv *priv =
  1712. container_of(data, struct iwl_priv, init_alive_start.work);
  1713. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1714. return;
  1715. mutex_lock(&priv->mutex);
  1716. priv->cfg->ops->lib->init_alive_start(priv);
  1717. mutex_unlock(&priv->mutex);
  1718. }
  1719. static void iwl_bg_alive_start(struct work_struct *data)
  1720. {
  1721. struct iwl_priv *priv =
  1722. container_of(data, struct iwl_priv, alive_start.work);
  1723. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1724. return;
  1725. /* enable dram interrupt */
  1726. iwl_reset_ict(priv);
  1727. mutex_lock(&priv->mutex);
  1728. iwl_alive_start(priv);
  1729. mutex_unlock(&priv->mutex);
  1730. }
  1731. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  1732. {
  1733. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1734. run_time_calib_work);
  1735. mutex_lock(&priv->mutex);
  1736. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  1737. test_bit(STATUS_SCANNING, &priv->status)) {
  1738. mutex_unlock(&priv->mutex);
  1739. return;
  1740. }
  1741. if (priv->start_calib) {
  1742. iwl_chain_noise_calibration(priv, &priv->statistics);
  1743. iwl_sensitivity_calibration(priv, &priv->statistics);
  1744. }
  1745. mutex_unlock(&priv->mutex);
  1746. return;
  1747. }
  1748. static void iwl_bg_up(struct work_struct *data)
  1749. {
  1750. struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
  1751. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1752. return;
  1753. mutex_lock(&priv->mutex);
  1754. __iwl_up(priv);
  1755. mutex_unlock(&priv->mutex);
  1756. }
  1757. static void iwl_bg_restart(struct work_struct *data)
  1758. {
  1759. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  1760. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1761. return;
  1762. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  1763. mutex_lock(&priv->mutex);
  1764. priv->vif = NULL;
  1765. priv->is_open = 0;
  1766. mutex_unlock(&priv->mutex);
  1767. iwl_down(priv);
  1768. ieee80211_restart_hw(priv->hw);
  1769. } else {
  1770. iwl_down(priv);
  1771. queue_work(priv->workqueue, &priv->up);
  1772. }
  1773. }
  1774. static void iwl_bg_rx_replenish(struct work_struct *data)
  1775. {
  1776. struct iwl_priv *priv =
  1777. container_of(data, struct iwl_priv, rx_replenish);
  1778. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1779. return;
  1780. mutex_lock(&priv->mutex);
  1781. iwl_rx_replenish(priv);
  1782. mutex_unlock(&priv->mutex);
  1783. }
  1784. #define IWL_DELAY_NEXT_SCAN (HZ*2)
  1785. void iwl_post_associate(struct iwl_priv *priv)
  1786. {
  1787. struct ieee80211_conf *conf = NULL;
  1788. int ret = 0;
  1789. unsigned long flags;
  1790. if (priv->iw_mode == NL80211_IFTYPE_AP) {
  1791. IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
  1792. return;
  1793. }
  1794. IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
  1795. priv->assoc_id, priv->active_rxon.bssid_addr);
  1796. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1797. return;
  1798. if (!priv->vif || !priv->is_open)
  1799. return;
  1800. iwl_scan_cancel_timeout(priv, 200);
  1801. conf = ieee80211_get_hw_conf(priv->hw);
  1802. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1803. iwlcore_commit_rxon(priv);
  1804. iwl_setup_rxon_timing(priv);
  1805. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  1806. sizeof(priv->rxon_timing), &priv->rxon_timing);
  1807. if (ret)
  1808. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  1809. "Attempting to continue.\n");
  1810. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1811. iwl_set_rxon_ht(priv, &priv->current_ht_config);
  1812. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1813. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1814. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  1815. IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
  1816. priv->assoc_id, priv->beacon_int);
  1817. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  1818. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1819. else
  1820. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1821. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  1822. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1823. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  1824. else
  1825. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1826. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  1827. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  1828. }
  1829. iwlcore_commit_rxon(priv);
  1830. switch (priv->iw_mode) {
  1831. case NL80211_IFTYPE_STATION:
  1832. break;
  1833. case NL80211_IFTYPE_ADHOC:
  1834. /* assume default assoc id */
  1835. priv->assoc_id = 1;
  1836. iwl_rxon_add_station(priv, priv->bssid, 0);
  1837. iwl_send_beacon_cmd(priv);
  1838. break;
  1839. default:
  1840. IWL_ERR(priv, "%s Should not be called in %d mode\n",
  1841. __func__, priv->iw_mode);
  1842. break;
  1843. }
  1844. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  1845. priv->assoc_station_added = 1;
  1846. spin_lock_irqsave(&priv->lock, flags);
  1847. iwl_activate_qos(priv, 0);
  1848. spin_unlock_irqrestore(&priv->lock, flags);
  1849. /* the chain noise calibration will enabled PM upon completion
  1850. * If chain noise has already been run, then we need to enable
  1851. * power management here */
  1852. if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
  1853. iwl_power_update_mode(priv, false);
  1854. /* Enable Rx differential gain and sensitivity calibrations */
  1855. iwl_chain_noise_reset(priv);
  1856. priv->start_calib = 1;
  1857. }
  1858. /*****************************************************************************
  1859. *
  1860. * mac80211 entry point functions
  1861. *
  1862. *****************************************************************************/
  1863. #define UCODE_READY_TIMEOUT (4 * HZ)
  1864. static int iwl_mac_start(struct ieee80211_hw *hw)
  1865. {
  1866. struct iwl_priv *priv = hw->priv;
  1867. int ret;
  1868. IWL_DEBUG_MAC80211(priv, "enter\n");
  1869. /* we should be verifying the device is ready to be opened */
  1870. mutex_lock(&priv->mutex);
  1871. /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
  1872. * ucode filename and max sizes are card-specific. */
  1873. if (!priv->ucode_code.len) {
  1874. ret = iwl_read_ucode(priv);
  1875. if (ret) {
  1876. IWL_ERR(priv, "Could not read microcode: %d\n", ret);
  1877. mutex_unlock(&priv->mutex);
  1878. return ret;
  1879. }
  1880. }
  1881. ret = __iwl_up(priv);
  1882. mutex_unlock(&priv->mutex);
  1883. if (ret)
  1884. return ret;
  1885. if (iwl_is_rfkill(priv))
  1886. goto out;
  1887. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  1888. /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
  1889. * mac80211 will not be run successfully. */
  1890. ret = wait_event_interruptible_timeout(priv->wait_command_queue,
  1891. test_bit(STATUS_READY, &priv->status),
  1892. UCODE_READY_TIMEOUT);
  1893. if (!ret) {
  1894. if (!test_bit(STATUS_READY, &priv->status)) {
  1895. IWL_ERR(priv, "START_ALIVE timeout after %dms.\n",
  1896. jiffies_to_msecs(UCODE_READY_TIMEOUT));
  1897. return -ETIMEDOUT;
  1898. }
  1899. }
  1900. out:
  1901. priv->is_open = 1;
  1902. IWL_DEBUG_MAC80211(priv, "leave\n");
  1903. return 0;
  1904. }
  1905. static void iwl_mac_stop(struct ieee80211_hw *hw)
  1906. {
  1907. struct iwl_priv *priv = hw->priv;
  1908. IWL_DEBUG_MAC80211(priv, "enter\n");
  1909. if (!priv->is_open)
  1910. return;
  1911. priv->is_open = 0;
  1912. if (iwl_is_ready_rf(priv) || test_bit(STATUS_SCAN_HW, &priv->status)) {
  1913. /* stop mac, cancel any scan request and clear
  1914. * RXON_FILTER_ASSOC_MSK BIT
  1915. */
  1916. mutex_lock(&priv->mutex);
  1917. iwl_scan_cancel_timeout(priv, 100);
  1918. mutex_unlock(&priv->mutex);
  1919. }
  1920. iwl_down(priv);
  1921. flush_workqueue(priv->workqueue);
  1922. /* enable interrupts again in order to receive rfkill changes */
  1923. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1924. iwl_enable_interrupts(priv);
  1925. IWL_DEBUG_MAC80211(priv, "leave\n");
  1926. }
  1927. static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  1928. {
  1929. struct iwl_priv *priv = hw->priv;
  1930. IWL_DEBUG_MACDUMP(priv, "enter\n");
  1931. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  1932. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  1933. if (iwl_tx_skb(priv, skb))
  1934. dev_kfree_skb_any(skb);
  1935. IWL_DEBUG_MACDUMP(priv, "leave\n");
  1936. return NETDEV_TX_OK;
  1937. }
  1938. void iwl_config_ap(struct iwl_priv *priv)
  1939. {
  1940. int ret = 0;
  1941. unsigned long flags;
  1942. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1943. return;
  1944. /* The following should be done only at AP bring up */
  1945. if (!iwl_is_associated(priv)) {
  1946. /* RXON - unassoc (to set timing command) */
  1947. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1948. iwlcore_commit_rxon(priv);
  1949. /* RXON Timing */
  1950. iwl_setup_rxon_timing(priv);
  1951. ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
  1952. sizeof(priv->rxon_timing), &priv->rxon_timing);
  1953. if (ret)
  1954. IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
  1955. "Attempting to continue.\n");
  1956. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1957. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1958. /* FIXME: what should be the assoc_id for AP? */
  1959. priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
  1960. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  1961. priv->staging_rxon.flags |=
  1962. RXON_FLG_SHORT_PREAMBLE_MSK;
  1963. else
  1964. priv->staging_rxon.flags &=
  1965. ~RXON_FLG_SHORT_PREAMBLE_MSK;
  1966. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
  1967. if (priv->assoc_capability &
  1968. WLAN_CAPABILITY_SHORT_SLOT_TIME)
  1969. priv->staging_rxon.flags |=
  1970. RXON_FLG_SHORT_SLOT_MSK;
  1971. else
  1972. priv->staging_rxon.flags &=
  1973. ~RXON_FLG_SHORT_SLOT_MSK;
  1974. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  1975. priv->staging_rxon.flags &=
  1976. ~RXON_FLG_SHORT_SLOT_MSK;
  1977. }
  1978. /* restore RXON assoc */
  1979. priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1980. iwlcore_commit_rxon(priv);
  1981. spin_lock_irqsave(&priv->lock, flags);
  1982. iwl_activate_qos(priv, 1);
  1983. spin_unlock_irqrestore(&priv->lock, flags);
  1984. iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
  1985. }
  1986. iwl_send_beacon_cmd(priv);
  1987. /* FIXME - we need to add code here to detect a totally new
  1988. * configuration, reset the AP, unassoc, rxon timing, assoc,
  1989. * clear sta table, add BCAST sta... */
  1990. }
  1991. static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
  1992. struct ieee80211_key_conf *keyconf, const u8 *addr,
  1993. u32 iv32, u16 *phase1key)
  1994. {
  1995. struct iwl_priv *priv = hw->priv;
  1996. IWL_DEBUG_MAC80211(priv, "enter\n");
  1997. iwl_update_tkip_key(priv, keyconf, addr, iv32, phase1key);
  1998. IWL_DEBUG_MAC80211(priv, "leave\n");
  1999. }
  2000. static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2001. struct ieee80211_vif *vif,
  2002. struct ieee80211_sta *sta,
  2003. struct ieee80211_key_conf *key)
  2004. {
  2005. struct iwl_priv *priv = hw->priv;
  2006. const u8 *addr;
  2007. int ret;
  2008. u8 sta_id;
  2009. bool is_default_wep_key = false;
  2010. IWL_DEBUG_MAC80211(priv, "enter\n");
  2011. if (priv->cfg->mod_params->sw_crypto) {
  2012. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2013. return -EOPNOTSUPP;
  2014. }
  2015. addr = sta ? sta->addr : iwl_bcast_addr;
  2016. sta_id = iwl_find_station(priv, addr);
  2017. if (sta_id == IWL_INVALID_STATION) {
  2018. IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
  2019. addr);
  2020. return -EINVAL;
  2021. }
  2022. mutex_lock(&priv->mutex);
  2023. iwl_scan_cancel_timeout(priv, 100);
  2024. mutex_unlock(&priv->mutex);
  2025. /* If we are getting WEP group key and we didn't receive any key mapping
  2026. * so far, we are in legacy wep mode (group key only), otherwise we are
  2027. * in 1X mode.
  2028. * In legacy wep mode, we use another host command to the uCode */
  2029. if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
  2030. priv->iw_mode != NL80211_IFTYPE_AP) {
  2031. if (cmd == SET_KEY)
  2032. is_default_wep_key = !priv->key_mapping_key;
  2033. else
  2034. is_default_wep_key =
  2035. (key->hw_key_idx == HW_KEY_DEFAULT);
  2036. }
  2037. switch (cmd) {
  2038. case SET_KEY:
  2039. if (is_default_wep_key)
  2040. ret = iwl_set_default_wep_key(priv, key);
  2041. else
  2042. ret = iwl_set_dynamic_key(priv, key, sta_id);
  2043. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2044. break;
  2045. case DISABLE_KEY:
  2046. if (is_default_wep_key)
  2047. ret = iwl_remove_default_wep_key(priv, key);
  2048. else
  2049. ret = iwl_remove_dynamic_key(priv, key, sta_id);
  2050. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2051. break;
  2052. default:
  2053. ret = -EINVAL;
  2054. }
  2055. IWL_DEBUG_MAC80211(priv, "leave\n");
  2056. return ret;
  2057. }
  2058. static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
  2059. enum ieee80211_ampdu_mlme_action action,
  2060. struct ieee80211_sta *sta, u16 tid, u16 *ssn)
  2061. {
  2062. struct iwl_priv *priv = hw->priv;
  2063. int ret;
  2064. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2065. sta->addr, tid);
  2066. if (!(priv->cfg->sku & IWL_SKU_N))
  2067. return -EACCES;
  2068. switch (action) {
  2069. case IEEE80211_AMPDU_RX_START:
  2070. IWL_DEBUG_HT(priv, "start Rx\n");
  2071. return iwl_sta_rx_agg_start(priv, sta->addr, tid, *ssn);
  2072. case IEEE80211_AMPDU_RX_STOP:
  2073. IWL_DEBUG_HT(priv, "stop Rx\n");
  2074. ret = iwl_sta_rx_agg_stop(priv, sta->addr, tid);
  2075. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2076. return 0;
  2077. else
  2078. return ret;
  2079. case IEEE80211_AMPDU_TX_START:
  2080. IWL_DEBUG_HT(priv, "start Tx\n");
  2081. return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
  2082. case IEEE80211_AMPDU_TX_STOP:
  2083. IWL_DEBUG_HT(priv, "stop Tx\n");
  2084. ret = iwl_tx_agg_stop(priv, sta->addr, tid);
  2085. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2086. return 0;
  2087. else
  2088. return ret;
  2089. default:
  2090. IWL_DEBUG_HT(priv, "unknown\n");
  2091. return -EINVAL;
  2092. break;
  2093. }
  2094. return 0;
  2095. }
  2096. static int iwl_mac_get_stats(struct ieee80211_hw *hw,
  2097. struct ieee80211_low_level_stats *stats)
  2098. {
  2099. struct iwl_priv *priv = hw->priv;
  2100. priv = hw->priv;
  2101. IWL_DEBUG_MAC80211(priv, "enter\n");
  2102. IWL_DEBUG_MAC80211(priv, "leave\n");
  2103. return 0;
  2104. }
  2105. /*****************************************************************************
  2106. *
  2107. * sysfs attributes
  2108. *
  2109. *****************************************************************************/
  2110. #ifdef CONFIG_IWLWIFI_DEBUG
  2111. /*
  2112. * The following adds a new attribute to the sysfs representation
  2113. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  2114. * used for controlling the debug level.
  2115. *
  2116. * See the level definitions in iwl for details.
  2117. *
  2118. * The debug_level being managed using sysfs below is a per device debug
  2119. * level that is used instead of the global debug level if it (the per
  2120. * device debug level) is set.
  2121. */
  2122. static ssize_t show_debug_level(struct device *d,
  2123. struct device_attribute *attr, char *buf)
  2124. {
  2125. struct iwl_priv *priv = dev_get_drvdata(d);
  2126. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  2127. }
  2128. static ssize_t store_debug_level(struct device *d,
  2129. struct device_attribute *attr,
  2130. const char *buf, size_t count)
  2131. {
  2132. struct iwl_priv *priv = dev_get_drvdata(d);
  2133. unsigned long val;
  2134. int ret;
  2135. ret = strict_strtoul(buf, 0, &val);
  2136. if (ret)
  2137. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  2138. else {
  2139. priv->debug_level = val;
  2140. if (iwl_alloc_traffic_mem(priv))
  2141. IWL_ERR(priv,
  2142. "Not enough memory to generate traffic log\n");
  2143. }
  2144. return strnlen(buf, count);
  2145. }
  2146. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  2147. show_debug_level, store_debug_level);
  2148. #endif /* CONFIG_IWLWIFI_DEBUG */
  2149. static ssize_t show_temperature(struct device *d,
  2150. struct device_attribute *attr, char *buf)
  2151. {
  2152. struct iwl_priv *priv = dev_get_drvdata(d);
  2153. if (!iwl_is_alive(priv))
  2154. return -EAGAIN;
  2155. return sprintf(buf, "%d\n", priv->temperature);
  2156. }
  2157. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  2158. static ssize_t show_tx_power(struct device *d,
  2159. struct device_attribute *attr, char *buf)
  2160. {
  2161. struct iwl_priv *priv = dev_get_drvdata(d);
  2162. if (!iwl_is_ready_rf(priv))
  2163. return sprintf(buf, "off\n");
  2164. else
  2165. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  2166. }
  2167. static ssize_t store_tx_power(struct device *d,
  2168. struct device_attribute *attr,
  2169. const char *buf, size_t count)
  2170. {
  2171. struct iwl_priv *priv = dev_get_drvdata(d);
  2172. unsigned long val;
  2173. int ret;
  2174. ret = strict_strtoul(buf, 10, &val);
  2175. if (ret)
  2176. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  2177. else {
  2178. ret = iwl_set_tx_power(priv, val, false);
  2179. if (ret)
  2180. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  2181. ret);
  2182. else
  2183. ret = count;
  2184. }
  2185. return ret;
  2186. }
  2187. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  2188. static ssize_t show_flags(struct device *d,
  2189. struct device_attribute *attr, char *buf)
  2190. {
  2191. struct iwl_priv *priv = dev_get_drvdata(d);
  2192. return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
  2193. }
  2194. static ssize_t store_flags(struct device *d,
  2195. struct device_attribute *attr,
  2196. const char *buf, size_t count)
  2197. {
  2198. struct iwl_priv *priv = dev_get_drvdata(d);
  2199. unsigned long val;
  2200. u32 flags;
  2201. int ret = strict_strtoul(buf, 0, &val);
  2202. if (ret)
  2203. return ret;
  2204. flags = (u32)val;
  2205. mutex_lock(&priv->mutex);
  2206. if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
  2207. /* Cancel any currently running scans... */
  2208. if (iwl_scan_cancel_timeout(priv, 100))
  2209. IWL_WARN(priv, "Could not cancel scan.\n");
  2210. else {
  2211. IWL_DEBUG_INFO(priv, "Commit rxon.flags = 0x%04X\n", flags);
  2212. priv->staging_rxon.flags = cpu_to_le32(flags);
  2213. iwlcore_commit_rxon(priv);
  2214. }
  2215. }
  2216. mutex_unlock(&priv->mutex);
  2217. return count;
  2218. }
  2219. static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
  2220. static ssize_t show_filter_flags(struct device *d,
  2221. struct device_attribute *attr, char *buf)
  2222. {
  2223. struct iwl_priv *priv = dev_get_drvdata(d);
  2224. return sprintf(buf, "0x%04X\n",
  2225. le32_to_cpu(priv->active_rxon.filter_flags));
  2226. }
  2227. static ssize_t store_filter_flags(struct device *d,
  2228. struct device_attribute *attr,
  2229. const char *buf, size_t count)
  2230. {
  2231. struct iwl_priv *priv = dev_get_drvdata(d);
  2232. unsigned long val;
  2233. u32 filter_flags;
  2234. int ret = strict_strtoul(buf, 0, &val);
  2235. if (ret)
  2236. return ret;
  2237. filter_flags = (u32)val;
  2238. mutex_lock(&priv->mutex);
  2239. if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
  2240. /* Cancel any currently running scans... */
  2241. if (iwl_scan_cancel_timeout(priv, 100))
  2242. IWL_WARN(priv, "Could not cancel scan.\n");
  2243. else {
  2244. IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
  2245. "0x%04X\n", filter_flags);
  2246. priv->staging_rxon.filter_flags =
  2247. cpu_to_le32(filter_flags);
  2248. iwlcore_commit_rxon(priv);
  2249. }
  2250. }
  2251. mutex_unlock(&priv->mutex);
  2252. return count;
  2253. }
  2254. static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
  2255. store_filter_flags);
  2256. static ssize_t show_statistics(struct device *d,
  2257. struct device_attribute *attr, char *buf)
  2258. {
  2259. struct iwl_priv *priv = dev_get_drvdata(d);
  2260. u32 size = sizeof(struct iwl_notif_statistics);
  2261. u32 len = 0, ofs = 0;
  2262. u8 *data = (u8 *)&priv->statistics;
  2263. int rc = 0;
  2264. if (!iwl_is_alive(priv))
  2265. return -EAGAIN;
  2266. mutex_lock(&priv->mutex);
  2267. rc = iwl_send_statistics_request(priv, 0);
  2268. mutex_unlock(&priv->mutex);
  2269. if (rc) {
  2270. len = sprintf(buf,
  2271. "Error sending statistics request: 0x%08X\n", rc);
  2272. return len;
  2273. }
  2274. while (size && (PAGE_SIZE - len)) {
  2275. hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
  2276. PAGE_SIZE - len, 1);
  2277. len = strlen(buf);
  2278. if (PAGE_SIZE - len)
  2279. buf[len++] = '\n';
  2280. ofs += 16;
  2281. size -= min(size, 16U);
  2282. }
  2283. return len;
  2284. }
  2285. static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
  2286. /*****************************************************************************
  2287. *
  2288. * driver setup and teardown
  2289. *
  2290. *****************************************************************************/
  2291. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  2292. {
  2293. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  2294. init_waitqueue_head(&priv->wait_command_queue);
  2295. INIT_WORK(&priv->up, iwl_bg_up);
  2296. INIT_WORK(&priv->restart, iwl_bg_restart);
  2297. INIT_WORK(&priv->rx_replenish, iwl_bg_rx_replenish);
  2298. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  2299. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  2300. INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
  2301. INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
  2302. iwl_setup_scan_deferred_work(priv);
  2303. if (priv->cfg->ops->lib->setup_deferred_work)
  2304. priv->cfg->ops->lib->setup_deferred_work(priv);
  2305. init_timer(&priv->statistics_periodic);
  2306. priv->statistics_periodic.data = (unsigned long)priv;
  2307. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  2308. if (!priv->cfg->use_isr_legacy)
  2309. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  2310. iwl_irq_tasklet, (unsigned long)priv);
  2311. else
  2312. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  2313. iwl_irq_tasklet_legacy, (unsigned long)priv);
  2314. }
  2315. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  2316. {
  2317. if (priv->cfg->ops->lib->cancel_deferred_work)
  2318. priv->cfg->ops->lib->cancel_deferred_work(priv);
  2319. cancel_delayed_work_sync(&priv->init_alive_start);
  2320. cancel_delayed_work(&priv->scan_check);
  2321. cancel_delayed_work(&priv->alive_start);
  2322. cancel_work_sync(&priv->beacon_update);
  2323. del_timer_sync(&priv->statistics_periodic);
  2324. }
  2325. static struct attribute *iwl_sysfs_entries[] = {
  2326. &dev_attr_flags.attr,
  2327. &dev_attr_filter_flags.attr,
  2328. &dev_attr_statistics.attr,
  2329. &dev_attr_temperature.attr,
  2330. &dev_attr_tx_power.attr,
  2331. #ifdef CONFIG_IWLWIFI_DEBUG
  2332. &dev_attr_debug_level.attr,
  2333. #endif
  2334. NULL
  2335. };
  2336. static struct attribute_group iwl_attribute_group = {
  2337. .name = NULL, /* put in device directory */
  2338. .attrs = iwl_sysfs_entries,
  2339. };
  2340. static struct ieee80211_ops iwl_hw_ops = {
  2341. .tx = iwl_mac_tx,
  2342. .start = iwl_mac_start,
  2343. .stop = iwl_mac_stop,
  2344. .add_interface = iwl_mac_add_interface,
  2345. .remove_interface = iwl_mac_remove_interface,
  2346. .config = iwl_mac_config,
  2347. .configure_filter = iwl_configure_filter,
  2348. .set_key = iwl_mac_set_key,
  2349. .update_tkip_key = iwl_mac_update_tkip_key,
  2350. .get_stats = iwl_mac_get_stats,
  2351. .get_tx_stats = iwl_mac_get_tx_stats,
  2352. .conf_tx = iwl_mac_conf_tx,
  2353. .reset_tsf = iwl_mac_reset_tsf,
  2354. .bss_info_changed = iwl_bss_info_changed,
  2355. .ampdu_action = iwl_mac_ampdu_action,
  2356. .hw_scan = iwl_mac_hw_scan
  2357. };
  2358. static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  2359. {
  2360. int err = 0;
  2361. struct iwl_priv *priv;
  2362. struct ieee80211_hw *hw;
  2363. struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
  2364. unsigned long flags;
  2365. u16 pci_cmd;
  2366. /************************
  2367. * 1. Allocating HW data
  2368. ************************/
  2369. /* Disabling hardware scan means that mac80211 will perform scans
  2370. * "the hard way", rather than using device's scan. */
  2371. if (cfg->mod_params->disable_hw_scan) {
  2372. if (iwl_debug_level & IWL_DL_INFO)
  2373. dev_printk(KERN_DEBUG, &(pdev->dev),
  2374. "Disabling hw_scan\n");
  2375. iwl_hw_ops.hw_scan = NULL;
  2376. }
  2377. hw = iwl_alloc_all(cfg, &iwl_hw_ops);
  2378. if (!hw) {
  2379. err = -ENOMEM;
  2380. goto out;
  2381. }
  2382. priv = hw->priv;
  2383. /* At this point both hw and priv are allocated. */
  2384. SET_IEEE80211_DEV(hw, &pdev->dev);
  2385. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  2386. priv->cfg = cfg;
  2387. priv->pci_dev = pdev;
  2388. priv->inta_mask = CSR_INI_SET_MASK;
  2389. #ifdef CONFIG_IWLWIFI_DEBUG
  2390. atomic_set(&priv->restrict_refcnt, 0);
  2391. #endif
  2392. if (iwl_alloc_traffic_mem(priv))
  2393. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  2394. /**************************
  2395. * 2. Initializing PCI bus
  2396. **************************/
  2397. if (pci_enable_device(pdev)) {
  2398. err = -ENODEV;
  2399. goto out_ieee80211_free_hw;
  2400. }
  2401. pci_set_master(pdev);
  2402. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
  2403. if (!err)
  2404. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
  2405. if (err) {
  2406. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  2407. if (!err)
  2408. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  2409. /* both attempts failed: */
  2410. if (err) {
  2411. IWL_WARN(priv, "No suitable DMA available.\n");
  2412. goto out_pci_disable_device;
  2413. }
  2414. }
  2415. err = pci_request_regions(pdev, DRV_NAME);
  2416. if (err)
  2417. goto out_pci_disable_device;
  2418. pci_set_drvdata(pdev, priv);
  2419. /***********************
  2420. * 3. Read REV register
  2421. ***********************/
  2422. priv->hw_base = pci_iomap(pdev, 0, 0);
  2423. if (!priv->hw_base) {
  2424. err = -ENODEV;
  2425. goto out_pci_release_regions;
  2426. }
  2427. IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
  2428. (unsigned long long) pci_resource_len(pdev, 0));
  2429. IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
  2430. /* this spin lock will be used in apm_ops.init and EEPROM access
  2431. * we should init now
  2432. */
  2433. spin_lock_init(&priv->reg_lock);
  2434. iwl_hw_detect(priv);
  2435. IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s REV=0x%X\n",
  2436. priv->cfg->name, priv->hw_rev);
  2437. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  2438. * PCI Tx retries from interfering with C3 CPU state */
  2439. pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
  2440. iwl_prepare_card_hw(priv);
  2441. if (!priv->hw_ready) {
  2442. IWL_WARN(priv, "Failed, HW not ready\n");
  2443. goto out_iounmap;
  2444. }
  2445. /* amp init */
  2446. err = priv->cfg->ops->lib->apm_ops.init(priv);
  2447. if (err < 0) {
  2448. IWL_ERR(priv, "Failed to init APMG\n");
  2449. goto out_iounmap;
  2450. }
  2451. /*****************
  2452. * 4. Read EEPROM
  2453. *****************/
  2454. /* Read the EEPROM */
  2455. err = iwl_eeprom_init(priv);
  2456. if (err) {
  2457. IWL_ERR(priv, "Unable to init EEPROM\n");
  2458. goto out_iounmap;
  2459. }
  2460. err = iwl_eeprom_check_version(priv);
  2461. if (err)
  2462. goto out_free_eeprom;
  2463. /* extract MAC Address */
  2464. iwl_eeprom_get_mac(priv, priv->mac_addr);
  2465. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
  2466. SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
  2467. /************************
  2468. * 5. Setup HW constants
  2469. ************************/
  2470. if (iwl_set_hw_params(priv)) {
  2471. IWL_ERR(priv, "failed to set hw parameters\n");
  2472. goto out_free_eeprom;
  2473. }
  2474. /*******************
  2475. * 6. Setup priv
  2476. *******************/
  2477. err = iwl_init_drv(priv);
  2478. if (err)
  2479. goto out_free_eeprom;
  2480. /* At this point both hw and priv are initialized. */
  2481. /********************
  2482. * 7. Setup services
  2483. ********************/
  2484. spin_lock_irqsave(&priv->lock, flags);
  2485. iwl_disable_interrupts(priv);
  2486. spin_unlock_irqrestore(&priv->lock, flags);
  2487. pci_enable_msi(priv->pci_dev);
  2488. iwl_alloc_isr_ict(priv);
  2489. err = request_irq(priv->pci_dev->irq, priv->cfg->ops->lib->isr,
  2490. IRQF_SHARED, DRV_NAME, priv);
  2491. if (err) {
  2492. IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
  2493. goto out_disable_msi;
  2494. }
  2495. err = sysfs_create_group(&pdev->dev.kobj, &iwl_attribute_group);
  2496. if (err) {
  2497. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  2498. goto out_free_irq;
  2499. }
  2500. iwl_setup_deferred_work(priv);
  2501. iwl_setup_rx_handlers(priv);
  2502. /**********************************
  2503. * 8. Setup and register mac80211
  2504. **********************************/
  2505. /* enable interrupts if needed: hw bug w/a */
  2506. pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
  2507. if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
  2508. pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
  2509. pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
  2510. }
  2511. iwl_enable_interrupts(priv);
  2512. err = iwl_setup_mac(priv);
  2513. if (err)
  2514. goto out_remove_sysfs;
  2515. err = iwl_dbgfs_register(priv, DRV_NAME);
  2516. if (err)
  2517. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  2518. /* If platform's RF_KILL switch is NOT set to KILL */
  2519. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  2520. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  2521. else
  2522. set_bit(STATUS_RF_KILL_HW, &priv->status);
  2523. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  2524. test_bit(STATUS_RF_KILL_HW, &priv->status));
  2525. iwl_power_initialize(priv);
  2526. iwl_tt_initialize(priv);
  2527. return 0;
  2528. out_remove_sysfs:
  2529. destroy_workqueue(priv->workqueue);
  2530. priv->workqueue = NULL;
  2531. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  2532. out_free_irq:
  2533. free_irq(priv->pci_dev->irq, priv);
  2534. iwl_free_isr_ict(priv);
  2535. out_disable_msi:
  2536. pci_disable_msi(priv->pci_dev);
  2537. iwl_uninit_drv(priv);
  2538. out_free_eeprom:
  2539. iwl_eeprom_free(priv);
  2540. out_iounmap:
  2541. pci_iounmap(pdev, priv->hw_base);
  2542. out_pci_release_regions:
  2543. pci_set_drvdata(pdev, NULL);
  2544. pci_release_regions(pdev);
  2545. out_pci_disable_device:
  2546. pci_disable_device(pdev);
  2547. out_ieee80211_free_hw:
  2548. iwl_free_traffic_mem(priv);
  2549. ieee80211_free_hw(priv->hw);
  2550. out:
  2551. return err;
  2552. }
  2553. static void __devexit iwl_pci_remove(struct pci_dev *pdev)
  2554. {
  2555. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2556. unsigned long flags;
  2557. if (!priv)
  2558. return;
  2559. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  2560. iwl_dbgfs_unregister(priv);
  2561. sysfs_remove_group(&pdev->dev.kobj, &iwl_attribute_group);
  2562. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  2563. * to be called and iwl_down since we are removing the device
  2564. * we need to set STATUS_EXIT_PENDING bit.
  2565. */
  2566. set_bit(STATUS_EXIT_PENDING, &priv->status);
  2567. if (priv->mac80211_registered) {
  2568. ieee80211_unregister_hw(priv->hw);
  2569. priv->mac80211_registered = 0;
  2570. } else {
  2571. iwl_down(priv);
  2572. }
  2573. iwl_tt_exit(priv);
  2574. /* make sure we flush any pending irq or
  2575. * tasklet for the driver
  2576. */
  2577. spin_lock_irqsave(&priv->lock, flags);
  2578. iwl_disable_interrupts(priv);
  2579. spin_unlock_irqrestore(&priv->lock, flags);
  2580. iwl_synchronize_irq(priv);
  2581. iwl_dealloc_ucode_pci(priv);
  2582. if (priv->rxq.bd)
  2583. iwl_rx_queue_free(priv, &priv->rxq);
  2584. iwl_hw_txq_ctx_free(priv);
  2585. iwl_clear_stations_table(priv);
  2586. iwl_eeprom_free(priv);
  2587. /*netif_stop_queue(dev); */
  2588. flush_workqueue(priv->workqueue);
  2589. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  2590. * priv->workqueue... so we can't take down the workqueue
  2591. * until now... */
  2592. destroy_workqueue(priv->workqueue);
  2593. priv->workqueue = NULL;
  2594. iwl_free_traffic_mem(priv);
  2595. free_irq(priv->pci_dev->irq, priv);
  2596. pci_disable_msi(priv->pci_dev);
  2597. pci_iounmap(pdev, priv->hw_base);
  2598. pci_release_regions(pdev);
  2599. pci_disable_device(pdev);
  2600. pci_set_drvdata(pdev, NULL);
  2601. iwl_uninit_drv(priv);
  2602. iwl_free_isr_ict(priv);
  2603. if (priv->ibss_beacon)
  2604. dev_kfree_skb(priv->ibss_beacon);
  2605. ieee80211_free_hw(priv->hw);
  2606. }
  2607. /*****************************************************************************
  2608. *
  2609. * driver and module entry point
  2610. *
  2611. *****************************************************************************/
  2612. /* Hardware specific file defines the PCI IDs table for that hardware module */
  2613. static struct pci_device_id iwl_hw_card_ids[] = {
  2614. #ifdef CONFIG_IWL4965
  2615. {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
  2616. {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
  2617. #endif /* CONFIG_IWL4965 */
  2618. #ifdef CONFIG_IWL5000
  2619. {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
  2620. {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
  2621. {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
  2622. {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
  2623. {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
  2624. {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
  2625. {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
  2626. {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
  2627. {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
  2628. {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
  2629. /* 5350 WiFi/WiMax */
  2630. {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
  2631. {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
  2632. {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
  2633. /* 5150 Wifi/WiMax */
  2634. {IWL_PCI_DEVICE(0x423C, PCI_ANY_ID, iwl5150_agn_cfg)},
  2635. {IWL_PCI_DEVICE(0x423D, PCI_ANY_ID, iwl5150_agn_cfg)},
  2636. /* 6000/6050 Series */
  2637. {IWL_PCI_DEVICE(0x008D, PCI_ANY_ID, iwl6000h_2agn_cfg)},
  2638. {IWL_PCI_DEVICE(0x008E, PCI_ANY_ID, iwl6000h_2agn_cfg)},
  2639. {IWL_PCI_DEVICE(0x422B, PCI_ANY_ID, iwl6000_3agn_cfg)},
  2640. {IWL_PCI_DEVICE(0x422C, PCI_ANY_ID, iwl6000i_2agn_cfg)},
  2641. {IWL_PCI_DEVICE(0x4238, PCI_ANY_ID, iwl6000_3agn_cfg)},
  2642. {IWL_PCI_DEVICE(0x4239, PCI_ANY_ID, iwl6000i_2agn_cfg)},
  2643. {IWL_PCI_DEVICE(0x0086, PCI_ANY_ID, iwl6050_3agn_cfg)},
  2644. {IWL_PCI_DEVICE(0x0087, PCI_ANY_ID, iwl6050_2agn_cfg)},
  2645. {IWL_PCI_DEVICE(0x0088, PCI_ANY_ID, iwl6050_3agn_cfg)},
  2646. {IWL_PCI_DEVICE(0x0089, PCI_ANY_ID, iwl6050_2agn_cfg)},
  2647. /* 1000 Series WiFi */
  2648. {IWL_PCI_DEVICE(0x0083, PCI_ANY_ID, iwl1000_bgn_cfg)},
  2649. {IWL_PCI_DEVICE(0x0084, PCI_ANY_ID, iwl1000_bgn_cfg)},
  2650. #endif /* CONFIG_IWL5000 */
  2651. {0}
  2652. };
  2653. MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
  2654. static struct pci_driver iwl_driver = {
  2655. .name = DRV_NAME,
  2656. .id_table = iwl_hw_card_ids,
  2657. .probe = iwl_pci_probe,
  2658. .remove = __devexit_p(iwl_pci_remove),
  2659. #ifdef CONFIG_PM
  2660. .suspend = iwl_pci_suspend,
  2661. .resume = iwl_pci_resume,
  2662. #endif
  2663. };
  2664. static int __init iwl_init(void)
  2665. {
  2666. int ret;
  2667. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  2668. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  2669. ret = iwlagn_rate_control_register();
  2670. if (ret) {
  2671. printk(KERN_ERR DRV_NAME
  2672. "Unable to register rate control algorithm: %d\n", ret);
  2673. return ret;
  2674. }
  2675. ret = pci_register_driver(&iwl_driver);
  2676. if (ret) {
  2677. printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
  2678. goto error_register;
  2679. }
  2680. return ret;
  2681. error_register:
  2682. iwlagn_rate_control_unregister();
  2683. return ret;
  2684. }
  2685. static void __exit iwl_exit(void)
  2686. {
  2687. pci_unregister_driver(&iwl_driver);
  2688. iwlagn_rate_control_unregister();
  2689. }
  2690. module_exit(iwl_exit);
  2691. module_init(iwl_init);
  2692. #ifdef CONFIG_IWLWIFI_DEBUG
  2693. module_param_named(debug50, iwl_debug_level, uint, 0444);
  2694. MODULE_PARM_DESC(debug50, "50XX debug output mask (deprecated)");
  2695. module_param_named(debug, iwl_debug_level, uint, 0644);
  2696. MODULE_PARM_DESC(debug, "debug output mask");
  2697. #endif