Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Wey-Yi Guy | 901069c | 2011-04-05 09:42:00 -0700 | [diff] [blame] | 3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | * |
| 28 | *****************************************************************************/ |
| 29 | |
| 30 | #include <net/mac80211.h> |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 31 | #include <linux/etherdevice.h> |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 32 | #include <linux/sched.h> |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 33 | #include <linux/lockdep.h> |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 34 | |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 35 | #include "iwl-dev.h" |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 36 | #include "iwl-core.h" |
| 37 | #include "iwl-sta.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 38 | #include "iwl-trans.h" |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 39 | #include "iwl-agn.h" |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 40 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 41 | /* priv->shrd->sta_lock must be held */ |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 42 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) |
| 43 | { |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 44 | |
| 45 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) |
| 46 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u addr %pM\n", |
| 47 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 48 | |
| 49 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { |
| 50 | IWL_DEBUG_ASSOC(priv, |
| 51 | "STA id %u addr %pM already present in uCode (according to driver)\n", |
| 52 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 53 | } else { |
| 54 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; |
| 55 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", |
| 56 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 57 | } |
| 58 | } |
| 59 | |
Johannes Berg | 09034cb | 2010-06-14 08:32:38 -0700 | [diff] [blame] | 60 | static int iwl_process_add_sta_resp(struct iwl_priv *priv, |
| 61 | struct iwl_addsta_cmd *addsta, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 62 | struct iwl_rx_packet *pkt) |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 63 | { |
| 64 | u8 sta_id = addsta->sta.sta_id; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 65 | unsigned long flags; |
Johannes Berg | 09034cb | 2010-06-14 08:32:38 -0700 | [diff] [blame] | 66 | int ret = -EIO; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 67 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 68 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
| 69 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", |
| 70 | pkt->hdr.flags); |
Johannes Berg | 09034cb | 2010-06-14 08:32:38 -0700 | [diff] [blame] | 71 | return ret; |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", |
| 75 | sta_id); |
| 76 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 77 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 78 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 79 | switch (pkt->u.add_sta.status) { |
| 80 | case ADD_STA_SUCCESS_MSK: |
| 81 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); |
| 82 | iwl_sta_ucode_activate(priv, sta_id); |
Johannes Berg | 09034cb | 2010-06-14 08:32:38 -0700 | [diff] [blame] | 83 | ret = 0; |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 84 | break; |
| 85 | case ADD_STA_NO_ROOM_IN_TABLE: |
| 86 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 87 | sta_id); |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 88 | break; |
| 89 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: |
| 90 | IWL_ERR(priv, "Adding station %d failed, no block ack resource.\n", |
| 91 | sta_id); |
| 92 | break; |
| 93 | case ADD_STA_MODIFY_NON_EXIST_STA: |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 94 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 95 | sta_id); |
| 96 | break; |
| 97 | default: |
| 98 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", |
| 99 | pkt->u.add_sta.status); |
| 100 | break; |
| 101 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 102 | |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 103 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", |
| 104 | priv->stations[sta_id].sta.mode == |
| 105 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 106 | sta_id, priv->stations[sta_id].sta.sta.addr); |
| 107 | |
| 108 | /* |
| 109 | * XXX: The MAC address in the command buffer is often changed from |
| 110 | * the original sent to the device. That is, the MAC address |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 111 | * written to the command buffer often is not the same MAC address |
Reinette Chatre | 1fa97aa | 2010-01-22 14:22:48 -0800 | [diff] [blame] | 112 | * read from the command buffer when the command returns. This |
| 113 | * issue has not yet been resolved and this debugging is left to |
| 114 | * observe the problem. |
| 115 | */ |
| 116 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", |
| 117 | priv->stations[sta_id].sta.mode == |
| 118 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", |
| 119 | addsta->sta.addr); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 120 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | 09034cb | 2010-06-14 08:32:38 -0700 | [diff] [blame] | 121 | |
| 122 | return ret; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 123 | } |
| 124 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 125 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, |
| 126 | struct iwl_device_cmd *cmd) |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 127 | { |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 128 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 3257e5d | 2008-10-14 12:32:43 -0700 | [diff] [blame] | 129 | struct iwl_addsta_cmd *addsta = |
Emmanuel Grumbach | 132f98c | 2011-09-20 15:37:24 -0700 | [diff] [blame] | 130 | (struct iwl_addsta_cmd *) cmd->payload; |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 131 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 132 | return iwl_process_add_sta_resp(priv, addsta, pkt); |
Tomas Winkler | 42132bc | 2008-05-29 16:35:03 +0800 | [diff] [blame] | 133 | } |
| 134 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 135 | static u16 iwlagn_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) |
| 136 | { |
| 137 | u16 size = (u16)sizeof(struct iwl_addsta_cmd); |
| 138 | struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data; |
| 139 | memcpy(addsta, cmd, size); |
| 140 | /* resrved in 5000 */ |
| 141 | addsta->rate_n_flags = cpu_to_le16(0); |
| 142 | return size; |
| 143 | } |
| 144 | |
Samuel Ortiz | 17f841c | 2009-01-23 13:45:20 -0800 | [diff] [blame] | 145 | int iwl_send_add_sta(struct iwl_priv *priv, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 146 | struct iwl_addsta_cmd *sta, u8 flags) |
| 147 | { |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 148 | int ret = 0; |
| 149 | u8 data[sizeof(*sta)]; |
| 150 | struct iwl_host_cmd cmd = { |
| 151 | .id = REPLY_ADD_STA, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 152 | .flags = flags, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 153 | .data = { data, }, |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 154 | }; |
Reinette Chatre | f875f51 | 2010-04-05 10:43:10 -0700 | [diff] [blame] | 155 | u8 sta_id __maybe_unused = sta->sta.sta_id; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 156 | |
| 157 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", |
| 158 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 159 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 160 | if (!(flags & CMD_ASYNC)) { |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 161 | cmd.flags |= CMD_WANT_SKB; |
Johannes Berg | 4620fef | 2010-06-16 03:30:27 -0700 | [diff] [blame] | 162 | might_sleep(); |
| 163 | } |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 164 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 165 | cmd.len[0] = iwlagn_build_addsta_hcmd(sta, data); |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 166 | ret = iwl_trans_send_cmd(trans(priv), &cmd); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 167 | |
| 168 | if (ret || (flags & CMD_ASYNC)) |
| 169 | return ret; |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 170 | /*else the command was successfully sent in SYNC mode, need to free |
| 171 | * the reply page */ |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 172 | |
Emmanuel Grumbach | 790428b | 2011-08-25 23:11:05 -0700 | [diff] [blame] | 173 | iwl_free_pages(priv->shrd, cmd.reply_page); |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 174 | |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 175 | if (cmd.handler_status) |
| 176 | IWL_ERR(priv, "%s - error in the CMD response %d", __func__, |
| 177 | cmd.handler_status); |
| 178 | |
| 179 | return cmd.handler_status; |
Tomas Winkler | 133636d | 2008-05-05 10:22:34 +0800 | [diff] [blame] | 180 | } |
Tomas Winkler | 947b13a | 2008-04-16 16:34:48 -0700 | [diff] [blame] | 181 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 182 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 183 | struct ieee80211_sta *sta, |
| 184 | struct iwl_rxon_context *ctx) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 185 | { |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 186 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 187 | __le32 sta_flags; |
| 188 | u8 mimo_ps_mode; |
| 189 | |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 190 | if (!sta || !sta_ht_inf->ht_supported) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 191 | goto done; |
| 192 | |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 193 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; |
Wey-Yi Guy | 3f3e037 | 2009-10-30 14:36:17 -0700 | [diff] [blame] | 194 | IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n", |
| 195 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? |
| 196 | "static" : |
| 197 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? |
| 198 | "dynamic" : "disabled"); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 199 | |
| 200 | sta_flags = priv->stations[index].sta.station_flags; |
| 201 | |
| 202 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); |
| 203 | |
| 204 | switch (mimo_ps_mode) { |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 205 | case WLAN_HT_CAP_SM_PS_STATIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 206 | sta_flags |= STA_FLG_MIMO_DIS_MSK; |
| 207 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 208 | case WLAN_HT_CAP_SM_PS_DYNAMIC: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 209 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; |
| 210 | break; |
Tomas Winkler | 00c5ae2 | 2008-09-03 11:26:42 +0800 | [diff] [blame] | 211 | case WLAN_HT_CAP_SM_PS_DISABLED: |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 212 | break; |
| 213 | default: |
Winkler, Tomas | 39aadf8 | 2008-12-19 10:37:32 +0800 | [diff] [blame] | 214 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 215 | break; |
| 216 | } |
| 217 | |
| 218 | sta_flags |= cpu_to_le32( |
| 219 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); |
| 220 | |
| 221 | sta_flags |= cpu_to_le32( |
| 222 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); |
| 223 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 224 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 225 | sta_flags |= STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 226 | else |
Wey-Yi Guy | 7aafef1 | 2009-08-07 15:41:38 -0700 | [diff] [blame] | 227 | sta_flags &= ~STA_FLG_HT40_EN_MSK; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 228 | |
| 229 | priv->stations[index].sta.station_flags = sta_flags; |
| 230 | done: |
| 231 | return; |
| 232 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 233 | |
| 234 | /** |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 235 | * iwl_prep_station - Prepare station information for addition |
| 236 | * |
| 237 | * should be called with sta_lock held |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 238 | */ |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 239 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 240 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta) |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 241 | { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 242 | struct iwl_station_entry *station; |
Tomas Winkler | c587de0 | 2009-06-03 11:44:07 -0700 | [diff] [blame] | 243 | int i; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 244 | u8 sta_id = IWL_INVALID_STATION; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 245 | |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 246 | if (is_ap) |
Johannes Berg | 2995baf | 2010-08-23 10:46:42 +0200 | [diff] [blame] | 247 | sta_id = ctx->ap_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 248 | else if (is_broadcast_ether_addr(addr)) |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 249 | sta_id = ctx->bcast_sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 250 | else |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 251 | for (i = IWL_STA_ID; |
| 252 | i < hw_params(priv).max_stations; i++) { |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 253 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, |
| 254 | addr)) { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 255 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 256 | break; |
| 257 | } |
| 258 | |
| 259 | if (!priv->stations[i].used && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 260 | sta_id == IWL_INVALID_STATION) |
| 261 | sta_id = i; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 262 | } |
| 263 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 264 | /* |
| 265 | * These two conditions have the same outcome, but keep them |
| 266 | * separate |
| 267 | */ |
| 268 | if (unlikely(sta_id == IWL_INVALID_STATION)) |
| 269 | return sta_id; |
| 270 | |
| 271 | /* |
| 272 | * uCode is not able to deal with multiple requests to add a |
| 273 | * station. Keep track if one is in progress so that we do not send |
| 274 | * another. |
| 275 | */ |
| 276 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 277 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 278 | sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 279 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 280 | } |
| 281 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 282 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 283 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 284 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 285 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 286 | sta_id, addr); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 287 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 288 | } |
| 289 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 290 | station = &priv->stations[sta_id]; |
| 291 | station->used = IWL_STA_DRIVER_ACTIVE; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 292 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 293 | sta_id, addr); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 294 | priv->num_stations++; |
| 295 | |
| 296 | /* Set up the REPLY_ADD_STA command to send to device */ |
| 297 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); |
| 298 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); |
| 299 | station->sta.mode = 0; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 300 | station->sta.sta.sta_id = sta_id; |
Johannes Berg | 770e13b | 2010-08-23 10:46:44 +0200 | [diff] [blame] | 301 | station->sta.station_flags = ctx->station_flags; |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 302 | station->ctxid = ctx->ctxid; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 303 | |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 304 | if (sta) { |
Johannes Berg | c689290 | 2011-09-20 15:37:21 -0700 | [diff] [blame] | 305 | struct iwl_station_priv *sta_priv; |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 306 | |
| 307 | sta_priv = (void *)sta->drv_priv; |
| 308 | sta_priv->ctx = ctx; |
| 309 | } |
| 310 | |
Johannes Berg | 63d4176 | 2010-04-30 11:30:50 -0700 | [diff] [blame] | 311 | /* |
| 312 | * OK to call unconditionally, since local stations (IBSS BSSID |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 313 | * STA and broadcast STA) pass in a NULL sta, and mac80211 |
Johannes Berg | 63d4176 | 2010-04-30 11:30:50 -0700 | [diff] [blame] | 314 | * doesn't allow HT IBSS. |
| 315 | */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 316 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 317 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 318 | return sta_id; |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 319 | |
| 320 | } |
Tomas Winkler | 4f40e4d | 2008-05-15 13:54:04 +0800 | [diff] [blame] | 321 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 322 | #define STA_WAIT_TIMEOUT (HZ/2) |
| 323 | |
| 324 | /** |
| 325 | * iwl_add_station_common - |
| 326 | */ |
Johannes Berg | a194e32 | 2010-08-27 08:53:46 -0700 | [diff] [blame] | 327 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
| 328 | const u8 *addr, bool is_ap, |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 329 | struct ieee80211_sta *sta, u8 *sta_id_r) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 330 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 331 | unsigned long flags_spin; |
| 332 | int ret = 0; |
| 333 | u8 sta_id; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 334 | struct iwl_addsta_cmd sta_cmd; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 335 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 336 | *sta_id_r = 0; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 337 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Johannes Berg | 238d781 | 2010-08-23 10:46:45 +0200 | [diff] [blame] | 338 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 339 | if (sta_id == IWL_INVALID_STATION) { |
| 340 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", |
| 341 | addr); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 342 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 343 | return -EINVAL; |
| 344 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 345 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 346 | /* |
| 347 | * uCode is not able to deal with multiple requests to add a |
| 348 | * station. Keep track if one is in progress so that we do not send |
| 349 | * another. |
| 350 | */ |
| 351 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { |
| 352 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", |
| 353 | sta_id); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 354 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 355 | return -EEXIST; |
| 356 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 357 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 358 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && |
| 359 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
| 360 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", |
| 361 | sta_id, addr); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 362 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 363 | return -EEXIST; |
| 364 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 365 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 366 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 367 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 368 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 369 | |
| 370 | /* Add station to device's station table */ |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 371 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 372 | if (ret) { |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 373 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 374 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 375 | priv->stations[sta_id].sta.sta.addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 376 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 377 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 378 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 379 | } |
| 380 | *sta_id_r = sta_id; |
| 381 | return ret; |
| 382 | } |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 383 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 384 | /** |
| 385 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station |
| 386 | * |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 387 | * priv->shrd->sta_lock must be held |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 388 | */ |
| 389 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) |
| 390 | { |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 391 | /* Ucode must be active and driver must be non active */ |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 392 | if ((priv->stations[sta_id].used & |
| 393 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 394 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 395 | |
| 396 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; |
| 397 | |
| 398 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 399 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 400 | } |
| 401 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 402 | static int iwl_send_remove_station(struct iwl_priv *priv, |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 403 | const u8 *addr, int sta_id, |
| 404 | bool temporary) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 405 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 406 | struct iwl_rx_packet *pkt; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 407 | int ret; |
| 408 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 409 | unsigned long flags_spin; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 410 | struct iwl_rem_sta_cmd rm_sta_cmd; |
| 411 | |
| 412 | struct iwl_host_cmd cmd = { |
| 413 | .id = REPLY_REMOVE_STA, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 414 | .len = { sizeof(struct iwl_rem_sta_cmd), }, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 415 | .flags = CMD_SYNC, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 416 | .data = { &rm_sta_cmd, }, |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 417 | }; |
| 418 | |
| 419 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); |
| 420 | rm_sta_cmd.num_sta = 1; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 421 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 422 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 423 | cmd.flags |= CMD_WANT_SKB; |
| 424 | |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 425 | ret = iwl_trans_send_cmd(trans(priv), &cmd); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 426 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 427 | if (ret) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 428 | return ret; |
| 429 | |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 430 | pkt = (struct iwl_rx_packet *)cmd.reply_page; |
| 431 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 432 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 433 | pkt->hdr.flags); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 434 | ret = -EIO; |
| 435 | } |
| 436 | |
| 437 | if (!ret) { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 438 | switch (pkt->u.rem_sta.status) { |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 439 | case REM_STA_SUCCESS_MSK: |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 440 | if (!temporary) { |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 441 | spin_lock_irqsave(&priv->shrd->sta_lock, |
| 442 | flags_spin); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 443 | iwl_sta_ucode_deactivate(priv, sta_id); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 444 | spin_unlock_irqrestore(&priv->shrd->sta_lock, |
| 445 | flags_spin); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 446 | } |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 447 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 448 | break; |
| 449 | default: |
| 450 | ret = -EIO; |
Winkler, Tomas | 15b1687 | 2008-12-19 10:37:33 +0800 | [diff] [blame] | 451 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 452 | break; |
| 453 | } |
| 454 | } |
Emmanuel Grumbach | 790428b | 2011-08-25 23:11:05 -0700 | [diff] [blame] | 455 | iwl_free_pages(priv->shrd, cmd.reply_page); |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 456 | |
| 457 | return ret; |
| 458 | } |
Emmanuel Grumbach | be1f3ab6 | 2008-06-12 09:47:18 +0800 | [diff] [blame] | 459 | |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 460 | /** |
| 461 | * iwl_remove_station - Remove driver's knowledge of station. |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 462 | */ |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 463 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, |
| 464 | const u8 *addr) |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 465 | { |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 466 | unsigned long flags; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 467 | |
Emmanuel Grumbach | 845a9c0 | 2011-08-25 23:11:04 -0700 | [diff] [blame] | 468 | if (!iwl_is_ready(priv->shrd)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 469 | IWL_DEBUG_INFO(priv, |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 470 | "Unable to remove station %pM, device not ready.\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 471 | addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 472 | /* |
| 473 | * It is typical for stations to be removed when we are |
| 474 | * going down. Return success since device will be down |
| 475 | * soon anyway |
| 476 | */ |
| 477 | return 0; |
| 478 | } |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 479 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 480 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 481 | sta_id, addr); |
| 482 | |
| 483 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) |
| 484 | return -EINVAL; |
| 485 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 486 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 487 | |
| 488 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 489 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 490 | addr); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 491 | goto out_err; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 492 | } |
| 493 | |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 494 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 495 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", |
Johannes Berg | c0222df | 2010-04-28 08:44:51 -0700 | [diff] [blame] | 496 | addr); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 497 | goto out_err; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 498 | } |
| 499 | |
Johannes Berg | 1fa61b2 | 2010-04-28 08:44:52 -0700 | [diff] [blame] | 500 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { |
| 501 | kfree(priv->stations[sta_id].lq); |
| 502 | priv->stations[sta_id].lq = NULL; |
| 503 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 504 | |
| 505 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 506 | |
| 507 | priv->num_stations--; |
| 508 | |
Johannes Berg | 3e41ace | 2011-04-18 09:12:37 -0700 | [diff] [blame] | 509 | if (WARN_ON(priv->num_stations < 0)) |
| 510 | priv->num_stations = 0; |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 511 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 512 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 513 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 514 | return iwl_send_remove_station(priv, addr, sta_id, false); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 515 | out_err: |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 516 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 517 | return -EINVAL; |
Tomas Winkler | 7a999bf | 2008-05-29 16:35:02 +0800 | [diff] [blame] | 518 | } |
Emmanuel Grumbach | 24e5c40 | 2008-06-30 17:23:03 +0800 | [diff] [blame] | 519 | |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 520 | /** |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 521 | * iwl_clear_ucode_stations - clear ucode station table bits |
| 522 | * |
| 523 | * This function clears all the bits in the driver indicating |
| 524 | * which stations are active in the ucode. Call when something |
| 525 | * other than explicit station management would cause this in |
| 526 | * the ucode, e.g. unassociated RXON. |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 527 | */ |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 528 | void iwl_clear_ucode_stations(struct iwl_priv *priv, |
| 529 | struct iwl_rxon_context *ctx) |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 530 | { |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 531 | int i; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 532 | unsigned long flags_spin; |
| 533 | bool cleared = false; |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 534 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 535 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); |
Mohamed Abbas | 48676eb | 2009-03-11 11:17:59 -0700 | [diff] [blame] | 536 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 537 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 538 | for (i = 0; i < hw_params(priv).max_stations; i++) { |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 539 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) |
| 540 | continue; |
| 541 | |
Johannes Berg | 2c810cc | 2010-04-29 00:53:29 -0700 | [diff] [blame] | 542 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { |
| 543 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); |
| 544 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 545 | cleared = true; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 546 | } |
| 547 | } |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 548 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 549 | |
| 550 | if (!cleared) |
| 551 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 552 | } |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 553 | |
| 554 | /** |
| 555 | * iwl_restore_stations() - Restore driver known stations to device |
| 556 | * |
| 557 | * All stations considered active by driver, but not present in ucode, is |
| 558 | * restored. |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 559 | * |
| 560 | * Function sleeps. |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 561 | */ |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 562 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 563 | { |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 564 | struct iwl_addsta_cmd sta_cmd; |
| 565 | struct iwl_link_quality_cmd lq; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 566 | unsigned long flags_spin; |
| 567 | int i; |
| 568 | bool found = false; |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 569 | int ret; |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 570 | bool send_lq; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 571 | |
Emmanuel Grumbach | 845a9c0 | 2011-08-25 23:11:04 -0700 | [diff] [blame] | 572 | if (!iwl_is_ready(priv->shrd)) { |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 573 | IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n"); |
| 574 | return; |
| 575 | } |
| 576 | |
| 577 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 578 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 579 | for (i = 0; i < hw_params(priv).max_stations; i++) { |
Johannes Berg | dcef732 | 2010-08-27 08:55:52 -0700 | [diff] [blame] | 580 | if (ctx->ctxid != priv->stations[i].ctxid) |
| 581 | continue; |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 582 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && |
| 583 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { |
| 584 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", |
| 585 | priv->stations[i].sta.sta.addr); |
| 586 | priv->stations[i].sta.mode = 0; |
| 587 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; |
| 588 | found = true; |
| 589 | } |
| 590 | } |
| 591 | |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 592 | for (i = 0; i < hw_params(priv).max_stations; i++) { |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 593 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 594 | memcpy(&sta_cmd, &priv->stations[i].sta, |
| 595 | sizeof(struct iwl_addsta_cmd)); |
| 596 | send_lq = false; |
| 597 | if (priv->stations[i].lq) { |
| 598 | memcpy(&lq, priv->stations[i].lq, |
| 599 | sizeof(struct iwl_link_quality_cmd)); |
| 600 | send_lq = true; |
| 601 | } |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 602 | spin_unlock_irqrestore(&priv->shrd->sta_lock, |
| 603 | flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 604 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 605 | if (ret) { |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 606 | spin_lock_irqsave(&priv->shrd->sta_lock, |
| 607 | flags_spin); |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 608 | IWL_ERR(priv, "Adding station %pM failed.\n", |
| 609 | priv->stations[i].sta.sta.addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 610 | priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE; |
| 611 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 612 | spin_unlock_irqrestore(&priv->shrd->sta_lock, |
| 613 | flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 614 | } |
| 615 | /* |
| 616 | * Rate scaling has already been initialized, send |
| 617 | * current LQ command |
| 618 | */ |
Reinette Chatre | 9c5ac09 | 2010-05-05 02:26:06 -0700 | [diff] [blame] | 619 | if (send_lq) |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 620 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 621 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 622 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; |
| 623 | } |
| 624 | } |
| 625 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 626 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 627 | if (!found) |
| 628 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n"); |
| 629 | else |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 630 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); |
Reinette Chatre | 7e24619 | 2010-02-18 22:58:32 -0800 | [diff] [blame] | 631 | } |
Winkler, Tomas | 83dde8c | 2008-11-19 15:32:23 -0800 | [diff] [blame] | 632 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 633 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx) |
| 634 | { |
| 635 | unsigned long flags; |
| 636 | int sta_id = ctx->ap_sta_id; |
| 637 | int ret; |
| 638 | struct iwl_addsta_cmd sta_cmd; |
| 639 | struct iwl_link_quality_cmd lq; |
| 640 | bool active; |
| 641 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 642 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 643 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 644 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 645 | return; |
| 646 | } |
| 647 | |
| 648 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); |
| 649 | sta_cmd.mode = 0; |
| 650 | memcpy(&lq, priv->stations[sta_id].lq, sizeof(lq)); |
| 651 | |
| 652 | active = priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE; |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 653 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 654 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 655 | |
| 656 | if (active) { |
| 657 | ret = iwl_send_remove_station( |
| 658 | priv, priv->stations[sta_id].sta.sta.addr, |
| 659 | sta_id, true); |
| 660 | if (ret) |
| 661 | IWL_ERR(priv, "failed to remove STA %pM (%d)\n", |
| 662 | priv->stations[sta_id].sta.sta.addr, ret); |
| 663 | } |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 664 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 665 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 666 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 667 | |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 668 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); |
| 669 | if (ret) |
| 670 | IWL_ERR(priv, "failed to re-add STA %pM (%d)\n", |
| 671 | priv->stations[sta_id].sta.sta.addr, ret); |
| 672 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); |
| 673 | } |
Johannes Berg | 2b5f7a6 | 2010-11-10 18:25:48 -0800 | [diff] [blame] | 674 | |
Johannes Berg | 5a3d988 | 2011-07-15 13:03:12 -0700 | [diff] [blame] | 675 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 676 | { |
| 677 | int i; |
| 678 | |
Johannes Berg | c10afb6 | 2010-08-23 10:46:43 +0200 | [diff] [blame] | 679 | for (i = 0; i < priv->sta_key_max_num; i++) |
Emmanuel Grumbach | 77bab60 | 2008-04-15 16:01:44 -0700 | [diff] [blame] | 680 | if (!test_and_set_bit(i, &priv->ucode_key_table)) |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 681 | return i; |
| 682 | |
Tomas Winkler | 40a9a82 | 2008-11-25 23:29:03 +0200 | [diff] [blame] | 683 | return WEP_INVALID_OFFSET; |
Emmanuel Grumbach | 80fb47a | 2008-04-14 21:16:08 -0700 | [diff] [blame] | 684 | } |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 685 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 686 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) |
Emmanuel Grumbach | 6974e36 | 2008-04-14 21:16:06 -0700 | [diff] [blame] | 687 | { |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 688 | unsigned long flags; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 689 | int i; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 690 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 691 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 692 | for (i = 0; i < hw_params(priv).max_stations; i++) { |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 693 | if (!(priv->stations[i].used & IWL_STA_BCAST)) |
| 694 | continue; |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 695 | |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 696 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; |
| 697 | priv->num_stations--; |
Johannes Berg | 3e41ace | 2011-04-18 09:12:37 -0700 | [diff] [blame] | 698 | if (WARN_ON(priv->num_stations < 0)) |
| 699 | priv->num_stations = 0; |
Johannes Berg | a30e311 | 2010-09-22 18:02:01 +0200 | [diff] [blame] | 700 | kfree(priv->stations[i].lq); |
| 701 | priv->stations[i].lq = NULL; |
| 702 | } |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 703 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); |
Tomas Winkler | 9f58671 | 2008-11-12 13:14:05 -0800 | [diff] [blame] | 704 | } |
Emmanuel Grumbach | 7480513 | 2008-04-14 21:16:09 -0700 | [diff] [blame] | 705 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 706 | #ifdef CONFIG_IWLWIFI_DEBUG |
| 707 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 708 | struct iwl_link_quality_cmd *lq) |
| 709 | { |
| 710 | int i; |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 711 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); |
| 712 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 713 | lq->general_params.single_stream_ant_msk, |
| 714 | lq->general_params.dual_stream_ant_msk); |
| 715 | |
| 716 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 717 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 718 | i, lq->rs_table[i].rate_n_flags); |
| 719 | } |
| 720 | #else |
| 721 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, |
| 722 | struct iwl_link_quality_cmd *lq) |
| 723 | { |
| 724 | } |
| 725 | #endif |
| 726 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 727 | /** |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 728 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity |
| 729 | * |
| 730 | * It sometimes happens when a HT rate has been in use and we |
| 731 | * loose connectivity with AP then mac80211 will first tell us that the |
| 732 | * current channel is not HT anymore before removing the station. In such a |
| 733 | * scenario the RXON flags will be updated to indicate we are not |
| 734 | * communicating HT anymore, but the LQ command may still contain HT rates. |
| 735 | * Test for this to prevent driver from sending LQ command between the time |
| 736 | * RXON flags are updated and when LQ command is updated. |
| 737 | */ |
| 738 | static bool is_lq_table_valid(struct iwl_priv *priv, |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 739 | struct iwl_rxon_context *ctx, |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 740 | struct iwl_link_quality_cmd *lq) |
| 741 | { |
| 742 | int i; |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 743 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 744 | if (ctx->ht.enabled) |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 745 | return true; |
| 746 | |
| 747 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", |
Johannes Berg | 246ed35 | 2010-08-23 10:46:32 +0200 | [diff] [blame] | 748 | ctx->active.channel); |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 749 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { |
| 750 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { |
| 751 | IWL_DEBUG_INFO(priv, |
| 752 | "index %d of LQ expects HT channel\n", |
| 753 | i); |
| 754 | return false; |
| 755 | } |
| 756 | } |
| 757 | return true; |
| 758 | } |
| 759 | |
| 760 | /** |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 761 | * iwl_send_lq_cmd() - Send link quality command |
| 762 | * @init: This command is sent as part of station initialization right |
| 763 | * after station has been added. |
| 764 | * |
| 765 | * The link quality command is sent as the last step of station creation. |
| 766 | * This is the special case in which init is set and we call a callback in |
| 767 | * this case to clear the state indicating that station creation is in |
| 768 | * progress. |
| 769 | */ |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 770 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 771 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 772 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 773 | int ret = 0; |
| 774 | unsigned long flags_spin; |
| 775 | |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 776 | struct iwl_host_cmd cmd = { |
| 777 | .id = REPLY_TX_LINK_QUALITY_CMD, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 778 | .len = { sizeof(struct iwl_link_quality_cmd), }, |
Johannes Berg | c2acea8 | 2009-07-24 11:13:05 -0700 | [diff] [blame] | 779 | .flags = flags, |
Johannes Berg | 3fa5073 | 2011-05-04 07:50:38 -0700 | [diff] [blame] | 780 | .data = { lq, }, |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 781 | }; |
| 782 | |
Johannes Berg | 76c3c69 | 2010-03-30 02:46:29 -0700 | [diff] [blame] | 783 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 784 | return -EINVAL; |
| 785 | |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 786 | |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 787 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 788 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 789 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 790 | return -EINVAL; |
| 791 | } |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 792 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Wey-Yi Guy | 40b97c2 | 2010-11-17 14:17:53 -0800 | [diff] [blame] | 793 | |
Tomas Winkler | 3ac7f14 | 2008-07-21 02:40:14 +0300 | [diff] [blame] | 794 | iwl_dump_lq_cmd(priv, lq); |
Johannes Berg | 3e41ace | 2011-04-18 09:12:37 -0700 | [diff] [blame] | 795 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) |
| 796 | return -EINVAL; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 797 | |
Johannes Berg | 7e6a588 | 2010-08-23 10:46:46 +0200 | [diff] [blame] | 798 | if (is_lq_table_valid(priv, ctx, lq)) |
Emmanuel Grumbach | e6bb4c9 | 2011-08-25 23:10:48 -0700 | [diff] [blame] | 799 | ret = iwl_trans_send_cmd(trans(priv), &cmd); |
Reinette Chatre | 3bce606 | 2010-04-13 16:11:19 -0700 | [diff] [blame] | 800 | else |
| 801 | ret = -EINVAL; |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 802 | |
| 803 | if (cmd.flags & CMD_ASYNC) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 804 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 805 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 806 | if (init) { |
Frans Pop | 91dd6c2 | 2010-03-24 14:19:58 -0700 | [diff] [blame] | 807 | IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n", |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 808 | lq->sta_id); |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 809 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 810 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; |
Emmanuel Grumbach | f39c95e | 2011-08-25 23:10:47 -0700 | [diff] [blame] | 811 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 812 | } |
Reinette Chatre | d2e210a | 2010-04-23 10:33:33 -0700 | [diff] [blame] | 813 | return ret; |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 814 | } |
Tomas Winkler | 66c73db | 2008-04-15 16:01:40 -0700 | [diff] [blame] | 815 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 816 | int iwl_mac_sta_remove(struct ieee80211_hw *hw, |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 817 | struct ieee80211_vif *vif, |
| 818 | struct ieee80211_sta *sta) |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 819 | { |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 820 | struct iwl_priv *priv = hw->priv; |
Johannes Berg | c689290 | 2011-09-20 15:37:21 -0700 | [diff] [blame] | 821 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; |
Johannes Berg | fd1af15 | 2010-04-30 11:30:43 -0700 | [diff] [blame] | 822 | int ret; |
| 823 | |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 824 | IWL_DEBUG_INFO(priv, "received request to remove station %pM\n", |
| 825 | sta->addr); |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 826 | mutex_lock(&priv->shrd->mutex); |
Reinette Chatre | da5ae1c | 2010-05-28 09:28:39 -0700 | [diff] [blame] | 827 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", |
| 828 | sta->addr); |
Johannes Berg | c689290 | 2011-09-20 15:37:21 -0700 | [diff] [blame] | 829 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 830 | if (ret) |
| 831 | IWL_ERR(priv, "Error removing station %pM\n", |
| 832 | sta->addr); |
Emmanuel Grumbach | 6ac2f83 | 2011-08-25 23:10:44 -0700 | [diff] [blame] | 833 | mutex_unlock(&priv->shrd->mutex); |
Reinette Chatre | fe6b23d | 2010-02-22 16:24:47 -0800 | [diff] [blame] | 834 | return ret; |
| 835 | } |