blob: 770f260726bd52c7c85f7ad5cbd55abc44907030 [file] [log] [blame]
Kalle Valoef2f8d42009-06-12 14:17:19 +03001#include "wl1251_cmd.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +03002
3#include <linux/module.h>
4#include <linux/crc7.h>
Kalle Valo2f01a1f2009-04-29 23:33:31 +03005
Kalle Valo13674112009-06-12 14:17:25 +03006#include "wl1251.h"
Kalle Valo29d904c2009-08-07 13:35:11 +03007#include "wl1251_reg.h"
Bob Copeland0764de62009-08-07 13:32:56 +03008#include "wl1251_io.h"
Kalle Valoef2f8d42009-06-12 14:17:19 +03009#include "wl1251_ps.h"
10#include "wl1251_acx.h"
Kalle Valo2f01a1f2009-04-29 23:33:31 +030011
Kalle Valoff258392009-06-12 14:14:19 +030012/**
13 * send command to firmware
14 *
15 * @wl: wl struct
16 * @id: command id
17 * @buf: buffer containing the command, must work with dma
18 * @len: length of the buffer
19 */
Kalle Valo80301cd2009-06-12 14:17:39 +030020int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030021{
Kalle Valo80301cd2009-06-12 14:17:39 +030022 struct wl1251_cmd_header *cmd;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030023 unsigned long timeout;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030024 u32 intr;
25 int ret = 0;
26
Kalle Valoff258392009-06-12 14:14:19 +030027 cmd = buf;
28 cmd->id = id;
29 cmd->status = 0;
30
31 WARN_ON(len % 4 != 0);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030032
Bob Copeland0764de62009-08-07 13:32:56 +030033 wl1251_mem_write(wl, wl->cmd_box_addr, buf, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030034
Kalle Valo80301cd2009-06-12 14:17:39 +030035 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030036
Kalle Valo80301cd2009-06-12 14:17:39 +030037 timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030038
Kalle Valo80301cd2009-06-12 14:17:39 +030039 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Kalle Valo0e71bb02009-08-07 13:33:57 +030040 while (!(intr & WL1251_ACX_INTR_CMD_COMPLETE)) {
Kalle Valo2f01a1f2009-04-29 23:33:31 +030041 if (time_after(jiffies, timeout)) {
Kalle Valo80301cd2009-06-12 14:17:39 +030042 wl1251_error("command complete timeout");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030043 ret = -ETIMEDOUT;
44 goto out;
45 }
46
47 msleep(1);
48
Kalle Valo80301cd2009-06-12 14:17:39 +030049 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030050 }
51
Kalle Valo80301cd2009-06-12 14:17:39 +030052 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
Kalle Valo0e71bb02009-08-07 13:33:57 +030053 WL1251_ACX_INTR_CMD_COMPLETE);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030054
55out:
Kalle Valo2f01a1f2009-04-29 23:33:31 +030056 return ret;
57}
58
Kalle Valoff258392009-06-12 14:14:19 +030059/**
60 * send test command to firmware
61 *
62 * @wl: wl struct
Ari Kauppi6021b282009-06-12 14:16:13 +030063 * @buf: buffer containing the command, with all headers, must work with dma
Kalle Valoff258392009-06-12 14:14:19 +030064 * @len: length of the buffer
65 * @answer: is answer needed
Kalle Valoff258392009-06-12 14:14:19 +030066 */
Kalle Valo80301cd2009-06-12 14:17:39 +030067int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
Kalle Valo2f01a1f2009-04-29 23:33:31 +030068{
69 int ret;
70
Kalle Valo80301cd2009-06-12 14:17:39 +030071 wl1251_debug(DEBUG_CMD, "cmd test");
Kalle Valo2f01a1f2009-04-29 23:33:31 +030072
Kalle Valo80301cd2009-06-12 14:17:39 +030073 ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
Kalle Valoff258392009-06-12 14:14:19 +030074
Kalle Valo2f01a1f2009-04-29 23:33:31 +030075 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +030076 wl1251_warning("TEST command failed");
Ari Kauppi6021b282009-06-12 14:16:13 +030077 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030078 }
79
80 if (answer) {
Kalle Valo80301cd2009-06-12 14:17:39 +030081 struct wl1251_command *cmd_answer;
Ari Kauppi6021b282009-06-12 14:16:13 +030082
Kalle Valo2f01a1f2009-04-29 23:33:31 +030083 /*
84 * The test command got in, we can read the answer.
Kalle Valo80301cd2009-06-12 14:17:39 +030085 * The answer would be a wl1251_command, where the
Kalle Valo2f01a1f2009-04-29 23:33:31 +030086 * parameter array contains the actual answer.
87 */
Bob Copeland0764de62009-08-07 13:32:56 +030088 wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030089
Ari Kauppi6021b282009-06-12 14:16:13 +030090 cmd_answer = buf;
91
92 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
Kalle Valo80301cd2009-06-12 14:17:39 +030093 wl1251_error("TEST command answer error: %d",
Ari Kauppi6021b282009-06-12 14:16:13 +030094 cmd_answer->header.status);
Kalle Valo2f01a1f2009-04-29 23:33:31 +030095 }
96
Ari Kauppi6021b282009-06-12 14:16:13 +030097 return 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +030098}
99
Kalle Valoff258392009-06-12 14:14:19 +0300100/**
101 * read acx from firmware
102 *
103 * @wl: wl struct
104 * @id: acx id
105 * @buf: buffer for the response, including all headers, must work with dma
106 * @len: lenght of buf
107 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300108int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300109{
Kalle Valoff258392009-06-12 14:14:19 +0300110 struct acx_header *acx = buf;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300111 int ret;
112
Kalle Valo80301cd2009-06-12 14:17:39 +0300113 wl1251_debug(DEBUG_CMD, "cmd interrogate");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300114
Kalle Valoff258392009-06-12 14:14:19 +0300115 acx->id = id;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300116
Kalle Valoff258392009-06-12 14:14:19 +0300117 /* payload length, does not include any headers */
118 acx->len = len - sizeof(*acx);
119
Kalle Valo80301cd2009-06-12 14:17:39 +0300120 ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300121 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300122 wl1251_error("INTERROGATE command failed");
Kalle Valoff258392009-06-12 14:14:19 +0300123 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300124 }
125
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300126 /* the interrogate command got in, we can read the answer */
Bob Copeland0764de62009-08-07 13:32:56 +0300127 wl1251_mem_read(wl, wl->cmd_box_addr, buf, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300128
Kalle Valoff258392009-06-12 14:14:19 +0300129 acx = buf;
130 if (acx->cmd.status != CMD_STATUS_SUCCESS)
Kalle Valo80301cd2009-06-12 14:17:39 +0300131 wl1251_error("INTERROGATE command error: %d",
Kalle Valoff258392009-06-12 14:14:19 +0300132 acx->cmd.status);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300133
Kalle Valoff258392009-06-12 14:14:19 +0300134out:
135 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300136}
137
Kalle Valoff258392009-06-12 14:14:19 +0300138/**
139 * write acx value to firmware
140 *
141 * @wl: wl struct
142 * @id: acx id
143 * @buf: buffer containing acx, including all headers, must work with dma
144 * @len: length of buf
145 */
Kalle Valo80301cd2009-06-12 14:17:39 +0300146int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300147{
Kalle Valoff258392009-06-12 14:14:19 +0300148 struct acx_header *acx = buf;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300149 int ret;
150
Kalle Valo80301cd2009-06-12 14:17:39 +0300151 wl1251_debug(DEBUG_CMD, "cmd configure");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300152
Kalle Valoff258392009-06-12 14:14:19 +0300153 acx->id = id;
154
155 /* payload length, does not include any headers */
156 acx->len = len - sizeof(*acx);
157
Kalle Valo80301cd2009-06-12 14:17:39 +0300158 ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300159 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300160 wl1251_warning("CONFIGURE command NOK");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300161 return ret;
162 }
163
164 return 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300165}
166
Kalle Valo80301cd2009-06-12 14:17:39 +0300167int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300168 void *bitmap, u16 bitmap_len, u8 bitmap_control)
169{
Kalle Valo80301cd2009-06-12 14:17:39 +0300170 struct wl1251_cmd_vbm_update *vbm;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300171 int ret;
172
Kalle Valo80301cd2009-06-12 14:17:39 +0300173 wl1251_debug(DEBUG_CMD, "cmd vbm");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300174
Kalle Valoff258392009-06-12 14:14:19 +0300175 vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
176 if (!vbm) {
177 ret = -ENOMEM;
178 goto out;
179 }
180
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300181 /* Count and period will be filled by the target */
Kalle Valoff258392009-06-12 14:14:19 +0300182 vbm->tim.bitmap_ctrl = bitmap_control;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300183 if (bitmap_len > PARTIAL_VBM_MAX) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300184 wl1251_warning("cmd vbm len is %d B, truncating to %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300185 bitmap_len, PARTIAL_VBM_MAX);
186 bitmap_len = PARTIAL_VBM_MAX;
187 }
Kalle Valoff258392009-06-12 14:14:19 +0300188 memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
189 vbm->tim.identity = identity;
190 vbm->tim.length = bitmap_len + 3;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300191
Kalle Valoff258392009-06-12 14:14:19 +0300192 vbm->len = cpu_to_le16(bitmap_len + 5);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300193
Kalle Valo80301cd2009-06-12 14:17:39 +0300194 ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300195 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300196 wl1251_error("VBM command failed");
Kalle Valoff258392009-06-12 14:14:19 +0300197 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300198 }
199
Kalle Valoff258392009-06-12 14:14:19 +0300200out:
201 kfree(vbm);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300202 return 0;
203}
204
Kalle Valo80301cd2009-06-12 14:17:39 +0300205int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300206{
Kalle Valoff258392009-06-12 14:14:19 +0300207 struct cmd_enabledisable_path *cmd;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300208 int ret;
209 u16 cmd_rx, cmd_tx;
210
Kalle Valo80301cd2009-06-12 14:17:39 +0300211 wl1251_debug(DEBUG_CMD, "cmd data path");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300212
Kalle Valoff258392009-06-12 14:14:19 +0300213 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
214 if (!cmd) {
215 ret = -ENOMEM;
216 goto out;
217 }
218
219 cmd->channel = channel;
220
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300221 if (enable) {
222 cmd_rx = CMD_ENABLE_RX;
223 cmd_tx = CMD_ENABLE_TX;
224 } else {
225 cmd_rx = CMD_DISABLE_RX;
226 cmd_tx = CMD_DISABLE_TX;
227 }
228
Kalle Valo80301cd2009-06-12 14:17:39 +0300229 ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300230 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300231 wl1251_error("rx %s cmd for channel %d failed",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300232 enable ? "start" : "stop", channel);
Kalle Valoff258392009-06-12 14:14:19 +0300233 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300234 }
235
Kalle Valo80301cd2009-06-12 14:17:39 +0300236 wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300237 enable ? "start" : "stop", channel);
238
Kalle Valo80301cd2009-06-12 14:17:39 +0300239 ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300240 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300241 wl1251_error("tx %s cmd for channel %d failed",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300242 enable ? "start" : "stop", channel);
243 return ret;
244 }
245
Kalle Valo80301cd2009-06-12 14:17:39 +0300246 wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300247 enable ? "start" : "stop", channel);
248
Kalle Valoff258392009-06-12 14:14:19 +0300249out:
250 kfree(cmd);
251 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300252}
253
Kalle Valoc88f8752009-08-07 13:34:34 +0300254int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel,
255 u16 beacon_interval, u8 dtim_interval)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300256{
Kalle Valoff258392009-06-12 14:14:19 +0300257 struct cmd_join *join;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300258 int ret, i;
259 u8 *bssid;
260
Kalle Valoff258392009-06-12 14:14:19 +0300261 join = kzalloc(sizeof(*join), GFP_KERNEL);
262 if (!join) {
263 ret = -ENOMEM;
264 goto out;
265 }
266
Kalle Valoc88f8752009-08-07 13:34:34 +0300267 wl1251_debug(DEBUG_CMD, "cmd join%s ch %d %d/%d",
Kalle Valoe2fd4612009-08-07 13:34:12 +0300268 bss_type == BSS_TYPE_IBSS ? " ibss" : "",
Kalle Valoc88f8752009-08-07 13:34:34 +0300269 channel, beacon_interval, dtim_interval);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300270
271 /* Reverse order BSSID */
Kalle Valoff258392009-06-12 14:14:19 +0300272 bssid = (u8 *) &join->bssid_lsb;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300273 for (i = 0; i < ETH_ALEN; i++)
274 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
275
Kalle Valoff258392009-06-12 14:14:19 +0300276 join->rx_config_options = wl->rx_config;
277 join->rx_filter_options = wl->rx_filter;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300278
Kalle Valof26b32e2009-08-07 13:35:33 +0300279 /*
280 * FIXME: disable temporarily all filters because after commit
281 * 9cef8737 "mac80211: fix managed mode BSSID handling" broke
282 * association. The filter logic needs to be implemented properly
283 * and once that is done, this hack can be removed.
284 */
285 join->rx_config_options = 0;
286 join->rx_filter_options = WL1251_DEFAULT_RX_FILTER;
287
Kalle Valoff258392009-06-12 14:14:19 +0300288 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300289 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
290
Kalle Valoff258392009-06-12 14:14:19 +0300291 join->beacon_interval = beacon_interval;
292 join->dtim_interval = dtim_interval;
293 join->bss_type = bss_type;
Kalle Valoc88f8752009-08-07 13:34:34 +0300294 join->channel = channel;
Kalle Valoff258392009-06-12 14:14:19 +0300295 join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300296
Kalle Valo80301cd2009-06-12 14:17:39 +0300297 ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300298 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300299 wl1251_error("failed to initiate cmd join");
Kalle Valoff258392009-06-12 14:14:19 +0300300 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300301 }
302
Kalle Valoff258392009-06-12 14:14:19 +0300303out:
304 kfree(join);
305 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300306}
307
Kalle Valo80301cd2009-06-12 14:17:39 +0300308int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300309{
Kalle Valo80301cd2009-06-12 14:17:39 +0300310 struct wl1251_cmd_ps_params *ps_params = NULL;
Kalle Valoff258392009-06-12 14:14:19 +0300311 int ret = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300312
Kalle Valo80301cd2009-06-12 14:17:39 +0300313 wl1251_debug(DEBUG_CMD, "cmd set ps mode");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300314
Kalle Valoff258392009-06-12 14:14:19 +0300315 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
316 if (!ps_params) {
317 ret = -ENOMEM;
318 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300319 }
320
Kalle Valoff258392009-06-12 14:14:19 +0300321 ps_params->ps_mode = ps_mode;
322 ps_params->send_null_data = 1;
323 ps_params->retries = 5;
324 ps_params->hang_over_period = 128;
325 ps_params->null_data_rate = 1; /* 1 Mbps */
326
Kalle Valo80301cd2009-06-12 14:17:39 +0300327 ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
Kalle Valoff258392009-06-12 14:14:19 +0300328 sizeof(*ps_params));
329 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300330 wl1251_error("cmd set_ps_mode failed");
Kalle Valoff258392009-06-12 14:14:19 +0300331 goto out;
332 }
333
334out:
335 kfree(ps_params);
336 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300337}
338
Kalle Valo80301cd2009-06-12 14:17:39 +0300339int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
Kalle Valoff258392009-06-12 14:14:19 +0300340 size_t len)
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300341{
Kalle Valoff258392009-06-12 14:14:19 +0300342 struct cmd_read_write_memory *cmd;
343 int ret = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300344
Kalle Valo80301cd2009-06-12 14:17:39 +0300345 wl1251_debug(DEBUG_CMD, "cmd read memory");
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300346
Kalle Valoff258392009-06-12 14:14:19 +0300347 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
348 if (!cmd) {
349 ret = -ENOMEM;
350 goto out;
351 }
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300352
Kalle Valoff258392009-06-12 14:14:19 +0300353 WARN_ON(len > MAX_READ_SIZE);
354 len = min_t(size_t, len, MAX_READ_SIZE);
355
356 cmd->addr = addr;
357 cmd->size = len;
358
Kalle Valo80301cd2009-06-12 14:17:39 +0300359 ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300360 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300361 wl1251_error("read memory command failed: %d", ret);
Kalle Valoff258392009-06-12 14:14:19 +0300362 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300363 }
364
365 /* the read command got in, we can now read the answer */
Bob Copeland0764de62009-08-07 13:32:56 +0300366 wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300367
Kalle Valoff258392009-06-12 14:14:19 +0300368 if (cmd->header.status != CMD_STATUS_SUCCESS)
Kalle Valo80301cd2009-06-12 14:17:39 +0300369 wl1251_error("error in read command result: %d",
Kalle Valoff258392009-06-12 14:14:19 +0300370 cmd->header.status);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300371
Kalle Valoff258392009-06-12 14:14:19 +0300372 memcpy(answer, cmd->value, len);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300373
Kalle Valoff258392009-06-12 14:14:19 +0300374out:
375 kfree(cmd);
376 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300377}
378
Kalle Valo80301cd2009-06-12 14:17:39 +0300379int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300380 void *buf, size_t buf_len)
381{
Kalle Valo80301cd2009-06-12 14:17:39 +0300382 struct wl1251_cmd_packet_template *cmd;
Kalle Valoff258392009-06-12 14:14:19 +0300383 size_t cmd_len;
384 int ret = 0;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300385
Kalle Valo80301cd2009-06-12 14:17:39 +0300386 wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300387
Kalle Valo80301cd2009-06-12 14:17:39 +0300388 WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
389 buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
Kalle Valoff258392009-06-12 14:14:19 +0300390 cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300391
Kalle Valoff258392009-06-12 14:14:19 +0300392 cmd = kzalloc(cmd_len, GFP_KERNEL);
393 if (!cmd) {
394 ret = -ENOMEM;
395 goto out;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300396 }
397
Kalle Valoff258392009-06-12 14:14:19 +0300398 cmd->size = cpu_to_le16(buf_len);
399
400 if (buf)
401 memcpy(cmd->data, buf, buf_len);
402
Kalle Valo80301cd2009-06-12 14:17:39 +0300403 ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
Kalle Valoff258392009-06-12 14:14:19 +0300404 if (ret < 0) {
Kalle Valo80301cd2009-06-12 14:17:39 +0300405 wl1251_warning("cmd set_template failed: %d", ret);
Kalle Valoff258392009-06-12 14:14:19 +0300406 goto out;
407 }
408
409out:
410 kfree(cmd);
411 return ret;
Kalle Valo2f01a1f2009-04-29 23:33:31 +0300412}