]>
Commit | Line | Data |
---|---|---|
f5fc0f86 LC |
1 | /* |
2 | * This file is part of wl1271 | |
3 | * | |
2f826f55 | 4 | * Copyright (C) 2009-2010 Nokia Corporation |
f5fc0f86 LC |
5 | * |
6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public License | |
10 | * version 2 as published by the Free Software Foundation. | |
11 | * | |
12 | * This program is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with this program; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
20 | * 02110-1301 USA | |
21 | * | |
22 | */ | |
23 | ||
24 | #include <linux/module.h> | |
25 | #include <linux/platform_device.h> | |
f5fc0f86 LC |
26 | #include <linux/spi/spi.h> |
27 | #include <linux/etherdevice.h> | |
023e0826 | 28 | #include <linux/ieee80211.h> |
5a0e3ad6 | 29 | #include <linux/slab.h> |
f5fc0f86 | 30 | |
c31be25a | 31 | #include "wlcore.h" |
0f4e3122 | 32 | #include "debug.h" |
00d20100 SL |
33 | #include "io.h" |
34 | #include "acx.h" | |
f5fc0f86 | 35 | #include "wl12xx_80211.h" |
00d20100 SL |
36 | #include "cmd.h" |
37 | #include "event.h" | |
98bdaabb | 38 | #include "tx.h" |
60462b48 | 39 | #include "hw_ops.h" |
f5fc0f86 | 40 | |
16092b5c | 41 | #define WL1271_CMD_FAST_POLL_COUNT 50 |
c45ee4ff | 42 | #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20 |
f5fc0f86 LC |
43 | |
44 | /* | |
45 | * send command to firmware | |
46 | * | |
47 | * @wl: wl struct | |
48 | * @id: command id | |
49 | * @buf: buffer containing the command, must work with dma | |
50 | * @len: length of the buffer | |
ea508435 | 51 | * return the cmd status code on success. |
f5fc0f86 | 52 | */ |
ea508435 EP |
53 | static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf, |
54 | size_t len, size_t res_len) | |
f5fc0f86 LC |
55 | { |
56 | struct wl1271_cmd_header *cmd; | |
57 | unsigned long timeout; | |
58 | u32 intr; | |
ea508435 | 59 | int ret; |
ad150e96 | 60 | u16 status; |
bc0f03ea | 61 | u16 poll_count = 0; |
f5fc0f86 | 62 | |
1ede9500 AN |
63 | if (unlikely(wl->state == WLCORE_STATE_RESTARTING && |
64 | id != CMD_STOP_FWLOGGER)) | |
4cc53383 IY |
65 | return -EIO; |
66 | ||
f5b8f479 LC |
67 | if (WARN_ON_ONCE(len < sizeof(*cmd))) |
68 | return -EIO; | |
69 | ||
f5fc0f86 | 70 | cmd = buf; |
d0f63b20 | 71 | cmd->id = cpu_to_le16(id); |
f5fc0f86 LC |
72 | cmd->status = 0; |
73 | ||
74 | WARN_ON(len % 4 != 0); | |
24225b37 | 75 | WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags)); |
f5fc0f86 | 76 | |
eb96f841 IY |
77 | ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false); |
78 | if (ret < 0) | |
ea508435 | 79 | return ret; |
f5fc0f86 | 80 | |
f16ff758 LC |
81 | /* |
82 | * TODO: we just need this because one bit is in a different | |
83 | * place. Is there any better way? | |
84 | */ | |
eb96f841 IY |
85 | ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len); |
86 | if (ret < 0) | |
ea508435 | 87 | return ret; |
f5fc0f86 LC |
88 | |
89 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); | |
90 | ||
6134323f IY |
91 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); |
92 | if (ret < 0) | |
ea508435 | 93 | return ret; |
6134323f | 94 | |
f5fc0f86 LC |
95 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
96 | if (time_after(jiffies, timeout)) { | |
97 | wl1271_error("command complete timeout"); | |
ea508435 | 98 | return -ETIMEDOUT; |
f5fc0f86 LC |
99 | } |
100 | ||
bc0f03ea | 101 | poll_count++; |
16092b5c JO |
102 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) |
103 | udelay(10); | |
104 | else | |
105 | msleep(1); | |
f5fc0f86 | 106 | |
6134323f IY |
107 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); |
108 | if (ret < 0) | |
ea508435 | 109 | return ret; |
f5fc0f86 LC |
110 | } |
111 | ||
3b775b4b | 112 | /* read back the status code of the command */ |
fa867e73 JO |
113 | if (res_len == 0) |
114 | res_len = sizeof(struct wl1271_cmd_header); | |
045b9b5f IY |
115 | |
116 | ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false); | |
117 | if (ret < 0) | |
ea508435 | 118 | return ret; |
3b775b4b | 119 | |
ad150e96 | 120 | status = le16_to_cpu(cmd->status); |
3b775b4b | 121 | |
b0f0ad39 IY |
122 | ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK, |
123 | WL1271_ACX_INTR_CMD_COMPLETE); | |
ea508435 EP |
124 | if (ret < 0) |
125 | return ret; | |
126 | ||
127 | return status; | |
128 | } | |
129 | ||
130 | /* | |
131 | * send command to fw and return cmd status on success | |
132 | * valid_rets contains a bitmap of allowed error codes | |
133 | */ | |
d351f5fe LC |
134 | static int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf, |
135 | size_t len, size_t res_len, | |
136 | unsigned long valid_rets) | |
ea508435 EP |
137 | { |
138 | int ret = __wlcore_cmd_send(wl, id, buf, len, res_len); | |
139 | ||
b0f0ad39 IY |
140 | if (ret < 0) |
141 | goto fail; | |
142 | ||
ea508435 EP |
143 | /* success is always a valid status */ |
144 | valid_rets |= BIT(CMD_STATUS_SUCCESS); | |
f5fc0f86 | 145 | |
ea508435 EP |
146 | if (ret >= MAX_COMMAND_STATUS || |
147 | !test_bit(ret, &valid_rets)) { | |
148 | wl1271_error("command execute failure %d", ret); | |
149 | ret = -EIO; | |
150 | goto fail; | |
151 | } | |
152 | return ret; | |
f482b762 | 153 | fail: |
baacb9ae | 154 | wl12xx_queue_recovery_work(wl); |
f5fc0f86 LC |
155 | return ret; |
156 | } | |
157 | ||
ea508435 EP |
158 | /* |
159 | * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS | |
160 | * return 0 on success. | |
161 | */ | |
162 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, | |
163 | size_t res_len) | |
164 | { | |
165 | int ret = wlcore_cmd_send_failsafe(wl, id, buf, len, res_len, 0); | |
166 | ||
167 | if (ret < 0) | |
168 | return ret; | |
169 | return 0; | |
170 | } | |
d351f5fe | 171 | EXPORT_SYMBOL_GPL(wl1271_cmd_send); |
f5fc0f86 | 172 | |
99d84c1d LC |
173 | /* |
174 | * Poll the mailbox event field until any of the bits in the mask is set or a | |
175 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) | |
176 | */ | |
c50a2825 EP |
177 | int wlcore_cmd_wait_for_event_or_timeout(struct wl1271 *wl, |
178 | u32 mask, bool *timeout) | |
99d84c1d | 179 | { |
690142e9 MG |
180 | u32 *events_vector; |
181 | u32 event; | |
6c15c1aa | 182 | unsigned long timeout_time; |
c45ee4ff | 183 | u16 poll_count = 0; |
690142e9 MG |
184 | int ret = 0; |
185 | ||
6c15c1aa ES |
186 | *timeout = false; |
187 | ||
0230dfea DC |
188 | events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA); |
189 | if (!events_vector) | |
190 | return -ENOMEM; | |
99d84c1d | 191 | |
6c15c1aa | 192 | timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); |
99d84c1d LC |
193 | |
194 | do { | |
6c15c1aa | 195 | if (time_after(jiffies, timeout_time)) { |
05285cf9 AN |
196 | wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", |
197 | (int)mask); | |
6c15c1aa | 198 | *timeout = true; |
690142e9 | 199 | goto out; |
52b0e7a6 | 200 | } |
99d84c1d | 201 | |
c45ee4ff YD |
202 | poll_count++; |
203 | if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT) | |
204 | usleep_range(50, 51); | |
205 | else | |
206 | usleep_range(1000, 5000); | |
99d84c1d LC |
207 | |
208 | /* read from both event fields */ | |
045b9b5f IY |
209 | ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector, |
210 | sizeof(*events_vector), false); | |
211 | if (ret < 0) | |
212 | goto out; | |
213 | ||
690142e9 | 214 | event = *events_vector & mask; |
045b9b5f IY |
215 | |
216 | ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector, | |
217 | sizeof(*events_vector), false); | |
218 | if (ret < 0) | |
219 | goto out; | |
220 | ||
690142e9 | 221 | event |= *events_vector & mask; |
99d84c1d LC |
222 | } while (!event); |
223 | ||
690142e9 MG |
224 | out: |
225 | kfree(events_vector); | |
226 | return ret; | |
99d84c1d | 227 | } |
c50a2825 | 228 | EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout); |
05285cf9 | 229 | |
784f694d EP |
230 | int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type, |
231 | u8 *role_id) | |
f5fc0f86 | 232 | { |
c690ec81 EP |
233 | struct wl12xx_cmd_role_enable *cmd; |
234 | int ret; | |
235 | ||
236 | wl1271_debug(DEBUG_CMD, "cmd role enable"); | |
237 | ||
238 | if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID)) | |
239 | return -EBUSY; | |
240 | ||
241 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
242 | if (!cmd) { | |
243 | ret = -ENOMEM; | |
244 | goto out; | |
245 | } | |
246 | ||
247 | /* get role id */ | |
248 | cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES); | |
249 | if (cmd->role_id >= WL12XX_MAX_ROLES) { | |
250 | ret = -EBUSY; | |
251 | goto out_free; | |
252 | } | |
253 | ||
784f694d | 254 | memcpy(cmd->mac_address, addr, ETH_ALEN); |
c690ec81 EP |
255 | cmd->role_type = role_type; |
256 | ||
257 | ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); | |
258 | if (ret < 0) { | |
259 | wl1271_error("failed to initiate cmd role enable"); | |
260 | goto out_free; | |
261 | } | |
262 | ||
263 | __set_bit(cmd->role_id, wl->roles_map); | |
264 | *role_id = cmd->role_id; | |
f5fc0f86 | 265 | |
c690ec81 EP |
266 | out_free: |
267 | kfree(cmd); | |
268 | ||
269 | out: | |
270 | return ret; | |
271 | } | |
272 | ||
273 | int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id) | |
274 | { | |
275 | struct wl12xx_cmd_role_disable *cmd; | |
276 | int ret; | |
277 | ||
278 | wl1271_debug(DEBUG_CMD, "cmd role disable"); | |
279 | ||
280 | if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID)) | |
281 | return -ENOENT; | |
282 | ||
283 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
284 | if (!cmd) { | |
f5fc0f86 LC |
285 | ret = -ENOMEM; |
286 | goto out; | |
287 | } | |
c690ec81 EP |
288 | cmd->role_id = *role_id; |
289 | ||
290 | ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0); | |
291 | if (ret < 0) { | |
292 | wl1271_error("failed to initiate cmd role disable"); | |
293 | goto out_free; | |
294 | } | |
f5fc0f86 | 295 | |
c690ec81 EP |
296 | __clear_bit(*role_id, wl->roles_map); |
297 | *role_id = WL12XX_INVALID_ROLE_ID; | |
f5fc0f86 | 298 | |
c690ec81 EP |
299 | out_free: |
300 | kfree(cmd); | |
301 | ||
302 | out: | |
303 | return ret; | |
304 | } | |
305 | ||
978cd3a0 EP |
306 | static int wlcore_get_new_session_id(struct wl1271 *wl, u8 hlid) |
307 | { | |
308 | if (wl->session_ids[hlid] >= SESSION_COUNTER_MAX) | |
309 | wl->session_ids[hlid] = 0; | |
310 | ||
311 | wl->session_ids[hlid]++; | |
312 | ||
313 | return wl->session_ids[hlid]; | |
314 | } | |
315 | ||
c7ffb902 | 316 | int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
c690ec81 | 317 | { |
0b0e32b7 | 318 | unsigned long flags; |
da08fdfa EP |
319 | u8 link = find_first_zero_bit(wl->links_map, wl->num_links); |
320 | if (link >= wl->num_links) | |
c690ec81 EP |
321 | return -EBUSY; |
322 | ||
978cd3a0 EP |
323 | wl->session_ids[link] = wlcore_get_new_session_id(wl, link); |
324 | ||
0b0e32b7 AN |
325 | /* these bits are used by op_tx */ |
326 | spin_lock_irqsave(&wl->wl_lock, flags); | |
c690ec81 | 327 | __set_bit(link, wl->links_map); |
c7ffb902 | 328 | __set_bit(link, wlvif->links_map); |
0b0e32b7 | 329 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
b50a62bb | 330 | |
75fb4df7 EP |
331 | /* |
332 | * take the last "freed packets" value from the current FW status. | |
333 | * on recovery, we might not have fw_status yet, and | |
334 | * tx_lnk_free_pkts will be NULL. check for it. | |
335 | */ | |
336 | if (wl->fw_status->counters.tx_lnk_free_pkts) | |
337 | wl->links[link].prev_freed_pkts = | |
338 | wl->fw_status->counters.tx_lnk_free_pkts[link]; | |
1e0708a9 | 339 | wl->links[link].wlvif = wlvif; |
93d5d100 AN |
340 | |
341 | /* | |
342 | * Take saved value for total freed packets from wlvif, in case this is | |
343 | * recovery/resume | |
344 | */ | |
345 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) | |
346 | wl->links[link].total_freed_pkts = wlvif->total_freed_pkts; | |
347 | ||
c690ec81 | 348 | *hlid = link; |
9a100968 AN |
349 | |
350 | wl->active_link_count++; | |
c690ec81 EP |
351 | return 0; |
352 | } | |
353 | ||
c7ffb902 | 354 | void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
c690ec81 | 355 | { |
0b0e32b7 AN |
356 | unsigned long flags; |
357 | ||
c690ec81 EP |
358 | if (*hlid == WL12XX_INVALID_LINK_ID) |
359 | return; | |
360 | ||
0b0e32b7 AN |
361 | /* these bits are used by op_tx */ |
362 | spin_lock_irqsave(&wl->wl_lock, flags); | |
c690ec81 | 363 | __clear_bit(*hlid, wl->links_map); |
c7ffb902 | 364 | __clear_bit(*hlid, wlvif->links_map); |
0b0e32b7 | 365 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
6246ca00 | 366 | |
6c4c4534 AN |
367 | wl->links[*hlid].allocated_pkts = 0; |
368 | wl->links[*hlid].prev_freed_pkts = 0; | |
369 | wl->links[*hlid].ba_bitmap = 0; | |
93803b33 | 370 | eth_zero_addr(wl->links[*hlid].addr); |
6c4c4534 | 371 | |
6246ca00 AN |
372 | /* |
373 | * At this point op_tx() will not add more packets to the queues. We | |
374 | * can purge them. | |
375 | */ | |
376 | wl1271_tx_reset_link_queues(wl, *hlid); | |
1e0708a9 | 377 | wl->links[*hlid].wlvif = NULL; |
6246ca00 | 378 | |
50d26aa3 EP |
379 | if (wlvif->bss_type == BSS_TYPE_AP_BSS && |
380 | *hlid == wlvif->ap.bcast_hlid) { | |
30a00358 | 381 | u32 sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING; |
93d5d100 AN |
382 | /* |
383 | * save the total freed packets in the wlvif, in case this is | |
384 | * recovery or suspend | |
385 | */ | |
386 | wlvif->total_freed_pkts = wl->links[*hlid].total_freed_pkts; | |
387 | ||
388 | /* | |
389 | * increment the initial seq number on recovery to account for | |
390 | * transmitted packets that we haven't yet got in the FW status | |
391 | */ | |
30a00358 EP |
392 | if (wlvif->encryption_type == KEY_GEM) |
393 | sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM; | |
394 | ||
93d5d100 | 395 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
30a00358 | 396 | wlvif->total_freed_pkts += sqn_padding; |
93d5d100 AN |
397 | } |
398 | ||
399 | wl->links[*hlid].total_freed_pkts = 0; | |
400 | ||
c690ec81 | 401 | *hlid = WL12XX_INVALID_LINK_ID; |
9a100968 AN |
402 | wl->active_link_count--; |
403 | WARN_ON_ONCE(wl->active_link_count < 0); | |
712e9bf7 AN |
404 | } |
405 | ||
750e9d15 | 406 | u8 wlcore_get_native_channel_type(u8 nl_channel_type) |
a6298dbe AN |
407 | { |
408 | switch (nl_channel_type) { | |
409 | case NL80211_CHAN_NO_HT: | |
410 | return WLCORE_CHAN_NO_HT; | |
411 | case NL80211_CHAN_HT20: | |
412 | return WLCORE_CHAN_HT20; | |
413 | case NL80211_CHAN_HT40MINUS: | |
414 | return WLCORE_CHAN_HT40MINUS; | |
415 | case NL80211_CHAN_HT40PLUS: | |
416 | return WLCORE_CHAN_HT40PLUS; | |
417 | default: | |
418 | WARN_ON(1); | |
419 | return WLCORE_CHAN_NO_HT; | |
420 | } | |
421 | } | |
750e9d15 | 422 | EXPORT_SYMBOL_GPL(wlcore_get_native_channel_type); |
a6298dbe | 423 | |
679a6734 | 424 | static int wl12xx_cmd_role_start_dev(struct wl1271 *wl, |
dabf37db | 425 | struct wl12xx_vif *wlvif, |
57fbcce3 | 426 | enum nl80211_band band, |
dabf37db | 427 | int channel) |
04e8079c EP |
428 | { |
429 | struct wl12xx_cmd_role_start *cmd; | |
430 | int ret; | |
431 | ||
432 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
433 | if (!cmd) { | |
434 | ret = -ENOMEM; | |
435 | goto out; | |
436 | } | |
437 | ||
7edebf56 | 438 | wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id); |
04e8079c | 439 | |
7edebf56 | 440 | cmd->role_id = wlvif->dev_role_id; |
57fbcce3 | 441 | if (band == NL80211_BAND_5GHZ) |
00782136 | 442 | cmd->band = WLCORE_BAND_5GHZ; |
dabf37db | 443 | cmd->channel = channel; |
04e8079c | 444 | |
afaf8bdb | 445 | if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) { |
c7ffb902 | 446 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid); |
04e8079c EP |
447 | if (ret) |
448 | goto out_free; | |
449 | } | |
afaf8bdb | 450 | cmd->device.hlid = wlvif->dev_hlid; |
978cd3a0 | 451 | cmd->device.session = wl->session_ids[wlvif->dev_hlid]; |
04e8079c EP |
452 | |
453 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", | |
454 | cmd->role_id, cmd->device.hlid, cmd->device.session); | |
455 | ||
456 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); | |
457 | if (ret < 0) { | |
458 | wl1271_error("failed to initiate cmd role enable"); | |
459 | goto err_hlid; | |
460 | } | |
461 | ||
462 | goto out_free; | |
463 | ||
464 | err_hlid: | |
465 | /* clear links on error */ | |
c7ffb902 | 466 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
04e8079c EP |
467 | |
468 | out_free: | |
469 | kfree(cmd); | |
470 | ||
471 | out: | |
472 | return ret; | |
473 | } | |
474 | ||
679a6734 EP |
475 | static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl, |
476 | struct wl12xx_vif *wlvif) | |
04e8079c EP |
477 | { |
478 | struct wl12xx_cmd_role_stop *cmd; | |
479 | int ret; | |
480 | ||
afaf8bdb | 481 | if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID)) |
04e8079c EP |
482 | return -EINVAL; |
483 | ||
484 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
485 | if (!cmd) { | |
486 | ret = -ENOMEM; | |
487 | goto out; | |
488 | } | |
489 | ||
490 | wl1271_debug(DEBUG_CMD, "cmd role stop dev"); | |
491 | ||
7edebf56 | 492 | cmd->role_id = wlvif->dev_role_id; |
04e8079c EP |
493 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
494 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); | |
495 | ||
496 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); | |
497 | if (ret < 0) { | |
498 | wl1271_error("failed to initiate cmd role stop"); | |
499 | goto out_free; | |
500 | } | |
501 | ||
c7ffb902 | 502 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
04e8079c EP |
503 | |
504 | out_free: | |
505 | kfree(cmd); | |
506 | ||
507 | out: | |
508 | return ret; | |
509 | } | |
510 | ||
87fbcb0f | 511 | int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c690ec81 | 512 | { |
cdf09495 | 513 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
c690ec81 | 514 | struct wl12xx_cmd_role_start *cmd; |
42ec1f82 | 515 | u32 supported_rates; |
c690ec81 | 516 | int ret; |
f5fc0f86 | 517 | |
c690ec81 EP |
518 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
519 | if (!cmd) { | |
520 | ret = -ENOMEM; | |
521 | goto out; | |
522 | } | |
f5fc0f86 | 523 | |
0603d891 | 524 | wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id); |
c690ec81 | 525 | |
0603d891 | 526 | cmd->role_id = wlvif->role_id; |
57fbcce3 | 527 | if (wlvif->band == NL80211_BAND_5GHZ) |
00782136 | 528 | cmd->band = WLCORE_BAND_5GHZ; |
61f845f4 | 529 | cmd->channel = wlvif->channel; |
87fbcb0f | 530 | cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
6a899796 | 531 | cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
c690ec81 | 532 | cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; |
1fe9f161 EP |
533 | cmd->sta.ssid_len = wlvif->ssid_len; |
534 | memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len); | |
cdf09495 | 535 | memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN); |
42ec1f82 EP |
536 | |
537 | supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | | |
538 | wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); | |
539 | if (wlvif->p2p) | |
540 | supported_rates &= ~CONF_TX_CCK_RATES; | |
541 | ||
542 | cmd->sta.local_rates = cpu_to_le32(supported_rates); | |
543 | ||
a6298dbe | 544 | cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); |
c690ec81 | 545 | |
154da67c | 546 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
c7ffb902 | 547 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
c690ec81 EP |
548 | if (ret) |
549 | goto out_free; | |
550 | } | |
154da67c | 551 | cmd->sta.hlid = wlvif->sta.hlid; |
978cd3a0 | 552 | cmd->sta.session = wl->session_ids[wlvif->sta.hlid]; |
dc62a3db | 553 | /* |
9c3a8d99 LC |
554 | * We don't have the correct remote rates in this stage. The |
555 | * rates will be reconfigured later, after association, if the | |
556 | * firmware supports ACX_PEER_CAP. Otherwise, there's nothing | |
557 | * we can do, so use all supported_rates here. | |
dc62a3db | 558 | */ |
9c3a8d99 | 559 | cmd->sta.remote_rates = cpu_to_le32(supported_rates); |
c690ec81 EP |
560 | |
561 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " | |
562 | "basic_rate_set: 0x%x, remote_rates: 0x%x", | |
0603d891 | 563 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
30d0c8fd | 564 | wlvif->basic_rate_set, wlvif->rate_set); |
c690ec81 EP |
565 | |
566 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); | |
567 | if (ret < 0) { | |
568 | wl1271_error("failed to initiate cmd role start sta"); | |
569 | goto err_hlid; | |
570 | } | |
571 | ||
5f9b6777 | 572 | wlvif->sta.role_chan_type = wlvif->channel_type; |
c690ec81 EP |
573 | goto out_free; |
574 | ||
575 | err_hlid: | |
576 | /* clear links on error. */ | |
c7ffb902 | 577 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
c690ec81 EP |
578 | |
579 | out_free: | |
580 | kfree(cmd); | |
581 | ||
582 | out: | |
583 | return ret; | |
584 | } | |
f5fc0f86 | 585 | |
31cd3aed | 586 | /* use this function to stop ibss as well */ |
0603d891 | 587 | int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c690ec81 EP |
588 | { |
589 | struct wl12xx_cmd_role_stop *cmd; | |
590 | int ret; | |
591 | ||
154da67c | 592 | if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)) |
c690ec81 EP |
593 | return -EINVAL; |
594 | ||
595 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
596 | if (!cmd) { | |
597 | ret = -ENOMEM; | |
598 | goto out; | |
599 | } | |
a4102645 | 600 | |
0603d891 | 601 | wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id); |
f5fc0f86 | 602 | |
0603d891 | 603 | cmd->role_id = wlvif->role_id; |
c690ec81 EP |
604 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
605 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); | |
f5fc0f86 | 606 | |
c690ec81 EP |
607 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
608 | if (ret < 0) { | |
609 | wl1271_error("failed to initiate cmd role stop sta"); | |
610 | goto out_free; | |
611 | } | |
72c2d9e5 | 612 | |
c7ffb902 | 613 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
c690ec81 EP |
614 | |
615 | out_free: | |
616 | kfree(cmd); | |
617 | ||
618 | out: | |
619 | return ret; | |
620 | } | |
621 | ||
87fbcb0f | 622 | int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c690ec81 EP |
623 | { |
624 | struct wl12xx_cmd_role_start *cmd; | |
6e8cd331 EP |
625 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
626 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; | |
60462b48 | 627 | u32 supported_rates; |
c690ec81 EP |
628 | int ret; |
629 | ||
0603d891 | 630 | wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id); |
c690ec81 | 631 | |
c0174ee2 MH |
632 | /* If MESH --> ssid_len is always 0 */ |
633 | if (!ieee80211_vif_is_mesh(vif)) { | |
634 | /* trying to use hidden SSID with an old hostapd version */ | |
635 | if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) { | |
636 | wl1271_error("got a null SSID from beacon/bss"); | |
637 | ret = -EINVAL; | |
638 | goto out; | |
639 | } | |
c690ec81 EP |
640 | } |
641 | ||
642 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
643 | if (!cmd) { | |
644 | ret = -ENOMEM; | |
645 | goto out; | |
646 | } | |
647 | ||
c7ffb902 | 648 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid); |
e51ae9be AN |
649 | if (ret < 0) |
650 | goto out_free; | |
651 | ||
c7ffb902 | 652 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
e51ae9be AN |
653 | if (ret < 0) |
654 | goto out_free_global; | |
655 | ||
0e752df6 AN |
656 | /* use the previous security seq, if this is a recovery/resume */ |
657 | wl->links[wlvif->ap.bcast_hlid].total_freed_pkts = | |
658 | wlvif->total_freed_pkts; | |
659 | ||
0603d891 | 660 | cmd->role_id = wlvif->role_id; |
c690ec81 EP |
661 | cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); |
662 | cmd->ap.bss_index = WL1271_AP_BSS_INDEX; | |
a8ab39a4 EP |
663 | cmd->ap.global_hlid = wlvif->ap.global_hlid; |
664 | cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid; | |
978cd3a0 EP |
665 | cmd->ap.global_session_id = wl->session_ids[wlvif->ap.global_hlid]; |
666 | cmd->ap.bcast_session_id = wl->session_ids[wlvif->ap.bcast_hlid]; | |
87fbcb0f | 667 | cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
6a899796 | 668 | cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
c690ec81 EP |
669 | cmd->ap.dtim_interval = bss_conf->dtim_period; |
670 | cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; | |
8332f0f6 EP |
671 | /* FIXME: Change when adding DFS */ |
672 | cmd->ap.reset_tsf = 1; /* By default reset AP TSF */ | |
d50529c0 | 673 | cmd->ap.wmm = wlvif->wmm_enabled; |
61f845f4 | 674 | cmd->channel = wlvif->channel; |
a6298dbe | 675 | cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); |
68eaaf6e AN |
676 | |
677 | if (!bss_conf->hidden_ssid) { | |
678 | /* take the SSID from the beacon for backward compatibility */ | |
679 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; | |
1fe9f161 EP |
680 | cmd->ap.ssid_len = wlvif->ssid_len; |
681 | memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len); | |
68eaaf6e AN |
682 | } else { |
683 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; | |
684 | cmd->ap.ssid_len = bss_conf->ssid_len; | |
685 | memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len); | |
686 | } | |
687 | ||
42ec1f82 | 688 | supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | |
60462b48 | 689 | wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif); |
873d2a40 EP |
690 | if (wlvif->p2p) |
691 | supported_rates &= ~CONF_TX_CCK_RATES; | |
60462b48 LC |
692 | |
693 | wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x", | |
694 | supported_rates); | |
695 | ||
696 | cmd->ap.local_rates = cpu_to_le32(supported_rates); | |
c690ec81 | 697 | |
1b92f15e | 698 | switch (wlvif->band) { |
57fbcce3 | 699 | case NL80211_BAND_2GHZ: |
00782136 | 700 | cmd->band = WLCORE_BAND_2_4GHZ; |
c690ec81 | 701 | break; |
57fbcce3 | 702 | case NL80211_BAND_5GHZ: |
00782136 | 703 | cmd->band = WLCORE_BAND_5GHZ; |
c690ec81 EP |
704 | break; |
705 | default: | |
1b92f15e | 706 | wl1271_warning("ap start - unknown band: %d", (int)wlvif->band); |
00782136 | 707 | cmd->band = WLCORE_BAND_2_4GHZ; |
c690ec81 EP |
708 | break; |
709 | } | |
710 | ||
711 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); | |
712 | if (ret < 0) { | |
713 | wl1271_error("failed to initiate cmd role start ap"); | |
e51ae9be | 714 | goto out_free_bcast; |
c690ec81 | 715 | } |
f5fc0f86 | 716 | |
e51ae9be AN |
717 | goto out_free; |
718 | ||
719 | out_free_bcast: | |
c7ffb902 | 720 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
e51ae9be AN |
721 | |
722 | out_free_global: | |
c7ffb902 | 723 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); |
e51ae9be | 724 | |
f5fc0f86 | 725 | out_free: |
c690ec81 | 726 | kfree(cmd); |
f5fc0f86 LC |
727 | |
728 | out: | |
729 | return ret; | |
730 | } | |
731 | ||
0603d891 | 732 | int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c690ec81 EP |
733 | { |
734 | struct wl12xx_cmd_role_stop *cmd; | |
735 | int ret; | |
736 | ||
737 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
738 | if (!cmd) { | |
739 | ret = -ENOMEM; | |
740 | goto out; | |
741 | } | |
742 | ||
0603d891 | 743 | wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id); |
c690ec81 | 744 | |
0603d891 | 745 | cmd->role_id = wlvif->role_id; |
c690ec81 EP |
746 | |
747 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); | |
748 | if (ret < 0) { | |
749 | wl1271_error("failed to initiate cmd role stop ap"); | |
750 | goto out_free; | |
751 | } | |
752 | ||
c7ffb902 EP |
753 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
754 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); | |
e51ae9be | 755 | |
c690ec81 EP |
756 | out_free: |
757 | kfree(cmd); | |
758 | ||
759 | out: | |
760 | return ret; | |
761 | } | |
762 | ||
87fbcb0f | 763 | int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
31cd3aed | 764 | { |
cdf09495 | 765 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
31cd3aed | 766 | struct wl12xx_cmd_role_start *cmd; |
6e8cd331 | 767 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
31cd3aed EP |
768 | int ret; |
769 | ||
770 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
771 | if (!cmd) { | |
772 | ret = -ENOMEM; | |
773 | goto out; | |
774 | } | |
775 | ||
0603d891 | 776 | wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id); |
31cd3aed | 777 | |
0603d891 | 778 | cmd->role_id = wlvif->role_id; |
57fbcce3 | 779 | if (wlvif->band == NL80211_BAND_5GHZ) |
00782136 | 780 | cmd->band = WLCORE_BAND_5GHZ; |
61f845f4 | 781 | cmd->channel = wlvif->channel; |
87fbcb0f | 782 | cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
6a899796 | 783 | cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
31cd3aed EP |
784 | cmd->ibss.dtim_interval = bss_conf->dtim_period; |
785 | cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; | |
1fe9f161 EP |
786 | cmd->ibss.ssid_len = wlvif->ssid_len; |
787 | memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len); | |
cdf09495 | 788 | memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN); |
30d0c8fd | 789 | cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); |
31cd3aed | 790 | |
154da67c | 791 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
c7ffb902 | 792 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
31cd3aed EP |
793 | if (ret) |
794 | goto out_free; | |
795 | } | |
154da67c | 796 | cmd->ibss.hlid = wlvif->sta.hlid; |
30d0c8fd | 797 | cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set); |
31cd3aed EP |
798 | |
799 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " | |
800 | "basic_rate_set: 0x%x, remote_rates: 0x%x", | |
0603d891 | 801 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
30d0c8fd | 802 | wlvif->basic_rate_set, wlvif->rate_set); |
31cd3aed | 803 | |
cdf09495 EP |
804 | wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM", |
805 | vif->bss_conf.bssid); | |
31cd3aed EP |
806 | |
807 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); | |
808 | if (ret < 0) { | |
809 | wl1271_error("failed to initiate cmd role enable"); | |
810 | goto err_hlid; | |
811 | } | |
812 | ||
813 | goto out_free; | |
814 | ||
815 | err_hlid: | |
816 | /* clear links on error. */ | |
c7ffb902 | 817 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
31cd3aed EP |
818 | |
819 | out_free: | |
820 | kfree(cmd); | |
821 | ||
822 | out: | |
823 | return ret; | |
824 | } | |
825 | ||
c690ec81 | 826 | |
f5fc0f86 LC |
827 | /** |
828 | * send test command to firmware | |
829 | * | |
830 | * @wl: wl struct | |
831 | * @buf: buffer containing the command, with all headers, must work with dma | |
832 | * @len: length of the buffer | |
833 | * @answer: is answer needed | |
834 | */ | |
835 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) | |
836 | { | |
837 | int ret; | |
fa867e73 | 838 | size_t res_len = 0; |
f5fc0f86 LC |
839 | |
840 | wl1271_debug(DEBUG_CMD, "cmd test"); | |
841 | ||
fa867e73 JO |
842 | if (answer) |
843 | res_len = buf_len; | |
844 | ||
845 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); | |
f5fc0f86 LC |
846 | |
847 | if (ret < 0) { | |
848 | wl1271_warning("TEST command failed"); | |
849 | return ret; | |
850 | } | |
851 | ||
fa867e73 | 852 | return ret; |
f5fc0f86 | 853 | } |
9d68d1ee | 854 | EXPORT_SYMBOL_GPL(wl1271_cmd_test); |
f5fc0f86 LC |
855 | |
856 | /** | |
857 | * read acx from firmware | |
858 | * | |
859 | * @wl: wl struct | |
860 | * @id: acx id | |
861 | * @buf: buffer for the response, including all headers, must work with dma | |
25985edc | 862 | * @len: length of buf |
f5fc0f86 | 863 | */ |
4b674144 IC |
864 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, |
865 | size_t cmd_len, size_t res_len) | |
f5fc0f86 LC |
866 | { |
867 | struct acx_header *acx = buf; | |
868 | int ret; | |
869 | ||
870 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); | |
871 | ||
d0f63b20 | 872 | acx->id = cpu_to_le16(id); |
f5fc0f86 | 873 | |
4b674144 IC |
874 | /* response payload length, does not include any headers */ |
875 | acx->len = cpu_to_le16(res_len - sizeof(*acx)); | |
f5fc0f86 | 876 | |
4b674144 | 877 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, cmd_len, res_len); |
fa867e73 | 878 | if (ret < 0) |
f5fc0f86 | 879 | wl1271_error("INTERROGATE command failed"); |
f5fc0f86 | 880 | |
f5fc0f86 LC |
881 | return ret; |
882 | } | |
883 | ||
884 | /** | |
885 | * write acx value to firmware | |
886 | * | |
887 | * @wl: wl struct | |
888 | * @id: acx id | |
889 | * @buf: buffer containing acx, including all headers, must work with dma | |
890 | * @len: length of buf | |
ea508435 EP |
891 | * @valid_rets: bitmap of valid cmd status codes (i.e. return values). |
892 | * return the cmd status on success. | |
f5fc0f86 | 893 | */ |
ea508435 EP |
894 | int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf, |
895 | size_t len, unsigned long valid_rets) | |
f5fc0f86 LC |
896 | { |
897 | struct acx_header *acx = buf; | |
898 | int ret; | |
899 | ||
c91d0600 | 900 | wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id); |
f5fc0f86 | 901 | |
f5b8f479 LC |
902 | if (WARN_ON_ONCE(len < sizeof(*acx))) |
903 | return -EIO; | |
904 | ||
d0f63b20 | 905 | acx->id = cpu_to_le16(id); |
f5fc0f86 LC |
906 | |
907 | /* payload length, does not include any headers */ | |
d0f63b20 | 908 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
f5fc0f86 | 909 | |
ea508435 EP |
910 | ret = wlcore_cmd_send_failsafe(wl, CMD_CONFIGURE, acx, len, 0, |
911 | valid_rets); | |
f5fc0f86 LC |
912 | if (ret < 0) { |
913 | wl1271_warning("CONFIGURE command NOK"); | |
914 | return ret; | |
915 | } | |
916 | ||
ea508435 EP |
917 | return ret; |
918 | } | |
919 | ||
920 | /* | |
921 | * wrapper for wlcore_cmd_configure that accepts only success status. | |
922 | * return 0 on success | |
923 | */ | |
924 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) | |
925 | { | |
926 | int ret = wlcore_cmd_configure_failsafe(wl, id, buf, len, 0); | |
927 | ||
928 | if (ret < 0) | |
929 | return ret; | |
f5fc0f86 LC |
930 | return 0; |
931 | } | |
9d68d1ee | 932 | EXPORT_SYMBOL_GPL(wl1271_cmd_configure); |
f5fc0f86 | 933 | |
94210897 | 934 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) |
f5fc0f86 LC |
935 | { |
936 | struct cmd_enabledisable_path *cmd; | |
937 | int ret; | |
938 | u16 cmd_rx, cmd_tx; | |
939 | ||
940 | wl1271_debug(DEBUG_CMD, "cmd data path"); | |
941 | ||
942 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
943 | if (!cmd) { | |
944 | ret = -ENOMEM; | |
945 | goto out; | |
946 | } | |
947 | ||
94210897 LC |
948 | /* the channel here is only used for calibration, so hardcoded to 1 */ |
949 | cmd->channel = 1; | |
f5fc0f86 LC |
950 | |
951 | if (enable) { | |
952 | cmd_rx = CMD_ENABLE_RX; | |
953 | cmd_tx = CMD_ENABLE_TX; | |
954 | } else { | |
955 | cmd_rx = CMD_DISABLE_RX; | |
956 | cmd_tx = CMD_DISABLE_TX; | |
957 | } | |
958 | ||
fa867e73 | 959 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
f5fc0f86 LC |
960 | if (ret < 0) { |
961 | wl1271_error("rx %s cmd for channel %d failed", | |
94210897 | 962 | enable ? "start" : "stop", cmd->channel); |
f5fc0f86 LC |
963 | goto out; |
964 | } | |
965 | ||
966 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", | |
94210897 | 967 | enable ? "start" : "stop", cmd->channel); |
f5fc0f86 | 968 | |
fa867e73 | 969 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
f5fc0f86 LC |
970 | if (ret < 0) { |
971 | wl1271_error("tx %s cmd for channel %d failed", | |
94210897 | 972 | enable ? "start" : "stop", cmd->channel); |
1b00f2b5 | 973 | goto out; |
f5fc0f86 LC |
974 | } |
975 | ||
976 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", | |
94210897 | 977 | enable ? "start" : "stop", cmd->channel); |
f5fc0f86 LC |
978 | |
979 | out: | |
980 | kfree(cmd); | |
981 | return ret; | |
982 | } | |
c331b344 | 983 | EXPORT_SYMBOL_GPL(wl1271_cmd_data_path); |
f5fc0f86 | 984 | |
0603d891 | 985 | int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
f1d63a59 | 986 | u8 ps_mode, u16 auto_ps_timeout) |
f5fc0f86 LC |
987 | { |
988 | struct wl1271_cmd_ps_params *ps_params = NULL; | |
989 | int ret = 0; | |
990 | ||
f5fc0f86 LC |
991 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
992 | ||
993 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); | |
994 | if (!ps_params) { | |
995 | ret = -ENOMEM; | |
996 | goto out; | |
997 | } | |
998 | ||
0603d891 | 999 | ps_params->role_id = wlvif->role_id; |
f5fc0f86 | 1000 | ps_params->ps_mode = ps_mode; |
f1d63a59 | 1001 | ps_params->auto_ps_timeout = auto_ps_timeout; |
f5fc0f86 LC |
1002 | |
1003 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, | |
fa867e73 | 1004 | sizeof(*ps_params), 0); |
f5fc0f86 LC |
1005 | if (ret < 0) { |
1006 | wl1271_error("cmd set_ps_mode failed"); | |
1007 | goto out; | |
1008 | } | |
1009 | ||
1010 | out: | |
1011 | kfree(ps_params); | |
1012 | return ret; | |
1013 | } | |
1014 | ||
cdaac628 EP |
1015 | int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id, |
1016 | u16 template_id, void *buf, size_t buf_len, | |
1017 | int index, u32 rates) | |
f5fc0f86 LC |
1018 | { |
1019 | struct wl1271_cmd_template_set *cmd; | |
1020 | int ret = 0; | |
1021 | ||
c059beb2 EP |
1022 | wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)", |
1023 | template_id, role_id); | |
f5fc0f86 LC |
1024 | |
1025 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); | |
1026 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); | |
1027 | ||
1028 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1029 | if (!cmd) { | |
1030 | ret = -ENOMEM; | |
1031 | goto out; | |
1032 | } | |
1033 | ||
cdaac628 EP |
1034 | /* during initialization wlvif is NULL */ |
1035 | cmd->role_id = role_id; | |
f5fc0f86 LC |
1036 | cmd->len = cpu_to_le16(buf_len); |
1037 | cmd->template_type = template_id; | |
606c1487 | 1038 | cmd->enabled_rates = cpu_to_le32(rates); |
1e05a818 AN |
1039 | cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; |
1040 | cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; | |
bfb24c9e | 1041 | cmd->index = index; |
f5fc0f86 LC |
1042 | |
1043 | if (buf) | |
1044 | memcpy(cmd->template_data, buf, buf_len); | |
1045 | ||
fa867e73 | 1046 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
f5fc0f86 LC |
1047 | if (ret < 0) { |
1048 | wl1271_warning("cmd set_template failed: %d", ret); | |
1049 | goto out_free; | |
1050 | } | |
1051 | ||
1052 | out_free: | |
1053 | kfree(cmd); | |
1054 | ||
1055 | out: | |
1056 | return ret; | |
1057 | } | |
1058 | ||
d2d66c56 | 1059 | int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
f5fc0f86 | 1060 | { |
a0cb7be4 JO |
1061 | struct sk_buff *skb = NULL; |
1062 | int size; | |
1063 | void *ptr; | |
1064 | int ret = -ENOMEM; | |
f5fc0f86 | 1065 | |
f5fc0f86 | 1066 | |
536129c8 | 1067 | if (wlvif->bss_type == BSS_TYPE_IBSS) { |
a0cb7be4 JO |
1068 | size = sizeof(struct wl12xx_null_data_template); |
1069 | ptr = NULL; | |
1070 | } else { | |
d2d66c56 | 1071 | skb = ieee80211_nullfunc_get(wl->hw, |
7b6ddeaf JB |
1072 | wl12xx_wlvif_to_vif(wlvif), |
1073 | false); | |
a0cb7be4 JO |
1074 | if (!skb) |
1075 | goto out; | |
1076 | size = skb->len; | |
1077 | ptr = skb->data; | |
1078 | } | |
1079 | ||
cdaac628 EP |
1080 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
1081 | CMD_TEMPL_NULL_DATA, ptr, size, 0, | |
d2d66c56 | 1082 | wlvif->basic_rate); |
f5fc0f86 | 1083 | |
899e6e65 KV |
1084 | out: |
1085 | dev_kfree_skb(skb); | |
a0cb7be4 JO |
1086 | if (ret) |
1087 | wl1271_warning("cmd buld null data failed %d", ret); | |
1088 | ||
899e6e65 | 1089 | return ret; |
f5fc0f86 LC |
1090 | |
1091 | } | |
1092 | ||
d2d66c56 EP |
1093 | int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl, |
1094 | struct wl12xx_vif *wlvif) | |
bfb24c9e | 1095 | { |
d2d66c56 | 1096 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
bfb24c9e JO |
1097 | struct sk_buff *skb = NULL; |
1098 | int ret = -ENOMEM; | |
1099 | ||
7b6ddeaf | 1100 | skb = ieee80211_nullfunc_get(wl->hw, vif, false); |
bfb24c9e JO |
1101 | if (!skb) |
1102 | goto out; | |
1103 | ||
cdaac628 | 1104 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV, |
bfb24c9e | 1105 | skb->data, skb->len, |
001e39a8 | 1106 | wlvif->sta.klv_template_id, |
d2d66c56 | 1107 | wlvif->basic_rate); |
bfb24c9e JO |
1108 | |
1109 | out: | |
1110 | dev_kfree_skb(skb); | |
1111 | if (ret) | |
1112 | wl1271_warning("cmd build klv null data failed %d", ret); | |
1113 | ||
1114 | return ret; | |
1115 | ||
1116 | } | |
1117 | ||
87fbcb0f EP |
1118 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1119 | u16 aid) | |
f5fc0f86 | 1120 | { |
6e8cd331 | 1121 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
899e6e65 KV |
1122 | struct sk_buff *skb; |
1123 | int ret = 0; | |
c3fea199 | 1124 | |
6e8cd331 | 1125 | skb = ieee80211_pspoll_get(wl->hw, vif); |
899e6e65 KV |
1126 | if (!skb) |
1127 | goto out; | |
f5fc0f86 | 1128 | |
cdaac628 EP |
1129 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
1130 | CMD_TEMPL_PS_POLL, skb->data, | |
87fbcb0f | 1131 | skb->len, 0, wlvif->basic_rate_set); |
f5fc0f86 | 1132 | |
899e6e65 KV |
1133 | out: |
1134 | dev_kfree_skb(skb); | |
1135 | return ret; | |
f5fc0f86 LC |
1136 | } |
1137 | ||
cdaac628 EP |
1138 | int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1139 | u8 role_id, u8 band, | |
818e3063 | 1140 | const u8 *ssid, size_t ssid_len, |
633e2713 DS |
1141 | const u8 *ie0, size_t ie0_len, const u8 *ie1, |
1142 | size_t ie1_len, bool sched_scan) | |
f5fc0f86 | 1143 | { |
83587505 | 1144 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
818e3063 | 1145 | struct sk_buff *skb; |
abb0b3bf | 1146 | int ret; |
af7fbb28 | 1147 | u32 rate; |
78e28062 EP |
1148 | u16 template_id_2_4 = wl->scan_templ_id_2_4; |
1149 | u16 template_id_5 = wl->scan_templ_id_5; | |
f5fc0f86 | 1150 | |
0fe72086 VG |
1151 | wl1271_debug(DEBUG_SCAN, "build probe request band %d", band); |
1152 | ||
a344d677 | 1153 | skb = ieee80211_probereq_get(wl->hw, vif->addr, ssid, ssid_len, |
633e2713 | 1154 | ie0_len + ie1_len); |
818e3063 KV |
1155 | if (!skb) { |
1156 | ret = -ENOMEM; | |
1157 | goto out; | |
1158 | } | |
633e2713 | 1159 | if (ie0_len) |
59ae1d12 | 1160 | skb_put_data(skb, ie0, ie0_len); |
633e2713 | 1161 | if (ie1_len) |
59ae1d12 | 1162 | skb_put_data(skb, ie1, ie1_len); |
818e3063 | 1163 | |
78e28062 | 1164 | if (sched_scan && |
3df74f46 | 1165 | (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) { |
78e28062 EP |
1166 | template_id_2_4 = wl->sched_scan_templ_id_2_4; |
1167 | template_id_5 = wl->sched_scan_templ_id_5; | |
3df74f46 YD |
1168 | } |
1169 | ||
83587505 | 1170 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]); |
57fbcce3 | 1171 | if (band == NL80211_BAND_2GHZ) |
cdaac628 | 1172 | ret = wl1271_cmd_template_set(wl, role_id, |
3df74f46 | 1173 | template_id_2_4, |
af7fbb28 | 1174 | skb->data, skb->len, 0, rate); |
abb0b3bf | 1175 | else |
cdaac628 | 1176 | ret = wl1271_cmd_template_set(wl, role_id, |
3df74f46 | 1177 | template_id_5, |
af7fbb28 | 1178 | skb->data, skb->len, 0, rate); |
818e3063 KV |
1179 | |
1180 | out: | |
1181 | dev_kfree_skb(skb); | |
abb0b3bf | 1182 | return ret; |
f5fc0f86 | 1183 | } |
78e28062 | 1184 | EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req); |
f5fc0f86 | 1185 | |
2f6724b2 | 1186 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, |
83587505 | 1187 | struct wl12xx_vif *wlvif, |
2f6724b2 JO |
1188 | struct sk_buff *skb) |
1189 | { | |
83587505 | 1190 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
2f6724b2 | 1191 | int ret; |
af7fbb28 | 1192 | u32 rate; |
2f6724b2 JO |
1193 | |
1194 | if (!skb) | |
83587505 | 1195 | skb = ieee80211_ap_probereq_get(wl->hw, vif); |
2f6724b2 JO |
1196 | if (!skb) |
1197 | goto out; | |
1198 | ||
0fe72086 | 1199 | wl1271_debug(DEBUG_SCAN, "set ap probe request template"); |
2f6724b2 | 1200 | |
1b92f15e | 1201 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]); |
57fbcce3 | 1202 | if (wlvif->band == NL80211_BAND_2GHZ) |
cdaac628 EP |
1203 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
1204 | CMD_TEMPL_CFG_PROBE_REQ_2_4, | |
af7fbb28 | 1205 | skb->data, skb->len, 0, rate); |
2f6724b2 | 1206 | else |
cdaac628 EP |
1207 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
1208 | CMD_TEMPL_CFG_PROBE_REQ_5, | |
af7fbb28 | 1209 | skb->data, skb->len, 0, rate); |
2f6724b2 JO |
1210 | |
1211 | if (ret < 0) | |
1212 | wl1271_error("Unable to set ap probe request template."); | |
1213 | ||
1214 | out: | |
1215 | return skb; | |
1216 | } | |
1217 | ||
5ec8a448 | 1218 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
c5312772 | 1219 | { |
2c0133a4 | 1220 | int ret, extra = 0; |
5ec8a448 | 1221 | u16 fc; |
6e8cd331 | 1222 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
5ec8a448 EP |
1223 | struct sk_buff *skb; |
1224 | struct wl12xx_arp_rsp_template *tmpl; | |
c5312772 EP |
1225 | struct ieee80211_hdr_3addr *hdr; |
1226 | struct arphdr *arp_hdr; | |
1227 | ||
5ec8a448 EP |
1228 | skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) + |
1229 | WL1271_EXTRA_SPACE_MAX); | |
1230 | if (!skb) { | |
1231 | wl1271_error("failed to allocate buffer for arp rsp template"); | |
1232 | return -ENOMEM; | |
1233 | } | |
c5312772 | 1234 | |
5ec8a448 EP |
1235 | skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX); |
1236 | ||
b080db58 | 1237 | tmpl = skb_put_zero(skb, sizeof(*tmpl)); |
c5312772 EP |
1238 | |
1239 | /* llc layer */ | |
5ec8a448 EP |
1240 | memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header)); |
1241 | tmpl->llc_type = cpu_to_be16(ETH_P_ARP); | |
c5312772 EP |
1242 | |
1243 | /* arp header */ | |
5ec8a448 | 1244 | arp_hdr = &tmpl->arp_hdr; |
6177eaea EP |
1245 | arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); |
1246 | arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); | |
c5312772 EP |
1247 | arp_hdr->ar_hln = ETH_ALEN; |
1248 | arp_hdr->ar_pln = 4; | |
6177eaea | 1249 | arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); |
c5312772 EP |
1250 | |
1251 | /* arp payload */ | |
5ec8a448 EP |
1252 | memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN); |
1253 | tmpl->sender_ip = wlvif->ip_addr; | |
1254 | ||
1255 | /* encryption space */ | |
1256 | switch (wlvif->encryption_type) { | |
1257 | case KEY_TKIP: | |
2c0133a4 AN |
1258 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) |
1259 | extra = WL1271_EXTRA_SPACE_TKIP; | |
5ec8a448 EP |
1260 | break; |
1261 | case KEY_AES: | |
1262 | extra = WL1271_EXTRA_SPACE_AES; | |
1263 | break; | |
1264 | case KEY_NONE: | |
1265 | case KEY_WEP: | |
1266 | case KEY_GEM: | |
1267 | extra = 0; | |
1268 | break; | |
1269 | default: | |
1270 | wl1271_warning("Unknown encryption type: %d", | |
1271 | wlvif->encryption_type); | |
1272 | ret = -EINVAL; | |
1273 | goto out; | |
1274 | } | |
1275 | ||
1276 | if (extra) { | |
1277 | u8 *space = skb_push(skb, extra); | |
1278 | memset(space, 0, extra); | |
1279 | } | |
1280 | ||
1281 | /* QoS header - BE */ | |
1282 | if (wlvif->sta.qos) | |
1283 | memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16)); | |
1284 | ||
1285 | /* mac80211 header */ | |
d58ff351 | 1286 | hdr = skb_push(skb, sizeof(*hdr)); |
161f17b5 | 1287 | memset(hdr, 0, sizeof(*hdr)); |
5ec8a448 EP |
1288 | fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS; |
1289 | if (wlvif->sta.qos) | |
1290 | fc |= IEEE80211_STYPE_QOS_DATA; | |
1291 | else | |
1292 | fc |= IEEE80211_STYPE_DATA; | |
1293 | if (wlvif->encryption_type != KEY_NONE) | |
1294 | fc |= IEEE80211_FCTL_PROTECTED; | |
1295 | ||
1296 | hdr->frame_control = cpu_to_le16(fc); | |
1297 | memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN); | |
1298 | memcpy(hdr->addr2, vif->addr, ETH_ALEN); | |
93803b33 | 1299 | eth_broadcast_addr(hdr->addr3); |
c5312772 | 1300 | |
cdaac628 | 1301 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP, |
5ec8a448 | 1302 | skb->data, skb->len, 0, |
d2d66c56 | 1303 | wlvif->basic_rate); |
5ec8a448 EP |
1304 | out: |
1305 | dev_kfree_skb(skb); | |
c5312772 EP |
1306 | return ret; |
1307 | } | |
1308 | ||
784f694d | 1309 | int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif) |
023e0826 | 1310 | { |
d2d66c56 | 1311 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
023e0826 KV |
1312 | struct ieee80211_qos_hdr template; |
1313 | ||
1314 | memset(&template, 0, sizeof(template)); | |
1315 | ||
cdf09495 | 1316 | memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN); |
784f694d | 1317 | memcpy(template.addr2, vif->addr, ETH_ALEN); |
cdf09495 | 1318 | memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN); |
023e0826 KV |
1319 | |
1320 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | | |
1321 | IEEE80211_STYPE_QOS_NULLFUNC | | |
1322 | IEEE80211_FCTL_TODS); | |
1323 | ||
1324 | /* FIXME: not sure what priority to use here */ | |
1325 | template.qos_ctrl = cpu_to_le16(0); | |
1326 | ||
cdaac628 EP |
1327 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
1328 | CMD_TEMPL_QOS_NULL_DATA, &template, | |
606c1487 | 1329 | sizeof(template), 0, |
d2d66c56 | 1330 | wlvif->basic_rate); |
023e0826 KV |
1331 | } |
1332 | ||
c690ec81 | 1333 | int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) |
f5fc0f86 | 1334 | { |
c690ec81 | 1335 | struct wl1271_cmd_set_keys *cmd; |
f5fc0f86 LC |
1336 | int ret = 0; |
1337 | ||
1338 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); | |
1339 | ||
1340 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1341 | if (!cmd) { | |
1342 | ret = -ENOMEM; | |
1343 | goto out; | |
1344 | } | |
1345 | ||
c690ec81 | 1346 | cmd->hlid = hlid; |
98bdaabb AN |
1347 | cmd->key_id = id; |
1348 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; | |
1349 | cmd->key_action = cpu_to_le16(KEY_SET_ID); | |
1350 | cmd->key_type = KEY_WEP; | |
1351 | ||
1352 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | |
1353 | if (ret < 0) { | |
c690ec81 | 1354 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
98bdaabb AN |
1355 | goto out; |
1356 | } | |
1357 | ||
1358 | out: | |
1359 | kfree(cmd); | |
1360 | ||
1361 | return ret; | |
1362 | } | |
1363 | ||
a8ab39a4 | 1364 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
154da67c | 1365 | u16 action, u8 id, u8 key_type, |
ac4e4ce5 JO |
1366 | u8 key_size, const u8 *key, const u8 *addr, |
1367 | u32 tx_seq_32, u16 tx_seq_16) | |
f5fc0f86 | 1368 | { |
c690ec81 | 1369 | struct wl1271_cmd_set_keys *cmd; |
f5fc0f86 LC |
1370 | int ret = 0; |
1371 | ||
b42f068b | 1372 | /* hlid might have already been deleted */ |
154da67c | 1373 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
b42f068b EP |
1374 | return 0; |
1375 | ||
f5fc0f86 LC |
1376 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
1377 | if (!cmd) { | |
1378 | ret = -ENOMEM; | |
1379 | goto out; | |
1380 | } | |
1381 | ||
154da67c | 1382 | cmd->hlid = wlvif->sta.hlid; |
c690ec81 EP |
1383 | |
1384 | if (key_type == KEY_WEP) | |
1385 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; | |
1386 | else if (is_broadcast_ether_addr(addr)) | |
1387 | cmd->lid_key_type = BROADCAST_LID_TYPE; | |
1388 | else | |
1389 | cmd->lid_key_type = UNICAST_LID_TYPE; | |
f5fc0f86 | 1390 | |
d0f63b20 | 1391 | cmd->key_action = cpu_to_le16(action); |
f5fc0f86 LC |
1392 | cmd->key_size = key_size; |
1393 | cmd->key_type = key_type; | |
1394 | ||
d0f63b20 LC |
1395 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
1396 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); | |
ac4e4ce5 | 1397 | |
c690ec81 | 1398 | cmd->key_id = id; |
f5fc0f86 | 1399 | |
f5fc0f86 LC |
1400 | if (key_type == KEY_TKIP) { |
1401 | /* | |
1402 | * We get the key in the following form: | |
1403 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) | |
1404 | * but the target is expecting: | |
1405 | * TKIP - RX MIC - TX MIC | |
1406 | */ | |
1407 | memcpy(cmd->key, key, 16); | |
1408 | memcpy(cmd->key + 16, key + 24, 8); | |
1409 | memcpy(cmd->key + 24, key + 16, 8); | |
1410 | ||
1411 | } else { | |
1412 | memcpy(cmd->key, key, key_size); | |
1413 | } | |
1414 | ||
1415 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); | |
1416 | ||
fa867e73 | 1417 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
f5fc0f86 LC |
1418 | if (ret < 0) { |
1419 | wl1271_warning("could not set keys"); | |
152ee6e0 | 1420 | goto out; |
f5fc0f86 LC |
1421 | } |
1422 | ||
1423 | out: | |
1424 | kfree(cmd); | |
1425 | ||
1426 | return ret; | |
1427 | } | |
25a7dc6d | 1428 | |
c690ec81 EP |
1429 | /* |
1430 | * TODO: merge with sta/ibss into 1 set_key function. | |
1431 | * note there are slight diffs | |
1432 | */ | |
a8ab39a4 EP |
1433 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1434 | u16 action, u8 id, u8 key_type, | |
1435 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, | |
1436 | u16 tx_seq_16) | |
98bdaabb | 1437 | { |
c690ec81 | 1438 | struct wl1271_cmd_set_keys *cmd; |
98bdaabb AN |
1439 | int ret = 0; |
1440 | u8 lid_type; | |
1441 | ||
1442 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1443 | if (!cmd) | |
1444 | return -ENOMEM; | |
1445 | ||
a8ab39a4 | 1446 | if (hlid == wlvif->ap.bcast_hlid) { |
98bdaabb AN |
1447 | if (key_type == KEY_WEP) |
1448 | lid_type = WEP_DEFAULT_LID_TYPE; | |
1449 | else | |
1450 | lid_type = BROADCAST_LID_TYPE; | |
1451 | } else { | |
1452 | lid_type = UNICAST_LID_TYPE; | |
1453 | } | |
1454 | ||
1455 | wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" | |
1456 | " hlid: %d", (int)action, (int)id, (int)lid_type, | |
1457 | (int)key_type, (int)hlid); | |
1458 | ||
1459 | cmd->lid_key_type = lid_type; | |
1460 | cmd->hlid = hlid; | |
1461 | cmd->key_action = cpu_to_le16(action); | |
1462 | cmd->key_size = key_size; | |
1463 | cmd->key_type = key_type; | |
1464 | cmd->key_id = id; | |
1465 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); | |
1466 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); | |
1467 | ||
1468 | if (key_type == KEY_TKIP) { | |
1469 | /* | |
1470 | * We get the key in the following form: | |
1471 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) | |
1472 | * but the target is expecting: | |
1473 | * TKIP - RX MIC - TX MIC | |
1474 | */ | |
1475 | memcpy(cmd->key, key, 16); | |
1476 | memcpy(cmd->key + 16, key + 24, 8); | |
1477 | memcpy(cmd->key + 24, key + 16, 8); | |
1478 | } else { | |
1479 | memcpy(cmd->key, key, key_size); | |
1480 | } | |
1481 | ||
1482 | wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); | |
1483 | ||
1484 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); | |
1485 | if (ret < 0) { | |
1486 | wl1271_warning("could not set ap keys"); | |
1487 | goto out; | |
1488 | } | |
1489 | ||
1490 | out: | |
1491 | kfree(cmd); | |
1492 | return ret; | |
1493 | } | |
1494 | ||
d50529c0 EP |
1495 | int wl12xx_cmd_set_peer_state(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1496 | u8 hlid) | |
be86cbea | 1497 | { |
c690ec81 | 1498 | struct wl12xx_cmd_set_peer_state *cmd; |
be86cbea JO |
1499 | int ret = 0; |
1500 | ||
b67476ef | 1501 | wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid); |
be86cbea JO |
1502 | |
1503 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1504 | if (!cmd) { | |
1505 | ret = -ENOMEM; | |
1506 | goto out; | |
1507 | } | |
1508 | ||
b67476ef | 1509 | cmd->hlid = hlid; |
be86cbea JO |
1510 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; |
1511 | ||
d50529c0 EP |
1512 | /* wmm param is valid only for station role */ |
1513 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) | |
1514 | cmd->wmm = wlvif->wmm_enabled; | |
1515 | ||
c690ec81 | 1516 | ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0); |
be86cbea | 1517 | if (ret < 0) { |
c690ec81 | 1518 | wl1271_error("failed to send set peer state command"); |
be86cbea JO |
1519 | goto out_free; |
1520 | } | |
1521 | ||
1522 | out_free: | |
1523 | kfree(cmd); | |
1524 | ||
1525 | out: | |
1526 | return ret; | |
1527 | } | |
99d5ad7b | 1528 | |
1b92f15e EP |
1529 | int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1530 | struct ieee80211_sta *sta, u8 hlid) | |
98bdaabb | 1531 | { |
c690ec81 | 1532 | struct wl12xx_cmd_add_peer *cmd; |
1ec23f7f | 1533 | int i, ret; |
99d5ad7b | 1534 | u32 sta_rates; |
98bdaabb | 1535 | |
c690ec81 | 1536 | wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid); |
98bdaabb AN |
1537 | |
1538 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1539 | if (!cmd) { | |
1540 | ret = -ENOMEM; | |
1541 | goto out; | |
1542 | } | |
1543 | ||
98bdaabb AN |
1544 | memcpy(cmd->addr, sta->addr, ETH_ALEN); |
1545 | cmd->bss_index = WL1271_AP_BSS_INDEX; | |
1546 | cmd->aid = sta->aid; | |
1547 | cmd->hlid = hlid; | |
1ec23f7f | 1548 | cmd->sp_len = sta->max_sp; |
b4d38db1 | 1549 | cmd->wmm = sta->wme ? 1 : 0; |
978cd3a0 | 1550 | cmd->session_id = wl->session_ids[hlid]; |
028e7243 | 1551 | cmd->role_id = wlvif->role_id; |
98bdaabb | 1552 | |
1ec23f7f EP |
1553 | for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++) |
1554 | if (sta->wme && (sta->uapsd_queues & BIT(i))) | |
2e42c203 YD |
1555 | cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = |
1556 | WL1271_PSD_UPSD_TRIGGER; | |
1ec23f7f | 1557 | else |
2e42c203 YD |
1558 | cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = |
1559 | WL1271_PSD_LEGACY; | |
1560 | ||
1ec23f7f | 1561 | |
1b92f15e | 1562 | sta_rates = sta->supp_rates[wlvif->band]; |
99d5ad7b | 1563 | if (sta->ht_cap.ht_supported) |
b3a47ee0 AN |
1564 | sta_rates |= |
1565 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) | | |
1566 | (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET); | |
99d5ad7b AN |
1567 | |
1568 | cmd->supported_rates = | |
af7fbb28 | 1569 | cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, |
1b92f15e | 1570 | wlvif->band)); |
98bdaabb | 1571 | |
535633a5 GM |
1572 | if (!cmd->supported_rates) { |
1573 | wl1271_debug(DEBUG_CMD, | |
1574 | "peer has no supported rates yet, configuring basic rates: 0x%x", | |
1575 | wlvif->basic_rate_set); | |
1576 | cmd->supported_rates = cpu_to_le32(wlvif->basic_rate_set); | |
1577 | } | |
1578 | ||
1ec23f7f EP |
1579 | wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", |
1580 | cmd->supported_rates, sta->uapsd_queues); | |
98bdaabb | 1581 | |
c690ec81 | 1582 | ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0); |
98bdaabb | 1583 | if (ret < 0) { |
c690ec81 | 1584 | wl1271_error("failed to initiate cmd add peer"); |
98bdaabb AN |
1585 | goto out_free; |
1586 | } | |
1587 | ||
1588 | out_free: | |
1589 | kfree(cmd); | |
1590 | ||
1591 | out: | |
1592 | return ret; | |
1593 | } | |
1594 | ||
028e7243 EP |
1595 | int wl12xx_cmd_remove_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
1596 | u8 hlid) | |
98bdaabb | 1597 | { |
c690ec81 | 1598 | struct wl12xx_cmd_remove_peer *cmd; |
98bdaabb | 1599 | int ret; |
6c15c1aa | 1600 | bool timeout = false; |
98bdaabb | 1601 | |
c690ec81 | 1602 | wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid); |
98bdaabb AN |
1603 | |
1604 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1605 | if (!cmd) { | |
1606 | ret = -ENOMEM; | |
1607 | goto out; | |
1608 | } | |
1609 | ||
1610 | cmd->hlid = hlid; | |
1611 | /* We never send a deauth, mac80211 is in charge of this */ | |
1612 | cmd->reason_opcode = 0; | |
1613 | cmd->send_deauth_flag = 0; | |
028e7243 | 1614 | cmd->role_id = wlvif->role_id; |
98bdaabb | 1615 | |
c690ec81 | 1616 | ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0); |
98bdaabb | 1617 | if (ret < 0) { |
c690ec81 | 1618 | wl1271_error("failed to initiate cmd remove peer"); |
98bdaabb AN |
1619 | goto out_free; |
1620 | } | |
1621 | ||
c50a2825 EP |
1622 | ret = wl->ops->wait_for_event(wl, |
1623 | WLCORE_EVENT_PEER_REMOVE_COMPLETE, | |
1624 | &timeout); | |
1625 | ||
05285cf9 AN |
1626 | /* |
1627 | * We are ok with a timeout here. The event is sometimes not sent | |
6c15c1aa ES |
1628 | * due to a firmware bug. In case of another error (like SDIO timeout) |
1629 | * queue a recovery. | |
05285cf9 | 1630 | */ |
6c15c1aa ES |
1631 | if (ret) |
1632 | wl12xx_queue_recovery_work(wl); | |
98bdaabb AN |
1633 | |
1634 | out_free: | |
1635 | kfree(cmd); | |
1636 | ||
1637 | out: | |
1638 | return ret; | |
1639 | } | |
95dac04f | 1640 | |
57fbcce3 | 1641 | static int wlcore_get_reg_conf_ch_idx(enum nl80211_band band, u16 ch) |
6b70e7eb | 1642 | { |
49540d1b EP |
1643 | /* |
1644 | * map the given band/channel to the respective predefined | |
1645 | * bit expected by the fw | |
1646 | */ | |
6b70e7eb | 1647 | switch (band) { |
57fbcce3 | 1648 | case NL80211_BAND_2GHZ: |
49540d1b | 1649 | /* channels 1..14 are mapped to 0..13 */ |
6b70e7eb | 1650 | if (ch >= 1 && ch <= 14) |
49540d1b EP |
1651 | return ch - 1; |
1652 | break; | |
57fbcce3 | 1653 | case NL80211_BAND_5GHZ: |
49540d1b EP |
1654 | switch (ch) { |
1655 | case 8 ... 16: | |
1656 | /* channels 8,12,16 are mapped to 18,19,20 */ | |
1657 | return 18 + (ch-8)/4; | |
1658 | case 34 ... 48: | |
1659 | /* channels 34,36..48 are mapped to 21..28 */ | |
1660 | return 21 + (ch-34)/2; | |
1661 | case 52 ... 64: | |
1662 | /* channels 52,56..64 are mapped to 29..32 */ | |
1663 | return 29 + (ch-52)/4; | |
1664 | case 100 ... 140: | |
1665 | /* channels 100,104..140 are mapped to 33..43 */ | |
1666 | return 33 + (ch-100)/4; | |
1667 | case 149 ... 165: | |
1668 | /* channels 149,153..165 are mapped to 44..48 */ | |
1669 | return 44 + (ch-149)/4; | |
1670 | default: | |
1671 | break; | |
1672 | } | |
6b70e7eb VG |
1673 | break; |
1674 | default: | |
49540d1b | 1675 | break; |
6b70e7eb VG |
1676 | } |
1677 | ||
49540d1b EP |
1678 | wl1271_error("%s: unknown band/channel: %d/%d", __func__, band, ch); |
1679 | return -1; | |
6b70e7eb VG |
1680 | } |
1681 | ||
1682 | void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, | |
57fbcce3 | 1683 | enum nl80211_band band) |
6b70e7eb VG |
1684 | { |
1685 | int ch_bit_idx = 0; | |
1686 | ||
1687 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) | |
1688 | return; | |
1689 | ||
1690 | ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel); | |
1691 | ||
49540d1b | 1692 | if (ch_bit_idx >= 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) |
6b70e7eb VG |
1693 | set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending); |
1694 | } | |
1695 | ||
1696 | int wlcore_cmd_regdomain_config_locked(struct wl1271 *wl) | |
1697 | { | |
1698 | struct wl12xx_cmd_regdomain_dfs_config *cmd = NULL; | |
1699 | int ret = 0, i, b, ch_bit_idx; | |
6b70e7eb | 1700 | u32 tmp_ch_bitmap[2]; |
6b70e7eb VG |
1701 | struct wiphy *wiphy = wl->hw->wiphy; |
1702 | struct ieee80211_supported_band *band; | |
1703 | bool timeout = false; | |
1704 | ||
1705 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) | |
1706 | return 0; | |
1707 | ||
1708 | wl1271_debug(DEBUG_CMD, "cmd reg domain config"); | |
1709 | ||
1710 | memset(tmp_ch_bitmap, 0, sizeof(tmp_ch_bitmap)); | |
1711 | ||
57fbcce3 | 1712 | for (b = NL80211_BAND_2GHZ; b <= NL80211_BAND_5GHZ; b++) { |
6b70e7eb VG |
1713 | band = wiphy->bands[b]; |
1714 | for (i = 0; i < band->n_channels; i++) { | |
4ce9fad3 EP |
1715 | struct ieee80211_channel *channel = &band->channels[i]; |
1716 | u16 ch = channel->hw_value; | |
1717 | u32 flags = channel->flags; | |
6b70e7eb | 1718 | |
4ce9fad3 EP |
1719 | if (flags & (IEEE80211_CHAN_DISABLED | |
1720 | IEEE80211_CHAN_NO_IR)) | |
1721 | continue; | |
1722 | ||
1723 | if ((flags & IEEE80211_CHAN_RADAR) && | |
1724 | channel->dfs_state != NL80211_DFS_AVAILABLE) | |
6b70e7eb VG |
1725 | continue; |
1726 | ||
1727 | ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch); | |
1728 | if (ch_bit_idx < 0) | |
1729 | continue; | |
1730 | ||
1731 | set_bit(ch_bit_idx, (long *)tmp_ch_bitmap); | |
1732 | } | |
1733 | } | |
1734 | ||
1735 | tmp_ch_bitmap[0] |= wl->reg_ch_conf_pending[0]; | |
1736 | tmp_ch_bitmap[1] |= wl->reg_ch_conf_pending[1]; | |
1737 | ||
1738 | if (!memcmp(tmp_ch_bitmap, wl->reg_ch_conf_last, sizeof(tmp_ch_bitmap))) | |
1739 | goto out; | |
1740 | ||
1741 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1742 | if (!cmd) { | |
1743 | ret = -ENOMEM; | |
1744 | goto out; | |
1745 | } | |
1746 | ||
1747 | cmd->ch_bit_map1 = cpu_to_le32(tmp_ch_bitmap[0]); | |
1748 | cmd->ch_bit_map2 = cpu_to_le32(tmp_ch_bitmap[1]); | |
1cd91b2c | 1749 | cmd->dfs_region = wl->dfs_region; |
6b70e7eb VG |
1750 | |
1751 | wl1271_debug(DEBUG_CMD, | |
1752 | "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x", | |
1753 | cmd->ch_bit_map1, cmd->ch_bit_map2); | |
1754 | ||
1755 | ret = wl1271_cmd_send(wl, CMD_DFS_CHANNEL_CONFIG, cmd, sizeof(*cmd), 0); | |
1756 | if (ret < 0) { | |
1757 | wl1271_error("failed to send reg domain dfs config"); | |
1758 | goto out; | |
1759 | } | |
1760 | ||
1761 | ret = wl->ops->wait_for_event(wl, | |
1762 | WLCORE_EVENT_DFS_CONFIG_COMPLETE, | |
1763 | &timeout); | |
1764 | if (ret < 0 || timeout) { | |
1765 | wl1271_error("reg domain conf %serror", | |
1766 | timeout ? "completion " : ""); | |
1767 | ret = timeout ? -ETIMEDOUT : ret; | |
1768 | goto out; | |
1769 | } | |
1770 | ||
1771 | memcpy(wl->reg_ch_conf_last, tmp_ch_bitmap, sizeof(tmp_ch_bitmap)); | |
1772 | memset(wl->reg_ch_conf_pending, 0, sizeof(wl->reg_ch_conf_pending)); | |
1773 | ||
1774 | out: | |
1775 | kfree(cmd); | |
1776 | return ret; | |
1777 | } | |
1778 | ||
95dac04f IY |
1779 | int wl12xx_cmd_config_fwlog(struct wl1271 *wl) |
1780 | { | |
1781 | struct wl12xx_cmd_config_fwlog *cmd; | |
1782 | int ret = 0; | |
1783 | ||
1784 | wl1271_debug(DEBUG_CMD, "cmd config firmware logger"); | |
1785 | ||
1786 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1787 | if (!cmd) { | |
1788 | ret = -ENOMEM; | |
1789 | goto out; | |
1790 | } | |
1791 | ||
1792 | cmd->logger_mode = wl->conf.fwlog.mode; | |
1793 | cmd->log_severity = wl->conf.fwlog.severity; | |
1794 | cmd->timestamp = wl->conf.fwlog.timestamp; | |
1795 | cmd->output = wl->conf.fwlog.output; | |
1796 | cmd->threshold = wl->conf.fwlog.threshold; | |
1797 | ||
1798 | ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0); | |
1799 | if (ret < 0) { | |
1800 | wl1271_error("failed to send config firmware logger command"); | |
1801 | goto out_free; | |
1802 | } | |
1803 | ||
1804 | out_free: | |
1805 | kfree(cmd); | |
1806 | ||
1807 | out: | |
1808 | return ret; | |
1809 | } | |
1810 | ||
1811 | int wl12xx_cmd_start_fwlog(struct wl1271 *wl) | |
1812 | { | |
1813 | struct wl12xx_cmd_start_fwlog *cmd; | |
1814 | int ret = 0; | |
1815 | ||
1816 | wl1271_debug(DEBUG_CMD, "cmd start firmware logger"); | |
1817 | ||
1818 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1819 | if (!cmd) { | |
1820 | ret = -ENOMEM; | |
1821 | goto out; | |
1822 | } | |
1823 | ||
1824 | ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0); | |
1825 | if (ret < 0) { | |
1826 | wl1271_error("failed to send start firmware logger command"); | |
1827 | goto out_free; | |
1828 | } | |
1829 | ||
1830 | out_free: | |
1831 | kfree(cmd); | |
1832 | ||
1833 | out: | |
1834 | return ret; | |
1835 | } | |
1836 | ||
1837 | int wl12xx_cmd_stop_fwlog(struct wl1271 *wl) | |
1838 | { | |
1839 | struct wl12xx_cmd_stop_fwlog *cmd; | |
1840 | int ret = 0; | |
1841 | ||
1842 | wl1271_debug(DEBUG_CMD, "cmd stop firmware logger"); | |
1843 | ||
1844 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1845 | if (!cmd) { | |
1846 | ret = -ENOMEM; | |
1847 | goto out; | |
1848 | } | |
1849 | ||
1850 | ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0); | |
1851 | if (ret < 0) { | |
1852 | wl1271_error("failed to send stop firmware logger command"); | |
1853 | goto out_free; | |
1854 | } | |
1855 | ||
1856 | out_free: | |
1857 | kfree(cmd); | |
1858 | ||
1859 | out: | |
1860 | return ret; | |
1861 | } | |
a7cba384 | 1862 | |
1b92f15e | 1863 | static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
57fbcce3 | 1864 | u8 role_id, enum nl80211_band band, u8 channel) |
a7cba384 EP |
1865 | { |
1866 | struct wl12xx_cmd_roc *cmd; | |
1867 | int ret = 0; | |
1868 | ||
dabf37db | 1869 | wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", channel, role_id); |
a7cba384 EP |
1870 | |
1871 | if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) | |
1872 | return -EINVAL; | |
1873 | ||
1874 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1875 | if (!cmd) { | |
1876 | ret = -ENOMEM; | |
1877 | goto out; | |
1878 | } | |
1879 | ||
1880 | cmd->role_id = role_id; | |
dabf37db EP |
1881 | cmd->channel = channel; |
1882 | switch (band) { | |
57fbcce3 | 1883 | case NL80211_BAND_2GHZ: |
00782136 | 1884 | cmd->band = WLCORE_BAND_2_4GHZ; |
a7cba384 | 1885 | break; |
57fbcce3 | 1886 | case NL80211_BAND_5GHZ: |
00782136 | 1887 | cmd->band = WLCORE_BAND_5GHZ; |
a7cba384 EP |
1888 | break; |
1889 | default: | |
1b92f15e | 1890 | wl1271_error("roc - unknown band: %d", (int)wlvif->band); |
a7cba384 EP |
1891 | ret = -EINVAL; |
1892 | goto out_free; | |
1893 | } | |
1894 | ||
1895 | ||
1896 | ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0); | |
1897 | if (ret < 0) { | |
1898 | wl1271_error("failed to send ROC command"); | |
1899 | goto out_free; | |
1900 | } | |
1901 | ||
1902 | out_free: | |
1903 | kfree(cmd); | |
1904 | ||
1905 | out: | |
1906 | return ret; | |
1907 | } | |
1908 | ||
1909 | static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id) | |
1910 | { | |
1911 | struct wl12xx_cmd_croc *cmd; | |
1912 | int ret = 0; | |
1913 | ||
1914 | wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id); | |
1915 | ||
1916 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1917 | if (!cmd) { | |
1918 | ret = -ENOMEM; | |
1919 | goto out; | |
1920 | } | |
1921 | cmd->role_id = role_id; | |
1922 | ||
1923 | ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd, | |
1924 | sizeof(*cmd), 0); | |
1925 | if (ret < 0) { | |
1926 | wl1271_error("failed to send ROC command"); | |
1927 | goto out_free; | |
1928 | } | |
1929 | ||
1930 | out_free: | |
1931 | kfree(cmd); | |
1932 | ||
1933 | out: | |
1934 | return ret; | |
1935 | } | |
251c177f | 1936 | |
dabf37db | 1937 | int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id, |
57fbcce3 | 1938 | enum nl80211_band band, u8 channel) |
251c177f EP |
1939 | { |
1940 | int ret = 0; | |
1941 | ||
1942 | if (WARN_ON(test_bit(role_id, wl->roc_map))) | |
1943 | return 0; | |
1944 | ||
dabf37db | 1945 | ret = wl12xx_cmd_roc(wl, wlvif, role_id, band, channel); |
251c177f EP |
1946 | if (ret < 0) |
1947 | goto out; | |
1948 | ||
251c177f EP |
1949 | __set_bit(role_id, wl->roc_map); |
1950 | out: | |
1951 | return ret; | |
1952 | } | |
1953 | ||
1954 | int wl12xx_croc(struct wl1271 *wl, u8 role_id) | |
1955 | { | |
1956 | int ret = 0; | |
1957 | ||
1958 | if (WARN_ON(!test_bit(role_id, wl->roc_map))) | |
1959 | return 0; | |
1960 | ||
1961 | ret = wl12xx_cmd_croc(wl, role_id); | |
1962 | if (ret < 0) | |
1963 | goto out; | |
1964 | ||
1965 | __clear_bit(role_id, wl->roc_map); | |
55df5afb AN |
1966 | |
1967 | /* | |
1968 | * Rearm the tx watchdog when removing the last ROC. This prevents | |
1969 | * recoveries due to just finished ROCs - when Tx hasn't yet had | |
1970 | * a chance to get out. | |
1971 | */ | |
1972 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) | |
1973 | wl12xx_rearm_tx_watchdog_locked(wl); | |
251c177f EP |
1974 | out: |
1975 | return ret; | |
1976 | } | |
6d158ff3 | 1977 | |
fcab1890 | 1978 | int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
6d158ff3 SL |
1979 | { |
1980 | struct wl12xx_cmd_stop_channel_switch *cmd; | |
1981 | int ret; | |
1982 | ||
1983 | wl1271_debug(DEBUG_ACX, "cmd stop channel switch"); | |
1984 | ||
1985 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
1986 | if (!cmd) { | |
1987 | ret = -ENOMEM; | |
1988 | goto out; | |
1989 | } | |
1990 | ||
fcab1890 EP |
1991 | cmd->role_id = wlvif->role_id; |
1992 | ||
6d158ff3 SL |
1993 | ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0); |
1994 | if (ret < 0) { | |
1995 | wl1271_error("failed to stop channel switch command"); | |
1996 | goto out_free; | |
1997 | } | |
1998 | ||
1999 | out_free: | |
2000 | kfree(cmd); | |
2001 | ||
2002 | out: | |
2003 | return ret; | |
2004 | } | |
679a6734 EP |
2005 | |
2006 | /* start dev role and roc on its channel */ | |
dabf37db | 2007 | int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
57fbcce3 | 2008 | enum nl80211_band band, int channel) |
679a6734 EP |
2009 | { |
2010 | int ret; | |
2011 | ||
2012 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || | |
2013 | wlvif->bss_type == BSS_TYPE_IBSS))) | |
2014 | return -EINVAL; | |
2015 | ||
7845af35 EP |
2016 | /* the dev role is already started for p2p mgmt interfaces */ |
2017 | if (!wlcore_is_p2p_mgmt(wlvif)) { | |
2018 | ret = wl12xx_cmd_role_enable(wl, | |
2019 | wl12xx_wlvif_to_vif(wlvif)->addr, | |
2020 | WL1271_ROLE_DEVICE, | |
2021 | &wlvif->dev_role_id); | |
2022 | if (ret < 0) | |
2023 | goto out; | |
2024 | } | |
679a6734 | 2025 | |
dabf37db | 2026 | ret = wl12xx_cmd_role_start_dev(wl, wlvif, band, channel); |
889300fa EP |
2027 | if (ret < 0) |
2028 | goto out_disable; | |
2029 | ||
dabf37db | 2030 | ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id, band, channel); |
679a6734 EP |
2031 | if (ret < 0) |
2032 | goto out_stop; | |
2033 | ||
2034 | return 0; | |
2035 | ||
2036 | out_stop: | |
2037 | wl12xx_cmd_role_stop_dev(wl, wlvif); | |
889300fa | 2038 | out_disable: |
7845af35 EP |
2039 | if (!wlcore_is_p2p_mgmt(wlvif)) |
2040 | wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); | |
679a6734 EP |
2041 | out: |
2042 | return ret; | |
2043 | } | |
2044 | ||
2045 | /* croc dev hlid, and stop the role */ | |
2046 | int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif) | |
2047 | { | |
2048 | int ret; | |
2049 | ||
2050 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || | |
2051 | wlvif->bss_type == BSS_TYPE_IBSS))) | |
2052 | return -EINVAL; | |
2053 | ||
8aefffea | 2054 | /* flush all pending packets */ |
eb96f841 IY |
2055 | ret = wlcore_tx_work_locked(wl); |
2056 | if (ret < 0) | |
2057 | goto out; | |
8aefffea | 2058 | |
679a6734 EP |
2059 | if (test_bit(wlvif->dev_role_id, wl->roc_map)) { |
2060 | ret = wl12xx_croc(wl, wlvif->dev_role_id); | |
2061 | if (ret < 0) | |
2062 | goto out; | |
2063 | } | |
2064 | ||
2065 | ret = wl12xx_cmd_role_stop_dev(wl, wlvif); | |
2066 | if (ret < 0) | |
2067 | goto out; | |
889300fa | 2068 | |
7845af35 EP |
2069 | if (!wlcore_is_p2p_mgmt(wlvif)) { |
2070 | ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); | |
2071 | if (ret < 0) | |
2072 | goto out; | |
2073 | } | |
889300fa | 2074 | |
679a6734 EP |
2075 | out: |
2076 | return ret; | |
2077 | } | |
c32e35f2 EP |
2078 | |
2079 | int wlcore_cmd_generic_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif, | |
2080 | u8 feature, u8 enable, u8 value) | |
2081 | { | |
2082 | struct wlcore_cmd_generic_cfg *cmd; | |
2083 | int ret; | |
2084 | ||
2085 | wl1271_debug(DEBUG_CMD, | |
2086 | "cmd generic cfg (role %d feature %d enable %d value %d)", | |
2087 | wlvif->role_id, feature, enable, value); | |
2088 | ||
2089 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | |
2090 | if (!cmd) | |
2091 | return -ENOMEM; | |
2092 | ||
2093 | cmd->role_id = wlvif->role_id; | |
2094 | cmd->feature = feature; | |
2095 | cmd->enable = enable; | |
2096 | cmd->value = value; | |
2097 | ||
2098 | ret = wl1271_cmd_send(wl, CMD_GENERIC_CFG, cmd, sizeof(*cmd), 0); | |
2099 | if (ret < 0) { | |
2100 | wl1271_error("failed to send generic cfg command"); | |
2101 | goto out_free; | |
2102 | } | |
2103 | out_free: | |
2104 | kfree(cmd); | |
2105 | return ret; | |
2106 | } | |
2107 | EXPORT_SYMBOL_GPL(wlcore_cmd_generic_cfg); |