iwl4965-base.c 91 KB

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