27 #include <linux/kernel.h>
28 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
34 #include <linux/sched.h>
36 #include <linux/netdevice.h>
39 #include <asm/unaligned.h>
60 #define IL_DECLARE_RATE_INFO(r, ip, in, rp, rn, pp, np) \
61 [RATE_##r##M_IDX] = { RATE_##r##M_PLCP, \
69 RATE_##r##M_IDX_TBL, \
70 RATE_##ip##M_IDX_TBL }
96 il3945_get_prev_ieee_rate(
u8 rate_idx)
106 #define IL_EVT_DISABLE (0)
107 #define IL_EVT_DISABLE_SIZE (1532/32)
176 if (!il3945_hw_valid_rtc_data_addr(base)) {
177 IL_ERR(
"Invalid event log pointer 0x%08X\n", base);
185 D_INFO(
"Disabling selected uCode log events at 0x%x\n",
192 D_INFO(
"Selected uCode log events may be disabled\n");
193 D_INFO(
" by writing \"1\"s into disable bitmap\n");
194 D_INFO(
" in SRAM at 0x%x, size %d u32s\n", disable_ptr,
201 il3945_hwrate_to_plcp_idx(
u8 plcp)
206 if (il3945_rates[idx].plcp == plcp)
211 #ifdef CONFIG_IWLEGACY_DEBUG
212 #define TX_STATUS_ENTRY(x) case TX_3945_STATUS_FAIL_ ## x: return #x
220 TX_STATUS_ENTRY(SHORT_LIMIT);
221 TX_STATUS_ENTRY(LONG_LIMIT);
222 TX_STATUS_ENTRY(FIFO_UNDERRUN);
223 TX_STATUS_ENTRY(MGMNT_ABORT);
224 TX_STATUS_ENTRY(NEXT_FRAG);
225 TX_STATUS_ENTRY(LIFE_EXPIRE);
226 TX_STATUS_ENTRY(DEST_PS);
228 TX_STATUS_ENTRY(BT_RETRY);
229 TX_STATUS_ENTRY(STA_INVALID);
230 TX_STATUS_ENTRY(FRAG_DROPPED);
231 TX_STATUS_ENTRY(TID_DISABLE);
232 TX_STATUS_ENTRY(FRAME_FLUSHED);
233 TX_STATUS_ENTRY(INSUFFICIENT_CF_POLL);
234 TX_STATUS_ENTRY(TX_LOCKED);
235 TX_STATUS_ENTRY(NO_BEACON_ON_RADAR);
241 static inline const char *
242 il3945_get_tx_fail_reason(
u32 status)
256 int next_rate = il3945_get_prev_ieee_rate(rate);
267 il_is_associated(il)) {
288 il3945_tx_queue_reclaim(
struct il_priv *il,
int txq_id,
int idx)
296 for (idx = il_queue_inc_wrap(idx, q->
n_bd); q->
read_ptr != idx;
299 skb = txq->
skbs[txq->
q.read_ptr];
302 il->
ops->txq_free_tfd(il, txq);
307 il_wake_queue(il, txq);
327 if (idx >= txq->
q.n_bd || il_queue_used(&txq->
q, idx) == 0) {
328 IL_ERR(
"Read idx for DMA queue txq_id (%d) idx %d "
329 "is out of range [0-%d] %d %d\n", txq_id, idx,
330 txq->
q.n_bd, txq->
q.write_ptr, txq->
q.read_ptr);
335 info = IEEE80211_SKB_CB(txq->
skbs[txq->
q.read_ptr]);
336 ieee80211_tx_info_clear_status(info);
339 rate_idx = il3945_hwrate_to_plcp_idx(tx_resp->
rate);
345 info->
status.rates[0].idx = rate_idx;
346 info->
status.rates[0].count = fail + 1;
353 D_TX(
"Tx queue %d Status %s (0x%08x) plcp rate %d retries %d\n", txq_id,
354 il3945_get_tx_fail_reason(status), status, tx_resp->
rate,
358 il3945_tx_queue_reclaim(il, txq_id, idx);
361 IL_ERR(
"TODO: Implement Tx ABORT REQUIRED!!!\n");
371 #ifdef CONFIG_IWLEGACY_DEBUGFS
380 prev_stats = (
__le32 *) &il->_3945.stats;
381 accum_stats = (
u32 *) &il->_3945.accum_stats;
382 delta = (
u32 *) &il->_3945.delta_stats;
383 max_delta = (
u32 *) &il->_3945.max_delta;
387 sizeof(
__le32), stats++, prev_stats++, delta++, max_delta++,
392 *accum_stats += *
delta;
393 if (*delta > *max_delta)
401 il->_3945.accum_stats.general.ttl_timestamp =
402 il->_3945.stats.general.ttl_timestamp;
411 D_RX(
"Statistics notification received (%d vs %d).\n",
414 #ifdef CONFIG_IWLEGACY_DEBUGFS
415 il3945_accumulative_stats(il, (
__le32 *) &pkt->
u.
raw);
418 memcpy(&il->_3945.stats, pkt->
u.
raw,
sizeof(il->_3945.stats));
428 #ifdef CONFIG_IWLEGACY_DEBUGFS
429 memset(&il->_3945.accum_stats, 0,
431 memset(&il->_3945.delta_stats, 0,
433 memset(&il->_3945.max_delta, 0,
436 D_RX(
"Statistics have been cleared\n");
456 return ether_addr_equal(header->
addr3, il->
bssid);
459 return ether_addr_equal(header->
addr2, il->
bssid);
481 D_DROP(
"Corruption detected!\n");
487 D_DROP(
"Dropping packet while interface is not open.\n");
491 skb = dev_alloc_skb(128);
493 IL_ERR(
"dev_alloc_skb failed\n");
502 (
void *)rx_hdr->
payload - (
void *)pkt, len,
506 memcpy(IEEE80211_SKB_RXCB(skb), stats,
sizeof(*stats));
513 #define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
525 u16 rx_stats_noise_diff __maybe_unused =
539 rx_status.
rate_idx = il3945_hwrate_to_plcp_idx(rx_hdr->
rate);
552 D_DROP(
"dsp size out of range [0,20]: %d/n",
559 D_RX(
"Bad CRC or FIFO: 0x%08X.\n", rx_end->
status);
566 D_STATS(
"Rssi %d sig_avg %d noise_diff %d\n", rx_status.
signal,
567 rx_stats_sig_avg, rx_stats_noise_diff);
571 network_packet = il3945_is_network_packet(il, header);
573 D_STATS(
"[%c] %d RSSI:%d Signal:%u, Rate:%u\n",
577 if (network_packet) {
578 il->_3945.last_beacon_time =
581 il->_3945.last_rx_rssi = rx_status.
signal;
584 il3945_pass_packet_to_mac80211(il, rxb, &rx_status);
600 memset(tfd, 0,
sizeof(*tfd));
605 IL_ERR(
"Error can not send more than %d chunks\n",
630 int idx = txq->
q.read_ptr;
678 u16 hw_value = ieee80211_get_tx_rate(il->
hw, info)->hw_value;
679 u16 rate_idx =
min(hw_value & 0xffff, RATE_COUNT_3945 - 1);
682 const u8 rts_retry_limit = 7;
688 rate = il3945_rates[rate_idx].
plcp;
696 if (ieee80211_is_probe_resp(fc))
697 data_retry_limit = 3;
714 D_RATE(
"Tx sta id: %d, rate: %d (plcp), flags: 0x%4X "
715 "cck/ofdm mask: 0x%x/0x%x\n", sta_id, tx_cmd->
rate,
723 unsigned long flags_spin;
736 spin_unlock_irqrestore(&il->
sta_lock, flags_spin);
738 D_RATE(
"SCALE sync station %d to rate %d\n", sta_id, tx_rate);
743 il3945_set_pwr_vmain(
struct il_priv *il)
792 il3945_tx_reset(
struct il_priv *il)
828 il3945_txq_ctx_reset(
struct il_priv *il)
840 rc = il3945_tx_reset(il);
845 for (txq_id = 0; txq_id < il->
hw_params.max_txq_num; txq_id++) {
848 IL_ERR(
"Tx %d queue init failed\n", txq_id);
866 il3945_apm_init(
struct il_priv *il)
883 il3945_nic_config(
struct il_priv *il)
892 D_INFO(
"HW Revision ID = 0x%X\n", rev_id);
897 D_INFO(
"3945 RADIO-MB type\n");
901 D_INFO(
"3945 RADIO-MM type\n");
907 D_INFO(
"SKU OP mode is mrc\n");
911 D_INFO(
"SKU OP mode is basic\n");
926 D_INFO(
"Card M type A version is 0x%X\n",
929 D_INFO(
"Card M type B version is 0x%X\n",
934 spin_unlock_irqrestore(&il->
lock,
flags);
937 D_RF_KILL(
"SW RF KILL supported in EEPROM.\n");
940 D_RF_KILL(
"HW RF KILL supported in EEPROM.\n");
952 spin_unlock_irqrestore(&il->
lock, flags);
954 il3945_set_pwr_vmain(il);
955 il3945_nic_config(il);
961 IL_ERR(
"Unable to initialize Rx queue\n");
969 il3945_rx_init(il, rxq);
978 rc = il3945_txq_ctx_reset(il);
999 for (txq_id = 0; txq_id < il->
hw_params.max_txq_num; txq_id++)
1019 for (txq_id = 0; txq_id < il->
hw_params.max_txq_num; txq_id++) {
1033 il3945_hw_reg_adjust_power_by_temp(
int new_reading,
int old_reading)
1035 return (new_reading - old_reading) * (-11) / 100;
1058 il3945_hw_reg_txpower_get_temperature(
struct il_priv *il)
1070 if (il3945_hw_reg_temp_out_of_range(temperature)) {
1071 IL_ERR(
"Error bad temperature value %d\n", temperature);
1076 temperature = eeprom->
groups[2].temperature;
1087 #define IL_TEMPERATURE_LIMIT_TIMER 6
1096 il3945_is_temp_calib_needed(
struct il_priv *il)
1100 il->
temperature = il3945_hw_reg_txpower_get_temperature(il);
1104 if (temp_diff < 0) {
1105 D_POWER(
"Getting cooler, delta %d,\n", temp_diff);
1106 temp_diff = -temp_diff;
1107 }
else if (temp_diff == 0)
1110 D_POWER(
"Getting warmer, delta %d,\n", temp_diff);
1114 D_POWER(
"Timed thermal calib not needed\n");
1118 D_POWER(
"Timed thermal calib needed\n");
1126 #define IL_MAX_GAIN_ENTRIES 78
1127 #define IL_CCK_FROM_OFDM_POWER_DIFF -5
1128 #define IL_CCK_FROM_OFDM_IDX_DIFF (10)
1296 il3945_hw_reg_fix_power_idx(
int idx)
1306 #define REG_RECALIB_PERIOD (60)
1315 il3945_hw_reg_set_scan_power(
struct il_priv *il,
u32 scan_tbl_idx,
s32 rate_idx,
1316 const s8 *clip_pwrs,
1339 ch_info->
power_info[rate_idx].power_table_idx - (power -
1356 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
1359 scan_power_info->
tpc.tx_gain =
1360 power_gain_table[band_idx][power_idx].
tx_gain;
1361 scan_power_info->
tpc.dsp_atten =
1362 power_gain_table[band_idx][power_idx].
dsp_atten;
1372 il3945_send_tx_power(
struct il_priv *il)
1383 "TX Power requested while scanning!\n"))
1391 IL_ERR(
"Failed to get channel info for channel %d [%d]\n", chan,
1396 if (!il_is_channel_valid(ch_info)) {
1397 D_POWER(
"Not calling TX_PWR_TBL_CMD on " "non-Tx channel.\n");
1407 txpower.
power[
i].rate = il3945_rates[rate_idx].
plcp;
1409 D_POWER(
"ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
1411 txpower.
power[i].tpc.tx_gain,
1412 txpower.
power[i].tpc.dsp_atten, txpower.
power[i].rate);
1418 txpower.
power[
i].rate = il3945_rates[rate_idx].
plcp;
1420 D_POWER(
"ch %d:%d rf %d dsp %3d rate code 0x%02x\n",
1422 txpower.
power[i].tpc.tx_gain,
1423 txpower.
power[i].tpc.dsp_atten, txpower.
power[i].rate);
1452 int power_changed = 0;
1454 const s8 *clip_pwrs;
1458 clip_pwrs = il->_3945.clip_groups[ch_info->
group_idx].clip_powers;
1485 if (power_changed) {
1517 if (ch_info->tgd_data.max_power != 0)
1519 min(ch_info->tgd_data.max_power,
1520 ch_info->
eeprom.max_power_avg);
1525 max_power = ch_info->
eeprom.max_power_avg;
1541 il3945_hw_reg_comp_txpower_temp(
struct il_priv *il)
1546 const s8 *clip_pwrs;
1561 a_band = il_is_channel_a_band(ch_info);
1569 il3945_hw_reg_adjust_power_by_temp(temperature, ref_temp);
1574 ch_info->
power_info[rate_idx].base_power_idx;
1577 power_idx += delta_idx;
1580 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
1581 ch_info->
power_info[rate_idx].power_table_idx =
1584 power_gain_table[a_band][power_idx];
1589 il->_3945.clip_groups[ch_info->
group_idx].clip_powers;
1597 il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
1598 actual_idx, clip_pwrs,
1604 return il->
ops->send_tx_power(il);
1616 D_POWER(
"Requested Tx power same as current " "limit: %ddBm.\n",
1621 D_POWER(
"Setting upper limit clamp to %ddBm.\n", power);
1628 a_band = il_is_channel_a_band(ch_info);
1632 max_power = il3945_hw_reg_get_ch_txpower_limit(ch_info);
1633 max_power =
min(power, max_power);
1638 il3945_hw_reg_set_new_power(il, ch_info);
1644 il3945_is_temp_calib_needed(il);
1645 il3945_hw_reg_comp_txpower_temp(il);
1651 il3945_send_rxon_assoc(
struct il_priv *il)
1658 .len =
sizeof(rxon_assoc),
1660 .
data = &rxon_assoc,
1669 D_INFO(
"Using current RXON_ASSOC. Not resending.\n");
1673 rxon_assoc.flags = il->
staging.flags;
1674 rxon_assoc.filter_flags = il->
staging.filter_flags;
1675 rxon_assoc.ofdm_basic_rates = il->
staging.ofdm_basic_rates;
1676 rxon_assoc.cck_basic_rates = il->
staging.cck_basic_rates;
1677 rxon_assoc.reserved = 0;
1685 IL_ERR(
"Bad return from C_RXON_ASSOC command\n");
1714 if (!il_is_alive(il))
1726 IL_ERR(
"Invalid RXON configuration. Not committing.\n");
1734 rc = il_send_rxon_assoc(il);
1736 IL_ERR(
"Error setting RXON_ASSOC "
1737 "configuration (%d).\n", rc);
1741 memcpy(active_rxon, staging_rxon,
sizeof(*active_rxon));
1754 if (il_is_associated(il) && new_assoc) {
1755 D_INFO(
"Toggling associated bit on current RXON\n");
1771 IL_ERR(
"Error clearing ASSOC_MSK on current "
1772 "configuration (%d).\n", rc);
1779 D_INFO(
"Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
1780 "* channel = %d\n" "* bssid = %pM\n", (new_assoc ?
"" :
"out"),
1781 le16_to_cpu(staging_rxon->channel), staging_rxon->bssid_addr);
1787 staging_rxon->reserved4 = 0;
1788 staging_rxon->reserved5 = 0;
1796 IL_ERR(
"Error setting new configuration (%d).\n", rc);
1800 memcpy(active_rxon, staging_rxon,
sizeof(*active_rxon));
1811 IL_ERR(
"Error setting Tx power (%d).\n", rc);
1818 IL_ERR(
"Error setting HW rate table: %02X\n", rc);
1840 if (!il3945_is_temp_calib_needed(il))
1846 il3945_hw_reg_comp_txpower_temp(il);
1857 _3945.thermal_periodic.work);
1879 il3945_hw_reg_get_ch_grp_idx(
struct il_priv *il,
1889 if (il_is_channel_a_band(ch_info)) {
1891 grp_channel = ch_grp[
group].group_channel;
1892 if (ch_info->
channel <= grp_channel) {
1903 D_POWER(
"Chnl %d mapped to grp %d\n", ch_info->
channel, group_idx);
1914 il3945_hw_reg_get_matched_power_idx(
struct il_priv *il,
s8 requested_power,
1915 s32 setting_idx,
s32 *new_idx)
1920 s32 power = 2 * requested_power;
1927 chnl_grp = &eeprom->
groups[setting_idx];
1929 for (i = 0; i < 5; i++) {
1930 if (power == samples[i].power) {
1931 *new_idx = samples[
i].gain_idx;
1936 if (power > samples[1].power) {
1939 }
else if (power > samples[2].power) {
1942 }
else if (power > samples[3].power) {
1950 denominator = (
s32) samples[idx1].power - (
s32) samples[idx0].power;
1951 if (denominator == 0)
1953 gains0 = (
s32) samples[idx0].gain_idx * (1 << 19);
1954 gains1 = (
s32) samples[idx1].gain_idx * (1 << 19);
1956 gains0 + (gains1 - gains0) * ((
s32) power -
1957 (
s32) samples[idx0].power) /
1958 denominator + (1 << 18);
1959 *new_idx =
res >> 19;
1971 D_POWER(
"Initializing factory calib info from EEPROM\n");
1979 if (
group->saturation_power < 40) {
1980 IL_WARN(
"Error: saturation power is %d, "
1981 "less than minimum expected 40\n",
1982 group->saturation_power);
1995 clip_pwrs = (
s8 *) il->_3945.clip_groups[i].clip_powers;
1998 satur_pwr = (
s8) (
group->saturation_power >> 1);
2002 rate_idx++, clip_pwrs++) {
2006 *clip_pwrs = satur_pwr;
2008 *clip_pwrs = satur_pwr - 5;
2012 *clip_pwrs = satur_pwr - 7;
2014 *clip_pwrs = satur_pwr - 10;
2018 *clip_pwrs = satur_pwr - 9;
2020 *clip_pwrs = satur_pwr - 12;
2023 *clip_pwrs = satur_pwr;
2054 const s8 *clip_pwrs;
2057 u8 pwr_idx, base_pwr_idx, a_band;
2063 temperature = il3945_hw_reg_txpower_get_temperature(il);
2066 il3945_hw_reg_init_channel_groups(il);
2071 a_band = il_is_channel_a_band(ch_info);
2072 if (!il_is_channel_valid(ch_info))
2076 ch_info->
group_idx = il3945_hw_reg_get_ch_grp_idx(il, ch_info);
2080 il->_3945.clip_groups[ch_info->
group_idx].clip_powers;
2085 il3945_hw_reg_adjust_power_by_temp(temperature,
2101 clip_pwrs[rate_idx]);
2107 rc = il3945_hw_reg_get_matched_power_idx(il, pwr,
2112 IL_ERR(
"Invalid power idx\n");
2118 power_idx += delta_idx;
2121 power_idx = il3945_hw_reg_fix_power_idx(power_idx);
2126 pwr_info->
tpc.tx_gain =
2127 power_gain_table[a_band][power_idx].
tx_gain;
2128 pwr_info->
tpc.dsp_atten =
2129 power_gain_table[a_band][power_idx].
dsp_atten;
2140 pwr_idx = il3945_hw_reg_fix_power_idx(pwr_idx);
2141 gain = power_gain_table[a_band][pwr_idx].
tx_gain;
2142 dsp_atten = power_gain_table[a_band][pwr_idx].
dsp_atten;
2147 for (rate_idx = 0; rate_idx <
IL_CCK_RATES; rate_idx++) {
2154 pwr_info->
tpc.dsp_atten = dsp_atten;
2163 il3945_hw_reg_set_scan_power(il, scan_tbl_idx,
2164 actual_idx, clip_pwrs,
2183 IL_ERR(
"Can't stop Rx DMA.\n");
2191 int txq_id = txq->
q.id;
2217 il3945_get_hcmd_size(
u8 cmd_id,
u16 len)
2248 il3945_add_bssid_station(
struct il_priv *il,
const u8 *
addr,
u8 * sta_id_r)
2252 unsigned long flags;
2259 IL_ERR(
"Unable to add station %pM\n", addr);
2268 spin_unlock_irqrestore(&il->
sta_lock, flags);
2277 struct il_vif_priv *vif_priv = (
void *)vif->drv_priv;
2282 il3945_add_bssid_station(il, vif->
bss_conf.bssid,
2306 int rc,
i,
idx, prev_idx;
2312 for (i = 0; i <
ARRAY_SIZE(il3945_rates); i++) {
2317 prev_idx = il3945_get_prev_ieee_rate(i);
2323 D_RATE(
"Select A mode rate scale\n");
2339 D_RATE(
"Select B/G mode rate scale\n");
2344 il_is_associated(il)) {
2349 il3945_rates[idx].table_rs_idx;
2379 il->_3945.shared_virt =
2382 if (!il->_3945.shared_virt) {
2383 IL_ERR(
"failed to allocate pci memory\n");
2412 unsigned int frame_size;
2415 memset(tx_beacon_cmd, 0,
sizeof(*tx_beacon_cmd));
2417 tx_beacon_cmd->
tx.sta_id = il->
hw_params.bcast_id;
2422 sizeof(frame->
u) -
sizeof(*tx_beacon_cmd));
2427 tx_beacon_cmd->
tx.rate =
rate;
2428 tx_beacon_cmd->
tx.tx_flags =
2432 tx_beacon_cmd->
tx.supp_rates[0] =
2451 il3945_bg_reg_txpower_periodic);
2462 il3945_verify_bsm(
struct il_priv *il)
2469 D_INFO(
"Begin verify bsm\n");
2474 reg +=
sizeof(
u32), image++) {
2477 IL_ERR(
"BSM uCode verification failed at "
2478 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
2485 D_INFO(
"BSM bootstrap uCode image OK\n");
2505 il3945_eeprom_acquire_semaphore(
struct il_priv *il)
2512 il3945_eeprom_release_semaphore(
struct il_priv *il)
2550 il3945_load_bsm(
struct il_priv *il)
2563 D_INFO(
"Begin load bsm\n");
2587 reg_offset +=
sizeof(
u32), image++)
2590 rc = il3945_verify_bsm(il);
2604 for (i = 0; i < 100; i++) {
2611 D_INFO(
"BSM write complete, poll %d iterations\n", i);
2613 IL_ERR(
"BSM write did not complete!\n");
2628 .load_ucode = il3945_load_bsm,
2630 .apm_init = il3945_apm_init,
2631 .send_tx_power = il3945_send_tx_power,
2632 .is_valid_rtc_data_addr = il3945_hw_valid_rtc_data_addr,
2633 .eeprom_acquire_semaphore = il3945_eeprom_acquire_semaphore,
2634 .eeprom_release_semaphore = il3945_eeprom_release_semaphore,
2636 .rxon_assoc = il3945_send_rxon_assoc,
2639 .get_hcmd_size = il3945_get_hcmd_size,
2640 .build_addsta_hcmd = il3945_build_addsta_hcmd,
2646 .manage_ibss_station = il3945_manage_ibss_station,
2648 .send_led_cmd = il3945_send_led_cmd,
2651 static struct il_cfg il3945_bg_cfg = {
2666 .led_compensation = 64,
2669 .regulatory_bands = {
2680 static struct il_cfg il3945_abg_cfg = {
2695 .led_compensation = 64,
2698 .regulatory_bands = {