blob: 0cb4cbb00395ce959ec013781813816af24e536d [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
39/*
40 * send command to firmware
41 *
42 * @wl: wl struct
43 * @id: command id
44 * @buf: buffer containing the command, must work with dma
45 * @len: length of the buffer
46 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020047int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
48 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030049{
50 struct wl1271_cmd_header *cmd;
51 unsigned long timeout;
52 u32 intr;
53 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020054 u16 status;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030055
56 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030057 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030058 cmd->status = 0;
59
60 WARN_ON(len % 4 != 0);
61
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020062 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030063
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020064 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030065
66 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
67
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020068 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030069 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
70 if (time_after(jiffies, timeout)) {
71 wl1271_error("command complete timeout");
72 ret = -ETIMEDOUT;
73 goto out;
74 }
75
76 msleep(1);
77
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020078 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030079 }
80
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020081 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020082 if (res_len == 0)
83 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020084 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020085
Juuso Oikarinenad150e92009-11-02 20:22:12 +020086 status = le16_to_cpu(cmd->status);
87 if (status != CMD_STATUS_SUCCESS) {
88 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020089 ret = -EIO;
90 }
91
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020092 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
93 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030094
95out:
96 return ret;
97}
98
Luciano Coelho938e30c2009-10-15 10:33:27 +030099static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300100{
101 struct wl1271_cmd_cal_channel_tune *cmd;
102 int ret = 0;
103
104 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
105 if (!cmd)
106 return -ENOMEM;
107
108 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
109
110 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
111 /* set up any channel, 7 is in the middle of the range */
112 cmd->channel = 7;
113
114 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
115 if (ret < 0)
116 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
117
118 kfree(cmd);
119 return ret;
120}
121
Luciano Coelho938e30c2009-10-15 10:33:27 +0300122static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300123{
124 struct wl1271_cmd_cal_update_ref_point *cmd;
125 int ret = 0;
126
127 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
128 if (!cmd)
129 return -ENOMEM;
130
131 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
132
133 /* FIXME: still waiting for the correct values */
134 cmd->ref_power = 0;
135 cmd->ref_detector = 0;
136
137 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
138
139 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
140 if (ret < 0)
141 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
142
143 kfree(cmd);
144 return ret;
145}
146
Luciano Coelho938e30c2009-10-15 10:33:27 +0300147static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300148{
149 struct wl1271_cmd_cal_p2g *cmd;
150 int ret = 0;
151
152 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
153 if (!cmd)
154 return -ENOMEM;
155
156 cmd->test.id = TEST_CMD_P2G_CAL;
157
158 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
159
160 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
161 if (ret < 0)
162 wl1271_warning("TEST_CMD_P2G_CAL failed");
163
164 kfree(cmd);
165 return ret;
166}
167
Luciano Coelho938e30c2009-10-15 10:33:27 +0300168static int wl1271_cmd_cal(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300169{
170 /*
171 * FIXME: we must make sure that we're not sleeping when calibration
172 * is done
173 */
174 int ret;
175
176 wl1271_notice("performing tx calibration");
177
178 ret = wl1271_cmd_cal_channel_tune(wl);
179 if (ret < 0)
180 return ret;
181
182 ret = wl1271_cmd_cal_update_ref_point(wl);
183 if (ret < 0)
184 return ret;
185
186 ret = wl1271_cmd_cal_p2g(wl);
187 if (ret < 0)
188 return ret;
189
190 return ret;
191}
192
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200193int wl1271_cmd_general_parms(struct wl1271 *wl)
194{
195 struct wl1271_general_parms_cmd *gen_parms;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200196 int ret;
197
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200198 if (!wl->nvs)
199 return -ENODEV;
200
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200201 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
202 if (!gen_parms)
203 return -ENOMEM;
204
205 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
206
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200207 memcpy(gen_parms->params, wl->nvs->general_params,
208 WL1271_NVS_GENERAL_PARAMS_SIZE);
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200209
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200210 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
211 if (ret < 0)
212 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
213
214 kfree(gen_parms);
215 return ret;
216}
217
218int wl1271_cmd_radio_parms(struct wl1271 *wl)
219{
220 struct wl1271_radio_parms_cmd *radio_parms;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200221 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
222 int ret;
223
224 if (!wl->nvs)
225 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200226
227 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
228 if (!radio_parms)
229 return -ENOMEM;
230
231 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
232
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200233 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
234 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
235 memcpy(radio_parms->dyn_radio_params,
236 wl->nvs->dyn_radio_params[rparam->fem],
237 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200238
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200239 /* FIXME: current NVS is missing 5GHz parameters */
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200240
241 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
242 radio_parms, sizeof(*radio_parms));
243
244 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
245 if (ret < 0)
246 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
247
248 kfree(radio_parms);
249 return ret;
250}
251
Luciano Coelho99d84c12010-03-26 12:53:20 +0200252/*
253 * Poll the mailbox event field until any of the bits in the mask is set or a
254 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
255 */
256static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
257{
258 u32 events_vector, event;
259 unsigned long timeout;
260
261 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
262
263 do {
264 if (time_after(jiffies, timeout))
265 return -ETIMEDOUT;
266
267 msleep(1);
268
269 /* read from both event fields */
270 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
271 sizeof(events_vector), false);
272 event = events_vector & mask;
273 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
274 sizeof(events_vector), false);
275 event |= events_vector & mask;
276 } while (!event);
277
278 return 0;
279}
280
Juuso Oikarinen15305492010-02-22 08:38:32 +0200281int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282{
283 static bool do_cal = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300284 struct wl1271_cmd_join *join;
285 int ret, i;
286 u8 *bssid;
287
288 /* FIXME: remove when we get calibration from the factory */
289 if (do_cal) {
290 ret = wl1271_cmd_cal(wl);
291 if (ret < 0)
292 wl1271_warning("couldn't calibrate");
293 else
294 do_cal = false;
295 }
296
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300297 join = kzalloc(sizeof(*join), GFP_KERNEL);
298 if (!join) {
299 ret = -ENOMEM;
300 goto out;
301 }
302
303 wl1271_debug(DEBUG_CMD, "cmd join");
304
305 /* Reverse order BSSID */
306 bssid = (u8 *) &join->bssid_lsb;
307 for (i = 0; i < ETH_ALEN; i++)
308 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
309
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300310 join->rx_config_options = cpu_to_le32(wl->rx_config);
311 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200312 join->bss_type = bss_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300313
Teemu Paasikivia4102642009-10-13 12:47:51 +0300314 if (wl->band == IEEE80211_BAND_2GHZ)
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300315 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS |
316 CONF_HW_BIT_RATE_2MBPS |
317 CONF_HW_BIT_RATE_5_5MBPS |
318 CONF_HW_BIT_RATE_11MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300319 else {
320 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300321 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS |
322 CONF_HW_BIT_RATE_12MBPS |
323 CONF_HW_BIT_RATE_24MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300324 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300325
Juuso Oikarinen60e84c22010-03-26 12:53:25 +0200326 join->beacon_interval = cpu_to_le16(wl->beacon_int);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300327 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300328
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300329 join->channel = wl->channel;
330 join->ssid_len = wl->ssid_len;
331 memcpy(join->ssid, wl->ssid, wl->ssid_len);
332 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
333
334 /* increment the session counter */
335 wl->session_counter++;
336 if (wl->session_counter >= SESSION_COUNTER_MAX)
337 wl->session_counter = 0;
338
339 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
340
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300341 /* reset TX security counters */
342 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200343 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300344
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200345 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300346 if (ret < 0) {
347 wl1271_error("failed to initiate cmd join");
348 goto out_free;
349 }
350
Luciano Coelho99d84c12010-03-26 12:53:20 +0200351 ret = wl1271_cmd_wait_for_event(wl, JOIN_EVENT_COMPLETE_ID);
352 if (ret < 0)
353 wl1271_error("cmd join event completion error");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354
355out_free:
356 kfree(join);
357
358out:
359 return ret;
360}
361
362/**
363 * send test command to firmware
364 *
365 * @wl: wl struct
366 * @buf: buffer containing the command, with all headers, must work with dma
367 * @len: length of the buffer
368 * @answer: is answer needed
369 */
370int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
371{
372 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200373 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300374
375 wl1271_debug(DEBUG_CMD, "cmd test");
376
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200377 if (answer)
378 res_len = buf_len;
379
380 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300381
382 if (ret < 0) {
383 wl1271_warning("TEST command failed");
384 return ret;
385 }
386
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200387 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300388}
389
390/**
391 * read acx from firmware
392 *
393 * @wl: wl struct
394 * @id: acx id
395 * @buf: buffer for the response, including all headers, must work with dma
396 * @len: lenght of buf
397 */
398int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
399{
400 struct acx_header *acx = buf;
401 int ret;
402
403 wl1271_debug(DEBUG_CMD, "cmd interrogate");
404
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300405 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300406
407 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300408 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300409
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200410 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
411 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300412 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300413
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300414 return ret;
415}
416
417/**
418 * write acx value to firmware
419 *
420 * @wl: wl struct
421 * @id: acx id
422 * @buf: buffer containing acx, including all headers, must work with dma
423 * @len: length of buf
424 */
425int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
426{
427 struct acx_header *acx = buf;
428 int ret;
429
430 wl1271_debug(DEBUG_CMD, "cmd configure");
431
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300432 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300433
434 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300435 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300436
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200437 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300438 if (ret < 0) {
439 wl1271_warning("CONFIGURE command NOK");
440 return ret;
441 }
442
443 return 0;
444}
445
Luciano Coelho94210892009-12-11 15:40:55 +0200446int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300447{
448 struct cmd_enabledisable_path *cmd;
449 int ret;
450 u16 cmd_rx, cmd_tx;
451
452 wl1271_debug(DEBUG_CMD, "cmd data path");
453
454 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
455 if (!cmd) {
456 ret = -ENOMEM;
457 goto out;
458 }
459
Luciano Coelho94210892009-12-11 15:40:55 +0200460 /* the channel here is only used for calibration, so hardcoded to 1 */
461 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300462
463 if (enable) {
464 cmd_rx = CMD_ENABLE_RX;
465 cmd_tx = CMD_ENABLE_TX;
466 } else {
467 cmd_rx = CMD_DISABLE_RX;
468 cmd_tx = CMD_DISABLE_TX;
469 }
470
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200471 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300472 if (ret < 0) {
473 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200474 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300475 goto out;
476 }
477
478 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200479 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300480
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200481 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300482 if (ret < 0) {
483 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200484 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200485 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300486 }
487
488 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200489 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300490
491out:
492 kfree(cmd);
493 return ret;
494}
495
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200496int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300497{
498 struct wl1271_cmd_ps_params *ps_params = NULL;
499 int ret = 0;
500
501 /* FIXME: this should be in ps.c */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300502 ret = wl1271_acx_wake_up_conditions(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300503 if (ret < 0) {
504 wl1271_error("couldn't set wake up conditions");
505 goto out;
506 }
507
508 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
509
510 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
511 if (!ps_params) {
512 ret = -ENOMEM;
513 goto out;
514 }
515
516 ps_params->ps_mode = ps_mode;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200517 ps_params->send_null_data = send;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300518 ps_params->retries = 5;
519 ps_params->hang_over_period = 128;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300520 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300521
522 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200523 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300524 if (ret < 0) {
525 wl1271_error("cmd set_ps_mode failed");
526 goto out;
527 }
528
529out:
530 kfree(ps_params);
531 return ret;
532}
533
534int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
535 size_t len)
536{
537 struct cmd_read_write_memory *cmd;
538 int ret = 0;
539
540 wl1271_debug(DEBUG_CMD, "cmd read memory");
541
542 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
543 if (!cmd) {
544 ret = -ENOMEM;
545 goto out;
546 }
547
548 WARN_ON(len > MAX_READ_SIZE);
549 len = min_t(size_t, len, MAX_READ_SIZE);
550
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300551 cmd->addr = cpu_to_le32(addr);
552 cmd->size = cpu_to_le32(len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300553
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200554 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
555 sizeof(*cmd));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300556 if (ret < 0) {
557 wl1271_error("read memory command failed: %d", ret);
558 goto out;
559 }
560
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200561 /* the read command got in */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300562 memcpy(answer, cmd->value, len);
563
564out:
565 kfree(cmd);
566 return ret;
567}
568
Kalle Valo818e3062010-03-18 12:26:35 +0200569int wl1271_cmd_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len,
570 const u8 *ie, size_t ie_len, u8 active_scan,
571 u8 high_prio, u8 band, u8 probe_requests)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300572{
573
574 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
575 struct wl1271_cmd_scan *params = NULL;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300576 struct ieee80211_channel *channels;
577 int i, j, n_ch, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300578 u16 scan_options = 0;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300579 u8 ieee_band;
580
581 if (band == WL1271_SCAN_BAND_2_4_GHZ)
582 ieee_band = IEEE80211_BAND_2GHZ;
583 else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled())
584 ieee_band = IEEE80211_BAND_2GHZ;
585 else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled())
586 ieee_band = IEEE80211_BAND_5GHZ;
587 else
588 return -EINVAL;
589
590 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
591 return -EINVAL;
592
593 channels = wl->hw->wiphy->bands[ieee_band]->channels;
594 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300595
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200596 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300597 return -EINVAL;
598
599 params = kzalloc(sizeof(*params), GFP_KERNEL);
600 if (!params)
601 return -ENOMEM;
602
603 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
604 params->params.rx_filter_options =
605 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
606
607 if (!active_scan)
608 scan_options |= WL1271_SCAN_OPT_PASSIVE;
609 if (high_prio)
610 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300611 params->params.scan_options = cpu_to_le16(scan_options);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300612
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300613 params->params.num_probe_requests = probe_requests;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300614 /* Let the fw autodetect suitable tx_rate for probes */
615 params->params.tx_rate = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300616 params->params.tid_trigger = 0;
617 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
618
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300619 if (band == WL1271_SCAN_BAND_DUAL)
620 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
621 else
622 params->params.band = band;
623
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300624 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
625 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
626 params->channels[j].min_duration =
627 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
628 params->channels[j].max_duration =
629 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
630 memset(&params->channels[j].bssid_lsb, 0xff, 4);
631 memset(&params->channels[j].bssid_msb, 0xff, 2);
632 params->channels[j].early_termination = 0;
633 params->channels[j].tx_power_att =
634 WL1271_SCAN_CURRENT_TX_PWR;
635 params->channels[j].channel = channels[i].hw_value;
636 j++;
637 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300638 }
639
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300640 params->params.num_channels = j;
641
Kalle Valo818e3062010-03-18 12:26:35 +0200642 if (ssid_len && ssid) {
643 params->params.ssid_len = ssid_len;
644 memcpy(params->params.ssid, ssid, ssid_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300645 }
646
Kalle Valo818e3062010-03-18 12:26:35 +0200647 ret = wl1271_cmd_build_probe_req(wl, ssid, ssid_len,
648 ie, ie_len, ieee_band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300649 if (ret < 0) {
650 wl1271_error("PROBE request template failed");
651 goto out;
652 }
653
654 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
655 if (!trigger) {
656 ret = -ENOMEM;
657 goto out;
658 }
659
660 /* disable the timeout */
661 trigger->timeout = 0;
662
663 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200664 sizeof(*trigger), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300665 if (ret < 0) {
666 wl1271_error("trigger scan to failed for hw scan");
667 goto out;
668 }
669
670 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
671
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200672 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300673 if (wl1271_11a_enabled()) {
674 wl->scan.state = band;
675 if (band == WL1271_SCAN_BAND_DUAL) {
676 wl->scan.active = active_scan;
677 wl->scan.high_prio = high_prio;
678 wl->scan.probe_requests = probe_requests;
Kalle Valo818e3062010-03-18 12:26:35 +0200679 if (ssid_len && ssid) {
680 wl->scan.ssid_len = ssid_len;
681 memcpy(wl->scan.ssid, ssid, ssid_len);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300682 } else
683 wl->scan.ssid_len = 0;
684 }
685 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300686
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200687 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300688 if (ret < 0) {
689 wl1271_error("SCAN failed");
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200690 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300691 goto out;
692 }
693
694out:
695 kfree(params);
Juuso Oikarinen9cea4612010-03-26 12:53:14 +0200696 kfree(trigger);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300697 return ret;
698}
699
700int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200701 void *buf, size_t buf_len, int index)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300702{
703 struct wl1271_cmd_template_set *cmd;
704 int ret = 0;
705
706 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
707
708 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
709 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
710
711 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
712 if (!cmd) {
713 ret = -ENOMEM;
714 goto out;
715 }
716
717 cmd->len = cpu_to_le16(buf_len);
718 cmd->template_type = template_id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300719 cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300720 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
721 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200722 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300723
724 if (buf)
725 memcpy(cmd->template_data, buf, buf_len);
726
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200727 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300728 if (ret < 0) {
729 wl1271_warning("cmd set_template failed: %d", ret);
730 goto out_free;
731 }
732
733out_free:
734 kfree(cmd);
735
736out:
737 return ret;
738}
739
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300740int wl1271_cmd_build_null_data(struct wl1271 *wl)
741{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200742 struct sk_buff *skb = NULL;
743 int size;
744 void *ptr;
745 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300746
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300747
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200748 if (wl->bss_type == BSS_TYPE_IBSS) {
749 size = sizeof(struct wl12xx_null_data_template);
750 ptr = NULL;
751 } else {
752 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
753 if (!skb)
754 goto out;
755 size = skb->len;
756 ptr = skb->data;
757 }
758
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200759 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300760
Kalle Valo899e6e62010-03-18 12:26:34 +0200761out:
762 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200763 if (ret)
764 wl1271_warning("cmd buld null data failed %d", ret);
765
Kalle Valo899e6e62010-03-18 12:26:34 +0200766 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300767
768}
769
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200770int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
771{
772 struct sk_buff *skb = NULL;
773 int ret = -ENOMEM;
774
775 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
776 if (!skb)
777 goto out;
778
779 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
780 skb->data, skb->len,
781 CMD_TEMPL_KLV_IDX_NULL_DATA);
782
783out:
784 dev_kfree_skb(skb);
785 if (ret)
786 wl1271_warning("cmd build klv null data failed %d", ret);
787
788 return ret;
789
790}
791
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300792int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
793{
Kalle Valo899e6e62010-03-18 12:26:34 +0200794 struct sk_buff *skb;
795 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300796
Kalle Valo899e6e62010-03-18 12:26:34 +0200797 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
798 if (!skb)
799 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300800
Kalle Valo899e6e62010-03-18 12:26:34 +0200801 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200802 skb->len, 0);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300803
Kalle Valo899e6e62010-03-18 12:26:34 +0200804out:
805 dev_kfree_skb(skb);
806 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300807}
808
Kalle Valo818e3062010-03-18 12:26:35 +0200809int wl1271_cmd_build_probe_req(struct wl1271 *wl,
810 const u8 *ssid, size_t ssid_len,
811 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300812{
Kalle Valo818e3062010-03-18 12:26:35 +0200813 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300814 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300815
Kalle Valo818e3062010-03-18 12:26:35 +0200816 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
817 ie, ie_len);
818 if (!skb) {
819 ret = -ENOMEM;
820 goto out;
821 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300822
Kalle Valo818e3062010-03-18 12:26:35 +0200823 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300824
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300825 if (band == IEEE80211_BAND_2GHZ)
826 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200827 skb->data, skb->len, 0);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300828 else
829 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200830 skb->data, skb->len, 0);
Kalle Valo818e3062010-03-18 12:26:35 +0200831
832out:
833 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300834 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300835}
836
Kalle Valo023e0822010-03-18 12:26:36 +0200837int wl1271_build_qos_null_data(struct wl1271 *wl)
838{
839 struct ieee80211_qos_hdr template;
840
841 memset(&template, 0, sizeof(template));
842
843 memcpy(template.addr1, wl->bssid, ETH_ALEN);
844 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
845 memcpy(template.addr3, wl->bssid, ETH_ALEN);
846
847 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
848 IEEE80211_STYPE_QOS_NULLFUNC |
849 IEEE80211_FCTL_TODS);
850
851 /* FIXME: not sure what priority to use here */
852 template.qos_ctrl = cpu_to_le16(0);
853
854 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200855 sizeof(template), 0);
Kalle Valo023e0822010-03-18 12:26:36 +0200856}
857
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300858int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
859{
860 struct wl1271_cmd_set_keys *cmd;
861 int ret = 0;
862
863 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
864
865 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
866 if (!cmd) {
867 ret = -ENOMEM;
868 goto out;
869 }
870
871 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300872 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300873 cmd->key_type = KEY_WEP;
874
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200875 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300876 if (ret < 0) {
877 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
878 goto out;
879 }
880
881out:
882 kfree(cmd);
883
884 return ret;
885}
886
887int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300888 u8 key_size, const u8 *key, const u8 *addr,
889 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300890{
891 struct wl1271_cmd_set_keys *cmd;
892 int ret = 0;
893
894 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
895 if (!cmd) {
896 ret = -ENOMEM;
897 goto out;
898 }
899
900 if (key_type != KEY_WEP)
901 memcpy(cmd->addr, addr, ETH_ALEN);
902
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300903 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300904 cmd->key_size = key_size;
905 cmd->key_type = key_type;
906
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300907 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
908 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300909
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300910 /* we have only one SSID profile */
911 cmd->ssid_profile = 0;
912
913 cmd->id = id;
914
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300915 if (key_type == KEY_TKIP) {
916 /*
917 * We get the key in the following form:
918 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
919 * but the target is expecting:
920 * TKIP - RX MIC - TX MIC
921 */
922 memcpy(cmd->key, key, 16);
923 memcpy(cmd->key + 16, key + 24, 8);
924 memcpy(cmd->key + 24, key + 16, 8);
925
926 } else {
927 memcpy(cmd->key, key, key_size);
928 }
929
930 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
931
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200932 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300933 if (ret < 0) {
934 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200935 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300936 }
937
938out:
939 kfree(cmd);
940
941 return ret;
942}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300943
944int wl1271_cmd_disconnect(struct wl1271 *wl)
945{
946 struct wl1271_cmd_disconnect *cmd;
947 int ret = 0;
948
949 wl1271_debug(DEBUG_CMD, "cmd disconnect");
950
951 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
952 if (!cmd) {
953 ret = -ENOMEM;
954 goto out;
955 }
956
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300957 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
958 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300959 /* disconnect reason is not used in immediate disconnections */
960 cmd->type = DISCONNECT_IMMEDIATE;
961
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200962 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300963 if (ret < 0) {
964 wl1271_error("failed to send disconnect command");
965 goto out_free;
966 }
967
Luciano Coelho2f826f52010-03-26 12:53:21 +0200968 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
969 if (ret < 0)
970 wl1271_error("cmd disconnect event completion error");
971
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300972out_free:
973 kfree(cmd);
974
975out:
976 return ret;
977}