iwl-core.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  1. /******************************************************************************
  2. *
  3. * GPL LICENSE SUMMARY
  4. *
  5. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of version 2 of the GNU General Public License as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
  19. * USA
  20. *
  21. * The full GNU General Public License is included in this distribution
  22. * in the file called LICENSE.GPL.
  23. *
  24. * Contact Information:
  25. * Tomas Winkler <tomas.winkler@intel.com>
  26. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  27. *****************************************************************************/
  28. #include <linux/kernel.h>
  29. #include <linux/module.h>
  30. #include <linux/version.h>
  31. #include <net/mac80211.h>
  32. struct iwl_priv; /* FIXME: remove */
  33. #include "iwl-debug.h"
  34. #include "iwl-eeprom.h"
  35. #include "iwl-dev.h" /* FIXME: remove */
  36. #include "iwl-core.h"
  37. #include "iwl-io.h"
  38. #include "iwl-rfkill.h"
  39. #include "iwl-power.h"
  40. MODULE_DESCRIPTION("iwl core");
  41. MODULE_VERSION(IWLWIFI_VERSION);
  42. MODULE_AUTHOR(DRV_COPYRIGHT);
  43. MODULE_LICENSE("GPL");
  44. #ifdef CONFIG_IWLWIFI_DEBUG
  45. u32 iwl_debug_level;
  46. EXPORT_SYMBOL(iwl_debug_level);
  47. #endif
  48. #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
  49. [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
  50. IWL_RATE_SISO_##s##M_PLCP, \
  51. IWL_RATE_MIMO2_##s##M_PLCP,\
  52. IWL_RATE_MIMO3_##s##M_PLCP,\
  53. IWL_RATE_##r##M_IEEE, \
  54. IWL_RATE_##ip##M_INDEX, \
  55. IWL_RATE_##in##M_INDEX, \
  56. IWL_RATE_##rp##M_INDEX, \
  57. IWL_RATE_##rn##M_INDEX, \
  58. IWL_RATE_##pp##M_INDEX, \
  59. IWL_RATE_##np##M_INDEX }
  60. /*
  61. * Parameter order:
  62. * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
  63. *
  64. * If there isn't a valid next or previous rate then INV is used which
  65. * maps to IWL_RATE_INVALID
  66. *
  67. */
  68. const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
  69. IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
  70. IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
  71. IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
  72. IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
  73. IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
  74. IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
  75. IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
  76. IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
  77. IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
  78. IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
  79. IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
  80. IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
  81. IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
  82. /* FIXME:RS: ^^ should be INV (legacy) */
  83. };
  84. EXPORT_SYMBOL(iwl4965_rates);
  85. /* This function both allocates and initializes hw and priv. */
  86. struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
  87. struct ieee80211_ops *hw_ops)
  88. {
  89. struct iwl_priv *priv;
  90. /* mac80211 allocates memory for this device instance, including
  91. * space for this driver's private structure */
  92. struct ieee80211_hw *hw =
  93. ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
  94. if (hw == NULL) {
  95. IWL_ERROR("Can not allocate network device\n");
  96. goto out;
  97. }
  98. priv = hw->priv;
  99. priv->hw = hw;
  100. out:
  101. return hw;
  102. }
  103. EXPORT_SYMBOL(iwl_alloc_all);
  104. void iwl_hw_detect(struct iwl_priv *priv)
  105. {
  106. priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
  107. priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
  108. pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
  109. }
  110. EXPORT_SYMBOL(iwl_hw_detect);
  111. /* Tell nic where to find the "keep warm" buffer */
  112. int iwl_kw_init(struct iwl_priv *priv)
  113. {
  114. unsigned long flags;
  115. int ret;
  116. spin_lock_irqsave(&priv->lock, flags);
  117. ret = iwl_grab_nic_access(priv);
  118. if (ret)
  119. goto out;
  120. iwl_write_direct32(priv, FH_KW_MEM_ADDR_REG,
  121. priv->kw.dma_addr >> 4);
  122. iwl_release_nic_access(priv);
  123. out:
  124. spin_unlock_irqrestore(&priv->lock, flags);
  125. return ret;
  126. }
  127. int iwl_kw_alloc(struct iwl_priv *priv)
  128. {
  129. struct pci_dev *dev = priv->pci_dev;
  130. struct iwl_kw *kw = &priv->kw;
  131. kw->size = IWL_KW_SIZE;
  132. kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
  133. if (!kw->v_addr)
  134. return -ENOMEM;
  135. return 0;
  136. }
  137. /**
  138. * iwl_kw_free - Free the "keep warm" buffer
  139. */
  140. void iwl_kw_free(struct iwl_priv *priv)
  141. {
  142. struct pci_dev *dev = priv->pci_dev;
  143. struct iwl_kw *kw = &priv->kw;
  144. if (kw->v_addr) {
  145. pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
  146. memset(kw, 0, sizeof(*kw));
  147. }
  148. }
  149. int iwl_hw_nic_init(struct iwl_priv *priv)
  150. {
  151. unsigned long flags;
  152. struct iwl_rx_queue *rxq = &priv->rxq;
  153. int ret;
  154. /* nic_init */
  155. priv->cfg->ops->lib->apm_ops.init(priv);
  156. spin_lock_irqsave(&priv->lock, flags);
  157. iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
  158. spin_unlock_irqrestore(&priv->lock, flags);
  159. ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
  160. priv->cfg->ops->lib->apm_ops.config(priv);
  161. /* Allocate the RX queue, or reset if it is already allocated */
  162. if (!rxq->bd) {
  163. ret = iwl_rx_queue_alloc(priv);
  164. if (ret) {
  165. IWL_ERROR("Unable to initialize Rx queue\n");
  166. return -ENOMEM;
  167. }
  168. } else
  169. iwl_rx_queue_reset(priv, rxq);
  170. iwl_rx_replenish(priv);
  171. iwl_rx_init(priv, rxq);
  172. spin_lock_irqsave(&priv->lock, flags);
  173. rxq->need_update = 1;
  174. iwl_rx_queue_update_write_ptr(priv, rxq);
  175. spin_unlock_irqrestore(&priv->lock, flags);
  176. /* Allocate and init all Tx and Command queues */
  177. ret = iwl_txq_ctx_reset(priv);
  178. if (ret)
  179. return ret;
  180. set_bit(STATUS_INIT, &priv->status);
  181. return 0;
  182. }
  183. EXPORT_SYMBOL(iwl_hw_nic_init);
  184. /**
  185. * iwlcore_clear_stations_table - Clear the driver's station table
  186. *
  187. * NOTE: This does not clear or otherwise alter the device's station table.
  188. */
  189. void iwlcore_clear_stations_table(struct iwl_priv *priv)
  190. {
  191. unsigned long flags;
  192. spin_lock_irqsave(&priv->sta_lock, flags);
  193. priv->num_stations = 0;
  194. memset(priv->stations, 0, sizeof(priv->stations));
  195. spin_unlock_irqrestore(&priv->sta_lock, flags);
  196. }
  197. EXPORT_SYMBOL(iwlcore_clear_stations_table);
  198. void iwl_reset_qos(struct iwl_priv *priv)
  199. {
  200. u16 cw_min = 15;
  201. u16 cw_max = 1023;
  202. u8 aifs = 2;
  203. u8 is_legacy = 0;
  204. unsigned long flags;
  205. int i;
  206. spin_lock_irqsave(&priv->lock, flags);
  207. priv->qos_data.qos_active = 0;
  208. if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
  209. if (priv->qos_data.qos_enable)
  210. priv->qos_data.qos_active = 1;
  211. if (!(priv->active_rate & 0xfff0)) {
  212. cw_min = 31;
  213. is_legacy = 1;
  214. }
  215. } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
  216. if (priv->qos_data.qos_enable)
  217. priv->qos_data.qos_active = 1;
  218. } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
  219. cw_min = 31;
  220. is_legacy = 1;
  221. }
  222. if (priv->qos_data.qos_active)
  223. aifs = 3;
  224. priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
  225. priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
  226. priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
  227. priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
  228. priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
  229. if (priv->qos_data.qos_active) {
  230. i = 1;
  231. priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
  232. priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
  233. priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
  234. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  235. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  236. i = 2;
  237. priv->qos_data.def_qos_parm.ac[i].cw_min =
  238. cpu_to_le16((cw_min + 1) / 2 - 1);
  239. priv->qos_data.def_qos_parm.ac[i].cw_max =
  240. cpu_to_le16(cw_max);
  241. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  242. if (is_legacy)
  243. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  244. cpu_to_le16(6016);
  245. else
  246. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  247. cpu_to_le16(3008);
  248. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  249. i = 3;
  250. priv->qos_data.def_qos_parm.ac[i].cw_min =
  251. cpu_to_le16((cw_min + 1) / 4 - 1);
  252. priv->qos_data.def_qos_parm.ac[i].cw_max =
  253. cpu_to_le16((cw_max + 1) / 2 - 1);
  254. priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
  255. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  256. if (is_legacy)
  257. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  258. cpu_to_le16(3264);
  259. else
  260. priv->qos_data.def_qos_parm.ac[i].edca_txop =
  261. cpu_to_le16(1504);
  262. } else {
  263. for (i = 1; i < 4; i++) {
  264. priv->qos_data.def_qos_parm.ac[i].cw_min =
  265. cpu_to_le16(cw_min);
  266. priv->qos_data.def_qos_parm.ac[i].cw_max =
  267. cpu_to_le16(cw_max);
  268. priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
  269. priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
  270. priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
  271. }
  272. }
  273. IWL_DEBUG_QOS("set QoS to default \n");
  274. spin_unlock_irqrestore(&priv->lock, flags);
  275. }
  276. EXPORT_SYMBOL(iwl_reset_qos);
  277. #ifdef CONFIG_IWL4965_HT
  278. static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  279. struct ieee80211_ht_info *ht_info,
  280. enum ieee80211_band band)
  281. {
  282. ht_info->cap = 0;
  283. memset(ht_info->supp_mcs_set, 0, 16);
  284. ht_info->ht_supported = 1;
  285. if (priv->hw_params.fat_channel & BIT(band)) {
  286. ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
  287. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
  288. ht_info->supp_mcs_set[4] = 0x01;
  289. }
  290. ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
  291. ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
  292. ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
  293. (IWL_MIMO_PS_NONE << 2));
  294. if (priv->cfg->mod_params->amsdu_size_8K)
  295. ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
  296. ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
  297. ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
  298. ht_info->supp_mcs_set[0] = 0xFF;
  299. if (priv->hw_params.tx_chains_num >= 2)
  300. ht_info->supp_mcs_set[1] = 0xFF;
  301. if (priv->hw_params.tx_chains_num >= 3)
  302. ht_info->supp_mcs_set[2] = 0xFF;
  303. }
  304. #else
  305. static inline void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
  306. struct ieee80211_ht_info *ht_info,
  307. enum ieee80211_band band)
  308. {
  309. }
  310. #endif /* CONFIG_IWL4965_HT */
  311. static void iwlcore_init_hw_rates(struct iwl_priv *priv,
  312. struct ieee80211_rate *rates)
  313. {
  314. int i;
  315. for (i = 0; i < IWL_RATE_COUNT; i++) {
  316. rates[i].bitrate = iwl4965_rates[i].ieee * 5;
  317. rates[i].hw_value = i; /* Rate scaling will work on indexes */
  318. rates[i].hw_value_short = i;
  319. rates[i].flags = 0;
  320. if ((i > IWL_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
  321. /*
  322. * If CCK != 1M then set short preamble rate flag.
  323. */
  324. rates[i].flags |=
  325. (iwl4965_rates[i].plcp == IWL_RATE_1M_PLCP) ?
  326. 0 : IEEE80211_RATE_SHORT_PREAMBLE;
  327. }
  328. }
  329. }
  330. /**
  331. * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
  332. */
  333. static int iwlcore_init_geos(struct iwl_priv *priv)
  334. {
  335. struct iwl_channel_info *ch;
  336. struct ieee80211_supported_band *sband;
  337. struct ieee80211_channel *channels;
  338. struct ieee80211_channel *geo_ch;
  339. struct ieee80211_rate *rates;
  340. int i = 0;
  341. if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
  342. priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
  343. IWL_DEBUG_INFO("Geography modes already initialized.\n");
  344. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  345. return 0;
  346. }
  347. channels = kzalloc(sizeof(struct ieee80211_channel) *
  348. priv->channel_count, GFP_KERNEL);
  349. if (!channels)
  350. return -ENOMEM;
  351. rates = kzalloc((sizeof(struct ieee80211_rate) * (IWL_RATE_COUNT + 1)),
  352. GFP_KERNEL);
  353. if (!rates) {
  354. kfree(channels);
  355. return -ENOMEM;
  356. }
  357. /* 5.2GHz channels start after the 2.4GHz channels */
  358. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  359. sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
  360. /* just OFDM */
  361. sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
  362. sband->n_bitrates = IWL_RATE_COUNT - IWL_FIRST_OFDM_RATE;
  363. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_5GHZ);
  364. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  365. sband->channels = channels;
  366. /* OFDM & CCK */
  367. sband->bitrates = rates;
  368. sband->n_bitrates = IWL_RATE_COUNT;
  369. iwlcore_init_ht_hw_capab(priv, &sband->ht_info, IEEE80211_BAND_2GHZ);
  370. priv->ieee_channels = channels;
  371. priv->ieee_rates = rates;
  372. iwlcore_init_hw_rates(priv, rates);
  373. for (i = 0; i < priv->channel_count; i++) {
  374. ch = &priv->channel_info[i];
  375. /* FIXME: might be removed if scan is OK */
  376. if (!is_channel_valid(ch))
  377. continue;
  378. if (is_channel_a_band(ch))
  379. sband = &priv->bands[IEEE80211_BAND_5GHZ];
  380. else
  381. sband = &priv->bands[IEEE80211_BAND_2GHZ];
  382. geo_ch = &sband->channels[sband->n_channels++];
  383. geo_ch->center_freq =
  384. ieee80211_channel_to_frequency(ch->channel);
  385. geo_ch->max_power = ch->max_power_avg;
  386. geo_ch->max_antenna_gain = 0xff;
  387. geo_ch->hw_value = ch->channel;
  388. if (is_channel_valid(ch)) {
  389. if (!(ch->flags & EEPROM_CHANNEL_IBSS))
  390. geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
  391. if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
  392. geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
  393. if (ch->flags & EEPROM_CHANNEL_RADAR)
  394. geo_ch->flags |= IEEE80211_CHAN_RADAR;
  395. if (ch->max_power_avg > priv->max_channel_txpower_limit)
  396. priv->max_channel_txpower_limit =
  397. ch->max_power_avg;
  398. } else {
  399. geo_ch->flags |= IEEE80211_CHAN_DISABLED;
  400. }
  401. /* Save flags for reg domain usage */
  402. geo_ch->orig_flags = geo_ch->flags;
  403. IWL_DEBUG_INFO("Channel %d Freq=%d[%sGHz] %s flag=0%X\n",
  404. ch->channel, geo_ch->center_freq,
  405. is_channel_a_band(ch) ? "5.2" : "2.4",
  406. geo_ch->flags & IEEE80211_CHAN_DISABLED ?
  407. "restricted" : "valid",
  408. geo_ch->flags);
  409. }
  410. if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
  411. priv->cfg->sku & IWL_SKU_A) {
  412. printk(KERN_INFO DRV_NAME
  413. ": Incorrectly detected BG card as ABG. Please send "
  414. "your PCI ID 0x%04X:0x%04X to maintainer.\n",
  415. priv->pci_dev->device, priv->pci_dev->subsystem_device);
  416. priv->cfg->sku &= ~IWL_SKU_A;
  417. }
  418. printk(KERN_INFO DRV_NAME
  419. ": Tunable channels: %d 802.11bg, %d 802.11a channels\n",
  420. priv->bands[IEEE80211_BAND_2GHZ].n_channels,
  421. priv->bands[IEEE80211_BAND_5GHZ].n_channels);
  422. if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
  423. priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
  424. &priv->bands[IEEE80211_BAND_2GHZ];
  425. if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
  426. priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
  427. &priv->bands[IEEE80211_BAND_5GHZ];
  428. set_bit(STATUS_GEO_CONFIGURED, &priv->status);
  429. return 0;
  430. }
  431. /*
  432. * iwlcore_free_geos - undo allocations in iwlcore_init_geos
  433. */
  434. void iwlcore_free_geos(struct iwl_priv *priv)
  435. {
  436. kfree(priv->ieee_channels);
  437. kfree(priv->ieee_rates);
  438. clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
  439. }
  440. EXPORT_SYMBOL(iwlcore_free_geos);
  441. #ifdef CONFIG_IWL4965_HT
  442. static u8 is_single_rx_stream(struct iwl_priv *priv)
  443. {
  444. return !priv->current_ht_config.is_ht ||
  445. ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
  446. (priv->current_ht_config.supp_mcs_set[2] == 0)) ||
  447. priv->ps_mode == IWL_MIMO_PS_STATIC;
  448. }
  449. static u8 iwl_is_channel_extension(struct iwl_priv *priv,
  450. enum ieee80211_band band,
  451. u16 channel, u8 extension_chan_offset)
  452. {
  453. const struct iwl_channel_info *ch_info;
  454. ch_info = iwl_get_channel_info(priv, band, channel);
  455. if (!is_channel_valid(ch_info))
  456. return 0;
  457. if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
  458. return 0;
  459. if ((ch_info->fat_extension_channel == extension_chan_offset) ||
  460. (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
  461. return 1;
  462. return 0;
  463. }
  464. u8 iwl_is_fat_tx_allowed(struct iwl_priv *priv,
  465. struct ieee80211_ht_info *sta_ht_inf)
  466. {
  467. struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
  468. if ((!iwl_ht_conf->is_ht) ||
  469. (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
  470. (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE))
  471. return 0;
  472. if (sta_ht_inf) {
  473. if ((!sta_ht_inf->ht_supported) ||
  474. (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
  475. return 0;
  476. }
  477. return iwl_is_channel_extension(priv, priv->band,
  478. iwl_ht_conf->control_channel,
  479. iwl_ht_conf->extension_chan_offset);
  480. }
  481. EXPORT_SYMBOL(iwl_is_fat_tx_allowed);
  482. void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
  483. {
  484. struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
  485. u32 val;
  486. if (!ht_info->is_ht)
  487. return;
  488. /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
  489. if (iwl_is_fat_tx_allowed(priv, NULL))
  490. rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  491. else
  492. rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
  493. RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
  494. if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
  495. IWL_DEBUG_ASSOC("control diff than current %d %d\n",
  496. le16_to_cpu(rxon->channel),
  497. ht_info->control_channel);
  498. rxon->channel = cpu_to_le16(ht_info->control_channel);
  499. return;
  500. }
  501. /* Note: control channel is opposite of extension channel */
  502. switch (ht_info->extension_chan_offset) {
  503. case IWL_EXT_CHANNEL_OFFSET_ABOVE:
  504. rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
  505. break;
  506. case IWL_EXT_CHANNEL_OFFSET_BELOW:
  507. rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
  508. break;
  509. case IWL_EXT_CHANNEL_OFFSET_NONE:
  510. default:
  511. rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
  512. break;
  513. }
  514. val = ht_info->ht_protection;
  515. rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
  516. iwl_set_rxon_chain(priv);
  517. IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
  518. "rxon flags 0x%X operation mode :0x%X "
  519. "extension channel offset 0x%x "
  520. "control chan %d\n",
  521. ht_info->supp_mcs_set[0],
  522. ht_info->supp_mcs_set[1],
  523. ht_info->supp_mcs_set[2],
  524. le32_to_cpu(rxon->flags), ht_info->ht_protection,
  525. ht_info->extension_chan_offset,
  526. ht_info->control_channel);
  527. return;
  528. }
  529. EXPORT_SYMBOL(iwl_set_rxon_ht);
  530. #else
  531. static inline u8 is_single_rx_stream(struct iwl_priv *priv)
  532. {
  533. return 1;
  534. }
  535. #endif /*CONFIG_IWL4965_HT */
  536. /*
  537. * Determine how many receiver/antenna chains to use.
  538. * More provides better reception via diversity. Fewer saves power.
  539. * MIMO (dual stream) requires at least 2, but works better with 3.
  540. * This does not determine *which* chains to use, just how many.
  541. */
  542. static int iwlcore_get_rx_chain_counter(struct iwl_priv *priv,
  543. u8 *idle_state, u8 *rx_state)
  544. {
  545. u8 is_single = is_single_rx_stream(priv);
  546. u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
  547. /* # of Rx chains to use when expecting MIMO. */
  548. if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
  549. *rx_state = 2;
  550. else
  551. *rx_state = 3;
  552. /* # Rx chains when idling and maybe trying to save power */
  553. switch (priv->ps_mode) {
  554. case IWL_MIMO_PS_STATIC:
  555. case IWL_MIMO_PS_DYNAMIC:
  556. *idle_state = (is_cam) ? 2 : 1;
  557. break;
  558. case IWL_MIMO_PS_NONE:
  559. *idle_state = (is_cam) ? *rx_state : 1;
  560. break;
  561. default:
  562. *idle_state = 1;
  563. break;
  564. }
  565. return 0;
  566. }
  567. /**
  568. * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
  569. *
  570. * Selects how many and which Rx receivers/antennas/chains to use.
  571. * This should not be used for scan command ... it puts data in wrong place.
  572. */
  573. void iwl_set_rxon_chain(struct iwl_priv *priv)
  574. {
  575. u8 is_single = is_single_rx_stream(priv);
  576. u8 idle_state, rx_state;
  577. priv->staging_rxon.rx_chain = 0;
  578. rx_state = idle_state = 3;
  579. /* Tell uCode which antennas are actually connected.
  580. * Before first association, we assume all antennas are connected.
  581. * Just after first association, iwl_chain_noise_calibration()
  582. * checks which antennas actually *are* connected. */
  583. priv->staging_rxon.rx_chain |=
  584. cpu_to_le16(priv->hw_params.valid_rx_ant <<
  585. RXON_RX_CHAIN_VALID_POS);
  586. /* How many receivers should we use? */
  587. iwlcore_get_rx_chain_counter(priv, &idle_state, &rx_state);
  588. priv->staging_rxon.rx_chain |=
  589. cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
  590. priv->staging_rxon.rx_chain |=
  591. cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
  592. if (!is_single && (rx_state >= 2) &&
  593. !test_bit(STATUS_POWER_PMI, &priv->status))
  594. priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
  595. else
  596. priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
  597. IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
  598. }
  599. EXPORT_SYMBOL(iwl_set_rxon_chain);
  600. /**
  601. * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
  602. * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
  603. * @channel: Any channel valid for the requested phymode
  604. * In addition to setting the staging RXON, priv->phymode is also set.
  605. *
  606. * NOTE: Does not commit to the hardware; it sets appropriate bit fields
  607. * in the staging RXON flag structure based on the phymode
  608. */
  609. int iwl_set_rxon_channel(struct iwl_priv *priv,
  610. enum ieee80211_band band,
  611. u16 channel)
  612. {
  613. if (!iwl_get_channel_info(priv, band, channel)) {
  614. IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
  615. channel, band);
  616. return -EINVAL;
  617. }
  618. if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
  619. (priv->band == band))
  620. return 0;
  621. priv->staging_rxon.channel = cpu_to_le16(channel);
  622. if (band == IEEE80211_BAND_5GHZ)
  623. priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
  624. else
  625. priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
  626. priv->band = band;
  627. IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
  628. return 0;
  629. }
  630. EXPORT_SYMBOL(iwl_set_rxon_channel);
  631. static void iwlcore_init_hw(struct iwl_priv *priv)
  632. {
  633. struct ieee80211_hw *hw = priv->hw;
  634. hw->rate_control_algorithm = "iwl-4965-rs";
  635. /* Tell mac80211 and its clients (e.g. Wireless Extensions)
  636. * the range of signal quality values that we'll provide.
  637. * Negative values for level/noise indicate that we'll provide dBm.
  638. * For WE, at least, non-0 values here *enable* display of values
  639. * in app (iwconfig). */
  640. hw->max_rssi = -20; /* signal level, negative indicates dBm */
  641. hw->max_noise = -20; /* noise level, negative indicates dBm */
  642. hw->max_signal = 100; /* link quality indication (%) */
  643. /* Tell mac80211 our Tx characteristics */
  644. hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
  645. /* Default value; 4 EDCA QOS priorities */
  646. hw->queues = 4;
  647. #ifdef CONFIG_IWL4965_HT
  648. /* Enhanced value; more queues, to support 11n aggregation */
  649. hw->ampdu_queues = 12;
  650. #endif /* CONFIG_IWL4965_HT */
  651. }
  652. static int iwlcore_init_drv(struct iwl_priv *priv)
  653. {
  654. int ret;
  655. int i;
  656. priv->retry_rate = 1;
  657. priv->ibss_beacon = NULL;
  658. spin_lock_init(&priv->lock);
  659. spin_lock_init(&priv->power_data.lock);
  660. spin_lock_init(&priv->sta_lock);
  661. spin_lock_init(&priv->hcmd_lock);
  662. spin_lock_init(&priv->lq_mngr.lock);
  663. for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
  664. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  665. INIT_LIST_HEAD(&priv->free_frames);
  666. mutex_init(&priv->mutex);
  667. /* Clear the driver's (not device's) station table */
  668. iwlcore_clear_stations_table(priv);
  669. priv->data_retry_limit = -1;
  670. priv->ieee_channels = NULL;
  671. priv->ieee_rates = NULL;
  672. priv->band = IEEE80211_BAND_2GHZ;
  673. priv->iw_mode = IEEE80211_IF_TYPE_STA;
  674. priv->use_ant_b_for_management_frame = 1; /* start with ant B */
  675. priv->ps_mode = IWL_MIMO_PS_NONE;
  676. /* Choose which receivers/antennas to use */
  677. iwl_set_rxon_chain(priv);
  678. iwl_reset_qos(priv);
  679. priv->qos_data.qos_active = 0;
  680. priv->qos_data.qos_cap.val = 0;
  681. iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
  682. priv->rates_mask = IWL_RATES_MASK;
  683. /* If power management is turned on, default to AC mode */
  684. priv->power_mode = IWL_POWER_AC;
  685. priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
  686. ret = iwl_init_channel_map(priv);
  687. if (ret) {
  688. IWL_ERROR("initializing regulatory failed: %d\n", ret);
  689. goto err;
  690. }
  691. ret = iwlcore_init_geos(priv);
  692. if (ret) {
  693. IWL_ERROR("initializing geos failed: %d\n", ret);
  694. goto err_free_channel_map;
  695. }
  696. ret = ieee80211_register_hw(priv->hw);
  697. if (ret) {
  698. IWL_ERROR("Failed to register network device (error %d)\n",
  699. ret);
  700. goto err_free_geos;
  701. }
  702. priv->hw->conf.beacon_int = 100;
  703. priv->mac80211_registered = 1;
  704. return 0;
  705. err_free_geos:
  706. iwlcore_free_geos(priv);
  707. err_free_channel_map:
  708. iwl_free_channel_map(priv);
  709. err:
  710. return ret;
  711. }
  712. int iwl_setup(struct iwl_priv *priv)
  713. {
  714. int ret = 0;
  715. iwlcore_init_hw(priv);
  716. ret = iwlcore_init_drv(priv);
  717. return ret;
  718. }
  719. EXPORT_SYMBOL(iwl_setup);
  720. /* Low level driver call this function to update iwlcore with
  721. * driver status.
  722. */
  723. int iwlcore_low_level_notify(struct iwl_priv *priv,
  724. enum iwlcore_card_notify notify)
  725. {
  726. int ret;
  727. switch (notify) {
  728. case IWLCORE_INIT_EVT:
  729. ret = iwl_rfkill_init(priv);
  730. if (ret)
  731. IWL_ERROR("Unable to initialize RFKILL system. "
  732. "Ignoring error: %d\n", ret);
  733. iwl_power_initialize(priv);
  734. break;
  735. case IWLCORE_START_EVT:
  736. iwl_power_update_mode(priv, 1);
  737. break;
  738. case IWLCORE_STOP_EVT:
  739. break;
  740. case IWLCORE_REMOVE_EVT:
  741. iwl_rfkill_unregister(priv);
  742. break;
  743. }
  744. return 0;
  745. }
  746. EXPORT_SYMBOL(iwlcore_low_level_notify);
  747. int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags)
  748. {
  749. u32 stat_flags = 0;
  750. struct iwl_host_cmd cmd = {
  751. .id = REPLY_STATISTICS_CMD,
  752. .meta.flags = flags,
  753. .len = sizeof(stat_flags),
  754. .data = (u8 *) &stat_flags,
  755. };
  756. return iwl_send_cmd(priv, &cmd);
  757. }
  758. EXPORT_SYMBOL(iwl_send_statistics_request);
  759. /**
  760. * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
  761. * using sample data 100 bytes apart. If these sample points are good,
  762. * it's a pretty good bet that everything between them is good, too.
  763. */
  764. static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
  765. {
  766. u32 val;
  767. int ret = 0;
  768. u32 errcnt = 0;
  769. u32 i;
  770. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  771. ret = iwl_grab_nic_access(priv);
  772. if (ret)
  773. return ret;
  774. for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
  775. /* read data comes through single port, auto-incr addr */
  776. /* NOTE: Use the debugless read so we don't flood kernel log
  777. * if IWL_DL_IO is set */
  778. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
  779. i + RTC_INST_LOWER_BOUND);
  780. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  781. if (val != le32_to_cpu(*image)) {
  782. ret = -EIO;
  783. errcnt++;
  784. if (errcnt >= 3)
  785. break;
  786. }
  787. }
  788. iwl_release_nic_access(priv);
  789. return ret;
  790. }
  791. /**
  792. * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
  793. * looking at all data.
  794. */
  795. static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
  796. u32 len)
  797. {
  798. u32 val;
  799. u32 save_len = len;
  800. int ret = 0;
  801. u32 errcnt;
  802. IWL_DEBUG_INFO("ucode inst image size is %u\n", len);
  803. ret = iwl_grab_nic_access(priv);
  804. if (ret)
  805. return ret;
  806. iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR, RTC_INST_LOWER_BOUND);
  807. errcnt = 0;
  808. for (; len > 0; len -= sizeof(u32), image++) {
  809. /* read data comes through single port, auto-incr addr */
  810. /* NOTE: Use the debugless read so we don't flood kernel log
  811. * if IWL_DL_IO is set */
  812. val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
  813. if (val != le32_to_cpu(*image)) {
  814. IWL_ERROR("uCode INST section is invalid at "
  815. "offset 0x%x, is 0x%x, s/b 0x%x\n",
  816. save_len - len, val, le32_to_cpu(*image));
  817. ret = -EIO;
  818. errcnt++;
  819. if (errcnt >= 20)
  820. break;
  821. }
  822. }
  823. iwl_release_nic_access(priv);
  824. if (!errcnt)
  825. IWL_DEBUG_INFO
  826. ("ucode image in INSTRUCTION memory is good\n");
  827. return ret;
  828. }
  829. /**
  830. * iwl_verify_ucode - determine which instruction image is in SRAM,
  831. * and verify its contents
  832. */
  833. int iwl_verify_ucode(struct iwl_priv *priv)
  834. {
  835. __le32 *image;
  836. u32 len;
  837. int ret;
  838. /* Try bootstrap */
  839. image = (__le32 *)priv->ucode_boot.v_addr;
  840. len = priv->ucode_boot.len;
  841. ret = iwlcore_verify_inst_sparse(priv, image, len);
  842. if (!ret) {
  843. IWL_DEBUG_INFO("Bootstrap uCode is good in inst SRAM\n");
  844. return 0;
  845. }
  846. /* Try initialize */
  847. image = (__le32 *)priv->ucode_init.v_addr;
  848. len = priv->ucode_init.len;
  849. ret = iwlcore_verify_inst_sparse(priv, image, len);
  850. if (!ret) {
  851. IWL_DEBUG_INFO("Initialize uCode is good in inst SRAM\n");
  852. return 0;
  853. }
  854. /* Try runtime/protocol */
  855. image = (__le32 *)priv->ucode_code.v_addr;
  856. len = priv->ucode_code.len;
  857. ret = iwlcore_verify_inst_sparse(priv, image, len);
  858. if (!ret) {
  859. IWL_DEBUG_INFO("Runtime uCode is good in inst SRAM\n");
  860. return 0;
  861. }
  862. IWL_ERROR("NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
  863. /* Since nothing seems to match, show first several data entries in
  864. * instruction SRAM, so maybe visual inspection will give a clue.
  865. * Selection of bootstrap image (vs. other images) is arbitrary. */
  866. image = (__le32 *)priv->ucode_boot.v_addr;
  867. len = priv->ucode_boot.len;
  868. ret = iwl_verify_inst_full(priv, image, len);
  869. return ret;
  870. }
  871. EXPORT_SYMBOL(iwl_verify_ucode);