blob: 36a64e06f2907c3b088de1cd6b351717b123c896 [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
4 * Copyright (C) 2009 Nokia Corporation
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/platform_device.h>
26#include <linux/crc7.h>
27#include <linux/spi/spi.h>
28#include <linux/etherdevice.h>
29
30#include "wl1271.h"
31#include "wl1271_reg.h"
32#include "wl1271_spi.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"
37
38/*
39 * send command to firmware
40 *
41 * @wl: wl struct
42 * @id: command id
43 * @buf: buffer containing the command, must work with dma
44 * @len: length of the buffer
45 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020046int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
47 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030048{
49 struct wl1271_cmd_header *cmd;
50 unsigned long timeout;
51 u32 intr;
52 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020053 u16 status;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030054
55 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030056 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030057 cmd->status = 0;
58
59 WARN_ON(len % 4 != 0);
60
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020061 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020063 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030064
65 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
66
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020067 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030068 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
69 if (time_after(jiffies, timeout)) {
70 wl1271_error("command complete timeout");
71 ret = -ETIMEDOUT;
72 goto out;
73 }
74
75 msleep(1);
76
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020077 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030078 }
79
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020080 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020081 if (res_len == 0)
82 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020083 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020084
Juuso Oikarinenad150e92009-11-02 20:22:12 +020085 status = le16_to_cpu(cmd->status);
86 if (status != CMD_STATUS_SUCCESS) {
87 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020088 ret = -EIO;
89 }
90
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020091 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
92 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030093
94out:
95 return ret;
96}
97
Luciano Coelho938e30c2009-10-15 10:33:27 +030098static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030099{
100 struct wl1271_cmd_cal_channel_tune *cmd;
101 int ret = 0;
102
103 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
104 if (!cmd)
105 return -ENOMEM;
106
107 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
108
109 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
110 /* set up any channel, 7 is in the middle of the range */
111 cmd->channel = 7;
112
113 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
114 if (ret < 0)
115 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
116
117 kfree(cmd);
118 return ret;
119}
120
Luciano Coelho938e30c2009-10-15 10:33:27 +0300121static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300122{
123 struct wl1271_cmd_cal_update_ref_point *cmd;
124 int ret = 0;
125
126 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
127 if (!cmd)
128 return -ENOMEM;
129
130 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
131
132 /* FIXME: still waiting for the correct values */
133 cmd->ref_power = 0;
134 cmd->ref_detector = 0;
135
136 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
137
138 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
139 if (ret < 0)
140 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
141
142 kfree(cmd);
143 return ret;
144}
145
Luciano Coelho938e30c2009-10-15 10:33:27 +0300146static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300147{
148 struct wl1271_cmd_cal_p2g *cmd;
149 int ret = 0;
150
151 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
152 if (!cmd)
153 return -ENOMEM;
154
155 cmd->test.id = TEST_CMD_P2G_CAL;
156
157 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
158
159 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
160 if (ret < 0)
161 wl1271_warning("TEST_CMD_P2G_CAL failed");
162
163 kfree(cmd);
164 return ret;
165}
166
Luciano Coelho938e30c2009-10-15 10:33:27 +0300167static int wl1271_cmd_cal(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300168{
169 /*
170 * FIXME: we must make sure that we're not sleeping when calibration
171 * is done
172 */
173 int ret;
174
175 wl1271_notice("performing tx calibration");
176
177 ret = wl1271_cmd_cal_channel_tune(wl);
178 if (ret < 0)
179 return ret;
180
181 ret = wl1271_cmd_cal_update_ref_point(wl);
182 if (ret < 0)
183 return ret;
184
185 ret = wl1271_cmd_cal_p2g(wl);
186 if (ret < 0)
187 return ret;
188
189 return ret;
190}
191
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200192int wl1271_cmd_general_parms(struct wl1271 *wl)
193{
194 struct wl1271_general_parms_cmd *gen_parms;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200195 int ret;
196
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200197 if (!wl->nvs)
198 return -ENODEV;
199
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200200 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
201 if (!gen_parms)
202 return -ENOMEM;
203
204 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
205
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200206 memcpy(gen_parms->params, wl->nvs->general_params,
207 WL1271_NVS_GENERAL_PARAMS_SIZE);
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200208
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200209 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
210 if (ret < 0)
211 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
212
213 kfree(gen_parms);
214 return ret;
215}
216
217int wl1271_cmd_radio_parms(struct wl1271 *wl)
218{
219 struct wl1271_radio_parms_cmd *radio_parms;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200220 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
221 int ret;
222
223 if (!wl->nvs)
224 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200225
226 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
227 if (!radio_parms)
228 return -ENOMEM;
229
230 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
231
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200232 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
233 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
234 memcpy(radio_parms->dyn_radio_params,
235 wl->nvs->dyn_radio_params[rparam->fem],
236 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200237
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200238 /* FIXME: current NVS is missing 5GHz parameters */
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200239
240 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
241 radio_parms, sizeof(*radio_parms));
242
243 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
244 if (ret < 0)
245 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
246
247 kfree(radio_parms);
248 return ret;
249}
250
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300251int wl1271_cmd_join(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300252{
253 static bool do_cal = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300254 struct wl1271_cmd_join *join;
255 int ret, i;
256 u8 *bssid;
257
258 /* FIXME: remove when we get calibration from the factory */
259 if (do_cal) {
260 ret = wl1271_cmd_cal(wl);
261 if (ret < 0)
262 wl1271_warning("couldn't calibrate");
263 else
264 do_cal = false;
265 }
266
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300267 join = kzalloc(sizeof(*join), GFP_KERNEL);
268 if (!join) {
269 ret = -ENOMEM;
270 goto out;
271 }
272
273 wl1271_debug(DEBUG_CMD, "cmd join");
274
275 /* Reverse order BSSID */
276 bssid = (u8 *) &join->bssid_lsb;
277 for (i = 0; i < ETH_ALEN; i++)
278 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
279
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300280 join->rx_config_options = cpu_to_le32(wl->rx_config);
281 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300282 join->bss_type = wl->bss_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300283
Luciano Coelho64a7f672009-10-08 21:56:28 +0300284 /*
285 * FIXME: disable temporarily all filters because after commit
286 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
287 * association. The filter logic needs to be implemented properly
288 * and once that is done, this hack can be removed.
289 */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300290 join->rx_config_options = cpu_to_le32(0);
291 join->rx_filter_options = cpu_to_le32(WL1271_DEFAULT_RX_FILTER);
Luciano Coelho64a7f672009-10-08 21:56:28 +0300292
Teemu Paasikivia4102642009-10-13 12:47:51 +0300293 if (wl->band == IEEE80211_BAND_2GHZ)
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300294 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS |
295 CONF_HW_BIT_RATE_2MBPS |
296 CONF_HW_BIT_RATE_5_5MBPS |
297 CONF_HW_BIT_RATE_11MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300298 else {
299 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300300 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS |
301 CONF_HW_BIT_RATE_12MBPS |
302 CONF_HW_BIT_RATE_24MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300303 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300304
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300305 join->beacon_interval = cpu_to_le16(WL1271_DEFAULT_BEACON_INT);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300306 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300307
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300308 join->channel = wl->channel;
309 join->ssid_len = wl->ssid_len;
310 memcpy(join->ssid, wl->ssid, wl->ssid_len);
311 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
312
313 /* increment the session counter */
314 wl->session_counter++;
315 if (wl->session_counter >= SESSION_COUNTER_MAX)
316 wl->session_counter = 0;
317
318 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
319
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300320 /* reset TX security counters */
321 wl->tx_security_last_seq = 0;
322 wl->tx_security_seq_16 = 0;
323 wl->tx_security_seq_32 = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200325 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300326 if (ret < 0) {
327 wl1271_error("failed to initiate cmd join");
328 goto out_free;
329 }
330
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300331 /*
332 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
333 * simplify locking we just sleep instead, for now
334 */
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300335 msleep(10);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300336
337out_free:
338 kfree(join);
339
340out:
341 return ret;
342}
343
344/**
345 * send test command to firmware
346 *
347 * @wl: wl struct
348 * @buf: buffer containing the command, with all headers, must work with dma
349 * @len: length of the buffer
350 * @answer: is answer needed
351 */
352int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
353{
354 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200355 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300356
357 wl1271_debug(DEBUG_CMD, "cmd test");
358
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200359 if (answer)
360 res_len = buf_len;
361
362 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300363
364 if (ret < 0) {
365 wl1271_warning("TEST command failed");
366 return ret;
367 }
368
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200369 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300370}
371
372/**
373 * read acx from firmware
374 *
375 * @wl: wl struct
376 * @id: acx id
377 * @buf: buffer for the response, including all headers, must work with dma
378 * @len: lenght of buf
379 */
380int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
381{
382 struct acx_header *acx = buf;
383 int ret;
384
385 wl1271_debug(DEBUG_CMD, "cmd interrogate");
386
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300387 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300388
389 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300390 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300391
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200392 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
393 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300394 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300395
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300396 return ret;
397}
398
399/**
400 * write acx value to firmware
401 *
402 * @wl: wl struct
403 * @id: acx id
404 * @buf: buffer containing acx, including all headers, must work with dma
405 * @len: length of buf
406 */
407int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
408{
409 struct acx_header *acx = buf;
410 int ret;
411
412 wl1271_debug(DEBUG_CMD, "cmd configure");
413
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300414 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300415
416 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300417 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300418
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200419 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300420 if (ret < 0) {
421 wl1271_warning("CONFIGURE command NOK");
422 return ret;
423 }
424
425 return 0;
426}
427
Luciano Coelho94210892009-12-11 15:40:55 +0200428int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300429{
430 struct cmd_enabledisable_path *cmd;
431 int ret;
432 u16 cmd_rx, cmd_tx;
433
434 wl1271_debug(DEBUG_CMD, "cmd data path");
435
436 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
437 if (!cmd) {
438 ret = -ENOMEM;
439 goto out;
440 }
441
Luciano Coelho94210892009-12-11 15:40:55 +0200442 /* the channel here is only used for calibration, so hardcoded to 1 */
443 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300444
445 if (enable) {
446 cmd_rx = CMD_ENABLE_RX;
447 cmd_tx = CMD_ENABLE_TX;
448 } else {
449 cmd_rx = CMD_DISABLE_RX;
450 cmd_tx = CMD_DISABLE_TX;
451 }
452
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200453 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300454 if (ret < 0) {
455 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200456 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300457 goto out;
458 }
459
460 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200461 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300462
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200463 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300464 if (ret < 0) {
465 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200466 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300467 return ret;
468 }
469
470 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200471 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300472
473out:
474 kfree(cmd);
475 return ret;
476}
477
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200478int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300479{
480 struct wl1271_cmd_ps_params *ps_params = NULL;
481 int ret = 0;
482
483 /* FIXME: this should be in ps.c */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300484 ret = wl1271_acx_wake_up_conditions(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300485 if (ret < 0) {
486 wl1271_error("couldn't set wake up conditions");
487 goto out;
488 }
489
490 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
491
492 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
493 if (!ps_params) {
494 ret = -ENOMEM;
495 goto out;
496 }
497
498 ps_params->ps_mode = ps_mode;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200499 ps_params->send_null_data = send;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300500 ps_params->retries = 5;
501 ps_params->hang_over_period = 128;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300502 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300503
504 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200505 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300506 if (ret < 0) {
507 wl1271_error("cmd set_ps_mode failed");
508 goto out;
509 }
510
511out:
512 kfree(ps_params);
513 return ret;
514}
515
516int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
517 size_t len)
518{
519 struct cmd_read_write_memory *cmd;
520 int ret = 0;
521
522 wl1271_debug(DEBUG_CMD, "cmd read memory");
523
524 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
525 if (!cmd) {
526 ret = -ENOMEM;
527 goto out;
528 }
529
530 WARN_ON(len > MAX_READ_SIZE);
531 len = min_t(size_t, len, MAX_READ_SIZE);
532
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300533 cmd->addr = cpu_to_le32(addr);
534 cmd->size = cpu_to_le32(len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300535
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200536 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
537 sizeof(*cmd));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300538 if (ret < 0) {
539 wl1271_error("read memory command failed: %d", ret);
540 goto out;
541 }
542
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200543 /* the read command got in */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300544 memcpy(answer, cmd->value, len);
545
546out:
547 kfree(cmd);
548 return ret;
549}
550
551int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300552 u8 active_scan, u8 high_prio, u8 band,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300553 u8 probe_requests)
554{
555
556 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
557 struct wl1271_cmd_scan *params = NULL;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300558 struct ieee80211_channel *channels;
559 int i, j, n_ch, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300560 u16 scan_options = 0;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300561 u8 ieee_band;
562
563 if (band == WL1271_SCAN_BAND_2_4_GHZ)
564 ieee_band = IEEE80211_BAND_2GHZ;
565 else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled())
566 ieee_band = IEEE80211_BAND_2GHZ;
567 else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled())
568 ieee_band = IEEE80211_BAND_5GHZ;
569 else
570 return -EINVAL;
571
572 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
573 return -EINVAL;
574
575 channels = wl->hw->wiphy->bands[ieee_band]->channels;
576 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300577
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200578 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300579 return -EINVAL;
580
581 params = kzalloc(sizeof(*params), GFP_KERNEL);
582 if (!params)
583 return -ENOMEM;
584
585 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
586 params->params.rx_filter_options =
587 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
588
589 if (!active_scan)
590 scan_options |= WL1271_SCAN_OPT_PASSIVE;
591 if (high_prio)
592 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300593 params->params.scan_options = cpu_to_le16(scan_options);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300594
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300595 params->params.num_probe_requests = probe_requests;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300596 /* Let the fw autodetect suitable tx_rate for probes */
597 params->params.tx_rate = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300598 params->params.tid_trigger = 0;
599 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
600
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300601 if (band == WL1271_SCAN_BAND_DUAL)
602 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
603 else
604 params->params.band = band;
605
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300606 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
607 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
608 params->channels[j].min_duration =
609 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
610 params->channels[j].max_duration =
611 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
612 memset(&params->channels[j].bssid_lsb, 0xff, 4);
613 memset(&params->channels[j].bssid_msb, 0xff, 2);
614 params->channels[j].early_termination = 0;
615 params->channels[j].tx_power_att =
616 WL1271_SCAN_CURRENT_TX_PWR;
617 params->channels[j].channel = channels[i].hw_value;
618 j++;
619 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300620 }
621
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300622 params->params.num_channels = j;
623
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300624 if (len && ssid) {
625 params->params.ssid_len = len;
626 memcpy(params->params.ssid, ssid, len);
627 }
628
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300629 ret = wl1271_cmd_build_probe_req(wl, ssid, len, ieee_band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300630 if (ret < 0) {
631 wl1271_error("PROBE request template failed");
632 goto out;
633 }
634
635 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
636 if (!trigger) {
637 ret = -ENOMEM;
638 goto out;
639 }
640
641 /* disable the timeout */
642 trigger->timeout = 0;
643
644 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200645 sizeof(*trigger), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300646 if (ret < 0) {
647 wl1271_error("trigger scan to failed for hw scan");
648 goto out;
649 }
650
651 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
652
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200653 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300654 if (wl1271_11a_enabled()) {
655 wl->scan.state = band;
656 if (band == WL1271_SCAN_BAND_DUAL) {
657 wl->scan.active = active_scan;
658 wl->scan.high_prio = high_prio;
659 wl->scan.probe_requests = probe_requests;
660 if (len && ssid) {
661 wl->scan.ssid_len = len;
662 memcpy(wl->scan.ssid, ssid, len);
663 } else
664 wl->scan.ssid_len = 0;
665 }
666 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300667
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200668 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300669 if (ret < 0) {
670 wl1271_error("SCAN failed");
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200671 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300672 goto out;
673 }
674
675out:
676 kfree(params);
677 return ret;
678}
679
680int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
681 void *buf, size_t buf_len)
682{
683 struct wl1271_cmd_template_set *cmd;
684 int ret = 0;
685
686 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
687
688 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
689 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
690
691 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
692 if (!cmd) {
693 ret = -ENOMEM;
694 goto out;
695 }
696
697 cmd->len = cpu_to_le16(buf_len);
698 cmd->template_type = template_id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300699 cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300700 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
701 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300702
703 if (buf)
704 memcpy(cmd->template_data, buf, buf_len);
705
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200706 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300707 if (ret < 0) {
708 wl1271_warning("cmd set_template failed: %d", ret);
709 goto out_free;
710 }
711
712out_free:
713 kfree(cmd);
714
715out:
716 return ret;
717}
718
Dan Carpenterbefabac2009-12-23 15:23:19 +0200719static int wl1271_build_basic_rates(u8 *rates, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300720{
721 u8 index = 0;
722
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300723 if (band == IEEE80211_BAND_2GHZ) {
724 rates[index++] =
725 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
726 rates[index++] =
727 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
728 rates[index++] =
729 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
730 rates[index++] =
731 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
732 } else if (band == IEEE80211_BAND_5GHZ) {
733 rates[index++] =
734 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
735 rates[index++] =
736 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
737 rates[index++] =
738 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
739 } else {
740 wl1271_error("build_basic_rates invalid band: %d", band);
741 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300742
743 return index;
744}
745
Dan Carpenterbefabac2009-12-23 15:23:19 +0200746static int wl1271_build_extended_rates(u8 *rates, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300747{
748 u8 index = 0;
749
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300750 if (band == IEEE80211_BAND_2GHZ) {
751 rates[index++] = IEEE80211_OFDM_RATE_6MB;
752 rates[index++] = IEEE80211_OFDM_RATE_9MB;
753 rates[index++] = IEEE80211_OFDM_RATE_12MB;
754 rates[index++] = IEEE80211_OFDM_RATE_18MB;
755 rates[index++] = IEEE80211_OFDM_RATE_24MB;
756 rates[index++] = IEEE80211_OFDM_RATE_36MB;
757 rates[index++] = IEEE80211_OFDM_RATE_48MB;
758 rates[index++] = IEEE80211_OFDM_RATE_54MB;
759 } else if (band == IEEE80211_BAND_5GHZ) {
760 rates[index++] =
761 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
762 rates[index++] =
763 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
764 rates[index++] =
765 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
766 rates[index++] =
767 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
768 rates[index++] =
769 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
770 rates[index++] =
771 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
772 } else {
773 wl1271_error("build_basic_rates invalid band: %d", band);
774 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300775
776 return index;
777}
778
779int wl1271_cmd_build_null_data(struct wl1271 *wl)
780{
781 struct wl12xx_null_data_template template;
782
783 if (!is_zero_ether_addr(wl->bssid)) {
784 memcpy(template.header.da, wl->bssid, ETH_ALEN);
785 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
786 } else {
787 memset(template.header.da, 0xff, ETH_ALEN);
788 memset(template.header.bssid, 0xff, ETH_ALEN);
789 }
790
791 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
792 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
Juuso Oikarinen7a380792009-10-15 10:33:26 +0300793 IEEE80211_STYPE_NULLFUNC |
794 IEEE80211_FCTL_TODS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300795
796 return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template,
797 sizeof(template));
798
799}
800
801int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
802{
803 struct wl12xx_ps_poll_template template;
804
805 memcpy(template.bssid, wl->bssid, ETH_ALEN);
806 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300807
808 /* aid in PS-Poll has its two MSBs each set to 1 */
809 template.aid = cpu_to_le16(1 << 15 | 1 << 14 | aid);
810
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300811 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
812
813 return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template,
814 sizeof(template));
815
816}
817
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300818int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len,
819 u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300820{
821 struct wl12xx_probe_req_template template;
822 struct wl12xx_ie_rates *rates;
823 char *ptr;
824 u16 size;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300825 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300826
827 ptr = (char *)&template;
828 size = sizeof(struct ieee80211_header);
829
830 memset(template.header.da, 0xff, ETH_ALEN);
831 memset(template.header.bssid, 0xff, ETH_ALEN);
832 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
833 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
834
835 /* IEs */
836 /* SSID */
837 template.ssid.header.id = WLAN_EID_SSID;
838 template.ssid.header.len = ssid_len;
839 if (ssid_len && ssid)
840 memcpy(template.ssid.ssid, ssid, ssid_len);
841 size += sizeof(struct wl12xx_ie_header) + ssid_len;
842 ptr += size;
843
844 /* Basic Rates */
845 rates = (struct wl12xx_ie_rates *)ptr;
846 rates->header.id = WLAN_EID_SUPP_RATES;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300847 rates->header.len = wl1271_build_basic_rates(rates->rates, band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300848 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
849 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
850
851 /* Extended rates */
852 rates = (struct wl12xx_ie_rates *)ptr;
853 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300854 rates->header.len = wl1271_build_extended_rates(rates->rates, band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300855 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
856
857 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
858
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300859 if (band == IEEE80211_BAND_2GHZ)
860 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
861 &template, size);
862 else
863 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
864 &template, size);
865 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300866}
867
868int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
869{
870 struct wl1271_cmd_set_keys *cmd;
871 int ret = 0;
872
873 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
874
875 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
876 if (!cmd) {
877 ret = -ENOMEM;
878 goto out;
879 }
880
881 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300882 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300883 cmd->key_type = KEY_WEP;
884
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200885 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300886 if (ret < 0) {
887 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
888 goto out;
889 }
890
891out:
892 kfree(cmd);
893
894 return ret;
895}
896
897int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300898 u8 key_size, const u8 *key, const u8 *addr,
899 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300900{
901 struct wl1271_cmd_set_keys *cmd;
902 int ret = 0;
903
904 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
905 if (!cmd) {
906 ret = -ENOMEM;
907 goto out;
908 }
909
910 if (key_type != KEY_WEP)
911 memcpy(cmd->addr, addr, ETH_ALEN);
912
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300913 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300914 cmd->key_size = key_size;
915 cmd->key_type = key_type;
916
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300917 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
918 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300919
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300920 /* we have only one SSID profile */
921 cmd->ssid_profile = 0;
922
923 cmd->id = id;
924
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300925 if (key_type == KEY_TKIP) {
926 /*
927 * We get the key in the following form:
928 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
929 * but the target is expecting:
930 * TKIP - RX MIC - TX MIC
931 */
932 memcpy(cmd->key, key, 16);
933 memcpy(cmd->key + 16, key + 24, 8);
934 memcpy(cmd->key + 24, key + 16, 8);
935
936 } else {
937 memcpy(cmd->key, key, key_size);
938 }
939
940 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
941
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200942 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300943 if (ret < 0) {
944 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200945 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300946 }
947
948out:
949 kfree(cmd);
950
951 return ret;
952}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300953
954int wl1271_cmd_disconnect(struct wl1271 *wl)
955{
956 struct wl1271_cmd_disconnect *cmd;
957 int ret = 0;
958
959 wl1271_debug(DEBUG_CMD, "cmd disconnect");
960
961 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
962 if (!cmd) {
963 ret = -ENOMEM;
964 goto out;
965 }
966
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300967 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
968 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300969 /* disconnect reason is not used in immediate disconnections */
970 cmd->type = DISCONNECT_IMMEDIATE;
971
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200972 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300973 if (ret < 0) {
974 wl1271_error("failed to send disconnect command");
975 goto out_free;
976 }
977
978out_free:
979 kfree(cmd);
980
981out:
982 return ret;
983}