iwl-agn.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080
  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. if (hw_params(priv).calib_rt_cfg)
  1085. iwlagn_send_calib_cfg_rt(priv,
  1086. hw_params(priv).calib_rt_cfg);
  1087. ieee80211_wake_queues(priv->hw);
  1088. priv->active_rate = IWL_RATES_MASK;
  1089. /* Configure Tx antenna selection based on H/W config */
  1090. iwlagn_send_tx_ant_config(priv, cfg(priv)->valid_tx_ant);
  1091. if (iwl_is_associated_ctx(ctx) && !priv->shrd->wowlan) {
  1092. struct iwl_rxon_cmd *active_rxon =
  1093. (struct iwl_rxon_cmd *)&ctx->active;
  1094. /* apply any changes in staging */
  1095. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  1096. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1097. } else {
  1098. struct iwl_rxon_context *tmp;
  1099. /* Initialize our rx_config data */
  1100. for_each_context(priv, tmp)
  1101. iwl_connection_init_rx_config(priv, tmp);
  1102. iwlagn_set_rxon_chain(priv, ctx);
  1103. }
  1104. if (!priv->shrd->wowlan) {
  1105. /* WoWLAN ucode will not reply in the same way, skip it */
  1106. iwl_reset_run_time_calib(priv);
  1107. }
  1108. set_bit(STATUS_READY, &priv->shrd->status);
  1109. /* Configure the adapter for unassociated operation */
  1110. ret = iwlagn_commit_rxon(priv, ctx);
  1111. if (ret)
  1112. return ret;
  1113. /* At this point, the NIC is initialized and operational */
  1114. iwl_rf_kill_ct_config(priv);
  1115. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  1116. return iwl_power_update_mode(priv, true);
  1117. }
  1118. static void iwl_cancel_deferred_work(struct iwl_priv *priv);
  1119. void __iwl_down(struct iwl_priv *priv)
  1120. {
  1121. int exit_pending;
  1122. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  1123. iwl_scan_cancel_timeout(priv, 200);
  1124. /*
  1125. * If active, scanning won't cancel it, so say it expired.
  1126. * No race since we hold the mutex here and a new one
  1127. * can't come in at this time.
  1128. */
  1129. ieee80211_remain_on_channel_expired(priv->hw);
  1130. exit_pending =
  1131. test_and_set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1132. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  1133. * to prevent rearm timer */
  1134. del_timer_sync(&priv->watchdog);
  1135. iwl_clear_ucode_stations(priv, NULL);
  1136. iwl_dealloc_bcast_stations(priv);
  1137. iwl_clear_driver_stations(priv);
  1138. /* reset BT coex data */
  1139. priv->bt_status = 0;
  1140. priv->cur_rssi_ctx = NULL;
  1141. priv->bt_is_sco = 0;
  1142. if (cfg(priv)->bt_params)
  1143. priv->bt_traffic_load =
  1144. cfg(priv)->bt_params->bt_init_traffic_load;
  1145. else
  1146. priv->bt_traffic_load = 0;
  1147. priv->bt_full_concurrent = false;
  1148. priv->bt_ci_compliance = 0;
  1149. /* Wipe out the EXIT_PENDING status bit if we are not actually
  1150. * exiting the module */
  1151. if (!exit_pending)
  1152. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1153. if (priv->mac80211_registered)
  1154. ieee80211_stop_queues(priv->hw);
  1155. iwl_trans_stop_device(trans(priv));
  1156. /* Clear out all status bits but a few that are stable across reset */
  1157. priv->shrd->status &=
  1158. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status) <<
  1159. STATUS_RF_KILL_HW |
  1160. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) <<
  1161. STATUS_GEO_CONFIGURED |
  1162. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  1163. STATUS_FW_ERROR |
  1164. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) <<
  1165. STATUS_EXIT_PENDING;
  1166. dev_kfree_skb(priv->beacon_skb);
  1167. priv->beacon_skb = NULL;
  1168. }
  1169. void iwl_down(struct iwl_priv *priv)
  1170. {
  1171. mutex_lock(&priv->shrd->mutex);
  1172. __iwl_down(priv);
  1173. mutex_unlock(&priv->shrd->mutex);
  1174. iwl_cancel_deferred_work(priv);
  1175. }
  1176. /*****************************************************************************
  1177. *
  1178. * Workqueue callbacks
  1179. *
  1180. *****************************************************************************/
  1181. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  1182. {
  1183. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1184. run_time_calib_work);
  1185. mutex_lock(&priv->shrd->mutex);
  1186. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  1187. test_bit(STATUS_SCANNING, &priv->shrd->status)) {
  1188. mutex_unlock(&priv->shrd->mutex);
  1189. return;
  1190. }
  1191. if (priv->start_calib) {
  1192. iwl_chain_noise_calibration(priv);
  1193. iwl_sensitivity_calibration(priv);
  1194. }
  1195. mutex_unlock(&priv->shrd->mutex);
  1196. }
  1197. void iwlagn_prepare_restart(struct iwl_priv *priv)
  1198. {
  1199. struct iwl_rxon_context *ctx;
  1200. bool bt_full_concurrent;
  1201. u8 bt_ci_compliance;
  1202. u8 bt_load;
  1203. u8 bt_status;
  1204. bool bt_is_sco;
  1205. lockdep_assert_held(&priv->shrd->mutex);
  1206. for_each_context(priv, ctx)
  1207. ctx->vif = NULL;
  1208. priv->is_open = 0;
  1209. /*
  1210. * __iwl_down() will clear the BT status variables,
  1211. * which is correct, but when we restart we really
  1212. * want to keep them so restore them afterwards.
  1213. *
  1214. * The restart process will later pick them up and
  1215. * re-configure the hw when we reconfigure the BT
  1216. * command.
  1217. */
  1218. bt_full_concurrent = priv->bt_full_concurrent;
  1219. bt_ci_compliance = priv->bt_ci_compliance;
  1220. bt_load = priv->bt_traffic_load;
  1221. bt_status = priv->bt_status;
  1222. bt_is_sco = priv->bt_is_sco;
  1223. __iwl_down(priv);
  1224. priv->bt_full_concurrent = bt_full_concurrent;
  1225. priv->bt_ci_compliance = bt_ci_compliance;
  1226. priv->bt_traffic_load = bt_load;
  1227. priv->bt_status = bt_status;
  1228. priv->bt_is_sco = bt_is_sco;
  1229. }
  1230. static void iwl_bg_restart(struct work_struct *data)
  1231. {
  1232. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  1233. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  1234. return;
  1235. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  1236. mutex_lock(&priv->shrd->mutex);
  1237. iwlagn_prepare_restart(priv);
  1238. mutex_unlock(&priv->shrd->mutex);
  1239. iwl_cancel_deferred_work(priv);
  1240. ieee80211_restart_hw(priv->hw);
  1241. } else {
  1242. WARN_ON(1);
  1243. }
  1244. }
  1245. void iwlagn_disable_roc(struct iwl_priv *priv)
  1246. {
  1247. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  1248. lockdep_assert_held(&priv->shrd->mutex);
  1249. if (!priv->hw_roc_setup)
  1250. return;
  1251. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  1252. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  1253. priv->hw_roc_channel = NULL;
  1254. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  1255. iwlagn_commit_rxon(priv, ctx);
  1256. ctx->is_active = false;
  1257. priv->hw_roc_setup = false;
  1258. }
  1259. static void iwlagn_disable_roc_work(struct work_struct *work)
  1260. {
  1261. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  1262. hw_roc_disable_work.work);
  1263. mutex_lock(&priv->shrd->mutex);
  1264. iwlagn_disable_roc(priv);
  1265. mutex_unlock(&priv->shrd->mutex);
  1266. }
  1267. /*****************************************************************************
  1268. *
  1269. * driver setup and teardown
  1270. *
  1271. *****************************************************************************/
  1272. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  1273. {
  1274. priv->shrd->workqueue = create_singlethread_workqueue(DRV_NAME);
  1275. init_waitqueue_head(&priv->shrd->wait_command_queue);
  1276. INIT_WORK(&priv->restart, iwl_bg_restart);
  1277. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  1278. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  1279. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  1280. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  1281. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  1282. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  1283. iwlagn_disable_roc_work);
  1284. iwl_setup_scan_deferred_work(priv);
  1285. if (cfg(priv)->lib->bt_setup_deferred_work)
  1286. cfg(priv)->lib->bt_setup_deferred_work(priv);
  1287. init_timer(&priv->statistics_periodic);
  1288. priv->statistics_periodic.data = (unsigned long)priv;
  1289. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  1290. init_timer(&priv->ucode_trace);
  1291. priv->ucode_trace.data = (unsigned long)priv;
  1292. priv->ucode_trace.function = iwl_bg_ucode_trace;
  1293. init_timer(&priv->watchdog);
  1294. priv->watchdog.data = (unsigned long)priv;
  1295. priv->watchdog.function = iwl_bg_watchdog;
  1296. }
  1297. static void iwl_cancel_deferred_work(struct iwl_priv *priv)
  1298. {
  1299. if (cfg(priv)->lib->cancel_deferred_work)
  1300. cfg(priv)->lib->cancel_deferred_work(priv);
  1301. cancel_work_sync(&priv->run_time_calib_work);
  1302. cancel_work_sync(&priv->beacon_update);
  1303. iwl_cancel_scan_deferred_work(priv);
  1304. cancel_work_sync(&priv->bt_full_concurrency);
  1305. cancel_work_sync(&priv->bt_runtime_config);
  1306. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  1307. del_timer_sync(&priv->statistics_periodic);
  1308. del_timer_sync(&priv->ucode_trace);
  1309. }
  1310. static void iwl_init_hw_rates(struct iwl_priv *priv,
  1311. struct ieee80211_rate *rates)
  1312. {
  1313. int i;
  1314. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  1315. rates[i].bitrate = iwl_rates[i].ieee * 5;
  1316. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  1317. rates[i].hw_value_short = i;
  1318. rates[i].flags = 0;
  1319. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  1320. /*
  1321. * If CCK != 1M then set short preamble rate flag.
  1322. */
  1323. rates[i].flags |=
  1324. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  1325. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  1326. }
  1327. }
  1328. }
  1329. static int iwl_init_drv(struct iwl_priv *priv)
  1330. {
  1331. int ret;
  1332. spin_lock_init(&priv->shrd->sta_lock);
  1333. mutex_init(&priv->shrd->mutex);
  1334. INIT_LIST_HEAD(&trans(priv)->calib_results);
  1335. priv->ieee_channels = NULL;
  1336. priv->ieee_rates = NULL;
  1337. priv->band = IEEE80211_BAND_2GHZ;
  1338. priv->iw_mode = NL80211_IFTYPE_STATION;
  1339. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  1340. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  1341. priv->agg_tids_count = 0;
  1342. /* initialize force reset */
  1343. priv->force_reset[IWL_RF_RESET].reset_duration =
  1344. IWL_DELAY_NEXT_FORCE_RF_RESET;
  1345. priv->force_reset[IWL_FW_RESET].reset_duration =
  1346. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  1347. priv->rx_statistics_jiffies = jiffies;
  1348. /* Choose which receivers/antennas to use */
  1349. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  1350. iwl_init_scan_params(priv);
  1351. /* init bt coex */
  1352. if (cfg(priv)->bt_params &&
  1353. cfg(priv)->bt_params->advanced_bt_coexist) {
  1354. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  1355. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  1356. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  1357. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  1358. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  1359. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  1360. }
  1361. ret = iwl_init_channel_map(priv);
  1362. if (ret) {
  1363. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  1364. goto err;
  1365. }
  1366. ret = iwl_init_geos(priv);
  1367. if (ret) {
  1368. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  1369. goto err_free_channel_map;
  1370. }
  1371. iwl_init_hw_rates(priv, priv->ieee_rates);
  1372. return 0;
  1373. err_free_channel_map:
  1374. iwl_free_channel_map(priv);
  1375. err:
  1376. return ret;
  1377. }
  1378. static void iwl_uninit_drv(struct iwl_priv *priv)
  1379. {
  1380. iwl_free_geos(priv);
  1381. iwl_free_channel_map(priv);
  1382. if (priv->tx_cmd_pool)
  1383. kmem_cache_destroy(priv->tx_cmd_pool);
  1384. kfree(priv->scan_cmd);
  1385. kfree(priv->beacon_cmd);
  1386. kfree(rcu_dereference_raw(priv->noa_data));
  1387. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1388. kfree(priv->wowlan_sram);
  1389. #endif
  1390. }
  1391. static u32 iwl_hw_detect(struct iwl_priv *priv)
  1392. {
  1393. return iwl_read32(bus(priv), CSR_HW_REV);
  1394. }
  1395. /* Size of one Rx buffer in host DRAM */
  1396. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  1397. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  1398. static int iwl_set_hw_params(struct iwl_priv *priv)
  1399. {
  1400. if (iwlagn_mod_params.amsdu_size_8K)
  1401. hw_params(priv).rx_page_order =
  1402. get_order(IWL_RX_BUF_SIZE_8K);
  1403. else
  1404. hw_params(priv).rx_page_order =
  1405. get_order(IWL_RX_BUF_SIZE_4K);
  1406. if (iwlagn_mod_params.disable_11n)
  1407. cfg(priv)->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  1408. hw_params(priv).num_ampdu_queues =
  1409. cfg(priv)->base_params->num_of_ampdu_queues;
  1410. hw_params(priv).shadow_reg_enable =
  1411. cfg(priv)->base_params->shadow_reg_enable;
  1412. hw_params(priv).sku = cfg(priv)->sku;
  1413. hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
  1414. /* Device-specific setup */
  1415. return cfg(priv)->lib->set_hw_params(priv);
  1416. }
  1417. static void iwl_debug_config(struct iwl_priv *priv)
  1418. {
  1419. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  1420. #ifdef CONFIG_IWLWIFI_DEBUG
  1421. "enabled\n");
  1422. #else
  1423. "disabled\n");
  1424. #endif
  1425. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  1426. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1427. "enabled\n");
  1428. #else
  1429. "disabled\n");
  1430. #endif
  1431. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  1432. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  1433. "enabled\n");
  1434. #else
  1435. "disabled\n");
  1436. #endif
  1437. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  1438. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  1439. "enabled\n");
  1440. #else
  1441. "disabled\n");
  1442. #endif
  1443. dev_printk(KERN_INFO, bus(priv)->dev, "CONFIG_IWLWIFI_P2P "
  1444. #ifdef CONFIG_IWLWIFI_P2P
  1445. "enabled\n");
  1446. #else
  1447. "disabled\n");
  1448. #endif
  1449. }
  1450. int iwl_probe(struct iwl_bus *bus, const struct iwl_trans_ops *trans_ops,
  1451. struct iwl_cfg *cfg)
  1452. {
  1453. int err = 0;
  1454. struct iwl_priv *priv;
  1455. struct ieee80211_hw *hw;
  1456. u16 num_mac;
  1457. u32 hw_rev;
  1458. /************************
  1459. * 1. Allocating HW data
  1460. ************************/
  1461. hw = iwl_alloc_all();
  1462. if (!hw) {
  1463. pr_err("%s: Cannot allocate network device\n", cfg->name);
  1464. err = -ENOMEM;
  1465. goto out;
  1466. }
  1467. priv = hw->priv;
  1468. priv->shrd = &priv->_shrd;
  1469. bus->shrd = priv->shrd;
  1470. priv->shrd->bus = bus;
  1471. priv->shrd->priv = priv;
  1472. priv->shrd->trans = trans_ops->alloc(priv->shrd);
  1473. if (priv->shrd->trans == NULL) {
  1474. err = -ENOMEM;
  1475. goto out_free_traffic_mem;
  1476. }
  1477. /* At this point both hw and priv are allocated. */
  1478. SET_IEEE80211_DEV(hw, bus(priv)->dev);
  1479. /* what debugging capabilities we have */
  1480. iwl_debug_config(priv);
  1481. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1482. cfg(priv) = cfg;
  1483. /* is antenna coupling more than 35dB ? */
  1484. priv->bt_ant_couple_ok =
  1485. (iwlagn_mod_params.ant_coupling >
  1486. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1487. true : false;
  1488. /* enable/disable bt channel inhibition */
  1489. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1490. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1491. (priv->bt_ch_announce) ? "On" : "Off");
  1492. if (iwl_alloc_traffic_mem(priv))
  1493. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1494. /* these spin locks will be used in apm_ops.init and EEPROM access
  1495. * we should init now
  1496. */
  1497. spin_lock_init(&bus(priv)->reg_lock);
  1498. spin_lock_init(&priv->shrd->lock);
  1499. /*
  1500. * stop and reset the on-board processor just in case it is in a
  1501. * strange state ... like being left stranded by a primary kernel
  1502. * and this is now the kdump kernel trying to start up
  1503. */
  1504. iwl_write32(bus(priv), CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
  1505. /***********************
  1506. * 3. Read REV register
  1507. ***********************/
  1508. hw_rev = iwl_hw_detect(priv);
  1509. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1510. cfg(priv)->name, hw_rev);
  1511. err = iwl_trans_request_irq(trans(priv));
  1512. if (err)
  1513. goto out_free_trans;
  1514. if (iwl_trans_prepare_card_hw(trans(priv))) {
  1515. err = -EIO;
  1516. IWL_WARN(priv, "Failed, HW not ready\n");
  1517. goto out_free_trans;
  1518. }
  1519. /*****************
  1520. * 4. Read EEPROM
  1521. *****************/
  1522. /* Read the EEPROM */
  1523. err = iwl_eeprom_init(priv, hw_rev);
  1524. if (err) {
  1525. IWL_ERR(priv, "Unable to init EEPROM\n");
  1526. goto out_free_trans;
  1527. }
  1528. err = iwl_eeprom_check_version(priv);
  1529. if (err)
  1530. goto out_free_eeprom;
  1531. err = iwl_eeprom_check_sku(priv);
  1532. if (err)
  1533. goto out_free_eeprom;
  1534. /* extract MAC Address */
  1535. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1536. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1537. priv->hw->wiphy->addresses = priv->addresses;
  1538. priv->hw->wiphy->n_addresses = 1;
  1539. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1540. if (num_mac > 1) {
  1541. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1542. ETH_ALEN);
  1543. priv->addresses[1].addr[5]++;
  1544. priv->hw->wiphy->n_addresses++;
  1545. }
  1546. /************************
  1547. * 5. Setup HW constants
  1548. ************************/
  1549. if (iwl_set_hw_params(priv)) {
  1550. err = -ENOENT;
  1551. IWL_ERR(priv, "failed to set hw parameters\n");
  1552. goto out_free_eeprom;
  1553. }
  1554. /*******************
  1555. * 6. Setup priv
  1556. *******************/
  1557. err = iwl_init_drv(priv);
  1558. if (err)
  1559. goto out_free_eeprom;
  1560. /* At this point both hw and priv are initialized. */
  1561. /********************
  1562. * 7. Setup services
  1563. ********************/
  1564. iwl_setup_deferred_work(priv);
  1565. iwl_setup_rx_handlers(priv);
  1566. iwl_testmode_init(priv);
  1567. /*********************************************
  1568. * 8. Enable interrupts
  1569. *********************************************/
  1570. iwl_enable_rfkill_int(priv);
  1571. /* If platform's RF_KILL switch is NOT set to KILL */
  1572. if (iwl_read32(bus(priv),
  1573. CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
  1574. clear_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  1575. else
  1576. set_bit(STATUS_RF_KILL_HW, &priv->shrd->status);
  1577. wiphy_rfkill_set_hw_state(priv->hw->wiphy,
  1578. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status));
  1579. iwl_power_initialize(priv);
  1580. iwl_tt_initialize(priv);
  1581. init_completion(&priv->firmware_loading_complete);
  1582. err = iwl_request_firmware(priv, true);
  1583. if (err)
  1584. goto out_destroy_workqueue;
  1585. return 0;
  1586. out_destroy_workqueue:
  1587. destroy_workqueue(priv->shrd->workqueue);
  1588. priv->shrd->workqueue = NULL;
  1589. iwl_uninit_drv(priv);
  1590. out_free_eeprom:
  1591. iwl_eeprom_free(priv->shrd);
  1592. out_free_trans:
  1593. iwl_trans_free(trans(priv));
  1594. out_free_traffic_mem:
  1595. iwl_free_traffic_mem(priv);
  1596. ieee80211_free_hw(priv->hw);
  1597. out:
  1598. return err;
  1599. }
  1600. void __devexit iwl_remove(struct iwl_priv * priv)
  1601. {
  1602. wait_for_completion(&priv->firmware_loading_complete);
  1603. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1604. iwl_dbgfs_unregister(priv);
  1605. /* ieee80211_unregister_hw call wil cause iwlagn_mac_stop to
  1606. * to be called and iwl_down since we are removing the device
  1607. * we need to set STATUS_EXIT_PENDING bit.
  1608. */
  1609. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1610. iwl_testmode_cleanup(priv);
  1611. iwlagn_mac_unregister(priv);
  1612. iwl_tt_exit(priv);
  1613. /*This will stop the queues, move the device to low power state */
  1614. iwl_trans_stop_device(trans(priv));
  1615. iwl_dealloc_ucode(trans(priv));
  1616. iwl_eeprom_free(priv->shrd);
  1617. /*netif_stop_queue(dev); */
  1618. flush_workqueue(priv->shrd->workqueue);
  1619. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1620. * priv->shrd->workqueue... so we can't take down the workqueue
  1621. * until now... */
  1622. destroy_workqueue(priv->shrd->workqueue);
  1623. priv->shrd->workqueue = NULL;
  1624. iwl_free_traffic_mem(priv);
  1625. iwl_trans_free(trans(priv));
  1626. iwl_uninit_drv(priv);
  1627. dev_kfree_skb(priv->beacon_skb);
  1628. ieee80211_free_hw(priv->hw);
  1629. }
  1630. /*****************************************************************************
  1631. *
  1632. * driver and module entry point
  1633. *
  1634. *****************************************************************************/
  1635. static int __init iwl_init(void)
  1636. {
  1637. int ret;
  1638. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1639. pr_info(DRV_COPYRIGHT "\n");
  1640. ret = iwlagn_rate_control_register();
  1641. if (ret) {
  1642. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1643. return ret;
  1644. }
  1645. ret = iwl_pci_register_driver();
  1646. if (ret)
  1647. goto error_register;
  1648. return ret;
  1649. error_register:
  1650. iwlagn_rate_control_unregister();
  1651. return ret;
  1652. }
  1653. static void __exit iwl_exit(void)
  1654. {
  1655. iwl_pci_unregister_driver();
  1656. iwlagn_rate_control_unregister();
  1657. }
  1658. module_exit(iwl_exit);
  1659. module_init(iwl_init);
  1660. #ifdef CONFIG_IWLWIFI_DEBUG
  1661. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1662. S_IRUGO | S_IWUSR);
  1663. MODULE_PARM_DESC(debug, "debug output mask");
  1664. #endif
  1665. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1666. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1667. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  1668. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  1669. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, int, S_IRUGO);
  1670. MODULE_PARM_DESC(11n_disable, "disable 11n functionality");
  1671. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1672. int, S_IRUGO);
  1673. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1674. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1675. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1676. module_param_named(ucode_alternative,
  1677. iwlagn_mod_params.wanted_ucode_alternative,
  1678. int, S_IRUGO);
  1679. MODULE_PARM_DESC(ucode_alternative,
  1680. "specify ucode alternative to use from ucode file");
  1681. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1682. int, S_IRUGO);
  1683. MODULE_PARM_DESC(antenna_coupling,
  1684. "specify antenna coupling in dB (defualt: 0 dB)");
  1685. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1686. bool, S_IRUGO);
  1687. MODULE_PARM_DESC(bt_ch_inhibition,
  1688. "Enable BT channel inhibition (default: enable)");
  1689. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1690. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1691. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1692. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1693. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1694. MODULE_PARM_DESC(wd_disable,
  1695. "Disable stuck queue watchdog timer 0=system default, "
  1696. "1=disable, 2=enable (default: 0)");
  1697. /*
  1698. * set bt_coex_active to true, uCode will do kill/defer
  1699. * every time the priority line is asserted (BT is sending signals on the
  1700. * priority line in the PCIx).
  1701. * set bt_coex_active to false, uCode will ignore the BT activity and
  1702. * perform the normal operation
  1703. *
  1704. * User might experience transmit issue on some platform due to WiFi/BT
  1705. * co-exist problem. The possible behaviors are:
  1706. * Able to scan and finding all the available AP
  1707. * Not able to associate with any AP
  1708. * On those platforms, WiFi communication can be restored by set
  1709. * "bt_coex_active" module parameter to "false"
  1710. *
  1711. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1712. */
  1713. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1714. bool, S_IRUGO);
  1715. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1716. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1717. MODULE_PARM_DESC(led_mode, "0=system default, "
  1718. "1=On(RF On)/Off(RF Off), 2=blinking (default: 0)");
  1719. module_param_named(power_save, iwlagn_mod_params.power_save,
  1720. bool, S_IRUGO);
  1721. MODULE_PARM_DESC(power_save,
  1722. "enable WiFi power management (default: disable)");
  1723. module_param_named(power_level, iwlagn_mod_params.power_level,
  1724. int, S_IRUGO);
  1725. MODULE_PARM_DESC(power_level,
  1726. "default power save level (range from 1 - 5, default: 1)");
  1727. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1728. bool, S_IRUGO);
  1729. MODULE_PARM_DESC(auto_agg,
  1730. "enable agg w/o check traffic load (default: enable)");
  1731. /*
  1732. * For now, keep using power level 1 instead of automatically
  1733. * adjusting ...
  1734. */
  1735. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1736. bool, S_IRUGO);
  1737. MODULE_PARM_DESC(no_sleep_autoadjust,
  1738. "don't automatically adjust sleep level "
  1739. "according to maximum network latency (default: true)");