blob: c620a9d4939c80a21c605b67e3d057e618de120b [file] [log] [blame]
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001/*
2 * This file is part of wl1271
3 *
Luciano Coelho2f826f52010-03-26 12:53:21 +02004 * Copyright (C) 2009-2010 Nokia Corporation
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03005 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
23
24#include <linux/module.h>
25#include <linux/platform_device.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030026#include <linux/spi/spi.h>
27#include <linux/etherdevice.h>
Kalle Valo023e0822010-03-18 12:26:36 +020028#include <linux/ieee80211.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090029#include <linux/slab.h>
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030030
Shahar Levi00d20102010-11-08 11:20:10 +000031#include "wl12xx.h"
32#include "reg.h"
33#include "io.h"
34#include "acx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030035#include "wl12xx_80211.h"
Shahar Levi00d20102010-11-08 11:20:10 +000036#include "cmd.h"
37#include "event.h"
Arik Nemtsov98bdaab2010-10-16 18:08:58 +020038#include "tx.h"
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030039
Juuso Oikarinen16092b52010-04-28 09:49:59 +030040#define WL1271_CMD_FAST_POLL_COUNT 50
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030041
42/*
43 * send command to firmware
44 *
45 * @wl: wl struct
46 * @id: command id
47 * @buf: buffer containing the command, must work with dma
48 * @len: length of the buffer
49 */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020050int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len,
51 size_t res_len)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030052{
53 struct wl1271_cmd_header *cmd;
54 unsigned long timeout;
55 u32 intr;
56 int ret = 0;
Juuso Oikarinenad150e92009-11-02 20:22:12 +020057 u16 status;
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020058 u16 poll_count = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030059
60 cmd = buf;
Luciano Coelhod0f63b22009-10-15 10:33:29 +030061 cmd->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030062 cmd->status = 0;
63
64 WARN_ON(len % 4 != 0);
Arik Nemtsov24225b32011-03-01 12:27:26 +020065 WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030066
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020067 wl1271_write(wl, wl->cmd_box_addr, buf, len, false);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030068
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020069 wl1271_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030070
71 timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT);
72
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020073 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030074 while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) {
75 if (time_after(jiffies, timeout)) {
76 wl1271_error("command complete timeout");
77 ret = -ETIMEDOUT;
Arik Nemtsovf482b762011-04-18 14:15:23 +030078 goto fail;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030079 }
80
Saravanan Dhanabalbc0f03e2010-03-26 12:53:33 +020081 poll_count++;
Juuso Oikarinen16092b52010-04-28 09:49:59 +030082 if (poll_count < WL1271_CMD_FAST_POLL_COUNT)
83 udelay(10);
84 else
85 msleep(1);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030086
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020087 intr = wl1271_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +030088 }
89
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020090 /* read back the status code of the command */
Juuso Oikarinenfa867e72009-11-02 20:22:13 +020091 if (res_len == 0)
92 res_len = sizeof(struct wl1271_cmd_header);
Teemu Paasikivi7b048c52010-02-18 13:25:55 +020093 wl1271_read(wl, wl->cmd_box_addr, cmd, res_len, false);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020094
Juuso Oikarinenad150e92009-11-02 20:22:12 +020095 status = le16_to_cpu(cmd->status);
96 if (status != CMD_STATUS_SUCCESS) {
97 wl1271_error("command execute failure %d", status);
Juuso Oikarinen3b775b42009-11-02 20:22:10 +020098 ret = -EIO;
Arik Nemtsovf482b762011-04-18 14:15:23 +030099 goto fail;
Juuso Oikarinen3b775b42009-11-02 20:22:10 +0200100 }
101
Teemu Paasikivi7b048c52010-02-18 13:25:55 +0200102 wl1271_write32(wl, ACX_REG_INTERRUPT_ACK,
103 WL1271_ACX_INTR_CMD_COMPLETE);
Arik Nemtsovf482b762011-04-18 14:15:23 +0300104 return 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300105
Arik Nemtsovf482b762011-04-18 14:15:23 +0300106fail:
107 WARN_ON(1);
Ido Yarivbaacb9ae2011-06-06 14:57:05 +0300108 wl12xx_queue_recovery_work(wl);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300109 return ret;
110}
111
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200112int wl1271_cmd_general_parms(struct wl1271 *wl)
113{
114 struct wl1271_general_parms_cmd *gen_parms;
Shahar Levi49d750ca2011-03-06 16:32:09 +0200115 struct wl1271_ini_general_params *gp =
116 &((struct wl1271_nvs_file *)wl->nvs)->general_params;
117 bool answer = false;
118 int ret;
119
120 if (!wl->nvs)
121 return -ENODEV;
122
123 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
124 if (!gen_parms)
125 return -ENOMEM;
126
127 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
128
129 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
130
131 if (gp->tx_bip_fem_auto_detect)
132 answer = true;
133
Shahar Levib03acad2011-04-03 13:54:54 +0300134 /* Override the REF CLK from the NVS with the one from platform data */
135 gen_parms->general_params.ref_clock = wl->ref_clock;
136
Shahar Levi0c005042011-06-12 10:34:43 +0300137 /* LPD mode enable (bits 6-7) in WL1271 AP mode only */
138 if (wl->quirks & WL12XX_QUIRK_LPD_MODE)
139 gen_parms->general_params.general_settings |=
140 GENERAL_SETTINGS_DRPW_LPD;
141
Shahar Levi49d750ca2011-03-06 16:32:09 +0200142 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
143 if (ret < 0) {
144 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
145 goto out;
146 }
147
148 gp->tx_bip_fem_manufacturer =
149 gen_parms->general_params.tx_bip_fem_manufacturer;
150
151 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
152 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
153
154out:
155 kfree(gen_parms);
156 return ret;
157}
158
159int wl128x_cmd_general_parms(struct wl1271 *wl)
160{
161 struct wl128x_general_parms_cmd *gen_parms;
162 struct wl128x_ini_general_params *gp =
163 &((struct wl128x_nvs_file *)wl->nvs)->general_params;
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300164 bool answer = false;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200165 int ret;
166
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200167 if (!wl->nvs)
168 return -ENODEV;
169
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200170 gen_parms = kzalloc(sizeof(*gen_parms), GFP_KERNEL);
171 if (!gen_parms)
172 return -ENOMEM;
173
174 gen_parms->test.id = TEST_CMD_INI_FILE_GENERAL_PARAM;
175
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300176 memcpy(&gen_parms->general_params, gp, sizeof(*gp));
Luciano Coelho76c0f8d2009-12-11 15:40:41 +0200177
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300178 if (gp->tx_bip_fem_auto_detect)
179 answer = true;
180
Shahar Levib03acad2011-04-03 13:54:54 +0300181 /* Replace REF and TCXO CLKs with the ones from platform data */
182 gen_parms->general_params.ref_clock = wl->ref_clock;
183 gen_parms->general_params.tcxo_ref_clock = wl->tcxo_clock;
184
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300185 ret = wl1271_cmd_test(wl, gen_parms, sizeof(*gen_parms), answer);
186 if (ret < 0) {
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200187 wl1271_warning("CMD_INI_FILE_GENERAL_PARAM failed");
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300188 goto out;
189 }
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200190
Juuso Oikarinen4b34d432010-10-07 10:16:42 +0300191 gp->tx_bip_fem_manufacturer =
192 gen_parms->general_params.tx_bip_fem_manufacturer;
193
194 wl1271_debug(DEBUG_CMD, "FEM autodetect: %s, manufacturer: %d\n",
195 answer ? "auto" : "manual", gp->tx_bip_fem_manufacturer);
196
197out:
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200198 kfree(gen_parms);
199 return ret;
200}
201
202int wl1271_cmd_radio_parms(struct wl1271 *wl)
203{
Shahar Levibc765bf2011-03-06 16:32:10 +0200204 struct wl1271_nvs_file *nvs = (struct wl1271_nvs_file *)wl->nvs;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200205 struct wl1271_radio_parms_cmd *radio_parms;
Shahar Levibc765bf2011-03-06 16:32:10 +0200206 struct wl1271_ini_general_params *gp = &nvs->general_params;
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +0200207 int ret;
208
209 if (!wl->nvs)
210 return -ENODEV;
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200211
212 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
213 if (!radio_parms)
214 return -ENOMEM;
215
216 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
217
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300218 /* 2.4GHz parameters */
Shahar Levibc765bf2011-03-06 16:32:10 +0200219 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300220 sizeof(struct wl1271_ini_band_params_2));
221 memcpy(&radio_parms->dyn_params_2,
Shahar Levibc765bf2011-03-06 16:32:10 +0200222 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarineneb70eb72010-05-14 10:46:22 +0300223 sizeof(struct wl1271_ini_fem_params_2));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200224
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300225 /* 5GHz parameters */
226 memcpy(&radio_parms->static_params_5,
Shahar Levibc765bf2011-03-06 16:32:10 +0200227 &nvs->stat_radio_params_5,
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300228 sizeof(struct wl1271_ini_band_params_5));
229 memcpy(&radio_parms->dyn_params_5,
Shahar Levibc765bf2011-03-06 16:32:10 +0200230 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
Juuso Oikarinena7da74f2010-05-14 10:46:23 +0300231 sizeof(struct wl1271_ini_fem_params_5));
Luciano Coelho98b5dd52009-11-23 23:22:17 +0200232
233 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
234 radio_parms, sizeof(*radio_parms));
235
236 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
237 if (ret < 0)
238 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
239
240 kfree(radio_parms);
241 return ret;
242}
243
Shahar Levi49d750ca2011-03-06 16:32:09 +0200244int wl128x_cmd_radio_parms(struct wl1271 *wl)
245{
246 struct wl128x_nvs_file *nvs = (struct wl128x_nvs_file *)wl->nvs;
247 struct wl128x_radio_parms_cmd *radio_parms;
248 struct wl128x_ini_general_params *gp = &nvs->general_params;
249 int ret;
250
251 if (!wl->nvs)
252 return -ENODEV;
253
254 radio_parms = kzalloc(sizeof(*radio_parms), GFP_KERNEL);
255 if (!radio_parms)
256 return -ENOMEM;
257
258 radio_parms->test.id = TEST_CMD_INI_FILE_RADIO_PARAM;
259
260 /* 2.4GHz parameters */
261 memcpy(&radio_parms->static_params_2, &nvs->stat_radio_params_2,
262 sizeof(struct wl128x_ini_band_params_2));
263 memcpy(&radio_parms->dyn_params_2,
264 &nvs->dyn_radio_params_2[gp->tx_bip_fem_manufacturer].params,
265 sizeof(struct wl128x_ini_fem_params_2));
266
267 /* 5GHz parameters */
268 memcpy(&radio_parms->static_params_5,
269 &nvs->stat_radio_params_5,
270 sizeof(struct wl128x_ini_band_params_5));
271 memcpy(&radio_parms->dyn_params_5,
272 &nvs->dyn_radio_params_5[gp->tx_bip_fem_manufacturer].params,
273 sizeof(struct wl128x_ini_fem_params_5));
274
275 radio_parms->fem_vendor_and_options = nvs->fem_vendor_and_options;
276
277 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_RADIO_PARAM: ",
278 radio_parms, sizeof(*radio_parms));
279
280 ret = wl1271_cmd_test(wl, radio_parms, sizeof(*radio_parms), 0);
281 if (ret < 0)
282 wl1271_warning("CMD_INI_FILE_RADIO_PARAM failed");
283
284 kfree(radio_parms);
285 return ret;
286}
287
Juuso Oikarinen644a4862010-10-05 13:11:56 +0200288int wl1271_cmd_ext_radio_parms(struct wl1271 *wl)
289{
290 struct wl1271_ext_radio_parms_cmd *ext_radio_parms;
291 struct conf_rf_settings *rf = &wl->conf.rf;
292 int ret;
293
294 if (!wl->nvs)
295 return -ENODEV;
296
297 ext_radio_parms = kzalloc(sizeof(*ext_radio_parms), GFP_KERNEL);
298 if (!ext_radio_parms)
299 return -ENOMEM;
300
301 ext_radio_parms->test.id = TEST_CMD_INI_FILE_RF_EXTENDED_PARAM;
302
303 memcpy(ext_radio_parms->tx_per_channel_power_compensation_2,
304 rf->tx_per_channel_power_compensation_2,
305 CONF_TX_PWR_COMPENSATION_LEN_2);
306 memcpy(ext_radio_parms->tx_per_channel_power_compensation_5,
307 rf->tx_per_channel_power_compensation_5,
308 CONF_TX_PWR_COMPENSATION_LEN_5);
309
310 wl1271_dump(DEBUG_CMD, "TEST_CMD_INI_FILE_EXT_RADIO_PARAM: ",
311 ext_radio_parms, sizeof(*ext_radio_parms));
312
313 ret = wl1271_cmd_test(wl, ext_radio_parms, sizeof(*ext_radio_parms), 0);
314 if (ret < 0)
315 wl1271_warning("TEST_CMD_INI_FILE_RF_EXTENDED_PARAM failed");
316
317 kfree(ext_radio_parms);
318 return ret;
319}
320
Luciano Coelho99d84c12010-03-26 12:53:20 +0200321/*
322 * Poll the mailbox event field until any of the bits in the mask is set or a
323 * timeout occurs (WL1271_EVENT_TIMEOUT in msecs)
324 */
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200325static int wl1271_cmd_wait_for_event_or_timeout(struct wl1271 *wl, u32 mask)
Luciano Coelho99d84c12010-03-26 12:53:20 +0200326{
327 u32 events_vector, event;
328 unsigned long timeout;
329
330 timeout = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT);
331
332 do {
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200333 if (time_after(jiffies, timeout)) {
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200334 wl1271_debug(DEBUG_CMD, "timeout waiting for event %d",
335 (int)mask);
Luciano Coelho99d84c12010-03-26 12:53:20 +0200336 return -ETIMEDOUT;
Juuso Oikarinen52b0e7a2010-09-21 06:23:31 +0200337 }
Luciano Coelho99d84c12010-03-26 12:53:20 +0200338
339 msleep(1);
340
341 /* read from both event fields */
342 wl1271_read(wl, wl->mbox_ptr[0], &events_vector,
343 sizeof(events_vector), false);
344 event = events_vector & mask;
345 wl1271_read(wl, wl->mbox_ptr[1], &events_vector,
346 sizeof(events_vector), false);
347 event |= events_vector & mask;
348 } while (!event);
349
350 return 0;
351}
352
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200353static int wl1271_cmd_wait_for_event(struct wl1271 *wl, u32 mask)
354{
355 int ret;
356
357 ret = wl1271_cmd_wait_for_event_or_timeout(wl, mask);
358 if (ret != 0) {
Ido Yarivbaacb9ae2011-06-06 14:57:05 +0300359 wl12xx_queue_recovery_work(wl);
Arik Nemtsov05285cf2010-11-12 17:15:03 +0200360 return ret;
361 }
362
363 return 0;
364}
365
Eliad Pellerc690ec82011-08-14 13:17:07 +0300366int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 role_type, u8 *role_id)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300367{
Eliad Pellerc690ec82011-08-14 13:17:07 +0300368 struct wl12xx_cmd_role_enable *cmd;
369 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300370
Eliad Pellerc690ec82011-08-14 13:17:07 +0300371 wl1271_debug(DEBUG_CMD, "cmd role enable");
372
373 if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID))
374 return -EBUSY;
375
376 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
377 if (!cmd) {
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300378 ret = -ENOMEM;
379 goto out;
380 }
381
Eliad Pellerc690ec82011-08-14 13:17:07 +0300382 /* get role id */
383 cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES);
384 if (cmd->role_id >= WL12XX_MAX_ROLES) {
385 ret = -EBUSY;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300386 goto out_free;
387 }
388
Eliad Pellerc690ec82011-08-14 13:17:07 +0300389 memcpy(cmd->mac_address, wl->mac_addr, ETH_ALEN);
390 cmd->role_type = role_type;
391
392 ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0);
393 if (ret < 0) {
394 wl1271_error("failed to initiate cmd role enable");
395 goto out_free;
396 }
397
398 __set_bit(cmd->role_id, wl->roles_map);
399 *role_id = cmd->role_id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300400
401out_free:
Eliad Pellerc690ec82011-08-14 13:17:07 +0300402 kfree(cmd);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300403
404out:
405 return ret;
406}
407
Eliad Pellerc690ec82011-08-14 13:17:07 +0300408int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id)
409{
410 struct wl12xx_cmd_role_disable *cmd;
411 int ret;
412
413 wl1271_debug(DEBUG_CMD, "cmd role disable");
414
415 if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID))
416 return -ENOENT;
417
418 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
419 if (!cmd) {
420 ret = -ENOMEM;
421 goto out;
422 }
423 cmd->role_id = *role_id;
424
425 ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0);
426 if (ret < 0) {
427 wl1271_error("failed to initiate cmd role disable");
428 goto out_free;
429 }
430
431 __clear_bit(*role_id, wl->roles_map);
432 *role_id = WL12XX_INVALID_ROLE_ID;
433
434out_free:
435 kfree(cmd);
436
437out:
438 return ret;
439}
440
441static int wl12xx_allocate_link(struct wl1271 *wl, u8 *hlid)
442{
443 u8 link = find_first_zero_bit(wl->links_map, WL12XX_MAX_LINKS);
444 if (link >= WL12XX_MAX_LINKS)
445 return -EBUSY;
446
447 __set_bit(link, wl->links_map);
448 *hlid = link;
449 return 0;
450}
451
452static void wl12xx_free_link(struct wl1271 *wl, u8 *hlid)
453{
454 if (*hlid == WL12XX_INVALID_LINK_ID)
455 return;
456
457 __clear_bit(*hlid, wl->links_map);
458 *hlid = WL12XX_INVALID_LINK_ID;
459}
460
Eliad Peller04e80792011-08-14 13:17:09 +0300461int wl12xx_cmd_role_start_dev(struct wl1271 *wl)
462{
463 struct wl12xx_cmd_role_start *cmd;
464 int ret;
465
466 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
467 if (!cmd) {
468 ret = -ENOMEM;
469 goto out;
470 }
471
472 wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wl->dev_role_id);
473
474 cmd->role_id = wl->dev_role_id;
475 if (wl->band == IEEE80211_BAND_5GHZ)
476 cmd->band = WL12XX_BAND_5GHZ;
477 cmd->channel = wl->channel;
478
479 if (wl->dev_hlid == WL12XX_INVALID_LINK_ID) {
480 ret = wl12xx_allocate_link(wl, &wl->dev_hlid);
481 if (ret)
482 goto out_free;
483 }
484 cmd->device.hlid = wl->dev_hlid;
485 cmd->device.session = wl->session_counter;
486
487 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d",
488 cmd->role_id, cmd->device.hlid, cmd->device.session);
489
490 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
491 if (ret < 0) {
492 wl1271_error("failed to initiate cmd role enable");
493 goto err_hlid;
494 }
495
496 goto out_free;
497
498err_hlid:
499 /* clear links on error */
500 __clear_bit(wl->dev_hlid, wl->links_map);
501 wl->dev_hlid = WL12XX_INVALID_LINK_ID;
502
503
504out_free:
505 kfree(cmd);
506
507out:
508 return ret;
509}
510
511int wl12xx_cmd_role_stop_dev(struct wl1271 *wl)
512{
513 struct wl12xx_cmd_role_stop *cmd;
514 int ret;
515
516 if (WARN_ON(wl->dev_hlid == WL12XX_INVALID_LINK_ID))
517 return -EINVAL;
518
519 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
520 if (!cmd) {
521 ret = -ENOMEM;
522 goto out;
523 }
524
525 wl1271_debug(DEBUG_CMD, "cmd role stop dev");
526
527 cmd->role_id = wl->dev_role_id;
528 cmd->disc_type = DISCONNECT_IMMEDIATE;
529 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
530
531 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
532 if (ret < 0) {
533 wl1271_error("failed to initiate cmd role stop");
534 goto out_free;
535 }
536
537 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
538 if (ret < 0) {
539 wl1271_error("cmd role stop dev event completion error");
540 goto out_free;
541 }
542
543 wl12xx_free_link(wl, &wl->dev_hlid);
544
545out_free:
546 kfree(cmd);
547
548out:
549 return ret;
550}
551
Eliad Pellerc690ec82011-08-14 13:17:07 +0300552int wl12xx_cmd_role_start_sta(struct wl1271 *wl)
553{
554 struct wl12xx_cmd_role_start *cmd;
555 int ret;
556
557 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
558 if (!cmd) {
559 ret = -ENOMEM;
560 goto out;
561 }
562
563 wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wl->role_id);
564
565 cmd->role_id = wl->role_id;
566 if (wl->band == IEEE80211_BAND_5GHZ)
567 cmd->band = WL12XX_BAND_5GHZ;
568 cmd->channel = wl->channel;
569 cmd->sta.basic_rate_set = cpu_to_le32(wl->basic_rate_set);
570 cmd->sta.beacon_interval = cpu_to_le16(wl->beacon_int);
571 cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY;
572 cmd->sta.ssid_len = wl->ssid_len;
573 memcpy(cmd->sta.ssid, wl->ssid, wl->ssid_len);
574 memcpy(cmd->sta.bssid, wl->bssid, ETH_ALEN);
575 cmd->sta.local_rates = cpu_to_le32(wl->rate_set);
576
577 if (wl->sta_hlid == WL12XX_INVALID_LINK_ID) {
578 ret = wl12xx_allocate_link(wl, &wl->sta_hlid);
579 if (ret)
580 goto out_free;
581 }
582 cmd->sta.hlid = wl->sta_hlid;
583 cmd->sta.session = wl->session_counter;
584 cmd->sta.remote_rates = cpu_to_le32(wl->rate_set);
585
586 wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d "
587 "basic_rate_set: 0x%x, remote_rates: 0x%x",
588 wl->role_id, cmd->sta.hlid, cmd->sta.session,
589 wl->basic_rate_set, wl->rate_set);
590
591 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
592 if (ret < 0) {
593 wl1271_error("failed to initiate cmd role start sta");
594 goto err_hlid;
595 }
596
597 goto out_free;
598
599err_hlid:
600 /* clear links on error. */
601 wl12xx_free_link(wl, &wl->sta_hlid);
602
603out_free:
604 kfree(cmd);
605
606out:
607 return ret;
608}
609
610int wl12xx_cmd_role_stop_sta(struct wl1271 *wl)
611{
612 struct wl12xx_cmd_role_stop *cmd;
613 int ret;
614
615 if (WARN_ON(wl->sta_hlid == WL12XX_INVALID_LINK_ID))
616 return -EINVAL;
617
618 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
619 if (!cmd) {
620 ret = -ENOMEM;
621 goto out;
622 }
623
624 wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wl->role_id);
625
626 cmd->role_id = wl->role_id;
627 cmd->disc_type = DISCONNECT_IMMEDIATE;
628 cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED);
629
630 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
631 if (ret < 0) {
632 wl1271_error("failed to initiate cmd role stop sta");
633 goto out_free;
634 }
635
636 ret = wl1271_cmd_wait_for_event(wl, DISCONNECT_EVENT_COMPLETE_ID);
637 if (ret < 0) {
638 wl1271_error("cmd role stop sta event completion error");
639 goto out_free;
640 }
641
642 wl12xx_free_link(wl, &wl->sta_hlid);
643
644out_free:
645 kfree(cmd);
646
647out:
648 return ret;
649}
650
651int wl12xx_cmd_role_start_ap(struct wl1271 *wl)
652{
653 struct wl12xx_cmd_role_start *cmd;
654 struct ieee80211_bss_conf *bss_conf = &wl->vif->bss_conf;
655 int ret;
656
657 wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wl->role_id);
658
659 /*
660 * We currently do not support hidden SSID. The real SSID
661 * should be fetched from mac80211 first.
662 */
663 if (wl->ssid_len == 0) {
664 wl1271_warning("Hidden SSID currently not supported for AP");
665 ret = -EINVAL;
666 goto out;
667 }
668
669 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
670 if (!cmd) {
671 ret = -ENOMEM;
672 goto out;
673 }
674
675 cmd->role_id = wl->role_id;
676 cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period);
677 cmd->ap.bss_index = WL1271_AP_BSS_INDEX;
678 cmd->ap.global_hlid = WL1271_AP_GLOBAL_HLID;
679 cmd->ap.broadcast_hlid = WL1271_AP_BROADCAST_HLID;
680 cmd->ap.basic_rate_set = cpu_to_le32(wl->basic_rate_set);
681 cmd->ap.beacon_interval = cpu_to_le16(wl->beacon_int);
682 cmd->ap.dtim_interval = bss_conf->dtim_period;
683 cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP;
684 cmd->channel = wl->channel;
685 cmd->ap.ssid_len = wl->ssid_len;
686 cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC;
687 memcpy(cmd->ap.ssid, wl->ssid, wl->ssid_len);
688 cmd->ap.local_rates = cpu_to_le32(0xffffffff);
689
690 switch (wl->band) {
691 case IEEE80211_BAND_2GHZ:
692 cmd->band = RADIO_BAND_2_4GHZ;
693 break;
694 case IEEE80211_BAND_5GHZ:
695 cmd->band = RADIO_BAND_5GHZ;
696 break;
697 default:
698 wl1271_warning("ap start - unknown band: %d", (int)wl->band);
699 cmd->band = RADIO_BAND_2_4GHZ;
700 break;
701 }
702
703 ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0);
704 if (ret < 0) {
705 wl1271_error("failed to initiate cmd role start ap");
706 goto out_free;
707 }
708
709out_free:
710 kfree(cmd);
711
712out:
713 return ret;
714}
715
716int wl12xx_cmd_role_stop_ap(struct wl1271 *wl)
717{
718 struct wl12xx_cmd_role_stop *cmd;
719 int ret;
720
721 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
722 if (!cmd) {
723 ret = -ENOMEM;
724 goto out;
725 }
726
727 wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wl->role_id);
728
729 cmd->role_id = wl->role_id;
730
731 ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0);
732 if (ret < 0) {
733 wl1271_error("failed to initiate cmd role stop ap");
734 goto out_free;
735 }
736
737out_free:
738 kfree(cmd);
739
740out:
741 return ret;
742}
743
744
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300745/**
746 * send test command to firmware
747 *
748 * @wl: wl struct
749 * @buf: buffer containing the command, with all headers, must work with dma
750 * @len: length of the buffer
751 * @answer: is answer needed
752 */
753int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer)
754{
755 int ret;
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200756 size_t res_len = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300757
758 wl1271_debug(DEBUG_CMD, "cmd test");
759
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200760 if (answer)
761 res_len = buf_len;
762
763 ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300764
765 if (ret < 0) {
766 wl1271_warning("TEST command failed");
767 return ret;
768 }
769
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200770 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300771}
772
773/**
774 * read acx from firmware
775 *
776 * @wl: wl struct
777 * @id: acx id
778 * @buf: buffer for the response, including all headers, must work with dma
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300779 * @len: length of buf
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300780 */
781int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, size_t len)
782{
783 struct acx_header *acx = buf;
784 int ret;
785
786 wl1271_debug(DEBUG_CMD, "cmd interrogate");
787
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300788 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300789
790 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300791 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300792
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200793 ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx), len);
794 if (ret < 0)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300795 wl1271_error("INTERROGATE command failed");
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300796
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300797 return ret;
798}
799
800/**
801 * write acx value to firmware
802 *
803 * @wl: wl struct
804 * @id: acx id
805 * @buf: buffer containing acx, including all headers, must work with dma
806 * @len: length of buf
807 */
808int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len)
809{
810 struct acx_header *acx = buf;
811 int ret;
812
813 wl1271_debug(DEBUG_CMD, "cmd configure");
814
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300815 acx->id = cpu_to_le16(id);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300816
817 /* payload length, does not include any headers */
Luciano Coelhod0f63b22009-10-15 10:33:29 +0300818 acx->len = cpu_to_le16(len - sizeof(*acx));
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300819
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200820 ret = wl1271_cmd_send(wl, CMD_CONFIGURE, acx, len, 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300821 if (ret < 0) {
822 wl1271_warning("CONFIGURE command NOK");
823 return ret;
824 }
825
826 return 0;
827}
828
Luciano Coelho94210892009-12-11 15:40:55 +0200829int wl1271_cmd_data_path(struct wl1271 *wl, bool enable)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300830{
831 struct cmd_enabledisable_path *cmd;
832 int ret;
833 u16 cmd_rx, cmd_tx;
834
835 wl1271_debug(DEBUG_CMD, "cmd data path");
836
837 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
838 if (!cmd) {
839 ret = -ENOMEM;
840 goto out;
841 }
842
Luciano Coelho94210892009-12-11 15:40:55 +0200843 /* the channel here is only used for calibration, so hardcoded to 1 */
844 cmd->channel = 1;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300845
846 if (enable) {
847 cmd_rx = CMD_ENABLE_RX;
848 cmd_tx = CMD_ENABLE_TX;
849 } else {
850 cmd_rx = CMD_DISABLE_RX;
851 cmd_tx = CMD_DISABLE_TX;
852 }
853
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200854 ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300855 if (ret < 0) {
856 wl1271_error("rx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200857 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300858 goto out;
859 }
860
861 wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200862 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300863
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200864 ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300865 if (ret < 0) {
866 wl1271_error("tx %s cmd for channel %d failed",
Luciano Coelho94210892009-12-11 15:40:55 +0200867 enable ? "start" : "stop", cmd->channel);
Juuso Oikarinen1b00f2b2010-03-26 12:53:17 +0200868 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300869 }
870
871 wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Luciano Coelho94210892009-12-11 15:40:55 +0200872 enable ? "start" : "stop", cmd->channel);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300873
874out:
875 kfree(cmd);
876 return ret;
877}
878
Eliad Pellerc8bde242011-02-02 09:59:35 +0200879int wl1271_cmd_ps_mode(struct wl1271 *wl, u8 ps_mode)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300880{
881 struct wl1271_cmd_ps_params *ps_params = NULL;
882 int ret = 0;
883
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300884 wl1271_debug(DEBUG_CMD, "cmd set ps mode");
885
886 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
887 if (!ps_params) {
888 ret = -ENOMEM;
889 goto out;
890 }
891
Eliad Pellerc690ec82011-08-14 13:17:07 +0300892 ps_params->role_id = wl->role_id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300893 ps_params->ps_mode = ps_mode;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300894
895 ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200896 sizeof(*ps_params), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300897 if (ret < 0) {
898 wl1271_error("cmd set_ps_mode failed");
899 goto out;
900 }
901
902out:
903 kfree(ps_params);
904 return ret;
905}
906
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300907int wl1271_cmd_template_set(struct wl1271 *wl, u16 template_id,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300908 void *buf, size_t buf_len, int index, u32 rates)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300909{
910 struct wl1271_cmd_template_set *cmd;
911 int ret = 0;
912
913 wl1271_debug(DEBUG_CMD, "cmd template_set %d", template_id);
914
915 WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE);
916 buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE);
917
918 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
919 if (!cmd) {
920 ret = -ENOMEM;
921 goto out;
922 }
923
924 cmd->len = cpu_to_le16(buf_len);
925 cmd->template_type = template_id;
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300926 cmd->enabled_rates = cpu_to_le32(rates);
Arik Nemtsov1e05a812010-10-16 17:44:51 +0200927 cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit;
928 cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit;
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200929 cmd->index = index;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300930
931 if (buf)
932 memcpy(cmd->template_data, buf, buf_len);
933
Juuso Oikarinenfa867e72009-11-02 20:22:13 +0200934 ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300935 if (ret < 0) {
936 wl1271_warning("cmd set_template failed: %d", ret);
937 goto out_free;
938 }
939
940out_free:
941 kfree(cmd);
942
943out:
944 return ret;
945}
946
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300947int wl1271_cmd_build_null_data(struct wl1271 *wl)
948{
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200949 struct sk_buff *skb = NULL;
950 int size;
951 void *ptr;
952 int ret = -ENOMEM;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300953
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300954
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200955 if (wl->bss_type == BSS_TYPE_IBSS) {
956 size = sizeof(struct wl12xx_null_data_template);
957 ptr = NULL;
958 } else {
959 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
960 if (!skb)
961 goto out;
962 size = skb->len;
963 ptr = skb->data;
964 }
965
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300966 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_NULL_DATA, ptr, size, 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200967 wl->basic_rate);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300968
Kalle Valo899e6e62010-03-18 12:26:34 +0200969out:
970 dev_kfree_skb(skb);
Juuso Oikarinena0cb7be2010-03-18 12:26:44 +0200971 if (ret)
972 wl1271_warning("cmd buld null data failed %d", ret);
973
Kalle Valo899e6e62010-03-18 12:26:34 +0200974 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +0300975
976}
977
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200978int wl1271_cmd_build_klv_null_data(struct wl1271 *wl)
979{
980 struct sk_buff *skb = NULL;
981 int ret = -ENOMEM;
982
983 skb = ieee80211_nullfunc_get(wl->hw, wl->vif);
984 if (!skb)
985 goto out;
986
987 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_KLV,
988 skb->data, skb->len,
Juuso Oikarinen606c1482010-04-01 11:38:21 +0300989 CMD_TEMPL_KLV_IDX_NULL_DATA,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +0200990 wl->basic_rate);
Juuso Oikarinenbfb24c92010-03-26 12:53:31 +0200991
992out:
993 dev_kfree_skb(skb);
994 if (ret)
995 wl1271_warning("cmd build klv null data failed %d", ret);
996
997 return ret;
998
999}
1000
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001001int wl1271_cmd_build_ps_poll(struct wl1271 *wl, u16 aid)
1002{
Kalle Valo899e6e62010-03-18 12:26:34 +02001003 struct sk_buff *skb;
1004 int ret = 0;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001005
Kalle Valo899e6e62010-03-18 12:26:34 +02001006 skb = ieee80211_pspoll_get(wl->hw, wl->vif);
1007 if (!skb)
1008 goto out;
Juuso Oikarinenc3fea192009-10-08 21:56:22 +03001009
Kalle Valo899e6e62010-03-18 12:26:34 +02001010 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_PS_POLL, skb->data,
Juuso Oikarinen849923f2010-07-08 17:49:59 +03001011 skb->len, 0, wl->basic_rate_set);
Juuso Oikarinenc3fea192009-10-08 21:56:22 +03001012
Kalle Valo899e6e62010-03-18 12:26:34 +02001013out:
1014 dev_kfree_skb(skb);
1015 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001016}
1017
Kalle Valo818e3062010-03-18 12:26:35 +02001018int wl1271_cmd_build_probe_req(struct wl1271 *wl,
1019 const u8 *ssid, size_t ssid_len,
1020 const u8 *ie, size_t ie_len, u8 band)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001021{
Kalle Valo818e3062010-03-18 12:26:35 +02001022 struct sk_buff *skb;
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001023 int ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001024
Kalle Valo818e3062010-03-18 12:26:35 +02001025 skb = ieee80211_probereq_get(wl->hw, wl->vif, ssid, ssid_len,
1026 ie, ie_len);
1027 if (!skb) {
1028 ret = -ENOMEM;
1029 goto out;
1030 }
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001031
Kalle Valo818e3062010-03-18 12:26:35 +02001032 wl1271_dump(DEBUG_SCAN, "PROBE REQ: ", skb->data, skb->len);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001033
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001034 if (band == IEEE80211_BAND_2GHZ)
1035 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
Juuso Oikarinen606c1482010-04-01 11:38:21 +03001036 skb->data, skb->len, 0,
1037 wl->conf.tx.basic_rate);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001038 else
1039 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
Juuso Oikarinen606c1482010-04-01 11:38:21 +03001040 skb->data, skb->len, 0,
1041 wl->conf.tx.basic_rate_5);
Kalle Valo818e3062010-03-18 12:26:35 +02001042
1043out:
1044 dev_kfree_skb(skb);
Teemu Paasikiviabb0b3b2009-10-13 12:47:50 +03001045 return ret;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001046}
1047
Juuso Oikarinen2f6724b2010-11-24 08:16:57 +02001048struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl,
1049 struct sk_buff *skb)
1050{
1051 int ret;
1052
1053 if (!skb)
1054 skb = ieee80211_ap_probereq_get(wl->hw, wl->vif);
1055 if (!skb)
1056 goto out;
1057
1058 wl1271_dump(DEBUG_SCAN, "AP PROBE REQ: ", skb->data, skb->len);
1059
1060 if (wl->band == IEEE80211_BAND_2GHZ)
1061 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_2_4,
1062 skb->data, skb->len, 0,
1063 wl->conf.tx.basic_rate);
1064 else
1065 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_CFG_PROBE_REQ_5,
1066 skb->data, skb->len, 0,
1067 wl->conf.tx.basic_rate_5);
1068
1069 if (ret < 0)
1070 wl1271_error("Unable to set ap probe request template.");
1071
1072out:
1073 return skb;
1074}
1075
Eliad Pellerc5312772010-12-09 11:31:27 +02001076int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, __be32 ip_addr)
1077{
1078 int ret;
1079 struct wl12xx_arp_rsp_template tmpl;
1080 struct ieee80211_hdr_3addr *hdr;
1081 struct arphdr *arp_hdr;
1082
1083 memset(&tmpl, 0, sizeof(tmpl));
1084
1085 /* mac80211 header */
1086 hdr = &tmpl.hdr;
1087 hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1088 IEEE80211_STYPE_DATA |
1089 IEEE80211_FCTL_TODS);
1090 memcpy(hdr->addr1, wl->vif->bss_conf.bssid, ETH_ALEN);
1091 memcpy(hdr->addr2, wl->vif->addr, ETH_ALEN);
1092 memset(hdr->addr3, 0xff, ETH_ALEN);
1093
1094 /* llc layer */
1095 memcpy(tmpl.llc_hdr, rfc1042_header, sizeof(rfc1042_header));
Eliad Peller6177eae2010-12-22 12:38:52 +01001096 tmpl.llc_type = cpu_to_be16(ETH_P_ARP);
Eliad Pellerc5312772010-12-09 11:31:27 +02001097
1098 /* arp header */
1099 arp_hdr = &tmpl.arp_hdr;
Eliad Peller6177eae2010-12-22 12:38:52 +01001100 arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER);
1101 arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP);
Eliad Pellerc5312772010-12-09 11:31:27 +02001102 arp_hdr->ar_hln = ETH_ALEN;
1103 arp_hdr->ar_pln = 4;
Eliad Peller6177eae2010-12-22 12:38:52 +01001104 arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY);
Eliad Pellerc5312772010-12-09 11:31:27 +02001105
1106 /* arp payload */
1107 memcpy(tmpl.sender_hw, wl->vif->addr, ETH_ALEN);
1108 tmpl.sender_ip = ip_addr;
1109
1110 ret = wl1271_cmd_template_set(wl, CMD_TEMPL_ARP_RSP,
1111 &tmpl, sizeof(tmpl), 0,
1112 wl->basic_rate);
1113
1114 return ret;
1115}
1116
Kalle Valo023e0822010-03-18 12:26:36 +02001117int wl1271_build_qos_null_data(struct wl1271 *wl)
1118{
1119 struct ieee80211_qos_hdr template;
1120
1121 memset(&template, 0, sizeof(template));
1122
1123 memcpy(template.addr1, wl->bssid, ETH_ALEN);
1124 memcpy(template.addr2, wl->mac_addr, ETH_ALEN);
1125 memcpy(template.addr3, wl->bssid, ETH_ALEN);
1126
1127 template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
1128 IEEE80211_STYPE_QOS_NULLFUNC |
1129 IEEE80211_FCTL_TODS);
1130
1131 /* FIXME: not sure what priority to use here */
1132 template.qos_ctrl = cpu_to_le16(0);
1133
1134 return wl1271_cmd_template_set(wl, CMD_TEMPL_QOS_NULL_DATA, &template,
Juuso Oikarinen606c1482010-04-01 11:38:21 +03001135 sizeof(template), 0,
Juuso Oikarinen8eab7b42010-09-24 03:10:11 +02001136 wl->basic_rate);
Kalle Valo023e0822010-03-18 12:26:36 +02001137}
1138
Eliad Pellerc690ec82011-08-14 13:17:07 +03001139int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001140{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001141 struct wl1271_cmd_set_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001142 int ret = 0;
1143
1144 wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id);
1145
1146 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1147 if (!cmd) {
1148 ret = -ENOMEM;
1149 goto out;
1150 }
1151
Eliad Pellerc690ec82011-08-14 13:17:07 +03001152 cmd->hlid = hlid;
1153 cmd->key_id = id;
1154 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001155 cmd->key_action = cpu_to_le16(KEY_SET_ID);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001156 cmd->key_type = KEY_WEP;
1157
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001158 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001159 if (ret < 0) {
1160 wl1271_warning("cmd set_default_wep_key failed: %d", ret);
1161 goto out;
1162 }
1163
1164out:
1165 kfree(cmd);
1166
1167 return ret;
1168}
1169
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001170int wl1271_cmd_set_sta_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03001171 u8 key_size, const u8 *key, const u8 *addr,
1172 u32 tx_seq_32, u16 tx_seq_16)
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001173{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001174 struct wl1271_cmd_set_keys *cmd;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001175 int ret = 0;
1176
1177 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1178 if (!cmd) {
1179 ret = -ENOMEM;
1180 goto out;
1181 }
1182
Eliad Pellerc690ec82011-08-14 13:17:07 +03001183 cmd->hlid = wl->sta_hlid;
1184
1185 if (key_type == KEY_WEP)
1186 cmd->lid_key_type = WEP_DEFAULT_LID_TYPE;
1187 else if (is_broadcast_ether_addr(addr))
1188 cmd->lid_key_type = BROADCAST_LID_TYPE;
1189 else
1190 cmd->lid_key_type = UNICAST_LID_TYPE;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001191
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001192 cmd->key_action = cpu_to_le16(action);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001193 cmd->key_size = key_size;
1194 cmd->key_type = key_type;
1195
Luciano Coelhod0f63b22009-10-15 10:33:29 +03001196 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1197 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
Juuso Oikarinenac4e4ce2009-10-08 21:56:19 +03001198
Eliad Pellerc690ec82011-08-14 13:17:07 +03001199 cmd->key_id = id;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001200
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001201 if (key_type == KEY_TKIP) {
1202 /*
1203 * We get the key in the following form:
1204 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1205 * but the target is expecting:
1206 * TKIP - RX MIC - TX MIC
1207 */
1208 memcpy(cmd->key, key, 16);
1209 memcpy(cmd->key + 16, key + 24, 8);
1210 memcpy(cmd->key + 24, key + 16, 8);
1211
1212 } else {
1213 memcpy(cmd->key, key, key_size);
1214 }
1215
1216 wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd));
1217
Juuso Oikarinenfa867e72009-11-02 20:22:13 +02001218 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001219 if (ret < 0) {
1220 wl1271_warning("could not set keys");
Juuso Oikarinen152ee6e2010-02-18 13:25:42 +02001221 goto out;
Luciano Coelhof5fc0f82009-08-06 16:25:28 +03001222 }
1223
1224out:
1225 kfree(cmd);
1226
1227 return ret;
1228}
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001229
Eliad Pellerc690ec82011-08-14 13:17:07 +03001230/*
1231 * TODO: merge with sta/ibss into 1 set_key function.
1232 * note there are slight diffs
1233 */
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001234int wl1271_cmd_set_ap_key(struct wl1271 *wl, u16 action, u8 id, u8 key_type,
1235 u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32,
1236 u16 tx_seq_16)
1237{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001238 struct wl1271_cmd_set_keys *cmd;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001239 int ret = 0;
1240 u8 lid_type;
1241
1242 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1243 if (!cmd)
1244 return -ENOMEM;
1245
1246 if (hlid == WL1271_AP_BROADCAST_HLID) {
1247 if (key_type == KEY_WEP)
1248 lid_type = WEP_DEFAULT_LID_TYPE;
1249 else
1250 lid_type = BROADCAST_LID_TYPE;
1251 } else {
1252 lid_type = UNICAST_LID_TYPE;
1253 }
1254
1255 wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d"
1256 " hlid: %d", (int)action, (int)id, (int)lid_type,
1257 (int)key_type, (int)hlid);
1258
1259 cmd->lid_key_type = lid_type;
1260 cmd->hlid = hlid;
1261 cmd->key_action = cpu_to_le16(action);
1262 cmd->key_size = key_size;
1263 cmd->key_type = key_type;
1264 cmd->key_id = id;
1265 cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16);
1266 cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32);
1267
1268 if (key_type == KEY_TKIP) {
1269 /*
1270 * We get the key in the following form:
1271 * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes)
1272 * but the target is expecting:
1273 * TKIP - RX MIC - TX MIC
1274 */
1275 memcpy(cmd->key, key, 16);
1276 memcpy(cmd->key + 16, key + 24, 8);
1277 memcpy(cmd->key + 24, key + 16, 8);
1278 } else {
1279 memcpy(cmd->key, key, key_size);
1280 }
1281
1282 wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd));
1283
1284 ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0);
1285 if (ret < 0) {
1286 wl1271_warning("could not set ap keys");
1287 goto out;
1288 }
1289
1290out:
1291 kfree(cmd);
1292 return ret;
1293}
1294
Eliad Pellerc690ec82011-08-14 13:17:07 +03001295int wl12xx_cmd_set_peer_state(struct wl1271 *wl)
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001296{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001297 struct wl12xx_cmd_set_peer_state *cmd;
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001298 int ret = 0;
1299
Eliad Pellerc690ec82011-08-14 13:17:07 +03001300 wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", wl->sta_hlid);
Luciano Coelho25a7dc62009-10-12 15:08:42 +03001301
1302 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1303 if (!cmd) {
1304 ret = -ENOMEM;
1305 goto out;
1306 }
1307
Eliad Pellerc690ec82011-08-14 13:17:07 +03001308 cmd->hlid = wl->sta_hlid;
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001309 cmd->state = WL1271_CMD_STA_STATE_CONNECTED;
1310
Eliad Pellerc690ec82011-08-14 13:17:07 +03001311 ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0);
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001312 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001313 wl1271_error("failed to send set peer state command");
Juuso Oikarinenbe86cbe2010-05-27 12:53:01 +03001314 goto out_free;
1315 }
1316
1317out_free:
1318 kfree(cmd);
1319
1320out:
1321 return ret;
1322}
Eliad Pellerc690ec82011-08-14 13:17:07 +03001323int wl12xx_cmd_add_peer(struct wl1271 *wl, struct ieee80211_sta *sta, u8 hlid)
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001324{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001325 struct wl12xx_cmd_add_peer *cmd;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001326 int ret;
1327
Eliad Pellerc690ec82011-08-14 13:17:07 +03001328 wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001329
1330 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1331 if (!cmd) {
1332 ret = -ENOMEM;
1333 goto out;
1334 }
1335
1336 /* currently we don't support UAPSD */
1337 cmd->sp_len = 0;
1338
1339 memcpy(cmd->addr, sta->addr, ETH_ALEN);
1340 cmd->bss_index = WL1271_AP_BSS_INDEX;
1341 cmd->aid = sta->aid;
1342 cmd->hlid = hlid;
Arik Nemtsovb4d38db2011-06-27 23:58:46 +03001343 cmd->wmm = sta->wme ? 1 : 0;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001344
1345 cmd->supported_rates = cpu_to_le32(wl1271_tx_enabled_rates_get(wl,
1346 sta->supp_rates[wl->band]));
1347
Eliad Pellerc690ec82011-08-14 13:17:07 +03001348 wl1271_debug(DEBUG_CMD, "new peer rates: 0x%x", cmd->supported_rates);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001349
Eliad Pellerc690ec82011-08-14 13:17:07 +03001350 ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001351 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001352 wl1271_error("failed to initiate cmd add peer");
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001353 goto out_free;
1354 }
1355
1356out_free:
1357 kfree(cmd);
1358
1359out:
1360 return ret;
1361}
1362
Eliad Pellerc690ec82011-08-14 13:17:07 +03001363int wl12xx_cmd_remove_peer(struct wl1271 *wl, u8 hlid)
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001364{
Eliad Pellerc690ec82011-08-14 13:17:07 +03001365 struct wl12xx_cmd_remove_peer *cmd;
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001366 int ret;
1367
Eliad Pellerc690ec82011-08-14 13:17:07 +03001368 wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001369
1370 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1371 if (!cmd) {
1372 ret = -ENOMEM;
1373 goto out;
1374 }
1375
1376 cmd->hlid = hlid;
1377 /* We never send a deauth, mac80211 is in charge of this */
1378 cmd->reason_opcode = 0;
1379 cmd->send_deauth_flag = 0;
1380
Eliad Pellerc690ec82011-08-14 13:17:07 +03001381 ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001382 if (ret < 0) {
Eliad Pellerc690ec82011-08-14 13:17:07 +03001383 wl1271_error("failed to initiate cmd remove peer");
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001384 goto out_free;
1385 }
1386
Arik Nemtsov05285cf2010-11-12 17:15:03 +02001387 /*
1388 * We are ok with a timeout here. The event is sometimes not sent
1389 * due to a firmware bug.
1390 */
Eliad Pellerc690ec82011-08-14 13:17:07 +03001391 wl1271_cmd_wait_for_event_or_timeout(wl,
1392 PEER_REMOVE_COMPLETE_EVENT_ID);
Arik Nemtsov98bdaab2010-10-16 18:08:58 +02001393
1394out_free:
1395 kfree(cmd);
1396
1397out:
1398 return ret;
1399}
Ido Yariv95dac04f2011-06-06 14:57:06 +03001400
1401int wl12xx_cmd_config_fwlog(struct wl1271 *wl)
1402{
1403 struct wl12xx_cmd_config_fwlog *cmd;
1404 int ret = 0;
1405
1406 wl1271_debug(DEBUG_CMD, "cmd config firmware logger");
1407
1408 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1409 if (!cmd) {
1410 ret = -ENOMEM;
1411 goto out;
1412 }
1413
1414 cmd->logger_mode = wl->conf.fwlog.mode;
1415 cmd->log_severity = wl->conf.fwlog.severity;
1416 cmd->timestamp = wl->conf.fwlog.timestamp;
1417 cmd->output = wl->conf.fwlog.output;
1418 cmd->threshold = wl->conf.fwlog.threshold;
1419
1420 ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0);
1421 if (ret < 0) {
1422 wl1271_error("failed to send config firmware logger command");
1423 goto out_free;
1424 }
1425
1426out_free:
1427 kfree(cmd);
1428
1429out:
1430 return ret;
1431}
1432
1433int wl12xx_cmd_start_fwlog(struct wl1271 *wl)
1434{
1435 struct wl12xx_cmd_start_fwlog *cmd;
1436 int ret = 0;
1437
1438 wl1271_debug(DEBUG_CMD, "cmd start firmware logger");
1439
1440 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1441 if (!cmd) {
1442 ret = -ENOMEM;
1443 goto out;
1444 }
1445
1446 ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0);
1447 if (ret < 0) {
1448 wl1271_error("failed to send start firmware logger command");
1449 goto out_free;
1450 }
1451
1452out_free:
1453 kfree(cmd);
1454
1455out:
1456 return ret;
1457}
1458
1459int wl12xx_cmd_stop_fwlog(struct wl1271 *wl)
1460{
1461 struct wl12xx_cmd_stop_fwlog *cmd;
1462 int ret = 0;
1463
1464 wl1271_debug(DEBUG_CMD, "cmd stop firmware logger");
1465
1466 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1467 if (!cmd) {
1468 ret = -ENOMEM;
1469 goto out;
1470 }
1471
1472 ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0);
1473 if (ret < 0) {
1474 wl1271_error("failed to send stop firmware logger command");
1475 goto out_free;
1476 }
1477
1478out_free:
1479 kfree(cmd);
1480
1481out:
1482 return ret;
1483}
Eliad Pellera7cba382011-08-14 13:17:16 +03001484
1485static int wl12xx_cmd_roc(struct wl1271 *wl, u8 role_id)
1486{
1487 struct wl12xx_cmd_roc *cmd;
1488 int ret = 0;
1489
1490 wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", wl->channel, role_id);
1491
1492 if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID))
1493 return -EINVAL;
1494
1495 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1496 if (!cmd) {
1497 ret = -ENOMEM;
1498 goto out;
1499 }
1500
1501 cmd->role_id = role_id;
1502 cmd->channel = wl->channel;
1503 switch (wl->band) {
1504 case IEEE80211_BAND_2GHZ:
1505 cmd->band = RADIO_BAND_2_4GHZ;
1506 break;
1507 case IEEE80211_BAND_5GHZ:
1508 cmd->band = RADIO_BAND_5GHZ;
1509 break;
1510 default:
1511 wl1271_error("roc - unknown band: %d", (int)wl->band);
1512 ret = -EINVAL;
1513 goto out_free;
1514 }
1515
1516
1517 ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0);
1518 if (ret < 0) {
1519 wl1271_error("failed to send ROC command");
1520 goto out_free;
1521 }
1522
1523out_free:
1524 kfree(cmd);
1525
1526out:
1527 return ret;
1528}
1529
1530static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id)
1531{
1532 struct wl12xx_cmd_croc *cmd;
1533 int ret = 0;
1534
1535 wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id);
1536
1537 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
1538 if (!cmd) {
1539 ret = -ENOMEM;
1540 goto out;
1541 }
1542 cmd->role_id = role_id;
1543
1544 ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd,
1545 sizeof(*cmd), 0);
1546 if (ret < 0) {
1547 wl1271_error("failed to send ROC command");
1548 goto out_free;
1549 }
1550
1551out_free:
1552 kfree(cmd);
1553
1554out:
1555 return ret;
1556}
Eliad Peller251c1772011-08-14 13:17:17 +03001557
1558int wl12xx_roc(struct wl1271 *wl, u8 role_id)
1559{
1560 int ret = 0;
1561
1562 if (WARN_ON(test_bit(role_id, wl->roc_map)))
1563 return 0;
1564
1565 ret = wl12xx_cmd_roc(wl, role_id);
1566 if (ret < 0)
1567 goto out;
1568
1569 ret = wl1271_cmd_wait_for_event(wl,
1570 REMAIN_ON_CHANNEL_COMPLETE_EVENT_ID);
1571 if (ret < 0) {
1572 wl1271_error("cmd roc event completion error");
1573 goto out;
1574 }
1575
1576 __set_bit(role_id, wl->roc_map);
1577out:
1578 return ret;
1579}
1580
1581int wl12xx_croc(struct wl1271 *wl, u8 role_id)
1582{
1583 int ret = 0;
1584
1585 if (WARN_ON(!test_bit(role_id, wl->roc_map)))
1586 return 0;
1587
1588 ret = wl12xx_cmd_croc(wl, role_id);
1589 if (ret < 0)
1590 goto out;
1591
1592 __clear_bit(role_id, wl->roc_map);
1593out:
1594 return ret;
1595}