iwl-agn.c 58 KB

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