main.c 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
  4. * Copyright(c) 2015 Intel Deutschland GmbH
  5. *
  6. * Portions of this file are derived from the ipw3945 project, as well
  7. * as portions of the ieee80211 subsystem header files.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of version 2 of the GNU General Public License as
  11. * published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  16. * more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along with
  19. * this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  21. *
  22. * The full GNU General Public License is included in this distribution in the
  23. * file called LICENSE.
  24. *
  25. * Contact Information:
  26. * Intel Linux Wireless <linuxwifi@intel.com>
  27. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  28. *
  29. *****************************************************************************/
  30. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/init.h>
  34. #include <linux/slab.h>
  35. #include <linux/delay.h>
  36. #include <linux/sched.h>
  37. #include <linux/skbuff.h>
  38. #include <linux/netdevice.h>
  39. #include <linux/etherdevice.h>
  40. #include <linux/if_arp.h>
  41. #include <net/mac80211.h>
  42. #include <asm/div64.h>
  43. #include "iwl-eeprom-read.h"
  44. #include "iwl-eeprom-parse.h"
  45. #include "iwl-io.h"
  46. #include "iwl-trans.h"
  47. #include "iwl-op-mode.h"
  48. #include "iwl-drv.h"
  49. #include "iwl-modparams.h"
  50. #include "iwl-prph.h"
  51. #include "dev.h"
  52. #include "calib.h"
  53. #include "agn.h"
  54. /******************************************************************************
  55. *
  56. * module boiler plate
  57. *
  58. ******************************************************************************/
  59. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  60. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  61. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  62. MODULE_LICENSE("GPL");
  63. /* Please keep this array *SORTED* by hex value.
  64. * Access is done through binary search.
  65. * A warning will be triggered on violation.
  66. */
  67. static const struct iwl_hcmd_names iwl_dvm_cmd_names[] = {
  68. HCMD_NAME(REPLY_ALIVE),
  69. HCMD_NAME(REPLY_ERROR),
  70. HCMD_NAME(REPLY_ECHO),
  71. HCMD_NAME(REPLY_RXON),
  72. HCMD_NAME(REPLY_RXON_ASSOC),
  73. HCMD_NAME(REPLY_QOS_PARAM),
  74. HCMD_NAME(REPLY_RXON_TIMING),
  75. HCMD_NAME(REPLY_ADD_STA),
  76. HCMD_NAME(REPLY_REMOVE_STA),
  77. HCMD_NAME(REPLY_REMOVE_ALL_STA),
  78. HCMD_NAME(REPLY_TX),
  79. HCMD_NAME(REPLY_TXFIFO_FLUSH),
  80. HCMD_NAME(REPLY_WEPKEY),
  81. HCMD_NAME(REPLY_LEDS_CMD),
  82. HCMD_NAME(REPLY_TX_LINK_QUALITY_CMD),
  83. HCMD_NAME(COEX_PRIORITY_TABLE_CMD),
  84. HCMD_NAME(COEX_MEDIUM_NOTIFICATION),
  85. HCMD_NAME(COEX_EVENT_CMD),
  86. HCMD_NAME(TEMPERATURE_NOTIFICATION),
  87. HCMD_NAME(CALIBRATION_CFG_CMD),
  88. HCMD_NAME(CALIBRATION_RES_NOTIFICATION),
  89. HCMD_NAME(CALIBRATION_COMPLETE_NOTIFICATION),
  90. HCMD_NAME(REPLY_QUIET_CMD),
  91. HCMD_NAME(REPLY_CHANNEL_SWITCH),
  92. HCMD_NAME(CHANNEL_SWITCH_NOTIFICATION),
  93. HCMD_NAME(REPLY_SPECTRUM_MEASUREMENT_CMD),
  94. HCMD_NAME(SPECTRUM_MEASURE_NOTIFICATION),
  95. HCMD_NAME(POWER_TABLE_CMD),
  96. HCMD_NAME(PM_SLEEP_NOTIFICATION),
  97. HCMD_NAME(PM_DEBUG_STATISTIC_NOTIFIC),
  98. HCMD_NAME(REPLY_SCAN_CMD),
  99. HCMD_NAME(REPLY_SCAN_ABORT_CMD),
  100. HCMD_NAME(SCAN_START_NOTIFICATION),
  101. HCMD_NAME(SCAN_RESULTS_NOTIFICATION),
  102. HCMD_NAME(SCAN_COMPLETE_NOTIFICATION),
  103. HCMD_NAME(BEACON_NOTIFICATION),
  104. HCMD_NAME(REPLY_TX_BEACON),
  105. HCMD_NAME(WHO_IS_AWAKE_NOTIFICATION),
  106. HCMD_NAME(REPLY_TX_POWER_DBM_CMD),
  107. HCMD_NAME(QUIET_NOTIFICATION),
  108. HCMD_NAME(REPLY_TX_PWR_TABLE_CMD),
  109. HCMD_NAME(REPLY_TX_POWER_DBM_CMD_V1),
  110. HCMD_NAME(TX_ANT_CONFIGURATION_CMD),
  111. HCMD_NAME(MEASURE_ABORT_NOTIFICATION),
  112. HCMD_NAME(REPLY_BT_CONFIG),
  113. HCMD_NAME(REPLY_STATISTICS_CMD),
  114. HCMD_NAME(STATISTICS_NOTIFICATION),
  115. HCMD_NAME(REPLY_CARD_STATE_CMD),
  116. HCMD_NAME(CARD_STATE_NOTIFICATION),
  117. HCMD_NAME(MISSED_BEACONS_NOTIFICATION),
  118. HCMD_NAME(REPLY_CT_KILL_CONFIG_CMD),
  119. HCMD_NAME(SENSITIVITY_CMD),
  120. HCMD_NAME(REPLY_PHY_CALIBRATION_CMD),
  121. HCMD_NAME(REPLY_WIPAN_PARAMS),
  122. HCMD_NAME(REPLY_WIPAN_RXON),
  123. HCMD_NAME(REPLY_WIPAN_RXON_TIMING),
  124. HCMD_NAME(REPLY_WIPAN_RXON_ASSOC),
  125. HCMD_NAME(REPLY_WIPAN_QOS_PARAM),
  126. HCMD_NAME(REPLY_WIPAN_WEPKEY),
  127. HCMD_NAME(REPLY_WIPAN_P2P_CHANNEL_SWITCH),
  128. HCMD_NAME(REPLY_WIPAN_NOA_NOTIFICATION),
  129. HCMD_NAME(REPLY_WIPAN_DEACTIVATION_COMPLETE),
  130. HCMD_NAME(REPLY_RX_PHY_CMD),
  131. HCMD_NAME(REPLY_RX_MPDU_CMD),
  132. HCMD_NAME(REPLY_RX),
  133. HCMD_NAME(REPLY_COMPRESSED_BA),
  134. HCMD_NAME(REPLY_BT_COEX_PRIO_TABLE),
  135. HCMD_NAME(REPLY_BT_COEX_PROT_ENV),
  136. HCMD_NAME(REPLY_BT_COEX_PROFILE_NOTIF),
  137. HCMD_NAME(REPLY_D3_CONFIG),
  138. HCMD_NAME(REPLY_WOWLAN_PATTERNS),
  139. HCMD_NAME(REPLY_WOWLAN_WAKEUP_FILTER),
  140. HCMD_NAME(REPLY_WOWLAN_TSC_RSC_PARAMS),
  141. HCMD_NAME(REPLY_WOWLAN_TKIP_PARAMS),
  142. HCMD_NAME(REPLY_WOWLAN_KEK_KCK_MATERIAL),
  143. HCMD_NAME(REPLY_WOWLAN_GET_STATUS),
  144. };
  145. static const struct iwl_hcmd_arr iwl_dvm_groups[] = {
  146. [0x0] = HCMD_ARR(iwl_dvm_cmd_names),
  147. };
  148. static const struct iwl_op_mode_ops iwl_dvm_ops;
  149. void iwl_update_chain_flags(struct iwl_priv *priv)
  150. {
  151. struct iwl_rxon_context *ctx;
  152. for_each_context(priv, ctx) {
  153. iwlagn_set_rxon_chain(priv, ctx);
  154. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  155. iwlagn_commit_rxon(priv, ctx);
  156. }
  157. }
  158. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  159. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  160. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  161. u8 *beacon, u32 frame_size)
  162. {
  163. u16 tim_idx;
  164. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  165. /*
  166. * The index is relative to frame start but we start looking at the
  167. * variable-length part of the beacon.
  168. */
  169. tim_idx = mgmt->u.beacon.variable - beacon;
  170. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  171. while ((tim_idx < (frame_size - 2)) &&
  172. (beacon[tim_idx] != WLAN_EID_TIM))
  173. tim_idx += beacon[tim_idx+1] + 2;
  174. /* If TIM field was found, set variables */
  175. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  176. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  177. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  178. } else
  179. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  180. }
  181. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  182. {
  183. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  184. struct iwl_host_cmd cmd = {
  185. .id = REPLY_TX_BEACON,
  186. };
  187. struct ieee80211_tx_info *info;
  188. u32 frame_size;
  189. u32 rate_flags;
  190. u32 rate;
  191. /*
  192. * We have to set up the TX command, the TX Beacon command, and the
  193. * beacon contents.
  194. */
  195. lockdep_assert_held(&priv->mutex);
  196. if (!priv->beacon_ctx) {
  197. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  198. return 0;
  199. }
  200. if (WARN_ON(!priv->beacon_skb))
  201. return -EINVAL;
  202. /* Allocate beacon command */
  203. if (!priv->beacon_cmd)
  204. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  205. tx_beacon_cmd = priv->beacon_cmd;
  206. if (!tx_beacon_cmd)
  207. return -ENOMEM;
  208. frame_size = priv->beacon_skb->len;
  209. /* Set up TX command fields */
  210. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  211. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  212. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  213. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  214. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  215. /* Set up TX beacon command fields */
  216. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  217. frame_size);
  218. /* Set up packet rate and flags */
  219. info = IEEE80211_SKB_CB(priv->beacon_skb);
  220. /*
  221. * Let's set up the rate at least somewhat correctly;
  222. * it will currently not actually be used by the uCode,
  223. * it uses the broadcast station's rate instead.
  224. */
  225. if (info->control.rates[0].idx < 0 ||
  226. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  227. rate = 0;
  228. else
  229. rate = info->control.rates[0].idx;
  230. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  231. priv->nvm_data->valid_tx_ant);
  232. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  233. /* In mac80211, rates for 5 GHz start at 0 */
  234. if (info->band == NL80211_BAND_5GHZ)
  235. rate += IWL_FIRST_OFDM_RATE;
  236. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  237. rate_flags |= RATE_MCS_CCK_MSK;
  238. tx_beacon_cmd->tx.rate_n_flags =
  239. iwl_hw_set_rate_n_flags(rate, rate_flags);
  240. /* Submit command */
  241. cmd.len[0] = sizeof(*tx_beacon_cmd);
  242. cmd.data[0] = tx_beacon_cmd;
  243. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  244. cmd.len[1] = frame_size;
  245. cmd.data[1] = priv->beacon_skb->data;
  246. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  247. return iwl_dvm_send_cmd(priv, &cmd);
  248. }
  249. static void iwl_bg_beacon_update(struct work_struct *work)
  250. {
  251. struct iwl_priv *priv =
  252. container_of(work, struct iwl_priv, beacon_update);
  253. struct sk_buff *beacon;
  254. mutex_lock(&priv->mutex);
  255. if (!priv->beacon_ctx) {
  256. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  257. goto out;
  258. }
  259. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  260. /*
  261. * The ucode will send beacon notifications even in
  262. * IBSS mode, but we don't want to process them. But
  263. * we need to defer the type check to here due to
  264. * requiring locking around the beacon_ctx access.
  265. */
  266. goto out;
  267. }
  268. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  269. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  270. if (!beacon) {
  271. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  272. goto out;
  273. }
  274. /* new beacon skb is allocated every time; dispose previous.*/
  275. dev_kfree_skb(priv->beacon_skb);
  276. priv->beacon_skb = beacon;
  277. iwlagn_send_beacon_cmd(priv);
  278. out:
  279. mutex_unlock(&priv->mutex);
  280. }
  281. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  282. {
  283. struct iwl_priv *priv =
  284. container_of(work, struct iwl_priv, bt_runtime_config);
  285. mutex_lock(&priv->mutex);
  286. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  287. goto out;
  288. /* dont send host command if rf-kill is on */
  289. if (!iwl_is_ready_rf(priv))
  290. goto out;
  291. iwlagn_send_advance_bt_config(priv);
  292. out:
  293. mutex_unlock(&priv->mutex);
  294. }
  295. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  296. {
  297. struct iwl_priv *priv =
  298. container_of(work, struct iwl_priv, bt_full_concurrency);
  299. struct iwl_rxon_context *ctx;
  300. mutex_lock(&priv->mutex);
  301. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  302. goto out;
  303. /* dont send host command if rf-kill is on */
  304. if (!iwl_is_ready_rf(priv))
  305. goto out;
  306. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  307. priv->bt_full_concurrent ?
  308. "full concurrency" : "3-wire");
  309. /*
  310. * LQ & RXON updated cmds must be sent before BT Config cmd
  311. * to avoid 3-wire collisions
  312. */
  313. for_each_context(priv, ctx) {
  314. iwlagn_set_rxon_chain(priv, ctx);
  315. iwlagn_commit_rxon(priv, ctx);
  316. }
  317. iwlagn_send_advance_bt_config(priv);
  318. out:
  319. mutex_unlock(&priv->mutex);
  320. }
  321. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
  322. {
  323. struct iwl_statistics_cmd statistics_cmd = {
  324. .configuration_flags =
  325. clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
  326. };
  327. if (flags & CMD_ASYNC)
  328. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
  329. CMD_ASYNC,
  330. sizeof(struct iwl_statistics_cmd),
  331. &statistics_cmd);
  332. else
  333. return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD, 0,
  334. sizeof(struct iwl_statistics_cmd),
  335. &statistics_cmd);
  336. }
  337. /**
  338. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  339. *
  340. * This callback is provided in order to send a statistics request.
  341. *
  342. * This timer function is continually reset to execute within
  343. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  344. * was received. We need to ensure we receive the statistics in order
  345. * to update the temperature used for calibrating the TXPOWER.
  346. */
  347. static void iwl_bg_statistics_periodic(struct timer_list *t)
  348. {
  349. struct iwl_priv *priv = from_timer(priv, t, statistics_periodic);
  350. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  351. return;
  352. /* dont send host command if rf-kill is on */
  353. if (!iwl_is_ready_rf(priv))
  354. return;
  355. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  356. }
  357. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  358. u32 start_idx, u32 num_events,
  359. u32 capacity, u32 mode)
  360. {
  361. u32 i;
  362. u32 ptr; /* SRAM byte address of log data */
  363. u32 ev, time, data; /* event log data */
  364. unsigned long reg_flags;
  365. if (mode == 0)
  366. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  367. else
  368. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  369. /* Make sure device is powered up for SRAM reads */
  370. if (!iwl_trans_grab_nic_access(priv->trans, &reg_flags))
  371. return;
  372. /* Set starting address; reads will auto-increment */
  373. iwl_write32(priv->trans, HBUS_TARG_MEM_RADDR, ptr);
  374. /*
  375. * Refuse to read more than would have fit into the log from
  376. * the current start_idx. This used to happen due to the race
  377. * described below, but now WARN because the code below should
  378. * prevent it from happening here.
  379. */
  380. if (WARN_ON(num_events > capacity - start_idx))
  381. num_events = capacity - start_idx;
  382. /*
  383. * "time" is actually "data" for mode 0 (no timestamp).
  384. * place event id # at far right for easier visual parsing.
  385. */
  386. for (i = 0; i < num_events; i++) {
  387. ev = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  388. time = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  389. if (mode == 0) {
  390. trace_iwlwifi_dev_ucode_cont_event(
  391. priv->trans->dev, 0, time, ev);
  392. } else {
  393. data = iwl_read32(priv->trans, HBUS_TARG_MEM_RDAT);
  394. trace_iwlwifi_dev_ucode_cont_event(
  395. priv->trans->dev, time, data, ev);
  396. }
  397. }
  398. /* Allow device to power down */
  399. iwl_trans_release_nic_access(priv->trans, &reg_flags);
  400. }
  401. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  402. {
  403. u32 capacity; /* event log capacity in # entries */
  404. struct {
  405. u32 capacity;
  406. u32 mode;
  407. u32 wrap_counter;
  408. u32 write_counter;
  409. } __packed read;
  410. u32 base; /* SRAM byte address of event log header */
  411. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  412. u32 num_wraps; /* # times uCode wrapped to top of log */
  413. u32 next_entry; /* index of next entry to be written by uCode */
  414. base = priv->device_pointers.log_event_table;
  415. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  416. iwl_trans_read_mem_bytes(priv->trans, base,
  417. &read, sizeof(read));
  418. capacity = read.capacity;
  419. mode = read.mode;
  420. num_wraps = read.wrap_counter;
  421. next_entry = read.write_counter;
  422. } else
  423. return;
  424. /*
  425. * Unfortunately, the uCode doesn't use temporary variables.
  426. * Therefore, it can happen that we read next_entry == capacity,
  427. * which really means next_entry == 0.
  428. */
  429. if (unlikely(next_entry == capacity))
  430. next_entry = 0;
  431. /*
  432. * Additionally, the uCode increases the write pointer before
  433. * the wraps counter, so if the write pointer is smaller than
  434. * the old write pointer (wrap occurred) but we read that no
  435. * wrap occurred, we actually read between the next_entry and
  436. * num_wraps update (this does happen in practice!!) -- take
  437. * that into account by increasing num_wraps.
  438. */
  439. if (unlikely(next_entry < priv->event_log.next_entry &&
  440. num_wraps == priv->event_log.num_wraps))
  441. num_wraps++;
  442. if (num_wraps == priv->event_log.num_wraps) {
  443. iwl_print_cont_event_trace(
  444. priv, base, priv->event_log.next_entry,
  445. next_entry - priv->event_log.next_entry,
  446. capacity, mode);
  447. priv->event_log.non_wraps_count++;
  448. } else {
  449. if (num_wraps - priv->event_log.num_wraps > 1)
  450. priv->event_log.wraps_more_count++;
  451. else
  452. priv->event_log.wraps_once_count++;
  453. trace_iwlwifi_dev_ucode_wrap_event(priv->trans->dev,
  454. num_wraps - priv->event_log.num_wraps,
  455. next_entry, priv->event_log.next_entry);
  456. if (next_entry < priv->event_log.next_entry) {
  457. iwl_print_cont_event_trace(
  458. priv, base, priv->event_log.next_entry,
  459. capacity - priv->event_log.next_entry,
  460. capacity, mode);
  461. iwl_print_cont_event_trace(
  462. priv, base, 0, next_entry, capacity, mode);
  463. } else {
  464. iwl_print_cont_event_trace(
  465. priv, base, next_entry,
  466. capacity - next_entry,
  467. capacity, mode);
  468. iwl_print_cont_event_trace(
  469. priv, base, 0, next_entry, capacity, mode);
  470. }
  471. }
  472. priv->event_log.num_wraps = num_wraps;
  473. priv->event_log.next_entry = next_entry;
  474. }
  475. /**
  476. * iwl_bg_ucode_trace - Timer callback to log ucode event
  477. *
  478. * The timer is continually set to execute every
  479. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  480. * this function is to perform continuous uCode event logging operation
  481. * if enabled
  482. */
  483. static void iwl_bg_ucode_trace(struct timer_list *t)
  484. {
  485. struct iwl_priv *priv = from_timer(priv, t, ucode_trace);
  486. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  487. return;
  488. if (priv->event_log.ucode_trace) {
  489. iwl_continuous_event_trace(priv);
  490. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  491. mod_timer(&priv->ucode_trace,
  492. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  493. }
  494. }
  495. static void iwl_bg_tx_flush(struct work_struct *work)
  496. {
  497. struct iwl_priv *priv =
  498. container_of(work, struct iwl_priv, tx_flush);
  499. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  500. return;
  501. /* do nothing if rf-kill is on */
  502. if (!iwl_is_ready_rf(priv))
  503. return;
  504. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  505. iwlagn_dev_txfifo_flush(priv);
  506. }
  507. /*
  508. * queue/FIFO/AC mapping definitions
  509. */
  510. static const u8 iwlagn_bss_ac_to_fifo[] = {
  511. IWL_TX_FIFO_VO,
  512. IWL_TX_FIFO_VI,
  513. IWL_TX_FIFO_BE,
  514. IWL_TX_FIFO_BK,
  515. };
  516. static const u8 iwlagn_bss_ac_to_queue[] = {
  517. 0, 1, 2, 3,
  518. };
  519. static const u8 iwlagn_pan_ac_to_fifo[] = {
  520. IWL_TX_FIFO_VO_IPAN,
  521. IWL_TX_FIFO_VI_IPAN,
  522. IWL_TX_FIFO_BE_IPAN,
  523. IWL_TX_FIFO_BK_IPAN,
  524. };
  525. static const u8 iwlagn_pan_ac_to_queue[] = {
  526. 7, 6, 5, 4,
  527. };
  528. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  529. {
  530. int i;
  531. /*
  532. * The default context is always valid,
  533. * the PAN context depends on uCode.
  534. */
  535. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  536. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  537. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  538. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  539. priv->contexts[i].ctxid = i;
  540. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  541. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  542. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  543. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  544. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  545. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  546. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  547. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  548. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  549. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  550. BIT(NL80211_IFTYPE_ADHOC) | BIT(NL80211_IFTYPE_MONITOR);
  551. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  552. BIT(NL80211_IFTYPE_STATION);
  553. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  554. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  555. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  556. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  557. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  558. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  559. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  560. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  561. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  562. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  563. REPLY_WIPAN_RXON_TIMING;
  564. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  565. REPLY_WIPAN_RXON_ASSOC;
  566. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  567. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  568. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  569. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  570. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  571. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  572. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  573. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  574. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  575. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  576. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  577. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  578. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  579. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  580. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  581. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  582. }
  583. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  584. {
  585. struct iwl_ct_kill_config cmd;
  586. struct iwl_ct_kill_throttling_config adv_cmd;
  587. int ret = 0;
  588. iwl_write32(priv->trans, CSR_UCODE_DRV_GP1_CLR,
  589. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  590. priv->thermal_throttle.ct_kill_toggle = false;
  591. if (priv->lib->support_ct_kill_exit) {
  592. adv_cmd.critical_temperature_enter =
  593. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  594. adv_cmd.critical_temperature_exit =
  595. cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
  596. ret = iwl_dvm_send_cmd_pdu(priv,
  597. REPLY_CT_KILL_CONFIG_CMD,
  598. 0, sizeof(adv_cmd), &adv_cmd);
  599. if (ret)
  600. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  601. else
  602. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  603. "succeeded, critical temperature enter is %d,"
  604. "exit is %d\n",
  605. priv->hw_params.ct_kill_threshold,
  606. priv->hw_params.ct_kill_exit_threshold);
  607. } else {
  608. cmd.critical_temperature_R =
  609. cpu_to_le32(priv->hw_params.ct_kill_threshold);
  610. ret = iwl_dvm_send_cmd_pdu(priv,
  611. REPLY_CT_KILL_CONFIG_CMD,
  612. 0, sizeof(cmd), &cmd);
  613. if (ret)
  614. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  615. else
  616. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  617. "succeeded, "
  618. "critical temperature is %d\n",
  619. priv->hw_params.ct_kill_threshold);
  620. }
  621. }
  622. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  623. {
  624. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  625. struct iwl_host_cmd cmd = {
  626. .id = CALIBRATION_CFG_CMD,
  627. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  628. .data = { &calib_cfg_cmd, },
  629. };
  630. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  631. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  632. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  633. return iwl_dvm_send_cmd(priv, &cmd);
  634. }
  635. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  636. {
  637. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  638. .valid = cpu_to_le32(valid_tx_ant),
  639. };
  640. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  641. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  642. return iwl_dvm_send_cmd_pdu(priv, TX_ANT_CONFIGURATION_CMD, 0,
  643. sizeof(struct iwl_tx_ant_config_cmd),
  644. &tx_ant_cmd);
  645. } else {
  646. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  647. return -EOPNOTSUPP;
  648. }
  649. }
  650. static void iwl_send_bt_config(struct iwl_priv *priv)
  651. {
  652. struct iwl_bt_cmd bt_cmd = {
  653. .lead_time = BT_LEAD_TIME_DEF,
  654. .max_kill = BT_MAX_KILL_DEF,
  655. .kill_ack_mask = 0,
  656. .kill_cts_mask = 0,
  657. };
  658. if (!iwlwifi_mod_params.bt_coex_active)
  659. bt_cmd.flags = BT_COEX_DISABLE;
  660. else
  661. bt_cmd.flags = BT_COEX_ENABLE;
  662. priv->bt_enable_flag = bt_cmd.flags;
  663. IWL_DEBUG_INFO(priv, "BT coex %s\n",
  664. (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
  665. if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
  666. 0, sizeof(struct iwl_bt_cmd), &bt_cmd))
  667. IWL_ERR(priv, "failed to send BT Coex Config\n");
  668. }
  669. /**
  670. * iwl_alive_start - called after REPLY_ALIVE notification received
  671. * from protocol/runtime uCode (initialization uCode's
  672. * Alive gets handled by iwl_init_alive_start()).
  673. */
  674. int iwl_alive_start(struct iwl_priv *priv)
  675. {
  676. int ret = 0;
  677. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  678. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  679. /* After the ALIVE response, we can send host commands to the uCode */
  680. set_bit(STATUS_ALIVE, &priv->status);
  681. if (iwl_is_rfkill(priv))
  682. return -ERFKILL;
  683. if (priv->event_log.ucode_trace) {
  684. /* start collecting data now */
  685. mod_timer(&priv->ucode_trace, jiffies);
  686. }
  687. /* download priority table before any calibration request */
  688. if (priv->lib->bt_params &&
  689. priv->lib->bt_params->advanced_bt_coexist) {
  690. /* Configure Bluetooth device coexistence support */
  691. if (priv->lib->bt_params->bt_sco_disable)
  692. priv->bt_enable_pspoll = false;
  693. else
  694. priv->bt_enable_pspoll = true;
  695. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  696. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  697. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  698. iwlagn_send_advance_bt_config(priv);
  699. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  700. priv->cur_rssi_ctx = NULL;
  701. iwl_send_prio_tbl(priv);
  702. /* FIXME: w/a to force change uCode BT state machine */
  703. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  704. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  705. if (ret)
  706. return ret;
  707. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  708. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  709. if (ret)
  710. return ret;
  711. } else if (priv->lib->bt_params) {
  712. /*
  713. * default is 2-wire BT coexexistence support
  714. */
  715. iwl_send_bt_config(priv);
  716. }
  717. /*
  718. * Perform runtime calibrations, including DC calibration.
  719. */
  720. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  721. ieee80211_wake_queues(priv->hw);
  722. /* Configure Tx antenna selection based on H/W config */
  723. iwlagn_send_tx_ant_config(priv, priv->nvm_data->valid_tx_ant);
  724. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  725. struct iwl_rxon_cmd *active_rxon =
  726. (struct iwl_rxon_cmd *)&ctx->active;
  727. /* apply any changes in staging */
  728. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  729. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  730. } else {
  731. struct iwl_rxon_context *tmp;
  732. /* Initialize our rx_config data */
  733. for_each_context(priv, tmp)
  734. iwl_connection_init_rx_config(priv, tmp);
  735. iwlagn_set_rxon_chain(priv, ctx);
  736. }
  737. if (!priv->wowlan) {
  738. /* WoWLAN ucode will not reply in the same way, skip it */
  739. iwl_reset_run_time_calib(priv);
  740. }
  741. set_bit(STATUS_READY, &priv->status);
  742. /* Configure the adapter for unassociated operation */
  743. ret = iwlagn_commit_rxon(priv, ctx);
  744. if (ret)
  745. return ret;
  746. /* At this point, the NIC is initialized and operational */
  747. iwl_rf_kill_ct_config(priv);
  748. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  749. return iwl_power_update_mode(priv, true);
  750. }
  751. /**
  752. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  753. * @priv: iwl priv struct
  754. *
  755. * This is called during iwl_down() to make sure that in the case
  756. * we're coming there from a hardware restart mac80211 will be
  757. * able to reconfigure stations -- if we're getting there in the
  758. * normal down flow then the stations will already be cleared.
  759. */
  760. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  761. {
  762. struct iwl_rxon_context *ctx;
  763. spin_lock_bh(&priv->sta_lock);
  764. memset(priv->stations, 0, sizeof(priv->stations));
  765. priv->num_stations = 0;
  766. priv->ucode_key_table = 0;
  767. for_each_context(priv, ctx) {
  768. /*
  769. * Remove all key information that is not stored as part
  770. * of station information since mac80211 may not have had
  771. * a chance to remove all the keys. When device is
  772. * reconfigured by mac80211 after an error all keys will
  773. * be reconfigured.
  774. */
  775. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  776. ctx->key_mapping_keys = 0;
  777. }
  778. spin_unlock_bh(&priv->sta_lock);
  779. }
  780. void iwl_down(struct iwl_priv *priv)
  781. {
  782. int exit_pending;
  783. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  784. lockdep_assert_held(&priv->mutex);
  785. iwl_scan_cancel_timeout(priv, 200);
  786. exit_pending =
  787. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  788. iwl_clear_ucode_stations(priv, NULL);
  789. iwl_dealloc_bcast_stations(priv);
  790. iwl_clear_driver_stations(priv);
  791. /* reset BT coex data */
  792. priv->bt_status = 0;
  793. priv->cur_rssi_ctx = NULL;
  794. priv->bt_is_sco = 0;
  795. if (priv->lib->bt_params)
  796. priv->bt_traffic_load =
  797. priv->lib->bt_params->bt_init_traffic_load;
  798. else
  799. priv->bt_traffic_load = 0;
  800. priv->bt_full_concurrent = false;
  801. priv->bt_ci_compliance = 0;
  802. /* Wipe out the EXIT_PENDING status bit if we are not actually
  803. * exiting the module */
  804. if (!exit_pending)
  805. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  806. if (priv->mac80211_registered)
  807. ieee80211_stop_queues(priv->hw);
  808. priv->ucode_loaded = false;
  809. iwl_trans_stop_device(priv->trans);
  810. /* Set num_aux_in_flight must be done after the transport is stopped */
  811. atomic_set(&priv->num_aux_in_flight, 0);
  812. /* Clear out all status bits but a few that are stable across reset */
  813. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  814. STATUS_RF_KILL_HW |
  815. test_bit(STATUS_FW_ERROR, &priv->status) <<
  816. STATUS_FW_ERROR |
  817. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  818. STATUS_EXIT_PENDING;
  819. dev_kfree_skb(priv->beacon_skb);
  820. priv->beacon_skb = NULL;
  821. }
  822. /*****************************************************************************
  823. *
  824. * Workqueue callbacks
  825. *
  826. *****************************************************************************/
  827. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  828. {
  829. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  830. run_time_calib_work);
  831. mutex_lock(&priv->mutex);
  832. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  833. test_bit(STATUS_SCANNING, &priv->status)) {
  834. mutex_unlock(&priv->mutex);
  835. return;
  836. }
  837. if (priv->start_calib) {
  838. iwl_chain_noise_calibration(priv);
  839. iwl_sensitivity_calibration(priv);
  840. }
  841. mutex_unlock(&priv->mutex);
  842. }
  843. void iwlagn_prepare_restart(struct iwl_priv *priv)
  844. {
  845. bool bt_full_concurrent;
  846. u8 bt_ci_compliance;
  847. u8 bt_load;
  848. u8 bt_status;
  849. bool bt_is_sco;
  850. int i;
  851. lockdep_assert_held(&priv->mutex);
  852. priv->is_open = 0;
  853. /*
  854. * __iwl_down() will clear the BT status variables,
  855. * which is correct, but when we restart we really
  856. * want to keep them so restore them afterwards.
  857. *
  858. * The restart process will later pick them up and
  859. * re-configure the hw when we reconfigure the BT
  860. * command.
  861. */
  862. bt_full_concurrent = priv->bt_full_concurrent;
  863. bt_ci_compliance = priv->bt_ci_compliance;
  864. bt_load = priv->bt_traffic_load;
  865. bt_status = priv->bt_status;
  866. bt_is_sco = priv->bt_is_sco;
  867. iwl_down(priv);
  868. priv->bt_full_concurrent = bt_full_concurrent;
  869. priv->bt_ci_compliance = bt_ci_compliance;
  870. priv->bt_traffic_load = bt_load;
  871. priv->bt_status = bt_status;
  872. priv->bt_is_sco = bt_is_sco;
  873. /* reset aggregation queues */
  874. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  875. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  876. /* and stop counts */
  877. for (i = 0; i < IWL_MAX_HW_QUEUES; i++)
  878. atomic_set(&priv->queue_stop_count[i], 0);
  879. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  880. }
  881. static void iwl_bg_restart(struct work_struct *data)
  882. {
  883. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  884. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  885. return;
  886. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
  887. mutex_lock(&priv->mutex);
  888. iwlagn_prepare_restart(priv);
  889. mutex_unlock(&priv->mutex);
  890. iwl_cancel_deferred_work(priv);
  891. if (priv->mac80211_registered)
  892. ieee80211_restart_hw(priv->hw);
  893. else
  894. IWL_ERR(priv,
  895. "Cannot request restart before registrating with mac80211\n");
  896. } else {
  897. WARN_ON(1);
  898. }
  899. }
  900. /*****************************************************************************
  901. *
  902. * driver setup and teardown
  903. *
  904. *****************************************************************************/
  905. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  906. {
  907. priv->workqueue = alloc_ordered_workqueue(DRV_NAME, 0);
  908. INIT_WORK(&priv->restart, iwl_bg_restart);
  909. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  910. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  911. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  912. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  913. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  914. iwl_setup_scan_deferred_work(priv);
  915. if (priv->lib->bt_params)
  916. iwlagn_bt_setup_deferred_work(priv);
  917. timer_setup(&priv->statistics_periodic, iwl_bg_statistics_periodic, 0);
  918. timer_setup(&priv->ucode_trace, iwl_bg_ucode_trace, 0);
  919. }
  920. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  921. {
  922. if (priv->lib->bt_params)
  923. iwlagn_bt_cancel_deferred_work(priv);
  924. cancel_work_sync(&priv->run_time_calib_work);
  925. cancel_work_sync(&priv->beacon_update);
  926. iwl_cancel_scan_deferred_work(priv);
  927. cancel_work_sync(&priv->bt_full_concurrency);
  928. cancel_work_sync(&priv->bt_runtime_config);
  929. del_timer_sync(&priv->statistics_periodic);
  930. del_timer_sync(&priv->ucode_trace);
  931. }
  932. static int iwl_init_drv(struct iwl_priv *priv)
  933. {
  934. spin_lock_init(&priv->sta_lock);
  935. mutex_init(&priv->mutex);
  936. INIT_LIST_HEAD(&priv->calib_results);
  937. priv->band = NL80211_BAND_2GHZ;
  938. priv->plcp_delta_threshold = priv->lib->plcp_delta_threshold;
  939. priv->iw_mode = NL80211_IFTYPE_STATION;
  940. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  941. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  942. priv->agg_tids_count = 0;
  943. priv->rx_statistics_jiffies = jiffies;
  944. /* Choose which receivers/antennas to use */
  945. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  946. iwl_init_scan_params(priv);
  947. /* init bt coex */
  948. if (priv->lib->bt_params &&
  949. priv->lib->bt_params->advanced_bt_coexist) {
  950. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  951. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  952. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  953. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  954. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  955. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  956. }
  957. return 0;
  958. }
  959. static void iwl_uninit_drv(struct iwl_priv *priv)
  960. {
  961. kfree(priv->scan_cmd);
  962. kfree(priv->beacon_cmd);
  963. kfree(rcu_dereference_raw(priv->noa_data));
  964. iwl_calib_free_results(priv);
  965. #ifdef CONFIG_IWLWIFI_DEBUGFS
  966. kfree(priv->wowlan_sram);
  967. #endif
  968. }
  969. static void iwl_set_hw_params(struct iwl_priv *priv)
  970. {
  971. if (priv->cfg->ht_params)
  972. priv->hw_params.use_rts_for_aggregation =
  973. priv->cfg->ht_params->use_rts_for_aggregation;
  974. /* Device-specific setup */
  975. priv->lib->set_hw_params(priv);
  976. }
  977. /* show what optional capabilities we have */
  978. static void iwl_option_config(struct iwl_priv *priv)
  979. {
  980. #ifdef CONFIG_IWLWIFI_DEBUG
  981. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG enabled\n");
  982. #else
  983. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUG disabled\n");
  984. #endif
  985. #ifdef CONFIG_IWLWIFI_DEBUGFS
  986. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS enabled\n");
  987. #else
  988. IWL_INFO(priv, "CONFIG_IWLWIFI_DEBUGFS disabled\n");
  989. #endif
  990. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  991. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING enabled\n");
  992. #else
  993. IWL_INFO(priv, "CONFIG_IWLWIFI_DEVICE_TRACING disabled\n");
  994. #endif
  995. }
  996. static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
  997. {
  998. struct iwl_nvm_data *data = priv->nvm_data;
  999. if (data->sku_cap_11n_enable &&
  1000. !priv->cfg->ht_params) {
  1001. IWL_ERR(priv, "Invalid 11n configuration\n");
  1002. return -EINVAL;
  1003. }
  1004. if (!data->sku_cap_11n_enable && !data->sku_cap_band_24ghz_enable &&
  1005. !data->sku_cap_band_52ghz_enable) {
  1006. IWL_ERR(priv, "Invalid device sku\n");
  1007. return -EINVAL;
  1008. }
  1009. IWL_DEBUG_INFO(priv,
  1010. "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n",
  1011. data->sku_cap_band_24ghz_enable ? "" : "NOT", "enabled",
  1012. data->sku_cap_band_52ghz_enable ? "" : "NOT", "enabled",
  1013. data->sku_cap_11n_enable ? "" : "NOT", "enabled");
  1014. priv->hw_params.tx_chains_num =
  1015. num_of_ant(data->valid_tx_ant);
  1016. if (priv->cfg->rx_with_siso_diversity)
  1017. priv->hw_params.rx_chains_num = 1;
  1018. else
  1019. priv->hw_params.rx_chains_num =
  1020. num_of_ant(data->valid_rx_ant);
  1021. IWL_DEBUG_INFO(priv, "Valid Tx ant: 0x%X, Valid Rx ant: 0x%X\n",
  1022. data->valid_tx_ant,
  1023. data->valid_rx_ant);
  1024. return 0;
  1025. }
  1026. static int iwl_nvm_check_version(struct iwl_nvm_data *data,
  1027. struct iwl_trans *trans)
  1028. {
  1029. if (data->nvm_version >= trans->cfg->nvm_ver ||
  1030. data->calib_version >= trans->cfg->nvm_calib_ver) {
  1031. IWL_DEBUG_INFO(trans, "device EEPROM VER=0x%x, CALIB=0x%x\n",
  1032. data->nvm_version, data->calib_version);
  1033. return 0;
  1034. }
  1035. IWL_ERR(trans,
  1036. "Unsupported (too old) EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
  1037. data->nvm_version, trans->cfg->nvm_ver,
  1038. data->calib_version, trans->cfg->nvm_calib_ver);
  1039. return -EINVAL;
  1040. }
  1041. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  1042. const struct iwl_cfg *cfg,
  1043. const struct iwl_fw *fw,
  1044. struct dentry *dbgfs_dir)
  1045. {
  1046. struct iwl_priv *priv;
  1047. struct ieee80211_hw *hw;
  1048. struct iwl_op_mode *op_mode;
  1049. u16 num_mac;
  1050. u32 ucode_flags;
  1051. struct iwl_trans_config trans_cfg = {};
  1052. static const u8 no_reclaim_cmds[] = {
  1053. REPLY_RX_PHY_CMD,
  1054. REPLY_RX_MPDU_CMD,
  1055. REPLY_COMPRESSED_BA,
  1056. STATISTICS_NOTIFICATION,
  1057. REPLY_TX,
  1058. };
  1059. int i;
  1060. /************************
  1061. * 1. Allocating HW data
  1062. ************************/
  1063. hw = iwl_alloc_all();
  1064. if (!hw) {
  1065. pr_err("%s: Cannot allocate network device\n", cfg->name);
  1066. goto out;
  1067. }
  1068. op_mode = hw->priv;
  1069. op_mode->ops = &iwl_dvm_ops;
  1070. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1071. priv->trans = trans;
  1072. priv->dev = trans->dev;
  1073. priv->cfg = cfg;
  1074. priv->fw = fw;
  1075. switch (priv->cfg->device_family) {
  1076. case IWL_DEVICE_FAMILY_1000:
  1077. case IWL_DEVICE_FAMILY_100:
  1078. priv->lib = &iwl_dvm_1000_cfg;
  1079. break;
  1080. case IWL_DEVICE_FAMILY_2000:
  1081. priv->lib = &iwl_dvm_2000_cfg;
  1082. break;
  1083. case IWL_DEVICE_FAMILY_105:
  1084. priv->lib = &iwl_dvm_105_cfg;
  1085. break;
  1086. case IWL_DEVICE_FAMILY_2030:
  1087. case IWL_DEVICE_FAMILY_135:
  1088. priv->lib = &iwl_dvm_2030_cfg;
  1089. break;
  1090. case IWL_DEVICE_FAMILY_5000:
  1091. priv->lib = &iwl_dvm_5000_cfg;
  1092. break;
  1093. case IWL_DEVICE_FAMILY_5150:
  1094. priv->lib = &iwl_dvm_5150_cfg;
  1095. break;
  1096. case IWL_DEVICE_FAMILY_6000:
  1097. case IWL_DEVICE_FAMILY_6000i:
  1098. priv->lib = &iwl_dvm_6000_cfg;
  1099. break;
  1100. case IWL_DEVICE_FAMILY_6005:
  1101. priv->lib = &iwl_dvm_6005_cfg;
  1102. break;
  1103. case IWL_DEVICE_FAMILY_6050:
  1104. case IWL_DEVICE_FAMILY_6150:
  1105. priv->lib = &iwl_dvm_6050_cfg;
  1106. break;
  1107. case IWL_DEVICE_FAMILY_6030:
  1108. priv->lib = &iwl_dvm_6030_cfg;
  1109. break;
  1110. default:
  1111. break;
  1112. }
  1113. if (WARN_ON(!priv->lib))
  1114. goto out_free_hw;
  1115. /*
  1116. * Populate the state variables that the transport layer needs
  1117. * to know about.
  1118. */
  1119. trans_cfg.op_mode = op_mode;
  1120. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1121. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1122. switch (iwlwifi_mod_params.amsdu_size) {
  1123. case IWL_AMSDU_DEF:
  1124. case IWL_AMSDU_4K:
  1125. trans_cfg.rx_buf_size = IWL_AMSDU_4K;
  1126. break;
  1127. case IWL_AMSDU_8K:
  1128. trans_cfg.rx_buf_size = IWL_AMSDU_8K;
  1129. break;
  1130. case IWL_AMSDU_12K:
  1131. default:
  1132. trans_cfg.rx_buf_size = IWL_AMSDU_4K;
  1133. pr_err("Unsupported amsdu_size: %d\n",
  1134. iwlwifi_mod_params.amsdu_size);
  1135. }
  1136. trans_cfg.cmd_q_wdg_timeout = IWL_WATCHDOG_DISABLED;
  1137. trans_cfg.command_groups = iwl_dvm_groups;
  1138. trans_cfg.command_groups_size = ARRAY_SIZE(iwl_dvm_groups);
  1139. trans_cfg.cmd_fifo = IWLAGN_CMD_FIFO_NUM;
  1140. trans_cfg.cb_data_offs = offsetof(struct ieee80211_tx_info,
  1141. driver_data[2]);
  1142. WARN_ON(sizeof(priv->transport_queue_stop) * BITS_PER_BYTE <
  1143. priv->cfg->base_params->num_of_queues);
  1144. ucode_flags = fw->ucode_capa.flags;
  1145. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1146. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1147. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1148. } else {
  1149. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1150. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1151. }
  1152. /* Configure transport layer */
  1153. iwl_trans_configure(priv->trans, &trans_cfg);
  1154. trans->rx_mpdu_cmd = REPLY_RX_MPDU_CMD;
  1155. trans->rx_mpdu_cmd_hdr_size = sizeof(struct iwl_rx_mpdu_res_start);
  1156. trans->command_groups = trans_cfg.command_groups;
  1157. trans->command_groups_size = trans_cfg.command_groups_size;
  1158. /* At this point both hw and priv are allocated. */
  1159. SET_IEEE80211_DEV(priv->hw, priv->trans->dev);
  1160. iwl_option_config(priv);
  1161. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1162. /* is antenna coupling more than 35dB ? */
  1163. priv->bt_ant_couple_ok =
  1164. (iwlwifi_mod_params.antenna_coupling >
  1165. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1166. true : false;
  1167. /* bt channel inhibition enabled*/
  1168. priv->bt_ch_announce = true;
  1169. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1170. (priv->bt_ch_announce) ? "On" : "Off");
  1171. /* these spin locks will be used in apm_ops.init and EEPROM access
  1172. * we should init now
  1173. */
  1174. spin_lock_init(&priv->statistics.lock);
  1175. /***********************
  1176. * 2. Read REV register
  1177. ***********************/
  1178. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1179. priv->cfg->name, priv->trans->hw_rev);
  1180. if (iwl_trans_start_hw(priv->trans))
  1181. goto out_free_hw;
  1182. /* Read the EEPROM */
  1183. if (iwl_read_eeprom(priv->trans, &priv->eeprom_blob,
  1184. &priv->eeprom_blob_size)) {
  1185. IWL_ERR(priv, "Unable to init EEPROM\n");
  1186. goto out_free_hw;
  1187. }
  1188. /* Reset chip to save power until we load uCode during "up". */
  1189. iwl_trans_stop_device(priv->trans);
  1190. priv->nvm_data = iwl_parse_eeprom_data(priv->trans->dev, priv->cfg,
  1191. priv->eeprom_blob,
  1192. priv->eeprom_blob_size);
  1193. if (!priv->nvm_data)
  1194. goto out_free_eeprom_blob;
  1195. if (iwl_nvm_check_version(priv->nvm_data, priv->trans))
  1196. goto out_free_eeprom;
  1197. if (iwl_eeprom_init_hw_params(priv))
  1198. goto out_free_eeprom;
  1199. /* extract MAC Address */
  1200. memcpy(priv->addresses[0].addr, priv->nvm_data->hw_addr, ETH_ALEN);
  1201. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1202. priv->hw->wiphy->addresses = priv->addresses;
  1203. priv->hw->wiphy->n_addresses = 1;
  1204. num_mac = priv->nvm_data->n_hw_addrs;
  1205. if (num_mac > 1) {
  1206. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1207. ETH_ALEN);
  1208. priv->addresses[1].addr[5]++;
  1209. priv->hw->wiphy->n_addresses++;
  1210. }
  1211. /************************
  1212. * 4. Setup HW constants
  1213. ************************/
  1214. iwl_set_hw_params(priv);
  1215. if (!(priv->nvm_data->sku_cap_ipan_enable)) {
  1216. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN\n");
  1217. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1218. /*
  1219. * if not PAN, then don't support P2P -- might be a uCode
  1220. * packaging bug or due to the eeprom check above
  1221. */
  1222. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1223. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1224. /* Configure transport layer again*/
  1225. iwl_trans_configure(priv->trans, &trans_cfg);
  1226. }
  1227. /*******************
  1228. * 5. Setup priv
  1229. *******************/
  1230. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1231. priv->queue_to_mac80211[i] = IWL_INVALID_MAC80211_QUEUE;
  1232. if (i < IWLAGN_FIRST_AMPDU_QUEUE &&
  1233. i != IWL_DEFAULT_CMD_QUEUE_NUM &&
  1234. i != IWL_IPAN_CMD_QUEUE_NUM)
  1235. priv->queue_to_mac80211[i] = i;
  1236. atomic_set(&priv->queue_stop_count[i], 0);
  1237. }
  1238. if (iwl_init_drv(priv))
  1239. goto out_free_eeprom;
  1240. /* At this point both hw and priv are initialized. */
  1241. /********************
  1242. * 6. Setup services
  1243. ********************/
  1244. iwl_setup_deferred_work(priv);
  1245. iwl_setup_rx_handlers(priv);
  1246. iwl_power_initialize(priv);
  1247. iwl_tt_initialize(priv);
  1248. snprintf(priv->hw->wiphy->fw_version,
  1249. sizeof(priv->hw->wiphy->fw_version),
  1250. "%s", fw->fw_version);
  1251. priv->new_scan_threshold_behaviour =
  1252. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1253. priv->phy_calib_chain_noise_reset_cmd =
  1254. fw->ucode_capa.standard_phy_calibration_size;
  1255. priv->phy_calib_chain_noise_gain_cmd =
  1256. fw->ucode_capa.standard_phy_calibration_size + 1;
  1257. /* initialize all valid contexts */
  1258. iwl_init_context(priv, ucode_flags);
  1259. /**************************************************
  1260. * This is still part of probe() in a sense...
  1261. *
  1262. * 7. Setup and register with mac80211 and debugfs
  1263. **************************************************/
  1264. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1265. goto out_destroy_workqueue;
  1266. if (iwl_dbgfs_register(priv, dbgfs_dir))
  1267. goto out_mac80211_unregister;
  1268. return op_mode;
  1269. out_mac80211_unregister:
  1270. iwlagn_mac_unregister(priv);
  1271. out_destroy_workqueue:
  1272. iwl_tt_exit(priv);
  1273. iwl_cancel_deferred_work(priv);
  1274. destroy_workqueue(priv->workqueue);
  1275. priv->workqueue = NULL;
  1276. iwl_uninit_drv(priv);
  1277. out_free_eeprom_blob:
  1278. kfree(priv->eeprom_blob);
  1279. out_free_eeprom:
  1280. kfree(priv->nvm_data);
  1281. out_free_hw:
  1282. ieee80211_free_hw(priv->hw);
  1283. out:
  1284. op_mode = NULL;
  1285. return op_mode;
  1286. }
  1287. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1288. {
  1289. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1290. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1291. iwlagn_mac_unregister(priv);
  1292. iwl_tt_exit(priv);
  1293. kfree(priv->eeprom_blob);
  1294. kfree(priv->nvm_data);
  1295. /*netif_stop_queue(dev); */
  1296. flush_workqueue(priv->workqueue);
  1297. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1298. * priv->workqueue... so we can't take down the workqueue
  1299. * until now... */
  1300. destroy_workqueue(priv->workqueue);
  1301. priv->workqueue = NULL;
  1302. iwl_uninit_drv(priv);
  1303. dev_kfree_skb(priv->beacon_skb);
  1304. iwl_trans_op_mode_leave(priv->trans);
  1305. ieee80211_free_hw(priv->hw);
  1306. }
  1307. static const char * const desc_lookup_text[] = {
  1308. "OK",
  1309. "FAIL",
  1310. "BAD_PARAM",
  1311. "BAD_CHECKSUM",
  1312. "NMI_INTERRUPT_WDG",
  1313. "SYSASSERT",
  1314. "FATAL_ERROR",
  1315. "BAD_COMMAND",
  1316. "HW_ERROR_TUNE_LOCK",
  1317. "HW_ERROR_TEMPERATURE",
  1318. "ILLEGAL_CHAN_FREQ",
  1319. "VCC_NOT_STABLE",
  1320. "FH_ERROR",
  1321. "NMI_INTERRUPT_HOST",
  1322. "NMI_INTERRUPT_ACTION_PT",
  1323. "NMI_INTERRUPT_UNKNOWN",
  1324. "UCODE_VERSION_MISMATCH",
  1325. "HW_ERROR_ABS_LOCK",
  1326. "HW_ERROR_CAL_LOCK_FAIL",
  1327. "NMI_INTERRUPT_INST_ACTION_PT",
  1328. "NMI_INTERRUPT_DATA_ACTION_PT",
  1329. "NMI_TRM_HW_ER",
  1330. "NMI_INTERRUPT_TRM",
  1331. "NMI_INTERRUPT_BREAK_POINT",
  1332. "DEBUG_0",
  1333. "DEBUG_1",
  1334. "DEBUG_2",
  1335. "DEBUG_3",
  1336. };
  1337. static struct { char *name; u8 num; } advanced_lookup[] = {
  1338. { "NMI_INTERRUPT_WDG", 0x34 },
  1339. { "SYSASSERT", 0x35 },
  1340. { "UCODE_VERSION_MISMATCH", 0x37 },
  1341. { "BAD_COMMAND", 0x38 },
  1342. { "NMI_INTERRUPT_DATA_ACTION_PT", 0x3C },
  1343. { "FATAL_ERROR", 0x3D },
  1344. { "NMI_TRM_HW_ERR", 0x46 },
  1345. { "NMI_INTERRUPT_TRM", 0x4C },
  1346. { "NMI_INTERRUPT_BREAK_POINT", 0x54 },
  1347. { "NMI_INTERRUPT_WDG_RXF_FULL", 0x5C },
  1348. { "NMI_INTERRUPT_WDG_NO_RBD_RXF_FULL", 0x64 },
  1349. { "NMI_INTERRUPT_HOST", 0x66 },
  1350. { "NMI_INTERRUPT_ACTION_PT", 0x7C },
  1351. { "NMI_INTERRUPT_UNKNOWN", 0x84 },
  1352. { "NMI_INTERRUPT_INST_ACTION_PT", 0x86 },
  1353. { "ADVANCED_SYSASSERT", 0 },
  1354. };
  1355. static const char *desc_lookup(u32 num)
  1356. {
  1357. int i;
  1358. int max = ARRAY_SIZE(desc_lookup_text);
  1359. if (num < max)
  1360. return desc_lookup_text[num];
  1361. max = ARRAY_SIZE(advanced_lookup) - 1;
  1362. for (i = 0; i < max; i++) {
  1363. if (advanced_lookup[i].num == num)
  1364. break;
  1365. }
  1366. return advanced_lookup[i].name;
  1367. }
  1368. #define ERROR_START_OFFSET (1 * sizeof(u32))
  1369. #define ERROR_ELEM_SIZE (7 * sizeof(u32))
  1370. static void iwl_dump_nic_error_log(struct iwl_priv *priv)
  1371. {
  1372. struct iwl_trans *trans = priv->trans;
  1373. u32 base;
  1374. struct iwl_error_event_table table;
  1375. base = priv->device_pointers.error_event_table;
  1376. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1377. if (!base)
  1378. base = priv->fw->init_errlog_ptr;
  1379. } else {
  1380. if (!base)
  1381. base = priv->fw->inst_errlog_ptr;
  1382. }
  1383. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1384. IWL_ERR(priv,
  1385. "Not valid error log pointer 0x%08X for %s uCode\n",
  1386. base,
  1387. (priv->cur_ucode == IWL_UCODE_INIT)
  1388. ? "Init" : "RT");
  1389. return;
  1390. }
  1391. /*TODO: Update dbgfs with ISR error stats obtained below */
  1392. iwl_trans_read_mem_bytes(trans, base, &table, sizeof(table));
  1393. if (ERROR_START_OFFSET <= table.valid * ERROR_ELEM_SIZE) {
  1394. IWL_ERR(trans, "Start IWL Error Log Dump:\n");
  1395. IWL_ERR(trans, "Status: 0x%08lX, count: %d\n",
  1396. priv->status, table.valid);
  1397. }
  1398. trace_iwlwifi_dev_ucode_error(trans->dev, &table, 0, table.brd_ver);
  1399. IWL_ERR(priv, "0x%08X | %-28s\n", table.error_id,
  1400. desc_lookup(table.error_id));
  1401. IWL_ERR(priv, "0x%08X | uPc\n", table.pc);
  1402. IWL_ERR(priv, "0x%08X | branchlink1\n", table.blink1);
  1403. IWL_ERR(priv, "0x%08X | branchlink2\n", table.blink2);
  1404. IWL_ERR(priv, "0x%08X | interruptlink1\n", table.ilink1);
  1405. IWL_ERR(priv, "0x%08X | interruptlink2\n", table.ilink2);
  1406. IWL_ERR(priv, "0x%08X | data1\n", table.data1);
  1407. IWL_ERR(priv, "0x%08X | data2\n", table.data2);
  1408. IWL_ERR(priv, "0x%08X | line\n", table.line);
  1409. IWL_ERR(priv, "0x%08X | beacon time\n", table.bcon_time);
  1410. IWL_ERR(priv, "0x%08X | tsf low\n", table.tsf_low);
  1411. IWL_ERR(priv, "0x%08X | tsf hi\n", table.tsf_hi);
  1412. IWL_ERR(priv, "0x%08X | time gp1\n", table.gp1);
  1413. IWL_ERR(priv, "0x%08X | time gp2\n", table.gp2);
  1414. IWL_ERR(priv, "0x%08X | time gp3\n", table.gp3);
  1415. IWL_ERR(priv, "0x%08X | uCode version\n", table.ucode_ver);
  1416. IWL_ERR(priv, "0x%08X | hw version\n", table.hw_ver);
  1417. IWL_ERR(priv, "0x%08X | board version\n", table.brd_ver);
  1418. IWL_ERR(priv, "0x%08X | hcmd\n", table.hcmd);
  1419. IWL_ERR(priv, "0x%08X | isr0\n", table.isr0);
  1420. IWL_ERR(priv, "0x%08X | isr1\n", table.isr1);
  1421. IWL_ERR(priv, "0x%08X | isr2\n", table.isr2);
  1422. IWL_ERR(priv, "0x%08X | isr3\n", table.isr3);
  1423. IWL_ERR(priv, "0x%08X | isr4\n", table.isr4);
  1424. IWL_ERR(priv, "0x%08X | isr_pref\n", table.isr_pref);
  1425. IWL_ERR(priv, "0x%08X | wait_event\n", table.wait_event);
  1426. IWL_ERR(priv, "0x%08X | l2p_control\n", table.l2p_control);
  1427. IWL_ERR(priv, "0x%08X | l2p_duration\n", table.l2p_duration);
  1428. IWL_ERR(priv, "0x%08X | l2p_mhvalid\n", table.l2p_mhvalid);
  1429. IWL_ERR(priv, "0x%08X | l2p_addr_match\n", table.l2p_addr_match);
  1430. IWL_ERR(priv, "0x%08X | lmpm_pmg_sel\n", table.lmpm_pmg_sel);
  1431. IWL_ERR(priv, "0x%08X | timestamp\n", table.u_timestamp);
  1432. IWL_ERR(priv, "0x%08X | flow_handler\n", table.flow_handler);
  1433. }
  1434. #define EVENT_START_OFFSET (4 * sizeof(u32))
  1435. /**
  1436. * iwl_print_event_log - Dump error event log to syslog
  1437. *
  1438. */
  1439. static int iwl_print_event_log(struct iwl_priv *priv, u32 start_idx,
  1440. u32 num_events, u32 mode,
  1441. int pos, char **buf, size_t bufsz)
  1442. {
  1443. u32 i;
  1444. u32 base; /* SRAM byte address of event log header */
  1445. u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
  1446. u32 ptr; /* SRAM byte address of log data */
  1447. u32 ev, time, data; /* event log data */
  1448. unsigned long reg_flags;
  1449. struct iwl_trans *trans = priv->trans;
  1450. if (num_events == 0)
  1451. return pos;
  1452. base = priv->device_pointers.log_event_table;
  1453. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1454. if (!base)
  1455. base = priv->fw->init_evtlog_ptr;
  1456. } else {
  1457. if (!base)
  1458. base = priv->fw->inst_evtlog_ptr;
  1459. }
  1460. if (mode == 0)
  1461. event_size = 2 * sizeof(u32);
  1462. else
  1463. event_size = 3 * sizeof(u32);
  1464. ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
  1465. /* Make sure device is powered up for SRAM reads */
  1466. if (!iwl_trans_grab_nic_access(trans, &reg_flags))
  1467. return pos;
  1468. /* Set starting address; reads will auto-increment */
  1469. iwl_write32(trans, HBUS_TARG_MEM_RADDR, ptr);
  1470. /* "time" is actually "data" for mode 0 (no timestamp).
  1471. * place event id # at far right for easier visual parsing. */
  1472. for (i = 0; i < num_events; i++) {
  1473. ev = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1474. time = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1475. if (mode == 0) {
  1476. /* data, ev */
  1477. if (bufsz) {
  1478. pos += scnprintf(*buf + pos, bufsz - pos,
  1479. "EVT_LOG:0x%08x:%04u\n",
  1480. time, ev);
  1481. } else {
  1482. trace_iwlwifi_dev_ucode_event(trans->dev, 0,
  1483. time, ev);
  1484. IWL_ERR(priv, "EVT_LOG:0x%08x:%04u\n",
  1485. time, ev);
  1486. }
  1487. } else {
  1488. data = iwl_read32(trans, HBUS_TARG_MEM_RDAT);
  1489. if (bufsz) {
  1490. pos += scnprintf(*buf + pos, bufsz - pos,
  1491. "EVT_LOGT:%010u:0x%08x:%04u\n",
  1492. time, data, ev);
  1493. } else {
  1494. IWL_ERR(priv, "EVT_LOGT:%010u:0x%08x:%04u\n",
  1495. time, data, ev);
  1496. trace_iwlwifi_dev_ucode_event(trans->dev, time,
  1497. data, ev);
  1498. }
  1499. }
  1500. }
  1501. /* Allow device to power down */
  1502. iwl_trans_release_nic_access(trans, &reg_flags);
  1503. return pos;
  1504. }
  1505. /**
  1506. * iwl_print_last_event_logs - Dump the newest # of event log to syslog
  1507. */
  1508. static int iwl_print_last_event_logs(struct iwl_priv *priv, u32 capacity,
  1509. u32 num_wraps, u32 next_entry,
  1510. u32 size, u32 mode,
  1511. int pos, char **buf, size_t bufsz)
  1512. {
  1513. /*
  1514. * display the newest DEFAULT_LOG_ENTRIES entries
  1515. * i.e the entries just before the next ont that uCode would fill.
  1516. */
  1517. if (num_wraps) {
  1518. if (next_entry < size) {
  1519. pos = iwl_print_event_log(priv,
  1520. capacity - (size - next_entry),
  1521. size - next_entry, mode,
  1522. pos, buf, bufsz);
  1523. pos = iwl_print_event_log(priv, 0,
  1524. next_entry, mode,
  1525. pos, buf, bufsz);
  1526. } else
  1527. pos = iwl_print_event_log(priv, next_entry - size,
  1528. size, mode, pos, buf, bufsz);
  1529. } else {
  1530. if (next_entry < size) {
  1531. pos = iwl_print_event_log(priv, 0, next_entry,
  1532. mode, pos, buf, bufsz);
  1533. } else {
  1534. pos = iwl_print_event_log(priv, next_entry - size,
  1535. size, mode, pos, buf, bufsz);
  1536. }
  1537. }
  1538. return pos;
  1539. }
  1540. #define DEFAULT_DUMP_EVENT_LOG_ENTRIES (20)
  1541. int iwl_dump_nic_event_log(struct iwl_priv *priv, bool full_log,
  1542. char **buf)
  1543. {
  1544. u32 base; /* SRAM byte address of event log header */
  1545. u32 capacity; /* event log capacity in # entries */
  1546. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  1547. u32 num_wraps; /* # times uCode wrapped to top of log */
  1548. u32 next_entry; /* index of next entry to be written by uCode */
  1549. u32 size; /* # entries that we'll print */
  1550. u32 logsize;
  1551. int pos = 0;
  1552. size_t bufsz = 0;
  1553. struct iwl_trans *trans = priv->trans;
  1554. base = priv->device_pointers.log_event_table;
  1555. if (priv->cur_ucode == IWL_UCODE_INIT) {
  1556. logsize = priv->fw->init_evtlog_size;
  1557. if (!base)
  1558. base = priv->fw->init_evtlog_ptr;
  1559. } else {
  1560. logsize = priv->fw->inst_evtlog_size;
  1561. if (!base)
  1562. base = priv->fw->inst_evtlog_ptr;
  1563. }
  1564. if (!iwlagn_hw_valid_rtc_data_addr(base)) {
  1565. IWL_ERR(priv,
  1566. "Invalid event log pointer 0x%08X for %s uCode\n",
  1567. base,
  1568. (priv->cur_ucode == IWL_UCODE_INIT)
  1569. ? "Init" : "RT");
  1570. return -EINVAL;
  1571. }
  1572. /* event log header */
  1573. capacity = iwl_trans_read_mem32(trans, base);
  1574. mode = iwl_trans_read_mem32(trans, base + (1 * sizeof(u32)));
  1575. num_wraps = iwl_trans_read_mem32(trans, base + (2 * sizeof(u32)));
  1576. next_entry = iwl_trans_read_mem32(trans, base + (3 * sizeof(u32)));
  1577. if (capacity > logsize) {
  1578. IWL_ERR(priv, "Log capacity %d is bogus, limit to %d "
  1579. "entries\n", capacity, logsize);
  1580. capacity = logsize;
  1581. }
  1582. if (next_entry > logsize) {
  1583. IWL_ERR(priv, "Log write index %d is bogus, limit to %d\n",
  1584. next_entry, logsize);
  1585. next_entry = logsize;
  1586. }
  1587. size = num_wraps ? capacity : next_entry;
  1588. /* bail out if nothing in log */
  1589. if (size == 0) {
  1590. IWL_ERR(trans, "Start IWL Event Log Dump: nothing in log\n");
  1591. return pos;
  1592. }
  1593. if (!(iwl_have_debug_level(IWL_DL_FW_ERRORS)) && !full_log)
  1594. size = (size > DEFAULT_DUMP_EVENT_LOG_ENTRIES)
  1595. ? DEFAULT_DUMP_EVENT_LOG_ENTRIES : size;
  1596. IWL_ERR(priv, "Start IWL Event Log Dump: display last %u entries\n",
  1597. size);
  1598. #ifdef CONFIG_IWLWIFI_DEBUG
  1599. if (buf) {
  1600. if (full_log)
  1601. bufsz = capacity * 48;
  1602. else
  1603. bufsz = size * 48;
  1604. *buf = kmalloc(bufsz, GFP_KERNEL);
  1605. if (!*buf)
  1606. return -ENOMEM;
  1607. }
  1608. if (iwl_have_debug_level(IWL_DL_FW_ERRORS) || full_log) {
  1609. /*
  1610. * if uCode has wrapped back to top of log,
  1611. * start at the oldest entry,
  1612. * i.e the next one that uCode would fill.
  1613. */
  1614. if (num_wraps)
  1615. pos = iwl_print_event_log(priv, next_entry,
  1616. capacity - next_entry, mode,
  1617. pos, buf, bufsz);
  1618. /* (then/else) start at top of log */
  1619. pos = iwl_print_event_log(priv, 0,
  1620. next_entry, mode, pos, buf, bufsz);
  1621. } else
  1622. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1623. next_entry, size, mode,
  1624. pos, buf, bufsz);
  1625. #else
  1626. pos = iwl_print_last_event_logs(priv, capacity, num_wraps,
  1627. next_entry, size, mode,
  1628. pos, buf, bufsz);
  1629. #endif
  1630. return pos;
  1631. }
  1632. static void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
  1633. {
  1634. unsigned int reload_msec;
  1635. unsigned long reload_jiffies;
  1636. if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
  1637. iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
  1638. /* uCode is no longer loaded. */
  1639. priv->ucode_loaded = false;
  1640. /* Set the FW error flag -- cleared on iwl_down */
  1641. set_bit(STATUS_FW_ERROR, &priv->status);
  1642. iwl_abort_notification_waits(&priv->notif_wait);
  1643. /* Keep the restart process from trying to send host
  1644. * commands by clearing the ready bit */
  1645. clear_bit(STATUS_READY, &priv->status);
  1646. if (!ondemand) {
  1647. /*
  1648. * If firmware keep reloading, then it indicate something
  1649. * serious wrong and firmware having problem to recover
  1650. * from it. Instead of keep trying which will fill the syslog
  1651. * and hang the system, let's just stop it
  1652. */
  1653. reload_jiffies = jiffies;
  1654. reload_msec = jiffies_to_msecs((long) reload_jiffies -
  1655. (long) priv->reload_jiffies);
  1656. priv->reload_jiffies = reload_jiffies;
  1657. if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
  1658. priv->reload_count++;
  1659. if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
  1660. IWL_ERR(priv, "BUG_ON, Stop restarting\n");
  1661. return;
  1662. }
  1663. } else
  1664. priv->reload_count = 0;
  1665. }
  1666. if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
  1667. if (iwlwifi_mod_params.fw_restart) {
  1668. IWL_DEBUG_FW_ERRORS(priv,
  1669. "Restarting adapter due to uCode error.\n");
  1670. queue_work(priv->workqueue, &priv->restart);
  1671. } else
  1672. IWL_DEBUG_FW_ERRORS(priv,
  1673. "Detected FW error, but not restarting\n");
  1674. }
  1675. }
  1676. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1677. {
  1678. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1679. IWL_ERR(priv, "Loaded firmware version: %s\n",
  1680. priv->fw->fw_version);
  1681. iwl_dump_nic_error_log(priv);
  1682. iwl_dump_nic_event_log(priv, false, NULL);
  1683. iwlagn_fw_error(priv, false);
  1684. }
  1685. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1686. {
  1687. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1688. if (!iwl_check_for_ct_kill(priv)) {
  1689. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1690. iwlagn_fw_error(priv, false);
  1691. }
  1692. }
  1693. #define EEPROM_RF_CONFIG_TYPE_MAX 0x3
  1694. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1695. {
  1696. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1697. /* SKU Control */
  1698. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1699. CSR_HW_IF_CONFIG_REG_MSK_MAC_DASH |
  1700. CSR_HW_IF_CONFIG_REG_MSK_MAC_STEP,
  1701. (CSR_HW_REV_STEP(priv->trans->hw_rev) <<
  1702. CSR_HW_IF_CONFIG_REG_POS_MAC_STEP) |
  1703. (CSR_HW_REV_DASH(priv->trans->hw_rev) <<
  1704. CSR_HW_IF_CONFIG_REG_POS_MAC_DASH));
  1705. /* write radio config values to register */
  1706. if (priv->nvm_data->radio_cfg_type <= EEPROM_RF_CONFIG_TYPE_MAX) {
  1707. u32 reg_val =
  1708. priv->nvm_data->radio_cfg_type <<
  1709. CSR_HW_IF_CONFIG_REG_POS_PHY_TYPE |
  1710. priv->nvm_data->radio_cfg_step <<
  1711. CSR_HW_IF_CONFIG_REG_POS_PHY_STEP |
  1712. priv->nvm_data->radio_cfg_dash <<
  1713. CSR_HW_IF_CONFIG_REG_POS_PHY_DASH;
  1714. iwl_trans_set_bits_mask(priv->trans, CSR_HW_IF_CONFIG_REG,
  1715. CSR_HW_IF_CONFIG_REG_MSK_PHY_TYPE |
  1716. CSR_HW_IF_CONFIG_REG_MSK_PHY_STEP |
  1717. CSR_HW_IF_CONFIG_REG_MSK_PHY_DASH,
  1718. reg_val);
  1719. IWL_INFO(priv, "Radio type=0x%x-0x%x-0x%x\n",
  1720. priv->nvm_data->radio_cfg_type,
  1721. priv->nvm_data->radio_cfg_step,
  1722. priv->nvm_data->radio_cfg_dash);
  1723. } else {
  1724. WARN_ON(1);
  1725. }
  1726. /* set CSR_HW_CONFIG_REG for uCode use */
  1727. iwl_set_bit(priv->trans, CSR_HW_IF_CONFIG_REG,
  1728. CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
  1729. CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
  1730. /* W/A : NIC is stuck in a reset state after Early PCIe power off
  1731. * (PCIe power is lost before PERST# is asserted),
  1732. * causing ME FW to lose ownership and not being able to obtain it back.
  1733. */
  1734. iwl_set_bits_mask_prph(priv->trans, APMG_PS_CTRL_REG,
  1735. APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS,
  1736. ~APMG_PS_CTRL_EARLY_PWR_OFF_RESET_DIS);
  1737. if (priv->lib->nic_config)
  1738. priv->lib->nic_config(priv);
  1739. }
  1740. static void iwl_wimax_active(struct iwl_op_mode *op_mode)
  1741. {
  1742. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1743. clear_bit(STATUS_READY, &priv->status);
  1744. IWL_ERR(priv, "RF is used by WiMAX\n");
  1745. }
  1746. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1747. {
  1748. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1749. int mq = priv->queue_to_mac80211[queue];
  1750. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1751. return;
  1752. if (atomic_inc_return(&priv->queue_stop_count[mq]) > 1) {
  1753. IWL_DEBUG_TX_QUEUES(priv,
  1754. "queue %d (mac80211 %d) already stopped\n",
  1755. queue, mq);
  1756. return;
  1757. }
  1758. set_bit(mq, &priv->transport_queue_stop);
  1759. ieee80211_stop_queue(priv->hw, mq);
  1760. }
  1761. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1762. {
  1763. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1764. int mq = priv->queue_to_mac80211[queue];
  1765. if (WARN_ON_ONCE(mq == IWL_INVALID_MAC80211_QUEUE))
  1766. return;
  1767. if (atomic_dec_return(&priv->queue_stop_count[mq]) > 0) {
  1768. IWL_DEBUG_TX_QUEUES(priv,
  1769. "queue %d (mac80211 %d) already awake\n",
  1770. queue, mq);
  1771. return;
  1772. }
  1773. clear_bit(mq, &priv->transport_queue_stop);
  1774. if (!priv->passive_no_rx)
  1775. ieee80211_wake_queue(priv->hw, mq);
  1776. }
  1777. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1778. {
  1779. int mq;
  1780. if (!priv->passive_no_rx)
  1781. return;
  1782. for (mq = 0; mq < IWLAGN_FIRST_AMPDU_QUEUE; mq++) {
  1783. if (!test_bit(mq, &priv->transport_queue_stop)) {
  1784. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d\n", mq);
  1785. ieee80211_wake_queue(priv->hw, mq);
  1786. } else {
  1787. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d\n", mq);
  1788. }
  1789. }
  1790. priv->passive_no_rx = false;
  1791. }
  1792. static void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
  1793. {
  1794. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1795. struct ieee80211_tx_info *info;
  1796. info = IEEE80211_SKB_CB(skb);
  1797. iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]);
  1798. ieee80211_free_txskb(priv->hw, skb);
  1799. }
  1800. static bool iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
  1801. {
  1802. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1803. if (state)
  1804. set_bit(STATUS_RF_KILL_HW, &priv->status);
  1805. else
  1806. clear_bit(STATUS_RF_KILL_HW, &priv->status);
  1807. wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
  1808. return false;
  1809. }
  1810. static const struct iwl_op_mode_ops iwl_dvm_ops = {
  1811. .start = iwl_op_mode_dvm_start,
  1812. .stop = iwl_op_mode_dvm_stop,
  1813. .rx = iwl_rx_dispatch,
  1814. .queue_full = iwl_stop_sw_queue,
  1815. .queue_not_full = iwl_wake_sw_queue,
  1816. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1817. .free_skb = iwl_free_skb,
  1818. .nic_error = iwl_nic_error,
  1819. .cmd_queue_full = iwl_cmd_queue_full,
  1820. .nic_config = iwl_nic_config,
  1821. .wimax_active = iwl_wimax_active,
  1822. };
  1823. /*****************************************************************************
  1824. *
  1825. * driver and module entry point
  1826. *
  1827. *****************************************************************************/
  1828. static int __init iwl_init(void)
  1829. {
  1830. int ret;
  1831. ret = iwlagn_rate_control_register();
  1832. if (ret) {
  1833. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1834. return ret;
  1835. }
  1836. ret = iwl_opmode_register("iwldvm", &iwl_dvm_ops);
  1837. if (ret) {
  1838. pr_err("Unable to register op_mode: %d\n", ret);
  1839. iwlagn_rate_control_unregister();
  1840. }
  1841. return ret;
  1842. }
  1843. module_init(iwl_init);
  1844. static void __exit iwl_exit(void)
  1845. {
  1846. iwl_opmode_deregister("iwldvm");
  1847. iwlagn_rate_control_unregister();
  1848. }
  1849. module_exit(iwl_exit);