blob: 96f83f09b8c5eee460a8c6f31c4fc84f7e80ee84 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
Luciano Coelho2f826f52010-03-26 12:53:21 +02004 * Copyright (C) 2009-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005 *
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>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030026#include <linux/spi/spi.h>
27#include <linux/etherdevice.h>
Kalle Valo023e0822010-03-18 12:26:36 +020028#include <linux/ieee80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030030
Luciano Coelhoc31be252011-11-21 19:25:24 +020031#include "wlcore.h"
Luciano Coelho0f4e3122011-10-07 11:02:42 +030032#include "debug.h"
Shahar Levi00d20102010-11-08 11:20:10 +000033#include "io.h"
34#include "acx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030035#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000036#include "cmd.h"
37#include "event.h"
Tony Lindgrenafeeecc2018-06-19 02:43:35 -070038#include "ps.h"
Arik Nemtsov98bdaab2010-10-16 18:08:58 +020039#include "tx.h"
Luciano Coelho60462b42012-05-10 12:14:14 +030040#include "hw_ops.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030041
Juuso Oikarinen16092b52010-04-28 09:49:59 +030042#define WL1271_CMD_FAST_POLL_COUNT 50
Yoni Divinskyc45ee4f2012-06-27 21:35:47 +030043#define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030044
45/*
46 * send command to firmware
47 *
48 * @wl: wl struct
49 * @id: command id
50 * @buf: buffer containing the command, must work with dma
51 * @len: length of the buffer
Eliad Pellerea508432012-11-27 08:44:45 +020052 * return the cmd status code on success.
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053 */
Eliad Pellerea508432012-11-27 08:44:45 +020054static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf,
55 size_t len, size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030056{
57 struct wl1271_cmd_header *cmd;
58 unsigned long timeout;
59 u32 intr;
Eliad Pellerea508432012-11-27 08:44:45 +020060 int ret;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020061 u16 status;
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020062 u16 poll_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030063
Arik Nemtsov1ede9502014-02-10 13:47:31 +020064 if (unlikely(wl->state == WLCORE_STATE_RESTARTING &&
65 id != CMD_STOP_FWLOGGER))
Ido Yariv4cc53382012-07-24 19:18:49 +030066 return -EIO;
67
Luciano Coelhof5b8f472014-11-10 09:25:17 +020068 if (WARN_ON_ONCE(len < sizeof(*cmd)))
69 return -EIO;
70
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030071 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030072 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030073 cmd->status = 0;
74
75 WARN_ON(len % 4 != 0);
Arik Nemtsov24225b32011-03-01 12:27:26 +020076 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030077
Ido Yariveb96f842012-06-18 13:21:55 +030078 ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false);
79 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +020080 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030081
Luciano Coelhof16ff752012-04-11 10:15:46 +030082 /*
83 * TODO: we just need this because one bit is in a different
84 * place. Is there any better way?
85 */
Ido Yariveb96f842012-06-18 13:21:55 +030086 ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len);
87 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +020088 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030089
90 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
91
Ido Yariv61343232012-06-18 15:50:21 +030092 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
93 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +020094 return ret;
Ido Yariv61343232012-06-18 15:50:21 +030095
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030096 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
97 if (time_after(jiffies, timeout)) {
98 wl1271_error("command complete timeout");
Eliad Pellerea508432012-11-27 08:44:45 +020099 return -ETIMEDOUT;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300100 }
101
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +0200102 poll_count++;
Juuso Oikarinen16092b52010-04-28 09:49:59 +0300103 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
104 udelay(10);
105 else
106 msleep(1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300107
Ido Yariv61343232012-06-18 15:50:21 +0300108 ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr);
109 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +0200110 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300111 }
112
Juuso Oikarinen3b775b42009-11-02 20:22:10 +0200113 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200114 if (res_len == 0)
115 res_len = sizeof(struct wl1271_cmd_header);
Ido Yariv045b9b52012-06-18 12:31:16 +0300116
117 ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false);
118 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +0200119 return ret;
Juuso Oikarinen3b775b42009-11-02 20:22:10 +0200120
Juuso Oikarinenad150e92009-11-02 20:22:12 +0200121 status = le16_to_cpu(cmd->status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +0200122
Ido Yarivb0f0ad32012-06-20 00:48:23 +0300123 ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK,
124 WL1271_ACX_INTR_CMD_COMPLETE);
125 if (ret < 0)
Eliad Pellerea508432012-11-27 08:44:45 +0200126 return ret;
127
128 return status;
129}
130
131/*
132 * send command to fw and return cmd status on success
133 * valid_rets contains a bitmap of allowed error codes
134 */
Luciano Coelhod351f5f2014-11-10 09:25:57 +0200135static int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf,
136 size_t len, size_t res_len,
137 unsigned long valid_rets)
Eliad Pellerea508432012-11-27 08:44:45 +0200138{
139 int ret = __wlcore_cmd_send(wl, id, buf, len, res_len);
140
141 if (ret < 0)
Ido Yarivb0f0ad32012-06-20 00:48:23 +0300142 goto fail;
143
Eliad Pellerea508432012-11-27 08:44:45 +0200144 /* success is always a valid status */
145 valid_rets |= BIT(CMD_STATUS_SUCCESS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300146
Eliad Pellerea508432012-11-27 08:44:45 +0200147 if (ret >= MAX_COMMAND_STATUS ||
148 !test_bit(ret, &valid_rets)) {
149 wl1271_error("command execute failure %d", ret);
150 ret = -EIO;
151 goto fail;
152 }
153 return ret;
Arik Nemtsovf482b762011-04-18 14:15:23 +0300154fail:
Ido Yarivbaacb9ae2011-06-06 14:57:05 +0300155 wl12xx_queue_recovery_work(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300156 return ret;
157}
158
Luciano Coelho99d84c12010-03-26 12:53:20 +0200159/*
Eliad Pellerea508432012-11-27 08:44:45 +0200160 * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS
161 * return 0 on success.
162 */
163int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
164 size_t res_len)
165{
166 int ret = wlcore_cmd_send_failsafe(wl, id, buf, len, res_len, 0);
167
168 if (ret < 0)
169 return ret;
170 return 0;
171}
Luciano Coelhod351f5f2014-11-10 09:25:57 +0200172EXPORT_SYMBOL_GPL(wl1271_cmd_send);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300173
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300174/*
175 * Poll the mailbox event field until any of the bits in the mask is set or a
176 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
177 */
Eliad Pellerc50a2822012-11-22 18:06:19 +0200178int wlcore_cmd_wait_for_event_or_timeout(struct wl1271 *wl,
179 u32 mask, bool *timeout)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300180{
Mircea Gherzan690142e2012-03-17 18:41:53 +0100181 u32 *events_vector;
182 u32 event;
Eyal Shapira6c15c1a2012-06-26 10:41:16 +0300183 unsigned long timeout_time;
Yoni Divinskyc45ee4f2012-06-27 21:35:47 +0300184 u16 poll_count = 0;
Mircea Gherzan690142e2012-03-17 18:41:53 +0100185 int ret = 0;
186
Eyal Shapira6c15c1a2012-06-26 10:41:16 +0300187 *timeout = false;
188
Dan Carpenter0230dfe2012-04-17 09:28:47 +0300189 events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA);
190 if (!events_vector)
191 return -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300192
Eyal Shapira6c15c1a2012-06-26 10:41:16 +0300193 timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300194
Tony Lindgrenafeeecc2018-06-19 02:43:35 -0700195 ret = wl1271_ps_elp_wakeup(wl);
196 if (ret < 0)
197 return ret;
198
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300199 do {
Eyal Shapira6c15c1a2012-06-26 10:41:16 +0300200 if (time_after(jiffies, timeout_time)) {
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200201 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
202 (int)mask);
Eyal Shapira6c15c1a2012-06-26 10:41:16 +0300203 *timeout = true;
Mircea Gherzan690142e2012-03-17 18:41:53 +0100204 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300205 }
206
Yoni Divinskyc45ee4f2012-06-27 21:35:47 +0300207 poll_count++;
208 if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT)
209 usleep_range(50, 51);
210 else
211 usleep_range(1000, 5000);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300212
213 /* read from both event fields */
Ido Yariv045b9b52012-06-18 12:31:16 +0300214 ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector,
215 sizeof(*events_vector), false);
216 if (ret < 0)
217 goto out;
218
Mircea Gherzan690142e2012-03-17 18:41:53 +0100219 event = *events_vector & mask;
Ido Yariv045b9b52012-06-18 12:31:16 +0300220
221 ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector,
222 sizeof(*events_vector), false);
223 if (ret < 0)
224 goto out;
225
Mircea Gherzan690142e2012-03-17 18:41:53 +0100226 event |= *events_vector & mask;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300227 } while (!event);
228
Mircea Gherzan690142e2012-03-17 18:41:53 +0100229out:
Tony Lindgrenafeeecc2018-06-19 02:43:35 -0700230 wl1271_ps_elp_sleep(wl);
Mircea Gherzan690142e2012-03-17 18:41:53 +0100231 kfree(events_vector);
232 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300233}
Eliad Pellerc50a2822012-11-22 18:06:19 +0200234EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout);
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200235
Eliad Peller784f6942011-10-05 11:55:39 +0200236int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type,
237 u8 *role_id)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300238{
Eliad Pellerc690ec82011-08-14 13:17:07 +0300239 struct wl12xx_cmd_role_enable *cmd;
240 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300241
Eliad Pellerc690ec82011-08-14 13:17:07 +0300242 wl1271_debug(DEBUG_CMD, "cmd role enable");
243
244 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
245 return -EBUSY;
246
247 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
248 if (!cmd) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300249 ret = -ENOMEM;
250 goto out;
251 }
252
Eliad Pellerc690ec82011-08-14 13:17:07 +0300253 /* get role id */
254 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
255 if (cmd->role_id >= WL12XX_MAX_ROLES) {
256 ret = -EBUSY;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300257 goto out_free;
258 }
259
Eliad Peller784f6942011-10-05 11:55:39 +0200260 memcpy(cmd->mac_address, addr, ETH_ALEN);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300261 cmd->role_type = role_type;
262
263 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
264 if (ret < 0) {
265 wl1271_error("failed to initiate cmd role enable");
266 goto out_free;
267 }
268
269 __set_bit(cmd->role_id, wl->roles_map);
270 *role_id = cmd->role_id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300271
272out_free:
Eliad Pellerc690ec82011-08-14 13:17:07 +0300273 kfree(cmd);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300274
275out:
276 return ret;
277}
278
Eliad Pellerc690ec82011-08-14 13:17:07 +0300279int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
280{
281 struct wl12xx_cmd_role_disable *cmd;
282 int ret;
283
284 wl1271_debug(DEBUG_CMD, "cmd role disable");
285
286 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
287 return -ENOENT;
288
289 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
290 if (!cmd) {
291 ret = -ENOMEM;
292 goto out;
293 }
294 cmd->role_id = *role_id;
295
296 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
297 if (ret < 0) {
298 wl1271_error("failed to initiate cmd role disable");
299 goto out_free;
300 }
301
302 __clear_bit(*role_id, wl->roles_map);
303 *role_id = WL12XX_INVALID_ROLE_ID;
304
305out_free:
306 kfree(cmd);
307
308out:
309 return ret;
310}
311
Eliad Peller978cd3a2012-11-22 18:06:21 +0200312static int wlcore_get_new_session_id(struct wl1271 *wl, u8 hlid)
313{
314 if (wl->session_ids[hlid] >= SESSION_COUNTER_MAX)
315 wl->session_ids[hlid] = 0;
316
317 wl->session_ids[hlid]++;
318
319 return wl->session_ids[hlid];
320}
321
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200322int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300323{
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200324 unsigned long flags;
Eliad Pellerda08fdf2014-02-10 13:47:22 +0200325 u8 link = find_first_zero_bit(wl->links_map, wl->num_links);
326 if (link >= wl->num_links)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300327 return -EBUSY;
328
Eliad Peller978cd3a2012-11-22 18:06:21 +0200329 wl->session_ids[link] = wlcore_get_new_session_id(wl, link);
330
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200331 /* these bits are used by op_tx */
332 spin_lock_irqsave(&wl->wl_lock, flags);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300333 __set_bit(link, wl->links_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200334 __set_bit(link, wlvif->links_map);
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200335 spin_unlock_irqrestore(&wl->wl_lock, flags);
Arik Nemtsovb50a62b2012-11-27 08:44:56 +0200336
Eliad Peller75fb4df2014-02-10 13:47:21 +0200337 /*
338 * take the last "freed packets" value from the current FW status.
339 * on recovery, we might not have fw_status yet, and
340 * tx_lnk_free_pkts will be NULL. check for it.
341 */
342 if (wl->fw_status->counters.tx_lnk_free_pkts)
343 wl->links[link].prev_freed_pkts =
344 wl->fw_status->counters.tx_lnk_free_pkts[link];
Arik Nemtsov1e0708a2012-11-27 08:44:57 +0200345 wl->links[link].wlvif = wlvif;
Arik Nemtsov93d5d102013-03-12 17:19:38 +0200346
347 /*
348 * Take saved value for total freed packets from wlvif, in case this is
349 * recovery/resume
350 */
351 if (wlvif->bss_type != BSS_TYPE_AP_BSS)
352 wl->links[link].total_freed_pkts = wlvif->total_freed_pkts;
353
Eliad Pellerc690ec82011-08-14 13:17:07 +0300354 *hlid = link;
Arik Nemtsov9a100962012-11-28 11:42:42 +0200355
356 wl->active_link_count++;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300357 return 0;
358}
359
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200360void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300361{
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200362 unsigned long flags;
363
Eliad Pellerc690ec82011-08-14 13:17:07 +0300364 if (*hlid == WL12XX_INVALID_LINK_ID)
365 return;
366
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200367 /* these bits are used by op_tx */
368 spin_lock_irqsave(&wl->wl_lock, flags);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300369 __clear_bit(*hlid, wl->links_map);
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200370 __clear_bit(*hlid, wlvif->links_map);
Arik Nemtsov0b0e32b2012-02-28 00:41:29 +0200371 spin_unlock_irqrestore(&wl->wl_lock, flags);
Arik Nemtsov6246ca02012-02-28 00:41:30 +0200372
Arik Nemtsov6c4c4532012-11-27 08:44:54 +0200373 wl->links[*hlid].allocated_pkts = 0;
374 wl->links[*hlid].prev_freed_pkts = 0;
375 wl->links[*hlid].ba_bitmap = 0;
Joe Perches93803b32015-03-02 19:54:49 -0800376 eth_zero_addr(wl->links[*hlid].addr);
Arik Nemtsov6c4c4532012-11-27 08:44:54 +0200377
Arik Nemtsov6246ca02012-02-28 00:41:30 +0200378 /*
379 * At this point op_tx() will not add more packets to the queues. We
380 * can purge them.
381 */
382 wl1271_tx_reset_link_queues(wl, *hlid);
Arik Nemtsov1e0708a2012-11-27 08:44:57 +0200383 wl->links[*hlid].wlvif = NULL;
Arik Nemtsov6246ca02012-02-28 00:41:30 +0200384
Eliad Peller50d26aa2014-07-11 03:01:26 +0300385 if (wlvif->bss_type == BSS_TYPE_AP_BSS &&
386 *hlid == wlvif->ap.bcast_hlid) {
Eliad Peller30a00352014-07-11 03:01:27 +0300387 u32 sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING;
Arik Nemtsov93d5d102013-03-12 17:19:38 +0200388 /*
389 * save the total freed packets in the wlvif, in case this is
390 * recovery or suspend
391 */
392 wlvif->total_freed_pkts = wl->links[*hlid].total_freed_pkts;
393
394 /*
395 * increment the initial seq number on recovery to account for
396 * transmitted packets that we haven't yet got in the FW status
397 */
Eliad Peller30a00352014-07-11 03:01:27 +0300398 if (wlvif->encryption_type == KEY_GEM)
399 sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM;
400
Arik Nemtsov93d5d102013-03-12 17:19:38 +0200401 if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags))
Eliad Peller30a00352014-07-11 03:01:27 +0300402 wlvif->total_freed_pkts += sqn_padding;
Arik Nemtsov93d5d102013-03-12 17:19:38 +0200403 }
404
405 wl->links[*hlid].total_freed_pkts = 0;
406
Eliad Pellerc690ec82011-08-14 13:17:07 +0300407 *hlid = WL12XX_INVALID_LINK_ID;
Arik Nemtsov9a100962012-11-28 11:42:42 +0200408 wl->active_link_count--;
409 WARN_ON_ONCE(wl->active_link_count < 0);
Arik Nemtsov712e9bf2011-08-14 13:17:20 +0300410}
411
Eliad Peller750e9d12014-12-29 08:24:07 +0200412u8 wlcore_get_native_channel_type(u8 nl_channel_type)
Arik Nemtsova6298db2012-05-10 12:13:31 +0300413{
414 switch (nl_channel_type) {
415 case NL80211_CHAN_NO_HT:
416 return WLCORE_CHAN_NO_HT;
417 case NL80211_CHAN_HT20:
418 return WLCORE_CHAN_HT20;
419 case NL80211_CHAN_HT40MINUS:
420 return WLCORE_CHAN_HT40MINUS;
421 case NL80211_CHAN_HT40PLUS:
422 return WLCORE_CHAN_HT40PLUS;
423 default:
424 WARN_ON(1);
425 return WLCORE_CHAN_NO_HT;
426 }
427}
Eliad Peller750e9d12014-12-29 08:24:07 +0200428EXPORT_SYMBOL_GPL(wlcore_get_native_channel_type);
Arik Nemtsova6298db2012-05-10 12:13:31 +0300429
Eliad Peller679a6732011-10-11 11:55:44 +0200430static int wl12xx_cmd_role_start_dev(struct wl1271 *wl,
Eliad Pellerdabf37d2012-11-20 13:20:03 +0200431 struct wl12xx_vif *wlvif,
Johannes Berg57fbcce2016-04-12 15:56:15 +0200432 enum nl80211_band band,
Eliad Pellerdabf37d2012-11-20 13:20:03 +0200433 int channel)
Eliad Peller04e80792011-08-14 13:17:09 +0300434{
435 struct wl12xx_cmd_role_start *cmd;
436 int ret;
437
438 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
439 if (!cmd) {
440 ret = -ENOMEM;
441 goto out;
442 }
443
Eliad Peller7edebf52011-10-05 11:55:52 +0200444 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id);
Eliad Peller04e80792011-08-14 13:17:09 +0300445
Eliad Peller7edebf52011-10-05 11:55:52 +0200446 cmd->role_id = wlvif->dev_role_id;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200447 if (band == NL80211_BAND_5GHZ)
Luciano Coelho00782132011-11-29 13:38:37 +0200448 cmd->band = WLCORE_BAND_5GHZ;
Eliad Pellerdabf37d2012-11-20 13:20:03 +0200449 cmd->channel = channel;
Eliad Peller04e80792011-08-14 13:17:09 +0300450
Eliad Pellerafaf8bd2011-10-05 11:55:57 +0200451 if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200452 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid);
Eliad Peller04e80792011-08-14 13:17:09 +0300453 if (ret)
454 goto out_free;
455 }
Eliad Pellerafaf8bd2011-10-05 11:55:57 +0200456 cmd->device.hlid = wlvif->dev_hlid;
Eliad Peller978cd3a2012-11-22 18:06:21 +0200457 cmd->device.session = wl->session_ids[wlvif->dev_hlid];
Eliad Peller04e80792011-08-14 13:17:09 +0300458
459 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
460 cmd->role_id, cmd->device.hlid, cmd->device.session);
461
462 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
463 if (ret < 0) {
464 wl1271_error("failed to initiate cmd role enable");
465 goto err_hlid;
466 }
467
468 goto out_free;
469
470err_hlid:
471 /* clear links on error */
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200472 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
Eliad Peller04e80792011-08-14 13:17:09 +0300473
474out_free:
475 kfree(cmd);
476
477out:
478 return ret;
479}
480
Eliad Peller679a6732011-10-11 11:55:44 +0200481static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl,
482 struct wl12xx_vif *wlvif)
Eliad Peller04e80792011-08-14 13:17:09 +0300483{
484 struct wl12xx_cmd_role_stop *cmd;
485 int ret;
486
Eliad Pellerafaf8bd2011-10-05 11:55:57 +0200487 if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID))
Eliad Peller04e80792011-08-14 13:17:09 +0300488 return -EINVAL;
489
490 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
491 if (!cmd) {
492 ret = -ENOMEM;
493 goto out;
494 }
495
496 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
497
Eliad Peller7edebf52011-10-05 11:55:52 +0200498 cmd->role_id = wlvif->dev_role_id;
Eliad Peller04e80792011-08-14 13:17:09 +0300499 cmd->disc_type = DISCONNECT_IMMEDIATE;
500 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
501
502 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
503 if (ret < 0) {
504 wl1271_error("failed to initiate cmd role stop");
505 goto out_free;
506 }
507
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200508 wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid);
Eliad Peller04e80792011-08-14 13:17:09 +0300509
510out_free:
511 kfree(cmd);
512
513out:
514 return ret;
515}
516
Eliad Peller87fbcb02011-10-05 11:55:41 +0200517int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300518{
Eliad Pellercdf09492011-10-05 11:55:44 +0200519 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300520 struct wl12xx_cmd_role_start *cmd;
Eliad Peller42ec1f82012-11-20 13:20:08 +0200521 u32 supported_rates;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300522 int ret;
523
524 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
525 if (!cmd) {
526 ret = -ENOMEM;
527 goto out;
528 }
529
Eliad Peller0603d892011-10-05 11:55:51 +0200530 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300531
Eliad Peller0603d892011-10-05 11:55:51 +0200532 cmd->role_id = wlvif->role_id;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200533 if (wlvif->band == NL80211_BAND_5GHZ)
Luciano Coelho00782132011-11-29 13:38:37 +0200534 cmd->band = WLCORE_BAND_5GHZ;
Eliad Peller61f845f2011-10-10 10:13:10 +0200535 cmd->channel = wlvif->channel;
Eliad Peller87fbcb02011-10-05 11:55:41 +0200536 cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
Eliad Peller6a899792011-10-05 11:55:58 +0200537 cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300538 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
Eliad Peller1fe9f162011-10-05 11:55:48 +0200539 cmd->sta.ssid_len = wlvif->ssid_len;
540 memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len);
Eliad Pellercdf09492011-10-05 11:55:44 +0200541 memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN);
Eliad Peller42ec1f82012-11-20 13:20:08 +0200542
543 supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES |
544 wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
545 if (wlvif->p2p)
546 supported_rates &= ~CONF_TX_CCK_RATES;
547
548 cmd->sta.local_rates = cpu_to_le32(supported_rates);
549
Arik Nemtsova6298db2012-05-10 12:13:31 +0300550 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300551
Eliad Peller154da672011-10-05 11:55:53 +0200552 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200553 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300554 if (ret)
555 goto out_free;
556 }
Eliad Peller154da672011-10-05 11:55:53 +0200557 cmd->sta.hlid = wlvif->sta.hlid;
Eliad Peller978cd3a2012-11-22 18:06:21 +0200558 cmd->sta.session = wl->session_ids[wlvif->sta.hlid];
Eliad Pellerdc62a3d2012-11-20 13:20:11 +0200559 /*
Luciano Coelho9c3a8d92013-02-07 11:35:33 +0200560 * We don't have the correct remote rates in this stage. The
561 * rates will be reconfigured later, after association, if the
562 * firmware supports ACX_PEER_CAP. Otherwise, there's nothing
563 * we can do, so use all supported_rates here.
Eliad Pellerdc62a3d2012-11-20 13:20:11 +0200564 */
Luciano Coelho9c3a8d92013-02-07 11:35:33 +0200565 cmd->sta.remote_rates = cpu_to_le32(supported_rates);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300566
567 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
568 "basic_rate_set: 0x%x, remote_rates: 0x%x",
Eliad Peller0603d892011-10-05 11:55:51 +0200569 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200570 wlvif->basic_rate_set, wlvif->rate_set);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300571
572 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
573 if (ret < 0) {
574 wl1271_error("failed to initiate cmd role start sta");
575 goto err_hlid;
576 }
577
Arik Nemtsov5f9b6772012-11-26 18:05:41 +0200578 wlvif->sta.role_chan_type = wlvif->channel_type;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300579 goto out_free;
580
581err_hlid:
582 /* clear links on error. */
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200583 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300584
585out_free:
586 kfree(cmd);
587
588out:
589 return ret;
590}
591
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300592/* use this function to stop ibss as well */
Eliad Peller0603d892011-10-05 11:55:51 +0200593int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300594{
595 struct wl12xx_cmd_role_stop *cmd;
596 int ret;
597
Eliad Peller154da672011-10-05 11:55:53 +0200598 if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID))
Eliad Pellerc690ec82011-08-14 13:17:07 +0300599 return -EINVAL;
600
601 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
602 if (!cmd) {
603 ret = -ENOMEM;
604 goto out;
605 }
606
Eliad Peller0603d892011-10-05 11:55:51 +0200607 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300608
Eliad Peller0603d892011-10-05 11:55:51 +0200609 cmd->role_id = wlvif->role_id;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300610 cmd->disc_type = DISCONNECT_IMMEDIATE;
611 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
612
613 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
614 if (ret < 0) {
615 wl1271_error("failed to initiate cmd role stop sta");
616 goto out_free;
617 }
618
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200619 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300620
621out_free:
622 kfree(cmd);
623
624out:
625 return ret;
626}
627
Eliad Peller87fbcb02011-10-05 11:55:41 +0200628int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300629{
630 struct wl12xx_cmd_role_start *cmd;
Eliad Peller6e8cd332011-10-10 10:13:13 +0200631 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
632 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Luciano Coelho60462b42012-05-10 12:14:14 +0300633 u32 supported_rates;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300634 int ret;
635
Eliad Peller0603d892011-10-05 11:55:51 +0200636 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300637
Maital Hahnc0174ee2016-06-28 13:41:35 +0300638 /* If MESH --> ssid_len is always 0 */
639 if (!ieee80211_vif_is_mesh(vif)) {
640 /* trying to use hidden SSID with an old hostapd version */
641 if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) {
642 wl1271_error("got a null SSID from beacon/bss");
643 ret = -EINVAL;
644 goto out;
645 }
Eliad Pellerc690ec82011-08-14 13:17:07 +0300646 }
647
648 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
649 if (!cmd) {
650 ret = -ENOMEM;
651 goto out;
652 }
653
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200654 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid);
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300655 if (ret < 0)
656 goto out_free;
657
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200658 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid);
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300659 if (ret < 0)
660 goto out_free_global;
661
Arik Nemtsov0e752df2013-03-12 17:19:44 +0200662 /* use the previous security seq, if this is a recovery/resume */
663 wl->links[wlvif->ap.bcast_hlid].total_freed_pkts =
664 wlvif->total_freed_pkts;
665
Eliad Peller0603d892011-10-05 11:55:51 +0200666 cmd->role_id = wlvif->role_id;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300667 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
668 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
Eliad Pellera8ab39a2011-10-05 11:55:54 +0200669 cmd->ap.global_hlid = wlvif->ap.global_hlid;
670 cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid;
Eliad Peller978cd3a2012-11-22 18:06:21 +0200671 cmd->ap.global_session_id = wl->session_ids[wlvif->ap.global_hlid];
672 cmd->ap.bcast_session_id = wl->session_ids[wlvif->ap.bcast_hlid];
Eliad Peller87fbcb02011-10-05 11:55:41 +0200673 cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
Eliad Peller6a899792011-10-05 11:55:58 +0200674 cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300675 cmd->ap.dtim_interval = bss_conf->dtim_period;
676 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
Eliad Peller8332f0f2012-01-31 11:57:19 +0200677 /* FIXME: Change when adding DFS */
678 cmd->ap.reset_tsf = 1; /* By default reset AP TSF */
Eliad Pellerd50529c2012-11-22 18:06:20 +0200679 cmd->ap.wmm = wlvif->wmm_enabled;
Eliad Peller61f845f2011-10-10 10:13:10 +0200680 cmd->channel = wlvif->channel;
Arik Nemtsova6298db2012-05-10 12:13:31 +0300681 cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +0300682
683 if (!bss_conf->hidden_ssid) {
684 /* take the SSID from the beacon for backward compatibility */
685 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
Eliad Peller1fe9f162011-10-05 11:55:48 +0200686 cmd->ap.ssid_len = wlvif->ssid_len;
687 memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len);
Arik Nemtsov68eaaf62011-09-03 20:22:03 +0300688 } else {
689 cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN;
690 cmd->ap.ssid_len = bss_conf->ssid_len;
691 memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len);
692 }
693
Eliad Peller42ec1f82012-11-20 13:20:08 +0200694 supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES |
Luciano Coelho60462b42012-05-10 12:14:14 +0300695 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
Eliad Peller873d2a42012-11-26 18:05:46 +0200696 if (wlvif->p2p)
697 supported_rates &= ~CONF_TX_CCK_RATES;
Luciano Coelho60462b42012-05-10 12:14:14 +0300698
699 wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x",
700 supported_rates);
701
702 cmd->ap.local_rates = cpu_to_le32(supported_rates);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300703
Eliad Peller1b92f152011-10-10 10:13:09 +0200704 switch (wlvif->band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +0200705 case NL80211_BAND_2GHZ:
Luciano Coelho00782132011-11-29 13:38:37 +0200706 cmd->band = WLCORE_BAND_2_4GHZ;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300707 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200708 case NL80211_BAND_5GHZ:
Luciano Coelho00782132011-11-29 13:38:37 +0200709 cmd->band = WLCORE_BAND_5GHZ;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300710 break;
711 default:
Eliad Peller1b92f152011-10-10 10:13:09 +0200712 wl1271_warning("ap start - unknown band: %d", (int)wlvif->band);
Luciano Coelho00782132011-11-29 13:38:37 +0200713 cmd->band = WLCORE_BAND_2_4GHZ;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300714 break;
715 }
716
717 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
718 if (ret < 0) {
719 wl1271_error("failed to initiate cmd role start ap");
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300720 goto out_free_bcast;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300721 }
722
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300723 goto out_free;
724
725out_free_bcast:
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200726 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300727
728out_free_global:
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200729 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300730
Eliad Pellerc690ec82011-08-14 13:17:07 +0300731out_free:
732 kfree(cmd);
733
734out:
735 return ret;
736}
737
Eliad Peller0603d892011-10-05 11:55:51 +0200738int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerc690ec82011-08-14 13:17:07 +0300739{
740 struct wl12xx_cmd_role_stop *cmd;
741 int ret;
742
743 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
744 if (!cmd) {
745 ret = -ENOMEM;
746 goto out;
747 }
748
Eliad Peller0603d892011-10-05 11:55:51 +0200749 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id);
Eliad Pellerc690ec82011-08-14 13:17:07 +0300750
Eliad Peller0603d892011-10-05 11:55:51 +0200751 cmd->role_id = wlvif->role_id;
Eliad Pellerc690ec82011-08-14 13:17:07 +0300752
753 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
754 if (ret < 0) {
755 wl1271_error("failed to initiate cmd role stop ap");
756 goto out_free;
757 }
758
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200759 wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid);
760 wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid);
Arik Nemtsove51ae9b2011-08-14 13:17:21 +0300761
Eliad Pellerc690ec82011-08-14 13:17:07 +0300762out_free:
763 kfree(cmd);
764
765out:
766 return ret;
767}
768
Eliad Peller87fbcb02011-10-05 11:55:41 +0200769int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300770{
Eliad Pellercdf09492011-10-05 11:55:44 +0200771 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300772 struct wl12xx_cmd_role_start *cmd;
Eliad Peller6e8cd332011-10-10 10:13:13 +0200773 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300774 int ret;
775
776 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
777 if (!cmd) {
778 ret = -ENOMEM;
779 goto out;
780 }
781
Eliad Peller0603d892011-10-05 11:55:51 +0200782 wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300783
Eliad Peller0603d892011-10-05 11:55:51 +0200784 cmd->role_id = wlvif->role_id;
Johannes Berg57fbcce2016-04-12 15:56:15 +0200785 if (wlvif->band == NL80211_BAND_5GHZ)
Luciano Coelho00782132011-11-29 13:38:37 +0200786 cmd->band = WLCORE_BAND_5GHZ;
Eliad Peller61f845f2011-10-10 10:13:10 +0200787 cmd->channel = wlvif->channel;
Eliad Peller87fbcb02011-10-05 11:55:41 +0200788 cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set);
Eliad Peller6a899792011-10-05 11:55:58 +0200789 cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300790 cmd->ibss.dtim_interval = bss_conf->dtim_period;
791 cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY;
Eliad Peller1fe9f162011-10-05 11:55:48 +0200792 cmd->ibss.ssid_len = wlvif->ssid_len;
793 memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len);
Eliad Pellercdf09492011-10-05 11:55:44 +0200794 memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN);
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200795 cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300796
Eliad Peller154da672011-10-05 11:55:53 +0200797 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) {
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200798 ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300799 if (ret)
800 goto out_free;
801 }
Eliad Peller154da672011-10-05 11:55:53 +0200802 cmd->ibss.hlid = wlvif->sta.hlid;
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200803 cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300804
805 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
806 "basic_rate_set: 0x%x, remote_rates: 0x%x",
Eliad Peller0603d892011-10-05 11:55:51 +0200807 wlvif->role_id, cmd->sta.hlid, cmd->sta.session,
Eliad Peller30d0c8f2011-10-05 11:55:42 +0200808 wlvif->basic_rate_set, wlvif->rate_set);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300809
Eliad Pellercdf09492011-10-05 11:55:44 +0200810 wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM",
811 vif->bss_conf.bssid);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300812
813 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
814 if (ret < 0) {
815 wl1271_error("failed to initiate cmd role enable");
816 goto err_hlid;
817 }
818
819 goto out_free;
820
821err_hlid:
822 /* clear links on error. */
Eliad Pellerc7ffb902011-10-05 11:56:05 +0200823 wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid);
Eliad Peller31cd3ae2011-08-14 13:17:25 +0300824
825out_free:
826 kfree(cmd);
827
828out:
829 return ret;
830}
831
Eliad Pellerc690ec82011-08-14 13:17:07 +0300832
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300833/**
834 * send test command to firmware
835 *
836 * @wl: wl struct
837 * @buf: buffer containing the command, with all headers, must work with dma
838 * @len: length of the buffer
839 * @answer: is answer needed
840 */
841int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
842{
843 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200844 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300845
846 wl1271_debug(DEBUG_CMD, "cmd test");
847
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200848 if (answer)
849 res_len = buf_len;
850
851 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300852
853 if (ret < 0) {
854 wl1271_warning("TEST command failed");
855 return ret;
856 }
857
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200858 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300859}
Luciano Coelho9d68d1e2011-12-02 00:47:45 +0200860EXPORT_SYMBOL_GPL(wl1271_cmd_test);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300861
862/**
863 * read acx from firmware
864 *
865 * @wl: wl struct
866 * @id: acx id
867 * @buf: buffer for the response, including all headers, must work with dma
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300868 * @len: length of buf
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300869 */
Igal Chernobelsky4b674142013-09-09 12:24:35 +0300870int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf,
871 size_t cmd_len, size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300872{
873 struct acx_header *acx = buf;
874 int ret;
875
876 wl1271_debug(DEBUG_CMD, "cmd interrogate");
877
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300878 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300879
Igal Chernobelsky4b674142013-09-09 12:24:35 +0300880 /* response payload length, does not include any headers */
881 acx->len = cpu_to_le16(res_len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300882
Igal Chernobelsky4b674142013-09-09 12:24:35 +0300883 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, cmd_len, res_len);
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200884 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300885 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300886
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300887 return ret;
888}
889
890/**
891 * write acx value to firmware
892 *
893 * @wl: wl struct
894 * @id: acx id
895 * @buf: buffer containing acx, including all headers, must work with dma
896 * @len: length of buf
Eliad Pellerea508432012-11-27 08:44:45 +0200897 * @valid_rets: bitmap of valid cmd status codes (i.e. return values).
898 * return the cmd status on success.
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300899 */
Eliad Pellerea508432012-11-27 08:44:45 +0200900int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf,
901 size_t len, unsigned long valid_rets)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300902{
903 struct acx_header *acx = buf;
904 int ret;
905
Eliad Pellerc91d0602011-08-25 18:10:57 +0300906 wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300907
Luciano Coelhof5b8f472014-11-10 09:25:17 +0200908 if (WARN_ON_ONCE(len < sizeof(*acx)))
909 return -EIO;
910
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300911 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300912
913 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300914 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300915
Eliad Pellerea508432012-11-27 08:44:45 +0200916 ret = wlcore_cmd_send_failsafe(wl, CMD_CONFIGURE, acx, len, 0,
917 valid_rets);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300918 if (ret < 0) {
919 wl1271_warning("CONFIGURE command NOK");
920 return ret;
921 }
922
Eliad Pellerea508432012-11-27 08:44:45 +0200923 return ret;
924}
925
926/*
927 * wrapper for wlcore_cmd_configure that accepts only success status.
928 * return 0 on success
929 */
930int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
931{
932 int ret = wlcore_cmd_configure_failsafe(wl, id, buf, len, 0);
933
934 if (ret < 0)
935 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300936 return 0;
937}
Luciano Coelho9d68d1e2011-12-02 00:47:45 +0200938EXPORT_SYMBOL_GPL(wl1271_cmd_configure);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300939
Luciano Coelho94210892009-12-11 15:40:55 +0200940int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300941{
942 struct cmd_enabledisable_path *cmd;
943 int ret;
944 u16 cmd_rx, cmd_tx;
945
946 wl1271_debug(DEBUG_CMD, "cmd data path");
947
948 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
949 if (!cmd) {
950 ret = -ENOMEM;
951 goto out;
952 }
953
Luciano Coelho94210892009-12-11 15:40:55 +0200954 /* the channel here is only used for calibration, so hardcoded to 1 */
955 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300956
957 if (enable) {
958 cmd_rx = CMD_ENABLE_RX;
959 cmd_tx = CMD_ENABLE_TX;
960 } else {
961 cmd_rx = CMD_DISABLE_RX;
962 cmd_tx = CMD_DISABLE_TX;
963 }
964
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200965 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300966 if (ret < 0) {
967 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200968 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300969 goto out;
970 }
971
972 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200973 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300974
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200975 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300976 if (ret < 0) {
977 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200978 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200979 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300980 }
981
982 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200983 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300984
985out:
986 kfree(cmd);
987 return ret;
988}
Luciano Coelhoc331b342012-05-10 12:13:49 +0300989EXPORT_SYMBOL_GPL(wl1271_cmd_data_path);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300990
Eliad Peller0603d892011-10-05 11:55:51 +0200991int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif,
Eyal Shapiraf1d63a52012-01-31 11:57:21 +0200992 u8 ps_mode, u16 auto_ps_timeout)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300993{
994 struct wl1271_cmd_ps_params *ps_params = NULL;
995 int ret = 0;
996
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300997 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
998
999 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
1000 if (!ps_params) {
1001 ret = -ENOMEM;
1002 goto out;
1003 }
1004
Eliad Peller0603d892011-10-05 11:55:51 +02001005 ps_params->role_id = wlvif->role_id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001006 ps_params->ps_mode = ps_mode;
Eyal Shapiraf1d63a52012-01-31 11:57:21 +02001007 ps_params->auto_ps_timeout = auto_ps_timeout;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001008
1009 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001010 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001011 if (ret < 0) {
1012 wl1271_error("cmd set_ps_mode failed");
1013 goto out;
1014 }
1015
1016out:
1017 kfree(ps_params);
1018 return ret;
1019}
1020
Eliad Pellercdaac622012-01-31 11:57:16 +02001021int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id,
1022 u16 template_id, void *buf, size_t buf_len,
1023 int index, u32 rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001024{
1025 struct wl1271_cmd_template_set *cmd;
1026 int ret = 0;
1027
Eliad Pellerc059beb2012-01-31 11:57:17 +02001028 wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)",
1029 template_id, role_id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001030
1031 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
1032 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
1033
1034 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1035 if (!cmd) {
1036 ret = -ENOMEM;
1037 goto out;
1038 }
1039
Eliad Pellercdaac622012-01-31 11:57:16 +02001040 /* during initialization wlvif is NULL */
1041 cmd->role_id = role_id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001042 cmd->len = cpu_to_le16(buf_len);
1043 cmd->template_type = template_id;
Juuso Oikarinen606c1482010-04-01 11:38:21 +03001044 cmd->enabled_rates = cpu_to_le32(rates);
Arik Nemtsov1e05a812010-10-16 17:44:51 +02001045 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
1046 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001047 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001048
1049 if (buf)
1050 memcpy(cmd->template_data, buf, buf_len);
1051
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001052 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001053 if (ret < 0) {
1054 wl1271_warning("cmd set_template failed: %d", ret);
1055 goto out_free;
1056 }
1057
1058out_free:
1059 kfree(cmd);
1060
1061out:
1062 return ret;
1063}
1064
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001065int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001066{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +02001067 struct sk_buff *skb = NULL;
1068 int size;
1069 void *ptr;
1070 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001071
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001072
Eliad Peller536129c2011-10-05 11:55:45 +02001073 if (wlvif->bss_type == BSS_TYPE_IBSS) {
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +02001074 size = sizeof(struct wl12xx_null_data_template);
1075 ptr = NULL;
1076 } else {
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001077 skb = ieee80211_nullfunc_get(wl->hw,
1078 wl12xx_wlvif_to_vif(wlvif));
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +02001079 if (!skb)
1080 goto out;
1081 size = skb->len;
1082 ptr = skb->data;
1083 }
1084
Eliad Pellercdaac622012-01-31 11:57:16 +02001085 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1086 CMD_TEMPL_NULL_DATA, ptr, size, 0,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001087 wlvif->basic_rate);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001088
Kalle Valo899e6e62010-03-18 12:26:34 +02001089out:
1090 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +02001091 if (ret)
1092 wl1271_warning("cmd buld null data failed %d", ret);
1093
Kalle Valo899e6e62010-03-18 12:26:34 +02001094 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001095
1096}
1097
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001098int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl,
1099 struct wl12xx_vif *wlvif)
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001100{
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001101 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001102 struct sk_buff *skb = NULL;
1103 int ret = -ENOMEM;
1104
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001105 skb = ieee80211_nullfunc_get(wl->hw, vif);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001106 if (!skb)
1107 goto out;
1108
Eliad Pellercdaac622012-01-31 11:57:16 +02001109 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001110 skb->data, skb->len,
Eliad Peller001e39a2012-08-16 13:52:47 +03001111 wlvif->sta.klv_template_id,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001112 wlvif->basic_rate);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +02001113
1114out:
1115 dev_kfree_skb(skb);
1116 if (ret)
1117 wl1271_warning("cmd build klv null data failed %d", ret);
1118
1119 return ret;
1120
1121}
1122
Eliad Peller87fbcb02011-10-05 11:55:41 +02001123int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1124 u16 aid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001125{
Eliad Peller6e8cd332011-10-10 10:13:13 +02001126 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Kalle Valo899e6e62010-03-18 12:26:34 +02001127 struct sk_buff *skb;
1128 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001129
Eliad Peller6e8cd332011-10-10 10:13:13 +02001130 skb = ieee80211_pspoll_get(wl->hw, vif);
Kalle Valo899e6e62010-03-18 12:26:34 +02001131 if (!skb)
1132 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +03001133
Eliad Pellercdaac622012-01-31 11:57:16 +02001134 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1135 CMD_TEMPL_PS_POLL, skb->data,
Eliad Peller87fbcb02011-10-05 11:55:41 +02001136 skb->len, 0, wlvif->basic_rate_set);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +03001137
Kalle Valo899e6e62010-03-18 12:26:34 +02001138out:
1139 dev_kfree_skb(skb);
1140 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001141}
1142
Eliad Pellercdaac622012-01-31 11:57:16 +02001143int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1144 u8 role_id, u8 band,
Kalle Valo818e3062010-03-18 12:26:35 +02001145 const u8 *ssid, size_t ssid_len,
David Spinadel633e2712014-02-06 16:15:23 +02001146 const u8 *ie0, size_t ie0_len, const u8 *ie1,
1147 size_t ie1_len, bool sched_scan)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001148{
Eliad Peller83587502011-10-10 10:12:53 +02001149 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Kalle Valo818e3062010-03-18 12:26:35 +02001150 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001151 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001152 u32 rate;
Eliad Peller78e28062012-11-22 18:06:15 +02001153 u16 template_id_2_4 = wl->scan_templ_id_2_4;
1154 u16 template_id_5 = wl->scan_templ_id_5;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001155
Victor Goldenshtein0fe72082013-09-17 18:41:24 +03001156 wl1271_debug(DEBUG_SCAN, "build probe request band %d", band);
1157
Johannes Berga344d672014-06-12 22:24:31 +02001158 skb = ieee80211_probereq_get(wl->hw, vif->addr, ssid, ssid_len,
David Spinadel633e2712014-02-06 16:15:23 +02001159 ie0_len + ie1_len);
Kalle Valo818e3062010-03-18 12:26:35 +02001160 if (!skb) {
1161 ret = -ENOMEM;
1162 goto out;
1163 }
David Spinadel633e2712014-02-06 16:15:23 +02001164 if (ie0_len)
1165 memcpy(skb_put(skb, ie0_len), ie0, ie0_len);
1166 if (ie1_len)
1167 memcpy(skb_put(skb, ie1_len), ie1, ie1_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001168
Eliad Peller78e28062012-11-22 18:06:15 +02001169 if (sched_scan &&
Yoni Divinsky3df74f42012-06-27 13:01:44 +03001170 (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) {
Eliad Peller78e28062012-11-22 18:06:15 +02001171 template_id_2_4 = wl->sched_scan_templ_id_2_4;
1172 template_id_5 = wl->sched_scan_templ_id_5;
Yoni Divinsky3df74f42012-06-27 13:01:44 +03001173 }
1174
Eliad Peller83587502011-10-10 10:12:53 +02001175 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02001176 if (band == NL80211_BAND_2GHZ)
Eliad Pellercdaac622012-01-31 11:57:16 +02001177 ret = wl1271_cmd_template_set(wl, role_id,
Yoni Divinsky3df74f42012-06-27 13:01:44 +03001178 template_id_2_4,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001179 skb->data, skb->len, 0, rate);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001180 else
Eliad Pellercdaac622012-01-31 11:57:16 +02001181 ret = wl1271_cmd_template_set(wl, role_id,
Yoni Divinsky3df74f42012-06-27 13:01:44 +03001182 template_id_5,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001183 skb->data, skb->len, 0, rate);
Kalle Valo818e3062010-03-18 12:26:35 +02001184
1185out:
1186 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001187 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001188}
Eliad Peller78e28062012-11-22 18:06:15 +02001189EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001190
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001191struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
Eliad Peller83587502011-10-10 10:12:53 +02001192 struct wl12xx_vif *wlvif,
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001193 struct sk_buff *skb)
1194{
Eliad Peller83587502011-10-10 10:12:53 +02001195 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001196 int ret;
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001197 u32 rate;
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001198
1199 if (!skb)
Eliad Peller83587502011-10-10 10:12:53 +02001200 skb = ieee80211_ap_probereq_get(wl->hw, vif);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001201 if (!skb)
1202 goto out;
1203
Victor Goldenshtein0fe72082013-09-17 18:41:24 +03001204 wl1271_debug(DEBUG_SCAN, "set ap probe request template");
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001205
Eliad Peller1b92f152011-10-10 10:13:09 +02001206 rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]);
Johannes Berg57fbcce2016-04-12 15:56:15 +02001207 if (wlvif->band == NL80211_BAND_2GHZ)
Eliad Pellercdaac622012-01-31 11:57:16 +02001208 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1209 CMD_TEMPL_CFG_PROBE_REQ_2_4,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001210 skb->data, skb->len, 0, rate);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001211 else
Eliad Pellercdaac622012-01-31 11:57:16 +02001212 ret = wl1271_cmd_template_set(wl, wlvif->role_id,
1213 CMD_TEMPL_CFG_PROBE_REQ_5,
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001214 skb->data, skb->len, 0, rate);
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001215
1216 if (ret < 0)
1217 wl1271_error("Unable to set ap probe request template.");
1218
1219out:
1220 return skb;
1221}
1222
Eliad Peller5ec8a442012-02-02 12:22:09 +02001223int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Eliad Pellerc5312772010-12-09 11:31:27 +02001224{
Arik Nemtsov2c0133a2012-05-18 07:46:36 +03001225 int ret, extra = 0;
Eliad Peller5ec8a442012-02-02 12:22:09 +02001226 u16 fc;
Eliad Peller6e8cd332011-10-10 10:13:13 +02001227 struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif);
Eliad Peller5ec8a442012-02-02 12:22:09 +02001228 struct sk_buff *skb;
1229 struct wl12xx_arp_rsp_template *tmpl;
Eliad Pellerc5312772010-12-09 11:31:27 +02001230 struct ieee80211_hdr_3addr *hdr;
1231 struct arphdr *arp_hdr;
1232
Eliad Peller5ec8a442012-02-02 12:22:09 +02001233 skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) +
1234 WL1271_EXTRA_SPACE_MAX);
1235 if (!skb) {
1236 wl1271_error("failed to allocate buffer for arp rsp template");
1237 return -ENOMEM;
1238 }
Eliad Pellerc5312772010-12-09 11:31:27 +02001239
Eliad Peller5ec8a442012-02-02 12:22:09 +02001240 skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX);
1241
1242 tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl));
Jesper Juhl161f17b2012-05-03 10:25:51 +03001243 memset(tmpl, 0, sizeof(*tmpl));
Eliad Pellerc5312772010-12-09 11:31:27 +02001244
1245 /* llc layer */
Eliad Peller5ec8a442012-02-02 12:22:09 +02001246 memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header));
1247 tmpl->llc_type = cpu_to_be16(ETH_P_ARP);
Eliad Pellerc5312772010-12-09 11:31:27 +02001248
1249 /* arp header */
Eliad Peller5ec8a442012-02-02 12:22:09 +02001250 arp_hdr = &tmpl->arp_hdr;
Eliad Peller6177eae2010-12-22 12:38:52 +01001251 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1252 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
Eliad Pellerc5312772010-12-09 11:31:27 +02001253 arp_hdr->ar_hln = ETH_ALEN;
1254 arp_hdr->ar_pln = 4;
Eliad Peller6177eae2010-12-22 12:38:52 +01001255 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
Eliad Pellerc5312772010-12-09 11:31:27 +02001256
1257 /* arp payload */
Eliad Peller5ec8a442012-02-02 12:22:09 +02001258 memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN);
1259 tmpl->sender_ip = wlvif->ip_addr;
1260
1261 /* encryption space */
1262 switch (wlvif->encryption_type) {
1263 case KEY_TKIP:
Arik Nemtsov2c0133a2012-05-18 07:46:36 +03001264 if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE)
1265 extra = WL1271_EXTRA_SPACE_TKIP;
Eliad Peller5ec8a442012-02-02 12:22:09 +02001266 break;
1267 case KEY_AES:
1268 extra = WL1271_EXTRA_SPACE_AES;
1269 break;
1270 case KEY_NONE:
1271 case KEY_WEP:
1272 case KEY_GEM:
1273 extra = 0;
1274 break;
1275 default:
1276 wl1271_warning("Unknown encryption type: %d",
1277 wlvif->encryption_type);
1278 ret = -EINVAL;
1279 goto out;
1280 }
1281
1282 if (extra) {
1283 u8 *space = skb_push(skb, extra);
1284 memset(space, 0, extra);
1285 }
1286
1287 /* QoS header - BE */
1288 if (wlvif->sta.qos)
1289 memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16));
1290
1291 /* mac80211 header */
1292 hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr));
Jesper Juhl161f17b2012-05-03 10:25:51 +03001293 memset(hdr, 0, sizeof(*hdr));
Eliad Peller5ec8a442012-02-02 12:22:09 +02001294 fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS;
1295 if (wlvif->sta.qos)
1296 fc |= IEEE80211_STYPE_QOS_DATA;
1297 else
1298 fc |= IEEE80211_STYPE_DATA;
1299 if (wlvif->encryption_type != KEY_NONE)
1300 fc |= IEEE80211_FCTL_PROTECTED;
1301
1302 hdr->frame_control = cpu_to_le16(fc);
1303 memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN);
1304 memcpy(hdr->addr2, vif->addr, ETH_ALEN);
Joe Perches93803b32015-03-02 19:54:49 -08001305 eth_broadcast_addr(hdr->addr3);
Eliad Pellerc5312772010-12-09 11:31:27 +02001306
Eliad Pellercdaac622012-01-31 11:57:16 +02001307 ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP,
Eliad Peller5ec8a442012-02-02 12:22:09 +02001308 skb->data, skb->len, 0,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001309 wlvif->basic_rate);
Eliad Peller5ec8a442012-02-02 12:22:09 +02001310out:
1311 dev_kfree_skb(skb);
Eliad Pellerc5312772010-12-09 11:31:27 +02001312 return ret;
1313}
1314
Eliad Peller784f6942011-10-05 11:55:39 +02001315int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif)
Kalle Valo023e0822010-03-18 12:26:36 +02001316{
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001317 struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif);
Kalle Valo023e0822010-03-18 12:26:36 +02001318 struct ieee80211_qos_hdr template;
1319
1320 memset(&template, 0, sizeof(template));
1321
Eliad Pellercdf09492011-10-05 11:55:44 +02001322 memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN);
Eliad Peller784f6942011-10-05 11:55:39 +02001323 memcpy(template.addr2, vif->addr, ETH_ALEN);
Eliad Pellercdf09492011-10-05 11:55:44 +02001324 memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN);
Kalle Valo023e0822010-03-18 12:26:36 +02001325
1326 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1327 IEEE80211_STYPE_QOS_NULLFUNC |
1328 IEEE80211_FCTL_TODS);
1329
1330 /* FIXME: not sure what priority to use here */
1331 template.qos_ctrl = cpu_to_le16(0);
1332
Eliad Pellercdaac622012-01-31 11:57:16 +02001333 return wl1271_cmd_template_set(wl, wlvif->role_id,
1334 CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinen606c1482010-04-01 11:38:21 +03001335 sizeof(template), 0,
Eliad Pellerd2d66c52011-10-05 11:55:43 +02001336 wlvif->basic_rate);
Kalle Valo023e0822010-03-18 12:26:36 +02001337}
1338
Eliad Pellerc690ec82011-08-14 13:17:07 +03001339int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001340{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001341 struct wl1271_cmd_set_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001342 int ret = 0;
1343
1344 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1345
1346 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1347 if (!cmd) {
1348 ret = -ENOMEM;
1349 goto out;
1350 }
1351
Eliad Pellerc690ec82011-08-14 13:17:07 +03001352 cmd->hlid = hlid;
1353 cmd->key_id = id;
1354 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001355 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001356 cmd->key_type = KEY_WEP;
1357
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001358 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001359 if (ret < 0) {
1360 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1361 goto out;
1362 }
1363
1364out:
1365 kfree(cmd);
1366
1367 return ret;
1368}
1369
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001370int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
Eliad Peller154da672011-10-05 11:55:53 +02001371 u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03001372 u8 key_size, const u8 *key, const u8 *addr,
1373 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001374{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001375 struct wl1271_cmd_set_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001376 int ret = 0;
1377
Eliad Pellerb42f0682011-08-14 13:17:24 +03001378 /* hlid might have already been deleted */
Eliad Peller154da672011-10-05 11:55:53 +02001379 if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)
Eliad Pellerb42f0682011-08-14 13:17:24 +03001380 return 0;
1381
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001382 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1383 if (!cmd) {
1384 ret = -ENOMEM;
1385 goto out;
1386 }
1387
Eliad Peller154da672011-10-05 11:55:53 +02001388 cmd->hlid = wlvif->sta.hlid;
Eliad Pellerc690ec82011-08-14 13:17:07 +03001389
1390 if (key_type == KEY_WEP)
1391 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1392 else if (is_broadcast_ether_addr(addr))
1393 cmd->lid_key_type = BROADCAST_LID_TYPE;
1394 else
1395 cmd->lid_key_type = UNICAST_LID_TYPE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001396
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001397 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001398 cmd->key_size = key_size;
1399 cmd->key_type = key_type;
1400
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001401 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1402 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03001403
Eliad Pellerc690ec82011-08-14 13:17:07 +03001404 cmd->key_id = id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001405
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001406 if (key_type == KEY_TKIP) {
1407 /*
1408 * We get the key in the following form:
1409 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1410 * but the target is expecting:
1411 * TKIP - RX MIC - TX MIC
1412 */
1413 memcpy(cmd->key, key, 16);
1414 memcpy(cmd->key + 16, key + 24, 8);
1415 memcpy(cmd->key + 24, key + 16, 8);
1416
1417 } else {
1418 memcpy(cmd->key, key, key_size);
1419 }
1420
1421 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1422
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001423 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001424 if (ret < 0) {
1425 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +02001426 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001427 }
1428
1429out:
1430 kfree(cmd);
1431
1432 return ret;
1433}
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001434
Eliad Pellerc690ec82011-08-14 13:17:07 +03001435/*
1436 * TODO: merge with sta/ibss into 1 set_key function.
1437 * note there are slight diffs
1438 */
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001439int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1440 u16 action, u8 id, u8 key_type,
1441 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1442 u16 tx_seq_16)
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001443{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001444 struct wl1271_cmd_set_keys *cmd;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001445 int ret = 0;
1446 u8 lid_type;
1447
1448 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1449 if (!cmd)
1450 return -ENOMEM;
1451
Eliad Pellera8ab39a2011-10-05 11:55:54 +02001452 if (hlid == wlvif->ap.bcast_hlid) {
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001453 if (key_type == KEY_WEP)
1454 lid_type = WEP_DEFAULT_LID_TYPE;
1455 else
1456 lid_type = BROADCAST_LID_TYPE;
1457 } else {
1458 lid_type = UNICAST_LID_TYPE;
1459 }
1460
1461 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1462 " hlid: %d", (int)action, (int)id, (int)lid_type,
1463 (int)key_type, (int)hlid);
1464
1465 cmd->lid_key_type = lid_type;
1466 cmd->hlid = hlid;
1467 cmd->key_action = cpu_to_le16(action);
1468 cmd->key_size = key_size;
1469 cmd->key_type = key_type;
1470 cmd->key_id = id;
1471 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1472 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1473
1474 if (key_type == KEY_TKIP) {
1475 /*
1476 * We get the key in the following form:
1477 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1478 * but the target is expecting:
1479 * TKIP - RX MIC - TX MIC
1480 */
1481 memcpy(cmd->key, key, 16);
1482 memcpy(cmd->key + 16, key + 24, 8);
1483 memcpy(cmd->key + 24, key + 16, 8);
1484 } else {
1485 memcpy(cmd->key, key, key_size);
1486 }
1487
1488 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1489
1490 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1491 if (ret < 0) {
1492 wl1271_warning("could not set ap keys");
1493 goto out;
1494 }
1495
1496out:
1497 kfree(cmd);
1498 return ret;
1499}
1500
Eliad Pellerd50529c2012-11-22 18:06:20 +02001501int wl12xx_cmd_set_peer_state(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1502 u8 hlid)
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001503{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001504 struct wl12xx_cmd_set_peer_state *cmd;
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001505 int ret = 0;
1506
Eliad Pellerb67476e2011-08-14 13:17:23 +03001507 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid);
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001508
1509 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1510 if (!cmd) {
1511 ret = -ENOMEM;
1512 goto out;
1513 }
1514
Eliad Pellerb67476e2011-08-14 13:17:23 +03001515 cmd->hlid = hlid;
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001516 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1517
Eliad Pellerd50529c2012-11-22 18:06:20 +02001518 /* wmm param is valid only for station role */
1519 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
1520 cmd->wmm = wlvif->wmm_enabled;
1521
Eliad Pellerc690ec82011-08-14 13:17:07 +03001522 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001523 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001524 wl1271_error("failed to send set peer state command");
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001525 goto out_free;
1526 }
1527
1528out_free:
1529 kfree(cmd);
1530
1531out:
1532 return ret;
1533}
Arik Nemtsov99d5ad72011-08-14 13:17:28 +03001534
Eliad Peller1b92f152011-10-10 10:13:09 +02001535int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1536 struct ieee80211_sta *sta, u8 hlid)
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001537{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001538 struct wl12xx_cmd_add_peer *cmd;
Eliad Peller1ec23f72011-08-25 14:26:54 +03001539 int i, ret;
Arik Nemtsov99d5ad72011-08-14 13:17:28 +03001540 u32 sta_rates;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001541
Eliad Pellerc690ec82011-08-14 13:17:07 +03001542 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001543
1544 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1545 if (!cmd) {
1546 ret = -ENOMEM;
1547 goto out;
1548 }
1549
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001550 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1551 cmd->bss_index = WL1271_AP_BSS_INDEX;
1552 cmd->aid = sta->aid;
1553 cmd->hlid = hlid;
Eliad Peller1ec23f72011-08-25 14:26:54 +03001554 cmd->sp_len = sta->max_sp;
Arik Nemtsovb4d38db2011-06-27 23:58:46 +03001555 cmd->wmm = sta->wme ? 1 : 0;
Eliad Peller978cd3a2012-11-22 18:06:21 +02001556 cmd->session_id = wl->session_ids[hlid];
Eliad Peller028e7242014-02-10 13:47:25 +02001557 cmd->role_id = wlvif->role_id;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001558
Eliad Peller1ec23f72011-08-25 14:26:54 +03001559 for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++)
1560 if (sta->wme && (sta->uapsd_queues & BIT(i)))
Yoni Divinsky2e42c202012-05-08 14:02:11 +03001561 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1562 WL1271_PSD_UPSD_TRIGGER;
Eliad Peller1ec23f72011-08-25 14:26:54 +03001563 else
Yoni Divinsky2e42c202012-05-08 14:02:11 +03001564 cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] =
1565 WL1271_PSD_LEGACY;
1566
Eliad Peller1ec23f72011-08-25 14:26:54 +03001567
Eliad Peller1b92f152011-10-10 10:13:09 +02001568 sta_rates = sta->supp_rates[wlvif->band];
Arik Nemtsov99d5ad72011-08-14 13:17:28 +03001569 if (sta->ht_cap.ht_supported)
Arik Nemtsovb3a47ee2012-05-10 12:13:33 +03001570 sta_rates |=
1571 (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) |
1572 (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET);
Arik Nemtsov99d5ad72011-08-14 13:17:28 +03001573
1574 cmd->supported_rates =
Eliad Pelleraf7fbb22011-09-19 13:51:42 +03001575 cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates,
Eliad Peller1b92f152011-10-10 10:13:09 +02001576 wlvif->band));
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001577
Guy Mishol535633a2016-06-19 17:08:58 +03001578 if (!cmd->supported_rates) {
1579 wl1271_debug(DEBUG_CMD,
1580 "peer has no supported rates yet, configuring basic rates: 0x%x",
1581 wlvif->basic_rate_set);
1582 cmd->supported_rates = cpu_to_le32(wlvif->basic_rate_set);
1583 }
1584
Eliad Peller1ec23f72011-08-25 14:26:54 +03001585 wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x",
1586 cmd->supported_rates, sta->uapsd_queues);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001587
Eliad Pellerc690ec82011-08-14 13:17:07 +03001588 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001589 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001590 wl1271_error("failed to initiate cmd add peer");
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001591 goto out_free;
1592 }
1593
1594out_free:
1595 kfree(cmd);
1596
1597out:
1598 return ret;
1599}
1600
Eliad Peller028e7242014-02-10 13:47:25 +02001601int wl12xx_cmd_remove_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif,
1602 u8 hlid)
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001603{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001604 struct wl12xx_cmd_remove_peer *cmd;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001605 int ret;
Eyal Shapira6c15c1a2012-06-26 10:41:16 +03001606 bool timeout = false;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001607
Eliad Pellerc690ec82011-08-14 13:17:07 +03001608 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001609
1610 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1611 if (!cmd) {
1612 ret = -ENOMEM;
1613 goto out;
1614 }
1615
1616 cmd->hlid = hlid;
1617 /* We never send a deauth, mac80211 is in charge of this */
1618 cmd->reason_opcode = 0;
1619 cmd->send_deauth_flag = 0;
Eliad Peller028e7242014-02-10 13:47:25 +02001620 cmd->role_id = wlvif->role_id;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001621
Eliad Pellerc690ec82011-08-14 13:17:07 +03001622 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001623 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001624 wl1271_error("failed to initiate cmd remove peer");
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001625 goto out_free;
1626 }
1627
Eliad Pellerc50a2822012-11-22 18:06:19 +02001628 ret = wl->ops->wait_for_event(wl,
1629 WLCORE_EVENT_PEER_REMOVE_COMPLETE,
1630 &timeout);
1631
Arik Nemtsov05285cf2010-11-12 17:15:03 +02001632 /*
1633 * We are ok with a timeout here. The event is sometimes not sent
Eyal Shapira6c15c1a2012-06-26 10:41:16 +03001634 * due to a firmware bug. In case of another error (like SDIO timeout)
1635 * queue a recovery.
Arik Nemtsov05285cf2010-11-12 17:15:03 +02001636 */
Eyal Shapira6c15c1a2012-06-26 10:41:16 +03001637 if (ret)
1638 wl12xx_queue_recovery_work(wl);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001639
1640out_free:
1641 kfree(cmd);
1642
1643out:
1644 return ret;
1645}
Ido Yariv95dac04f2011-06-06 14:57:06 +03001646
Johannes Berg57fbcce2016-04-12 15:56:15 +02001647static int wlcore_get_reg_conf_ch_idx(enum nl80211_band band, u16 ch)
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001648{
Eliad Peller49540d12013-09-17 18:41:27 +03001649 /*
1650 * map the given band/channel to the respective predefined
1651 * bit expected by the fw
1652 */
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001653 switch (band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02001654 case NL80211_BAND_2GHZ:
Eliad Peller49540d12013-09-17 18:41:27 +03001655 /* channels 1..14 are mapped to 0..13 */
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001656 if (ch >= 1 && ch <= 14)
Eliad Peller49540d12013-09-17 18:41:27 +03001657 return ch - 1;
1658 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001659 case NL80211_BAND_5GHZ:
Eliad Peller49540d12013-09-17 18:41:27 +03001660 switch (ch) {
1661 case 8 ... 16:
1662 /* channels 8,12,16 are mapped to 18,19,20 */
1663 return 18 + (ch-8)/4;
1664 case 34 ... 48:
1665 /* channels 34,36..48 are mapped to 21..28 */
1666 return 21 + (ch-34)/2;
1667 case 52 ... 64:
1668 /* channels 52,56..64 are mapped to 29..32 */
1669 return 29 + (ch-52)/4;
1670 case 100 ... 140:
1671 /* channels 100,104..140 are mapped to 33..43 */
1672 return 33 + (ch-100)/4;
1673 case 149 ... 165:
1674 /* channels 149,153..165 are mapped to 44..48 */
1675 return 44 + (ch-149)/4;
1676 default:
1677 break;
1678 }
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001679 break;
1680 default:
Eliad Peller49540d12013-09-17 18:41:27 +03001681 break;
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001682 }
1683
Eliad Peller49540d12013-09-17 18:41:27 +03001684 wl1271_error("%s: unknown band/channel: %d/%d", __func__, band, ch);
1685 return -1;
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001686}
1687
1688void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel,
Johannes Berg57fbcce2016-04-12 15:56:15 +02001689 enum nl80211_band band)
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001690{
1691 int ch_bit_idx = 0;
1692
1693 if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF))
1694 return;
1695
1696 ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel);
1697
Eliad Peller49540d12013-09-17 18:41:27 +03001698 if (ch_bit_idx >= 0 && ch_bit_idx <= WL1271_MAX_CHANNELS)
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001699 set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending);
1700}
1701
1702int wlcore_cmd_regdomain_config_locked(struct wl1271 *wl)
1703{
1704 struct wl12xx_cmd_regdomain_dfs_config *cmd = NULL;
1705 int ret = 0, i, b, ch_bit_idx;
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001706 u32 tmp_ch_bitmap[2];
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001707 struct wiphy *wiphy = wl->hw->wiphy;
1708 struct ieee80211_supported_band *band;
1709 bool timeout = false;
1710
1711 if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF))
1712 return 0;
1713
1714 wl1271_debug(DEBUG_CMD, "cmd reg domain config");
1715
1716 memset(tmp_ch_bitmap, 0, sizeof(tmp_ch_bitmap));
1717
Johannes Berg57fbcce2016-04-12 15:56:15 +02001718 for (b = NL80211_BAND_2GHZ; b <= NL80211_BAND_5GHZ; b++) {
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001719 band = wiphy->bands[b];
1720 for (i = 0; i < band->n_channels; i++) {
Eliad Peller4ce9fad2014-12-29 08:24:11 +02001721 struct ieee80211_channel *channel = &band->channels[i];
1722 u16 ch = channel->hw_value;
1723 u32 flags = channel->flags;
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001724
Eliad Peller4ce9fad2014-12-29 08:24:11 +02001725 if (flags & (IEEE80211_CHAN_DISABLED |
1726 IEEE80211_CHAN_NO_IR))
1727 continue;
1728
1729 if ((flags & IEEE80211_CHAN_RADAR) &&
1730 channel->dfs_state != NL80211_DFS_AVAILABLE)
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001731 continue;
1732
1733 ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch);
1734 if (ch_bit_idx < 0)
1735 continue;
1736
1737 set_bit(ch_bit_idx, (long *)tmp_ch_bitmap);
1738 }
1739 }
1740
1741 tmp_ch_bitmap[0] |= wl->reg_ch_conf_pending[0];
1742 tmp_ch_bitmap[1] |= wl->reg_ch_conf_pending[1];
1743
1744 if (!memcmp(tmp_ch_bitmap, wl->reg_ch_conf_last, sizeof(tmp_ch_bitmap)))
1745 goto out;
1746
1747 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1748 if (!cmd) {
1749 ret = -ENOMEM;
1750 goto out;
1751 }
1752
1753 cmd->ch_bit_map1 = cpu_to_le32(tmp_ch_bitmap[0]);
1754 cmd->ch_bit_map2 = cpu_to_le32(tmp_ch_bitmap[1]);
Guy Mishol1cd91b22014-12-29 08:24:12 +02001755 cmd->dfs_region = wl->dfs_region;
Victor Goldenshtein6b70e7e2012-11-25 18:26:59 +02001756
1757 wl1271_debug(DEBUG_CMD,
1758 "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x",
1759 cmd->ch_bit_map1, cmd->ch_bit_map2);
1760
1761 ret = wl1271_cmd_send(wl, CMD_DFS_CHANNEL_CONFIG, cmd, sizeof(*cmd), 0);
1762 if (ret < 0) {
1763 wl1271_error("failed to send reg domain dfs config");
1764 goto out;
1765 }
1766
1767 ret = wl->ops->wait_for_event(wl,
1768 WLCORE_EVENT_DFS_CONFIG_COMPLETE,
1769 &timeout);
1770 if (ret < 0 || timeout) {
1771 wl1271_error("reg domain conf %serror",
1772 timeout ? "completion " : "");
1773 ret = timeout ? -ETIMEDOUT : ret;
1774 goto out;
1775 }
1776
1777 memcpy(wl->reg_ch_conf_last, tmp_ch_bitmap, sizeof(tmp_ch_bitmap));
1778 memset(wl->reg_ch_conf_pending, 0, sizeof(wl->reg_ch_conf_pending));
1779
1780out:
1781 kfree(cmd);
1782 return ret;
1783}
1784
Ido Yariv95dac04f2011-06-06 14:57:06 +03001785int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1786{
1787 struct wl12xx_cmd_config_fwlog *cmd;
1788 int ret = 0;
1789
1790 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1791
1792 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1793 if (!cmd) {
1794 ret = -ENOMEM;
1795 goto out;
1796 }
1797
1798 cmd->logger_mode = wl->conf.fwlog.mode;
1799 cmd->log_severity = wl->conf.fwlog.severity;
1800 cmd->timestamp = wl->conf.fwlog.timestamp;
1801 cmd->output = wl->conf.fwlog.output;
1802 cmd->threshold = wl->conf.fwlog.threshold;
1803
1804 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1805 if (ret < 0) {
1806 wl1271_error("failed to send config firmware logger command");
1807 goto out_free;
1808 }
1809
1810out_free:
1811 kfree(cmd);
1812
1813out:
1814 return ret;
1815}
1816
1817int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1818{
1819 struct wl12xx_cmd_start_fwlog *cmd;
1820 int ret = 0;
1821
1822 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1823
1824 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1825 if (!cmd) {
1826 ret = -ENOMEM;
1827 goto out;
1828 }
1829
1830 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1831 if (ret < 0) {
1832 wl1271_error("failed to send start firmware logger command");
1833 goto out_free;
1834 }
1835
1836out_free:
1837 kfree(cmd);
1838
1839out:
1840 return ret;
1841}
1842
1843int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1844{
1845 struct wl12xx_cmd_stop_fwlog *cmd;
1846 int ret = 0;
1847
1848 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1849
1850 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1851 if (!cmd) {
1852 ret = -ENOMEM;
1853 goto out;
1854 }
1855
1856 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1857 if (ret < 0) {
1858 wl1271_error("failed to send stop firmware logger command");
1859 goto out_free;
1860 }
1861
1862out_free:
1863 kfree(cmd);
1864
1865out:
1866 return ret;
1867}
Eliad Pellera7cba382011-08-14 13:17:16 +03001868
Eliad Peller1b92f152011-10-10 10:13:09 +02001869static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif,
Johannes Berg57fbcce2016-04-12 15:56:15 +02001870 u8 role_id, enum nl80211_band band, u8 channel)
Eliad Pellera7cba382011-08-14 13:17:16 +03001871{
1872 struct wl12xx_cmd_roc *cmd;
1873 int ret = 0;
1874
Eliad Pellerdabf37d2012-11-20 13:20:03 +02001875 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", channel, role_id);
Eliad Pellera7cba382011-08-14 13:17:16 +03001876
1877 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1878 return -EINVAL;
1879
1880 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1881 if (!cmd) {
1882 ret = -ENOMEM;
1883 goto out;
1884 }
1885
1886 cmd->role_id = role_id;
Eliad Pellerdabf37d2012-11-20 13:20:03 +02001887 cmd->channel = channel;
1888 switch (band) {
Johannes Berg57fbcce2016-04-12 15:56:15 +02001889 case NL80211_BAND_2GHZ:
Luciano Coelho00782132011-11-29 13:38:37 +02001890 cmd->band = WLCORE_BAND_2_4GHZ;
Eliad Pellera7cba382011-08-14 13:17:16 +03001891 break;
Johannes Berg57fbcce2016-04-12 15:56:15 +02001892 case NL80211_BAND_5GHZ:
Luciano Coelho00782132011-11-29 13:38:37 +02001893 cmd->band = WLCORE_BAND_5GHZ;
Eliad Pellera7cba382011-08-14 13:17:16 +03001894 break;
1895 default:
Eliad Peller1b92f152011-10-10 10:13:09 +02001896 wl1271_error("roc - unknown band: %d", (int)wlvif->band);
Eliad Pellera7cba382011-08-14 13:17:16 +03001897 ret = -EINVAL;
1898 goto out_free;
1899 }
1900
1901
1902 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1903 if (ret < 0) {
1904 wl1271_error("failed to send ROC command");
1905 goto out_free;
1906 }
1907
1908out_free:
1909 kfree(cmd);
1910
1911out:
1912 return ret;
1913}
1914
1915static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1916{
1917 struct wl12xx_cmd_croc *cmd;
1918 int ret = 0;
1919
1920 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1921
1922 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1923 if (!cmd) {
1924 ret = -ENOMEM;
1925 goto out;
1926 }
1927 cmd->role_id = role_id;
1928
1929 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1930 sizeof(*cmd), 0);
1931 if (ret < 0) {
1932 wl1271_error("failed to send ROC command");
1933 goto out_free;
1934 }
1935
1936out_free:
1937 kfree(cmd);
1938
1939out:
1940 return ret;
1941}
Eliad Peller251c1772011-08-14 13:17:17 +03001942
Eliad Pellerdabf37d2012-11-20 13:20:03 +02001943int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id,
Johannes Berg57fbcce2016-04-12 15:56:15 +02001944 enum nl80211_band band, u8 channel)
Eliad Peller251c1772011-08-14 13:17:17 +03001945{
1946 int ret = 0;
1947
1948 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1949 return 0;
1950
Eliad Pellerdabf37d2012-11-20 13:20:03 +02001951 ret = wl12xx_cmd_roc(wl, wlvif, role_id, band, channel);
Eliad Peller251c1772011-08-14 13:17:17 +03001952 if (ret < 0)
1953 goto out;
1954
Eliad Peller251c1772011-08-14 13:17:17 +03001955 __set_bit(role_id, wl->roc_map);
1956out:
1957 return ret;
1958}
1959
1960int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1961{
1962 int ret = 0;
1963
1964 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1965 return 0;
1966
1967 ret = wl12xx_cmd_croc(wl, role_id);
1968 if (ret < 0)
1969 goto out;
1970
1971 __clear_bit(role_id, wl->roc_map);
Arik Nemtsov55df5af2012-03-03 22:18:00 +02001972
1973 /*
1974 * Rearm the tx watchdog when removing the last ROC. This prevents
1975 * recoveries due to just finished ROCs - when Tx hasn't yet had
1976 * a chance to get out.
1977 */
1978 if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES)
1979 wl12xx_rearm_tx_watchdog_locked(wl);
Eliad Peller251c1772011-08-14 13:17:17 +03001980out:
1981 return ret;
1982}
Shahar Levi6d158ff2011-09-08 13:01:33 +03001983
Eliad Pellerfcab1892012-11-22 18:06:18 +02001984int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl, struct wl12xx_vif *wlvif)
Shahar Levi6d158ff2011-09-08 13:01:33 +03001985{
1986 struct wl12xx_cmd_stop_channel_switch *cmd;
1987 int ret;
1988
1989 wl1271_debug(DEBUG_ACX, "cmd stop channel switch");
1990
1991 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1992 if (!cmd) {
1993 ret = -ENOMEM;
1994 goto out;
1995 }
1996
Eliad Pellerfcab1892012-11-22 18:06:18 +02001997 cmd->role_id = wlvif->role_id;
1998
Shahar Levi6d158ff2011-09-08 13:01:33 +03001999 ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0);
2000 if (ret < 0) {
2001 wl1271_error("failed to stop channel switch command");
2002 goto out_free;
2003 }
2004
2005out_free:
2006 kfree(cmd);
2007
2008out:
2009 return ret;
2010}
Eliad Peller679a6732011-10-11 11:55:44 +02002011
2012/* start dev role and roc on its channel */
Eliad Pellerdabf37d2012-11-20 13:20:03 +02002013int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif,
Johannes Berg57fbcce2016-04-12 15:56:15 +02002014 enum nl80211_band band, int channel)
Eliad Peller679a6732011-10-11 11:55:44 +02002015{
2016 int ret;
2017
2018 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
2019 wlvif->bss_type == BSS_TYPE_IBSS)))
2020 return -EINVAL;
2021
Eliad Peller7845af32015-07-30 22:38:22 +03002022 /* the dev role is already started for p2p mgmt interfaces */
2023 if (!wlcore_is_p2p_mgmt(wlvif)) {
2024 ret = wl12xx_cmd_role_enable(wl,
2025 wl12xx_wlvif_to_vif(wlvif)->addr,
2026 WL1271_ROLE_DEVICE,
2027 &wlvif->dev_role_id);
2028 if (ret < 0)
2029 goto out;
2030 }
Eliad Peller679a6732011-10-11 11:55:44 +02002031
Eliad Pellerdabf37d2012-11-20 13:20:03 +02002032 ret = wl12xx_cmd_role_start_dev(wl, wlvif, band, channel);
Eliad Peller889300f2012-07-26 17:17:06 +03002033 if (ret < 0)
2034 goto out_disable;
2035
Eliad Pellerdabf37d2012-11-20 13:20:03 +02002036 ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id, band, channel);
Eliad Peller679a6732011-10-11 11:55:44 +02002037 if (ret < 0)
2038 goto out_stop;
2039
2040 return 0;
2041
2042out_stop:
2043 wl12xx_cmd_role_stop_dev(wl, wlvif);
Eliad Peller889300f2012-07-26 17:17:06 +03002044out_disable:
Eliad Peller7845af32015-07-30 22:38:22 +03002045 if (!wlcore_is_p2p_mgmt(wlvif))
2046 wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
Eliad Peller679a6732011-10-11 11:55:44 +02002047out:
2048 return ret;
2049}
2050
2051/* croc dev hlid, and stop the role */
2052int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif)
2053{
2054 int ret;
2055
2056 if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS ||
2057 wlvif->bss_type == BSS_TYPE_IBSS)))
2058 return -EINVAL;
2059
Eliad Peller8aefffe2011-12-18 20:25:42 +02002060 /* flush all pending packets */
Ido Yariveb96f842012-06-18 13:21:55 +03002061 ret = wlcore_tx_work_locked(wl);
2062 if (ret < 0)
2063 goto out;
Eliad Peller8aefffe2011-12-18 20:25:42 +02002064
Eliad Peller679a6732011-10-11 11:55:44 +02002065 if (test_bit(wlvif->dev_role_id, wl->roc_map)) {
2066 ret = wl12xx_croc(wl, wlvif->dev_role_id);
2067 if (ret < 0)
2068 goto out;
2069 }
2070
2071 ret = wl12xx_cmd_role_stop_dev(wl, wlvif);
2072 if (ret < 0)
2073 goto out;
Eliad Peller889300f2012-07-26 17:17:06 +03002074
Eliad Peller7845af32015-07-30 22:38:22 +03002075 if (!wlcore_is_p2p_mgmt(wlvif)) {
2076 ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id);
2077 if (ret < 0)
2078 goto out;
2079 }
Eliad Peller889300f2012-07-26 17:17:06 +03002080
Eliad Peller679a6732011-10-11 11:55:44 +02002081out:
2082 return ret;
2083}
Eliad Pellerc32e35f2015-07-30 22:38:21 +03002084
2085int wlcore_cmd_generic_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif,
2086 u8 feature, u8 enable, u8 value)
2087{
2088 struct wlcore_cmd_generic_cfg *cmd;
2089 int ret;
2090
2091 wl1271_debug(DEBUG_CMD,
2092 "cmd generic cfg (role %d feature %d enable %d value %d)",
2093 wlvif->role_id, feature, enable, value);
2094
2095 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
2096 if (!cmd)
2097 return -ENOMEM;
2098
2099 cmd->role_id = wlvif->role_id;
2100 cmd->feature = feature;
2101 cmd->enable = enable;
2102 cmd->value = value;
2103
2104 ret = wl1271_cmd_send(wl, CMD_GENERIC_CFG, cmd, sizeof(*cmd), 0);
2105 if (ret < 0) {
2106 wl1271_error("failed to send generic cfg command");
2107 goto out_free;
2108 }
2109out_free:
2110 kfree(cmd);
2111 return ret;
2112}
2113EXPORT_SYMBOL_GPL(wlcore_cmd_generic_cfg);