blob: d59b3830a6a53c06d8b8baf6314f0e5770701801 [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"
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020032#include "wl1271_io.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030033#include "wl1271_acx.h"
34#include "wl12xx_80211.h"
35#include "wl1271_cmd.h"
36
37/*
38 * send command to firmware
39 *
40 * @wl: wl struct
41 * @id: command id
42 * @buf: buffer containing the command, must work with dma
43 * @len: length of the buffer
44 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020045int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
46 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030047{
48 struct wl1271_cmd_header *cmd;
49 unsigned long timeout;
50 u32 intr;
51 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020052 u16 status;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030053
54 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030055 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030056 cmd->status = 0;
57
58 WARN_ON(len % 4 != 0);
59
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020060 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030061
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020062 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030063
64 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
65
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020066 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030067 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
68 if (time_after(jiffies, timeout)) {
69 wl1271_error("command complete timeout");
70 ret = -ETIMEDOUT;
71 goto out;
72 }
73
74 msleep(1);
75
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020076 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030077 }
78
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020079 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020080 if (res_len == 0)
81 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020082 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020083
Juuso Oikarinenad150e92009-11-02 20:22:12 +020084 status = le16_to_cpu(cmd->status);
85 if (status != CMD_STATUS_SUCCESS) {
86 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020087 ret = -EIO;
88 }
89
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020090 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
91 WL1271_ACX_INTR_CMD_COMPLETE);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030092
93out:
94 return ret;
95}
96
Luciano Coelho938e30c2009-10-15 10:33:27 +030097static int wl1271_cmd_cal_channel_tune(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030098{
99 struct wl1271_cmd_cal_channel_tune *cmd;
100 int ret = 0;
101
102 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
103 if (!cmd)
104 return -ENOMEM;
105
106 cmd->test.id = TEST_CMD_CHANNEL_TUNE;
107
108 cmd->band = WL1271_CHANNEL_TUNE_BAND_2_4;
109 /* set up any channel, 7 is in the middle of the range */
110 cmd->channel = 7;
111
112 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
113 if (ret < 0)
114 wl1271_warning("TEST_CMD_CHANNEL_TUNE failed");
115
116 kfree(cmd);
117 return ret;
118}
119
Luciano Coelho938e30c2009-10-15 10:33:27 +0300120static int wl1271_cmd_cal_update_ref_point(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300121{
122 struct wl1271_cmd_cal_update_ref_point *cmd;
123 int ret = 0;
124
125 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
126 if (!cmd)
127 return -ENOMEM;
128
129 cmd->test.id = TEST_CMD_UPDATE_PD_REFERENCE_POINT;
130
131 /* FIXME: still waiting for the correct values */
132 cmd->ref_power = 0;
133 cmd->ref_detector = 0;
134
135 cmd->sub_band = WL1271_PD_REFERENCE_POINT_BAND_B_G;
136
137 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
138 if (ret < 0)
139 wl1271_warning("TEST_CMD_UPDATE_PD_REFERENCE_POINT failed");
140
141 kfree(cmd);
142 return ret;
143}
144
Luciano Coelho938e30c2009-10-15 10:33:27 +0300145static int wl1271_cmd_cal_p2g(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300146{
147 struct wl1271_cmd_cal_p2g *cmd;
148 int ret = 0;
149
150 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
151 if (!cmd)
152 return -ENOMEM;
153
154 cmd->test.id = TEST_CMD_P2G_CAL;
155
156 cmd->sub_band_mask = WL1271_CAL_P2G_BAND_B_G;
157
158 ret = wl1271_cmd_test(wl, cmd, sizeof(*cmd), 0);
159 if (ret < 0)
160 wl1271_warning("TEST_CMD_P2G_CAL failed");
161
162 kfree(cmd);
163 return ret;
164}
165
Luciano Coelho938e30c2009-10-15 10:33:27 +0300166static int wl1271_cmd_cal(struct wl1271 *wl)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300167{
168 /*
169 * FIXME: we must make sure that we're not sleeping when calibration
170 * is done
171 */
172 int ret;
173
174 wl1271_notice("performing tx calibration");
175
176 ret = wl1271_cmd_cal_channel_tune(wl);
177 if (ret < 0)
178 return ret;
179
180 ret = wl1271_cmd_cal_update_ref_point(wl);
181 if (ret < 0)
182 return ret;
183
184 ret = wl1271_cmd_cal_p2g(wl);
185 if (ret < 0)
186 return ret;
187
188 return ret;
189}
190
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200191int wl1271_cmd_general_parms(struct wl1271 *wl)
192{
193 struct wl1271_general_parms_cmd *gen_parms;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200194 int ret;
195
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200196 if (!wl->nvs)
197 return -ENODEV;
198
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200199 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
200 if (!gen_parms)
201 return -ENOMEM;
202
203 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
204
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200205 memcpy(gen_parms->params, wl->nvs->general_params,
206 WL1271_NVS_GENERAL_PARAMS_SIZE);
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200207
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200208 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), 0);
209 if (ret < 0)
210 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
211
212 kfree(gen_parms);
213 return ret;
214}
215
216int wl1271_cmd_radio_parms(struct wl1271 *wl)
217{
218 struct wl1271_radio_parms_cmd *radio_parms;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200219 struct conf_radio_parms *rparam = &wl->conf.init.radioparam;
220 int ret;
221
222 if (!wl->nvs)
223 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200224
225 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
226 if (!radio_parms)
227 return -ENOMEM;
228
229 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
230
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200231 memcpy(radio_parms->stat_radio_params, wl->nvs->stat_radio_params,
232 WL1271_NVS_STAT_RADIO_PARAMS_SIZE);
233 memcpy(radio_parms->dyn_radio_params,
234 wl->nvs->dyn_radio_params[rparam->fem],
235 WL1271_NVS_DYN_RADIO_PARAMS_SIZE);
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200236
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200237 /* FIXME: current NVS is missing 5GHz parameters */
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200238
239 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
240 radio_parms, sizeof(*radio_parms));
241
242 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
243 if (ret < 0)
244 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
245
246 kfree(radio_parms);
247 return ret;
248}
249
Juuso Oikarinen15305492010-02-22 08:38:32 +0200250int wl1271_cmd_join(struct wl1271 *wl, u8 bss_type)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300251{
252 static bool do_cal = true;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300253 struct wl1271_cmd_join *join;
254 int ret, i;
255 u8 *bssid;
256
257 /* FIXME: remove when we get calibration from the factory */
258 if (do_cal) {
259 ret = wl1271_cmd_cal(wl);
260 if (ret < 0)
261 wl1271_warning("couldn't calibrate");
262 else
263 do_cal = false;
264 }
265
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300266 join = kzalloc(sizeof(*join), GFP_KERNEL);
267 if (!join) {
268 ret = -ENOMEM;
269 goto out;
270 }
271
272 wl1271_debug(DEBUG_CMD, "cmd join");
273
274 /* Reverse order BSSID */
275 bssid = (u8 *) &join->bssid_lsb;
276 for (i = 0; i < ETH_ALEN; i++)
277 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
278
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300279 join->rx_config_options = cpu_to_le32(wl->rx_config);
280 join->rx_filter_options = cpu_to_le32(wl->rx_filter);
Juuso Oikarinen15305492010-02-22 08:38:32 +0200281 join->bss_type = bss_type;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300282
Luciano Coelho64a7f672009-10-08 21:56:28 +0300283 /*
284 * FIXME: disable temporarily all filters because after commit
285 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
286 * association. The filter logic needs to be implemented properly
287 * and once that is done, this hack can be removed.
288 */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300289 join->rx_config_options = cpu_to_le32(0);
290 join->rx_filter_options = cpu_to_le32(WL1271_DEFAULT_RX_FILTER);
Luciano Coelho64a7f672009-10-08 21:56:28 +0300291
Teemu Paasikivia4102642009-10-13 12:47:51 +0300292 if (wl->band == IEEE80211_BAND_2GHZ)
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300293 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_1MBPS |
294 CONF_HW_BIT_RATE_2MBPS |
295 CONF_HW_BIT_RATE_5_5MBPS |
296 CONF_HW_BIT_RATE_11MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300297 else {
298 join->bss_type |= WL1271_JOIN_CMD_BSS_TYPE_5GHZ;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300299 join->basic_rate_set = cpu_to_le32(CONF_HW_BIT_RATE_6MBPS |
300 CONF_HW_BIT_RATE_12MBPS |
301 CONF_HW_BIT_RATE_24MBPS);
Teemu Paasikivia4102642009-10-13 12:47:51 +0300302 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300303
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300304 join->beacon_interval = cpu_to_le16(WL1271_DEFAULT_BEACON_INT);
Luciano Coelhoae751ba2009-10-12 15:08:57 +0300305 join->dtim_interval = WL1271_DEFAULT_DTIM_PERIOD;
Teemu Paasikivia4102642009-10-13 12:47:51 +0300306
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300307 join->channel = wl->channel;
308 join->ssid_len = wl->ssid_len;
309 memcpy(join->ssid, wl->ssid, wl->ssid_len);
310 join->ctrl = WL1271_JOIN_CMD_CTRL_TX_FLUSH;
311
312 /* increment the session counter */
313 wl->session_counter++;
314 if (wl->session_counter >= SESSION_COUNTER_MAX)
315 wl->session_counter = 0;
316
317 join->ctrl |= wl->session_counter << WL1271_JOIN_CMD_TX_SESSION_OFFSET;
318
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300319 /* reset TX security counters */
320 wl->tx_security_last_seq = 0;
Juuso Oikarinen04e36fc2010-02-22 08:38:40 +0200321 wl->tx_security_seq = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300322
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200323 ret = wl1271_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300324 if (ret < 0) {
325 wl1271_error("failed to initiate cmd join");
326 goto out_free;
327 }
328
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300329 /*
330 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
331 * simplify locking we just sleep instead, for now
332 */
Juuso Oikarinend94cd292009-10-08 21:56:25 +0300333 msleep(10);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300334
335out_free:
336 kfree(join);
337
338out:
339 return ret;
340}
341
342/**
343 * send test command to firmware
344 *
345 * @wl: wl struct
346 * @buf: buffer containing the command, with all headers, must work with dma
347 * @len: length of the buffer
348 * @answer: is answer needed
349 */
350int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
351{
352 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200353 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300354
355 wl1271_debug(DEBUG_CMD, "cmd test");
356
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200357 if (answer)
358 res_len = buf_len;
359
360 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300361
362 if (ret < 0) {
363 wl1271_warning("TEST command failed");
364 return ret;
365 }
366
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200367 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300368}
369
370/**
371 * read acx from firmware
372 *
373 * @wl: wl struct
374 * @id: acx id
375 * @buf: buffer for the response, including all headers, must work with dma
376 * @len: lenght of buf
377 */
378int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
379{
380 struct acx_header *acx = buf;
381 int ret;
382
383 wl1271_debug(DEBUG_CMD, "cmd interrogate");
384
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300385 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386
387 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300388 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300389
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200390 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
391 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300392 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300393
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300394 return ret;
395}
396
397/**
398 * write acx value to firmware
399 *
400 * @wl: wl struct
401 * @id: acx id
402 * @buf: buffer containing acx, including all headers, must work with dma
403 * @len: length of buf
404 */
405int wl1271_cmd_configure(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 configure");
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_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300418 if (ret < 0) {
419 wl1271_warning("CONFIGURE command NOK");
420 return ret;
421 }
422
423 return 0;
424}
425
Luciano Coelho94210892009-12-11 15:40:55 +0200426int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300427{
428 struct cmd_enabledisable_path *cmd;
429 int ret;
430 u16 cmd_rx, cmd_tx;
431
432 wl1271_debug(DEBUG_CMD, "cmd data path");
433
434 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
435 if (!cmd) {
436 ret = -ENOMEM;
437 goto out;
438 }
439
Luciano Coelho94210892009-12-11 15:40:55 +0200440 /* the channel here is only used for calibration, so hardcoded to 1 */
441 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300442
443 if (enable) {
444 cmd_rx = CMD_ENABLE_RX;
445 cmd_tx = CMD_ENABLE_TX;
446 } else {
447 cmd_rx = CMD_DISABLE_RX;
448 cmd_tx = CMD_DISABLE_TX;
449 }
450
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200451 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300452 if (ret < 0) {
453 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200454 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300455 goto out;
456 }
457
458 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200459 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300460
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200461 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300462 if (ret < 0) {
463 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200464 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300465 return ret;
466 }
467
468 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200469 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300470
471out:
472 kfree(cmd);
473 return ret;
474}
475
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200476int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode, bool send)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300477{
478 struct wl1271_cmd_ps_params *ps_params = NULL;
479 int ret = 0;
480
481 /* FIXME: this should be in ps.c */
Juuso Oikarinen51f2be22009-10-13 12:47:42 +0300482 ret = wl1271_acx_wake_up_conditions(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300483 if (ret < 0) {
484 wl1271_error("couldn't set wake up conditions");
485 goto out;
486 }
487
488 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
489
490 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
491 if (!ps_params) {
492 ret = -ENOMEM;
493 goto out;
494 }
495
496 ps_params->ps_mode = ps_mode;
Juuso Oikarinend8c42c02010-02-18 13:25:36 +0200497 ps_params->send_null_data = send;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300498 ps_params->retries = 5;
499 ps_params->hang_over_period = 128;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300500 ps_params->null_data_rate = cpu_to_le32(1); /* 1 Mbps */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300501
502 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200503 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300504 if (ret < 0) {
505 wl1271_error("cmd set_ps_mode failed");
506 goto out;
507 }
508
509out:
510 kfree(ps_params);
511 return ret;
512}
513
514int wl1271_cmd_read_memory(struct wl1271 *wl, u32 addr, void *answer,
515 size_t len)
516{
517 struct cmd_read_write_memory *cmd;
518 int ret = 0;
519
520 wl1271_debug(DEBUG_CMD, "cmd read memory");
521
522 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
523 if (!cmd) {
524 ret = -ENOMEM;
525 goto out;
526 }
527
528 WARN_ON(len > MAX_READ_SIZE);
529 len = min_t(size_t, len, MAX_READ_SIZE);
530
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300531 cmd->addr = cpu_to_le32(addr);
532 cmd->size = cpu_to_le32(len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300533
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200534 ret = wl1271_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd),
535 sizeof(*cmd));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300536 if (ret < 0) {
537 wl1271_error("read memory command failed: %d", ret);
538 goto out;
539 }
540
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200541 /* the read command got in */
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300542 memcpy(answer, cmd->value, len);
543
544out:
545 kfree(cmd);
546 return ret;
547}
548
549int wl1271_cmd_scan(struct wl1271 *wl, u8 *ssid, size_t len,
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300550 u8 active_scan, u8 high_prio, u8 band,
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300551 u8 probe_requests)
552{
553
554 struct wl1271_cmd_trigger_scan_to *trigger = NULL;
555 struct wl1271_cmd_scan *params = NULL;
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300556 struct ieee80211_channel *channels;
557 int i, j, n_ch, ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300558 u16 scan_options = 0;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300559 u8 ieee_band;
560
561 if (band == WL1271_SCAN_BAND_2_4_GHZ)
562 ieee_band = IEEE80211_BAND_2GHZ;
563 else if (band == WL1271_SCAN_BAND_DUAL && wl1271_11a_enabled())
564 ieee_band = IEEE80211_BAND_2GHZ;
565 else if (band == WL1271_SCAN_BAND_5_GHZ && wl1271_11a_enabled())
566 ieee_band = IEEE80211_BAND_5GHZ;
567 else
568 return -EINVAL;
569
570 if (wl->hw->wiphy->bands[ieee_band]->channels == NULL)
571 return -EINVAL;
572
573 channels = wl->hw->wiphy->bands[ieee_band]->channels;
574 n_ch = wl->hw->wiphy->bands[ieee_band]->n_channels;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300575
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200576 if (test_bit(WL1271_FLAG_SCANNING, &wl->flags))
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300577 return -EINVAL;
578
579 params = kzalloc(sizeof(*params), GFP_KERNEL);
580 if (!params)
581 return -ENOMEM;
582
583 params->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD);
584 params->params.rx_filter_options =
585 cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN);
586
587 if (!active_scan)
588 scan_options |= WL1271_SCAN_OPT_PASSIVE;
589 if (high_prio)
590 scan_options |= WL1271_SCAN_OPT_PRIORITY_HIGH;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300591 params->params.scan_options = cpu_to_le16(scan_options);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300592
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300593 params->params.num_probe_requests = probe_requests;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300594 /* Let the fw autodetect suitable tx_rate for probes */
595 params->params.tx_rate = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300596 params->params.tid_trigger = 0;
597 params->params.scan_tag = WL1271_SCAN_DEFAULT_TAG;
598
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300599 if (band == WL1271_SCAN_BAND_DUAL)
600 params->params.band = WL1271_SCAN_BAND_2_4_GHZ;
601 else
602 params->params.band = band;
603
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300604 for (i = 0, j = 0; i < n_ch && i < WL1271_SCAN_MAX_CHANNELS; i++) {
605 if (!(channels[i].flags & IEEE80211_CHAN_DISABLED)) {
606 params->channels[j].min_duration =
607 cpu_to_le32(WL1271_SCAN_CHAN_MIN_DURATION);
608 params->channels[j].max_duration =
609 cpu_to_le32(WL1271_SCAN_CHAN_MAX_DURATION);
610 memset(&params->channels[j].bssid_lsb, 0xff, 4);
611 memset(&params->channels[j].bssid_msb, 0xff, 2);
612 params->channels[j].early_termination = 0;
613 params->channels[j].tx_power_att =
614 WL1271_SCAN_CURRENT_TX_PWR;
615 params->channels[j].channel = channels[i].hw_value;
616 j++;
617 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300618 }
619
Teemu Paasikivi311494c2009-10-13 12:47:49 +0300620 params->params.num_channels = j;
621
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300622 if (len && ssid) {
623 params->params.ssid_len = len;
624 memcpy(params->params.ssid, ssid, len);
625 }
626
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300627 ret = wl1271_cmd_build_probe_req(wl, ssid, len, ieee_band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300628 if (ret < 0) {
629 wl1271_error("PROBE request template failed");
630 goto out;
631 }
632
633 trigger = kzalloc(sizeof(*trigger), GFP_KERNEL);
634 if (!trigger) {
635 ret = -ENOMEM;
636 goto out;
637 }
638
639 /* disable the timeout */
640 trigger->timeout = 0;
641
642 ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200643 sizeof(*trigger), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300644 if (ret < 0) {
645 wl1271_error("trigger scan to failed for hw scan");
646 goto out;
647 }
648
649 wl1271_dump(DEBUG_SCAN, "SCAN: ", params, sizeof(*params));
650
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200651 set_bit(WL1271_FLAG_SCANNING, &wl->flags);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300652 if (wl1271_11a_enabled()) {
653 wl->scan.state = band;
654 if (band == WL1271_SCAN_BAND_DUAL) {
655 wl->scan.active = active_scan;
656 wl->scan.high_prio = high_prio;
657 wl->scan.probe_requests = probe_requests;
658 if (len && ssid) {
659 wl->scan.ssid_len = len;
660 memcpy(wl->scan.ssid, ssid, len);
661 } else
662 wl->scan.ssid_len = 0;
663 }
664 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300665
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200666 ret = wl1271_cmd_send(wl, CMD_SCAN, params, sizeof(*params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300667 if (ret < 0) {
668 wl1271_error("SCAN failed");
Juuso Oikarinen71449f82009-12-11 15:41:07 +0200669 clear_bit(WL1271_FLAG_SCANNING, &wl->flags);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300670 goto out;
671 }
672
673out:
674 kfree(params);
675 return ret;
676}
677
678int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
679 void *buf, size_t buf_len)
680{
681 struct wl1271_cmd_template_set *cmd;
682 int ret = 0;
683
684 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
685
686 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
687 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
688
689 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
690 if (!cmd) {
691 ret = -ENOMEM;
692 goto out;
693 }
694
695 cmd->len = cpu_to_le16(buf_len);
696 cmd->template_type = template_id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300697 cmd->enabled_rates = cpu_to_le32(wl->conf.tx.rc_conf.enabled_rates);
Juuso Oikarinen45b531a2009-10-13 12:47:41 +0300698 cmd->short_retry_limit = wl->conf.tx.rc_conf.short_retry_limit;
699 cmd->long_retry_limit = wl->conf.tx.rc_conf.long_retry_limit;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300700
701 if (buf)
702 memcpy(cmd->template_data, buf, buf_len);
703
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200704 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300705 if (ret < 0) {
706 wl1271_warning("cmd set_template failed: %d", ret);
707 goto out_free;
708 }
709
710out_free:
711 kfree(cmd);
712
713out:
714 return ret;
715}
716
Dan Carpenterbefabac2009-12-23 15:23:19 +0200717static int wl1271_build_basic_rates(u8 *rates, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300718{
719 u8 index = 0;
720
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300721 if (band == IEEE80211_BAND_2GHZ) {
722 rates[index++] =
723 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
724 rates[index++] =
725 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
726 rates[index++] =
727 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_5MB;
728 rates[index++] =
729 IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_11MB;
730 } else if (band == IEEE80211_BAND_5GHZ) {
731 rates[index++] =
732 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_6MB;
733 rates[index++] =
734 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_12MB;
735 rates[index++] =
736 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
737 } else {
738 wl1271_error("build_basic_rates invalid band: %d", band);
739 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300740
741 return index;
742}
743
Dan Carpenterbefabac2009-12-23 15:23:19 +0200744static int wl1271_build_extended_rates(u8 *rates, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300745{
746 u8 index = 0;
747
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300748 if (band == IEEE80211_BAND_2GHZ) {
749 rates[index++] = IEEE80211_OFDM_RATE_6MB;
750 rates[index++] = IEEE80211_OFDM_RATE_9MB;
751 rates[index++] = IEEE80211_OFDM_RATE_12MB;
752 rates[index++] = IEEE80211_OFDM_RATE_18MB;
753 rates[index++] = IEEE80211_OFDM_RATE_24MB;
754 rates[index++] = IEEE80211_OFDM_RATE_36MB;
755 rates[index++] = IEEE80211_OFDM_RATE_48MB;
756 rates[index++] = IEEE80211_OFDM_RATE_54MB;
757 } else if (band == IEEE80211_BAND_5GHZ) {
758 rates[index++] =
759 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_9MB;
760 rates[index++] =
761 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_18MB;
762 rates[index++] =
763 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_24MB;
764 rates[index++] =
765 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_36MB;
766 rates[index++] =
767 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_48MB;
768 rates[index++] =
769 IEEE80211_BASIC_RATE_MASK | IEEE80211_OFDM_RATE_54MB;
770 } else {
771 wl1271_error("build_basic_rates invalid band: %d", band);
772 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300773
774 return index;
775}
776
777int wl1271_cmd_build_null_data(struct wl1271 *wl)
778{
779 struct wl12xx_null_data_template template;
780
781 if (!is_zero_ether_addr(wl->bssid)) {
782 memcpy(template.header.da, wl->bssid, ETH_ALEN);
783 memcpy(template.header.bssid, wl->bssid, ETH_ALEN);
784 } else {
785 memset(template.header.da, 0xff, ETH_ALEN);
786 memset(template.header.bssid, 0xff, ETH_ALEN);
787 }
788
789 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
790 template.header.frame_ctl = cpu_to_le16(IEEE80211_FTYPE_DATA |
Juuso Oikarinen7a380792009-10-15 10:33:26 +0300791 IEEE80211_STYPE_NULLFUNC |
792 IEEE80211_FCTL_TODS);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300793
794 return wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, &template,
795 sizeof(template));
796
797}
798
799int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
800{
801 struct wl12xx_ps_poll_template template;
802
803 memcpy(template.bssid, wl->bssid, ETH_ALEN);
804 memcpy(template.ta, wl->mac_addr, ETH_ALEN);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +0300805
806 /* aid in PS-Poll has its two MSBs each set to 1 */
807 template.aid = cpu_to_le16(1 << 15 | 1 << 14 | aid);
808
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300809 template.fc = cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_PSPOLL);
810
811 return wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, &template,
812 sizeof(template));
813
814}
815
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300816int wl1271_cmd_build_probe_req(struct wl1271 *wl, u8 *ssid, size_t ssid_len,
817 u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300818{
819 struct wl12xx_probe_req_template template;
820 struct wl12xx_ie_rates *rates;
821 char *ptr;
822 u16 size;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300823 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300824
825 ptr = (char *)&template;
826 size = sizeof(struct ieee80211_header);
827
828 memset(template.header.da, 0xff, ETH_ALEN);
829 memset(template.header.bssid, 0xff, ETH_ALEN);
830 memcpy(template.header.sa, wl->mac_addr, ETH_ALEN);
831 template.header.frame_ctl = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ);
832
833 /* IEs */
834 /* SSID */
835 template.ssid.header.id = WLAN_EID_SSID;
836 template.ssid.header.len = ssid_len;
837 if (ssid_len && ssid)
838 memcpy(template.ssid.ssid, ssid, ssid_len);
839 size += sizeof(struct wl12xx_ie_header) + ssid_len;
840 ptr += size;
841
842 /* Basic Rates */
843 rates = (struct wl12xx_ie_rates *)ptr;
844 rates->header.id = WLAN_EID_SUPP_RATES;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300845 rates->header.len = wl1271_build_basic_rates(rates->rates, band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300846 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
847 ptr += sizeof(struct wl12xx_ie_header) + rates->header.len;
848
849 /* Extended rates */
850 rates = (struct wl12xx_ie_rates *)ptr;
851 rates->header.id = WLAN_EID_EXT_SUPP_RATES;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300852 rates->header.len = wl1271_build_extended_rates(rates->rates, band);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300853 size += sizeof(struct wl12xx_ie_header) + rates->header.len;
854
855 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", &template, size);
856
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +0300857 if (band == IEEE80211_BAND_2GHZ)
858 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
859 &template, size);
860 else
861 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
862 &template, size);
863 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300864}
865
866int wl1271_cmd_set_default_wep_key(struct wl1271 *wl, u8 id)
867{
868 struct wl1271_cmd_set_keys *cmd;
869 int ret = 0;
870
871 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
872
873 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
874 if (!cmd) {
875 ret = -ENOMEM;
876 goto out;
877 }
878
879 cmd->id = id;
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300880 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300881 cmd->key_type = KEY_WEP;
882
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200883 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300884 if (ret < 0) {
885 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
886 goto out;
887 }
888
889out:
890 kfree(cmd);
891
892 return ret;
893}
894
895int wl1271_cmd_set_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300896 u8 key_size, const u8 *key, const u8 *addr,
897 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300898{
899 struct wl1271_cmd_set_keys *cmd;
900 int ret = 0;
901
902 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
903 if (!cmd) {
904 ret = -ENOMEM;
905 goto out;
906 }
907
908 if (key_type != KEY_WEP)
909 memcpy(cmd->addr, addr, ETH_ALEN);
910
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300911 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300912 cmd->key_size = key_size;
913 cmd->key_type = key_type;
914
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300915 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
916 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +0300917
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300918 /* we have only one SSID profile */
919 cmd->ssid_profile = 0;
920
921 cmd->id = id;
922
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300923 if (key_type == KEY_TKIP) {
924 /*
925 * We get the key in the following form:
926 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
927 * but the target is expecting:
928 * TKIP - RX MIC - TX MIC
929 */
930 memcpy(cmd->key, key, 16);
931 memcpy(cmd->key + 16, key + 24, 8);
932 memcpy(cmd->key + 24, key + 16, 8);
933
934 } else {
935 memcpy(cmd->key, key, key_size);
936 }
937
938 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
939
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200940 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300941 if (ret < 0) {
942 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200943 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300944 }
945
946out:
947 kfree(cmd);
948
949 return ret;
950}
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300951
952int wl1271_cmd_disconnect(struct wl1271 *wl)
953{
954 struct wl1271_cmd_disconnect *cmd;
955 int ret = 0;
956
957 wl1271_debug(DEBUG_CMD, "cmd disconnect");
958
959 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
960 if (!cmd) {
961 ret = -ENOMEM;
962 goto out;
963 }
964
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300965 cmd->rx_config_options = cpu_to_le32(wl->rx_config);
966 cmd->rx_filter_options = cpu_to_le32(wl->rx_filter);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300967 /* disconnect reason is not used in immediate disconnections */
968 cmd->type = DISCONNECT_IMMEDIATE;
969
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200970 ret = wl1271_cmd_send(wl, CMD_DISCONNECT, cmd, sizeof(*cmd), 0);
Luciano Coelho25a7dc62009-10-12 15:08:42 +0300971 if (ret < 0) {
972 wl1271_error("failed to send disconnect command");
973 goto out_free;
974 }
975
976out_free:
977 kfree(cmd);
978
979out:
980 return ret;
981}