iwl4965-base.c 91 KB

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