aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorJohn W. Linville <linville@tuxdriver.com>2010-08-31 14:12:19 -0400
committerJohn W. Linville <linville@tuxdriver.com>2010-08-31 14:12:19 -0400
commit486699532e43460234cbebc19cbebd2755b67da3 (patch)
tree0983829da193c1d222f6a52d94849f24111879d8 /drivers/net
parent5b714c6a3753dad0798a70a049e15c7f6bc9446b (diff)
parentd0fe478c9f42dbc4916aa8d1d7a05d7f669d2209 (diff)
Merge branch 'wireless-next-2.6' of git://git.kernel.org/pub/scm/linux/kernel/git/iwlwifi/iwlwifi-2.6
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-1000.c4
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-hw.h1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945-rs.c7
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-3945.c86
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-4965.c57
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-5000.c25
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-6000.c23
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-calib.c12
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c104
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-lib.c32
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-rs.c66
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tt.c26
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-tx.c81
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn-ucode.c31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.c423
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-agn.h3
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-commands.h110
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.c676
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-core.h55
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-debugfs.c31
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-dev.h142
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-hcmd.c10
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-prph.h9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-rx.c9
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-scan.c35
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.c183
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-sta.h64
-rw-r--r--drivers/net/wireless/iwlwifi/iwl-tx.c34
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c168
29 files changed, 1658 insertions, 849 deletions
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c
index 3bf5a30828b..674fb93ae17 100644
--- a/drivers/net/wireless/iwlwifi/iwl-1000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-1000.c
@@ -130,7 +130,7 @@ static int iwl1000_hw_set_hw_params(struct iwl_priv *priv)
130 sizeof(struct iwlagn_scd_bc_tbl); 130 sizeof(struct iwlagn_scd_bc_tbl);
131 priv->hw_params.tfd_size = sizeof(struct iwl_tfd); 131 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
132 priv->hw_params.max_stations = IWLAGN_STATION_COUNT; 132 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
133 priv->hw_params.bcast_sta_id = IWLAGN_BROADCAST_ID; 133 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
134 134
135 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE; 135 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
136 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE; 136 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
@@ -217,7 +217,7 @@ static struct iwl_lib_ops iwl1000_lib = {
217 .set_ct_kill = iwl1000_set_ct_threshold, 217 .set_ct_kill = iwl1000_set_ct_threshold,
218 }, 218 },
219 .manage_ibss_station = iwlagn_manage_ibss_station, 219 .manage_ibss_station = iwlagn_manage_ibss_station,
220 .update_bcast_station = iwl_update_bcast_station, 220 .update_bcast_stations = iwl_update_bcast_stations,
221 .debugfs_ops = { 221 .debugfs_ops = {
222 .rx_stats_read = iwl_ucode_rx_stats_read, 222 .rx_stats_read = iwl_ucode_rx_stats_read,
223 .tx_stats_read = iwl_ucode_tx_stats_read, 223 .tx_stats_read = iwl_ucode_tx_stats_read,
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
index a4a3194779d..65b5834da28 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-hw.h
@@ -226,6 +226,7 @@ struct iwl3945_eeprom {
226 226
227/* 4 DATA + 1 CMD. There are 2 HCCA queues that are not used. */ 227/* 4 DATA + 1 CMD. There are 2 HCCA queues that are not used. */
228#define IWL39_NUM_QUEUES 5 228#define IWL39_NUM_QUEUES 5
229#define IWL39_CMD_QUEUE_NUM 4
229 230
230#define IWL_DEFAULT_TX_RETRY 15 231#define IWL_DEFAULT_TX_RETRY 15
231 232
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
index 8e84a08ff95..d707f5bb1a8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945-rs.c
@@ -343,7 +343,7 @@ void iwl3945_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 s
343 int i; 343 int i;
344 344
345 IWL_DEBUG_INFO(priv, "enter\n"); 345 IWL_DEBUG_INFO(priv, "enter\n");
346 if (sta_id == priv->hw_params.bcast_sta_id) 346 if (sta_id == priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id)
347 goto out; 347 goto out;
348 348
349 psta = (struct iwl3945_sta_priv *) sta->drv_priv; 349 psta = (struct iwl3945_sta_priv *) sta->drv_priv;
@@ -932,7 +932,7 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
932 932
933 rcu_read_lock(); 933 rcu_read_lock();
934 934
935 sta = ieee80211_find_sta(priv->vif, 935 sta = ieee80211_find_sta(priv->contexts[IWL_RXON_CTX_BSS].vif,
936 priv->stations[sta_id].sta.sta.addr); 936 priv->stations[sta_id].sta.sta.addr);
937 if (!sta) { 937 if (!sta) {
938 IWL_DEBUG_RATE(priv, "Unable to find station to initialize rate scaling.\n"); 938 IWL_DEBUG_RATE(priv, "Unable to find station to initialize rate scaling.\n");
@@ -949,7 +949,8 @@ void iwl3945_rate_scale_init(struct ieee80211_hw *hw, s32 sta_id)
949 switch (priv->band) { 949 switch (priv->band) {
950 case IEEE80211_BAND_2GHZ: 950 case IEEE80211_BAND_2GHZ:
951 /* TODO: this always does G, not a regression */ 951 /* TODO: this always does G, not a regression */
952 if (priv->active_rxon.flags & RXON_FLG_TGG_PROTECT_MSK) { 952 if (priv->contexts[IWL_RXON_CTX_BSS].active.flags &
953 RXON_FLG_TGG_PROTECT_MSK) {
953 rs_sta->tgg = 1; 954 rs_sta->tgg = 1;
954 rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot; 955 rs_sta->expected_tpt = iwl3945_expected_tpt_g_prot;
955 } else 956 } else
diff --git a/drivers/net/wireless/iwlwifi/iwl-3945.c b/drivers/net/wireless/iwlwifi/iwl-3945.c
index 8ccfcd08218..5d09686c338 100644
--- a/drivers/net/wireless/iwlwifi/iwl-3945.c
+++ b/drivers/net/wireless/iwlwifi/iwl-3945.c
@@ -245,7 +245,7 @@ int iwl3945_rs_next_rate(struct iwl_priv *priv, int rate)
245 break; 245 break;
246 case IEEE80211_BAND_2GHZ: 246 case IEEE80211_BAND_2GHZ:
247 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) && 247 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) &&
248 iwl_is_associated(priv)) { 248 iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
249 if (rate == IWL_RATE_11M_INDEX) 249 if (rate == IWL_RATE_11M_INDEX)
250 next_rate = IWL_RATE_5M_INDEX; 250 next_rate = IWL_RATE_5M_INDEX;
251 } 251 }
@@ -273,7 +273,7 @@ static void iwl3945_tx_queue_reclaim(struct iwl_priv *priv,
273 struct iwl_queue *q = &txq->q; 273 struct iwl_queue *q = &txq->q;
274 struct iwl_tx_info *tx_info; 274 struct iwl_tx_info *tx_info;
275 275
276 BUG_ON(txq_id == IWL_CMD_QUEUE_NUM); 276 BUG_ON(txq_id == IWL39_CMD_QUEUE_NUM);
277 277
278 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index; 278 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
279 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 279 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
@@ -285,7 +285,7 @@ static void iwl3945_tx_queue_reclaim(struct iwl_priv *priv,
285 } 285 }
286 286
287 if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) && 287 if (iwl_queue_space(q) > q->low_mark && (txq_id >= 0) &&
288 (txq_id != IWL_CMD_QUEUE_NUM) && 288 (txq_id != IWL39_CMD_QUEUE_NUM) &&
289 priv->mac80211_registered) 289 priv->mac80211_registered)
290 iwl_wake_queue(priv, txq_id); 290 iwl_wake_queue(priv, txq_id);
291} 291}
@@ -760,7 +760,7 @@ void iwl3945_hw_build_tx_cmd_rate(struct iwl_priv *priv,
760 data_retry_limit = IWL_DEFAULT_TX_RETRY; 760 data_retry_limit = IWL_DEFAULT_TX_RETRY;
761 tx_cmd->data_retry_limit = data_retry_limit; 761 tx_cmd->data_retry_limit = data_retry_limit;
762 762
763 if (tx_id >= IWL_CMD_QUEUE_NUM) 763 if (tx_id >= IWL39_CMD_QUEUE_NUM)
764 rts_retry_limit = 3; 764 rts_retry_limit = 3;
765 else 765 else
766 rts_retry_limit = 7; 766 rts_retry_limit = 7;
@@ -909,7 +909,7 @@ static int iwl3945_txq_ctx_reset(struct iwl_priv *priv)
909 909
910 /* Tx queue(s) */ 910 /* Tx queue(s) */
911 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { 911 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
912 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? 912 slots_num = (txq_id == IWL39_CMD_QUEUE_NUM) ?
913 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; 913 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
914 rc = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num, 914 rc = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
915 txq_id); 915 txq_id);
@@ -1072,7 +1072,7 @@ void iwl3945_hw_txq_ctx_free(struct iwl_priv *priv)
1072 if (priv->txq) 1072 if (priv->txq)
1073 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; 1073 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num;
1074 txq_id++) 1074 txq_id++)
1075 if (txq_id == IWL_CMD_QUEUE_NUM) 1075 if (txq_id == IWL39_CMD_QUEUE_NUM)
1076 iwl_cmd_queue_free(priv); 1076 iwl_cmd_queue_free(priv);
1077 else 1077 else
1078 iwl_tx_queue_free(priv, txq_id); 1078 iwl_tx_queue_free(priv, txq_id);
@@ -1439,17 +1439,18 @@ static int iwl3945_send_tx_power(struct iwl_priv *priv)
1439 int rate_idx, i; 1439 int rate_idx, i;
1440 const struct iwl_channel_info *ch_info = NULL; 1440 const struct iwl_channel_info *ch_info = NULL;
1441 struct iwl3945_txpowertable_cmd txpower = { 1441 struct iwl3945_txpowertable_cmd txpower = {
1442 .channel = priv->active_rxon.channel, 1442 .channel = priv->contexts[IWL_RXON_CTX_BSS].active.channel,
1443 }; 1443 };
1444 u16 chan;
1445
1446 chan = le16_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.channel);
1444 1447
1445 txpower.band = (priv->band == IEEE80211_BAND_5GHZ) ? 0 : 1; 1448 txpower.band = (priv->band == IEEE80211_BAND_5GHZ) ? 0 : 1;
1446 ch_info = iwl_get_channel_info(priv, 1449 ch_info = iwl_get_channel_info(priv, priv->band, chan);
1447 priv->band,
1448 le16_to_cpu(priv->active_rxon.channel));
1449 if (!ch_info) { 1450 if (!ch_info) {
1450 IWL_ERR(priv, 1451 IWL_ERR(priv,
1451 "Failed to get channel info for channel %d [%d]\n", 1452 "Failed to get channel info for channel %d [%d]\n",
1452 le16_to_cpu(priv->active_rxon.channel), priv->band); 1453 chan, priv->band);
1453 return -EINVAL; 1454 return -EINVAL;
1454 } 1455 }
1455 1456
@@ -1710,7 +1711,8 @@ int iwl3945_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
1710 return 0; 1711 return 0;
1711} 1712}
1712 1713
1713static int iwl3945_send_rxon_assoc(struct iwl_priv *priv) 1714static int iwl3945_send_rxon_assoc(struct iwl_priv *priv,
1715 struct iwl_rxon_context *ctx)
1714{ 1716{
1715 int rc = 0; 1717 int rc = 0;
1716 struct iwl_rx_packet *pkt; 1718 struct iwl_rx_packet *pkt;
@@ -1721,8 +1723,8 @@ static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
1721 .flags = CMD_WANT_SKB, 1723 .flags = CMD_WANT_SKB,
1722 .data = &rxon_assoc, 1724 .data = &rxon_assoc,
1723 }; 1725 };
1724 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; 1726 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
1725 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; 1727 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
1726 1728
1727 if ((rxon1->flags == rxon2->flags) && 1729 if ((rxon1->flags == rxon2->flags) &&
1728 (rxon1->filter_flags == rxon2->filter_flags) && 1730 (rxon1->filter_flags == rxon2->filter_flags) &&
@@ -1732,10 +1734,10 @@ static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
1732 return 0; 1734 return 0;
1733 } 1735 }
1734 1736
1735 rxon_assoc.flags = priv->staging_rxon.flags; 1737 rxon_assoc.flags = ctx->staging.flags;
1736 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; 1738 rxon_assoc.filter_flags = ctx->staging.filter_flags;
1737 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; 1739 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
1738 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; 1740 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
1739 rxon_assoc.reserved = 0; 1741 rxon_assoc.reserved = 0;
1740 1742
1741 rc = iwl_send_cmd_sync(priv, &cmd); 1743 rc = iwl_send_cmd_sync(priv, &cmd);
@@ -1761,14 +1763,14 @@ static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
1761 * function correctly transitions out of the RXON_ASSOC_MSK state if 1763 * function correctly transitions out of the RXON_ASSOC_MSK state if
1762 * a HW tune is required based on the RXON structure changes. 1764 * a HW tune is required based on the RXON structure changes.
1763 */ 1765 */
1764static int iwl3945_commit_rxon(struct iwl_priv *priv) 1766static int iwl3945_commit_rxon(struct iwl_priv *priv,
1767 struct iwl_rxon_context *ctx)
1765{ 1768{
1766 /* cast away the const for active_rxon in this function */ 1769 /* cast away the const for active_rxon in this function */
1767 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 1770 struct iwl3945_rxon_cmd *active_rxon = (void *)&ctx->active;
1768 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon; 1771 struct iwl3945_rxon_cmd *staging_rxon = (void *)&ctx->staging;
1769 int rc = 0; 1772 int rc = 0;
1770 bool new_assoc = 1773 bool new_assoc = !!(staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK);
1771 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
1772 1774
1773 if (!iwl_is_alive(priv)) 1775 if (!iwl_is_alive(priv))
1774 return -1; 1776 return -1;
@@ -1781,7 +1783,7 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1781 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK); 1783 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
1782 staging_rxon->flags |= iwl3945_get_antenna_flags(priv); 1784 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
1783 1785
1784 rc = iwl_check_rxon_cmd(priv); 1786 rc = iwl_check_rxon_cmd(priv, ctx);
1785 if (rc) { 1787 if (rc) {
1786 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); 1788 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1787 return -EINVAL; 1789 return -EINVAL;
@@ -1790,8 +1792,9 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1790 /* If we don't need to send a full RXON, we can use 1792 /* If we don't need to send a full RXON, we can use
1791 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter 1793 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
1792 * and other flags for the current radio configuration. */ 1794 * and other flags for the current radio configuration. */
1793 if (!iwl_full_rxon_required(priv)) { 1795 if (!iwl_full_rxon_required(priv, &priv->contexts[IWL_RXON_CTX_BSS])) {
1794 rc = iwl_send_rxon_assoc(priv); 1796 rc = iwl_send_rxon_assoc(priv,
1797 &priv->contexts[IWL_RXON_CTX_BSS]);
1795 if (rc) { 1798 if (rc) {
1796 IWL_ERR(priv, "Error setting RXON_ASSOC " 1799 IWL_ERR(priv, "Error setting RXON_ASSOC "
1797 "configuration (%d).\n", rc); 1800 "configuration (%d).\n", rc);
@@ -1807,7 +1810,7 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1807 * an RXON_ASSOC and the new config wants the associated mask enabled, 1810 * an RXON_ASSOC and the new config wants the associated mask enabled,
1808 * we must clear the associated from the active configuration 1811 * we must clear the associated from the active configuration
1809 * before we apply the new config */ 1812 * before we apply the new config */
1810 if (iwl_is_associated(priv) && new_assoc) { 1813 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS) && new_assoc) {
1811 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n"); 1814 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
1812 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 1815 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1813 1816
@@ -1819,7 +1822,7 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1819 active_rxon->reserved5 = 0; 1822 active_rxon->reserved5 = 0;
1820 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 1823 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
1821 sizeof(struct iwl3945_rxon_cmd), 1824 sizeof(struct iwl3945_rxon_cmd),
1822 &priv->active_rxon); 1825 &priv->contexts[IWL_RXON_CTX_BSS].active);
1823 1826
1824 /* If the mask clearing failed then we set 1827 /* If the mask clearing failed then we set
1825 * active_rxon back to what it was previously */ 1828 * active_rxon back to what it was previously */
@@ -1829,8 +1832,9 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1829 "configuration (%d).\n", rc); 1832 "configuration (%d).\n", rc);
1830 return rc; 1833 return rc;
1831 } 1834 }
1832 iwl_clear_ucode_stations(priv); 1835 iwl_clear_ucode_stations(priv,
1833 iwl_restore_stations(priv); 1836 &priv->contexts[IWL_RXON_CTX_BSS]);
1837 iwl_restore_stations(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
1834 } 1838 }
1835 1839
1836 IWL_DEBUG_INFO(priv, "Sending RXON\n" 1840 IWL_DEBUG_INFO(priv, "Sending RXON\n"
@@ -1848,7 +1852,7 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1848 staging_rxon->reserved4 = 0; 1852 staging_rxon->reserved4 = 0;
1849 staging_rxon->reserved5 = 0; 1853 staging_rxon->reserved5 = 0;
1850 1854
1851 iwl_set_rxon_hwcrypto(priv, !iwl3945_mod_params.sw_crypto); 1855 iwl_set_rxon_hwcrypto(priv, ctx, !iwl3945_mod_params.sw_crypto);
1852 1856
1853 /* Apply the new configuration */ 1857 /* Apply the new configuration */
1854 rc = iwl_send_cmd_pdu(priv, REPLY_RXON, 1858 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
@@ -1862,8 +1866,9 @@ static int iwl3945_commit_rxon(struct iwl_priv *priv)
1862 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon)); 1866 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
1863 1867
1864 if (!new_assoc) { 1868 if (!new_assoc) {
1865 iwl_clear_ucode_stations(priv); 1869 iwl_clear_ucode_stations(priv,
1866 iwl_restore_stations(priv); 1870 &priv->contexts[IWL_RXON_CTX_BSS]);
1871 iwl_restore_stations(priv, &priv->contexts[IWL_RXON_CTX_BSS]);
1867 } 1872 }
1868 1873
1869 /* If we issue a new RXON command which required a tune then we must 1874 /* If we issue a new RXON command which required a tune then we must
@@ -2302,8 +2307,10 @@ static int iwl3945_manage_ibss_station(struct iwl_priv *priv,
2302 int ret; 2307 int ret;
2303 2308
2304 if (add) { 2309 if (add) {
2305 ret = iwl_add_bssid_station(priv, vif->bss_conf.bssid, false, 2310 ret = iwl_add_bssid_station(
2306 &vif_priv->ibss_bssid_sta_id); 2311 priv, &priv->contexts[IWL_RXON_CTX_BSS],
2312 vif->bss_conf.bssid, false,
2313 &vif_priv->ibss_bssid_sta_id);
2307 if (ret) 2314 if (ret)
2308 return ret; 2315 return ret;
2309 2316
@@ -2366,7 +2373,7 @@ int iwl3945_init_hw_rate_table(struct iwl_priv *priv)
2366 * 1M CCK rates */ 2373 * 1M CCK rates */
2367 2374
2368 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) && 2375 if (!(priv->_3945.sta_supp_rates & IWL_OFDM_RATES_MASK) &&
2369 iwl_is_associated(priv)) { 2376 iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
2370 2377
2371 index = IWL_FIRST_CCK_RATE; 2378 index = IWL_FIRST_CCK_RATE;
2372 for (i = IWL_RATE_6M_INDEX_TABLE; 2379 for (i = IWL_RATE_6M_INDEX_TABLE;
@@ -2421,7 +2428,9 @@ int iwl3945_hw_set_hw_params(struct iwl_priv *priv)
2421 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE; 2428 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
2422 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG; 2429 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
2423 priv->hw_params.max_stations = IWL3945_STATION_COUNT; 2430 priv->hw_params.max_stations = IWL3945_STATION_COUNT;
2424 priv->hw_params.bcast_sta_id = IWL3945_BROADCAST_ID; 2431 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWL3945_BROADCAST_ID;
2432
2433 priv->sta_key_max_num = STA_KEY_MAX_NUM;
2425 2434
2426 priv->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR; 2435 priv->hw_params.rx_wrt_ptr_reg = FH39_RSCSR_CHNL0_WPTR;
2427 priv->hw_params.max_beacon_itrvl = IWL39_MAX_UCODE_BEACON_INTERVAL; 2436 priv->hw_params.max_beacon_itrvl = IWL39_MAX_UCODE_BEACON_INTERVAL;
@@ -2439,7 +2448,8 @@ unsigned int iwl3945_hw_get_beacon_cmd(struct iwl_priv *priv,
2439 tx_beacon_cmd = (struct iwl3945_tx_beacon_cmd *)&frame->u; 2448 tx_beacon_cmd = (struct iwl3945_tx_beacon_cmd *)&frame->u;
2440 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); 2449 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
2441 2450
2442 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id; 2451 tx_beacon_cmd->tx.sta_id =
2452 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
2443 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 2453 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2444 2454
2445 frame_size = iwl3945_fill_beacon_frame(priv, 2455 frame_size = iwl3945_fill_beacon_frame(priv,
diff --git a/drivers/net/wireless/iwlwifi/iwl-4965.c b/drivers/net/wireless/iwlwifi/iwl-4965.c
index f0a47f42d4b..1d6a46d4db5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-4965.c
+++ b/drivers/net/wireless/iwlwifi/iwl-4965.c
@@ -347,7 +347,7 @@ static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
347 struct iwl_chain_noise_data *data = &(priv->chain_noise_data); 347 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
348 348
349 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && 349 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
350 iwl_is_associated(priv)) { 350 iwl_is_any_associated(priv)) {
351 struct iwl_calib_diff_gain_cmd cmd; 351 struct iwl_calib_diff_gain_cmd cmd;
352 352
353 /* clear data for chain noise calibration algorithm */ 353 /* clear data for chain noise calibration algorithm */
@@ -576,7 +576,7 @@ static int iwl4965_alive_notify(struct iwl_priv *priv)
576 /* Activate all Tx DMA/FIFO channels */ 576 /* Activate all Tx DMA/FIFO channels */
577 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 6)); 577 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 6));
578 578
579 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); 579 iwl4965_set_wr_ptrs(priv, IWL_DEFAULT_CMD_QUEUE_NUM, 0);
580 580
581 /* make sure all queue are not stopped */ 581 /* make sure all queue are not stopped */
582 memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped)); 582 memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
@@ -587,6 +587,7 @@ static int iwl4965_alive_notify(struct iwl_priv *priv)
587 priv->txq_ctx_active_msk = 0; 587 priv->txq_ctx_active_msk = 0;
588 /* Map each Tx/cmd queue to its corresponding fifo */ 588 /* Map each Tx/cmd queue to its corresponding fifo */
589 BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7); 589 BUILD_BUG_ON(ARRAY_SIZE(default_queue_to_tx_fifo) != 7);
590
590 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) { 591 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
591 int ac = default_queue_to_tx_fifo[i]; 592 int ac = default_queue_to_tx_fifo[i];
592 593
@@ -656,7 +657,7 @@ static int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
656 sizeof(struct iwl4965_scd_bc_tbl); 657 sizeof(struct iwl4965_scd_bc_tbl);
657 priv->hw_params.tfd_size = sizeof(struct iwl_tfd); 658 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
658 priv->hw_params.max_stations = IWL4965_STATION_COUNT; 659 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
659 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID; 660 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWL4965_BROADCAST_ID;
660 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE; 661 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
661 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE; 662 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
662 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE; 663 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
@@ -1374,6 +1375,7 @@ static int iwl4965_send_tx_power(struct iwl_priv *priv)
1374 u8 band = 0; 1375 u8 band = 0;
1375 bool is_ht40 = false; 1376 bool is_ht40 = false;
1376 u8 ctrl_chan_high = 0; 1377 u8 ctrl_chan_high = 0;
1378 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1377 1379
1378 if (test_bit(STATUS_SCANNING, &priv->status)) { 1380 if (test_bit(STATUS_SCANNING, &priv->status)) {
1379 /* If this gets hit a lot, switch it to a BUG() and catch 1381 /* If this gets hit a lot, switch it to a BUG() and catch
@@ -1385,17 +1387,16 @@ static int iwl4965_send_tx_power(struct iwl_priv *priv)
1385 1387
1386 band = priv->band == IEEE80211_BAND_2GHZ; 1388 band = priv->band == IEEE80211_BAND_2GHZ;
1387 1389
1388 is_ht40 = is_ht40_channel(priv->active_rxon.flags); 1390 is_ht40 = is_ht40_channel(ctx->active.flags);
1389 1391
1390 if (is_ht40 && 1392 if (is_ht40 && (ctx->active.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1391 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1392 ctrl_chan_high = 1; 1393 ctrl_chan_high = 1;
1393 1394
1394 cmd.band = band; 1395 cmd.band = band;
1395 cmd.channel = priv->active_rxon.channel; 1396 cmd.channel = ctx->active.channel;
1396 1397
1397 ret = iwl4965_fill_txpower_tbl(priv, band, 1398 ret = iwl4965_fill_txpower_tbl(priv, band,
1398 le16_to_cpu(priv->active_rxon.channel), 1399 le16_to_cpu(ctx->active.channel),
1399 is_ht40, ctrl_chan_high, &cmd.tx_power); 1400 is_ht40, ctrl_chan_high, &cmd.tx_power);
1400 if (ret) 1401 if (ret)
1401 goto out; 1402 goto out;
@@ -1406,12 +1407,13 @@ out:
1406 return ret; 1407 return ret;
1407} 1408}
1408 1409
1409static int iwl4965_send_rxon_assoc(struct iwl_priv *priv) 1410static int iwl4965_send_rxon_assoc(struct iwl_priv *priv,
1411 struct iwl_rxon_context *ctx)
1410{ 1412{
1411 int ret = 0; 1413 int ret = 0;
1412 struct iwl4965_rxon_assoc_cmd rxon_assoc; 1414 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1413 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; 1415 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
1414 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; 1416 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
1415 1417
1416 if ((rxon1->flags == rxon2->flags) && 1418 if ((rxon1->flags == rxon2->flags) &&
1417 (rxon1->filter_flags == rxon2->filter_flags) && 1419 (rxon1->filter_flags == rxon2->filter_flags) &&
@@ -1426,16 +1428,16 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1426 return 0; 1428 return 0;
1427 } 1429 }
1428 1430
1429 rxon_assoc.flags = priv->staging_rxon.flags; 1431 rxon_assoc.flags = ctx->staging.flags;
1430 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; 1432 rxon_assoc.filter_flags = ctx->staging.filter_flags;
1431 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; 1433 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
1432 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; 1434 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
1433 rxon_assoc.reserved = 0; 1435 rxon_assoc.reserved = 0;
1434 rxon_assoc.ofdm_ht_single_stream_basic_rates = 1436 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1435 priv->staging_rxon.ofdm_ht_single_stream_basic_rates; 1437 ctx->staging.ofdm_ht_single_stream_basic_rates;
1436 rxon_assoc.ofdm_ht_dual_stream_basic_rates = 1438 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1437 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; 1439 ctx->staging.ofdm_ht_dual_stream_basic_rates;
1438 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; 1440 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
1439 1441
1440 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC, 1442 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1441 sizeof(rxon_assoc), &rxon_assoc, NULL); 1443 sizeof(rxon_assoc), &rxon_assoc, NULL);
@@ -1448,6 +1450,7 @@ static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1448static int iwl4965_hw_channel_switch(struct iwl_priv *priv, 1450static int iwl4965_hw_channel_switch(struct iwl_priv *priv,
1449 struct ieee80211_channel_switch *ch_switch) 1451 struct ieee80211_channel_switch *ch_switch)
1450{ 1452{
1453 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1451 int rc; 1454 int rc;
1452 u8 band = 0; 1455 u8 band = 0;
1453 bool is_ht40 = false; 1456 bool is_ht40 = false;
@@ -1458,22 +1461,22 @@ static int iwl4965_hw_channel_switch(struct iwl_priv *priv,
1458 u16 ch; 1461 u16 ch;
1459 u32 tsf_low; 1462 u32 tsf_low;
1460 u8 switch_count; 1463 u8 switch_count;
1461 u16 beacon_interval = le16_to_cpu(priv->rxon_timing.beacon_interval); 1464 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
1462 struct ieee80211_vif *vif = priv->vif; 1465 struct ieee80211_vif *vif = ctx->vif;
1463 band = priv->band == IEEE80211_BAND_2GHZ; 1466 band = priv->band == IEEE80211_BAND_2GHZ;
1464 1467
1465 is_ht40 = is_ht40_channel(priv->staging_rxon.flags); 1468 is_ht40 = is_ht40_channel(ctx->staging.flags);
1466 1469
1467 if (is_ht40 && 1470 if (is_ht40 &&
1468 (priv->staging_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK)) 1471 (ctx->staging.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1469 ctrl_chan_high = 1; 1472 ctrl_chan_high = 1;
1470 1473
1471 cmd.band = band; 1474 cmd.band = band;
1472 cmd.expect_beacon = 0; 1475 cmd.expect_beacon = 0;
1473 ch = ch_switch->channel->hw_value; 1476 ch = ch_switch->channel->hw_value;
1474 cmd.channel = cpu_to_le16(ch); 1477 cmd.channel = cpu_to_le16(ch);
1475 cmd.rxon_flags = priv->staging_rxon.flags; 1478 cmd.rxon_flags = ctx->staging.flags;
1476 cmd.rxon_filter_flags = priv->staging_rxon.filter_flags; 1479 cmd.rxon_filter_flags = ctx->staging.filter_flags;
1477 switch_count = ch_switch->count; 1480 switch_count = ch_switch->count;
1478 tsf_low = ch_switch->timestamp & 0x0ffffffff; 1481 tsf_low = ch_switch->timestamp & 0x0ffffffff;
1479 /* 1482 /*
@@ -1508,7 +1511,7 @@ static int iwl4965_hw_channel_switch(struct iwl_priv *priv,
1508 cmd.expect_beacon = is_channel_radar(ch_info); 1511 cmd.expect_beacon = is_channel_radar(ch_info);
1509 else { 1512 else {
1510 IWL_ERR(priv, "invalid channel switch from %u to %u\n", 1513 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
1511 priv->active_rxon.channel, ch); 1514 ctx->active.channel, ch);
1512 return -EFAULT; 1515 return -EFAULT;
1513 } 1516 }
1514 1517
@@ -2007,7 +2010,7 @@ static u8 iwl_find_station(struct iwl_priv *priv, const u8 *addr)
2007 start = IWL_STA_ID; 2010 start = IWL_STA_ID;
2008 2011
2009 if (is_broadcast_ether_addr(addr)) 2012 if (is_broadcast_ether_addr(addr))
2010 return priv->hw_params.bcast_sta_id; 2013 return priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
2011 2014
2012 spin_lock_irqsave(&priv->sta_lock, flags); 2015 spin_lock_irqsave(&priv->sta_lock, flags);
2013 for (i = start; i < priv->hw_params.max_stations; i++) 2016 for (i = start; i < priv->hw_params.max_stations; i++)
@@ -2280,7 +2283,7 @@ static struct iwl_lib_ops iwl4965_lib = {
2280 .set_ct_kill = iwl4965_set_ct_threshold, 2283 .set_ct_kill = iwl4965_set_ct_threshold,
2281 }, 2284 },
2282 .manage_ibss_station = iwlagn_manage_ibss_station, 2285 .manage_ibss_station = iwlagn_manage_ibss_station,
2283 .update_bcast_station = iwl_update_bcast_station, 2286 .update_bcast_stations = iwl_update_bcast_stations,
2284 .debugfs_ops = { 2287 .debugfs_ops = {
2285 .rx_stats_read = iwl_ucode_rx_stats_read, 2288 .rx_stats_read = iwl_ucode_rx_stats_read,
2286 .tx_stats_read = iwl_ucode_tx_stats_read, 2289 .tx_stats_read = iwl_ucode_tx_stats_read,
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c
index 013f3dae69f..1dbb1246c08 100644
--- a/drivers/net/wireless/iwlwifi/iwl-5000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-5000.c
@@ -180,7 +180,7 @@ static int iwl5000_hw_set_hw_params(struct iwl_priv *priv)
180 sizeof(struct iwlagn_scd_bc_tbl); 180 sizeof(struct iwlagn_scd_bc_tbl);
181 priv->hw_params.tfd_size = sizeof(struct iwl_tfd); 181 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
182 priv->hw_params.max_stations = IWLAGN_STATION_COUNT; 182 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
183 priv->hw_params.bcast_sta_id = IWLAGN_BROADCAST_ID; 183 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
184 184
185 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE; 185 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
186 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE; 186 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
@@ -227,7 +227,7 @@ static int iwl5150_hw_set_hw_params(struct iwl_priv *priv)
227 sizeof(struct iwlagn_scd_bc_tbl); 227 sizeof(struct iwlagn_scd_bc_tbl);
228 priv->hw_params.tfd_size = sizeof(struct iwl_tfd); 228 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
229 priv->hw_params.max_stations = IWLAGN_STATION_COUNT; 229 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
230 priv->hw_params.bcast_sta_id = IWLAGN_BROADCAST_ID; 230 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
231 231
232 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE; 232 priv->hw_params.max_data_size = IWLAGN_RTC_DATA_SIZE;
233 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE; 233 priv->hw_params.max_inst_size = IWLAGN_RTC_INST_SIZE;
@@ -275,14 +275,19 @@ static void iwl5150_temperature(struct iwl_priv *priv)
275static int iwl5000_hw_channel_switch(struct iwl_priv *priv, 275static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
276 struct ieee80211_channel_switch *ch_switch) 276 struct ieee80211_channel_switch *ch_switch)
277{ 277{
278 /*
279 * MULTI-FIXME
280 * See iwl_mac_channel_switch.
281 */
282 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
278 struct iwl5000_channel_switch_cmd cmd; 283 struct iwl5000_channel_switch_cmd cmd;
279 const struct iwl_channel_info *ch_info; 284 const struct iwl_channel_info *ch_info;
280 u32 switch_time_in_usec, ucode_switch_time; 285 u32 switch_time_in_usec, ucode_switch_time;
281 u16 ch; 286 u16 ch;
282 u32 tsf_low; 287 u32 tsf_low;
283 u8 switch_count; 288 u8 switch_count;
284 u16 beacon_interval = le16_to_cpu(priv->rxon_timing.beacon_interval); 289 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
285 struct ieee80211_vif *vif = priv->vif; 290 struct ieee80211_vif *vif = ctx->vif;
286 struct iwl_host_cmd hcmd = { 291 struct iwl_host_cmd hcmd = {
287 .id = REPLY_CHANNEL_SWITCH, 292 .id = REPLY_CHANNEL_SWITCH,
288 .len = sizeof(cmd), 293 .len = sizeof(cmd),
@@ -293,10 +298,10 @@ static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
293 cmd.band = priv->band == IEEE80211_BAND_2GHZ; 298 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
294 ch = ch_switch->channel->hw_value; 299 ch = ch_switch->channel->hw_value;
295 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n", 300 IWL_DEBUG_11H(priv, "channel switch from %d to %d\n",
296 priv->active_rxon.channel, ch); 301 ctx->active.channel, ch);
297 cmd.channel = cpu_to_le16(ch); 302 cmd.channel = cpu_to_le16(ch);
298 cmd.rxon_flags = priv->staging_rxon.flags; 303 cmd.rxon_flags = ctx->staging.flags;
299 cmd.rxon_filter_flags = priv->staging_rxon.filter_flags; 304 cmd.rxon_filter_flags = ctx->staging.filter_flags;
300 switch_count = ch_switch->count; 305 switch_count = ch_switch->count;
301 tsf_low = ch_switch->timestamp & 0x0ffffffff; 306 tsf_low = ch_switch->timestamp & 0x0ffffffff;
302 /* 307 /*
@@ -331,7 +336,7 @@ static int iwl5000_hw_channel_switch(struct iwl_priv *priv,
331 cmd.expect_beacon = is_channel_radar(ch_info); 336 cmd.expect_beacon = is_channel_radar(ch_info);
332 else { 337 else {
333 IWL_ERR(priv, "invalid channel switch from %u to %u\n", 338 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
334 priv->active_rxon.channel, ch); 339 ctx->active.channel, ch);
335 return -EFAULT; 340 return -EFAULT;
336 } 341 }
337 priv->switch_rxon.channel = cmd.channel; 342 priv->switch_rxon.channel = cmd.channel;
@@ -393,7 +398,7 @@ static struct iwl_lib_ops iwl5000_lib = {
393 .set_ct_kill = iwl5000_set_ct_threshold, 398 .set_ct_kill = iwl5000_set_ct_threshold,
394 }, 399 },
395 .manage_ibss_station = iwlagn_manage_ibss_station, 400 .manage_ibss_station = iwlagn_manage_ibss_station,
396 .update_bcast_station = iwl_update_bcast_station, 401 .update_bcast_stations = iwl_update_bcast_stations,
397 .debugfs_ops = { 402 .debugfs_ops = {
398 .rx_stats_read = iwl_ucode_rx_stats_read, 403 .rx_stats_read = iwl_ucode_rx_stats_read,
399 .tx_stats_read = iwl_ucode_tx_stats_read, 404 .tx_stats_read = iwl_ucode_tx_stats_read,
@@ -464,7 +469,7 @@ static struct iwl_lib_ops iwl5150_lib = {
464 .set_ct_kill = iwl5150_set_ct_threshold, 469 .set_ct_kill = iwl5150_set_ct_threshold,
465 }, 470 },
466 .manage_ibss_station = iwlagn_manage_ibss_station, 471 .manage_ibss_station = iwlagn_manage_ibss_station,
467 .update_bcast_station = iwl_update_bcast_station, 472 .update_bcast_stations = iwl_update_bcast_stations,
468 .debugfs_ops = { 473 .debugfs_ops = {
469 .rx_stats_read = iwl_ucode_rx_stats_read, 474 .rx_stats_read = iwl_ucode_rx_stats_read,
470 .tx_stats_read = iwl_ucode_tx_stats_read, 475 .tx_stats_read = iwl_ucode_tx_stats_read,
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c
index fc9344b873b..2fdba088bd2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-6000.c
+++ b/drivers/net/wireless/iwlwifi/iwl-6000.c
@@ -161,7 +161,7 @@ static int iwl6000_hw_set_hw_params(struct iwl_priv *priv)
161 sizeof(struct iwlagn_scd_bc_tbl); 161 sizeof(struct iwlagn_scd_bc_tbl);
162 priv->hw_params.tfd_size = sizeof(struct iwl_tfd); 162 priv->hw_params.tfd_size = sizeof(struct iwl_tfd);
163 priv->hw_params.max_stations = IWLAGN_STATION_COUNT; 163 priv->hw_params.max_stations = IWLAGN_STATION_COUNT;
164 priv->hw_params.bcast_sta_id = IWLAGN_BROADCAST_ID; 164 priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id = IWLAGN_BROADCAST_ID;
165 165
166 priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE; 166 priv->hw_params.max_data_size = IWL60_RTC_DATA_SIZE;
167 priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE; 167 priv->hw_params.max_inst_size = IWL60_RTC_INST_SIZE;
@@ -198,14 +198,19 @@ static int iwl6000_hw_set_hw_params(struct iwl_priv *priv)
198static int iwl6000_hw_channel_switch(struct iwl_priv *priv, 198static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
199 struct ieee80211_channel_switch *ch_switch) 199 struct ieee80211_channel_switch *ch_switch)
200{ 200{
201 /*
202 * MULTI-FIXME
203 * See iwl_mac_channel_switch.
204 */
205 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
201 struct iwl6000_channel_switch_cmd cmd; 206 struct iwl6000_channel_switch_cmd cmd;
202 const struct iwl_channel_info *ch_info; 207 const struct iwl_channel_info *ch_info;
203 u32 switch_time_in_usec, ucode_switch_time; 208 u32 switch_time_in_usec, ucode_switch_time;
204 u16 ch; 209 u16 ch;
205 u32 tsf_low; 210 u32 tsf_low;
206 u8 switch_count; 211 u8 switch_count;
207 u16 beacon_interval = le16_to_cpu(priv->rxon_timing.beacon_interval); 212 u16 beacon_interval = le16_to_cpu(ctx->timing.beacon_interval);
208 struct ieee80211_vif *vif = priv->vif; 213 struct ieee80211_vif *vif = ctx->vif;
209 struct iwl_host_cmd hcmd = { 214 struct iwl_host_cmd hcmd = {
210 .id = REPLY_CHANNEL_SWITCH, 215 .id = REPLY_CHANNEL_SWITCH,
211 .len = sizeof(cmd), 216 .len = sizeof(cmd),
@@ -216,10 +221,10 @@ static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
216 cmd.band = priv->band == IEEE80211_BAND_2GHZ; 221 cmd.band = priv->band == IEEE80211_BAND_2GHZ;
217 ch = ch_switch->channel->hw_value; 222 ch = ch_switch->channel->hw_value;
218 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n", 223 IWL_DEBUG_11H(priv, "channel switch from %u to %u\n",
219 priv->active_rxon.channel, ch); 224 ctx->active.channel, ch);
220 cmd.channel = cpu_to_le16(ch); 225 cmd.channel = cpu_to_le16(ch);
221 cmd.rxon_flags = priv->staging_rxon.flags; 226 cmd.rxon_flags = ctx->staging.flags;
222 cmd.rxon_filter_flags = priv->staging_rxon.filter_flags; 227 cmd.rxon_filter_flags = ctx->staging.filter_flags;
223 switch_count = ch_switch->count; 228 switch_count = ch_switch->count;
224 tsf_low = ch_switch->timestamp & 0x0ffffffff; 229 tsf_low = ch_switch->timestamp & 0x0ffffffff;
225 /* 230 /*
@@ -254,7 +259,7 @@ static int iwl6000_hw_channel_switch(struct iwl_priv *priv,
254 cmd.expect_beacon = is_channel_radar(ch_info); 259 cmd.expect_beacon = is_channel_radar(ch_info);
255 else { 260 else {
256 IWL_ERR(priv, "invalid channel switch from %u to %u\n", 261 IWL_ERR(priv, "invalid channel switch from %u to %u\n",
257 priv->active_rxon.channel, ch); 262 ctx->active.channel, ch);
258 return -EFAULT; 263 return -EFAULT;
259 } 264 }
260 priv->switch_rxon.channel = cmd.channel; 265 priv->switch_rxon.channel = cmd.channel;
@@ -318,7 +323,7 @@ static struct iwl_lib_ops iwl6000_lib = {
318 .set_calib_version = iwl6000_set_calib_version, 323 .set_calib_version = iwl6000_set_calib_version,
319 }, 324 },
320 .manage_ibss_station = iwlagn_manage_ibss_station, 325 .manage_ibss_station = iwlagn_manage_ibss_station,
321 .update_bcast_station = iwl_update_bcast_station, 326 .update_bcast_stations = iwl_update_bcast_stations,
322 .debugfs_ops = { 327 .debugfs_ops = {
323 .rx_stats_read = iwl_ucode_rx_stats_read, 328 .rx_stats_read = iwl_ucode_rx_stats_read,
324 .tx_stats_read = iwl_ucode_tx_stats_read, 329 .tx_stats_read = iwl_ucode_tx_stats_read,
@@ -393,7 +398,7 @@ static struct iwl_lib_ops iwl6000g2b_lib = {
393 .set_calib_version = iwl6000_set_calib_version, 398 .set_calib_version = iwl6000_set_calib_version,
394 }, 399 },
395 .manage_ibss_station = iwlagn_manage_ibss_station, 400 .manage_ibss_station = iwlagn_manage_ibss_station,
396 .update_bcast_station = iwl_update_bcast_station, 401 .update_bcast_stations = iwl_update_bcast_stations,
397 .debugfs_ops = { 402 .debugfs_ops = {
398 .rx_stats_read = iwl_ucode_rx_stats_read, 403 .rx_stats_read = iwl_ucode_rx_stats_read,
399 .tx_stats_read = iwl_ucode_tx_stats_read, 404 .tx_stats_read = iwl_ucode_tx_stats_read,
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-calib.c b/drivers/net/wireless/iwlwifi/iwl-agn-calib.c
index 156b125dba7..84ad6295853 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-calib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-calib.c
@@ -625,7 +625,7 @@ void iwl_sensitivity_calibration(struct iwl_priv *priv, void *resp)
625 625
626 data = &(priv->sensitivity_data); 626 data = &(priv->sensitivity_data);
627 627
628 if (!iwl_is_associated(priv)) { 628 if (!iwl_is_any_associated(priv)) {
629 IWL_DEBUG_CALIB(priv, "<< - not associated\n"); 629 IWL_DEBUG_CALIB(priv, "<< - not associated\n");
630 return; 630 return;
631 } 631 }
@@ -763,6 +763,12 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv, void *stat_resp)
763 unsigned long flags; 763 unsigned long flags;
764 struct statistics_rx_non_phy *rx_info; 764 struct statistics_rx_non_phy *rx_info;
765 u8 first_chain; 765 u8 first_chain;
766 /*
767 * MULTI-FIXME:
768 * When we support multiple interfaces on different channels,
769 * this must be modified/fixed.
770 */
771 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
766 772
767 if (priv->disable_chain_noise_cal) 773 if (priv->disable_chain_noise_cal)
768 return; 774 return;
@@ -793,8 +799,8 @@ void iwl_chain_noise_calibration(struct iwl_priv *priv, void *stat_resp)
793 return; 799 return;
794 } 800 }
795 801
796 rxon_band24 = !!(priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK); 802 rxon_band24 = !!(ctx->staging.flags & RXON_FLG_BAND_24G_MSK);
797 rxon_chnum = le16_to_cpu(priv->staging_rxon.channel); 803 rxon_chnum = le16_to_cpu(ctx->staging.channel);
798 if (priv->cfg->bt_statistics) { 804 if (priv->cfg->bt_statistics) {
799 stat_band24 = !!(((struct iwl_bt_notif_statistics *) 805 stat_band24 = !!(((struct iwl_bt_notif_statistics *)
800 stat_resp)->flag & 806 stat_resp)->flag &
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
index 84fe06adcef..6fb52abafc8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-hcmd.c
@@ -37,12 +37,13 @@
37#include "iwl-io.h" 37#include "iwl-io.h"
38#include "iwl-agn.h" 38#include "iwl-agn.h"
39 39
40int iwlagn_send_rxon_assoc(struct iwl_priv *priv) 40int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
41 struct iwl_rxon_context *ctx)
41{ 42{
42 int ret = 0; 43 int ret = 0;
43 struct iwl5000_rxon_assoc_cmd rxon_assoc; 44 struct iwl5000_rxon_assoc_cmd rxon_assoc;
44 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon; 45 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
45 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon; 46 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
46 47
47 if ((rxon1->flags == rxon2->flags) && 48 if ((rxon1->flags == rxon2->flags) &&
48 (rxon1->filter_flags == rxon2->filter_flags) && 49 (rxon1->filter_flags == rxon2->filter_flags) &&
@@ -60,23 +61,23 @@ int iwlagn_send_rxon_assoc(struct iwl_priv *priv)
60 return 0; 61 return 0;
61 } 62 }
62 63
63 rxon_assoc.flags = priv->staging_rxon.flags; 64 rxon_assoc.flags = ctx->staging.flags;
64 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags; 65 rxon_assoc.filter_flags = ctx->staging.filter_flags;
65 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates; 66 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
66 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates; 67 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
67 rxon_assoc.reserved1 = 0; 68 rxon_assoc.reserved1 = 0;
68 rxon_assoc.reserved2 = 0; 69 rxon_assoc.reserved2 = 0;
69 rxon_assoc.reserved3 = 0; 70 rxon_assoc.reserved3 = 0;
70 rxon_assoc.ofdm_ht_single_stream_basic_rates = 71 rxon_assoc.ofdm_ht_single_stream_basic_rates =
71 priv->staging_rxon.ofdm_ht_single_stream_basic_rates; 72 ctx->staging.ofdm_ht_single_stream_basic_rates;
72 rxon_assoc.ofdm_ht_dual_stream_basic_rates = 73 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
73 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates; 74 ctx->staging.ofdm_ht_dual_stream_basic_rates;
74 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain; 75 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
75 rxon_assoc.ofdm_ht_triple_stream_basic_rates = 76 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
76 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates; 77 ctx->staging.ofdm_ht_triple_stream_basic_rates;
77 rxon_assoc.acquisition_data = priv->staging_rxon.acquisition_data; 78 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
78 79
79 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC, 80 ret = iwl_send_cmd_pdu_async(priv, ctx->rxon_assoc_cmd,
80 sizeof(rxon_assoc), &rxon_assoc, NULL); 81 sizeof(rxon_assoc), &rxon_assoc, NULL);
81 if (ret) 82 if (ret)
82 return ret; 83 return ret;
@@ -184,7 +185,7 @@ static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
184 int ret; 185 int ret;
185 186
186 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && 187 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
187 iwl_is_associated(priv)) { 188 iwl_is_any_associated(priv)) {
188 struct iwl_calib_chain_noise_reset_cmd cmd; 189 struct iwl_calib_chain_noise_reset_cmd cmd;
189 190
190 /* clear data for chain noise calibration algorithm */ 191 /* clear data for chain noise calibration algorithm */
@@ -269,12 +270,86 @@ static int iwlagn_calc_rssi(struct iwl_priv *priv,
269 return max_rssi - agc - IWLAGN_RSSI_OFFSET; 270 return max_rssi - agc - IWLAGN_RSSI_OFFSET;
270} 271}
271 272
273static int iwlagn_set_pan_params(struct iwl_priv *priv)
274{
275 struct iwl_wipan_params_cmd cmd;
276 struct iwl_rxon_context *ctx_bss, *ctx_pan;
277 int slot0 = 300, slot1 = 0;
278 int ret;
279
280 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
281 return 0;
282
283 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
284
285 lockdep_assert_held(&priv->mutex);
286
287 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
288 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
289
290 memset(&cmd, 0, sizeof(cmd));
291
292 /* only 2 slots are currently allowed */
293 cmd.num_slots = 2;
294
295 cmd.slots[0].type = 0; /* BSS */
296 cmd.slots[1].type = 1; /* PAN */
297
298 if (ctx_bss->vif && ctx_pan->vif) {
299 int bcnint = ctx_pan->vif->bss_conf.beacon_int;
300
301 /* should be set, but seems unused?? */
302 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
303
304 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
305 bcnint &&
306 bcnint != ctx_bss->vif->bss_conf.beacon_int) {
307 IWL_ERR(priv,
308 "beacon intervals don't match (%d, %d)\n",
309 ctx_bss->vif->bss_conf.beacon_int,
310 ctx_pan->vif->bss_conf.beacon_int);
311 } else
312 bcnint = max_t(int, bcnint,
313 ctx_bss->vif->bss_conf.beacon_int);
314 if (!bcnint)
315 bcnint = 100;
316 slot0 = bcnint / 2;
317 slot1 = bcnint - slot0;
318
319 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
320 (!ctx_bss->vif->bss_conf.idle &&
321 !ctx_bss->vif->bss_conf.assoc)) {
322 slot0 = bcnint * 3 - 20;
323 slot1 = 20;
324 } else if (!ctx_pan->vif->bss_conf.idle &&
325 !ctx_pan->vif->bss_conf.assoc) {
326 slot1 = bcnint * 3 - 20;
327 slot0 = 20;
328 }
329 } else if (ctx_pan->vif) {
330 slot0 = 0;
331 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
332 ctx_pan->vif->bss_conf.beacon_int;
333 slot1 = max_t(int, 100, slot1);
334 }
335
336 cmd.slots[0].width = cpu_to_le16(slot0);
337 cmd.slots[1].width = cpu_to_le16(slot1);
338
339 ret = iwl_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, sizeof(cmd), &cmd);
340 if (ret)
341 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
342
343 return ret;
344}
345
272struct iwl_hcmd_ops iwlagn_hcmd = { 346struct iwl_hcmd_ops iwlagn_hcmd = {
273 .rxon_assoc = iwlagn_send_rxon_assoc, 347 .rxon_assoc = iwlagn_send_rxon_assoc,
274 .commit_rxon = iwl_commit_rxon, 348 .commit_rxon = iwl_commit_rxon,
275 .set_rxon_chain = iwl_set_rxon_chain, 349 .set_rxon_chain = iwl_set_rxon_chain,
276 .set_tx_ant = iwlagn_send_tx_ant_config, 350 .set_tx_ant = iwlagn_send_tx_ant_config,
277 .send_bt_config = iwl_send_bt_config, 351 .send_bt_config = iwl_send_bt_config,
352 .set_pan_params = iwlagn_set_pan_params,
278}; 353};
279 354
280struct iwl_hcmd_ops iwlagn_bt_hcmd = { 355struct iwl_hcmd_ops iwlagn_bt_hcmd = {
@@ -283,6 +358,7 @@ struct iwl_hcmd_ops iwlagn_bt_hcmd = {
283 .set_rxon_chain = iwl_set_rxon_chain, 358 .set_rxon_chain = iwl_set_rxon_chain,
284 .set_tx_ant = iwlagn_send_tx_ant_config, 359 .set_tx_ant = iwlagn_send_tx_ant_config,
285 .send_bt_config = iwlagn_send_advance_bt_config, 360 .send_bt_config = iwlagn_send_advance_bt_config,
361 .set_pan_params = iwlagn_set_pan_params,
286}; 362};
287 363
288struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = { 364struct iwl_hcmd_utils_ops iwlagn_hcmd_utils = {
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
index a9e69a6213f..a8f2adfd799 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c
@@ -1163,6 +1163,7 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1163 }; 1163 };
1164 struct iwl_scan_cmd *scan; 1164 struct iwl_scan_cmd *scan;
1165 struct ieee80211_conf *conf = NULL; 1165 struct ieee80211_conf *conf = NULL;
1166 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1166 u32 rate_flags = 0; 1167 u32 rate_flags = 0;
1167 u16 cmd_len; 1168 u16 cmd_len;
1168 u16 rx_chain = 0; 1169 u16 rx_chain = 0;
@@ -1175,6 +1176,9 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1175 u8 active_chains; 1176 u8 active_chains;
1176 u8 scan_tx_antennas = priv->hw_params.valid_tx_ant; 1177 u8 scan_tx_antennas = priv->hw_params.valid_tx_ant;
1177 1178
1179 if (vif)
1180 ctx = iwl_rxon_ctx_from_vif(vif);
1181
1178 conf = ieee80211_get_hw_conf(priv->hw); 1182 conf = ieee80211_get_hw_conf(priv->hw);
1179 1183
1180 cancel_delayed_work(&priv->scan_check); 1184 cancel_delayed_work(&priv->scan_check);
@@ -1232,7 +1236,7 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1232 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; 1236 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
1233 scan->quiet_time = IWL_ACTIVE_QUIET_TIME; 1237 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
1234 1238
1235 if (iwl_is_associated(priv)) { 1239 if (iwl_is_any_associated(priv)) {
1236 u16 interval = 0; 1240 u16 interval = 0;
1237 u32 extra; 1241 u32 extra;
1238 u32 suspend_time = 100; 1242 u32 suspend_time = 100;
@@ -1283,13 +1287,15 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1283 IWL_DEBUG_SCAN(priv, "Start passive scan.\n"); 1287 IWL_DEBUG_SCAN(priv, "Start passive scan.\n");
1284 1288
1285 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; 1289 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
1286 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; 1290 scan->tx_cmd.sta_id = ctx->bcast_sta_id;
1287 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 1291 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1288 1292
1289 switch (priv->scan_band) { 1293 switch (priv->scan_band) {
1290 case IEEE80211_BAND_2GHZ: 1294 case IEEE80211_BAND_2GHZ:
1291 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; 1295 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
1292 chan_mod = le32_to_cpu(priv->active_rxon.flags & RXON_FLG_CHANNEL_MODE_MSK) 1296 chan_mod = le32_to_cpu(
1297 priv->contexts[IWL_RXON_CTX_BSS].active.flags &
1298 RXON_FLG_CHANNEL_MODE_MSK)
1293 >> RXON_FLG_CHANNEL_MODE_POS; 1299 >> RXON_FLG_CHANNEL_MODE_POS;
1294 if (chan_mod == CHANNEL_MODE_PURE_40) { 1300 if (chan_mod == CHANNEL_MODE_PURE_40) {
1295 rate = IWL_RATE_6M_PLCP; 1301 rate = IWL_RATE_6M_PLCP;
@@ -1418,6 +1424,11 @@ void iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
1418 scan->len = cpu_to_le16(cmd.len); 1424 scan->len = cpu_to_le16(cmd.len);
1419 1425
1420 set_bit(STATUS_SCAN_HW, &priv->status); 1426 set_bit(STATUS_SCAN_HW, &priv->status);
1427
1428 if (priv->cfg->ops->hcmd->set_pan_params &&
1429 priv->cfg->ops->hcmd->set_pan_params(priv))
1430 goto done;
1431
1421 if (iwl_send_cmd_sync(priv, &cmd)) 1432 if (iwl_send_cmd_sync(priv, &cmd))
1422 goto done; 1433 goto done;
1423 1434
@@ -1444,7 +1455,8 @@ int iwlagn_manage_ibss_station(struct iwl_priv *priv,
1444 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv; 1455 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1445 1456
1446 if (add) 1457 if (add)
1447 return iwl_add_bssid_station(priv, vif->bss_conf.bssid, true, 1458 return iwl_add_bssid_station(priv, vif_priv->ctx,
1459 vif->bss_conf.bssid, true,
1448 &vif_priv->ibss_bssid_sta_id); 1460 &vif_priv->ibss_bssid_sta_id);
1449 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id, 1461 return iwl_remove_station(priv, vif_priv->ibss_bssid_sta_id,
1450 vif->bss_conf.bssid); 1462 vif->bss_conf.bssid);
@@ -1477,7 +1489,7 @@ int iwlagn_wait_tx_queue_empty(struct iwl_priv *priv)
1477 1489
1478 /* waiting for all the tx frames complete might take a while */ 1490 /* waiting for all the tx frames complete might take a while */
1479 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { 1491 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
1480 if (cnt == IWL_CMD_QUEUE_NUM) 1492 if (cnt == priv->cmd_queue)
1481 continue; 1493 continue;
1482 txq = &priv->txq[cnt]; 1494 txq = &priv->txq[cnt];
1483 q = &txq->q; 1495 q = &txq->q;
@@ -1713,6 +1725,7 @@ static void iwlagn_bt_traffic_change_work(struct work_struct *work)
1713{ 1725{
1714 struct iwl_priv *priv = 1726 struct iwl_priv *priv =
1715 container_of(work, struct iwl_priv, bt_traffic_change_work); 1727 container_of(work, struct iwl_priv, bt_traffic_change_work);
1728 struct iwl_rxon_context *ctx;
1716 int smps_request = -1; 1729 int smps_request = -1;
1717 1730
1718 IWL_DEBUG_INFO(priv, "BT traffic load changes: %d\n", 1731 IWL_DEBUG_INFO(priv, "BT traffic load changes: %d\n",
@@ -1740,9 +1753,12 @@ static void iwlagn_bt_traffic_change_work(struct work_struct *work)
1740 if (priv->cfg->ops->lib->update_chain_flags) 1753 if (priv->cfg->ops->lib->update_chain_flags)
1741 priv->cfg->ops->lib->update_chain_flags(priv); 1754 priv->cfg->ops->lib->update_chain_flags(priv);
1742 1755
1743 if (smps_request != -1 && 1756 if (smps_request != -1) {
1744 priv->vif && priv->vif->type == NL80211_IFTYPE_STATION) 1757 for_each_context(priv, ctx) {
1745 ieee80211_request_smps(priv->vif, smps_request); 1758 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION)
1759 ieee80211_request_smps(ctx->vif, smps_request);
1760 }
1761 }
1746 1762
1747 mutex_unlock(&priv->mutex); 1763 mutex_unlock(&priv->mutex);
1748} 1764}
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
index e78f3f0592d..57629fba3a7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c
@@ -602,11 +602,13 @@ static int rs_toggle_antenna(u32 valid_ant, u32 *rate_n_flags,
602 * Green-field mode is valid if the station supports it and 602 * Green-field mode is valid if the station supports it and
603 * there are no non-GF stations present in the BSS. 603 * there are no non-GF stations present in the BSS.
604 */ 604 */
605static inline u8 rs_use_green(struct ieee80211_sta *sta, 605static bool rs_use_green(struct ieee80211_sta *sta)
606 struct iwl_ht_config *ht_conf)
607{ 606{
607 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
608 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
609
608 return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) && 610 return (sta->ht_cap.cap & IEEE80211_HT_CAP_GRN_FLD) &&
609 !(ht_conf->non_GF_STA_present); 611 !(ctx->ht.non_gf_sta_present);
610} 612}
611 613
612/** 614/**
@@ -758,8 +760,8 @@ static bool table_type_matches(struct iwl_scale_tbl_info *a,
758 (a->is_SGI == b->is_SGI); 760 (a->is_SGI == b->is_SGI);
759} 761}
760 762
761static void rs_bt_update_lq(struct iwl_priv *priv, 763static void rs_bt_update_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
762 struct iwl_lq_sta *lq_sta) 764 struct iwl_lq_sta *lq_sta)
763{ 765{
764 struct iwl_scale_tbl_info *tbl; 766 struct iwl_scale_tbl_info *tbl;
765 bool full_concurrent; 767 bool full_concurrent;
@@ -778,7 +780,7 @@ static void rs_bt_update_lq(struct iwl_priv *priv,
778 /* Update uCode's rate table. */ 780 /* Update uCode's rate table. */
779 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); 781 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
780 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 782 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
781 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false); 783 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
782 784
783 queue_work(priv->workqueue, &priv->bt_full_concurrency); 785 queue_work(priv->workqueue, &priv->bt_full_concurrency);
784 } 786 }
@@ -803,6 +805,8 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
803 u32 tx_rate; 805 u32 tx_rate;
804 struct iwl_scale_tbl_info tbl_type; 806 struct iwl_scale_tbl_info tbl_type;
805 struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl; 807 struct iwl_scale_tbl_info *curr_tbl, *other_tbl, *tmp_tbl;
808 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
809 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
806 810
807 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n"); 811 IWL_DEBUG_RATE_LIMIT(priv, "get frame ack response, update rate scale window\n");
808 812
@@ -869,7 +873,7 @@ static void rs_tx_status(void *priv_r, struct ieee80211_supported_band *sband,
869 lq_sta->missed_rate_counter++; 873 lq_sta->missed_rate_counter++;
870 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) { 874 if (lq_sta->missed_rate_counter > IWL_MISSED_RATE_MAX) {
871 lq_sta->missed_rate_counter = 0; 875 lq_sta->missed_rate_counter = 0;
872 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false); 876 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
873 } 877 }
874 /* Regardless, ignore this status info for outdated rate */ 878 /* Regardless, ignore this status info for outdated rate */
875 return; 879 return;
@@ -969,7 +973,7 @@ done:
969 973
970 /* Is there a need to switch between full concurrency and 3-wire? */ 974 /* Is there a need to switch between full concurrency and 3-wire? */
971 if (priv->bt_ant_couple_ok) 975 if (priv->bt_ant_couple_ok)
972 rs_bt_update_lq(priv, lq_sta); 976 rs_bt_update_lq(priv, ctx, lq_sta);
973} 977}
974 978
975/* 979/*
@@ -1163,6 +1167,8 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1163 u16 rate_mask; 1167 u16 rate_mask;
1164 s32 rate; 1168 s32 rate;
1165 s8 is_green = lq_sta->is_green; 1169 s8 is_green = lq_sta->is_green;
1170 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1171 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
1166 1172
1167 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) 1173 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1168 return -1; 1174 return -1;
@@ -1183,7 +1189,7 @@ static int rs_switch_to_mimo2(struct iwl_priv *priv,
1183 tbl->max_search = IWL_MAX_SEARCH; 1189 tbl->max_search = IWL_MAX_SEARCH;
1184 rate_mask = lq_sta->active_mimo2_rate; 1190 rate_mask = lq_sta->active_mimo2_rate;
1185 1191
1186 if (iwl_is_ht40_tx_allowed(priv, &sta->ht_cap)) 1192 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
1187 tbl->is_ht40 = 1; 1193 tbl->is_ht40 = 1;
1188 else 1194 else
1189 tbl->is_ht40 = 0; 1195 tbl->is_ht40 = 0;
@@ -1217,6 +1223,8 @@ static int rs_switch_to_mimo3(struct iwl_priv *priv,
1217 u16 rate_mask; 1223 u16 rate_mask;
1218 s32 rate; 1224 s32 rate;
1219 s8 is_green = lq_sta->is_green; 1225 s8 is_green = lq_sta->is_green;
1226 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1227 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
1220 1228
1221 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) 1229 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1222 return -1; 1230 return -1;
@@ -1237,7 +1245,7 @@ static int rs_switch_to_mimo3(struct iwl_priv *priv,
1237 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH; 1245 tbl->max_search = IWL_MAX_11N_MIMO3_SEARCH;
1238 rate_mask = lq_sta->active_mimo3_rate; 1246 rate_mask = lq_sta->active_mimo3_rate;
1239 1247
1240 if (iwl_is_ht40_tx_allowed(priv, &sta->ht_cap)) 1248 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
1241 tbl->is_ht40 = 1; 1249 tbl->is_ht40 = 1;
1242 else 1250 else
1243 tbl->is_ht40 = 0; 1251 tbl->is_ht40 = 0;
@@ -1272,6 +1280,8 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1272 u16 rate_mask; 1280 u16 rate_mask;
1273 u8 is_green = lq_sta->is_green; 1281 u8 is_green = lq_sta->is_green;
1274 s32 rate; 1282 s32 rate;
1283 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
1284 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
1275 1285
1276 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported) 1286 if (!conf_is_ht(conf) || !sta->ht_cap.ht_supported)
1277 return -1; 1287 return -1;
@@ -1284,7 +1294,7 @@ static int rs_switch_to_siso(struct iwl_priv *priv,
1284 tbl->max_search = IWL_MAX_SEARCH; 1294 tbl->max_search = IWL_MAX_SEARCH;
1285 rate_mask = lq_sta->active_siso_rate; 1295 rate_mask = lq_sta->active_siso_rate;
1286 1296
1287 if (iwl_is_ht40_tx_allowed(priv, &sta->ht_cap)) 1297 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
1288 tbl->is_ht40 = 1; 1298 tbl->is_ht40 = 1;
1289 else 1299 else
1290 tbl->is_ht40 = 0; 1300 tbl->is_ht40 = 0;
@@ -2086,6 +2096,7 @@ static void rs_stay_in_table(struct iwl_lq_sta *lq_sta, bool force_search)
2086 * return rate_n_flags as used in the table 2096 * return rate_n_flags as used in the table
2087 */ 2097 */
2088static u32 rs_update_rate_tbl(struct iwl_priv *priv, 2098static u32 rs_update_rate_tbl(struct iwl_priv *priv,
2099 struct iwl_rxon_context *ctx,
2089 struct iwl_lq_sta *lq_sta, 2100 struct iwl_lq_sta *lq_sta,
2090 struct iwl_scale_tbl_info *tbl, 2101 struct iwl_scale_tbl_info *tbl,
2091 int index, u8 is_green) 2102 int index, u8 is_green)
@@ -2095,7 +2106,7 @@ static u32 rs_update_rate_tbl(struct iwl_priv *priv,
2095 /* Update uCode's rate table. */ 2106 /* Update uCode's rate table. */
2096 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green); 2107 rate = rate_n_flags_from_tbl(priv, tbl, index, is_green);
2097 rs_fill_link_cmd(priv, lq_sta, rate); 2108 rs_fill_link_cmd(priv, lq_sta, rate);
2098 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false); 2109 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
2099 2110
2100 return rate; 2111 return rate;
2101} 2112}
@@ -2134,6 +2145,8 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2134 s32 sr; 2145 s32 sr;
2135 u8 tid = MAX_TID_COUNT; 2146 u8 tid = MAX_TID_COUNT;
2136 struct iwl_tid_data *tid_data; 2147 struct iwl_tid_data *tid_data;
2148 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
2149 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
2137 2150
2138 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n"); 2151 IWL_DEBUG_RATE(priv, "rate scale calculate new rate for skb\n");
2139 2152
@@ -2172,7 +2185,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2172 if (is_legacy(tbl->lq_type)) 2185 if (is_legacy(tbl->lq_type))
2173 lq_sta->is_green = 0; 2186 lq_sta->is_green = 0;
2174 else 2187 else
2175 lq_sta->is_green = rs_use_green(sta, &priv->current_ht_config); 2188 lq_sta->is_green = rs_use_green(sta);
2176 is_green = lq_sta->is_green; 2189 is_green = lq_sta->is_green;
2177 2190
2178 /* current tx rate */ 2191 /* current tx rate */
@@ -2211,7 +2224,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2211 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]); 2224 tbl = &(lq_sta->lq_info[lq_sta->active_tbl]);
2212 /* get "active" rate info */ 2225 /* get "active" rate info */
2213 index = iwl_hwrate_to_plcp_idx(tbl->current_rate); 2226 index = iwl_hwrate_to_plcp_idx(tbl->current_rate);
2214 rate = rs_update_rate_tbl(priv, lq_sta, 2227 rate = rs_update_rate_tbl(priv, ctx, lq_sta,
2215 tbl, index, is_green); 2228 tbl, index, is_green);
2216 } 2229 }
2217 return; 2230 return;
@@ -2453,7 +2466,7 @@ static void rs_rate_scale_perform(struct iwl_priv *priv,
2453lq_update: 2466lq_update:
2454 /* Replace uCode's rate table for the destination station. */ 2467 /* Replace uCode's rate table for the destination station. */
2455 if (update_lq) 2468 if (update_lq)
2456 rate = rs_update_rate_tbl(priv, lq_sta, 2469 rate = rs_update_rate_tbl(priv, ctx, lq_sta,
2457 tbl, index, is_green); 2470 tbl, index, is_green);
2458 2471
2459 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) { 2472 if (iwl_tx_ant_restriction(priv) == IWL_ANT_OK_MULTI) {
@@ -2495,7 +2508,7 @@ lq_update:
2495 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n", 2508 IWL_DEBUG_RATE(priv, "Switch current mcs: %X index: %d\n",
2496 tbl->current_rate, index); 2509 tbl->current_rate, index);
2497 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate); 2510 rs_fill_link_cmd(priv, lq_sta, tbl->current_rate);
2498 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_ASYNC, false); 2511 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_ASYNC, false);
2499 } else 2512 } else
2500 done_search = 1; 2513 done_search = 1;
2501 } 2514 }
@@ -2565,12 +2578,17 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2565 int rate_idx; 2578 int rate_idx;
2566 int i; 2579 int i;
2567 u32 rate; 2580 u32 rate;
2568 u8 use_green = rs_use_green(sta, &priv->current_ht_config); 2581 u8 use_green = rs_use_green(sta);
2569 u8 active_tbl = 0; 2582 u8 active_tbl = 0;
2570 u8 valid_tx_ant; 2583 u8 valid_tx_ant;
2584 struct iwl_station_priv *sta_priv;
2585 struct iwl_rxon_context *ctx;
2571 2586
2572 if (!sta || !lq_sta) 2587 if (!sta || !lq_sta)
2573 goto out; 2588 return;
2589
2590 sta_priv = (void *)sta->drv_priv;
2591 ctx = sta_priv->common.ctx;
2574 2592
2575 i = lq_sta->last_txrate_idx; 2593 i = lq_sta->last_txrate_idx;
2576 2594
@@ -2602,9 +2620,7 @@ static void rs_initialize_lq(struct iwl_priv *priv,
2602 rs_set_expected_tpt_table(lq_sta, tbl); 2620 rs_set_expected_tpt_table(lq_sta, tbl);
2603 rs_fill_link_cmd(NULL, lq_sta, rate); 2621 rs_fill_link_cmd(NULL, lq_sta, rate);
2604 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq; 2622 priv->stations[lq_sta->lq.sta_id].lq = &lq_sta->lq;
2605 iwl_send_lq_cmd(priv, &lq_sta->lq, CMD_SYNC, true); 2623 iwl_send_lq_cmd(priv, ctx, &lq_sta->lq, CMD_SYNC, true);
2606 out:
2607 return;
2608} 2624}
2609 2625
2610static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta, 2626static void rs_get_rate(void *priv_r, struct ieee80211_sta *sta, void *priv_sta,
@@ -2732,7 +2748,7 @@ void iwl_rs_rate_init(struct iwl_priv *priv, struct ieee80211_sta *sta, u8 sta_i
2732 lq_sta->is_dup = 0; 2748 lq_sta->is_dup = 0;
2733 lq_sta->max_rate_idx = -1; 2749 lq_sta->max_rate_idx = -1;
2734 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX; 2750 lq_sta->missed_rate_counter = IWL_MISSED_RATE_MAX;
2735 lq_sta->is_green = rs_use_green(sta, &priv->current_ht_config); 2751 lq_sta->is_green = rs_use_green(sta);
2736 lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000); 2752 lq_sta->active_legacy_rate = priv->active_rate & ~(0x1000);
2737 lq_sta->band = priv->band; 2753 lq_sta->band = priv->band;
2738 /* 2754 /*
@@ -2992,6 +3008,9 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
2992 char buf[64]; 3008 char buf[64];
2993 int buf_size; 3009 int buf_size;
2994 u32 parsed_rate; 3010 u32 parsed_rate;
3011 struct iwl_station_priv *sta_priv =
3012 container_of(lq_sta, struct iwl_station_priv, lq_sta);
3013 struct iwl_rxon_context *ctx = sta_priv->common.ctx;
2995 3014
2996 priv = lq_sta->drv; 3015 priv = lq_sta->drv;
2997 memset(buf, 0, sizeof(buf)); 3016 memset(buf, 0, sizeof(buf));
@@ -3014,7 +3033,8 @@ static ssize_t rs_sta_dbgfs_scale_table_write(struct file *file,
3014 3033
3015 if (lq_sta->dbg_fixed_rate) { 3034 if (lq_sta->dbg_fixed_rate) {
3016 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate); 3035 rs_fill_link_cmd(NULL, lq_sta, lq_sta->dbg_fixed_rate);
3017 iwl_send_lq_cmd(lq_sta->drv, &lq_sta->lq, CMD_ASYNC, false); 3036 iwl_send_lq_cmd(lq_sta->drv, ctx, &lq_sta->lq, CMD_ASYNC,
3037 false);
3018 } 3038 }
3019 3039
3020 return count; 3040 return count;
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
index 30298ea56a2..07b2c6cadf5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tt.c
@@ -416,18 +416,26 @@ static void iwl_advance_tt_handler(struct iwl_priv *priv, s32 temp, bool force)
416 /* stop ct_kill_waiting_tm timer */ 416 /* stop ct_kill_waiting_tm timer */
417 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm); 417 del_timer_sync(&priv->thermal_throttle.ct_kill_waiting_tm);
418 if (changed) { 418 if (changed) {
419 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
420
421 if (tt->state >= IWL_TI_1) { 419 if (tt->state >= IWL_TI_1) {
422 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */ 420 /* force PI = IWL_POWER_INDEX_5 in the case of TI > 0 */
423 tt->tt_power_mode = IWL_POWER_INDEX_5; 421 tt->tt_power_mode = IWL_POWER_INDEX_5;
424 if (!iwl_ht_enabled(priv)) 422
425 /* disable HT */ 423 if (!iwl_ht_enabled(priv)) {
426 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | 424 struct iwl_rxon_context *ctx;
427 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | 425
428 RXON_FLG_HT40_PROT_MSK | 426 for_each_context(priv, ctx) {
429 RXON_FLG_HT_PROT_MSK); 427 struct iwl_rxon_cmd *rxon;
430 else { 428
429 rxon = &ctx->staging;
430
431 /* disable HT */
432 rxon->flags &= ~(
433 RXON_FLG_CHANNEL_MODE_MSK |
434 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
435 RXON_FLG_HT40_PROT_MSK |
436 RXON_FLG_HT_PROT_MSK);
437 }
438 } else {
431 /* check HT capability and set 439 /* check HT capability and set
432 * according to the system HT capability 440 * according to the system HT capability
433 * in case get disabled before */ 441 * in case get disabled before */
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
index a51a7cfa5a1..5950184d986 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c
@@ -71,18 +71,6 @@ static const u8 tid_to_ac[] = {
71 2, 3, 3, 2, 1, 1, 0, 0 71 2, 3, 3, 2, 1, 1, 0, 0
72}; 72};
73 73
74static const u8 ac_to_fifo[] = {
75 IWL_TX_FIFO_VO,
76 IWL_TX_FIFO_VI,
77 IWL_TX_FIFO_BE,
78 IWL_TX_FIFO_BK,
79};
80
81static inline int get_fifo_from_ac(u8 ac)
82{
83 return ac_to_fifo[ac];
84}
85
86static inline int get_ac_from_tid(u16 tid) 74static inline int get_ac_from_tid(u16 tid)
87{ 75{
88 if (likely(tid < ARRAY_SIZE(tid_to_ac))) 76 if (likely(tid < ARRAY_SIZE(tid_to_ac)))
@@ -92,10 +80,10 @@ static inline int get_ac_from_tid(u16 tid)
92 return -EINVAL; 80 return -EINVAL;
93} 81}
94 82
95static inline int get_fifo_from_tid(u16 tid) 83static inline int get_fifo_from_tid(struct iwl_rxon_context *ctx, u16 tid)
96{ 84{
97 if (likely(tid < ARRAY_SIZE(tid_to_ac))) 85 if (likely(tid < ARRAY_SIZE(tid_to_ac)))
98 return get_fifo_from_ac(tid_to_ac[tid]); 86 return ctx->ac_to_fifo[tid_to_ac[tid]];
99 87
100 /* no support for TIDs 8-15 yet */ 88 /* no support for TIDs 8-15 yet */
101 return -EINVAL; 89 return -EINVAL;
@@ -118,7 +106,7 @@ void iwlagn_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
118 106
119 WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX); 107 WARN_ON(len > 0xFFF || write_ptr >= TFD_QUEUE_SIZE_MAX);
120 108
121 if (txq_id != IWL_CMD_QUEUE_NUM) { 109 if (txq_id != priv->cmd_queue) {
122 sta_id = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id; 110 sta_id = txq->cmd[txq->q.write_ptr]->cmd.tx.sta_id;
123 sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl; 111 sec_ctl = txq->cmd[txq->q.write_ptr]->cmd.tx.sec_ctl;
124 112
@@ -155,7 +143,7 @@ void iwlagn_txq_inval_byte_cnt_tbl(struct iwl_priv *priv,
155 143
156 WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX); 144 WARN_ON(read_ptr >= TFD_QUEUE_SIZE_MAX);
157 145
158 if (txq_id != IWL_CMD_QUEUE_NUM) 146 if (txq_id != priv->cmd_queue)
159 sta_id = txq->cmd[read_ptr]->cmd.tx.sta_id; 147 sta_id = txq->cmd[read_ptr]->cmd.tx.sta_id;
160 148
161 bc_ent = cpu_to_le16(1 | (sta_id << 12)); 149 bc_ent = cpu_to_le16(1 | (sta_id << 12));
@@ -333,11 +321,6 @@ void iwlagn_txq_set_sched(struct iwl_priv *priv, u32 mask)
333 iwl_write_prph(priv, IWLAGN_SCD_TXFACT, mask); 321 iwl_write_prph(priv, IWLAGN_SCD_TXFACT, mask);
334} 322}
335 323
336static inline int get_queue_from_ac(u16 ac)
337{
338 return ac;
339}
340
341/* 324/*
342 * handle build REPLY_TX command notification. 325 * handle build REPLY_TX command notification.
343 */ 326 */
@@ -531,6 +514,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
531 struct iwl_device_cmd *out_cmd; 514 struct iwl_device_cmd *out_cmd;
532 struct iwl_cmd_meta *out_meta; 515 struct iwl_cmd_meta *out_meta;
533 struct iwl_tx_cmd *tx_cmd; 516 struct iwl_tx_cmd *tx_cmd;
517 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
534 int swq_id, txq_id; 518 int swq_id, txq_id;
535 dma_addr_t phys_addr; 519 dma_addr_t phys_addr;
536 dma_addr_t txcmd_phys; 520 dma_addr_t txcmd_phys;
@@ -545,6 +529,9 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
545 u8 *qc = NULL; 529 u8 *qc = NULL;
546 unsigned long flags; 530 unsigned long flags;
547 531
532 if (info->control.vif)
533 ctx = iwl_rxon_ctx_from_vif(info->control.vif);
534
548 spin_lock_irqsave(&priv->lock, flags); 535 spin_lock_irqsave(&priv->lock, flags);
549 if (iwl_is_rfkill(priv)) { 536 if (iwl_is_rfkill(priv)) {
550 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n"); 537 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
@@ -565,7 +552,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
565 hdr_len = ieee80211_hdrlen(fc); 552 hdr_len = ieee80211_hdrlen(fc);
566 553
567 /* Find index into station table for destination station */ 554 /* Find index into station table for destination station */
568 sta_id = iwl_sta_id_or_broadcast(priv, info->control.sta); 555 sta_id = iwl_sta_id_or_broadcast(priv, ctx, info->control.sta);
569 if (sta_id == IWL_INVALID_STATION) { 556 if (sta_id == IWL_INVALID_STATION) {
570 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", 557 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
571 hdr->addr1); 558 hdr->addr1);
@@ -577,8 +564,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
577 if (sta) 564 if (sta)
578 sta_priv = (void *)sta->drv_priv; 565 sta_priv = (void *)sta->drv_priv;
579 566
580 if (sta_priv && sta_id != priv->hw_params.bcast_sta_id && 567 if (sta_priv && sta_priv->asleep) {
581 sta_priv->asleep) {
582 WARN_ON(!(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE)); 568 WARN_ON(!(info->flags & IEEE80211_TX_CTL_PSPOLL_RESPONSE));
583 /* 569 /*
584 * This sends an asynchronous command to the device, 570 * This sends an asynchronous command to the device,
@@ -592,7 +578,20 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
592 iwl_sta_modify_sleep_tx_count(priv, sta_id, 1); 578 iwl_sta_modify_sleep_tx_count(priv, sta_id, 1);
593 } 579 }
594 580
595 txq_id = get_queue_from_ac(skb_get_queue_mapping(skb)); 581 /*
582 * Send this frame after DTIM -- there's a special queue
583 * reserved for this for contexts that support AP mode.
584 */
585 if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) {
586 txq_id = ctx->mcast_queue;
587 /*
588 * The microcode will clear the more data
589 * bit in the last frame it transmits.
590 */
591 hdr->frame_control |=
592 cpu_to_le16(IEEE80211_FCTL_MOREDATA);
593 } else
594 txq_id = ctx->ac_to_queue[skb_get_queue_mapping(skb)];
596 595
597 /* irqs already disabled/saved above when locking priv->lock */ 596 /* irqs already disabled/saved above when locking priv->lock */
598 spin_lock(&priv->sta_lock); 597 spin_lock(&priv->sta_lock);
@@ -637,6 +636,7 @@ int iwlagn_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
637 /* Set up driver data for this TFD */ 636 /* Set up driver data for this TFD */
638 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); 637 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
639 txq->txb[q->write_ptr].skb = skb; 638 txq->txb[q->write_ptr].skb = skb;
639 txq->txb[q->write_ptr].ctx = ctx;
640 640
641 /* Set up first empty entry in queue's array of Tx/cmd buffers */ 641 /* Set up first empty entry in queue's array of Tx/cmd buffers */
642 out_cmd = txq->cmd[q->write_ptr]; 642 out_cmd = txq->cmd[q->write_ptr];
@@ -825,7 +825,7 @@ void iwlagn_hw_txq_ctx_free(struct iwl_priv *priv)
825 /* Tx queues */ 825 /* Tx queues */
826 if (priv->txq) { 826 if (priv->txq) {
827 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) 827 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
828 if (txq_id == IWL_CMD_QUEUE_NUM) 828 if (txq_id == priv->cmd_queue)
829 iwl_cmd_queue_free(priv); 829 iwl_cmd_queue_free(priv);
830 else 830 else
831 iwl_tx_queue_free(priv, txq_id); 831 iwl_tx_queue_free(priv, txq_id);
@@ -882,9 +882,9 @@ int iwlagn_txq_ctx_alloc(struct iwl_priv *priv)
882 882
883 spin_unlock_irqrestore(&priv->lock, flags); 883 spin_unlock_irqrestore(&priv->lock, flags);
884 884
885 /* Alloc and init all Tx queues, including the command queue (#4) */ 885 /* Alloc and init all Tx queues, including the command queue (#4/#9) */
886 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { 886 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
887 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ? 887 slots_num = (txq_id == priv->cmd_queue) ?
888 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; 888 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
889 ret = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num, 889 ret = iwl_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
890 txq_id); 890 txq_id);
@@ -922,7 +922,7 @@ void iwlagn_txq_ctx_reset(struct iwl_priv *priv)
922 922
923 /* Alloc and init all Tx queues, including the command queue (#4) */ 923 /* Alloc and init all Tx queues, including the command queue (#4) */
924 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) { 924 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
925 slots_num = txq_id == IWL_CMD_QUEUE_NUM ? 925 slots_num = txq_id == priv->cmd_queue ?
926 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS; 926 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
927 iwl_tx_queue_reset(priv, &priv->txq[txq_id], slots_num, txq_id); 927 iwl_tx_queue_reset(priv, &priv->txq[txq_id], slots_num, txq_id);
928 } 928 }
@@ -980,7 +980,7 @@ int iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif,
980 unsigned long flags; 980 unsigned long flags;
981 struct iwl_tid_data *tid_data; 981 struct iwl_tid_data *tid_data;
982 982
983 tx_fifo = get_fifo_from_tid(tid); 983 tx_fifo = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
984 if (unlikely(tx_fifo < 0)) 984 if (unlikely(tx_fifo < 0))
985 return tx_fifo; 985 return tx_fifo;
986 986
@@ -1041,7 +1041,7 @@ int iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif,
1041 int write_ptr, read_ptr; 1041 int write_ptr, read_ptr;
1042 unsigned long flags; 1042 unsigned long flags;
1043 1043
1044 tx_fifo_id = get_fifo_from_tid(tid); 1044 tx_fifo_id = get_fifo_from_tid(iwl_rxon_ctx_from_vif(vif), tid);
1045 if (unlikely(tx_fifo_id < 0)) 1045 if (unlikely(tx_fifo_id < 0))
1046 return tx_fifo_id; 1046 return tx_fifo_id;
1047 1047
@@ -1116,6 +1116,9 @@ int iwlagn_txq_check_empty(struct iwl_priv *priv,
1116 struct iwl_queue *q = &priv->txq[txq_id].q; 1116 struct iwl_queue *q = &priv->txq[txq_id].q;
1117 u8 *addr = priv->stations[sta_id].sta.sta.addr; 1117 u8 *addr = priv->stations[sta_id].sta.sta.addr;
1118 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid]; 1118 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
1119 struct iwl_rxon_context *ctx;
1120
1121 ctx = &priv->contexts[priv->stations[sta_id].ctxid];
1119 1122
1120 lockdep_assert_held(&priv->sta_lock); 1123 lockdep_assert_held(&priv->sta_lock);
1121 1124
@@ -1126,12 +1129,12 @@ int iwlagn_txq_check_empty(struct iwl_priv *priv,
1126 if ((txq_id == tid_data->agg.txq_id) && 1129 if ((txq_id == tid_data->agg.txq_id) &&
1127 (q->read_ptr == q->write_ptr)) { 1130 (q->read_ptr == q->write_ptr)) {
1128 u16 ssn = SEQ_TO_SN(tid_data->seq_number); 1131 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
1129 int tx_fifo = get_fifo_from_tid(tid); 1132 int tx_fifo = get_fifo_from_tid(ctx, tid);
1130 IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n"); 1133 IWL_DEBUG_HT(priv, "HW queue empty: continue DELBA flow\n");
1131 priv->cfg->ops->lib->txq_agg_disable(priv, txq_id, 1134 priv->cfg->ops->lib->txq_agg_disable(priv, txq_id,
1132 ssn, tx_fifo); 1135 ssn, tx_fifo);
1133 tid_data->agg.state = IWL_AGG_OFF; 1136 tid_data->agg.state = IWL_AGG_OFF;
1134 ieee80211_stop_tx_ba_cb_irqsafe(priv->vif, addr, tid); 1137 ieee80211_stop_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
1135 } 1138 }
1136 break; 1139 break;
1137 case IWL_EMPTYING_HW_QUEUE_ADDBA: 1140 case IWL_EMPTYING_HW_QUEUE_ADDBA:
@@ -1139,7 +1142,7 @@ int iwlagn_txq_check_empty(struct iwl_priv *priv,
1139 if (tid_data->tfds_in_queue == 0) { 1142 if (tid_data->tfds_in_queue == 0) {
1140 IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n"); 1143 IWL_DEBUG_HT(priv, "HW queue empty: continue ADDBA flow\n");
1141 tid_data->agg.state = IWL_AGG_ON; 1144 tid_data->agg.state = IWL_AGG_ON;
1142 ieee80211_start_tx_ba_cb_irqsafe(priv->vif, addr, tid); 1145 ieee80211_start_tx_ba_cb_irqsafe(ctx->vif, addr, tid);
1143 } 1146 }
1144 break; 1147 break;
1145 } 1148 }
@@ -1147,14 +1150,14 @@ int iwlagn_txq_check_empty(struct iwl_priv *priv,
1147 return 0; 1150 return 0;
1148} 1151}
1149 1152
1150static void iwlagn_tx_status(struct iwl_priv *priv, struct sk_buff *skb) 1153static void iwlagn_tx_status(struct iwl_priv *priv, struct iwl_tx_info *tx_info)
1151{ 1154{
1152 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data; 1155 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) tx_info->skb->data;
1153 struct ieee80211_sta *sta; 1156 struct ieee80211_sta *sta;
1154 struct iwl_station_priv *sta_priv; 1157 struct iwl_station_priv *sta_priv;
1155 1158
1156 rcu_read_lock(); 1159 rcu_read_lock();
1157 sta = ieee80211_find_sta(priv->vif, hdr->addr1); 1160 sta = ieee80211_find_sta(tx_info->ctx->vif, hdr->addr1);
1158 if (sta) { 1161 if (sta) {
1159 sta_priv = (void *)sta->drv_priv; 1162 sta_priv = (void *)sta->drv_priv;
1160 /* avoid atomic ops if this isn't a client */ 1163 /* avoid atomic ops if this isn't a client */
@@ -1164,7 +1167,7 @@ static void iwlagn_tx_status(struct iwl_priv *priv, struct sk_buff *skb)
1164 } 1167 }
1165 rcu_read_unlock(); 1168 rcu_read_unlock();
1166 1169
1167 ieee80211_tx_status_irqsafe(priv->hw, skb); 1170 ieee80211_tx_status_irqsafe(priv->hw, tx_info->skb);
1168} 1171}
1169 1172
1170int iwlagn_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index) 1173int iwlagn_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
@@ -1187,7 +1190,7 @@ int iwlagn_tx_queue_reclaim(struct iwl_priv *priv, int txq_id, int index)
1187 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) { 1190 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1188 1191
1189 tx_info = &txq->txb[txq->q.read_ptr]; 1192 tx_info = &txq->txb[txq->q.read_ptr];
1190 iwlagn_tx_status(priv, tx_info->skb); 1193 iwlagn_tx_status(priv, tx_info);
1191 1194
1192 hdr = (struct ieee80211_hdr *)tx_info->skb->data; 1195 hdr = (struct ieee80211_hdr *)tx_info->skb->data;
1193 if (hdr && ieee80211_is_data_qos(hdr->frame_control)) 1196 if (hdr && ieee80211_is_data_qos(hdr->frame_control))
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
index f2499e1f204..a7961bf395f 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn-ucode.c
@@ -52,6 +52,19 @@ static const s8 iwlagn_default_queue_to_tx_fifo[] = {
52 IWL_TX_FIFO_UNUSED, 52 IWL_TX_FIFO_UNUSED,
53}; 53};
54 54
55static const s8 iwlagn_ipan_queue_to_tx_fifo[] = {
56 IWL_TX_FIFO_VO,
57 IWL_TX_FIFO_VI,
58 IWL_TX_FIFO_BE,
59 IWL_TX_FIFO_BK,
60 IWL_TX_FIFO_BK_IPAN,
61 IWL_TX_FIFO_BE_IPAN,
62 IWL_TX_FIFO_VI_IPAN,
63 IWL_TX_FIFO_VO_IPAN,
64 IWL_TX_FIFO_BE_IPAN,
65 IWLAGN_CMD_FIFO_NUM,
66};
67
55static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = { 68static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
56 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP, 69 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
57 0, COEX_UNASSOC_IDLE_FLAGS}, 70 0, COEX_UNASSOC_IDLE_FLAGS},
@@ -376,6 +389,7 @@ static void iwlagn_send_bt_env(struct iwl_priv *priv, u8 action, u8 type)
376 389
377int iwlagn_alive_notify(struct iwl_priv *priv) 390int iwlagn_alive_notify(struct iwl_priv *priv)
378{ 391{
392 const s8 *queues;
379 u32 a; 393 u32 a;
380 unsigned long flags; 394 unsigned long flags;
381 int i, chan; 395 int i, chan;
@@ -410,7 +424,7 @@ int iwlagn_alive_notify(struct iwl_priv *priv)
410 reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN); 424 reg_val | FH_TX_CHICKEN_BITS_SCD_AUTO_RETRY_EN);
411 425
412 iwl_write_prph(priv, IWLAGN_SCD_QUEUECHAIN_SEL, 426 iwl_write_prph(priv, IWLAGN_SCD_QUEUECHAIN_SEL,
413 IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv->hw_params.max_txq_num)); 427 IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv));
414 iwl_write_prph(priv, IWLAGN_SCD_AGGR_SEL, 0); 428 iwl_write_prph(priv, IWLAGN_SCD_AGGR_SEL, 0);
415 429
416 /* initiate the queues */ 430 /* initiate the queues */
@@ -436,7 +450,13 @@ int iwlagn_alive_notify(struct iwl_priv *priv)
436 /* Activate all Tx DMA/FIFO channels */ 450 /* Activate all Tx DMA/FIFO channels */
437 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7)); 451 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
438 452
439 iwlagn_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0); 453 /* map queues to FIFOs */
454 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
455 queues = iwlagn_ipan_queue_to_tx_fifo;
456 else
457 queues = iwlagn_default_queue_to_tx_fifo;
458
459 iwlagn_set_wr_ptrs(priv, priv->cmd_queue, 0);
440 460
441 /* make sure all queue are not stopped */ 461 /* make sure all queue are not stopped */
442 memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped)); 462 memset(&priv->queue_stopped[0], 0, sizeof(priv->queue_stopped));
@@ -445,11 +465,12 @@ int iwlagn_alive_notify(struct iwl_priv *priv)
445 465
446 /* reset to 0 to enable all the queue first */ 466 /* reset to 0 to enable all the queue first */
447 priv->txq_ctx_active_msk = 0; 467 priv->txq_ctx_active_msk = 0;
448 /* map qos queues to fifos one-to-one */ 468
449 BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) != 10); 469 BUILD_BUG_ON(ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo) != 10);
470 BUILD_BUG_ON(ARRAY_SIZE(iwlagn_ipan_queue_to_tx_fifo) != 10);
450 471
451 for (i = 0; i < ARRAY_SIZE(iwlagn_default_queue_to_tx_fifo); i++) { 472 for (i = 0; i < 10; i++) {
452 int ac = iwlagn_default_queue_to_tx_fifo[i]; 473 int ac = queues[i];
453 474
454 iwl_txq_ctx_activate(priv, i); 475 iwl_txq_ctx_activate(priv, i);
455 476
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c
index 5e0d0d527bf..ad0e67f5c0d 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.c
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.c
@@ -98,21 +98,22 @@ static bool iwlagn_bt_ch_announce = 1;
98 * function correctly transitions out of the RXON_ASSOC_MSK state if 98 * function correctly transitions out of the RXON_ASSOC_MSK state if
99 * a HW tune is required based on the RXON structure changes. 99 * a HW tune is required based on the RXON structure changes.
100 */ 100 */
101int iwl_commit_rxon(struct iwl_priv *priv) 101int iwl_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
102{ 102{
103 /* cast away the const for active_rxon in this function */ 103 /* cast away the const for active_rxon in this function */
104 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon; 104 struct iwl_rxon_cmd *active_rxon = (void *)&ctx->active;
105 int ret; 105 int ret;
106 bool new_assoc = 106 bool new_assoc =
107 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK); 107 !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
108 bool old_assoc = !!(ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK);
108 109
109 if (!iwl_is_alive(priv)) 110 if (!iwl_is_alive(priv))
110 return -EBUSY; 111 return -EBUSY;
111 112
112 /* always get timestamp with Rx frame */ 113 /* always get timestamp with Rx frame */
113 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK; 114 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
114 115
115 ret = iwl_check_rxon_cmd(priv); 116 ret = iwl_check_rxon_cmd(priv, ctx);
116 if (ret) { 117 if (ret) {
117 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n"); 118 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
118 return -EINVAL; 119 return -EINVAL;
@@ -123,7 +124,7 @@ int iwl_commit_rxon(struct iwl_priv *priv)
123 * abort any previous channel switch if still in process 124 * abort any previous channel switch if still in process
124 */ 125 */
125 if (priv->switch_rxon.switch_in_progress && 126 if (priv->switch_rxon.switch_in_progress &&
126 (priv->switch_rxon.channel != priv->staging_rxon.channel)) { 127 (priv->switch_rxon.channel != ctx->staging.channel)) {
127 IWL_DEBUG_11H(priv, "abort channel switch on %d\n", 128 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
128 le16_to_cpu(priv->switch_rxon.channel)); 129 le16_to_cpu(priv->switch_rxon.channel));
129 iwl_chswitch_done(priv, false); 130 iwl_chswitch_done(priv, false);
@@ -132,15 +133,15 @@ int iwl_commit_rxon(struct iwl_priv *priv)
132 /* If we don't need to send a full RXON, we can use 133 /* If we don't need to send a full RXON, we can use
133 * iwl_rxon_assoc_cmd which is used to reconfigure filter 134 * iwl_rxon_assoc_cmd which is used to reconfigure filter
134 * and other flags for the current radio configuration. */ 135 * and other flags for the current radio configuration. */
135 if (!iwl_full_rxon_required(priv)) { 136 if (!iwl_full_rxon_required(priv, ctx)) {
136 ret = iwl_send_rxon_assoc(priv); 137 ret = iwl_send_rxon_assoc(priv, ctx);
137 if (ret) { 138 if (ret) {
138 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret); 139 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
139 return ret; 140 return ret;
140 } 141 }
141 142
142 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 143 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
143 iwl_print_rx_config_cmd(priv); 144 iwl_print_rx_config_cmd(priv, ctx);
144 return 0; 145 return 0;
145 } 146 }
146 147
@@ -148,13 +149,13 @@ int iwl_commit_rxon(struct iwl_priv *priv)
148 * an RXON_ASSOC and the new config wants the associated mask enabled, 149 * an RXON_ASSOC and the new config wants the associated mask enabled,
149 * we must clear the associated from the active configuration 150 * we must clear the associated from the active configuration
150 * before we apply the new config */ 151 * before we apply the new config */
151 if (iwl_is_associated(priv) && new_assoc) { 152 if (iwl_is_associated_ctx(ctx) && new_assoc) {
152 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n"); 153 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
153 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 154 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
154 155
155 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 156 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
156 sizeof(struct iwl_rxon_cmd), 157 sizeof(struct iwl_rxon_cmd),
157 &priv->active_rxon); 158 active_rxon);
158 159
159 /* If the mask clearing failed then we set 160 /* If the mask clearing failed then we set
160 * active_rxon back to what it was previously */ 161 * active_rxon back to what it was previously */
@@ -163,9 +164,9 @@ int iwl_commit_rxon(struct iwl_priv *priv)
163 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret); 164 IWL_ERR(priv, "Error clearing ASSOC_MSK (%d)\n", ret);
164 return ret; 165 return ret;
165 } 166 }
166 iwl_clear_ucode_stations(priv); 167 iwl_clear_ucode_stations(priv, ctx);
167 iwl_restore_stations(priv); 168 iwl_restore_stations(priv, ctx);
168 ret = iwl_restore_default_wep_keys(priv); 169 ret = iwl_restore_default_wep_keys(priv, ctx);
169 if (ret) { 170 if (ret) {
170 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); 171 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
171 return ret; 172 return ret;
@@ -177,27 +178,46 @@ int iwl_commit_rxon(struct iwl_priv *priv)
177 "* channel = %d\n" 178 "* channel = %d\n"
178 "* bssid = %pM\n", 179 "* bssid = %pM\n",
179 (new_assoc ? "" : "out"), 180 (new_assoc ? "" : "out"),
180 le16_to_cpu(priv->staging_rxon.channel), 181 le16_to_cpu(ctx->staging.channel),
181 priv->staging_rxon.bssid_addr); 182 ctx->staging.bssid_addr);
182 183
183 iwl_set_rxon_hwcrypto(priv, !priv->cfg->mod_params->sw_crypto); 184 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
185
186 if (!old_assoc) {
187 /*
188 * First of all, before setting associated, we need to
189 * send RXON timing so the device knows about the DTIM
190 * period and other timing values
191 */
192 ret = iwl_send_rxon_timing(priv, ctx);
193 if (ret) {
194 IWL_ERR(priv, "Error setting RXON timing!\n");
195 return ret;
196 }
197 }
198
199 if (priv->cfg->ops->hcmd->set_pan_params) {
200 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
201 if (ret)
202 return ret;
203 }
184 204
185 /* Apply the new configuration 205 /* Apply the new configuration
186 * RXON unassoc clears the station table in uCode so restoration of 206 * RXON unassoc clears the station table in uCode so restoration of
187 * stations is needed after it (the RXON command) completes 207 * stations is needed after it (the RXON command) completes
188 */ 208 */
189 if (!new_assoc) { 209 if (!new_assoc) {
190 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 210 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
191 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); 211 sizeof(struct iwl_rxon_cmd), &ctx->staging);
192 if (ret) { 212 if (ret) {
193 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); 213 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
194 return ret; 214 return ret;
195 } 215 }
196 IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n"); 216 IWL_DEBUG_INFO(priv, "Return from !new_assoc RXON.\n");
197 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 217 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
198 iwl_clear_ucode_stations(priv); 218 iwl_clear_ucode_stations(priv, ctx);
199 iwl_restore_stations(priv); 219 iwl_restore_stations(priv, ctx);
200 ret = iwl_restore_default_wep_keys(priv); 220 ret = iwl_restore_default_wep_keys(priv, ctx);
201 if (ret) { 221 if (ret) {
202 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret); 222 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
203 return ret; 223 return ret;
@@ -209,15 +229,15 @@ int iwl_commit_rxon(struct iwl_priv *priv)
209 /* Apply the new configuration 229 /* Apply the new configuration
210 * RXON assoc doesn't clear the station table in uCode, 230 * RXON assoc doesn't clear the station table in uCode,
211 */ 231 */
212 ret = iwl_send_cmd_pdu(priv, REPLY_RXON, 232 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
213 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon); 233 sizeof(struct iwl_rxon_cmd), &ctx->staging);
214 if (ret) { 234 if (ret) {
215 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret); 235 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
216 return ret; 236 return ret;
217 } 237 }
218 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon)); 238 memcpy(active_rxon, &ctx->staging, sizeof(*active_rxon));
219 } 239 }
220 iwl_print_rx_config_cmd(priv); 240 iwl_print_rx_config_cmd(priv, ctx);
221 241
222 iwl_init_sensitivity(priv); 242 iwl_init_sensitivity(priv);
223 243
@@ -234,10 +254,14 @@ int iwl_commit_rxon(struct iwl_priv *priv)
234 254
235void iwl_update_chain_flags(struct iwl_priv *priv) 255void iwl_update_chain_flags(struct iwl_priv *priv)
236{ 256{
257 struct iwl_rxon_context *ctx;
237 258
238 if (priv->cfg->ops->hcmd->set_rxon_chain) 259 if (priv->cfg->ops->hcmd->set_rxon_chain) {
239 priv->cfg->ops->hcmd->set_rxon_chain(priv); 260 for_each_context(priv, ctx) {
240 iwlcore_commit_rxon(priv); 261 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
262 iwlcore_commit_rxon(priv, ctx);
263 }
264 }
241} 265}
242 266
243static void iwl_clear_free_frames(struct iwl_priv *priv) 267static void iwl_clear_free_frames(struct iwl_priv *priv)
@@ -341,6 +365,13 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
341 * beacon contents. 365 * beacon contents.
342 */ 366 */
343 367
368 lockdep_assert_held(&priv->mutex);
369
370 if (!priv->beacon_ctx) {
371 IWL_ERR(priv, "trying to build beacon w/o beacon context!\n");
372 return -EINVAL;
373 }
374
344 /* Initialize memory */ 375 /* Initialize memory */
345 tx_beacon_cmd = &frame->u.beacon; 376 tx_beacon_cmd = &frame->u.beacon;
346 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd)); 377 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
@@ -353,7 +384,7 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
353 384
354 /* Set up TX command fields */ 385 /* Set up TX command fields */
355 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size); 386 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
356 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id; 387 tx_beacon_cmd->tx.sta_id = priv->beacon_ctx->bcast_sta_id;
357 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 388 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
358 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK | 389 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
359 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK; 390 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK;
@@ -363,7 +394,7 @@ static unsigned int iwl_hw_get_beacon_cmd(struct iwl_priv *priv,
363 frame_size); 394 frame_size);
364 395
365 /* Set up packet rate and flags */ 396 /* Set up packet rate and flags */
366 rate = iwl_rate_get_lowest_plcp(priv); 397 rate = iwl_rate_get_lowest_plcp(priv, priv->beacon_ctx);
367 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 398 priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant,
368 priv->hw_params.valid_tx_ant); 399 priv->hw_params.valid_tx_ant);
369 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant); 400 rate_flags = iwl_ant_idx_to_flags(priv->mgmt_tx_ant);
@@ -596,23 +627,38 @@ static void iwl_bg_beacon_update(struct work_struct *work)
596 container_of(work, struct iwl_priv, beacon_update); 627 container_of(work, struct iwl_priv, beacon_update);
597 struct sk_buff *beacon; 628 struct sk_buff *beacon;
598 629
599 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 630 mutex_lock(&priv->mutex);
600 beacon = ieee80211_beacon_get(priv->hw, priv->vif); 631 if (!priv->beacon_ctx) {
632 IWL_ERR(priv, "updating beacon w/o beacon context!\n");
633 goto out;
634 }
635
636 if (priv->beacon_ctx->vif->type != NL80211_IFTYPE_AP) {
637 /*
638 * The ucode will send beacon notifications even in
639 * IBSS mode, but we don't want to process them. But
640 * we need to defer the type check to here due to
641 * requiring locking around the beacon_ctx access.
642 */
643 goto out;
644 }
601 645
646 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
647 beacon = ieee80211_beacon_get(priv->hw, priv->beacon_ctx->vif);
602 if (!beacon) { 648 if (!beacon) {
603 IWL_ERR(priv, "update beacon failed\n"); 649 IWL_ERR(priv, "update beacon failed\n");
604 return; 650 goto out;
605 } 651 }
606 652
607 mutex_lock(&priv->mutex);
608 /* new beacon skb is allocated every time; dispose previous.*/ 653 /* new beacon skb is allocated every time; dispose previous.*/
609 if (priv->ibss_beacon) 654 if (priv->ibss_beacon)
610 dev_kfree_skb(priv->ibss_beacon); 655 dev_kfree_skb(priv->ibss_beacon);
611 656
612 priv->ibss_beacon = beacon; 657 priv->ibss_beacon = beacon;
613 mutex_unlock(&priv->mutex);
614 658
615 iwl_send_beacon_cmd(priv); 659 iwl_send_beacon_cmd(priv);
660 out:
661 mutex_unlock(&priv->mutex);
616} 662}
617 663
618static void iwl_bg_bt_runtime_config(struct work_struct *work) 664static void iwl_bg_bt_runtime_config(struct work_struct *work)
@@ -633,6 +679,7 @@ static void iwl_bg_bt_full_concurrency(struct work_struct *work)
633{ 679{
634 struct iwl_priv *priv = 680 struct iwl_priv *priv =
635 container_of(work, struct iwl_priv, bt_full_concurrency); 681 container_of(work, struct iwl_priv, bt_full_concurrency);
682 struct iwl_rxon_context *ctx;
636 683
637 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 684 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
638 return; 685 return;
@@ -649,9 +696,13 @@ static void iwl_bg_bt_full_concurrency(struct work_struct *work)
649 * LQ & RXON updated cmds must be sent before BT Config cmd 696 * LQ & RXON updated cmds must be sent before BT Config cmd
650 * to avoid 3-wire collisions 697 * to avoid 3-wire collisions
651 */ 698 */
652 if (priv->cfg->ops->hcmd->set_rxon_chain) 699 mutex_lock(&priv->mutex);
653 priv->cfg->ops->hcmd->set_rxon_chain(priv); 700 for_each_context(priv, ctx) {
654 iwlcore_commit_rxon(priv); 701 if (priv->cfg->ops->hcmd->set_rxon_chain)
702 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
703 iwlcore_commit_rxon(priv, ctx);
704 }
705 mutex_unlock(&priv->mutex);
655 706
656 priv->cfg->ops->hcmd->send_bt_config(priv); 707 priv->cfg->ops->hcmd->send_bt_config(priv);
657} 708}
@@ -825,8 +876,7 @@ static void iwl_rx_beacon_notif(struct iwl_priv *priv,
825 876
826 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status); 877 priv->ibss_manager = le32_to_cpu(beacon->ibss_mgr_status);
827 878
828 if ((priv->iw_mode == NL80211_IFTYPE_AP) && 879 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
829 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
830 queue_work(priv->workqueue, &priv->beacon_update); 880 queue_work(priv->workqueue, &priv->beacon_update);
831} 881}
832 882
@@ -1697,6 +1747,7 @@ static void iwl_nic_start(struct iwl_priv *priv)
1697struct iwlagn_ucode_capabilities { 1747struct iwlagn_ucode_capabilities {
1698 u32 max_probe_length; 1748 u32 max_probe_length;
1699 u32 standard_phy_calibration_size; 1749 u32 standard_phy_calibration_size;
1750 bool pan;
1700}; 1751};
1701 1752
1702static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context); 1753static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context);
@@ -1934,6 +1985,11 @@ static int iwlagn_load_firmware(struct iwl_priv *priv,
1934 capa->max_probe_length = 1985 capa->max_probe_length =
1935 le32_to_cpup((__le32 *)tlv_data); 1986 le32_to_cpup((__le32 *)tlv_data);
1936 break; 1987 break;
1988 case IWL_UCODE_TLV_PAN:
1989 if (tlv_len)
1990 goto invalid_tlv_len;
1991 capa->pan = true;
1992 break;
1937 case IWL_UCODE_TLV_INIT_EVTLOG_PTR: 1993 case IWL_UCODE_TLV_INIT_EVTLOG_PTR:
1938 if (tlv_len != sizeof(u32)) 1994 if (tlv_len != sizeof(u32))
1939 goto invalid_tlv_len; 1995 goto invalid_tlv_len;
@@ -2209,6 +2265,12 @@ static void iwl_ucode_callback(const struct firmware *ucode_raw, void *context)
2209 priv->_agn.inst_evtlog_size = priv->cfg->max_event_log_size; 2265 priv->_agn.inst_evtlog_size = priv->cfg->max_event_log_size;
2210 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr; 2266 priv->_agn.inst_errlog_ptr = pieces.inst_errlog_ptr;
2211 2267
2268 if (ucode_capa.pan) {
2269 priv->valid_contexts |= BIT(IWL_RXON_CTX_PAN);
2270 priv->sta_key_max_num = STA_KEY_MAX_NUM_PAN;
2271 } else
2272 priv->sta_key_max_num = STA_KEY_MAX_NUM;
2273
2212 /* Copy images into buffers for card's bus-master reads ... */ 2274 /* Copy images into buffers for card's bus-master reads ... */
2213 2275
2214 /* Runtime instructions (first block of data in file) */ 2276 /* Runtime instructions (first block of data in file) */
@@ -2710,6 +2772,7 @@ static void iwl_rf_kill_ct_config(struct iwl_priv *priv)
2710static void iwl_alive_start(struct iwl_priv *priv) 2772static void iwl_alive_start(struct iwl_priv *priv)
2711{ 2773{
2712 int ret = 0; 2774 int ret = 0;
2775 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2713 2776
2714 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); 2777 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
2715 2778
@@ -2758,18 +2821,20 @@ static void iwl_alive_start(struct iwl_priv *priv)
2758 if (priv->cfg->ops->hcmd->set_tx_ant) 2821 if (priv->cfg->ops->hcmd->set_tx_ant)
2759 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant); 2822 priv->cfg->ops->hcmd->set_tx_ant(priv, priv->cfg->valid_tx_ant);
2760 2823
2761 if (iwl_is_associated(priv)) { 2824 if (iwl_is_associated_ctx(ctx)) {
2762 struct iwl_rxon_cmd *active_rxon = 2825 struct iwl_rxon_cmd *active_rxon =
2763 (struct iwl_rxon_cmd *)&priv->active_rxon; 2826 (struct iwl_rxon_cmd *)&ctx->active;
2764 /* apply any changes in staging */ 2827 /* apply any changes in staging */
2765 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2828 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
2766 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2829 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2767 } else { 2830 } else {
2831 struct iwl_rxon_context *tmp;
2768 /* Initialize our rx_config data */ 2832 /* Initialize our rx_config data */
2769 iwl_connection_init_rx_config(priv, NULL); 2833 for_each_context(priv, tmp)
2834 iwl_connection_init_rx_config(priv, tmp);
2770 2835
2771 if (priv->cfg->ops->hcmd->set_rxon_chain) 2836 if (priv->cfg->ops->hcmd->set_rxon_chain)
2772 priv->cfg->ops->hcmd->set_rxon_chain(priv); 2837 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
2773 } 2838 }
2774 2839
2775 if (!priv->cfg->advanced_bt_coexist) { 2840 if (!priv->cfg->advanced_bt_coexist) {
@@ -2780,7 +2845,7 @@ static void iwl_alive_start(struct iwl_priv *priv)
2780 iwl_reset_run_time_calib(priv); 2845 iwl_reset_run_time_calib(priv);
2781 2846
2782 /* Configure the adapter for unassociated operation */ 2847 /* Configure the adapter for unassociated operation */
2783 iwlcore_commit_rxon(priv); 2848 iwlcore_commit_rxon(priv, ctx);
2784 2849
2785 /* At this point, the NIC is initialized and operational */ 2850 /* At this point, the NIC is initialized and operational */
2786 iwl_rf_kill_ct_config(priv); 2851 iwl_rf_kill_ct_config(priv);
@@ -2818,8 +2883,8 @@ static void __iwl_down(struct iwl_priv *priv)
2818 if (priv->cfg->ops->lib->recover_from_tx_stall) 2883 if (priv->cfg->ops->lib->recover_from_tx_stall)
2819 del_timer_sync(&priv->monitor_recover); 2884 del_timer_sync(&priv->monitor_recover);
2820 2885
2821 iwl_clear_ucode_stations(priv); 2886 iwl_clear_ucode_stations(priv, NULL);
2822 iwl_dealloc_bcast_station(priv); 2887 iwl_dealloc_bcast_stations(priv);
2823 iwl_clear_driver_stations(priv); 2888 iwl_clear_driver_stations(priv);
2824 2889
2825 /* reset BT coex data */ 2890 /* reset BT coex data */
@@ -2961,6 +3026,7 @@ static int iwl_prepare_card_hw(struct iwl_priv *priv)
2961 3026
2962static int __iwl_up(struct iwl_priv *priv) 3027static int __iwl_up(struct iwl_priv *priv)
2963{ 3028{
3029 struct iwl_rxon_context *ctx;
2964 int i; 3030 int i;
2965 int ret; 3031 int ret;
2966 3032
@@ -2974,9 +3040,13 @@ static int __iwl_up(struct iwl_priv *priv)
2974 return -EIO; 3040 return -EIO;
2975 } 3041 }
2976 3042
2977 ret = iwl_alloc_bcast_station(priv, true); 3043 for_each_context(priv, ctx) {
2978 if (ret) 3044 ret = iwl_alloc_bcast_station(priv, ctx, true);
2979 return ret; 3045 if (ret) {
3046 iwl_dealloc_bcast_stations(priv);
3047 return ret;
3048 }
3049 }
2980 3050
2981 iwl_prepare_card_hw(priv); 3051 iwl_prepare_card_hw(priv);
2982 3052
@@ -3001,6 +3071,12 @@ static int __iwl_up(struct iwl_priv *priv)
3001 3071
3002 iwl_write32(priv, CSR_INT, 0xFFFFFFFF); 3072 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
3003 3073
3074 /* must be initialised before iwl_hw_nic_init */
3075 if (priv->valid_contexts != BIT(IWL_RXON_CTX_BSS))
3076 priv->cmd_queue = IWL_IPAN_CMD_QUEUE_NUM;
3077 else
3078 priv->cmd_queue = IWL_DEFAULT_CMD_QUEUE_NUM;
3079
3004 ret = iwlagn_hw_nic_init(priv); 3080 ret = iwlagn_hw_nic_init(priv);
3005 if (ret) { 3081 if (ret) {
3006 IWL_ERR(priv, "Unable to init nic\n"); 3082 IWL_ERR(priv, "Unable to init nic\n");
@@ -3131,13 +3207,15 @@ static void iwl_bg_restart(struct work_struct *data)
3131 return; 3207 return;
3132 3208
3133 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { 3209 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
3210 struct iwl_rxon_context *ctx;
3134 bool bt_sco, bt_full_concurrent; 3211 bool bt_sco, bt_full_concurrent;
3135 u8 bt_ci_compliance; 3212 u8 bt_ci_compliance;
3136 u8 bt_load; 3213 u8 bt_load;
3137 u8 bt_status; 3214 u8 bt_status;
3138 3215
3139 mutex_lock(&priv->mutex); 3216 mutex_lock(&priv->mutex);
3140 priv->vif = NULL; 3217 for_each_context(priv, ctx)
3218 ctx->vif = NULL;
3141 priv->is_open = 0; 3219 priv->is_open = 0;
3142 3220
3143 /* 3221 /*
@@ -3195,12 +3273,15 @@ static void iwl_bg_rx_replenish(struct work_struct *data)
3195 3273
3196void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif) 3274void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3197{ 3275{
3276 struct iwl_rxon_context *ctx;
3198 struct ieee80211_conf *conf = NULL; 3277 struct ieee80211_conf *conf = NULL;
3199 int ret = 0; 3278 int ret = 0;
3200 3279
3201 if (!vif || !priv->is_open) 3280 if (!vif || !priv->is_open)
3202 return; 3281 return;
3203 3282
3283 ctx = iwl_rxon_ctx_from_vif(vif);
3284
3204 if (vif->type == NL80211_IFTYPE_AP) { 3285 if (vif->type == NL80211_IFTYPE_AP) {
3205 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__); 3286 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
3206 return; 3287 return;
@@ -3213,42 +3294,42 @@ void iwl_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3213 3294
3214 conf = ieee80211_get_hw_conf(priv->hw); 3295 conf = ieee80211_get_hw_conf(priv->hw);
3215 3296
3216 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3297 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3217 iwlcore_commit_rxon(priv); 3298 iwlcore_commit_rxon(priv, ctx);
3218 3299
3219 ret = iwl_send_rxon_timing(priv, vif); 3300 ret = iwl_send_rxon_timing(priv, ctx);
3220 if (ret) 3301 if (ret)
3221 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3302 IWL_WARN(priv, "RXON timing - "
3222 "Attempting to continue.\n"); 3303 "Attempting to continue.\n");
3223 3304
3224 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3305 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3225 3306
3226 iwl_set_rxon_ht(priv, &priv->current_ht_config); 3307 iwl_set_rxon_ht(priv, &priv->current_ht_config);
3227 3308
3228 if (priv->cfg->ops->hcmd->set_rxon_chain) 3309 if (priv->cfg->ops->hcmd->set_rxon_chain)
3229 priv->cfg->ops->hcmd->set_rxon_chain(priv); 3310 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
3230 3311
3231 priv->staging_rxon.assoc_id = cpu_to_le16(vif->bss_conf.aid); 3312 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
3232 3313
3233 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", 3314 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
3234 vif->bss_conf.aid, vif->bss_conf.beacon_int); 3315 vif->bss_conf.aid, vif->bss_conf.beacon_int);
3235 3316
3236 if (vif->bss_conf.use_short_preamble) 3317 if (vif->bss_conf.use_short_preamble)
3237 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 3318 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3238 else 3319 else
3239 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; 3320 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3240 3321
3241 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { 3322 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
3242 if (vif->bss_conf.use_short_slot) 3323 if (vif->bss_conf.use_short_slot)
3243 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 3324 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
3244 else 3325 else
3245 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 3326 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3246 } 3327 }
3247 3328
3248 iwlcore_commit_rxon(priv); 3329 iwlcore_commit_rxon(priv, ctx);
3249 3330
3250 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n", 3331 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
3251 vif->bss_conf.aid, priv->active_rxon.bssid_addr); 3332 vif->bss_conf.aid, ctx->active.bssid_addr);
3252 3333
3253 switch (vif->type) { 3334 switch (vif->type) {
3254 case NL80211_IFTYPE_STATION: 3335 case NL80211_IFTYPE_STATION:
@@ -3291,11 +3372,14 @@ static int iwl_mac_setup_register(struct iwl_priv *priv,
3291{ 3372{
3292 int ret; 3373 int ret;
3293 struct ieee80211_hw *hw = priv->hw; 3374 struct ieee80211_hw *hw = priv->hw;
3375 struct iwl_rxon_context *ctx;
3376
3294 hw->rate_control_algorithm = "iwl-agn-rs"; 3377 hw->rate_control_algorithm = "iwl-agn-rs";
3295 3378
3296 /* Tell mac80211 our characteristics */ 3379 /* Tell mac80211 our characteristics */
3297 hw->flags = IEEE80211_HW_SIGNAL_DBM | 3380 hw->flags = IEEE80211_HW_SIGNAL_DBM |
3298 IEEE80211_HW_AMPDU_AGGREGATION | 3381 IEEE80211_HW_AMPDU_AGGREGATION |
3382 IEEE80211_HW_NEED_DTIM_PERIOD |
3299 IEEE80211_HW_SPECTRUM_MGMT; 3383 IEEE80211_HW_SPECTRUM_MGMT;
3300 3384
3301 if (!priv->cfg->broken_powersave) 3385 if (!priv->cfg->broken_powersave)
@@ -3309,9 +3393,10 @@ static int iwl_mac_setup_register(struct iwl_priv *priv,
3309 hw->sta_data_size = sizeof(struct iwl_station_priv); 3393 hw->sta_data_size = sizeof(struct iwl_station_priv);
3310 hw->vif_data_size = sizeof(struct iwl_vif_priv); 3394 hw->vif_data_size = sizeof(struct iwl_vif_priv);
3311 3395
3312 hw->wiphy->interface_modes = 3396 for_each_context(priv, ctx) {
3313 BIT(NL80211_IFTYPE_STATION) | 3397 hw->wiphy->interface_modes |= ctx->interface_modes;
3314 BIT(NL80211_IFTYPE_ADHOC); 3398 hw->wiphy->interface_modes |= ctx->exclusive_interface_modes;
3399 }
3315 3400
3316 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | 3401 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
3317 WIPHY_FLAG_DISABLE_BEACON_HINTS; 3402 WIPHY_FLAG_DISABLE_BEACON_HINTS;
@@ -3439,22 +3524,25 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3439 3524
3440void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif) 3525void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
3441{ 3526{
3527 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
3442 int ret = 0; 3528 int ret = 0;
3443 3529
3530 lockdep_assert_held(&priv->mutex);
3531
3444 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3532 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3445 return; 3533 return;
3446 3534
3447 /* The following should be done only at AP bring up */ 3535 /* The following should be done only at AP bring up */
3448 if (!iwl_is_associated(priv)) { 3536 if (!iwl_is_associated_ctx(ctx)) {
3449 3537
3450 /* RXON - unassoc (to set timing command) */ 3538 /* RXON - unassoc (to set timing command) */
3451 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3539 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3452 iwlcore_commit_rxon(priv); 3540 iwlcore_commit_rxon(priv, ctx);
3453 3541
3454 /* RXON Timing */ 3542 /* RXON Timing */
3455 ret = iwl_send_rxon_timing(priv, vif); 3543 ret = iwl_send_rxon_timing(priv, ctx);
3456 if (ret) 3544 if (ret)
3457 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3545 IWL_WARN(priv, "RXON timing failed - "
3458 "Attempting to continue.\n"); 3546 "Attempting to continue.\n");
3459 3547
3460 /* AP has all antennas */ 3548 /* AP has all antennas */
@@ -3462,28 +3550,30 @@ void iwl_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
3462 priv->hw_params.valid_rx_ant; 3550 priv->hw_params.valid_rx_ant;
3463 iwl_set_rxon_ht(priv, &priv->current_ht_config); 3551 iwl_set_rxon_ht(priv, &priv->current_ht_config);
3464 if (priv->cfg->ops->hcmd->set_rxon_chain) 3552 if (priv->cfg->ops->hcmd->set_rxon_chain)
3465 priv->cfg->ops->hcmd->set_rxon_chain(priv); 3553 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
3466 3554
3467 priv->staging_rxon.assoc_id = 0; 3555 ctx->staging.assoc_id = 0;
3468 3556
3469 if (vif->bss_conf.use_short_preamble) 3557 if (vif->bss_conf.use_short_preamble)
3470 priv->staging_rxon.flags |= 3558 ctx->staging.flags |=
3471 RXON_FLG_SHORT_PREAMBLE_MSK; 3559 RXON_FLG_SHORT_PREAMBLE_MSK;
3472 else 3560 else
3473 priv->staging_rxon.flags &= 3561 ctx->staging.flags &=
3474 ~RXON_FLG_SHORT_PREAMBLE_MSK; 3562 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3475 3563
3476 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { 3564 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
3477 if (vif->bss_conf.use_short_slot) 3565 if (vif->bss_conf.use_short_slot)
3478 priv->staging_rxon.flags |= 3566 ctx->staging.flags |=
3479 RXON_FLG_SHORT_SLOT_MSK; 3567 RXON_FLG_SHORT_SLOT_MSK;
3480 else 3568 else
3481 priv->staging_rxon.flags &= 3569 ctx->staging.flags &=
3482 ~RXON_FLG_SHORT_SLOT_MSK; 3570 ~RXON_FLG_SHORT_SLOT_MSK;
3483 } 3571 }
3572 /* need to send beacon cmd before committing assoc RXON! */
3573 iwl_send_beacon_cmd(priv);
3484 /* restore RXON assoc */ 3574 /* restore RXON assoc */
3485 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3575 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3486 iwlcore_commit_rxon(priv); 3576 iwlcore_commit_rxon(priv, ctx);
3487 } 3577 }
3488 iwl_send_beacon_cmd(priv); 3578 iwl_send_beacon_cmd(priv);
3489 3579
@@ -3500,9 +3590,11 @@ static void iwl_mac_update_tkip_key(struct ieee80211_hw *hw,
3500{ 3590{
3501 3591
3502 struct iwl_priv *priv = hw->priv; 3592 struct iwl_priv *priv = hw->priv;
3593 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
3594
3503 IWL_DEBUG_MAC80211(priv, "enter\n"); 3595 IWL_DEBUG_MAC80211(priv, "enter\n");
3504 3596
3505 iwl_update_tkip_key(priv, keyconf, sta, 3597 iwl_update_tkip_key(priv, vif_priv->ctx, keyconf, sta,
3506 iv32, phase1key); 3598 iv32, phase1key);
3507 3599
3508 IWL_DEBUG_MAC80211(priv, "leave\n"); 3600 IWL_DEBUG_MAC80211(priv, "leave\n");
@@ -3514,6 +3606,8 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3514 struct ieee80211_key_conf *key) 3606 struct ieee80211_key_conf *key)
3515{ 3607{
3516 struct iwl_priv *priv = hw->priv; 3608 struct iwl_priv *priv = hw->priv;
3609 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
3610 struct iwl_rxon_context *ctx = vif_priv->ctx;
3517 int ret; 3611 int ret;
3518 u8 sta_id; 3612 u8 sta_id;
3519 bool is_default_wep_key = false; 3613 bool is_default_wep_key = false;
@@ -3525,7 +3619,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3525 return -EOPNOTSUPP; 3619 return -EOPNOTSUPP;
3526 } 3620 }
3527 3621
3528 sta_id = iwl_sta_id_or_broadcast(priv, sta); 3622 sta_id = iwl_sta_id_or_broadcast(priv, vif_priv->ctx, sta);
3529 if (sta_id == IWL_INVALID_STATION) 3623 if (sta_id == IWL_INVALID_STATION)
3530 return -EINVAL; 3624 return -EINVAL;
3531 3625
@@ -3542,7 +3636,7 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3542 key->cipher == WLAN_CIPHER_SUITE_WEP104) && 3636 key->cipher == WLAN_CIPHER_SUITE_WEP104) &&
3543 !sta) { 3637 !sta) {
3544 if (cmd == SET_KEY) 3638 if (cmd == SET_KEY)
3545 is_default_wep_key = !priv->key_mapping_key; 3639 is_default_wep_key = !ctx->key_mapping_keys;
3546 else 3640 else
3547 is_default_wep_key = 3641 is_default_wep_key =
3548 (key->hw_key_idx == HW_KEY_DEFAULT); 3642 (key->hw_key_idx == HW_KEY_DEFAULT);
@@ -3551,17 +3645,18 @@ static int iwl_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3551 switch (cmd) { 3645 switch (cmd) {
3552 case SET_KEY: 3646 case SET_KEY:
3553 if (is_default_wep_key) 3647 if (is_default_wep_key)
3554 ret = iwl_set_default_wep_key(priv, key); 3648 ret = iwl_set_default_wep_key(priv, vif_priv->ctx, key);
3555 else 3649 else
3556 ret = iwl_set_dynamic_key(priv, key, sta_id); 3650 ret = iwl_set_dynamic_key(priv, vif_priv->ctx,
3651 key, sta_id);
3557 3652
3558 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n"); 3653 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
3559 break; 3654 break;
3560 case DISABLE_KEY: 3655 case DISABLE_KEY:
3561 if (is_default_wep_key) 3656 if (is_default_wep_key)
3562 ret = iwl_remove_default_wep_key(priv, key); 3657 ret = iwl_remove_default_wep_key(priv, ctx, key);
3563 else 3658 else
3564 ret = iwl_remove_dynamic_key(priv, key, sta_id); 3659 ret = iwl_remove_dynamic_key(priv, ctx, key, sta_id);
3565 3660
3566 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n"); 3661 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
3567 break; 3662 break;
@@ -3630,8 +3725,8 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3630 3725
3631 sta_priv->lq_sta.lq.general_params.flags &= 3726 sta_priv->lq_sta.lq.general_params.flags &=
3632 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; 3727 ~LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3633 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq, 3728 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
3634 CMD_ASYNC, false); 3729 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
3635 } 3730 }
3636 break; 3731 break;
3637 case IEEE80211_AMPDU_TX_OPERATIONAL: 3732 case IEEE80211_AMPDU_TX_OPERATIONAL:
@@ -3646,8 +3741,8 @@ static int iwl_mac_ampdu_action(struct ieee80211_hw *hw,
3646 3741
3647 sta_priv->lq_sta.lq.general_params.flags |= 3742 sta_priv->lq_sta.lq.general_params.flags |=
3648 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; 3743 LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK;
3649 iwl_send_lq_cmd(priv, &sta_priv->lq_sta.lq, 3744 iwl_send_lq_cmd(priv, iwl_rxon_ctx_from_vif(vif),
3650 CMD_ASYNC, false); 3745 &sta_priv->lq_sta.lq, CMD_ASYNC, false);
3651 } 3746 }
3652 ret = 0; 3747 ret = 0;
3653 break; 3748 break;
@@ -3693,6 +3788,7 @@ static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
3693{ 3788{
3694 struct iwl_priv *priv = hw->priv; 3789 struct iwl_priv *priv = hw->priv;
3695 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; 3790 struct iwl_station_priv *sta_priv = (void *)sta->drv_priv;
3791 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
3696 bool is_ap = vif->type == NL80211_IFTYPE_STATION; 3792 bool is_ap = vif->type == NL80211_IFTYPE_STATION;
3697 int ret; 3793 int ret;
3698 u8 sta_id; 3794 u8 sta_id;
@@ -3708,8 +3804,8 @@ static int iwlagn_mac_sta_add(struct ieee80211_hw *hw,
3708 if (vif->type == NL80211_IFTYPE_AP) 3804 if (vif->type == NL80211_IFTYPE_AP)
3709 sta_priv->client = true; 3805 sta_priv->client = true;
3710 3806
3711 ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap, 3807 ret = iwl_add_station_common(priv, vif_priv->ctx, sta->addr,
3712 &sta_id); 3808 is_ap, sta, &sta_id);
3713 if (ret) { 3809 if (ret) {
3714 IWL_ERR(priv, "Unable to add station %pM (%d)\n", 3810 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3715 sta->addr, ret); 3811 sta->addr, ret);
@@ -3737,6 +3833,15 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3737 struct ieee80211_conf *conf = &hw->conf; 3833 struct ieee80211_conf *conf = &hw->conf;
3738 struct ieee80211_channel *channel = ch_switch->channel; 3834 struct ieee80211_channel *channel = ch_switch->channel;
3739 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 3835 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
3836 /*
3837 * MULTI-FIXME
3838 * When we add support for multiple interfaces, we need to
3839 * revisit this. The channel switch command in the device
3840 * only affects the BSS context, but what does that really
3841 * mean? And what if we get a CSA on the second interface?
3842 * This needs a lot of work.
3843 */
3844 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3740 u16 ch; 3845 u16 ch;
3741 unsigned long flags = 0; 3846 unsigned long flags = 0;
3742 3847
@@ -3749,7 +3854,7 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3749 test_bit(STATUS_SCANNING, &priv->status)) 3854 test_bit(STATUS_SCANNING, &priv->status))
3750 goto out_exit; 3855 goto out_exit;
3751 3856
3752 if (!iwl_is_associated(priv)) 3857 if (!iwl_is_associated_ctx(ctx))
3753 goto out_exit; 3858 goto out_exit;
3754 3859
3755 /* channel switch in progress */ 3860 /* channel switch in progress */
@@ -3760,7 +3865,7 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3760 if (priv->cfg->ops->lib->set_channel_switch) { 3865 if (priv->cfg->ops->lib->set_channel_switch) {
3761 3866
3762 ch = channel->hw_value; 3867 ch = channel->hw_value;
3763 if (le16_to_cpu(priv->active_rxon.channel) != ch) { 3868 if (le16_to_cpu(ctx->active.channel) != ch) {
3764 ch_info = iwl_get_channel_info(priv, 3869 ch_info = iwl_get_channel_info(priv,
3765 channel->band, 3870 channel->band,
3766 ch); 3871 ch);
@@ -3773,31 +3878,31 @@ static void iwl_mac_channel_switch(struct ieee80211_hw *hw,
3773 priv->current_ht_config.smps = conf->smps_mode; 3878 priv->current_ht_config.smps = conf->smps_mode;
3774 3879
3775 /* Configure HT40 channels */ 3880 /* Configure HT40 channels */
3776 ht_conf->is_ht = conf_is_ht(conf); 3881 ctx->ht.enabled = conf_is_ht(conf);
3777 if (ht_conf->is_ht) { 3882 if (ctx->ht.enabled) {
3778 if (conf_is_ht40_minus(conf)) { 3883 if (conf_is_ht40_minus(conf)) {
3779 ht_conf->extension_chan_offset = 3884 ctx->ht.extension_chan_offset =
3780 IEEE80211_HT_PARAM_CHA_SEC_BELOW; 3885 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
3781 ht_conf->is_40mhz = true; 3886 ctx->ht.is_40mhz = true;
3782 } else if (conf_is_ht40_plus(conf)) { 3887 } else if (conf_is_ht40_plus(conf)) {
3783 ht_conf->extension_chan_offset = 3888 ctx->ht.extension_chan_offset =
3784 IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 3889 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
3785 ht_conf->is_40mhz = true; 3890 ctx->ht.is_40mhz = true;
3786 } else { 3891 } else {
3787 ht_conf->extension_chan_offset = 3892 ctx->ht.extension_chan_offset =
3788 IEEE80211_HT_PARAM_CHA_SEC_NONE; 3893 IEEE80211_HT_PARAM_CHA_SEC_NONE;
3789 ht_conf->is_40mhz = false; 3894 ctx->ht.is_40mhz = false;
3790 } 3895 }
3791 } else 3896 } else
3792 ht_conf->is_40mhz = false; 3897 ctx->ht.is_40mhz = false;
3793 3898
3794 if (le16_to_cpu(priv->staging_rxon.channel) != ch) 3899 if ((le16_to_cpu(ctx->staging.channel) != ch))
3795 priv->staging_rxon.flags = 0; 3900 ctx->staging.flags = 0;
3796 3901
3797 iwl_set_rxon_channel(priv, channel); 3902 iwl_set_rxon_channel(priv, channel, ctx);
3798 iwl_set_rxon_ht(priv, ht_conf); 3903 iwl_set_rxon_ht(priv, ht_conf);
3799 iwl_set_flags_for_band(priv, channel->band, 3904 iwl_set_flags_for_band(priv, ctx, channel->band,
3800 priv->vif); 3905 ctx->vif);
3801 spin_unlock_irqrestore(&priv->lock, flags); 3906 spin_unlock_irqrestore(&priv->lock, flags);
3802 3907
3803 iwl_set_rate(priv); 3908 iwl_set_rate(priv);
@@ -3814,7 +3919,7 @@ out:
3814 mutex_unlock(&priv->mutex); 3919 mutex_unlock(&priv->mutex);
3815out_exit: 3920out_exit:
3816 if (!priv->switch_rxon.switch_in_progress) 3921 if (!priv->switch_rxon.switch_in_progress)
3817 ieee80211_chswitch_done(priv->vif, false); 3922 ieee80211_chswitch_done(ctx->vif, false);
3818 IWL_DEBUG_MAC80211(priv, "leave\n"); 3923 IWL_DEBUG_MAC80211(priv, "leave\n");
3819} 3924}
3820 3925
@@ -3825,6 +3930,7 @@ static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3825{ 3930{
3826 struct iwl_priv *priv = hw->priv; 3931 struct iwl_priv *priv = hw->priv;
3827 __le32 filter_or = 0, filter_nand = 0; 3932 __le32 filter_or = 0, filter_nand = 0;
3933 struct iwl_rxon_context *ctx;
3828 3934
3829#define CHK(test, flag) do { \ 3935#define CHK(test, flag) do { \
3830 if (*total_flags & (test)) \ 3936 if (*total_flags & (test)) \
@@ -3844,10 +3950,11 @@ static void iwlagn_configure_filter(struct ieee80211_hw *hw,
3844 3950
3845 mutex_lock(&priv->mutex); 3951 mutex_lock(&priv->mutex);
3846 3952
3847 priv->staging_rxon.filter_flags &= ~filter_nand; 3953 for_each_context(priv, ctx) {
3848 priv->staging_rxon.filter_flags |= filter_or; 3954 ctx->staging.filter_flags &= ~filter_nand;
3849 3955 ctx->staging.filter_flags |= filter_or;
3850 iwlcore_commit_rxon(priv); 3956 iwlcore_commit_rxon(priv, ctx);
3957 }
3851 3958
3852 mutex_unlock(&priv->mutex); 3959 mutex_unlock(&priv->mutex);
3853 3960
@@ -4018,7 +4125,8 @@ static int iwl_init_drv(struct iwl_priv *priv)
4018 4125
4019 /* Choose which receivers/antennas to use */ 4126 /* Choose which receivers/antennas to use */
4020 if (priv->cfg->ops->hcmd->set_rxon_chain) 4127 if (priv->cfg->ops->hcmd->set_rxon_chain)
4021 priv->cfg->ops->hcmd->set_rxon_chain(priv); 4128 priv->cfg->ops->hcmd->set_rxon_chain(priv,
4129 &priv->contexts[IWL_RXON_CTX_BSS]);
4022 4130
4023 iwl_init_scan_params(priv); 4131 iwl_init_scan_params(priv);
4024 4132
@@ -4116,9 +4224,31 @@ static int iwl_set_hw_params(struct iwl_priv *priv)
4116 return priv->cfg->ops->lib->set_hw_params(priv); 4224 return priv->cfg->ops->lib->set_hw_params(priv);
4117} 4225}
4118 4226
4227static const u8 iwlagn_bss_ac_to_fifo[] = {
4228 IWL_TX_FIFO_VO,
4229 IWL_TX_FIFO_VI,
4230 IWL_TX_FIFO_BE,
4231 IWL_TX_FIFO_BK,
4232};
4233
4234static const u8 iwlagn_bss_ac_to_queue[] = {
4235 0, 1, 2, 3,
4236};
4237
4238static const u8 iwlagn_pan_ac_to_fifo[] = {
4239 IWL_TX_FIFO_VO_IPAN,
4240 IWL_TX_FIFO_VI_IPAN,
4241 IWL_TX_FIFO_BE_IPAN,
4242 IWL_TX_FIFO_BK_IPAN,
4243};
4244
4245static const u8 iwlagn_pan_ac_to_queue[] = {
4246 7, 6, 5, 4,
4247};
4248
4119static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 4249static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4120{ 4250{
4121 int err = 0; 4251 int err = 0, i;
4122 struct iwl_priv *priv; 4252 struct iwl_priv *priv;
4123 struct ieee80211_hw *hw; 4253 struct ieee80211_hw *hw;
4124 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); 4254 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
@@ -4146,6 +4276,51 @@ static int iwl_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
4146 priv = hw->priv; 4276 priv = hw->priv;
4147 /* At this point both hw and priv are allocated. */ 4277 /* At this point both hw and priv are allocated. */
4148 4278
4279 /*
4280 * The default context is always valid,
4281 * more may be discovered when firmware
4282 * is loaded.
4283 */
4284 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
4285
4286 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
4287 priv->contexts[i].ctxid = i;
4288
4289 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
4290 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
4291 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
4292 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
4293 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
4294 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
4295 priv->contexts[IWL_RXON_CTX_BSS].ac_to_fifo = iwlagn_bss_ac_to_fifo;
4296 priv->contexts[IWL_RXON_CTX_BSS].ac_to_queue = iwlagn_bss_ac_to_queue;
4297 priv->contexts[IWL_RXON_CTX_BSS].exclusive_interface_modes =
4298 BIT(NL80211_IFTYPE_ADHOC);
4299 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
4300 BIT(NL80211_IFTYPE_STATION);
4301 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
4302 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
4303 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
4304
4305 priv->contexts[IWL_RXON_CTX_PAN].rxon_cmd = REPLY_WIPAN_RXON;
4306 priv->contexts[IWL_RXON_CTX_PAN].rxon_timing_cmd = REPLY_WIPAN_RXON_TIMING;
4307 priv->contexts[IWL_RXON_CTX_PAN].rxon_assoc_cmd = REPLY_WIPAN_RXON_ASSOC;
4308 priv->contexts[IWL_RXON_CTX_PAN].qos_cmd = REPLY_WIPAN_QOS_PARAM;
4309 priv->contexts[IWL_RXON_CTX_PAN].ap_sta_id = IWL_AP_ID_PAN;
4310 priv->contexts[IWL_RXON_CTX_PAN].wep_key_cmd = REPLY_WIPAN_WEPKEY;
4311 priv->contexts[IWL_RXON_CTX_PAN].bcast_sta_id = IWLAGN_PAN_BCAST_ID;
4312 priv->contexts[IWL_RXON_CTX_PAN].station_flags = STA_FLG_PAN_STATION;
4313 priv->contexts[IWL_RXON_CTX_PAN].ac_to_fifo = iwlagn_pan_ac_to_fifo;
4314 priv->contexts[IWL_RXON_CTX_PAN].ac_to_queue = iwlagn_pan_ac_to_queue;
4315 priv->contexts[IWL_RXON_CTX_PAN].mcast_queue = IWL_IPAN_MCAST_QUEUE;
4316 priv->contexts[IWL_RXON_CTX_PAN].interface_modes =
4317 BIT(NL80211_IFTYPE_STATION) | BIT(NL80211_IFTYPE_AP);
4318 priv->contexts[IWL_RXON_CTX_PAN].ap_devtype = RXON_DEV_TYPE_CP;
4319 priv->contexts[IWL_RXON_CTX_PAN].station_devtype = RXON_DEV_TYPE_2STA;
4320 priv->contexts[IWL_RXON_CTX_PAN].unused_devtype = RXON_DEV_TYPE_P2P;
4321
4322 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
4323
4149 SET_IEEE80211_DEV(hw, &pdev->dev); 4324 SET_IEEE80211_DEV(hw, &pdev->dev);
4150 4325
4151 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n"); 4326 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h
index 1a7f70f293a..7c542a8c8f8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-agn.h
+++ b/drivers/net/wireless/iwlwifi/iwl-agn.h
@@ -224,7 +224,8 @@ int iwlagn_manage_ibss_station(struct iwl_priv *priv,
224 struct ieee80211_vif *vif, bool add); 224 struct ieee80211_vif *vif, bool add);
225 225
226/* hcmd */ 226/* hcmd */
227int iwlagn_send_rxon_assoc(struct iwl_priv *priv); 227int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
228 struct iwl_rxon_context *ctx);
228int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant); 229int iwlagn_send_tx_ant_config(struct iwl_priv *priv, u8 valid_tx_ant);
229 230
230/* bt coex */ 231/* bt coex */
diff --git a/drivers/net/wireless/iwlwifi/iwl-commands.h b/drivers/net/wireless/iwlwifi/iwl-commands.h
index 9b535832f11..3e4ba31b5d5 100644
--- a/drivers/net/wireless/iwlwifi/iwl-commands.h
+++ b/drivers/net/wireless/iwlwifi/iwl-commands.h
@@ -180,6 +180,16 @@ enum {
180 REPLY_BT_COEX_PROFILE_NOTIF = 0xce, 180 REPLY_BT_COEX_PROFILE_NOTIF = 0xce,
181 REPLY_BT_COEX_SCO = 0xcf, 181 REPLY_BT_COEX_SCO = 0xcf,
182 182
183 /* PAN commands */
184 REPLY_WIPAN_PARAMS = 0xb2,
185 REPLY_WIPAN_RXON = 0xb3, /* use REPLY_RXON structure */
186 REPLY_WIPAN_RXON_TIMING = 0xb4, /* use REPLY_RXON_TIMING structure */
187 REPLY_WIPAN_RXON_ASSOC = 0xb6, /* use REPLY_RXON_ASSOC structure */
188 REPLY_WIPAN_QOS_PARAM = 0xb7, /* use REPLY_QOS_PARAM structure */
189 REPLY_WIPAN_WEPKEY = 0xb8, /* use REPLY_WEPKEY structure */
190 REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9,
191 REPLY_WIPAN_NOA_NOTIFICATION = 0xbc,
192
183 REPLY_MAX = 0xff 193 REPLY_MAX = 0xff
184}; 194};
185 195
@@ -607,6 +617,9 @@ enum {
607 RXON_DEV_TYPE_ESS = 3, 617 RXON_DEV_TYPE_ESS = 3,
608 RXON_DEV_TYPE_IBSS = 4, 618 RXON_DEV_TYPE_IBSS = 4,
609 RXON_DEV_TYPE_SNIFFER = 6, 619 RXON_DEV_TYPE_SNIFFER = 6,
620 RXON_DEV_TYPE_CP = 7,
621 RXON_DEV_TYPE_2STA = 8,
622 RXON_DEV_TYPE_P2P = 9,
610}; 623};
611 624
612 625
@@ -823,7 +836,8 @@ struct iwl_rxon_time_cmd {
823 __le16 atim_window; 836 __le16 atim_window;
824 __le32 beacon_init_val; 837 __le32 beacon_init_val;
825 __le16 listen_interval; 838 __le16 listen_interval;
826 __le16 reserved; 839 u8 dtim_period;
840 u8 delta_cp_bss_tbtts;
827} __packed; 841} __packed;
828 842
829/* 843/*
@@ -960,11 +974,13 @@ struct iwl_qosparam_cmd {
960 974
961/* Special, dedicated locations within device's station table */ 975/* Special, dedicated locations within device's station table */
962#define IWL_AP_ID 0 976#define IWL_AP_ID 0
977#define IWL_AP_ID_PAN 1
963#define IWL_STA_ID 2 978#define IWL_STA_ID 2
964#define IWL3945_BROADCAST_ID 24 979#define IWL3945_BROADCAST_ID 24
965#define IWL3945_STATION_COUNT 25 980#define IWL3945_STATION_COUNT 25
966#define IWL4965_BROADCAST_ID 31 981#define IWL4965_BROADCAST_ID 31
967#define IWL4965_STATION_COUNT 32 982#define IWL4965_STATION_COUNT 32
983#define IWLAGN_PAN_BCAST_ID 14
968#define IWLAGN_BROADCAST_ID 15 984#define IWLAGN_BROADCAST_ID 15
969#define IWLAGN_STATION_COUNT 16 985#define IWLAGN_STATION_COUNT 16
970 986
@@ -973,6 +989,7 @@ struct iwl_qosparam_cmd {
973 989
974#define STA_FLG_TX_RATE_MSK cpu_to_le32(1 << 2) 990#define STA_FLG_TX_RATE_MSK cpu_to_le32(1 << 2)
975#define STA_FLG_PWR_SAVE_MSK cpu_to_le32(1 << 8) 991#define STA_FLG_PWR_SAVE_MSK cpu_to_le32(1 << 8)
992#define STA_FLG_PAN_STATION cpu_to_le32(1 << 13)
976#define STA_FLG_RTS_MIMO_PROT_MSK cpu_to_le32(1 << 17) 993#define STA_FLG_RTS_MIMO_PROT_MSK cpu_to_le32(1 << 17)
977#define STA_FLG_AGG_MPDU_8US_MSK cpu_to_le32(1 << 18) 994#define STA_FLG_AGG_MPDU_8US_MSK cpu_to_le32(1 << 18)
978#define STA_FLG_MAX_AGG_SIZE_POS (19) 995#define STA_FLG_MAX_AGG_SIZE_POS (19)
@@ -1001,6 +1018,7 @@ struct iwl_qosparam_cmd {
1001#define STA_KEY_FLG_KEY_SIZE_MSK cpu_to_le16(0x1000) 1018#define STA_KEY_FLG_KEY_SIZE_MSK cpu_to_le16(0x1000)
1002#define STA_KEY_MULTICAST_MSK cpu_to_le16(0x4000) 1019#define STA_KEY_MULTICAST_MSK cpu_to_le16(0x4000)
1003#define STA_KEY_MAX_NUM 8 1020#define STA_KEY_MAX_NUM 8
1021#define STA_KEY_MAX_NUM_PAN 16
1004 1022
1005/* Flags indicate whether to modify vs. don't change various station params */ 1023/* Flags indicate whether to modify vs. don't change various station params */
1006#define STA_MODIFY_KEY_MASK 0x01 1024#define STA_MODIFY_KEY_MASK 0x01
@@ -4308,4 +4326,94 @@ struct iwl_rx_packet {
4308 4326
4309int iwl_agn_check_rxon_cmd(struct iwl_priv *priv); 4327int iwl_agn_check_rxon_cmd(struct iwl_priv *priv);
4310 4328
4329/*
4330 * REPLY_WIPAN_PARAMS = 0xb2 (Commands and Notification)
4331 */
4332
4333/**
4334 * struct iwl_wipan_slot
4335 * @width: Time in TU
4336 * @type:
4337 * 0 - BSS
4338 * 1 - PAN
4339 */
4340struct iwl_wipan_slot {
4341 __le16 width;
4342 u8 type;
4343 u8 reserved;
4344} __packed;
4345
4346#define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_CTS BIT(1) /* reserved */
4347#define IWL_WIPAN_PARAMS_FLG_LEAVE_CHANNEL_QUIET BIT(2) /* reserved */
4348#define IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE BIT(3) /* reserved */
4349#define IWL_WIPAN_PARAMS_FLG_FILTER_BEACON_NOTIF BIT(4)
4350#define IWL_WIPAN_PARAMS_FLG_FULL_SLOTTED_MODE BIT(5)
4351
4352/**
4353 * struct iwl_wipan_params_cmd
4354 * @flags:
4355 * bit0: reserved
4356 * bit1: CP leave channel with CTS
4357 * bit2: CP leave channel qith Quiet
4358 * bit3: slotted mode
4359 * 1 - work in slotted mode
4360 * 0 - work in non slotted mode
4361 * bit4: filter beacon notification
4362 * bit5: full tx slotted mode. if this flag is set,
4363 * uCode will perform leaving channel methods in context switch
4364 * also when working in same channel mode
4365 * @num_slots: 1 - 10
4366 */
4367struct iwl_wipan_params_cmd {
4368 __le16 flags;
4369 u8 reserved;
4370 u8 num_slots;
4371 struct iwl_wipan_slot slots[10];
4372} __packed;
4373
4374/*
4375 * REPLY_WIPAN_P2P_CHANNEL_SWITCH = 0xb9
4376 *
4377 * TODO: Figure out what this is used for,
4378 * it can only switch between 2.4 GHz
4379 * channels!!
4380 */
4381
4382struct iwl_wipan_p2p_channel_switch_cmd {
4383 __le16 channel;
4384 __le16 reserved;
4385};
4386
4387/*
4388 * REPLY_WIPAN_NOA_NOTIFICATION = 0xbc
4389 *
4390 * This is used by the device to notify us of the
4391 * NoA schedule it determined so we can forward it
4392 * to userspace for inclusion in probe responses.
4393 *
4394 * In beacons, the NoA schedule is simply appended
4395 * to the frame we give the device.
4396 */
4397
4398struct iwl_wipan_noa_descriptor {
4399 u8 count;
4400 __le32 duration;
4401 __le32 interval;
4402 __le32 starttime;
4403} __packed;
4404
4405struct iwl_wipan_noa_attribute {
4406 u8 id;
4407 __le16 length;
4408 u8 index;
4409 u8 ct_window;
4410 struct iwl_wipan_noa_descriptor descr0, descr1;
4411 u8 reserved;
4412} __packed;
4413
4414struct iwl_wipan_noa_notification {
4415 u32 noa_active;
4416 struct iwl_wipan_noa_attribute noa_attribute;
4417} __packed;
4418
4311#endif /* __iwl_commands_h__ */ 4419#endif /* __iwl_commands_h__ */
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c
index c43124c997c..87a2e40972b 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.c
+++ b/drivers/net/wireless/iwlwifi/iwl-core.c
@@ -191,27 +191,27 @@ EXPORT_SYMBOL(iwl_alloc_all);
191/* 191/*
192 * QoS support 192 * QoS support
193*/ 193*/
194static void iwl_update_qos(struct iwl_priv *priv) 194static void iwl_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
195{ 195{
196 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 196 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
197 return; 197 return;
198 198
199 priv->qos_data.def_qos_parm.qos_flags = 0; 199 ctx->qos_data.def_qos_parm.qos_flags = 0;
200 200
201 if (priv->qos_data.qos_active) 201 if (ctx->qos_data.qos_active)
202 priv->qos_data.def_qos_parm.qos_flags |= 202 ctx->qos_data.def_qos_parm.qos_flags |=
203 QOS_PARAM_FLG_UPDATE_EDCA_MSK; 203 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
204 204
205 if (priv->current_ht_config.is_ht) 205 if (ctx->ht.enabled)
206 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; 206 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
207 207
208 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", 208 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
209 priv->qos_data.qos_active, 209 ctx->qos_data.qos_active,
210 priv->qos_data.def_qos_parm.qos_flags); 210 ctx->qos_data.def_qos_parm.qos_flags);
211 211
212 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM, 212 iwl_send_cmd_pdu_async(priv, ctx->qos_cmd,
213 sizeof(struct iwl_qosparam_cmd), 213 sizeof(struct iwl_qosparam_cmd),
214 &priv->qos_data.def_qos_parm, NULL); 214 &ctx->qos_data.def_qos_parm, NULL);
215} 215}
216 216
217#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */ 217#define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
@@ -441,15 +441,15 @@ static bool is_single_rx_stream(struct iwl_priv *priv)
441 priv->current_ht_config.single_chain_sufficient; 441 priv->current_ht_config.single_chain_sufficient;
442} 442}
443 443
444static u8 iwl_is_channel_extension(struct iwl_priv *priv, 444static bool iwl_is_channel_extension(struct iwl_priv *priv,
445 enum ieee80211_band band, 445 enum ieee80211_band band,
446 u16 channel, u8 extension_chan_offset) 446 u16 channel, u8 extension_chan_offset)
447{ 447{
448 const struct iwl_channel_info *ch_info; 448 const struct iwl_channel_info *ch_info;
449 449
450 ch_info = iwl_get_channel_info(priv, band, channel); 450 ch_info = iwl_get_channel_info(priv, band, channel);
451 if (!is_channel_valid(ch_info)) 451 if (!is_channel_valid(ch_info))
452 return 0; 452 return false;
453 453
454 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE) 454 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
455 return !(ch_info->ht40_extension_channel & 455 return !(ch_info->ht40_extension_channel &
@@ -458,31 +458,31 @@ static u8 iwl_is_channel_extension(struct iwl_priv *priv,
458 return !(ch_info->ht40_extension_channel & 458 return !(ch_info->ht40_extension_channel &
459 IEEE80211_CHAN_NO_HT40MINUS); 459 IEEE80211_CHAN_NO_HT40MINUS);
460 460
461 return 0; 461 return false;
462} 462}
463 463
464u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv, 464bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
465 struct ieee80211_sta_ht_cap *sta_ht_inf) 465 struct iwl_rxon_context *ctx,
466 struct ieee80211_sta_ht_cap *ht_cap)
466{ 467{
467 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 468 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
469 return false;
468 470
469 if (!ht_conf->is_ht || !ht_conf->is_40mhz) 471 /*
470 return 0; 472 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
471
472 /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
473 * the bit will not set if it is pure 40MHz case 473 * the bit will not set if it is pure 40MHz case
474 */ 474 */
475 if (sta_ht_inf) { 475 if (ht_cap && !ht_cap->ht_supported)
476 if (!sta_ht_inf->ht_supported) 476 return false;
477 return 0; 477
478 }
479#ifdef CONFIG_IWLWIFI_DEBUGFS 478#ifdef CONFIG_IWLWIFI_DEBUGFS
480 if (priv->disable_ht40) 479 if (priv->disable_ht40)
481 return 0; 480 return false;
482#endif 481#endif
482
483 return iwl_is_channel_extension(priv, priv->band, 483 return iwl_is_channel_extension(priv, priv->band,
484 le16_to_cpu(priv->staging_rxon.channel), 484 le16_to_cpu(ctx->staging.channel),
485 ht_conf->extension_chan_offset); 485 ctx->ht.extension_chan_offset);
486} 486}
487EXPORT_SYMBOL(iwl_is_ht40_tx_allowed); 487EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
488 488
@@ -500,55 +500,64 @@ static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
500 return new_val; 500 return new_val;
501} 501}
502 502
503int iwl_send_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif) 503int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
504{ 504{
505 u64 tsf; 505 u64 tsf;
506 s32 interval_tm, rem; 506 s32 interval_tm, rem;
507 struct ieee80211_conf *conf = NULL; 507 struct ieee80211_conf *conf = NULL;
508 u16 beacon_int; 508 u16 beacon_int;
509 struct ieee80211_vif *vif = ctx->vif;
509 510
510 conf = ieee80211_get_hw_conf(priv->hw); 511 conf = ieee80211_get_hw_conf(priv->hw);
511 512
512 lockdep_assert_held(&priv->mutex); 513 lockdep_assert_held(&priv->mutex);
513 514
514 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd)); 515 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
515 516
516 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp); 517 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
517 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval); 518 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
518 519
519 beacon_int = vif->bss_conf.beacon_int; 520 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
520 521
521 if (vif->type == NL80211_IFTYPE_ADHOC) { 522 /*
522 /* TODO: we need to get atim_window from upper stack 523 * TODO: For IBSS we need to get atim_window from mac80211,
523 * for now we set to 0 */ 524 * for now just always use 0
524 priv->rxon_timing.atim_window = 0; 525 */
525 } else { 526 ctx->timing.atim_window = 0;
526 priv->rxon_timing.atim_window = 0;
527 }
528 527
529 beacon_int = iwl_adjust_beacon_interval(beacon_int, 528 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
529 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION)) {
530 ctx->timing.beacon_interval =
531 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
532 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
533 } else {
534 beacon_int = iwl_adjust_beacon_interval(beacon_int,
530 priv->hw_params.max_beacon_itrvl * TIME_UNIT); 535 priv->hw_params.max_beacon_itrvl * TIME_UNIT);
531 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int); 536 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
537 }
532 538
533 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */ 539 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
534 interval_tm = beacon_int * TIME_UNIT; 540 interval_tm = beacon_int * TIME_UNIT;
535 rem = do_div(tsf, interval_tm); 541 rem = do_div(tsf, interval_tm);
536 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem); 542 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
543
544 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
537 545
538 IWL_DEBUG_ASSOC(priv, 546 IWL_DEBUG_ASSOC(priv,
539 "beacon interval %d beacon timer %d beacon tim %d\n", 547 "beacon interval %d beacon timer %d beacon tim %d\n",
540 le16_to_cpu(priv->rxon_timing.beacon_interval), 548 le16_to_cpu(ctx->timing.beacon_interval),
541 le32_to_cpu(priv->rxon_timing.beacon_init_val), 549 le32_to_cpu(ctx->timing.beacon_init_val),
542 le16_to_cpu(priv->rxon_timing.atim_window)); 550 le16_to_cpu(ctx->timing.atim_window));
543 551
544 return iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING, 552 return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
545 sizeof(priv->rxon_timing), &priv->rxon_timing); 553 sizeof(ctx->timing), &ctx->timing);
546} 554}
547EXPORT_SYMBOL(iwl_send_rxon_timing); 555EXPORT_SYMBOL(iwl_send_rxon_timing);
548 556
549void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt) 557void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
558 int hw_decrypt)
550{ 559{
551 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 560 struct iwl_rxon_cmd *rxon = &ctx->staging;
552 561
553 if (hw_decrypt) 562 if (hw_decrypt)
554 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK; 563 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
@@ -565,11 +574,11 @@ EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
565 * be #ifdef'd out once the driver is stable and folks aren't actively 574 * be #ifdef'd out once the driver is stable and folks aren't actively
566 * making changes 575 * making changes
567 */ 576 */
568int iwl_check_rxon_cmd(struct iwl_priv *priv) 577int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
569{ 578{
570 int error = 0; 579 int error = 0;
571 int counter = 1; 580 int counter = 1;
572 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 581 struct iwl_rxon_cmd *rxon = &ctx->staging;
573 582
574 if (rxon->flags & RXON_FLG_BAND_24G_MSK) { 583 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
575 error |= le32_to_cpu(rxon->flags & 584 error |= le32_to_cpu(rxon->flags &
@@ -641,66 +650,83 @@ EXPORT_SYMBOL(iwl_check_rxon_cmd);
641 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that 650 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
642 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required. 651 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
643 */ 652 */
644int iwl_full_rxon_required(struct iwl_priv *priv) 653int iwl_full_rxon_required(struct iwl_priv *priv,
654 struct iwl_rxon_context *ctx)
645{ 655{
656 const struct iwl_rxon_cmd *staging = &ctx->staging;
657 const struct iwl_rxon_cmd *active = &ctx->active;
658
659#define CHK(cond) \
660 if ((cond)) { \
661 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
662 return 1; \
663 }
664
665#define CHK_NEQ(c1, c2) \
666 if ((c1) != (c2)) { \
667 IWL_DEBUG_INFO(priv, "need full RXON - " \
668 #c1 " != " #c2 " - %d != %d\n", \
669 (c1), (c2)); \
670 return 1; \
671 }
646 672
647 /* These items are only settable from the full RXON command */ 673 /* These items are only settable from the full RXON command */
648 if (!(iwl_is_associated(priv)) || 674 CHK(!iwl_is_associated_ctx(ctx));
649 compare_ether_addr(priv->staging_rxon.bssid_addr, 675 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
650 priv->active_rxon.bssid_addr) || 676 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
651 compare_ether_addr(priv->staging_rxon.node_addr, 677 CHK(compare_ether_addr(staging->wlap_bssid_addr,
652 priv->active_rxon.node_addr) || 678 active->wlap_bssid_addr));
653 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr, 679 CHK_NEQ(staging->dev_type, active->dev_type);
654 priv->active_rxon.wlap_bssid_addr) || 680 CHK_NEQ(staging->channel, active->channel);
655 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) || 681 CHK_NEQ(staging->air_propagation, active->air_propagation);
656 (priv->staging_rxon.channel != priv->active_rxon.channel) || 682 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
657 (priv->staging_rxon.air_propagation != 683 active->ofdm_ht_single_stream_basic_rates);
658 priv->active_rxon.air_propagation) || 684 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
659 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates != 685 active->ofdm_ht_dual_stream_basic_rates);
660 priv->active_rxon.ofdm_ht_single_stream_basic_rates) || 686 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
661 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates != 687 active->ofdm_ht_triple_stream_basic_rates);
662 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) || 688 CHK_NEQ(staging->assoc_id, active->assoc_id);
663 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
664 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
665 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
666 return 1;
667 689
668 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can 690 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
669 * be updated with the RXON_ASSOC command -- however only some 691 * be updated with the RXON_ASSOC command -- however only some
670 * flag transitions are allowed using RXON_ASSOC */ 692 * flag transitions are allowed using RXON_ASSOC */
671 693
672 /* Check if we are not switching bands */ 694 /* Check if we are not switching bands */
673 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) != 695 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
674 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)) 696 active->flags & RXON_FLG_BAND_24G_MSK);
675 return 1;
676 697
677 /* Check if we are switching association toggle */ 698 /* Check if we are switching association toggle */
678 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) != 699 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
679 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK)) 700 active->filter_flags & RXON_FILTER_ASSOC_MSK);
680 return 1; 701
702#undef CHK
703#undef CHK_NEQ
681 704
682 return 0; 705 return 0;
683} 706}
684EXPORT_SYMBOL(iwl_full_rxon_required); 707EXPORT_SYMBOL(iwl_full_rxon_required);
685 708
686u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv) 709u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
710 struct iwl_rxon_context *ctx)
687{ 711{
688 /* 712 /*
689 * Assign the lowest rate -- should really get this from 713 * Assign the lowest rate -- should really get this from
690 * the beacon skb from mac80211. 714 * the beacon skb from mac80211.
691 */ 715 */
692 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) 716 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
693 return IWL_RATE_1M_PLCP; 717 return IWL_RATE_1M_PLCP;
694 else 718 else
695 return IWL_RATE_6M_PLCP; 719 return IWL_RATE_6M_PLCP;
696} 720}
697EXPORT_SYMBOL(iwl_rate_get_lowest_plcp); 721EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
698 722
699void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf) 723static void _iwl_set_rxon_ht(struct iwl_priv *priv,
724 struct iwl_ht_config *ht_conf,
725 struct iwl_rxon_context *ctx)
700{ 726{
701 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 727 struct iwl_rxon_cmd *rxon = &ctx->staging;
702 728
703 if (!ht_conf->is_ht) { 729 if (!ctx->ht.enabled) {
704 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | 730 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
705 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK | 731 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
706 RXON_FLG_HT40_PROT_MSK | 732 RXON_FLG_HT40_PROT_MSK |
@@ -708,22 +734,22 @@ void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
708 return; 734 return;
709 } 735 }
710 736
711 /* FIXME: if the definition of ht_protection changed, the "translation" 737 /* FIXME: if the definition of ht.protection changed, the "translation"
712 * will be needed for rxon->flags 738 * will be needed for rxon->flags
713 */ 739 */
714 rxon->flags |= cpu_to_le32(ht_conf->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS); 740 rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
715 741
716 /* Set up channel bandwidth: 742 /* Set up channel bandwidth:
717 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */ 743 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
718 /* clear the HT channel mode before set the mode */ 744 /* clear the HT channel mode before set the mode */
719 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK | 745 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
720 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); 746 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
721 if (iwl_is_ht40_tx_allowed(priv, NULL)) { 747 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
722 /* pure ht40 */ 748 /* pure ht40 */
723 if (ht_conf->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) { 749 if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
724 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40; 750 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
725 /* Note: control channel is opposite of extension channel */ 751 /* Note: control channel is opposite of extension channel */
726 switch (ht_conf->extension_chan_offset) { 752 switch (ctx->ht.extension_chan_offset) {
727 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 753 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
728 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK; 754 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
729 break; 755 break;
@@ -733,7 +759,7 @@ void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
733 } 759 }
734 } else { 760 } else {
735 /* Note: control channel is opposite of extension channel */ 761 /* Note: control channel is opposite of extension channel */
736 switch (ht_conf->extension_chan_offset) { 762 switch (ctx->ht.extension_chan_offset) {
737 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE: 763 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
738 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK); 764 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
739 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED; 765 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
@@ -754,12 +780,20 @@ void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
754 } 780 }
755 781
756 if (priv->cfg->ops->hcmd->set_rxon_chain) 782 if (priv->cfg->ops->hcmd->set_rxon_chain)
757 priv->cfg->ops->hcmd->set_rxon_chain(priv); 783 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
758 784
759 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X " 785 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
760 "extension channel offset 0x%x\n", 786 "extension channel offset 0x%x\n",
761 le32_to_cpu(rxon->flags), ht_conf->ht_protection, 787 le32_to_cpu(rxon->flags), ctx->ht.protection,
762 ht_conf->extension_chan_offset); 788 ctx->ht.extension_chan_offset);
789}
790
791void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
792{
793 struct iwl_rxon_context *ctx;
794
795 for_each_context(priv, ctx)
796 _iwl_set_rxon_ht(priv, ht_conf, ctx);
763} 797}
764EXPORT_SYMBOL(iwl_set_rxon_ht); 798EXPORT_SYMBOL(iwl_set_rxon_ht);
765 799
@@ -832,7 +866,7 @@ static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
832 * Selects how many and which Rx receivers/antennas/chains to use. 866 * Selects how many and which Rx receivers/antennas/chains to use.
833 * This should not be used for scan command ... it puts data in wrong place. 867 * This should not be used for scan command ... it puts data in wrong place.
834 */ 868 */
835void iwl_set_rxon_chain(struct iwl_priv *priv) 869void iwl_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
836{ 870{
837 bool is_single = is_single_rx_stream(priv); 871 bool is_single = is_single_rx_stream(priv);
838 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status); 872 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
@@ -878,15 +912,15 @@ void iwl_set_rxon_chain(struct iwl_priv *priv)
878 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS; 912 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
879 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS; 913 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
880 914
881 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain); 915 ctx->staging.rx_chain = cpu_to_le16(rx_chain);
882 916
883 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam) 917 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
884 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK; 918 ctx->staging.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
885 else 919 else
886 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK; 920 ctx->staging.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
887 921
888 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n", 922 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
889 priv->staging_rxon.rx_chain, 923 ctx->staging.rx_chain,
890 active_rx_cnt, idle_rx_cnt); 924 active_rx_cnt, idle_rx_cnt);
891 925
892 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 || 926 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
@@ -894,39 +928,41 @@ void iwl_set_rxon_chain(struct iwl_priv *priv)
894} 928}
895EXPORT_SYMBOL(iwl_set_rxon_chain); 929EXPORT_SYMBOL(iwl_set_rxon_chain);
896 930
897/* Return valid channel */ 931/* Return valid, unused, channel for a passive scan to reset the RF */
898u8 iwl_get_single_channel_number(struct iwl_priv *priv, 932u8 iwl_get_single_channel_number(struct iwl_priv *priv,
899 enum ieee80211_band band) 933 enum ieee80211_band band)
900{ 934{
901 const struct iwl_channel_info *ch_info; 935 const struct iwl_channel_info *ch_info;
902 int i; 936 int i;
903 u8 channel = 0; 937 u8 channel = 0;
938 u8 min, max;
939 struct iwl_rxon_context *ctx;
904 940
905 /* only scan single channel, good enough to reset the RF */
906 /* pick the first valid not in-use channel */
907 if (band == IEEE80211_BAND_5GHZ) { 941 if (band == IEEE80211_BAND_5GHZ) {
908 for (i = 14; i < priv->channel_count; i++) { 942 min = 14;
909 if (priv->channel_info[i].channel != 943 max = priv->channel_count;
910 le16_to_cpu(priv->staging_rxon.channel)) {
911 channel = priv->channel_info[i].channel;
912 ch_info = iwl_get_channel_info(priv,
913 band, channel);
914 if (is_channel_valid(ch_info))
915 break;
916 }
917 }
918 } else { 944 } else {
919 for (i = 0; i < 14; i++) { 945 min = 0;
920 if (priv->channel_info[i].channel != 946 max = 14;
921 le16_to_cpu(priv->staging_rxon.channel)) { 947 }
922 channel = 948
923 priv->channel_info[i].channel; 949 for (i = min; i < max; i++) {
924 ch_info = iwl_get_channel_info(priv, 950 bool busy = false;
925 band, channel); 951
926 if (is_channel_valid(ch_info)) 952 for_each_context(priv, ctx) {
927 break; 953 busy = priv->channel_info[i].channel ==
928 } 954 le16_to_cpu(ctx->staging.channel);
955 if (busy)
956 break;
929 } 957 }
958
959 if (busy)
960 continue;
961
962 channel = priv->channel_info[i].channel;
963 ch_info = iwl_get_channel_info(priv, band, channel);
964 if (is_channel_valid(ch_info))
965 break;
930 } 966 }
931 967
932 return channel; 968 return channel;
@@ -937,25 +973,24 @@ EXPORT_SYMBOL(iwl_get_single_channel_number);
937 * iwl_set_rxon_channel - Set the band and channel values in staging RXON 973 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
938 * @ch: requested channel as a pointer to struct ieee80211_channel 974 * @ch: requested channel as a pointer to struct ieee80211_channel
939 975
940 * In addition to setting the staging RXON, priv->band is also set.
941 *
942 * NOTE: Does not commit to the hardware; it sets appropriate bit fields 976 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
943 * in the staging RXON flag structure based on the ch->band 977 * in the staging RXON flag structure based on the ch->band
944 */ 978 */
945int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch) 979int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
980 struct iwl_rxon_context *ctx)
946{ 981{
947 enum ieee80211_band band = ch->band; 982 enum ieee80211_band band = ch->band;
948 u16 channel = ch->hw_value; 983 u16 channel = ch->hw_value;
949 984
950 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) && 985 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
951 (priv->band == band)) 986 (priv->band == band))
952 return 0; 987 return 0;
953 988
954 priv->staging_rxon.channel = cpu_to_le16(channel); 989 ctx->staging.channel = cpu_to_le16(channel);
955 if (band == IEEE80211_BAND_5GHZ) 990 if (band == IEEE80211_BAND_5GHZ)
956 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK; 991 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
957 else 992 else
958 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; 993 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
959 994
960 priv->band = band; 995 priv->band = band;
961 996
@@ -966,24 +1001,25 @@ int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
966EXPORT_SYMBOL(iwl_set_rxon_channel); 1001EXPORT_SYMBOL(iwl_set_rxon_channel);
967 1002
968void iwl_set_flags_for_band(struct iwl_priv *priv, 1003void iwl_set_flags_for_band(struct iwl_priv *priv,
1004 struct iwl_rxon_context *ctx,
969 enum ieee80211_band band, 1005 enum ieee80211_band band,
970 struct ieee80211_vif *vif) 1006 struct ieee80211_vif *vif)
971{ 1007{
972 if (band == IEEE80211_BAND_5GHZ) { 1008 if (band == IEEE80211_BAND_5GHZ) {
973 priv->staging_rxon.flags &= 1009 ctx->staging.flags &=
974 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK 1010 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
975 | RXON_FLG_CCK_MSK); 1011 | RXON_FLG_CCK_MSK);
976 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 1012 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
977 } else { 1013 } else {
978 /* Copied from iwl_post_associate() */ 1014 /* Copied from iwl_post_associate() */
979 if (vif && vif->bss_conf.use_short_slot) 1015 if (vif && vif->bss_conf.use_short_slot)
980 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 1016 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
981 else 1017 else
982 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 1018 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
983 1019
984 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK; 1020 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
985 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK; 1021 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
986 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK; 1022 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
987 } 1023 }
988} 1024}
989EXPORT_SYMBOL(iwl_set_flags_for_band); 1025EXPORT_SYMBOL(iwl_set_flags_for_band);
@@ -992,35 +1028,34 @@ EXPORT_SYMBOL(iwl_set_flags_for_band);
992 * initialize rxon structure with default values from eeprom 1028 * initialize rxon structure with default values from eeprom
993 */ 1029 */
994void iwl_connection_init_rx_config(struct iwl_priv *priv, 1030void iwl_connection_init_rx_config(struct iwl_priv *priv,
995 struct ieee80211_vif *vif) 1031 struct iwl_rxon_context *ctx)
996{ 1032{
997 const struct iwl_channel_info *ch_info; 1033 const struct iwl_channel_info *ch_info;
998 enum nl80211_iftype type = NL80211_IFTYPE_STATION;
999
1000 if (vif)
1001 type = vif->type;
1002 1034
1003 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon)); 1035 memset(&ctx->staging, 0, sizeof(ctx->staging));
1004 1036
1005 switch (type) { 1037 if (!ctx->vif) {
1038 ctx->staging.dev_type = ctx->unused_devtype;
1039 } else switch (ctx->vif->type) {
1006 case NL80211_IFTYPE_AP: 1040 case NL80211_IFTYPE_AP:
1007 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP; 1041 ctx->staging.dev_type = ctx->ap_devtype;
1008 break; 1042 break;
1009 1043
1010 case NL80211_IFTYPE_STATION: 1044 case NL80211_IFTYPE_STATION:
1011 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS; 1045 ctx->staging.dev_type = ctx->station_devtype;
1012 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK; 1046 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
1013 break; 1047 break;
1014 1048
1015 case NL80211_IFTYPE_ADHOC: 1049 case NL80211_IFTYPE_ADHOC:
1016 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS; 1050 ctx->staging.dev_type = ctx->ibss_devtype;
1017 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK; 1051 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
1018 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK | 1052 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
1019 RXON_FILTER_ACCEPT_GRP_MSK; 1053 RXON_FILTER_ACCEPT_GRP_MSK;
1020 break; 1054 break;
1021 1055
1022 default: 1056 default:
1023 IWL_ERR(priv, "Unsupported interface type %d\n", type); 1057 IWL_ERR(priv, "Unsupported interface type %d\n",
1058 ctx->vif->type);
1024 break; 1059 break;
1025 } 1060 }
1026 1061
@@ -1028,37 +1063,36 @@ void iwl_connection_init_rx_config(struct iwl_priv *priv,
1028 /* TODO: Figure out when short_preamble would be set and cache from 1063 /* TODO: Figure out when short_preamble would be set and cache from
1029 * that */ 1064 * that */
1030 if (!hw_to_local(priv->hw)->short_preamble) 1065 if (!hw_to_local(priv->hw)->short_preamble)
1031 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; 1066 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1032 else 1067 else
1033 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 1068 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1034#endif 1069#endif
1035 1070
1036 ch_info = iwl_get_channel_info(priv, priv->band, 1071 ch_info = iwl_get_channel_info(priv, priv->band,
1037 le16_to_cpu(priv->active_rxon.channel)); 1072 le16_to_cpu(ctx->active.channel));
1038 1073
1039 if (!ch_info) 1074 if (!ch_info)
1040 ch_info = &priv->channel_info[0]; 1075 ch_info = &priv->channel_info[0];
1041 1076
1042 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel); 1077 ctx->staging.channel = cpu_to_le16(ch_info->channel);
1043 priv->band = ch_info->band; 1078 priv->band = ch_info->band;
1044 1079
1045 iwl_set_flags_for_band(priv, priv->band, vif); 1080 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
1046 1081
1047 priv->staging_rxon.ofdm_basic_rates = 1082 ctx->staging.ofdm_basic_rates =
1048 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 1083 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1049 priv->staging_rxon.cck_basic_rates = 1084 ctx->staging.cck_basic_rates =
1050 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; 1085 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1051 1086
1052 /* clear both MIX and PURE40 mode flag */ 1087 /* clear both MIX and PURE40 mode flag */
1053 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED | 1088 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
1054 RXON_FLG_CHANNEL_MODE_PURE_40); 1089 RXON_FLG_CHANNEL_MODE_PURE_40);
1090 if (ctx->vif)
1091 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
1055 1092
1056 if (vif) 1093 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
1057 memcpy(priv->staging_rxon.node_addr, vif->addr, ETH_ALEN); 1094 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
1058 1095 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
1059 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1060 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1061 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
1062} 1096}
1063EXPORT_SYMBOL(iwl_connection_init_rx_config); 1097EXPORT_SYMBOL(iwl_connection_init_rx_config);
1064 1098
@@ -1066,6 +1100,7 @@ void iwl_set_rate(struct iwl_priv *priv)
1066{ 1100{
1067 const struct ieee80211_supported_band *hw = NULL; 1101 const struct ieee80211_supported_band *hw = NULL;
1068 struct ieee80211_rate *rate; 1102 struct ieee80211_rate *rate;
1103 struct iwl_rxon_context *ctx;
1069 int i; 1104 int i;
1070 1105
1071 hw = iwl_get_hw_mode(priv, priv->band); 1106 hw = iwl_get_hw_mode(priv, priv->band);
@@ -1084,21 +1119,29 @@ void iwl_set_rate(struct iwl_priv *priv)
1084 1119
1085 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate); 1120 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
1086 1121
1087 priv->staging_rxon.cck_basic_rates = 1122 for_each_context(priv, ctx) {
1088 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF; 1123 ctx->staging.cck_basic_rates =
1124 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1089 1125
1090 priv->staging_rxon.ofdm_basic_rates = 1126 ctx->staging.ofdm_basic_rates =
1091 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF; 1127 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1128 }
1092} 1129}
1093EXPORT_SYMBOL(iwl_set_rate); 1130EXPORT_SYMBOL(iwl_set_rate);
1094 1131
1095void iwl_chswitch_done(struct iwl_priv *priv, bool is_success) 1132void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
1096{ 1133{
1134 /*
1135 * MULTI-FIXME
1136 * See iwl_mac_channel_switch.
1137 */
1138 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1139
1097 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 1140 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1098 return; 1141 return;
1099 1142
1100 if (priv->switch_rxon.switch_in_progress) { 1143 if (priv->switch_rxon.switch_in_progress) {
1101 ieee80211_chswitch_done(priv->vif, is_success); 1144 ieee80211_chswitch_done(ctx->vif, is_success);
1102 mutex_lock(&priv->mutex); 1145 mutex_lock(&priv->mutex);
1103 priv->switch_rxon.switch_in_progress = false; 1146 priv->switch_rxon.switch_in_progress = false;
1104 mutex_unlock(&priv->mutex); 1147 mutex_unlock(&priv->mutex);
@@ -1109,14 +1152,19 @@ EXPORT_SYMBOL(iwl_chswitch_done);
1109void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb) 1152void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1110{ 1153{
1111 struct iwl_rx_packet *pkt = rxb_addr(rxb); 1154 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1112 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1113 struct iwl_csa_notification *csa = &(pkt->u.csa_notif); 1155 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
1156 /*
1157 * MULTI-FIXME
1158 * See iwl_mac_channel_switch.
1159 */
1160 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
1161 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
1114 1162
1115 if (priv->switch_rxon.switch_in_progress) { 1163 if (priv->switch_rxon.switch_in_progress) {
1116 if (!le32_to_cpu(csa->status) && 1164 if (!le32_to_cpu(csa->status) &&
1117 (csa->channel == priv->switch_rxon.channel)) { 1165 (csa->channel == priv->switch_rxon.channel)) {
1118 rxon->channel = csa->channel; 1166 rxon->channel = csa->channel;
1119 priv->staging_rxon.channel = csa->channel; 1167 ctx->staging.channel = csa->channel;
1120 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n", 1168 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
1121 le16_to_cpu(csa->channel)); 1169 le16_to_cpu(csa->channel));
1122 iwl_chswitch_done(priv, true); 1170 iwl_chswitch_done(priv, true);
@@ -1130,9 +1178,10 @@ void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1130EXPORT_SYMBOL(iwl_rx_csa); 1178EXPORT_SYMBOL(iwl_rx_csa);
1131 1179
1132#ifdef CONFIG_IWLWIFI_DEBUG 1180#ifdef CONFIG_IWLWIFI_DEBUG
1133void iwl_print_rx_config_cmd(struct iwl_priv *priv) 1181void iwl_print_rx_config_cmd(struct iwl_priv *priv,
1182 struct iwl_rxon_context *ctx)
1134{ 1183{
1135 struct iwl_rxon_cmd *rxon = &priv->staging_rxon; 1184 struct iwl_rxon_cmd *rxon = &ctx->staging;
1136 1185
1137 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n"); 1186 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
1138 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon)); 1187 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
@@ -1172,7 +1221,8 @@ void iwl_irq_handle_error(struct iwl_priv *priv)
1172 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false); 1221 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
1173#ifdef CONFIG_IWLWIFI_DEBUG 1222#ifdef CONFIG_IWLWIFI_DEBUG
1174 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS) 1223 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
1175 iwl_print_rx_config_cmd(priv); 1224 iwl_print_rx_config_cmd(priv,
1225 &priv->contexts[IWL_RXON_CTX_BSS]);
1176#endif 1226#endif
1177 1227
1178 wake_up_interruptible(&priv->wait_command_queue); 1228 wake_up_interruptible(&priv->wait_command_queue);
@@ -1540,6 +1590,7 @@ int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1540 const struct ieee80211_tx_queue_params *params) 1590 const struct ieee80211_tx_queue_params *params)
1541{ 1591{
1542 struct iwl_priv *priv = hw->priv; 1592 struct iwl_priv *priv = hw->priv;
1593 struct iwl_rxon_context *ctx;
1543 unsigned long flags; 1594 unsigned long flags;
1544 int q; 1595 int q;
1545 1596
@@ -1559,13 +1610,21 @@ int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1559 1610
1560 spin_lock_irqsave(&priv->lock, flags); 1611 spin_lock_irqsave(&priv->lock, flags);
1561 1612
1562 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min); 1613 /*
1563 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max); 1614 * MULTI-FIXME
1564 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs; 1615 * This may need to be done per interface in nl80211/cfg80211/mac80211.
1565 priv->qos_data.def_qos_parm.ac[q].edca_txop = 1616 */
1566 cpu_to_le16((params->txop * 32)); 1617 for_each_context(priv, ctx) {
1618 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1619 cpu_to_le16(params->cw_min);
1620 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1621 cpu_to_le16(params->cw_max);
1622 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1623 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1624 cpu_to_le16((params->txop * 32));
1567 1625
1568 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; 1626 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1627 }
1569 1628
1570 spin_unlock_irqrestore(&priv->lock, flags); 1629 spin_unlock_irqrestore(&priv->lock, flags);
1571 1630
@@ -1588,15 +1647,16 @@ static void iwl_ht_conf(struct iwl_priv *priv,
1588 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 1647 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1589 struct ieee80211_sta *sta; 1648 struct ieee80211_sta *sta;
1590 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; 1649 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1650 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1591 1651
1592 IWL_DEBUG_MAC80211(priv, "enter:\n"); 1652 IWL_DEBUG_MAC80211(priv, "enter:\n");
1593 1653
1594 if (!ht_conf->is_ht) 1654 if (!ctx->ht.enabled)
1595 return; 1655 return;
1596 1656
1597 ht_conf->ht_protection = 1657 ctx->ht.protection =
1598 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION; 1658 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
1599 ht_conf->non_GF_STA_present = 1659 ctx->ht.non_gf_sta_present =
1600 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT); 1660 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1601 1661
1602 ht_conf->single_chain_sufficient = false; 1662 ht_conf->single_chain_sufficient = false;
@@ -1640,18 +1700,20 @@ static void iwl_ht_conf(struct iwl_priv *priv,
1640 IWL_DEBUG_MAC80211(priv, "leave\n"); 1700 IWL_DEBUG_MAC80211(priv, "leave\n");
1641} 1701}
1642 1702
1643static inline void iwl_set_no_assoc(struct iwl_priv *priv) 1703static inline void iwl_set_no_assoc(struct iwl_priv *priv,
1704 struct ieee80211_vif *vif)
1644{ 1705{
1706 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1707
1645 iwl_led_disassociate(priv); 1708 iwl_led_disassociate(priv);
1646 /* 1709 /*
1647 * inform the ucode that there is no longer an 1710 * inform the ucode that there is no longer an
1648 * association and that no more packets should be 1711 * association and that no more packets should be
1649 * sent 1712 * sent
1650 */ 1713 */
1651 priv->staging_rxon.filter_flags &= 1714 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1652 ~RXON_FILTER_ASSOC_MSK; 1715 ctx->staging.assoc_id = 0;
1653 priv->staging_rxon.assoc_id = 0; 1716 iwlcore_commit_rxon(priv, ctx);
1654 iwlcore_commit_rxon(priv);
1655} 1717}
1656 1718
1657static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) 1719static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
@@ -1662,6 +1724,14 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
1662 1724
1663 IWL_DEBUG_MAC80211(priv, "enter\n"); 1725 IWL_DEBUG_MAC80211(priv, "enter\n");
1664 1726
1727 lockdep_assert_held(&priv->mutex);
1728
1729 if (!priv->beacon_ctx) {
1730 IWL_ERR(priv, "update beacon but no beacon context!\n");
1731 dev_kfree_skb(skb);
1732 return -EINVAL;
1733 }
1734
1665 if (!iwl_is_ready_rf(priv)) { 1735 if (!iwl_is_ready_rf(priv)) {
1666 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n"); 1736 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1667 return -EIO; 1737 return -EIO;
@@ -1680,7 +1750,7 @@ static int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
1680 IWL_DEBUG_MAC80211(priv, "leave\n"); 1750 IWL_DEBUG_MAC80211(priv, "leave\n");
1681 spin_unlock_irqrestore(&priv->lock, flags); 1751 spin_unlock_irqrestore(&priv->lock, flags);
1682 1752
1683 priv->cfg->ops->lib->post_associate(priv, priv->vif); 1753 priv->cfg->ops->lib->post_associate(priv, priv->beacon_ctx->vif);
1684 1754
1685 return 0; 1755 return 0;
1686} 1756}
@@ -1691,6 +1761,7 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1691 u32 changes) 1761 u32 changes)
1692{ 1762{
1693 struct iwl_priv *priv = hw->priv; 1763 struct iwl_priv *priv = hw->priv;
1764 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1694 int ret; 1765 int ret;
1695 1766
1696 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes); 1767 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
@@ -1704,11 +1775,23 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1704 unsigned long flags; 1775 unsigned long flags;
1705 1776
1706 spin_lock_irqsave(&priv->lock, flags); 1777 spin_lock_irqsave(&priv->lock, flags);
1707 priv->qos_data.qos_active = bss_conf->qos; 1778 ctx->qos_data.qos_active = bss_conf->qos;
1708 iwl_update_qos(priv); 1779 iwl_update_qos(priv, ctx);
1709 spin_unlock_irqrestore(&priv->lock, flags); 1780 spin_unlock_irqrestore(&priv->lock, flags);
1710 } 1781 }
1711 1782
1783 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1784 /*
1785 * the add_interface code must make sure we only ever
1786 * have a single interface that could be beaconing at
1787 * any time.
1788 */
1789 if (vif->bss_conf.enable_beacon)
1790 priv->beacon_ctx = ctx;
1791 else
1792 priv->beacon_ctx = NULL;
1793 }
1794
1712 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) { 1795 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) {
1713 dev_kfree_skb(priv->ibss_beacon); 1796 dev_kfree_skb(priv->ibss_beacon);
1714 priv->ibss_beacon = ieee80211_beacon_get(hw, vif); 1797 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
@@ -1735,13 +1818,13 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1735 1818
1736 /* mac80211 only sets assoc when in STATION mode */ 1819 /* mac80211 only sets assoc when in STATION mode */
1737 if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) { 1820 if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
1738 memcpy(priv->staging_rxon.bssid_addr, 1821 memcpy(ctx->staging.bssid_addr,
1739 bss_conf->bssid, ETH_ALEN); 1822 bss_conf->bssid, ETH_ALEN);
1740 1823
1741 /* currently needed in a few places */ 1824 /* currently needed in a few places */
1742 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN); 1825 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1743 } else { 1826 } else {
1744 priv->staging_rxon.filter_flags &= 1827 ctx->staging.filter_flags &=
1745 ~RXON_FILTER_ASSOC_MSK; 1828 ~RXON_FILTER_ASSOC_MSK;
1746 } 1829 }
1747 1830
@@ -1764,21 +1847,21 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1764 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n", 1847 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
1765 bss_conf->use_short_preamble); 1848 bss_conf->use_short_preamble);
1766 if (bss_conf->use_short_preamble) 1849 if (bss_conf->use_short_preamble)
1767 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 1850 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1768 else 1851 else
1769 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; 1852 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1770 } 1853 }
1771 1854
1772 if (changes & BSS_CHANGED_ERP_CTS_PROT) { 1855 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
1773 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot); 1856 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
1774 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ)) 1857 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1775 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK; 1858 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1776 else 1859 else
1777 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK; 1860 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1778 if (bss_conf->use_cts_prot) 1861 if (bss_conf->use_cts_prot)
1779 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN; 1862 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1780 else 1863 else
1781 priv->staging_rxon.flags &= ~RXON_FLG_SELF_CTS_EN; 1864 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1782 } 1865 }
1783 1866
1784 if (changes & BSS_CHANGED_BASIC_RATES) { 1867 if (changes & BSS_CHANGED_BASIC_RATES) {
@@ -1788,12 +1871,12 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1788 * like this here: 1871 * like this here:
1789 * 1872 *
1790 if (A-band) 1873 if (A-band)
1791 priv->staging_rxon.ofdm_basic_rates = 1874 ctx->staging.ofdm_basic_rates =
1792 bss_conf->basic_rates; 1875 bss_conf->basic_rates;
1793 else 1876 else
1794 priv->staging_rxon.ofdm_basic_rates = 1877 ctx->staging.ofdm_basic_rates =
1795 bss_conf->basic_rates >> 4; 1878 bss_conf->basic_rates >> 4;
1796 priv->staging_rxon.cck_basic_rates = 1879 ctx->staging.cck_basic_rates =
1797 bss_conf->basic_rates & 0xF; 1880 bss_conf->basic_rates & 0xF;
1798 */ 1881 */
1799 } 1882 }
@@ -1802,7 +1885,7 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1802 iwl_ht_conf(priv, vif); 1885 iwl_ht_conf(priv, vif);
1803 1886
1804 if (priv->cfg->ops->hcmd->set_rxon_chain) 1887 if (priv->cfg->ops->hcmd->set_rxon_chain)
1805 priv->cfg->ops->hcmd->set_rxon_chain(priv); 1888 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1806 } 1889 }
1807 1890
1808 if (changes & BSS_CHANGED_ASSOC) { 1891 if (changes & BSS_CHANGED_ASSOC) {
@@ -1815,29 +1898,29 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1815 if (!iwl_is_rfkill(priv)) 1898 if (!iwl_is_rfkill(priv))
1816 priv->cfg->ops->lib->post_associate(priv, vif); 1899 priv->cfg->ops->lib->post_associate(priv, vif);
1817 } else 1900 } else
1818 iwl_set_no_assoc(priv); 1901 iwl_set_no_assoc(priv, vif);
1819 } 1902 }
1820 1903
1821 if (changes && iwl_is_associated(priv) && bss_conf->aid) { 1904 if (changes && iwl_is_associated_ctx(ctx) && bss_conf->aid) {
1822 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n", 1905 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
1823 changes); 1906 changes);
1824 ret = iwl_send_rxon_assoc(priv); 1907 ret = iwl_send_rxon_assoc(priv, ctx);
1825 if (!ret) { 1908 if (!ret) {
1826 /* Sync active_rxon with latest change. */ 1909 /* Sync active_rxon with latest change. */
1827 memcpy((void *)&priv->active_rxon, 1910 memcpy((void *)&ctx->active,
1828 &priv->staging_rxon, 1911 &ctx->staging,
1829 sizeof(struct iwl_rxon_cmd)); 1912 sizeof(struct iwl_rxon_cmd));
1830 } 1913 }
1831 } 1914 }
1832 1915
1833 if (changes & BSS_CHANGED_BEACON_ENABLED) { 1916 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1834 if (vif->bss_conf.enable_beacon) { 1917 if (vif->bss_conf.enable_beacon) {
1835 memcpy(priv->staging_rxon.bssid_addr, 1918 memcpy(ctx->staging.bssid_addr,
1836 bss_conf->bssid, ETH_ALEN); 1919 bss_conf->bssid, ETH_ALEN);
1837 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN); 1920 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1838 iwlcore_config_ap(priv, vif); 1921 iwlcore_config_ap(priv, vif);
1839 } else 1922 } else
1840 iwl_set_no_assoc(priv); 1923 iwl_set_no_assoc(priv, vif);
1841 } 1924 }
1842 1925
1843 if (changes & BSS_CHANGED_IBSS) { 1926 if (changes & BSS_CHANGED_IBSS) {
@@ -1849,6 +1932,12 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
1849 bss_conf->bssid); 1932 bss_conf->bssid);
1850 } 1933 }
1851 1934
1935 if (changes & BSS_CHANGED_IDLE &&
1936 priv->cfg->ops->hcmd->set_pan_params) {
1937 if (priv->cfg->ops->hcmd->set_pan_params(priv))
1938 IWL_ERR(priv, "failed to update PAN params\n");
1939 }
1940
1852 mutex_unlock(&priv->mutex); 1941 mutex_unlock(&priv->mutex);
1853 1942
1854 IWL_DEBUG_MAC80211(priv, "leave\n"); 1943 IWL_DEBUG_MAC80211(priv, "leave\n");
@@ -1857,17 +1946,21 @@ EXPORT_SYMBOL(iwl_bss_info_changed);
1857 1946
1858static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif) 1947static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
1859{ 1948{
1860 iwl_connection_init_rx_config(priv, vif); 1949 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1950
1951 iwl_connection_init_rx_config(priv, ctx);
1861 1952
1862 if (priv->cfg->ops->hcmd->set_rxon_chain) 1953 if (priv->cfg->ops->hcmd->set_rxon_chain)
1863 priv->cfg->ops->hcmd->set_rxon_chain(priv); 1954 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1864 1955
1865 return iwlcore_commit_rxon(priv); 1956 return iwlcore_commit_rxon(priv, ctx);
1866} 1957}
1867 1958
1868int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif) 1959int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1869{ 1960{
1870 struct iwl_priv *priv = hw->priv; 1961 struct iwl_priv *priv = hw->priv;
1962 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1963 struct iwl_rxon_context *tmp, *ctx = NULL;
1871 int err = 0; 1964 int err = 0;
1872 1965
1873 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n", 1966 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
@@ -1880,13 +1973,40 @@ int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1880 goto out; 1973 goto out;
1881 } 1974 }
1882 1975
1883 if (priv->vif) { 1976 for_each_context(priv, tmp) {
1884 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n"); 1977 u32 possible_modes =
1978 tmp->interface_modes | tmp->exclusive_interface_modes;
1979
1980 if (tmp->vif) {
1981 /* check if this busy context is exclusive */
1982 if (tmp->exclusive_interface_modes &
1983 BIT(tmp->vif->type)) {
1984 err = -EINVAL;
1985 goto out;
1986 }
1987 continue;
1988 }
1989
1990 if (!(possible_modes & BIT(vif->type)))
1991 continue;
1992
1993 /* have maybe usable context w/o interface */
1994 ctx = tmp;
1995 break;
1996 }
1997
1998 if (!ctx) {
1885 err = -EOPNOTSUPP; 1999 err = -EOPNOTSUPP;
1886 goto out; 2000 goto out;
1887 } 2001 }
1888 2002
1889 priv->vif = vif; 2003 vif_priv->ctx = ctx;
2004 ctx->vif = vif;
2005 /*
2006 * This variable will be correct only when there's just
2007 * a single context, but all code using it is for hardware
2008 * that supports only one context.
2009 */
1890 priv->iw_mode = vif->type; 2010 priv->iw_mode = vif->type;
1891 2011
1892 err = iwl_set_mode(priv, vif); 2012 err = iwl_set_mode(priv, vif);
@@ -1906,7 +2026,7 @@ int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1906 goto out; 2026 goto out;
1907 2027
1908 out_err: 2028 out_err:
1909 priv->vif = NULL; 2029 ctx->vif = NULL;
1910 priv->iw_mode = NL80211_IFTYPE_STATION; 2030 priv->iw_mode = NL80211_IFTYPE_STATION;
1911 out: 2031 out:
1912 mutex_unlock(&priv->mutex); 2032 mutex_unlock(&priv->mutex);
@@ -1920,25 +2040,23 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
1920 struct ieee80211_vif *vif) 2040 struct ieee80211_vif *vif)
1921{ 2041{
1922 struct iwl_priv *priv = hw->priv; 2042 struct iwl_priv *priv = hw->priv;
2043 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1923 bool scan_completed = false; 2044 bool scan_completed = false;
1924 2045
1925 IWL_DEBUG_MAC80211(priv, "enter\n"); 2046 IWL_DEBUG_MAC80211(priv, "enter\n");
1926 2047
1927 mutex_lock(&priv->mutex); 2048 mutex_lock(&priv->mutex);
1928 2049
1929 if (iwl_is_ready_rf(priv)) { 2050 WARN_ON(ctx->vif != vif);
1930 iwl_scan_cancel_timeout(priv, 100); 2051 ctx->vif = NULL;
1931 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2052
1932 iwlcore_commit_rxon(priv); 2053 iwl_scan_cancel_timeout(priv, 100);
1933 } 2054 iwl_set_mode(priv, vif);
1934 if (priv->vif == vif) { 2055
1935 priv->vif = NULL; 2056 if (priv->scan_vif == vif) {
1936 if (priv->scan_vif == vif) { 2057 scan_completed = true;
1937 scan_completed = true; 2058 priv->scan_vif = NULL;
1938 priv->scan_vif = NULL; 2059 priv->scan_request = NULL;
1939 priv->scan_request = NULL;
1940 }
1941 memset(priv->bssid, 0, ETH_ALEN);
1942 } 2060 }
1943 2061
1944 /* 2062 /*
@@ -1951,6 +2069,7 @@ void iwl_mac_remove_interface(struct ieee80211_hw *hw,
1951 if (vif->type == NL80211_IFTYPE_ADHOC) 2069 if (vif->type == NL80211_IFTYPE_ADHOC)
1952 priv->bt_traffic_load = priv->notif_bt_traffic_load; 2070 priv->bt_traffic_load = priv->notif_bt_traffic_load;
1953 2071
2072 memset(priv->bssid, 0, ETH_ALEN);
1954 mutex_unlock(&priv->mutex); 2073 mutex_unlock(&priv->mutex);
1955 2074
1956 if (scan_completed) 2075 if (scan_completed)
@@ -1971,6 +2090,7 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
1971 struct ieee80211_conf *conf = &hw->conf; 2090 struct ieee80211_conf *conf = &hw->conf;
1972 struct ieee80211_channel *channel = conf->channel; 2091 struct ieee80211_channel *channel = conf->channel;
1973 struct iwl_ht_config *ht_conf = &priv->current_ht_config; 2092 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
2093 struct iwl_rxon_context *ctx;
1974 unsigned long flags = 0; 2094 unsigned long flags = 0;
1975 int ret = 0; 2095 int ret = 0;
1976 u16 ch; 2096 u16 ch;
@@ -2000,7 +2120,8 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2000 * configured. 2120 * configured.
2001 */ 2121 */
2002 if (priv->cfg->ops->hcmd->set_rxon_chain) 2122 if (priv->cfg->ops->hcmd->set_rxon_chain)
2003 priv->cfg->ops->hcmd->set_rxon_chain(priv); 2123 for_each_context(priv, ctx)
2124 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
2004 } 2125 }
2005 2126
2006 /* during scanning mac80211 will delay channel setting until 2127 /* during scanning mac80211 will delay channel setting until
@@ -2020,39 +2141,49 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2020 2141
2021 spin_lock_irqsave(&priv->lock, flags); 2142 spin_lock_irqsave(&priv->lock, flags);
2022 2143
2023 /* Configure HT40 channels */ 2144 for_each_context(priv, ctx) {
2024 ht_conf->is_ht = conf_is_ht(conf); 2145 /* Configure HT40 channels */
2025 if (ht_conf->is_ht) { 2146 ctx->ht.enabled = conf_is_ht(conf);
2026 if (conf_is_ht40_minus(conf)) { 2147 if (ctx->ht.enabled) {
2027 ht_conf->extension_chan_offset = 2148 if (conf_is_ht40_minus(conf)) {
2028 IEEE80211_HT_PARAM_CHA_SEC_BELOW; 2149 ctx->ht.extension_chan_offset =
2029 ht_conf->is_40mhz = true; 2150 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2030 } else if (conf_is_ht40_plus(conf)) { 2151 ctx->ht.is_40mhz = true;
2031 ht_conf->extension_chan_offset = 2152 } else if (conf_is_ht40_plus(conf)) {
2032 IEEE80211_HT_PARAM_CHA_SEC_ABOVE; 2153 ctx->ht.extension_chan_offset =
2033 ht_conf->is_40mhz = true; 2154 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2034 } else { 2155 ctx->ht.is_40mhz = true;
2035 ht_conf->extension_chan_offset = 2156 } else {
2036 IEEE80211_HT_PARAM_CHA_SEC_NONE; 2157 ctx->ht.extension_chan_offset =
2037 ht_conf->is_40mhz = false; 2158 IEEE80211_HT_PARAM_CHA_SEC_NONE;
2038 } 2159 ctx->ht.is_40mhz = false;
2039 } else 2160 }
2040 ht_conf->is_40mhz = false; 2161 } else
2041 /* Default to no protection. Protection mode will later be set 2162 ctx->ht.is_40mhz = false;
2042 * from BSS config in iwl_ht_conf */ 2163
2043 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE; 2164 /*
2165 * Default to no protection. Protection mode will
2166 * later be set from BSS config in iwl_ht_conf
2167 */
2168 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2044 2169
2045 if ((le16_to_cpu(priv->staging_rxon.channel) != ch)) 2170 /* if we are switching from ht to 2.4 clear flags
2046 priv->staging_rxon.flags = 0; 2171 * from any ht related info since 2.4 does not
2172 * support ht */
2173 if ((le16_to_cpu(ctx->staging.channel) != ch))
2174 ctx->staging.flags = 0;
2047 2175
2048 iwl_set_rxon_channel(priv, channel); 2176 iwl_set_rxon_channel(priv, channel, ctx);
2049 iwl_set_rxon_ht(priv, ht_conf); 2177 iwl_set_rxon_ht(priv, ht_conf);
2178
2179 iwl_set_flags_for_band(priv, ctx, channel->band,
2180 ctx->vif);
2181 }
2050 2182
2051 iwl_set_flags_for_band(priv, channel->band, priv->vif);
2052 spin_unlock_irqrestore(&priv->lock, flags); 2183 spin_unlock_irqrestore(&priv->lock, flags);
2053 2184
2054 if (priv->cfg->ops->lib->update_bcast_station) 2185 if (priv->cfg->ops->lib->update_bcast_stations)
2055 ret = priv->cfg->ops->lib->update_bcast_station(priv); 2186 ret = priv->cfg->ops->lib->update_bcast_stations(priv);
2056 2187
2057 set_ch_out: 2188 set_ch_out:
2058 /* The list of supported rates and rate mask can be different 2189 /* The list of supported rates and rate mask can be different
@@ -2083,12 +2214,13 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2083 if (scan_active) 2214 if (scan_active)
2084 goto out; 2215 goto out;
2085 2216
2086 if (memcmp(&priv->active_rxon, 2217 for_each_context(priv, ctx) {
2087 &priv->staging_rxon, sizeof(priv->staging_rxon))) 2218 if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
2088 iwlcore_commit_rxon(priv); 2219 iwlcore_commit_rxon(priv, ctx);
2089 else 2220 else
2090 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n"); 2221 IWL_DEBUG_INFO(priv,
2091 2222 "Not re-sending same RXON configuration.\n");
2223 }
2092 2224
2093out: 2225out:
2094 IWL_DEBUG_MAC80211(priv, "leave\n"); 2226 IWL_DEBUG_MAC80211(priv, "leave\n");
@@ -2101,6 +2233,8 @@ void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2101{ 2233{
2102 struct iwl_priv *priv = hw->priv; 2234 struct iwl_priv *priv = hw->priv;
2103 unsigned long flags; 2235 unsigned long flags;
2236 /* IBSS can only be the IWL_RXON_CTX_BSS context */
2237 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2104 2238
2105 mutex_lock(&priv->mutex); 2239 mutex_lock(&priv->mutex);
2106 IWL_DEBUG_MAC80211(priv, "enter\n"); 2240 IWL_DEBUG_MAC80211(priv, "enter\n");
@@ -2131,8 +2265,8 @@ void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2131 * clear RXON_FILTER_ASSOC_MSK bit 2265 * clear RXON_FILTER_ASSOC_MSK bit
2132 */ 2266 */
2133 iwl_scan_cancel_timeout(priv, 100); 2267 iwl_scan_cancel_timeout(priv, 100);
2134 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2268 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2135 iwlcore_commit_rxon(priv); 2269 iwlcore_commit_rxon(priv, ctx);
2136 2270
2137 iwl_set_rate(priv); 2271 iwl_set_rate(priv);
2138 2272
@@ -2541,7 +2675,7 @@ static void iwl_force_rf_reset(struct iwl_priv *priv)
2541 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 2675 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2542 return; 2676 return;
2543 2677
2544 if (!iwl_is_associated(priv)) { 2678 if (!iwl_is_any_associated(priv)) {
2545 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); 2679 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
2546 return; 2680 return;
2547 } 2681 }
@@ -2692,14 +2826,14 @@ void iwl_bg_monitor_recover(unsigned long data)
2692 return; 2826 return;
2693 2827
2694 /* monitor and check for stuck cmd queue */ 2828 /* monitor and check for stuck cmd queue */
2695 if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM)) 2829 if (iwl_check_stuck_queue(priv, priv->cmd_queue))
2696 return; 2830 return;
2697 2831
2698 /* monitor and check for other stuck queues */ 2832 /* monitor and check for other stuck queues */
2699 if (iwl_is_associated(priv)) { 2833 if (iwl_is_any_associated(priv)) {
2700 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { 2834 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
2701 /* skip as we already checked the command queue */ 2835 /* skip as we already checked the command queue */
2702 if (cnt == IWL_CMD_QUEUE_NUM) 2836 if (cnt == priv->cmd_queue)
2703 continue; 2837 continue;
2704 if (iwl_check_stuck_queue(priv, cnt)) 2838 if (iwl_check_stuck_queue(priv, cnt))
2705 return; 2839 return;
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h
index de2e39f36c2..f7b57ed84f6 100644
--- a/drivers/net/wireless/iwlwifi/iwl-core.h
+++ b/drivers/net/wireless/iwlwifi/iwl-core.h
@@ -88,11 +88,13 @@ struct iwl_cmd;
88#define IWL_CMD(x) case x: return #x 88#define IWL_CMD(x) case x: return #x
89 89
90struct iwl_hcmd_ops { 90struct iwl_hcmd_ops {
91 int (*rxon_assoc)(struct iwl_priv *priv); 91 int (*rxon_assoc)(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
92 int (*commit_rxon)(struct iwl_priv *priv); 92 int (*commit_rxon)(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
93 void (*set_rxon_chain)(struct iwl_priv *priv); 93 void (*set_rxon_chain)(struct iwl_priv *priv,
94 struct iwl_rxon_context *ctx);
94 int (*set_tx_ant)(struct iwl_priv *priv, u8 valid_tx_ant); 95 int (*set_tx_ant)(struct iwl_priv *priv, u8 valid_tx_ant);
95 void (*send_bt_config)(struct iwl_priv *priv); 96 void (*send_bt_config)(struct iwl_priv *priv);
97 int (*set_pan_params)(struct iwl_priv *priv);
96}; 98};
97 99
98struct iwl_hcmd_utils_ops { 100struct iwl_hcmd_utils_ops {
@@ -205,7 +207,7 @@ struct iwl_lib_ops {
205 /* station management */ 207 /* station management */
206 int (*manage_ibss_station)(struct iwl_priv *priv, 208 int (*manage_ibss_station)(struct iwl_priv *priv,
207 struct ieee80211_vif *vif, bool add); 209 struct ieee80211_vif *vif, bool add);
208 int (*update_bcast_station)(struct iwl_priv *priv); 210 int (*update_bcast_stations)(struct iwl_priv *priv);
209 /* recover from tx queue stall */ 211 /* recover from tx queue stall */
210 void (*recover_from_tx_stall)(unsigned long data); 212 void (*recover_from_tx_stall)(unsigned long data);
211 /* check for plcp health */ 213 /* check for plcp health */
@@ -374,21 +376,25 @@ void iwl_activate_qos(struct iwl_priv *priv);
374int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, 376int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
375 const struct ieee80211_tx_queue_params *params); 377 const struct ieee80211_tx_queue_params *params);
376int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw); 378int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw);
377void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt); 379void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
378int iwl_check_rxon_cmd(struct iwl_priv *priv); 380 int hw_decrypt);
379int iwl_full_rxon_required(struct iwl_priv *priv); 381int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
380void iwl_set_rxon_chain(struct iwl_priv *priv); 382int iwl_full_rxon_required(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
381int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch); 383void iwl_set_rxon_chain(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
384int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
385 struct iwl_rxon_context *ctx);
382void iwl_set_flags_for_band(struct iwl_priv *priv, 386void iwl_set_flags_for_band(struct iwl_priv *priv,
387 struct iwl_rxon_context *ctx,
383 enum ieee80211_band band, 388 enum ieee80211_band band,
384 struct ieee80211_vif *vif); 389 struct ieee80211_vif *vif);
385u8 iwl_get_single_channel_number(struct iwl_priv *priv, 390u8 iwl_get_single_channel_number(struct iwl_priv *priv,
386 enum ieee80211_band band); 391 enum ieee80211_band band);
387void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf); 392void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf);
388u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv, 393bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
389 struct ieee80211_sta_ht_cap *sta_ht_inf); 394 struct iwl_rxon_context *ctx,
395 struct ieee80211_sta_ht_cap *ht_cap);
390void iwl_connection_init_rx_config(struct iwl_priv *priv, 396void iwl_connection_init_rx_config(struct iwl_priv *priv,
391 struct ieee80211_vif *vif); 397 struct iwl_rxon_context *ctx);
392void iwl_set_rate(struct iwl_priv *priv); 398void iwl_set_rate(struct iwl_priv *priv);
393int iwl_set_decrypted_flag(struct iwl_priv *priv, 399int iwl_set_decrypted_flag(struct iwl_priv *priv,
394 struct ieee80211_hdr *hdr, 400 struct ieee80211_hdr *hdr,
@@ -400,7 +406,7 @@ void iwl_bss_info_changed(struct ieee80211_hw *hw,
400 struct ieee80211_vif *vif, 406 struct ieee80211_vif *vif,
401 struct ieee80211_bss_conf *bss_conf, 407 struct ieee80211_bss_conf *bss_conf,
402 u32 changes); 408 u32 changes);
403int iwl_commit_rxon(struct iwl_priv *priv); 409int iwl_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
404int iwl_mac_add_interface(struct ieee80211_hw *hw, 410int iwl_mac_add_interface(struct ieee80211_hw *hw,
405 struct ieee80211_vif *vif); 411 struct ieee80211_vif *vif);
406void iwl_mac_remove_interface(struct ieee80211_hw *hw, 412void iwl_mac_remove_interface(struct ieee80211_hw *hw,
@@ -518,7 +524,8 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force);
518 524
519int iwl_hwrate_to_plcp_idx(u32 rate_n_flags); 525int iwl_hwrate_to_plcp_idx(u32 rate_n_flags);
520 526
521u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv); 527u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
528 struct iwl_rxon_context *ctx);
522 529
523u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid); 530u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid);
524 531
@@ -632,9 +639,11 @@ int iwl_dump_nic_event_log(struct iwl_priv *priv,
632void iwl_dump_csr(struct iwl_priv *priv); 639void iwl_dump_csr(struct iwl_priv *priv);
633int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display); 640int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display);
634#ifdef CONFIG_IWLWIFI_DEBUG 641#ifdef CONFIG_IWLWIFI_DEBUG
635void iwl_print_rx_config_cmd(struct iwl_priv *priv); 642void iwl_print_rx_config_cmd(struct iwl_priv *priv,
643 struct iwl_rxon_context *ctx);
636#else 644#else
637static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv) 645static inline void iwl_print_rx_config_cmd(struct iwl_priv *priv,
646 struct iwl_rxon_context *ctx)
638{ 647{
639} 648}
640#endif 649#endif
@@ -714,19 +723,21 @@ static inline int iwl_is_ready_rf(struct iwl_priv *priv)
714extern void iwl_send_bt_config(struct iwl_priv *priv); 723extern void iwl_send_bt_config(struct iwl_priv *priv);
715extern int iwl_send_statistics_request(struct iwl_priv *priv, 724extern int iwl_send_statistics_request(struct iwl_priv *priv,
716 u8 flags, bool clear); 725 u8 flags, bool clear);
717extern int iwl_send_lq_cmd(struct iwl_priv *priv, 726extern int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
718 struct iwl_link_quality_cmd *lq, u8 flags, bool init); 727 struct iwl_link_quality_cmd *lq, u8 flags, bool init);
719void iwl_apm_stop(struct iwl_priv *priv); 728void iwl_apm_stop(struct iwl_priv *priv);
720int iwl_apm_init(struct iwl_priv *priv); 729int iwl_apm_init(struct iwl_priv *priv);
721 730
722int iwl_send_rxon_timing(struct iwl_priv *priv, struct ieee80211_vif *vif); 731int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
723static inline int iwl_send_rxon_assoc(struct iwl_priv *priv) 732static inline int iwl_send_rxon_assoc(struct iwl_priv *priv,
733 struct iwl_rxon_context *ctx)
724{ 734{
725 return priv->cfg->ops->hcmd->rxon_assoc(priv); 735 return priv->cfg->ops->hcmd->rxon_assoc(priv, ctx);
726} 736}
727static inline int iwlcore_commit_rxon(struct iwl_priv *priv) 737static inline int iwlcore_commit_rxon(struct iwl_priv *priv,
738 struct iwl_rxon_context *ctx)
728{ 739{
729 return priv->cfg->ops->hcmd->commit_rxon(priv); 740 return priv->cfg->ops->hcmd->commit_rxon(priv, ctx);
730} 741}
731static inline void iwlcore_config_ap(struct iwl_priv *priv, 742static inline void iwlcore_config_ap(struct iwl_priv *priv,
732 struct ieee80211_vif *vif) 743 struct ieee80211_vif *vif)
diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
index ef787905f51..0ee8f516c4a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
+++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
@@ -643,19 +643,25 @@ static ssize_t iwl_dbgfs_qos_read(struct file *file, char __user *user_buf,
643 size_t count, loff_t *ppos) 643 size_t count, loff_t *ppos)
644{ 644{
645 struct iwl_priv *priv = file->private_data; 645 struct iwl_priv *priv = file->private_data;
646 struct iwl_rxon_context *ctx;
646 int pos = 0, i; 647 int pos = 0, i;
647 char buf[256]; 648 char buf[256 * NUM_IWL_RXON_CTX];
648 const size_t bufsz = sizeof(buf); 649 const size_t bufsz = sizeof(buf);
649 650
650 for (i = 0; i < AC_NUM; i++) { 651 for_each_context(priv, ctx) {
651 pos += scnprintf(buf + pos, bufsz - pos, 652 pos += scnprintf(buf + pos, bufsz - pos, "context %d:\n",
652 "\tcw_min\tcw_max\taifsn\ttxop\n"); 653 ctx->ctxid);
653 pos += scnprintf(buf + pos, bufsz - pos, 654 for (i = 0; i < AC_NUM; i++) {
655 pos += scnprintf(buf + pos, bufsz - pos,
656 "\tcw_min\tcw_max\taifsn\ttxop\n");
657 pos += scnprintf(buf + pos, bufsz - pos,
654 "AC[%d]\t%u\t%u\t%u\t%u\n", i, 658 "AC[%d]\t%u\t%u\t%u\t%u\n", i,
655 priv->qos_data.def_qos_parm.ac[i].cw_min, 659 ctx->qos_data.def_qos_parm.ac[i].cw_min,
656 priv->qos_data.def_qos_parm.ac[i].cw_max, 660 ctx->qos_data.def_qos_parm.ac[i].cw_max,
657 priv->qos_data.def_qos_parm.ac[i].aifsn, 661 ctx->qos_data.def_qos_parm.ac[i].aifsn,
658 priv->qos_data.def_qos_parm.ac[i].edca_txop); 662 ctx->qos_data.def_qos_parm.ac[i].edca_txop);
663 }
664 pos += scnprintf(buf + pos, bufsz - pos, "\n");
659 } 665 }
660 return simple_read_from_buffer(user_buf, count, ppos, buf, pos); 666 return simple_read_from_buffer(user_buf, count, ppos, buf, pos);
661} 667}
@@ -730,7 +736,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
730 return -EFAULT; 736 return -EFAULT;
731 if (sscanf(buf, "%d", &ht40) != 1) 737 if (sscanf(buf, "%d", &ht40) != 1)
732 return -EFAULT; 738 return -EFAULT;
733 if (!iwl_is_associated(priv)) 739 if (!iwl_is_any_associated(priv))
734 priv->disable_ht40 = ht40 ? true : false; 740 priv->disable_ht40 = ht40 ? true : false;
735 else { 741 else {
736 IWL_ERR(priv, "Sta associated with AP - " 742 IWL_ERR(priv, "Sta associated with AP - "
@@ -1319,7 +1325,8 @@ static ssize_t iwl_dbgfs_rxon_flags_read(struct file *file,
1319 int len = 0; 1325 int len = 0;
1320 char buf[20]; 1326 char buf[20];
1321 1327
1322 len = sprintf(buf, "0x%04X\n", le32_to_cpu(priv->active_rxon.flags)); 1328 len = sprintf(buf, "0x%04X\n",
1329 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.flags));
1323 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1330 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1324} 1331}
1325 1332
@@ -1332,7 +1339,7 @@ static ssize_t iwl_dbgfs_rxon_filter_flags_read(struct file *file,
1332 char buf[20]; 1339 char buf[20];
1333 1340
1334 len = sprintf(buf, "0x%04X\n", 1341 len = sprintf(buf, "0x%04X\n",
1335 le32_to_cpu(priv->active_rxon.filter_flags)); 1342 le32_to_cpu(priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags));
1336 return simple_read_from_buffer(user_buf, count, ppos, buf, len); 1343 return simple_read_from_buffer(user_buf, count, ppos, buf, len);
1337} 1344}
1338 1345
diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h
index 8d5201ac80f..4dd38b7b8b7 100644
--- a/drivers/net/wireless/iwlwifi/iwl-dev.h
+++ b/drivers/net/wireless/iwlwifi/iwl-dev.h
@@ -144,6 +144,7 @@ struct iwl_queue {
144/* One for each TFD */ 144/* One for each TFD */
145struct iwl_tx_info { 145struct iwl_tx_info {
146 struct sk_buff *skb; 146 struct sk_buff *skb;
147 struct iwl_rxon_context *ctx;
147}; 148};
148 149
149/** 150/**
@@ -253,10 +254,14 @@ struct iwl_channel_info {
253 struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES]; 254 struct iwl3945_scan_power_info scan_pwr_info[IWL_NUM_SCAN_RATES];
254}; 255};
255 256
256#define IWL_TX_FIFO_BK 0 257#define IWL_TX_FIFO_BK 0 /* shared */
257#define IWL_TX_FIFO_BE 1 258#define IWL_TX_FIFO_BE 1
258#define IWL_TX_FIFO_VI 2 259#define IWL_TX_FIFO_VI 2 /* shared */
259#define IWL_TX_FIFO_VO 3 260#define IWL_TX_FIFO_VO 3
261#define IWL_TX_FIFO_BK_IPAN IWL_TX_FIFO_BK
262#define IWL_TX_FIFO_BE_IPAN 4
263#define IWL_TX_FIFO_VI_IPAN IWL_TX_FIFO_VI
264#define IWL_TX_FIFO_VO_IPAN 5
260#define IWL_TX_FIFO_UNUSED -1 265#define IWL_TX_FIFO_UNUSED -1
261 266
262/* Minimum number of queues. MAX_NUM is defined in hw specific files. 267/* Minimum number of queues. MAX_NUM is defined in hw specific files.
@@ -265,11 +270,17 @@ struct iwl_channel_info {
265#define IWL_MIN_NUM_QUEUES 10 270#define IWL_MIN_NUM_QUEUES 10
266 271
267/* 272/*
268 * Queue #4 is the command queue for 3945/4965/5x00/1000/6x00, 273 * Command queue depends on iPAN support.
269 * the driver maps it into the appropriate device FIFO for the
270 * uCode.
271 */ 274 */
272#define IWL_CMD_QUEUE_NUM 4 275#define IWL_DEFAULT_CMD_QUEUE_NUM 4
276#define IWL_IPAN_CMD_QUEUE_NUM 9
277
278/*
279 * This queue number is required for proper operation
280 * because the ucode will stop/start the scheduler as
281 * required.
282 */
283#define IWL_IPAN_MCAST_QUEUE 8
273 284
274/* Power management (not Tx power) structures */ 285/* Power management (not Tx power) structures */
275 286
@@ -459,15 +470,8 @@ union iwl_ht_rate_supp {
459#define CFG_HT_MPDU_DENSITY_MIN (0x1) 470#define CFG_HT_MPDU_DENSITY_MIN (0x1)
460 471
461struct iwl_ht_config { 472struct iwl_ht_config {
462 /* self configuration data */
463 bool is_ht;
464 bool is_40mhz;
465 bool single_chain_sufficient; 473 bool single_chain_sufficient;
466 enum ieee80211_smps_mode smps; /* current smps mode */ 474 enum ieee80211_smps_mode smps; /* current smps mode */
467 /* BSS related data */
468 u8 extension_chan_offset;
469 u8 ht_protection;
470 u8 non_GF_STA_present;
471}; 475};
472 476
473/* QoS structures */ 477/* QoS structures */
@@ -485,12 +489,13 @@ struct iwl_qos_info {
485struct iwl_station_entry { 489struct iwl_station_entry {
486 struct iwl_addsta_cmd sta; 490 struct iwl_addsta_cmd sta;
487 struct iwl_tid_data tid[MAX_TID_COUNT]; 491 struct iwl_tid_data tid[MAX_TID_COUNT];
488 u8 used; 492 u8 used, ctxid;
489 struct iwl_hw_key keyinfo; 493 struct iwl_hw_key keyinfo;
490 struct iwl_link_quality_cmd *lq; 494 struct iwl_link_quality_cmd *lq;
491}; 495};
492 496
493struct iwl_station_priv_common { 497struct iwl_station_priv_common {
498 struct iwl_rxon_context *ctx;
494 u8 sta_id; 499 u8 sta_id;
495}; 500};
496 501
@@ -519,6 +524,7 @@ struct iwl_station_priv {
519 * space for us to put data into. 524 * space for us to put data into.
520 */ 525 */
521struct iwl_vif_priv { 526struct iwl_vif_priv {
527 struct iwl_rxon_context *ctx;
522 u8 ibss_bssid_sta_id; 528 u8 ibss_bssid_sta_id;
523}; 529};
524 530
@@ -576,6 +582,7 @@ enum iwl_ucode_tlv_type {
576 IWL_UCODE_TLV_INIT_DATA = 4, 582 IWL_UCODE_TLV_INIT_DATA = 4,
577 IWL_UCODE_TLV_BOOT = 5, 583 IWL_UCODE_TLV_BOOT = 5,
578 IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */ 584 IWL_UCODE_TLV_PROBE_MAX_LEN = 6, /* a u32 value */
585 IWL_UCODE_TLV_PAN = 7,
579 IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8, 586 IWL_UCODE_TLV_RUNT_EVTLOG_PTR = 8,
580 IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9, 587 IWL_UCODE_TLV_RUNT_EVTLOG_SIZE = 9,
581 IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10, 588 IWL_UCODE_TLV_RUNT_ERRLOG_PTR = 10,
@@ -670,7 +677,6 @@ struct iwl_sensitivity_ranges {
670 * @rx_page_order: Rx buffer page order 677 * @rx_page_order: Rx buffer page order
671 * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR 678 * @rx_wrt_ptr_reg: FH{39}_RSCSR_CHNL0_WPTR
672 * @max_stations: 679 * @max_stations:
673 * @bcast_sta_id:
674 * @ht40_channel: is 40MHz width possible in band 2.4 680 * @ht40_channel: is 40MHz width possible in band 2.4
675 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ) 681 * BIT(IEEE80211_BAND_5GHZ) BIT(IEEE80211_BAND_5GHZ)
676 * @sw_crypto: 0 for hw, 1 for sw 682 * @sw_crypto: 0 for hw, 1 for sw
@@ -694,7 +700,6 @@ struct iwl_hw_params {
694 u32 rx_page_order; 700 u32 rx_page_order;
695 u32 rx_wrt_ptr_reg; 701 u32 rx_wrt_ptr_reg;
696 u8 max_stations; 702 u8 max_stations;
697 u8 bcast_sta_id;
698 u8 ht40_channel; 703 u8 ht40_channel;
699 u8 max_beacon_itrvl; /* in 1024 ms */ 704 u8 max_beacon_itrvl; /* in 1024 ms */
700 u32 max_inst_size; 705 u32 max_inst_size;
@@ -1097,6 +1102,57 @@ struct iwl_force_reset {
1097 */ 1102 */
1098#define IWLAGN_EXT_BEACON_TIME_POS 22 1103#define IWLAGN_EXT_BEACON_TIME_POS 22
1099 1104
1105enum iwl_rxon_context_id {
1106 IWL_RXON_CTX_BSS,
1107 IWL_RXON_CTX_PAN,
1108
1109 NUM_IWL_RXON_CTX
1110};
1111
1112struct iwl_rxon_context {
1113 struct ieee80211_vif *vif;
1114
1115 const u8 *ac_to_fifo;
1116 const u8 *ac_to_queue;
1117 u8 mcast_queue;
1118
1119 enum iwl_rxon_context_id ctxid;
1120
1121 u32 interface_modes, exclusive_interface_modes;
1122 u8 unused_devtype, ap_devtype, ibss_devtype, station_devtype;
1123
1124 /*
1125 * We declare this const so it can only be
1126 * changed via explicit cast within the
1127 * routines that actually update the physical
1128 * hardware.
1129 */
1130 const struct iwl_rxon_cmd active;
1131 struct iwl_rxon_cmd staging;
1132
1133 struct iwl_rxon_time_cmd timing;
1134
1135 struct iwl_qos_info qos_data;
1136
1137 u8 bcast_sta_id, ap_sta_id;
1138
1139 u8 rxon_cmd, rxon_assoc_cmd, rxon_timing_cmd;
1140 u8 qos_cmd;
1141 u8 wep_key_cmd;
1142
1143 struct iwl_wep_key wep_keys[WEP_KEYS_MAX];
1144 u8 key_mapping_keys;
1145
1146 __le32 station_flags;
1147
1148 struct {
1149 bool non_gf_sta_present;
1150 u8 protection;
1151 bool enabled, is_40mhz;
1152 u8 extension_chan_offset;
1153 } ht;
1154};
1155
1100struct iwl_priv { 1156struct iwl_priv {
1101 1157
1102 /* ieee device used by generic ieee processing code */ 1158 /* ieee device used by generic ieee processing code */
@@ -1173,6 +1229,15 @@ struct iwl_priv {
1173 u32 hw_wa_rev; 1229 u32 hw_wa_rev;
1174 u8 rev_id; 1230 u8 rev_id;
1175 1231
1232 /* microcode/device supports multiple contexts */
1233 u8 valid_contexts;
1234
1235 /* command queue number */
1236 u8 cmd_queue;
1237
1238 /* max number of station keys */
1239 u8 sta_key_max_num;
1240
1176 /* EEPROM MAC addresses */ 1241 /* EEPROM MAC addresses */
1177 struct mac_address addresses[2]; 1242 struct mac_address addresses[2];
1178 1243
@@ -1190,15 +1255,7 @@ struct iwl_priv {
1190 u8 ucode_write_complete; /* the image write is complete */ 1255 u8 ucode_write_complete; /* the image write is complete */
1191 char firmware_name[25]; 1256 char firmware_name[25];
1192 1257
1193 1258 struct iwl_rxon_context contexts[NUM_IWL_RXON_CTX];
1194 struct iwl_rxon_time_cmd rxon_timing;
1195
1196 /* We declare this const so it can only be
1197 * changed via explicit cast within the
1198 * routines that actually update the physical
1199 * hardware */
1200 const struct iwl_rxon_cmd active_rxon;
1201 struct iwl_rxon_cmd staging_rxon;
1202 1259
1203 struct iwl_switch_rxon switch_rxon; 1260 struct iwl_switch_rxon switch_rxon;
1204 1261
@@ -1260,8 +1317,6 @@ struct iwl_priv {
1260 spinlock_t sta_lock; 1317 spinlock_t sta_lock;
1261 int num_stations; 1318 int num_stations;
1262 struct iwl_station_entry stations[IWL_STATION_COUNT]; 1319 struct iwl_station_entry stations[IWL_STATION_COUNT];
1263 struct iwl_wep_key wep_keys[WEP_KEYS_MAX]; /* protected by mutex */
1264 u8 key_mapping_key;
1265 unsigned long ucode_key_table; 1320 unsigned long ucode_key_table;
1266 1321
1267 /* queue refcounts */ 1322 /* queue refcounts */
@@ -1286,7 +1341,6 @@ struct iwl_priv {
1286 1341
1287 /* Last Rx'd beacon timestamp */ 1342 /* Last Rx'd beacon timestamp */
1288 u64 timestamp; 1343 u64 timestamp;
1289 struct ieee80211_vif *vif;
1290 1344
1291 union { 1345 union {
1292#if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE) 1346#if defined(CONFIG_IWL3945) || defined(CONFIG_IWL3945_MODULE)
@@ -1387,8 +1441,6 @@ struct iwl_priv {
1387 1441
1388 u32 inta_mask; 1442 u32 inta_mask;
1389 1443
1390 struct iwl_qos_info qos_data;
1391
1392 struct workqueue_struct *workqueue; 1444 struct workqueue_struct *workqueue;
1393 1445
1394 struct work_struct restart; 1446 struct work_struct restart;
@@ -1396,6 +1448,8 @@ struct iwl_priv {
1396 struct work_struct rx_replenish; 1448 struct work_struct rx_replenish;
1397 struct work_struct abort_scan; 1449 struct work_struct abort_scan;
1398 struct work_struct beacon_update; 1450 struct work_struct beacon_update;
1451 struct iwl_rxon_context *beacon_ctx;
1452
1399 struct work_struct tt_work; 1453 struct work_struct tt_work;
1400 struct work_struct ct_enter; 1454 struct work_struct ct_enter;
1401 struct work_struct ct_exit; 1455 struct work_struct ct_exit;
@@ -1490,10 +1544,34 @@ static inline struct ieee80211_hdr *iwl_tx_queue_get_hdr(struct iwl_priv *priv,
1490 return NULL; 1544 return NULL;
1491} 1545}
1492 1546
1547static inline struct iwl_rxon_context *
1548iwl_rxon_ctx_from_vif(struct ieee80211_vif *vif)
1549{
1550 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1551
1552 return vif_priv->ctx;
1553}
1554
1555#define for_each_context(priv, ctx) \
1556 for (ctx = &priv->contexts[IWL_RXON_CTX_BSS]; \
1557 ctx < &priv->contexts[NUM_IWL_RXON_CTX]; ctx++) \
1558 if (priv->valid_contexts & BIT(ctx->ctxid))
1559
1560static inline int iwl_is_associated(struct iwl_priv *priv,
1561 enum iwl_rxon_context_id ctxid)
1562{
1563 return (priv->contexts[ctxid].active.filter_flags &
1564 RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1565}
1566
1567static inline int iwl_is_any_associated(struct iwl_priv *priv)
1568{
1569 return iwl_is_associated(priv, IWL_RXON_CTX_BSS);
1570}
1493 1571
1494static inline int iwl_is_associated(struct iwl_priv *priv) 1572static inline int iwl_is_associated_ctx(struct iwl_rxon_context *ctx)
1495{ 1573{
1496 return (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0; 1574 return (ctx->active.filter_flags & RXON_FILTER_ASSOC_MSK) ? 1 : 0;
1497} 1575}
1498 1576
1499static inline int is_channel_valid(const struct iwl_channel_info *ch_info) 1577static inline int is_channel_valid(const struct iwl_channel_info *ch_info)
diff --git a/drivers/net/wireless/iwlwifi/iwl-hcmd.c b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
index 1f15b3aa847..c373b53babe 100644
--- a/drivers/net/wireless/iwlwifi/iwl-hcmd.c
+++ b/drivers/net/wireless/iwlwifi/iwl-hcmd.c
@@ -100,6 +100,14 @@ const char *get_cmd_string(u8 cmd)
100 IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF); 100 IWL_CMD(REPLY_BT_COEX_PROFILE_NOTIF);
101 IWL_CMD(REPLY_BT_COEX_PRIO_TABLE); 101 IWL_CMD(REPLY_BT_COEX_PRIO_TABLE);
102 IWL_CMD(REPLY_BT_COEX_PROT_ENV); 102 IWL_CMD(REPLY_BT_COEX_PROT_ENV);
103 IWL_CMD(REPLY_WIPAN_PARAMS);
104 IWL_CMD(REPLY_WIPAN_RXON);
105 IWL_CMD(REPLY_WIPAN_RXON_TIMING);
106 IWL_CMD(REPLY_WIPAN_RXON_ASSOC);
107 IWL_CMD(REPLY_WIPAN_QOS_PARAM);
108 IWL_CMD(REPLY_WIPAN_WEPKEY);
109 IWL_CMD(REPLY_WIPAN_P2P_CHANNEL_SWITCH);
110 IWL_CMD(REPLY_WIPAN_NOA_NOTIFICATION);
103 default: 111 default:
104 return "UNKNOWN"; 112 return "UNKNOWN";
105 113
@@ -232,7 +240,7 @@ cancel:
232 * in later, it will possibly set an invalid 240 * in later, it will possibly set an invalid
233 * address (cmd->meta.source). 241 * address (cmd->meta.source).
234 */ 242 */
235 priv->txq[IWL_CMD_QUEUE_NUM].meta[cmd_idx].flags &= 243 priv->txq[priv->cmd_queue].meta[cmd_idx].flags &=
236 ~CMD_WANT_SKB; 244 ~CMD_WANT_SKB;
237 } 245 }
238fail: 246fail:
diff --git a/drivers/net/wireless/iwlwifi/iwl-prph.h b/drivers/net/wireless/iwlwifi/iwl-prph.h
index b1f101caf19..5469655646a 100644
--- a/drivers/net/wireless/iwlwifi/iwl-prph.h
+++ b/drivers/net/wireless/iwlwifi/iwl-prph.h
@@ -306,7 +306,7 @@
306 * at a time, until receiving ACK from receiving station, or reaching 306 * at a time, until receiving ACK from receiving station, or reaching
307 * retry limit and giving up. 307 * retry limit and giving up.
308 * 308 *
309 * The command queue (#4) must use this mode! 309 * The command queue (#4/#9) must use this mode!
310 * This mode does not require use of the Byte Count table in host DRAM. 310 * This mode does not require use of the Byte Count table in host DRAM.
311 * 311 *
312 * Driver controls scheduler operation via 3 means: 312 * Driver controls scheduler operation via 3 means:
@@ -322,7 +322,7 @@
322 * (1024 bytes for each queue). 322 * (1024 bytes for each queue).
323 * 323 *
324 * After receiving "Alive" response from uCode, driver must initialize 324 * After receiving "Alive" response from uCode, driver must initialize
325 * the scheduler (especially for queue #4, the command queue, otherwise 325 * the scheduler (especially for queue #4/#9, the command queue, otherwise
326 * the driver can't issue commands!): 326 * the driver can't issue commands!):
327 */ 327 */
328 328
@@ -555,8 +555,9 @@
555#define IWLAGN_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \ 555#define IWLAGN_SCD_TRANSLATE_TBL_OFFSET_QUEUE(x) \
556 ((IWLAGN_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffc) 556 ((IWLAGN_SCD_TRANSLATE_TBL_OFFSET + ((x) * 2)) & 0xfffc)
557 557
558#define IWLAGN_SCD_QUEUECHAIN_SEL_ALL(x) (((1<<(x)) - 1) &\ 558#define IWLAGN_SCD_QUEUECHAIN_SEL_ALL(priv) \
559 (~(1<<IWL_CMD_QUEUE_NUM))) 559 (((1<<(priv)->hw_params.max_txq_num) - 1) &\
560 (~(1<<(priv)->cmd_queue)))
560 561
561#define IWLAGN_SCD_BASE (PRPH_BASE + 0xa02c00) 562#define IWLAGN_SCD_BASE (PRPH_BASE + 0xa02c00)
562 563
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c
index 79773e353ba..10be197b0f2 100644
--- a/drivers/net/wireless/iwlwifi/iwl-rx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-rx.c
@@ -228,7 +228,7 @@ void iwl_recover_from_statistics(struct iwl_priv *priv,
228{ 228{
229 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 229 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
230 return; 230 return;
231 if (iwl_is_associated(priv)) { 231 if (iwl_is_any_associated(priv)) {
232 if (priv->cfg->ops->lib->check_ack_health) { 232 if (priv->cfg->ops->lib->check_ack_health) {
233 if (!priv->cfg->ops->lib->check_ack_health( 233 if (!priv->cfg->ops->lib->check_ack_health(
234 priv, pkt)) { 234 priv, pkt)) {
@@ -266,7 +266,12 @@ int iwl_set_decrypted_flag(struct iwl_priv *priv,
266{ 266{
267 u16 fc = le16_to_cpu(hdr->frame_control); 267 u16 fc = le16_to_cpu(hdr->frame_control);
268 268
269 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK) 269 /*
270 * All contexts have the same setting here due to it being
271 * a module parameter, so OK to check any context.
272 */
273 if (priv->contexts[IWL_RXON_CTX_BSS].active.filter_flags &
274 RXON_FILTER_DIS_DECRYPT_MSK)
270 return 0; 275 return 0;
271 276
272 if (!(fc & IEEE80211_FCTL_PROTECTED)) 277 if (!(fc & IEEE80211_FCTL_PROTECTED))
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c
index 2939699a120..7727f0966d3 100644
--- a/drivers/net/wireless/iwlwifi/iwl-scan.c
+++ b/drivers/net/wireless/iwlwifi/iwl-scan.c
@@ -286,18 +286,28 @@ u16 iwl_get_passive_dwell_time(struct iwl_priv *priv,
286 enum ieee80211_band band, 286 enum ieee80211_band band,
287 struct ieee80211_vif *vif) 287 struct ieee80211_vif *vif)
288{ 288{
289 struct iwl_rxon_context *ctx;
289 u16 passive = (band == IEEE80211_BAND_2GHZ) ? 290 u16 passive = (band == IEEE80211_BAND_2GHZ) ?
290 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : 291 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 :
291 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; 292 IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52;
292 293
293 if (iwl_is_associated(priv)) { 294 if (iwl_is_any_associated(priv)) {
294 /* If we're associated, we clamp the maximum passive 295 /*
295 * dwell time to be 98% of the beacon interval (minus 296 * If we're associated, we clamp the maximum passive
296 * 2 * channel tune time) */ 297 * dwell time to be 98% of the smallest beacon interval
297 passive = vif ? vif->bss_conf.beacon_int : 0; 298 * (minus 2 * channel tune time)
298 if ((passive > IWL_PASSIVE_DWELL_BASE) || !passive) 299 */
299 passive = IWL_PASSIVE_DWELL_BASE; 300 for_each_context(priv, ctx) {
300 passive = (passive * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; 301 u16 value;
302
303 if (!iwl_is_associated_ctx(ctx))
304 continue;
305 value = ctx->vif ? ctx->vif->bss_conf.beacon_int : 0;
306 if ((value > IWL_PASSIVE_DWELL_BASE) || !value)
307 value = IWL_PASSIVE_DWELL_BASE;
308 value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2;
309 passive = min(value, passive);
310 }
301 } 311 }
302 312
303 return passive; 313 return passive;
@@ -527,6 +537,7 @@ static void iwl_bg_scan_completed(struct work_struct *work)
527 container_of(work, struct iwl_priv, scan_completed); 537 container_of(work, struct iwl_priv, scan_completed);
528 bool internal = false; 538 bool internal = false;
529 bool scan_completed = false; 539 bool scan_completed = false;
540 struct iwl_rxon_context *ctx;
530 541
531 IWL_DEBUG_SCAN(priv, "SCAN complete scan\n"); 542 IWL_DEBUG_SCAN(priv, "SCAN complete scan\n");
532 543
@@ -557,11 +568,13 @@ static void iwl_bg_scan_completed(struct work_struct *work)
557 * Since setting the RXON may have been deferred while 568 * Since setting the RXON may have been deferred while
558 * performing the scan, fire one off if needed 569 * performing the scan, fire one off if needed
559 */ 570 */
560 if (memcmp(&priv->active_rxon, 571 for_each_context(priv, ctx)
561 &priv->staging_rxon, sizeof(priv->staging_rxon))) 572 iwlcore_commit_rxon(priv, ctx);
562 iwlcore_commit_rxon(priv);
563 573
564 out: 574 out:
575 if (priv->cfg->ops->hcmd->set_pan_params)
576 priv->cfg->ops->hcmd->set_pan_params(priv);
577
565 mutex_unlock(&priv->mutex); 578 mutex_unlock(&priv->mutex);
566 579
567 /* 580 /*
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c
index d5e8db37b86..ccd09027c7c 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.c
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.c
@@ -172,12 +172,14 @@ int iwl_send_add_sta(struct iwl_priv *priv,
172EXPORT_SYMBOL(iwl_send_add_sta); 172EXPORT_SYMBOL(iwl_send_add_sta);
173 173
174static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, 174static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
175 struct ieee80211_sta_ht_cap *sta_ht_inf) 175 struct ieee80211_sta *sta,
176 struct iwl_rxon_context *ctx)
176{ 177{
178 struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap;
177 __le32 sta_flags; 179 __le32 sta_flags;
178 u8 mimo_ps_mode; 180 u8 mimo_ps_mode;
179 181
180 if (!sta_ht_inf || !sta_ht_inf->ht_supported) 182 if (!sta || !sta_ht_inf->ht_supported)
181 goto done; 183 goto done;
182 184
183 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; 185 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2;
@@ -211,7 +213,7 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
211 sta_flags |= cpu_to_le32( 213 sta_flags |= cpu_to_le32(
212 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); 214 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
213 215
214 if (iwl_is_ht40_tx_allowed(priv, sta_ht_inf)) 216 if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap))
215 sta_flags |= STA_FLG_HT40_EN_MSK; 217 sta_flags |= STA_FLG_HT40_EN_MSK;
216 else 218 else
217 sta_flags &= ~STA_FLG_HT40_EN_MSK; 219 sta_flags &= ~STA_FLG_HT40_EN_MSK;
@@ -226,9 +228,9 @@ static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index,
226 * 228 *
227 * should be called with sta_lock held 229 * should be called with sta_lock held
228 */ 230 */
229static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr, 231static u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
230 bool is_ap, 232 const u8 *addr, bool is_ap,
231 struct ieee80211_sta_ht_cap *ht_info) 233 struct ieee80211_sta *sta)
232{ 234{
233 struct iwl_station_entry *station; 235 struct iwl_station_entry *station;
234 int i; 236 int i;
@@ -236,9 +238,9 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
236 u16 rate; 238 u16 rate;
237 239
238 if (is_ap) 240 if (is_ap)
239 sta_id = IWL_AP_ID; 241 sta_id = ctx->ap_sta_id;
240 else if (is_broadcast_ether_addr(addr)) 242 else if (is_broadcast_ether_addr(addr))
241 sta_id = priv->hw_params.bcast_sta_id; 243 sta_id = ctx->bcast_sta_id;
242 else 244 else
243 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) { 245 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
244 if (!compare_ether_addr(priv->stations[i].sta.sta.addr, 246 if (!compare_ether_addr(priv->stations[i].sta.sta.addr,
@@ -289,14 +291,22 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
289 memcpy(station->sta.sta.addr, addr, ETH_ALEN); 291 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
290 station->sta.mode = 0; 292 station->sta.mode = 0;
291 station->sta.sta.sta_id = sta_id; 293 station->sta.sta.sta_id = sta_id;
292 station->sta.station_flags = 0; 294 station->sta.station_flags = ctx->station_flags;
295 station->ctxid = ctx->ctxid;
296
297 if (sta) {
298 struct iwl_station_priv_common *sta_priv;
299
300 sta_priv = (void *)sta->drv_priv;
301 sta_priv->ctx = ctx;
302 }
293 303
294 /* 304 /*
295 * OK to call unconditionally, since local stations (IBSS BSSID 305 * OK to call unconditionally, since local stations (IBSS BSSID
296 * STA and broadcast STA) pass in a NULL ht_info, and mac80211 306 * STA and broadcast STA) pass in a NULL sta, and mac80211
297 * doesn't allow HT IBSS. 307 * doesn't allow HT IBSS.
298 */ 308 */
299 iwl_set_ht_add_station(priv, sta_id, ht_info); 309 iwl_set_ht_add_station(priv, sta_id, sta, ctx);
300 310
301 /* 3945 only */ 311 /* 3945 only */
302 rate = (priv->band == IEEE80211_BAND_5GHZ) ? 312 rate = (priv->band == IEEE80211_BAND_5GHZ) ?
@@ -313,10 +323,9 @@ static u8 iwl_prep_station(struct iwl_priv *priv, const u8 *addr,
313/** 323/**
314 * iwl_add_station_common - 324 * iwl_add_station_common -
315 */ 325 */
316int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, 326int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
317 bool is_ap, 327 const u8 *addr, bool is_ap,
318 struct ieee80211_sta_ht_cap *ht_info, 328 struct ieee80211_sta *sta, u8 *sta_id_r)
319 u8 *sta_id_r)
320{ 329{
321 unsigned long flags_spin; 330 unsigned long flags_spin;
322 int ret = 0; 331 int ret = 0;
@@ -325,7 +334,7 @@ int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr,
325 334
326 *sta_id_r = 0; 335 *sta_id_r = 0;
327 spin_lock_irqsave(&priv->sta_lock, flags_spin); 336 spin_lock_irqsave(&priv->sta_lock, flags_spin);
328 sta_id = iwl_prep_station(priv, addr, is_ap, ht_info); 337 sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta);
329 if (sta_id == IWL_INVALID_STATION) { 338 if (sta_id == IWL_INVALID_STATION) {
330 IWL_ERR(priv, "Unable to prepare station %pM for addition\n", 339 IWL_ERR(priv, "Unable to prepare station %pM for addition\n",
331 addr); 340 addr);
@@ -431,8 +440,8 @@ static struct iwl_link_quality_cmd *iwl_sta_alloc_lq(struct iwl_priv *priv,
431 * 440 *
432 * Function sleeps. 441 * Function sleeps.
433 */ 442 */
434int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs, 443int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
435 u8 *sta_id_r) 444 const u8 *addr, bool init_rs, u8 *sta_id_r)
436{ 445{
437 int ret; 446 int ret;
438 u8 sta_id; 447 u8 sta_id;
@@ -442,7 +451,7 @@ int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
442 if (sta_id_r) 451 if (sta_id_r)
443 *sta_id_r = IWL_INVALID_STATION; 452 *sta_id_r = IWL_INVALID_STATION;
444 453
445 ret = iwl_add_station_common(priv, addr, 0, NULL, &sta_id); 454 ret = iwl_add_station_common(priv, ctx, addr, 0, NULL, &sta_id);
446 if (ret) { 455 if (ret) {
447 IWL_ERR(priv, "Unable to add station %pM\n", addr); 456 IWL_ERR(priv, "Unable to add station %pM\n", addr);
448 return ret; 457 return ret;
@@ -464,7 +473,7 @@ int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs,
464 return -ENOMEM; 473 return -ENOMEM;
465 } 474 }
466 475
467 ret = iwl_send_lq_cmd(priv, link_cmd, CMD_SYNC, true); 476 ret = iwl_send_lq_cmd(priv, ctx, link_cmd, CMD_SYNC, true);
468 if (ret) 477 if (ret)
469 IWL_ERR(priv, "Link quality command failed (%d)\n", ret); 478 IWL_ERR(priv, "Link quality command failed (%d)\n", ret);
470 479
@@ -616,7 +625,8 @@ EXPORT_SYMBOL_GPL(iwl_remove_station);
616 * other than explicit station management would cause this in 625 * other than explicit station management would cause this in
617 * the ucode, e.g. unassociated RXON. 626 * the ucode, e.g. unassociated RXON.
618 */ 627 */
619void iwl_clear_ucode_stations(struct iwl_priv *priv) 628void iwl_clear_ucode_stations(struct iwl_priv *priv,
629 struct iwl_rxon_context *ctx)
620{ 630{
621 int i; 631 int i;
622 unsigned long flags_spin; 632 unsigned long flags_spin;
@@ -626,6 +636,9 @@ void iwl_clear_ucode_stations(struct iwl_priv *priv)
626 636
627 spin_lock_irqsave(&priv->sta_lock, flags_spin); 637 spin_lock_irqsave(&priv->sta_lock, flags_spin);
628 for (i = 0; i < priv->hw_params.max_stations; i++) { 638 for (i = 0; i < priv->hw_params.max_stations; i++) {
639 if (ctx && ctx->ctxid != priv->stations[i].ctxid)
640 continue;
641
629 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { 642 if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) {
630 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); 643 IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i);
631 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; 644 priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE;
@@ -647,7 +660,7 @@ EXPORT_SYMBOL(iwl_clear_ucode_stations);
647 * 660 *
648 * Function sleeps. 661 * Function sleeps.
649 */ 662 */
650void iwl_restore_stations(struct iwl_priv *priv) 663void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
651{ 664{
652 struct iwl_addsta_cmd sta_cmd; 665 struct iwl_addsta_cmd sta_cmd;
653 struct iwl_link_quality_cmd lq; 666 struct iwl_link_quality_cmd lq;
@@ -665,6 +678,8 @@ void iwl_restore_stations(struct iwl_priv *priv)
665 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); 678 IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n");
666 spin_lock_irqsave(&priv->sta_lock, flags_spin); 679 spin_lock_irqsave(&priv->sta_lock, flags_spin);
667 for (i = 0; i < priv->hw_params.max_stations; i++) { 680 for (i = 0; i < priv->hw_params.max_stations; i++) {
681 if (ctx->ctxid != priv->stations[i].ctxid)
682 continue;
668 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && 683 if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) &&
669 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { 684 !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) {
670 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", 685 IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n",
@@ -700,7 +715,7 @@ void iwl_restore_stations(struct iwl_priv *priv)
700 * current LQ command 715 * current LQ command
701 */ 716 */
702 if (send_lq) 717 if (send_lq)
703 iwl_send_lq_cmd(priv, &lq, CMD_SYNC, true); 718 iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true);
704 spin_lock_irqsave(&priv->sta_lock, flags_spin); 719 spin_lock_irqsave(&priv->sta_lock, flags_spin);
705 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; 720 priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS;
706 } 721 }
@@ -718,7 +733,7 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
718{ 733{
719 int i; 734 int i;
720 735
721 for (i = 0; i < STA_KEY_MAX_NUM; i++) 736 for (i = 0; i < priv->sta_key_max_num; i++)
722 if (!test_and_set_bit(i, &priv->ucode_key_table)) 737 if (!test_and_set_bit(i, &priv->ucode_key_table))
723 return i; 738 return i;
724 739
@@ -726,7 +741,9 @@ int iwl_get_free_ucode_key_index(struct iwl_priv *priv)
726} 741}
727EXPORT_SYMBOL(iwl_get_free_ucode_key_index); 742EXPORT_SYMBOL(iwl_get_free_ucode_key_index);
728 743
729static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty) 744static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv,
745 struct iwl_rxon_context *ctx,
746 bool send_if_empty)
730{ 747{
731 int i, not_empty = 0; 748 int i, not_empty = 0;
732 u8 buff[sizeof(struct iwl_wep_cmd) + 749 u8 buff[sizeof(struct iwl_wep_cmd) +
@@ -734,7 +751,7 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
734 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff; 751 struct iwl_wep_cmd *wep_cmd = (struct iwl_wep_cmd *)buff;
735 size_t cmd_size = sizeof(struct iwl_wep_cmd); 752 size_t cmd_size = sizeof(struct iwl_wep_cmd);
736 struct iwl_host_cmd cmd = { 753 struct iwl_host_cmd cmd = {
737 .id = REPLY_WEPKEY, 754 .id = ctx->wep_key_cmd,
738 .data = wep_cmd, 755 .data = wep_cmd,
739 .flags = CMD_SYNC, 756 .flags = CMD_SYNC,
740 }; 757 };
@@ -746,16 +763,16 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
746 763
747 for (i = 0; i < WEP_KEYS_MAX ; i++) { 764 for (i = 0; i < WEP_KEYS_MAX ; i++) {
748 wep_cmd->key[i].key_index = i; 765 wep_cmd->key[i].key_index = i;
749 if (priv->wep_keys[i].key_size) { 766 if (ctx->wep_keys[i].key_size) {
750 wep_cmd->key[i].key_offset = i; 767 wep_cmd->key[i].key_offset = i;
751 not_empty = 1; 768 not_empty = 1;
752 } else { 769 } else {
753 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET; 770 wep_cmd->key[i].key_offset = WEP_INVALID_OFFSET;
754 } 771 }
755 772
756 wep_cmd->key[i].key_size = priv->wep_keys[i].key_size; 773 wep_cmd->key[i].key_size = ctx->wep_keys[i].key_size;
757 memcpy(&wep_cmd->key[i].key[3], priv->wep_keys[i].key, 774 memcpy(&wep_cmd->key[i].key[3], ctx->wep_keys[i].key,
758 priv->wep_keys[i].key_size); 775 ctx->wep_keys[i].key_size);
759 } 776 }
760 777
761 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE; 778 wep_cmd->global_key_type = WEP_KEY_WEP_TYPE;
@@ -771,15 +788,17 @@ static int iwl_send_static_wepkey_cmd(struct iwl_priv *priv, u8 send_if_empty)
771 return 0; 788 return 0;
772} 789}
773 790
774int iwl_restore_default_wep_keys(struct iwl_priv *priv) 791int iwl_restore_default_wep_keys(struct iwl_priv *priv,
792 struct iwl_rxon_context *ctx)
775{ 793{
776 lockdep_assert_held(&priv->mutex); 794 lockdep_assert_held(&priv->mutex);
777 795
778 return iwl_send_static_wepkey_cmd(priv, 0); 796 return iwl_send_static_wepkey_cmd(priv, ctx, false);
779} 797}
780EXPORT_SYMBOL(iwl_restore_default_wep_keys); 798EXPORT_SYMBOL(iwl_restore_default_wep_keys);
781 799
782int iwl_remove_default_wep_key(struct iwl_priv *priv, 800int iwl_remove_default_wep_key(struct iwl_priv *priv,
801 struct iwl_rxon_context *ctx,
783 struct ieee80211_key_conf *keyconf) 802 struct ieee80211_key_conf *keyconf)
784{ 803{
785 int ret; 804 int ret;
@@ -789,13 +808,13 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
789 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n", 808 IWL_DEBUG_WEP(priv, "Removing default WEP key: idx=%d\n",
790 keyconf->keyidx); 809 keyconf->keyidx);
791 810
792 memset(&priv->wep_keys[keyconf->keyidx], 0, sizeof(priv->wep_keys[0])); 811 memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0]));
793 if (iwl_is_rfkill(priv)) { 812 if (iwl_is_rfkill(priv)) {
794 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); 813 IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n");
795 /* but keys in device are clear anyway so return success */ 814 /* but keys in device are clear anyway so return success */
796 return 0; 815 return 0;
797 } 816 }
798 ret = iwl_send_static_wepkey_cmd(priv, 1); 817 ret = iwl_send_static_wepkey_cmd(priv, ctx, 1);
799 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n", 818 IWL_DEBUG_WEP(priv, "Remove default WEP key: idx=%d ret=%d\n",
800 keyconf->keyidx, ret); 819 keyconf->keyidx, ret);
801 820
@@ -804,6 +823,7 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv,
804EXPORT_SYMBOL(iwl_remove_default_wep_key); 823EXPORT_SYMBOL(iwl_remove_default_wep_key);
805 824
806int iwl_set_default_wep_key(struct iwl_priv *priv, 825int iwl_set_default_wep_key(struct iwl_priv *priv,
826 struct iwl_rxon_context *ctx,
807 struct ieee80211_key_conf *keyconf) 827 struct ieee80211_key_conf *keyconf)
808{ 828{
809 int ret; 829 int ret;
@@ -818,13 +838,13 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
818 838
819 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV; 839 keyconf->flags &= ~IEEE80211_KEY_FLAG_GENERATE_IV;
820 keyconf->hw_key_idx = HW_KEY_DEFAULT; 840 keyconf->hw_key_idx = HW_KEY_DEFAULT;
821 priv->stations[IWL_AP_ID].keyinfo.cipher = keyconf->cipher; 841 priv->stations[ctx->ap_sta_id].keyinfo.cipher = keyconf->cipher;
822 842
823 priv->wep_keys[keyconf->keyidx].key_size = keyconf->keylen; 843 ctx->wep_keys[keyconf->keyidx].key_size = keyconf->keylen;
824 memcpy(&priv->wep_keys[keyconf->keyidx].key, &keyconf->key, 844 memcpy(&ctx->wep_keys[keyconf->keyidx].key, &keyconf->key,
825 keyconf->keylen); 845 keyconf->keylen);
826 846
827 ret = iwl_send_static_wepkey_cmd(priv, 0); 847 ret = iwl_send_static_wepkey_cmd(priv, ctx, false);
828 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n", 848 IWL_DEBUG_WEP(priv, "Set default WEP key: len=%d idx=%d ret=%d\n",
829 keyconf->keylen, keyconf->keyidx, ret); 849 keyconf->keylen, keyconf->keyidx, ret);
830 850
@@ -833,8 +853,9 @@ int iwl_set_default_wep_key(struct iwl_priv *priv,
833EXPORT_SYMBOL(iwl_set_default_wep_key); 853EXPORT_SYMBOL(iwl_set_default_wep_key);
834 854
835static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv, 855static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
836 struct ieee80211_key_conf *keyconf, 856 struct iwl_rxon_context *ctx,
837 u8 sta_id) 857 struct ieee80211_key_conf *keyconf,
858 u8 sta_id)
838{ 859{
839 unsigned long flags; 860 unsigned long flags;
840 __le16 key_flags = 0; 861 __le16 key_flags = 0;
@@ -851,7 +872,7 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
851 if (keyconf->keylen == WEP_KEY_LEN_128) 872 if (keyconf->keylen == WEP_KEY_LEN_128)
852 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK; 873 key_flags |= STA_KEY_FLG_KEY_SIZE_MSK;
853 874
854 if (sta_id == priv->hw_params.bcast_sta_id) 875 if (sta_id == ctx->bcast_sta_id)
855 key_flags |= STA_KEY_MULTICAST_MSK; 876 key_flags |= STA_KEY_MULTICAST_MSK;
856 877
857 spin_lock_irqsave(&priv->sta_lock, flags); 878 spin_lock_irqsave(&priv->sta_lock, flags);
@@ -887,8 +908,9 @@ static int iwl_set_wep_dynamic_key_info(struct iwl_priv *priv,
887} 908}
888 909
889static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv, 910static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
890 struct ieee80211_key_conf *keyconf, 911 struct iwl_rxon_context *ctx,
891 u8 sta_id) 912 struct ieee80211_key_conf *keyconf,
913 u8 sta_id)
892{ 914{
893 unsigned long flags; 915 unsigned long flags;
894 __le16 key_flags = 0; 916 __le16 key_flags = 0;
@@ -900,7 +922,7 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
900 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 922 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
901 key_flags &= ~STA_KEY_FLG_INVALID; 923 key_flags &= ~STA_KEY_FLG_INVALID;
902 924
903 if (sta_id == priv->hw_params.bcast_sta_id) 925 if (sta_id == ctx->bcast_sta_id)
904 key_flags |= STA_KEY_MULTICAST_MSK; 926 key_flags |= STA_KEY_MULTICAST_MSK;
905 927
906 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 928 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
@@ -936,8 +958,9 @@ static int iwl_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
936} 958}
937 959
938static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv, 960static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
939 struct ieee80211_key_conf *keyconf, 961 struct iwl_rxon_context *ctx,
940 u8 sta_id) 962 struct ieee80211_key_conf *keyconf,
963 u8 sta_id)
941{ 964{
942 unsigned long flags; 965 unsigned long flags;
943 int ret = 0; 966 int ret = 0;
@@ -947,7 +970,7 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
947 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 970 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
948 key_flags &= ~STA_KEY_FLG_INVALID; 971 key_flags &= ~STA_KEY_FLG_INVALID;
949 972
950 if (sta_id == priv->hw_params.bcast_sta_id) 973 if (sta_id == ctx->bcast_sta_id)
951 key_flags |= STA_KEY_MULTICAST_MSK; 974 key_flags |= STA_KEY_MULTICAST_MSK;
952 975
953 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 976 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
@@ -982,8 +1005,9 @@ static int iwl_set_tkip_dynamic_key_info(struct iwl_priv *priv,
982} 1005}
983 1006
984void iwl_update_tkip_key(struct iwl_priv *priv, 1007void iwl_update_tkip_key(struct iwl_priv *priv,
985 struct ieee80211_key_conf *keyconf, 1008 struct iwl_rxon_context *ctx,
986 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key) 1009 struct ieee80211_key_conf *keyconf,
1010 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key)
987{ 1011{
988 u8 sta_id; 1012 u8 sta_id;
989 unsigned long flags; 1013 unsigned long flags;
@@ -995,7 +1019,7 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
995 return; 1019 return;
996 } 1020 }
997 1021
998 sta_id = iwl_sta_id_or_broadcast(priv, sta); 1022 sta_id = iwl_sta_id_or_broadcast(priv, ctx, sta);
999 if (sta_id == IWL_INVALID_STATION) 1023 if (sta_id == IWL_INVALID_STATION)
1000 return; 1024 return;
1001 1025
@@ -1018,8 +1042,9 @@ void iwl_update_tkip_key(struct iwl_priv *priv,
1018EXPORT_SYMBOL(iwl_update_tkip_key); 1042EXPORT_SYMBOL(iwl_update_tkip_key);
1019 1043
1020int iwl_remove_dynamic_key(struct iwl_priv *priv, 1044int iwl_remove_dynamic_key(struct iwl_priv *priv,
1021 struct ieee80211_key_conf *keyconf, 1045 struct iwl_rxon_context *ctx,
1022 u8 sta_id) 1046 struct ieee80211_key_conf *keyconf,
1047 u8 sta_id)
1023{ 1048{
1024 unsigned long flags; 1049 unsigned long flags;
1025 u16 key_flags; 1050 u16 key_flags;
@@ -1028,7 +1053,7 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
1028 1053
1029 lockdep_assert_held(&priv->mutex); 1054 lockdep_assert_held(&priv->mutex);
1030 1055
1031 priv->key_mapping_key--; 1056 ctx->key_mapping_keys--;
1032 1057
1033 spin_lock_irqsave(&priv->sta_lock, flags); 1058 spin_lock_irqsave(&priv->sta_lock, flags);
1034 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags); 1059 key_flags = le16_to_cpu(priv->stations[sta_id].sta.key.key_flags);
@@ -1080,26 +1105,26 @@ int iwl_remove_dynamic_key(struct iwl_priv *priv,
1080} 1105}
1081EXPORT_SYMBOL(iwl_remove_dynamic_key); 1106EXPORT_SYMBOL(iwl_remove_dynamic_key);
1082 1107
1083int iwl_set_dynamic_key(struct iwl_priv *priv, 1108int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1084 struct ieee80211_key_conf *keyconf, u8 sta_id) 1109 struct ieee80211_key_conf *keyconf, u8 sta_id)
1085{ 1110{
1086 int ret; 1111 int ret;
1087 1112
1088 lockdep_assert_held(&priv->mutex); 1113 lockdep_assert_held(&priv->mutex);
1089 1114
1090 priv->key_mapping_key++; 1115 ctx->key_mapping_keys++;
1091 keyconf->hw_key_idx = HW_KEY_DYNAMIC; 1116 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
1092 1117
1093 switch (keyconf->cipher) { 1118 switch (keyconf->cipher) {
1094 case WLAN_CIPHER_SUITE_CCMP: 1119 case WLAN_CIPHER_SUITE_CCMP:
1095 ret = iwl_set_ccmp_dynamic_key_info(priv, keyconf, sta_id); 1120 ret = iwl_set_ccmp_dynamic_key_info(priv, ctx, keyconf, sta_id);
1096 break; 1121 break;
1097 case WLAN_CIPHER_SUITE_TKIP: 1122 case WLAN_CIPHER_SUITE_TKIP:
1098 ret = iwl_set_tkip_dynamic_key_info(priv, keyconf, sta_id); 1123 ret = iwl_set_tkip_dynamic_key_info(priv, ctx, keyconf, sta_id);
1099 break; 1124 break;
1100 case WLAN_CIPHER_SUITE_WEP40: 1125 case WLAN_CIPHER_SUITE_WEP40:
1101 case WLAN_CIPHER_SUITE_WEP104: 1126 case WLAN_CIPHER_SUITE_WEP104:
1102 ret = iwl_set_wep_dynamic_key_info(priv, keyconf, sta_id); 1127 ret = iwl_set_wep_dynamic_key_info(priv, ctx, keyconf, sta_id);
1103 break; 1128 break;
1104 default: 1129 default:
1105 IWL_ERR(priv, 1130 IWL_ERR(priv,
@@ -1149,16 +1174,16 @@ static inline void iwl_dump_lq_cmd(struct iwl_priv *priv,
1149 * RXON flags are updated and when LQ command is updated. 1174 * RXON flags are updated and when LQ command is updated.
1150 */ 1175 */
1151static bool is_lq_table_valid(struct iwl_priv *priv, 1176static bool is_lq_table_valid(struct iwl_priv *priv,
1177 struct iwl_rxon_context *ctx,
1152 struct iwl_link_quality_cmd *lq) 1178 struct iwl_link_quality_cmd *lq)
1153{ 1179{
1154 int i; 1180 int i;
1155 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1156 1181
1157 if (ht_conf->is_ht) 1182 if (ctx->ht.enabled)
1158 return true; 1183 return true;
1159 1184
1160 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", 1185 IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n",
1161 priv->active_rxon.channel); 1186 ctx->active.channel);
1162 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { 1187 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
1163 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { 1188 if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) {
1164 IWL_DEBUG_INFO(priv, 1189 IWL_DEBUG_INFO(priv,
@@ -1180,7 +1205,7 @@ static bool is_lq_table_valid(struct iwl_priv *priv,
1180 * this case to clear the state indicating that station creation is in 1205 * this case to clear the state indicating that station creation is in
1181 * progress. 1206 * progress.
1182 */ 1207 */
1183int iwl_send_lq_cmd(struct iwl_priv *priv, 1208int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1184 struct iwl_link_quality_cmd *lq, u8 flags, bool init) 1209 struct iwl_link_quality_cmd *lq, u8 flags, bool init)
1185{ 1210{
1186 int ret = 0; 1211 int ret = 0;
@@ -1199,7 +1224,7 @@ int iwl_send_lq_cmd(struct iwl_priv *priv,
1199 iwl_dump_lq_cmd(priv, lq); 1224 iwl_dump_lq_cmd(priv, lq);
1200 BUG_ON(init && (cmd.flags & CMD_ASYNC)); 1225 BUG_ON(init && (cmd.flags & CMD_ASYNC));
1201 1226
1202 if (is_lq_table_valid(priv, lq)) 1227 if (is_lq_table_valid(priv, ctx, lq))
1203 ret = iwl_send_cmd(priv, &cmd); 1228 ret = iwl_send_cmd(priv, &cmd);
1204 else 1229 else
1205 ret = -EINVAL; 1230 ret = -EINVAL;
@@ -1225,14 +1250,15 @@ EXPORT_SYMBOL(iwl_send_lq_cmd);
1225 * and marks it driver active, so that it will be restored to the 1250 * and marks it driver active, so that it will be restored to the
1226 * device at the next best time. 1251 * device at the next best time.
1227 */ 1252 */
1228int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq) 1253int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
1254 bool init_lq)
1229{ 1255{
1230 struct iwl_link_quality_cmd *link_cmd; 1256 struct iwl_link_quality_cmd *link_cmd;
1231 unsigned long flags; 1257 unsigned long flags;
1232 u8 sta_id; 1258 u8 sta_id;
1233 1259
1234 spin_lock_irqsave(&priv->sta_lock, flags); 1260 spin_lock_irqsave(&priv->sta_lock, flags);
1235 sta_id = iwl_prep_station(priv, iwl_bcast_addr, false, NULL); 1261 sta_id = iwl_prep_station(priv, ctx, iwl_bcast_addr, false, NULL);
1236 if (sta_id == IWL_INVALID_STATION) { 1262 if (sta_id == IWL_INVALID_STATION) {
1237 IWL_ERR(priv, "Unable to prepare broadcast station\n"); 1263 IWL_ERR(priv, "Unable to prepare broadcast station\n");
1238 spin_unlock_irqrestore(&priv->sta_lock, flags); 1264 spin_unlock_irqrestore(&priv->sta_lock, flags);
@@ -1267,11 +1293,12 @@ EXPORT_SYMBOL_GPL(iwl_alloc_bcast_station);
1267 * Only used by iwlagn. Placed here to have all bcast station management 1293 * Only used by iwlagn. Placed here to have all bcast station management
1268 * code together. 1294 * code together.
1269 */ 1295 */
1270int iwl_update_bcast_station(struct iwl_priv *priv) 1296static int iwl_update_bcast_station(struct iwl_priv *priv,
1297 struct iwl_rxon_context *ctx)
1271{ 1298{
1272 unsigned long flags; 1299 unsigned long flags;
1273 struct iwl_link_quality_cmd *link_cmd; 1300 struct iwl_link_quality_cmd *link_cmd;
1274 u8 sta_id = priv->hw_params.bcast_sta_id; 1301 u8 sta_id = ctx->bcast_sta_id;
1275 1302
1276 link_cmd = iwl_sta_alloc_lq(priv, sta_id); 1303 link_cmd = iwl_sta_alloc_lq(priv, sta_id);
1277 if (!link_cmd) { 1304 if (!link_cmd) {
@@ -1289,9 +1316,23 @@ int iwl_update_bcast_station(struct iwl_priv *priv)
1289 1316
1290 return 0; 1317 return 0;
1291} 1318}
1292EXPORT_SYMBOL_GPL(iwl_update_bcast_station);
1293 1319
1294void iwl_dealloc_bcast_station(struct iwl_priv *priv) 1320int iwl_update_bcast_stations(struct iwl_priv *priv)
1321{
1322 struct iwl_rxon_context *ctx;
1323 int ret = 0;
1324
1325 for_each_context(priv, ctx) {
1326 ret = iwl_update_bcast_station(priv, ctx);
1327 if (ret)
1328 break;
1329 }
1330
1331 return ret;
1332}
1333EXPORT_SYMBOL_GPL(iwl_update_bcast_stations);
1334
1335void iwl_dealloc_bcast_stations(struct iwl_priv *priv)
1295{ 1336{
1296 unsigned long flags; 1337 unsigned long flags;
1297 int i; 1338 int i;
@@ -1309,7 +1350,7 @@ void iwl_dealloc_bcast_station(struct iwl_priv *priv)
1309 } 1350 }
1310 spin_unlock_irqrestore(&priv->sta_lock, flags); 1351 spin_unlock_irqrestore(&priv->sta_lock, flags);
1311} 1352}
1312EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_station); 1353EXPORT_SYMBOL_GPL(iwl_dealloc_bcast_stations);
1313 1354
1314/** 1355/**
1315 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table 1356 * iwl_sta_tx_modify_enable_tid - Enable Tx for this TID in station table
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h
index d38a350ba0b..56bad3f60d8 100644
--- a/drivers/net/wireless/iwlwifi/iwl-sta.h
+++ b/drivers/net/wireless/iwlwifi/iwl-sta.h
@@ -44,32 +44,37 @@
44 44
45 45
46int iwl_remove_default_wep_key(struct iwl_priv *priv, 46int iwl_remove_default_wep_key(struct iwl_priv *priv,
47 struct iwl_rxon_context *ctx,
47 struct ieee80211_key_conf *key); 48 struct ieee80211_key_conf *key);
48int iwl_set_default_wep_key(struct iwl_priv *priv, 49int iwl_set_default_wep_key(struct iwl_priv *priv,
50 struct iwl_rxon_context *ctx,
49 struct ieee80211_key_conf *key); 51 struct ieee80211_key_conf *key);
50int iwl_restore_default_wep_keys(struct iwl_priv *priv); 52int iwl_restore_default_wep_keys(struct iwl_priv *priv,
51int iwl_set_dynamic_key(struct iwl_priv *priv, 53 struct iwl_rxon_context *ctx);
54int iwl_set_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
52 struct ieee80211_key_conf *key, u8 sta_id); 55 struct ieee80211_key_conf *key, u8 sta_id);
53int iwl_remove_dynamic_key(struct iwl_priv *priv, 56int iwl_remove_dynamic_key(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
54 struct ieee80211_key_conf *key, u8 sta_id); 57 struct ieee80211_key_conf *key, u8 sta_id);
55void iwl_update_tkip_key(struct iwl_priv *priv, 58void iwl_update_tkip_key(struct iwl_priv *priv,
56 struct ieee80211_key_conf *keyconf, 59 struct iwl_rxon_context *ctx,
57 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key); 60 struct ieee80211_key_conf *keyconf,
58 61 struct ieee80211_sta *sta, u32 iv32, u16 *phase1key);
59void iwl_restore_stations(struct iwl_priv *priv); 62
60void iwl_clear_ucode_stations(struct iwl_priv *priv); 63void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx);
61int iwl_alloc_bcast_station(struct iwl_priv *priv, bool init_lq); 64void iwl_clear_ucode_stations(struct iwl_priv *priv,
62void iwl_dealloc_bcast_station(struct iwl_priv *priv); 65 struct iwl_rxon_context *ctx);
63int iwl_update_bcast_station(struct iwl_priv *priv); 66int iwl_alloc_bcast_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
67 bool init_lq);
68void iwl_dealloc_bcast_stations(struct iwl_priv *priv);
69int iwl_update_bcast_stations(struct iwl_priv *priv);
64int iwl_get_free_ucode_key_index(struct iwl_priv *priv); 70int iwl_get_free_ucode_key_index(struct iwl_priv *priv);
65int iwl_send_add_sta(struct iwl_priv *priv, 71int iwl_send_add_sta(struct iwl_priv *priv,
66 struct iwl_addsta_cmd *sta, u8 flags); 72 struct iwl_addsta_cmd *sta, u8 flags);
67int iwl_add_bssid_station(struct iwl_priv *priv, const u8 *addr, bool init_rs, 73int iwl_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
68 u8 *sta_id_r); 74 const u8 *addr, bool init_rs, u8 *sta_id_r);
69int iwl_add_station_common(struct iwl_priv *priv, const u8 *addr, 75int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
70 bool is_ap, 76 const u8 *addr, bool is_ap,
71 struct ieee80211_sta_ht_cap *ht_info, 77 struct ieee80211_sta *sta, u8 *sta_id_r);
72 u8 *sta_id_r);
73int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, 78int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id,
74 const u8 *addr); 79 const u8 *addr);
75int iwl_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, 80int iwl_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
@@ -94,20 +99,25 @@ void iwl_sta_modify_sleep_tx_count(struct iwl_priv *priv, int sta_id, int cnt);
94static inline void iwl_clear_driver_stations(struct iwl_priv *priv) 99static inline void iwl_clear_driver_stations(struct iwl_priv *priv)
95{ 100{
96 unsigned long flags; 101 unsigned long flags;
102 struct iwl_rxon_context *ctx;
97 103
98 spin_lock_irqsave(&priv->sta_lock, flags); 104 spin_lock_irqsave(&priv->sta_lock, flags);
99 memset(priv->stations, 0, sizeof(priv->stations)); 105 memset(priv->stations, 0, sizeof(priv->stations));
100 priv->num_stations = 0; 106 priv->num_stations = 0;
101 107
102 /*
103 * Remove all key information that is not stored as part of station
104 * information since mac80211 may not have had a
105 * chance to remove all the keys. When device is reconfigured by
106 * mac80211 after an error all keys will be reconfigured.
107 */
108 priv->ucode_key_table = 0; 108 priv->ucode_key_table = 0;
109 priv->key_mapping_key = 0; 109
110 memset(priv->wep_keys, 0, sizeof(priv->wep_keys)); 110 for_each_context(priv, ctx) {
111 /*
112 * Remove all key information that is not stored as part
113 * of station information since mac80211 may not have had
114 * a chance to remove all the keys. When device is
115 * reconfigured by mac80211 after an error all keys will
116 * be reconfigured.
117 */
118 memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys));
119 ctx->key_mapping_keys = 0;
120 }
111 121
112 spin_unlock_irqrestore(&priv->sta_lock, flags); 122 spin_unlock_irqrestore(&priv->sta_lock, flags);
113} 123}
@@ -123,6 +133,7 @@ static inline int iwl_sta_id(struct ieee80211_sta *sta)
123/** 133/**
124 * iwl_sta_id_or_broadcast - return sta_id or broadcast sta 134 * iwl_sta_id_or_broadcast - return sta_id or broadcast sta
125 * @priv: iwl priv 135 * @priv: iwl priv
136 * @context: the current context
126 * @sta: mac80211 station 137 * @sta: mac80211 station
127 * 138 *
128 * In certain circumstances mac80211 passes a station pointer 139 * In certain circumstances mac80211 passes a station pointer
@@ -131,12 +142,13 @@ static inline int iwl_sta_id(struct ieee80211_sta *sta)
131 * inline wraps that pattern. 142 * inline wraps that pattern.
132 */ 143 */
133static inline int iwl_sta_id_or_broadcast(struct iwl_priv *priv, 144static inline int iwl_sta_id_or_broadcast(struct iwl_priv *priv,
145 struct iwl_rxon_context *context,
134 struct ieee80211_sta *sta) 146 struct ieee80211_sta *sta)
135{ 147{
136 int sta_id; 148 int sta_id;
137 149
138 if (!sta) 150 if (!sta)
139 return priv->hw_params.bcast_sta_id; 151 return context->bcast_sta_id;
140 152
141 sta_id = iwl_sta_id(sta); 153 sta_id = iwl_sta_id(sta);
142 154
diff --git a/drivers/net/wireless/iwlwifi/iwl-tx.c b/drivers/net/wireless/iwlwifi/iwl-tx.c
index c308dab1467..347d3dc6a01 100644
--- a/drivers/net/wireless/iwlwifi/iwl-tx.c
+++ b/drivers/net/wireless/iwlwifi/iwl-tx.c
@@ -134,7 +134,7 @@ EXPORT_SYMBOL(iwl_tx_queue_free);
134 */ 134 */
135void iwl_cmd_queue_free(struct iwl_priv *priv) 135void iwl_cmd_queue_free(struct iwl_priv *priv)
136{ 136{
137 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; 137 struct iwl_tx_queue *txq = &priv->txq[priv->cmd_queue];
138 struct iwl_queue *q = &txq->q; 138 struct iwl_queue *q = &txq->q;
139 struct device *dev = &priv->pci_dev->dev; 139 struct device *dev = &priv->pci_dev->dev;
140 int i; 140 int i;
@@ -271,7 +271,7 @@ static int iwl_tx_queue_alloc(struct iwl_priv *priv,
271 271
272 /* Driver private data, only for Tx (not command) queues, 272 /* Driver private data, only for Tx (not command) queues,
273 * not shared with device. */ 273 * not shared with device. */
274 if (id != IWL_CMD_QUEUE_NUM) { 274 if (id != priv->cmd_queue) {
275 txq->txb = kzalloc(sizeof(txq->txb[0]) * 275 txq->txb = kzalloc(sizeof(txq->txb[0]) *
276 TFD_QUEUE_SIZE_MAX, GFP_KERNEL); 276 TFD_QUEUE_SIZE_MAX, GFP_KERNEL);
277 if (!txq->txb) { 277 if (!txq->txb) {
@@ -314,13 +314,13 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
314 314
315 /* 315 /*
316 * Alloc buffer array for commands (Tx or other types of commands). 316 * Alloc buffer array for commands (Tx or other types of commands).
317 * For the command queue (#4), allocate command space + one big 317 * For the command queue (#4/#9), allocate command space + one big
318 * command for scan, since scan command is very huge; the system will 318 * command for scan, since scan command is very huge; the system will
319 * not have two scans at the same time, so only one is needed. 319 * not have two scans at the same time, so only one is needed.
320 * For normal Tx queues (all other queues), no super-size command 320 * For normal Tx queues (all other queues), no super-size command
321 * space is needed. 321 * space is needed.
322 */ 322 */
323 if (txq_id == IWL_CMD_QUEUE_NUM) 323 if (txq_id == priv->cmd_queue)
324 actual_slots++; 324 actual_slots++;
325 325
326 txq->meta = kzalloc(sizeof(struct iwl_cmd_meta) * actual_slots, 326 txq->meta = kzalloc(sizeof(struct iwl_cmd_meta) * actual_slots,
@@ -355,7 +355,7 @@ int iwl_tx_queue_init(struct iwl_priv *priv, struct iwl_tx_queue *txq,
355 * need an swq_id so don't set one to catch errors, all others can 355 * need an swq_id so don't set one to catch errors, all others can
356 * be set up to the identity mapping. 356 * be set up to the identity mapping.
357 */ 357 */
358 if (txq_id != IWL_CMD_QUEUE_NUM) 358 if (txq_id != priv->cmd_queue)
359 txq->swq_id = txq_id; 359 txq->swq_id = txq_id;
360 360
361 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise 361 /* TFD_QUEUE_SIZE_MAX must be power-of-two size, otherwise
@@ -385,7 +385,7 @@ void iwl_tx_queue_reset(struct iwl_priv *priv, struct iwl_tx_queue *txq,
385{ 385{
386 int actual_slots = slots_num; 386 int actual_slots = slots_num;
387 387
388 if (txq_id == IWL_CMD_QUEUE_NUM) 388 if (txq_id == priv->cmd_queue)
389 actual_slots++; 389 actual_slots++;
390 390
391 memset(txq->meta, 0, sizeof(struct iwl_cmd_meta) * actual_slots); 391 memset(txq->meta, 0, sizeof(struct iwl_cmd_meta) * actual_slots);
@@ -413,7 +413,7 @@ EXPORT_SYMBOL(iwl_tx_queue_reset);
413 */ 413 */
414int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd) 414int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
415{ 415{
416 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; 416 struct iwl_tx_queue *txq = &priv->txq[priv->cmd_queue];
417 struct iwl_queue *q = &txq->q; 417 struct iwl_queue *q = &txq->q;
418 struct iwl_device_cmd *out_cmd; 418 struct iwl_device_cmd *out_cmd;
419 struct iwl_cmd_meta *out_meta; 419 struct iwl_cmd_meta *out_meta;
@@ -483,7 +483,7 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
483 * information */ 483 * information */
484 484
485 out_cmd->hdr.flags = 0; 485 out_cmd->hdr.flags = 0;
486 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(IWL_CMD_QUEUE_NUM) | 486 out_cmd->hdr.sequence = cpu_to_le16(QUEUE_TO_SEQ(priv->cmd_queue) |
487 INDEX_TO_SEQ(q->write_ptr)); 487 INDEX_TO_SEQ(q->write_ptr));
488 if (cmd->flags & CMD_SIZE_HUGE) 488 if (cmd->flags & CMD_SIZE_HUGE)
489 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME; 489 out_cmd->hdr.sequence |= SEQ_HUGE_FRAME;
@@ -500,15 +500,15 @@ int iwl_enqueue_hcmd(struct iwl_priv *priv, struct iwl_host_cmd *cmd)
500 get_cmd_string(out_cmd->hdr.cmd), 500 get_cmd_string(out_cmd->hdr.cmd),
501 out_cmd->hdr.cmd, 501 out_cmd->hdr.cmd,
502 le16_to_cpu(out_cmd->hdr.sequence), fix_size, 502 le16_to_cpu(out_cmd->hdr.sequence), fix_size,
503 q->write_ptr, idx, IWL_CMD_QUEUE_NUM); 503 q->write_ptr, idx, priv->cmd_queue);
504 break; 504 break;
505 default: 505 default:
506 IWL_DEBUG_HC(priv, "Sending command %s (#%x), seq: 0x%04X, " 506 IWL_DEBUG_HC(priv, "Sending command %s (#%x), seq: 0x%04X, "
507 "%d bytes at %d[%d]:%d\n", 507 "%d bytes at %d[%d]:%d\n",
508 get_cmd_string(out_cmd->hdr.cmd), 508 get_cmd_string(out_cmd->hdr.cmd),
509 out_cmd->hdr.cmd, 509 out_cmd->hdr.cmd,
510 le16_to_cpu(out_cmd->hdr.sequence), fix_size, 510 le16_to_cpu(out_cmd->hdr.sequence), fix_size,
511 q->write_ptr, idx, IWL_CMD_QUEUE_NUM); 511 q->write_ptr, idx, priv->cmd_queue);
512 } 512 }
513#endif 513#endif
514 txq->need_update = 1; 514 txq->need_update = 1;
@@ -587,16 +587,16 @@ void iwl_tx_cmd_complete(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
587 bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME); 587 bool huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
588 struct iwl_device_cmd *cmd; 588 struct iwl_device_cmd *cmd;
589 struct iwl_cmd_meta *meta; 589 struct iwl_cmd_meta *meta;
590 struct iwl_tx_queue *txq = &priv->txq[IWL_CMD_QUEUE_NUM]; 590 struct iwl_tx_queue *txq = &priv->txq[priv->cmd_queue];
591 591
592 /* If a Tx command is being handled and it isn't in the actual 592 /* If a Tx command is being handled and it isn't in the actual
593 * command queue then there a command routing bug has been introduced 593 * command queue then there a command routing bug has been introduced
594 * in the queue management code. */ 594 * in the queue management code. */
595 if (WARN(txq_id != IWL_CMD_QUEUE_NUM, 595 if (WARN(txq_id != priv->cmd_queue,
596 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n", 596 "wrong command queue %d (should be %d), sequence 0x%X readp=%d writep=%d\n",
597 txq_id, sequence, 597 txq_id, priv->cmd_queue, sequence,
598 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr, 598 priv->txq[priv->cmd_queue].q.read_ptr,
599 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) { 599 priv->txq[priv->cmd_queue].q.write_ptr)) {
600 iwl_print_hex_error(priv, pkt, 32); 600 iwl_print_hex_error(priv, pkt, 32);
601 return; 601 return;
602 } 602 }
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 53e6cbb3aaa..68e624afb98 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -144,7 +144,7 @@ static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
144 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK); 144 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
145 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS); 145 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
146 146
147 if (sta_id == priv->hw_params.bcast_sta_id) 147 if (sta_id == priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id)
148 key_flags |= STA_KEY_MULTICAST_MSK; 148 key_flags |= STA_KEY_MULTICAST_MSK;
149 149
150 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV; 150 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
@@ -317,7 +317,7 @@ unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
317 int left) 317 int left)
318{ 318{
319 319
320 if (!iwl_is_associated(priv) || !priv->ibss_beacon) 320 if (!iwl_is_associated(priv, IWL_RXON_CTX_BSS) || !priv->ibss_beacon)
321 return 0; 321 return 0;
322 322
323 if (priv->ibss_beacon->len > left) 323 if (priv->ibss_beacon->len > left)
@@ -343,7 +343,8 @@ static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
343 return -ENOMEM; 343 return -ENOMEM;
344 } 344 }
345 345
346 rate = iwl_rate_get_lowest_plcp(priv); 346 rate = iwl_rate_get_lowest_plcp(priv,
347 &priv->contexts[IWL_RXON_CTX_BSS]);
347 348
348 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate); 349 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
349 350
@@ -512,7 +513,9 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
512 hdr_len = ieee80211_hdrlen(fc); 513 hdr_len = ieee80211_hdrlen(fc);
513 514
514 /* Find index into station table for destination station */ 515 /* Find index into station table for destination station */
515 sta_id = iwl_sta_id_or_broadcast(priv, info->control.sta); 516 sta_id = iwl_sta_id_or_broadcast(
517 priv, &priv->contexts[IWL_RXON_CTX_BSS],
518 info->control.sta);
516 if (sta_id == IWL_INVALID_STATION) { 519 if (sta_id == IWL_INVALID_STATION) {
517 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", 520 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
518 hdr->addr1); 521 hdr->addr1);
@@ -542,6 +545,7 @@ static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
542 /* Set up driver data for this TFD */ 545 /* Set up driver data for this TFD */
543 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info)); 546 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
544 txq->txb[q->write_ptr].skb = skb; 547 txq->txb[q->write_ptr].skb = skb;
548 txq->txb[q->write_ptr].ctx = &priv->contexts[IWL_RXON_CTX_BSS];
545 549
546 /* Init first empty entry in queue's array of Tx/cmd buffers */ 550 /* Init first empty entry in queue's array of Tx/cmd buffers */
547 out_cmd = txq->cmd[idx]; 551 out_cmd = txq->cmd[idx];
@@ -683,11 +687,12 @@ static int iwl3945_get_measurement(struct iwl_priv *priv,
683 int rc; 687 int rc;
684 int spectrum_resp_status; 688 int spectrum_resp_status;
685 int duration = le16_to_cpu(params->duration); 689 int duration = le16_to_cpu(params->duration);
690 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
686 691
687 if (iwl_is_associated(priv)) 692 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
688 add_time = iwl_usecs_to_beacons(priv, 693 add_time = iwl_usecs_to_beacons(priv,
689 le64_to_cpu(params->start_time) - priv->_3945.last_tsf, 694 le64_to_cpu(params->start_time) - priv->_3945.last_tsf,
690 le16_to_cpu(priv->rxon_timing.beacon_interval)); 695 le16_to_cpu(ctx->timing.beacon_interval));
691 696
692 memset(&spectrum, 0, sizeof(spectrum)); 697 memset(&spectrum, 0, sizeof(spectrum));
693 698
@@ -698,18 +703,18 @@ static int iwl3945_get_measurement(struct iwl_priv *priv,
698 cmd.len = sizeof(spectrum); 703 cmd.len = sizeof(spectrum);
699 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len)); 704 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
700 705
701 if (iwl_is_associated(priv)) 706 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS))
702 spectrum.start_time = 707 spectrum.start_time =
703 iwl_add_beacon_time(priv, 708 iwl_add_beacon_time(priv,
704 priv->_3945.last_beacon_time, add_time, 709 priv->_3945.last_beacon_time, add_time,
705 le16_to_cpu(priv->rxon_timing.beacon_interval)); 710 le16_to_cpu(ctx->timing.beacon_interval));
706 else 711 else
707 spectrum.start_time = 0; 712 spectrum.start_time = 0;
708 713
709 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT); 714 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
710 spectrum.channels[0].channel = params->channel; 715 spectrum.channels[0].channel = params->channel;
711 spectrum.channels[0].type = type; 716 spectrum.channels[0].type = type;
712 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK) 717 if (ctx->active.flags & RXON_FLG_BAND_24G_MSK)
713 spectrum.flags |= RXON_FLG_BAND_24G_MSK | 718 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
714 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK; 719 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
715 720
@@ -798,7 +803,8 @@ static void iwl3945_bg_beacon_update(struct work_struct *work)
798 struct sk_buff *beacon; 803 struct sk_buff *beacon;
799 804
800 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */ 805 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
801 beacon = ieee80211_beacon_get(priv->hw, priv->vif); 806 beacon = ieee80211_beacon_get(priv->hw,
807 priv->contexts[IWL_RXON_CTX_BSS].vif);
802 808
803 if (!beacon) { 809 if (!beacon) {
804 IWL_ERR(priv, "update beacon failed\n"); 810 IWL_ERR(priv, "update beacon failed\n");
@@ -2468,6 +2474,7 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2468{ 2474{
2469 int thermal_spin = 0; 2475 int thermal_spin = 0;
2470 u32 rfkill; 2476 u32 rfkill;
2477 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2471 2478
2472 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n"); 2479 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
2473 2480
@@ -2525,22 +2532,22 @@ static void iwl3945_alive_start(struct iwl_priv *priv)
2525 2532
2526 iwl_power_update_mode(priv, true); 2533 iwl_power_update_mode(priv, true);
2527 2534
2528 if (iwl_is_associated(priv)) { 2535 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
2529 struct iwl3945_rxon_cmd *active_rxon = 2536 struct iwl3945_rxon_cmd *active_rxon =
2530 (struct iwl3945_rxon_cmd *)(&priv->active_rxon); 2537 (struct iwl3945_rxon_cmd *)(&ctx->active);
2531 2538
2532 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 2539 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
2533 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK; 2540 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2534 } else { 2541 } else {
2535 /* Initialize our rx_config data */ 2542 /* Initialize our rx_config data */
2536 iwl_connection_init_rx_config(priv, NULL); 2543 iwl_connection_init_rx_config(priv, ctx);
2537 } 2544 }
2538 2545
2539 /* Configure Bluetooth device coexistence support */ 2546 /* Configure Bluetooth device coexistence support */
2540 priv->cfg->ops->hcmd->send_bt_config(priv); 2547 priv->cfg->ops->hcmd->send_bt_config(priv);
2541 2548
2542 /* Configure the adapter for unassociated operation */ 2549 /* Configure the adapter for unassociated operation */
2543 iwlcore_commit_rxon(priv); 2550 iwlcore_commit_rxon(priv, ctx);
2544 2551
2545 iwl3945_reg_txpower_periodic(priv); 2552 iwl3945_reg_txpower_periodic(priv);
2546 2553
@@ -2577,8 +2584,8 @@ static void __iwl3945_down(struct iwl_priv *priv)
2577 del_timer_sync(&priv->monitor_recover); 2584 del_timer_sync(&priv->monitor_recover);
2578 2585
2579 /* Station information will now be cleared in device */ 2586 /* Station information will now be cleared in device */
2580 iwl_clear_ucode_stations(priv); 2587 iwl_clear_ucode_stations(priv, NULL);
2581 iwl_dealloc_bcast_station(priv); 2588 iwl_dealloc_bcast_stations(priv);
2582 iwl_clear_driver_stations(priv); 2589 iwl_clear_driver_stations(priv);
2583 2590
2584 /* Unblock any waiting calls */ 2591 /* Unblock any waiting calls */
@@ -2660,7 +2667,8 @@ static int __iwl3945_up(struct iwl_priv *priv)
2660{ 2667{
2661 int rc, i; 2668 int rc, i;
2662 2669
2663 rc = iwl_alloc_bcast_station(priv, false); 2670 rc = iwl_alloc_bcast_station(priv, &priv->contexts[IWL_RXON_CTX_BSS],
2671 false);
2664 if (rc) 2672 if (rc)
2665 return rc; 2673 return rc;
2666 2674
@@ -2883,7 +2891,7 @@ void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
2883 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; 2891 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
2884 scan->quiet_time = IWL_ACTIVE_QUIET_TIME; 2892 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
2885 2893
2886 if (iwl_is_associated(priv)) { 2894 if (iwl_is_associated(priv, IWL_RXON_CTX_BSS)) {
2887 u16 interval = 0; 2895 u16 interval = 0;
2888 u32 extra; 2896 u32 extra;
2889 u32 suspend_time = 100; 2897 u32 suspend_time = 100;
@@ -2944,7 +2952,7 @@ void iwl3945_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif)
2944 /* We don't build a direct scan probe request; the uCode will do 2952 /* We don't build a direct scan probe request; the uCode will do
2945 * that based on the direct_mask added to each channel entry */ 2953 * that based on the direct_mask added to each channel entry */
2946 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; 2954 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
2947 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id; 2955 scan->tx_cmd.sta_id = priv->contexts[IWL_RXON_CTX_BSS].bcast_sta_id;
2948 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 2956 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2949 2957
2950 /* flags + rate selection */ 2958 /* flags + rate selection */
@@ -3042,8 +3050,10 @@ static void iwl3945_bg_restart(struct work_struct *data)
3042 return; 3050 return;
3043 3051
3044 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) { 3052 if (test_and_clear_bit(STATUS_FW_ERROR, &priv->status)) {
3053 struct iwl_rxon_context *ctx;
3045 mutex_lock(&priv->mutex); 3054 mutex_lock(&priv->mutex);
3046 priv->vif = NULL; 3055 for_each_context(priv, ctx)
3056 ctx->vif = NULL;
3047 priv->is_open = 0; 3057 priv->is_open = 0;
3048 mutex_unlock(&priv->mutex); 3058 mutex_unlock(&priv->mutex);
3049 iwl3945_down(priv); 3059 iwl3945_down(priv);
@@ -3077,6 +3087,7 @@ void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3077{ 3087{
3078 int rc = 0; 3088 int rc = 0;
3079 struct ieee80211_conf *conf = NULL; 3089 struct ieee80211_conf *conf = NULL;
3090 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3080 3091
3081 if (!vif || !priv->is_open) 3092 if (!vif || !priv->is_open)
3082 return; 3093 return;
@@ -3087,7 +3098,7 @@ void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3087 } 3098 }
3088 3099
3089 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n", 3100 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
3090 vif->bss_conf.aid, priv->active_rxon.bssid_addr); 3101 vif->bss_conf.aid, ctx->active.bssid_addr);
3091 3102
3092 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3103 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3093 return; 3104 return;
@@ -3096,34 +3107,34 @@ void iwl3945_post_associate(struct iwl_priv *priv, struct ieee80211_vif *vif)
3096 3107
3097 conf = ieee80211_get_hw_conf(priv->hw); 3108 conf = ieee80211_get_hw_conf(priv->hw);
3098 3109
3099 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3110 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3100 iwlcore_commit_rxon(priv); 3111 iwlcore_commit_rxon(priv, ctx);
3101 3112
3102 rc = iwl_send_rxon_timing(priv, vif); 3113 rc = iwl_send_rxon_timing(priv, ctx);
3103 if (rc) 3114 if (rc)
3104 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3115 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3105 "Attempting to continue.\n"); 3116 "Attempting to continue.\n");
3106 3117
3107 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3118 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3108 3119
3109 priv->staging_rxon.assoc_id = cpu_to_le16(vif->bss_conf.aid); 3120 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
3110 3121
3111 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n", 3122 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
3112 vif->bss_conf.aid, vif->bss_conf.beacon_int); 3123 vif->bss_conf.aid, vif->bss_conf.beacon_int);
3113 3124
3114 if (vif->bss_conf.use_short_preamble) 3125 if (vif->bss_conf.use_short_preamble)
3115 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK; 3126 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3116 else 3127 else
3117 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK; 3128 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3118 3129
3119 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { 3130 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
3120 if (vif->bss_conf.use_short_slot) 3131 if (vif->bss_conf.use_short_slot)
3121 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK; 3132 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
3122 else 3133 else
3123 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK; 3134 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
3124 } 3135 }
3125 3136
3126 iwlcore_commit_rxon(priv); 3137 iwlcore_commit_rxon(priv, ctx);
3127 3138
3128 switch (vif->type) { 3139 switch (vif->type) {
3129 case NL80211_IFTYPE_STATION: 3140 case NL80211_IFTYPE_STATION:
@@ -3260,44 +3271,45 @@ static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
3260 3271
3261void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif) 3272void iwl3945_config_ap(struct iwl_priv *priv, struct ieee80211_vif *vif)
3262{ 3273{
3274 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3263 int rc = 0; 3275 int rc = 0;
3264 3276
3265 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) 3277 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3266 return; 3278 return;
3267 3279
3268 /* The following should be done only at AP bring up */ 3280 /* The following should be done only at AP bring up */
3269 if (!(iwl_is_associated(priv))) { 3281 if (!(iwl_is_associated(priv, IWL_RXON_CTX_BSS))) {
3270 3282
3271 /* RXON - unassoc (to set timing command) */ 3283 /* RXON - unassoc (to set timing command) */
3272 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK; 3284 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3273 iwlcore_commit_rxon(priv); 3285 iwlcore_commit_rxon(priv, ctx);
3274 3286
3275 /* RXON Timing */ 3287 /* RXON Timing */
3276 rc = iwl_send_rxon_timing(priv, vif); 3288 rc = iwl_send_rxon_timing(priv, ctx);
3277 if (rc) 3289 if (rc)
3278 IWL_WARN(priv, "REPLY_RXON_TIMING failed - " 3290 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
3279 "Attempting to continue.\n"); 3291 "Attempting to continue.\n");
3280 3292
3281 priv->staging_rxon.assoc_id = 0; 3293 ctx->staging.assoc_id = 0;
3282 3294
3283 if (vif->bss_conf.use_short_preamble) 3295 if (vif->bss_conf.use_short_preamble)
3284 priv->staging_rxon.flags |= 3296 ctx->staging.flags |=
3285 RXON_FLG_SHORT_PREAMBLE_MSK; 3297 RXON_FLG_SHORT_PREAMBLE_MSK;
3286 else 3298 else
3287 priv->staging_rxon.flags &= 3299 ctx->staging.flags &=
3288 ~RXON_FLG_SHORT_PREAMBLE_MSK; 3300 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3289 3301
3290 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) { 3302 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK) {
3291 if (vif->bss_conf.use_short_slot) 3303 if (vif->bss_conf.use_short_slot)
3292 priv->staging_rxon.flags |= 3304 ctx->staging.flags |=
3293 RXON_FLG_SHORT_SLOT_MSK; 3305 RXON_FLG_SHORT_SLOT_MSK;
3294 else 3306 else
3295 priv->staging_rxon.flags &= 3307 ctx->staging.flags &=
3296 ~RXON_FLG_SHORT_SLOT_MSK; 3308 ~RXON_FLG_SHORT_SLOT_MSK;
3297 } 3309 }
3298 /* restore RXON assoc */ 3310 /* restore RXON assoc */
3299 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; 3311 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
3300 iwlcore_commit_rxon(priv); 3312 iwlcore_commit_rxon(priv, ctx);
3301 } 3313 }
3302 iwl3945_send_beacon_cmd(priv); 3314 iwl3945_send_beacon_cmd(priv);
3303 3315
@@ -3323,10 +3335,11 @@ static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
3323 return -EOPNOTSUPP; 3335 return -EOPNOTSUPP;
3324 } 3336 }
3325 3337
3326 static_key = !iwl_is_associated(priv); 3338 static_key = !iwl_is_associated(priv, IWL_RXON_CTX_BSS);
3327 3339
3328 if (!static_key) { 3340 if (!static_key) {
3329 sta_id = iwl_sta_id_or_broadcast(priv, sta); 3341 sta_id = iwl_sta_id_or_broadcast(
3342 priv, &priv->contexts[IWL_RXON_CTX_BSS], sta);
3330 if (sta_id == IWL_INVALID_STATION) 3343 if (sta_id == IWL_INVALID_STATION)
3331 return -EINVAL; 3344 return -EINVAL;
3332 } 3345 }
@@ -3377,8 +3390,8 @@ static int iwl3945_mac_sta_add(struct ieee80211_hw *hw,
3377 sta_priv->common.sta_id = IWL_INVALID_STATION; 3390 sta_priv->common.sta_id = IWL_INVALID_STATION;
3378 3391
3379 3392
3380 ret = iwl_add_station_common(priv, sta->addr, is_ap, &sta->ht_cap, 3393 ret = iwl_add_station_common(priv, &priv->contexts[IWL_RXON_CTX_BSS],
3381 &sta_id); 3394 sta->addr, is_ap, sta, &sta_id);
3382 if (ret) { 3395 if (ret) {
3383 IWL_ERR(priv, "Unable to add station %pM (%d)\n", 3396 IWL_ERR(priv, "Unable to add station %pM (%d)\n",
3384 sta->addr, ret); 3397 sta->addr, ret);
@@ -3405,6 +3418,7 @@ static void iwl3945_configure_filter(struct ieee80211_hw *hw,
3405{ 3418{
3406 struct iwl_priv *priv = hw->priv; 3419 struct iwl_priv *priv = hw->priv;
3407 __le32 filter_or = 0, filter_nand = 0; 3420 __le32 filter_or = 0, filter_nand = 0;
3421 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3408 3422
3409#define CHK(test, flag) do { \ 3423#define CHK(test, flag) do { \
3410 if (*total_flags & (test)) \ 3424 if (*total_flags & (test)) \
@@ -3424,8 +3438,8 @@ static void iwl3945_configure_filter(struct ieee80211_hw *hw,
3424 3438
3425 mutex_lock(&priv->mutex); 3439 mutex_lock(&priv->mutex);
3426 3440
3427 priv->staging_rxon.filter_flags &= ~filter_nand; 3441 ctx->staging.filter_flags &= ~filter_nand;
3428 priv->staging_rxon.filter_flags |= filter_or; 3442 ctx->staging.filter_flags |= filter_or;
3429 3443
3430 /* 3444 /*
3431 * Committing directly here breaks for some reason, 3445 * Committing directly here breaks for some reason,
@@ -3539,8 +3553,9 @@ static ssize_t show_flags(struct device *d,
3539 struct device_attribute *attr, char *buf) 3553 struct device_attribute *attr, char *buf)
3540{ 3554{
3541 struct iwl_priv *priv = dev_get_drvdata(d); 3555 struct iwl_priv *priv = dev_get_drvdata(d);
3556 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3542 3557
3543 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags); 3558 return sprintf(buf, "0x%04X\n", ctx->active.flags);
3544} 3559}
3545 3560
3546static ssize_t store_flags(struct device *d, 3561static ssize_t store_flags(struct device *d,
@@ -3549,17 +3564,18 @@ static ssize_t store_flags(struct device *d,
3549{ 3564{
3550 struct iwl_priv *priv = dev_get_drvdata(d); 3565 struct iwl_priv *priv = dev_get_drvdata(d);
3551 u32 flags = simple_strtoul(buf, NULL, 0); 3566 u32 flags = simple_strtoul(buf, NULL, 0);
3567 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3552 3568
3553 mutex_lock(&priv->mutex); 3569 mutex_lock(&priv->mutex);
3554 if (le32_to_cpu(priv->staging_rxon.flags) != flags) { 3570 if (le32_to_cpu(ctx->staging.flags) != flags) {
3555 /* Cancel any currently running scans... */ 3571 /* Cancel any currently running scans... */
3556 if (iwl_scan_cancel_timeout(priv, 100)) 3572 if (iwl_scan_cancel_timeout(priv, 100))
3557 IWL_WARN(priv, "Could not cancel scan.\n"); 3573 IWL_WARN(priv, "Could not cancel scan.\n");
3558 else { 3574 else {
3559 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n", 3575 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
3560 flags); 3576 flags);
3561 priv->staging_rxon.flags = cpu_to_le32(flags); 3577 ctx->staging.flags = cpu_to_le32(flags);
3562 iwlcore_commit_rxon(priv); 3578 iwlcore_commit_rxon(priv, ctx);
3563 } 3579 }
3564 } 3580 }
3565 mutex_unlock(&priv->mutex); 3581 mutex_unlock(&priv->mutex);
@@ -3573,9 +3589,10 @@ static ssize_t show_filter_flags(struct device *d,
3573 struct device_attribute *attr, char *buf) 3589 struct device_attribute *attr, char *buf)
3574{ 3590{
3575 struct iwl_priv *priv = dev_get_drvdata(d); 3591 struct iwl_priv *priv = dev_get_drvdata(d);
3592 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3576 3593
3577 return sprintf(buf, "0x%04X\n", 3594 return sprintf(buf, "0x%04X\n",
3578 le32_to_cpu(priv->active_rxon.filter_flags)); 3595 le32_to_cpu(ctx->active.filter_flags));
3579} 3596}
3580 3597
3581static ssize_t store_filter_flags(struct device *d, 3598static ssize_t store_filter_flags(struct device *d,
@@ -3583,19 +3600,20 @@ static ssize_t store_filter_flags(struct device *d,
3583 const char *buf, size_t count) 3600 const char *buf, size_t count)
3584{ 3601{
3585 struct iwl_priv *priv = dev_get_drvdata(d); 3602 struct iwl_priv *priv = dev_get_drvdata(d);
3603 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3586 u32 filter_flags = simple_strtoul(buf, NULL, 0); 3604 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3587 3605
3588 mutex_lock(&priv->mutex); 3606 mutex_lock(&priv->mutex);
3589 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) { 3607 if (le32_to_cpu(ctx->staging.filter_flags) != filter_flags) {
3590 /* Cancel any currently running scans... */ 3608 /* Cancel any currently running scans... */
3591 if (iwl_scan_cancel_timeout(priv, 100)) 3609 if (iwl_scan_cancel_timeout(priv, 100))
3592 IWL_WARN(priv, "Could not cancel scan.\n"); 3610 IWL_WARN(priv, "Could not cancel scan.\n");
3593 else { 3611 else {
3594 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = " 3612 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
3595 "0x%04X\n", filter_flags); 3613 "0x%04X\n", filter_flags);
3596 priv->staging_rxon.filter_flags = 3614 ctx->staging.filter_flags =
3597 cpu_to_le32(filter_flags); 3615 cpu_to_le32(filter_flags);
3598 iwlcore_commit_rxon(priv); 3616 iwlcore_commit_rxon(priv, ctx);
3599 } 3617 }
3600 } 3618 }
3601 mutex_unlock(&priv->mutex); 3619 mutex_unlock(&priv->mutex);
@@ -3643,8 +3661,9 @@ static ssize_t store_measurement(struct device *d,
3643 const char *buf, size_t count) 3661 const char *buf, size_t count)
3644{ 3662{
3645 struct iwl_priv *priv = dev_get_drvdata(d); 3663 struct iwl_priv *priv = dev_get_drvdata(d);
3664 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
3646 struct ieee80211_measurement_params params = { 3665 struct ieee80211_measurement_params params = {
3647 .channel = le16_to_cpu(priv->active_rxon.channel), 3666 .channel = le16_to_cpu(ctx->active.channel),
3648 .start_time = cpu_to_le64(priv->_3945.last_tsf), 3667 .start_time = cpu_to_le64(priv->_3945.last_tsf),
3649 .duration = cpu_to_le16(1), 3668 .duration = cpu_to_le16(1),
3650 }; 3669 };
@@ -3936,8 +3955,7 @@ static int iwl3945_setup_mac(struct iwl_priv *priv)
3936 IEEE80211_HW_SUPPORTS_DYNAMIC_PS; 3955 IEEE80211_HW_SUPPORTS_DYNAMIC_PS;
3937 3956
3938 hw->wiphy->interface_modes = 3957 hw->wiphy->interface_modes =
3939 BIT(NL80211_IFTYPE_STATION) | 3958 priv->contexts[IWL_RXON_CTX_BSS].interface_modes;
3940 BIT(NL80211_IFTYPE_ADHOC);
3941 3959
3942 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY | 3960 hw->wiphy->flags |= WIPHY_FLAG_CUSTOM_REGULATORY |
3943 WIPHY_FLAG_DISABLE_BEACON_HINTS; 3961 WIPHY_FLAG_DISABLE_BEACON_HINTS;
@@ -3969,7 +3987,7 @@ static int iwl3945_setup_mac(struct iwl_priv *priv)
3969 3987
3970static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 3988static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
3971{ 3989{
3972 int err = 0; 3990 int err = 0, i;
3973 struct iwl_priv *priv; 3991 struct iwl_priv *priv;
3974 struct ieee80211_hw *hw; 3992 struct ieee80211_hw *hw;
3975 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data); 3993 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
@@ -3991,6 +4009,27 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
3991 priv = hw->priv; 4009 priv = hw->priv;
3992 SET_IEEE80211_DEV(hw, &pdev->dev); 4010 SET_IEEE80211_DEV(hw, &pdev->dev);
3993 4011
4012 priv->cmd_queue = IWL39_CMD_QUEUE_NUM;
4013
4014 /* 3945 has only one valid context */
4015 priv->valid_contexts = BIT(IWL_RXON_CTX_BSS);
4016
4017 for (i = 0; i < NUM_IWL_RXON_CTX; i++)
4018 priv->contexts[i].ctxid = i;
4019
4020 priv->contexts[IWL_RXON_CTX_BSS].rxon_cmd = REPLY_RXON;
4021 priv->contexts[IWL_RXON_CTX_BSS].rxon_timing_cmd = REPLY_RXON_TIMING;
4022 priv->contexts[IWL_RXON_CTX_BSS].rxon_assoc_cmd = REPLY_RXON_ASSOC;
4023 priv->contexts[IWL_RXON_CTX_BSS].qos_cmd = REPLY_QOS_PARAM;
4024 priv->contexts[IWL_RXON_CTX_BSS].ap_sta_id = IWL_AP_ID;
4025 priv->contexts[IWL_RXON_CTX_BSS].wep_key_cmd = REPLY_WEPKEY;
4026 priv->contexts[IWL_RXON_CTX_BSS].interface_modes =
4027 BIT(NL80211_IFTYPE_STATION) |
4028 BIT(NL80211_IFTYPE_ADHOC);
4029 priv->contexts[IWL_RXON_CTX_BSS].ibss_devtype = RXON_DEV_TYPE_IBSS;
4030 priv->contexts[IWL_RXON_CTX_BSS].station_devtype = RXON_DEV_TYPE_ESS;
4031 priv->contexts[IWL_RXON_CTX_BSS].unused_devtype = RXON_DEV_TYPE_ESS;
4032
3994 /* 4033 /*
3995 * Disabling hardware scan means that mac80211 will perform scans 4034 * Disabling hardware scan means that mac80211 will perform scans
3996 * "the hard way", rather than using device's scan. 4035 * "the hard way", rather than using device's scan.
@@ -4126,7 +4165,8 @@ static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *e
4126 } 4165 }
4127 4166
4128 iwl_set_rxon_channel(priv, 4167 iwl_set_rxon_channel(priv,
4129 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]); 4168 &priv->bands[IEEE80211_BAND_2GHZ].channels[5],
4169 &priv->contexts[IWL_RXON_CTX_BSS]);
4130 iwl3945_setup_deferred_work(priv); 4170 iwl3945_setup_deferred_work(priv);
4131 iwl3945_setup_rx_handlers(priv); 4171 iwl3945_setup_rx_handlers(priv);
4132 iwl_power_initialize(priv); 4172 iwl_power_initialize(priv);