diff options
author | Wey-Yi Guy <wey-yi.w.guy@intel.com> | 2011-10-10 10:27:12 -0400 |
---|---|---|
committer | John W. Linville <linville@tuxdriver.com> | 2011-10-14 14:48:13 -0400 |
commit | c745f55baf63d08d6e9bb20682102fb8bae8f67a (patch) | |
tree | 133dbee0b351a2a8939db350147d98394a74fd59 /drivers/net | |
parent | ade4c649a0e9e862751fe1c98f43fbee86554c8a (diff) |
iwlagn: merge station management functions
After driver split, no need to separate station management functions
in two files, merge it
Signed-off-by: Wey-Yi Guy <wey-yi.w.guy@intel.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
Diffstat (limited to 'drivers/net')
-rw-r--r-- | drivers/net/wireless/iwlwifi/Makefile | 3 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-1000.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-2000.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-5000.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-6000.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-lib.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-rs.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-rxon.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-sta.c | 833 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn-tx.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-agn.h | 117 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-core.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-rx.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-scan.c | 1 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-sta.c | 839 | ||||
-rw-r--r-- | drivers/net/wireless/iwlwifi/iwl-sta.h | 143 |
17 files changed, 940 insertions, 1007 deletions
diff --git a/drivers/net/wireless/iwlwifi/Makefile b/drivers/net/wireless/iwlwifi/Makefile index bacafa4a5f4..3dfb9df4089 100644 --- a/drivers/net/wireless/iwlwifi/Makefile +++ b/drivers/net/wireless/iwlwifi/Makefile | |||
@@ -6,8 +6,7 @@ iwlwifi-objs += iwl-agn-lib.o iwl-agn-calib.o iwl-io.o | |||
6 | iwlwifi-objs += iwl-agn-tt.o iwl-agn-sta.o | 6 | iwlwifi-objs += iwl-agn-tt.o iwl-agn-sta.o |
7 | 7 | ||
8 | iwlwifi-objs += iwl-core.o iwl-eeprom.o iwl-power.o | 8 | iwlwifi-objs += iwl-core.o iwl-eeprom.o iwl-power.o |
9 | iwlwifi-objs += iwl-rx.o iwl-sta.o | 9 | iwlwifi-objs += iwl-rx.o iwl-scan.o iwl-led.o |
10 | iwlwifi-objs += iwl-scan.o iwl-led.o | ||
11 | iwlwifi-objs += iwl-agn-rxon.o | 10 | iwlwifi-objs += iwl-agn-rxon.o |
12 | iwlwifi-objs += iwl-5000.o | 11 | iwlwifi-objs += iwl-5000.o |
13 | iwlwifi-objs += iwl-6000.o | 12 | iwlwifi-objs += iwl-6000.o |
diff --git a/drivers/net/wireless/iwlwifi/iwl-1000.c b/drivers/net/wireless/iwlwifi/iwl-1000.c index dfd81debc32..0bf6afd8e65 100644 --- a/drivers/net/wireless/iwlwifi/iwl-1000.c +++ b/drivers/net/wireless/iwlwifi/iwl-1000.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include "iwl-dev.h" | 39 | #include "iwl-dev.h" |
40 | #include "iwl-core.h" | 40 | #include "iwl-core.h" |
41 | #include "iwl-io.h" | 41 | #include "iwl-io.h" |
42 | #include "iwl-sta.h" | ||
43 | #include "iwl-agn.h" | 42 | #include "iwl-agn.h" |
44 | #include "iwl-helpers.h" | 43 | #include "iwl-helpers.h" |
45 | #include "iwl-agn-hw.h" | 44 | #include "iwl-agn-hw.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-2000.c b/drivers/net/wireless/iwlwifi/iwl-2000.c index c7634b2d263..e969c5f2f4b 100644 --- a/drivers/net/wireless/iwlwifi/iwl-2000.c +++ b/drivers/net/wireless/iwlwifi/iwl-2000.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include "iwl-dev.h" | 39 | #include "iwl-dev.h" |
40 | #include "iwl-core.h" | 40 | #include "iwl-core.h" |
41 | #include "iwl-io.h" | 41 | #include "iwl-io.h" |
42 | #include "iwl-sta.h" | ||
43 | #include "iwl-agn.h" | 42 | #include "iwl-agn.h" |
44 | #include "iwl-helpers.h" | 43 | #include "iwl-helpers.h" |
45 | #include "iwl-agn-hw.h" | 44 | #include "iwl-agn-hw.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-5000.c b/drivers/net/wireless/iwlwifi/iwl-5000.c index e88aca5282e..b85e80a7136 100644 --- a/drivers/net/wireless/iwlwifi/iwl-5000.c +++ b/drivers/net/wireless/iwlwifi/iwl-5000.c | |||
@@ -40,7 +40,6 @@ | |||
40 | #include "iwl-dev.h" | 40 | #include "iwl-dev.h" |
41 | #include "iwl-core.h" | 41 | #include "iwl-core.h" |
42 | #include "iwl-io.h" | 42 | #include "iwl-io.h" |
43 | #include "iwl-sta.h" | ||
44 | #include "iwl-helpers.h" | 43 | #include "iwl-helpers.h" |
45 | #include "iwl-agn.h" | 44 | #include "iwl-agn.h" |
46 | #include "iwl-agn-hw.h" | 45 | #include "iwl-agn-hw.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-6000.c b/drivers/net/wireless/iwlwifi/iwl-6000.c index 4abfcf2f257..aece578226c 100644 --- a/drivers/net/wireless/iwlwifi/iwl-6000.c +++ b/drivers/net/wireless/iwlwifi/iwl-6000.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include "iwl-dev.h" | 39 | #include "iwl-dev.h" |
40 | #include "iwl-core.h" | 40 | #include "iwl-core.h" |
41 | #include "iwl-io.h" | 41 | #include "iwl-io.h" |
42 | #include "iwl-sta.h" | ||
43 | #include "iwl-agn.h" | 42 | #include "iwl-agn.h" |
44 | #include "iwl-helpers.h" | 43 | #include "iwl-helpers.h" |
45 | #include "iwl-agn-hw.h" | 44 | #include "iwl-agn-hw.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c index d30714be515..b1746f9b664 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-lib.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-lib.c | |||
@@ -38,7 +38,6 @@ | |||
38 | #include "iwl-helpers.h" | 38 | #include "iwl-helpers.h" |
39 | #include "iwl-agn-hw.h" | 39 | #include "iwl-agn-hw.h" |
40 | #include "iwl-agn.h" | 40 | #include "iwl-agn.h" |
41 | #include "iwl-sta.h" | ||
42 | #include "iwl-trans.h" | 41 | #include "iwl-trans.h" |
43 | #include "iwl-shared.h" | 42 | #include "iwl-shared.h" |
44 | 43 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c index 353af8f995b..66118cea2af 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-rs.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-rs.c | |||
@@ -36,7 +36,6 @@ | |||
36 | #include <linux/workqueue.h> | 36 | #include <linux/workqueue.h> |
37 | 37 | ||
38 | #include "iwl-dev.h" | 38 | #include "iwl-dev.h" |
39 | #include "iwl-sta.h" | ||
40 | #include "iwl-core.h" | 39 | #include "iwl-core.h" |
41 | #include "iwl-agn.h" | 40 | #include "iwl-agn.h" |
42 | 41 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c index 81555223262..68bdc195e4f 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-rxon.c | |||
@@ -26,7 +26,6 @@ | |||
26 | 26 | ||
27 | #include "iwl-dev.h" | 27 | #include "iwl-dev.h" |
28 | #include "iwl-agn.h" | 28 | #include "iwl-agn.h" |
29 | #include "iwl-sta.h" | ||
30 | #include "iwl-core.h" | 29 | #include "iwl-core.h" |
31 | #include "iwl-agn-calib.h" | 30 | #include "iwl-agn-calib.h" |
32 | #include "iwl-helpers.h" | 31 | #include "iwl-helpers.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c index c1807fa1d17..ed628362393 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-sta.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-sta.c | |||
@@ -31,10 +31,823 @@ | |||
31 | 31 | ||
32 | #include "iwl-dev.h" | 32 | #include "iwl-dev.h" |
33 | #include "iwl-core.h" | 33 | #include "iwl-core.h" |
34 | #include "iwl-sta.h" | ||
35 | #include "iwl-agn.h" | 34 | #include "iwl-agn.h" |
36 | #include "iwl-trans.h" | 35 | #include "iwl-trans.h" |
37 | 36 | ||
37 | /* priv->shrd->sta_lock must be held */ | ||
38 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) | ||
39 | { | ||
40 | |||
41 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) | ||
42 | IWL_ERR(priv, "ACTIVATE a non DRIVER active station id %u " | ||
43 | "addr %pM\n", | ||
44 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
45 | |||
46 | if (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) { | ||
47 | IWL_DEBUG_ASSOC(priv, | ||
48 | "STA id %u addr %pM already present in uCode " | ||
49 | "(according to driver)\n", | ||
50 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
51 | } else { | ||
52 | priv->stations[sta_id].used |= IWL_STA_UCODE_ACTIVE; | ||
53 | IWL_DEBUG_ASSOC(priv, "Added STA id %u addr %pM to uCode\n", | ||
54 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | static int iwl_process_add_sta_resp(struct iwl_priv *priv, | ||
59 | struct iwl_addsta_cmd *addsta, | ||
60 | struct iwl_rx_packet *pkt) | ||
61 | { | ||
62 | u8 sta_id = addsta->sta.sta_id; | ||
63 | unsigned long flags; | ||
64 | int ret = -EIO; | ||
65 | |||
66 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
67 | IWL_ERR(priv, "Bad return from REPLY_ADD_STA (0x%08X)\n", | ||
68 | pkt->hdr.flags); | ||
69 | return ret; | ||
70 | } | ||
71 | |||
72 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", | ||
73 | sta_id); | ||
74 | |||
75 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
76 | |||
77 | switch (pkt->u.add_sta.status) { | ||
78 | case ADD_STA_SUCCESS_MSK: | ||
79 | IWL_DEBUG_INFO(priv, "REPLY_ADD_STA PASSED\n"); | ||
80 | iwl_sta_ucode_activate(priv, sta_id); | ||
81 | ret = 0; | ||
82 | break; | ||
83 | case ADD_STA_NO_ROOM_IN_TABLE: | ||
84 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", | ||
85 | sta_id); | ||
86 | break; | ||
87 | case ADD_STA_NO_BLOCK_ACK_RESOURCE: | ||
88 | IWL_ERR(priv, "Adding station %d failed, no block ack " | ||
89 | "resource.\n", sta_id); | ||
90 | break; | ||
91 | case ADD_STA_MODIFY_NON_EXIST_STA: | ||
92 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", | ||
93 | sta_id); | ||
94 | break; | ||
95 | default: | ||
96 | IWL_DEBUG_ASSOC(priv, "Received REPLY_ADD_STA:(0x%08X)\n", | ||
97 | pkt->u.add_sta.status); | ||
98 | break; | ||
99 | } | ||
100 | |||
101 | IWL_DEBUG_INFO(priv, "%s station id %u addr %pM\n", | ||
102 | priv->stations[sta_id].sta.mode == | ||
103 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", | ||
104 | sta_id, priv->stations[sta_id].sta.sta.addr); | ||
105 | |||
106 | /* | ||
107 | * XXX: The MAC address in the command buffer is often changed from | ||
108 | * the original sent to the device. That is, the MAC address | ||
109 | * written to the command buffer often is not the same MAC address | ||
110 | * read from the command buffer when the command returns. This | ||
111 | * issue has not yet been resolved and this debugging is left to | ||
112 | * observe the problem. | ||
113 | */ | ||
114 | IWL_DEBUG_INFO(priv, "%s station according to cmd buffer %pM\n", | ||
115 | priv->stations[sta_id].sta.mode == | ||
116 | STA_CONTROL_MODIFY_MSK ? "Modified" : "Added", | ||
117 | addsta->sta.addr); | ||
118 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
119 | |||
120 | return ret; | ||
121 | } | ||
122 | |||
123 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, | ||
124 | struct iwl_device_cmd *cmd) | ||
125 | { | ||
126 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
127 | struct iwl_addsta_cmd *addsta = | ||
128 | (struct iwl_addsta_cmd *) cmd->payload; | ||
129 | |||
130 | return iwl_process_add_sta_resp(priv, addsta, pkt); | ||
131 | } | ||
132 | |||
133 | static u16 iwlagn_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data) | ||
134 | { | ||
135 | u16 size = (u16)sizeof(struct iwl_addsta_cmd); | ||
136 | struct iwl_addsta_cmd *addsta = (struct iwl_addsta_cmd *)data; | ||
137 | memcpy(addsta, cmd, size); | ||
138 | /* resrved in 5000 */ | ||
139 | addsta->rate_n_flags = cpu_to_le16(0); | ||
140 | return size; | ||
141 | } | ||
142 | |||
143 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
144 | struct iwl_addsta_cmd *sta, u8 flags) | ||
145 | { | ||
146 | int ret = 0; | ||
147 | u8 data[sizeof(*sta)]; | ||
148 | struct iwl_host_cmd cmd = { | ||
149 | .id = REPLY_ADD_STA, | ||
150 | .flags = flags, | ||
151 | .data = { data, }, | ||
152 | }; | ||
153 | u8 sta_id __maybe_unused = sta->sta.sta_id; | ||
154 | |||
155 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", | ||
156 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); | ||
157 | |||
158 | if (!(flags & CMD_ASYNC)) { | ||
159 | cmd.flags |= CMD_WANT_SKB; | ||
160 | might_sleep(); | ||
161 | } | ||
162 | |||
163 | cmd.len[0] = iwlagn_build_addsta_hcmd(sta, data); | ||
164 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
165 | |||
166 | if (ret || (flags & CMD_ASYNC)) | ||
167 | return ret; | ||
168 | /*else the command was successfully sent in SYNC mode, need to free | ||
169 | * the reply page */ | ||
170 | |||
171 | iwl_free_pages(priv->shrd, cmd.reply_page); | ||
172 | |||
173 | if (cmd.handler_status) | ||
174 | IWL_ERR(priv, "%s - error in the CMD response %d", __func__, | ||
175 | cmd.handler_status); | ||
176 | |||
177 | return cmd.handler_status; | ||
178 | } | ||
179 | |||
180 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | ||
181 | struct ieee80211_sta *sta, | ||
182 | struct iwl_rxon_context *ctx) | ||
183 | { | ||
184 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; | ||
185 | __le32 sta_flags; | ||
186 | u8 mimo_ps_mode; | ||
187 | |||
188 | if (!sta || !sta_ht_inf->ht_supported) | ||
189 | goto done; | ||
190 | |||
191 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; | ||
192 | IWL_DEBUG_ASSOC(priv, "spatial multiplexing power save mode: %s\n", | ||
193 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_STATIC) ? | ||
194 | "static" : | ||
195 | (mimo_ps_mode == WLAN_HT_CAP_SM_PS_DYNAMIC) ? | ||
196 | "dynamic" : "disabled"); | ||
197 | |||
198 | sta_flags = priv->stations[index].sta.station_flags; | ||
199 | |||
200 | sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK); | ||
201 | |||
202 | switch (mimo_ps_mode) { | ||
203 | case WLAN_HT_CAP_SM_PS_STATIC: | ||
204 | sta_flags |= STA_FLG_MIMO_DIS_MSK; | ||
205 | break; | ||
206 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | ||
207 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; | ||
208 | break; | ||
209 | case WLAN_HT_CAP_SM_PS_DISABLED: | ||
210 | break; | ||
211 | default: | ||
212 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); | ||
213 | break; | ||
214 | } | ||
215 | |||
216 | sta_flags |= cpu_to_le32( | ||
217 | (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS); | ||
218 | |||
219 | sta_flags |= cpu_to_le32( | ||
220 | (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS); | ||
221 | |||
222 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
223 | sta_flags |= STA_FLG_HT40_EN_MSK; | ||
224 | else | ||
225 | sta_flags &= ~STA_FLG_HT40_EN_MSK; | ||
226 | |||
227 | priv->stations[index].sta.station_flags = sta_flags; | ||
228 | done: | ||
229 | return; | ||
230 | } | ||
231 | |||
232 | /** | ||
233 | * iwl_prep_station - Prepare station information for addition | ||
234 | * | ||
235 | * should be called with sta_lock held | ||
236 | */ | ||
237 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
238 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta) | ||
239 | { | ||
240 | struct iwl_station_entry *station; | ||
241 | int i; | ||
242 | u8 sta_id = IWL_INVALID_STATION; | ||
243 | |||
244 | if (is_ap) | ||
245 | sta_id = ctx->ap_sta_id; | ||
246 | else if (is_broadcast_ether_addr(addr)) | ||
247 | sta_id = ctx->bcast_sta_id; | ||
248 | else | ||
249 | for (i = IWL_STA_ID; i < IWLAGN_STATION_COUNT; i++) { | ||
250 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, | ||
251 | addr)) { | ||
252 | sta_id = i; | ||
253 | break; | ||
254 | } | ||
255 | |||
256 | if (!priv->stations[i].used && | ||
257 | sta_id == IWL_INVALID_STATION) | ||
258 | sta_id = i; | ||
259 | } | ||
260 | |||
261 | /* | ||
262 | * These two conditions have the same outcome, but keep them | ||
263 | * separate | ||
264 | */ | ||
265 | if (unlikely(sta_id == IWL_INVALID_STATION)) | ||
266 | return sta_id; | ||
267 | |||
268 | /* | ||
269 | * uCode is not able to deal with multiple requests to add a | ||
270 | * station. Keep track if one is in progress so that we do not send | ||
271 | * another. | ||
272 | */ | ||
273 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
274 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " | ||
275 | "added.\n", sta_id); | ||
276 | return sta_id; | ||
277 | } | ||
278 | |||
279 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
280 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && | ||
281 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { | ||
282 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " | ||
283 | "adding again.\n", sta_id, addr); | ||
284 | return sta_id; | ||
285 | } | ||
286 | |||
287 | station = &priv->stations[sta_id]; | ||
288 | station->used = IWL_STA_DRIVER_ACTIVE; | ||
289 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", | ||
290 | sta_id, addr); | ||
291 | priv->num_stations++; | ||
292 | |||
293 | /* Set up the REPLY_ADD_STA command to send to device */ | ||
294 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); | ||
295 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); | ||
296 | station->sta.mode = 0; | ||
297 | station->sta.sta.sta_id = sta_id; | ||
298 | station->sta.station_flags = ctx->station_flags; | ||
299 | station->ctxid = ctx->ctxid; | ||
300 | |||
301 | if (sta) { | ||
302 | struct iwl_station_priv *sta_priv; | ||
303 | |||
304 | sta_priv = (void *)sta->drv_priv; | ||
305 | sta_priv->ctx = ctx; | ||
306 | } | ||
307 | |||
308 | /* | ||
309 | * OK to call unconditionally, since local stations (IBSS BSSID | ||
310 | * STA and broadcast STA) pass in a NULL sta, and mac80211 | ||
311 | * doesn't allow HT IBSS. | ||
312 | */ | ||
313 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); | ||
314 | |||
315 | return sta_id; | ||
316 | |||
317 | } | ||
318 | |||
319 | #define STA_WAIT_TIMEOUT (HZ/2) | ||
320 | |||
321 | /** | ||
322 | * iwl_add_station_common - | ||
323 | */ | ||
324 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
325 | const u8 *addr, bool is_ap, | ||
326 | struct ieee80211_sta *sta, u8 *sta_id_r) | ||
327 | { | ||
328 | unsigned long flags_spin; | ||
329 | int ret = 0; | ||
330 | u8 sta_id; | ||
331 | struct iwl_addsta_cmd sta_cmd; | ||
332 | |||
333 | *sta_id_r = 0; | ||
334 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
335 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); | ||
336 | if (sta_id == IWL_INVALID_STATION) { | ||
337 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", | ||
338 | addr); | ||
339 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
340 | return -EINVAL; | ||
341 | } | ||
342 | |||
343 | /* | ||
344 | * uCode is not able to deal with multiple requests to add a | ||
345 | * station. Keep track if one is in progress so that we do not send | ||
346 | * another. | ||
347 | */ | ||
348 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
349 | IWL_DEBUG_INFO(priv, "STA %d already in process of being " | ||
350 | "added.\n", sta_id); | ||
351 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
352 | return -EEXIST; | ||
353 | } | ||
354 | |||
355 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
356 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
357 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not " | ||
358 | "adding again.\n", sta_id, addr); | ||
359 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
360 | return -EEXIST; | ||
361 | } | ||
362 | |||
363 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; | ||
364 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, | ||
365 | sizeof(struct iwl_addsta_cmd)); | ||
366 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
367 | |||
368 | /* Add station to device's station table */ | ||
369 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
370 | if (ret) { | ||
371 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
372 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
373 | priv->stations[sta_id].sta.sta.addr); | ||
374 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
375 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
376 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
377 | } | ||
378 | *sta_id_r = sta_id; | ||
379 | return ret; | ||
380 | } | ||
381 | |||
382 | /** | ||
383 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station | ||
384 | * | ||
385 | * priv->shrd->sta_lock must be held | ||
386 | */ | ||
387 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) | ||
388 | { | ||
389 | /* Ucode must be active and driver must be non active */ | ||
390 | if ((priv->stations[sta_id].used & | ||
391 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != | ||
392 | IWL_STA_UCODE_ACTIVE) | ||
393 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); | ||
394 | |||
395 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; | ||
396 | |||
397 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); | ||
398 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); | ||
399 | } | ||
400 | |||
401 | static int iwl_send_remove_station(struct iwl_priv *priv, | ||
402 | const u8 *addr, int sta_id, | ||
403 | bool temporary) | ||
404 | { | ||
405 | struct iwl_rx_packet *pkt; | ||
406 | int ret; | ||
407 | |||
408 | unsigned long flags_spin; | ||
409 | struct iwl_rem_sta_cmd rm_sta_cmd; | ||
410 | |||
411 | struct iwl_host_cmd cmd = { | ||
412 | .id = REPLY_REMOVE_STA, | ||
413 | .len = { sizeof(struct iwl_rem_sta_cmd), }, | ||
414 | .flags = CMD_SYNC, | ||
415 | .data = { &rm_sta_cmd, }, | ||
416 | }; | ||
417 | |||
418 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); | ||
419 | rm_sta_cmd.num_sta = 1; | ||
420 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); | ||
421 | |||
422 | cmd.flags |= CMD_WANT_SKB; | ||
423 | |||
424 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
425 | |||
426 | if (ret) | ||
427 | return ret; | ||
428 | |||
429 | pkt = (struct iwl_rx_packet *)cmd.reply_page; | ||
430 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
431 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", | ||
432 | pkt->hdr.flags); | ||
433 | ret = -EIO; | ||
434 | } | ||
435 | |||
436 | if (!ret) { | ||
437 | switch (pkt->u.rem_sta.status) { | ||
438 | case REM_STA_SUCCESS_MSK: | ||
439 | if (!temporary) { | ||
440 | spin_lock_irqsave(&priv->shrd->sta_lock, | ||
441 | flags_spin); | ||
442 | iwl_sta_ucode_deactivate(priv, sta_id); | ||
443 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
444 | flags_spin); | ||
445 | } | ||
446 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); | ||
447 | break; | ||
448 | default: | ||
449 | ret = -EIO; | ||
450 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); | ||
451 | break; | ||
452 | } | ||
453 | } | ||
454 | iwl_free_pages(priv->shrd, cmd.reply_page); | ||
455 | |||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * iwl_remove_station - Remove driver's knowledge of station. | ||
461 | */ | ||
462 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
463 | const u8 *addr) | ||
464 | { | ||
465 | unsigned long flags; | ||
466 | |||
467 | if (!iwl_is_ready(priv->shrd)) { | ||
468 | IWL_DEBUG_INFO(priv, | ||
469 | "Unable to remove station %pM, device not ready.\n", | ||
470 | addr); | ||
471 | /* | ||
472 | * It is typical for stations to be removed when we are | ||
473 | * going down. Return success since device will be down | ||
474 | * soon anyway | ||
475 | */ | ||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", | ||
480 | sta_id, addr); | ||
481 | |||
482 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) | ||
483 | return -EINVAL; | ||
484 | |||
485 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
486 | |||
487 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
488 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", | ||
489 | addr); | ||
490 | goto out_err; | ||
491 | } | ||
492 | |||
493 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
494 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", | ||
495 | addr); | ||
496 | goto out_err; | ||
497 | } | ||
498 | |||
499 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { | ||
500 | kfree(priv->stations[sta_id].lq); | ||
501 | priv->stations[sta_id].lq = NULL; | ||
502 | } | ||
503 | |||
504 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
505 | |||
506 | priv->num_stations--; | ||
507 | |||
508 | if (WARN_ON(priv->num_stations < 0)) | ||
509 | priv->num_stations = 0; | ||
510 | |||
511 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
512 | |||
513 | return iwl_send_remove_station(priv, addr, sta_id, false); | ||
514 | out_err: | ||
515 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
516 | return -EINVAL; | ||
517 | } | ||
518 | |||
519 | /** | ||
520 | * iwl_clear_ucode_stations - clear ucode station table bits | ||
521 | * | ||
522 | * This function clears all the bits in the driver indicating | ||
523 | * which stations are active in the ucode. Call when something | ||
524 | * other than explicit station management would cause this in | ||
525 | * the ucode, e.g. unassociated RXON. | ||
526 | */ | ||
527 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
528 | struct iwl_rxon_context *ctx) | ||
529 | { | ||
530 | int i; | ||
531 | unsigned long flags_spin; | ||
532 | bool cleared = false; | ||
533 | |||
534 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); | ||
535 | |||
536 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
537 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
538 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) | ||
539 | continue; | ||
540 | |||
541 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { | ||
542 | IWL_DEBUG_INFO(priv, | ||
543 | "Clearing ucode active for station %d\n", i); | ||
544 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
545 | cleared = true; | ||
546 | } | ||
547 | } | ||
548 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
549 | |||
550 | if (!cleared) | ||
551 | IWL_DEBUG_INFO(priv, | ||
552 | "No active stations found to be cleared\n"); | ||
553 | } | ||
554 | |||
555 | /** | ||
556 | * iwl_restore_stations() - Restore driver known stations to device | ||
557 | * | ||
558 | * All stations considered active by driver, but not present in ucode, is | ||
559 | * restored. | ||
560 | * | ||
561 | * Function sleeps. | ||
562 | */ | ||
563 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
564 | { | ||
565 | struct iwl_addsta_cmd sta_cmd; | ||
566 | struct iwl_link_quality_cmd lq; | ||
567 | unsigned long flags_spin; | ||
568 | int i; | ||
569 | bool found = false; | ||
570 | int ret; | ||
571 | bool send_lq; | ||
572 | |||
573 | if (!iwl_is_ready(priv->shrd)) { | ||
574 | IWL_DEBUG_INFO(priv, | ||
575 | "Not ready yet, not restoring any stations.\n"); | ||
576 | return; | ||
577 | } | ||
578 | |||
579 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); | ||
580 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
581 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
582 | if (ctx->ctxid != priv->stations[i].ctxid) | ||
583 | continue; | ||
584 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && | ||
585 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { | ||
586 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", | ||
587 | priv->stations[i].sta.sta.addr); | ||
588 | priv->stations[i].sta.mode = 0; | ||
589 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; | ||
590 | found = true; | ||
591 | } | ||
592 | } | ||
593 | |||
594 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
595 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { | ||
596 | memcpy(&sta_cmd, &priv->stations[i].sta, | ||
597 | sizeof(struct iwl_addsta_cmd)); | ||
598 | send_lq = false; | ||
599 | if (priv->stations[i].lq) { | ||
600 | if (priv->shrd->wowlan) | ||
601 | iwl_sta_fill_lq(priv, ctx, i, &lq); | ||
602 | else | ||
603 | memcpy(&lq, priv->stations[i].lq, | ||
604 | sizeof(struct iwl_link_quality_cmd)); | ||
605 | send_lq = true; | ||
606 | } | ||
607 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
608 | flags_spin); | ||
609 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
610 | if (ret) { | ||
611 | spin_lock_irqsave(&priv->shrd->sta_lock, | ||
612 | flags_spin); | ||
613 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
614 | priv->stations[i].sta.sta.addr); | ||
615 | priv->stations[i].used &= | ||
616 | ~IWL_STA_DRIVER_ACTIVE; | ||
617 | priv->stations[i].used &= | ||
618 | ~IWL_STA_UCODE_INPROGRESS; | ||
619 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
620 | flags_spin); | ||
621 | } | ||
622 | /* | ||
623 | * Rate scaling has already been initialized, send | ||
624 | * current LQ command | ||
625 | */ | ||
626 | if (send_lq) | ||
627 | iwl_send_lq_cmd(priv, ctx, &lq, | ||
628 | CMD_SYNC, true); | ||
629 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
630 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
631 | } | ||
632 | } | ||
633 | |||
634 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
635 | if (!found) | ||
636 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " | ||
637 | "no stations to be restored.\n"); | ||
638 | else | ||
639 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... " | ||
640 | "complete.\n"); | ||
641 | } | ||
642 | |||
643 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
644 | { | ||
645 | unsigned long flags; | ||
646 | int sta_id = ctx->ap_sta_id; | ||
647 | int ret; | ||
648 | struct iwl_addsta_cmd sta_cmd; | ||
649 | struct iwl_link_quality_cmd lq; | ||
650 | bool active; | ||
651 | |||
652 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
653 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
654 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
655 | return; | ||
656 | } | ||
657 | |||
658 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); | ||
659 | sta_cmd.mode = 0; | ||
660 | memcpy(&lq, priv->stations[sta_id].lq, sizeof(lq)); | ||
661 | |||
662 | active = priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE; | ||
663 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
664 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
665 | |||
666 | if (active) { | ||
667 | ret = iwl_send_remove_station( | ||
668 | priv, priv->stations[sta_id].sta.sta.addr, | ||
669 | sta_id, true); | ||
670 | if (ret) | ||
671 | IWL_ERR(priv, "failed to remove STA %pM (%d)\n", | ||
672 | priv->stations[sta_id].sta.sta.addr, ret); | ||
673 | } | ||
674 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
675 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | ||
676 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
677 | |||
678 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
679 | if (ret) | ||
680 | IWL_ERR(priv, "failed to re-add STA %pM (%d)\n", | ||
681 | priv->stations[sta_id].sta.sta.addr, ret); | ||
682 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); | ||
683 | } | ||
684 | |||
685 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv) | ||
686 | { | ||
687 | int i; | ||
688 | |||
689 | for (i = 0; i < priv->sta_key_max_num; i++) | ||
690 | if (!test_and_set_bit(i, &priv->ucode_key_table)) | ||
691 | return i; | ||
692 | |||
693 | return WEP_INVALID_OFFSET; | ||
694 | } | ||
695 | |||
696 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) | ||
697 | { | ||
698 | unsigned long flags; | ||
699 | int i; | ||
700 | |||
701 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
702 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
703 | if (!(priv->stations[i].used & IWL_STA_BCAST)) | ||
704 | continue; | ||
705 | |||
706 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
707 | priv->num_stations--; | ||
708 | if (WARN_ON(priv->num_stations < 0)) | ||
709 | priv->num_stations = 0; | ||
710 | kfree(priv->stations[i].lq); | ||
711 | priv->stations[i].lq = NULL; | ||
712 | } | ||
713 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
714 | } | ||
715 | |||
716 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
717 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
718 | struct iwl_link_quality_cmd *lq) | ||
719 | { | ||
720 | int i; | ||
721 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); | ||
722 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", | ||
723 | lq->general_params.single_stream_ant_msk, | ||
724 | lq->general_params.dual_stream_ant_msk); | ||
725 | |||
726 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) | ||
727 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", | ||
728 | i, lq->rs_table[i].rate_n_flags); | ||
729 | } | ||
730 | #else | ||
731 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
732 | struct iwl_link_quality_cmd *lq) | ||
733 | { | ||
734 | } | ||
735 | #endif | ||
736 | |||
737 | /** | ||
738 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity | ||
739 | * | ||
740 | * It sometimes happens when a HT rate has been in use and we | ||
741 | * loose connectivity with AP then mac80211 will first tell us that the | ||
742 | * current channel is not HT anymore before removing the station. In such a | ||
743 | * scenario the RXON flags will be updated to indicate we are not | ||
744 | * communicating HT anymore, but the LQ command may still contain HT rates. | ||
745 | * Test for this to prevent driver from sending LQ command between the time | ||
746 | * RXON flags are updated and when LQ command is updated. | ||
747 | */ | ||
748 | static bool is_lq_table_valid(struct iwl_priv *priv, | ||
749 | struct iwl_rxon_context *ctx, | ||
750 | struct iwl_link_quality_cmd *lq) | ||
751 | { | ||
752 | int i; | ||
753 | |||
754 | if (ctx->ht.enabled) | ||
755 | return true; | ||
756 | |||
757 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", | ||
758 | ctx->active.channel); | ||
759 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | ||
760 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & | ||
761 | RATE_MCS_HT_MSK) { | ||
762 | IWL_DEBUG_INFO(priv, | ||
763 | "index %d of LQ expects HT channel\n", | ||
764 | i); | ||
765 | return false; | ||
766 | } | ||
767 | } | ||
768 | return true; | ||
769 | } | ||
770 | |||
771 | /** | ||
772 | * iwl_send_lq_cmd() - Send link quality command | ||
773 | * @init: This command is sent as part of station initialization right | ||
774 | * after station has been added. | ||
775 | * | ||
776 | * The link quality command is sent as the last step of station creation. | ||
777 | * This is the special case in which init is set and we call a callback in | ||
778 | * this case to clear the state indicating that station creation is in | ||
779 | * progress. | ||
780 | */ | ||
781 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
782 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) | ||
783 | { | ||
784 | int ret = 0; | ||
785 | unsigned long flags_spin; | ||
786 | |||
787 | struct iwl_host_cmd cmd = { | ||
788 | .id = REPLY_TX_LINK_QUALITY_CMD, | ||
789 | .len = { sizeof(struct iwl_link_quality_cmd), }, | ||
790 | .flags = flags, | ||
791 | .data = { lq, }, | ||
792 | }; | ||
793 | |||
794 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) | ||
795 | return -EINVAL; | ||
796 | |||
797 | |||
798 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
799 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
800 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
801 | return -EINVAL; | ||
802 | } | ||
803 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
804 | |||
805 | iwl_dump_lq_cmd(priv, lq); | ||
806 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) | ||
807 | return -EINVAL; | ||
808 | |||
809 | if (is_lq_table_valid(priv, ctx, lq)) | ||
810 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
811 | else | ||
812 | ret = -EINVAL; | ||
813 | |||
814 | if (cmd.flags & CMD_ASYNC) | ||
815 | return ret; | ||
816 | |||
817 | if (init) { | ||
818 | IWL_DEBUG_INFO(priv, "init LQ command complete, " | ||
819 | "clearing sta addition status for sta %d\n", | ||
820 | lq->sta_id); | ||
821 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
822 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
823 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
824 | } | ||
825 | return ret; | ||
826 | } | ||
827 | |||
828 | int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, | ||
829 | struct ieee80211_vif *vif, | ||
830 | struct ieee80211_sta *sta) | ||
831 | { | ||
832 | struct iwl_priv *priv = hw->priv; | ||
833 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
834 | int ret; | ||
835 | |||
836 | IWL_DEBUG_MAC80211(priv, "enter: received request to remove " | ||
837 | "station %pM\n", sta->addr); | ||
838 | mutex_lock(&priv->shrd->mutex); | ||
839 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", | ||
840 | sta->addr); | ||
841 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); | ||
842 | if (ret) | ||
843 | IWL_ERR(priv, "Error removing station %pM\n", | ||
844 | sta->addr); | ||
845 | mutex_unlock(&priv->shrd->mutex); | ||
846 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
847 | |||
848 | return ret; | ||
849 | } | ||
850 | |||
38 | void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | 851 | void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
39 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd) | 852 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd) |
40 | { | 853 | { |
@@ -77,7 +890,8 @@ void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | |||
77 | hw_params(priv).valid_tx_ant; | 890 | hw_params(priv).valid_tx_ant; |
78 | } | 891 | } |
79 | 892 | ||
80 | link_cmd->agg_params.agg_dis_start_th = LINK_QUAL_AGG_DISABLE_START_DEF; | 893 | link_cmd->agg_params.agg_dis_start_th = |
894 | LINK_QUAL_AGG_DISABLE_START_DEF; | ||
81 | link_cmd->agg_params.agg_time_limit = | 895 | link_cmd->agg_params.agg_time_limit = |
82 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); | 896 | cpu_to_le16(LINK_QUAL_AGG_TIME_LIMIT_DEF); |
83 | 897 | ||
@@ -85,7 +899,8 @@ void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | |||
85 | } | 899 | } |
86 | 900 | ||
87 | static struct iwl_link_quality_cmd * | 901 | static struct iwl_link_quality_cmd * |
88 | iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id) | 902 | iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
903 | u8 sta_id) | ||
89 | { | 904 | { |
90 | struct iwl_link_quality_cmd *link_cmd; | 905 | struct iwl_link_quality_cmd *link_cmd; |
91 | 906 | ||
@@ -105,7 +920,8 @@ iwl_sta_alloc_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, u8 sta_id) | |||
105 | * | 920 | * |
106 | * Function sleeps. | 921 | * Function sleeps. |
107 | */ | 922 | */ |
108 | int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | 923 | int iwlagn_add_bssid_station(struct iwl_priv *priv, |
924 | struct iwl_rxon_context *ctx, | ||
109 | const u8 *addr, u8 *sta_id_r) | 925 | const u8 *addr, u8 *sta_id_r) |
110 | { | 926 | { |
111 | int ret; | 927 | int ret; |
@@ -132,7 +948,8 @@ int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx | |||
132 | /* Set up default rate scaling table in device's station table */ | 948 | /* Set up default rate scaling table in device's station table */ |
133 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); | 949 | link_cmd = iwl_sta_alloc_lq(priv, ctx, sta_id); |
134 | if (!link_cmd) { | 950 | if (!link_cmd) { |
135 | IWL_ERR(priv, "Unable to initialize rate scaling for station %pM.\n", | 951 | IWL_ERR(priv, |
952 | "Unable to initialize rate scaling for station %pM.\n", | ||
136 | addr); | 953 | addr); |
137 | return -ENOMEM; | 954 | return -ENOMEM; |
138 | } | 955 | } |
@@ -224,7 +1041,8 @@ int iwl_remove_default_wep_key(struct iwl_priv *priv, | |||
224 | 1041 | ||
225 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); | 1042 | memset(&ctx->wep_keys[keyconf->keyidx], 0, sizeof(ctx->wep_keys[0])); |
226 | if (iwl_is_rfkill(priv->shrd)) { | 1043 | if (iwl_is_rfkill(priv->shrd)) { |
227 | IWL_DEBUG_WEP(priv, "Not sending REPLY_WEPKEY command due to RFKILL.\n"); | 1044 | IWL_DEBUG_WEP(priv, |
1045 | "Not sending REPLY_WEPKEY command due to RFKILL.\n"); | ||
228 | /* but keys in device are clear anyway so return success */ | 1046 | /* but keys in device are clear anyway so return success */ |
229 | return 0; | 1047 | return 0; |
230 | } | 1048 | } |
@@ -245,7 +1063,8 @@ int iwl_set_default_wep_key(struct iwl_priv *priv, | |||
245 | 1063 | ||
246 | if (keyconf->keylen != WEP_KEY_LEN_128 && | 1064 | if (keyconf->keylen != WEP_KEY_LEN_128 && |
247 | keyconf->keylen != WEP_KEY_LEN_64) { | 1065 | keyconf->keylen != WEP_KEY_LEN_64) { |
248 | IWL_DEBUG_WEP(priv, "Bad WEP key length %d\n", keyconf->keylen); | 1066 | IWL_DEBUG_WEP(priv, |
1067 | "Bad WEP key length %d\n", keyconf->keylen); | ||
249 | return -EINVAL; | 1068 | return -EINVAL; |
250 | } | 1069 | } |
251 | 1070 | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c index f849097cf7e..d7e48f26270 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn-tx.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn-tx.c | |||
@@ -35,7 +35,6 @@ | |||
35 | 35 | ||
36 | #include "iwl-dev.h" | 36 | #include "iwl-dev.h" |
37 | #include "iwl-core.h" | 37 | #include "iwl-core.h" |
38 | #include "iwl-sta.h" | ||
39 | #include "iwl-io.h" | 38 | #include "iwl-io.h" |
40 | #include "iwl-helpers.h" | 39 | #include "iwl-helpers.h" |
41 | #include "iwl-agn-hw.h" | 40 | #include "iwl-agn-hw.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c index 6c57199b041..5a78480e452 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.c +++ b/drivers/net/wireless/iwlwifi/iwl-agn.c | |||
@@ -48,7 +48,6 @@ | |||
48 | #include "iwl-core.h" | 48 | #include "iwl-core.h" |
49 | #include "iwl-io.h" | 49 | #include "iwl-io.h" |
50 | #include "iwl-helpers.h" | 50 | #include "iwl-helpers.h" |
51 | #include "iwl-sta.h" | ||
52 | #include "iwl-agn-calib.h" | 51 | #include "iwl-agn-calib.h" |
53 | #include "iwl-agn.h" | 52 | #include "iwl-agn.h" |
54 | #include "iwl-shared.h" | 53 | #include "iwl-shared.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.h b/drivers/net/wireless/iwlwifi/iwl-agn.h index a8df7eb596c..5b936ec1a54 100644 --- a/drivers/net/wireless/iwlwifi/iwl-agn.h +++ b/drivers/net/wireless/iwlwifi/iwl-agn.h | |||
@@ -152,10 +152,6 @@ u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant_idx, u8 valid); | |||
152 | void iwlagn_post_scan(struct iwl_priv *priv); | 152 | void iwlagn_post_scan(struct iwl_priv *priv); |
153 | void iwlagn_disable_roc(struct iwl_priv *priv); | 153 | void iwlagn_disable_roc(struct iwl_priv *priv); |
154 | 154 | ||
155 | /* station mgmt */ | ||
156 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, | ||
157 | struct ieee80211_vif *vif, bool add); | ||
158 | |||
159 | /* bt coex */ | 155 | /* bt coex */ |
160 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv); | 156 | void iwlagn_send_advance_bt_config(struct iwl_priv *priv); |
161 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, | 157 | int iwlagn_bt_coex_profile_notif(struct iwl_priv *priv, |
@@ -175,7 +171,120 @@ static inline const char *iwl_get_tx_fail_reason(u32 status) { return ""; } | |||
175 | static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; } | 171 | static inline const char *iwl_get_agg_tx_fail_reason(u16 status) { return ""; } |
176 | #endif | 172 | #endif |
177 | 173 | ||
174 | |||
178 | /* station management */ | 175 | /* station management */ |
176 | int iwlagn_manage_ibss_station(struct iwl_priv *priv, | ||
177 | struct ieee80211_vif *vif, bool add); | ||
178 | #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */ | ||
179 | #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */ | ||
180 | #define IWL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of | ||
181 | being activated */ | ||
182 | #define IWL_STA_LOCAL BIT(3) /* station state not directed by mac80211; | ||
183 | (this is for the IBSS BSSID stations) */ | ||
184 | #define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */ | ||
185 | |||
186 | |||
187 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
188 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
189 | struct iwl_rxon_context *ctx); | ||
190 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv); | ||
191 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv); | ||
192 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
193 | struct iwl_addsta_cmd *sta, u8 flags); | ||
194 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
195 | const u8 *addr, bool is_ap, | ||
196 | struct ieee80211_sta *sta, u8 *sta_id_r); | ||
197 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
198 | const u8 *addr); | ||
199 | int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | ||
200 | struct ieee80211_sta *sta); | ||
201 | |||
202 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
203 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta); | ||
204 | |||
205 | void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
206 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd); | ||
207 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
208 | struct iwl_link_quality_cmd *lq, u8 flags, bool init); | ||
209 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
210 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, | ||
211 | struct iwl_device_cmd *cmd); | ||
212 | |||
213 | |||
214 | /** | ||
215 | * iwl_clear_driver_stations - clear knowledge of all stations from driver | ||
216 | * @priv: iwl priv struct | ||
217 | * | ||
218 | * This is called during iwl_down() to make sure that in the case | ||
219 | * we're coming there from a hardware restart mac80211 will be | ||
220 | * able to reconfigure stations -- if we're getting there in the | ||
221 | * normal down flow then the stations will already be cleared. | ||
222 | */ | ||
223 | static inline void iwl_clear_driver_stations(struct iwl_priv *priv) | ||
224 | { | ||
225 | unsigned long flags; | ||
226 | struct iwl_rxon_context *ctx; | ||
227 | |||
228 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
229 | memset(priv->stations, 0, sizeof(priv->stations)); | ||
230 | priv->num_stations = 0; | ||
231 | |||
232 | priv->ucode_key_table = 0; | ||
233 | |||
234 | for_each_context(priv, ctx) { | ||
235 | /* | ||
236 | * Remove all key information that is not stored as part | ||
237 | * of station information since mac80211 may not have had | ||
238 | * a chance to remove all the keys. When device is | ||
239 | * reconfigured by mac80211 after an error all keys will | ||
240 | * be reconfigured. | ||
241 | */ | ||
242 | memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys)); | ||
243 | ctx->key_mapping_keys = 0; | ||
244 | } | ||
245 | |||
246 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
247 | } | ||
248 | |||
249 | static inline int iwl_sta_id(struct ieee80211_sta *sta) | ||
250 | { | ||
251 | if (WARN_ON(!sta)) | ||
252 | return IWL_INVALID_STATION; | ||
253 | |||
254 | return ((struct iwl_station_priv *)sta->drv_priv)->sta_id; | ||
255 | } | ||
256 | |||
257 | /** | ||
258 | * iwl_sta_id_or_broadcast - return sta_id or broadcast sta | ||
259 | * @priv: iwl priv | ||
260 | * @context: the current context | ||
261 | * @sta: mac80211 station | ||
262 | * | ||
263 | * In certain circumstances mac80211 passes a station pointer | ||
264 | * that may be %NULL, for example during TX or key setup. In | ||
265 | * that case, we need to use the broadcast station, so this | ||
266 | * inline wraps that pattern. | ||
267 | */ | ||
268 | static inline int iwl_sta_id_or_broadcast(struct iwl_priv *priv, | ||
269 | struct iwl_rxon_context *context, | ||
270 | struct ieee80211_sta *sta) | ||
271 | { | ||
272 | int sta_id; | ||
273 | |||
274 | if (!sta) | ||
275 | return context->bcast_sta_id; | ||
276 | |||
277 | sta_id = iwl_sta_id(sta); | ||
278 | |||
279 | /* | ||
280 | * mac80211 should not be passing a partially | ||
281 | * initialised station! | ||
282 | */ | ||
283 | WARN_ON(sta_id == IWL_INVALID_STATION); | ||
284 | |||
285 | return sta_id; | ||
286 | } | ||
287 | |||
179 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, | 288 | int iwlagn_alloc_bcast_station(struct iwl_priv *priv, |
180 | struct iwl_rxon_context *ctx); | 289 | struct iwl_rxon_context *ctx); |
181 | int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | 290 | int iwlagn_add_bssid_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, |
diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c index f8007560143..ad66150a46c 100644 --- a/drivers/net/wireless/iwlwifi/iwl-core.c +++ b/drivers/net/wireless/iwlwifi/iwl-core.c | |||
@@ -39,7 +39,6 @@ | |||
39 | #include "iwl-core.h" | 39 | #include "iwl-core.h" |
40 | #include "iwl-io.h" | 40 | #include "iwl-io.h" |
41 | #include "iwl-power.h" | 41 | #include "iwl-power.h" |
42 | #include "iwl-sta.h" | ||
43 | #include "iwl-agn.h" | 42 | #include "iwl-agn.h" |
44 | #include "iwl-helpers.h" | 43 | #include "iwl-helpers.h" |
45 | #include "iwl-shared.h" | 44 | #include "iwl-shared.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-rx.c b/drivers/net/wireless/iwlwifi/iwl-rx.c index 2581c3cbfb5..d406c7288cc 100644 --- a/drivers/net/wireless/iwlwifi/iwl-rx.c +++ b/drivers/net/wireless/iwlwifi/iwl-rx.c | |||
@@ -35,7 +35,6 @@ | |||
35 | #include "iwl-eeprom.h" | 35 | #include "iwl-eeprom.h" |
36 | #include "iwl-dev.h" | 36 | #include "iwl-dev.h" |
37 | #include "iwl-core.h" | 37 | #include "iwl-core.h" |
38 | #include "iwl-sta.h" | ||
39 | #include "iwl-io.h" | 38 | #include "iwl-io.h" |
40 | #include "iwl-helpers.h" | 39 | #include "iwl-helpers.h" |
41 | #include "iwl-agn-calib.h" | 40 | #include "iwl-agn-calib.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c index 55f1f86796a..bb03bf8398e 100644 --- a/drivers/net/wireless/iwlwifi/iwl-scan.c +++ b/drivers/net/wireless/iwlwifi/iwl-scan.c | |||
@@ -33,7 +33,6 @@ | |||
33 | #include "iwl-eeprom.h" | 33 | #include "iwl-eeprom.h" |
34 | #include "iwl-dev.h" | 34 | #include "iwl-dev.h" |
35 | #include "iwl-core.h" | 35 | #include "iwl-core.h" |
36 | #include "iwl-sta.h" | ||
37 | #include "iwl-io.h" | 36 | #include "iwl-io.h" |
38 | #include "iwl-helpers.h" | 37 | #include "iwl-helpers.h" |
39 | #include "iwl-agn.h" | 38 | #include "iwl-agn.h" |
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.c b/drivers/net/wireless/iwlwifi/iwl-sta.c deleted file mode 100644 index 586007ee3a8..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-sta.c +++ /dev/null | |||
@@ -1,839 +0,0 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. | ||
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: | ||
25 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
27 | * | ||
28 | *****************************************************************************/ | ||
29 | |||
30 | #include <net/mac80211.h> | ||
31 | #include <linux/etherdevice.h> | ||
32 | #include <linux/sched.h> | ||
33 | #include <linux/lockdep.h> | ||
34 | |||
35 | #include "iwl-dev.h" | ||
36 | #include "iwl-core.h" | ||
37 | #include "iwl-sta.h" | ||
38 | #include "iwl-trans.h" | ||
39 | #include "iwl-agn.h" | ||
40 | |||
41 | /* priv->shrd->sta_lock must be held */ | ||
42 | static void iwl_sta_ucode_activate(struct iwl_priv *priv, u8 sta_id) | ||
43 | { | ||
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 | |||
60 | static int iwl_process_add_sta_resp(struct iwl_priv *priv, | ||
61 | struct iwl_addsta_cmd *addsta, | ||
62 | struct iwl_rx_packet *pkt) | ||
63 | { | ||
64 | u8 sta_id = addsta->sta.sta_id; | ||
65 | unsigned long flags; | ||
66 | int ret = -EIO; | ||
67 | |||
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); | ||
71 | return ret; | ||
72 | } | ||
73 | |||
74 | IWL_DEBUG_INFO(priv, "Processing response for adding station %u\n", | ||
75 | sta_id); | ||
76 | |||
77 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
78 | |||
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); | ||
83 | ret = 0; | ||
84 | break; | ||
85 | case ADD_STA_NO_ROOM_IN_TABLE: | ||
86 | IWL_ERR(priv, "Adding station %d failed, no room in table.\n", | ||
87 | sta_id); | ||
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: | ||
94 | IWL_ERR(priv, "Attempting to modify non-existing station %d\n", | ||
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 | } | ||
102 | |||
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 | ||
111 | * written to the command buffer often is not the same MAC address | ||
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); | ||
120 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
121 | |||
122 | return ret; | ||
123 | } | ||
124 | |||
125 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, | ||
126 | struct iwl_device_cmd *cmd) | ||
127 | { | ||
128 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | ||
129 | struct iwl_addsta_cmd *addsta = | ||
130 | (struct iwl_addsta_cmd *) cmd->payload; | ||
131 | |||
132 | return iwl_process_add_sta_resp(priv, addsta, pkt); | ||
133 | } | ||
134 | |||
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 | |||
145 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
146 | struct iwl_addsta_cmd *sta, u8 flags) | ||
147 | { | ||
148 | int ret = 0; | ||
149 | u8 data[sizeof(*sta)]; | ||
150 | struct iwl_host_cmd cmd = { | ||
151 | .id = REPLY_ADD_STA, | ||
152 | .flags = flags, | ||
153 | .data = { data, }, | ||
154 | }; | ||
155 | u8 sta_id __maybe_unused = sta->sta.sta_id; | ||
156 | |||
157 | IWL_DEBUG_INFO(priv, "Adding sta %u (%pM) %ssynchronously\n", | ||
158 | sta_id, sta->sta.addr, flags & CMD_ASYNC ? "a" : ""); | ||
159 | |||
160 | if (!(flags & CMD_ASYNC)) { | ||
161 | cmd.flags |= CMD_WANT_SKB; | ||
162 | might_sleep(); | ||
163 | } | ||
164 | |||
165 | cmd.len[0] = iwlagn_build_addsta_hcmd(sta, data); | ||
166 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
167 | |||
168 | if (ret || (flags & CMD_ASYNC)) | ||
169 | return ret; | ||
170 | /*else the command was successfully sent in SYNC mode, need to free | ||
171 | * the reply page */ | ||
172 | |||
173 | iwl_free_pages(priv->shrd, cmd.reply_page); | ||
174 | |||
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; | ||
180 | } | ||
181 | |||
182 | static void iwl_set_ht_add_station(struct iwl_priv *priv, u8 index, | ||
183 | struct ieee80211_sta *sta, | ||
184 | struct iwl_rxon_context *ctx) | ||
185 | { | ||
186 | struct ieee80211_sta_ht_cap *sta_ht_inf = &sta->ht_cap; | ||
187 | __le32 sta_flags; | ||
188 | u8 mimo_ps_mode; | ||
189 | |||
190 | if (!sta || !sta_ht_inf->ht_supported) | ||
191 | goto done; | ||
192 | |||
193 | mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_SM_PS) >> 2; | ||
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"); | ||
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) { | ||
205 | case WLAN_HT_CAP_SM_PS_STATIC: | ||
206 | sta_flags |= STA_FLG_MIMO_DIS_MSK; | ||
207 | break; | ||
208 | case WLAN_HT_CAP_SM_PS_DYNAMIC: | ||
209 | sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK; | ||
210 | break; | ||
211 | case WLAN_HT_CAP_SM_PS_DISABLED: | ||
212 | break; | ||
213 | default: | ||
214 | IWL_WARN(priv, "Invalid MIMO PS mode %d\n", mimo_ps_mode); | ||
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 | |||
224 | if (iwl_is_ht40_tx_allowed(priv, ctx, &sta->ht_cap)) | ||
225 | sta_flags |= STA_FLG_HT40_EN_MSK; | ||
226 | else | ||
227 | sta_flags &= ~STA_FLG_HT40_EN_MSK; | ||
228 | |||
229 | priv->stations[index].sta.station_flags = sta_flags; | ||
230 | done: | ||
231 | return; | ||
232 | } | ||
233 | |||
234 | /** | ||
235 | * iwl_prep_station - Prepare station information for addition | ||
236 | * | ||
237 | * should be called with sta_lock held | ||
238 | */ | ||
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) | ||
241 | { | ||
242 | struct iwl_station_entry *station; | ||
243 | int i; | ||
244 | u8 sta_id = IWL_INVALID_STATION; | ||
245 | |||
246 | if (is_ap) | ||
247 | sta_id = ctx->ap_sta_id; | ||
248 | else if (is_broadcast_ether_addr(addr)) | ||
249 | sta_id = ctx->bcast_sta_id; | ||
250 | else | ||
251 | for (i = IWL_STA_ID; i < IWLAGN_STATION_COUNT; i++) { | ||
252 | if (!compare_ether_addr(priv->stations[i].sta.sta.addr, | ||
253 | addr)) { | ||
254 | sta_id = i; | ||
255 | break; | ||
256 | } | ||
257 | |||
258 | if (!priv->stations[i].used && | ||
259 | sta_id == IWL_INVALID_STATION) | ||
260 | sta_id = i; | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * These two conditions have the same outcome, but keep them | ||
265 | * separate | ||
266 | */ | ||
267 | if (unlikely(sta_id == IWL_INVALID_STATION)) | ||
268 | return sta_id; | ||
269 | |||
270 | /* | ||
271 | * uCode is not able to deal with multiple requests to add a | ||
272 | * station. Keep track if one is in progress so that we do not send | ||
273 | * another. | ||
274 | */ | ||
275 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
276 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", | ||
277 | sta_id); | ||
278 | return sta_id; | ||
279 | } | ||
280 | |||
281 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
282 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE) && | ||
283 | !compare_ether_addr(priv->stations[sta_id].sta.sta.addr, addr)) { | ||
284 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", | ||
285 | sta_id, addr); | ||
286 | return sta_id; | ||
287 | } | ||
288 | |||
289 | station = &priv->stations[sta_id]; | ||
290 | station->used = IWL_STA_DRIVER_ACTIVE; | ||
291 | IWL_DEBUG_ASSOC(priv, "Add STA to driver ID %d: %pM\n", | ||
292 | sta_id, addr); | ||
293 | priv->num_stations++; | ||
294 | |||
295 | /* Set up the REPLY_ADD_STA command to send to device */ | ||
296 | memset(&station->sta, 0, sizeof(struct iwl_addsta_cmd)); | ||
297 | memcpy(station->sta.sta.addr, addr, ETH_ALEN); | ||
298 | station->sta.mode = 0; | ||
299 | station->sta.sta.sta_id = sta_id; | ||
300 | station->sta.station_flags = ctx->station_flags; | ||
301 | station->ctxid = ctx->ctxid; | ||
302 | |||
303 | if (sta) { | ||
304 | struct iwl_station_priv *sta_priv; | ||
305 | |||
306 | sta_priv = (void *)sta->drv_priv; | ||
307 | sta_priv->ctx = ctx; | ||
308 | } | ||
309 | |||
310 | /* | ||
311 | * OK to call unconditionally, since local stations (IBSS BSSID | ||
312 | * STA and broadcast STA) pass in a NULL sta, and mac80211 | ||
313 | * doesn't allow HT IBSS. | ||
314 | */ | ||
315 | iwl_set_ht_add_station(priv, sta_id, sta, ctx); | ||
316 | |||
317 | return sta_id; | ||
318 | |||
319 | } | ||
320 | |||
321 | #define STA_WAIT_TIMEOUT (HZ/2) | ||
322 | |||
323 | /** | ||
324 | * iwl_add_station_common - | ||
325 | */ | ||
326 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
327 | const u8 *addr, bool is_ap, | ||
328 | struct ieee80211_sta *sta, u8 *sta_id_r) | ||
329 | { | ||
330 | unsigned long flags_spin; | ||
331 | int ret = 0; | ||
332 | u8 sta_id; | ||
333 | struct iwl_addsta_cmd sta_cmd; | ||
334 | |||
335 | *sta_id_r = 0; | ||
336 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
337 | sta_id = iwl_prep_station(priv, ctx, addr, is_ap, sta); | ||
338 | if (sta_id == IWL_INVALID_STATION) { | ||
339 | IWL_ERR(priv, "Unable to prepare station %pM for addition\n", | ||
340 | addr); | ||
341 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
342 | return -EINVAL; | ||
343 | } | ||
344 | |||
345 | /* | ||
346 | * uCode is not able to deal with multiple requests to add a | ||
347 | * station. Keep track if one is in progress so that we do not send | ||
348 | * another. | ||
349 | */ | ||
350 | if (priv->stations[sta_id].used & IWL_STA_UCODE_INPROGRESS) { | ||
351 | IWL_DEBUG_INFO(priv, "STA %d already in process of being added.\n", | ||
352 | sta_id); | ||
353 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
354 | return -EEXIST; | ||
355 | } | ||
356 | |||
357 | if ((priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE) && | ||
358 | (priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
359 | IWL_DEBUG_ASSOC(priv, "STA %d (%pM) already added, not adding again.\n", | ||
360 | sta_id, addr); | ||
361 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
362 | return -EEXIST; | ||
363 | } | ||
364 | |||
365 | priv->stations[sta_id].used |= IWL_STA_UCODE_INPROGRESS; | ||
366 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(struct iwl_addsta_cmd)); | ||
367 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
368 | |||
369 | /* Add station to device's station table */ | ||
370 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
371 | if (ret) { | ||
372 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
373 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
374 | priv->stations[sta_id].sta.sta.addr); | ||
375 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
376 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
377 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
378 | } | ||
379 | *sta_id_r = sta_id; | ||
380 | return ret; | ||
381 | } | ||
382 | |||
383 | /** | ||
384 | * iwl_sta_ucode_deactivate - deactivate ucode status for a station | ||
385 | * | ||
386 | * priv->shrd->sta_lock must be held | ||
387 | */ | ||
388 | static void iwl_sta_ucode_deactivate(struct iwl_priv *priv, u8 sta_id) | ||
389 | { | ||
390 | /* Ucode must be active and driver must be non active */ | ||
391 | if ((priv->stations[sta_id].used & | ||
392 | (IWL_STA_UCODE_ACTIVE | IWL_STA_DRIVER_ACTIVE)) != IWL_STA_UCODE_ACTIVE) | ||
393 | IWL_ERR(priv, "removed non active STA %u\n", sta_id); | ||
394 | |||
395 | priv->stations[sta_id].used &= ~IWL_STA_UCODE_ACTIVE; | ||
396 | |||
397 | memset(&priv->stations[sta_id], 0, sizeof(struct iwl_station_entry)); | ||
398 | IWL_DEBUG_ASSOC(priv, "Removed STA %u\n", sta_id); | ||
399 | } | ||
400 | |||
401 | static int iwl_send_remove_station(struct iwl_priv *priv, | ||
402 | const u8 *addr, int sta_id, | ||
403 | bool temporary) | ||
404 | { | ||
405 | struct iwl_rx_packet *pkt; | ||
406 | int ret; | ||
407 | |||
408 | unsigned long flags_spin; | ||
409 | struct iwl_rem_sta_cmd rm_sta_cmd; | ||
410 | |||
411 | struct iwl_host_cmd cmd = { | ||
412 | .id = REPLY_REMOVE_STA, | ||
413 | .len = { sizeof(struct iwl_rem_sta_cmd), }, | ||
414 | .flags = CMD_SYNC, | ||
415 | .data = { &rm_sta_cmd, }, | ||
416 | }; | ||
417 | |||
418 | memset(&rm_sta_cmd, 0, sizeof(rm_sta_cmd)); | ||
419 | rm_sta_cmd.num_sta = 1; | ||
420 | memcpy(&rm_sta_cmd.addr, addr, ETH_ALEN); | ||
421 | |||
422 | cmd.flags |= CMD_WANT_SKB; | ||
423 | |||
424 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
425 | |||
426 | if (ret) | ||
427 | return ret; | ||
428 | |||
429 | pkt = (struct iwl_rx_packet *)cmd.reply_page; | ||
430 | if (pkt->hdr.flags & IWL_CMD_FAILED_MSK) { | ||
431 | IWL_ERR(priv, "Bad return from REPLY_REMOVE_STA (0x%08X)\n", | ||
432 | pkt->hdr.flags); | ||
433 | ret = -EIO; | ||
434 | } | ||
435 | |||
436 | if (!ret) { | ||
437 | switch (pkt->u.rem_sta.status) { | ||
438 | case REM_STA_SUCCESS_MSK: | ||
439 | if (!temporary) { | ||
440 | spin_lock_irqsave(&priv->shrd->sta_lock, | ||
441 | flags_spin); | ||
442 | iwl_sta_ucode_deactivate(priv, sta_id); | ||
443 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
444 | flags_spin); | ||
445 | } | ||
446 | IWL_DEBUG_ASSOC(priv, "REPLY_REMOVE_STA PASSED\n"); | ||
447 | break; | ||
448 | default: | ||
449 | ret = -EIO; | ||
450 | IWL_ERR(priv, "REPLY_REMOVE_STA failed\n"); | ||
451 | break; | ||
452 | } | ||
453 | } | ||
454 | iwl_free_pages(priv->shrd, cmd.reply_page); | ||
455 | |||
456 | return ret; | ||
457 | } | ||
458 | |||
459 | /** | ||
460 | * iwl_remove_station - Remove driver's knowledge of station. | ||
461 | */ | ||
462 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
463 | const u8 *addr) | ||
464 | { | ||
465 | unsigned long flags; | ||
466 | |||
467 | if (!iwl_is_ready(priv->shrd)) { | ||
468 | IWL_DEBUG_INFO(priv, | ||
469 | "Unable to remove station %pM, device not ready.\n", | ||
470 | addr); | ||
471 | /* | ||
472 | * It is typical for stations to be removed when we are | ||
473 | * going down. Return success since device will be down | ||
474 | * soon anyway | ||
475 | */ | ||
476 | return 0; | ||
477 | } | ||
478 | |||
479 | IWL_DEBUG_ASSOC(priv, "Removing STA from driver:%d %pM\n", | ||
480 | sta_id, addr); | ||
481 | |||
482 | if (WARN_ON(sta_id == IWL_INVALID_STATION)) | ||
483 | return -EINVAL; | ||
484 | |||
485 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
486 | |||
487 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
488 | IWL_DEBUG_INFO(priv, "Removing %pM but non DRIVER active\n", | ||
489 | addr); | ||
490 | goto out_err; | ||
491 | } | ||
492 | |||
493 | if (!(priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE)) { | ||
494 | IWL_DEBUG_INFO(priv, "Removing %pM but non UCODE active\n", | ||
495 | addr); | ||
496 | goto out_err; | ||
497 | } | ||
498 | |||
499 | if (priv->stations[sta_id].used & IWL_STA_LOCAL) { | ||
500 | kfree(priv->stations[sta_id].lq); | ||
501 | priv->stations[sta_id].lq = NULL; | ||
502 | } | ||
503 | |||
504 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
505 | |||
506 | priv->num_stations--; | ||
507 | |||
508 | if (WARN_ON(priv->num_stations < 0)) | ||
509 | priv->num_stations = 0; | ||
510 | |||
511 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
512 | |||
513 | return iwl_send_remove_station(priv, addr, sta_id, false); | ||
514 | out_err: | ||
515 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
516 | return -EINVAL; | ||
517 | } | ||
518 | |||
519 | /** | ||
520 | * iwl_clear_ucode_stations - clear ucode station table bits | ||
521 | * | ||
522 | * This function clears all the bits in the driver indicating | ||
523 | * which stations are active in the ucode. Call when something | ||
524 | * other than explicit station management would cause this in | ||
525 | * the ucode, e.g. unassociated RXON. | ||
526 | */ | ||
527 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
528 | struct iwl_rxon_context *ctx) | ||
529 | { | ||
530 | int i; | ||
531 | unsigned long flags_spin; | ||
532 | bool cleared = false; | ||
533 | |||
534 | IWL_DEBUG_INFO(priv, "Clearing ucode stations in driver\n"); | ||
535 | |||
536 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
537 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
538 | if (ctx && ctx->ctxid != priv->stations[i].ctxid) | ||
539 | continue; | ||
540 | |||
541 | if (priv->stations[i].used & IWL_STA_UCODE_ACTIVE) { | ||
542 | IWL_DEBUG_INFO(priv, "Clearing ucode active for station %d\n", i); | ||
543 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
544 | cleared = true; | ||
545 | } | ||
546 | } | ||
547 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
548 | |||
549 | if (!cleared) | ||
550 | IWL_DEBUG_INFO(priv, "No active stations found to be cleared\n"); | ||
551 | } | ||
552 | |||
553 | /** | ||
554 | * iwl_restore_stations() - Restore driver known stations to device | ||
555 | * | ||
556 | * All stations considered active by driver, but not present in ucode, is | ||
557 | * restored. | ||
558 | * | ||
559 | * Function sleeps. | ||
560 | */ | ||
561 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
562 | { | ||
563 | struct iwl_addsta_cmd sta_cmd; | ||
564 | struct iwl_link_quality_cmd lq; | ||
565 | unsigned long flags_spin; | ||
566 | int i; | ||
567 | bool found = false; | ||
568 | int ret; | ||
569 | bool send_lq; | ||
570 | |||
571 | if (!iwl_is_ready(priv->shrd)) { | ||
572 | IWL_DEBUG_INFO(priv, "Not ready yet, not restoring any stations.\n"); | ||
573 | return; | ||
574 | } | ||
575 | |||
576 | IWL_DEBUG_ASSOC(priv, "Restoring all known stations ... start.\n"); | ||
577 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
578 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
579 | if (ctx->ctxid != priv->stations[i].ctxid) | ||
580 | continue; | ||
581 | if ((priv->stations[i].used & IWL_STA_DRIVER_ACTIVE) && | ||
582 | !(priv->stations[i].used & IWL_STA_UCODE_ACTIVE)) { | ||
583 | IWL_DEBUG_ASSOC(priv, "Restoring sta %pM\n", | ||
584 | priv->stations[i].sta.sta.addr); | ||
585 | priv->stations[i].sta.mode = 0; | ||
586 | priv->stations[i].used |= IWL_STA_UCODE_INPROGRESS; | ||
587 | found = true; | ||
588 | } | ||
589 | } | ||
590 | |||
591 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
592 | if ((priv->stations[i].used & IWL_STA_UCODE_INPROGRESS)) { | ||
593 | memcpy(&sta_cmd, &priv->stations[i].sta, | ||
594 | sizeof(struct iwl_addsta_cmd)); | ||
595 | send_lq = false; | ||
596 | if (priv->stations[i].lq) { | ||
597 | if (priv->shrd->wowlan) | ||
598 | iwl_sta_fill_lq(priv, ctx, i, &lq); | ||
599 | else | ||
600 | memcpy(&lq, priv->stations[i].lq, | ||
601 | sizeof(struct iwl_link_quality_cmd)); | ||
602 | send_lq = true; | ||
603 | } | ||
604 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
605 | flags_spin); | ||
606 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
607 | if (ret) { | ||
608 | spin_lock_irqsave(&priv->shrd->sta_lock, | ||
609 | flags_spin); | ||
610 | IWL_ERR(priv, "Adding station %pM failed.\n", | ||
611 | priv->stations[i].sta.sta.addr); | ||
612 | priv->stations[i].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
613 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
614 | spin_unlock_irqrestore(&priv->shrd->sta_lock, | ||
615 | flags_spin); | ||
616 | } | ||
617 | /* | ||
618 | * Rate scaling has already been initialized, send | ||
619 | * current LQ command | ||
620 | */ | ||
621 | if (send_lq) | ||
622 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); | ||
623 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
624 | priv->stations[i].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
625 | } | ||
626 | } | ||
627 | |||
628 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
629 | if (!found) | ||
630 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... no stations to be restored.\n"); | ||
631 | else | ||
632 | IWL_DEBUG_INFO(priv, "Restoring all known stations .... complete.\n"); | ||
633 | } | ||
634 | |||
635 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx) | ||
636 | { | ||
637 | unsigned long flags; | ||
638 | int sta_id = ctx->ap_sta_id; | ||
639 | int ret; | ||
640 | struct iwl_addsta_cmd sta_cmd; | ||
641 | struct iwl_link_quality_cmd lq; | ||
642 | bool active; | ||
643 | |||
644 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
645 | if (!(priv->stations[sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
646 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
647 | return; | ||
648 | } | ||
649 | |||
650 | memcpy(&sta_cmd, &priv->stations[sta_id].sta, sizeof(sta_cmd)); | ||
651 | sta_cmd.mode = 0; | ||
652 | memcpy(&lq, priv->stations[sta_id].lq, sizeof(lq)); | ||
653 | |||
654 | active = priv->stations[sta_id].used & IWL_STA_UCODE_ACTIVE; | ||
655 | priv->stations[sta_id].used &= ~IWL_STA_DRIVER_ACTIVE; | ||
656 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
657 | |||
658 | if (active) { | ||
659 | ret = iwl_send_remove_station( | ||
660 | priv, priv->stations[sta_id].sta.sta.addr, | ||
661 | sta_id, true); | ||
662 | if (ret) | ||
663 | IWL_ERR(priv, "failed to remove STA %pM (%d)\n", | ||
664 | priv->stations[sta_id].sta.sta.addr, ret); | ||
665 | } | ||
666 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
667 | priv->stations[sta_id].used |= IWL_STA_DRIVER_ACTIVE; | ||
668 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
669 | |||
670 | ret = iwl_send_add_sta(priv, &sta_cmd, CMD_SYNC); | ||
671 | if (ret) | ||
672 | IWL_ERR(priv, "failed to re-add STA %pM (%d)\n", | ||
673 | priv->stations[sta_id].sta.sta.addr, ret); | ||
674 | iwl_send_lq_cmd(priv, ctx, &lq, CMD_SYNC, true); | ||
675 | } | ||
676 | |||
677 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv) | ||
678 | { | ||
679 | int i; | ||
680 | |||
681 | for (i = 0; i < priv->sta_key_max_num; i++) | ||
682 | if (!test_and_set_bit(i, &priv->ucode_key_table)) | ||
683 | return i; | ||
684 | |||
685 | return WEP_INVALID_OFFSET; | ||
686 | } | ||
687 | |||
688 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv) | ||
689 | { | ||
690 | unsigned long flags; | ||
691 | int i; | ||
692 | |||
693 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
694 | for (i = 0; i < IWLAGN_STATION_COUNT; i++) { | ||
695 | if (!(priv->stations[i].used & IWL_STA_BCAST)) | ||
696 | continue; | ||
697 | |||
698 | priv->stations[i].used &= ~IWL_STA_UCODE_ACTIVE; | ||
699 | priv->num_stations--; | ||
700 | if (WARN_ON(priv->num_stations < 0)) | ||
701 | priv->num_stations = 0; | ||
702 | kfree(priv->stations[i].lq); | ||
703 | priv->stations[i].lq = NULL; | ||
704 | } | ||
705 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
706 | } | ||
707 | |||
708 | #ifdef CONFIG_IWLWIFI_DEBUG | ||
709 | static void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
710 | struct iwl_link_quality_cmd *lq) | ||
711 | { | ||
712 | int i; | ||
713 | IWL_DEBUG_RATE(priv, "lq station id 0x%x\n", lq->sta_id); | ||
714 | IWL_DEBUG_RATE(priv, "lq ant 0x%X 0x%X\n", | ||
715 | lq->general_params.single_stream_ant_msk, | ||
716 | lq->general_params.dual_stream_ant_msk); | ||
717 | |||
718 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) | ||
719 | IWL_DEBUG_RATE(priv, "lq index %d 0x%X\n", | ||
720 | i, lq->rs_table[i].rate_n_flags); | ||
721 | } | ||
722 | #else | ||
723 | static inline void iwl_dump_lq_cmd(struct iwl_priv *priv, | ||
724 | struct iwl_link_quality_cmd *lq) | ||
725 | { | ||
726 | } | ||
727 | #endif | ||
728 | |||
729 | /** | ||
730 | * is_lq_table_valid() - Test one aspect of LQ cmd for validity | ||
731 | * | ||
732 | * It sometimes happens when a HT rate has been in use and we | ||
733 | * loose connectivity with AP then mac80211 will first tell us that the | ||
734 | * current channel is not HT anymore before removing the station. In such a | ||
735 | * scenario the RXON flags will be updated to indicate we are not | ||
736 | * communicating HT anymore, but the LQ command may still contain HT rates. | ||
737 | * Test for this to prevent driver from sending LQ command between the time | ||
738 | * RXON flags are updated and when LQ command is updated. | ||
739 | */ | ||
740 | static bool is_lq_table_valid(struct iwl_priv *priv, | ||
741 | struct iwl_rxon_context *ctx, | ||
742 | struct iwl_link_quality_cmd *lq) | ||
743 | { | ||
744 | int i; | ||
745 | |||
746 | if (ctx->ht.enabled) | ||
747 | return true; | ||
748 | |||
749 | IWL_DEBUG_INFO(priv, "Channel %u is not an HT channel\n", | ||
750 | ctx->active.channel); | ||
751 | for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) { | ||
752 | if (le32_to_cpu(lq->rs_table[i].rate_n_flags) & RATE_MCS_HT_MSK) { | ||
753 | IWL_DEBUG_INFO(priv, | ||
754 | "index %d of LQ expects HT channel\n", | ||
755 | i); | ||
756 | return false; | ||
757 | } | ||
758 | } | ||
759 | return true; | ||
760 | } | ||
761 | |||
762 | /** | ||
763 | * iwl_send_lq_cmd() - Send link quality command | ||
764 | * @init: This command is sent as part of station initialization right | ||
765 | * after station has been added. | ||
766 | * | ||
767 | * The link quality command is sent as the last step of station creation. | ||
768 | * This is the special case in which init is set and we call a callback in | ||
769 | * this case to clear the state indicating that station creation is in | ||
770 | * progress. | ||
771 | */ | ||
772 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
773 | struct iwl_link_quality_cmd *lq, u8 flags, bool init) | ||
774 | { | ||
775 | int ret = 0; | ||
776 | unsigned long flags_spin; | ||
777 | |||
778 | struct iwl_host_cmd cmd = { | ||
779 | .id = REPLY_TX_LINK_QUALITY_CMD, | ||
780 | .len = { sizeof(struct iwl_link_quality_cmd), }, | ||
781 | .flags = flags, | ||
782 | .data = { lq, }, | ||
783 | }; | ||
784 | |||
785 | if (WARN_ON(lq->sta_id == IWL_INVALID_STATION)) | ||
786 | return -EINVAL; | ||
787 | |||
788 | |||
789 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
790 | if (!(priv->stations[lq->sta_id].used & IWL_STA_DRIVER_ACTIVE)) { | ||
791 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
792 | return -EINVAL; | ||
793 | } | ||
794 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
795 | |||
796 | iwl_dump_lq_cmd(priv, lq); | ||
797 | if (WARN_ON(init && (cmd.flags & CMD_ASYNC))) | ||
798 | return -EINVAL; | ||
799 | |||
800 | if (is_lq_table_valid(priv, ctx, lq)) | ||
801 | ret = iwl_trans_send_cmd(trans(priv), &cmd); | ||
802 | else | ||
803 | ret = -EINVAL; | ||
804 | |||
805 | if (cmd.flags & CMD_ASYNC) | ||
806 | return ret; | ||
807 | |||
808 | if (init) { | ||
809 | IWL_DEBUG_INFO(priv, "init LQ command complete, clearing sta addition status for sta %d\n", | ||
810 | lq->sta_id); | ||
811 | spin_lock_irqsave(&priv->shrd->sta_lock, flags_spin); | ||
812 | priv->stations[lq->sta_id].used &= ~IWL_STA_UCODE_INPROGRESS; | ||
813 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags_spin); | ||
814 | } | ||
815 | return ret; | ||
816 | } | ||
817 | |||
818 | int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, | ||
819 | struct ieee80211_vif *vif, | ||
820 | struct ieee80211_sta *sta) | ||
821 | { | ||
822 | struct iwl_priv *priv = hw->priv; | ||
823 | struct iwl_station_priv *sta_priv = (void *)sta->drv_priv; | ||
824 | int ret; | ||
825 | |||
826 | IWL_DEBUG_MAC80211(priv, "enter: received request to remove " | ||
827 | "station %pM\n", sta->addr); | ||
828 | mutex_lock(&priv->shrd->mutex); | ||
829 | IWL_DEBUG_INFO(priv, "proceeding to remove station %pM\n", | ||
830 | sta->addr); | ||
831 | ret = iwl_remove_station(priv, sta_priv->sta_id, sta->addr); | ||
832 | if (ret) | ||
833 | IWL_ERR(priv, "Error removing station %pM\n", | ||
834 | sta->addr); | ||
835 | mutex_unlock(&priv->shrd->mutex); | ||
836 | IWL_DEBUG_MAC80211(priv, "leave\n"); | ||
837 | |||
838 | return ret; | ||
839 | } | ||
diff --git a/drivers/net/wireless/iwlwifi/iwl-sta.h b/drivers/net/wireless/iwlwifi/iwl-sta.h deleted file mode 100644 index 73b4af268c3..00000000000 --- a/drivers/net/wireless/iwlwifi/iwl-sta.h +++ /dev/null | |||
@@ -1,143 +0,0 @@ | |||
1 | /****************************************************************************** | ||
2 | * | ||
3 | * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved. | ||
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: | ||
25 | * Intel Linux Wireless <ilw@linux.intel.com> | ||
26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | ||
27 | * | ||
28 | *****************************************************************************/ | ||
29 | #ifndef __iwl_sta_h__ | ||
30 | #define __iwl_sta_h__ | ||
31 | |||
32 | #include "iwl-dev.h" | ||
33 | |||
34 | #define IWL_STA_DRIVER_ACTIVE BIT(0) /* driver entry is active */ | ||
35 | #define IWL_STA_UCODE_ACTIVE BIT(1) /* ucode entry is active */ | ||
36 | #define IWL_STA_UCODE_INPROGRESS BIT(2) /* ucode entry is in process of | ||
37 | being activated */ | ||
38 | #define IWL_STA_LOCAL BIT(3) /* station state not directed by mac80211; | ||
39 | (this is for the IBSS BSSID stations) */ | ||
40 | #define IWL_STA_BCAST BIT(4) /* this station is the special bcast station */ | ||
41 | |||
42 | |||
43 | void iwl_restore_stations(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
44 | void iwl_clear_ucode_stations(struct iwl_priv *priv, | ||
45 | struct iwl_rxon_context *ctx); | ||
46 | void iwl_dealloc_bcast_stations(struct iwl_priv *priv); | ||
47 | int iwl_get_free_ucode_key_offset(struct iwl_priv *priv); | ||
48 | int iwl_send_add_sta(struct iwl_priv *priv, | ||
49 | struct iwl_addsta_cmd *sta, u8 flags); | ||
50 | int iwl_add_station_common(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
51 | const u8 *addr, bool is_ap, | ||
52 | struct ieee80211_sta *sta, u8 *sta_id_r); | ||
53 | int iwl_remove_station(struct iwl_priv *priv, const u8 sta_id, | ||
54 | const u8 *addr); | ||
55 | int iwlagn_mac_sta_remove(struct ieee80211_hw *hw, struct ieee80211_vif *vif, | ||
56 | struct ieee80211_sta *sta); | ||
57 | |||
58 | u8 iwl_prep_station(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
59 | const u8 *addr, bool is_ap, struct ieee80211_sta *sta); | ||
60 | |||
61 | void iwl_sta_fill_lq(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
62 | u8 sta_id, struct iwl_link_quality_cmd *link_cmd); | ||
63 | int iwl_send_lq_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx, | ||
64 | struct iwl_link_quality_cmd *lq, u8 flags, bool init); | ||
65 | void iwl_reprogram_ap_sta(struct iwl_priv *priv, struct iwl_rxon_context *ctx); | ||
66 | int iwl_add_sta_callback(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb, | ||
67 | struct iwl_device_cmd *cmd); | ||
68 | |||
69 | |||
70 | /** | ||
71 | * iwl_clear_driver_stations - clear knowledge of all stations from driver | ||
72 | * @priv: iwl priv struct | ||
73 | * | ||
74 | * This is called during iwl_down() to make sure that in the case | ||
75 | * we're coming there from a hardware restart mac80211 will be | ||
76 | * able to reconfigure stations -- if we're getting there in the | ||
77 | * normal down flow then the stations will already be cleared. | ||
78 | */ | ||
79 | static inline void iwl_clear_driver_stations(struct iwl_priv *priv) | ||
80 | { | ||
81 | unsigned long flags; | ||
82 | struct iwl_rxon_context *ctx; | ||
83 | |||
84 | spin_lock_irqsave(&priv->shrd->sta_lock, flags); | ||
85 | memset(priv->stations, 0, sizeof(priv->stations)); | ||
86 | priv->num_stations = 0; | ||
87 | |||
88 | priv->ucode_key_table = 0; | ||
89 | |||
90 | for_each_context(priv, ctx) { | ||
91 | /* | ||
92 | * Remove all key information that is not stored as part | ||
93 | * of station information since mac80211 may not have had | ||
94 | * a chance to remove all the keys. When device is | ||
95 | * reconfigured by mac80211 after an error all keys will | ||
96 | * be reconfigured. | ||
97 | */ | ||
98 | memset(ctx->wep_keys, 0, sizeof(ctx->wep_keys)); | ||
99 | ctx->key_mapping_keys = 0; | ||
100 | } | ||
101 | |||
102 | spin_unlock_irqrestore(&priv->shrd->sta_lock, flags); | ||
103 | } | ||
104 | |||
105 | static inline int iwl_sta_id(struct ieee80211_sta *sta) | ||
106 | { | ||
107 | if (WARN_ON(!sta)) | ||
108 | return IWL_INVALID_STATION; | ||
109 | |||
110 | return ((struct iwl_station_priv *)sta->drv_priv)->sta_id; | ||
111 | } | ||
112 | |||
113 | /** | ||
114 | * iwl_sta_id_or_broadcast - return sta_id or broadcast sta | ||
115 | * @priv: iwl priv | ||
116 | * @context: the current context | ||
117 | * @sta: mac80211 station | ||
118 | * | ||
119 | * In certain circumstances mac80211 passes a station pointer | ||
120 | * that may be %NULL, for example during TX or key setup. In | ||
121 | * that case, we need to use the broadcast station, so this | ||
122 | * inline wraps that pattern. | ||
123 | */ | ||
124 | static inline int iwl_sta_id_or_broadcast(struct iwl_priv *priv, | ||
125 | struct iwl_rxon_context *context, | ||
126 | struct ieee80211_sta *sta) | ||
127 | { | ||
128 | int sta_id; | ||
129 | |||
130 | if (!sta) | ||
131 | return context->bcast_sta_id; | ||
132 | |||
133 | sta_id = iwl_sta_id(sta); | ||
134 | |||
135 | /* | ||
136 | * mac80211 should not be passing a partially | ||
137 | * initialised station! | ||
138 | */ | ||
139 | WARN_ON(sta_id == IWL_INVALID_STATION); | ||
140 | |||
141 | return sta_id; | ||
142 | } | ||
143 | #endif /* __iwl_sta_h__ */ | ||