iwl-agn.c 94 KB

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