blob: f11f9f47ffd5d245a1182bac23c409f976cec8b7 [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>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28#include <linux/etherdevice.h>
Kalle Valo023e0822010-03-18 12:26:36 +020029#include <linux/ieee80211.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030030
31#include "wl1271.h"
32#include "wl1271_reg.h"
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020033#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030034#include "wl1271_acx.h"
35#include "wl12xx_80211.h"
36#include "wl1271_cmd.h"
Luciano Coelho99d84c12010-03-26 12:53:20 +020037#include "wl1271_event.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030038
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020039#define WL1271_CMD_POLL_COUNT 5
40
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030041/*
42 * send command to firmware
43 *
44 * @wl: wl struct
45 * @id: command id
46 * @buf: buffer containing the command, must work with dma
47 * @len: length of the buffer
48 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020049int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
50 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030051{
52 struct wl1271_cmd_header *cmd;
53 unsigned long timeout;
54 u32 intr;
55 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020056 u16 status;
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020057 u16 poll_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030058
59 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030060 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030061 cmd->status = 0;
62
63 WARN_ON(len % 4 != 0);
64
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020065 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030066
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020067 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030068
69 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
70
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020071 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030072 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
73 if (time_after(jiffies, timeout)) {
74 wl1271_error("command complete timeout");
75 ret = -ETIMEDOUT;
76 goto out;
77 }
78
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020079 udelay(10);
80 poll_count++;
81 if (poll_count == WL1271_CMD_POLL_COUNT)
82 wl1271_info("cmd polling took over %d cycles",
83 poll_count);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030084
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020085 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030086 }
87
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020088 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020089 if (res_len == 0)
90 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020091 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020092
Juuso Oikarinenad150e92009-11-02 20:22:12 +020093 status = le16_to_cpu(cmd->status);
94 if (status != CMD_STATUS_SUCCESS) {
95 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020096 ret = -EIO;
97 }
98
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020099 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
100 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300101
102out:
103 return ret;
104}
105
Luciano Coelho938e30c2009-10-15 10:33:27 +0300106static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300107{
108 struct wl1271_cmd_cal_channel_tune *cmd;
109 int ret = 0;
110
111 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
112 if (!cmd)
113 return -ENOMEM;
114
115 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
116
117 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
118 /* set up any channel, 7 is in the middle of the range */
119 cmd->channel = 7;
120
121 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
122 if (ret < 0)
123 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
124
125 kfree(cmd);
126 return ret;
127}
128
Luciano Coelho938e30c2009-10-15 10:33:27 +0300129static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300130{
131 struct wl1271_cmd_cal_update_ref_point *cmd;
132 int ret = 0;
133
134 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
135 if (!cmd)
136 return -ENOMEM;
137
138 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
139
140 /* FIXME: still waiting for the correct values */
141 cmd->ref_power = 0;
142 cmd->ref_detector = 0;
143
144 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
145
146 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
147 if (ret < 0)
148 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
149
150 kfree(cmd);
151 return ret;
152}
153
Luciano Coelho938e30c2009-10-15 10:33:27 +0300154static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300155{
156 struct wl1271_cmd_cal_p2g *cmd;
157 int ret = 0;
158
159 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
160 if (!cmd)
161 return -ENOMEM;
162
163 cmd->test.id = TEST_CMD_P2G_CAL;
164
165 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
166
167 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
168 if (ret < 0)
169 wl1271_warning("TEST_CMD_P2G_CAL failed");
170
171 kfree(cmd);
172 return ret;
173}
174
Luciano Coelho938e30c2009-10-15 10:33:27 +0300175static int wl1271_cmd_cal(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300176{
177 /*
178 * FIXME: we must make sure that we're not sleeping when calibration
179 * is done
180 */
181 int ret;
182
183 wl1271_notice("performing tx calibration");
184
185 ret = wl1271_cmd_cal_channel_tune(wl);
186 if (ret < 0)
187 return ret;
188
189 ret = wl1271_cmd_cal_update_ref_point(wl);
190 if (ret < 0)
191 return ret;
192
193 ret = wl1271_cmd_cal_p2g(wl);
194 if (ret < 0)
195 return ret;
196
197 return ret;
198}
199
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200200int wl1271_cmd_general_parms(struct wl1271 *wl)
201{
202 struct wl1271_general_parms_cmd *gen_parms;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200203 int ret;
204
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200205 if (!wl->nvs)
206 return -ENODEV;
207
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200208 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
209 if (!gen_parms)
210 return -ENOMEM;
211
212 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
213
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200214 memcpy(gen_parms->params, wl->nvs->general_params,
215 WL1271_NVS_GENERAL_PARAMS_SIZE);
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200216
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200217 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
218 if (ret < 0)
219 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
220
221 kfree(gen_parms);
222 return ret;
223}
224
225int wl1271_cmd_radio_parms(struct wl1271 *wl)
226{
227 struct wl1271_radio_parms_cmd *radio_parms;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200228 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
229 int ret;
230
231 if (!wl->nvs)
232 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200233
234 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
235 if (!radio_parms)
236 return -ENOMEM;
237
238 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
239
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200240 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
241 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
242 memcpy(radio_parms->dyn_radio_params,
243 wl->nvs->dyn_radio_params[rparam->fem],
244 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200245
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200246 /* FIXME: current NVS is missing 5GHz parameters */
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200247
248 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
249 radio_parms, sizeof(*radio_parms));
250
251 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
252 if (ret < 0)
253 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
254
255 kfree(radio_parms);
256 return ret;
257}
258
Luciano Coelho99d84c12010-03-26 12:53:20 +0200259/*
260 * Poll the mailbox event field until any of the bits in the mask is set or a
261 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
262 */
263static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
264{
265 u32 events_vector, event;
266 unsigned long timeout;
267
268 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
269
270 do {
271 if (time_after(jiffies, timeout))
272 return -ETIMEDOUT;
273
274 msleep(1);
275
276 /* read from both event fields */
277 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
278 sizeof(events_vector), false);
279 event = events_vector & mask;
280 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
281 sizeof(events_vector), false);
282 event |= events_vector & mask;
283 } while (!event);
284
285 return 0;
286}
287
Juuso Oikarinen15305492010-02-22 08:38:32 +0200288int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300289{
290 static bool do_cal = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300291 struct wl1271_cmd_join *join;
292 int ret, i;
293 u8 *bssid;
294
295 /* FIXME: remove when we get calibration from the factory */
296 if (do_cal) {
297 ret = wl1271_cmd_cal(wl);
298 if (ret < 0)
299 wl1271_warning("couldn't calibrate");
300 else
301 do_cal = false;
302 }
303
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300304 join = kzalloc(sizeof(*join), GFP_KERNEL);
305 if (!join) {
306 ret = -ENOMEM;
307 goto out;
308 }
309
310 wl1271_debug(DEBUG_CMD, "cmd join");
311
312 /* Reverse order BSSID */
313 bssid = (u8 *) &join->bssid_lsb;
314 for (i = 0; i < ETH_ALEN; i++)
315 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
316
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300317 join->rx_config_options = cpu_to_le32(wl->rx_config);
318 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200319 join->bss_type = bss_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300320
Teemu Paasikivia4102642009-10-13 12:47:51 +0300321 if (wl->band == IEEE80211_BAND_2GHZ)
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300322 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS |
323 CONF_HW_BIT_RATE_2MBPS |
324 CONF_HW_BIT_RATE_5_5MBPS |
325 CONF_HW_BIT_RATE_11MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300326 else {
327 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300328 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS |
329 CONF_HW_BIT_RATE_12MBPS |
330 CONF_HW_BIT_RATE_24MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300331 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300332
Juuso Oikarinen60e84c22010-03-26 12:53:25 +0200333 join->beacon_interval = cpu_to_le16(wl->beacon_int);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300334 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300335
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300336 join->channel = wl->channel;
337 join->ssid_len = wl->ssid_len;
338 memcpy(join->ssid, wl->ssid, wl->ssid_len);
339 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
340
341 /* increment the session counter */
342 wl->session_counter++;
343 if (wl->session_counter >= SESSION_COUNTER_MAX)
344 wl->session_counter = 0;
345
346 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
347
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300348 /* reset TX security counters */
349 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200350 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300351
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200352 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300353 if (ret < 0) {
354 wl1271_error("failed to initiate cmd join");
355 goto out_free;
356 }
357
Luciano Coelho99d84c12010-03-26 12:53:20 +0200358 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
359 if (ret < 0)
360 wl1271_error("cmd join event completion error");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300361
362out_free:
363 kfree(join);
364
365out:
366 return ret;
367}
368
369/**
370 * send test command to firmware
371 *
372 * @wl: wl struct
373 * @buf: buffer containing the command, with all headers, must work with dma
374 * @len: length of the buffer
375 * @answer: is answer needed
376 */
377int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
378{
379 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200380 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300381
382 wl1271_debug(DEBUG_CMD, "cmd test");
383
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200384 if (answer)
385 res_len = buf_len;
386
387 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300388
389 if (ret < 0) {
390 wl1271_warning("TEST command failed");
391 return ret;
392 }
393
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200394 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395}
396
397/**
398 * read acx from firmware
399 *
400 * @wl: wl struct
401 * @id: acx id
402 * @buf: buffer for the response, including all headers, must work with dma
403 * @len: lenght of buf
404 */
405int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
406{
407 struct acx_header *acx = buf;
408 int ret;
409
410 wl1271_debug(DEBUG_CMD, "cmd interrogate");
411
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300412 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300413
414 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300415 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300416
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200417 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
418 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300419 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300420
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300421 return ret;
422}
423
424/**
425 * write acx value to firmware
426 *
427 * @wl: wl struct
428 * @id: acx id
429 * @buf: buffer containing acx, including all headers, must work with dma
430 * @len: length of buf
431 */
432int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
433{
434 struct acx_header *acx = buf;
435 int ret;
436
437 wl1271_debug(DEBUG_CMD, "cmd configure");
438
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300439 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300440
441 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300442 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300443
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200444 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300445 if (ret < 0) {
446 wl1271_warning("CONFIGURE command NOK");
447 return ret;
448 }
449
450 return 0;
451}
452
Luciano Coelho94210892009-12-11 15:40:55 +0200453int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300454{
455 struct cmd_enabledisable_path *cmd;
456 int ret;
457 u16 cmd_rx, cmd_tx;
458
459 wl1271_debug(DEBUG_CMD, "cmd data path");
460
461 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
462 if (!cmd) {
463 ret = -ENOMEM;
464 goto out;
465 }
466
Luciano Coelho94210892009-12-11 15:40:55 +0200467 /* the channel here is only used for calibration, so hardcoded to 1 */
468 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300469
470 if (enable) {
471 cmd_rx = CMD_ENABLE_RX;
472 cmd_tx = CMD_ENABLE_TX;
473 } else {
474 cmd_rx = CMD_DISABLE_RX;
475 cmd_tx = CMD_DISABLE_TX;
476 }
477
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200478 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300479 if (ret < 0) {
480 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200481 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300482 goto out;
483 }
484
485 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200486 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300487
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200488 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300489 if (ret < 0) {
490 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200491 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200492 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300493 }
494
495 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200496 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300497
498out:
499 kfree(cmd);
500 return ret;
501}
502
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200503int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300504{
505 struct wl1271_cmd_ps_params *ps_params = NULL;
506 int ret = 0;
507
508 /* FIXME: this should be in ps.c */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300509 ret = wl1271_acx_wake_up_conditions(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300510 if (ret < 0) {
511 wl1271_error("couldn't set wake up conditions");
512 goto out;
513 }
514
515 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
516
517 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
518 if (!ps_params) {
519 ret = -ENOMEM;
520 goto out;
521 }
522
523 ps_params->ps_mode = ps_mode;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200524 ps_params->send_null_data = send;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300525 ps_params->retries = 5;
526 ps_params->hang_over_period = 128;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300527 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300528
529 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200530 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300531 if (ret < 0) {
532 wl1271_error("cmd set_ps_mode failed");
533 goto out;
534 }
535
536out:
537 kfree(ps_params);
538 return ret;
539}
540
541int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
542 size_t len)
543{
544 struct cmd_read_write_memory *cmd;
545 int ret = 0;
546
547 wl1271_debug(DEBUG_CMD, "cmd read memory");
548
549 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
550 if (!cmd) {
551 ret = -ENOMEM;
552 goto out;
553 }
554
555 WARN_ON(len > MAX_READ_SIZE);
556 len = min_t(size_t, len, MAX_READ_SIZE);
557
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300558 cmd->addr = cpu_to_le32(addr);
559 cmd->size = cpu_to_le32(len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300560
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200561 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
562 sizeof(*cmd));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300563 if (ret < 0) {
564 wl1271_error("read memory command failed: %d", ret);
565 goto out;
566 }
567
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200568 /* the read command got in */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300569 memcpy(answer, cmd->value, len);
570
571out:
572 kfree(cmd);
573 return ret;
574}
575
Kalle Valo818e3062010-03-18 12:26:35 +0200576int wl1271_cmd_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
577 const u8 *ie, size_t ie_len, u8 active_scan,
578 u8 high_prio, u8 band, u8 probe_requests)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300579{
580
581 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
582 struct wl1271_cmd_scan *params = NULL;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300583 struct ieee80211_channel *channels;
584 int i, j, n_ch, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300585 u16 scan_options = 0;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300586 u8 ieee_band;
587
588 if (band == WL1271_SCAN_BAND_2_4_GHZ)
589 ieee_band = IEEE80211_BAND_2GHZ;
590 else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled())
591 ieee_band = IEEE80211_BAND_2GHZ;
592 else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled())
593 ieee_band = IEEE80211_BAND_5GHZ;
594 else
595 return -EINVAL;
596
597 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
598 return -EINVAL;
599
600 channels = wl->hw->wiphy->bands[ieee_band]->channels;
601 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300602
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200603 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300604 return -EINVAL;
605
606 params = kzalloc(sizeof(*params), GFP_KERNEL);
607 if (!params)
608 return -ENOMEM;
609
610 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
611 params->params.rx_filter_options =
612 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
613
614 if (!active_scan)
615 scan_options |= WL1271_SCAN_OPT_PASSIVE;
616 if (high_prio)
617 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300618 params->params.scan_options = cpu_to_le16(scan_options);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300619
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300620 params->params.num_probe_requests = probe_requests;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300621 /* Let the fw autodetect suitable tx_rate for probes */
622 params->params.tx_rate = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300623 params->params.tid_trigger = 0;
624 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
625
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300626 if (band == WL1271_SCAN_BAND_DUAL)
627 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
628 else
629 params->params.band = band;
630
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300631 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
632 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
633 params->channels[j].min_duration =
634 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
635 params->channels[j].max_duration =
636 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
637 memset(&params->channels[j].bssid_lsb, 0xff, 4);
638 memset(&params->channels[j].bssid_msb, 0xff, 2);
639 params->channels[j].early_termination = 0;
640 params->channels[j].tx_power_att =
641 WL1271_SCAN_CURRENT_TX_PWR;
642 params->channels[j].channel = channels[i].hw_value;
643 j++;
644 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300645 }
646
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300647 params->params.num_channels = j;
648
Kalle Valo818e3062010-03-18 12:26:35 +0200649 if (ssid_len && ssid) {
650 params->params.ssid_len = ssid_len;
651 memcpy(params->params.ssid, ssid, ssid_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300652 }
653
Kalle Valo818e3062010-03-18 12:26:35 +0200654 ret = wl1271_cmd_build_probe_req(wl, ssid, ssid_len,
655 ie, ie_len, ieee_band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300656 if (ret < 0) {
657 wl1271_error("PROBE request template failed");
658 goto out;
659 }
660
661 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
662 if (!trigger) {
663 ret = -ENOMEM;
664 goto out;
665 }
666
667 /* disable the timeout */
668 trigger->timeout = 0;
669
670 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200671 sizeof(*trigger), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300672 if (ret < 0) {
673 wl1271_error("trigger scan to failed for hw scan");
674 goto out;
675 }
676
677 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
678
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200679 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300680 if (wl1271_11a_enabled()) {
681 wl->scan.state = band;
682 if (band == WL1271_SCAN_BAND_DUAL) {
683 wl->scan.active = active_scan;
684 wl->scan.high_prio = high_prio;
685 wl->scan.probe_requests = probe_requests;
Kalle Valo818e3062010-03-18 12:26:35 +0200686 if (ssid_len && ssid) {
687 wl->scan.ssid_len = ssid_len;
688 memcpy(wl->scan.ssid, ssid, ssid_len);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300689 } else
690 wl->scan.ssid_len = 0;
691 }
692 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300693
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200694 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300695 if (ret < 0) {
696 wl1271_error("SCAN failed");
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200697 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300698 goto out;
699 }
700
701out:
702 kfree(params);
Juuso Oikarinen9cea4612010-03-26 12:53:14 +0200703 kfree(trigger);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300704 return ret;
705}
706
707int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200708 void *buf, size_t buf_len, int index)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300709{
710 struct wl1271_cmd_template_set *cmd;
711 int ret = 0;
712
713 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
714
715 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
716 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
717
718 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
719 if (!cmd) {
720 ret = -ENOMEM;
721 goto out;
722 }
723
724 cmd->len = cpu_to_le16(buf_len);
725 cmd->template_type = template_id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300726 cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300727 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
728 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200729 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300730
731 if (buf)
732 memcpy(cmd->template_data, buf, buf_len);
733
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200734 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300735 if (ret < 0) {
736 wl1271_warning("cmd set_template failed: %d", ret);
737 goto out_free;
738 }
739
740out_free:
741 kfree(cmd);
742
743out:
744 return ret;
745}
746
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300747int wl1271_cmd_build_null_data(struct wl1271 *wl)
748{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200749 struct sk_buff *skb = NULL;
750 int size;
751 void *ptr;
752 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300753
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300754
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200755 if (wl->bss_type == BSS_TYPE_IBSS) {
756 size = sizeof(struct wl12xx_null_data_template);
757 ptr = NULL;
758 } else {
759 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
760 if (!skb)
761 goto out;
762 size = skb->len;
763 ptr = skb->data;
764 }
765
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200766 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300767
Kalle Valo899e6e62010-03-18 12:26:34 +0200768out:
769 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200770 if (ret)
771 wl1271_warning("cmd buld null data failed %d", ret);
772
Kalle Valo899e6e62010-03-18 12:26:34 +0200773 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300774
775}
776
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200777int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
778{
779 struct sk_buff *skb = NULL;
780 int ret = -ENOMEM;
781
782 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
783 if (!skb)
784 goto out;
785
786 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
787 skb->data, skb->len,
788 CMD_TEMPL_KLV_IDX_NULL_DATA);
789
790out:
791 dev_kfree_skb(skb);
792 if (ret)
793 wl1271_warning("cmd build klv null data failed %d", ret);
794
795 return ret;
796
797}
798
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300799int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
800{
Kalle Valo899e6e62010-03-18 12:26:34 +0200801 struct sk_buff *skb;
802 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300803
Kalle Valo899e6e62010-03-18 12:26:34 +0200804 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
805 if (!skb)
806 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300807
Kalle Valo899e6e62010-03-18 12:26:34 +0200808 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200809 skb->len, 0);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300810
Kalle Valo899e6e62010-03-18 12:26:34 +0200811out:
812 dev_kfree_skb(skb);
813 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300814}
815
Kalle Valo818e3062010-03-18 12:26:35 +0200816int wl1271_cmd_build_probe_req(struct wl1271 *wl,
817 const u8 *ssid, size_t ssid_len,
818 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300819{
Kalle Valo818e3062010-03-18 12:26:35 +0200820 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300821 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822
Kalle Valo818e3062010-03-18 12:26:35 +0200823 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
824 ie, ie_len);
825 if (!skb) {
826 ret = -ENOMEM;
827 goto out;
828 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300829
Kalle Valo818e3062010-03-18 12:26:35 +0200830 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300831
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300832 if (band == IEEE80211_BAND_2GHZ)
833 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200834 skb->data, skb->len, 0);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300835 else
836 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200837 skb->data, skb->len, 0);
Kalle Valo818e3062010-03-18 12:26:35 +0200838
839out:
840 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300841 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300842}
843
Kalle Valo023e0822010-03-18 12:26:36 +0200844int wl1271_build_qos_null_data(struct wl1271 *wl)
845{
846 struct ieee80211_qos_hdr template;
847
848 memset(&template, 0, sizeof(template));
849
850 memcpy(template.addr1, wl->bssid, ETH_ALEN);
851 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
852 memcpy(template.addr3, wl->bssid, ETH_ALEN);
853
854 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
855 IEEE80211_STYPE_QOS_NULLFUNC |
856 IEEE80211_FCTL_TODS);
857
858 /* FIXME: not sure what priority to use here */
859 template.qos_ctrl = cpu_to_le16(0);
860
861 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200862 sizeof(template), 0);
Kalle Valo023e0822010-03-18 12:26:36 +0200863}
864
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300865int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
866{
867 struct wl1271_cmd_set_keys *cmd;
868 int ret = 0;
869
870 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
871
872 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
873 if (!cmd) {
874 ret = -ENOMEM;
875 goto out;
876 }
877
878 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300879 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300880 cmd->key_type = KEY_WEP;
881
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200882 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300883 if (ret < 0) {
884 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
885 goto out;
886 }
887
888out:
889 kfree(cmd);
890
891 return ret;
892}
893
894int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300895 u8 key_size, const u8 *key, const u8 *addr,
896 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300897{
898 struct wl1271_cmd_set_keys *cmd;
899 int ret = 0;
900
901 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
902 if (!cmd) {
903 ret = -ENOMEM;
904 goto out;
905 }
906
907 if (key_type != KEY_WEP)
908 memcpy(cmd->addr, addr, ETH_ALEN);
909
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300910 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300911 cmd->key_size = key_size;
912 cmd->key_type = key_type;
913
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300914 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
915 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300916
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300917 /* we have only one SSID profile */
918 cmd->ssid_profile = 0;
919
920 cmd->id = id;
921
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300922 if (key_type == KEY_TKIP) {
923 /*
924 * We get the key in the following form:
925 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
926 * but the target is expecting:
927 * TKIP - RX MIC - TX MIC
928 */
929 memcpy(cmd->key, key, 16);
930 memcpy(cmd->key + 16, key + 24, 8);
931 memcpy(cmd->key + 24, key + 16, 8);
932
933 } else {
934 memcpy(cmd->key, key, key_size);
935 }
936
937 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
938
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200939 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300940 if (ret < 0) {
941 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200942 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300943 }
944
945out:
946 kfree(cmd);
947
948 return ret;
949}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300950
951int wl1271_cmd_disconnect(struct wl1271 *wl)
952{
953 struct wl1271_cmd_disconnect *cmd;
954 int ret = 0;
955
956 wl1271_debug(DEBUG_CMD, "cmd disconnect");
957
958 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
959 if (!cmd) {
960 ret = -ENOMEM;
961 goto out;
962 }
963
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300964 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
965 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300966 /* disconnect reason is not used in immediate disconnections */
967 cmd->type = DISCONNECT_IMMEDIATE;
968
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200969 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300970 if (ret < 0) {
971 wl1271_error("failed to send disconnect command");
972 goto out_free;
973 }
974
Luciano Coelho2f826f52010-03-26 12:53:21 +0200975 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
976 if (ret < 0)
977 wl1271_error("cmd disconnect event completion error");
978
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300979out_free:
980 kfree(cmd);
981
982out:
983 return ret;
984}