27 #include <linux/kernel.h>
28 #include <linux/module.h>
30 #include <linux/pci.h>
33 #include <linux/sched.h>
35 #include <linux/netdevice.h>
38 #include <asm/unaligned.h>
56 D_INFO(
"ucode inst image size is %u\n", len);
58 for (i = 0; i < len; i += 100, image += 100 /
sizeof(
u32)) {
87 D_INFO(
"ucode inst image size is %u\n", len);
92 for (; len > 0; len -=
sizeof(
u32), image++) {
98 IL_ERR(
"uCode INST section is invalid at "
99 "offset 0x%x, is 0x%x, s/b 0x%x\n",
109 D_INFO(
"ucode image in INSTRUCTION memory is good\n");
128 ret = il4965_verify_inst_sparse(il, image, len);
130 D_INFO(
"Bootstrap uCode is good in inst SRAM\n");
137 ret = il4965_verify_inst_sparse(il, image, len);
139 D_INFO(
"Initialize uCode is good in inst SRAM\n");
146 ret = il4965_verify_inst_sparse(il, image, len);
148 D_INFO(
"Runtime uCode is good in inst SRAM\n");
152 IL_ERR(
"NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
159 ret = il4965_verify_inst_full(il, image, len);
217 if (eeprom_ver < il->
cfg->eeprom_ver ||
218 calib_ver < il->
cfg->eeprom_calib_ver)
221 IL_INFO(
"device EEPROM VER=0x%x, CALIB=0x%x\n", eeprom_ver, calib_ver);
225 IL_ERR(
"Unsupported (too old) EEPROM VER=0x%x < 0x%x "
226 "CALIB=0x%x < 0x%x\n", eeprom_ver, il->
cfg->eeprom_ver,
227 calib_ver, il->
cfg->eeprom_calib_ver);
255 _il_wr(il,
CSR_LED_REG, reg & CSR_LED_BSM_CTRL_MSK);
267 static int il4965_send_tx_power(
struct il_priv *il);
268 static int il4965_hw_get_temperature(
struct il_priv *il);
271 #define IL4965_UCODE_API_MAX 2
274 #define IL4965_UCODE_API_MIN 2
276 #define IL4965_FW_PRE "iwlwifi-4965-"
277 #define _IL4965_MODULE_FIRMWARE(api) IL4965_FW_PRE #api ".ucode"
278 #define IL4965_MODULE_FIRMWARE(api) _IL4965_MODULE_FIRMWARE(api)
282 il4965_verify_bsm(
struct il_priv *il)
289 D_INFO(
"Begin verify bsm\n");
294 reg +=
sizeof(
u32), image++) {
297 IL_ERR(
"BSM uCode verification failed at "
298 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
305 D_INFO(
"BSM bootstrap uCode image OK\n");
343 il4965_load_bsm(
struct il_priv *il)
356 D_INFO(
"Begin load bsm\n");
383 reg_offset +=
sizeof(
u32), image++)
386 ret = il4965_verify_bsm(il);
400 for (i = 0; i < 100; i++) {
407 D_INFO(
"BSM write complete, poll %d iterations\n", i);
409 IL_ERR(
"BSM write did not complete!\n");
430 il4965_set_ucode_ptrs(
struct il_priv *il)
449 D_INFO(
"Runtime uCode pointers are set.\n");
466 il4965_init_alive_start(
struct il_priv *il)
474 D_INFO(
"Bad \"initialize\" uCode load.\n");
484 D_INFO(
"Initialization Alive received.\n");
485 if (il4965_set_ucode_ptrs(il)) {
488 D_INFO(
"Couldn't set up uCode pointers.\n");
498 iw4965_is_ht40_channel(
__le32 rxon_flags)
533 spin_unlock_irqrestore(&il->
lock, flags);
540 il4965_chain_noise_reset(
struct il_priv *il)
556 memset(&cmd, 0,
sizeof(cmd));
562 IL_ERR(
"Could not send C_PHY_CALIBRATION\n");
564 D_CALIB(
"Run chain_noise_calibrate\n");
582 *res = ((num * 2 + denom) / (denom * 2)) * sign;
599 il4965_get_voltage_compensation(
s32 eeprom_voltage,
s32 current_voltage)
607 il4965_math_div_round(current_voltage - eeprom_voltage,
610 if (current_voltage > eeprom_voltage)
612 if ((comp < -2) || (comp > 2))
645 il4965_get_sub_band(
const struct il_priv *il,
u32 channel)
650 if (il->
calib_info->band_info[b].ch_from == 0)
653 if (channel >= il->
calib_info->band_info[b].ch_from &&
669 il4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
683 il4965_interpolate_chan(
struct il_priv *il,
u32 channel,
695 s = il4965_get_sub_band(il, channel);
696 if (s >= EEPROM_TX_POWER_BANDS) {
697 IL_ERR(
"Tx Power can not find channel %d\n", channel);
705 D_TXPOWER(
"channel %d subband %d factory cal ch %d & %d\n", channel, s,
717 (
u8) il4965_interpolate_value(channel, ch_i1,
721 (
u8) il4965_interpolate_value(channel, ch_i1,
725 (
u8) il4965_interpolate_value(channel, ch_i1,
730 (
s8) il4965_interpolate_value(channel, ch_i1,
734 D_TXPOWER(
"chain %d meas %d AP1=%d AP2=%d AP=%d\n", c,
737 D_TXPOWER(
"chain %d meas %d NI1=%d NI2=%d NI=%d\n", c,
740 D_TXPOWER(
"chain %d meas %d PA1=%d PA2=%d PA=%d\n", c,
742 D_TXPOWER(
"chain %d meas %d T1=%d T2=%d T=%d\n", c,
753 static s32 back_off_table[] = {
754 10, 10, 10, 10, 10, 15, 17, 20,
755 10, 10, 10, 10, 10, 15, 17, 20,
756 10, 10, 10, 10, 10, 15, 17, 20,
757 10, 10, 10, 10, 10, 15, 17, 20,
763 static struct il4965_txpower_comp_entry {
764 s32 degrees_per_05db_a;
765 s32 degrees_per_05db_a_denom;
780 get_min_power_idx(
s32 rate_power_idx,
u32 band)
783 if ((rate_power_idx & 7) <= 4)
794 static const struct gain_entry gain_table[2][108] = {
1020 il4965_fill_txpower_tbl(
struct il_priv *il,
u8 band,
u16 channel,
u8 is_ht40,
1024 u8 saturation_power;
1026 s32 user_target_power;
1030 s32 current_regulatory;
1039 s32 voltage_compensation;
1040 s32 degrees_per_05db_num;
1041 s32 degrees_per_05db_denom;
1043 s32 temperature_comp[2];
1044 s32 factory_gain_idx[2];
1045 s32 factory_actual_pwr[2];
1053 D_TXPOWER(
"chan %d band %d is_ht40 %d\n", channel, band, is_ht40);
1057 if (!il_is_channel_valid(ch_info))
1062 txatten_grp = il4965_get_tx_atten_grp(channel);
1063 if (txatten_grp < 0) {
1064 IL_ERR(
"Can't find txatten group for channel %d.\n", channel);
1068 D_TXPOWER(
"channel %d belongs to txatten group %d\n", channel,
1081 saturation_power = il->
calib_info->saturation_power24;
1083 saturation_power = il->
calib_info->saturation_power52;
1110 il4965_interpolate_chan(il, channel, &ch_eeprom_info);
1115 voltage_compensation =
1116 il4965_get_voltage_compensation(voltage, init_voltage);
1118 D_TXPOWER(
"curr volt %d eeprom volt %d volt comp %d\n", init_voltage,
1119 voltage, voltage_compensation);
1128 degrees_per_05db_num =
1129 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1130 degrees_per_05db_denom =
1131 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1134 for (c = 0; c < 2; c++) {
1135 measurement = &ch_eeprom_info.measurements[
c][1];
1140 il4965_math_div_round((current_temp -
1141 factory_temp) * degrees_per_05db_denom,
1142 degrees_per_05db_num,
1143 &temperature_comp[c]);
1145 factory_gain_idx[
c] = measurement->
gain_idx;
1149 D_TXPOWER(
"fctry tmp %d, " "curr tmp %d, comp %d steps\n",
1150 factory_temp, current_temp, temperature_comp[c]);
1152 D_TXPOWER(
"fctry idx %d, fctry pwr %d\n", factory_gain_idx[c],
1153 factory_actual_pwr[c]);
1165 current_regulatory =
1170 current_regulatory = reg_limit;
1175 power_limit = saturation_power - back_off_table[
i];
1176 if (power_limit > current_regulatory)
1177 power_limit = current_regulatory;
1181 target_power = user_target_power;
1182 if (target_power > power_limit)
1183 target_power = power_limit;
1185 D_TXPOWER(
"rate %d sat %d reg %d usr %d tgt %d\n", i,
1186 saturation_power - back_off_table[i],
1187 current_regulatory, user_target_power, target_power);
1190 for (c = 0; c < 2; c++) {
1196 tx_atten[txatten_grp][c]);
1202 (
u8) (factory_gain_idx[c] -
1203 (target_power - factory_actual_pwr[c]) -
1204 temperature_comp[
c] - voltage_compensation +
1210 if (power_idx < get_min_power_idx(i, band))
1211 power_idx = get_min_power_idx(i, band);
1223 if (power_idx > 107) {
1224 IL_WARN(
"txpower idx %d > 107\n", power_idx);
1227 if (power_idx < 0) {
1228 IL_WARN(
"txpower idx %d < 0\n", power_idx);
1234 gain_table[band][power_idx].
radio;
1236 gain_table[band][power_idx].
dsp;
1239 "gain 0x%02x dsp %d\n", c, atten_value,
1240 power_idx,
tx_power.s.radio_tx_gain[c],
1258 il4965_send_tx_power(
struct il_priv *il)
1263 bool is_ht40 =
false;
1264 u8 ctrl_chan_high = 0;
1268 "TX Power requested while scanning!\n"))
1273 is_ht40 = iw4965_is_ht40_channel(il->
active.flags);
1283 is_ht40, ctrl_chan_high, &cmd.
tx_power);
1294 il4965_send_rxon_assoc(
struct il_priv *il)
1310 D_INFO(
"Using current RXON_ASSOC. Not resending.\n");
1314 rxon_assoc.flags = il->
staging.flags;
1315 rxon_assoc.filter_flags = il->
staging.filter_flags;
1316 rxon_assoc.ofdm_basic_rates = il->
staging.ofdm_basic_rates;
1317 rxon_assoc.cck_basic_rates = il->
staging.cck_basic_rates;
1318 rxon_assoc.reserved = 0;
1319 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1320 il->
staging.ofdm_ht_single_stream_basic_rates;
1321 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1322 il->
staging.ofdm_ht_dual_stream_basic_rates;
1323 rxon_assoc.rx_chain_select_flags = il->
staging.rx_chain;
1333 il4965_commit_rxon(
struct il_priv *il)
1340 if (!il_is_alive(il))
1348 IL_ERR(
"Invalid RXON configuration. Not committing.\n");
1358 D_11H(
"abort channel switch on %d\n",
1367 ret = il_send_rxon_assoc(il);
1369 IL_ERR(
"Error setting RXON_ASSOC (%d)\n", ret);
1374 il_print_rx_config_cmd(il);
1387 if (il_is_associated(il) && new_assoc) {
1388 D_INFO(
"Toggling associated bit on current RXON\n");
1399 IL_ERR(
"Error clearing ASSOC_MSK (%d)\n", ret);
1406 IL_ERR(
"Failed to restore WEP keys (%d)\n", ret);
1411 D_INFO(
"Sending RXON\n" "* with%s RXON_FILTER_ASSOC_MSK\n"
1412 "* channel = %d\n" "* bssid = %pM\n", (new_assoc ?
"" :
"out"),
1426 IL_ERR(
"Error setting new RXON (%d)\n", ret);
1429 D_INFO(
"Return from !new_assoc RXON.\n");
1435 IL_ERR(
"Failed to restore WEP keys (%d)\n", ret);
1448 IL_ERR(
"Error setting new RXON (%d)\n", ret);
1453 il_print_rx_config_cmd(il);
1461 IL_ERR(
"Error sending TX power (%d)\n", ret);
1469 il4965_hw_channel_switch(
struct il_priv *il,
1474 bool is_ht40 =
false;
1475 u8 ctrl_chan_high = 0;
1478 u32 switch_time_in_usec, ucode_switch_time;
1489 is_ht40 = iw4965_is_ht40_channel(il->
staging.flags);
1495 cmd.expect_beacon = 0;
1496 ch = ch_switch->
channel->hw_value;
1498 cmd.rxon_flags = il->
staging.flags;
1499 cmd.rxon_filter_flags = il->
staging.filter_flags;
1500 switch_count = ch_switch->
count;
1501 tsf_low = ch_switch->
timestamp & 0x0ffffffff;
1514 if (switch_count <= 1)
1517 switch_time_in_usec =
1524 ucode_switch_time, beacon_interval);
1526 D_11H(
"uCode time for the switch is 0x%x\n", cmd.switch_time);
1529 cmd.expect_beacon = il_is_channel_radar(ch_info);
1531 IL_ERR(
"invalid channel switch from %u to %u\n",
1536 rc = il4965_fill_txpower_tbl(il, band, ch, is_ht40, ctrl_chan_high,
1539 D_11H(
"error:%d fill txpower_tbl\n", rc);
1554 int txq_id = txq->
q.id;
1555 int write_ptr = txq->
q.write_ptr;
1563 scd_bc_tbl[txq_id].
tfd_offset[write_ptr] = bc_ent;
1578 il4965_hw_get_temperature(
struct il_priv *il)
1587 D_TEMP(
"Running HT40 temperature calibration\n");
1593 D_TEMP(
"Running temperature calibration\n");
1608 vt = sign_extend32(R4, 23);
1614 D_TEMP(
"Calib values R[1-3]: %d %d %d R4: %d\n", R1, R2, R3, vt);
1617 IL_ERR(
"Calibration conflict R1 == R3\n");
1624 temperature /= (R3 -
R1);
1628 D_TEMP(
"Calibrated temperature: %dK, %dC\n", temperature,
1635 #define IL_TEMPERATURE_THRESHOLD 3
1647 il4965_is_temp_calib_needed(
struct il_priv *il)
1652 D_TEMP(
"Temperature not updated -- no stats.\n");
1659 if (temp_diff < 0) {
1660 D_POWER(
"Getting cooler, delta %d\n", temp_diff);
1661 temp_diff = -temp_diff;
1662 }
else if (temp_diff == 0)
1663 D_POWER(
"Temperature unchanged\n");
1665 D_POWER(
"Getting warmer, delta %d\n", temp_diff);
1668 D_POWER(
" => thermal txpower calib not needed\n");
1672 D_POWER(
" => thermal txpower calib needed\n");
1682 temp = il4965_hw_get_temperature(il);
1688 D_TEMP(
"Temperature changed " "from %dC to %dC\n",
1692 D_TEMP(
"Temperature " "initialized to %dC\n",
1701 il4965_is_temp_calib_needed(il))
1706 il4965_get_hcmd_size(
u8 cmd_id,
u16 len)
1737 il4965_post_scan(
struct il_priv *il)
1748 il4965_post_associate(
struct il_priv *il)
1762 conf = &il->
hw->conf;
1769 IL_WARN(
"RXON timing - " "Attempting to continue.\n");
1775 if (il->
ops->set_rxon_chain)
1776 il->
ops->set_rxon_chain(il);
1783 if (vif->
bss_conf.use_short_preamble)
1800 switch (vif->
type) {
1807 IL_ERR(
"%s Should not be called in %d mode\n", __func__,
1819 il4965_chain_noise_reset(il);
1824 il4965_config_ap(
struct il_priv *il)
1835 if (!il_is_associated(il)) {
1844 IL_WARN(
"RXON timing failed - "
1845 "Attempting to continue.\n");
1850 if (il->
ops->set_rxon_chain)
1851 il->
ops->set_rxon_chain(il);
1855 if (vif->
bss_conf.use_short_preamble)
1876 .txq_update_byte_cnt_tbl = il4965_txq_update_byte_cnt_tbl,
1880 .is_valid_rtc_data_addr = il4965_hw_valid_rtc_data_addr,
1881 .init_alive_start = il4965_init_alive_start,
1882 .load_ucode = il4965_load_bsm,
1885 .set_channel_switch = il4965_hw_channel_switch,
1887 .send_tx_power = il4965_send_tx_power,
1892 .rxon_assoc = il4965_send_rxon_assoc,
1893 .commit_rxon = il4965_commit_rxon,
1896 .get_hcmd_size = il4965_get_hcmd_size,
1897 .build_addsta_hcmd = il4965_build_addsta_hcmd,
1899 .post_scan = il4965_post_scan,
1901 .post_associate = il4965_post_associate,
1902 .config_ap = il4965_config_ap,
1906 .send_led_cmd = il4965_send_led_cmd,
1910 .name =
"Intel(R) Wireless WiFi Link 4965AGN",
1933 .led_compensation = 61,
1936 .temperature_kelvin =
true,
1937 .ucode_tracing =
true,
1938 .sensitivity_calib_by_driver =
true,
1939 .chain_noise_calib_by_driver =
true,
1941 .regulatory_bands = {