+@@ -558,8 +558,7 @@ struct ath_ant_comb {
+ #define SC_OP_BT_PRIORITY_DETECTED BIT(12)
+ #define SC_OP_BT_SCAN BIT(13)
+ #define SC_OP_ANI_RUN BIT(14)
+-#define SC_OP_ENABLE_APM BIT(15)
+-#define SC_OP_PRIM_STA_VIF BIT(16)
++#define SC_OP_PRIM_STA_VIF BIT(15)
+
+ /* Powersave flags */
+ #define PS_WAIT_FOR_BEACON BIT(0)
+@@ -664,7 +663,6 @@ extern int led_blink;
+ extern bool is_ath9k_unloaded;
+
+ irqreturn_t ath_isr(int irq, void *dev);
+-void ath9k_init_crypto(struct ath_softc *sc);
+ int ath9k_init_device(u16 devid, struct ath_softc *sc,
+ const struct ath_bus_ops *bus_ops);
+ void ath9k_deinit_device(struct ath_softc *sc);
+--- a/drivers/net/wireless/ath/ath9k/common.c
++++ b/drivers/net/wireless/ath/ath9k/common.c
+@@ -169,6 +169,32 @@ void ath9k_cmn_update_txpow(struct ath_h
+ }
+ EXPORT_SYMBOL(ath9k_cmn_update_txpow);
+
++void ath9k_cmn_init_crypto(struct ath_hw *ah)
++{
++ struct ath_common *common = ath9k_hw_common(ah);
++ int i = 0;
++
++ /* Get the hardware key cache size. */
++ common->keymax = AR_KEYTABLE_SIZE;
++
++ /*
++ * Check whether the separate key cache entries
++ * are required to handle both tx+rx MIC keys.
++ * With split mic keys the number of stations is limited
++ * to 27 otherwise 59.
++ */
++ if (ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
++ common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
++
++ /*
++ * Reset the key cache since some parts do not
++ * reset the contents on initial power up.
++ */
++ for (i = 0; i < common->keymax; i++)
++ ath_hw_keyreset(common, (u16) i);
++}
++EXPORT_SYMBOL(ath9k_cmn_init_crypto);
++
+ static int __init ath9k_cmn_init(void)
+ {
+ return 0;
+--- a/drivers/net/wireless/ath/ath9k/common.h
++++ b/drivers/net/wireless/ath/ath9k/common.h
+@@ -62,3 +62,4 @@ void ath9k_cmn_btcoex_bt_stomp(struct at
+ enum ath_stomp_type stomp_type);
+ void ath9k_cmn_update_txpow(struct ath_hw *ah, u16 cur_txpow,
+ u16 new_txpow, u16 *txpower);
++void ath9k_cmn_init_crypto(struct ath_hw *ah);
+--- a/drivers/net/wireless/ath/ath9k/htc_drv_init.c
++++ b/drivers/net/wireless/ath/ath9k/htc_drv_init.c
+@@ -572,25 +572,6 @@ err:
+ return -EINVAL;
+ }
+
+-static void ath9k_init_crypto(struct ath9k_htc_priv *priv)
+-{
+- struct ath_common *common = ath9k_hw_common(priv->ah);
+- int i = 0;
+-
+- /* Get the hardware key cache size. */
+- common->keymax = AR_KEYTABLE_SIZE;
+-
+- if (priv->ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
+- common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
+-
+- /*
+- * Reset the key cache since some parts do not
+- * reset the contents on initial power up.
+- */
+- for (i = 0; i < common->keymax; i++)
+- ath_hw_keyreset(common, (u16) i);
+-}
+-
+ static void ath9k_init_channels_rates(struct ath9k_htc_priv *priv)
+ {
+ if (priv->ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ) {
+@@ -720,7 +701,7 @@ static int ath9k_init_priv(struct ath9k_
+ for (i = 0; i < ATH9K_HTC_MAX_BCN_VIF; i++)
+ priv->cur_beacon_conf.bslot[i] = NULL;
+
+- ath9k_init_crypto(priv);
++ ath9k_cmn_init_crypto(ah);
+ ath9k_init_channels_rates(priv);
+ ath9k_init_misc(priv);
+
+--- a/drivers/net/wireless/ath/ath9k/init.c
++++ b/drivers/net/wireless/ath/ath9k/init.c
+@@ -404,31 +404,6 @@ fail:
+ return error;
+ }
+
+-void ath9k_init_crypto(struct ath_softc *sc)
+-{
+- struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+- int i = 0;
+-
+- /* Get the hardware key cache size. */
+- common->keymax = AR_KEYTABLE_SIZE;
+-
+- /*
+- * Reset the key cache since some parts do not
+- * reset the contents on initial power up.
+- */
+- for (i = 0; i < common->keymax; i++)
+- ath_hw_keyreset(common, (u16) i);
+-
+- /*
+- * Check whether the separate key cache entries
+- * are required to handle both tx+rx MIC keys.
+- * With split mic keys the number of stations is limited
+- * to 27 otherwise 59.
+- */
+- if (sc->sc_ah->misc_mode & AR_PCU_MIC_NEW_LOC_ENA)
+- common->crypt_caps |= ATH_CRYPT_CAP_MIC_COMBINED;
+-}
+-
+ static int ath9k_init_btcoex(struct ath_softc *sc)
+ {
+ struct ath_txq *txq;
+@@ -630,7 +605,7 @@ static int ath9k_init_softc(u16 devid, s
+ if (ret)
+ goto err_btcoex;
+
+- ath9k_init_crypto(sc);
++ ath9k_cmn_init_crypto(sc->sc_ah);
+ ath9k_init_misc(sc);
+
+ return 0;
+--- a/drivers/net/wireless/ath/ath9k/pci.c
++++ b/drivers/net/wireless/ath/ath9k/pci.c
+@@ -129,7 +129,7 @@ static void ath_pci_aspm_init(struct ath
+ return;
+
+ parent = pdev->bus->self;
+- if (WARN_ON(!parent))
++ if (!parent)
+ return;
+
+ pos = pci_pcie_cap(parent);
+@@ -338,7 +338,7 @@ static int ath_pci_resume(struct device
+ * semi-random values after suspend/resume.
+ */
+ ath9k_ps_wakeup(sc);
+- ath9k_init_crypto(sc);
++ ath9k_cmn_init_crypto(sc->sc_ah);
+ ath9k_ps_restore(sc);
+
+ sc->ps_idle = true;
+--- a/drivers/net/wireless/ath/ath9k/calib.c
++++ b/drivers/net/wireless/ath/ath9k/calib.c
+@@ -82,7 +82,6 @@ static void ath9k_hw_update_nfcal_hist_b
+ int16_t *nfarray)
+ {
+ struct ath_common *common = ath9k_hw_common(ah);
+- struct ieee80211_conf *conf = &common->hw->conf;
+ struct ath_nf_limits *limit;
+ struct ath9k_nfcal_hist *h;
+ bool high_nf_mid = false;
+@@ -94,7 +93,7 @@ static void ath9k_hw_update_nfcal_hist_b
+
+ for (i = 0; i < NUM_NF_READINGS; i++) {
+ if (!(chainmask & (1 << i)) ||
+- ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
++ ((i >= AR5416_MAX_CHAINS) && !IS_CHAN_HT40(ah->curchan)))
+ continue;
+
+ h[i].nfCalBuffer[h[i].currIndex] = nfarray[i];
+--- a/drivers/net/wireless/ath/ath9k/debug.c
++++ b/drivers/net/wireless/ath/ath9k/debug.c
+@@ -1163,6 +1163,59 @@ static const struct file_operations fops
+ .llseek = default_llseek,/* read accesses f_pos */
+ };
+
++static ssize_t read_file_dump_nfcal(struct file *file, char __user *user_buf,
++ size_t count, loff_t *ppos)
++{
++ struct ath_softc *sc = file->private_data;
++ struct ath_hw *ah = sc->sc_ah;
++ struct ath9k_nfcal_hist *h = sc->caldata.nfCalHist;
++ struct ath_common *common = ath9k_hw_common(ah);
++ struct ieee80211_conf *conf = &common->hw->conf;
++ u32 len = 0, size = 1500;
++ u32 i, j;
++ ssize_t retval = 0;
++ char *buf;
++ u8 chainmask = (ah->rxchainmask << 3) | ah->rxchainmask;
++ u8 nread;
++
++ buf = kzalloc(size, GFP_KERNEL);
++ if (!buf)
++ return -ENOMEM;
++
++ len += snprintf(buf + len, size - len,
++ "Channel Noise Floor : %d\n", ah->noise);
++ len += snprintf(buf + len, size - len,
++ "Chain | privNF | # Readings | NF Readings\n");
++ for (i = 0; i < NUM_NF_READINGS; i++) {
++ if (!(chainmask & (1 << i)) ||
++ ((i >= AR5416_MAX_CHAINS) && !conf_is_ht40(conf)))
++ continue;
++
++ nread = AR_PHY_CCA_FILTERWINDOW_LENGTH - h[i].invalidNFcount;
++ len += snprintf(buf + len, size - len, " %d\t %d\t %d\t\t",
++ i, h[i].privNF, nread);
++ for (j = 0; j < nread; j++)
++ len += snprintf(buf + len, size - len,
++ " %d", h[i].nfCalBuffer[j]);
++ len += snprintf(buf + len, size - len, "\n");
++ }
++
++ if (len > size)
++ len = size;
++
++ retval = simple_read_from_buffer(user_buf, count, ppos, buf, len);
++ kfree(buf);
++
++ return retval;
++}
++
++static const struct file_operations fops_dump_nfcal = {
++ .read = read_file_dump_nfcal,
++ .open = ath9k_debugfs_open,
++ .owner = THIS_MODULE,
++ .llseek = default_llseek,
++};
++
+ static ssize_t read_file_base_eeprom(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+ {
+@@ -1262,6 +1315,8 @@ int ath9k_init_debug(struct ath_hw *ah)
+ &ah->config.cwm_ignore_extcca);
+ debugfs_create_file("regdump", S_IRUSR, sc->debug.debugfs_phy, sc,
+ &fops_regdump);
++ debugfs_create_file("dump_nfcal", S_IRUSR, sc->debug.debugfs_phy, sc,
++ &fops_dump_nfcal);
+ debugfs_create_file("base_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
+ &fops_base_eeprom);
+ debugfs_create_file("modal_eeprom", S_IRUSR, sc->debug.debugfs_phy, sc,
+--- a/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
++++ b/drivers/net/wireless/ath/ath9k/ar9003_eeprom.c
+@@ -69,7 +69,7 @@ static int ar9003_hw_power_interpolate(i
+ static const struct ar9300_eeprom ar9300_default = {
+ .eepromVersion = 2,
+ .templateVersion = 2,
+- .macAddr = {1, 2, 3, 4, 5, 6},
++ .macAddr = {0, 2, 3, 4, 5, 6},
+ .custData = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
+ .baseEepHeader = {
+--- a/drivers/net/wireless/ath/ath9k/eeprom_4k.c
++++ b/drivers/net/wireless/ath/ath9k/eeprom_4k.c
+@@ -349,10 +349,7 @@ static u32 ath9k_hw_4k_get_eeprom(struct
+ case EEP_ANT_DIV_CTL1:
+ return pModal->antdiv_ctl1;
+ case EEP_TXGAIN_TYPE:
+- if (ver_minor >= AR5416_EEP_MINOR_VER_19)
+- return pBase->txGainType;
+- else
+- return AR5416_EEP_TXGAIN_ORIGINAL;
++ return pBase->txGainType;
+ default:
+ return 0;