1 #include "wl1251_cmd.h"
3 #include <linux/module.h>
4 #include <linux/crc7.h>
7 #include "wl1251_reg.h"
10 #include "wl1251_acx.h"
13 * send command to firmware
17 * @buf: buffer containing the command, must work with dma
18 * @len: length of the buffer
20 int wl1251_cmd_send(struct wl1251
*wl
, u16 id
, void *buf
, size_t len
)
22 struct wl1251_cmd_header
*cmd
;
23 unsigned long timeout
;
31 WARN_ON(len
% 4 != 0);
33 wl1251_mem_write(wl
, wl
->cmd_box_addr
, buf
, len
);
35 wl1251_reg_write32(wl
, ACX_REG_INTERRUPT_TRIG
, INTR_TRIG_CMD
);
37 timeout
= jiffies
+ msecs_to_jiffies(WL1251_COMMAND_TIMEOUT
);
39 intr
= wl1251_reg_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
40 while (!(intr
& WL1251_ACX_INTR_CMD_COMPLETE
)) {
41 if (time_after(jiffies
, timeout
)) {
42 wl1251_error("command complete timeout");
49 intr
= wl1251_reg_read32(wl
, ACX_REG_INTERRUPT_NO_CLEAR
);
52 wl1251_reg_write32(wl
, ACX_REG_INTERRUPT_ACK
,
53 WL1251_ACX_INTR_CMD_COMPLETE
);
60 * send test command to firmware
63 * @buf: buffer containing the command, with all headers, must work with dma
64 * @len: length of the buffer
65 * @answer: is answer needed
67 int wl1251_cmd_test(struct wl1251
*wl
, void *buf
, size_t buf_len
, u8 answer
)
71 wl1251_debug(DEBUG_CMD
, "cmd test");
73 ret
= wl1251_cmd_send(wl
, CMD_TEST
, buf
, buf_len
);
76 wl1251_warning("TEST command failed");
81 struct wl1251_command
*cmd_answer
;
84 * The test command got in, we can read the answer.
85 * The answer would be a wl1251_command, where the
86 * parameter array contains the actual answer.
88 wl1251_mem_read(wl
, wl
->cmd_box_addr
, buf
, buf_len
);
92 if (cmd_answer
->header
.status
!= CMD_STATUS_SUCCESS
)
93 wl1251_error("TEST command answer error: %d",
94 cmd_answer
->header
.status
);
101 * read acx from firmware
105 * @buf: buffer for the response, including all headers, must work with dma
106 * @len: lenght of buf
108 int wl1251_cmd_interrogate(struct wl1251
*wl
, u16 id
, void *buf
, size_t len
)
110 struct acx_header
*acx
= buf
;
113 wl1251_debug(DEBUG_CMD
, "cmd interrogate");
117 /* payload length, does not include any headers */
118 acx
->len
= len
- sizeof(*acx
);
120 ret
= wl1251_cmd_send(wl
, CMD_INTERROGATE
, acx
, sizeof(*acx
));
122 wl1251_error("INTERROGATE command failed");
126 /* the interrogate command got in, we can read the answer */
127 wl1251_mem_read(wl
, wl
->cmd_box_addr
, buf
, len
);
130 if (acx
->cmd
.status
!= CMD_STATUS_SUCCESS
)
131 wl1251_error("INTERROGATE command error: %d",
139 * write acx value to firmware
143 * @buf: buffer containing acx, including all headers, must work with dma
144 * @len: length of buf
146 int wl1251_cmd_configure(struct wl1251
*wl
, u16 id
, void *buf
, size_t len
)
148 struct acx_header
*acx
= buf
;
151 wl1251_debug(DEBUG_CMD
, "cmd configure");
155 /* payload length, does not include any headers */
156 acx
->len
= len
- sizeof(*acx
);
158 ret
= wl1251_cmd_send(wl
, CMD_CONFIGURE
, acx
, len
);
160 wl1251_warning("CONFIGURE command NOK");
167 int wl1251_cmd_vbm(struct wl1251
*wl
, u8 identity
,
168 void *bitmap
, u16 bitmap_len
, u8 bitmap_control
)
170 struct wl1251_cmd_vbm_update
*vbm
;
173 wl1251_debug(DEBUG_CMD
, "cmd vbm");
175 vbm
= kzalloc(sizeof(*vbm
), GFP_KERNEL
);
181 /* Count and period will be filled by the target */
182 vbm
->tim
.bitmap_ctrl
= bitmap_control
;
183 if (bitmap_len
> PARTIAL_VBM_MAX
) {
184 wl1251_warning("cmd vbm len is %d B, truncating to %d",
185 bitmap_len
, PARTIAL_VBM_MAX
);
186 bitmap_len
= PARTIAL_VBM_MAX
;
188 memcpy(vbm
->tim
.pvb_field
, bitmap
, bitmap_len
);
189 vbm
->tim
.identity
= identity
;
190 vbm
->tim
.length
= bitmap_len
+ 3;
192 vbm
->len
= cpu_to_le16(bitmap_len
+ 5);
194 ret
= wl1251_cmd_send(wl
, CMD_VBM
, vbm
, sizeof(*vbm
));
196 wl1251_error("VBM command failed");
205 int wl1251_cmd_data_path(struct wl1251
*wl
, u8 channel
, bool enable
)
207 struct cmd_enabledisable_path
*cmd
;
211 wl1251_debug(DEBUG_CMD
, "cmd data path");
213 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
219 cmd
->channel
= channel
;
222 cmd_rx
= CMD_ENABLE_RX
;
223 cmd_tx
= CMD_ENABLE_TX
;
225 cmd_rx
= CMD_DISABLE_RX
;
226 cmd_tx
= CMD_DISABLE_TX
;
229 ret
= wl1251_cmd_send(wl
, cmd_rx
, cmd
, sizeof(*cmd
));
231 wl1251_error("rx %s cmd for channel %d failed",
232 enable
? "start" : "stop", channel
);
236 wl1251_debug(DEBUG_BOOT
, "rx %s cmd channel %d",
237 enable
? "start" : "stop", channel
);
239 ret
= wl1251_cmd_send(wl
, cmd_tx
, cmd
, sizeof(*cmd
));
241 wl1251_error("tx %s cmd for channel %d failed",
242 enable
? "start" : "stop", channel
);
246 wl1251_debug(DEBUG_BOOT
, "tx %s cmd channel %d",
247 enable
? "start" : "stop", channel
);
254 int wl1251_cmd_join(struct wl1251
*wl
, u8 bss_type
, u8 channel
,
255 u16 beacon_interval
, u8 dtim_interval
)
257 struct cmd_join
*join
;
261 join
= kzalloc(sizeof(*join
), GFP_KERNEL
);
267 wl1251_debug(DEBUG_CMD
, "cmd join%s ch %d %d/%d",
268 bss_type
== BSS_TYPE_IBSS
? " ibss" : "",
269 channel
, beacon_interval
, dtim_interval
);
271 /* Reverse order BSSID */
272 bssid
= (u8
*) &join
->bssid_lsb
;
273 for (i
= 0; i
< ETH_ALEN
; i
++)
274 bssid
[i
] = wl
->bssid
[ETH_ALEN
- i
- 1];
276 join
->rx_config_options
= wl
->rx_config
;
277 join
->rx_filter_options
= wl
->rx_filter
;
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.
285 join
->rx_config_options
= 0;
286 join
->rx_filter_options
= WL1251_DEFAULT_RX_FILTER
;
288 join
->basic_rate_set
= RATE_MASK_1MBPS
| RATE_MASK_2MBPS
|
289 RATE_MASK_5_5MBPS
| RATE_MASK_11MBPS
;
291 join
->beacon_interval
= beacon_interval
;
292 join
->dtim_interval
= dtim_interval
;
293 join
->bss_type
= bss_type
;
294 join
->channel
= channel
;
295 join
->ctrl
= JOIN_CMD_CTRL_TX_FLUSH
;
297 ret
= wl1251_cmd_send(wl
, CMD_START_JOIN
, join
, sizeof(*join
));
299 wl1251_error("failed to initiate cmd join");
308 int wl1251_cmd_ps_mode(struct wl1251
*wl
, u8 ps_mode
)
310 struct wl1251_cmd_ps_params
*ps_params
= NULL
;
313 wl1251_debug(DEBUG_CMD
, "cmd set ps mode");
315 ps_params
= kzalloc(sizeof(*ps_params
), GFP_KERNEL
);
321 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 */
327 ret
= wl1251_cmd_send(wl
, CMD_SET_PS_MODE
, ps_params
,
330 wl1251_error("cmd set_ps_mode failed");
339 int wl1251_cmd_read_memory(struct wl1251
*wl
, u32 addr
, void *answer
,
342 struct cmd_read_write_memory
*cmd
;
345 wl1251_debug(DEBUG_CMD
, "cmd read memory");
347 cmd
= kzalloc(sizeof(*cmd
), GFP_KERNEL
);
353 WARN_ON(len
> MAX_READ_SIZE
);
354 len
= min_t(size_t, len
, MAX_READ_SIZE
);
359 ret
= wl1251_cmd_send(wl
, CMD_READ_MEMORY
, cmd
, sizeof(*cmd
));
361 wl1251_error("read memory command failed: %d", ret
);
365 /* the read command got in, we can now read the answer */
366 wl1251_mem_read(wl
, wl
->cmd_box_addr
, cmd
, sizeof(*cmd
));
368 if (cmd
->header
.status
!= CMD_STATUS_SUCCESS
)
369 wl1251_error("error in read command result: %d",
372 memcpy(answer
, cmd
->value
, len
);
379 int wl1251_cmd_template_set(struct wl1251
*wl
, u16 cmd_id
,
380 void *buf
, size_t buf_len
)
382 struct wl1251_cmd_packet_template
*cmd
;
386 wl1251_debug(DEBUG_CMD
, "cmd template %d", cmd_id
);
388 WARN_ON(buf_len
> WL1251_MAX_TEMPLATE_SIZE
);
389 buf_len
= min_t(size_t, buf_len
, WL1251_MAX_TEMPLATE_SIZE
);
390 cmd_len
= ALIGN(sizeof(*cmd
) + buf_len
, 4);
392 cmd
= kzalloc(cmd_len
, GFP_KERNEL
);
398 cmd
->size
= cpu_to_le16(buf_len
);
401 memcpy(cmd
->data
, buf
, buf_len
);
403 ret
= wl1251_cmd_send(wl
, cmd_id
, cmd
, cmd_len
);
405 wl1251_warning("cmd set_template failed: %d", ret
);