iwl4965-base.c 102 KB

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