iwl-core.c 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 - 2009 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  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. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/etherdevice.h>
  31. #include <net/mac80211.h>
  32. #include "iwl-eeprom.h"
  33. #include "iwl-dev.h" /* FIXME: remove */
  34. #include "iwl-debug.h"
  35. #include "iwl-core.h"
  36. #include "iwl-io.h"
  37. #include "iwl-power.h"
  38. #include "iwl-sta.h"
  39. #include "iwl-helpers.h"
  40. MODULE_DESCRIPTION("iwl core");
  41. MODULE_VERSION(IWLWIFI_VERSION);
  42. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  43. MODULE_LICENSE("GPL");
  44. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  45. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  46. IWL_RATE_SISO_##s##M_PLCP, \
  47. IWL_RATE_MIMO2_##s##M_PLCP,\
  48. IWL_RATE_MIMO3_##s##M_PLCP,\
  49. IWL_RATE_##r##M_IEEE, \
  50. IWL_RATE_##ip##M_INDEX, \
  51. IWL_RATE_##in##M_INDEX, \
  52. IWL_RATE_##rp##M_INDEX, \
  53. IWL_RATE_##rn##M_INDEX, \
  54. IWL_RATE_##pp##M_INDEX, \
  55. IWL_RATE_##np##M_INDEX }
  56. static irqreturn_t iwl_isr(int irq, void *data);
  57. /*
  58. * Parameter order:
  59. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  60. *
  61. * If there isn't a valid next or previous rate then INV is used which
  62. * maps to IWL_RATE_INVALID
  63. *
  64. */
  65. const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
  66. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  67. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  68. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  69. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  70. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  71. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  72. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  73. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  74. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  75. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  76. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  77. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  78. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  79. /* FIXME:RS: ^^ should be INV (legacy) */
  80. };
  81. EXPORT_SYMBOL(iwl_rates);
  82. /**
  83. * translate ucode response to mac80211 tx status control values
  84. */
  85. void iwl_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
  86. struct ieee80211_tx_info *info)
  87. {
  88. int rate_index;
  89. struct ieee80211_tx_rate *r = &info->control.rates[0];
  90. info->antenna_sel_tx =
  91. ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
  92. if (rate_n_flags & RATE_MCS_HT_MSK)
  93. r->flags |= IEEE80211_TX_RC_MCS;
  94. if (rate_n_flags & RATE_MCS_GF_MSK)
  95. r->flags |= IEEE80211_TX_RC_GREEN_FIELD;
  96. if (rate_n_flags & RATE_MCS_FAT_MSK)
  97. r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH;
  98. if (rate_n_flags & RATE_MCS_DUP_MSK)
  99. r->flags |= IEEE80211_TX_RC_DUP_DATA;
  100. if (rate_n_flags & RATE_MCS_SGI_MSK)
  101. r->flags |= IEEE80211_TX_RC_SHORT_GI;
  102. rate_index = iwl_hwrate_to_plcp_idx(rate_n_flags);
  103. if (info->band == IEEE80211_BAND_5GHZ)
  104. rate_index -= IWL_FIRST_OFDM_RATE;
  105. r->idx = rate_index;
  106. }
  107. EXPORT_SYMBOL(iwl_hwrate_to_tx_control);
  108. int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
  109. {
  110. int idx = 0;
  111. /* HT rate format */
  112. if (rate_n_flags & RATE_MCS_HT_MSK) {
  113. idx = (rate_n_flags & 0xff);
  114. if (idx >= IWL_RATE_MIMO3_6M_PLCP)
  115. idx = idx - IWL_RATE_MIMO3_6M_PLCP;
  116. else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
  117. idx = idx - IWL_RATE_MIMO2_6M_PLCP;
  118. idx += IWL_FIRST_OFDM_RATE;
  119. /* skip 9M not supported in ht*/
  120. if (idx >= IWL_RATE_9M_INDEX)
  121. idx += 1;
  122. if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
  123. return idx;
  124. /* legacy rate format, search for match in table */
  125. } else {
  126. for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
  127. if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
  128. return idx;
  129. }
  130. return -1;
  131. }
  132. EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
  133. u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant)
  134. {
  135. int i;
  136. u8 ind = ant;
  137. for (i = 0; i < RATE_ANT_NUM - 1; i++) {
  138. ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
  139. if (priv->hw_params.valid_tx_ant & BIT(ind))
  140. return ind;
  141. }
  142. return ant;
  143. }
  144. const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
  145. EXPORT_SYMBOL(iwl_bcast_addr);
  146. /* This function both allocates and initializes hw and priv. */
  147. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  148. struct ieee80211_ops *hw_ops)
  149. {
  150. struct iwl_priv *priv;
  151. /* mac80211 allocates memory for this device instance, including
  152. * space for this driver's private structure */
  153. struct ieee80211_hw *hw =
  154. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  155. if (hw == NULL) {
  156. printk(KERN_ERR "%s: Can not allocate network device\n",
  157. cfg->name);
  158. goto out;
  159. }
  160. priv = hw->priv;
  161. priv->hw = hw;
  162. out:
  163. return hw;
  164. }
  165. EXPORT_SYMBOL(iwl_alloc_all);
  166. void iwl_hw_detect(struct iwl_priv *priv)
  167. {
  168. priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
  169. priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
  170. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  171. }
  172. EXPORT_SYMBOL(iwl_hw_detect);
  173. int iwl_hw_nic_init(struct iwl_priv *priv)
  174. {
  175. unsigned long flags;
  176. struct iwl_rx_queue *rxq = &priv->rxq;
  177. int ret;
  178. /* nic_init */
  179. spin_lock_irqsave(&priv->lock, flags);
  180. priv->cfg->ops->lib->apm_ops.init(priv);
  181. iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
  182. spin_unlock_irqrestore(&priv->lock, flags);
  183. ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
  184. priv->cfg->ops->lib->apm_ops.config(priv);
  185. /* Allocate the RX queue, or reset if it is already allocated */
  186. if (!rxq->bd) {
  187. ret = iwl_rx_queue_alloc(priv);
  188. if (ret) {
  189. IWL_ERR(priv, "Unable to initialize Rx queue\n");
  190. return -ENOMEM;
  191. }
  192. } else
  193. iwl_rx_queue_reset(priv, rxq);
  194. iwl_rx_replenish(priv);
  195. iwl_rx_init(priv, rxq);
  196. spin_lock_irqsave(&priv->lock, flags);
  197. rxq->need_update = 1;
  198. iwl_rx_queue_update_write_ptr(priv, rxq);
  199. spin_unlock_irqrestore(&priv->lock, flags);
  200. /* Allocate and init all Tx and Command queues */
  201. ret = iwl_txq_ctx_reset(priv);
  202. if (ret)
  203. return ret;
  204. set_bit(STATUS_INIT, &priv->status);
  205. return 0;
  206. }
  207. EXPORT_SYMBOL(iwl_hw_nic_init);
  208. /*
  209. * QoS support
  210. */
  211. void iwl_activate_qos(struct iwl_priv *priv, u8 force)
  212. {
  213. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  214. return;
  215. priv->qos_data.def_qos_parm.qos_flags = 0;
  216. if (priv->qos_data.qos_cap.q_AP.queue_request &&
  217. !priv->qos_data.qos_cap.q_AP.txop_request)
  218. priv->qos_data.def_qos_parm.qos_flags |=
  219. QOS_PARAM_FLG_TXOP_TYPE_MSK;
  220. if (priv->qos_data.qos_active)
  221. priv->qos_data.def_qos_parm.qos_flags |=
  222. QOS_PARAM_FLG_UPDATE_EDCA_MSK;
  223. if (priv->current_ht_config.is_ht)
  224. priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
  225. if (force || iwl_is_associated(priv)) {
  226. IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
  227. priv->qos_data.qos_active,
  228. priv->qos_data.def_qos_parm.qos_flags);
  229. iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
  230. sizeof(struct iwl_qosparam_cmd),
  231. &priv->qos_data.def_qos_parm, NULL);
  232. }
  233. }
  234. EXPORT_SYMBOL(iwl_activate_qos);
  235. /*
  236. * AC CWmin CW max AIFSN TXOP Limit TXOP Limit
  237. * (802.11b) (802.11a/g)
  238. * AC_BK 15 1023 7 0 0
  239. * AC_BE 15 1023 3 0 0
  240. * AC_VI 7 15 2 6.016ms 3.008ms
  241. * AC_VO 3 7 2 3.264ms 1.504ms
  242. */
  243. void iwl_reset_qos(struct iwl_priv *priv)
  244. {
  245. u16 cw_min = 15;
  246. u16 cw_max = 1023;
  247. u8 aifs = 2;
  248. bool is_legacy = false;
  249. unsigned long flags;
  250. int i;
  251. spin_lock_irqsave(&priv->lock, flags);
  252. /* QoS always active in AP and ADHOC mode
  253. * In STA mode wait for association
  254. */
  255. if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
  256. priv->iw_mode == NL80211_IFTYPE_AP)
  257. priv->qos_data.qos_active = 1;
  258. else
  259. priv->qos_data.qos_active = 0;
  260. /* check for legacy mode */
  261. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  262. (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) ||
  263. (priv->iw_mode == NL80211_IFTYPE_STATION &&
  264. (priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) {
  265. cw_min = 31;
  266. is_legacy = 1;
  267. }
  268. if (priv->qos_data.qos_active)
  269. aifs = 3;
  270. /* AC_BE */
  271. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  272. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  273. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  274. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  275. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  276. if (priv->qos_data.qos_active) {
  277. /* AC_BK */
  278. i = 1;
  279. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  280. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  281. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  282. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  283. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  284. /* AC_VI */
  285. i = 2;
  286. priv->qos_data.def_qos_parm.ac[i].cw_min =
  287. cpu_to_le16((cw_min + 1) / 2 - 1);
  288. priv->qos_data.def_qos_parm.ac[i].cw_max =
  289. cpu_to_le16(cw_min);
  290. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  291. if (is_legacy)
  292. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  293. cpu_to_le16(6016);
  294. else
  295. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  296. cpu_to_le16(3008);
  297. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  298. /* AC_VO */
  299. i = 3;
  300. priv->qos_data.def_qos_parm.ac[i].cw_min =
  301. cpu_to_le16((cw_min + 1) / 4 - 1);
  302. priv->qos_data.def_qos_parm.ac[i].cw_max =
  303. cpu_to_le16((cw_min + 1) / 2 - 1);
  304. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  305. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  306. if (is_legacy)
  307. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  308. cpu_to_le16(3264);
  309. else
  310. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  311. cpu_to_le16(1504);
  312. } else {
  313. for (i = 1; i < 4; i++) {
  314. priv->qos_data.def_qos_parm.ac[i].cw_min =
  315. cpu_to_le16(cw_min);
  316. priv->qos_data.def_qos_parm.ac[i].cw_max =
  317. cpu_to_le16(cw_max);
  318. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  319. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  320. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  321. }
  322. }
  323. IWL_DEBUG_QOS(priv, "set QoS to default \n");
  324. spin_unlock_irqrestore(&priv->lock, flags);
  325. }
  326. EXPORT_SYMBOL(iwl_reset_qos);
  327. #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
  328. #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
  329. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  330. struct ieee80211_sta_ht_cap *ht_info,
  331. enum ieee80211_band band)
  332. {
  333. u16 max_bit_rate = 0;
  334. u8 rx_chains_num = priv->hw_params.rx_chains_num;
  335. u8 tx_chains_num = priv->hw_params.tx_chains_num;
  336. ht_info->cap = 0;
  337. memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
  338. ht_info->ht_supported = true;
  339. ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
  340. ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
  341. ht_info->cap |= (IEEE80211_HT_CAP_SM_PS &
  342. (WLAN_HT_CAP_SM_PS_DISABLED << 2));
  343. max_bit_rate = MAX_BIT_RATE_20_MHZ;
  344. if (priv->hw_params.fat_channel & BIT(band)) {
  345. ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  346. ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
  347. ht_info->mcs.rx_mask[4] = 0x01;
  348. max_bit_rate = MAX_BIT_RATE_40_MHZ;
  349. }
  350. if (priv->cfg->mod_params->amsdu_size_8K)
  351. ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
  352. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  353. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  354. ht_info->mcs.rx_mask[0] = 0xFF;
  355. if (rx_chains_num >= 2)
  356. ht_info->mcs.rx_mask[1] = 0xFF;
  357. if (rx_chains_num >= 3)
  358. ht_info->mcs.rx_mask[2] = 0xFF;
  359. /* Highest supported Rx data rate */
  360. max_bit_rate *= rx_chains_num;
  361. WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
  362. ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
  363. /* Tx MCS capabilities */
  364. ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  365. if (tx_chains_num != rx_chains_num) {
  366. ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
  367. ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
  368. IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
  369. }
  370. }
  371. static void iwlcore_init_hw_rates(struct iwl_priv *priv,
  372. struct ieee80211_rate *rates)
  373. {
  374. int i;
  375. for (i = 0; i < IWL_RATE_COUNT; i++) {
  376. rates[i].bitrate = iwl_rates[i].ieee * 5;
  377. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  378. rates[i].hw_value_short = i;
  379. rates[i].flags = 0;
  380. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  381. /*
  382. * If CCK != 1M then set short preamble rate flag.
  383. */
  384. rates[i].flags |=
  385. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  386. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  387. }
  388. }
  389. }
  390. /**
  391. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  392. */
  393. int iwlcore_init_geos(struct iwl_priv *priv)
  394. {
  395. struct iwl_channel_info *ch;
  396. struct ieee80211_supported_band *sband;
  397. struct ieee80211_channel *channels;
  398. struct ieee80211_channel *geo_ch;
  399. struct ieee80211_rate *rates;
  400. int i = 0;
  401. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  402. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  403. IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
  404. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  405. return 0;
  406. }
  407. channels = kzalloc(sizeof(struct ieee80211_channel) *
  408. priv->channel_count, GFP_KERNEL);
  409. if (!channels)
  410. return -ENOMEM;
  411. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  412. GFP_KERNEL);
  413. if (!rates) {
  414. kfree(channels);
  415. return -ENOMEM;
  416. }
  417. /* 5.2GHz channels start after the 2.4GHz channels */
  418. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  419. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  420. /* just OFDM */
  421. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  422. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  423. if (priv->cfg->sku & IWL_SKU_N)
  424. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  425. IEEE80211_BAND_5GHZ);
  426. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  427. sband->channels = channels;
  428. /* OFDM & CCK */
  429. sband->bitrates = rates;
  430. sband->n_bitrates = IWL_RATE_COUNT;
  431. if (priv->cfg->sku & IWL_SKU_N)
  432. iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
  433. IEEE80211_BAND_2GHZ);
  434. priv->ieee_channels = channels;
  435. priv->ieee_rates = rates;
  436. for (i = 0; i < priv->channel_count; i++) {
  437. ch = &priv->channel_info[i];
  438. /* FIXME: might be removed if scan is OK */
  439. if (!is_channel_valid(ch))
  440. continue;
  441. if (is_channel_a_band(ch))
  442. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  443. else
  444. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  445. geo_ch = &sband->channels[sband->n_channels++];
  446. geo_ch->center_freq =
  447. ieee80211_channel_to_frequency(ch->channel);
  448. geo_ch->max_power = ch->max_power_avg;
  449. geo_ch->max_antenna_gain = 0xff;
  450. geo_ch->hw_value = ch->channel;
  451. if (is_channel_valid(ch)) {
  452. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  453. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  454. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  455. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  456. if (ch->flags & EEPROM_CHANNEL_RADAR)
  457. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  458. geo_ch->flags |= ch->fat_extension_channel;
  459. if (ch->max_power_avg > priv->tx_power_channel_lmt)
  460. priv->tx_power_channel_lmt = ch->max_power_avg;
  461. } else {
  462. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  463. }
  464. /* Save flags for reg domain usage */
  465. geo_ch->orig_flags = geo_ch->flags;
  466. IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
  467. ch->channel, geo_ch->center_freq,
  468. is_channel_a_band(ch) ? "5.2" : "2.4",
  469. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  470. "restricted" : "valid",
  471. geo_ch->flags);
  472. }
  473. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  474. priv->cfg->sku & IWL_SKU_A) {
  475. IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
  476. "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
  477. priv->pci_dev->device,
  478. priv->pci_dev->subsystem_device);
  479. priv->cfg->sku &= ~IWL_SKU_A;
  480. }
  481. IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  482. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  483. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  484. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  485. return 0;
  486. }
  487. EXPORT_SYMBOL(iwlcore_init_geos);
  488. /*
  489. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  490. */
  491. void iwlcore_free_geos(struct iwl_priv *priv)
  492. {
  493. kfree(priv->ieee_channels);
  494. kfree(priv->ieee_rates);
  495. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  496. }
  497. EXPORT_SYMBOL(iwlcore_free_geos);
  498. static bool is_single_rx_stream(struct iwl_priv *priv)
  499. {
  500. return !priv->current_ht_config.is_ht ||
  501. ((priv->current_ht_config.mcs.rx_mask[1] == 0) &&
  502. (priv->current_ht_config.mcs.rx_mask[2] == 0));
  503. }
  504. static u8 iwl_is_channel_extension(struct iwl_priv *priv,
  505. enum ieee80211_band band,
  506. u16 channel, u8 extension_chan_offset)
  507. {
  508. const struct iwl_channel_info *ch_info;
  509. ch_info = iwl_get_channel_info(priv, band, channel);
  510. if (!is_channel_valid(ch_info))
  511. return 0;
  512. if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
  513. return !(ch_info->fat_extension_channel &
  514. IEEE80211_CHAN_NO_HT40PLUS);
  515. else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  516. return !(ch_info->fat_extension_channel &
  517. IEEE80211_CHAN_NO_HT40MINUS);
  518. return 0;
  519. }
  520. u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
  521. struct ieee80211_sta_ht_cap *sta_ht_inf)
  522. {
  523. struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
  524. if ((!iwl_ht_conf->is_ht) ||
  525. (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ))
  526. return 0;
  527. /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
  528. * the bit will not set if it is pure 40MHz case
  529. */
  530. if (sta_ht_inf) {
  531. if (!sta_ht_inf->ht_supported)
  532. return 0;
  533. }
  534. return iwl_is_channel_extension(priv, priv->band,
  535. le16_to_cpu(priv->staging_rxon.channel),
  536. iwl_ht_conf->extension_chan_offset);
  537. }
  538. EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
  539. static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
  540. {
  541. u16 new_val = 0;
  542. u16 beacon_factor = 0;
  543. beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
  544. new_val = beacon_val / beacon_factor;
  545. if (!new_val)
  546. new_val = max_beacon_val;
  547. return new_val;
  548. }
  549. void iwl_setup_rxon_timing(struct iwl_priv *priv)
  550. {
  551. u64 tsf;
  552. s32 interval_tm, rem;
  553. unsigned long flags;
  554. struct ieee80211_conf *conf = NULL;
  555. u16 beacon_int;
  556. conf = ieee80211_get_hw_conf(priv->hw);
  557. spin_lock_irqsave(&priv->lock, flags);
  558. priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
  559. priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
  560. if (priv->iw_mode == NL80211_IFTYPE_STATION) {
  561. beacon_int = priv->beacon_int;
  562. priv->rxon_timing.atim_window = 0;
  563. } else {
  564. beacon_int = priv->vif->bss_conf.beacon_int;
  565. /* TODO: we need to get atim_window from upper stack
  566. * for now we set to 0 */
  567. priv->rxon_timing.atim_window = 0;
  568. }
  569. beacon_int = iwl_adjust_beacon_interval(beacon_int,
  570. priv->hw_params.max_beacon_itrvl * 1024);
  571. priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
  572. tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
  573. interval_tm = beacon_int * 1024;
  574. rem = do_div(tsf, interval_tm);
  575. priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
  576. spin_unlock_irqrestore(&priv->lock, flags);
  577. IWL_DEBUG_ASSOC(priv,
  578. "beacon interval %d beacon timer %d beacon tim %d\n",
  579. le16_to_cpu(priv->rxon_timing.beacon_interval),
  580. le32_to_cpu(priv->rxon_timing.beacon_init_val),
  581. le16_to_cpu(priv->rxon_timing.atim_window));
  582. }
  583. EXPORT_SYMBOL(iwl_setup_rxon_timing);
  584. void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
  585. {
  586. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  587. if (hw_decrypt)
  588. rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
  589. else
  590. rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
  591. }
  592. EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
  593. /**
  594. * iwl_check_rxon_cmd - validate RXON structure is valid
  595. *
  596. * NOTE: This is really only useful during development and can eventually
  597. * be #ifdef'd out once the driver is stable and folks aren't actively
  598. * making changes
  599. */
  600. int iwl_check_rxon_cmd(struct iwl_priv *priv)
  601. {
  602. int error = 0;
  603. int counter = 1;
  604. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  605. if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
  606. error |= le32_to_cpu(rxon->flags &
  607. (RXON_FLG_TGJ_NARROW_BAND_MSK |
  608. RXON_FLG_RADAR_DETECT_MSK));
  609. if (error)
  610. IWL_WARN(priv, "check 24G fields %d | %d\n",
  611. counter++, error);
  612. } else {
  613. error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
  614. 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
  615. if (error)
  616. IWL_WARN(priv, "check 52 fields %d | %d\n",
  617. counter++, error);
  618. error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
  619. if (error)
  620. IWL_WARN(priv, "check 52 CCK %d | %d\n",
  621. counter++, error);
  622. }
  623. error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
  624. if (error)
  625. IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
  626. /* make sure basic rates 6Mbps and 1Mbps are supported */
  627. error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
  628. ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
  629. if (error)
  630. IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
  631. error |= (le16_to_cpu(rxon->assoc_id) > 2007);
  632. if (error)
  633. IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
  634. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
  635. == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
  636. if (error)
  637. IWL_WARN(priv, "check CCK and short slot %d | %d\n",
  638. counter++, error);
  639. error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
  640. == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
  641. if (error)
  642. IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
  643. counter++, error);
  644. error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
  645. RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
  646. if (error)
  647. IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
  648. counter++, error);
  649. if (error)
  650. IWL_WARN(priv, "Tuning to channel %d\n",
  651. le16_to_cpu(rxon->channel));
  652. if (error) {
  653. IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
  654. return -1;
  655. }
  656. return 0;
  657. }
  658. EXPORT_SYMBOL(iwl_check_rxon_cmd);
  659. /**
  660. * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
  661. * @priv: staging_rxon is compared to active_rxon
  662. *
  663. * If the RXON structure is changing enough to require a new tune,
  664. * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
  665. * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
  666. */
  667. int iwl_full_rxon_required(struct iwl_priv *priv)
  668. {
  669. /* These items are only settable from the full RXON command */
  670. if (!(iwl_is_associated(priv)) ||
  671. compare_ether_addr(priv->staging_rxon.bssid_addr,
  672. priv->active_rxon.bssid_addr) ||
  673. compare_ether_addr(priv->staging_rxon.node_addr,
  674. priv->active_rxon.node_addr) ||
  675. compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
  676. priv->active_rxon.wlap_bssid_addr) ||
  677. (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
  678. (priv->staging_rxon.channel != priv->active_rxon.channel) ||
  679. (priv->staging_rxon.air_propagation !=
  680. priv->active_rxon.air_propagation) ||
  681. (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
  682. priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
  683. (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
  684. priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
  685. (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
  686. priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
  687. (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
  688. return 1;
  689. /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
  690. * be updated with the RXON_ASSOC command -- however only some
  691. * flag transitions are allowed using RXON_ASSOC */
  692. /* Check if we are not switching bands */
  693. if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
  694. (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
  695. return 1;
  696. /* Check if we are switching association toggle */
  697. if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
  698. (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
  699. return 1;
  700. return 0;
  701. }
  702. EXPORT_SYMBOL(iwl_full_rxon_required);
  703. u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
  704. {
  705. int i;
  706. int rate_mask;
  707. /* Set rate mask*/
  708. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  709. rate_mask = priv->active_rate_basic & IWL_CCK_RATES_MASK;
  710. else
  711. rate_mask = priv->active_rate_basic & IWL_OFDM_RATES_MASK;
  712. /* Find lowest valid rate */
  713. for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
  714. i = iwl_rates[i].next_ieee) {
  715. if (rate_mask & (1 << i))
  716. return iwl_rates[i].plcp;
  717. }
  718. /* No valid rate was found. Assign the lowest one */
  719. if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
  720. return IWL_RATE_1M_PLCP;
  721. else
  722. return IWL_RATE_6M_PLCP;
  723. }
  724. EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
  725. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
  726. {
  727. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  728. if (!ht_info->is_ht) {
  729. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  730. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
  731. RXON_FLG_FAT_PROT_MSK |
  732. RXON_FLG_HT_PROT_MSK);
  733. return;
  734. }
  735. /* FIXME: if the definition of ht_protection changed, the "translation"
  736. * will be needed for rxon->flags
  737. */
  738. rxon->flags |= cpu_to_le32(ht_info->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
  739. /* Set up channel bandwidth:
  740. * 20 MHz only, 20/40 mixed or pure 40 if fat ok */
  741. /* clear the HT channel mode before set the mode */
  742. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
  743. RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  744. if (iwl_is_fat_tx_allowed(priv, NULL)) {
  745. /* pure 40 fat */
  746. if (ht_info->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
  747. rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
  748. /* Note: control channel is opposite of extension channel */
  749. switch (ht_info->extension_chan_offset) {
  750. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  751. rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  752. break;
  753. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  754. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  755. break;
  756. }
  757. } else {
  758. /* Note: control channel is opposite of extension channel */
  759. switch (ht_info->extension_chan_offset) {
  760. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  761. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  762. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  763. break;
  764. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  765. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  766. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
  767. break;
  768. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  769. default:
  770. /* channel location only valid if in Mixed mode */
  771. IWL_ERR(priv, "invalid extension channel offset\n");
  772. break;
  773. }
  774. }
  775. } else {
  776. rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
  777. }
  778. if (priv->cfg->ops->hcmd->set_rxon_chain)
  779. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  780. IWL_DEBUG_ASSOC(priv, "supported HT rate 0x%X 0x%X 0x%X "
  781. "rxon flags 0x%X operation mode :0x%X "
  782. "extension channel offset 0x%x\n",
  783. ht_info->mcs.rx_mask[0],
  784. ht_info->mcs.rx_mask[1],
  785. ht_info->mcs.rx_mask[2],
  786. le32_to_cpu(rxon->flags), ht_info->ht_protection,
  787. ht_info->extension_chan_offset);
  788. return;
  789. }
  790. EXPORT_SYMBOL(iwl_set_rxon_ht);
  791. #define IWL_NUM_RX_CHAINS_MULTIPLE 3
  792. #define IWL_NUM_RX_CHAINS_SINGLE 2
  793. #define IWL_NUM_IDLE_CHAINS_DUAL 2
  794. #define IWL_NUM_IDLE_CHAINS_SINGLE 1
  795. /* Determine how many receiver/antenna chains to use.
  796. * More provides better reception via diversity. Fewer saves power.
  797. * MIMO (dual stream) requires at least 2, but works better with 3.
  798. * This does not determine *which* chains to use, just how many.
  799. */
  800. static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
  801. {
  802. bool is_single = is_single_rx_stream(priv);
  803. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  804. /* # of Rx chains to use when expecting MIMO. */
  805. if (is_single || (!is_cam && (priv->current_ht_config.sm_ps ==
  806. WLAN_HT_CAP_SM_PS_STATIC)))
  807. return IWL_NUM_RX_CHAINS_SINGLE;
  808. else
  809. return IWL_NUM_RX_CHAINS_MULTIPLE;
  810. }
  811. static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
  812. {
  813. int idle_cnt;
  814. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  815. /* # Rx chains when idling and maybe trying to save power */
  816. switch (priv->current_ht_config.sm_ps) {
  817. case WLAN_HT_CAP_SM_PS_STATIC:
  818. case WLAN_HT_CAP_SM_PS_DYNAMIC:
  819. idle_cnt = (is_cam) ? IWL_NUM_IDLE_CHAINS_DUAL :
  820. IWL_NUM_IDLE_CHAINS_SINGLE;
  821. break;
  822. case WLAN_HT_CAP_SM_PS_DISABLED:
  823. idle_cnt = (is_cam) ? active_cnt : IWL_NUM_IDLE_CHAINS_SINGLE;
  824. break;
  825. case WLAN_HT_CAP_SM_PS_INVALID:
  826. default:
  827. IWL_ERR(priv, "invalid mimo ps mode %d\n",
  828. priv->current_ht_config.sm_ps);
  829. WARN_ON(1);
  830. idle_cnt = -1;
  831. break;
  832. }
  833. return idle_cnt;
  834. }
  835. /* up to 4 chains */
  836. static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
  837. {
  838. u8 res;
  839. res = (chain_bitmap & BIT(0)) >> 0;
  840. res += (chain_bitmap & BIT(1)) >> 1;
  841. res += (chain_bitmap & BIT(2)) >> 2;
  842. res += (chain_bitmap & BIT(4)) >> 4;
  843. return res;
  844. }
  845. /**
  846. * iwl_is_monitor_mode - Determine if interface in monitor mode
  847. *
  848. * priv->iw_mode is set in add_interface, but add_interface is
  849. * never called for monitor mode. The only way mac80211 informs us about
  850. * monitor mode is through configuring filters (call to configure_filter).
  851. */
  852. bool iwl_is_monitor_mode(struct iwl_priv *priv)
  853. {
  854. return !!(priv->staging_rxon.filter_flags & RXON_FILTER_PROMISC_MSK);
  855. }
  856. EXPORT_SYMBOL(iwl_is_monitor_mode);
  857. /**
  858. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  859. *
  860. * Selects how many and which Rx receivers/antennas/chains to use.
  861. * This should not be used for scan command ... it puts data in wrong place.
  862. */
  863. void iwl_set_rxon_chain(struct iwl_priv *priv)
  864. {
  865. bool is_single = is_single_rx_stream(priv);
  866. bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
  867. u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
  868. u32 active_chains;
  869. u16 rx_chain;
  870. /* Tell uCode which antennas are actually connected.
  871. * Before first association, we assume all antennas are connected.
  872. * Just after first association, iwl_chain_noise_calibration()
  873. * checks which antennas actually *are* connected. */
  874. if (priv->chain_noise_data.active_chains)
  875. active_chains = priv->chain_noise_data.active_chains;
  876. else
  877. active_chains = priv->hw_params.valid_rx_ant;
  878. rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
  879. /* How many receivers should we use? */
  880. active_rx_cnt = iwl_get_active_rx_chain_count(priv);
  881. idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
  882. /* correct rx chain count according hw settings
  883. * and chain noise calibration
  884. */
  885. valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
  886. if (valid_rx_cnt < active_rx_cnt)
  887. active_rx_cnt = valid_rx_cnt;
  888. if (valid_rx_cnt < idle_rx_cnt)
  889. idle_rx_cnt = valid_rx_cnt;
  890. rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
  891. rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
  892. /* copied from 'iwl_bg_request_scan()' */
  893. /* Force use of chains B and C (0x6) for Rx for 4965
  894. * Avoid A (0x1) because of its off-channel reception on A-band.
  895. * MIMO is not used here, but value is required */
  896. if (iwl_is_monitor_mode(priv) &&
  897. !(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) &&
  898. ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) == CSR_HW_REV_TYPE_4965)) {
  899. rx_chain = ANT_ABC << RXON_RX_CHAIN_VALID_POS;
  900. rx_chain |= ANT_BC << RXON_RX_CHAIN_FORCE_SEL_POS;
  901. rx_chain |= ANT_ABC << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS;
  902. rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS;
  903. }
  904. priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
  905. if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
  906. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  907. else
  908. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  909. IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
  910. priv->staging_rxon.rx_chain,
  911. active_rx_cnt, idle_rx_cnt);
  912. WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
  913. active_rx_cnt < idle_rx_cnt);
  914. }
  915. EXPORT_SYMBOL(iwl_set_rxon_chain);
  916. /**
  917. * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
  918. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  919. * @channel: Any channel valid for the requested phymode
  920. * In addition to setting the staging RXON, priv->phymode is also set.
  921. *
  922. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  923. * in the staging RXON flag structure based on the phymode
  924. */
  925. int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
  926. {
  927. enum ieee80211_band band = ch->band;
  928. u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
  929. if (!iwl_get_channel_info(priv, band, channel)) {
  930. IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
  931. channel, band);
  932. return -EINVAL;
  933. }
  934. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  935. (priv->band == band))
  936. return 0;
  937. priv->staging_rxon.channel = cpu_to_le16(channel);
  938. if (band == IEEE80211_BAND_5GHZ)
  939. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  940. else
  941. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  942. priv->band = band;
  943. IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
  944. return 0;
  945. }
  946. EXPORT_SYMBOL(iwl_set_rxon_channel);
  947. void iwl_set_flags_for_band(struct iwl_priv *priv,
  948. enum ieee80211_band band)
  949. {
  950. if (band == IEEE80211_BAND_5GHZ) {
  951. priv->staging_rxon.flags &=
  952. ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
  953. | RXON_FLG_CCK_MSK);
  954. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  955. } else {
  956. /* Copied from iwl_post_associate() */
  957. if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
  958. priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
  959. else
  960. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  961. if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
  962. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
  963. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  964. priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
  965. priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
  966. }
  967. }
  968. EXPORT_SYMBOL(iwl_set_flags_for_band);
  969. /*
  970. * initialize rxon structure with default values from eeprom
  971. */
  972. void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
  973. {
  974. const struct iwl_channel_info *ch_info;
  975. memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
  976. switch (mode) {
  977. case NL80211_IFTYPE_AP:
  978. priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
  979. break;
  980. case NL80211_IFTYPE_STATION:
  981. priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
  982. priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
  983. break;
  984. case NL80211_IFTYPE_ADHOC:
  985. priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
  986. priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
  987. priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
  988. RXON_FILTER_ACCEPT_GRP_MSK;
  989. break;
  990. default:
  991. IWL_ERR(priv, "Unsupported interface type %d\n", mode);
  992. break;
  993. }
  994. #if 0
  995. /* TODO: Figure out when short_preamble would be set and cache from
  996. * that */
  997. if (!hw_to_local(priv->hw)->short_preamble)
  998. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  999. else
  1000. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  1001. #endif
  1002. ch_info = iwl_get_channel_info(priv, priv->band,
  1003. le16_to_cpu(priv->active_rxon.channel));
  1004. if (!ch_info)
  1005. ch_info = &priv->channel_info[0];
  1006. /*
  1007. * in some case A channels are all non IBSS
  1008. * in this case force B/G channel
  1009. */
  1010. if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
  1011. !(is_channel_ibss(ch_info)))
  1012. ch_info = &priv->channel_info[0];
  1013. priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
  1014. priv->band = ch_info->band;
  1015. iwl_set_flags_for_band(priv, priv->band);
  1016. priv->staging_rxon.ofdm_basic_rates =
  1017. (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1018. priv->staging_rxon.cck_basic_rates =
  1019. (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1020. /* clear both MIX and PURE40 mode flag */
  1021. priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
  1022. RXON_FLG_CHANNEL_MODE_PURE_40);
  1023. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  1024. memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
  1025. priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
  1026. priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
  1027. priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
  1028. }
  1029. EXPORT_SYMBOL(iwl_connection_init_rx_config);
  1030. static void iwl_set_rate(struct iwl_priv *priv)
  1031. {
  1032. const struct ieee80211_supported_band *hw = NULL;
  1033. struct ieee80211_rate *rate;
  1034. int i;
  1035. hw = iwl_get_hw_mode(priv, priv->band);
  1036. if (!hw) {
  1037. IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
  1038. return;
  1039. }
  1040. priv->active_rate = 0;
  1041. priv->active_rate_basic = 0;
  1042. for (i = 0; i < hw->n_bitrates; i++) {
  1043. rate = &(hw->bitrates[i]);
  1044. if (rate->hw_value < IWL_RATE_COUNT)
  1045. priv->active_rate |= (1 << rate->hw_value);
  1046. }
  1047. IWL_DEBUG_RATE(priv, "Set active_rate = %0x, active_rate_basic = %0x\n",
  1048. priv->active_rate, priv->active_rate_basic);
  1049. /*
  1050. * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
  1051. * otherwise set it to the default of all CCK rates and 6, 12, 24 for
  1052. * OFDM
  1053. */
  1054. if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
  1055. priv->staging_rxon.cck_basic_rates =
  1056. ((priv->active_rate_basic &
  1057. IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
  1058. else
  1059. priv->staging_rxon.cck_basic_rates =
  1060. (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
  1061. if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
  1062. priv->staging_rxon.ofdm_basic_rates =
  1063. ((priv->active_rate_basic &
  1064. (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
  1065. IWL_FIRST_OFDM_RATE) & 0xFF;
  1066. else
  1067. priv->staging_rxon.ofdm_basic_rates =
  1068. (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
  1069. }
  1070. void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
  1071. {
  1072. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1073. struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
  1074. struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
  1075. IWL_DEBUG_11H(priv, "CSA notif: channel %d, status %d\n",
  1076. le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
  1077. rxon->channel = csa->channel;
  1078. priv->staging_rxon.channel = csa->channel;
  1079. }
  1080. EXPORT_SYMBOL(iwl_rx_csa);
  1081. #ifdef CONFIG_IWLWIFI_DEBUG
  1082. static void iwl_print_rx_config_cmd(struct iwl_priv *priv)
  1083. {
  1084. struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
  1085. IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
  1086. iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
  1087. IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
  1088. IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
  1089. IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
  1090. le32_to_cpu(rxon->filter_flags));
  1091. IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
  1092. IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
  1093. rxon->ofdm_basic_rates);
  1094. IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
  1095. IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
  1096. IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
  1097. IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
  1098. }
  1099. #endif
  1100. /**
  1101. * iwl_irq_handle_error - called for HW or SW error interrupt from card
  1102. */
  1103. void iwl_irq_handle_error(struct iwl_priv *priv)
  1104. {
  1105. /* Set the FW error flag -- cleared on iwl_down */
  1106. set_bit(STATUS_FW_ERROR, &priv->status);
  1107. /* Cancel currently queued command. */
  1108. clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
  1109. #ifdef CONFIG_IWLWIFI_DEBUG
  1110. if (priv->debug_level & IWL_DL_FW_ERRORS) {
  1111. iwl_dump_nic_error_log(priv);
  1112. iwl_dump_nic_event_log(priv);
  1113. iwl_print_rx_config_cmd(priv);
  1114. }
  1115. #endif
  1116. wake_up_interruptible(&priv->wait_command_queue);
  1117. /* Keep the restart process from trying to send host
  1118. * commands by clearing the INIT status bit */
  1119. clear_bit(STATUS_READY, &priv->status);
  1120. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1121. IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
  1122. "Restarting adapter due to uCode error.\n");
  1123. if (priv->cfg->mod_params->restart_fw)
  1124. queue_work(priv->workqueue, &priv->restart);
  1125. }
  1126. }
  1127. EXPORT_SYMBOL(iwl_irq_handle_error);
  1128. void iwl_configure_filter(struct ieee80211_hw *hw,
  1129. unsigned int changed_flags,
  1130. unsigned int *total_flags,
  1131. int mc_count, struct dev_addr_list *mc_list)
  1132. {
  1133. struct iwl_priv *priv = hw->priv;
  1134. __le32 *filter_flags = &priv->staging_rxon.filter_flags;
  1135. IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
  1136. changed_flags, *total_flags);
  1137. if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
  1138. if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
  1139. *filter_flags |= RXON_FILTER_PROMISC_MSK;
  1140. else
  1141. *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
  1142. }
  1143. if (changed_flags & FIF_ALLMULTI) {
  1144. if (*total_flags & FIF_ALLMULTI)
  1145. *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
  1146. else
  1147. *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
  1148. }
  1149. if (changed_flags & FIF_CONTROL) {
  1150. if (*total_flags & FIF_CONTROL)
  1151. *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
  1152. else
  1153. *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
  1154. }
  1155. if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
  1156. if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
  1157. *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
  1158. else
  1159. *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
  1160. }
  1161. /* We avoid iwl_commit_rxon here to commit the new filter flags
  1162. * since mac80211 will call ieee80211_hw_config immediately.
  1163. * (mc_list is not supported at this time). Otherwise, we need to
  1164. * queue a background iwl_commit_rxon work.
  1165. */
  1166. *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
  1167. FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
  1168. }
  1169. EXPORT_SYMBOL(iwl_configure_filter);
  1170. int iwl_setup_mac(struct iwl_priv *priv)
  1171. {
  1172. int ret;
  1173. struct ieee80211_hw *hw = priv->hw;
  1174. hw->rate_control_algorithm = "iwl-agn-rs";
  1175. /* Tell mac80211 our characteristics */
  1176. hw->flags = IEEE80211_HW_SIGNAL_DBM |
  1177. IEEE80211_HW_NOISE_DBM |
  1178. IEEE80211_HW_AMPDU_AGGREGATION |
  1179. IEEE80211_HW_SPECTRUM_MGMT;
  1180. hw->wiphy->interface_modes =
  1181. BIT(NL80211_IFTYPE_STATION) |
  1182. BIT(NL80211_IFTYPE_ADHOC);
  1183. hw->wiphy->custom_regulatory = true;
  1184. hw->wiphy->max_scan_ssids = PROBE_OPTION_MAX;
  1185. /* we create the 802.11 header and a zero-length SSID element */
  1186. hw->wiphy->max_scan_ie_len = IWL_MAX_PROBE_REQUEST - 24 - 2;
  1187. /* Default value; 4 EDCA QOS priorities */
  1188. hw->queues = 4;
  1189. hw->max_listen_interval = IWL_CONN_MAX_LISTEN_INTERVAL;
  1190. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  1191. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  1192. &priv->bands[IEEE80211_BAND_2GHZ];
  1193. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  1194. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  1195. &priv->bands[IEEE80211_BAND_5GHZ];
  1196. ret = ieee80211_register_hw(priv->hw);
  1197. if (ret) {
  1198. IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
  1199. return ret;
  1200. }
  1201. priv->mac80211_registered = 1;
  1202. return 0;
  1203. }
  1204. EXPORT_SYMBOL(iwl_setup_mac);
  1205. int iwl_set_hw_params(struct iwl_priv *priv)
  1206. {
  1207. priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
  1208. priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
  1209. if (priv->cfg->mod_params->amsdu_size_8K)
  1210. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
  1211. else
  1212. priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
  1213. priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
  1214. priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
  1215. if (priv->cfg->mod_params->disable_11n)
  1216. priv->cfg->sku &= ~IWL_SKU_N;
  1217. /* Device-specific setup */
  1218. return priv->cfg->ops->lib->set_hw_params(priv);
  1219. }
  1220. EXPORT_SYMBOL(iwl_set_hw_params);
  1221. int iwl_init_drv(struct iwl_priv *priv)
  1222. {
  1223. int ret;
  1224. priv->ibss_beacon = NULL;
  1225. spin_lock_init(&priv->lock);
  1226. spin_lock_init(&priv->sta_lock);
  1227. spin_lock_init(&priv->hcmd_lock);
  1228. INIT_LIST_HEAD(&priv->free_frames);
  1229. mutex_init(&priv->mutex);
  1230. /* Clear the driver's (not device's) station table */
  1231. iwl_clear_stations_table(priv);
  1232. priv->data_retry_limit = -1;
  1233. priv->ieee_channels = NULL;
  1234. priv->ieee_rates = NULL;
  1235. priv->band = IEEE80211_BAND_2GHZ;
  1236. priv->iw_mode = NL80211_IFTYPE_STATION;
  1237. priv->current_ht_config.sm_ps = WLAN_HT_CAP_SM_PS_DISABLED;
  1238. /* Choose which receivers/antennas to use */
  1239. if (priv->cfg->ops->hcmd->set_rxon_chain)
  1240. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  1241. iwl_init_scan_params(priv);
  1242. iwl_reset_qos(priv);
  1243. priv->qos_data.qos_active = 0;
  1244. priv->qos_data.qos_cap.val = 0;
  1245. priv->rates_mask = IWL_RATES_MASK;
  1246. /* If power management is turned on, default to CAM mode */
  1247. priv->power_mode = IWL_POWER_MODE_CAM;
  1248. priv->tx_power_user_lmt = IWL_TX_POWER_TARGET_POWER_MAX;
  1249. ret = iwl_init_channel_map(priv);
  1250. if (ret) {
  1251. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  1252. goto err;
  1253. }
  1254. ret = iwlcore_init_geos(priv);
  1255. if (ret) {
  1256. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  1257. goto err_free_channel_map;
  1258. }
  1259. iwlcore_init_hw_rates(priv, priv->ieee_rates);
  1260. return 0;
  1261. err_free_channel_map:
  1262. iwl_free_channel_map(priv);
  1263. err:
  1264. return ret;
  1265. }
  1266. EXPORT_SYMBOL(iwl_init_drv);
  1267. int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
  1268. {
  1269. int ret = 0;
  1270. if (tx_power < IWL_TX_POWER_TARGET_POWER_MIN) {
  1271. IWL_WARN(priv, "Requested user TXPOWER %d below lower limit %d.\n",
  1272. tx_power,
  1273. IWL_TX_POWER_TARGET_POWER_MIN);
  1274. return -EINVAL;
  1275. }
  1276. if (tx_power > IWL_TX_POWER_TARGET_POWER_MAX) {
  1277. IWL_WARN(priv, "Requested user TXPOWER %d above upper limit %d.\n",
  1278. tx_power,
  1279. IWL_TX_POWER_TARGET_POWER_MAX);
  1280. return -EINVAL;
  1281. }
  1282. if (priv->tx_power_user_lmt != tx_power)
  1283. force = true;
  1284. priv->tx_power_user_lmt = tx_power;
  1285. /* if nic is not up don't send command */
  1286. if (!iwl_is_ready_rf(priv))
  1287. return ret;
  1288. if (force && priv->cfg->ops->lib->send_tx_power)
  1289. ret = priv->cfg->ops->lib->send_tx_power(priv);
  1290. return ret;
  1291. }
  1292. EXPORT_SYMBOL(iwl_set_tx_power);
  1293. void iwl_uninit_drv(struct iwl_priv *priv)
  1294. {
  1295. iwl_calib_free_results(priv);
  1296. iwlcore_free_geos(priv);
  1297. iwl_free_channel_map(priv);
  1298. kfree(priv->scan);
  1299. }
  1300. EXPORT_SYMBOL(iwl_uninit_drv);
  1301. void iwl_disable_interrupts(struct iwl_priv *priv)
  1302. {
  1303. clear_bit(STATUS_INT_ENABLED, &priv->status);
  1304. /* disable interrupts from uCode/NIC to host */
  1305. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1306. /* acknowledge/clear/reset any interrupts still pending
  1307. * from uCode or flow handler (Rx/Tx DMA) */
  1308. iwl_write32(priv, CSR_INT, 0xffffffff);
  1309. iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
  1310. IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
  1311. }
  1312. EXPORT_SYMBOL(iwl_disable_interrupts);
  1313. void iwl_enable_interrupts(struct iwl_priv *priv)
  1314. {
  1315. IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
  1316. set_bit(STATUS_INT_ENABLED, &priv->status);
  1317. iwl_write32(priv, CSR_INT_MASK, priv->inta_mask);
  1318. }
  1319. EXPORT_SYMBOL(iwl_enable_interrupts);
  1320. #define ICT_COUNT (PAGE_SIZE/sizeof(u32))
  1321. /* Free dram table */
  1322. void iwl_free_isr_ict(struct iwl_priv *priv)
  1323. {
  1324. if (priv->ict_tbl_vir) {
  1325. pci_free_consistent(priv->pci_dev, (sizeof(u32) * ICT_COUNT) +
  1326. PAGE_SIZE, priv->ict_tbl_vir,
  1327. priv->ict_tbl_dma);
  1328. priv->ict_tbl_vir = NULL;
  1329. }
  1330. }
  1331. EXPORT_SYMBOL(iwl_free_isr_ict);
  1332. /* allocate dram shared table it is a PAGE_SIZE aligned
  1333. * also reset all data related to ICT table interrupt.
  1334. */
  1335. int iwl_alloc_isr_ict(struct iwl_priv *priv)
  1336. {
  1337. if (priv->cfg->use_isr_legacy)
  1338. return 0;
  1339. /* allocate shrared data table */
  1340. priv->ict_tbl_vir = pci_alloc_consistent(priv->pci_dev, (sizeof(u32) *
  1341. ICT_COUNT) + PAGE_SIZE,
  1342. &priv->ict_tbl_dma);
  1343. if (!priv->ict_tbl_vir)
  1344. return -ENOMEM;
  1345. /* align table to PAGE_SIZE boundry */
  1346. priv->aligned_ict_tbl_dma = ALIGN(priv->ict_tbl_dma, PAGE_SIZE);
  1347. IWL_DEBUG_ISR(priv, "ict dma addr %Lx dma aligned %Lx diff %d\n",
  1348. (unsigned long long)priv->ict_tbl_dma,
  1349. (unsigned long long)priv->aligned_ict_tbl_dma,
  1350. (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
  1351. priv->ict_tbl = priv->ict_tbl_vir +
  1352. (priv->aligned_ict_tbl_dma - priv->ict_tbl_dma);
  1353. IWL_DEBUG_ISR(priv, "ict vir addr %p vir aligned %p diff %d\n",
  1354. priv->ict_tbl, priv->ict_tbl_vir,
  1355. (int)(priv->aligned_ict_tbl_dma - priv->ict_tbl_dma));
  1356. /* reset table and index to all 0 */
  1357. memset(priv->ict_tbl_vir,0, (sizeof(u32) * ICT_COUNT) + PAGE_SIZE);
  1358. priv->ict_index = 0;
  1359. /* add periodic RX interrupt */
  1360. priv->inta_mask |= CSR_INT_BIT_RX_PERIODIC;
  1361. return 0;
  1362. }
  1363. EXPORT_SYMBOL(iwl_alloc_isr_ict);
  1364. /* Device is going up inform it about using ICT interrupt table,
  1365. * also we need to tell the driver to start using ICT interrupt.
  1366. */
  1367. int iwl_reset_ict(struct iwl_priv *priv)
  1368. {
  1369. u32 val;
  1370. unsigned long flags;
  1371. if (!priv->ict_tbl_vir)
  1372. return 0;
  1373. spin_lock_irqsave(&priv->lock, flags);
  1374. iwl_disable_interrupts(priv);
  1375. memset(&priv->ict_tbl[0],0, sizeof(u32) * ICT_COUNT);
  1376. val = priv->aligned_ict_tbl_dma >> PAGE_SHIFT;
  1377. val |= CSR_DRAM_INT_TBL_ENABLE;
  1378. val |= CSR_DRAM_INIT_TBL_WRAP_CHECK;
  1379. IWL_DEBUG_ISR(priv, "CSR_DRAM_INT_TBL_REG =0x%X "
  1380. "aligned dma address %Lx\n",
  1381. val, (unsigned long long)priv->aligned_ict_tbl_dma);
  1382. iwl_write32(priv, CSR_DRAM_INT_TBL_REG, val);
  1383. priv->use_ict = true;
  1384. priv->ict_index = 0;
  1385. iwl_write32(priv, CSR_INT, priv->inta_mask);
  1386. iwl_enable_interrupts(priv);
  1387. spin_unlock_irqrestore(&priv->lock, flags);
  1388. return 0;
  1389. }
  1390. EXPORT_SYMBOL(iwl_reset_ict);
  1391. /* Device is going down disable ict interrupt usage */
  1392. void iwl_disable_ict(struct iwl_priv *priv)
  1393. {
  1394. unsigned long flags;
  1395. spin_lock_irqsave(&priv->lock, flags);
  1396. priv->use_ict = false;
  1397. spin_unlock_irqrestore(&priv->lock, flags);
  1398. }
  1399. EXPORT_SYMBOL(iwl_disable_ict);
  1400. /* interrupt handler using ict table, with this interrupt driver will
  1401. * stop using INTA register to get device's interrupt, reading this register
  1402. * is expensive, device will write interrupts in ICT dram table, increment
  1403. * index then will fire interrupt to driver, driver will OR all ICT table
  1404. * entries from current index up to table entry with 0 value. the result is
  1405. * the interrupt we need to service, driver will set the entries back to 0 and
  1406. * set index.
  1407. */
  1408. irqreturn_t iwl_isr_ict(int irq, void *data)
  1409. {
  1410. struct iwl_priv *priv = data;
  1411. u32 inta, inta_mask;
  1412. u32 val = 0;
  1413. if (!priv)
  1414. return IRQ_NONE;
  1415. /* dram interrupt table not set yet,
  1416. * use legacy interrupt.
  1417. */
  1418. if (!priv->use_ict)
  1419. return iwl_isr(irq, data);
  1420. spin_lock(&priv->lock);
  1421. /* Disable (but don't clear!) interrupts here to avoid
  1422. * back-to-back ISRs and sporadic interrupts from our NIC.
  1423. * If we have something to service, the tasklet will re-enable ints.
  1424. * If we *don't* have something, we'll re-enable before leaving here.
  1425. */
  1426. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1427. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1428. /* Ignore interrupt if there's nothing in NIC to service.
  1429. * This may be due to IRQ shared with another device,
  1430. * or due to sporadic interrupts thrown from our NIC. */
  1431. if (!priv->ict_tbl[priv->ict_index]) {
  1432. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  1433. goto none;
  1434. }
  1435. /* read all entries that not 0 start with ict_index */
  1436. while (priv->ict_tbl[priv->ict_index]) {
  1437. val |= priv->ict_tbl[priv->ict_index];
  1438. IWL_DEBUG_ISR(priv, "ICT index %d value 0x%08X\n",
  1439. priv->ict_index,
  1440. priv->ict_tbl[priv->ict_index]);
  1441. priv->ict_tbl[priv->ict_index] = 0;
  1442. priv->ict_index = iwl_queue_inc_wrap(priv->ict_index,
  1443. ICT_COUNT);
  1444. }
  1445. /* We should not get this value, just ignore it. */
  1446. if (val == 0xffffffff)
  1447. val = 0;
  1448. inta = (0xff & val) | ((0xff00 & val) << 16);
  1449. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x ict 0x%08x\n",
  1450. inta, inta_mask, val);
  1451. inta &= priv->inta_mask;
  1452. priv->inta |= inta;
  1453. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1454. if (likely(inta))
  1455. tasklet_schedule(&priv->irq_tasklet);
  1456. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta) {
  1457. /* Allow interrupt if was disabled by this handler and
  1458. * no tasklet was schedules, We should not enable interrupt,
  1459. * tasklet will enable it.
  1460. */
  1461. iwl_enable_interrupts(priv);
  1462. }
  1463. spin_unlock(&priv->lock);
  1464. return IRQ_HANDLED;
  1465. none:
  1466. /* re-enable interrupts here since we don't have anything to service.
  1467. * only Re-enable if disabled by irq.
  1468. */
  1469. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1470. iwl_enable_interrupts(priv);
  1471. spin_unlock(&priv->lock);
  1472. return IRQ_NONE;
  1473. }
  1474. EXPORT_SYMBOL(iwl_isr_ict);
  1475. static irqreturn_t iwl_isr(int irq, void *data)
  1476. {
  1477. struct iwl_priv *priv = data;
  1478. u32 inta, inta_mask;
  1479. #ifdef CONFIG_IWLWIFI_DEBUG
  1480. u32 inta_fh;
  1481. #endif
  1482. if (!priv)
  1483. return IRQ_NONE;
  1484. spin_lock(&priv->lock);
  1485. /* Disable (but don't clear!) interrupts here to avoid
  1486. * back-to-back ISRs and sporadic interrupts from our NIC.
  1487. * If we have something to service, the tasklet will re-enable ints.
  1488. * If we *don't* have something, we'll re-enable before leaving here. */
  1489. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1490. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1491. /* Discover which interrupts are active/pending */
  1492. inta = iwl_read32(priv, CSR_INT);
  1493. /* Ignore interrupt if there's nothing in NIC to service.
  1494. * This may be due to IRQ shared with another device,
  1495. * or due to sporadic interrupts thrown from our NIC. */
  1496. if (!inta) {
  1497. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0\n");
  1498. goto none;
  1499. }
  1500. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1501. /* Hardware disappeared. It might have already raised
  1502. * an interrupt */
  1503. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1504. goto unplugged;
  1505. }
  1506. #ifdef CONFIG_IWLWIFI_DEBUG
  1507. if (priv->debug_level & (IWL_DL_ISR)) {
  1508. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1509. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, "
  1510. "fh 0x%08x\n", inta, inta_mask, inta_fh);
  1511. }
  1512. #endif
  1513. priv->inta |= inta;
  1514. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1515. if (likely(inta))
  1516. tasklet_schedule(&priv->irq_tasklet);
  1517. else if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1518. iwl_enable_interrupts(priv);
  1519. unplugged:
  1520. spin_unlock(&priv->lock);
  1521. return IRQ_HANDLED;
  1522. none:
  1523. /* re-enable interrupts here since we don't have anything to service. */
  1524. /* only Re-enable if diabled by irq and no schedules tasklet. */
  1525. if (test_bit(STATUS_INT_ENABLED, &priv->status) && !priv->inta)
  1526. iwl_enable_interrupts(priv);
  1527. spin_unlock(&priv->lock);
  1528. return IRQ_NONE;
  1529. }
  1530. irqreturn_t iwl_isr_legacy(int irq, void *data)
  1531. {
  1532. struct iwl_priv *priv = data;
  1533. u32 inta, inta_mask;
  1534. u32 inta_fh;
  1535. if (!priv)
  1536. return IRQ_NONE;
  1537. spin_lock(&priv->lock);
  1538. /* Disable (but don't clear!) interrupts here to avoid
  1539. * back-to-back ISRs and sporadic interrupts from our NIC.
  1540. * If we have something to service, the tasklet will re-enable ints.
  1541. * If we *don't* have something, we'll re-enable before leaving here. */
  1542. inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
  1543. iwl_write32(priv, CSR_INT_MASK, 0x00000000);
  1544. /* Discover which interrupts are active/pending */
  1545. inta = iwl_read32(priv, CSR_INT);
  1546. inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
  1547. /* Ignore interrupt if there's nothing in NIC to service.
  1548. * This may be due to IRQ shared with another device,
  1549. * or due to sporadic interrupts thrown from our NIC. */
  1550. if (!inta && !inta_fh) {
  1551. IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
  1552. goto none;
  1553. }
  1554. if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
  1555. /* Hardware disappeared. It might have already raised
  1556. * an interrupt */
  1557. IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
  1558. goto unplugged;
  1559. }
  1560. IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
  1561. inta, inta_mask, inta_fh);
  1562. inta &= ~CSR_INT_BIT_SCD;
  1563. /* iwl_irq_tasklet() will service interrupts and re-enable them */
  1564. if (likely(inta || inta_fh))
  1565. tasklet_schedule(&priv->irq_tasklet);
  1566. unplugged:
  1567. spin_unlock(&priv->lock);
  1568. return IRQ_HANDLED;
  1569. none:
  1570. /* re-enable interrupts here since we don't have anything to service. */
  1571. /* only Re-enable if diabled by irq */
  1572. if (test_bit(STATUS_INT_ENABLED, &priv->status))
  1573. iwl_enable_interrupts(priv);
  1574. spin_unlock(&priv->lock);
  1575. return IRQ_NONE;
  1576. }
  1577. EXPORT_SYMBOL(iwl_isr_legacy);
  1578. int iwl_send_bt_config(struct iwl_priv *priv)
  1579. {
  1580. struct iwl_bt_cmd bt_cmd = {
  1581. .flags = 3,
  1582. .lead_time = 0xAA,
  1583. .max_kill = 1,
  1584. .kill_ack_mask = 0,
  1585. .kill_cts_mask = 0,
  1586. };
  1587. return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  1588. sizeof(struct iwl_bt_cmd), &bt_cmd);
  1589. }
  1590. EXPORT_SYMBOL(iwl_send_bt_config);
  1591. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
  1592. {
  1593. u32 stat_flags = 0;
  1594. struct iwl_host_cmd cmd = {
  1595. .id = REPLY_STATISTICS_CMD,
  1596. .meta.flags = flags,
  1597. .len = sizeof(stat_flags),
  1598. .data = (u8 *) &stat_flags,
  1599. };
  1600. return iwl_send_cmd(priv, &cmd);
  1601. }
  1602. EXPORT_SYMBOL(iwl_send_statistics_request);
  1603. /**
  1604. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  1605. * using sample data 100 bytes apart. If these sample points are good,
  1606. * it's a pretty good bet that everything between them is good, too.
  1607. */
  1608. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  1609. {
  1610. u32 val;
  1611. int ret = 0;
  1612. u32 errcnt = 0;
  1613. u32 i;
  1614. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1615. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  1616. /* read data comes through single port, auto-incr addr */
  1617. /* NOTE: Use the debugless read so we don't flood kernel log
  1618. * if IWL_DL_IO is set */
  1619. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1620. i + IWL49_RTC_INST_LOWER_BOUND);
  1621. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1622. if (val != le32_to_cpu(*image)) {
  1623. ret = -EIO;
  1624. errcnt++;
  1625. if (errcnt >= 3)
  1626. break;
  1627. }
  1628. }
  1629. return ret;
  1630. }
  1631. /**
  1632. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  1633. * looking at all data.
  1634. */
  1635. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  1636. u32 len)
  1637. {
  1638. u32 val;
  1639. u32 save_len = len;
  1640. int ret = 0;
  1641. u32 errcnt;
  1642. IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
  1643. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  1644. IWL49_RTC_INST_LOWER_BOUND);
  1645. errcnt = 0;
  1646. for (; len > 0; len -= sizeof(u32), image++) {
  1647. /* read data comes through single port, auto-incr addr */
  1648. /* NOTE: Use the debugless read so we don't flood kernel log
  1649. * if IWL_DL_IO is set */
  1650. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  1651. if (val != le32_to_cpu(*image)) {
  1652. IWL_ERR(priv, "uCode INST section is invalid at "
  1653. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  1654. save_len - len, val, le32_to_cpu(*image));
  1655. ret = -EIO;
  1656. errcnt++;
  1657. if (errcnt >= 20)
  1658. break;
  1659. }
  1660. }
  1661. if (!errcnt)
  1662. IWL_DEBUG_INFO(priv,
  1663. "ucode image in INSTRUCTION memory is good\n");
  1664. return ret;
  1665. }
  1666. /**
  1667. * iwl_verify_ucode - determine which instruction image is in SRAM,
  1668. * and verify its contents
  1669. */
  1670. int iwl_verify_ucode(struct iwl_priv *priv)
  1671. {
  1672. __le32 *image;
  1673. u32 len;
  1674. int ret;
  1675. /* Try bootstrap */
  1676. image = (__le32 *)priv->ucode_boot.v_addr;
  1677. len = priv->ucode_boot.len;
  1678. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1679. if (!ret) {
  1680. IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
  1681. return 0;
  1682. }
  1683. /* Try initialize */
  1684. image = (__le32 *)priv->ucode_init.v_addr;
  1685. len = priv->ucode_init.len;
  1686. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1687. if (!ret) {
  1688. IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
  1689. return 0;
  1690. }
  1691. /* Try runtime/protocol */
  1692. image = (__le32 *)priv->ucode_code.v_addr;
  1693. len = priv->ucode_code.len;
  1694. ret = iwlcore_verify_inst_sparse(priv, image, len);
  1695. if (!ret) {
  1696. IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
  1697. return 0;
  1698. }
  1699. IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  1700. /* Since nothing seems to match, show first several data entries in
  1701. * instruction SRAM, so maybe visual inspection will give a clue.
  1702. * Selection of bootstrap image (vs. other images) is arbitrary. */
  1703. image = (__le32 *)priv->ucode_boot.v_addr;
  1704. len = priv->ucode_boot.len;
  1705. ret = iwl_verify_inst_full(priv, image, len);
  1706. return ret;
  1707. }
  1708. EXPORT_SYMBOL(iwl_verify_ucode);
  1709. static const char *desc_lookup_text[] = {
  1710. "OK",
  1711. "FAIL",
  1712. "BAD_PARAM",
  1713. "BAD_CHECKSUM",
  1714. "NMI_INTERRUPT_WDG",
  1715. "SYSASSERT",
  1716. "FATAL_ERROR",
  1717. "BAD_COMMAND",
  1718. "HW_ERROR_TUNE_LOCK",
  1719. "HW_ERROR_TEMPERATURE",
  1720. "ILLEGAL_CHAN_FREQ",
  1721. "VCC_NOT_STABLE",
  1722. "FH_ERROR",
  1723. "NMI_INTERRUPT_HOST",
  1724. "NMI_INTERRUPT_ACTION_PT",
  1725. "NMI_INTERRUPT_UNKNOWN",
  1726. "UCODE_VERSION_MISMATCH",
  1727. "HW_ERROR_ABS_LOCK",
  1728. "HW_ERROR_CAL_LOCK_FAIL",
  1729. "NMI_INTERRUPT_INST_ACTION_PT",
  1730. "NMI_INTERRUPT_DATA_ACTION_PT",
  1731. "NMI_TRM_HW_ER",
  1732. "NMI_INTERRUPT_TRM",
  1733. "NMI_INTERRUPT_BREAK_POINT"
  1734. "DEBUG_0",
  1735. "DEBUG_1",
  1736. "DEBUG_2",
  1737. "DEBUG_3",
  1738. "UNKNOWN"
  1739. };
  1740. static const char *desc_lookup(int i)
  1741. {
  1742. int max = ARRAY_SIZE(desc_lookup_text) - 1;
  1743. if (i < 0 || i > max)
  1744. i = max;
  1745. return desc_lookup_text[i];
  1746. }
  1747. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1748. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1749. void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1750. {
  1751. u32 data2, line;
  1752. u32 desc, time, count, base, data1;
  1753. u32 blink1, blink2, ilink1, ilink2;
  1754. if (priv->ucode_type == UCODE_INIT)
  1755. base = le32_to_cpu(priv->card_alive_init.error_event_table_ptr);
  1756. else
  1757. base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
  1758. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1759. IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
  1760. return;
  1761. }
  1762. count = iwl_read_targ_mem(priv, base);
  1763. if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
  1764. IWL_ERR(priv, "Start IWL Error Log Dump:\n");
  1765. IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
  1766. priv->status, count);
  1767. }
  1768. desc = iwl_read_targ_mem(priv, base + 1 * sizeof(u32));
  1769. blink1 = iwl_read_targ_mem(priv, base + 3 * sizeof(u32));
  1770. blink2 = iwl_read_targ_mem(priv, base + 4 * sizeof(u32));
  1771. ilink1 = iwl_read_targ_mem(priv, base + 5 * sizeof(u32));
  1772. ilink2 = iwl_read_targ_mem(priv, base + 6 * sizeof(u32));
  1773. data1 = iwl_read_targ_mem(priv, base + 7 * sizeof(u32));
  1774. data2 = iwl_read_targ_mem(priv, base + 8 * sizeof(u32));
  1775. line = iwl_read_targ_mem(priv, base + 9 * sizeof(u32));
  1776. time = iwl_read_targ_mem(priv, base + 11 * sizeof(u32));
  1777. IWL_ERR(priv, "Desc Time "
  1778. "data1 data2 line\n");
  1779. IWL_ERR(priv, "%-28s (#%02d) %010u 0x%08X 0x%08X %u\n",
  1780. desc_lookup(desc), desc, time, data1, data2, line);
  1781. IWL_ERR(priv, "blink1 blink2 ilink1 ilink2\n");
  1782. IWL_ERR(priv, "0x%05X 0x%05X 0x%05X 0x%05X\n", blink1, blink2,
  1783. ilink1, ilink2);
  1784. }
  1785. EXPORT_SYMBOL(iwl_dump_nic_error_log);
  1786. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1787. /**
  1788. * iwl_print_event_log - Dump error event log to syslog
  1789. *
  1790. */
  1791. static void iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1792. u32 num_events, u32 mode)
  1793. {
  1794. u32 i;
  1795. u32 base; /* SRAM byte address of event log header */
  1796. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1797. u32 ptr; /* SRAM byte address of log data */
  1798. u32 ev, time, data; /* event log data */
  1799. if (num_events == 0)
  1800. return;
  1801. if (priv->ucode_type == UCODE_INIT)
  1802. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1803. else
  1804. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1805. if (mode == 0)
  1806. event_size = 2 * sizeof(u32);
  1807. else
  1808. event_size = 3 * sizeof(u32);
  1809. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1810. /* "time" is actually "data" for mode 0 (no timestamp).
  1811. * place event id # at far right for easier visual parsing. */
  1812. for (i = 0; i < num_events; i++) {
  1813. ev = iwl_read_targ_mem(priv, ptr);
  1814. ptr += sizeof(u32);
  1815. time = iwl_read_targ_mem(priv, ptr);
  1816. ptr += sizeof(u32);
  1817. if (mode == 0) {
  1818. /* data, ev */
  1819. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n", time, ev);
  1820. } else {
  1821. data = iwl_read_targ_mem(priv, ptr);
  1822. ptr += sizeof(u32);
  1823. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1824. time, data, ev);
  1825. }
  1826. }
  1827. }
  1828. void iwl_dump_nic_event_log(struct iwl_priv *priv)
  1829. {
  1830. u32 base; /* SRAM byte address of event log header */
  1831. u32 capacity; /* event log capacity in # entries */
  1832. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1833. u32 num_wraps; /* # times uCode wrapped to top of log */
  1834. u32 next_entry; /* index of next entry to be written by uCode */
  1835. u32 size; /* # entries that we'll print */
  1836. if (priv->ucode_type == UCODE_INIT)
  1837. base = le32_to_cpu(priv->card_alive_init.log_event_table_ptr);
  1838. else
  1839. base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
  1840. if (!priv->cfg->ops->lib->is_valid_rtc_data_addr(base)) {
  1841. IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
  1842. return;
  1843. }
  1844. /* event log header */
  1845. capacity = iwl_read_targ_mem(priv, base);
  1846. mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
  1847. num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
  1848. next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
  1849. size = num_wraps ? capacity : next_entry;
  1850. /* bail out if nothing in log */
  1851. if (size == 0) {
  1852. IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
  1853. return;
  1854. }
  1855. IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
  1856. size, num_wraps);
  1857. /* if uCode has wrapped back to top of log, start at the oldest entry,
  1858. * i.e the next one that uCode would fill. */
  1859. if (num_wraps)
  1860. iwl_print_event_log(priv, next_entry,
  1861. capacity - next_entry, mode);
  1862. /* (then/else) start at top of log */
  1863. iwl_print_event_log(priv, 0, next_entry, mode);
  1864. }
  1865. EXPORT_SYMBOL(iwl_dump_nic_event_log);
  1866. void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  1867. {
  1868. struct iwl_ct_kill_config cmd;
  1869. unsigned long flags;
  1870. int ret = 0;
  1871. spin_lock_irqsave(&priv->lock, flags);
  1872. iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
  1873. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  1874. spin_unlock_irqrestore(&priv->lock, flags);
  1875. cmd.critical_temperature_R =
  1876. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  1877. ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
  1878. sizeof(cmd), &cmd);
  1879. if (ret)
  1880. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  1881. else
  1882. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD succeeded, "
  1883. "critical temperature is %d\n",
  1884. cmd.critical_temperature_R);
  1885. }
  1886. EXPORT_SYMBOL(iwl_rf_kill_ct_config);
  1887. /*
  1888. * CARD_STATE_CMD
  1889. *
  1890. * Use: Sets the device's internal card state to enable, disable, or halt
  1891. *
  1892. * When in the 'enable' state the card operates as normal.
  1893. * When in the 'disable' state, the card enters into a low power mode.
  1894. * When in the 'halt' state, the card is shut down and must be fully
  1895. * restarted to come back on.
  1896. */
  1897. int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
  1898. {
  1899. struct iwl_host_cmd cmd = {
  1900. .id = REPLY_CARD_STATE_CMD,
  1901. .len = sizeof(u32),
  1902. .data = &flags,
  1903. .meta.flags = meta_flag,
  1904. };
  1905. return iwl_send_cmd(priv, &cmd);
  1906. }
  1907. EXPORT_SYMBOL(iwl_send_card_state);
  1908. void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
  1909. struct iwl_rx_mem_buffer *rxb)
  1910. {
  1911. #ifdef CONFIG_IWLWIFI_DEBUG
  1912. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1913. struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
  1914. IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
  1915. sleep->pm_sleep_mode, sleep->pm_wakeup_src);
  1916. #endif
  1917. }
  1918. EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
  1919. void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
  1920. struct iwl_rx_mem_buffer *rxb)
  1921. {
  1922. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1923. IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
  1924. "notification for %s:\n",
  1925. le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
  1926. iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
  1927. }
  1928. EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
  1929. void iwl_rx_reply_error(struct iwl_priv *priv,
  1930. struct iwl_rx_mem_buffer *rxb)
  1931. {
  1932. struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
  1933. IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
  1934. "seq 0x%04X ser 0x%08X\n",
  1935. le32_to_cpu(pkt->u.err_resp.error_type),
  1936. get_cmd_string(pkt->u.err_resp.cmd_id),
  1937. pkt->u.err_resp.cmd_id,
  1938. le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
  1939. le32_to_cpu(pkt->u.err_resp.error_info));
  1940. }
  1941. EXPORT_SYMBOL(iwl_rx_reply_error);
  1942. void iwl_clear_isr_stats(struct iwl_priv *priv)
  1943. {
  1944. memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
  1945. }
  1946. EXPORT_SYMBOL(iwl_clear_isr_stats);
  1947. int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
  1948. const struct ieee80211_tx_queue_params *params)
  1949. {
  1950. struct iwl_priv *priv = hw->priv;
  1951. unsigned long flags;
  1952. int q;
  1953. IWL_DEBUG_MAC80211(priv, "enter\n");
  1954. if (!iwl_is_ready_rf(priv)) {
  1955. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  1956. return -EIO;
  1957. }
  1958. if (queue >= AC_NUM) {
  1959. IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
  1960. return 0;
  1961. }
  1962. q = AC_NUM - 1 - queue;
  1963. spin_lock_irqsave(&priv->lock, flags);
  1964. priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
  1965. priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
  1966. priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
  1967. priv->qos_data.def_qos_parm.ac[q].edca_txop =
  1968. cpu_to_le16((params->txop * 32));
  1969. priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
  1970. priv->qos_data.qos_active = 1;
  1971. if (priv->iw_mode == NL80211_IFTYPE_AP)
  1972. iwl_activate_qos(priv, 1);
  1973. else if (priv->assoc_id && iwl_is_associated(priv))
  1974. iwl_activate_qos(priv, 0);
  1975. spin_unlock_irqrestore(&priv->lock, flags);
  1976. IWL_DEBUG_MAC80211(priv, "leave\n");
  1977. return 0;
  1978. }
  1979. EXPORT_SYMBOL(iwl_mac_conf_tx);
  1980. static void iwl_ht_conf(struct iwl_priv *priv,
  1981. struct ieee80211_bss_conf *bss_conf)
  1982. {
  1983. struct ieee80211_sta_ht_cap *ht_conf;
  1984. struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
  1985. struct ieee80211_sta *sta;
  1986. IWL_DEBUG_MAC80211(priv, "enter: \n");
  1987. if (!iwl_conf->is_ht)
  1988. return;
  1989. /*
  1990. * It is totally wrong to base global information on something
  1991. * that is valid only when associated, alas, this driver works
  1992. * that way and I don't know how to fix it.
  1993. */
  1994. rcu_read_lock();
  1995. sta = ieee80211_find_sta(priv->hw, priv->bssid);
  1996. if (!sta) {
  1997. rcu_read_unlock();
  1998. return;
  1999. }
  2000. ht_conf = &sta->ht_cap;
  2001. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
  2002. iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
  2003. if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
  2004. iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
  2005. iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
  2006. iwl_conf->max_amsdu_size =
  2007. !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
  2008. iwl_conf->supported_chan_width =
  2009. !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40);
  2010. /*
  2011. * XXX: The HT configuration needs to be moved into iwl_mac_config()
  2012. * to be done there correctly.
  2013. */
  2014. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2015. if (conf_is_ht40_minus(&priv->hw->conf))
  2016. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2017. else if (conf_is_ht40_plus(&priv->hw->conf))
  2018. iwl_conf->extension_chan_offset = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2019. /* If no above or below channel supplied disable FAT channel */
  2020. if (iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_ABOVE &&
  2021. iwl_conf->extension_chan_offset != IEEE80211_HT_PARAM_CHA_SEC_BELOW)
  2022. iwl_conf->supported_chan_width = 0;
  2023. iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
  2024. memcpy(&iwl_conf->mcs, &ht_conf->mcs, 16);
  2025. iwl_conf->tx_chan_width = iwl_conf->supported_chan_width != 0;
  2026. iwl_conf->ht_protection =
  2027. bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
  2028. iwl_conf->non_GF_STA_present =
  2029. !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
  2030. rcu_read_unlock();
  2031. IWL_DEBUG_MAC80211(priv, "leave\n");
  2032. }
  2033. #define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
  2034. void iwl_bss_info_changed(struct ieee80211_hw *hw,
  2035. struct ieee80211_vif *vif,
  2036. struct ieee80211_bss_conf *bss_conf,
  2037. u32 changes)
  2038. {
  2039. struct iwl_priv *priv = hw->priv;
  2040. int ret;
  2041. IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
  2042. if (!iwl_is_alive(priv))
  2043. return;
  2044. mutex_lock(&priv->mutex);
  2045. if (changes & BSS_CHANGED_BEACON &&
  2046. priv->iw_mode == NL80211_IFTYPE_AP) {
  2047. dev_kfree_skb(priv->ibss_beacon);
  2048. priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
  2049. }
  2050. if (changes & BSS_CHANGED_BEACON_INT) {
  2051. priv->beacon_int = bss_conf->beacon_int;
  2052. /* TODO: in AP mode, do something to make this take effect */
  2053. }
  2054. if (changes & BSS_CHANGED_BSSID) {
  2055. IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
  2056. /*
  2057. * If there is currently a HW scan going on in the
  2058. * background then we need to cancel it else the RXON
  2059. * below/in post_associate will fail.
  2060. */
  2061. if (iwl_scan_cancel_timeout(priv, 100)) {
  2062. IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
  2063. IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
  2064. mutex_unlock(&priv->mutex);
  2065. return;
  2066. }
  2067. /* mac80211 only sets assoc when in STATION mode */
  2068. if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
  2069. bss_conf->assoc) {
  2070. memcpy(priv->staging_rxon.bssid_addr,
  2071. bss_conf->bssid, ETH_ALEN);
  2072. /* currently needed in a few places */
  2073. memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
  2074. } else {
  2075. priv->staging_rxon.filter_flags &=
  2076. ~RXON_FILTER_ASSOC_MSK;
  2077. }
  2078. }
  2079. /*
  2080. * This needs to be after setting the BSSID in case
  2081. * mac80211 decides to do both changes at once because
  2082. * it will invoke post_associate.
  2083. */
  2084. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  2085. changes & BSS_CHANGED_BEACON) {
  2086. struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
  2087. if (beacon)
  2088. iwl_mac_beacon_update(hw, beacon);
  2089. }
  2090. if (changes & BSS_CHANGED_ERP_PREAMBLE) {
  2091. IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
  2092. bss_conf->use_short_preamble);
  2093. if (bss_conf->use_short_preamble)
  2094. priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
  2095. else
  2096. priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
  2097. }
  2098. if (changes & BSS_CHANGED_ERP_CTS_PROT) {
  2099. IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
  2100. if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
  2101. priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
  2102. else
  2103. priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
  2104. }
  2105. if (changes & BSS_CHANGED_BASIC_RATES) {
  2106. /* XXX use this information
  2107. *
  2108. * To do that, remove code from iwl_set_rate() and put something
  2109. * like this here:
  2110. *
  2111. if (A-band)
  2112. priv->staging_rxon.ofdm_basic_rates =
  2113. bss_conf->basic_rates;
  2114. else
  2115. priv->staging_rxon.ofdm_basic_rates =
  2116. bss_conf->basic_rates >> 4;
  2117. priv->staging_rxon.cck_basic_rates =
  2118. bss_conf->basic_rates & 0xF;
  2119. */
  2120. }
  2121. if (changes & BSS_CHANGED_HT) {
  2122. iwl_ht_conf(priv, bss_conf);
  2123. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2124. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2125. }
  2126. if (changes & BSS_CHANGED_ASSOC) {
  2127. IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
  2128. if (bss_conf->assoc) {
  2129. priv->assoc_id = bss_conf->aid;
  2130. priv->beacon_int = bss_conf->beacon_int;
  2131. priv->power_data.dtim_period = bss_conf->dtim_period;
  2132. priv->timestamp = bss_conf->timestamp;
  2133. priv->assoc_capability = bss_conf->assoc_capability;
  2134. /*
  2135. * We have just associated, don't start scan too early
  2136. * leave time for EAPOL exchange to complete.
  2137. *
  2138. * XXX: do this in mac80211
  2139. */
  2140. priv->next_scan_jiffies = jiffies +
  2141. IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
  2142. if (!iwl_is_rfkill(priv))
  2143. priv->cfg->ops->lib->post_associate(priv);
  2144. } else
  2145. priv->assoc_id = 0;
  2146. }
  2147. if (changes && iwl_is_associated(priv) && priv->assoc_id) {
  2148. IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
  2149. changes);
  2150. ret = iwl_send_rxon_assoc(priv);
  2151. if (!ret) {
  2152. /* Sync active_rxon with latest change. */
  2153. memcpy((void *)&priv->active_rxon,
  2154. &priv->staging_rxon,
  2155. sizeof(struct iwl_rxon_cmd));
  2156. }
  2157. }
  2158. mutex_unlock(&priv->mutex);
  2159. IWL_DEBUG_MAC80211(priv, "leave\n");
  2160. }
  2161. EXPORT_SYMBOL(iwl_bss_info_changed);
  2162. int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
  2163. {
  2164. struct iwl_priv *priv = hw->priv;
  2165. unsigned long flags;
  2166. __le64 timestamp;
  2167. IWL_DEBUG_MAC80211(priv, "enter\n");
  2168. if (!iwl_is_ready_rf(priv)) {
  2169. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  2170. return -EIO;
  2171. }
  2172. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  2173. IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
  2174. return -EIO;
  2175. }
  2176. spin_lock_irqsave(&priv->lock, flags);
  2177. if (priv->ibss_beacon)
  2178. dev_kfree_skb(priv->ibss_beacon);
  2179. priv->ibss_beacon = skb;
  2180. priv->assoc_id = 0;
  2181. timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
  2182. priv->timestamp = le64_to_cpu(timestamp);
  2183. IWL_DEBUG_MAC80211(priv, "leave\n");
  2184. spin_unlock_irqrestore(&priv->lock, flags);
  2185. iwl_reset_qos(priv);
  2186. priv->cfg->ops->lib->post_associate(priv);
  2187. return 0;
  2188. }
  2189. EXPORT_SYMBOL(iwl_mac_beacon_update);
  2190. int iwl_set_mode(struct iwl_priv *priv, int mode)
  2191. {
  2192. if (mode == NL80211_IFTYPE_ADHOC) {
  2193. const struct iwl_channel_info *ch_info;
  2194. ch_info = iwl_get_channel_info(priv,
  2195. priv->band,
  2196. le16_to_cpu(priv->staging_rxon.channel));
  2197. if (!ch_info || !is_channel_ibss(ch_info)) {
  2198. IWL_ERR(priv, "channel %d not IBSS channel\n",
  2199. le16_to_cpu(priv->staging_rxon.channel));
  2200. return -EINVAL;
  2201. }
  2202. }
  2203. iwl_connection_init_rx_config(priv, mode);
  2204. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2205. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2206. memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
  2207. iwl_clear_stations_table(priv);
  2208. /* dont commit rxon if rf-kill is on*/
  2209. if (!iwl_is_ready_rf(priv))
  2210. return -EAGAIN;
  2211. iwlcore_commit_rxon(priv);
  2212. return 0;
  2213. }
  2214. EXPORT_SYMBOL(iwl_set_mode);
  2215. int iwl_mac_add_interface(struct ieee80211_hw *hw,
  2216. struct ieee80211_if_init_conf *conf)
  2217. {
  2218. struct iwl_priv *priv = hw->priv;
  2219. unsigned long flags;
  2220. IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
  2221. if (priv->vif) {
  2222. IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
  2223. return -EOPNOTSUPP;
  2224. }
  2225. spin_lock_irqsave(&priv->lock, flags);
  2226. priv->vif = conf->vif;
  2227. priv->iw_mode = conf->type;
  2228. spin_unlock_irqrestore(&priv->lock, flags);
  2229. mutex_lock(&priv->mutex);
  2230. if (conf->mac_addr) {
  2231. IWL_DEBUG_MAC80211(priv, "Set %pM\n", conf->mac_addr);
  2232. memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
  2233. }
  2234. if (iwl_set_mode(priv, conf->type) == -EAGAIN)
  2235. /* we are not ready, will run again when ready */
  2236. set_bit(STATUS_MODE_PENDING, &priv->status);
  2237. mutex_unlock(&priv->mutex);
  2238. IWL_DEBUG_MAC80211(priv, "leave\n");
  2239. return 0;
  2240. }
  2241. EXPORT_SYMBOL(iwl_mac_add_interface);
  2242. void iwl_mac_remove_interface(struct ieee80211_hw *hw,
  2243. struct ieee80211_if_init_conf *conf)
  2244. {
  2245. struct iwl_priv *priv = hw->priv;
  2246. IWL_DEBUG_MAC80211(priv, "enter\n");
  2247. mutex_lock(&priv->mutex);
  2248. if (iwl_is_ready_rf(priv)) {
  2249. iwl_scan_cancel_timeout(priv, 100);
  2250. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2251. iwlcore_commit_rxon(priv);
  2252. }
  2253. if (priv->vif == conf->vif) {
  2254. priv->vif = NULL;
  2255. memset(priv->bssid, 0, ETH_ALEN);
  2256. }
  2257. mutex_unlock(&priv->mutex);
  2258. IWL_DEBUG_MAC80211(priv, "leave\n");
  2259. }
  2260. EXPORT_SYMBOL(iwl_mac_remove_interface);
  2261. /**
  2262. * iwl_mac_config - mac80211 config callback
  2263. *
  2264. * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
  2265. * be set inappropriately and the driver currently sets the hardware up to
  2266. * use it whenever needed.
  2267. */
  2268. int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
  2269. {
  2270. struct iwl_priv *priv = hw->priv;
  2271. const struct iwl_channel_info *ch_info;
  2272. struct ieee80211_conf *conf = &hw->conf;
  2273. unsigned long flags = 0;
  2274. int ret = 0;
  2275. u16 ch;
  2276. int scan_active = 0;
  2277. mutex_lock(&priv->mutex);
  2278. IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
  2279. conf->channel->hw_value, changed);
  2280. if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
  2281. test_bit(STATUS_SCANNING, &priv->status))) {
  2282. scan_active = 1;
  2283. IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
  2284. }
  2285. /* during scanning mac80211 will delay channel setting until
  2286. * scan finish with changed = 0
  2287. */
  2288. if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
  2289. if (scan_active)
  2290. goto set_ch_out;
  2291. ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
  2292. ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
  2293. if (!is_channel_valid(ch_info)) {
  2294. IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
  2295. ret = -EINVAL;
  2296. goto set_ch_out;
  2297. }
  2298. if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
  2299. !is_channel_ibss(ch_info)) {
  2300. IWL_ERR(priv, "channel %d in band %d not "
  2301. "IBSS channel\n",
  2302. conf->channel->hw_value, conf->channel->band);
  2303. ret = -EINVAL;
  2304. goto set_ch_out;
  2305. }
  2306. priv->current_ht_config.is_ht = conf_is_ht(conf);
  2307. spin_lock_irqsave(&priv->lock, flags);
  2308. /* if we are switching from ht to 2.4 clear flags
  2309. * from any ht related info since 2.4 does not
  2310. * support ht */
  2311. if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
  2312. priv->staging_rxon.flags = 0;
  2313. iwl_set_rxon_channel(priv, conf->channel);
  2314. iwl_set_flags_for_band(priv, conf->channel->band);
  2315. spin_unlock_irqrestore(&priv->lock, flags);
  2316. set_ch_out:
  2317. /* The list of supported rates and rate mask can be different
  2318. * for each band; since the band may have changed, reset
  2319. * the rate mask to what mac80211 lists */
  2320. iwl_set_rate(priv);
  2321. }
  2322. if (changed & IEEE80211_CONF_CHANGE_PS &&
  2323. priv->iw_mode == NL80211_IFTYPE_STATION) {
  2324. priv->power_data.power_disabled =
  2325. !(conf->flags & IEEE80211_CONF_PS);
  2326. ret = iwl_power_update_mode(priv, 0);
  2327. if (ret)
  2328. IWL_DEBUG_MAC80211(priv, "Error setting power level\n");
  2329. }
  2330. if (changed & IEEE80211_CONF_CHANGE_POWER) {
  2331. IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
  2332. priv->tx_power_user_lmt, conf->power_level);
  2333. iwl_set_tx_power(priv, conf->power_level, false);
  2334. }
  2335. /* call to ensure that 4965 rx_chain is set properly in monitor mode */
  2336. if (priv->cfg->ops->hcmd->set_rxon_chain)
  2337. priv->cfg->ops->hcmd->set_rxon_chain(priv);
  2338. if (!iwl_is_ready(priv)) {
  2339. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  2340. goto out;
  2341. }
  2342. if (scan_active)
  2343. goto out;
  2344. if (memcmp(&priv->active_rxon,
  2345. &priv->staging_rxon, sizeof(priv->staging_rxon)))
  2346. iwlcore_commit_rxon(priv);
  2347. else
  2348. IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
  2349. out:
  2350. IWL_DEBUG_MAC80211(priv, "leave\n");
  2351. mutex_unlock(&priv->mutex);
  2352. return ret;
  2353. }
  2354. EXPORT_SYMBOL(iwl_mac_config);
  2355. int iwl_mac_get_tx_stats(struct ieee80211_hw *hw,
  2356. struct ieee80211_tx_queue_stats *stats)
  2357. {
  2358. struct iwl_priv *priv = hw->priv;
  2359. int i, avail;
  2360. struct iwl_tx_queue *txq;
  2361. struct iwl_queue *q;
  2362. unsigned long flags;
  2363. IWL_DEBUG_MAC80211(priv, "enter\n");
  2364. if (!iwl_is_ready_rf(priv)) {
  2365. IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
  2366. return -EIO;
  2367. }
  2368. spin_lock_irqsave(&priv->lock, flags);
  2369. for (i = 0; i < AC_NUM; i++) {
  2370. txq = &priv->txq[i];
  2371. q = &txq->q;
  2372. avail = iwl_queue_space(q);
  2373. stats[i].len = q->n_window - avail;
  2374. stats[i].limit = q->n_window - q->high_mark;
  2375. stats[i].count = q->n_window;
  2376. }
  2377. spin_unlock_irqrestore(&priv->lock, flags);
  2378. IWL_DEBUG_MAC80211(priv, "leave\n");
  2379. return 0;
  2380. }
  2381. EXPORT_SYMBOL(iwl_mac_get_tx_stats);
  2382. void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
  2383. {
  2384. struct iwl_priv *priv = hw->priv;
  2385. unsigned long flags;
  2386. mutex_lock(&priv->mutex);
  2387. IWL_DEBUG_MAC80211(priv, "enter\n");
  2388. spin_lock_irqsave(&priv->lock, flags);
  2389. memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
  2390. spin_unlock_irqrestore(&priv->lock, flags);
  2391. iwl_reset_qos(priv);
  2392. spin_lock_irqsave(&priv->lock, flags);
  2393. priv->assoc_id = 0;
  2394. priv->assoc_capability = 0;
  2395. priv->assoc_station_added = 0;
  2396. /* new association get rid of ibss beacon skb */
  2397. if (priv->ibss_beacon)
  2398. dev_kfree_skb(priv->ibss_beacon);
  2399. priv->ibss_beacon = NULL;
  2400. priv->beacon_int = priv->vif->bss_conf.beacon_int;
  2401. priv->timestamp = 0;
  2402. if ((priv->iw_mode == NL80211_IFTYPE_STATION))
  2403. priv->beacon_int = 0;
  2404. spin_unlock_irqrestore(&priv->lock, flags);
  2405. if (!iwl_is_ready_rf(priv)) {
  2406. IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
  2407. mutex_unlock(&priv->mutex);
  2408. return;
  2409. }
  2410. /* we are restarting association process
  2411. * clear RXON_FILTER_ASSOC_MSK bit
  2412. */
  2413. if (priv->iw_mode != NL80211_IFTYPE_AP) {
  2414. iwl_scan_cancel_timeout(priv, 100);
  2415. priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  2416. iwlcore_commit_rxon(priv);
  2417. }
  2418. if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
  2419. IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
  2420. mutex_unlock(&priv->mutex);
  2421. return;
  2422. }
  2423. iwl_set_rate(priv);
  2424. mutex_unlock(&priv->mutex);
  2425. IWL_DEBUG_MAC80211(priv, "leave\n");
  2426. }
  2427. EXPORT_SYMBOL(iwl_mac_reset_tsf);
  2428. #ifdef CONFIG_PM
  2429. int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  2430. {
  2431. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2432. /*
  2433. * This function is called when system goes into suspend state
  2434. * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
  2435. * first but since iwl_mac_stop() has no knowledge of who the caller is,
  2436. * it will not call apm_ops.stop() to stop the DMA operation.
  2437. * Calling apm_ops.stop here to make sure we stop the DMA.
  2438. */
  2439. priv->cfg->ops->lib->apm_ops.stop(priv);
  2440. pci_save_state(pdev);
  2441. pci_disable_device(pdev);
  2442. pci_set_power_state(pdev, PCI_D3hot);
  2443. return 0;
  2444. }
  2445. EXPORT_SYMBOL(iwl_pci_suspend);
  2446. int iwl_pci_resume(struct pci_dev *pdev)
  2447. {
  2448. struct iwl_priv *priv = pci_get_drvdata(pdev);
  2449. int ret;
  2450. pci_set_power_state(pdev, PCI_D0);
  2451. ret = pci_enable_device(pdev);
  2452. if (ret)
  2453. return ret;
  2454. pci_restore_state(pdev);
  2455. iwl_enable_interrupts(priv);
  2456. return 0;
  2457. }
  2458. EXPORT_SYMBOL(iwl_pci_resume);
  2459. #endif /* CONFIG_PM */