iwl-agn.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985
  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. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/slab.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/delay.h>
  35. #include <linux/sched.h>
  36. #include <linux/skbuff.h>
  37. #include <linux/netdevice.h>
  38. #include <linux/wireless.h>
  39. #include <linux/firmware.h>
  40. #include <linux/etherdevice.h>
  41. #include <linux/if_arp.h>
  42. #include <net/mac80211.h>
  43. #include <asm/div64.h>
  44. #include "iwl-eeprom.h"
  45. #include "iwl-dev.h"
  46. #include "iwl-core.h"
  47. #include "iwl-io.h"
  48. #include "iwl-helpers.h"
  49. #include "iwl-sta.h"
  50. #include "iwl-agn-calib.h"
  51. #include "iwl-agn.h"
  52. #include "iwl-bus.h"
  53. #include "iwl-trans.h"
  54. /******************************************************************************
  55. *
  56. * module boiler plate
  57. *
  58. ******************************************************************************/
  59. /*
  60. * module name, copyright, version, etc.
  61. */
  62. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  63. #ifdef CONFIG_IWLWIFI_DEBUG
  64. #define VD "d"
  65. #else
  66. #define VD
  67. #endif
  68. #define DRV_VERSION IWLWIFI_VERSION VD
  69. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  70. MODULE_VERSION(DRV_VERSION);
  71. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  72. MODULE_LICENSE("GPL");
  73. static int iwlagn_ant_coupling;
  74. static bool iwlagn_bt_ch_announce = 1;
  75. void iwl_update_chain_flags(struct iwl_priv *priv)
  76. {
  77. struct iwl_rxon_context *ctx;
  78. for_each_context(priv, ctx) {
  79. iwlagn_set_rxon_chain(priv, ctx);
  80. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  81. iwlagn_commit_rxon(priv, ctx);
  82. }
  83. }
  84. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  85. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  86. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  87. u8 *beacon, u32 frame_size)
  88. {
  89. u16 tim_idx;
  90. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  91. /*
  92. * The index is relative to frame start but we start looking at the
  93. * variable-length part of the beacon.
  94. */
  95. tim_idx = mgmt->u.beacon.variable - beacon;
  96. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  97. while ((tim_idx < (frame_size - 2)) &&
  98. (beacon[tim_idx] != WLAN_EID_TIM))
  99. tim_idx += beacon[tim_idx+1] + 2;
  100. /* If TIM field was found, set variables */
  101. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  102. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  103. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  104. } else
  105. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  106. }
  107. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  108. {
  109. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  110. struct iwl_host_cmd cmd = {
  111. .id = REPLY_TX_BEACON,
  112. .flags = CMD_SYNC,
  113. };
  114. struct ieee80211_tx_info *info;
  115. u32 frame_size;
  116. u32 rate_flags;
  117. u32 rate;
  118. /*
  119. * We have to set up the TX command, the TX Beacon command, and the
  120. * beacon contents.
  121. */
  122. lockdep_assert_held(&priv->mutex);
  123. if (!priv->beacon_ctx) {
  124. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  125. return 0;
  126. }
  127. if (WARN_ON(!priv->beacon_skb))
  128. return -EINVAL;
  129. /* Allocate beacon command */
  130. if (!priv->beacon_cmd)
  131. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  132. tx_beacon_cmd = priv->beacon_cmd;
  133. if (!tx_beacon_cmd)
  134. return -ENOMEM;
  135. frame_size = priv->beacon_skb->len;
  136. /* Set up TX command fields */
  137. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  138. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  139. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  140. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  141. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  142. /* Set up TX beacon command fields */
  143. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  144. frame_size);
  145. /* Set up packet rate and flags */
  146. info = IEEE80211_SKB_CB(priv->beacon_skb);
  147. /*
  148. * Let's set up the rate at least somewhat correctly;
  149. * it will currently not actually be used by the uCode,
  150. * it uses the broadcast station's rate instead.
  151. */
  152. if (info->control.rates[0].idx < 0 ||
  153. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  154. rate = 0;
  155. else
  156. rate = info->control.rates[0].idx;
  157. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  158. priv->hw_params.valid_tx_ant);
  159. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  160. /* In mac80211, rates for 5 GHz start at 0 */
  161. if (info->band == IEEE80211_BAND_5GHZ)
  162. rate += IWL_FIRST_OFDM_RATE;
  163. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  164. rate_flags |= RATE_MCS_CCK_MSK;
  165. tx_beacon_cmd->tx.rate_n_flags =
  166. iwl_hw_set_rate_n_flags(rate, rate_flags);
  167. /* Submit command */
  168. cmd.len[0] = sizeof(*tx_beacon_cmd);
  169. cmd.data[0] = tx_beacon_cmd;
  170. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  171. cmd.len[1] = frame_size;
  172. cmd.data[1] = priv->beacon_skb->data;
  173. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  174. return trans_send_cmd(&priv->trans, &cmd);
  175. }
  176. static void iwl_bg_beacon_update(struct work_struct *work)
  177. {
  178. struct iwl_priv *priv =
  179. container_of(work, struct iwl_priv, beacon_update);
  180. struct sk_buff *beacon;
  181. mutex_lock(&priv->mutex);
  182. if (!priv->beacon_ctx) {
  183. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  184. goto out;
  185. }
  186. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  187. /*
  188. * The ucode will send beacon notifications even in
  189. * IBSS mode, but we don't want to process them. But
  190. * we need to defer the type check to here due to
  191. * requiring locking around the beacon_ctx access.
  192. */
  193. goto out;
  194. }
  195. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  196. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  197. if (!beacon) {
  198. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  199. goto out;
  200. }
  201. /* new beacon skb is allocated every time; dispose previous.*/
  202. dev_kfree_skb(priv->beacon_skb);
  203. priv->beacon_skb = beacon;
  204. iwlagn_send_beacon_cmd(priv);
  205. out:
  206. mutex_unlock(&priv->mutex);
  207. }
  208. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  209. {
  210. struct iwl_priv *priv =
  211. container_of(work, struct iwl_priv, bt_runtime_config);
  212. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  213. return;
  214. /* dont send host command if rf-kill is on */
  215. if (!iwl_is_ready_rf(priv))
  216. return;
  217. iwlagn_send_advance_bt_config(priv);
  218. }
  219. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  220. {
  221. struct iwl_priv *priv =
  222. container_of(work, struct iwl_priv, bt_full_concurrency);
  223. struct iwl_rxon_context *ctx;
  224. mutex_lock(&priv->mutex);
  225. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  226. goto out;
  227. /* dont send host command if rf-kill is on */
  228. if (!iwl_is_ready_rf(priv))
  229. goto out;
  230. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  231. priv->bt_full_concurrent ?
  232. "full concurrency" : "3-wire");
  233. /*
  234. * LQ & RXON updated cmds must be sent before BT Config cmd
  235. * to avoid 3-wire collisions
  236. */
  237. for_each_context(priv, ctx) {
  238. iwlagn_set_rxon_chain(priv, ctx);
  239. iwlagn_commit_rxon(priv, ctx);
  240. }
  241. iwlagn_send_advance_bt_config(priv);
  242. out:
  243. mutex_unlock(&priv->mutex);
  244. }
  245. /**
  246. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  247. *
  248. * This callback is provided in order to send a statistics request.
  249. *
  250. * This timer function is continually reset to execute within
  251. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  252. * was received. We need to ensure we receive the statistics in order
  253. * to update the temperature used for calibrating the TXPOWER.
  254. */
  255. static void iwl_bg_statistics_periodic(unsigned long data)
  256. {
  257. struct iwl_priv *priv = (struct iwl_priv *)data;
  258. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  259. return;
  260. /* dont send host command if rf-kill is on */
  261. if (!iwl_is_ready_rf(priv))
  262. return;
  263. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  264. }
  265. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  266. u32 start_idx, u32 num_events,
  267. u32 mode)
  268. {
  269. u32 i;
  270. u32 ptr; /* SRAM byte address of log data */
  271. u32 ev, time, data; /* event log data */
  272. unsigned long reg_flags;
  273. if (mode == 0)
  274. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  275. else
  276. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  277. /* Make sure device is powered up for SRAM reads */
  278. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  279. if (iwl_grab_nic_access(priv)) {
  280. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  281. return;
  282. }
  283. /* Set starting address; reads will auto-increment */
  284. iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
  285. rmb();
  286. /*
  287. * "time" is actually "data" for mode 0 (no timestamp).
  288. * place event id # at far right for easier visual parsing.
  289. */
  290. for (i = 0; i < num_events; i++) {
  291. ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  292. time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  293. if (mode == 0) {
  294. trace_iwlwifi_dev_ucode_cont_event(priv,
  295. 0, time, ev);
  296. } else {
  297. data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  298. trace_iwlwifi_dev_ucode_cont_event(priv,
  299. time, data, ev);
  300. }
  301. }
  302. /* Allow device to power down */
  303. iwl_release_nic_access(priv);
  304. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  305. }
  306. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  307. {
  308. u32 capacity; /* event log capacity in # entries */
  309. u32 base; /* SRAM byte address of event log header */
  310. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  311. u32 num_wraps; /* # times uCode wrapped to top of log */
  312. u32 next_entry; /* index of next entry to be written by uCode */
  313. base = priv->device_pointers.error_event_table;
  314. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  315. capacity = iwl_read_targ_mem(priv, base);
  316. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  317. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  318. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  319. } else
  320. return;
  321. if (num_wraps == priv->event_log.num_wraps) {
  322. iwl_print_cont_event_trace(priv,
  323. base, priv->event_log.next_entry,
  324. next_entry - priv->event_log.next_entry,
  325. mode);
  326. priv->event_log.non_wraps_count++;
  327. } else {
  328. if ((num_wraps - priv->event_log.num_wraps) > 1)
  329. priv->event_log.wraps_more_count++;
  330. else
  331. priv->event_log.wraps_once_count++;
  332. trace_iwlwifi_dev_ucode_wrap_event(priv,
  333. num_wraps - priv->event_log.num_wraps,
  334. next_entry, priv->event_log.next_entry);
  335. if (next_entry < priv->event_log.next_entry) {
  336. iwl_print_cont_event_trace(priv, base,
  337. priv->event_log.next_entry,
  338. capacity - priv->event_log.next_entry,
  339. mode);
  340. iwl_print_cont_event_trace(priv, base, 0,
  341. next_entry, mode);
  342. } else {
  343. iwl_print_cont_event_trace(priv, base,
  344. next_entry, capacity - next_entry,
  345. mode);
  346. iwl_print_cont_event_trace(priv, base, 0,
  347. next_entry, mode);
  348. }
  349. }
  350. priv->event_log.num_wraps = num_wraps;
  351. priv->event_log.next_entry = next_entry;
  352. }
  353. /**
  354. * iwl_bg_ucode_trace - Timer callback to log ucode event
  355. *
  356. * The timer is continually set to execute every
  357. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  358. * this function is to perform continuous uCode event logging operation
  359. * if enabled
  360. */
  361. static void iwl_bg_ucode_trace(unsigned long data)
  362. {
  363. struct iwl_priv *priv = (struct iwl_priv *)data;
  364. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  365. return;
  366. if (priv->event_log.ucode_trace) {
  367. iwl_continuous_event_trace(priv);
  368. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  369. mod_timer(&priv->ucode_trace,
  370. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  371. }
  372. }
  373. static void iwl_bg_tx_flush(struct work_struct *work)
  374. {
  375. struct iwl_priv *priv =
  376. container_of(work, struct iwl_priv, tx_flush);
  377. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  378. return;
  379. /* do nothing if rf-kill is on */
  380. if (!iwl_is_ready_rf(priv))
  381. return;
  382. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  383. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  384. }
  385. /*****************************************************************************
  386. *
  387. * sysfs attributes
  388. *
  389. *****************************************************************************/
  390. #ifdef CONFIG_IWLWIFI_DEBUG
  391. /*
  392. * The following adds a new attribute to the sysfs representation
  393. * of this device driver (i.e. a new file in /sys/class/net/wlan0/device/)
  394. * used for controlling the debug level.
  395. *
  396. * See the level definitions in iwl for details.
  397. *
  398. * The debug_level being managed using sysfs below is a per device debug
  399. * level that is used instead of the global debug level if it (the per
  400. * device debug level) is set.
  401. */
  402. static ssize_t show_debug_level(struct device *d,
  403. struct device_attribute *attr, char *buf)
  404. {
  405. struct iwl_priv *priv = dev_get_drvdata(d);
  406. return sprintf(buf, "0x%08X\n", iwl_get_debug_level(priv));
  407. }
  408. static ssize_t store_debug_level(struct device *d,
  409. struct device_attribute *attr,
  410. const char *buf, size_t count)
  411. {
  412. struct iwl_priv *priv = dev_get_drvdata(d);
  413. unsigned long val;
  414. int ret;
  415. ret = strict_strtoul(buf, 0, &val);
  416. if (ret)
  417. IWL_ERR(priv, "%s is not in hex or decimal form.\n", buf);
  418. else {
  419. priv->debug_level = val;
  420. if (iwl_alloc_traffic_mem(priv))
  421. IWL_ERR(priv,
  422. "Not enough memory to generate traffic log\n");
  423. }
  424. return strnlen(buf, count);
  425. }
  426. static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
  427. show_debug_level, store_debug_level);
  428. #endif /* CONFIG_IWLWIFI_DEBUG */
  429. static ssize_t show_temperature(struct device *d,
  430. struct device_attribute *attr, char *buf)
  431. {
  432. struct iwl_priv *priv = dev_get_drvdata(d);
  433. if (!iwl_is_alive(priv))
  434. return -EAGAIN;
  435. return sprintf(buf, "%d\n", priv->temperature);
  436. }
  437. static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
  438. static ssize_t show_tx_power(struct device *d,
  439. struct device_attribute *attr, char *buf)
  440. {
  441. struct iwl_priv *priv = dev_get_drvdata(d);
  442. if (!iwl_is_ready_rf(priv))
  443. return sprintf(buf, "off\n");
  444. else
  445. return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
  446. }
  447. static ssize_t store_tx_power(struct device *d,
  448. struct device_attribute *attr,
  449. const char *buf, size_t count)
  450. {
  451. struct iwl_priv *priv = dev_get_drvdata(d);
  452. unsigned long val;
  453. int ret;
  454. ret = strict_strtoul(buf, 10, &val);
  455. if (ret)
  456. IWL_INFO(priv, "%s is not in decimal form.\n", buf);
  457. else {
  458. ret = iwl_set_tx_power(priv, val, false);
  459. if (ret)
  460. IWL_ERR(priv, "failed setting tx power (0x%d).\n",
  461. ret);
  462. else
  463. ret = count;
  464. }
  465. return ret;
  466. }
  467. static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
  468. static struct attribute *iwl_sysfs_entries[] = {
  469. &dev_attr_temperature.attr,
  470. &dev_attr_tx_power.attr,
  471. #ifdef CONFIG_IWLWIFI_DEBUG
  472. &dev_attr_debug_level.attr,
  473. #endif
  474. NULL
  475. };
  476. static struct attribute_group iwl_attribute_group = {
  477. .name = NULL, /* put in device directory */
  478. .attrs = iwl_sysfs_entries,
  479. };
  480. /******************************************************************************
  481. *
  482. * uCode download functions
  483. *
  484. ******************************************************************************/
  485. static void iwl_free_fw_desc(struct iwl_priv *priv, struct fw_desc *desc)
  486. {
  487. if (desc->v_addr)
  488. dma_free_coherent(priv->bus->dev, desc->len,
  489. desc->v_addr, desc->p_addr);
  490. desc->v_addr = NULL;
  491. desc->len = 0;
  492. }
  493. static void iwl_free_fw_img(struct iwl_priv *priv, struct fw_img *img)
  494. {
  495. iwl_free_fw_desc(priv, &img->code);
  496. iwl_free_fw_desc(priv, &img->data);
  497. }
  498. static void iwl_dealloc_ucode(struct iwl_priv *priv)
  499. {
  500. iwl_free_fw_img(priv, &priv->ucode_rt);
  501. iwl_free_fw_img(priv, &priv->ucode_init);
  502. iwl_free_fw_img(priv, &priv->ucode_wowlan);
  503. }
  504. static int iwl_alloc_fw_desc(struct iwl_priv *priv, struct fw_desc *desc,
  505. const void *data, size_t len)
  506. {
  507. if (!len) {
  508. desc->v_addr = NULL;
  509. return -EINVAL;
  510. }
  511. desc->v_addr = dma_alloc_coherent(priv->bus->dev, len,
  512. &desc->p_addr, GFP_KERNEL);
  513. if (!desc->v_addr)
  514. return -ENOMEM;
  515. desc->len = len;
  516. memcpy(desc->v_addr, data, len);
  517. return 0;
  518. }
  519. struct iwlagn_ucode_capabilities {
  520. u32 max_probe_length;
  521. u32 standard_phy_calibration_size;
  522. u32 flags;
  523. };
  524. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  525. static int iwl_mac_setup_register(struct iwl_priv *priv,
  526. struct iwlagn_ucode_capabilities *capa);
  527. #define UCODE_EXPERIMENTAL_INDEX 100
  528. #define UCODE_EXPERIMENTAL_TAG "exp"
  529. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  530. {
  531. const char *name_pre = priv->cfg->fw_name_pre;
  532. char tag[8];
  533. if (first) {
  534. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  535. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  536. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  537. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  538. #endif
  539. priv->fw_index = priv->cfg->ucode_api_max;
  540. sprintf(tag, "%d", priv->fw_index);
  541. } else {
  542. priv->fw_index--;
  543. sprintf(tag, "%d", priv->fw_index);
  544. }
  545. if (priv->fw_index < priv->cfg->ucode_api_min) {
  546. IWL_ERR(priv, "no suitable firmware found!\n");
  547. return -ENOENT;
  548. }
  549. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  550. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  551. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  552. ? "EXPERIMENTAL " : "",
  553. priv->firmware_name);
  554. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  555. priv->bus->dev,
  556. GFP_KERNEL, priv, iwl_ucode_callback);
  557. }
  558. struct iwlagn_firmware_pieces {
  559. const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data;
  560. size_t inst_size, data_size, init_size, init_data_size,
  561. wowlan_inst_size, wowlan_data_size;
  562. u32 build;
  563. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  564. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  565. };
  566. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  567. const struct firmware *ucode_raw,
  568. struct iwlagn_firmware_pieces *pieces)
  569. {
  570. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  571. u32 api_ver, hdr_size;
  572. const u8 *src;
  573. priv->ucode_ver = le32_to_cpu(ucode->ver);
  574. api_ver = IWL_UCODE_API(priv->ucode_ver);
  575. switch (api_ver) {
  576. default:
  577. hdr_size = 28;
  578. if (ucode_raw->size < hdr_size) {
  579. IWL_ERR(priv, "File size too small!\n");
  580. return -EINVAL;
  581. }
  582. pieces->build = le32_to_cpu(ucode->u.v2.build);
  583. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  584. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  585. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  586. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  587. src = ucode->u.v2.data;
  588. break;
  589. case 0:
  590. case 1:
  591. case 2:
  592. hdr_size = 24;
  593. if (ucode_raw->size < hdr_size) {
  594. IWL_ERR(priv, "File size too small!\n");
  595. return -EINVAL;
  596. }
  597. pieces->build = 0;
  598. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  599. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  600. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  601. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  602. src = ucode->u.v1.data;
  603. break;
  604. }
  605. /* Verify size of file vs. image size info in file's header */
  606. if (ucode_raw->size != hdr_size + pieces->inst_size +
  607. pieces->data_size + pieces->init_size +
  608. pieces->init_data_size) {
  609. IWL_ERR(priv,
  610. "uCode file size %d does not match expected size\n",
  611. (int)ucode_raw->size);
  612. return -EINVAL;
  613. }
  614. pieces->inst = src;
  615. src += pieces->inst_size;
  616. pieces->data = src;
  617. src += pieces->data_size;
  618. pieces->init = src;
  619. src += pieces->init_size;
  620. pieces->init_data = src;
  621. src += pieces->init_data_size;
  622. return 0;
  623. }
  624. static int iwlagn_wanted_ucode_alternative = 1;
  625. static int iwlagn_load_firmware(struct iwl_priv *priv,
  626. const struct firmware *ucode_raw,
  627. struct iwlagn_firmware_pieces *pieces,
  628. struct iwlagn_ucode_capabilities *capa)
  629. {
  630. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  631. struct iwl_ucode_tlv *tlv;
  632. size_t len = ucode_raw->size;
  633. const u8 *data;
  634. int wanted_alternative = iwlagn_wanted_ucode_alternative, tmp;
  635. u64 alternatives;
  636. u32 tlv_len;
  637. enum iwl_ucode_tlv_type tlv_type;
  638. const u8 *tlv_data;
  639. if (len < sizeof(*ucode)) {
  640. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  641. return -EINVAL;
  642. }
  643. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  644. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  645. le32_to_cpu(ucode->magic));
  646. return -EINVAL;
  647. }
  648. /*
  649. * Check which alternatives are present, and "downgrade"
  650. * when the chosen alternative is not present, warning
  651. * the user when that happens. Some files may not have
  652. * any alternatives, so don't warn in that case.
  653. */
  654. alternatives = le64_to_cpu(ucode->alternatives);
  655. tmp = wanted_alternative;
  656. if (wanted_alternative > 63)
  657. wanted_alternative = 63;
  658. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  659. wanted_alternative--;
  660. if (wanted_alternative && wanted_alternative != tmp)
  661. IWL_WARN(priv,
  662. "uCode alternative %d not available, choosing %d\n",
  663. tmp, wanted_alternative);
  664. priv->ucode_ver = le32_to_cpu(ucode->ver);
  665. pieces->build = le32_to_cpu(ucode->build);
  666. data = ucode->data;
  667. len -= sizeof(*ucode);
  668. while (len >= sizeof(*tlv)) {
  669. u16 tlv_alt;
  670. len -= sizeof(*tlv);
  671. tlv = (void *)data;
  672. tlv_len = le32_to_cpu(tlv->length);
  673. tlv_type = le16_to_cpu(tlv->type);
  674. tlv_alt = le16_to_cpu(tlv->alternative);
  675. tlv_data = tlv->data;
  676. if (len < tlv_len) {
  677. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  678. len, tlv_len);
  679. return -EINVAL;
  680. }
  681. len -= ALIGN(tlv_len, 4);
  682. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  683. /*
  684. * Alternative 0 is always valid.
  685. *
  686. * Skip alternative TLVs that are not selected.
  687. */
  688. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  689. continue;
  690. switch (tlv_type) {
  691. case IWL_UCODE_TLV_INST:
  692. pieces->inst = tlv_data;
  693. pieces->inst_size = tlv_len;
  694. break;
  695. case IWL_UCODE_TLV_DATA:
  696. pieces->data = tlv_data;
  697. pieces->data_size = tlv_len;
  698. break;
  699. case IWL_UCODE_TLV_INIT:
  700. pieces->init = tlv_data;
  701. pieces->init_size = tlv_len;
  702. break;
  703. case IWL_UCODE_TLV_INIT_DATA:
  704. pieces->init_data = tlv_data;
  705. pieces->init_data_size = tlv_len;
  706. break;
  707. case IWL_UCODE_TLV_BOOT:
  708. IWL_ERR(priv, "Found unexpected BOOT ucode\n");
  709. break;
  710. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  711. if (tlv_len != sizeof(u32))
  712. goto invalid_tlv_len;
  713. capa->max_probe_length =
  714. le32_to_cpup((__le32 *)tlv_data);
  715. break;
  716. case IWL_UCODE_TLV_PAN:
  717. if (tlv_len)
  718. goto invalid_tlv_len;
  719. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  720. break;
  721. case IWL_UCODE_TLV_FLAGS:
  722. /* must be at least one u32 */
  723. if (tlv_len < sizeof(u32))
  724. goto invalid_tlv_len;
  725. /* and a proper number of u32s */
  726. if (tlv_len % sizeof(u32))
  727. goto invalid_tlv_len;
  728. /*
  729. * This driver only reads the first u32 as
  730. * right now no more features are defined,
  731. * if that changes then either the driver
  732. * will not work with the new firmware, or
  733. * it'll not take advantage of new features.
  734. */
  735. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  736. break;
  737. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  738. if (tlv_len != sizeof(u32))
  739. goto invalid_tlv_len;
  740. pieces->init_evtlog_ptr =
  741. le32_to_cpup((__le32 *)tlv_data);
  742. break;
  743. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  744. if (tlv_len != sizeof(u32))
  745. goto invalid_tlv_len;
  746. pieces->init_evtlog_size =
  747. le32_to_cpup((__le32 *)tlv_data);
  748. break;
  749. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  750. if (tlv_len != sizeof(u32))
  751. goto invalid_tlv_len;
  752. pieces->init_errlog_ptr =
  753. le32_to_cpup((__le32 *)tlv_data);
  754. break;
  755. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  756. if (tlv_len != sizeof(u32))
  757. goto invalid_tlv_len;
  758. pieces->inst_evtlog_ptr =
  759. le32_to_cpup((__le32 *)tlv_data);
  760. break;
  761. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  762. if (tlv_len != sizeof(u32))
  763. goto invalid_tlv_len;
  764. pieces->inst_evtlog_size =
  765. le32_to_cpup((__le32 *)tlv_data);
  766. break;
  767. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  768. if (tlv_len != sizeof(u32))
  769. goto invalid_tlv_len;
  770. pieces->inst_errlog_ptr =
  771. le32_to_cpup((__le32 *)tlv_data);
  772. break;
  773. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  774. if (tlv_len)
  775. goto invalid_tlv_len;
  776. priv->enhance_sensitivity_table = true;
  777. break;
  778. case IWL_UCODE_TLV_WOWLAN_INST:
  779. pieces->wowlan_inst = tlv_data;
  780. pieces->wowlan_inst_size = tlv_len;
  781. break;
  782. case IWL_UCODE_TLV_WOWLAN_DATA:
  783. pieces->wowlan_data = tlv_data;
  784. pieces->wowlan_data_size = tlv_len;
  785. break;
  786. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  787. if (tlv_len != sizeof(u32))
  788. goto invalid_tlv_len;
  789. capa->standard_phy_calibration_size =
  790. le32_to_cpup((__le32 *)tlv_data);
  791. break;
  792. default:
  793. IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
  794. break;
  795. }
  796. }
  797. if (len) {
  798. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  799. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  800. return -EINVAL;
  801. }
  802. return 0;
  803. invalid_tlv_len:
  804. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  805. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  806. return -EINVAL;
  807. }
  808. /**
  809. * iwl_ucode_callback - callback when firmware was loaded
  810. *
  811. * If loaded successfully, copies the firmware into buffers
  812. * for the card to fetch (via DMA).
  813. */
  814. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  815. {
  816. struct iwl_priv *priv = context;
  817. struct iwl_ucode_header *ucode;
  818. int err;
  819. struct iwlagn_firmware_pieces pieces;
  820. const unsigned int api_max = priv->cfg->ucode_api_max;
  821. const unsigned int api_min = priv->cfg->ucode_api_min;
  822. u32 api_ver;
  823. char buildstr[25];
  824. u32 build;
  825. struct iwlagn_ucode_capabilities ucode_capa = {
  826. .max_probe_length = 200,
  827. .standard_phy_calibration_size =
  828. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  829. };
  830. memset(&pieces, 0, sizeof(pieces));
  831. if (!ucode_raw) {
  832. if (priv->fw_index <= priv->cfg->ucode_api_max)
  833. IWL_ERR(priv,
  834. "request for firmware file '%s' failed.\n",
  835. priv->firmware_name);
  836. goto try_again;
  837. }
  838. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  839. priv->firmware_name, ucode_raw->size);
  840. /* Make sure that we got at least the API version number */
  841. if (ucode_raw->size < 4) {
  842. IWL_ERR(priv, "File size way too small!\n");
  843. goto try_again;
  844. }
  845. /* Data from ucode file: header followed by uCode images */
  846. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  847. if (ucode->ver)
  848. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  849. else
  850. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  851. &ucode_capa);
  852. if (err)
  853. goto try_again;
  854. api_ver = IWL_UCODE_API(priv->ucode_ver);
  855. build = pieces.build;
  856. /*
  857. * api_ver should match the api version forming part of the
  858. * firmware filename ... but we don't check for that and only rely
  859. * on the API version read from firmware header from here on forward
  860. */
  861. /* no api version check required for experimental uCode */
  862. if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  863. if (api_ver < api_min || api_ver > api_max) {
  864. IWL_ERR(priv,
  865. "Driver unable to support your firmware API. "
  866. "Driver supports v%u, firmware is v%u.\n",
  867. api_max, api_ver);
  868. goto try_again;
  869. }
  870. if (api_ver != api_max)
  871. IWL_ERR(priv,
  872. "Firmware has old API version. Expected v%u, "
  873. "got v%u. New firmware can be obtained "
  874. "from http://www.intellinuxwireless.org.\n",
  875. api_max, api_ver);
  876. }
  877. if (build)
  878. sprintf(buildstr, " build %u%s", build,
  879. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  880. ? " (EXP)" : "");
  881. else
  882. buildstr[0] = '\0';
  883. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  884. IWL_UCODE_MAJOR(priv->ucode_ver),
  885. IWL_UCODE_MINOR(priv->ucode_ver),
  886. IWL_UCODE_API(priv->ucode_ver),
  887. IWL_UCODE_SERIAL(priv->ucode_ver),
  888. buildstr);
  889. snprintf(priv->hw->wiphy->fw_version,
  890. sizeof(priv->hw->wiphy->fw_version),
  891. "%u.%u.%u.%u%s",
  892. IWL_UCODE_MAJOR(priv->ucode_ver),
  893. IWL_UCODE_MINOR(priv->ucode_ver),
  894. IWL_UCODE_API(priv->ucode_ver),
  895. IWL_UCODE_SERIAL(priv->ucode_ver),
  896. buildstr);
  897. /*
  898. * For any of the failures below (before allocating pci memory)
  899. * we will try to load a version with a smaller API -- maybe the
  900. * user just got a corrupted version of the latest API.
  901. */
  902. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  903. priv->ucode_ver);
  904. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  905. pieces.inst_size);
  906. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  907. pieces.data_size);
  908. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  909. pieces.init_size);
  910. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  911. pieces.init_data_size);
  912. /* Verify that uCode images will fit in card's SRAM */
  913. if (pieces.inst_size > priv->hw_params.max_inst_size) {
  914. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  915. pieces.inst_size);
  916. goto try_again;
  917. }
  918. if (pieces.data_size > priv->hw_params.max_data_size) {
  919. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  920. pieces.data_size);
  921. goto try_again;
  922. }
  923. if (pieces.init_size > priv->hw_params.max_inst_size) {
  924. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  925. pieces.init_size);
  926. goto try_again;
  927. }
  928. if (pieces.init_data_size > priv->hw_params.max_data_size) {
  929. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  930. pieces.init_data_size);
  931. goto try_again;
  932. }
  933. /* Allocate ucode buffers for card's bus-master loading ... */
  934. /* Runtime instructions and 2 copies of data:
  935. * 1) unmodified from disk
  936. * 2) backup cache for save/restore during power-downs */
  937. if (iwl_alloc_fw_desc(priv, &priv->ucode_rt.code,
  938. pieces.inst, pieces.inst_size))
  939. goto err_pci_alloc;
  940. if (iwl_alloc_fw_desc(priv, &priv->ucode_rt.data,
  941. pieces.data, pieces.data_size))
  942. goto err_pci_alloc;
  943. /* Initialization instructions and data */
  944. if (pieces.init_size && pieces.init_data_size) {
  945. if (iwl_alloc_fw_desc(priv, &priv->ucode_init.code,
  946. pieces.init, pieces.init_size))
  947. goto err_pci_alloc;
  948. if (iwl_alloc_fw_desc(priv, &priv->ucode_init.data,
  949. pieces.init_data, pieces.init_data_size))
  950. goto err_pci_alloc;
  951. }
  952. /* WoWLAN instructions and data */
  953. if (pieces.wowlan_inst_size && pieces.wowlan_data_size) {
  954. if (iwl_alloc_fw_desc(priv, &priv->ucode_wowlan.code,
  955. pieces.wowlan_inst,
  956. pieces.wowlan_inst_size))
  957. goto err_pci_alloc;
  958. if (iwl_alloc_fw_desc(priv, &priv->ucode_wowlan.data,
  959. pieces.wowlan_data,
  960. pieces.wowlan_data_size))
  961. goto err_pci_alloc;
  962. }
  963. /* Now that we can no longer fail, copy information */
  964. /*
  965. * The (size - 16) / 12 formula is based on the information recorded
  966. * for each event, which is of mode 1 (including timestamp) for all
  967. * new microcodes that include this information.
  968. */
  969. priv->init_evtlog_ptr = pieces.init_evtlog_ptr;
  970. if (pieces.init_evtlog_size)
  971. priv->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  972. else
  973. priv->init_evtlog_size =
  974. priv->cfg->base_params->max_event_log_size;
  975. priv->init_errlog_ptr = pieces.init_errlog_ptr;
  976. priv->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  977. if (pieces.inst_evtlog_size)
  978. priv->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  979. else
  980. priv->inst_evtlog_size =
  981. priv->cfg->base_params->max_event_log_size;
  982. priv->inst_errlog_ptr = pieces.inst_errlog_ptr;
  983. priv->new_scan_threshold_behaviour =
  984. !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  985. if ((priv->cfg->sku & EEPROM_SKU_CAP_IPAN_ENABLE) &&
  986. (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN)) {
  987. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  988. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  989. } else
  990. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  991. if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
  992. priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  993. else
  994. priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  995. /*
  996. * figure out the offset of chain noise reset and gain commands
  997. * base on the size of standard phy calibration commands table size
  998. */
  999. if (ucode_capa.standard_phy_calibration_size >
  1000. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  1001. ucode_capa.standard_phy_calibration_size =
  1002. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  1003. priv->phy_calib_chain_noise_reset_cmd =
  1004. ucode_capa.standard_phy_calibration_size;
  1005. priv->phy_calib_chain_noise_gain_cmd =
  1006. ucode_capa.standard_phy_calibration_size + 1;
  1007. /**************************************************
  1008. * This is still part of probe() in a sense...
  1009. *
  1010. * 9. Setup and register with mac80211 and debugfs
  1011. **************************************************/
  1012. err = iwl_mac_setup_register(priv, &ucode_capa);
  1013. if (err)
  1014. goto out_unbind;
  1015. err = iwl_dbgfs_register(priv, DRV_NAME);
  1016. if (err)
  1017. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  1018. err = sysfs_create_group(&(priv->bus->dev->kobj),
  1019. &iwl_attribute_group);
  1020. if (err) {
  1021. IWL_ERR(priv, "failed to create sysfs device attributes\n");
  1022. goto out_unbind;
  1023. }
  1024. /* We have our copies now, allow OS release its copies */
  1025. release_firmware(ucode_raw);
  1026. complete(&priv->firmware_loading_complete);
  1027. return;
  1028. try_again:
  1029. /* try next, if any */
  1030. if (iwl_request_firmware(priv, false))
  1031. goto out_unbind;
  1032. release_firmware(ucode_raw);
  1033. return;
  1034. err_pci_alloc:
  1035. IWL_ERR(priv, "failed to allocate pci memory\n");
  1036. iwl_dealloc_ucode(priv);
  1037. out_unbind:
  1038. complete(&priv->firmware_loading_complete);
  1039. device_release_driver(priv->bus->dev);
  1040. release_firmware(ucode_raw);
  1041. }
  1042. static const char * const desc_lookup_text[] = {
  1043. "OK",
  1044. "FAIL",
  1045. "BAD_PARAM",
  1046. "BAD_CHECKSUM",
  1047. "NMI_INTERRUPT_WDG",
  1048. "SYSASSERT",
  1049. "FATAL_ERROR",
  1050. "BAD_COMMAND",
  1051. "HW_ERROR_TUNE_LOCK",
  1052. "HW_ERROR_TEMPERATURE",
  1053. "ILLEGAL_CHAN_FREQ",
  1054. "VCC_NOT_STABLE",
  1055. "FH_ERROR",
  1056. "NMI_INTERRUPT_HOST",
  1057. "NMI_INTERRUPT_ACTION_PT",
  1058. "NMI_INTERRUPT_UNKNOWN",
  1059. "UCODE_VERSION_MISMATCH",
  1060. "HW_ERROR_ABS_LOCK",
  1061. "HW_ERROR_CAL_LOCK_FAIL",
  1062. "NMI_INTERRUPT_INST_ACTION_PT",
  1063. "NMI_INTERRUPT_DATA_ACTION_PT",
  1064. "NMI_TRM_HW_ER",
  1065. "NMI_INTERRUPT_TRM",
  1066. "NMI_INTERRUPT_BREAK_POINT",
  1067. "DEBUG_0",
  1068. "DEBUG_1",
  1069. "DEBUG_2",
  1070. "DEBUG_3",
  1071. };
  1072. static struct { char *name; u8 num; } advanced_lookup[] = {
  1073. { "NMI_INTERRUPT_WDG", 0x34 },
  1074. { "SYSASSERT", 0x35 },
  1075. { "UCODE_VERSION_MISMATCH", 0x37 },
  1076. { "BAD_COMMAND", 0x38 },
  1077. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1078. { "FATAL_ERROR", 0x3D },
  1079. { "NMI_TRM_HW_ERR", 0x46 },
  1080. { "NMI_INTERRUPT_TRM", 0x4C },
  1081. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1082. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1083. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1084. { "NMI_INTERRUPT_HOST", 0x66 },
  1085. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1086. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1087. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1088. { "ADVANCED_SYSASSERT", 0 },
  1089. };
  1090. static const char *desc_lookup(u32 num)
  1091. {
  1092. int i;
  1093. int max = ARRAY_SIZE(desc_lookup_text);
  1094. if (num < max)
  1095. return desc_lookup_text[num];
  1096. max = ARRAY_SIZE(advanced_lookup) - 1;
  1097. for (i = 0; i < max; i++) {
  1098. if (advanced_lookup[i].num == num)
  1099. break;
  1100. }
  1101. return advanced_lookup[i].name;
  1102. }
  1103. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1104. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1105. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1106. {
  1107. u32 base;
  1108. struct iwl_error_event_table table;
  1109. base = priv->device_pointers.error_event_table;
  1110. if (priv->ucode_type == IWL_UCODE_INIT) {
  1111. if (!base)
  1112. base = priv->init_errlog_ptr;
  1113. } else {
  1114. if (!base)
  1115. base = priv->inst_errlog_ptr;
  1116. }
  1117. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1118. IWL_ERR(priv,
  1119. "Not valid error log pointer 0x%08X for %s uCode\n",
  1120. base,
  1121. (priv->ucode_type == IWL_UCODE_INIT)
  1122. ? "Init" : "RT");
  1123. return;
  1124. }
  1125. iwl_read_targ_mem_words(priv, base, &table, sizeof(table));
  1126. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1127. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1128. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1129. priv->status, table.valid);
  1130. }
  1131. priv->isr_stats.err_code = table.error_id;
  1132. trace_iwlwifi_dev_ucode_error(priv, table.error_id, table.tsf_low,
  1133. table.data1, table.data2, table.line,
  1134. table.blink1, table.blink2, table.ilink1,
  1135. table.ilink2, table.bcon_time, table.gp1,
  1136. table.gp2, table.gp3, table.ucode_ver,
  1137. table.hw_ver, table.brd_ver);
  1138. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1139. desc_lookup(table.error_id));
  1140. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1141. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1142. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1143. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1144. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1145. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1146. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1147. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1148. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1149. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1150. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1151. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1152. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1153. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1154. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1155. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1156. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1157. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1158. }
  1159. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1160. /**
  1161. * iwl_print_event_log - Dump error event log to syslog
  1162. *
  1163. */
  1164. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1165. u32 num_events, u32 mode,
  1166. int pos, char **buf, size_t bufsz)
  1167. {
  1168. u32 i;
  1169. u32 base; /* SRAM byte address of event log header */
  1170. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1171. u32 ptr; /* SRAM byte address of log data */
  1172. u32 ev, time, data; /* event log data */
  1173. unsigned long reg_flags;
  1174. if (num_events == 0)
  1175. return pos;
  1176. base = priv->device_pointers.log_event_table;
  1177. if (priv->ucode_type == IWL_UCODE_INIT) {
  1178. if (!base)
  1179. base = priv->init_evtlog_ptr;
  1180. } else {
  1181. if (!base)
  1182. base = priv->inst_evtlog_ptr;
  1183. }
  1184. if (mode == 0)
  1185. event_size = 2 * sizeof(u32);
  1186. else
  1187. event_size = 3 * sizeof(u32);
  1188. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1189. /* Make sure device is powered up for SRAM reads */
  1190. spin_lock_irqsave(&priv->reg_lock, reg_flags);
  1191. iwl_grab_nic_access(priv);
  1192. /* Set starting address; reads will auto-increment */
  1193. iwl_write32(priv, HBUS_TARG_MEM_RADDR, ptr);
  1194. rmb();
  1195. /* "time" is actually "data" for mode 0 (no timestamp).
  1196. * place event id # at far right for easier visual parsing. */
  1197. for (i = 0; i < num_events; i++) {
  1198. ev = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1199. time = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1200. if (mode == 0) {
  1201. /* data, ev */
  1202. if (bufsz) {
  1203. pos += scnprintf(*buf + pos, bufsz - pos,
  1204. "EVT_LOG:0x%08x:%04u\n",
  1205. time, ev);
  1206. } else {
  1207. trace_iwlwifi_dev_ucode_event(priv, 0,
  1208. time, ev);
  1209. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1210. time, ev);
  1211. }
  1212. } else {
  1213. data = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  1214. if (bufsz) {
  1215. pos += scnprintf(*buf + pos, bufsz - pos,
  1216. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1217. time, data, ev);
  1218. } else {
  1219. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1220. time, data, ev);
  1221. trace_iwlwifi_dev_ucode_event(priv, time,
  1222. data, ev);
  1223. }
  1224. }
  1225. }
  1226. /* Allow device to power down */
  1227. iwl_release_nic_access(priv);
  1228. spin_unlock_irqrestore(&priv->reg_lock, reg_flags);
  1229. return pos;
  1230. }
  1231. /**
  1232. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1233. */
  1234. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1235. u32 num_wraps, u32 next_entry,
  1236. u32 size, u32 mode,
  1237. int pos, char **buf, size_t bufsz)
  1238. {
  1239. /*
  1240. * display the newest DEFAULT_LOG_ENTRIES entries
  1241. * i.e the entries just before the next ont that uCode would fill.
  1242. */
  1243. if (num_wraps) {
  1244. if (next_entry < size) {
  1245. pos = iwl_print_event_log(priv,
  1246. capacity - (size - next_entry),
  1247. size - next_entry, mode,
  1248. pos, buf, bufsz);
  1249. pos = iwl_print_event_log(priv, 0,
  1250. next_entry, mode,
  1251. pos, buf, bufsz);
  1252. } else
  1253. pos = iwl_print_event_log(priv, next_entry - size,
  1254. size, mode, pos, buf, bufsz);
  1255. } else {
  1256. if (next_entry < size) {
  1257. pos = iwl_print_event_log(priv, 0, next_entry,
  1258. mode, pos, buf, bufsz);
  1259. } else {
  1260. pos = iwl_print_event_log(priv, next_entry - size,
  1261. size, mode, pos, buf, bufsz);
  1262. }
  1263. }
  1264. return pos;
  1265. }
  1266. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1267. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1268. char **buf, bool display)
  1269. {
  1270. u32 base; /* SRAM byte address of event log header */
  1271. u32 capacity; /* event log capacity in # entries */
  1272. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1273. u32 num_wraps; /* # times uCode wrapped to top of log */
  1274. u32 next_entry; /* index of next entry to be written by uCode */
  1275. u32 size; /* # entries that we'll print */
  1276. u32 logsize;
  1277. int pos = 0;
  1278. size_t bufsz = 0;
  1279. base = priv->device_pointers.log_event_table;
  1280. if (priv->ucode_type == IWL_UCODE_INIT) {
  1281. logsize = priv->init_evtlog_size;
  1282. if (!base)
  1283. base = priv->init_evtlog_ptr;
  1284. } else {
  1285. logsize = priv->inst_evtlog_size;
  1286. if (!base)
  1287. base = priv->inst_evtlog_ptr;
  1288. }
  1289. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1290. IWL_ERR(priv,
  1291. "Invalid event log pointer 0x%08X for %s uCode\n",
  1292. base,
  1293. (priv->ucode_type == IWL_UCODE_INIT)
  1294. ? "Init" : "RT");
  1295. return -EINVAL;
  1296. }
  1297. /* event log header */
  1298. capacity = iwl_read_targ_mem(priv, base);
  1299. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1300. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1301. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1302. if (capacity > logsize) {
  1303. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d entries\n",
  1304. capacity, logsize);
  1305. capacity = logsize;
  1306. }
  1307. if (next_entry > logsize) {
  1308. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1309. next_entry, logsize);
  1310. next_entry = logsize;
  1311. }
  1312. size = num_wraps ? capacity : next_entry;
  1313. /* bail out if nothing in log */
  1314. if (size == 0) {
  1315. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1316. return pos;
  1317. }
  1318. /* enable/disable bt channel inhibition */
  1319. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  1320. #ifdef CONFIG_IWLWIFI_DEBUG
  1321. if (!(iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) && !full_log)
  1322. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1323. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1324. #else
  1325. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1326. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1327. #endif
  1328. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1329. size);
  1330. #ifdef CONFIG_IWLWIFI_DEBUG
  1331. if (display) {
  1332. if (full_log)
  1333. bufsz = capacity * 48;
  1334. else
  1335. bufsz = size * 48;
  1336. *buf = kmalloc(bufsz, GFP_KERNEL);
  1337. if (!*buf)
  1338. return -ENOMEM;
  1339. }
  1340. if ((iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) || full_log) {
  1341. /*
  1342. * if uCode has wrapped back to top of log,
  1343. * start at the oldest entry,
  1344. * i.e the next one that uCode would fill.
  1345. */
  1346. if (num_wraps)
  1347. pos = iwl_print_event_log(priv, next_entry,
  1348. capacity - next_entry, mode,
  1349. pos, buf, bufsz);
  1350. /* (then/else) start at top of log */
  1351. pos = iwl_print_event_log(priv, 0,
  1352. next_entry, mode, pos, buf, bufsz);
  1353. } else
  1354. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1355. next_entry, size, mode,
  1356. pos, buf, bufsz);
  1357. #else
  1358. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1359. next_entry, size, mode,
  1360. pos, buf, bufsz);
  1361. #endif
  1362. return pos;
  1363. }
  1364. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1365. {
  1366. struct iwl_ct_kill_config cmd;
  1367. struct iwl_ct_kill_throttling_config adv_cmd;
  1368. unsigned long flags;
  1369. int ret = 0;
  1370. spin_lock_irqsave(&priv->lock, flags);
  1371. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1372. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1373. spin_unlock_irqrestore(&priv->lock, flags);
  1374. priv->thermal_throttle.ct_kill_toggle = false;
  1375. if (priv->cfg->base_params->support_ct_kill_exit) {
  1376. adv_cmd.critical_temperature_enter =
  1377. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1378. adv_cmd.critical_temperature_exit =
  1379. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  1380. ret = trans_send_cmd_pdu(&priv->trans,
  1381. REPLY_CT_KILL_CONFIG_CMD,
  1382. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  1383. if (ret)
  1384. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1385. else
  1386. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1387. "succeeded, "
  1388. "critical temperature enter is %d,"
  1389. "exit is %d\n",
  1390. priv->hw_params.ct_kill_threshold,
  1391. priv->hw_params.ct_kill_exit_threshold);
  1392. } else {
  1393. cmd.critical_temperature_R =
  1394. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1395. ret = trans_send_cmd_pdu(&priv->trans,
  1396. REPLY_CT_KILL_CONFIG_CMD,
  1397. CMD_SYNC, sizeof(cmd), &cmd);
  1398. if (ret)
  1399. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1400. else
  1401. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1402. "succeeded, "
  1403. "critical temperature is %d\n",
  1404. priv->hw_params.ct_kill_threshold);
  1405. }
  1406. }
  1407. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  1408. {
  1409. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  1410. struct iwl_host_cmd cmd = {
  1411. .id = CALIBRATION_CFG_CMD,
  1412. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  1413. .data = { &calib_cfg_cmd, },
  1414. };
  1415. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  1416. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_INIT_CFG_ALL;
  1417. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  1418. return trans_send_cmd(&priv->trans, &cmd);
  1419. }
  1420. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  1421. {
  1422. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  1423. .valid = cpu_to_le32(valid_tx_ant),
  1424. };
  1425. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  1426. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  1427. return trans_send_cmd_pdu(&priv->trans,
  1428. TX_ANT_CONFIGURATION_CMD,
  1429. CMD_SYNC,
  1430. sizeof(struct iwl_tx_ant_config_cmd),
  1431. &tx_ant_cmd);
  1432. } else {
  1433. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  1434. return -EOPNOTSUPP;
  1435. }
  1436. }
  1437. /**
  1438. * iwl_alive_start - called after REPLY_ALIVE notification received
  1439. * from protocol/runtime uCode (initialization uCode's
  1440. * Alive gets handled by iwl_init_alive_start()).
  1441. */
  1442. int iwl_alive_start(struct iwl_priv *priv)
  1443. {
  1444. int ret = 0;
  1445. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1446. /*TODO: this should go to the transport layer */
  1447. iwl_reset_ict(priv);
  1448. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1449. /* After the ALIVE response, we can send host commands to the uCode */
  1450. set_bit(STATUS_ALIVE, &priv->status);
  1451. /* Enable watchdog to monitor the driver tx queues */
  1452. iwl_setup_watchdog(priv);
  1453. if (iwl_is_rfkill(priv))
  1454. return -ERFKILL;
  1455. /* download priority table before any calibration request */
  1456. if (priv->cfg->bt_params &&
  1457. priv->cfg->bt_params->advanced_bt_coexist) {
  1458. /* Configure Bluetooth device coexistence support */
  1459. if (priv->cfg->bt_params->bt_sco_disable)
  1460. priv->bt_enable_pspoll = false;
  1461. else
  1462. priv->bt_enable_pspoll = true;
  1463. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1464. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1465. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1466. iwlagn_send_advance_bt_config(priv);
  1467. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  1468. priv->cur_rssi_ctx = NULL;
  1469. iwlagn_send_prio_tbl(priv);
  1470. /* FIXME: w/a to force change uCode BT state machine */
  1471. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  1472. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1473. if (ret)
  1474. return ret;
  1475. ret = iwlagn_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  1476. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1477. if (ret)
  1478. return ret;
  1479. } else {
  1480. /*
  1481. * default is 2-wire BT coexexistence support
  1482. */
  1483. iwl_send_bt_config(priv);
  1484. }
  1485. if (priv->hw_params.calib_rt_cfg)
  1486. iwlagn_send_calib_cfg_rt(priv, priv->hw_params.calib_rt_cfg);
  1487. ieee80211_wake_queues(priv->hw);
  1488. priv->active_rate = IWL_RATES_MASK;
  1489. /* Configure Tx antenna selection based on H/W config */
  1490. iwlagn_send_tx_ant_config(priv, priv->cfg->valid_tx_ant);
  1491. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  1492. struct iwl_rxon_cmd *active_rxon =
  1493. (struct iwl_rxon_cmd *)&ctx->active;
  1494. /* apply any changes in staging */
  1495. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1496. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1497. } else {
  1498. struct iwl_rxon_context *tmp;
  1499. /* Initialize our rx_config data */
  1500. for_each_context(priv, tmp)
  1501. iwl_connection_init_rx_config(priv, tmp);
  1502. iwlagn_set_rxon_chain(priv, ctx);
  1503. }
  1504. if (!priv->wowlan) {
  1505. /* WoWLAN ucode will not reply in the same way, skip it */
  1506. iwl_reset_run_time_calib(priv);
  1507. }
  1508. set_bit(STATUS_READY, &priv->status);
  1509. /* Configure the adapter for unassociated operation */
  1510. ret = iwlagn_commit_rxon(priv, ctx);
  1511. if (ret)
  1512. return ret;
  1513. /* At this point, the NIC is initialized and operational */
  1514. iwl_rf_kill_ct_config(priv);
  1515. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1516. return iwl_power_update_mode(priv, true);
  1517. }
  1518. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1519. static void __iwl_down(struct iwl_priv *priv)
  1520. {
  1521. int exit_pending;
  1522. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1523. iwl_scan_cancel_timeout(priv, 200);
  1524. exit_pending = test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  1525. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1526. * to prevent rearm timer */
  1527. del_timer_sync(&priv->watchdog);
  1528. iwl_clear_ucode_stations(priv, NULL);
  1529. iwl_dealloc_bcast_stations(priv);
  1530. iwl_clear_driver_stations(priv);
  1531. /* reset BT coex data */
  1532. priv->bt_status = 0;
  1533. priv->cur_rssi_ctx = NULL;
  1534. priv->bt_is_sco = 0;
  1535. if (priv->cfg->bt_params)
  1536. priv->bt_traffic_load =
  1537. priv->cfg->bt_params->bt_init_traffic_load;
  1538. else
  1539. priv->bt_traffic_load = 0;
  1540. priv->bt_full_concurrent = false;
  1541. priv->bt_ci_compliance = 0;
  1542. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1543. * exiting the module */
  1544. if (!exit_pending)
  1545. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1546. if (priv->mac80211_registered)
  1547. ieee80211_stop_queues(priv->hw);
  1548. /* Clear out all status bits but a few that are stable across reset */
  1549. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  1550. STATUS_RF_KILL_HW |
  1551. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  1552. STATUS_GEO_CONFIGURED |
  1553. test_bit(STATUS_FW_ERROR, &priv->status) <<
  1554. STATUS_FW_ERROR |
  1555. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  1556. STATUS_EXIT_PENDING;
  1557. trans_stop_device(&priv->trans);
  1558. dev_kfree_skb(priv->beacon_skb);
  1559. priv->beacon_skb = NULL;
  1560. }
  1561. static void iwl_down(struct iwl_priv *priv)
  1562. {
  1563. mutex_lock(&priv->mutex);
  1564. __iwl_down(priv);
  1565. mutex_unlock(&priv->mutex);
  1566. iwl_cancel_deferred_work(priv);
  1567. }
  1568. #define MAX_HW_RESTARTS 5
  1569. static int __iwl_up(struct iwl_priv *priv)
  1570. {
  1571. struct iwl_rxon_context *ctx;
  1572. int ret;
  1573. lockdep_assert_held(&priv->mutex);
  1574. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1575. IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
  1576. return -EIO;
  1577. }
  1578. for_each_context(priv, ctx) {
  1579. ret = iwlagn_alloc_bcast_station(priv, ctx);
  1580. if (ret) {
  1581. iwl_dealloc_bcast_stations(priv);
  1582. return ret;
  1583. }
  1584. }
  1585. ret = iwlagn_run_init_ucode(priv);
  1586. if (ret) {
  1587. IWL_ERR(priv, "Failed to run INIT ucode: %d\n", ret);
  1588. goto error;
  1589. }
  1590. ret = iwlagn_load_ucode_wait_alive(priv,
  1591. &priv->ucode_rt,
  1592. IWL_UCODE_REGULAR);
  1593. if (ret) {
  1594. IWL_ERR(priv, "Failed to start RT ucode: %d\n", ret);
  1595. goto error;
  1596. }
  1597. ret = iwl_alive_start(priv);
  1598. if (ret)
  1599. goto error;
  1600. return 0;
  1601. error:
  1602. set_bit(STATUS_EXIT_PENDING, &priv->status);
  1603. __iwl_down(priv);
  1604. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  1605. IWL_ERR(priv, "Unable to initialize device.\n");
  1606. return ret;
  1607. }
  1608. /*****************************************************************************
  1609. *
  1610. * Workqueue callbacks
  1611. *
  1612. *****************************************************************************/
  1613. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  1614. {
  1615. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1616. run_time_calib_work);
  1617. mutex_lock(&priv->mutex);
  1618. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  1619. test_bit(STATUS_SCANNING, &priv->status)) {
  1620. mutex_unlock(&priv->mutex);
  1621. return;
  1622. }
  1623. if (priv->start_calib) {
  1624. iwl_chain_noise_calibration(priv);
  1625. iwl_sensitivity_calibration(priv);
  1626. }
  1627. mutex_unlock(&priv->mutex);
  1628. }
  1629. static void iwlagn_prepare_restart(struct iwl_priv *priv)
  1630. {
  1631. struct iwl_rxon_context *ctx;
  1632. bool bt_full_concurrent;
  1633. u8 bt_ci_compliance;
  1634. u8 bt_load;
  1635. u8 bt_status;
  1636. bool bt_is_sco;
  1637. lockdep_assert_held(&priv->mutex);
  1638. for_each_context(priv, ctx)
  1639. ctx->vif = NULL;
  1640. priv->is_open = 0;
  1641. /*
  1642. * __iwl_down() will clear the BT status variables,
  1643. * which is correct, but when we restart we really
  1644. * want to keep them so restore them afterwards.
  1645. *
  1646. * The restart process will later pick them up and
  1647. * re-configure the hw when we reconfigure the BT
  1648. * command.
  1649. */
  1650. bt_full_concurrent = priv->bt_full_concurrent;
  1651. bt_ci_compliance = priv->bt_ci_compliance;
  1652. bt_load = priv->bt_traffic_load;
  1653. bt_status = priv->bt_status;
  1654. bt_is_sco = priv->bt_is_sco;
  1655. __iwl_down(priv);
  1656. priv->bt_full_concurrent = bt_full_concurrent;
  1657. priv->bt_ci_compliance = bt_ci_compliance;
  1658. priv->bt_traffic_load = bt_load;
  1659. priv->bt_status = bt_status;
  1660. priv->bt_is_sco = bt_is_sco;
  1661. }
  1662. static void iwl_bg_restart(struct work_struct *data)
  1663. {
  1664. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  1665. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  1666. return;
  1667. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  1668. mutex_lock(&priv->mutex);
  1669. iwlagn_prepare_restart(priv);
  1670. mutex_unlock(&priv->mutex);
  1671. iwl_cancel_deferred_work(priv);
  1672. ieee80211_restart_hw(priv->hw);
  1673. } else {
  1674. WARN_ON(1);
  1675. }
  1676. }
  1677. static int iwl_mac_offchannel_tx(struct ieee80211_hw *hw, struct sk_buff *skb,
  1678. struct ieee80211_channel *chan,
  1679. enum nl80211_channel_type channel_type,
  1680. unsigned int wait)
  1681. {
  1682. struct iwl_priv *priv = hw->priv;
  1683. int ret;
  1684. /* Not supported if we don't have PAN */
  1685. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN))) {
  1686. ret = -EOPNOTSUPP;
  1687. goto free;
  1688. }
  1689. /* Not supported on pre-P2P firmware */
  1690. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  1691. BIT(NL80211_IFTYPE_P2P_CLIENT))) {
  1692. ret = -EOPNOTSUPP;
  1693. goto free;
  1694. }
  1695. mutex_lock(&priv->mutex);
  1696. if (!priv->contexts[IWL_RXON_CTX_PAN].is_active) {
  1697. /*
  1698. * If the PAN context is free, use the normal
  1699. * way of doing remain-on-channel offload + TX.
  1700. */
  1701. ret = 1;
  1702. goto out;
  1703. }
  1704. /* TODO: queue up if scanning? */
  1705. if (test_bit(STATUS_SCANNING, &priv->status) ||
  1706. priv->offchan_tx_skb) {
  1707. ret = -EBUSY;
  1708. goto out;
  1709. }
  1710. /*
  1711. * max_scan_ie_len doesn't include the blank SSID or the header,
  1712. * so need to add that again here.
  1713. */
  1714. if (skb->len > hw->wiphy->max_scan_ie_len + 24 + 2) {
  1715. ret = -ENOBUFS;
  1716. goto out;
  1717. }
  1718. priv->offchan_tx_skb = skb;
  1719. priv->offchan_tx_timeout = wait;
  1720. priv->offchan_tx_chan = chan;
  1721. ret = iwl_scan_initiate(priv, priv->contexts[IWL_RXON_CTX_PAN].vif,
  1722. IWL_SCAN_OFFCH_TX, chan->band);
  1723. if (ret)
  1724. priv->offchan_tx_skb = NULL;
  1725. out:
  1726. mutex_unlock(&priv->mutex);
  1727. free:
  1728. if (ret < 0)
  1729. kfree_skb(skb);
  1730. return ret;
  1731. }
  1732. static int iwl_mac_offchannel_tx_cancel_wait(struct ieee80211_hw *hw)
  1733. {
  1734. struct iwl_priv *priv = hw->priv;
  1735. int ret;
  1736. mutex_lock(&priv->mutex);
  1737. if (!priv->offchan_tx_skb) {
  1738. ret = -EINVAL;
  1739. goto unlock;
  1740. }
  1741. priv->offchan_tx_skb = NULL;
  1742. ret = iwl_scan_cancel_timeout(priv, 200);
  1743. if (ret)
  1744. ret = -EIO;
  1745. unlock:
  1746. mutex_unlock(&priv->mutex);
  1747. return ret;
  1748. }
  1749. /*****************************************************************************
  1750. *
  1751. * mac80211 entry point functions
  1752. *
  1753. *****************************************************************************/
  1754. static const struct ieee80211_iface_limit iwlagn_sta_ap_limits[] = {
  1755. {
  1756. .max = 1,
  1757. .types = BIT(NL80211_IFTYPE_STATION),
  1758. },
  1759. {
  1760. .max = 1,
  1761. .types = BIT(NL80211_IFTYPE_AP),
  1762. },
  1763. };
  1764. static const struct ieee80211_iface_limit iwlagn_2sta_limits[] = {
  1765. {
  1766. .max = 2,
  1767. .types = BIT(NL80211_IFTYPE_STATION),
  1768. },
  1769. };
  1770. static const struct ieee80211_iface_limit iwlagn_p2p_sta_go_limits[] = {
  1771. {
  1772. .max = 1,
  1773. .types = BIT(NL80211_IFTYPE_STATION),
  1774. },
  1775. {
  1776. .max = 1,
  1777. .types = BIT(NL80211_IFTYPE_P2P_GO) |
  1778. BIT(NL80211_IFTYPE_AP),
  1779. },
  1780. };
  1781. static const struct ieee80211_iface_limit iwlagn_p2p_2sta_limits[] = {
  1782. {
  1783. .max = 2,
  1784. .types = BIT(NL80211_IFTYPE_STATION),
  1785. },
  1786. {
  1787. .max = 1,
  1788. .types = BIT(NL80211_IFTYPE_P2P_CLIENT),
  1789. },
  1790. };
  1791. static const struct ieee80211_iface_combination
  1792. iwlagn_iface_combinations_dualmode[] = {
  1793. { .num_different_channels = 1,
  1794. .max_interfaces = 2,
  1795. .beacon_int_infra_match = true,
  1796. .limits = iwlagn_sta_ap_limits,
  1797. .n_limits = ARRAY_SIZE(iwlagn_sta_ap_limits),
  1798. },
  1799. { .num_different_channels = 1,
  1800. .max_interfaces = 2,
  1801. .limits = iwlagn_2sta_limits,
  1802. .n_limits = ARRAY_SIZE(iwlagn_2sta_limits),
  1803. },
  1804. };
  1805. static const struct ieee80211_iface_combination
  1806. iwlagn_iface_combinations_p2p[] = {
  1807. { .num_different_channels = 1,
  1808. .max_interfaces = 2,
  1809. .beacon_int_infra_match = true,
  1810. .limits = iwlagn_p2p_sta_go_limits,
  1811. .n_limits = ARRAY_SIZE(iwlagn_p2p_sta_go_limits),
  1812. },
  1813. { .num_different_channels = 1,
  1814. .max_interfaces = 2,
  1815. .limits = iwlagn_p2p_2sta_limits,
  1816. .n_limits = ARRAY_SIZE(iwlagn_p2p_2sta_limits),
  1817. },
  1818. };
  1819. /*
  1820. * Not a mac80211 entry point function, but it fits in with all the
  1821. * other mac80211 functions grouped here.
  1822. */
  1823. static int iwl_mac_setup_register(struct iwl_priv *priv,
  1824. struct iwlagn_ucode_capabilities *capa)
  1825. {
  1826. int ret;
  1827. struct ieee80211_hw *hw = priv->hw;
  1828. struct iwl_rxon_context *ctx;
  1829. hw->rate_control_algorithm = "iwl-agn-rs";
  1830. /* Tell mac80211 our characteristics */
  1831. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1832. IEEE80211_HW_AMPDU_AGGREGATION |
  1833. IEEE80211_HW_NEED_DTIM_PERIOD |
  1834. IEEE80211_HW_SPECTRUM_MGMT |
  1835. IEEE80211_HW_REPORTS_TX_ACK_STATUS;
  1836. hw->max_tx_aggregation_subframes = LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  1837. hw->flags |= IEEE80211_HW_SUPPORTS_PS |
  1838. IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
  1839. if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
  1840. hw->flags |= IEEE80211_HW_SUPPORTS_DYNAMIC_SMPS |
  1841. IEEE80211_HW_SUPPORTS_STATIC_SMPS;
  1842. if (capa->flags & IWL_UCODE_TLV_FLAGS_MFP)
  1843. hw->flags |= IEEE80211_HW_MFP_CAPABLE;
  1844. hw->sta_data_size = sizeof(struct iwl_station_priv);
  1845. hw->vif_data_size = sizeof(struct iwl_vif_priv);
  1846. for_each_context(priv, ctx) {
  1847. hw->wiphy->interface_modes |= ctx->interface_modes;
  1848. hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
  1849. }
  1850. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  1851. if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_P2P_CLIENT)) {
  1852. hw->wiphy->iface_combinations = iwlagn_iface_combinations_p2p;
  1853. hw->wiphy->n_iface_combinations =
  1854. ARRAY_SIZE(iwlagn_iface_combinations_p2p);
  1855. } else if (hw->wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  1856. hw->wiphy->iface_combinations = iwlagn_iface_combinations_dualmode;
  1857. hw->wiphy->n_iface_combinations =
  1858. ARRAY_SIZE(iwlagn_iface_combinations_dualmode);
  1859. }
  1860. hw->wiphy->max_remain_on_channel_duration = 1000;
  1861. hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
  1862. WIPHY_FLAG_DISABLE_BEACON_HINTS |
  1863. WIPHY_FLAG_IBSS_RSN;
  1864. if (priv->ucode_wowlan.code.len && device_can_wakeup(priv->bus->dev)) {
  1865. hw->wiphy->wowlan.flags = WIPHY_WOWLAN_MAGIC_PKT |
  1866. WIPHY_WOWLAN_DISCONNECT |
  1867. WIPHY_WOWLAN_EAP_IDENTITY_REQ |
  1868. WIPHY_WOWLAN_RFKILL_RELEASE;
  1869. if (!iwlagn_mod_params.sw_crypto)
  1870. hw->wiphy->wowlan.flags |=
  1871. WIPHY_WOWLAN_SUPPORTS_GTK_REKEY |
  1872. WIPHY_WOWLAN_GTK_REKEY_FAILURE;
  1873. hw->wiphy->wowlan.n_patterns = IWLAGN_WOWLAN_MAX_PATTERNS;
  1874. hw->wiphy->wowlan.pattern_min_len =
  1875. IWLAGN_WOWLAN_MIN_PATTERN_LEN;
  1876. hw->wiphy->wowlan.pattern_max_len =
  1877. IWLAGN_WOWLAN_MAX_PATTERN_LEN;
  1878. }
  1879. if (iwlagn_mod_params.power_save)
  1880. hw->wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1881. else
  1882. hw->wiphy->flags &= ~WIPHY_FLAG_PS_ON_BY_DEFAULT;
  1883. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  1884. /* we create the 802.11 header and a zero-length SSID element */
  1885. hw->wiphy->max_scan_ie_len = capa->max_probe_length - 24 - 2;
  1886. /* Default value; 4 EDCA QOS priorities */
  1887. hw->queues = 4;
  1888. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  1889. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  1890. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1891. &priv->bands[IEEE80211_BAND_2GHZ];
  1892. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  1893. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1894. &priv->bands[IEEE80211_BAND_5GHZ];
  1895. iwl_leds_init(priv);
  1896. ret = ieee80211_register_hw(priv->hw);
  1897. if (ret) {
  1898. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  1899. return ret;
  1900. }
  1901. priv->mac80211_registered = 1;
  1902. return 0;
  1903. }
  1904. static int iwlagn_mac_start(struct ieee80211_hw *hw)
  1905. {
  1906. struct iwl_priv *priv = hw->priv;
  1907. int ret;
  1908. IWL_DEBUG_MAC80211(priv, "enter\n");
  1909. /* we should be verifying the device is ready to be opened */
  1910. mutex_lock(&priv->mutex);
  1911. ret = __iwl_up(priv);
  1912. mutex_unlock(&priv->mutex);
  1913. if (ret)
  1914. return ret;
  1915. IWL_DEBUG_INFO(priv, "Start UP work done.\n");
  1916. /* Now we should be done, and the READY bit should be set. */
  1917. if (WARN_ON(!test_bit(STATUS_READY, &priv->status)))
  1918. ret = -EIO;
  1919. iwlagn_led_enable(priv);
  1920. priv->is_open = 1;
  1921. IWL_DEBUG_MAC80211(priv, "leave\n");
  1922. return 0;
  1923. }
  1924. static void iwlagn_mac_stop(struct ieee80211_hw *hw)
  1925. {
  1926. struct iwl_priv *priv = hw->priv;
  1927. IWL_DEBUG_MAC80211(priv, "enter\n");
  1928. if (!priv->is_open)
  1929. return;
  1930. priv->is_open = 0;
  1931. iwl_down(priv);
  1932. flush_workqueue(priv->workqueue);
  1933. /* User space software may expect getting rfkill changes
  1934. * even if interface is down */
  1935. iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
  1936. iwl_enable_rfkill_int(priv);
  1937. IWL_DEBUG_MAC80211(priv, "leave\n");
  1938. }
  1939. #ifdef CONFIG_PM
  1940. static int iwlagn_send_patterns(struct iwl_priv *priv,
  1941. struct cfg80211_wowlan *wowlan)
  1942. {
  1943. struct iwlagn_wowlan_patterns_cmd *pattern_cmd;
  1944. struct iwl_host_cmd cmd = {
  1945. .id = REPLY_WOWLAN_PATTERNS,
  1946. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  1947. .flags = CMD_SYNC,
  1948. };
  1949. int i, err;
  1950. if (!wowlan->n_patterns)
  1951. return 0;
  1952. cmd.len[0] = sizeof(*pattern_cmd) +
  1953. wowlan->n_patterns * sizeof(struct iwlagn_wowlan_pattern);
  1954. pattern_cmd = kmalloc(cmd.len[0], GFP_KERNEL);
  1955. if (!pattern_cmd)
  1956. return -ENOMEM;
  1957. pattern_cmd->n_patterns = cpu_to_le32(wowlan->n_patterns);
  1958. for (i = 0; i < wowlan->n_patterns; i++) {
  1959. int mask_len = DIV_ROUND_UP(wowlan->patterns[i].pattern_len, 8);
  1960. memcpy(&pattern_cmd->patterns[i].mask,
  1961. wowlan->patterns[i].mask, mask_len);
  1962. memcpy(&pattern_cmd->patterns[i].pattern,
  1963. wowlan->patterns[i].pattern,
  1964. wowlan->patterns[i].pattern_len);
  1965. pattern_cmd->patterns[i].mask_size = mask_len;
  1966. pattern_cmd->patterns[i].pattern_size =
  1967. wowlan->patterns[i].pattern_len;
  1968. }
  1969. cmd.data[0] = pattern_cmd;
  1970. err = trans_send_cmd(&priv->trans, &cmd);
  1971. kfree(pattern_cmd);
  1972. return err;
  1973. }
  1974. #endif
  1975. static void iwlagn_mac_set_rekey_data(struct ieee80211_hw *hw,
  1976. struct ieee80211_vif *vif,
  1977. struct cfg80211_gtk_rekey_data *data)
  1978. {
  1979. struct iwl_priv *priv = hw->priv;
  1980. if (iwlagn_mod_params.sw_crypto)
  1981. return;
  1982. mutex_lock(&priv->mutex);
  1983. if (priv->contexts[IWL_RXON_CTX_BSS].vif != vif)
  1984. goto out;
  1985. memcpy(priv->kek, data->kek, NL80211_KEK_LEN);
  1986. memcpy(priv->kck, data->kck, NL80211_KCK_LEN);
  1987. priv->replay_ctr = cpu_to_le64(be64_to_cpup((__be64 *)&data->replay_ctr));
  1988. priv->have_rekey_data = true;
  1989. out:
  1990. mutex_unlock(&priv->mutex);
  1991. }
  1992. struct wowlan_key_data {
  1993. struct iwl_rxon_context *ctx;
  1994. struct iwlagn_wowlan_rsc_tsc_params_cmd *rsc_tsc;
  1995. struct iwlagn_wowlan_tkip_params_cmd *tkip;
  1996. const u8 *bssid;
  1997. bool error, use_rsc_tsc, use_tkip;
  1998. };
  1999. #ifdef CONFIG_PM
  2000. static void iwlagn_convert_p1k(u16 *p1k, __le16 *out)
  2001. {
  2002. int i;
  2003. for (i = 0; i < IWLAGN_P1K_SIZE; i++)
  2004. out[i] = cpu_to_le16(p1k[i]);
  2005. }
  2006. static void iwlagn_wowlan_program_keys(struct ieee80211_hw *hw,
  2007. struct ieee80211_vif *vif,
  2008. struct ieee80211_sta *sta,
  2009. struct ieee80211_key_conf *key,
  2010. void *_data)
  2011. {
  2012. struct iwl_priv *priv = hw->priv;
  2013. struct wowlan_key_data *data = _data;
  2014. struct iwl_rxon_context *ctx = data->ctx;
  2015. struct aes_sc *aes_sc, *aes_tx_sc = NULL;
  2016. struct tkip_sc *tkip_sc, *tkip_tx_sc = NULL;
  2017. struct iwlagn_p1k_cache *rx_p1ks;
  2018. u8 *rx_mic_key;
  2019. struct ieee80211_key_seq seq;
  2020. u32 cur_rx_iv32 = 0;
  2021. u16 p1k[IWLAGN_P1K_SIZE];
  2022. int ret, i;
  2023. mutex_lock(&priv->mutex);
  2024. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2025. key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
  2026. !sta && !ctx->key_mapping_keys)
  2027. ret = iwl_set_default_wep_key(priv, ctx, key);
  2028. else
  2029. ret = iwl_set_dynamic_key(priv, ctx, key, sta);
  2030. if (ret) {
  2031. IWL_ERR(priv, "Error setting key during suspend!\n");
  2032. data->error = true;
  2033. }
  2034. switch (key->cipher) {
  2035. case WLAN_CIPHER_SUITE_TKIP:
  2036. if (sta) {
  2037. tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.unicast_rsc;
  2038. tkip_tx_sc = &data->rsc_tsc->all_tsc_rsc.tkip.tsc;
  2039. rx_p1ks = data->tkip->rx_uni;
  2040. ieee80211_get_key_tx_seq(key, &seq);
  2041. tkip_tx_sc->iv16 = cpu_to_le16(seq.tkip.iv16);
  2042. tkip_tx_sc->iv32 = cpu_to_le32(seq.tkip.iv32);
  2043. ieee80211_get_tkip_p1k_iv(key, seq.tkip.iv32, p1k);
  2044. iwlagn_convert_p1k(p1k, data->tkip->tx.p1k);
  2045. memcpy(data->tkip->mic_keys.tx,
  2046. &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY],
  2047. IWLAGN_MIC_KEY_SIZE);
  2048. rx_mic_key = data->tkip->mic_keys.rx_unicast;
  2049. } else {
  2050. tkip_sc = data->rsc_tsc->all_tsc_rsc.tkip.multicast_rsc;
  2051. rx_p1ks = data->tkip->rx_multi;
  2052. rx_mic_key = data->tkip->mic_keys.rx_mcast;
  2053. }
  2054. /*
  2055. * For non-QoS this relies on the fact that both the uCode and
  2056. * mac80211 use TID 0 (as they need to to avoid replay attacks)
  2057. * for checking the IV in the frames.
  2058. */
  2059. for (i = 0; i < IWLAGN_NUM_RSC; i++) {
  2060. ieee80211_get_key_rx_seq(key, i, &seq);
  2061. tkip_sc[i].iv16 = cpu_to_le16(seq.tkip.iv16);
  2062. tkip_sc[i].iv32 = cpu_to_le32(seq.tkip.iv32);
  2063. /* wrapping isn't allowed, AP must rekey */
  2064. if (seq.tkip.iv32 > cur_rx_iv32)
  2065. cur_rx_iv32 = seq.tkip.iv32;
  2066. }
  2067. ieee80211_get_tkip_rx_p1k(key, data->bssid, cur_rx_iv32, p1k);
  2068. iwlagn_convert_p1k(p1k, rx_p1ks[0].p1k);
  2069. ieee80211_get_tkip_rx_p1k(key, data->bssid,
  2070. cur_rx_iv32 + 1, p1k);
  2071. iwlagn_convert_p1k(p1k, rx_p1ks[1].p1k);
  2072. memcpy(rx_mic_key,
  2073. &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY],
  2074. IWLAGN_MIC_KEY_SIZE);
  2075. data->use_tkip = true;
  2076. data->use_rsc_tsc = true;
  2077. break;
  2078. case WLAN_CIPHER_SUITE_CCMP:
  2079. if (sta) {
  2080. u8 *pn = seq.ccmp.pn;
  2081. aes_sc = data->rsc_tsc->all_tsc_rsc.aes.unicast_rsc;
  2082. aes_tx_sc = &data->rsc_tsc->all_tsc_rsc.aes.tsc;
  2083. ieee80211_get_key_tx_seq(key, &seq);
  2084. aes_tx_sc->pn = cpu_to_le64(
  2085. (u64)pn[5] |
  2086. ((u64)pn[4] << 8) |
  2087. ((u64)pn[3] << 16) |
  2088. ((u64)pn[2] << 24) |
  2089. ((u64)pn[1] << 32) |
  2090. ((u64)pn[0] << 40));
  2091. } else
  2092. aes_sc = data->rsc_tsc->all_tsc_rsc.aes.multicast_rsc;
  2093. /*
  2094. * For non-QoS this relies on the fact that both the uCode and
  2095. * mac80211 use TID 0 for checking the IV in the frames.
  2096. */
  2097. for (i = 0; i < IWLAGN_NUM_RSC; i++) {
  2098. u8 *pn = seq.ccmp.pn;
  2099. ieee80211_get_key_rx_seq(key, i, &seq);
  2100. aes_sc->pn = cpu_to_le64(
  2101. (u64)pn[5] |
  2102. ((u64)pn[4] << 8) |
  2103. ((u64)pn[3] << 16) |
  2104. ((u64)pn[2] << 24) |
  2105. ((u64)pn[1] << 32) |
  2106. ((u64)pn[0] << 40));
  2107. }
  2108. data->use_rsc_tsc = true;
  2109. break;
  2110. }
  2111. mutex_unlock(&priv->mutex);
  2112. }
  2113. static int iwlagn_mac_suspend(struct ieee80211_hw *hw,
  2114. struct cfg80211_wowlan *wowlan)
  2115. {
  2116. struct iwl_priv *priv = hw->priv;
  2117. struct iwlagn_wowlan_wakeup_filter_cmd wakeup_filter_cmd;
  2118. struct iwl_rxon_cmd rxon;
  2119. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2120. struct iwlagn_wowlan_kek_kck_material_cmd kek_kck_cmd;
  2121. struct iwlagn_wowlan_tkip_params_cmd tkip_cmd = {};
  2122. struct wowlan_key_data key_data = {
  2123. .ctx = ctx,
  2124. .bssid = ctx->active.bssid_addr,
  2125. .use_rsc_tsc = false,
  2126. .tkip = &tkip_cmd,
  2127. .use_tkip = false,
  2128. };
  2129. int ret, i;
  2130. u16 seq;
  2131. if (WARN_ON(!wowlan))
  2132. return -EINVAL;
  2133. mutex_lock(&priv->mutex);
  2134. /* Don't attempt WoWLAN when not associated, tear down instead. */
  2135. if (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION ||
  2136. !iwl_is_associated_ctx(ctx)) {
  2137. ret = 1;
  2138. goto out;
  2139. }
  2140. key_data.rsc_tsc = kzalloc(sizeof(*key_data.rsc_tsc), GFP_KERNEL);
  2141. if (!key_data.rsc_tsc) {
  2142. ret = -ENOMEM;
  2143. goto out;
  2144. }
  2145. memset(&wakeup_filter_cmd, 0, sizeof(wakeup_filter_cmd));
  2146. /*
  2147. * We know the last used seqno, and the uCode expects to know that
  2148. * one, it will increment before TX.
  2149. */
  2150. seq = le16_to_cpu(priv->last_seq_ctl) & IEEE80211_SCTL_SEQ;
  2151. wakeup_filter_cmd.non_qos_seq = cpu_to_le16(seq);
  2152. /*
  2153. * For QoS counters, we store the one to use next, so subtract 0x10
  2154. * since the uCode will add 0x10 before using the value.
  2155. */
  2156. for (i = 0; i < 8; i++) {
  2157. seq = priv->stations[IWL_AP_ID].tid[i].seq_number;
  2158. seq -= 0x10;
  2159. wakeup_filter_cmd.qos_seq[i] = cpu_to_le16(seq);
  2160. }
  2161. if (wowlan->disconnect)
  2162. wakeup_filter_cmd.enabled |=
  2163. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_BEACON_MISS |
  2164. IWLAGN_WOWLAN_WAKEUP_LINK_CHANGE);
  2165. if (wowlan->magic_pkt)
  2166. wakeup_filter_cmd.enabled |=
  2167. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_MAGIC_PACKET);
  2168. if (wowlan->gtk_rekey_failure)
  2169. wakeup_filter_cmd.enabled |=
  2170. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_GTK_REKEY_FAIL);
  2171. if (wowlan->eap_identity_req)
  2172. wakeup_filter_cmd.enabled |=
  2173. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_EAP_IDENT_REQ);
  2174. if (wowlan->four_way_handshake)
  2175. wakeup_filter_cmd.enabled |=
  2176. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_4WAY_HANDSHAKE);
  2177. if (wowlan->rfkill_release)
  2178. wakeup_filter_cmd.enabled |=
  2179. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_RFKILL);
  2180. if (wowlan->n_patterns)
  2181. wakeup_filter_cmd.enabled |=
  2182. cpu_to_le32(IWLAGN_WOWLAN_WAKEUP_PATTERN_MATCH);
  2183. iwl_scan_cancel_timeout(priv, 200);
  2184. memcpy(&rxon, &ctx->active, sizeof(rxon));
  2185. trans_stop_device(&priv->trans);
  2186. priv->wowlan = true;
  2187. ret = iwlagn_load_ucode_wait_alive(priv, &priv->ucode_wowlan,
  2188. IWL_UCODE_WOWLAN);
  2189. if (ret)
  2190. goto error;
  2191. /* now configure WoWLAN ucode */
  2192. ret = iwl_alive_start(priv);
  2193. if (ret)
  2194. goto error;
  2195. memcpy(&ctx->staging, &rxon, sizeof(rxon));
  2196. ret = iwlagn_commit_rxon(priv, ctx);
  2197. if (ret)
  2198. goto error;
  2199. ret = iwl_power_update_mode(priv, true);
  2200. if (ret)
  2201. goto error;
  2202. if (!iwlagn_mod_params.sw_crypto) {
  2203. /* mark all keys clear */
  2204. priv->ucode_key_table = 0;
  2205. ctx->key_mapping_keys = 0;
  2206. /*
  2207. * This needs to be unlocked due to lock ordering
  2208. * constraints. Since we're in the suspend path
  2209. * that isn't really a problem though.
  2210. */
  2211. mutex_unlock(&priv->mutex);
  2212. ieee80211_iter_keys(priv->hw, ctx->vif,
  2213. iwlagn_wowlan_program_keys,
  2214. &key_data);
  2215. mutex_lock(&priv->mutex);
  2216. if (key_data.error) {
  2217. ret = -EIO;
  2218. goto error;
  2219. }
  2220. if (key_data.use_rsc_tsc) {
  2221. struct iwl_host_cmd rsc_tsc_cmd = {
  2222. .id = REPLY_WOWLAN_TSC_RSC_PARAMS,
  2223. .flags = CMD_SYNC,
  2224. .data[0] = key_data.rsc_tsc,
  2225. .dataflags[0] = IWL_HCMD_DFL_NOCOPY,
  2226. .len[0] = sizeof(*key_data.rsc_tsc),
  2227. };
  2228. ret = trans_send_cmd(&priv->trans, &rsc_tsc_cmd);
  2229. if (ret)
  2230. goto error;
  2231. }
  2232. if (key_data.use_tkip) {
  2233. ret = trans_send_cmd_pdu(&priv->trans,
  2234. REPLY_WOWLAN_TKIP_PARAMS,
  2235. CMD_SYNC, sizeof(tkip_cmd),
  2236. &tkip_cmd);
  2237. if (ret)
  2238. goto error;
  2239. }
  2240. if (priv->have_rekey_data) {
  2241. memset(&kek_kck_cmd, 0, sizeof(kek_kck_cmd));
  2242. memcpy(kek_kck_cmd.kck, priv->kck, NL80211_KCK_LEN);
  2243. kek_kck_cmd.kck_len = cpu_to_le16(NL80211_KCK_LEN);
  2244. memcpy(kek_kck_cmd.kek, priv->kek, NL80211_KEK_LEN);
  2245. kek_kck_cmd.kek_len = cpu_to_le16(NL80211_KEK_LEN);
  2246. kek_kck_cmd.replay_ctr = priv->replay_ctr;
  2247. ret = trans_send_cmd_pdu(&priv->trans,
  2248. REPLY_WOWLAN_KEK_KCK_MATERIAL,
  2249. CMD_SYNC, sizeof(kek_kck_cmd),
  2250. &kek_kck_cmd);
  2251. if (ret)
  2252. goto error;
  2253. }
  2254. }
  2255. ret = trans_send_cmd_pdu(&priv->trans, REPLY_WOWLAN_WAKEUP_FILTER,
  2256. CMD_SYNC, sizeof(wakeup_filter_cmd),
  2257. &wakeup_filter_cmd);
  2258. if (ret)
  2259. goto error;
  2260. ret = iwlagn_send_patterns(priv, wowlan);
  2261. if (ret)
  2262. goto error;
  2263. device_set_wakeup_enable(priv->bus->dev, true);
  2264. /* Now let the ucode operate on its own */
  2265. iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
  2266. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  2267. goto out;
  2268. error:
  2269. priv->wowlan = false;
  2270. iwlagn_prepare_restart(priv);
  2271. ieee80211_restart_hw(priv->hw);
  2272. out:
  2273. mutex_unlock(&priv->mutex);
  2274. kfree(key_data.rsc_tsc);
  2275. return ret;
  2276. }
  2277. static int iwlagn_mac_resume(struct ieee80211_hw *hw)
  2278. {
  2279. struct iwl_priv *priv = hw->priv;
  2280. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2281. struct ieee80211_vif *vif;
  2282. unsigned long flags;
  2283. u32 base, status = 0xffffffff;
  2284. int ret = -EIO;
  2285. mutex_lock(&priv->mutex);
  2286. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  2287. CSR_UCODE_DRV_GP1_BIT_D3_CFG_COMPLETE);
  2288. base = priv->device_pointers.error_event_table;
  2289. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  2290. spin_lock_irqsave(&priv->reg_lock, flags);
  2291. ret = iwl_grab_nic_access_silent(priv);
  2292. if (ret == 0) {
  2293. iwl_write32(priv, HBUS_TARG_MEM_RADDR, base);
  2294. status = iwl_read32(priv, HBUS_TARG_MEM_RDAT);
  2295. iwl_release_nic_access(priv);
  2296. }
  2297. spin_unlock_irqrestore(&priv->reg_lock, flags);
  2298. #ifdef CONFIG_IWLWIFI_DEBUGFS
  2299. if (ret == 0) {
  2300. if (!priv->wowlan_sram)
  2301. priv->wowlan_sram =
  2302. kzalloc(priv->ucode_wowlan.data.len,
  2303. GFP_KERNEL);
  2304. if (priv->wowlan_sram)
  2305. _iwl_read_targ_mem_words(
  2306. priv, 0x800000, priv->wowlan_sram,
  2307. priv->ucode_wowlan.data.len / 4);
  2308. }
  2309. #endif
  2310. }
  2311. /* we'll clear ctx->vif during iwlagn_prepare_restart() */
  2312. vif = ctx->vif;
  2313. priv->wowlan = false;
  2314. device_set_wakeup_enable(priv->bus->dev, false);
  2315. iwlagn_prepare_restart(priv);
  2316. memset((void *)&ctx->active, 0, sizeof(ctx->active));
  2317. iwl_connection_init_rx_config(priv, ctx);
  2318. iwlagn_set_rxon_chain(priv, ctx);
  2319. mutex_unlock(&priv->mutex);
  2320. ieee80211_resume_disconnect(vif);
  2321. return 1;
  2322. }
  2323. #endif
  2324. static void iwlagn_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2325. {
  2326. struct iwl_priv *priv = hw->priv;
  2327. IWL_DEBUG_MACDUMP(priv, "enter\n");
  2328. IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
  2329. ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
  2330. if (iwlagn_tx_skb(priv, skb))
  2331. dev_kfree_skb_any(skb);
  2332. IWL_DEBUG_MACDUMP(priv, "leave\n");
  2333. }
  2334. static void iwlagn_mac_update_tkip_key(struct ieee80211_hw *hw,
  2335. struct ieee80211_vif *vif,
  2336. struct ieee80211_key_conf *keyconf,
  2337. struct ieee80211_sta *sta,
  2338. u32 iv32, u16 *phase1key)
  2339. {
  2340. struct iwl_priv *priv = hw->priv;
  2341. iwl_update_tkip_key(priv, vif, keyconf, sta, iv32, phase1key);
  2342. }
  2343. static int iwlagn_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
  2344. struct ieee80211_vif *vif,
  2345. struct ieee80211_sta *sta,
  2346. struct ieee80211_key_conf *key)
  2347. {
  2348. struct iwl_priv *priv = hw->priv;
  2349. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2350. struct iwl_rxon_context *ctx = vif_priv->ctx;
  2351. int ret;
  2352. bool is_default_wep_key = false;
  2353. IWL_DEBUG_MAC80211(priv, "enter\n");
  2354. if (iwlagn_mod_params.sw_crypto) {
  2355. IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
  2356. return -EOPNOTSUPP;
  2357. }
  2358. /*
  2359. * We could program these keys into the hardware as well, but we
  2360. * don't expect much multicast traffic in IBSS and having keys
  2361. * for more stations is probably more useful.
  2362. *
  2363. * Mark key TX-only and return 0.
  2364. */
  2365. if (vif->type == NL80211_IFTYPE_ADHOC &&
  2366. !(key->flags & IEEE80211_KEY_FLAG_PAIRWISE)) {
  2367. key->hw_key_idx = WEP_INVALID_OFFSET;
  2368. return 0;
  2369. }
  2370. /* If they key was TX-only, accept deletion */
  2371. if (cmd == DISABLE_KEY && key->hw_key_idx == WEP_INVALID_OFFSET)
  2372. return 0;
  2373. mutex_lock(&priv->mutex);
  2374. iwl_scan_cancel_timeout(priv, 100);
  2375. BUILD_BUG_ON(WEP_INVALID_OFFSET == IWLAGN_HW_KEY_DEFAULT);
  2376. /*
  2377. * If we are getting WEP group key and we didn't receive any key mapping
  2378. * so far, we are in legacy wep mode (group key only), otherwise we are
  2379. * in 1X mode.
  2380. * In legacy wep mode, we use another host command to the uCode.
  2381. */
  2382. if ((key->cipher == WLAN_CIPHER_SUITE_WEP40 ||
  2383. key->cipher == WLAN_CIPHER_SUITE_WEP104) && !sta) {
  2384. if (cmd == SET_KEY)
  2385. is_default_wep_key = !ctx->key_mapping_keys;
  2386. else
  2387. is_default_wep_key =
  2388. key->hw_key_idx == IWLAGN_HW_KEY_DEFAULT;
  2389. }
  2390. switch (cmd) {
  2391. case SET_KEY:
  2392. if (is_default_wep_key) {
  2393. ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
  2394. break;
  2395. }
  2396. ret = iwl_set_dynamic_key(priv, vif_priv->ctx, key, sta);
  2397. if (ret) {
  2398. /*
  2399. * can't add key for RX, but we don't need it
  2400. * in the device for TX so still return 0
  2401. */
  2402. ret = 0;
  2403. key->hw_key_idx = WEP_INVALID_OFFSET;
  2404. }
  2405. IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
  2406. break;
  2407. case DISABLE_KEY:
  2408. if (is_default_wep_key)
  2409. ret = iwl_remove_default_wep_key(priv, ctx, key);
  2410. else
  2411. ret = iwl_remove_dynamic_key(priv, ctx, key, sta);
  2412. IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
  2413. break;
  2414. default:
  2415. ret = -EINVAL;
  2416. }
  2417. mutex_unlock(&priv->mutex);
  2418. IWL_DEBUG_MAC80211(priv, "leave\n");
  2419. return ret;
  2420. }
  2421. static int iwlagn_mac_ampdu_action(struct ieee80211_hw *hw,
  2422. struct ieee80211_vif *vif,
  2423. enum ieee80211_ampdu_mlme_action action,
  2424. struct ieee80211_sta *sta, u16 tid, u16 *ssn,
  2425. u8 buf_size)
  2426. {
  2427. struct iwl_priv *priv = hw->priv;
  2428. int ret = -EINVAL;
  2429. struct iwl_station_priv *sta_priv = (void *) sta->drv_priv;
  2430. IWL_DEBUG_HT(priv, "A-MPDU action on addr %pM tid %d\n",
  2431. sta->addr, tid);
  2432. if (!(priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE))
  2433. return -EACCES;
  2434. mutex_lock(&priv->mutex);
  2435. switch (action) {
  2436. case IEEE80211_AMPDU_RX_START:
  2437. IWL_DEBUG_HT(priv, "start Rx\n");
  2438. ret = iwl_sta_rx_agg_start(priv, sta, tid, *ssn);
  2439. break;
  2440. case IEEE80211_AMPDU_RX_STOP:
  2441. IWL_DEBUG_HT(priv, "stop Rx\n");
  2442. ret = iwl_sta_rx_agg_stop(priv, sta, tid);
  2443. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2444. ret = 0;
  2445. break;
  2446. case IEEE80211_AMPDU_TX_START:
  2447. IWL_DEBUG_HT(priv, "start Tx\n");
  2448. ret = iwlagn_tx_agg_start(priv, vif, sta, tid, ssn);
  2449. if (ret == 0) {
  2450. priv->agg_tids_count++;
  2451. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  2452. priv->agg_tids_count);
  2453. }
  2454. break;
  2455. case IEEE80211_AMPDU_TX_STOP:
  2456. IWL_DEBUG_HT(priv, "stop Tx\n");
  2457. ret = iwlagn_tx_agg_stop(priv, vif, sta, tid);
  2458. if ((ret == 0) && (priv->agg_tids_count > 0)) {
  2459. priv->agg_tids_count--;
  2460. IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n",
  2461. priv->agg_tids_count);
  2462. }
  2463. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  2464. ret = 0;
  2465. if (priv->cfg->ht_params &&
  2466. priv->cfg->ht_params->use_rts_for_aggregation) {
  2467. /*
  2468. * switch off RTS/CTS if it was previously enabled
  2469. */
  2470. sta_priv->lq_sta.lq.general_params.flags &=
  2471. ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2472. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2473. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2474. }
  2475. break;
  2476. case IEEE80211_AMPDU_TX_OPERATIONAL:
  2477. buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF);
  2478. trans_txq_agg_setup(&priv->trans, iwl_sta_id(sta), tid,
  2479. buf_size);
  2480. /*
  2481. * If the limit is 0, then it wasn't initialised yet,
  2482. * use the default. We can do that since we take the
  2483. * minimum below, and we don't want to go above our
  2484. * default due to hardware restrictions.
  2485. */
  2486. if (sta_priv->max_agg_bufsize == 0)
  2487. sta_priv->max_agg_bufsize =
  2488. LINK_QUAL_AGG_FRAME_LIMIT_DEF;
  2489. /*
  2490. * Even though in theory the peer could have different
  2491. * aggregation reorder buffer sizes for different sessions,
  2492. * our ucode doesn't allow for that and has a global limit
  2493. * for each station. Therefore, use the minimum of all the
  2494. * aggregation sessions and our default value.
  2495. */
  2496. sta_priv->max_agg_bufsize =
  2497. min(sta_priv->max_agg_bufsize, buf_size);
  2498. if (priv->cfg->ht_params &&
  2499. priv->cfg->ht_params->use_rts_for_aggregation) {
  2500. /*
  2501. * switch to RTS/CTS if it is the prefer protection
  2502. * method for HT traffic
  2503. */
  2504. sta_priv->lq_sta.lq.general_params.flags |=
  2505. LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
  2506. }
  2507. sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit =
  2508. sta_priv->max_agg_bufsize;
  2509. iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
  2510. &sta_priv->lq_sta.lq, CMD_ASYNC, false);
  2511. IWL_INFO(priv, "Tx aggregation enabled on ra = %pM tid = %d\n",
  2512. sta->addr, tid);
  2513. ret = 0;
  2514. break;
  2515. }
  2516. mutex_unlock(&priv->mutex);
  2517. return ret;
  2518. }
  2519. static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
  2520. struct ieee80211_vif *vif,
  2521. struct ieee80211_sta *sta)
  2522. {
  2523. struct iwl_priv *priv = hw->priv;
  2524. struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
  2525. struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
  2526. bool is_ap = vif->type == NL80211_IFTYPE_STATION;
  2527. int ret;
  2528. u8 sta_id;
  2529. IWL_DEBUG_INFO(priv, "received request to add station %pM\n",
  2530. sta->addr);
  2531. mutex_lock(&priv->mutex);
  2532. IWL_DEBUG_INFO(priv, "proceeding to add station %pM\n",
  2533. sta->addr);
  2534. sta_priv->common.sta_id = IWL_INVALID_STATION;
  2535. atomic_set(&sta_priv->pending_frames, 0);
  2536. if (vif->type == NL80211_IFTYPE_AP)
  2537. sta_priv->client = true;
  2538. ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
  2539. is_ap, sta, &sta_id);
  2540. if (ret) {
  2541. IWL_ERR(priv, "Unable to add station %pM (%d)\n",
  2542. sta->addr, ret);
  2543. /* Should we return success if return code is EEXIST ? */
  2544. mutex_unlock(&priv->mutex);
  2545. return ret;
  2546. }
  2547. sta_priv->common.sta_id = sta_id;
  2548. /* Initialize rate scaling */
  2549. IWL_DEBUG_INFO(priv, "Initializing rate scaling for station %pM\n",
  2550. sta->addr);
  2551. iwl_rs_rate_init(priv, sta, sta_id);
  2552. mutex_unlock(&priv->mutex);
  2553. return 0;
  2554. }
  2555. static void iwlagn_mac_channel_switch(struct ieee80211_hw *hw,
  2556. struct ieee80211_channel_switch *ch_switch)
  2557. {
  2558. struct iwl_priv *priv = hw->priv;
  2559. const struct iwl_channel_info *ch_info;
  2560. struct ieee80211_conf *conf = &hw->conf;
  2561. struct ieee80211_channel *channel = ch_switch->channel;
  2562. struct iwl_ht_config *ht_conf = &priv->current_ht_config;
  2563. /*
  2564. * MULTI-FIXME
  2565. * When we add support for multiple interfaces, we need to
  2566. * revisit this. The channel switch command in the device
  2567. * only affects the BSS context, but what does that really
  2568. * mean? And what if we get a CSA on the second interface?
  2569. * This needs a lot of work.
  2570. */
  2571. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  2572. u16 ch;
  2573. IWL_DEBUG_MAC80211(priv, "enter\n");
  2574. mutex_lock(&priv->mutex);
  2575. if (iwl_is_rfkill(priv))
  2576. goto out;
  2577. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  2578. test_bit(STATUS_SCANNING, &priv->status) ||
  2579. test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
  2580. goto out;
  2581. if (!iwl_is_associated_ctx(ctx))
  2582. goto out;
  2583. if (!priv->cfg->lib->set_channel_switch)
  2584. goto out;
  2585. ch = channel->hw_value;
  2586. if (le16_to_cpu(ctx->active.channel) == ch)
  2587. goto out;
  2588. ch_info = iwl_get_channel_info(priv, channel->band, ch);
  2589. if (!is_channel_valid(ch_info)) {
  2590. IWL_DEBUG_MAC80211(priv, "invalid channel\n");
  2591. goto out;
  2592. }
  2593. spin_lock_irq(&priv->lock);
  2594. priv->current_ht_config.smps = conf->smps_mode;
  2595. /* Configure HT40 channels */
  2596. ctx->ht.enabled = conf_is_ht(conf);
  2597. if (ctx->ht.enabled) {
  2598. if (conf_is_ht40_minus(conf)) {
  2599. ctx->ht.extension_chan_offset =
  2600. IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2601. ctx->ht.is_40mhz = true;
  2602. } else if (conf_is_ht40_plus(conf)) {
  2603. ctx->ht.extension_chan_offset =
  2604. IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2605. ctx->ht.is_40mhz = true;
  2606. } else {
  2607. ctx->ht.extension_chan_offset =
  2608. IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2609. ctx->ht.is_40mhz = false;
  2610. }
  2611. } else
  2612. ctx->ht.is_40mhz = false;
  2613. if ((le16_to_cpu(ctx->staging.channel) != ch))
  2614. ctx->staging.flags = 0;
  2615. iwl_set_rxon_channel(priv, channel, ctx);
  2616. iwl_set_rxon_ht(priv, ht_conf);
  2617. iwl_set_flags_for_band(priv, ctx, channel->band, ctx->vif);
  2618. spin_unlock_irq(&priv->lock);
  2619. iwl_set_rate(priv);
  2620. /*
  2621. * at this point, staging_rxon has the
  2622. * configuration for channel switch
  2623. */
  2624. set_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  2625. priv->switch_channel = cpu_to_le16(ch);
  2626. if (priv->cfg->lib->set_channel_switch(priv, ch_switch)) {
  2627. clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status);
  2628. priv->switch_channel = 0;
  2629. ieee80211_chswitch_done(ctx->vif, false);
  2630. }
  2631. out:
  2632. mutex_unlock(&priv->mutex);
  2633. IWL_DEBUG_MAC80211(priv, "leave\n");
  2634. }
  2635. static void iwlagn_configure_filter(struct ieee80211_hw *hw,
  2636. unsigned int changed_flags,
  2637. unsigned int *total_flags,
  2638. u64 multicast)
  2639. {
  2640. struct iwl_priv *priv = hw->priv;
  2641. __le32 filter_or = 0, filter_nand = 0;
  2642. struct iwl_rxon_context *ctx;
  2643. #define CHK(test, flag) do { \
  2644. if (*total_flags & (test)) \
  2645. filter_or |= (flag); \
  2646. else \
  2647. filter_nand |= (flag); \
  2648. } while (0)
  2649. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  2650. changed_flags, *total_flags);
  2651. CHK(FIF_OTHER_BSS | FIF_PROMISC_IN_BSS, RXON_FILTER_PROMISC_MSK);
  2652. /* Setting _just_ RXON_FILTER_CTL2HOST_MSK causes FH errors */
  2653. CHK(FIF_CONTROL, RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_PROMISC_MSK);
  2654. CHK(FIF_BCN_PRBRESP_PROMISC, RXON_FILTER_BCON_AWARE_MSK);
  2655. #undef CHK
  2656. mutex_lock(&priv->mutex);
  2657. for_each_context(priv, ctx) {
  2658. ctx->staging.filter_flags &= ~filter_nand;
  2659. ctx->staging.filter_flags |= filter_or;
  2660. /*
  2661. * Not committing directly because hardware can perform a scan,
  2662. * but we'll eventually commit the filter flags change anyway.
  2663. */
  2664. }
  2665. mutex_unlock(&priv->mutex);
  2666. /*
  2667. * Receiving all multicast frames is always enabled by the
  2668. * default flags setup in iwl_connection_init_rx_config()
  2669. * since we currently do not support programming multicast
  2670. * filters into the device.
  2671. */
  2672. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  2673. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  2674. }
  2675. static void iwlagn_mac_flush(struct ieee80211_hw *hw, bool drop)
  2676. {
  2677. struct iwl_priv *priv = hw->priv;
  2678. mutex_lock(&priv->mutex);
  2679. IWL_DEBUG_MAC80211(priv, "enter\n");
  2680. if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  2681. IWL_DEBUG_TX(priv, "Aborting flush due to device shutdown\n");
  2682. goto done;
  2683. }
  2684. if (iwl_is_rfkill(priv)) {
  2685. IWL_DEBUG_TX(priv, "Aborting flush due to RF Kill\n");
  2686. goto done;
  2687. }
  2688. /*
  2689. * mac80211 will not push any more frames for transmit
  2690. * until the flush is completed
  2691. */
  2692. if (drop) {
  2693. IWL_DEBUG_MAC80211(priv, "send flush command\n");
  2694. if (iwlagn_txfifo_flush(priv, IWL_DROP_ALL)) {
  2695. IWL_ERR(priv, "flush request fail\n");
  2696. goto done;
  2697. }
  2698. }
  2699. IWL_DEBUG_MAC80211(priv, "wait transmit/flush all frames\n");
  2700. iwlagn_wait_tx_queue_empty(priv);
  2701. done:
  2702. mutex_unlock(&priv->mutex);
  2703. IWL_DEBUG_MAC80211(priv, "leave\n");
  2704. }
  2705. static void iwlagn_disable_roc(struct iwl_priv *priv)
  2706. {
  2707. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  2708. struct ieee80211_channel *chan = ACCESS_ONCE(priv->hw->conf.channel);
  2709. lockdep_assert_held(&priv->mutex);
  2710. if (!ctx->is_active)
  2711. return;
  2712. ctx->staging.dev_type = RXON_DEV_TYPE_2STA;
  2713. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2714. iwl_set_rxon_channel(priv, chan, ctx);
  2715. iwl_set_flags_for_band(priv, ctx, chan->band, NULL);
  2716. priv->hw_roc_channel = NULL;
  2717. iwlagn_commit_rxon(priv, ctx);
  2718. ctx->is_active = false;
  2719. }
  2720. static void iwlagn_bg_roc_done(struct work_struct *work)
  2721. {
  2722. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  2723. hw_roc_work.work);
  2724. mutex_lock(&priv->mutex);
  2725. ieee80211_remain_on_channel_expired(priv->hw);
  2726. iwlagn_disable_roc(priv);
  2727. mutex_unlock(&priv->mutex);
  2728. }
  2729. static int iwl_mac_remain_on_channel(struct ieee80211_hw *hw,
  2730. struct ieee80211_channel *channel,
  2731. enum nl80211_channel_type channel_type,
  2732. int duration)
  2733. {
  2734. struct iwl_priv *priv = hw->priv;
  2735. int err = 0;
  2736. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2737. return -EOPNOTSUPP;
  2738. if (!(priv->contexts[IWL_RXON_CTX_PAN].interface_modes &
  2739. BIT(NL80211_IFTYPE_P2P_CLIENT)))
  2740. return -EOPNOTSUPP;
  2741. mutex_lock(&priv->mutex);
  2742. if (priv->contexts[IWL_RXON_CTX_PAN].is_active ||
  2743. test_bit(STATUS_SCAN_HW, &priv->status)) {
  2744. err = -EBUSY;
  2745. goto out;
  2746. }
  2747. priv->contexts[IWL_RXON_CTX_PAN].is_active = true;
  2748. priv->hw_roc_channel = channel;
  2749. priv->hw_roc_chantype = channel_type;
  2750. priv->hw_roc_duration = DIV_ROUND_UP(duration * 1000, 1024);
  2751. iwlagn_commit_rxon(priv, &priv->contexts[IWL_RXON_CTX_PAN]);
  2752. queue_delayed_work(priv->workqueue, &priv->hw_roc_work,
  2753. msecs_to_jiffies(duration + 20));
  2754. msleep(IWL_MIN_SLOT_TIME); /* TU is almost ms */
  2755. ieee80211_ready_on_channel(priv->hw);
  2756. out:
  2757. mutex_unlock(&priv->mutex);
  2758. return err;
  2759. }
  2760. static int iwl_mac_cancel_remain_on_channel(struct ieee80211_hw *hw)
  2761. {
  2762. struct iwl_priv *priv = hw->priv;
  2763. if (!(priv->valid_contexts & BIT(IWL_RXON_CTX_PAN)))
  2764. return -EOPNOTSUPP;
  2765. cancel_delayed_work_sync(&priv->hw_roc_work);
  2766. mutex_lock(&priv->mutex);
  2767. iwlagn_disable_roc(priv);
  2768. mutex_unlock(&priv->mutex);
  2769. return 0;
  2770. }
  2771. /*****************************************************************************
  2772. *
  2773. * driver setup and teardown
  2774. *
  2775. *****************************************************************************/
  2776. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  2777. {
  2778. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  2779. init_waitqueue_head(&priv->wait_command_queue);
  2780. INIT_WORK(&priv->restart, iwl_bg_restart);
  2781. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  2782. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  2783. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  2784. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  2785. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  2786. INIT_DELAYED_WORK(&priv->hw_roc_work, iwlagn_bg_roc_done);
  2787. iwl_setup_scan_deferred_work(priv);
  2788. if (priv->cfg->lib->bt_setup_deferred_work)
  2789. priv->cfg->lib->bt_setup_deferred_work(priv);
  2790. init_timer(&priv->statistics_periodic);
  2791. priv->statistics_periodic.data = (unsigned long)priv;
  2792. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  2793. init_timer(&priv->ucode_trace);
  2794. priv->ucode_trace.data = (unsigned long)priv;
  2795. priv->ucode_trace.function = iwl_bg_ucode_trace;
  2796. init_timer(&priv->watchdog);
  2797. priv->watchdog.data = (unsigned long)priv;
  2798. priv->watchdog.function = iwl_bg_watchdog;
  2799. }
  2800. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  2801. {
  2802. if (priv->cfg->lib->cancel_deferred_work)
  2803. priv->cfg->lib->cancel_deferred_work(priv);
  2804. cancel_work_sync(&priv->run_time_calib_work);
  2805. cancel_work_sync(&priv->beacon_update);
  2806. iwl_cancel_scan_deferred_work(priv);
  2807. cancel_work_sync(&priv->bt_full_concurrency);
  2808. cancel_work_sync(&priv->bt_runtime_config);
  2809. del_timer_sync(&priv->statistics_periodic);
  2810. del_timer_sync(&priv->ucode_trace);
  2811. }
  2812. static void iwl_init_hw_rates(struct iwl_priv *priv,
  2813. struct ieee80211_rate *rates)
  2814. {
  2815. int i;
  2816. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  2817. rates[i].bitrate = iwl_rates[i].ieee * 5;
  2818. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  2819. rates[i].hw_value_short = i;
  2820. rates[i].flags = 0;
  2821. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  2822. /*
  2823. * If CCK != 1M then set short preamble rate flag.
  2824. */
  2825. rates[i].flags |=
  2826. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  2827. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  2828. }
  2829. }
  2830. }
  2831. static int iwl_init_drv(struct iwl_priv *priv)
  2832. {
  2833. int ret;
  2834. spin_lock_init(&priv->sta_lock);
  2835. spin_lock_init(&priv->hcmd_lock);
  2836. mutex_init(&priv->mutex);
  2837. priv->ieee_channels = NULL;
  2838. priv->ieee_rates = NULL;
  2839. priv->band = IEEE80211_BAND_2GHZ;
  2840. priv->iw_mode = NL80211_IFTYPE_STATION;
  2841. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  2842. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  2843. priv->agg_tids_count = 0;
  2844. /* initialize force reset */
  2845. priv->force_reset[IWL_RF_RESET].reset_duration =
  2846. IWL_DELAY_NEXT_FORCE_RF_RESET;
  2847. priv->force_reset[IWL_FW_RESET].reset_duration =
  2848. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  2849. priv->rx_statistics_jiffies = jiffies;
  2850. /* Choose which receivers/antennas to use */
  2851. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  2852. iwl_init_scan_params(priv);
  2853. /* init bt coex */
  2854. if (priv->cfg->bt_params &&
  2855. priv->cfg->bt_params->advanced_bt_coexist) {
  2856. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  2857. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  2858. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  2859. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  2860. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  2861. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  2862. }
  2863. ret = iwl_init_channel_map(priv);
  2864. if (ret) {
  2865. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  2866. goto err;
  2867. }
  2868. ret = iwlcore_init_geos(priv);
  2869. if (ret) {
  2870. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  2871. goto err_free_channel_map;
  2872. }
  2873. iwl_init_hw_rates(priv, priv->ieee_rates);
  2874. return 0;
  2875. err_free_channel_map:
  2876. iwl_free_channel_map(priv);
  2877. err:
  2878. return ret;
  2879. }
  2880. static void iwl_uninit_drv(struct iwl_priv *priv)
  2881. {
  2882. iwl_calib_free_results(priv);
  2883. iwlcore_free_geos(priv);
  2884. iwl_free_channel_map(priv);
  2885. kfree(priv->scan_cmd);
  2886. kfree(priv->beacon_cmd);
  2887. #ifdef CONFIG_IWLWIFI_DEBUGFS
  2888. kfree(priv->wowlan_sram);
  2889. #endif
  2890. }
  2891. static void iwl_mac_rssi_callback(struct ieee80211_hw *hw,
  2892. enum ieee80211_rssi_event rssi_event)
  2893. {
  2894. struct iwl_priv *priv = hw->priv;
  2895. mutex_lock(&priv->mutex);
  2896. if (priv->cfg->bt_params &&
  2897. priv->cfg->bt_params->advanced_bt_coexist) {
  2898. if (rssi_event == RSSI_EVENT_LOW)
  2899. priv->bt_enable_pspoll = true;
  2900. else if (rssi_event == RSSI_EVENT_HIGH)
  2901. priv->bt_enable_pspoll = false;
  2902. iwlagn_send_advance_bt_config(priv);
  2903. } else {
  2904. IWL_DEBUG_MAC80211(priv, "Advanced BT coex disabled,"
  2905. "ignoring RSSI callback\n");
  2906. }
  2907. mutex_unlock(&priv->mutex);
  2908. }
  2909. struct ieee80211_ops iwlagn_hw_ops = {
  2910. .tx = iwlagn_mac_tx,
  2911. .start = iwlagn_mac_start,
  2912. .stop = iwlagn_mac_stop,
  2913. #ifdef CONFIG_PM
  2914. .suspend = iwlagn_mac_suspend,
  2915. .resume = iwlagn_mac_resume,
  2916. #endif
  2917. .add_interface = iwl_mac_add_interface,
  2918. .remove_interface = iwl_mac_remove_interface,
  2919. .change_interface = iwl_mac_change_interface,
  2920. .config = iwlagn_mac_config,
  2921. .configure_filter = iwlagn_configure_filter,
  2922. .set_key = iwlagn_mac_set_key,
  2923. .update_tkip_key = iwlagn_mac_update_tkip_key,
  2924. .set_rekey_data = iwlagn_mac_set_rekey_data,
  2925. .conf_tx = iwl_mac_conf_tx,
  2926. .bss_info_changed = iwlagn_bss_info_changed,
  2927. .ampdu_action = iwlagn_mac_ampdu_action,
  2928. .hw_scan = iwl_mac_hw_scan,
  2929. .sta_notify = iwlagn_mac_sta_notify,
  2930. .sta_add = iwlagn_mac_sta_add,
  2931. .sta_remove = iwl_mac_sta_remove,
  2932. .channel_switch = iwlagn_mac_channel_switch,
  2933. .flush = iwlagn_mac_flush,
  2934. .tx_last_beacon = iwl_mac_tx_last_beacon,
  2935. .remain_on_channel = iwl_mac_remain_on_channel,
  2936. .cancel_remain_on_channel = iwl_mac_cancel_remain_on_channel,
  2937. .offchannel_tx = iwl_mac_offchannel_tx,
  2938. .offchannel_tx_cancel_wait = iwl_mac_offchannel_tx_cancel_wait,
  2939. .rssi_callback = iwl_mac_rssi_callback,
  2940. CFG80211_TESTMODE_CMD(iwl_testmode_cmd)
  2941. CFG80211_TESTMODE_DUMP(iwl_testmode_dump)
  2942. };
  2943. static u32 iwl_hw_detect(struct iwl_priv *priv)
  2944. {
  2945. return iwl_read32(priv, CSR_HW_REV);
  2946. }
  2947. static int iwl_set_hw_params(struct iwl_priv *priv)
  2948. {
  2949. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  2950. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  2951. if (iwlagn_mod_params.amsdu_size_8K)
  2952. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
  2953. else
  2954. priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
  2955. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  2956. if (iwlagn_mod_params.disable_11n)
  2957. priv->cfg->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  2958. /* Device-specific setup */
  2959. return priv->cfg->lib->set_hw_params(priv);
  2960. }
  2961. static const u8 iwlagn_bss_ac_to_fifo[] = {
  2962. IWL_TX_FIFO_VO,
  2963. IWL_TX_FIFO_VI,
  2964. IWL_TX_FIFO_BE,
  2965. IWL_TX_FIFO_BK,
  2966. };
  2967. static const u8 iwlagn_bss_ac_to_queue[] = {
  2968. 0, 1, 2, 3,
  2969. };
  2970. static const u8 iwlagn_pan_ac_to_fifo[] = {
  2971. IWL_TX_FIFO_VO_IPAN,
  2972. IWL_TX_FIFO_VI_IPAN,
  2973. IWL_TX_FIFO_BE_IPAN,
  2974. IWL_TX_FIFO_BK_IPAN,
  2975. };
  2976. static const u8 iwlagn_pan_ac_to_queue[] = {
  2977. 7, 6, 5, 4,
  2978. };
  2979. /* This function both allocates and initializes hw and priv. */
  2980. static struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
  2981. {
  2982. struct iwl_priv *priv;
  2983. /* mac80211 allocates memory for this device instance, including
  2984. * space for this driver's private structure */
  2985. struct ieee80211_hw *hw;
  2986. hw = ieee80211_alloc_hw(sizeof(struct iwl_priv), &iwlagn_hw_ops);
  2987. if (hw == NULL) {
  2988. pr_err("%s: Can not allocate network device\n",
  2989. cfg->name);
  2990. goto out;
  2991. }
  2992. priv = hw->priv;
  2993. priv->hw = hw;
  2994. out:
  2995. return hw;
  2996. }
  2997. static void iwl_init_context(struct iwl_priv *priv)
  2998. {
  2999. int i;
  3000. /*
  3001. * The default context is always valid,
  3002. * more may be discovered when firmware
  3003. * is loaded.
  3004. */
  3005. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  3006. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  3007. priv->contexts[i].ctxid = i;
  3008. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  3009. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  3010. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  3011. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  3012. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  3013. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  3014. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  3015. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  3016. priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
  3017. priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
  3018. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  3019. BIT(NL80211_IFTYPE_ADHOC);
  3020. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  3021. BIT(NL80211_IFTYPE_STATION);
  3022. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  3023. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  3024. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  3025. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  3026. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  3027. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  3028. REPLY_WIPAN_RXON_TIMING;
  3029. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  3030. REPLY_WIPAN_RXON_ASSOC;
  3031. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  3032. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  3033. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  3034. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  3035. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  3036. priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
  3037. priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
  3038. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  3039. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  3040. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  3041. #ifdef CONFIG_IWL_P2P
  3042. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  3043. BIT(NL80211_IFTYPE_P2P_CLIENT) | BIT(NL80211_IFTYPE_P2P_GO);
  3044. #endif
  3045. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  3046. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  3047. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  3048. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  3049. }
  3050. int iwl_probe(struct iwl_bus *bus, struct iwl_cfg *cfg)
  3051. {
  3052. int err = 0;
  3053. struct iwl_priv *priv;
  3054. struct ieee80211_hw *hw;
  3055. u16 num_mac;
  3056. u32 hw_rev;
  3057. /************************
  3058. * 1. Allocating HW data
  3059. ************************/
  3060. hw = iwl_alloc_all(cfg);
  3061. if (!hw) {
  3062. err = -ENOMEM;
  3063. goto out;
  3064. }
  3065. priv = hw->priv;
  3066. priv->bus = bus;
  3067. bus_set_drv_data(priv->bus, priv);
  3068. /* At this point both hw and priv are allocated. */
  3069. SET_IEEE80211_DEV(hw, priv->bus->dev);
  3070. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  3071. priv->cfg = cfg;
  3072. priv->inta_mask = CSR_INI_SET_MASK;
  3073. /* is antenna coupling more than 35dB ? */
  3074. priv->bt_ant_couple_ok =
  3075. (iwlagn_ant_coupling > IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  3076. true : false;
  3077. /* enable/disable bt channel inhibition */
  3078. priv->bt_ch_announce = iwlagn_bt_ch_announce;
  3079. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  3080. (priv->bt_ch_announce) ? "On" : "Off");
  3081. if (iwl_alloc_traffic_mem(priv))
  3082. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  3083. /* these spin locks will be used in apm_ops.init and EEPROM access
  3084. * we should init now
  3085. */
  3086. spin_lock_init(&priv->reg_lock);
  3087. spin_lock_init(&priv->lock);
  3088. /*
  3089. * stop and reset the on-board processor just in case it is in a
  3090. * strange state ... like being left stranded by a primary kernel
  3091. * and this is now the kdump kernel trying to start up
  3092. */
  3093. iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  3094. /***********************
  3095. * 3. Read REV register
  3096. ***********************/
  3097. hw_rev = iwl_hw_detect(priv);
  3098. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  3099. priv->cfg->name, hw_rev);
  3100. err = iwl_trans_register(&priv->trans, priv);
  3101. if (err)
  3102. goto out_free_traffic_mem;
  3103. if (trans_prepare_card_hw(&priv->trans)) {
  3104. err = -EIO;
  3105. IWL_WARN(priv, "Failed, HW not ready\n");
  3106. goto out_free_trans;
  3107. }
  3108. /*****************
  3109. * 4. Read EEPROM
  3110. *****************/
  3111. /* Read the EEPROM */
  3112. err = iwl_eeprom_init(priv, hw_rev);
  3113. if (err) {
  3114. IWL_ERR(priv, "Unable to init EEPROM\n");
  3115. goto out_free_trans;
  3116. }
  3117. err = iwl_eeprom_check_version(priv);
  3118. if (err)
  3119. goto out_free_eeprom;
  3120. err = iwl_eeprom_check_sku(priv);
  3121. if (err)
  3122. goto out_free_eeprom;
  3123. /* extract MAC Address */
  3124. iwl_eeprom_get_mac(priv, priv->addresses[0].addr);
  3125. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  3126. priv->hw->wiphy->addresses = priv->addresses;
  3127. priv->hw->wiphy->n_addresses = 1;
  3128. num_mac = iwl_eeprom_query16(priv, EEPROM_NUM_MAC_ADDRESS);
  3129. if (num_mac > 1) {
  3130. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  3131. ETH_ALEN);
  3132. priv->addresses[1].addr[5]++;
  3133. priv->hw->wiphy->n_addresses++;
  3134. }
  3135. /* initialize all valid contexts */
  3136. iwl_init_context(priv);
  3137. /************************
  3138. * 5. Setup HW constants
  3139. ************************/
  3140. if (iwl_set_hw_params(priv)) {
  3141. err = -ENOENT;
  3142. IWL_ERR(priv, "failed to set hw parameters\n");
  3143. goto out_free_eeprom;
  3144. }
  3145. /*******************
  3146. * 6. Setup priv
  3147. *******************/
  3148. err = iwl_init_drv(priv);
  3149. if (err)
  3150. goto out_free_eeprom;
  3151. /* At this point both hw and priv are initialized. */
  3152. /********************
  3153. * 7. Setup services
  3154. ********************/
  3155. iwl_setup_deferred_work(priv);
  3156. iwl_setup_rx_handlers(priv);
  3157. iwl_testmode_init(priv);
  3158. /*********************************************
  3159. * 8. Enable interrupts
  3160. *********************************************/
  3161. iwl_enable_rfkill_int(priv);
  3162. /* If platform's RF_KILL switch is NOT set to KILL */
  3163. if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  3164. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  3165. else
  3166. set_bit(STATUS_RF_KILL_HW, &priv->status);
  3167. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  3168. test_bit(STATUS_RF_KILL_HW, &priv->status));
  3169. iwl_power_initialize(priv);
  3170. iwl_tt_initialize(priv);
  3171. init_completion(&priv->firmware_loading_complete);
  3172. err = iwl_request_firmware(priv, true);
  3173. if (err)
  3174. goto out_destroy_workqueue;
  3175. return 0;
  3176. out_destroy_workqueue:
  3177. destroy_workqueue(priv->workqueue);
  3178. priv->workqueue = NULL;
  3179. iwl_uninit_drv(priv);
  3180. out_free_eeprom:
  3181. iwl_eeprom_free(priv);
  3182. out_free_trans:
  3183. trans_free(&priv->trans);
  3184. out_free_traffic_mem:
  3185. iwl_free_traffic_mem(priv);
  3186. ieee80211_free_hw(priv->hw);
  3187. out:
  3188. return err;
  3189. }
  3190. void __devexit iwl_remove(struct iwl_priv * priv)
  3191. {
  3192. unsigned long flags;
  3193. wait_for_completion(&priv->firmware_loading_complete);
  3194. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  3195. iwl_dbgfs_unregister(priv);
  3196. sysfs_remove_group(&priv->bus->dev->kobj,
  3197. &iwl_attribute_group);
  3198. /* ieee80211_unregister_hw call wil cause iwl_mac_stop to
  3199. * to be called and iwl_down since we are removing the device
  3200. * we need to set STATUS_EXIT_PENDING bit.
  3201. */
  3202. set_bit(STATUS_EXIT_PENDING, &priv->status);
  3203. iwl_testmode_cleanup(priv);
  3204. iwl_leds_exit(priv);
  3205. if (priv->mac80211_registered) {
  3206. ieee80211_unregister_hw(priv->hw);
  3207. priv->mac80211_registered = 0;
  3208. }
  3209. /* Reset to low power before unloading driver. */
  3210. iwl_apm_stop(priv);
  3211. iwl_tt_exit(priv);
  3212. /* make sure we flush any pending irq or
  3213. * tasklet for the driver
  3214. */
  3215. spin_lock_irqsave(&priv->lock, flags);
  3216. iwl_disable_interrupts(priv);
  3217. spin_unlock_irqrestore(&priv->lock, flags);
  3218. trans_sync_irq(&priv->trans);
  3219. iwl_dealloc_ucode(priv);
  3220. trans_rx_free(&priv->trans);
  3221. trans_tx_free(&priv->trans);
  3222. iwl_eeprom_free(priv);
  3223. /*netif_stop_queue(dev); */
  3224. flush_workqueue(priv->workqueue);
  3225. /* ieee80211_unregister_hw calls iwl_mac_stop, which flushes
  3226. * priv->workqueue... so we can't take down the workqueue
  3227. * until now... */
  3228. destroy_workqueue(priv->workqueue);
  3229. priv->workqueue = NULL;
  3230. iwl_free_traffic_mem(priv);
  3231. trans_free(&priv->trans);
  3232. bus_set_drv_data(priv->bus, NULL);
  3233. iwl_uninit_drv(priv);
  3234. dev_kfree_skb(priv->beacon_skb);
  3235. ieee80211_free_hw(priv->hw);
  3236. }
  3237. /*****************************************************************************
  3238. *
  3239. * driver and module entry point
  3240. *
  3241. *****************************************************************************/
  3242. static int __init iwl_init(void)
  3243. {
  3244. int ret;
  3245. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  3246. pr_info(DRV_COPYRIGHT "\n");
  3247. ret = iwlagn_rate_control_register();
  3248. if (ret) {
  3249. pr_err("Unable to register rate control algorithm: %d\n", ret);
  3250. return ret;
  3251. }
  3252. ret = iwl_pci_register_driver();
  3253. if (ret)
  3254. goto error_register;
  3255. return ret;
  3256. error_register:
  3257. iwlagn_rate_control_unregister();
  3258. return ret;
  3259. }
  3260. static void __exit iwl_exit(void)
  3261. {
  3262. iwl_pci_unregister_driver();
  3263. iwlagn_rate_control_unregister();
  3264. }
  3265. module_exit(iwl_exit);
  3266. module_init(iwl_init);
  3267. #ifdef CONFIG_IWLWIFI_DEBUG
  3268. module_param_named(debug, iwl_debug_level, uint, S_IRUGO | S_IWUSR);
  3269. MODULE_PARM_DESC(debug, "debug output mask");
  3270. #endif
  3271. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  3272. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  3273. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  3274. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  3275. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  3276. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  3277. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  3278. int, S_IRUGO);
  3279. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  3280. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  3281. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  3282. module_param_named(ucode_alternative, iwlagn_wanted_ucode_alternative, int,
  3283. S_IRUGO);
  3284. MODULE_PARM_DESC(ucode_alternative,
  3285. "specify ucode alternative to use from ucode file");
  3286. module_param_named(antenna_coupling, iwlagn_ant_coupling, int, S_IRUGO);
  3287. MODULE_PARM_DESC(antenna_coupling,
  3288. "specify antenna coupling in dB (defualt: 0 dB)");
  3289. module_param_named(bt_ch_inhibition, iwlagn_bt_ch_announce, bool, S_IRUGO);
  3290. MODULE_PARM_DESC(bt_ch_inhibition,
  3291. "Disable BT channel inhibition (default: enable)");
  3292. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  3293. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  3294. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  3295. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  3296. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, bool, S_IRUGO);
  3297. MODULE_PARM_DESC(wd_disable,
  3298. "Disable stuck queue watchdog timer (default: 0 [enabled])");
  3299. /*
  3300. * set bt_coex_active to true, uCode will do kill/defer
  3301. * every time the priority line is asserted (BT is sending signals on the
  3302. * priority line in the PCIx).
  3303. * set bt_coex_active to false, uCode will ignore the BT activity and
  3304. * perform the normal operation
  3305. *
  3306. * User might experience transmit issue on some platform due to WiFi/BT
  3307. * co-exist problem. The possible behaviors are:
  3308. * Able to scan and finding all the available AP
  3309. * Not able to associate with any AP
  3310. * On those platforms, WiFi communication can be restored by set
  3311. * "bt_coex_active" module parameter to "false"
  3312. *
  3313. * default: bt_coex_active = true (BT_COEX_ENABLE)
  3314. */
  3315. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  3316. bool, S_IRUGO);
  3317. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  3318. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  3319. MODULE_PARM_DESC(led_mode, "0=system default, "
  3320. "1=On(RF On)/Off(RF Off), 2=blinking (default: 0)");
  3321. module_param_named(power_save, iwlagn_mod_params.power_save,
  3322. bool, S_IRUGO);
  3323. MODULE_PARM_DESC(power_save,
  3324. "enable WiFi power management (default: disable)");
  3325. module_param_named(power_level, iwlagn_mod_params.power_level,
  3326. int, S_IRUGO);
  3327. MODULE_PARM_DESC(power_level,
  3328. "default power save level (range from 1 - 5, default: 1)");
  3329. /*
  3330. * For now, keep using power level 1 instead of automatically
  3331. * adjusting ...
  3332. */
  3333. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  3334. bool, S_IRUGO);
  3335. MODULE_PARM_DESC(no_sleep_autoadjust,
  3336. "don't automatically adjust sleep level "
  3337. "according to maximum network latency (default: true)");