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