iwl-agn.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795
  1. /******************************************************************************
  2. *
  3. * Copyright(c) 2003 - 2012 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/etherdevice.h>
  38. #include <linux/if_arp.h>
  39. #include <net/mac80211.h>
  40. #include <asm/div64.h>
  41. #include "iwl-eeprom.h"
  42. #include "iwl-dev.h"
  43. #include "iwl-core.h"
  44. #include "iwl-io.h"
  45. #include "iwl-agn-calib.h"
  46. #include "iwl-agn.h"
  47. #include "iwl-shared.h"
  48. #include "iwl-trans.h"
  49. #include "iwl-op-mode.h"
  50. /******************************************************************************
  51. *
  52. * module boiler plate
  53. *
  54. ******************************************************************************/
  55. /*
  56. * module name, copyright, version, etc.
  57. */
  58. #define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
  59. #ifdef CONFIG_IWLWIFI_DEBUG
  60. #define VD "d"
  61. #else
  62. #define VD
  63. #endif
  64. #define DRV_VERSION IWLWIFI_VERSION VD
  65. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  66. MODULE_VERSION(DRV_VERSION);
  67. MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
  68. MODULE_LICENSE("GPL");
  69. MODULE_ALIAS("iwlagn");
  70. void iwl_update_chain_flags(struct iwl_priv *priv)
  71. {
  72. struct iwl_rxon_context *ctx;
  73. for_each_context(priv, ctx) {
  74. iwlagn_set_rxon_chain(priv, ctx);
  75. if (ctx->active.rx_chain != ctx->staging.rx_chain)
  76. iwlagn_commit_rxon(priv, ctx);
  77. }
  78. }
  79. /* Parse the beacon frame to find the TIM element and set tim_idx & tim_size */
  80. static void iwl_set_beacon_tim(struct iwl_priv *priv,
  81. struct iwl_tx_beacon_cmd *tx_beacon_cmd,
  82. u8 *beacon, u32 frame_size)
  83. {
  84. u16 tim_idx;
  85. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)beacon;
  86. /*
  87. * The index is relative to frame start but we start looking at the
  88. * variable-length part of the beacon.
  89. */
  90. tim_idx = mgmt->u.beacon.variable - beacon;
  91. /* Parse variable-length elements of beacon to find WLAN_EID_TIM */
  92. while ((tim_idx < (frame_size - 2)) &&
  93. (beacon[tim_idx] != WLAN_EID_TIM))
  94. tim_idx += beacon[tim_idx+1] + 2;
  95. /* If TIM field was found, set variables */
  96. if ((tim_idx < (frame_size - 1)) && (beacon[tim_idx] == WLAN_EID_TIM)) {
  97. tx_beacon_cmd->tim_idx = cpu_to_le16(tim_idx);
  98. tx_beacon_cmd->tim_size = beacon[tim_idx+1];
  99. } else
  100. IWL_WARN(priv, "Unable to find TIM Element in beacon\n");
  101. }
  102. int iwlagn_send_beacon_cmd(struct iwl_priv *priv)
  103. {
  104. struct iwl_tx_beacon_cmd *tx_beacon_cmd;
  105. struct iwl_host_cmd cmd = {
  106. .id = REPLY_TX_BEACON,
  107. .flags = CMD_SYNC,
  108. };
  109. struct ieee80211_tx_info *info;
  110. u32 frame_size;
  111. u32 rate_flags;
  112. u32 rate;
  113. /*
  114. * We have to set up the TX command, the TX Beacon command, and the
  115. * beacon contents.
  116. */
  117. lockdep_assert_held(&priv->mutex);
  118. if (!priv->beacon_ctx) {
  119. IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
  120. return 0;
  121. }
  122. if (WARN_ON(!priv->beacon_skb))
  123. return -EINVAL;
  124. /* Allocate beacon command */
  125. if (!priv->beacon_cmd)
  126. priv->beacon_cmd = kzalloc(sizeof(*tx_beacon_cmd), GFP_KERNEL);
  127. tx_beacon_cmd = priv->beacon_cmd;
  128. if (!tx_beacon_cmd)
  129. return -ENOMEM;
  130. frame_size = priv->beacon_skb->len;
  131. /* Set up TX command fields */
  132. tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
  133. tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
  134. tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
  135. tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
  136. TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
  137. /* Set up TX beacon command fields */
  138. iwl_set_beacon_tim(priv, tx_beacon_cmd, priv->beacon_skb->data,
  139. frame_size);
  140. /* Set up packet rate and flags */
  141. info = IEEE80211_SKB_CB(priv->beacon_skb);
  142. /*
  143. * Let's set up the rate at least somewhat correctly;
  144. * it will currently not actually be used by the uCode,
  145. * it uses the broadcast station's rate instead.
  146. */
  147. if (info->control.rates[0].idx < 0 ||
  148. info->control.rates[0].flags & IEEE80211_TX_RC_MCS)
  149. rate = 0;
  150. else
  151. rate = info->control.rates[0].idx;
  152. priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
  153. hw_params(priv).valid_tx_ant);
  154. rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
  155. /* In mac80211, rates for 5 GHz start at 0 */
  156. if (info->band == IEEE80211_BAND_5GHZ)
  157. rate += IWL_FIRST_OFDM_RATE;
  158. else if (rate >= IWL_FIRST_CCK_RATE && rate <= IWL_LAST_CCK_RATE)
  159. rate_flags |= RATE_MCS_CCK_MSK;
  160. tx_beacon_cmd->tx.rate_n_flags =
  161. iwl_hw_set_rate_n_flags(rate, rate_flags);
  162. /* Submit command */
  163. cmd.len[0] = sizeof(*tx_beacon_cmd);
  164. cmd.data[0] = tx_beacon_cmd;
  165. cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY;
  166. cmd.len[1] = frame_size;
  167. cmd.data[1] = priv->beacon_skb->data;
  168. cmd.dataflags[1] = IWL_HCMD_DFL_NOCOPY;
  169. return iwl_dvm_send_cmd(priv, &cmd);
  170. }
  171. static void iwl_bg_beacon_update(struct work_struct *work)
  172. {
  173. struct iwl_priv *priv =
  174. container_of(work, struct iwl_priv, beacon_update);
  175. struct sk_buff *beacon;
  176. mutex_lock(&priv->mutex);
  177. if (!priv->beacon_ctx) {
  178. IWL_ERR(priv, "updating beacon w/o beacon context!\n");
  179. goto out;
  180. }
  181. if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
  182. /*
  183. * The ucode will send beacon notifications even in
  184. * IBSS mode, but we don't want to process them. But
  185. * we need to defer the type check to here due to
  186. * requiring locking around the beacon_ctx access.
  187. */
  188. goto out;
  189. }
  190. /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
  191. beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
  192. if (!beacon) {
  193. IWL_ERR(priv, "update beacon failed -- keeping old\n");
  194. goto out;
  195. }
  196. /* new beacon skb is allocated every time; dispose previous.*/
  197. dev_kfree_skb(priv->beacon_skb);
  198. priv->beacon_skb = beacon;
  199. iwlagn_send_beacon_cmd(priv);
  200. out:
  201. mutex_unlock(&priv->mutex);
  202. }
  203. static void iwl_bg_bt_runtime_config(struct work_struct *work)
  204. {
  205. struct iwl_priv *priv =
  206. container_of(work, struct iwl_priv, bt_runtime_config);
  207. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  208. return;
  209. /* dont send host command if rf-kill is on */
  210. if (!iwl_is_ready_rf(priv))
  211. return;
  212. iwlagn_send_advance_bt_config(priv);
  213. }
  214. static void iwl_bg_bt_full_concurrency(struct work_struct *work)
  215. {
  216. struct iwl_priv *priv =
  217. container_of(work, struct iwl_priv, bt_full_concurrency);
  218. struct iwl_rxon_context *ctx;
  219. mutex_lock(&priv->mutex);
  220. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  221. goto out;
  222. /* dont send host command if rf-kill is on */
  223. if (!iwl_is_ready_rf(priv))
  224. goto out;
  225. IWL_DEBUG_INFO(priv, "BT coex in %s mode\n",
  226. priv->bt_full_concurrent ?
  227. "full concurrency" : "3-wire");
  228. /*
  229. * LQ & RXON updated cmds must be sent before BT Config cmd
  230. * to avoid 3-wire collisions
  231. */
  232. for_each_context(priv, ctx) {
  233. iwlagn_set_rxon_chain(priv, ctx);
  234. iwlagn_commit_rxon(priv, ctx);
  235. }
  236. iwlagn_send_advance_bt_config(priv);
  237. out:
  238. mutex_unlock(&priv->mutex);
  239. }
  240. /**
  241. * iwl_bg_statistics_periodic - Timer callback to queue statistics
  242. *
  243. * This callback is provided in order to send a statistics request.
  244. *
  245. * This timer function is continually reset to execute within
  246. * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
  247. * was received. We need to ensure we receive the statistics in order
  248. * to update the temperature used for calibrating the TXPOWER.
  249. */
  250. static void iwl_bg_statistics_periodic(unsigned long data)
  251. {
  252. struct iwl_priv *priv = (struct iwl_priv *)data;
  253. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  254. return;
  255. /* dont send host command if rf-kill is on */
  256. if (!iwl_is_ready_rf(priv))
  257. return;
  258. iwl_send_statistics_request(priv, CMD_ASYNC, false);
  259. }
  260. static void iwl_print_cont_event_trace(struct iwl_priv *priv, u32 base,
  261. u32 start_idx, u32 num_events,
  262. u32 capacity, u32 mode)
  263. {
  264. u32 i;
  265. u32 ptr; /* SRAM byte address of log data */
  266. u32 ev, time, data; /* event log data */
  267. unsigned long reg_flags;
  268. if (mode == 0)
  269. ptr = base + (4 * sizeof(u32)) + (start_idx * 2 * sizeof(u32));
  270. else
  271. ptr = base + (4 * sizeof(u32)) + (start_idx * 3 * sizeof(u32));
  272. /* Make sure device is powered up for SRAM reads */
  273. spin_lock_irqsave(&trans(priv)->reg_lock, reg_flags);
  274. if (unlikely(!iwl_grab_nic_access(trans(priv)))) {
  275. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  276. return;
  277. }
  278. /* Set starting address; reads will auto-increment */
  279. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, ptr);
  280. /*
  281. * Refuse to read more than would have fit into the log from
  282. * the current start_idx. This used to happen due to the race
  283. * described below, but now WARN because the code below should
  284. * prevent it from happening here.
  285. */
  286. if (WARN_ON(num_events > capacity - start_idx))
  287. num_events = capacity - start_idx;
  288. /*
  289. * "time" is actually "data" for mode 0 (no timestamp).
  290. * place event id # at far right for easier visual parsing.
  291. */
  292. for (i = 0; i < num_events; i++) {
  293. ev = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  294. time = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  295. if (mode == 0) {
  296. trace_iwlwifi_dev_ucode_cont_event(
  297. trans(priv)->dev, 0, time, ev);
  298. } else {
  299. data = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  300. trace_iwlwifi_dev_ucode_cont_event(
  301. trans(priv)->dev, time, data, ev);
  302. }
  303. }
  304. /* Allow device to power down */
  305. iwl_release_nic_access(trans(priv));
  306. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  307. }
  308. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  309. {
  310. u32 capacity; /* event log capacity in # entries */
  311. struct {
  312. u32 capacity;
  313. u32 mode;
  314. u32 wrap_counter;
  315. u32 write_counter;
  316. } __packed read;
  317. u32 base; /* SRAM byte address of event log header */
  318. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  319. u32 num_wraps; /* # times uCode wrapped to top of log */
  320. u32 next_entry; /* index of next entry to be written by uCode */
  321. base = priv->shrd->device_pointers.log_event_table;
  322. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  323. iwl_read_targ_mem_words(trans(priv), base, &read, sizeof(read));
  324. capacity = read.capacity;
  325. mode = read.mode;
  326. num_wraps = read.wrap_counter;
  327. next_entry = read.write_counter;
  328. } else
  329. return;
  330. /*
  331. * Unfortunately, the uCode doesn't use temporary variables.
  332. * Therefore, it can happen that we read next_entry == capacity,
  333. * which really means next_entry == 0.
  334. */
  335. if (unlikely(next_entry == capacity))
  336. next_entry = 0;
  337. /*
  338. * Additionally, the uCode increases the write pointer before
  339. * the wraps counter, so if the write pointer is smaller than
  340. * the old write pointer (wrap occurred) but we read that no
  341. * wrap occurred, we actually read between the next_entry and
  342. * num_wraps update (this does happen in practice!!) -- take
  343. * that into account by increasing num_wraps.
  344. */
  345. if (unlikely(next_entry < priv->event_log.next_entry &&
  346. num_wraps == priv->event_log.num_wraps))
  347. num_wraps++;
  348. if (num_wraps == priv->event_log.num_wraps) {
  349. iwl_print_cont_event_trace(
  350. priv, base, priv->event_log.next_entry,
  351. next_entry - priv->event_log.next_entry,
  352. capacity, mode);
  353. priv->event_log.non_wraps_count++;
  354. } else {
  355. if (num_wraps - priv->event_log.num_wraps > 1)
  356. priv->event_log.wraps_more_count++;
  357. else
  358. priv->event_log.wraps_once_count++;
  359. trace_iwlwifi_dev_ucode_wrap_event(trans(priv)->dev,
  360. num_wraps - priv->event_log.num_wraps,
  361. next_entry, priv->event_log.next_entry);
  362. if (next_entry < priv->event_log.next_entry) {
  363. iwl_print_cont_event_trace(
  364. priv, base, priv->event_log.next_entry,
  365. capacity - priv->event_log.next_entry,
  366. capacity, mode);
  367. iwl_print_cont_event_trace(
  368. priv, base, 0, next_entry, capacity, mode);
  369. } else {
  370. iwl_print_cont_event_trace(
  371. priv, base, next_entry,
  372. capacity - next_entry,
  373. capacity, mode);
  374. iwl_print_cont_event_trace(
  375. priv, base, 0, next_entry, capacity, mode);
  376. }
  377. }
  378. priv->event_log.num_wraps = num_wraps;
  379. priv->event_log.next_entry = next_entry;
  380. }
  381. /**
  382. * iwl_bg_ucode_trace - Timer callback to log ucode event
  383. *
  384. * The timer is continually set to execute every
  385. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  386. * this function is to perform continuous uCode event logging operation
  387. * if enabled
  388. */
  389. static void iwl_bg_ucode_trace(unsigned long data)
  390. {
  391. struct iwl_priv *priv = (struct iwl_priv *)data;
  392. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  393. return;
  394. if (priv->event_log.ucode_trace) {
  395. iwl_continuous_event_trace(priv);
  396. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  397. mod_timer(&priv->ucode_trace,
  398. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  399. }
  400. }
  401. static void iwl_bg_tx_flush(struct work_struct *work)
  402. {
  403. struct iwl_priv *priv =
  404. container_of(work, struct iwl_priv, tx_flush);
  405. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  406. return;
  407. /* do nothing if rf-kill is on */
  408. if (!iwl_is_ready_rf(priv))
  409. return;
  410. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  411. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  412. }
  413. /*
  414. * queue/FIFO/AC mapping definitions
  415. */
  416. #define IWL_TX_FIFO_BK 0 /* shared */
  417. #define IWL_TX_FIFO_BE 1
  418. #define IWL_TX_FIFO_VI 2 /* shared */
  419. #define IWL_TX_FIFO_VO 3
  420. #define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
  421. #define IWL_TX_FIFO_BE_IPAN 4
  422. #define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
  423. #define IWL_TX_FIFO_VO_IPAN 5
  424. /* re-uses the VO FIFO, uCode will properly flush/schedule */
  425. #define IWL_TX_FIFO_AUX 5
  426. #define IWL_TX_FIFO_UNUSED -1
  427. #define IWLAGN_CMD_FIFO_NUM 7
  428. /*
  429. * This queue number is required for proper operation
  430. * because the ucode will stop/start the scheduler as
  431. * required.
  432. */
  433. #define IWL_IPAN_MCAST_QUEUE 8
  434. static const u8 iwlagn_default_queue_to_tx_fifo[] = {
  435. IWL_TX_FIFO_VO,
  436. IWL_TX_FIFO_VI,
  437. IWL_TX_FIFO_BE,
  438. IWL_TX_FIFO_BK,
  439. IWLAGN_CMD_FIFO_NUM,
  440. };
  441. static const u8 iwlagn_ipan_queue_to_tx_fifo[] = {
  442. IWL_TX_FIFO_VO,
  443. IWL_TX_FIFO_VI,
  444. IWL_TX_FIFO_BE,
  445. IWL_TX_FIFO_BK,
  446. IWL_TX_FIFO_BK_IPAN,
  447. IWL_TX_FIFO_BE_IPAN,
  448. IWL_TX_FIFO_VI_IPAN,
  449. IWL_TX_FIFO_VO_IPAN,
  450. IWL_TX_FIFO_BE_IPAN,
  451. IWLAGN_CMD_FIFO_NUM,
  452. IWL_TX_FIFO_AUX,
  453. };
  454. static const u8 iwlagn_bss_ac_to_fifo[] = {
  455. IWL_TX_FIFO_VO,
  456. IWL_TX_FIFO_VI,
  457. IWL_TX_FIFO_BE,
  458. IWL_TX_FIFO_BK,
  459. };
  460. static const u8 iwlagn_bss_ac_to_queue[] = {
  461. 0, 1, 2, 3,
  462. };
  463. static const u8 iwlagn_pan_ac_to_fifo[] = {
  464. IWL_TX_FIFO_VO_IPAN,
  465. IWL_TX_FIFO_VI_IPAN,
  466. IWL_TX_FIFO_BE_IPAN,
  467. IWL_TX_FIFO_BK_IPAN,
  468. };
  469. static const u8 iwlagn_pan_ac_to_queue[] = {
  470. 7, 6, 5, 4,
  471. };
  472. static const u8 iwlagn_bss_queue_to_ac[] = {
  473. IEEE80211_AC_VO,
  474. IEEE80211_AC_VI,
  475. IEEE80211_AC_BE,
  476. IEEE80211_AC_BK,
  477. };
  478. static const u8 iwlagn_pan_queue_to_ac[] = {
  479. IEEE80211_AC_VO,
  480. IEEE80211_AC_VI,
  481. IEEE80211_AC_BE,
  482. IEEE80211_AC_BK,
  483. IEEE80211_AC_BK,
  484. IEEE80211_AC_BE,
  485. IEEE80211_AC_VI,
  486. IEEE80211_AC_VO,
  487. };
  488. static void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  489. {
  490. int i;
  491. /*
  492. * The default context is always valid,
  493. * the PAN context depends on uCode.
  494. */
  495. priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  496. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  497. priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  498. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  499. priv->contexts[i].ctxid = i;
  500. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  501. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  502. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  503. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  504. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  505. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  506. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  507. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  508. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  509. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  510. BIT(NL80211_IFTYPE_ADHOC);
  511. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  512. BIT(NL80211_IFTYPE_STATION);
  513. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  514. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  515. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  516. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  517. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue,
  518. iwlagn_bss_ac_to_queue, sizeof(iwlagn_bss_ac_to_queue));
  519. memcpy(priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo,
  520. iwlagn_bss_ac_to_fifo, sizeof(iwlagn_bss_ac_to_fifo));
  521. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  522. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  523. REPLY_WIPAN_RXON_TIMING;
  524. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  525. REPLY_WIPAN_RXON_ASSOC;
  526. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  527. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  528. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  529. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  530. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  531. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  532. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  533. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  534. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  535. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  536. BIT(NL80211_IFTYPE_P2P_GO);
  537. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  538. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  539. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  540. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue,
  541. iwlagn_pan_ac_to_queue, sizeof(iwlagn_pan_ac_to_queue));
  542. memcpy(priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo,
  543. iwlagn_pan_ac_to_fifo, sizeof(iwlagn_pan_ac_to_fifo));
  544. priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
  545. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  546. }
  547. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  548. {
  549. struct iwl_ct_kill_config cmd;
  550. struct iwl_ct_kill_throttling_config adv_cmd;
  551. int ret = 0;
  552. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  553. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  554. priv->thermal_throttle.ct_kill_toggle = false;
  555. if (cfg(priv)->base_params->support_ct_kill_exit) {
  556. adv_cmd.critical_temperature_enter =
  557. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  558. adv_cmd.critical_temperature_exit =
  559. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  560. ret = iwl_dvm_send_cmd_pdu(priv,
  561. REPLY_CT_KILL_CONFIG_CMD,
  562. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  563. if (ret)
  564. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  565. else
  566. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  567. "succeeded, critical temperature enter is %d,"
  568. "exit is %d\n",
  569. hw_params(priv).ct_kill_threshold,
  570. hw_params(priv).ct_kill_exit_threshold);
  571. } else {
  572. cmd.critical_temperature_R =
  573. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  574. ret = iwl_dvm_send_cmd_pdu(priv,
  575. REPLY_CT_KILL_CONFIG_CMD,
  576. CMD_SYNC, sizeof(cmd), &cmd);
  577. if (ret)
  578. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  579. else
  580. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  581. "succeeded, "
  582. "critical temperature is %d\n",
  583. hw_params(priv).ct_kill_threshold);
  584. }
  585. }
  586. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  587. {
  588. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  589. struct iwl_host_cmd cmd = {
  590. .id = CALIBRATION_CFG_CMD,
  591. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  592. .data = { &calib_cfg_cmd, },
  593. };
  594. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  595. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  596. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  597. return iwl_dvm_send_cmd(priv, &cmd);
  598. }
  599. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  600. {
  601. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  602. .valid = cpu_to_le32(valid_tx_ant),
  603. };
  604. if (IWL_UCODE_API(priv->fw->ucode_ver) > 1) {
  605. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  606. return iwl_dvm_send_cmd_pdu(priv,
  607. TX_ANT_CONFIGURATION_CMD,
  608. CMD_SYNC,
  609. sizeof(struct iwl_tx_ant_config_cmd),
  610. &tx_ant_cmd);
  611. } else {
  612. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  613. return -EOPNOTSUPP;
  614. }
  615. }
  616. /**
  617. * iwl_alive_start - called after REPLY_ALIVE notification received
  618. * from protocol/runtime uCode (initialization uCode's
  619. * Alive gets handled by iwl_init_alive_start()).
  620. */
  621. int iwl_alive_start(struct iwl_priv *priv)
  622. {
  623. int ret = 0;
  624. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  625. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  626. /* After the ALIVE response, we can send host commands to the uCode */
  627. set_bit(STATUS_ALIVE, &priv->status);
  628. /* Enable watchdog to monitor the driver tx queues */
  629. iwl_setup_watchdog(priv);
  630. if (iwl_is_rfkill(priv))
  631. return -ERFKILL;
  632. if (priv->event_log.ucode_trace) {
  633. /* start collecting data now */
  634. mod_timer(&priv->ucode_trace, jiffies);
  635. }
  636. /* download priority table before any calibration request */
  637. if (cfg(priv)->bt_params &&
  638. cfg(priv)->bt_params->advanced_bt_coexist) {
  639. /* Configure Bluetooth device coexistence support */
  640. if (cfg(priv)->bt_params->bt_sco_disable)
  641. priv->bt_enable_pspoll = false;
  642. else
  643. priv->bt_enable_pspoll = true;
  644. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  645. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  646. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  647. iwlagn_send_advance_bt_config(priv);
  648. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  649. priv->cur_rssi_ctx = NULL;
  650. iwl_send_prio_tbl(priv);
  651. /* FIXME: w/a to force change uCode BT state machine */
  652. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_OPEN,
  653. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  654. if (ret)
  655. return ret;
  656. ret = iwl_send_bt_env(priv, IWL_BT_COEX_ENV_CLOSE,
  657. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  658. if (ret)
  659. return ret;
  660. } else {
  661. /*
  662. * default is 2-wire BT coexexistence support
  663. */
  664. iwl_send_bt_config(priv);
  665. }
  666. /*
  667. * Perform runtime calibrations, including DC calibration.
  668. */
  669. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  670. ieee80211_wake_queues(priv->hw);
  671. priv->active_rate = IWL_RATES_MASK;
  672. /* Configure Tx antenna selection based on H/W config */
  673. iwlagn_send_tx_ant_config(priv, hw_params(priv).valid_tx_ant);
  674. if (iwl_is_associated_ctx(ctx) && !priv->wowlan) {
  675. struct iwl_rxon_cmd *active_rxon =
  676. (struct iwl_rxon_cmd *)&ctx->active;
  677. /* apply any changes in staging */
  678. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  679. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  680. } else {
  681. struct iwl_rxon_context *tmp;
  682. /* Initialize our rx_config data */
  683. for_each_context(priv, tmp)
  684. iwl_connection_init_rx_config(priv, tmp);
  685. iwlagn_set_rxon_chain(priv, ctx);
  686. }
  687. if (!priv->wowlan) {
  688. /* WoWLAN ucode will not reply in the same way, skip it */
  689. iwl_reset_run_time_calib(priv);
  690. }
  691. set_bit(STATUS_READY, &priv->status);
  692. /* Configure the adapter for unassociated operation */
  693. ret = iwlagn_commit_rxon(priv, ctx);
  694. if (ret)
  695. return ret;
  696. /* At this point, the NIC is initialized and operational */
  697. iwl_rf_kill_ct_config(priv);
  698. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  699. return iwl_power_update_mode(priv, true);
  700. }
  701. /**
  702. * iwl_clear_driver_stations - clear knowledge of all stations from driver
  703. * @priv: iwl priv struct
  704. *
  705. * This is called during iwl_down() to make sure that in the case
  706. * we're coming there from a hardware restart mac80211 will be
  707. * able to reconfigure stations -- if we're getting there in the
  708. * normal down flow then the stations will already be cleared.
  709. */
  710. static void iwl_clear_driver_stations(struct iwl_priv *priv)
  711. {
  712. struct iwl_rxon_context *ctx;
  713. spin_lock_bh(&priv->sta_lock);
  714. memset(priv->stations, 0, sizeof(priv->stations));
  715. priv->num_stations = 0;
  716. priv->ucode_key_table = 0;
  717. for_each_context(priv, ctx) {
  718. /*
  719. * Remove all key information that is not stored as part
  720. * of station information since mac80211 may not have had
  721. * a chance to remove all the keys. When device is
  722. * reconfigured by mac80211 after an error all keys will
  723. * be reconfigured.
  724. */
  725. memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
  726. ctx->key_mapping_keys = 0;
  727. }
  728. spin_unlock_bh(&priv->sta_lock);
  729. }
  730. void iwl_down(struct iwl_priv *priv)
  731. {
  732. int exit_pending;
  733. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  734. lockdep_assert_held(&priv->mutex);
  735. iwl_scan_cancel_timeout(priv, 200);
  736. /*
  737. * If active, scanning won't cancel it, so say it expired.
  738. * No race since we hold the mutex here and a new one
  739. * can't come in at this time.
  740. */
  741. ieee80211_remain_on_channel_expired(priv->hw);
  742. exit_pending =
  743. test_and_set_bit(STATUS_EXIT_PENDING, &priv->status);
  744. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  745. * to prevent rearm timer */
  746. del_timer_sync(&priv->watchdog);
  747. iwl_clear_ucode_stations(priv, NULL);
  748. iwl_dealloc_bcast_stations(priv);
  749. iwl_clear_driver_stations(priv);
  750. /* reset BT coex data */
  751. priv->bt_status = 0;
  752. priv->cur_rssi_ctx = NULL;
  753. priv->bt_is_sco = 0;
  754. if (cfg(priv)->bt_params)
  755. priv->bt_traffic_load =
  756. cfg(priv)->bt_params->bt_init_traffic_load;
  757. else
  758. priv->bt_traffic_load = 0;
  759. priv->bt_full_concurrent = false;
  760. priv->bt_ci_compliance = 0;
  761. /* Wipe out the EXIT_PENDING status bit if we are not actually
  762. * exiting the module */
  763. if (!exit_pending)
  764. clear_bit(STATUS_EXIT_PENDING, &priv->status);
  765. if (priv->mac80211_registered)
  766. ieee80211_stop_queues(priv->hw);
  767. priv->ucode_loaded = false;
  768. iwl_trans_stop_device(trans(priv));
  769. /* Clear out all status bits but a few that are stable across reset */
  770. priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
  771. STATUS_RF_KILL_HW |
  772. test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
  773. STATUS_GEO_CONFIGURED |
  774. test_bit(STATUS_EXIT_PENDING, &priv->status) <<
  775. STATUS_EXIT_PENDING;
  776. priv->shrd->status &=
  777. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  778. STATUS_FW_ERROR;
  779. dev_kfree_skb(priv->beacon_skb);
  780. priv->beacon_skb = NULL;
  781. }
  782. /*****************************************************************************
  783. *
  784. * Workqueue callbacks
  785. *
  786. *****************************************************************************/
  787. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  788. {
  789. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  790. run_time_calib_work);
  791. mutex_lock(&priv->mutex);
  792. if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
  793. test_bit(STATUS_SCANNING, &priv->status)) {
  794. mutex_unlock(&priv->mutex);
  795. return;
  796. }
  797. if (priv->start_calib) {
  798. iwl_chain_noise_calibration(priv);
  799. iwl_sensitivity_calibration(priv);
  800. }
  801. mutex_unlock(&priv->mutex);
  802. }
  803. void iwlagn_prepare_restart(struct iwl_priv *priv)
  804. {
  805. struct iwl_rxon_context *ctx;
  806. bool bt_full_concurrent;
  807. u8 bt_ci_compliance;
  808. u8 bt_load;
  809. u8 bt_status;
  810. bool bt_is_sco;
  811. int i;
  812. lockdep_assert_held(&priv->mutex);
  813. for_each_context(priv, ctx)
  814. ctx->vif = NULL;
  815. priv->is_open = 0;
  816. /*
  817. * __iwl_down() will clear the BT status variables,
  818. * which is correct, but when we restart we really
  819. * want to keep them so restore them afterwards.
  820. *
  821. * The restart process will later pick them up and
  822. * re-configure the hw when we reconfigure the BT
  823. * command.
  824. */
  825. bt_full_concurrent = priv->bt_full_concurrent;
  826. bt_ci_compliance = priv->bt_ci_compliance;
  827. bt_load = priv->bt_traffic_load;
  828. bt_status = priv->bt_status;
  829. bt_is_sco = priv->bt_is_sco;
  830. iwl_down(priv);
  831. priv->bt_full_concurrent = bt_full_concurrent;
  832. priv->bt_ci_compliance = bt_ci_compliance;
  833. priv->bt_traffic_load = bt_load;
  834. priv->bt_status = bt_status;
  835. priv->bt_is_sco = bt_is_sco;
  836. /* reset all queues */
  837. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  838. atomic_set(&priv->ac_stop_count[i], 0);
  839. for (i = IWLAGN_FIRST_AMPDU_QUEUE; i < IWL_MAX_HW_QUEUES; i++)
  840. priv->queue_to_ac[i] = IWL_INVALID_AC;
  841. memset(priv->agg_q_alloc, 0, sizeof(priv->agg_q_alloc));
  842. }
  843. static void iwl_bg_restart(struct work_struct *data)
  844. {
  845. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  846. if (test_bit(STATUS_EXIT_PENDING, &priv->status))
  847. return;
  848. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  849. mutex_lock(&priv->mutex);
  850. iwlagn_prepare_restart(priv);
  851. mutex_unlock(&priv->mutex);
  852. iwl_cancel_deferred_work(priv);
  853. ieee80211_restart_hw(priv->hw);
  854. } else {
  855. WARN_ON(1);
  856. }
  857. }
  858. void iwlagn_disable_roc(struct iwl_priv *priv)
  859. {
  860. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  861. lockdep_assert_held(&priv->mutex);
  862. if (!priv->hw_roc_setup)
  863. return;
  864. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  865. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  866. priv->hw_roc_channel = NULL;
  867. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  868. iwlagn_commit_rxon(priv, ctx);
  869. ctx->is_active = false;
  870. priv->hw_roc_setup = false;
  871. }
  872. static void iwlagn_disable_roc_work(struct work_struct *work)
  873. {
  874. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  875. hw_roc_disable_work.work);
  876. mutex_lock(&priv->mutex);
  877. iwlagn_disable_roc(priv);
  878. mutex_unlock(&priv->mutex);
  879. }
  880. /*****************************************************************************
  881. *
  882. * driver setup and teardown
  883. *
  884. *****************************************************************************/
  885. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  886. {
  887. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  888. INIT_WORK(&priv->restart, iwl_bg_restart);
  889. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  890. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  891. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  892. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  893. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  894. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  895. iwlagn_disable_roc_work);
  896. iwl_setup_scan_deferred_work(priv);
  897. if (cfg(priv)->bt_params)
  898. iwlagn_bt_setup_deferred_work(priv);
  899. init_timer(&priv->statistics_periodic);
  900. priv->statistics_periodic.data = (unsigned long)priv;
  901. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  902. init_timer(&priv->ucode_trace);
  903. priv->ucode_trace.data = (unsigned long)priv;
  904. priv->ucode_trace.function = iwl_bg_ucode_trace;
  905. init_timer(&priv->watchdog);
  906. priv->watchdog.data = (unsigned long)priv;
  907. priv->watchdog.function = iwl_bg_watchdog;
  908. }
  909. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  910. {
  911. if (cfg(priv)->bt_params)
  912. iwlagn_bt_cancel_deferred_work(priv);
  913. cancel_work_sync(&priv->run_time_calib_work);
  914. cancel_work_sync(&priv->beacon_update);
  915. iwl_cancel_scan_deferred_work(priv);
  916. cancel_work_sync(&priv->bt_full_concurrency);
  917. cancel_work_sync(&priv->bt_runtime_config);
  918. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  919. del_timer_sync(&priv->statistics_periodic);
  920. del_timer_sync(&priv->ucode_trace);
  921. }
  922. static void iwl_init_hw_rates(struct ieee80211_rate *rates)
  923. {
  924. int i;
  925. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  926. rates[i].bitrate = iwl_rates[i].ieee * 5;
  927. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  928. rates[i].hw_value_short = i;
  929. rates[i].flags = 0;
  930. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  931. /*
  932. * If CCK != 1M then set short preamble rate flag.
  933. */
  934. rates[i].flags |=
  935. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  936. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  937. }
  938. }
  939. }
  940. static int iwl_init_drv(struct iwl_priv *priv)
  941. {
  942. int ret;
  943. spin_lock_init(&priv->sta_lock);
  944. mutex_init(&priv->mutex);
  945. INIT_LIST_HEAD(&priv->calib_results);
  946. priv->ieee_channels = NULL;
  947. priv->ieee_rates = NULL;
  948. priv->band = IEEE80211_BAND_2GHZ;
  949. priv->plcp_delta_threshold =
  950. cfg(priv)->base_params->plcp_delta_threshold;
  951. priv->iw_mode = NL80211_IFTYPE_STATION;
  952. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  953. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  954. priv->agg_tids_count = 0;
  955. priv->ucode_owner = IWL_OWNERSHIP_DRIVER;
  956. /* initialize force reset */
  957. priv->force_reset[IWL_RF_RESET].reset_duration =
  958. IWL_DELAY_NEXT_FORCE_RF_RESET;
  959. priv->force_reset[IWL_FW_RESET].reset_duration =
  960. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  961. priv->rx_statistics_jiffies = jiffies;
  962. /* Choose which receivers/antennas to use */
  963. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  964. iwl_init_scan_params(priv);
  965. /* init bt coex */
  966. if (cfg(priv)->bt_params &&
  967. cfg(priv)->bt_params->advanced_bt_coexist) {
  968. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  969. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  970. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  971. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  972. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  973. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  974. }
  975. ret = iwl_init_channel_map(priv);
  976. if (ret) {
  977. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  978. goto err;
  979. }
  980. ret = iwl_init_geos(priv);
  981. if (ret) {
  982. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  983. goto err_free_channel_map;
  984. }
  985. iwl_init_hw_rates(priv->ieee_rates);
  986. return 0;
  987. err_free_channel_map:
  988. iwl_free_channel_map(priv);
  989. err:
  990. return ret;
  991. }
  992. static void iwl_uninit_drv(struct iwl_priv *priv)
  993. {
  994. iwl_free_geos(priv);
  995. iwl_free_channel_map(priv);
  996. kfree(priv->scan_cmd);
  997. kfree(priv->beacon_cmd);
  998. kfree(rcu_dereference_raw(priv->noa_data));
  999. iwl_calib_free_results(priv);
  1000. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1001. kfree(priv->wowlan_sram);
  1002. #endif
  1003. }
  1004. /* Size of one Rx buffer in host DRAM */
  1005. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  1006. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  1007. static void iwl_set_hw_params(struct iwl_priv *priv)
  1008. {
  1009. if (cfg(priv)->ht_params)
  1010. hw_params(priv).use_rts_for_aggregation =
  1011. cfg(priv)->ht_params->use_rts_for_aggregation;
  1012. if (iwlagn_mod_params.amsdu_size_8K)
  1013. hw_params(priv).rx_page_order =
  1014. get_order(IWL_RX_BUF_SIZE_8K);
  1015. else
  1016. hw_params(priv).rx_page_order =
  1017. get_order(IWL_RX_BUF_SIZE_4K);
  1018. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  1019. hw_params(priv).sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  1020. hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
  1021. /* Device-specific setup */
  1022. cfg(priv)->lib->set_hw_params(priv);
  1023. }
  1024. static void iwl_debug_config(struct iwl_priv *priv)
  1025. {
  1026. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  1027. #ifdef CONFIG_IWLWIFI_DEBUG
  1028. "enabled\n");
  1029. #else
  1030. "disabled\n");
  1031. #endif
  1032. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  1033. #ifdef CONFIG_IWLWIFI_DEBUGFS
  1034. "enabled\n");
  1035. #else
  1036. "disabled\n");
  1037. #endif
  1038. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  1039. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  1040. "enabled\n");
  1041. #else
  1042. "disabled\n");
  1043. #endif
  1044. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  1045. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  1046. "enabled\n");
  1047. #else
  1048. "disabled\n");
  1049. #endif
  1050. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_P2P "
  1051. #ifdef CONFIG_IWLWIFI_P2P
  1052. "enabled\n");
  1053. #else
  1054. "disabled\n");
  1055. #endif
  1056. }
  1057. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans,
  1058. const struct iwl_fw *fw)
  1059. {
  1060. struct iwl_priv *priv;
  1061. struct ieee80211_hw *hw;
  1062. struct iwl_op_mode *op_mode;
  1063. u16 num_mac;
  1064. u32 ucode_flags;
  1065. struct iwl_trans_config trans_cfg;
  1066. static const u8 no_reclaim_cmds[] = {
  1067. REPLY_RX_PHY_CMD,
  1068. REPLY_RX,
  1069. REPLY_RX_MPDU_CMD,
  1070. REPLY_COMPRESSED_BA,
  1071. STATISTICS_NOTIFICATION,
  1072. REPLY_TX,
  1073. };
  1074. const u8 *q_to_ac;
  1075. int n_q_to_ac;
  1076. int i;
  1077. /************************
  1078. * 1. Allocating HW data
  1079. ************************/
  1080. hw = iwl_alloc_all();
  1081. if (!hw) {
  1082. pr_err("%s: Cannot allocate network device\n",
  1083. cfg(trans)->name);
  1084. goto out;
  1085. }
  1086. op_mode = hw->priv;
  1087. op_mode->ops = &iwl_dvm_ops;
  1088. priv = IWL_OP_MODE_GET_DVM(op_mode);
  1089. priv->shrd = trans->shrd;
  1090. priv->fw = fw;
  1091. /* TODO: remove fw from shared data later */
  1092. priv->shrd->fw = fw;
  1093. /*
  1094. * Populate the state variables that the transport layer needs
  1095. * to know about.
  1096. */
  1097. trans_cfg.op_mode = op_mode;
  1098. trans_cfg.no_reclaim_cmds = no_reclaim_cmds;
  1099. trans_cfg.n_no_reclaim_cmds = ARRAY_SIZE(no_reclaim_cmds);
  1100. ucode_flags = fw->ucode_capa.flags;
  1101. #ifndef CONFIG_IWLWIFI_P2P
  1102. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1103. #endif
  1104. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1105. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1106. trans_cfg.cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1107. trans_cfg.queue_to_fifo = iwlagn_ipan_queue_to_tx_fifo;
  1108. trans_cfg.n_queue_to_fifo =
  1109. ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo);
  1110. q_to_ac = iwlagn_pan_queue_to_ac;
  1111. n_q_to_ac = ARRAY_SIZE(iwlagn_pan_queue_to_ac);
  1112. } else {
  1113. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1114. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1115. trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
  1116. trans_cfg.n_queue_to_fifo =
  1117. ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
  1118. q_to_ac = iwlagn_bss_queue_to_ac;
  1119. n_q_to_ac = ARRAY_SIZE(iwlagn_bss_queue_to_ac);
  1120. }
  1121. /* Configure transport layer */
  1122. iwl_trans_configure(trans(priv), &trans_cfg);
  1123. /* At this point both hw and priv are allocated. */
  1124. SET_IEEE80211_DEV(priv->hw, trans(priv)->dev);
  1125. /* show what debugging capabilities we have */
  1126. iwl_debug_config(priv);
  1127. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  1128. /* is antenna coupling more than 35dB ? */
  1129. priv->bt_ant_couple_ok =
  1130. (iwlagn_mod_params.ant_coupling >
  1131. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  1132. true : false;
  1133. /* enable/disable bt channel inhibition */
  1134. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  1135. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  1136. (priv->bt_ch_announce) ? "On" : "Off");
  1137. if (iwl_alloc_traffic_mem(priv))
  1138. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  1139. /* these spin locks will be used in apm_ops.init and EEPROM access
  1140. * we should init now
  1141. */
  1142. spin_lock_init(&trans(priv)->reg_lock);
  1143. spin_lock_init(&priv->statistics.lock);
  1144. /***********************
  1145. * 2. Read REV register
  1146. ***********************/
  1147. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  1148. cfg(priv)->name, trans(priv)->hw_rev);
  1149. if (iwl_trans_start_hw(trans(priv)))
  1150. goto out_free_traffic_mem;
  1151. /*****************
  1152. * 3. Read EEPROM
  1153. *****************/
  1154. /* Read the EEPROM */
  1155. if (iwl_eeprom_init(trans(priv), trans(priv)->hw_rev)) {
  1156. IWL_ERR(priv, "Unable to init EEPROM\n");
  1157. goto out_free_traffic_mem;
  1158. }
  1159. /* Reset chip to save power until we load uCode during "up". */
  1160. iwl_trans_stop_hw(trans(priv));
  1161. if (iwl_eeprom_check_version(priv))
  1162. goto out_free_eeprom;
  1163. if (iwl_eeprom_init_hw_params(priv))
  1164. goto out_free_eeprom;
  1165. /* extract MAC Address */
  1166. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1167. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1168. priv->hw->wiphy->addresses = priv->addresses;
  1169. priv->hw->wiphy->n_addresses = 1;
  1170. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1171. if (num_mac > 1) {
  1172. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1173. ETH_ALEN);
  1174. priv->addresses[1].addr[5]++;
  1175. priv->hw->wiphy->n_addresses++;
  1176. }
  1177. /************************
  1178. * 4. Setup HW constants
  1179. ************************/
  1180. iwl_set_hw_params(priv);
  1181. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_IPAN_ENABLE)) {
  1182. IWL_DEBUG_INFO(priv, "Your EEPROM disabled PAN");
  1183. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1184. /*
  1185. * if not PAN, then don't support P2P -- might be a uCode
  1186. * packaging bug or due to the eeprom check above
  1187. */
  1188. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1189. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1190. trans_cfg.cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1191. trans_cfg.queue_to_fifo = iwlagn_default_queue_to_tx_fifo;
  1192. trans_cfg.n_queue_to_fifo =
  1193. ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo);
  1194. q_to_ac = iwlagn_bss_queue_to_ac;
  1195. n_q_to_ac = ARRAY_SIZE(iwlagn_bss_queue_to_ac);
  1196. /* Configure transport layer again*/
  1197. iwl_trans_configure(trans(priv), &trans_cfg);
  1198. }
  1199. /*******************
  1200. * 5. Setup priv
  1201. *******************/
  1202. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1203. atomic_set(&priv->ac_stop_count[i], 0);
  1204. for (i = 0; i < IWL_MAX_HW_QUEUES; i++) {
  1205. if (i < n_q_to_ac)
  1206. priv->queue_to_ac[i] = q_to_ac[i];
  1207. else
  1208. priv->queue_to_ac[i] = IWL_INVALID_AC;
  1209. }
  1210. WARN_ON(trans_cfg.queue_to_fifo[trans_cfg.cmd_queue] !=
  1211. IWLAGN_CMD_FIFO_NUM);
  1212. if (iwl_init_drv(priv))
  1213. goto out_free_eeprom;
  1214. /* At this point both hw and priv are initialized. */
  1215. /********************
  1216. * 6. Setup services
  1217. ********************/
  1218. iwl_setup_deferred_work(priv);
  1219. iwl_setup_rx_handlers(priv);
  1220. iwl_testmode_init(priv);
  1221. iwl_power_initialize(priv);
  1222. iwl_tt_initialize(priv);
  1223. snprintf(priv->hw->wiphy->fw_version,
  1224. sizeof(priv->hw->wiphy->fw_version),
  1225. "%s", fw->fw_version);
  1226. priv->new_scan_threshold_behaviour =
  1227. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1228. priv->phy_calib_chain_noise_reset_cmd =
  1229. fw->ucode_capa.standard_phy_calibration_size;
  1230. priv->phy_calib_chain_noise_gain_cmd =
  1231. fw->ucode_capa.standard_phy_calibration_size + 1;
  1232. /* initialize all valid contexts */
  1233. iwl_init_context(priv, ucode_flags);
  1234. /**************************************************
  1235. * This is still part of probe() in a sense...
  1236. *
  1237. * 7. Setup and register with mac80211 and debugfs
  1238. **************************************************/
  1239. if (iwlagn_mac_setup_register(priv, &fw->ucode_capa))
  1240. goto out_destroy_workqueue;
  1241. if (iwl_dbgfs_register(priv, DRV_NAME))
  1242. IWL_ERR(priv,
  1243. "failed to create debugfs files. Ignoring error\n");
  1244. return op_mode;
  1245. out_destroy_workqueue:
  1246. destroy_workqueue(priv->workqueue);
  1247. priv->workqueue = NULL;
  1248. iwl_uninit_drv(priv);
  1249. out_free_eeprom:
  1250. iwl_eeprom_free(priv->shrd);
  1251. out_free_traffic_mem:
  1252. iwl_free_traffic_mem(priv);
  1253. ieee80211_free_hw(priv->hw);
  1254. out:
  1255. op_mode = NULL;
  1256. return op_mode;
  1257. }
  1258. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1259. {
  1260. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1261. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1262. iwl_dbgfs_unregister(priv);
  1263. iwl_testmode_cleanup(priv);
  1264. iwlagn_mac_unregister(priv);
  1265. iwl_tt_exit(priv);
  1266. /*This will stop the queues, move the device to low power state */
  1267. priv->ucode_loaded = false;
  1268. iwl_trans_stop_device(trans(priv));
  1269. iwl_eeprom_free(priv->shrd);
  1270. /*netif_stop_queue(dev); */
  1271. flush_workqueue(priv->workqueue);
  1272. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1273. * priv->workqueue... so we can't take down the workqueue
  1274. * until now... */
  1275. destroy_workqueue(priv->workqueue);
  1276. priv->workqueue = NULL;
  1277. iwl_free_traffic_mem(priv);
  1278. iwl_uninit_drv(priv);
  1279. dev_kfree_skb(priv->beacon_skb);
  1280. ieee80211_free_hw(priv->hw);
  1281. }
  1282. static void iwl_nic_error(struct iwl_op_mode *op_mode)
  1283. {
  1284. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1285. iwlagn_fw_error(priv, false);
  1286. }
  1287. static void iwl_cmd_queue_full(struct iwl_op_mode *op_mode)
  1288. {
  1289. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1290. if (!iwl_check_for_ct_kill(priv)) {
  1291. IWL_ERR(priv, "Restarting adapter queue is full\n");
  1292. iwlagn_fw_error(priv, false);
  1293. }
  1294. }
  1295. static void iwl_nic_config(struct iwl_op_mode *op_mode)
  1296. {
  1297. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1298. cfg(priv)->lib->nic_config(priv);
  1299. }
  1300. static void iwl_stop_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1301. {
  1302. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1303. int ac = priv->queue_to_ac[queue];
  1304. if (WARN_ON_ONCE(ac == IWL_INVALID_AC))
  1305. return;
  1306. if (atomic_inc_return(&priv->ac_stop_count[ac]) > 1) {
  1307. IWL_DEBUG_TX_QUEUES(priv,
  1308. "queue %d (AC %d) already stopped\n",
  1309. queue, ac);
  1310. return;
  1311. }
  1312. set_bit(ac, &priv->transport_queue_stop);
  1313. ieee80211_stop_queue(priv->hw, ac);
  1314. }
  1315. static void iwl_wake_sw_queue(struct iwl_op_mode *op_mode, int queue)
  1316. {
  1317. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1318. int ac = priv->queue_to_ac[queue];
  1319. if (WARN_ON_ONCE(ac == IWL_INVALID_AC))
  1320. return;
  1321. if (atomic_dec_return(&priv->ac_stop_count[ac]) > 0) {
  1322. IWL_DEBUG_TX_QUEUES(priv,
  1323. "queue %d (AC %d) already awake\n",
  1324. queue, ac);
  1325. return;
  1326. }
  1327. clear_bit(ac, &priv->transport_queue_stop);
  1328. if (!priv->passive_no_rx)
  1329. ieee80211_wake_queue(priv->hw, ac);
  1330. }
  1331. void iwlagn_lift_passive_no_rx(struct iwl_priv *priv)
  1332. {
  1333. int ac;
  1334. if (!priv->passive_no_rx)
  1335. return;
  1336. for (ac = IEEE80211_AC_VO; ac < IEEE80211_NUM_ACS; ac++) {
  1337. if (!test_bit(ac, &priv->transport_queue_stop)) {
  1338. IWL_DEBUG_TX_QUEUES(priv, "Wake queue %d");
  1339. ieee80211_wake_queue(priv->hw, ac);
  1340. } else {
  1341. IWL_DEBUG_TX_QUEUES(priv, "Don't wake queue %d");
  1342. }
  1343. }
  1344. priv->passive_no_rx = false;
  1345. }
  1346. const struct iwl_op_mode_ops iwl_dvm_ops = {
  1347. .start = iwl_op_mode_dvm_start,
  1348. .stop = iwl_op_mode_dvm_stop,
  1349. .rx = iwl_rx_dispatch,
  1350. .queue_full = iwl_stop_sw_queue,
  1351. .queue_not_full = iwl_wake_sw_queue,
  1352. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1353. .free_skb = iwl_free_skb,
  1354. .nic_error = iwl_nic_error,
  1355. .cmd_queue_full = iwl_cmd_queue_full,
  1356. .nic_config = iwl_nic_config,
  1357. };
  1358. /*****************************************************************************
  1359. *
  1360. * driver and module entry point
  1361. *
  1362. *****************************************************************************/
  1363. struct kmem_cache *iwl_tx_cmd_pool;
  1364. static int __init iwl_init(void)
  1365. {
  1366. int ret;
  1367. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1368. pr_info(DRV_COPYRIGHT "\n");
  1369. iwl_tx_cmd_pool = kmem_cache_create("iwl_dev_cmd",
  1370. sizeof(struct iwl_device_cmd),
  1371. sizeof(void *), 0, NULL);
  1372. if (!iwl_tx_cmd_pool)
  1373. return -ENOMEM;
  1374. ret = iwlagn_rate_control_register();
  1375. if (ret) {
  1376. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1377. goto error_rc_register;
  1378. }
  1379. ret = iwl_pci_register_driver();
  1380. if (ret)
  1381. goto error_pci_register;
  1382. return ret;
  1383. error_pci_register:
  1384. iwlagn_rate_control_unregister();
  1385. error_rc_register:
  1386. kmem_cache_destroy(iwl_tx_cmd_pool);
  1387. return ret;
  1388. }
  1389. static void __exit iwl_exit(void)
  1390. {
  1391. iwl_pci_unregister_driver();
  1392. iwlagn_rate_control_unregister();
  1393. kmem_cache_destroy(iwl_tx_cmd_pool);
  1394. }
  1395. module_exit(iwl_exit);
  1396. module_init(iwl_init);
  1397. #ifdef CONFIG_IWLWIFI_DEBUG
  1398. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1399. S_IRUGO | S_IWUSR);
  1400. MODULE_PARM_DESC(debug, "debug output mask");
  1401. #endif
  1402. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1403. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1404. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  1405. MODULE_PARM_DESC(11n_disable,
  1406. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1407. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1408. int, S_IRUGO);
  1409. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1410. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1411. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1412. module_param_named(ucode_alternative,
  1413. iwlagn_mod_params.wanted_ucode_alternative,
  1414. int, S_IRUGO);
  1415. MODULE_PARM_DESC(ucode_alternative,
  1416. "specify ucode alternative to use from ucode file");
  1417. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1418. int, S_IRUGO);
  1419. MODULE_PARM_DESC(antenna_coupling,
  1420. "specify antenna coupling in dB (defualt: 0 dB)");
  1421. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1422. bool, S_IRUGO);
  1423. MODULE_PARM_DESC(bt_ch_inhibition,
  1424. "Enable BT channel inhibition (default: enable)");
  1425. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1426. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1427. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1428. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1429. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1430. MODULE_PARM_DESC(wd_disable,
  1431. "Disable stuck queue watchdog timer 0=system default, "
  1432. "1=disable, 2=enable (default: 0)");
  1433. /*
  1434. * set bt_coex_active to true, uCode will do kill/defer
  1435. * every time the priority line is asserted (BT is sending signals on the
  1436. * priority line in the PCIx).
  1437. * set bt_coex_active to false, uCode will ignore the BT activity and
  1438. * perform the normal operation
  1439. *
  1440. * User might experience transmit issue on some platform due to WiFi/BT
  1441. * co-exist problem. The possible behaviors are:
  1442. * Able to scan and finding all the available AP
  1443. * Not able to associate with any AP
  1444. * On those platforms, WiFi communication can be restored by set
  1445. * "bt_coex_active" module parameter to "false"
  1446. *
  1447. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1448. */
  1449. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1450. bool, S_IRUGO);
  1451. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1452. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1453. MODULE_PARM_DESC(led_mode, "0=system default, "
  1454. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1455. module_param_named(power_save, iwlagn_mod_params.power_save,
  1456. bool, S_IRUGO);
  1457. MODULE_PARM_DESC(power_save,
  1458. "enable WiFi power management (default: disable)");
  1459. module_param_named(power_level, iwlagn_mod_params.power_level,
  1460. int, S_IRUGO);
  1461. MODULE_PARM_DESC(power_level,
  1462. "default power save level (range from 1 - 5, default: 1)");
  1463. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1464. bool, S_IRUGO);
  1465. MODULE_PARM_DESC(auto_agg,
  1466. "enable agg w/o check traffic load (default: enable)");
  1467. /*
  1468. * For now, keep using power level 1 instead of automatically
  1469. * adjusting ...
  1470. */
  1471. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1472. bool, S_IRUGO);
  1473. MODULE_PARM_DESC(no_sleep_autoadjust,
  1474. "don't automatically adjust sleep level "
  1475. "according to maximum network latency (default: true)");