iwl-agn.c 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
  4. *
  5. * Portions of this file are derived from the ipw3945 project, as well
  6. * as portions of the ieee80211 subsystem header files.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of version 2 of the GNU General Public License as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful, but WITHOUT
  13. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  15. * more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along with
  18. * this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
  20. *
  21. * The full GNU General Public License is included in this distribution in the
  22. * file called LICENSE.
  23. *
  24. * Contact Information:
  25. * Intel Linux Wireless <ilw@linux.intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *
  28. *****************************************************************************/
  29. #include <linux/kernel.h>
  30. #include <linux/module.h>
  31. #include <linux/init.h>
  32. #include <linux/slab.h>
  33. #include <linux/delay.h>
  34. #include <linux/sched.h>
  35. #include <linux/skbuff.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/firmware.h>
  38. #include <linux/etherdevice.h>
  39. #include <linux/if_arp.h>
  40. #include <net/mac80211.h>
  41. #include <asm/div64.h>
  42. #include "iwl-eeprom.h"
  43. #include "iwl-wifi.h"
  44. #include "iwl-dev.h"
  45. #include "iwl-core.h"
  46. #include "iwl-io.h"
  47. #include "iwl-agn-calib.h"
  48. #include "iwl-agn.h"
  49. #include "iwl-shared.h"
  50. #include "iwl-bus.h"
  51. #include "iwl-trans.h"
  52. /******************************************************************************
  53. *
  54. * module boiler plate
  55. *
  56. ******************************************************************************/
  57. /*
  58. * module name, copyright, version, etc.
  59. */
  60. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  61. #ifdef CONFIG_IWLWIFI_DEBUG
  62. #define VD "d"
  63. #else
  64. #define VD
  65. #endif
  66. #define DRV_VERSION IWLWIFI_VERSION VD
  67. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  68. MODULE_VERSION(DRV_VERSION);
  69. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  70. MODULE_LICENSE("GPL");
  71. MODULE_ALIAS("iwlagn");
  72. void iwl_update_chain_flags(struct iwl_priv *priv)
  73. {
  74. struct iwl_rxon_context *ctx;
  75. for_each_context(priv, ctx) {
  76. iwlagn_set_rxon_chain(priv, ctx);
  77. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  78. iwlagn_commit_rxon(priv, ctx);
  79. }
  80. }
  81. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  82. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  83. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  84. u8 *beacon, u32 frame_size)
  85. {
  86. u16 tim_idx;
  87. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  88. /*
  89. * The index is relative to frame start but we start looking at the
  90. * variable-length part of the beacon.
  91. */
  92. tim_idx = mgmt->u.beacon.variable - beacon;
  93. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  94. while ((tim_idx < (frame_size - 2)) &&
  95. (beacon[tim_idx] != WLAN_EID_TIM))
  96. tim_idx += beacon[tim_idx+1] + 2;
  97. /* If TIM field was found, set variables */
  98. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  99. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  100. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  101. } else
  102. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  103. }
  104. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  105. {
  106. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  107. struct iwl_host_cmd cmd = {
  108. .id = REPLY_TX_BEACON,
  109. .flags = CMD_SYNC,
  110. };
  111. struct ieee80211_tx_info *info;
  112. u32 frame_size;
  113. u32 rate_flags;
  114. u32 rate;
  115. /*
  116. * We have to set up the TX command, the TX Beacon command, and the
  117. * beacon contents.
  118. */
  119. lockdep_assert_held(&priv->shrd->mutex);
  120. if (!priv->beacon_ctx) {
  121. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  122. return 0;
  123. }
  124. if (WARN_ON(!priv->beacon_skb))
  125. return -EINVAL;
  126. /* Allocate beacon command */
  127. if (!priv->beacon_cmd)
  128. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  129. tx_beacon_cmd = priv->beacon_cmd;
  130. if (!tx_beacon_cmd)
  131. return -ENOMEM;
  132. frame_size = priv->beacon_skb->len;
  133. /* Set up TX command fields */
  134. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  135. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  136. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  137. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  138. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  139. /* Set up TX beacon command fields */
  140. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  141. frame_size);
  142. /* Set up packet rate and flags */
  143. info = IEEE80211_SKB_CB(priv->beacon_skb);
  144. /*
  145. * Let's set up the rate at least somewhat correctly;
  146. * it will currently not actually be used by the uCode,
  147. * it uses the broadcast station's rate instead.
  148. */
  149. if (info->control.rates[0].idx < 0 ||
  150. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  151. rate = 0;
  152. else
  153. rate = info->control.rates[0].idx;
  154. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  155. hw_params(priv).valid_tx_ant);
  156. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  157. /* In mac80211, rates for 5 GHz start at 0 */
  158. if (info->band == IEEE80211_BAND_5GHZ)
  159. rate += IWL_FIRST_OFDM_RATE;
  160. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  161. rate_flags |= RATE_MCS_CCK_MSK;
  162. tx_beacon_cmd->tx.rate_n_flags =
  163. iwl_hw_set_rate_n_flags(rate, rate_flags);
  164. /* Submit command */
  165. cmd.len[0] = sizeof(*tx_beacon_cmd);
  166. cmd.data[0] = tx_beacon_cmd;
  167. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  168. cmd.len[1] = frame_size;
  169. cmd.data[1] = priv->beacon_skb->data;
  170. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  171. return iwl_trans_send_cmd(trans(priv), &cmd);
  172. }
  173. static void iwl_bg_beacon_update(struct work_struct *work)
  174. {
  175. struct iwl_priv *priv =
  176. container_of(work, struct iwl_priv, beacon_update);
  177. struct sk_buff *beacon;
  178. mutex_lock(&priv->shrd->mutex);
  179. if (!priv->beacon_ctx) {
  180. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  181. goto out;
  182. }
  183. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  184. /*
  185. * The ucode will send beacon notifications even in
  186. * IBSS mode, but we don't want to process them. But
  187. * we need to defer the type check to here due to
  188. * requiring locking around the beacon_ctx access.
  189. */
  190. goto out;
  191. }
  192. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  193. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  194. if (!beacon) {
  195. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  196. goto out;
  197. }
  198. /* new beacon skb is allocated every time; dispose previous.*/
  199. dev_kfree_skb(priv->beacon_skb);
  200. priv->beacon_skb = beacon;
  201. iwlagn_send_beacon_cmd(priv);
  202. out:
  203. mutex_unlock(&priv->shrd->mutex);
  204. }
  205. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  206. {
  207. struct iwl_priv *priv =
  208. container_of(work, struct iwl_priv, bt_runtime_config);
  209. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  210. return;
  211. /* dont send host command if rf-kill is on */
  212. if (!iwl_is_ready_rf(priv->shrd))
  213. return;
  214. iwlagn_send_advance_bt_config(priv);
  215. }
  216. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  217. {
  218. struct iwl_priv *priv =
  219. container_of(work, struct iwl_priv, bt_full_concurrency);
  220. struct iwl_rxon_context *ctx;
  221. mutex_lock(&priv->shrd->mutex);
  222. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  223. goto out;
  224. /* dont send host command if rf-kill is on */
  225. if (!iwl_is_ready_rf(priv->shrd))
  226. goto out;
  227. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  228. priv->bt_full_concurrent ?
  229. "full concurrency" : "3-wire");
  230. /*
  231. * LQ & RXON updated cmds must be sent before BT Config cmd
  232. * to avoid 3-wire collisions
  233. */
  234. for_each_context(priv, ctx) {
  235. iwlagn_set_rxon_chain(priv, ctx);
  236. iwlagn_commit_rxon(priv, ctx);
  237. }
  238. iwlagn_send_advance_bt_config(priv);
  239. out:
  240. mutex_unlock(&priv->shrd->mutex);
  241. }
  242. /**
  243. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  244. *
  245. * This callback is provided in order to send a statistics request.
  246. *
  247. * This timer function is continually reset to execute within
  248. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  249. * was received. We need to ensure we receive the statistics in order
  250. * to update the temperature used for calibrating the TXPOWER.
  251. */
  252. static void iwl_bg_statistics_periodic(unsigned long data)
  253. {
  254. struct iwl_priv *priv = (struct iwl_priv *)data;
  255. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  256. return;
  257. /* dont send host command if rf-kill is on */
  258. if (!iwl_is_ready_rf(priv->shrd))
  259. return;
  260. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  261. }
  262. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  263. u32 start_idx, u32 num_events,
  264. u32 mode)
  265. {
  266. u32 i;
  267. u32 ptr; /* SRAM byte address of log data */
  268. u32 ev, time, data; /* event log data */
  269. unsigned long reg_flags;
  270. if (mode == 0)
  271. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  272. else
  273. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  274. /* Make sure device is powered up for SRAM reads */
  275. spin_lock_irqsave(&bus(priv)->reg_lock, reg_flags);
  276. if (iwl_grab_nic_access(bus(priv))) {
  277. spin_unlock_irqrestore(&bus(priv)->reg_lock, reg_flags);
  278. return;
  279. }
  280. /* Set starting address; reads will auto-increment */
  281. iwl_write32(bus(priv), HBUS_TARG_MEM_RADDR, ptr);
  282. rmb();
  283. /*
  284. * "time" is actually "data" for mode 0 (no timestamp).
  285. * place event id # at far right for easier visual parsing.
  286. */
  287. for (i = 0; i < num_events; i++) {
  288. ev = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  289. time = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  290. if (mode == 0) {
  291. trace_iwlwifi_dev_ucode_cont_event(priv,
  292. 0, time, ev);
  293. } else {
  294. data = iwl_read32(bus(priv), HBUS_TARG_MEM_RDAT);
  295. trace_iwlwifi_dev_ucode_cont_event(priv,
  296. time, data, ev);
  297. }
  298. }
  299. /* Allow device to power down */
  300. iwl_release_nic_access(bus(priv));
  301. spin_unlock_irqrestore(&bus(priv)->reg_lock, reg_flags);
  302. }
  303. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  304. {
  305. u32 capacity; /* event log capacity in # entries */
  306. u32 base; /* SRAM byte address of event log header */
  307. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  308. u32 num_wraps; /* # times uCode wrapped to top of log */
  309. u32 next_entry; /* index of next entry to be written by uCode */
  310. base = priv->shrd->device_pointers.error_event_table;
  311. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  312. capacity = iwl_read_targ_mem(bus(priv), base);
  313. num_wraps = iwl_read_targ_mem(bus(priv),
  314. base + (2 * sizeof(u32)));
  315. mode = iwl_read_targ_mem(bus(priv), base + (1 * sizeof(u32)));
  316. next_entry = iwl_read_targ_mem(bus(priv),
  317. base + (3 * sizeof(u32)));
  318. } else
  319. return;
  320. if (num_wraps == priv->event_log.num_wraps) {
  321. iwl_print_cont_event_trace(priv,
  322. base, priv->event_log.next_entry,
  323. next_entry - priv->event_log.next_entry,
  324. mode);
  325. priv->event_log.non_wraps_count++;
  326. } else {
  327. if ((num_wraps - priv->event_log.num_wraps) > 1)
  328. priv->event_log.wraps_more_count++;
  329. else
  330. priv->event_log.wraps_once_count++;
  331. trace_iwlwifi_dev_ucode_wrap_event(priv,
  332. num_wraps - priv->event_log.num_wraps,
  333. next_entry, priv->event_log.next_entry);
  334. if (next_entry < priv->event_log.next_entry) {
  335. iwl_print_cont_event_trace(priv, base,
  336. priv->event_log.next_entry,
  337. capacity - priv->event_log.next_entry,
  338. mode);
  339. iwl_print_cont_event_trace(priv, base, 0,
  340. next_entry, mode);
  341. } else {
  342. iwl_print_cont_event_trace(priv, base,
  343. next_entry, capacity - next_entry,
  344. mode);
  345. iwl_print_cont_event_trace(priv, base, 0,
  346. next_entry, mode);
  347. }
  348. }
  349. priv->event_log.num_wraps = num_wraps;
  350. priv->event_log.next_entry = next_entry;
  351. }
  352. /**
  353. * iwl_bg_ucode_trace - Timer callback to log ucode event
  354. *
  355. * The timer is continually set to execute every
  356. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  357. * this function is to perform continuous uCode event logging operation
  358. * if enabled
  359. */
  360. static void iwl_bg_ucode_trace(unsigned long data)
  361. {
  362. struct iwl_priv *priv = (struct iwl_priv *)data;
  363. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  364. return;
  365. if (priv->event_log.ucode_trace) {
  366. iwl_continuous_event_trace(priv);
  367. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  368. mod_timer(&priv->ucode_trace,
  369. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  370. }
  371. }
  372. static void iwl_bg_tx_flush(struct work_struct *work)
  373. {
  374. struct iwl_priv *priv =
  375. container_of(work, struct iwl_priv, tx_flush);
  376. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  377. return;
  378. /* do nothing if rf-kill is on */
  379. if (!iwl_is_ready_rf(priv->shrd))
  380. return;
  381. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  382. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  383. }
  384. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  385. {
  386. int i;
  387. /*
  388. * The default context is always valid,
  389. * the PAN context depends on uCode.
  390. */
  391. priv->shrd->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  392. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  393. priv->shrd->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  394. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  395. priv->contexts[i].ctxid = i;
  396. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  397. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  398. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  399. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  400. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  401. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  402. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  403. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  404. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  405. BIT(NL80211_IFTYPE_ADHOC);
  406. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  407. BIT(NL80211_IFTYPE_STATION);
  408. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  409. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  410. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  411. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  412. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  413. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  414. REPLY_WIPAN_RXON_TIMING;
  415. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  416. REPLY_WIPAN_RXON_ASSOC;
  417. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  418. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  419. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  420. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  421. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  422. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  423. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  424. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  425. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  426. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  427. BIT(NL80211_IFTYPE_P2P_GO);
  428. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  429. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  430. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  431. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  432. }
  433. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
  434. #define UCODE_EXPERIMENTAL_INDEX 100
  435. #define UCODE_EXPERIMENTAL_TAG "exp"
  436. static int __must_check iwl_request_firmware(struct iwl_priv *priv, bool first)
  437. {
  438. const char *name_pre = cfg(priv)->fw_name_pre;
  439. char tag[8];
  440. if (first) {
  441. #ifdef CONFIG_IWLWIFI_DEBUG_EXPERIMENTAL_UCODE
  442. priv->fw_index = UCODE_EXPERIMENTAL_INDEX;
  443. strcpy(tag, UCODE_EXPERIMENTAL_TAG);
  444. } else if (priv->fw_index == UCODE_EXPERIMENTAL_INDEX) {
  445. #endif
  446. priv->fw_index = cfg(priv)->ucode_api_max;
  447. sprintf(tag, "%d", priv->fw_index);
  448. } else {
  449. priv->fw_index--;
  450. sprintf(tag, "%d", priv->fw_index);
  451. }
  452. if (priv->fw_index < cfg(priv)->ucode_api_min) {
  453. IWL_ERR(priv, "no suitable firmware found!\n");
  454. return -ENOENT;
  455. }
  456. sprintf(priv->firmware_name, "%s%s%s", name_pre, tag, ".ucode");
  457. IWL_DEBUG_INFO(priv, "attempting to load firmware %s'%s'\n",
  458. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  459. ? "EXPERIMENTAL " : "",
  460. priv->firmware_name);
  461. return request_firmware_nowait(THIS_MODULE, 1, priv->firmware_name,
  462. bus(priv)->dev,
  463. GFP_KERNEL, priv, iwl_ucode_callback);
  464. }
  465. struct iwlagn_firmware_pieces {
  466. const void *inst, *data, *init, *init_data, *wowlan_inst, *wowlan_data;
  467. size_t inst_size, data_size, init_size, init_data_size,
  468. wowlan_inst_size, wowlan_data_size;
  469. u32 build;
  470. u32 init_evtlog_ptr, init_evtlog_size, init_errlog_ptr;
  471. u32 inst_evtlog_ptr, inst_evtlog_size, inst_errlog_ptr;
  472. };
  473. static int iwlagn_load_legacy_firmware(struct iwl_priv *priv,
  474. const struct firmware *ucode_raw,
  475. struct iwlagn_firmware_pieces *pieces)
  476. {
  477. struct iwl_ucode_header *ucode = (void *)ucode_raw->data;
  478. u32 api_ver, hdr_size;
  479. const u8 *src;
  480. priv->ucode_ver = le32_to_cpu(ucode->ver);
  481. api_ver = IWL_UCODE_API(priv->ucode_ver);
  482. switch (api_ver) {
  483. default:
  484. hdr_size = 28;
  485. if (ucode_raw->size < hdr_size) {
  486. IWL_ERR(priv, "File size too small!\n");
  487. return -EINVAL;
  488. }
  489. pieces->build = le32_to_cpu(ucode->u.v2.build);
  490. pieces->inst_size = le32_to_cpu(ucode->u.v2.inst_size);
  491. pieces->data_size = le32_to_cpu(ucode->u.v2.data_size);
  492. pieces->init_size = le32_to_cpu(ucode->u.v2.init_size);
  493. pieces->init_data_size = le32_to_cpu(ucode->u.v2.init_data_size);
  494. src = ucode->u.v2.data;
  495. break;
  496. case 0:
  497. case 1:
  498. case 2:
  499. hdr_size = 24;
  500. if (ucode_raw->size < hdr_size) {
  501. IWL_ERR(priv, "File size too small!\n");
  502. return -EINVAL;
  503. }
  504. pieces->build = 0;
  505. pieces->inst_size = le32_to_cpu(ucode->u.v1.inst_size);
  506. pieces->data_size = le32_to_cpu(ucode->u.v1.data_size);
  507. pieces->init_size = le32_to_cpu(ucode->u.v1.init_size);
  508. pieces->init_data_size = le32_to_cpu(ucode->u.v1.init_data_size);
  509. src = ucode->u.v1.data;
  510. break;
  511. }
  512. /* Verify size of file vs. image size info in file's header */
  513. if (ucode_raw->size != hdr_size + pieces->inst_size +
  514. pieces->data_size + pieces->init_size +
  515. pieces->init_data_size) {
  516. IWL_ERR(priv,
  517. "uCode file size %d does not match expected size\n",
  518. (int)ucode_raw->size);
  519. return -EINVAL;
  520. }
  521. pieces->inst = src;
  522. src += pieces->inst_size;
  523. pieces->data = src;
  524. src += pieces->data_size;
  525. pieces->init = src;
  526. src += pieces->init_size;
  527. pieces->init_data = src;
  528. src += pieces->init_data_size;
  529. return 0;
  530. }
  531. static int iwlagn_load_firmware(struct iwl_priv *priv,
  532. const struct firmware *ucode_raw,
  533. struct iwlagn_firmware_pieces *pieces,
  534. struct iwlagn_ucode_capabilities *capa)
  535. {
  536. struct iwl_tlv_ucode_header *ucode = (void *)ucode_raw->data;
  537. struct iwl_ucode_tlv *tlv;
  538. size_t len = ucode_raw->size;
  539. const u8 *data;
  540. int wanted_alternative = iwlagn_mod_params.wanted_ucode_alternative;
  541. int tmp;
  542. u64 alternatives;
  543. u32 tlv_len;
  544. enum iwl_ucode_tlv_type tlv_type;
  545. const u8 *tlv_data;
  546. if (len < sizeof(*ucode)) {
  547. IWL_ERR(priv, "uCode has invalid length: %zd\n", len);
  548. return -EINVAL;
  549. }
  550. if (ucode->magic != cpu_to_le32(IWL_TLV_UCODE_MAGIC)) {
  551. IWL_ERR(priv, "invalid uCode magic: 0X%x\n",
  552. le32_to_cpu(ucode->magic));
  553. return -EINVAL;
  554. }
  555. /*
  556. * Check which alternatives are present, and "downgrade"
  557. * when the chosen alternative is not present, warning
  558. * the user when that happens. Some files may not have
  559. * any alternatives, so don't warn in that case.
  560. */
  561. alternatives = le64_to_cpu(ucode->alternatives);
  562. tmp = wanted_alternative;
  563. if (wanted_alternative > 63)
  564. wanted_alternative = 63;
  565. while (wanted_alternative && !(alternatives & BIT(wanted_alternative)))
  566. wanted_alternative--;
  567. if (wanted_alternative && wanted_alternative != tmp)
  568. IWL_WARN(priv,
  569. "uCode alternative %d not available, choosing %d\n",
  570. tmp, wanted_alternative);
  571. priv->ucode_ver = le32_to_cpu(ucode->ver);
  572. pieces->build = le32_to_cpu(ucode->build);
  573. data = ucode->data;
  574. len -= sizeof(*ucode);
  575. while (len >= sizeof(*tlv)) {
  576. u16 tlv_alt;
  577. len -= sizeof(*tlv);
  578. tlv = (void *)data;
  579. tlv_len = le32_to_cpu(tlv->length);
  580. tlv_type = le16_to_cpu(tlv->type);
  581. tlv_alt = le16_to_cpu(tlv->alternative);
  582. tlv_data = tlv->data;
  583. if (len < tlv_len) {
  584. IWL_ERR(priv, "invalid TLV len: %zd/%u\n",
  585. len, tlv_len);
  586. return -EINVAL;
  587. }
  588. len -= ALIGN(tlv_len, 4);
  589. data += sizeof(*tlv) + ALIGN(tlv_len, 4);
  590. /*
  591. * Alternative 0 is always valid.
  592. *
  593. * Skip alternative TLVs that are not selected.
  594. */
  595. if (tlv_alt != 0 && tlv_alt != wanted_alternative)
  596. continue;
  597. switch (tlv_type) {
  598. case IWL_UCODE_TLV_INST:
  599. pieces->inst = tlv_data;
  600. pieces->inst_size = tlv_len;
  601. break;
  602. case IWL_UCODE_TLV_DATA:
  603. pieces->data = tlv_data;
  604. pieces->data_size = tlv_len;
  605. break;
  606. case IWL_UCODE_TLV_INIT:
  607. pieces->init = tlv_data;
  608. pieces->init_size = tlv_len;
  609. break;
  610. case IWL_UCODE_TLV_INIT_DATA:
  611. pieces->init_data = tlv_data;
  612. pieces->init_data_size = tlv_len;
  613. break;
  614. case IWL_UCODE_TLV_BOOT:
  615. IWL_ERR(priv, "Found unexpected BOOT ucode\n");
  616. break;
  617. case IWL_UCODE_TLV_PROBE_MAX_LEN:
  618. if (tlv_len != sizeof(u32))
  619. goto invalid_tlv_len;
  620. capa->max_probe_length =
  621. le32_to_cpup((__le32 *)tlv_data);
  622. break;
  623. case IWL_UCODE_TLV_PAN:
  624. if (tlv_len)
  625. goto invalid_tlv_len;
  626. capa->flags |= IWL_UCODE_TLV_FLAGS_PAN;
  627. break;
  628. case IWL_UCODE_TLV_FLAGS:
  629. /* must be at least one u32 */
  630. if (tlv_len < sizeof(u32))
  631. goto invalid_tlv_len;
  632. /* and a proper number of u32s */
  633. if (tlv_len % sizeof(u32))
  634. goto invalid_tlv_len;
  635. /*
  636. * This driver only reads the first u32 as
  637. * right now no more features are defined,
  638. * if that changes then either the driver
  639. * will not work with the new firmware, or
  640. * it'll not take advantage of new features.
  641. */
  642. capa->flags = le32_to_cpup((__le32 *)tlv_data);
  643. break;
  644. case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
  645. if (tlv_len != sizeof(u32))
  646. goto invalid_tlv_len;
  647. pieces->init_evtlog_ptr =
  648. le32_to_cpup((__le32 *)tlv_data);
  649. break;
  650. case IWL_UCODE_TLV_INIT_EVTLOG_SIZE:
  651. if (tlv_len != sizeof(u32))
  652. goto invalid_tlv_len;
  653. pieces->init_evtlog_size =
  654. le32_to_cpup((__le32 *)tlv_data);
  655. break;
  656. case IWL_UCODE_TLV_INIT_ERRLOG_PTR:
  657. if (tlv_len != sizeof(u32))
  658. goto invalid_tlv_len;
  659. pieces->init_errlog_ptr =
  660. le32_to_cpup((__le32 *)tlv_data);
  661. break;
  662. case IWL_UCODE_TLV_RUNT_EVTLOG_PTR:
  663. if (tlv_len != sizeof(u32))
  664. goto invalid_tlv_len;
  665. pieces->inst_evtlog_ptr =
  666. le32_to_cpup((__le32 *)tlv_data);
  667. break;
  668. case IWL_UCODE_TLV_RUNT_EVTLOG_SIZE:
  669. if (tlv_len != sizeof(u32))
  670. goto invalid_tlv_len;
  671. pieces->inst_evtlog_size =
  672. le32_to_cpup((__le32 *)tlv_data);
  673. break;
  674. case IWL_UCODE_TLV_RUNT_ERRLOG_PTR:
  675. if (tlv_len != sizeof(u32))
  676. goto invalid_tlv_len;
  677. pieces->inst_errlog_ptr =
  678. le32_to_cpup((__le32 *)tlv_data);
  679. break;
  680. case IWL_UCODE_TLV_ENHANCE_SENS_TBL:
  681. if (tlv_len)
  682. goto invalid_tlv_len;
  683. priv->enhance_sensitivity_table = true;
  684. break;
  685. case IWL_UCODE_TLV_WOWLAN_INST:
  686. pieces->wowlan_inst = tlv_data;
  687. pieces->wowlan_inst_size = tlv_len;
  688. break;
  689. case IWL_UCODE_TLV_WOWLAN_DATA:
  690. pieces->wowlan_data = tlv_data;
  691. pieces->wowlan_data_size = tlv_len;
  692. break;
  693. case IWL_UCODE_TLV_PHY_CALIBRATION_SIZE:
  694. if (tlv_len != sizeof(u32))
  695. goto invalid_tlv_len;
  696. capa->standard_phy_calibration_size =
  697. le32_to_cpup((__le32 *)tlv_data);
  698. break;
  699. default:
  700. IWL_DEBUG_INFO(priv, "unknown TLV: %d\n", tlv_type);
  701. break;
  702. }
  703. }
  704. if (len) {
  705. IWL_ERR(priv, "invalid TLV after parsing: %zd\n", len);
  706. iwl_print_hex_dump(priv, IWL_DL_FW, (u8 *)data, len);
  707. return -EINVAL;
  708. }
  709. return 0;
  710. invalid_tlv_len:
  711. IWL_ERR(priv, "TLV %d has invalid size: %u\n", tlv_type, tlv_len);
  712. iwl_print_hex_dump(priv, IWL_DL_FW, tlv_data, tlv_len);
  713. return -EINVAL;
  714. }
  715. /**
  716. * iwl_ucode_callback - callback when firmware was loaded
  717. *
  718. * If loaded successfully, copies the firmware into buffers
  719. * for the card to fetch (via DMA).
  720. */
  721. static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
  722. {
  723. struct iwl_priv *priv = context;
  724. struct iwl_ucode_header *ucode;
  725. int err;
  726. struct iwlagn_firmware_pieces pieces;
  727. const unsigned int api_max = cfg(priv)->ucode_api_max;
  728. unsigned int api_ok = cfg(priv)->ucode_api_ok;
  729. const unsigned int api_min = cfg(priv)->ucode_api_min;
  730. u32 api_ver;
  731. char buildstr[25];
  732. u32 build;
  733. struct iwlagn_ucode_capabilities ucode_capa = {
  734. .max_probe_length = 200,
  735. .standard_phy_calibration_size =
  736. IWL_DEFAULT_STANDARD_PHY_CALIBRATE_TBL_SIZE,
  737. };
  738. if (!api_ok)
  739. api_ok = api_max;
  740. memset(&pieces, 0, sizeof(pieces));
  741. if (!ucode_raw) {
  742. if (priv->fw_index <= api_ok)
  743. IWL_ERR(priv,
  744. "request for firmware file '%s' failed.\n",
  745. priv->firmware_name);
  746. goto try_again;
  747. }
  748. IWL_DEBUG_INFO(priv, "Loaded firmware file '%s' (%zd bytes).\n",
  749. priv->firmware_name, ucode_raw->size);
  750. /* Make sure that we got at least the API version number */
  751. if (ucode_raw->size < 4) {
  752. IWL_ERR(priv, "File size way too small!\n");
  753. goto try_again;
  754. }
  755. /* Data from ucode file: header followed by uCode images */
  756. ucode = (struct iwl_ucode_header *)ucode_raw->data;
  757. if (ucode->ver)
  758. err = iwlagn_load_legacy_firmware(priv, ucode_raw, &pieces);
  759. else
  760. err = iwlagn_load_firmware(priv, ucode_raw, &pieces,
  761. &ucode_capa);
  762. if (err)
  763. goto try_again;
  764. api_ver = IWL_UCODE_API(priv->ucode_ver);
  765. build = pieces.build;
  766. /*
  767. * api_ver should match the api version forming part of the
  768. * firmware filename ... but we don't check for that and only rely
  769. * on the API version read from firmware header from here on forward
  770. */
  771. /* no api version check required for experimental uCode */
  772. if (priv->fw_index != UCODE_EXPERIMENTAL_INDEX) {
  773. if (api_ver < api_min || api_ver > api_max) {
  774. IWL_ERR(priv,
  775. "Driver unable to support your firmware API. "
  776. "Driver supports v%u, firmware is v%u.\n",
  777. api_max, api_ver);
  778. goto try_again;
  779. }
  780. if (api_ver < api_ok) {
  781. if (api_ok != api_max)
  782. IWL_ERR(priv, "Firmware has old API version, "
  783. "expected v%u through v%u, got v%u.\n",
  784. api_ok, api_max, api_ver);
  785. else
  786. IWL_ERR(priv, "Firmware has old API version, "
  787. "expected v%u, got v%u.\n",
  788. api_max, api_ver);
  789. IWL_ERR(priv, "New firmware can be obtained from "
  790. "http://www.intellinuxwireless.org/.\n");
  791. }
  792. }
  793. if (build)
  794. sprintf(buildstr, " build %u%s", build,
  795. (priv->fw_index == UCODE_EXPERIMENTAL_INDEX)
  796. ? " (EXP)" : "");
  797. else
  798. buildstr[0] = '\0';
  799. IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u%s\n",
  800. IWL_UCODE_MAJOR(priv->ucode_ver),
  801. IWL_UCODE_MINOR(priv->ucode_ver),
  802. IWL_UCODE_API(priv->ucode_ver),
  803. IWL_UCODE_SERIAL(priv->ucode_ver),
  804. buildstr);
  805. snprintf(priv->hw->wiphy->fw_version,
  806. sizeof(priv->hw->wiphy->fw_version),
  807. "%u.%u.%u.%u%s",
  808. IWL_UCODE_MAJOR(priv->ucode_ver),
  809. IWL_UCODE_MINOR(priv->ucode_ver),
  810. IWL_UCODE_API(priv->ucode_ver),
  811. IWL_UCODE_SERIAL(priv->ucode_ver),
  812. buildstr);
  813. /*
  814. * For any of the failures below (before allocating pci memory)
  815. * we will try to load a version with a smaller API -- maybe the
  816. * user just got a corrupted version of the latest API.
  817. */
  818. IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
  819. priv->ucode_ver);
  820. IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %Zd\n",
  821. pieces.inst_size);
  822. IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %Zd\n",
  823. pieces.data_size);
  824. IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %Zd\n",
  825. pieces.init_size);
  826. IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %Zd\n",
  827. pieces.init_data_size);
  828. /* Verify that uCode images will fit in card's SRAM */
  829. if (pieces.inst_size > hw_params(priv).max_inst_size) {
  830. IWL_ERR(priv, "uCode instr len %Zd too large to fit in\n",
  831. pieces.inst_size);
  832. goto try_again;
  833. }
  834. if (pieces.data_size > hw_params(priv).max_data_size) {
  835. IWL_ERR(priv, "uCode data len %Zd too large to fit in\n",
  836. pieces.data_size);
  837. goto try_again;
  838. }
  839. if (pieces.init_size > hw_params(priv).max_inst_size) {
  840. IWL_ERR(priv, "uCode init instr len %Zd too large to fit in\n",
  841. pieces.init_size);
  842. goto try_again;
  843. }
  844. if (pieces.init_data_size > hw_params(priv).max_data_size) {
  845. IWL_ERR(priv, "uCode init data len %Zd too large to fit in\n",
  846. pieces.init_data_size);
  847. goto try_again;
  848. }
  849. /* Allocate ucode buffers for card's bus-master loading ... */
  850. /* Runtime instructions and 2 copies of data:
  851. * 1) unmodified from disk
  852. * 2) backup cache for save/restore during power-downs */
  853. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_rt.code,
  854. pieces.inst, pieces.inst_size))
  855. goto err_pci_alloc;
  856. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_rt.data,
  857. pieces.data, pieces.data_size))
  858. goto err_pci_alloc;
  859. /* Initialization instructions and data */
  860. if (pieces.init_size && pieces.init_data_size) {
  861. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_init.code,
  862. pieces.init, pieces.init_size))
  863. goto err_pci_alloc;
  864. if (iwl_alloc_fw_desc(bus(priv), &trans(priv)->ucode_init.data,
  865. pieces.init_data, pieces.init_data_size))
  866. goto err_pci_alloc;
  867. }
  868. /* WoWLAN instructions and data */
  869. if (pieces.wowlan_inst_size && pieces.wowlan_data_size) {
  870. if (iwl_alloc_fw_desc(bus(priv),
  871. &trans(priv)->ucode_wowlan.code,
  872. pieces.wowlan_inst,
  873. pieces.wowlan_inst_size))
  874. goto err_pci_alloc;
  875. if (iwl_alloc_fw_desc(bus(priv),
  876. &trans(priv)->ucode_wowlan.data,
  877. pieces.wowlan_data,
  878. pieces.wowlan_data_size))
  879. goto err_pci_alloc;
  880. }
  881. /* Now that we can no longer fail, copy information */
  882. /*
  883. * The (size - 16) / 12 formula is based on the information recorded
  884. * for each event, which is of mode 1 (including timestamp) for all
  885. * new microcodes that include this information.
  886. */
  887. priv->init_evtlog_ptr = pieces.init_evtlog_ptr;
  888. if (pieces.init_evtlog_size)
  889. priv->init_evtlog_size = (pieces.init_evtlog_size - 16)/12;
  890. else
  891. priv->init_evtlog_size =
  892. cfg(priv)->base_params->max_event_log_size;
  893. priv->init_errlog_ptr = pieces.init_errlog_ptr;
  894. priv->inst_evtlog_ptr = pieces.inst_evtlog_ptr;
  895. if (pieces.inst_evtlog_size)
  896. priv->inst_evtlog_size = (pieces.inst_evtlog_size - 16)/12;
  897. else
  898. priv->inst_evtlog_size =
  899. cfg(priv)->base_params->max_event_log_size;
  900. priv->inst_errlog_ptr = pieces.inst_errlog_ptr;
  901. #ifndef CONFIG_IWLWIFI_P2P
  902. ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  903. #endif
  904. priv->new_scan_threshold_behaviour =
  905. !!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  906. if (!(cfg(priv)->sku & EEPROM_SKU_CAP_IPAN_ENABLE))
  907. ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  908. /*
  909. * if not PAN, then don't support P2P -- might be a uCode
  910. * packaging bug or due to the eeprom check above
  911. */
  912. if (!(ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN))
  913. ucode_capa.flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  914. if (ucode_capa.flags & IWL_UCODE_TLV_FLAGS_PAN) {
  915. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  916. priv->shrd->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  917. } else {
  918. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  919. priv->shrd->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  920. }
  921. /*
  922. * figure out the offset of chain noise reset and gain commands
  923. * base on the size of standard phy calibration commands table size
  924. */
  925. if (ucode_capa.standard_phy_calibration_size >
  926. IWL_MAX_PHY_CALIBRATE_TBL_SIZE)
  927. ucode_capa.standard_phy_calibration_size =
  928. IWL_MAX_STANDARD_PHY_CALIBRATE_TBL_SIZE;
  929. priv->phy_calib_chain_noise_reset_cmd =
  930. ucode_capa.standard_phy_calibration_size;
  931. priv->phy_calib_chain_noise_gain_cmd =
  932. ucode_capa.standard_phy_calibration_size + 1;
  933. /* initialize all valid contexts */
  934. iwl_init_context(priv, ucode_capa.flags);
  935. /**************************************************
  936. * This is still part of probe() in a sense...
  937. *
  938. * 9. Setup and register with mac80211 and debugfs
  939. **************************************************/
  940. err = iwlagn_mac_setup_register(priv, &ucode_capa);
  941. if (err)
  942. goto out_unbind;
  943. err = iwl_dbgfs_register(priv, DRV_NAME);
  944. if (err)
  945. IWL_ERR(priv, "failed to create debugfs files. Ignoring error: %d\n", err);
  946. /* We have our copies now, allow OS release its copies */
  947. release_firmware(ucode_raw);
  948. complete(&priv->firmware_loading_complete);
  949. return;
  950. try_again:
  951. /* try next, if any */
  952. if (iwl_request_firmware(priv, false))
  953. goto out_unbind;
  954. release_firmware(ucode_raw);
  955. return;
  956. err_pci_alloc:
  957. IWL_ERR(priv, "failed to allocate pci memory\n");
  958. iwl_dealloc_ucode(trans(priv));
  959. out_unbind:
  960. complete(&priv->firmware_loading_complete);
  961. device_release_driver(bus(priv)->dev);
  962. release_firmware(ucode_raw);
  963. }
  964. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  965. {
  966. struct iwl_ct_kill_config cmd;
  967. struct iwl_ct_kill_throttling_config adv_cmd;
  968. unsigned long flags;
  969. int ret = 0;
  970. spin_lock_irqsave(&priv->shrd->lock, flags);
  971. iwl_write32(bus(priv), CSR_UCODE_DRV_GP1_CLR,
  972. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  973. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  974. priv->thermal_throttle.ct_kill_toggle = false;
  975. if (cfg(priv)->base_params->support_ct_kill_exit) {
  976. adv_cmd.critical_temperature_enter =
  977. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  978. adv_cmd.critical_temperature_exit =
  979. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  980. ret = iwl_trans_send_cmd_pdu(trans(priv),
  981. REPLY_CT_KILL_CONFIG_CMD,
  982. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  983. if (ret)
  984. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  985. else
  986. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  987. "succeeded, critical temperature enter is %d,"
  988. "exit is %d\n",
  989. hw_params(priv).ct_kill_threshold,
  990. hw_params(priv).ct_kill_exit_threshold);
  991. } else {
  992. cmd.critical_temperature_R =
  993. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  994. ret = iwl_trans_send_cmd_pdu(trans(priv),
  995. REPLY_CT_KILL_CONFIG_CMD,
  996. CMD_SYNC, sizeof(cmd), &cmd);
  997. if (ret)
  998. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  999. else
  1000. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  1001. "succeeded, "
  1002. "critical temperature is %d\n",
  1003. hw_params(priv).ct_kill_threshold);
  1004. }
  1005. }
  1006. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  1007. {
  1008. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  1009. struct iwl_host_cmd cmd = {
  1010. .id = CALIBRATION_CFG_CMD,
  1011. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  1012. .data = { &calib_cfg_cmd, },
  1013. };
  1014. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  1015. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  1016. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  1017. return iwl_trans_send_cmd(trans(priv), &cmd);
  1018. }
  1019. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  1020. {
  1021. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  1022. .valid = cpu_to_le32(valid_tx_ant),
  1023. };
  1024. if (IWL_UCODE_API(priv->ucode_ver) > 1) {
  1025. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  1026. return iwl_trans_send_cmd_pdu(trans(priv),
  1027. TX_ANT_CONFIGURATION_CMD,
  1028. CMD_SYNC,
  1029. sizeof(struct iwl_tx_ant_config_cmd),
  1030. &tx_ant_cmd);
  1031. } else {
  1032. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  1033. return -EOPNOTSUPP;
  1034. }
  1035. }
  1036. /**
  1037. * iwl_alive_start - called after REPLY_ALIVE notification received
  1038. * from protocol/runtime uCode (initialization uCode's
  1039. * Alive gets handled by iwl_init_alive_start()).
  1040. */
  1041. int iwl_alive_start(struct iwl_priv *priv)
  1042. {
  1043. int ret = 0;
  1044. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  1045. /*TODO: this should go to the transport layer */
  1046. iwl_reset_ict(trans(priv));
  1047. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  1048. /* After the ALIVE response, we can send host commands to the uCode */
  1049. set_bit(STATUS_ALIVE, &priv->shrd->status);
  1050. /* Enable watchdog to monitor the driver tx queues */
  1051. iwl_setup_watchdog(priv);
  1052. if (iwl_is_rfkill(priv->shrd))
  1053. return -ERFKILL;
  1054. /* download priority table before any calibration request */
  1055. if (cfg(priv)->bt_params &&
  1056. cfg(priv)->bt_params->advanced_bt_coexist) {
  1057. /* Configure Bluetooth device coexistence support */
  1058. if (cfg(priv)->bt_params->bt_sco_disable)
  1059. priv->bt_enable_pspoll = false;
  1060. else
  1061. priv->bt_enable_pspoll = true;
  1062. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1063. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1064. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1065. iwlagn_send_advance_bt_config(priv);
  1066. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  1067. priv->cur_rssi_ctx = NULL;
  1068. iwl_send_prio_tbl(trans(priv));
  1069. /* FIXME: w/a to force change uCode BT state machine */
  1070. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_OPEN,
  1071. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1072. if (ret)
  1073. return ret;
  1074. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_CLOSE,
  1075. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  1076. if (ret)
  1077. return ret;
  1078. } else {
  1079. /*
  1080. * default is 2-wire BT coexexistence support
  1081. */
  1082. iwl_send_bt_config(priv);
  1083. }
  1084. /*
  1085. * Perform runtime calibrations, including DC calibration.
  1086. */
  1087. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  1088. ieee80211_wake_queues(priv->hw);
  1089. priv->active_rate = IWL_RATES_MASK;
  1090. /* Configure Tx antenna selection based on H/W config */
  1091. iwlagn_send_tx_ant_config(priv, cfg(priv)->valid_tx_ant);
  1092. if (iwl_is_associated_ctx(ctx) && !priv->shrd->wowlan) {
  1093. struct iwl_rxon_cmd *active_rxon =
  1094. (struct iwl_rxon_cmd *)&ctx->active;
  1095. /* apply any changes in staging */
  1096. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1097. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1098. } else {
  1099. struct iwl_rxon_context *tmp;
  1100. /* Initialize our rx_config data */
  1101. for_each_context(priv, tmp)
  1102. iwl_connection_init_rx_config(priv, tmp);
  1103. iwlagn_set_rxon_chain(priv, ctx);
  1104. }
  1105. if (!priv->shrd->wowlan) {
  1106. /* WoWLAN ucode will not reply in the same way, skip it */
  1107. iwl_reset_run_time_calib(priv);
  1108. }
  1109. set_bit(STATUS_READY, &priv->shrd->status);
  1110. /* Configure the adapter for unassociated operation */
  1111. ret = iwlagn_commit_rxon(priv, ctx);
  1112. if (ret)
  1113. return ret;
  1114. /* At this point, the NIC is initialized and operational */
  1115. iwl_rf_kill_ct_config(priv);
  1116. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1117. return iwl_power_update_mode(priv, true);
  1118. }
  1119. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1120. void __iwl_down(struct iwl_priv *priv)
  1121. {
  1122. int exit_pending;
  1123. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1124. iwl_scan_cancel_timeout(priv, 200);
  1125. /*
  1126. * If active, scanning won't cancel it, so say it expired.
  1127. * No race since we hold the mutex here and a new one
  1128. * can't come in at this time.
  1129. */
  1130. ieee80211_remain_on_channel_expired(priv->hw);
  1131. exit_pending =
  1132. test_and_set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1133. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1134. * to prevent rearm timer */
  1135. del_timer_sync(&priv->watchdog);
  1136. iwl_clear_ucode_stations(priv, NULL);
  1137. iwl_dealloc_bcast_stations(priv);
  1138. iwl_clear_driver_stations(priv);
  1139. /* reset BT coex data */
  1140. priv->bt_status = 0;
  1141. priv->cur_rssi_ctx = NULL;
  1142. priv->bt_is_sco = 0;
  1143. if (cfg(priv)->bt_params)
  1144. priv->bt_traffic_load =
  1145. cfg(priv)->bt_params->bt_init_traffic_load;
  1146. else
  1147. priv->bt_traffic_load = 0;
  1148. priv->bt_full_concurrent = false;
  1149. priv->bt_ci_compliance = 0;
  1150. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1151. * exiting the module */
  1152. if (!exit_pending)
  1153. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1154. if (priv->mac80211_registered)
  1155. ieee80211_stop_queues(priv->hw);
  1156. iwl_trans_stop_device(trans(priv));
  1157. /* Clear out all status bits but a few that are stable across reset */
  1158. priv->shrd->status &=
  1159. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status) <<
  1160. STATUS_RF_KILL_HW |
  1161. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) <<
  1162. STATUS_GEO_CONFIGURED |
  1163. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  1164. STATUS_FW_ERROR |
  1165. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) <<
  1166. STATUS_EXIT_PENDING;
  1167. dev_kfree_skb(priv->beacon_skb);
  1168. priv->beacon_skb = NULL;
  1169. }
  1170. void iwl_down(struct iwl_priv *priv)
  1171. {
  1172. mutex_lock(&priv->shrd->mutex);
  1173. __iwl_down(priv);
  1174. mutex_unlock(&priv->shrd->mutex);
  1175. iwl_cancel_deferred_work(priv);
  1176. }
  1177. /*****************************************************************************
  1178. *
  1179. * Workqueue callbacks
  1180. *
  1181. *****************************************************************************/
  1182. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  1183. {
  1184. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1185. run_time_calib_work);
  1186. mutex_lock(&priv->shrd->mutex);
  1187. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  1188. test_bit(STATUS_SCANNING, &priv->shrd->status)) {
  1189. mutex_unlock(&priv->shrd->mutex);
  1190. return;
  1191. }
  1192. if (priv->start_calib) {
  1193. iwl_chain_noise_calibration(priv);
  1194. iwl_sensitivity_calibration(priv);
  1195. }
  1196. mutex_unlock(&priv->shrd->mutex);
  1197. }
  1198. void iwlagn_prepare_restart(struct iwl_priv *priv)
  1199. {
  1200. struct iwl_rxon_context *ctx;
  1201. bool bt_full_concurrent;
  1202. u8 bt_ci_compliance;
  1203. u8 bt_load;
  1204. u8 bt_status;
  1205. bool bt_is_sco;
  1206. lockdep_assert_held(&priv->shrd->mutex);
  1207. for_each_context(priv, ctx)
  1208. ctx->vif = NULL;
  1209. priv->is_open = 0;
  1210. /*
  1211. * __iwl_down() will clear the BT status variables,
  1212. * which is correct, but when we restart we really
  1213. * want to keep them so restore them afterwards.
  1214. *
  1215. * The restart process will later pick them up and
  1216. * re-configure the hw when we reconfigure the BT
  1217. * command.
  1218. */
  1219. bt_full_concurrent = priv->bt_full_concurrent;
  1220. bt_ci_compliance = priv->bt_ci_compliance;
  1221. bt_load = priv->bt_traffic_load;
  1222. bt_status = priv->bt_status;
  1223. bt_is_sco = priv->bt_is_sco;
  1224. __iwl_down(priv);
  1225. priv->bt_full_concurrent = bt_full_concurrent;
  1226. priv->bt_ci_compliance = bt_ci_compliance;
  1227. priv->bt_traffic_load = bt_load;
  1228. priv->bt_status = bt_status;
  1229. priv->bt_is_sco = bt_is_sco;
  1230. }
  1231. static void iwl_bg_restart(struct work_struct *data)
  1232. {
  1233. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  1234. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1235. return;
  1236. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  1237. mutex_lock(&priv->shrd->mutex);
  1238. iwlagn_prepare_restart(priv);
  1239. mutex_unlock(&priv->shrd->mutex);
  1240. iwl_cancel_deferred_work(priv);
  1241. ieee80211_restart_hw(priv->hw);
  1242. } else {
  1243. WARN_ON(1);
  1244. }
  1245. }
  1246. void iwlagn_disable_roc(struct iwl_priv *priv)
  1247. {
  1248. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  1249. lockdep_assert_held(&priv->shrd->mutex);
  1250. if (!priv->hw_roc_setup)
  1251. return;
  1252. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  1253. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1254. priv->hw_roc_channel = NULL;
  1255. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  1256. iwlagn_commit_rxon(priv, ctx);
  1257. ctx->is_active = false;
  1258. priv->hw_roc_setup = false;
  1259. }
  1260. static void iwlagn_disable_roc_work(struct work_struct *work)
  1261. {
  1262. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1263. hw_roc_disable_work.work);
  1264. mutex_lock(&priv->shrd->mutex);
  1265. iwlagn_disable_roc(priv);
  1266. mutex_unlock(&priv->shrd->mutex);
  1267. }
  1268. /*****************************************************************************
  1269. *
  1270. * driver setup and teardown
  1271. *
  1272. *****************************************************************************/
  1273. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  1274. {
  1275. priv->shrd->workqueue = create_singlethread_workqueue(DRV_NAME);
  1276. init_waitqueue_head(&priv->shrd->wait_command_queue);
  1277. INIT_WORK(&priv->restart, iwl_bg_restart);
  1278. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  1279. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  1280. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  1281. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  1282. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  1283. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  1284. iwlagn_disable_roc_work);
  1285. iwl_setup_scan_deferred_work(priv);
  1286. if (cfg(priv)->lib->bt_setup_deferred_work)
  1287. cfg(priv)->lib->bt_setup_deferred_work(priv);
  1288. init_timer(&priv->statistics_periodic);
  1289. priv->statistics_periodic.data = (unsigned long)priv;
  1290. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  1291. init_timer(&priv->ucode_trace);
  1292. priv->ucode_trace.data = (unsigned long)priv;
  1293. priv->ucode_trace.function = iwl_bg_ucode_trace;
  1294. init_timer(&priv->watchdog);
  1295. priv->watchdog.data = (unsigned long)priv;
  1296. priv->watchdog.function = iwl_bg_watchdog;
  1297. }
  1298. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  1299. {
  1300. if (cfg(priv)->lib->cancel_deferred_work)
  1301. cfg(priv)->lib->cancel_deferred_work(priv);
  1302. cancel_work_sync(&priv->run_time_calib_work);
  1303. cancel_work_sync(&priv->beacon_update);
  1304. iwl_cancel_scan_deferred_work(priv);
  1305. cancel_work_sync(&priv->bt_full_concurrency);
  1306. cancel_work_sync(&priv->bt_runtime_config);
  1307. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1308. del_timer_sync(&priv->statistics_periodic);
  1309. del_timer_sync(&priv->ucode_trace);
  1310. }
  1311. static void iwl_init_hw_rates(struct iwl_priv *priv,
  1312. struct ieee80211_rate *rates)
  1313. {
  1314. int i;
  1315. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  1316. rates[i].bitrate = iwl_rates[i].ieee * 5;
  1317. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  1318. rates[i].hw_value_short = i;
  1319. rates[i].flags = 0;
  1320. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  1321. /*
  1322. * If CCK != 1M then set short preamble rate flag.
  1323. */
  1324. rates[i].flags |=
  1325. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  1326. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  1327. }
  1328. }
  1329. }
  1330. static int iwl_init_drv(struct iwl_priv *priv)
  1331. {
  1332. int ret;
  1333. spin_lock_init(&priv->shrd->sta_lock);
  1334. mutex_init(&priv->shrd->mutex);
  1335. INIT_LIST_HEAD(&trans(priv)->calib_results);
  1336. priv->ieee_channels = NULL;
  1337. priv->ieee_rates = NULL;
  1338. priv->band = IEEE80211_BAND_2GHZ;
  1339. priv->iw_mode = NL80211_IFTYPE_STATION;
  1340. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  1341. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  1342. priv->agg_tids_count = 0;
  1343. /* initialize force reset */
  1344. priv->force_reset[IWL_RF_RESET].reset_duration =
  1345. IWL_DELAY_NEXT_FORCE_RF_RESET;
  1346. priv->force_reset[IWL_FW_RESET].reset_duration =
  1347. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  1348. priv->rx_statistics_jiffies = jiffies;
  1349. /* Choose which receivers/antennas to use */
  1350. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  1351. iwl_init_scan_params(priv);
  1352. /* init bt coex */
  1353. if (cfg(priv)->bt_params &&
  1354. cfg(priv)->bt_params->advanced_bt_coexist) {
  1355. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1356. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1357. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1358. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  1359. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  1360. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  1361. }
  1362. ret = iwl_init_channel_map(priv);
  1363. if (ret) {
  1364. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  1365. goto err;
  1366. }
  1367. ret = iwl_init_geos(priv);
  1368. if (ret) {
  1369. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  1370. goto err_free_channel_map;
  1371. }
  1372. iwl_init_hw_rates(priv, priv->ieee_rates);
  1373. return 0;
  1374. err_free_channel_map:
  1375. iwl_free_channel_map(priv);
  1376. err:
  1377. return ret;
  1378. }
  1379. static void iwl_uninit_drv(struct iwl_priv *priv)
  1380. {
  1381. iwl_free_geos(priv);
  1382. iwl_free_channel_map(priv);
  1383. if (priv->tx_cmd_pool)
  1384. kmem_cache_destroy(priv->tx_cmd_pool);
  1385. kfree(priv->scan_cmd);
  1386. kfree(priv->beacon_cmd);
  1387. kfree(rcu_dereference_raw(priv->noa_data));
  1388. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1389. kfree(priv->wowlan_sram);
  1390. #endif
  1391. }
  1392. static u32 iwl_hw_detect(struct iwl_priv *priv)
  1393. {
  1394. return iwl_read32(bus(priv), CSR_HW_REV);
  1395. }
  1396. /* Size of one Rx buffer in host DRAM */
  1397. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  1398. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  1399. static int iwl_set_hw_params(struct iwl_priv *priv)
  1400. {
  1401. if (iwlagn_mod_params.amsdu_size_8K)
  1402. hw_params(priv).rx_page_order =
  1403. get_order(IWL_RX_BUF_SIZE_8K);
  1404. else
  1405. hw_params(priv).rx_page_order =
  1406. get_order(IWL_RX_BUF_SIZE_4K);
  1407. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  1408. cfg(priv)->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  1409. hw_params(priv).num_ampdu_queues =
  1410. cfg(priv)->base_params->num_of_ampdu_queues;
  1411. hw_params(priv).shadow_reg_enable =
  1412. cfg(priv)->base_params->shadow_reg_enable;
  1413. hw_params(priv).sku = cfg(priv)->sku;
  1414. hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
  1415. /* Device-specific setup */
  1416. return cfg(priv)->lib->set_hw_params(priv);
  1417. }
  1418. static void iwl_debug_config(struct iwl_priv *priv)
  1419. {
  1420. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  1421. #ifdef CONFIG_IWLWIFI_DEBUG
  1422. "enabled\n");
  1423. #else
  1424. "disabled\n");
  1425. #endif
  1426. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  1427. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1428. "enabled\n");
  1429. #else
  1430. "disabled\n");
  1431. #endif
  1432. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  1433. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  1434. "enabled\n");
  1435. #else
  1436. "disabled\n");
  1437. #endif
  1438. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  1439. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  1440. "enabled\n");
  1441. #else
  1442. "disabled\n");
  1443. #endif
  1444. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_P2P "
  1445. #ifdef CONFIG_IWLWIFI_P2P
  1446. "enabled\n");
  1447. #else
  1448. "disabled\n");
  1449. #endif
  1450. }
  1451. int iwl_probe(struct iwl_bus *bus, const struct iwl_trans_ops *trans_ops,
  1452. struct iwl_cfg *cfg)
  1453. {
  1454. int err = 0;
  1455. struct iwl_priv *priv;
  1456. struct ieee80211_hw *hw;
  1457. u16 num_mac;
  1458. u32 hw_rev;
  1459. /************************
  1460. * 1. Allocating HW data
  1461. ************************/
  1462. hw = iwl_alloc_all();
  1463. if (!hw) {
  1464. pr_err("%s: Cannot allocate network device\n", cfg->name);
  1465. err = -ENOMEM;
  1466. goto out;
  1467. }
  1468. priv = hw->priv;
  1469. priv->shrd = &priv->_shrd;
  1470. bus->shrd = priv->shrd;
  1471. priv->shrd->bus = bus;
  1472. priv->shrd->priv = priv;
  1473. priv->shrd->trans = trans_ops->alloc(priv->shrd);
  1474. if (priv->shrd->trans == NULL) {
  1475. err = -ENOMEM;
  1476. goto out_free_traffic_mem;
  1477. }
  1478. /* At this point both hw and priv are allocated. */
  1479. SET_IEEE80211_DEV(hw, bus(priv)->dev);
  1480. /* what debugging capabilities we have */
  1481. iwl_debug_config(priv);
  1482. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1483. cfg(priv) = cfg;
  1484. /* is antenna coupling more than 35dB ? */
  1485. priv->bt_ant_couple_ok =
  1486. (iwlagn_mod_params.ant_coupling >
  1487. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1488. true : false;
  1489. /* enable/disable bt channel inhibition */
  1490. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1491. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1492. (priv->bt_ch_announce) ? "On" : "Off");
  1493. if (iwl_alloc_traffic_mem(priv))
  1494. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1495. /* these spin locks will be used in apm_ops.init and EEPROM access
  1496. * we should init now
  1497. */
  1498. spin_lock_init(&bus(priv)->reg_lock);
  1499. spin_lock_init(&priv->shrd->lock);
  1500. /*
  1501. * stop and reset the on-board processor just in case it is in a
  1502. * strange state ... like being left stranded by a primary kernel
  1503. * and this is now the kdump kernel trying to start up
  1504. */
  1505. iwl_write32(bus(priv), CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1506. /***********************
  1507. * 3. Read REV register
  1508. ***********************/
  1509. hw_rev = iwl_hw_detect(priv);
  1510. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1511. cfg(priv)->name, hw_rev);
  1512. err = iwl_trans_request_irq(trans(priv));
  1513. if (err)
  1514. goto out_free_trans;
  1515. if (iwl_trans_prepare_card_hw(trans(priv))) {
  1516. err = -EIO;
  1517. IWL_WARN(priv, "Failed, HW not ready\n");
  1518. goto out_free_trans;
  1519. }
  1520. /*****************
  1521. * 4. Read EEPROM
  1522. *****************/
  1523. /* Read the EEPROM */
  1524. err = iwl_eeprom_init(priv, hw_rev);
  1525. if (err) {
  1526. IWL_ERR(priv, "Unable to init EEPROM\n");
  1527. goto out_free_trans;
  1528. }
  1529. err = iwl_eeprom_check_version(priv);
  1530. if (err)
  1531. goto out_free_eeprom;
  1532. err = iwl_eeprom_check_sku(priv);
  1533. if (err)
  1534. goto out_free_eeprom;
  1535. /* extract MAC Address */
  1536. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1537. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1538. priv->hw->wiphy->addresses = priv->addresses;
  1539. priv->hw->wiphy->n_addresses = 1;
  1540. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1541. if (num_mac > 1) {
  1542. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1543. ETH_ALEN);
  1544. priv->addresses[1].addr[5]++;
  1545. priv->hw->wiphy->n_addresses++;
  1546. }
  1547. /************************
  1548. * 5. Setup HW constants
  1549. ************************/
  1550. if (iwl_set_hw_params(priv)) {
  1551. err = -ENOENT;
  1552. IWL_ERR(priv, "failed to set hw parameters\n");
  1553. goto out_free_eeprom;
  1554. }
  1555. /*******************
  1556. * 6. Setup priv
  1557. *******************/
  1558. err = iwl_init_drv(priv);
  1559. if (err)
  1560. goto out_free_eeprom;
  1561. /* At this point both hw and priv are initialized. */
  1562. /********************
  1563. * 7. Setup services
  1564. ********************/
  1565. iwl_setup_deferred_work(priv);
  1566. iwl_setup_rx_handlers(priv);
  1567. iwl_testmode_init(priv);
  1568. /*********************************************
  1569. * 8. Enable interrupts
  1570. *********************************************/
  1571. iwl_enable_rfkill_int(priv);
  1572. /* If platform's RF_KILL switch is NOT set to KILL */
  1573. if (iwl_read32(bus(priv),
  1574. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1575. clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  1576. else
  1577. set_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  1578. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  1579. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  1580. iwl_power_initialize(priv);
  1581. iwl_tt_initialize(priv);
  1582. init_completion(&priv->firmware_loading_complete);
  1583. err = iwl_request_firmware(priv, true);
  1584. if (err)
  1585. goto out_destroy_workqueue;
  1586. return 0;
  1587. out_destroy_workqueue:
  1588. destroy_workqueue(priv->shrd->workqueue);
  1589. priv->shrd->workqueue = NULL;
  1590. iwl_uninit_drv(priv);
  1591. out_free_eeprom:
  1592. iwl_eeprom_free(priv->shrd);
  1593. out_free_trans:
  1594. iwl_trans_free(trans(priv));
  1595. out_free_traffic_mem:
  1596. iwl_free_traffic_mem(priv);
  1597. ieee80211_free_hw(priv->hw);
  1598. out:
  1599. return err;
  1600. }
  1601. void __devexit iwl_remove(struct iwl_priv * priv)
  1602. {
  1603. wait_for_completion(&priv->firmware_loading_complete);
  1604. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1605. iwl_dbgfs_unregister(priv);
  1606. /* ieee80211_unregister_hw call wil cause iwlagn_mac_stop to
  1607. * to be called and iwl_down since we are removing the device
  1608. * we need to set STATUS_EXIT_PENDING bit.
  1609. */
  1610. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1611. iwl_testmode_cleanup(priv);
  1612. iwlagn_mac_unregister(priv);
  1613. iwl_tt_exit(priv);
  1614. /*This will stop the queues, move the device to low power state */
  1615. iwl_trans_stop_device(trans(priv));
  1616. iwl_dealloc_ucode(trans(priv));
  1617. iwl_eeprom_free(priv->shrd);
  1618. /*netif_stop_queue(dev); */
  1619. flush_workqueue(priv->shrd->workqueue);
  1620. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1621. * priv->shrd->workqueue... so we can't take down the workqueue
  1622. * until now... */
  1623. destroy_workqueue(priv->shrd->workqueue);
  1624. priv->shrd->workqueue = NULL;
  1625. iwl_free_traffic_mem(priv);
  1626. iwl_trans_free(trans(priv));
  1627. iwl_uninit_drv(priv);
  1628. dev_kfree_skb(priv->beacon_skb);
  1629. ieee80211_free_hw(priv->hw);
  1630. }
  1631. /*****************************************************************************
  1632. *
  1633. * driver and module entry point
  1634. *
  1635. *****************************************************************************/
  1636. static int __init iwl_init(void)
  1637. {
  1638. int ret;
  1639. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1640. pr_info(DRV_COPYRIGHT "\n");
  1641. ret = iwlagn_rate_control_register();
  1642. if (ret) {
  1643. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1644. return ret;
  1645. }
  1646. ret = iwl_pci_register_driver();
  1647. if (ret)
  1648. goto error_register;
  1649. return ret;
  1650. error_register:
  1651. iwlagn_rate_control_unregister();
  1652. return ret;
  1653. }
  1654. static void __exit iwl_exit(void)
  1655. {
  1656. iwl_pci_unregister_driver();
  1657. iwlagn_rate_control_unregister();
  1658. }
  1659. module_exit(iwl_exit);
  1660. module_init(iwl_init);
  1661. #ifdef CONFIG_IWLWIFI_DEBUG
  1662. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1663. S_IRUGO | S_IWUSR);
  1664. MODULE_PARM_DESC(debug, "debug output mask");
  1665. #endif
  1666. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1667. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1668. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  1669. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  1670. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  1671. MODULE_PARM_DESC(11n_disable,
  1672. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1673. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1674. int, S_IRUGO);
  1675. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1676. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1677. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1678. module_param_named(ucode_alternative,
  1679. iwlagn_mod_params.wanted_ucode_alternative,
  1680. int, S_IRUGO);
  1681. MODULE_PARM_DESC(ucode_alternative,
  1682. "specify ucode alternative to use from ucode file");
  1683. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1684. int, S_IRUGO);
  1685. MODULE_PARM_DESC(antenna_coupling,
  1686. "specify antenna coupling in dB (defualt: 0 dB)");
  1687. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1688. bool, S_IRUGO);
  1689. MODULE_PARM_DESC(bt_ch_inhibition,
  1690. "Enable BT channel inhibition (default: enable)");
  1691. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1692. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1693. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1694. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1695. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1696. MODULE_PARM_DESC(wd_disable,
  1697. "Disable stuck queue watchdog timer 0=system default, "
  1698. "1=disable, 2=enable (default: 0)");
  1699. /*
  1700. * set bt_coex_active to true, uCode will do kill/defer
  1701. * every time the priority line is asserted (BT is sending signals on the
  1702. * priority line in the PCIx).
  1703. * set bt_coex_active to false, uCode will ignore the BT activity and
  1704. * perform the normal operation
  1705. *
  1706. * User might experience transmit issue on some platform due to WiFi/BT
  1707. * co-exist problem. The possible behaviors are:
  1708. * Able to scan and finding all the available AP
  1709. * Not able to associate with any AP
  1710. * On those platforms, WiFi communication can be restored by set
  1711. * "bt_coex_active" module parameter to "false"
  1712. *
  1713. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1714. */
  1715. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1716. bool, S_IRUGO);
  1717. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1718. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1719. MODULE_PARM_DESC(led_mode, "0=system default, "
  1720. "1=On(RF On)/Off(RF Off), 2=blinking (default: 0)");
  1721. module_param_named(power_save, iwlagn_mod_params.power_save,
  1722. bool, S_IRUGO);
  1723. MODULE_PARM_DESC(power_save,
  1724. "enable WiFi power management (default: disable)");
  1725. module_param_named(power_level, iwlagn_mod_params.power_level,
  1726. int, S_IRUGO);
  1727. MODULE_PARM_DESC(power_level,
  1728. "default power save level (range from 1 - 5, default: 1)");
  1729. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1730. bool, S_IRUGO);
  1731. MODULE_PARM_DESC(auto_agg,
  1732. "enable agg w/o check traffic load (default: enable)");
  1733. /*
  1734. * For now, keep using power level 1 instead of automatically
  1735. * adjusting ...
  1736. */
  1737. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1738. bool, S_IRUGO);
  1739. MODULE_PARM_DESC(no_sleep_autoadjust,
  1740. "don't automatically adjust sleep level "
  1741. "according to maximum network latency (default: true)");