1 #include "wl1251_cmd.h"
3 #include <linux/module.h>
4 #include <linux/crc7.h>
5 #include <linux/spi/spi.h>
10 #include "wl1251_ps.h"
11 #include "wl1251_acx.h"
14 * send command to firmware
18 * @buf: buffer containing the command, must work with dma
19 * @len: length of the buffer
21 int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len)
23 struct wl1251_cmd_header *cmd;
24 unsigned long timeout;
32 WARN_ON(len % 4 != 0);
34 wl1251_mem_write(wl, wl->cmd_box_addr, buf, len);
36 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD);
38 timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT);
40 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
41 while (!(intr & wl->chip.intr_cmd_complete)) {
42 if (time_after(jiffies, timeout)) {
43 wl1251_error("command complete timeout");
50 intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR);
53 wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK,
54 wl->chip.intr_cmd_complete);
61 * send test command to firmware
64 * @buf: buffer containing the command, with all headers, must work with dma
65 * @len: length of the buffer
66 * @answer: is answer needed
68 int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer)
72 wl1251_debug(DEBUG_CMD, "cmd test");
74 ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len);
77 wl1251_warning("TEST command failed");
82 struct wl1251_command *cmd_answer;
85 * The test command got in, we can read the answer.
86 * The answer would be a wl1251_command, where the
87 * parameter array contains the actual answer.
89 wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len);
93 if (cmd_answer->header.status != CMD_STATUS_SUCCESS)
94 wl1251_error("TEST command answer error: %d",
95 cmd_answer->header.status);
102 * read acx from firmware
106 * @buf: buffer for the response, including all headers, must work with dma
107 * @len: lenght of buf
109 int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len)
111 struct acx_header *acx = buf;
114 wl1251_debug(DEBUG_CMD, "cmd interrogate");
118 /* payload length, does not include any headers */
119 acx->len = len - sizeof(*acx);
121 ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx));
123 wl1251_error("INTERROGATE command failed");
127 /* the interrogate command got in, we can read the answer */
128 wl1251_mem_read(wl, wl->cmd_box_addr, buf, len);
131 if (acx->cmd.status != CMD_STATUS_SUCCESS)
132 wl1251_error("INTERROGATE command error: %d",
140 * write acx value to firmware
144 * @buf: buffer containing acx, including all headers, must work with dma
145 * @len: length of buf
147 int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len)
149 struct acx_header *acx = buf;
152 wl1251_debug(DEBUG_CMD, "cmd configure");
156 /* payload length, does not include any headers */
157 acx->len = len - sizeof(*acx);
159 ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len);
161 wl1251_warning("CONFIGURE command NOK");
168 int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity,
169 void *bitmap, u16 bitmap_len, u8 bitmap_control)
171 struct wl1251_cmd_vbm_update *vbm;
174 wl1251_debug(DEBUG_CMD, "cmd vbm");
176 vbm = kzalloc(sizeof(*vbm), GFP_KERNEL);
182 /* Count and period will be filled by the target */
183 vbm->tim.bitmap_ctrl = bitmap_control;
184 if (bitmap_len > PARTIAL_VBM_MAX) {
185 wl1251_warning("cmd vbm len is %d B, truncating to %d",
186 bitmap_len, PARTIAL_VBM_MAX);
187 bitmap_len = PARTIAL_VBM_MAX;
189 memcpy(vbm->tim.pvb_field, bitmap, bitmap_len);
190 vbm->tim.identity = identity;
191 vbm->tim.length = bitmap_len + 3;
193 vbm->len = cpu_to_le16(bitmap_len + 5);
195 ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm));
197 wl1251_error("VBM command failed");
206 int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable)
208 struct cmd_enabledisable_path *cmd;
212 wl1251_debug(DEBUG_CMD, "cmd data path");
214 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
220 cmd->channel = channel;
223 cmd_rx = CMD_ENABLE_RX;
224 cmd_tx = CMD_ENABLE_TX;
226 cmd_rx = CMD_DISABLE_RX;
227 cmd_tx = CMD_DISABLE_TX;
230 ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd));
232 wl1251_error("rx %s cmd for channel %d failed",
233 enable ? "start" : "stop", channel);
237 wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d",
238 enable ? "start" : "stop", channel);
240 ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd));
242 wl1251_error("tx %s cmd for channel %d failed",
243 enable ? "start" : "stop", channel);
247 wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d",
248 enable ? "start" : "stop", channel);
255 int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 dtim_interval,
256 u16 beacon_interval, u8 wait)
258 unsigned long timeout;
259 struct cmd_join *join;
263 join = kzalloc(sizeof(*join), GFP_KERNEL);
269 /* FIXME: this should be in main.c */
270 ret = wl1251_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE,
271 DEFAULT_HW_GEN_MODULATION_TYPE,
272 wl->tx_mgmt_frm_rate,
273 wl->tx_mgmt_frm_mod);
277 wl1251_debug(DEBUG_CMD, "cmd join");
279 /* Reverse order BSSID */
280 bssid = (u8 *) &join->bssid_lsb;
281 for (i = 0; i < ETH_ALEN; i++)
282 bssid[i] = wl->bssid[ETH_ALEN - i - 1];
284 join->rx_config_options = wl->rx_config;
285 join->rx_filter_options = wl->rx_filter;
287 join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS |
288 RATE_MASK_5_5MBPS | RATE_MASK_11MBPS;
290 join->beacon_interval = beacon_interval;
291 join->dtim_interval = dtim_interval;
292 join->bss_type = bss_type;
293 join->channel = wl->channel;
294 join->ctrl = JOIN_CMD_CTRL_TX_FLUSH;
296 ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join));
298 wl1251_error("failed to initiate cmd join");
302 timeout = msecs_to_jiffies(JOIN_TIMEOUT);
305 * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to
306 * simplify locking we just sleep instead, for now
316 int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode)
318 struct wl1251_cmd_ps_params *ps_params = NULL;
321 /* FIXME: this should be in ps.c */
322 ret = wl1251_acx_wake_up_conditions(wl, WAKE_UP_EVENT_DTIM_BITMAP,
325 wl1251_error("couldn't set wake up conditions");
329 wl1251_debug(DEBUG_CMD, "cmd set ps mode");
331 ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL);
337 ps_params->ps_mode = ps_mode;
338 ps_params->send_null_data = 1;
339 ps_params->retries = 5;
340 ps_params->hang_over_period = 128;
341 ps_params->null_data_rate = 1; /* 1 Mbps */
343 ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params,
346 wl1251_error("cmd set_ps_mode failed");
355 int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer,
358 struct cmd_read_write_memory *cmd;
361 wl1251_debug(DEBUG_CMD, "cmd read memory");
363 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
369 WARN_ON(len > MAX_READ_SIZE);
370 len = min_t(size_t, len, MAX_READ_SIZE);
375 ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd));
377 wl1251_error("read memory command failed: %d", ret);
381 /* the read command got in, we can now read the answer */
382 wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd));
384 if (cmd->header.status != CMD_STATUS_SUCCESS)
385 wl1251_error("error in read command result: %d",
388 memcpy(answer, cmd->value, len);
395 int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id,
396 void *buf, size_t buf_len)
398 struct wl1251_cmd_packet_template *cmd;
402 wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id);
404 WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE);
405 buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE);
406 cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4);
408 cmd = kzalloc(cmd_len, GFP_KERNEL);
414 cmd->size = cpu_to_le16(buf_len);
417 memcpy(cmd->data, buf, buf_len);
419 ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len);
421 wl1251_warning("cmd set_template failed: %d", ret);