]>
Commit | Line | Data |
---|---|---|
876c9d3a MT |
1 | /** |
2 | * This file contains the handling of command. | |
3 | * It prepares command and sends it to firmware when it is ready. | |
4 | */ | |
5 | ||
7919b89c | 6 | #include <linux/kfifo.h> |
e93156e7 | 7 | #include <linux/sched.h> |
5a0e3ad6 | 8 | #include <linux/slab.h> |
a45b6f4f | 9 | #include <linux/if_arp.h> |
e93156e7 | 10 | |
876c9d3a | 11 | #include "decl.h" |
e86dc1ca | 12 | #include "cfg.h" |
6e66f03f | 13 | #include "cmd.h" |
876c9d3a | 14 | |
9fb7663d DW |
15 | #define CAL_NF(nf) ((s32)(-(s32)(nf))) |
16 | #define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf))) | |
e93156e7 | 17 | |
2fd6cfe3 | 18 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv); |
0d61d042 | 19 | |
8db4a2b9 HS |
20 | /** |
21 | * @brief Simple callback that copies response back into command | |
22 | * | |
23 | * @param priv A pointer to struct lbs_private structure | |
24 | * @param extra A pointer to the original command structure for which | |
25 | * 'resp' is a response | |
26 | * @param resp A pointer to the command response | |
27 | * | |
28 | * @return 0 on success, error on failure | |
29 | */ | |
30 | int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra, | |
31 | struct cmd_header *resp) | |
32 | { | |
33 | struct cmd_header *buf = (void *)extra; | |
34 | uint16_t copy_len; | |
35 | ||
36 | copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size)); | |
37 | memcpy(buf, resp, copy_len); | |
38 | return 0; | |
39 | } | |
40 | EXPORT_SYMBOL_GPL(lbs_cmd_copyback); | |
41 | ||
42 | /** | |
43 | * @brief Simple callback that ignores the result. Use this if | |
44 | * you just want to send a command to the hardware, but don't | |
45 | * care for the result. | |
46 | * | |
47 | * @param priv ignored | |
48 | * @param extra ignored | |
49 | * @param resp ignored | |
50 | * | |
51 | * @return 0 for success | |
52 | */ | |
53 | static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra, | |
54 | struct cmd_header *resp) | |
55 | { | |
56 | return 0; | |
57 | } | |
58 | ||
59 | ||
876c9d3a | 60 | /** |
852e1f2a | 61 | * @brief Checks whether a command is allowed in Power Save mode |
876c9d3a MT |
62 | * |
63 | * @param command the command ID | |
852e1f2a | 64 | * @return 1 if allowed, 0 if not allowed |
876c9d3a | 65 | */ |
852e1f2a | 66 | static u8 is_command_allowed_in_ps(u16 cmd) |
876c9d3a | 67 | { |
852e1f2a DW |
68 | switch (cmd) { |
69 | case CMD_802_11_RSSI: | |
70 | return 1; | |
66fceb69 AK |
71 | case CMD_802_11_HOST_SLEEP_CFG: |
72 | return 1; | |
852e1f2a DW |
73 | default: |
74 | break; | |
876c9d3a | 75 | } |
876c9d3a MT |
76 | return 0; |
77 | } | |
78 | ||
63f275df AK |
79 | /** |
80 | * @brief This function checks if the command is allowed. | |
81 | * | |
82 | * @param priv A pointer to lbs_private structure | |
83 | * @return allowed or not allowed. | |
84 | */ | |
85 | ||
86 | static int lbs_is_cmd_allowed(struct lbs_private *priv) | |
87 | { | |
88 | int ret = 1; | |
89 | ||
90 | lbs_deb_enter(LBS_DEB_CMD); | |
91 | ||
92 | if (!priv->is_auto_deep_sleep_enabled) { | |
93 | if (priv->is_deep_sleep) { | |
94 | lbs_deb_cmd("command not allowed in deep sleep\n"); | |
95 | ret = 0; | |
96 | } | |
97 | } | |
98 | ||
99 | lbs_deb_leave(LBS_DEB_CMD); | |
100 | return ret; | |
101 | } | |
102 | ||
6e66f03f DW |
103 | /** |
104 | * @brief Updates the hardware details like MAC address and regulatory region | |
105 | * | |
106 | * @param priv A pointer to struct lbs_private structure | |
107 | * | |
108 | * @return 0 on success, error on failure | |
109 | */ | |
110 | int lbs_update_hw_spec(struct lbs_private *priv) | |
876c9d3a | 111 | { |
6e66f03f DW |
112 | struct cmd_ds_get_hw_spec cmd; |
113 | int ret = -1; | |
114 | u32 i; | |
876c9d3a | 115 | |
9012b28a | 116 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 117 | |
6e66f03f DW |
118 | memset(&cmd, 0, sizeof(cmd)); |
119 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
120 | memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN); | |
689442dc | 121 | ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd); |
6e66f03f DW |
122 | if (ret) |
123 | goto out; | |
124 | ||
125 | priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo); | |
6e66f03f | 126 | |
dac10a9f HS |
127 | /* The firmware release is in an interesting format: the patch |
128 | * level is in the most significant nibble ... so fix that: */ | |
129 | priv->fwrelease = le32_to_cpu(cmd.fwrelease); | |
130 | priv->fwrelease = (priv->fwrelease << 8) | | |
131 | (priv->fwrelease >> 24 & 0xff); | |
132 | ||
133 | /* Some firmware capabilities: | |
134 | * CF card firmware 5.0.16p0: cap 0x00000303 | |
135 | * USB dongle firmware 5.110.17p2: cap 0x00000303 | |
136 | */ | |
e174961c JB |
137 | lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n", |
138 | cmd.permanentaddr, | |
dac10a9f HS |
139 | priv->fwrelease >> 24 & 0xff, |
140 | priv->fwrelease >> 16 & 0xff, | |
141 | priv->fwrelease >> 8 & 0xff, | |
142 | priv->fwrelease & 0xff, | |
143 | priv->fwcapinfo); | |
6e66f03f DW |
144 | lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n", |
145 | cmd.hwifversion, cmd.version); | |
146 | ||
147 | /* Clamp region code to 8-bit since FW spec indicates that it should | |
148 | * only ever be 8-bit, even though the field size is 16-bit. Some firmware | |
149 | * returns non-zero high 8 bits here. | |
15483996 MV |
150 | * |
151 | * Firmware version 4.0.102 used in CF8381 has region code shifted. We | |
152 | * need to check for this problem and handle it properly. | |
6e66f03f | 153 | */ |
15483996 MV |
154 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4) |
155 | priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF; | |
156 | else | |
157 | priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF; | |
6e66f03f DW |
158 | |
159 | for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) { | |
160 | /* use the region code to search for the index */ | |
161 | if (priv->regioncode == lbs_region_code_to_index[i]) | |
162 | break; | |
163 | } | |
164 | ||
165 | /* if it's unidentified region code, use the default (USA) */ | |
166 | if (i >= MRVDRV_MAX_REGION_CODE) { | |
167 | priv->regioncode = 0x10; | |
168 | lbs_pr_info("unidentified region code; using the default (USA)\n"); | |
169 | } | |
170 | ||
171 | if (priv->current_addr[0] == 0xff) | |
172 | memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN); | |
876c9d3a | 173 | |
6e66f03f DW |
174 | memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN); |
175 | if (priv->mesh_dev) | |
176 | memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN); | |
177 | ||
6e66f03f | 178 | out: |
9012b28a | 179 | lbs_deb_leave(LBS_DEB_CMD); |
6e66f03f | 180 | return ret; |
876c9d3a MT |
181 | } |
182 | ||
66fceb69 AK |
183 | static int lbs_ret_host_sleep_cfg(struct lbs_private *priv, unsigned long dummy, |
184 | struct cmd_header *resp) | |
185 | { | |
186 | lbs_deb_enter(LBS_DEB_CMD); | |
1311843c | 187 | if (priv->is_host_sleep_activated) { |
66fceb69 AK |
188 | priv->is_host_sleep_configured = 0; |
189 | if (priv->psstate == PS_STATE_FULL_POWER) { | |
190 | priv->is_host_sleep_activated = 0; | |
191 | wake_up_interruptible(&priv->host_sleep_q); | |
192 | } | |
193 | } else { | |
194 | priv->is_host_sleep_configured = 1; | |
195 | } | |
196 | lbs_deb_leave(LBS_DEB_CMD); | |
197 | return 0; | |
198 | } | |
199 | ||
582c1b53 AN |
200 | int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria, |
201 | struct wol_config *p_wol_config) | |
6ce4fd2a DW |
202 | { |
203 | struct cmd_ds_host_sleep cmd_config; | |
204 | int ret; | |
205 | ||
9fae899c | 206 | cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config)); |
6ce4fd2a | 207 | cmd_config.criteria = cpu_to_le32(criteria); |
506e9025 DW |
208 | cmd_config.gpio = priv->wol_gpio; |
209 | cmd_config.gap = priv->wol_gap; | |
6ce4fd2a | 210 | |
582c1b53 AN |
211 | if (p_wol_config != NULL) |
212 | memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config, | |
213 | sizeof(struct wol_config)); | |
214 | else | |
215 | cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE; | |
216 | ||
66fceb69 AK |
217 | ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config.hdr, |
218 | le16_to_cpu(cmd_config.hdr.size), | |
219 | lbs_ret_host_sleep_cfg, 0); | |
506e9025 | 220 | if (!ret) { |
66fceb69 | 221 | if (p_wol_config) |
582c1b53 AN |
222 | memcpy((uint8_t *) p_wol_config, |
223 | (uint8_t *)&cmd_config.wol_conf, | |
224 | sizeof(struct wol_config)); | |
506e9025 | 225 | } else { |
6ce4fd2a | 226 | lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret); |
6ce4fd2a | 227 | } |
506e9025 | 228 | |
6ce4fd2a DW |
229 | return ret; |
230 | } | |
231 | EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg); | |
232 | ||
e98a88dd | 233 | static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd, |
876c9d3a MT |
234 | u16 cmd_action) |
235 | { | |
236 | struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode; | |
876c9d3a | 237 | |
9012b28a | 238 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 239 | |
0aef64d7 | 240 | cmd->command = cpu_to_le16(CMD_802_11_PS_MODE); |
981f187b | 241 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) + |
8ec97cc8 | 242 | sizeof(struct cmd_header)); |
876c9d3a MT |
243 | psm->action = cpu_to_le16(cmd_action); |
244 | psm->multipledtim = 0; | |
981f187b | 245 | switch (cmd_action) { |
0aef64d7 | 246 | case CMD_SUBCMD_ENTER_PS: |
9012b28a | 247 | lbs_deb_cmd("PS command:" "SubCode- Enter PS\n"); |
876c9d3a | 248 | |
252cf0d1 | 249 | psm->locallisteninterval = 0; |
97605c3e | 250 | psm->nullpktinterval = 0; |
876c9d3a | 251 | psm->multipledtim = |
56c4656e | 252 | cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM); |
876c9d3a MT |
253 | break; |
254 | ||
0aef64d7 | 255 | case CMD_SUBCMD_EXIT_PS: |
9012b28a | 256 | lbs_deb_cmd("PS command:" "SubCode- Exit PS\n"); |
876c9d3a MT |
257 | break; |
258 | ||
0aef64d7 | 259 | case CMD_SUBCMD_SLEEP_CONFIRMED: |
9012b28a | 260 | lbs_deb_cmd("PS command: SubCode- sleep confirm\n"); |
876c9d3a MT |
261 | break; |
262 | ||
263 | default: | |
264 | break; | |
265 | } | |
266 | ||
9012b28a | 267 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
268 | return 0; |
269 | } | |
270 | ||
3fbe104c DW |
271 | int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action, |
272 | struct sleep_params *sp) | |
876c9d3a | 273 | { |
3fbe104c DW |
274 | struct cmd_ds_802_11_sleep_params cmd; |
275 | int ret; | |
876c9d3a | 276 | |
9012b28a | 277 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 278 | |
0aef64d7 | 279 | if (cmd_action == CMD_ACT_GET) { |
3fbe104c DW |
280 | memset(&cmd, 0, sizeof(cmd)); |
281 | } else { | |
282 | cmd.error = cpu_to_le16(sp->sp_error); | |
283 | cmd.offset = cpu_to_le16(sp->sp_offset); | |
284 | cmd.stabletime = cpu_to_le16(sp->sp_stabletime); | |
285 | cmd.calcontrol = sp->sp_calcontrol; | |
286 | cmd.externalsleepclk = sp->sp_extsleepclk; | |
287 | cmd.reserved = cpu_to_le16(sp->sp_reserved); | |
876c9d3a | 288 | } |
3fbe104c DW |
289 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
290 | cmd.action = cpu_to_le16(cmd_action); | |
876c9d3a | 291 | |
3fbe104c DW |
292 | ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd); |
293 | ||
294 | if (!ret) { | |
295 | lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, " | |
296 | "calcontrol 0x%x extsleepclk 0x%x\n", | |
297 | le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset), | |
298 | le16_to_cpu(cmd.stabletime), cmd.calcontrol, | |
299 | cmd.externalsleepclk); | |
300 | ||
301 | sp->sp_error = le16_to_cpu(cmd.error); | |
302 | sp->sp_offset = le16_to_cpu(cmd.offset); | |
303 | sp->sp_stabletime = le16_to_cpu(cmd.stabletime); | |
304 | sp->sp_calcontrol = cmd.calcontrol; | |
305 | sp->sp_extsleepclk = cmd.externalsleepclk; | |
306 | sp->sp_reserved = le16_to_cpu(cmd.reserved); | |
307 | } | |
308 | ||
309 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
876c9d3a MT |
310 | return 0; |
311 | } | |
312 | ||
49125454 AK |
313 | static int lbs_wait_for_ds_awake(struct lbs_private *priv) |
314 | { | |
315 | int ret = 0; | |
316 | ||
317 | lbs_deb_enter(LBS_DEB_CMD); | |
318 | ||
319 | if (priv->is_deep_sleep) { | |
320 | if (!wait_event_interruptible_timeout(priv->ds_awake_q, | |
321 | !priv->is_deep_sleep, (10 * HZ))) { | |
322 | lbs_pr_err("ds_awake_q: timer expired\n"); | |
323 | ret = -1; | |
324 | } | |
325 | } | |
326 | ||
327 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
328 | return ret; | |
329 | } | |
330 | ||
331 | int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep) | |
332 | { | |
333 | int ret = 0; | |
334 | ||
335 | lbs_deb_enter(LBS_DEB_CMD); | |
336 | ||
337 | if (deep_sleep) { | |
338 | if (priv->is_deep_sleep != 1) { | |
339 | lbs_deb_cmd("deep sleep: sleep\n"); | |
340 | BUG_ON(!priv->enter_deep_sleep); | |
341 | ret = priv->enter_deep_sleep(priv); | |
342 | if (!ret) { | |
343 | netif_stop_queue(priv->dev); | |
344 | netif_carrier_off(priv->dev); | |
345 | } | |
346 | } else { | |
347 | lbs_pr_err("deep sleep: already enabled\n"); | |
348 | } | |
349 | } else { | |
350 | if (priv->is_deep_sleep) { | |
351 | lbs_deb_cmd("deep sleep: wakeup\n"); | |
352 | BUG_ON(!priv->exit_deep_sleep); | |
353 | ret = priv->exit_deep_sleep(priv); | |
354 | if (!ret) { | |
355 | ret = lbs_wait_for_ds_awake(priv); | |
356 | if (ret) | |
357 | lbs_pr_err("deep sleep: wakeup" | |
358 | "failed\n"); | |
359 | } | |
360 | } | |
361 | } | |
362 | ||
363 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
364 | return ret; | |
365 | } | |
366 | ||
1311843c AK |
367 | static int lbs_ret_host_sleep_activate(struct lbs_private *priv, |
368 | unsigned long dummy, | |
369 | struct cmd_header *cmd) | |
370 | { | |
371 | lbs_deb_enter(LBS_DEB_FW); | |
372 | priv->is_host_sleep_activated = 1; | |
373 | wake_up_interruptible(&priv->host_sleep_q); | |
374 | lbs_deb_leave(LBS_DEB_FW); | |
375 | return 0; | |
376 | } | |
377 | ||
378 | int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep) | |
379 | { | |
380 | struct cmd_header cmd; | |
381 | int ret = 0; | |
382 | uint32_t criteria = EHS_REMOVE_WAKEUP; | |
383 | ||
384 | lbs_deb_enter(LBS_DEB_CMD); | |
385 | ||
386 | if (host_sleep) { | |
387 | if (priv->is_host_sleep_activated != 1) { | |
388 | memset(&cmd, 0, sizeof(cmd)); | |
389 | ret = lbs_host_sleep_cfg(priv, priv->wol_criteria, | |
390 | (struct wol_config *)NULL); | |
391 | if (ret) { | |
392 | lbs_pr_info("Host sleep configuration failed: " | |
393 | "%d\n", ret); | |
394 | return ret; | |
395 | } | |
396 | if (priv->psstate == PS_STATE_FULL_POWER) { | |
397 | ret = __lbs_cmd(priv, | |
398 | CMD_802_11_HOST_SLEEP_ACTIVATE, | |
399 | &cmd, | |
400 | sizeof(cmd), | |
401 | lbs_ret_host_sleep_activate, 0); | |
402 | if (ret) | |
403 | lbs_pr_info("HOST_SLEEP_ACTIVATE " | |
404 | "failed: %d\n", ret); | |
405 | } | |
406 | ||
407 | if (!wait_event_interruptible_timeout( | |
408 | priv->host_sleep_q, | |
409 | priv->is_host_sleep_activated, | |
410 | (10 * HZ))) { | |
411 | lbs_pr_err("host_sleep_q: timer expired\n"); | |
412 | ret = -1; | |
413 | } | |
414 | } else { | |
415 | lbs_pr_err("host sleep: already enabled\n"); | |
416 | } | |
417 | } else { | |
418 | if (priv->is_host_sleep_activated) | |
419 | ret = lbs_host_sleep_cfg(priv, criteria, | |
420 | (struct wol_config *)NULL); | |
421 | } | |
422 | ||
423 | return ret; | |
424 | } | |
425 | ||
39fcf7a3 DW |
426 | /** |
427 | * @brief Set an SNMP MIB value | |
428 | * | |
429 | * @param priv A pointer to struct lbs_private structure | |
430 | * @param oid The OID to set in the firmware | |
431 | * @param val Value to set the OID to | |
432 | * | |
433 | * @return 0 on success, error on failure | |
434 | */ | |
435 | int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val) | |
876c9d3a | 436 | { |
39fcf7a3 DW |
437 | struct cmd_ds_802_11_snmp_mib cmd; |
438 | int ret; | |
876c9d3a | 439 | |
9012b28a | 440 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 441 | |
39fcf7a3 DW |
442 | memset(&cmd, 0, sizeof (cmd)); |
443 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
444 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
445 | cmd.oid = cpu_to_le16((u16) oid); | |
876c9d3a | 446 | |
39fcf7a3 DW |
447 | switch (oid) { |
448 | case SNMP_MIB_OID_BSS_TYPE: | |
449 | cmd.bufsize = cpu_to_le16(sizeof(u8)); | |
fef0640e | 450 | cmd.value[0] = val; |
39fcf7a3 DW |
451 | break; |
452 | case SNMP_MIB_OID_11D_ENABLE: | |
453 | case SNMP_MIB_OID_FRAG_THRESHOLD: | |
454 | case SNMP_MIB_OID_RTS_THRESHOLD: | |
455 | case SNMP_MIB_OID_SHORT_RETRY_LIMIT: | |
456 | case SNMP_MIB_OID_LONG_RETRY_LIMIT: | |
457 | cmd.bufsize = cpu_to_le16(sizeof(u16)); | |
458 | *((__le16 *)(&cmd.value)) = cpu_to_le16(val); | |
876c9d3a | 459 | break; |
39fcf7a3 DW |
460 | default: |
461 | lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid); | |
462 | ret = -EINVAL; | |
463 | goto out; | |
876c9d3a MT |
464 | } |
465 | ||
39fcf7a3 DW |
466 | lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n", |
467 | le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val); | |
876c9d3a | 468 | |
39fcf7a3 | 469 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
876c9d3a | 470 | |
39fcf7a3 DW |
471 | out: |
472 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
473 | return ret; | |
474 | } | |
876c9d3a | 475 | |
39fcf7a3 DW |
476 | /** |
477 | * @brief Get an SNMP MIB value | |
478 | * | |
479 | * @param priv A pointer to struct lbs_private structure | |
480 | * @param oid The OID to retrieve from the firmware | |
481 | * @param out_val Location for the returned value | |
482 | * | |
483 | * @return 0 on success, error on failure | |
484 | */ | |
485 | int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val) | |
486 | { | |
487 | struct cmd_ds_802_11_snmp_mib cmd; | |
488 | int ret; | |
876c9d3a | 489 | |
39fcf7a3 | 490 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 491 | |
39fcf7a3 DW |
492 | memset(&cmd, 0, sizeof (cmd)); |
493 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
494 | cmd.action = cpu_to_le16(CMD_ACT_GET); | |
495 | cmd.oid = cpu_to_le16(oid); | |
876c9d3a | 496 | |
39fcf7a3 DW |
497 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
498 | if (ret) | |
499 | goto out; | |
876c9d3a | 500 | |
39fcf7a3 DW |
501 | switch (le16_to_cpu(cmd.bufsize)) { |
502 | case sizeof(u8): | |
fef0640e | 503 | *out_val = cmd.value[0]; |
39fcf7a3 DW |
504 | break; |
505 | case sizeof(u16): | |
506 | *out_val = le16_to_cpu(*((__le16 *)(&cmd.value))); | |
876c9d3a MT |
507 | break; |
508 | default: | |
39fcf7a3 DW |
509 | lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n", |
510 | oid, le16_to_cpu(cmd.bufsize)); | |
876c9d3a MT |
511 | break; |
512 | } | |
513 | ||
39fcf7a3 DW |
514 | out: |
515 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
516 | return ret; | |
876c9d3a MT |
517 | } |
518 | ||
87c8c72d DW |
519 | /** |
520 | * @brief Get the min, max, and current TX power | |
521 | * | |
522 | * @param priv A pointer to struct lbs_private structure | |
523 | * @param curlevel Current power level in dBm | |
524 | * @param minlevel Minimum supported power level in dBm (optional) | |
525 | * @param maxlevel Maximum supported power level in dBm (optional) | |
526 | * | |
527 | * @return 0 on success, error on failure | |
528 | */ | |
529 | int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel, | |
530 | s16 *maxlevel) | |
876c9d3a | 531 | { |
87c8c72d DW |
532 | struct cmd_ds_802_11_rf_tx_power cmd; |
533 | int ret; | |
876c9d3a | 534 | |
9012b28a | 535 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 536 | |
87c8c72d DW |
537 | memset(&cmd, 0, sizeof(cmd)); |
538 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
539 | cmd.action = cpu_to_le16(CMD_ACT_GET); | |
540 | ||
541 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); | |
542 | if (ret == 0) { | |
543 | *curlevel = le16_to_cpu(cmd.curlevel); | |
544 | if (minlevel) | |
87bf24f3 | 545 | *minlevel = cmd.minlevel; |
87c8c72d | 546 | if (maxlevel) |
87bf24f3 | 547 | *maxlevel = cmd.maxlevel; |
87c8c72d | 548 | } |
876c9d3a | 549 | |
87c8c72d DW |
550 | lbs_deb_leave(LBS_DEB_CMD); |
551 | return ret; | |
552 | } | |
876c9d3a | 553 | |
87c8c72d DW |
554 | /** |
555 | * @brief Set the TX power | |
556 | * | |
557 | * @param priv A pointer to struct lbs_private structure | |
558 | * @param dbm The desired power level in dBm | |
559 | * | |
560 | * @return 0 on success, error on failure | |
561 | */ | |
562 | int lbs_set_tx_power(struct lbs_private *priv, s16 dbm) | |
563 | { | |
564 | struct cmd_ds_802_11_rf_tx_power cmd; | |
565 | int ret; | |
876c9d3a | 566 | |
87c8c72d | 567 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 568 | |
87c8c72d DW |
569 | memset(&cmd, 0, sizeof(cmd)); |
570 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
571 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
572 | cmd.curlevel = cpu_to_le16(dbm); | |
876c9d3a | 573 | |
87c8c72d DW |
574 | lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm); |
575 | ||
576 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); | |
9012b28a HS |
577 | |
578 | lbs_deb_leave(LBS_DEB_CMD); | |
87c8c72d | 579 | return ret; |
876c9d3a MT |
580 | } |
581 | ||
a45b6f4f DW |
582 | /** |
583 | * @brief Enable or disable monitor mode (only implemented on OLPC usb8388 FW) | |
584 | * | |
585 | * @param priv A pointer to struct lbs_private structure | |
586 | * @param enable 1 to enable monitor mode, 0 to disable | |
587 | * | |
588 | * @return 0 on success, error on failure | |
589 | */ | |
590 | int lbs_set_monitor_mode(struct lbs_private *priv, int enable) | |
965f8bbc | 591 | { |
a45b6f4f DW |
592 | struct cmd_ds_802_11_monitor_mode cmd; |
593 | int ret; | |
965f8bbc | 594 | |
a45b6f4f DW |
595 | memset(&cmd, 0, sizeof(cmd)); |
596 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
597 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
598 | if (enable) | |
599 | cmd.mode = cpu_to_le16(0x1); | |
965f8bbc | 600 | |
a45b6f4f DW |
601 | lbs_deb_cmd("SET_MONITOR_MODE: %d\n", enable); |
602 | ||
603 | ret = lbs_cmd_with_response(priv, CMD_802_11_MONITOR_MODE, &cmd); | |
604 | if (ret == 0) { | |
605 | priv->dev->type = enable ? ARPHRD_IEEE80211_RADIOTAP : | |
606 | ARPHRD_ETHER; | |
965f8bbc LCC |
607 | } |
608 | ||
a45b6f4f DW |
609 | lbs_deb_leave(LBS_DEB_CMD); |
610 | return ret; | |
965f8bbc LCC |
611 | } |
612 | ||
2dd4b262 DW |
613 | /** |
614 | * @brief Get the radio channel | |
615 | * | |
616 | * @param priv A pointer to struct lbs_private structure | |
617 | * | |
618 | * @return The channel on success, error on failure | |
619 | */ | |
a3cbfb08 | 620 | static int lbs_get_channel(struct lbs_private *priv) |
876c9d3a | 621 | { |
2dd4b262 DW |
622 | struct cmd_ds_802_11_rf_channel cmd; |
623 | int ret = 0; | |
876c9d3a | 624 | |
8ff12da1 | 625 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 626 | |
8d0c7fad | 627 | memset(&cmd, 0, sizeof(cmd)); |
2dd4b262 DW |
628 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
629 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET); | |
876c9d3a | 630 | |
689442dc | 631 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
2dd4b262 DW |
632 | if (ret) |
633 | goto out; | |
876c9d3a | 634 | |
cb182a60 DW |
635 | ret = le16_to_cpu(cmd.channel); |
636 | lbs_deb_cmd("current radio channel is %d\n", ret); | |
2dd4b262 DW |
637 | |
638 | out: | |
639 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
640 | return ret; | |
641 | } | |
642 | ||
73ab1f25 HS |
643 | int lbs_update_channel(struct lbs_private *priv) |
644 | { | |
645 | int ret; | |
646 | ||
647 | /* the channel in f/w could be out of sync; get the current channel */ | |
648 | lbs_deb_enter(LBS_DEB_ASSOC); | |
649 | ||
650 | ret = lbs_get_channel(priv); | |
651 | if (ret > 0) { | |
c14951fe | 652 | priv->channel = ret; |
73ab1f25 HS |
653 | ret = 0; |
654 | } | |
655 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
656 | return ret; | |
657 | } | |
658 | ||
2dd4b262 DW |
659 | /** |
660 | * @brief Set the radio channel | |
661 | * | |
662 | * @param priv A pointer to struct lbs_private structure | |
663 | * @param channel The desired channel, or 0 to clear a locked channel | |
664 | * | |
665 | * @return 0 on success, error on failure | |
666 | */ | |
667 | int lbs_set_channel(struct lbs_private *priv, u8 channel) | |
668 | { | |
669 | struct cmd_ds_802_11_rf_channel cmd; | |
96d46d5d | 670 | #ifdef DEBUG |
c14951fe | 671 | u8 old_channel = priv->channel; |
96d46d5d | 672 | #endif |
2dd4b262 DW |
673 | int ret = 0; |
674 | ||
675 | lbs_deb_enter(LBS_DEB_CMD); | |
676 | ||
8d0c7fad | 677 | memset(&cmd, 0, sizeof(cmd)); |
2dd4b262 DW |
678 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
679 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET); | |
680 | cmd.channel = cpu_to_le16(channel); | |
681 | ||
689442dc | 682 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
2dd4b262 DW |
683 | if (ret) |
684 | goto out; | |
685 | ||
c14951fe | 686 | priv->channel = (uint8_t) le16_to_cpu(cmd.channel); |
cb182a60 | 687 | lbs_deb_cmd("channel switch from %d to %d\n", old_channel, |
c14951fe | 688 | priv->channel); |
2dd4b262 DW |
689 | |
690 | out: | |
691 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
692 | return ret; | |
876c9d3a MT |
693 | } |
694 | ||
9fb7663d DW |
695 | /** |
696 | * @brief Get current RSSI and noise floor | |
697 | * | |
698 | * @param priv A pointer to struct lbs_private structure | |
699 | * @param rssi On successful return, signal level in mBm | |
700 | * | |
701 | * @return The channel on success, error on failure | |
702 | */ | |
703 | int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf) | |
704 | { | |
705 | struct cmd_ds_802_11_rssi cmd; | |
706 | int ret = 0; | |
707 | ||
708 | lbs_deb_enter(LBS_DEB_CMD); | |
709 | ||
710 | BUG_ON(rssi == NULL); | |
711 | BUG_ON(nf == NULL); | |
712 | ||
713 | memset(&cmd, 0, sizeof(cmd)); | |
714 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
715 | /* Average SNR over last 8 beacons */ | |
716 | cmd.n_or_snr = cpu_to_le16(8); | |
717 | ||
718 | ret = lbs_cmd_with_response(priv, CMD_802_11_RSSI, &cmd); | |
719 | if (ret == 0) { | |
720 | *nf = CAL_NF(le16_to_cpu(cmd.nf)); | |
721 | *rssi = CAL_RSSI(le16_to_cpu(cmd.n_or_snr), le16_to_cpu(cmd.nf)); | |
722 | } | |
723 | ||
724 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
725 | return ret; | |
726 | } | |
727 | ||
e98a88dd | 728 | static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr, |
876c9d3a MT |
729 | u8 cmd_action, void *pdata_buf) |
730 | { | |
10078321 | 731 | struct lbs_offset_value *offval; |
876c9d3a | 732 | |
9012b28a | 733 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 734 | |
10078321 | 735 | offval = (struct lbs_offset_value *)pdata_buf; |
876c9d3a | 736 | |
c2df2efe | 737 | switch (le16_to_cpu(cmdptr->command)) { |
0aef64d7 | 738 | case CMD_MAC_REG_ACCESS: |
876c9d3a MT |
739 | { |
740 | struct cmd_ds_mac_reg_access *macreg; | |
741 | ||
742 | cmdptr->size = | |
981f187b | 743 | cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access) |
8ec97cc8 | 744 | + sizeof(struct cmd_header)); |
876c9d3a MT |
745 | macreg = |
746 | (struct cmd_ds_mac_reg_access *)&cmdptr->params. | |
747 | macreg; | |
748 | ||
749 | macreg->action = cpu_to_le16(cmd_action); | |
750 | macreg->offset = cpu_to_le16((u16) offval->offset); | |
751 | macreg->value = cpu_to_le32(offval->value); | |
752 | ||
753 | break; | |
754 | } | |
755 | ||
0aef64d7 | 756 | case CMD_BBP_REG_ACCESS: |
876c9d3a MT |
757 | { |
758 | struct cmd_ds_bbp_reg_access *bbpreg; | |
759 | ||
760 | cmdptr->size = | |
761 | cpu_to_le16(sizeof | |
762 | (struct cmd_ds_bbp_reg_access) | |
8ec97cc8 | 763 | + sizeof(struct cmd_header)); |
876c9d3a MT |
764 | bbpreg = |
765 | (struct cmd_ds_bbp_reg_access *)&cmdptr->params. | |
766 | bbpreg; | |
767 | ||
768 | bbpreg->action = cpu_to_le16(cmd_action); | |
769 | bbpreg->offset = cpu_to_le16((u16) offval->offset); | |
770 | bbpreg->value = (u8) offval->value; | |
771 | ||
772 | break; | |
773 | } | |
774 | ||
0aef64d7 | 775 | case CMD_RF_REG_ACCESS: |
876c9d3a MT |
776 | { |
777 | struct cmd_ds_rf_reg_access *rfreg; | |
778 | ||
779 | cmdptr->size = | |
780 | cpu_to_le16(sizeof | |
781 | (struct cmd_ds_rf_reg_access) + | |
8ec97cc8 | 782 | sizeof(struct cmd_header)); |
876c9d3a MT |
783 | rfreg = |
784 | (struct cmd_ds_rf_reg_access *)&cmdptr->params. | |
785 | rfreg; | |
786 | ||
787 | rfreg->action = cpu_to_le16(cmd_action); | |
788 | rfreg->offset = cpu_to_le16((u16) offval->offset); | |
789 | rfreg->value = (u8) offval->value; | |
790 | ||
791 | break; | |
792 | } | |
793 | ||
794 | default: | |
795 | break; | |
796 | } | |
797 | ||
9012b28a | 798 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
799 | return 0; |
800 | } | |
801 | ||
681ffbb7 DW |
802 | static void lbs_queue_cmd(struct lbs_private *priv, |
803 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
804 | { |
805 | unsigned long flags; | |
681ffbb7 | 806 | int addtail = 1; |
876c9d3a | 807 | |
8ff12da1 | 808 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 809 | |
c4ab4127 DW |
810 | if (!cmdnode) { |
811 | lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n"); | |
876c9d3a MT |
812 | goto done; |
813 | } | |
d9896ee1 DW |
814 | if (!cmdnode->cmdbuf->size) { |
815 | lbs_deb_host("DNLD_CMD: cmd size is zero\n"); | |
816 | goto done; | |
817 | } | |
ae125bf8 | 818 | cmdnode->result = 0; |
876c9d3a MT |
819 | |
820 | /* Exit_PS command needs to be queued in the header always. */ | |
ddac4526 | 821 | if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) { |
38bfab1a | 822 | struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1]; |
ddac4526 | 823 | |
0aef64d7 | 824 | if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
aa21c004 | 825 | if (priv->psstate != PS_STATE_FULL_POWER) |
876c9d3a MT |
826 | addtail = 0; |
827 | } | |
828 | } | |
829 | ||
66fceb69 AK |
830 | if (le16_to_cpu(cmdnode->cmdbuf->command) == |
831 | CMD_802_11_WAKEUP_CONFIRM) | |
832 | addtail = 0; | |
833 | ||
aa21c004 | 834 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 835 | |
ac47246e | 836 | if (addtail) |
aa21c004 | 837 | list_add_tail(&cmdnode->list, &priv->cmdpendingq); |
ac47246e | 838 | else |
aa21c004 | 839 | list_add(&cmdnode->list, &priv->cmdpendingq); |
876c9d3a | 840 | |
aa21c004 | 841 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 842 | |
8ff12da1 | 843 | lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n", |
c4ab4127 | 844 | le16_to_cpu(cmdnode->cmdbuf->command)); |
876c9d3a MT |
845 | |
846 | done: | |
8ff12da1 | 847 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
848 | } |
849 | ||
18c52e7c DW |
850 | static void lbs_submit_command(struct lbs_private *priv, |
851 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
852 | { |
853 | unsigned long flags; | |
ddac4526 | 854 | struct cmd_header *cmd; |
18c52e7c DW |
855 | uint16_t cmdsize; |
856 | uint16_t command; | |
57962f0b | 857 | int timeo = 3 * HZ; |
18c52e7c | 858 | int ret; |
876c9d3a | 859 | |
8ff12da1 | 860 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 861 | |
ddac4526 | 862 | cmd = cmdnode->cmdbuf; |
876c9d3a | 863 | |
aa21c004 | 864 | spin_lock_irqsave(&priv->driver_lock, flags); |
aa21c004 DW |
865 | priv->cur_cmd = cmdnode; |
866 | priv->cur_cmd_retcode = 0; | |
867 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a | 868 | |
ddac4526 DW |
869 | cmdsize = le16_to_cpu(cmd->size); |
870 | command = le16_to_cpu(cmd->command); | |
876c9d3a | 871 | |
18c52e7c | 872 | /* These commands take longer */ |
be0d76e4 | 873 | if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE) |
57962f0b | 874 | timeo = 5 * HZ; |
18c52e7c | 875 | |
e5225b39 HS |
876 | lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n", |
877 | command, le16_to_cpu(cmd->seqnum), cmdsize); | |
1afc09ab | 878 | lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize); |
8ff12da1 | 879 | |
ddac4526 | 880 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize); |
18c52e7c | 881 | |
d9896ee1 DW |
882 | if (ret) { |
883 | lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret); | |
18c52e7c DW |
884 | /* Let the timer kick in and retry, and potentially reset |
885 | the whole thing if the condition persists */ | |
57962f0b | 886 | timeo = HZ/4; |
1afc09ab | 887 | } |
876c9d3a | 888 | |
49125454 AK |
889 | if (command == CMD_802_11_DEEP_SLEEP) { |
890 | if (priv->is_auto_deep_sleep_enabled) { | |
891 | priv->wakeup_dev_required = 1; | |
892 | priv->dnld_sent = 0; | |
893 | } | |
894 | priv->is_deep_sleep = 1; | |
895 | lbs_complete_command(priv, cmdnode, 0); | |
896 | } else { | |
897 | /* Setup the timer after transmit command */ | |
898 | mod_timer(&priv->command_timer, jiffies + timeo); | |
899 | } | |
876c9d3a | 900 | |
18c52e7c | 901 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
902 | } |
903 | ||
876c9d3a MT |
904 | /** |
905 | * This function inserts command node to cmdfreeq | |
aa21c004 | 906 | * after cleans it. Requires priv->driver_lock held. |
876c9d3a | 907 | */ |
183aeac1 | 908 | static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
5ba2f8a0 | 909 | struct cmd_ctrl_node *cmdnode) |
876c9d3a | 910 | { |
5ba2f8a0 DW |
911 | lbs_deb_enter(LBS_DEB_HOST); |
912 | ||
913 | if (!cmdnode) | |
914 | goto out; | |
915 | ||
5ba2f8a0 DW |
916 | cmdnode->callback = NULL; |
917 | cmdnode->callback_arg = 0; | |
876c9d3a | 918 | |
5ba2f8a0 | 919 | memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE); |
876c9d3a | 920 | |
5ba2f8a0 DW |
921 | list_add_tail(&cmdnode->list, &priv->cmdfreeq); |
922 | out: | |
923 | lbs_deb_leave(LBS_DEB_HOST); | |
876c9d3a MT |
924 | } |
925 | ||
69f9032d HS |
926 | static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
927 | struct cmd_ctrl_node *ptempcmd) | |
876c9d3a MT |
928 | { |
929 | unsigned long flags; | |
930 | ||
aa21c004 | 931 | spin_lock_irqsave(&priv->driver_lock, flags); |
10078321 | 932 | __lbs_cleanup_and_insert_cmd(priv, ptempcmd); |
aa21c004 | 933 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
934 | } |
935 | ||
183aeac1 DW |
936 | void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd, |
937 | int result) | |
938 | { | |
939 | if (cmd == priv->cur_cmd) | |
940 | priv->cur_cmd_retcode = result; | |
5ba2f8a0 | 941 | |
ae125bf8 | 942 | cmd->result = result; |
5ba2f8a0 DW |
943 | cmd->cmdwaitqwoken = 1; |
944 | wake_up_interruptible(&cmd->cmdwait_q); | |
945 | ||
8db4a2b9 | 946 | if (!cmd->callback || cmd->callback == lbs_cmd_async_callback) |
ad12d0f4 | 947 | __lbs_cleanup_and_insert_cmd(priv, cmd); |
183aeac1 DW |
948 | priv->cur_cmd = NULL; |
949 | } | |
950 | ||
d5db2dfa | 951 | int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on) |
876c9d3a | 952 | { |
a7c45890 | 953 | struct cmd_ds_802_11_radio_control cmd; |
d5db2dfa | 954 | int ret = -EINVAL; |
876c9d3a | 955 | |
9012b28a | 956 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 957 | |
a7c45890 DW |
958 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
959 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
960 | ||
d5db2dfa DW |
961 | /* Only v8 and below support setting the preamble */ |
962 | if (priv->fwrelease < 0x09000000) { | |
963 | switch (preamble) { | |
964 | case RADIO_PREAMBLE_SHORT: | |
d5db2dfa DW |
965 | case RADIO_PREAMBLE_AUTO: |
966 | case RADIO_PREAMBLE_LONG: | |
967 | cmd.control = cpu_to_le16(preamble); | |
968 | break; | |
969 | default: | |
970 | goto out; | |
971 | } | |
972 | } | |
a7c45890 | 973 | |
d5db2dfa DW |
974 | if (radio_on) |
975 | cmd.control |= cpu_to_le16(0x1); | |
976 | else { | |
977 | cmd.control &= cpu_to_le16(~0x1); | |
978 | priv->txpower_cur = 0; | |
a7c45890 | 979 | } |
876c9d3a | 980 | |
d5db2dfa DW |
981 | lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n", |
982 | radio_on ? "ON" : "OFF", preamble); | |
a7c45890 | 983 | |
d5db2dfa | 984 | priv->radio_on = radio_on; |
a7c45890 DW |
985 | |
986 | ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd); | |
876c9d3a | 987 | |
d5db2dfa | 988 | out: |
9012b28a | 989 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
990 | return ret; |
991 | } | |
992 | ||
c97329e2 | 993 | void lbs_set_mac_control(struct lbs_private *priv) |
876c9d3a | 994 | { |
835d3ac5 | 995 | struct cmd_ds_mac_control cmd; |
876c9d3a | 996 | |
9012b28a | 997 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 998 | |
835d3ac5 | 999 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
d9e9778c | 1000 | cmd.action = cpu_to_le16(priv->mac_control); |
835d3ac5 HS |
1001 | cmd.reserved = 0; |
1002 | ||
75bf45a7 | 1003 | lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd)); |
876c9d3a | 1004 | |
c97329e2 | 1005 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1006 | } |
1007 | ||
1047d5ed KD |
1008 | /** |
1009 | * @brief This function implements command CMD_802_11D_DOMAIN_INFO | |
1010 | * @param priv pointer to struct lbs_private | |
1011 | * @param cmd pointer to cmd buffer | |
1012 | * @param cmdno cmd ID | |
1013 | * @param cmdOption cmd action | |
1014 | * @return 0 | |
1015 | */ | |
1016 | int lbs_cmd_802_11d_domain_info(struct lbs_private *priv, | |
1017 | struct cmd_ds_command *cmd, | |
1018 | u16 cmdoption) | |
1019 | { | |
1020 | struct cmd_ds_802_11d_domain_info *pdomaininfo = | |
1021 | &cmd->params.domaininfo; | |
1022 | struct mrvl_ie_domain_param_set *domain = &pdomaininfo->domain; | |
1023 | u8 nr_triplet = priv->domain_reg.no_triplet; | |
1024 | ||
1025 | lbs_deb_enter(LBS_DEB_11D); | |
1026 | ||
1027 | lbs_deb_11d("nr_triplet=%x\n", nr_triplet); | |
1028 | ||
1029 | pdomaininfo->action = cpu_to_le16(cmdoption); | |
1030 | if (cmdoption == CMD_ACT_GET) { | |
1031 | cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) + | |
1032 | sizeof(struct cmd_header)); | |
1033 | lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd, | |
1034 | le16_to_cpu(cmd->size)); | |
1035 | goto done; | |
1036 | } | |
1037 | ||
1038 | domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN); | |
1039 | memcpy(domain->countrycode, priv->domain_reg.country_code, | |
1040 | sizeof(domain->countrycode)); | |
1041 | ||
1042 | domain->header.len = cpu_to_le16(nr_triplet | |
1043 | * sizeof(struct ieee80211_country_ie_triplet) | |
1044 | + sizeof(domain->countrycode)); | |
1045 | ||
1046 | if (nr_triplet) { | |
1047 | memcpy(domain->triplet, priv->domain_reg.triplet, | |
1048 | nr_triplet * | |
1049 | sizeof(struct ieee80211_country_ie_triplet)); | |
1050 | ||
1051 | cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) + | |
1052 | le16_to_cpu(domain->header.len) + | |
1053 | sizeof(struct mrvl_ie_header) + | |
1054 | sizeof(struct cmd_header)); | |
1055 | } else { | |
1056 | cmd->size = cpu_to_le16(sizeof(pdomaininfo->action) + | |
1057 | sizeof(struct cmd_header)); | |
1058 | } | |
1059 | ||
1060 | lbs_deb_hex(LBS_DEB_11D, "802_11D_DOMAIN_INFO", (u8 *) cmd, | |
1061 | le16_to_cpu(cmd->size)); | |
1062 | ||
1063 | done: | |
1064 | lbs_deb_enter(LBS_DEB_11D); | |
1065 | return 0; | |
1066 | } | |
1067 | ||
876c9d3a MT |
1068 | /** |
1069 | * @brief This function prepare the command before send to firmware. | |
1070 | * | |
69f9032d | 1071 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1072 | * @param cmd_no command number |
1073 | * @param cmd_action command action: GET or SET | |
1074 | * @param wait_option wait option: wait response or not | |
1075 | * @param cmd_oid cmd oid: treated as sub command | |
1076 | * @param pdata_buf A pointer to informaion buffer | |
1077 | * @return 0 or -1 | |
1078 | */ | |
69f9032d | 1079 | int lbs_prepare_and_send_command(struct lbs_private *priv, |
876c9d3a MT |
1080 | u16 cmd_no, |
1081 | u16 cmd_action, | |
1082 | u16 wait_option, u32 cmd_oid, void *pdata_buf) | |
1083 | { | |
1084 | int ret = 0; | |
876c9d3a MT |
1085 | struct cmd_ctrl_node *cmdnode; |
1086 | struct cmd_ds_command *cmdptr; | |
1087 | unsigned long flags; | |
1088 | ||
8ff12da1 | 1089 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1090 | |
aa21c004 DW |
1091 | if (!priv) { |
1092 | lbs_deb_host("PREP_CMD: priv is NULL\n"); | |
876c9d3a MT |
1093 | ret = -1; |
1094 | goto done; | |
1095 | } | |
1096 | ||
aa21c004 | 1097 | if (priv->surpriseremoved) { |
8ff12da1 | 1098 | lbs_deb_host("PREP_CMD: card removed\n"); |
876c9d3a MT |
1099 | ret = -1; |
1100 | goto done; | |
1101 | } | |
1102 | ||
63f275df AK |
1103 | if (!lbs_is_cmd_allowed(priv)) { |
1104 | ret = -EBUSY; | |
1105 | goto done; | |
1106 | } | |
1107 | ||
0d61d042 | 1108 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
876c9d3a MT |
1109 | |
1110 | if (cmdnode == NULL) { | |
8ff12da1 | 1111 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
876c9d3a MT |
1112 | |
1113 | /* Wake up main thread to execute next command */ | |
fe336150 | 1114 | wake_up_interruptible(&priv->waitq); |
876c9d3a MT |
1115 | ret = -1; |
1116 | goto done; | |
1117 | } | |
1118 | ||
e98a88dd HS |
1119 | cmdnode->callback = NULL; |
1120 | cmdnode->callback_arg = (unsigned long)pdata_buf; | |
876c9d3a | 1121 | |
ddac4526 | 1122 | cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf; |
876c9d3a | 1123 | |
8ff12da1 | 1124 | lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no); |
876c9d3a | 1125 | |
876c9d3a | 1126 | /* Set sequence number, command and INT option */ |
aa21c004 DW |
1127 | priv->seqnum++; |
1128 | cmdptr->seqnum = cpu_to_le16(priv->seqnum); | |
876c9d3a | 1129 | |
981f187b | 1130 | cmdptr->command = cpu_to_le16(cmd_no); |
876c9d3a MT |
1131 | cmdptr->result = 0; |
1132 | ||
1133 | switch (cmd_no) { | |
0aef64d7 | 1134 | case CMD_802_11_PS_MODE: |
e98a88dd | 1135 | ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action); |
876c9d3a MT |
1136 | break; |
1137 | ||
0aef64d7 DW |
1138 | case CMD_MAC_REG_ACCESS: |
1139 | case CMD_BBP_REG_ACCESS: | |
1140 | case CMD_RF_REG_ACCESS: | |
e98a88dd | 1141 | ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1142 | break; |
1143 | ||
0aef64d7 DW |
1144 | case CMD_802_11_SET_AFC: |
1145 | case CMD_802_11_GET_AFC: | |
876c9d3a MT |
1146 | |
1147 | cmdptr->command = cpu_to_le16(cmd_no); | |
981f187b | 1148 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) + |
8ec97cc8 | 1149 | sizeof(struct cmd_header)); |
876c9d3a MT |
1150 | |
1151 | memmove(&cmdptr->params.afc, | |
1152 | pdata_buf, sizeof(struct cmd_ds_802_11_afc)); | |
1153 | ||
1154 | ret = 0; | |
1155 | goto done; | |
1156 | ||
1047d5ed KD |
1157 | case CMD_802_11D_DOMAIN_INFO: |
1158 | cmdptr->command = cpu_to_le16(cmd_no); | |
1159 | ret = lbs_cmd_802_11d_domain_info(priv, cmdptr, cmd_action); | |
1160 | break; | |
1161 | ||
0aef64d7 DW |
1162 | case CMD_802_11_TPC_CFG: |
1163 | cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG); | |
876c9d3a MT |
1164 | cmdptr->size = |
1165 | cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) + | |
8ec97cc8 | 1166 | sizeof(struct cmd_header)); |
876c9d3a MT |
1167 | |
1168 | memmove(&cmdptr->params.tpccfg, | |
1169 | pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg)); | |
1170 | ||
1171 | ret = 0; | |
1172 | break; | |
5844d12e | 1173 | |
4143a23d HS |
1174 | #ifdef CONFIG_LIBERTAS_MESH |
1175 | ||
0aef64d7 | 1176 | case CMD_BT_ACCESS: |
e98a88dd | 1177 | ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1178 | break; |
1179 | ||
0aef64d7 | 1180 | case CMD_FWT_ACCESS: |
e98a88dd | 1181 | ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1182 | break; |
1183 | ||
4143a23d HS |
1184 | #endif |
1185 | ||
96287ac4 BD |
1186 | case CMD_802_11_BEACON_CTRL: |
1187 | ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action); | |
1188 | break; | |
49125454 AK |
1189 | case CMD_802_11_DEEP_SLEEP: |
1190 | cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP); | |
8ec97cc8 | 1191 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_header)); |
49125454 | 1192 | break; |
876c9d3a | 1193 | default: |
e37fc6e1 | 1194 | lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no); |
876c9d3a MT |
1195 | ret = -1; |
1196 | break; | |
1197 | } | |
1198 | ||
1199 | /* return error, since the command preparation failed */ | |
1200 | if (ret != 0) { | |
8ff12da1 | 1201 | lbs_deb_host("PREP_CMD: command preparation failed\n"); |
10078321 | 1202 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1203 | ret = -1; |
1204 | goto done; | |
1205 | } | |
1206 | ||
1207 | cmdnode->cmdwaitqwoken = 0; | |
1208 | ||
681ffbb7 | 1209 | lbs_queue_cmd(priv, cmdnode); |
fe336150 | 1210 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1211 | |
0aef64d7 | 1212 | if (wait_option & CMD_OPTION_WAITFORRSP) { |
8ff12da1 | 1213 | lbs_deb_host("PREP_CMD: wait for response\n"); |
876c9d3a MT |
1214 | might_sleep(); |
1215 | wait_event_interruptible(cmdnode->cmdwait_q, | |
1216 | cmdnode->cmdwaitqwoken); | |
1217 | } | |
1218 | ||
aa21c004 DW |
1219 | spin_lock_irqsave(&priv->driver_lock, flags); |
1220 | if (priv->cur_cmd_retcode) { | |
8ff12da1 | 1221 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", |
aa21c004 DW |
1222 | priv->cur_cmd_retcode); |
1223 | priv->cur_cmd_retcode = 0; | |
876c9d3a MT |
1224 | ret = -1; |
1225 | } | |
aa21c004 | 1226 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1227 | |
1228 | done: | |
8ff12da1 | 1229 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1230 | return ret; |
1231 | } | |
1232 | ||
1233 | /** | |
1234 | * @brief This function allocates the command buffer and link | |
1235 | * it to command free queue. | |
1236 | * | |
69f9032d | 1237 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1238 | * @return 0 or -1 |
1239 | */ | |
69f9032d | 1240 | int lbs_allocate_cmd_buffer(struct lbs_private *priv) |
876c9d3a MT |
1241 | { |
1242 | int ret = 0; | |
ddac4526 | 1243 | u32 bufsize; |
876c9d3a | 1244 | u32 i; |
ddac4526 | 1245 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1246 | |
8ff12da1 | 1247 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1248 | |
ddac4526 DW |
1249 | /* Allocate and initialize the command array */ |
1250 | bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS; | |
1251 | if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) { | |
8ff12da1 | 1252 | lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n"); |
876c9d3a MT |
1253 | ret = -1; |
1254 | goto done; | |
1255 | } | |
ddac4526 | 1256 | priv->cmd_array = cmdarray; |
876c9d3a | 1257 | |
ddac4526 DW |
1258 | /* Allocate and initialize each command buffer in the command array */ |
1259 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { | |
1260 | cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL); | |
1261 | if (!cmdarray[i].cmdbuf) { | |
8ff12da1 | 1262 | lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); |
876c9d3a MT |
1263 | ret = -1; |
1264 | goto done; | |
1265 | } | |
876c9d3a MT |
1266 | } |
1267 | ||
ddac4526 DW |
1268 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1269 | init_waitqueue_head(&cmdarray[i].cmdwait_q); | |
1270 | lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]); | |
876c9d3a | 1271 | } |
876c9d3a | 1272 | ret = 0; |
9012b28a HS |
1273 | |
1274 | done: | |
8ff12da1 | 1275 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1276 | return ret; |
1277 | } | |
1278 | ||
1279 | /** | |
1280 | * @brief This function frees the command buffer. | |
1281 | * | |
69f9032d | 1282 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1283 | * @return 0 or -1 |
1284 | */ | |
69f9032d | 1285 | int lbs_free_cmd_buffer(struct lbs_private *priv) |
876c9d3a | 1286 | { |
ddac4526 | 1287 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1288 | unsigned int i; |
876c9d3a | 1289 | |
8ff12da1 | 1290 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1291 | |
1292 | /* need to check if cmd array is allocated or not */ | |
aa21c004 | 1293 | if (priv->cmd_array == NULL) { |
8ff12da1 | 1294 | lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n"); |
876c9d3a MT |
1295 | goto done; |
1296 | } | |
1297 | ||
ddac4526 | 1298 | cmdarray = priv->cmd_array; |
876c9d3a MT |
1299 | |
1300 | /* Release shared memory buffers */ | |
ddac4526 DW |
1301 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1302 | if (cmdarray[i].cmdbuf) { | |
1303 | kfree(cmdarray[i].cmdbuf); | |
1304 | cmdarray[i].cmdbuf = NULL; | |
876c9d3a MT |
1305 | } |
1306 | } | |
1307 | ||
1308 | /* Release cmd_ctrl_node */ | |
aa21c004 DW |
1309 | if (priv->cmd_array) { |
1310 | kfree(priv->cmd_array); | |
1311 | priv->cmd_array = NULL; | |
876c9d3a MT |
1312 | } |
1313 | ||
1314 | done: | |
8ff12da1 | 1315 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1316 | return 0; |
1317 | } | |
1318 | ||
1319 | /** | |
1320 | * @brief This function gets a free command node if available in | |
1321 | * command free queue. | |
1322 | * | |
69f9032d | 1323 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1324 | * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL |
1325 | */ | |
2fd6cfe3 | 1326 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv) |
876c9d3a MT |
1327 | { |
1328 | struct cmd_ctrl_node *tempnode; | |
876c9d3a MT |
1329 | unsigned long flags; |
1330 | ||
8ff12da1 HS |
1331 | lbs_deb_enter(LBS_DEB_HOST); |
1332 | ||
aa21c004 | 1333 | if (!priv) |
876c9d3a MT |
1334 | return NULL; |
1335 | ||
aa21c004 | 1336 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1337 | |
aa21c004 DW |
1338 | if (!list_empty(&priv->cmdfreeq)) { |
1339 | tempnode = list_first_entry(&priv->cmdfreeq, | |
abe3ed14 LZ |
1340 | struct cmd_ctrl_node, list); |
1341 | list_del(&tempnode->list); | |
876c9d3a | 1342 | } else { |
8ff12da1 | 1343 | lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n"); |
876c9d3a MT |
1344 | tempnode = NULL; |
1345 | } | |
1346 | ||
aa21c004 | 1347 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 1348 | |
8ff12da1 | 1349 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1350 | return tempnode; |
1351 | } | |
1352 | ||
876c9d3a MT |
1353 | /** |
1354 | * @brief This function executes next command in command | |
877d0310 | 1355 | * pending queue. It will put firmware back to PS mode |
876c9d3a MT |
1356 | * if applicable. |
1357 | * | |
69f9032d | 1358 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1359 | * @return 0 or -1 |
1360 | */ | |
69f9032d | 1361 | int lbs_execute_next_command(struct lbs_private *priv) |
876c9d3a | 1362 | { |
876c9d3a | 1363 | struct cmd_ctrl_node *cmdnode = NULL; |
ddac4526 | 1364 | struct cmd_header *cmd; |
876c9d3a MT |
1365 | unsigned long flags; |
1366 | int ret = 0; | |
1367 | ||
1afc09ab HS |
1368 | /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the |
1369 | * only caller to us is lbs_thread() and we get even when a | |
1370 | * data packet is received */ | |
8ff12da1 | 1371 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1372 | |
aa21c004 | 1373 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1374 | |
aa21c004 | 1375 | if (priv->cur_cmd) { |
8ff12da1 | 1376 | lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); |
aa21c004 | 1377 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1378 | ret = -1; |
1379 | goto done; | |
1380 | } | |
1381 | ||
aa21c004 DW |
1382 | if (!list_empty(&priv->cmdpendingq)) { |
1383 | cmdnode = list_first_entry(&priv->cmdpendingq, | |
abe3ed14 | 1384 | struct cmd_ctrl_node, list); |
876c9d3a MT |
1385 | } |
1386 | ||
aa21c004 | 1387 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1388 | |
1389 | if (cmdnode) { | |
ddac4526 | 1390 | cmd = cmdnode->cmdbuf; |
876c9d3a | 1391 | |
ddac4526 | 1392 | if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) { |
aa21c004 DW |
1393 | if ((priv->psstate == PS_STATE_SLEEP) || |
1394 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1395 | lbs_deb_host( |
1396 | "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n", | |
ddac4526 | 1397 | le16_to_cpu(cmd->command), |
aa21c004 | 1398 | priv->psstate); |
876c9d3a MT |
1399 | ret = -1; |
1400 | goto done; | |
1401 | } | |
8ff12da1 | 1402 | lbs_deb_host("EXEC_NEXT_CMD: OK to send command " |
ddac4526 DW |
1403 | "0x%04x in psstate %d\n", |
1404 | le16_to_cpu(cmd->command), priv->psstate); | |
aa21c004 | 1405 | } else if (priv->psstate != PS_STATE_FULL_POWER) { |
876c9d3a MT |
1406 | /* |
1407 | * 1. Non-PS command: | |
1408 | * Queue it. set needtowakeup to TRUE if current state | |
10078321 | 1409 | * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS. |
876c9d3a MT |
1410 | * 2. PS command but not Exit_PS: |
1411 | * Ignore it. | |
1412 | * 3. PS command Exit_PS: | |
1413 | * Set needtowakeup to TRUE if current state is SLEEP, | |
1414 | * otherwise send this command down to firmware | |
1415 | * immediately. | |
1416 | */ | |
ddac4526 | 1417 | if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) { |
876c9d3a MT |
1418 | /* Prepare to send Exit PS, |
1419 | * this non PS command will be sent later */ | |
aa21c004 DW |
1420 | if ((priv->psstate == PS_STATE_SLEEP) |
1421 | || (priv->psstate == PS_STATE_PRE_SLEEP) | |
876c9d3a MT |
1422 | ) { |
1423 | /* w/ new scheme, it will not reach here. | |
1424 | since it is blocked in main_thread. */ | |
aa21c004 | 1425 | priv->needtowakeup = 1; |
876c9d3a | 1426 | } else |
10078321 | 1427 | lbs_ps_wakeup(priv, 0); |
876c9d3a MT |
1428 | |
1429 | ret = 0; | |
1430 | goto done; | |
1431 | } else { | |
1432 | /* | |
1433 | * PS command. Ignore it if it is not Exit_PS. | |
1434 | * otherwise send it down immediately. | |
1435 | */ | |
38bfab1a | 1436 | struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1]; |
876c9d3a | 1437 | |
8ff12da1 HS |
1438 | lbs_deb_host( |
1439 | "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n", | |
876c9d3a MT |
1440 | psm->action); |
1441 | if (psm->action != | |
0aef64d7 | 1442 | cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
8ff12da1 HS |
1443 | lbs_deb_host( |
1444 | "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); | |
abe3ed14 | 1445 | list_del(&cmdnode->list); |
183aeac1 DW |
1446 | spin_lock_irqsave(&priv->driver_lock, flags); |
1447 | lbs_complete_command(priv, cmdnode, 0); | |
1448 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a MT |
1449 | |
1450 | ret = 0; | |
1451 | goto done; | |
1452 | } | |
1453 | ||
aa21c004 DW |
1454 | if ((priv->psstate == PS_STATE_SLEEP) || |
1455 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1456 | lbs_deb_host( |
1457 | "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); | |
abe3ed14 | 1458 | list_del(&cmdnode->list); |
183aeac1 DW |
1459 | spin_lock_irqsave(&priv->driver_lock, flags); |
1460 | lbs_complete_command(priv, cmdnode, 0); | |
1461 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
aa21c004 | 1462 | priv->needtowakeup = 1; |
876c9d3a MT |
1463 | |
1464 | ret = 0; | |
1465 | goto done; | |
1466 | } | |
1467 | ||
8ff12da1 HS |
1468 | lbs_deb_host( |
1469 | "EXEC_NEXT_CMD: sending EXIT_PS\n"); | |
876c9d3a MT |
1470 | } |
1471 | } | |
abe3ed14 | 1472 | list_del(&cmdnode->list); |
8ff12da1 | 1473 | lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", |
ddac4526 | 1474 | le16_to_cpu(cmd->command)); |
d9896ee1 | 1475 | lbs_submit_command(priv, cmdnode); |
876c9d3a MT |
1476 | } else { |
1477 | /* | |
1478 | * check if in power save mode, if yes, put the device back | |
1479 | * to PS mode | |
1480 | */ | |
e86dc1ca KD |
1481 | #ifdef TODO |
1482 | /* | |
1483 | * This was the old code for libertas+wext. Someone that | |
1484 | * understands this beast should re-code it in a sane way. | |
1485 | * | |
1486 | * I actually don't understand why this is related to WPA | |
1487 | * and to connection status, shouldn't powering should be | |
1488 | * independ of such things? | |
1489 | */ | |
aa21c004 DW |
1490 | if ((priv->psmode != LBS802_11POWERMODECAM) && |
1491 | (priv->psstate == PS_STATE_FULL_POWER) && | |
1492 | ((priv->connect_status == LBS_CONNECTED) || | |
602114ae | 1493 | lbs_mesh_connected(priv))) { |
aa21c004 DW |
1494 | if (priv->secinfo.WPAenabled || |
1495 | priv->secinfo.WPA2enabled) { | |
876c9d3a | 1496 | /* check for valid WPA group keys */ |
aa21c004 DW |
1497 | if (priv->wpa_mcast_key.len || |
1498 | priv->wpa_unicast_key.len) { | |
8ff12da1 | 1499 | lbs_deb_host( |
876c9d3a MT |
1500 | "EXEC_NEXT_CMD: WPA enabled and GTK_SET" |
1501 | " go back to PS_SLEEP"); | |
10078321 | 1502 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1503 | } |
1504 | } else { | |
8ff12da1 HS |
1505 | lbs_deb_host( |
1506 | "EXEC_NEXT_CMD: cmdpendingq empty, " | |
1507 | "go back to PS_SLEEP"); | |
10078321 | 1508 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1509 | } |
1510 | } | |
e86dc1ca | 1511 | #endif |
876c9d3a MT |
1512 | } |
1513 | ||
1514 | ret = 0; | |
1515 | done: | |
8ff12da1 | 1516 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
1517 | return ret; |
1518 | } | |
1519 | ||
f539f2ef | 1520 | static void lbs_send_confirmsleep(struct lbs_private *priv) |
876c9d3a MT |
1521 | { |
1522 | unsigned long flags; | |
f539f2ef | 1523 | int ret; |
876c9d3a | 1524 | |
8ff12da1 | 1525 | lbs_deb_enter(LBS_DEB_HOST); |
f539f2ef HS |
1526 | lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep, |
1527 | sizeof(confirm_sleep)); | |
876c9d3a | 1528 | |
f539f2ef HS |
1529 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep, |
1530 | sizeof(confirm_sleep)); | |
876c9d3a | 1531 | if (ret) { |
f539f2ef | 1532 | lbs_pr_alert("confirm_sleep failed\n"); |
7919b89c | 1533 | goto out; |
876c9d3a | 1534 | } |
7919b89c HS |
1535 | |
1536 | spin_lock_irqsave(&priv->driver_lock, flags); | |
1537 | ||
a01f5450 HS |
1538 | /* We don't get a response on the sleep-confirmation */ |
1539 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
1540 | ||
66fceb69 AK |
1541 | if (priv->is_host_sleep_configured) { |
1542 | priv->is_host_sleep_activated = 1; | |
1543 | wake_up_interruptible(&priv->host_sleep_q); | |
1544 | } | |
1545 | ||
7919b89c | 1546 | /* If nothing to do, go back to sleep (?) */ |
e64c026d | 1547 | if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx]) |
7919b89c HS |
1548 | priv->psstate = PS_STATE_SLEEP; |
1549 | ||
1550 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
1551 | ||
1552 | out: | |
f539f2ef | 1553 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1554 | } |
1555 | ||
69f9032d | 1556 | void lbs_ps_sleep(struct lbs_private *priv, int wait_option) |
876c9d3a | 1557 | { |
8ff12da1 | 1558 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1559 | |
1560 | /* | |
1561 | * PS is currently supported only in Infrastructure mode | |
1562 | * Remove this check if it is to be supported in IBSS mode also | |
1563 | */ | |
1564 | ||
10078321 | 1565 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1566 | CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL); |
876c9d3a | 1567 | |
8ff12da1 | 1568 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1569 | } |
1570 | ||
1571 | /** | |
8ff12da1 | 1572 | * @brief This function sends Exit_PS command to firmware. |
876c9d3a | 1573 | * |
69f9032d | 1574 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1575 | * @param wait_option wait response or not |
1576 | * @return n/a | |
1577 | */ | |
69f9032d | 1578 | void lbs_ps_wakeup(struct lbs_private *priv, int wait_option) |
876c9d3a | 1579 | { |
981f187b | 1580 | __le32 Localpsmode; |
876c9d3a | 1581 | |
8ff12da1 | 1582 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1583 | |
10078321 | 1584 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
876c9d3a | 1585 | |
10078321 | 1586 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1587 | CMD_SUBCMD_EXIT_PS, |
876c9d3a MT |
1588 | wait_option, 0, &Localpsmode); |
1589 | ||
8ff12da1 | 1590 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1591 | } |
1592 | ||
1593 | /** | |
1594 | * @brief This function checks condition and prepares to | |
1595 | * send sleep confirm command to firmware if ok. | |
1596 | * | |
69f9032d | 1597 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1598 | * @param psmode Power Saving mode |
1599 | * @return n/a | |
1600 | */ | |
d4ff0ef6 | 1601 | void lbs_ps_confirm_sleep(struct lbs_private *priv) |
876c9d3a MT |
1602 | { |
1603 | unsigned long flags =0; | |
d4ff0ef6 | 1604 | int allowed = 1; |
876c9d3a | 1605 | |
8ff12da1 | 1606 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1607 | |
a01f5450 | 1608 | spin_lock_irqsave(&priv->driver_lock, flags); |
634b8f49 | 1609 | if (priv->dnld_sent) { |
876c9d3a | 1610 | allowed = 0; |
23d36eec | 1611 | lbs_deb_host("dnld_sent was set\n"); |
876c9d3a MT |
1612 | } |
1613 | ||
7919b89c | 1614 | /* In-progress command? */ |
aa21c004 | 1615 | if (priv->cur_cmd) { |
876c9d3a | 1616 | allowed = 0; |
23d36eec | 1617 | lbs_deb_host("cur_cmd was set\n"); |
876c9d3a | 1618 | } |
7919b89c HS |
1619 | |
1620 | /* Pending events or command responses? */ | |
e64c026d | 1621 | if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) { |
876c9d3a | 1622 | allowed = 0; |
7919b89c | 1623 | lbs_deb_host("pending events or command responses\n"); |
876c9d3a | 1624 | } |
aa21c004 | 1625 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1626 | |
1627 | if (allowed) { | |
10078321 | 1628 | lbs_deb_host("sending lbs_ps_confirm_sleep\n"); |
f539f2ef | 1629 | lbs_send_confirmsleep(priv); |
876c9d3a | 1630 | } else { |
8ff12da1 | 1631 | lbs_deb_host("sleep confirm has been delayed\n"); |
876c9d3a MT |
1632 | } |
1633 | ||
8ff12da1 | 1634 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a | 1635 | } |
675787e2 HS |
1636 | |
1637 | ||
0112c9e9 AN |
1638 | /** |
1639 | * @brief Configures the transmission power control functionality. | |
1640 | * | |
1641 | * @param priv A pointer to struct lbs_private structure | |
1642 | * @param enable Transmission power control enable | |
1643 | * @param p0 Power level when link quality is good (dBm). | |
1644 | * @param p1 Power level when link quality is fair (dBm). | |
1645 | * @param p2 Power level when link quality is poor (dBm). | |
1646 | * @param usesnr Use Signal to Noise Ratio in TPC | |
1647 | * | |
1648 | * @return 0 on success | |
1649 | */ | |
1650 | int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1, | |
1651 | int8_t p2, int usesnr) | |
1652 | { | |
1653 | struct cmd_ds_802_11_tpc_cfg cmd; | |
1654 | int ret; | |
1655 | ||
1656 | memset(&cmd, 0, sizeof(cmd)); | |
1657 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1658 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1659 | cmd.enable = !!enable; | |
3ed6e080 | 1660 | cmd.usesnr = !!usesnr; |
0112c9e9 AN |
1661 | cmd.P0 = p0; |
1662 | cmd.P1 = p1; | |
1663 | cmd.P2 = p2; | |
1664 | ||
1665 | ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd); | |
1666 | ||
1667 | return ret; | |
1668 | } | |
1669 | ||
1670 | /** | |
1671 | * @brief Configures the power adaptation settings. | |
1672 | * | |
1673 | * @param priv A pointer to struct lbs_private structure | |
1674 | * @param enable Power adaptation enable | |
1675 | * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm). | |
1676 | * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm). | |
1677 | * @param p2 Power level for 48 and 54 Mbps (dBm). | |
1678 | * | |
1679 | * @return 0 on Success | |
1680 | */ | |
1681 | ||
1682 | int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0, | |
1683 | int8_t p1, int8_t p2) | |
1684 | { | |
1685 | struct cmd_ds_802_11_pa_cfg cmd; | |
1686 | int ret; | |
1687 | ||
1688 | memset(&cmd, 0, sizeof(cmd)); | |
1689 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1690 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1691 | cmd.enable = !!enable; | |
1692 | cmd.P0 = p0; | |
1693 | cmd.P1 = p1; | |
1694 | cmd.P2 = p2; | |
1695 | ||
1696 | ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd); | |
1697 | ||
1698 | return ret; | |
1699 | } | |
1700 | ||
1701 | ||
6d898b19 | 1702 | struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, |
8db4a2b9 HS |
1703 | uint16_t command, struct cmd_header *in_cmd, int in_cmd_size, |
1704 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
1705 | unsigned long callback_arg) | |
675787e2 | 1706 | { |
675787e2 | 1707 | struct cmd_ctrl_node *cmdnode; |
675787e2 HS |
1708 | |
1709 | lbs_deb_enter(LBS_DEB_HOST); | |
675787e2 | 1710 | |
aa21c004 | 1711 | if (priv->surpriseremoved) { |
675787e2 | 1712 | lbs_deb_host("PREP_CMD: card removed\n"); |
3399ea5f | 1713 | cmdnode = ERR_PTR(-ENOENT); |
675787e2 HS |
1714 | goto done; |
1715 | } | |
1716 | ||
63f275df AK |
1717 | if (!lbs_is_cmd_allowed(priv)) { |
1718 | cmdnode = ERR_PTR(-EBUSY); | |
1719 | goto done; | |
1720 | } | |
1721 | ||
675787e2 | 1722 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
675787e2 HS |
1723 | if (cmdnode == NULL) { |
1724 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); | |
1725 | ||
1726 | /* Wake up main thread to execute next command */ | |
1727 | wake_up_interruptible(&priv->waitq); | |
3399ea5f | 1728 | cmdnode = ERR_PTR(-ENOBUFS); |
675787e2 HS |
1729 | goto done; |
1730 | } | |
1731 | ||
448a51ae | 1732 | cmdnode->callback = callback; |
1309b55b | 1733 | cmdnode->callback_arg = callback_arg; |
675787e2 | 1734 | |
7ad994de | 1735 | /* Copy the incoming command to the buffer */ |
ddac4526 | 1736 | memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size); |
7ad994de | 1737 | |
675787e2 | 1738 | /* Set sequence number, clean result, move to buffer */ |
aa21c004 | 1739 | priv->seqnum++; |
ddac4526 DW |
1740 | cmdnode->cmdbuf->command = cpu_to_le16(command); |
1741 | cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size); | |
1742 | cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum); | |
1743 | cmdnode->cmdbuf->result = 0; | |
675787e2 HS |
1744 | |
1745 | lbs_deb_host("PREP_CMD: command 0x%04x\n", command); | |
1746 | ||
675787e2 | 1747 | cmdnode->cmdwaitqwoken = 0; |
681ffbb7 | 1748 | lbs_queue_cmd(priv, cmdnode); |
675787e2 HS |
1749 | wake_up_interruptible(&priv->waitq); |
1750 | ||
3399ea5f DW |
1751 | done: |
1752 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode); | |
1753 | return cmdnode; | |
1754 | } | |
1755 | ||
8db4a2b9 HS |
1756 | void lbs_cmd_async(struct lbs_private *priv, uint16_t command, |
1757 | struct cmd_header *in_cmd, int in_cmd_size) | |
1758 | { | |
1759 | lbs_deb_enter(LBS_DEB_CMD); | |
1760 | __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
1761 | lbs_cmd_async_callback, 0); | |
1762 | lbs_deb_leave(LBS_DEB_CMD); | |
1763 | } | |
1764 | ||
3399ea5f DW |
1765 | int __lbs_cmd(struct lbs_private *priv, uint16_t command, |
1766 | struct cmd_header *in_cmd, int in_cmd_size, | |
1767 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
1768 | unsigned long callback_arg) | |
1769 | { | |
1770 | struct cmd_ctrl_node *cmdnode; | |
1771 | unsigned long flags; | |
1772 | int ret = 0; | |
1773 | ||
1774 | lbs_deb_enter(LBS_DEB_HOST); | |
1775 | ||
1776 | cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
1777 | callback, callback_arg); | |
1778 | if (IS_ERR(cmdnode)) { | |
1779 | ret = PTR_ERR(cmdnode); | |
1780 | goto done; | |
1781 | } | |
1782 | ||
675787e2 HS |
1783 | might_sleep(); |
1784 | wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken); | |
1785 | ||
aa21c004 | 1786 | spin_lock_irqsave(&priv->driver_lock, flags); |
ae125bf8 DW |
1787 | ret = cmdnode->result; |
1788 | if (ret) | |
1789 | lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n", | |
1790 | command, ret); | |
3399ea5f | 1791 | |
ad12d0f4 | 1792 | __lbs_cleanup_and_insert_cmd(priv, cmdnode); |
aa21c004 | 1793 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
675787e2 HS |
1794 | |
1795 | done: | |
1796 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); | |
1797 | return ret; | |
1798 | } | |
14e865ba | 1799 | EXPORT_SYMBOL_GPL(__lbs_cmd); |