iwl-agn.c 44 KB

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