iwl-agn.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526
  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-ucode.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-trans.h"
  51. #include "iwl-op-mode.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 capacity, 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(&trans(priv)->reg_lock, reg_flags);
  276. if (iwl_grab_nic_access(trans(priv))) {
  277. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  278. return;
  279. }
  280. /* Set starting address; reads will auto-increment */
  281. iwl_write32(trans(priv), HBUS_TARG_MEM_RADDR, ptr);
  282. rmb();
  283. /*
  284. * Refuse to read more than would have fit into the log from
  285. * the current start_idx. This used to happen due to the race
  286. * described below, but now WARN because the code below should
  287. * prevent it from happening here.
  288. */
  289. if (WARN_ON(num_events > capacity - start_idx))
  290. num_events = capacity - start_idx;
  291. /*
  292. * "time" is actually "data" for mode 0 (no timestamp).
  293. * place event id # at far right for easier visual parsing.
  294. */
  295. for (i = 0; i < num_events; i++) {
  296. ev = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  297. time = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  298. if (mode == 0) {
  299. trace_iwlwifi_dev_ucode_cont_event(priv, 0, time, ev);
  300. } else {
  301. data = iwl_read32(trans(priv), HBUS_TARG_MEM_RDAT);
  302. trace_iwlwifi_dev_ucode_cont_event(priv, time,
  303. data, ev);
  304. }
  305. }
  306. /* Allow device to power down */
  307. iwl_release_nic_access(trans(priv));
  308. spin_unlock_irqrestore(&trans(priv)->reg_lock, reg_flags);
  309. }
  310. static void iwl_continuous_event_trace(struct iwl_priv *priv)
  311. {
  312. u32 capacity; /* event log capacity in # entries */
  313. struct {
  314. u32 capacity;
  315. u32 mode;
  316. u32 wrap_counter;
  317. u32 write_counter;
  318. } __packed read;
  319. u32 base; /* SRAM byte address of event log header */
  320. u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
  321. u32 num_wraps; /* # times uCode wrapped to top of log */
  322. u32 next_entry; /* index of next entry to be written by uCode */
  323. base = priv->shrd->device_pointers.log_event_table;
  324. if (iwlagn_hw_valid_rtc_data_addr(base)) {
  325. iwl_read_targ_mem_words(trans(priv), base, &read, sizeof(read));
  326. capacity = read.capacity;
  327. mode = read.mode;
  328. num_wraps = read.wrap_counter;
  329. next_entry = read.write_counter;
  330. } else
  331. return;
  332. /*
  333. * Unfortunately, the uCode doesn't use temporary variables.
  334. * Therefore, it can happen that we read next_entry == capacity,
  335. * which really means next_entry == 0.
  336. */
  337. if (unlikely(next_entry == capacity))
  338. next_entry = 0;
  339. /*
  340. * Additionally, the uCode increases the write pointer before
  341. * the wraps counter, so if the write pointer is smaller than
  342. * the old write pointer (wrap occurred) but we read that no
  343. * wrap occurred, we actually read between the next_entry and
  344. * num_wraps update (this does happen in practice!!) -- take
  345. * that into account by increasing num_wraps.
  346. */
  347. if (unlikely(next_entry < priv->event_log.next_entry &&
  348. num_wraps == priv->event_log.num_wraps))
  349. num_wraps++;
  350. if (num_wraps == priv->event_log.num_wraps) {
  351. iwl_print_cont_event_trace(
  352. priv, base, priv->event_log.next_entry,
  353. next_entry - priv->event_log.next_entry,
  354. capacity, mode);
  355. priv->event_log.non_wraps_count++;
  356. } else {
  357. if (num_wraps - priv->event_log.num_wraps > 1)
  358. priv->event_log.wraps_more_count++;
  359. else
  360. priv->event_log.wraps_once_count++;
  361. trace_iwlwifi_dev_ucode_wrap_event(priv,
  362. num_wraps - priv->event_log.num_wraps,
  363. next_entry, priv->event_log.next_entry);
  364. if (next_entry < priv->event_log.next_entry) {
  365. iwl_print_cont_event_trace(
  366. priv, base, priv->event_log.next_entry,
  367. capacity - priv->event_log.next_entry,
  368. capacity, mode);
  369. iwl_print_cont_event_trace(
  370. priv, base, 0, next_entry, capacity, mode);
  371. } else {
  372. iwl_print_cont_event_trace(
  373. priv, base, next_entry,
  374. capacity - next_entry,
  375. capacity, mode);
  376. iwl_print_cont_event_trace(
  377. priv, base, 0, next_entry, capacity, mode);
  378. }
  379. }
  380. priv->event_log.num_wraps = num_wraps;
  381. priv->event_log.next_entry = next_entry;
  382. }
  383. /**
  384. * iwl_bg_ucode_trace - Timer callback to log ucode event
  385. *
  386. * The timer is continually set to execute every
  387. * UCODE_TRACE_PERIOD milliseconds after the last timer expired
  388. * this function is to perform continuous uCode event logging operation
  389. * if enabled
  390. */
  391. static void iwl_bg_ucode_trace(unsigned long data)
  392. {
  393. struct iwl_priv *priv = (struct iwl_priv *)data;
  394. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  395. return;
  396. if (priv->event_log.ucode_trace) {
  397. iwl_continuous_event_trace(priv);
  398. /* Reschedule the timer to occur in UCODE_TRACE_PERIOD */
  399. mod_timer(&priv->ucode_trace,
  400. jiffies + msecs_to_jiffies(UCODE_TRACE_PERIOD));
  401. }
  402. }
  403. static void iwl_bg_tx_flush(struct work_struct *work)
  404. {
  405. struct iwl_priv *priv =
  406. container_of(work, struct iwl_priv, tx_flush);
  407. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  408. return;
  409. /* do nothing if rf-kill is on */
  410. if (!iwl_is_ready_rf(priv->shrd))
  411. return;
  412. IWL_DEBUG_INFO(priv, "device request: flush all tx frames\n");
  413. iwlagn_dev_txfifo_flush(priv, IWL_DROP_ALL);
  414. }
  415. void iwl_init_context(struct iwl_priv *priv, u32 ucode_flags)
  416. {
  417. int i;
  418. /*
  419. * The default context is always valid,
  420. * the PAN context depends on uCode.
  421. */
  422. priv->shrd->valid_contexts = BIT(IWL_RXON_CTX_BSS);
  423. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN)
  424. priv->shrd->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
  425. for (i = 0; i < NUM_IWL_RXON_CTX; i++)
  426. priv->contexts[i].ctxid = i;
  427. priv->contexts[IWL_RXON_CTX_BSS].always_active = true;
  428. priv->contexts[IWL_RXON_CTX_BSS].is_active = true;
  429. priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
  430. priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
  431. priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
  432. priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
  433. priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
  434. priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
  435. priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
  436. priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
  437. BIT(NL80211_IFTYPE_ADHOC);
  438. priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
  439. BIT(NL80211_IFTYPE_STATION);
  440. priv->contexts[IWL_RXON_CTX_BSS].ap_devtype = RXON_DEV_TYPE_AP;
  441. priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
  442. priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
  443. priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
  444. priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
  445. priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd =
  446. REPLY_WIPAN_RXON_TIMING;
  447. priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd =
  448. REPLY_WIPAN_RXON_ASSOC;
  449. priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
  450. priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
  451. priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
  452. priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
  453. priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
  454. priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
  455. BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
  456. if (ucode_flags & IWL_UCODE_TLV_FLAGS_P2P)
  457. priv->contexts[IWL_RXON_CTX_PAN].interface_modes |=
  458. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  459. BIT(NL80211_IFTYPE_P2P_GO);
  460. priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
  461. priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
  462. priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
  463. BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
  464. }
  465. static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
  466. {
  467. struct iwl_ct_kill_config cmd;
  468. struct iwl_ct_kill_throttling_config adv_cmd;
  469. unsigned long flags;
  470. int ret = 0;
  471. spin_lock_irqsave(&priv->shrd->lock, flags);
  472. iwl_write32(trans(priv), CSR_UCODE_DRV_GP1_CLR,
  473. CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
  474. spin_unlock_irqrestore(&priv->shrd->lock, flags);
  475. priv->thermal_throttle.ct_kill_toggle = false;
  476. if (cfg(priv)->base_params->support_ct_kill_exit) {
  477. adv_cmd.critical_temperature_enter =
  478. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  479. adv_cmd.critical_temperature_exit =
  480. cpu_to_le32(hw_params(priv).ct_kill_exit_threshold);
  481. ret = iwl_trans_send_cmd_pdu(trans(priv),
  482. REPLY_CT_KILL_CONFIG_CMD,
  483. CMD_SYNC, sizeof(adv_cmd), &adv_cmd);
  484. if (ret)
  485. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  486. else
  487. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  488. "succeeded, critical temperature enter is %d,"
  489. "exit is %d\n",
  490. hw_params(priv).ct_kill_threshold,
  491. hw_params(priv).ct_kill_exit_threshold);
  492. } else {
  493. cmd.critical_temperature_R =
  494. cpu_to_le32(hw_params(priv).ct_kill_threshold);
  495. ret = iwl_trans_send_cmd_pdu(trans(priv),
  496. REPLY_CT_KILL_CONFIG_CMD,
  497. CMD_SYNC, sizeof(cmd), &cmd);
  498. if (ret)
  499. IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
  500. else
  501. IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
  502. "succeeded, "
  503. "critical temperature is %d\n",
  504. hw_params(priv).ct_kill_threshold);
  505. }
  506. }
  507. static int iwlagn_send_calib_cfg_rt(struct iwl_priv *priv, u32 cfg)
  508. {
  509. struct iwl_calib_cfg_cmd calib_cfg_cmd;
  510. struct iwl_host_cmd cmd = {
  511. .id = CALIBRATION_CFG_CMD,
  512. .len = { sizeof(struct iwl_calib_cfg_cmd), },
  513. .data = { &calib_cfg_cmd, },
  514. };
  515. memset(&calib_cfg_cmd, 0, sizeof(calib_cfg_cmd));
  516. calib_cfg_cmd.ucd_calib_cfg.once.is_enable = IWL_CALIB_RT_CFG_ALL;
  517. calib_cfg_cmd.ucd_calib_cfg.once.start = cpu_to_le32(cfg);
  518. return iwl_trans_send_cmd(trans(priv), &cmd);
  519. }
  520. static int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant)
  521. {
  522. struct iwl_tx_ant_config_cmd tx_ant_cmd = {
  523. .valid = cpu_to_le32(valid_tx_ant),
  524. };
  525. if (IWL_UCODE_API(nic(priv)->fw.ucode_ver) > 1) {
  526. IWL_DEBUG_HC(priv, "select valid tx ant: %u\n", valid_tx_ant);
  527. return iwl_trans_send_cmd_pdu(trans(priv),
  528. TX_ANT_CONFIGURATION_CMD,
  529. CMD_SYNC,
  530. sizeof(struct iwl_tx_ant_config_cmd),
  531. &tx_ant_cmd);
  532. } else {
  533. IWL_DEBUG_HC(priv, "TX_ANT_CONFIGURATION_CMD not supported\n");
  534. return -EOPNOTSUPP;
  535. }
  536. }
  537. /**
  538. * iwl_alive_start - called after REPLY_ALIVE notification received
  539. * from protocol/runtime uCode (initialization uCode's
  540. * Alive gets handled by iwl_init_alive_start()).
  541. */
  542. int iwl_alive_start(struct iwl_priv *priv)
  543. {
  544. int ret = 0;
  545. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
  546. IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
  547. /* After the ALIVE response, we can send host commands to the uCode */
  548. set_bit(STATUS_ALIVE, &priv->shrd->status);
  549. /* Enable watchdog to monitor the driver tx queues */
  550. iwl_setup_watchdog(priv);
  551. if (iwl_is_rfkill(priv->shrd))
  552. return -ERFKILL;
  553. if (priv->event_log.ucode_trace) {
  554. /* start collecting data now */
  555. mod_timer(&priv->ucode_trace, jiffies);
  556. }
  557. /* download priority table before any calibration request */
  558. if (cfg(priv)->bt_params &&
  559. cfg(priv)->bt_params->advanced_bt_coexist) {
  560. /* Configure Bluetooth device coexistence support */
  561. if (cfg(priv)->bt_params->bt_sco_disable)
  562. priv->bt_enable_pspoll = false;
  563. else
  564. priv->bt_enable_pspoll = true;
  565. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  566. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  567. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  568. iwlagn_send_advance_bt_config(priv);
  569. priv->bt_valid = IWLAGN_BT_VALID_ENABLE_FLAGS;
  570. priv->cur_rssi_ctx = NULL;
  571. iwl_send_prio_tbl(trans(priv));
  572. /* FIXME: w/a to force change uCode BT state machine */
  573. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_OPEN,
  574. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  575. if (ret)
  576. return ret;
  577. ret = iwl_send_bt_env(trans(priv), IWL_BT_COEX_ENV_CLOSE,
  578. BT_COEX_PRIO_TBL_EVT_INIT_CALIB2);
  579. if (ret)
  580. return ret;
  581. } else {
  582. /*
  583. * default is 2-wire BT coexexistence support
  584. */
  585. iwl_send_bt_config(priv);
  586. }
  587. /*
  588. * Perform runtime calibrations, including DC calibration.
  589. */
  590. iwlagn_send_calib_cfg_rt(priv, IWL_CALIB_CFG_DC_IDX);
  591. ieee80211_wake_queues(priv->hw);
  592. priv->active_rate = IWL_RATES_MASK;
  593. /* Configure Tx antenna selection based on H/W config */
  594. iwlagn_send_tx_ant_config(priv, cfg(priv)->valid_tx_ant);
  595. if (iwl_is_associated_ctx(ctx) && !priv->shrd->wowlan) {
  596. struct iwl_rxon_cmd *active_rxon =
  597. (struct iwl_rxon_cmd *)&ctx->active;
  598. /* apply any changes in staging */
  599. ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
  600. active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  601. } else {
  602. struct iwl_rxon_context *tmp;
  603. /* Initialize our rx_config data */
  604. for_each_context(priv, tmp)
  605. iwl_connection_init_rx_config(priv, tmp);
  606. iwlagn_set_rxon_chain(priv, ctx);
  607. }
  608. if (!priv->shrd->wowlan) {
  609. /* WoWLAN ucode will not reply in the same way, skip it */
  610. iwl_reset_run_time_calib(priv);
  611. }
  612. set_bit(STATUS_READY, &priv->shrd->status);
  613. /* Configure the adapter for unassociated operation */
  614. ret = iwlagn_commit_rxon(priv, ctx);
  615. if (ret)
  616. return ret;
  617. /* At this point, the NIC is initialized and operational */
  618. iwl_rf_kill_ct_config(priv);
  619. IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
  620. return iwl_power_update_mode(priv, true);
  621. }
  622. void iwl_down(struct iwl_priv *priv)
  623. {
  624. int exit_pending;
  625. IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
  626. lockdep_assert_held(&priv->shrd->mutex);
  627. iwl_scan_cancel_timeout(priv, 200);
  628. /*
  629. * If active, scanning won't cancel it, so say it expired.
  630. * No race since we hold the mutex here and a new one
  631. * can't come in at this time.
  632. */
  633. ieee80211_remain_on_channel_expired(priv->hw);
  634. exit_pending =
  635. test_and_set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  636. /* Stop TX queues watchdog. We need to have STATUS_EXIT_PENDING bit set
  637. * to prevent rearm timer */
  638. del_timer_sync(&priv->watchdog);
  639. iwl_clear_ucode_stations(priv, NULL);
  640. iwl_dealloc_bcast_stations(priv);
  641. iwl_clear_driver_stations(priv);
  642. /* reset BT coex data */
  643. priv->bt_status = 0;
  644. priv->cur_rssi_ctx = NULL;
  645. priv->bt_is_sco = 0;
  646. if (cfg(priv)->bt_params)
  647. priv->bt_traffic_load =
  648. cfg(priv)->bt_params->bt_init_traffic_load;
  649. else
  650. priv->bt_traffic_load = 0;
  651. priv->bt_full_concurrent = false;
  652. priv->bt_ci_compliance = 0;
  653. /* Wipe out the EXIT_PENDING status bit if we are not actually
  654. * exiting the module */
  655. if (!exit_pending)
  656. clear_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  657. if (priv->mac80211_registered)
  658. ieee80211_stop_queues(priv->hw);
  659. iwl_trans_stop_device(trans(priv));
  660. /* Clear out all status bits but a few that are stable across reset */
  661. priv->shrd->status &=
  662. test_bit(STATUS_RF_KILL_HW, &priv->shrd->status) <<
  663. STATUS_RF_KILL_HW |
  664. test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) <<
  665. STATUS_GEO_CONFIGURED |
  666. test_bit(STATUS_FW_ERROR, &priv->shrd->status) <<
  667. STATUS_FW_ERROR |
  668. test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) <<
  669. STATUS_EXIT_PENDING;
  670. dev_kfree_skb(priv->beacon_skb);
  671. priv->beacon_skb = NULL;
  672. }
  673. /*****************************************************************************
  674. *
  675. * Workqueue callbacks
  676. *
  677. *****************************************************************************/
  678. static void iwl_bg_run_time_calib_work(struct work_struct *work)
  679. {
  680. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  681. run_time_calib_work);
  682. mutex_lock(&priv->shrd->mutex);
  683. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status) ||
  684. test_bit(STATUS_SCANNING, &priv->shrd->status)) {
  685. mutex_unlock(&priv->shrd->mutex);
  686. return;
  687. }
  688. if (priv->start_calib) {
  689. iwl_chain_noise_calibration(priv);
  690. iwl_sensitivity_calibration(priv);
  691. }
  692. mutex_unlock(&priv->shrd->mutex);
  693. }
  694. void iwlagn_prepare_restart(struct iwl_priv *priv)
  695. {
  696. struct iwl_rxon_context *ctx;
  697. bool bt_full_concurrent;
  698. u8 bt_ci_compliance;
  699. u8 bt_load;
  700. u8 bt_status;
  701. bool bt_is_sco;
  702. lockdep_assert_held(&priv->shrd->mutex);
  703. for_each_context(priv, ctx)
  704. ctx->vif = NULL;
  705. priv->is_open = 0;
  706. /*
  707. * __iwl_down() will clear the BT status variables,
  708. * which is correct, but when we restart we really
  709. * want to keep them so restore them afterwards.
  710. *
  711. * The restart process will later pick them up and
  712. * re-configure the hw when we reconfigure the BT
  713. * command.
  714. */
  715. bt_full_concurrent = priv->bt_full_concurrent;
  716. bt_ci_compliance = priv->bt_ci_compliance;
  717. bt_load = priv->bt_traffic_load;
  718. bt_status = priv->bt_status;
  719. bt_is_sco = priv->bt_is_sco;
  720. iwl_down(priv);
  721. priv->bt_full_concurrent = bt_full_concurrent;
  722. priv->bt_ci_compliance = bt_ci_compliance;
  723. priv->bt_traffic_load = bt_load;
  724. priv->bt_status = bt_status;
  725. priv->bt_is_sco = bt_is_sco;
  726. }
  727. static void iwl_bg_restart(struct work_struct *data)
  728. {
  729. struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
  730. if (test_bit(STATUS_EXIT_PENDING, &priv->shrd->status))
  731. return;
  732. if (test_and_clear_bit(STATUS_FW_ERROR, &priv->shrd->status)) {
  733. mutex_lock(&priv->shrd->mutex);
  734. iwlagn_prepare_restart(priv);
  735. mutex_unlock(&priv->shrd->mutex);
  736. iwl_cancel_deferred_work(priv);
  737. ieee80211_restart_hw(priv->hw);
  738. } else {
  739. WARN_ON(1);
  740. }
  741. }
  742. void iwlagn_disable_roc(struct iwl_priv *priv)
  743. {
  744. struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_PAN];
  745. lockdep_assert_held(&priv->shrd->mutex);
  746. if (!priv->hw_roc_setup)
  747. return;
  748. ctx->staging.dev_type = RXON_DEV_TYPE_P2P;
  749. ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
  750. priv->hw_roc_channel = NULL;
  751. memset(ctx->staging.node_addr, 0, ETH_ALEN);
  752. iwlagn_commit_rxon(priv, ctx);
  753. ctx->is_active = false;
  754. priv->hw_roc_setup = false;
  755. }
  756. static void iwlagn_disable_roc_work(struct work_struct *work)
  757. {
  758. struct iwl_priv *priv = container_of(work, struct iwl_priv,
  759. hw_roc_disable_work.work);
  760. mutex_lock(&priv->shrd->mutex);
  761. iwlagn_disable_roc(priv);
  762. mutex_unlock(&priv->shrd->mutex);
  763. }
  764. /*****************************************************************************
  765. *
  766. * driver setup and teardown
  767. *
  768. *****************************************************************************/
  769. static void iwl_setup_deferred_work(struct iwl_priv *priv)
  770. {
  771. priv->workqueue = create_singlethread_workqueue(DRV_NAME);
  772. init_waitqueue_head(&priv->shrd->wait_command_queue);
  773. INIT_WORK(&priv->restart, iwl_bg_restart);
  774. INIT_WORK(&priv->beacon_update, iwl_bg_beacon_update);
  775. INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
  776. INIT_WORK(&priv->tx_flush, iwl_bg_tx_flush);
  777. INIT_WORK(&priv->bt_full_concurrency, iwl_bg_bt_full_concurrency);
  778. INIT_WORK(&priv->bt_runtime_config, iwl_bg_bt_runtime_config);
  779. INIT_DELAYED_WORK(&priv->hw_roc_disable_work,
  780. iwlagn_disable_roc_work);
  781. iwl_setup_scan_deferred_work(priv);
  782. if (cfg(priv)->lib->bt_setup_deferred_work)
  783. cfg(priv)->lib->bt_setup_deferred_work(priv);
  784. init_timer(&priv->statistics_periodic);
  785. priv->statistics_periodic.data = (unsigned long)priv;
  786. priv->statistics_periodic.function = iwl_bg_statistics_periodic;
  787. init_timer(&priv->ucode_trace);
  788. priv->ucode_trace.data = (unsigned long)priv;
  789. priv->ucode_trace.function = iwl_bg_ucode_trace;
  790. init_timer(&priv->watchdog);
  791. priv->watchdog.data = (unsigned long)priv;
  792. priv->watchdog.function = iwl_bg_watchdog;
  793. }
  794. void iwl_cancel_deferred_work(struct iwl_priv *priv)
  795. {
  796. if (cfg(priv)->lib->cancel_deferred_work)
  797. cfg(priv)->lib->cancel_deferred_work(priv);
  798. cancel_work_sync(&priv->run_time_calib_work);
  799. cancel_work_sync(&priv->beacon_update);
  800. iwl_cancel_scan_deferred_work(priv);
  801. cancel_work_sync(&priv->bt_full_concurrency);
  802. cancel_work_sync(&priv->bt_runtime_config);
  803. cancel_delayed_work_sync(&priv->hw_roc_disable_work);
  804. del_timer_sync(&priv->statistics_periodic);
  805. del_timer_sync(&priv->ucode_trace);
  806. }
  807. static void iwl_init_hw_rates(struct iwl_priv *priv,
  808. struct ieee80211_rate *rates)
  809. {
  810. int i;
  811. for (i = 0; i < IWL_RATE_COUNT_LEGACY; i++) {
  812. rates[i].bitrate = iwl_rates[i].ieee * 5;
  813. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  814. rates[i].hw_value_short = i;
  815. rates[i].flags = 0;
  816. if ((i >= IWL_FIRST_CCK_RATE) && (i <= IWL_LAST_CCK_RATE)) {
  817. /*
  818. * If CCK != 1M then set short preamble rate flag.
  819. */
  820. rates[i].flags |=
  821. (iwl_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  822. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  823. }
  824. }
  825. }
  826. static int iwl_init_drv(struct iwl_priv *priv)
  827. {
  828. int ret;
  829. spin_lock_init(&priv->shrd->sta_lock);
  830. mutex_init(&priv->shrd->mutex);
  831. INIT_LIST_HEAD(&trans(priv)->calib_results);
  832. priv->ieee_channels = NULL;
  833. priv->ieee_rates = NULL;
  834. priv->band = IEEE80211_BAND_2GHZ;
  835. priv->iw_mode = NL80211_IFTYPE_STATION;
  836. priv->current_ht_config.smps = IEEE80211_SMPS_STATIC;
  837. priv->missed_beacon_threshold = IWL_MISSED_BEACON_THRESHOLD_DEF;
  838. priv->agg_tids_count = 0;
  839. /* initialize force reset */
  840. priv->force_reset[IWL_RF_RESET].reset_duration =
  841. IWL_DELAY_NEXT_FORCE_RF_RESET;
  842. priv->force_reset[IWL_FW_RESET].reset_duration =
  843. IWL_DELAY_NEXT_FORCE_FW_RELOAD;
  844. priv->rx_statistics_jiffies = jiffies;
  845. /* Choose which receivers/antennas to use */
  846. iwlagn_set_rxon_chain(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
  847. iwl_init_scan_params(priv);
  848. /* init bt coex */
  849. if (cfg(priv)->bt_params &&
  850. cfg(priv)->bt_params->advanced_bt_coexist) {
  851. priv->kill_ack_mask = IWLAGN_BT_KILL_ACK_MASK_DEFAULT;
  852. priv->kill_cts_mask = IWLAGN_BT_KILL_CTS_MASK_DEFAULT;
  853. priv->bt_valid = IWLAGN_BT_ALL_VALID_MSK;
  854. priv->bt_on_thresh = BT_ON_THRESHOLD_DEF;
  855. priv->bt_duration = BT_DURATION_LIMIT_DEF;
  856. priv->dynamic_frag_thresh = BT_FRAG_THRESHOLD_DEF;
  857. }
  858. ret = iwl_init_channel_map(priv);
  859. if (ret) {
  860. IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
  861. goto err;
  862. }
  863. ret = iwl_init_geos(priv);
  864. if (ret) {
  865. IWL_ERR(priv, "initializing geos failed: %d\n", ret);
  866. goto err_free_channel_map;
  867. }
  868. iwl_init_hw_rates(priv, priv->ieee_rates);
  869. return 0;
  870. err_free_channel_map:
  871. iwl_free_channel_map(priv);
  872. err:
  873. return ret;
  874. }
  875. static void iwl_uninit_drv(struct iwl_priv *priv)
  876. {
  877. iwl_free_geos(priv);
  878. iwl_free_channel_map(priv);
  879. if (priv->tx_cmd_pool)
  880. kmem_cache_destroy(priv->tx_cmd_pool);
  881. kfree(priv->scan_cmd);
  882. kfree(priv->beacon_cmd);
  883. kfree(rcu_dereference_raw(priv->noa_data));
  884. #ifdef CONFIG_IWLWIFI_DEBUGFS
  885. kfree(priv->wowlan_sram);
  886. #endif
  887. }
  888. /* Size of one Rx buffer in host DRAM */
  889. #define IWL_RX_BUF_SIZE_4K (4 * 1024)
  890. #define IWL_RX_BUF_SIZE_8K (8 * 1024)
  891. static void iwl_set_hw_params(struct iwl_priv *priv)
  892. {
  893. if (iwlagn_mod_params.amsdu_size_8K)
  894. hw_params(priv).rx_page_order =
  895. get_order(IWL_RX_BUF_SIZE_8K);
  896. else
  897. hw_params(priv).rx_page_order =
  898. get_order(IWL_RX_BUF_SIZE_4K);
  899. if (iwlagn_mod_params.disable_11n & IWL_DISABLE_HT_ALL)
  900. cfg(priv)->sku &= ~EEPROM_SKU_CAP_11N_ENABLE;
  901. hw_params(priv).num_ampdu_queues =
  902. cfg(priv)->base_params->num_of_ampdu_queues;
  903. hw_params(priv).shadow_reg_enable =
  904. cfg(priv)->base_params->shadow_reg_enable;
  905. hw_params(priv).sku = cfg(priv)->sku;
  906. hw_params(priv).wd_timeout = cfg(priv)->base_params->wd_timeout;
  907. /* Device-specific setup */
  908. cfg(priv)->lib->set_hw_params(priv);
  909. }
  910. static void iwl_debug_config(struct iwl_priv *priv)
  911. {
  912. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUG "
  913. #ifdef CONFIG_IWLWIFI_DEBUG
  914. "enabled\n");
  915. #else
  916. "disabled\n");
  917. #endif
  918. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEBUGFS "
  919. #ifdef CONFIG_IWLWIFI_DEBUGFS
  920. "enabled\n");
  921. #else
  922. "disabled\n");
  923. #endif
  924. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TRACING "
  925. #ifdef CONFIG_IWLWIFI_DEVICE_TRACING
  926. "enabled\n");
  927. #else
  928. "disabled\n");
  929. #endif
  930. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_DEVICE_TESTMODE "
  931. #ifdef CONFIG_IWLWIFI_DEVICE_TESTMODE
  932. "enabled\n");
  933. #else
  934. "disabled\n");
  935. #endif
  936. dev_printk(KERN_INFO, trans(priv)->dev, "CONFIG_IWLWIFI_P2P "
  937. #ifdef CONFIG_IWLWIFI_P2P
  938. "enabled\n");
  939. #else
  940. "disabled\n");
  941. #endif
  942. }
  943. static struct iwl_op_mode *iwl_op_mode_dvm_start(struct iwl_trans *trans)
  944. {
  945. struct iwl_fw *fw = &nic(trans)->fw;
  946. int err = 0;
  947. struct iwl_priv *priv;
  948. struct ieee80211_hw *hw;
  949. struct iwl_op_mode *op_mode;
  950. u16 num_mac;
  951. u32 ucode_flags;
  952. /************************
  953. * 1. Allocating HW data
  954. ************************/
  955. hw = iwl_alloc_all();
  956. if (!hw) {
  957. pr_err("%s: Cannot allocate network device\n",
  958. cfg(trans)->name);
  959. err = -ENOMEM;
  960. goto out;
  961. }
  962. op_mode = hw->priv;
  963. op_mode->ops = &iwl_dvm_ops;
  964. priv = IWL_OP_MODE_GET_DVM(op_mode);
  965. priv->shrd = trans->shrd;
  966. priv->shrd->priv = priv;
  967. iwl_trans_configure(trans(priv), op_mode);
  968. /* At this point both hw and priv are allocated. */
  969. SET_IEEE80211_DEV(priv->hw, trans(priv)->dev);
  970. /* show what debugging capabilities we have */
  971. iwl_debug_config(priv);
  972. IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
  973. /* is antenna coupling more than 35dB ? */
  974. priv->bt_ant_couple_ok =
  975. (iwlagn_mod_params.ant_coupling >
  976. IWL_BT_ANTENNA_COUPLING_THRESHOLD) ?
  977. true : false;
  978. /* enable/disable bt channel inhibition */
  979. priv->bt_ch_announce = iwlagn_mod_params.bt_ch_announce;
  980. IWL_DEBUG_INFO(priv, "BT channel inhibition is %s\n",
  981. (priv->bt_ch_announce) ? "On" : "Off");
  982. if (iwl_alloc_traffic_mem(priv))
  983. IWL_ERR(priv, "Not enough memory to generate traffic log\n");
  984. /* these spin locks will be used in apm_ops.init and EEPROM access
  985. * we should init now
  986. */
  987. spin_lock_init(&trans(priv)->reg_lock);
  988. spin_lock_init(&priv->shrd->lock);
  989. /***********************
  990. * 3. Read REV register
  991. ***********************/
  992. IWL_INFO(priv, "Detected %s, REV=0x%X\n",
  993. cfg(priv)->name, trans(priv)->hw_rev);
  994. err = iwl_trans_start_hw(trans(priv));
  995. if (err)
  996. goto out_free_traffic_mem;
  997. /*****************
  998. * 4. Read EEPROM
  999. *****************/
  1000. /* Read the EEPROM */
  1001. err = iwl_eeprom_init(trans(priv), trans(priv)->hw_rev);
  1002. /* Reset chip to save power until we load uCode during "up". */
  1003. iwl_trans_stop_hw(trans(priv));
  1004. if (err) {
  1005. IWL_ERR(priv, "Unable to init EEPROM\n");
  1006. goto out_free_traffic_mem;
  1007. }
  1008. err = iwl_eeprom_check_version(priv);
  1009. if (err)
  1010. goto out_free_eeprom;
  1011. err = iwl_eeprom_check_sku(priv);
  1012. if (err)
  1013. goto out_free_eeprom;
  1014. /* extract MAC Address */
  1015. iwl_eeprom_get_mac(priv->shrd, priv->addresses[0].addr);
  1016. IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->addresses[0].addr);
  1017. priv->hw->wiphy->addresses = priv->addresses;
  1018. priv->hw->wiphy->n_addresses = 1;
  1019. num_mac = iwl_eeprom_query16(priv->shrd, EEPROM_NUM_MAC_ADDRESS);
  1020. if (num_mac > 1) {
  1021. memcpy(priv->addresses[1].addr, priv->addresses[0].addr,
  1022. ETH_ALEN);
  1023. priv->addresses[1].addr[5]++;
  1024. priv->hw->wiphy->n_addresses++;
  1025. }
  1026. /************************
  1027. * 5. Setup HW constants
  1028. ************************/
  1029. iwl_set_hw_params(priv);
  1030. ucode_flags = fw->ucode_capa.flags;
  1031. #ifndef CONFIG_IWLWIFI_P2P
  1032. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1033. #endif
  1034. if (!(hw_params(priv).sku & EEPROM_SKU_CAP_IPAN_ENABLE))
  1035. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_PAN;
  1036. /*
  1037. * if not PAN, then don't support P2P -- might be a uCode
  1038. * packaging bug or due to the eeprom check above
  1039. */
  1040. if (!(ucode_flags & IWL_UCODE_TLV_FLAGS_PAN))
  1041. ucode_flags &= ~IWL_UCODE_TLV_FLAGS_P2P;
  1042. /*******************
  1043. * 6. Setup priv
  1044. *******************/
  1045. err = iwl_init_drv(priv);
  1046. if (err)
  1047. goto out_free_eeprom;
  1048. /* At this point both hw and priv are initialized. */
  1049. /********************
  1050. * 7. Setup services
  1051. ********************/
  1052. iwl_setup_deferred_work(priv);
  1053. iwl_setup_rx_handlers(priv);
  1054. iwl_testmode_init(priv);
  1055. iwl_power_initialize(priv);
  1056. iwl_tt_initialize(priv);
  1057. snprintf(priv->hw->wiphy->fw_version,
  1058. sizeof(priv->hw->wiphy->fw_version),
  1059. "%s", fw->fw_version);
  1060. priv->new_scan_threshold_behaviour =
  1061. !!(ucode_flags & IWL_UCODE_TLV_FLAGS_NEWSCAN);
  1062. if (ucode_flags & IWL_UCODE_TLV_FLAGS_PAN) {
  1063. priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
  1064. priv->shrd->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
  1065. } else {
  1066. priv->sta_key_max_num = STA_KEY_MAX_NUM;
  1067. priv->shrd->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
  1068. }
  1069. priv->phy_calib_chain_noise_reset_cmd =
  1070. fw->ucode_capa.standard_phy_calibration_size;
  1071. priv->phy_calib_chain_noise_gain_cmd =
  1072. fw->ucode_capa.standard_phy_calibration_size + 1;
  1073. /* initialize all valid contexts */
  1074. iwl_init_context(priv, ucode_flags);
  1075. /**************************************************
  1076. * This is still part of probe() in a sense...
  1077. *
  1078. * 9. Setup and register with mac80211 and debugfs
  1079. **************************************************/
  1080. err = iwlagn_mac_setup_register(priv, &fw->ucode_capa);
  1081. if (err)
  1082. goto out_destroy_workqueue;
  1083. err = iwl_dbgfs_register(priv, DRV_NAME);
  1084. if (err)
  1085. IWL_ERR(priv,
  1086. "failed to create debugfs files. Ignoring error: %d\n",
  1087. err);
  1088. return op_mode;
  1089. out_destroy_workqueue:
  1090. destroy_workqueue(priv->workqueue);
  1091. priv->workqueue = NULL;
  1092. iwl_uninit_drv(priv);
  1093. out_free_eeprom:
  1094. iwl_eeprom_free(priv->shrd);
  1095. out_free_traffic_mem:
  1096. iwl_free_traffic_mem(priv);
  1097. ieee80211_free_hw(priv->hw);
  1098. out:
  1099. op_mode = NULL;
  1100. return op_mode;
  1101. }
  1102. static void iwl_op_mode_dvm_stop(struct iwl_op_mode *op_mode)
  1103. {
  1104. struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
  1105. wait_for_completion(&nic(priv)->request_firmware_complete);
  1106. IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
  1107. iwl_dbgfs_unregister(priv);
  1108. /* ieee80211_unregister_hw call wil cause iwlagn_mac_stop to
  1109. * to be called and iwl_down since we are removing the device
  1110. * we need to set STATUS_EXIT_PENDING bit.
  1111. */
  1112. set_bit(STATUS_EXIT_PENDING, &priv->shrd->status);
  1113. iwl_testmode_cleanup(priv);
  1114. iwlagn_mac_unregister(priv);
  1115. iwl_tt_exit(priv);
  1116. /*This will stop the queues, move the device to low power state */
  1117. iwl_trans_stop_device(trans(priv));
  1118. iwl_dealloc_ucode(nic(priv));
  1119. iwl_eeprom_free(priv->shrd);
  1120. /*netif_stop_queue(dev); */
  1121. flush_workqueue(priv->workqueue);
  1122. /* ieee80211_unregister_hw calls iwlagn_mac_stop, which flushes
  1123. * priv->workqueue... so we can't take down the workqueue
  1124. * until now... */
  1125. destroy_workqueue(priv->workqueue);
  1126. priv->workqueue = NULL;
  1127. iwl_free_traffic_mem(priv);
  1128. iwl_uninit_drv(priv);
  1129. dev_kfree_skb(priv->beacon_skb);
  1130. ieee80211_free_hw(priv->hw);
  1131. }
  1132. const struct iwl_op_mode_ops iwl_dvm_ops = {
  1133. .start = iwl_op_mode_dvm_start,
  1134. .stop = iwl_op_mode_dvm_stop,
  1135. .rx = iwl_rx_dispatch,
  1136. .queue_full = iwl_stop_sw_queue,
  1137. .queue_not_full = iwl_wake_sw_queue,
  1138. .hw_rf_kill = iwl_set_hw_rfkill_state,
  1139. .free_skb = iwl_free_skb,
  1140. .nic_error = iwl_nic_error,
  1141. };
  1142. /*****************************************************************************
  1143. *
  1144. * driver and module entry point
  1145. *
  1146. *****************************************************************************/
  1147. static int __init iwl_init(void)
  1148. {
  1149. int ret;
  1150. pr_info(DRV_DESCRIPTION ", " DRV_VERSION "\n");
  1151. pr_info(DRV_COPYRIGHT "\n");
  1152. ret = iwlagn_rate_control_register();
  1153. if (ret) {
  1154. pr_err("Unable to register rate control algorithm: %d\n", ret);
  1155. return ret;
  1156. }
  1157. ret = iwl_pci_register_driver();
  1158. if (ret)
  1159. goto error_register;
  1160. return ret;
  1161. error_register:
  1162. iwlagn_rate_control_unregister();
  1163. return ret;
  1164. }
  1165. static void __exit iwl_exit(void)
  1166. {
  1167. iwl_pci_unregister_driver();
  1168. iwlagn_rate_control_unregister();
  1169. }
  1170. module_exit(iwl_exit);
  1171. module_init(iwl_init);
  1172. #ifdef CONFIG_IWLWIFI_DEBUG
  1173. module_param_named(debug, iwlagn_mod_params.debug_level, uint,
  1174. S_IRUGO | S_IWUSR);
  1175. MODULE_PARM_DESC(debug, "debug output mask");
  1176. #endif
  1177. module_param_named(swcrypto, iwlagn_mod_params.sw_crypto, int, S_IRUGO);
  1178. MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])");
  1179. module_param_named(queues_num, iwlagn_mod_params.num_of_queues, int, S_IRUGO);
  1180. MODULE_PARM_DESC(queues_num, "number of hw queues.");
  1181. module_param_named(11n_disable, iwlagn_mod_params.disable_11n, uint, S_IRUGO);
  1182. MODULE_PARM_DESC(11n_disable,
  1183. "disable 11n functionality, bitmap: 1: full, 2: agg TX, 4: agg RX");
  1184. module_param_named(amsdu_size_8K, iwlagn_mod_params.amsdu_size_8K,
  1185. int, S_IRUGO);
  1186. MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
  1187. module_param_named(fw_restart, iwlagn_mod_params.restart_fw, int, S_IRUGO);
  1188. MODULE_PARM_DESC(fw_restart, "restart firmware in case of error");
  1189. module_param_named(ucode_alternative,
  1190. iwlagn_mod_params.wanted_ucode_alternative,
  1191. int, S_IRUGO);
  1192. MODULE_PARM_DESC(ucode_alternative,
  1193. "specify ucode alternative to use from ucode file");
  1194. module_param_named(antenna_coupling, iwlagn_mod_params.ant_coupling,
  1195. int, S_IRUGO);
  1196. MODULE_PARM_DESC(antenna_coupling,
  1197. "specify antenna coupling in dB (defualt: 0 dB)");
  1198. module_param_named(bt_ch_inhibition, iwlagn_mod_params.bt_ch_announce,
  1199. bool, S_IRUGO);
  1200. MODULE_PARM_DESC(bt_ch_inhibition,
  1201. "Enable BT channel inhibition (default: enable)");
  1202. module_param_named(plcp_check, iwlagn_mod_params.plcp_check, bool, S_IRUGO);
  1203. MODULE_PARM_DESC(plcp_check, "Check plcp health (default: 1 [enabled])");
  1204. module_param_named(ack_check, iwlagn_mod_params.ack_check, bool, S_IRUGO);
  1205. MODULE_PARM_DESC(ack_check, "Check ack health (default: 0 [disabled])");
  1206. module_param_named(wd_disable, iwlagn_mod_params.wd_disable, int, S_IRUGO);
  1207. MODULE_PARM_DESC(wd_disable,
  1208. "Disable stuck queue watchdog timer 0=system default, "
  1209. "1=disable, 2=enable (default: 0)");
  1210. /*
  1211. * set bt_coex_active to true, uCode will do kill/defer
  1212. * every time the priority line is asserted (BT is sending signals on the
  1213. * priority line in the PCIx).
  1214. * set bt_coex_active to false, uCode will ignore the BT activity and
  1215. * perform the normal operation
  1216. *
  1217. * User might experience transmit issue on some platform due to WiFi/BT
  1218. * co-exist problem. The possible behaviors are:
  1219. * Able to scan and finding all the available AP
  1220. * Not able to associate with any AP
  1221. * On those platforms, WiFi communication can be restored by set
  1222. * "bt_coex_active" module parameter to "false"
  1223. *
  1224. * default: bt_coex_active = true (BT_COEX_ENABLE)
  1225. */
  1226. module_param_named(bt_coex_active, iwlagn_mod_params.bt_coex_active,
  1227. bool, S_IRUGO);
  1228. MODULE_PARM_DESC(bt_coex_active, "enable wifi/bt co-exist (default: enable)");
  1229. module_param_named(led_mode, iwlagn_mod_params.led_mode, int, S_IRUGO);
  1230. MODULE_PARM_DESC(led_mode, "0=system default, "
  1231. "1=On(RF On)/Off(RF Off), 2=blinking, 3=Off (default: 0)");
  1232. module_param_named(power_save, iwlagn_mod_params.power_save,
  1233. bool, S_IRUGO);
  1234. MODULE_PARM_DESC(power_save,
  1235. "enable WiFi power management (default: disable)");
  1236. module_param_named(power_level, iwlagn_mod_params.power_level,
  1237. int, S_IRUGO);
  1238. MODULE_PARM_DESC(power_level,
  1239. "default power save level (range from 1 - 5, default: 1)");
  1240. module_param_named(auto_agg, iwlagn_mod_params.auto_agg,
  1241. bool, S_IRUGO);
  1242. MODULE_PARM_DESC(auto_agg,
  1243. "enable agg w/o check traffic load (default: enable)");
  1244. /*
  1245. * For now, keep using power level 1 instead of automatically
  1246. * adjusting ...
  1247. */
  1248. module_param_named(no_sleep_autoadjust, iwlagn_mod_params.no_sleep_autoadjust,
  1249. bool, S_IRUGO);
  1250. MODULE_PARM_DESC(no_sleep_autoadjust,
  1251. "don't automatically adjust sleep level "
  1252. "according to maximum network latency (default: true)");