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 | ||
cc4b9d39 DW |
728 | /** |
729 | * @brief Send regulatory and 802.11d domain information to the firmware | |
730 | * | |
731 | * @param priv pointer to struct lbs_private | |
732 | * @param request cfg80211 regulatory request structure | |
733 | * @param bands the device's supported bands and channels | |
734 | * | |
735 | * @return 0 on success, error code on failure | |
736 | */ | |
737 | int lbs_set_11d_domain_info(struct lbs_private *priv, | |
738 | struct regulatory_request *request, | |
739 | struct ieee80211_supported_band **bands) | |
740 | { | |
741 | struct cmd_ds_802_11d_domain_info cmd; | |
742 | struct mrvl_ie_domain_param_set *domain = &cmd.domain; | |
743 | struct ieee80211_country_ie_triplet *t; | |
744 | enum ieee80211_band band; | |
745 | struct ieee80211_channel *ch; | |
746 | u8 num_triplet = 0; | |
747 | u8 num_parsed_chan = 0; | |
748 | u8 first_channel = 0, next_chan = 0, max_pwr = 0; | |
749 | u8 i, flag = 0; | |
750 | size_t triplet_size; | |
751 | int ret; | |
752 | ||
753 | lbs_deb_enter(LBS_DEB_11D); | |
754 | ||
755 | memset(&cmd, 0, sizeof(cmd)); | |
756 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
757 | ||
758 | lbs_deb_11d("Setting country code '%c%c'\n", | |
759 | request->alpha2[0], request->alpha2[1]); | |
760 | ||
761 | domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN); | |
762 | ||
763 | /* Set country code */ | |
764 | domain->country_code[0] = request->alpha2[0]; | |
765 | domain->country_code[1] = request->alpha2[1]; | |
766 | domain->country_code[2] = ' '; | |
767 | ||
768 | /* Now set up the channel triplets; firmware is somewhat picky here | |
769 | * and doesn't validate channel numbers and spans; hence it would | |
770 | * interpret a triplet of (36, 4, 20) as channels 36, 37, 38, 39. Since | |
771 | * the last 3 aren't valid channels, the driver is responsible for | |
772 | * splitting that up into 4 triplet pairs of (36, 1, 20) + (40, 1, 20) | |
773 | * etc. | |
774 | */ | |
775 | for (band = 0; | |
776 | (band < IEEE80211_NUM_BANDS) && (num_triplet < MAX_11D_TRIPLETS); | |
777 | band++) { | |
778 | ||
779 | if (!bands[band]) | |
780 | continue; | |
781 | ||
782 | for (i = 0; | |
783 | (i < bands[band]->n_channels) && (num_triplet < MAX_11D_TRIPLETS); | |
784 | i++) { | |
785 | ch = &bands[band]->channels[i]; | |
786 | if (ch->flags & IEEE80211_CHAN_DISABLED) | |
787 | continue; | |
788 | ||
789 | if (!flag) { | |
790 | flag = 1; | |
791 | next_chan = first_channel = (u32) ch->hw_value; | |
792 | max_pwr = ch->max_power; | |
793 | num_parsed_chan = 1; | |
794 | continue; | |
795 | } | |
796 | ||
797 | if ((ch->hw_value == next_chan + 1) && | |
798 | (ch->max_power == max_pwr)) { | |
799 | /* Consolidate adjacent channels */ | |
800 | next_chan++; | |
801 | num_parsed_chan++; | |
802 | } else { | |
803 | /* Add this triplet */ | |
804 | lbs_deb_11d("11D triplet (%d, %d, %d)\n", | |
805 | first_channel, num_parsed_chan, | |
806 | max_pwr); | |
807 | t = &domain->triplet[num_triplet]; | |
808 | t->chans.first_channel = first_channel; | |
809 | t->chans.num_channels = num_parsed_chan; | |
810 | t->chans.max_power = max_pwr; | |
811 | num_triplet++; | |
812 | flag = 0; | |
813 | } | |
814 | } | |
815 | ||
816 | if (flag) { | |
817 | /* Add last triplet */ | |
818 | lbs_deb_11d("11D triplet (%d, %d, %d)\n", first_channel, | |
819 | num_parsed_chan, max_pwr); | |
820 | t = &domain->triplet[num_triplet]; | |
821 | t->chans.first_channel = first_channel; | |
822 | t->chans.num_channels = num_parsed_chan; | |
823 | t->chans.max_power = max_pwr; | |
824 | num_triplet++; | |
825 | } | |
826 | } | |
827 | ||
828 | lbs_deb_11d("# triplets %d\n", num_triplet); | |
829 | ||
830 | /* Set command header sizes */ | |
831 | triplet_size = num_triplet * sizeof(struct ieee80211_country_ie_triplet); | |
832 | domain->header.len = cpu_to_le16(sizeof(domain->country_code) + | |
833 | triplet_size); | |
834 | ||
835 | lbs_deb_hex(LBS_DEB_11D, "802.11D domain param set", | |
836 | (u8 *) &cmd.domain.country_code, | |
837 | le16_to_cpu(domain->header.len)); | |
838 | ||
839 | cmd.hdr.size = cpu_to_le16(sizeof(cmd.hdr) + | |
840 | sizeof(cmd.action) + | |
841 | sizeof(cmd.domain.header) + | |
842 | sizeof(cmd.domain.country_code) + | |
843 | triplet_size); | |
844 | ||
845 | ret = lbs_cmd_with_response(priv, CMD_802_11D_DOMAIN_INFO, &cmd); | |
846 | ||
847 | lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret); | |
848 | return ret; | |
849 | } | |
850 | ||
4c7c6e00 DW |
851 | /** |
852 | * @brief Read a MAC, Baseband, or RF register | |
853 | * | |
854 | * @param priv pointer to struct lbs_private | |
855 | * @param cmd register command, one of CMD_MAC_REG_ACCESS, | |
856 | * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS | |
857 | * @param offset byte offset of the register to get | |
858 | * @param value on success, the value of the register at 'offset' | |
859 | * | |
860 | * @return 0 on success, error code on failure | |
861 | */ | |
862 | int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value) | |
876c9d3a | 863 | { |
4c7c6e00 DW |
864 | struct cmd_ds_reg_access cmd; |
865 | int ret = 0; | |
876c9d3a | 866 | |
9012b28a | 867 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 868 | |
4c7c6e00 | 869 | BUG_ON(value == NULL); |
876c9d3a | 870 | |
4c7c6e00 DW |
871 | memset(&cmd, 0, sizeof(cmd)); |
872 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
873 | cmd.action = cpu_to_le16(CMD_ACT_GET); | |
876c9d3a | 874 | |
4c7c6e00 DW |
875 | if (reg != CMD_MAC_REG_ACCESS && |
876 | reg != CMD_BBP_REG_ACCESS && | |
877 | reg != CMD_RF_REG_ACCESS) { | |
878 | ret = -EINVAL; | |
879 | goto out; | |
880 | } | |
876c9d3a | 881 | |
4c7c6e00 DW |
882 | ret = lbs_cmd_with_response(priv, reg, &cmd); |
883 | if (ret) { | |
884 | if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS) | |
885 | *value = cmd.value.bbp_rf; | |
886 | else if (reg == CMD_MAC_REG_ACCESS) | |
887 | *value = le32_to_cpu(cmd.value.mac); | |
888 | } | |
876c9d3a | 889 | |
4c7c6e00 DW |
890 | out: |
891 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
892 | return ret; | |
893 | } | |
876c9d3a | 894 | |
4c7c6e00 DW |
895 | /** |
896 | * @brief Write a MAC, Baseband, or RF register | |
897 | * | |
898 | * @param priv pointer to struct lbs_private | |
899 | * @param cmd register command, one of CMD_MAC_REG_ACCESS, | |
900 | * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS | |
901 | * @param offset byte offset of the register to set | |
902 | * @param value the value to write to the register at 'offset' | |
903 | * | |
904 | * @return 0 on success, error code on failure | |
905 | */ | |
906 | int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value) | |
907 | { | |
908 | struct cmd_ds_reg_access cmd; | |
909 | int ret = 0; | |
876c9d3a | 910 | |
4c7c6e00 | 911 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 912 | |
4c7c6e00 DW |
913 | memset(&cmd, 0, sizeof(cmd)); |
914 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
915 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
876c9d3a | 916 | |
4c7c6e00 DW |
917 | if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS) |
918 | cmd.value.bbp_rf = (u8) (value & 0xFF); | |
919 | else if (reg == CMD_MAC_REG_ACCESS) | |
920 | cmd.value.mac = cpu_to_le32(value); | |
921 | else { | |
922 | ret = -EINVAL; | |
923 | goto out; | |
876c9d3a MT |
924 | } |
925 | ||
4c7c6e00 DW |
926 | ret = lbs_cmd_with_response(priv, reg, &cmd); |
927 | ||
928 | out: | |
929 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
930 | return ret; | |
876c9d3a MT |
931 | } |
932 | ||
681ffbb7 DW |
933 | static void lbs_queue_cmd(struct lbs_private *priv, |
934 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
935 | { |
936 | unsigned long flags; | |
681ffbb7 | 937 | int addtail = 1; |
876c9d3a | 938 | |
8ff12da1 | 939 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 940 | |
c4ab4127 DW |
941 | if (!cmdnode) { |
942 | lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n"); | |
876c9d3a MT |
943 | goto done; |
944 | } | |
d9896ee1 DW |
945 | if (!cmdnode->cmdbuf->size) { |
946 | lbs_deb_host("DNLD_CMD: cmd size is zero\n"); | |
947 | goto done; | |
948 | } | |
ae125bf8 | 949 | cmdnode->result = 0; |
876c9d3a MT |
950 | |
951 | /* Exit_PS command needs to be queued in the header always. */ | |
ddac4526 | 952 | if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) { |
38bfab1a | 953 | struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1]; |
ddac4526 | 954 | |
0aef64d7 | 955 | if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
aa21c004 | 956 | if (priv->psstate != PS_STATE_FULL_POWER) |
876c9d3a MT |
957 | addtail = 0; |
958 | } | |
959 | } | |
960 | ||
66fceb69 AK |
961 | if (le16_to_cpu(cmdnode->cmdbuf->command) == |
962 | CMD_802_11_WAKEUP_CONFIRM) | |
963 | addtail = 0; | |
964 | ||
aa21c004 | 965 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 966 | |
ac47246e | 967 | if (addtail) |
aa21c004 | 968 | list_add_tail(&cmdnode->list, &priv->cmdpendingq); |
ac47246e | 969 | else |
aa21c004 | 970 | list_add(&cmdnode->list, &priv->cmdpendingq); |
876c9d3a | 971 | |
aa21c004 | 972 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 973 | |
8ff12da1 | 974 | lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n", |
c4ab4127 | 975 | le16_to_cpu(cmdnode->cmdbuf->command)); |
876c9d3a MT |
976 | |
977 | done: | |
8ff12da1 | 978 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
979 | } |
980 | ||
18c52e7c DW |
981 | static void lbs_submit_command(struct lbs_private *priv, |
982 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
983 | { |
984 | unsigned long flags; | |
ddac4526 | 985 | struct cmd_header *cmd; |
18c52e7c DW |
986 | uint16_t cmdsize; |
987 | uint16_t command; | |
57962f0b | 988 | int timeo = 3 * HZ; |
18c52e7c | 989 | int ret; |
876c9d3a | 990 | |
8ff12da1 | 991 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 992 | |
ddac4526 | 993 | cmd = cmdnode->cmdbuf; |
876c9d3a | 994 | |
aa21c004 | 995 | spin_lock_irqsave(&priv->driver_lock, flags); |
aa21c004 DW |
996 | priv->cur_cmd = cmdnode; |
997 | priv->cur_cmd_retcode = 0; | |
998 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a | 999 | |
ddac4526 DW |
1000 | cmdsize = le16_to_cpu(cmd->size); |
1001 | command = le16_to_cpu(cmd->command); | |
876c9d3a | 1002 | |
18c52e7c | 1003 | /* These commands take longer */ |
be0d76e4 | 1004 | if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE) |
57962f0b | 1005 | timeo = 5 * HZ; |
18c52e7c | 1006 | |
e5225b39 HS |
1007 | lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n", |
1008 | command, le16_to_cpu(cmd->seqnum), cmdsize); | |
1afc09ab | 1009 | lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize); |
8ff12da1 | 1010 | |
ddac4526 | 1011 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize); |
18c52e7c | 1012 | |
d9896ee1 DW |
1013 | if (ret) { |
1014 | lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret); | |
18c52e7c DW |
1015 | /* Let the timer kick in and retry, and potentially reset |
1016 | the whole thing if the condition persists */ | |
57962f0b | 1017 | timeo = HZ/4; |
1afc09ab | 1018 | } |
876c9d3a | 1019 | |
49125454 AK |
1020 | if (command == CMD_802_11_DEEP_SLEEP) { |
1021 | if (priv->is_auto_deep_sleep_enabled) { | |
1022 | priv->wakeup_dev_required = 1; | |
1023 | priv->dnld_sent = 0; | |
1024 | } | |
1025 | priv->is_deep_sleep = 1; | |
1026 | lbs_complete_command(priv, cmdnode, 0); | |
1027 | } else { | |
1028 | /* Setup the timer after transmit command */ | |
1029 | mod_timer(&priv->command_timer, jiffies + timeo); | |
1030 | } | |
876c9d3a | 1031 | |
18c52e7c | 1032 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1033 | } |
1034 | ||
876c9d3a MT |
1035 | /** |
1036 | * This function inserts command node to cmdfreeq | |
aa21c004 | 1037 | * after cleans it. Requires priv->driver_lock held. |
876c9d3a | 1038 | */ |
183aeac1 | 1039 | static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
5ba2f8a0 | 1040 | struct cmd_ctrl_node *cmdnode) |
876c9d3a | 1041 | { |
5ba2f8a0 DW |
1042 | lbs_deb_enter(LBS_DEB_HOST); |
1043 | ||
1044 | if (!cmdnode) | |
1045 | goto out; | |
1046 | ||
5ba2f8a0 DW |
1047 | cmdnode->callback = NULL; |
1048 | cmdnode->callback_arg = 0; | |
876c9d3a | 1049 | |
5ba2f8a0 | 1050 | memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE); |
876c9d3a | 1051 | |
5ba2f8a0 DW |
1052 | list_add_tail(&cmdnode->list, &priv->cmdfreeq); |
1053 | out: | |
1054 | lbs_deb_leave(LBS_DEB_HOST); | |
876c9d3a MT |
1055 | } |
1056 | ||
69f9032d HS |
1057 | static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
1058 | struct cmd_ctrl_node *ptempcmd) | |
876c9d3a MT |
1059 | { |
1060 | unsigned long flags; | |
1061 | ||
aa21c004 | 1062 | spin_lock_irqsave(&priv->driver_lock, flags); |
10078321 | 1063 | __lbs_cleanup_and_insert_cmd(priv, ptempcmd); |
aa21c004 | 1064 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1065 | } |
1066 | ||
183aeac1 DW |
1067 | void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd, |
1068 | int result) | |
1069 | { | |
1070 | if (cmd == priv->cur_cmd) | |
1071 | priv->cur_cmd_retcode = result; | |
5ba2f8a0 | 1072 | |
ae125bf8 | 1073 | cmd->result = result; |
5ba2f8a0 DW |
1074 | cmd->cmdwaitqwoken = 1; |
1075 | wake_up_interruptible(&cmd->cmdwait_q); | |
1076 | ||
8db4a2b9 | 1077 | if (!cmd->callback || cmd->callback == lbs_cmd_async_callback) |
ad12d0f4 | 1078 | __lbs_cleanup_and_insert_cmd(priv, cmd); |
183aeac1 DW |
1079 | priv->cur_cmd = NULL; |
1080 | } | |
1081 | ||
d5db2dfa | 1082 | int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on) |
876c9d3a | 1083 | { |
a7c45890 | 1084 | struct cmd_ds_802_11_radio_control cmd; |
d5db2dfa | 1085 | int ret = -EINVAL; |
876c9d3a | 1086 | |
9012b28a | 1087 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1088 | |
a7c45890 DW |
1089 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
1090 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1091 | ||
d5db2dfa DW |
1092 | /* Only v8 and below support setting the preamble */ |
1093 | if (priv->fwrelease < 0x09000000) { | |
1094 | switch (preamble) { | |
1095 | case RADIO_PREAMBLE_SHORT: | |
d5db2dfa DW |
1096 | case RADIO_PREAMBLE_AUTO: |
1097 | case RADIO_PREAMBLE_LONG: | |
1098 | cmd.control = cpu_to_le16(preamble); | |
1099 | break; | |
1100 | default: | |
1101 | goto out; | |
1102 | } | |
1103 | } | |
a7c45890 | 1104 | |
d5db2dfa DW |
1105 | if (radio_on) |
1106 | cmd.control |= cpu_to_le16(0x1); | |
1107 | else { | |
1108 | cmd.control &= cpu_to_le16(~0x1); | |
1109 | priv->txpower_cur = 0; | |
a7c45890 | 1110 | } |
876c9d3a | 1111 | |
d5db2dfa DW |
1112 | lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n", |
1113 | radio_on ? "ON" : "OFF", preamble); | |
a7c45890 | 1114 | |
d5db2dfa | 1115 | priv->radio_on = radio_on; |
a7c45890 DW |
1116 | |
1117 | ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd); | |
876c9d3a | 1118 | |
d5db2dfa | 1119 | out: |
9012b28a | 1120 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
1121 | return ret; |
1122 | } | |
1123 | ||
c97329e2 | 1124 | void lbs_set_mac_control(struct lbs_private *priv) |
876c9d3a | 1125 | { |
835d3ac5 | 1126 | struct cmd_ds_mac_control cmd; |
876c9d3a | 1127 | |
9012b28a | 1128 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1129 | |
835d3ac5 | 1130 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
d9e9778c | 1131 | cmd.action = cpu_to_le16(priv->mac_control); |
835d3ac5 HS |
1132 | cmd.reserved = 0; |
1133 | ||
75bf45a7 | 1134 | lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd)); |
876c9d3a | 1135 | |
c97329e2 | 1136 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1137 | } |
1138 | ||
1139 | /** | |
1140 | * @brief This function prepare the command before send to firmware. | |
1141 | * | |
69f9032d | 1142 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1143 | * @param cmd_no command number |
1144 | * @param cmd_action command action: GET or SET | |
1145 | * @param wait_option wait option: wait response or not | |
1146 | * @param cmd_oid cmd oid: treated as sub command | |
1147 | * @param pdata_buf A pointer to informaion buffer | |
1148 | * @return 0 or -1 | |
1149 | */ | |
69f9032d | 1150 | int lbs_prepare_and_send_command(struct lbs_private *priv, |
876c9d3a MT |
1151 | u16 cmd_no, |
1152 | u16 cmd_action, | |
1153 | u16 wait_option, u32 cmd_oid, void *pdata_buf) | |
1154 | { | |
1155 | int ret = 0; | |
876c9d3a MT |
1156 | struct cmd_ctrl_node *cmdnode; |
1157 | struct cmd_ds_command *cmdptr; | |
1158 | unsigned long flags; | |
1159 | ||
8ff12da1 | 1160 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1161 | |
aa21c004 DW |
1162 | if (!priv) { |
1163 | lbs_deb_host("PREP_CMD: priv is NULL\n"); | |
876c9d3a MT |
1164 | ret = -1; |
1165 | goto done; | |
1166 | } | |
1167 | ||
aa21c004 | 1168 | if (priv->surpriseremoved) { |
8ff12da1 | 1169 | lbs_deb_host("PREP_CMD: card removed\n"); |
876c9d3a MT |
1170 | ret = -1; |
1171 | goto done; | |
1172 | } | |
1173 | ||
63f275df AK |
1174 | if (!lbs_is_cmd_allowed(priv)) { |
1175 | ret = -EBUSY; | |
1176 | goto done; | |
1177 | } | |
1178 | ||
0d61d042 | 1179 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
876c9d3a MT |
1180 | |
1181 | if (cmdnode == NULL) { | |
8ff12da1 | 1182 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
876c9d3a MT |
1183 | |
1184 | /* Wake up main thread to execute next command */ | |
fe336150 | 1185 | wake_up_interruptible(&priv->waitq); |
876c9d3a MT |
1186 | ret = -1; |
1187 | goto done; | |
1188 | } | |
1189 | ||
e98a88dd HS |
1190 | cmdnode->callback = NULL; |
1191 | cmdnode->callback_arg = (unsigned long)pdata_buf; | |
876c9d3a | 1192 | |
ddac4526 | 1193 | cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf; |
876c9d3a | 1194 | |
8ff12da1 | 1195 | lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no); |
876c9d3a | 1196 | |
876c9d3a | 1197 | /* Set sequence number, command and INT option */ |
aa21c004 DW |
1198 | priv->seqnum++; |
1199 | cmdptr->seqnum = cpu_to_le16(priv->seqnum); | |
876c9d3a | 1200 | |
981f187b | 1201 | cmdptr->command = cpu_to_le16(cmd_no); |
876c9d3a MT |
1202 | cmdptr->result = 0; |
1203 | ||
1204 | switch (cmd_no) { | |
0aef64d7 | 1205 | case CMD_802_11_PS_MODE: |
e98a88dd | 1206 | ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action); |
876c9d3a MT |
1207 | break; |
1208 | ||
49125454 AK |
1209 | case CMD_802_11_DEEP_SLEEP: |
1210 | cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP); | |
8ec97cc8 | 1211 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_header)); |
49125454 | 1212 | break; |
876c9d3a | 1213 | default: |
e37fc6e1 | 1214 | lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no); |
876c9d3a MT |
1215 | ret = -1; |
1216 | break; | |
1217 | } | |
1218 | ||
1219 | /* return error, since the command preparation failed */ | |
1220 | if (ret != 0) { | |
8ff12da1 | 1221 | lbs_deb_host("PREP_CMD: command preparation failed\n"); |
10078321 | 1222 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1223 | ret = -1; |
1224 | goto done; | |
1225 | } | |
1226 | ||
1227 | cmdnode->cmdwaitqwoken = 0; | |
1228 | ||
681ffbb7 | 1229 | lbs_queue_cmd(priv, cmdnode); |
fe336150 | 1230 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1231 | |
0aef64d7 | 1232 | if (wait_option & CMD_OPTION_WAITFORRSP) { |
8ff12da1 | 1233 | lbs_deb_host("PREP_CMD: wait for response\n"); |
876c9d3a MT |
1234 | might_sleep(); |
1235 | wait_event_interruptible(cmdnode->cmdwait_q, | |
1236 | cmdnode->cmdwaitqwoken); | |
1237 | } | |
1238 | ||
aa21c004 DW |
1239 | spin_lock_irqsave(&priv->driver_lock, flags); |
1240 | if (priv->cur_cmd_retcode) { | |
8ff12da1 | 1241 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", |
aa21c004 DW |
1242 | priv->cur_cmd_retcode); |
1243 | priv->cur_cmd_retcode = 0; | |
876c9d3a MT |
1244 | ret = -1; |
1245 | } | |
aa21c004 | 1246 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1247 | |
1248 | done: | |
8ff12da1 | 1249 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1250 | return ret; |
1251 | } | |
1252 | ||
1253 | /** | |
1254 | * @brief This function allocates the command buffer and link | |
1255 | * it to command free queue. | |
1256 | * | |
69f9032d | 1257 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1258 | * @return 0 or -1 |
1259 | */ | |
69f9032d | 1260 | int lbs_allocate_cmd_buffer(struct lbs_private *priv) |
876c9d3a MT |
1261 | { |
1262 | int ret = 0; | |
ddac4526 | 1263 | u32 bufsize; |
876c9d3a | 1264 | u32 i; |
ddac4526 | 1265 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1266 | |
8ff12da1 | 1267 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1268 | |
ddac4526 DW |
1269 | /* Allocate and initialize the command array */ |
1270 | bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS; | |
1271 | if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) { | |
8ff12da1 | 1272 | lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n"); |
876c9d3a MT |
1273 | ret = -1; |
1274 | goto done; | |
1275 | } | |
ddac4526 | 1276 | priv->cmd_array = cmdarray; |
876c9d3a | 1277 | |
ddac4526 DW |
1278 | /* Allocate and initialize each command buffer in the command array */ |
1279 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { | |
1280 | cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL); | |
1281 | if (!cmdarray[i].cmdbuf) { | |
8ff12da1 | 1282 | lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); |
876c9d3a MT |
1283 | ret = -1; |
1284 | goto done; | |
1285 | } | |
876c9d3a MT |
1286 | } |
1287 | ||
ddac4526 DW |
1288 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1289 | init_waitqueue_head(&cmdarray[i].cmdwait_q); | |
1290 | lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]); | |
876c9d3a | 1291 | } |
876c9d3a | 1292 | ret = 0; |
9012b28a HS |
1293 | |
1294 | done: | |
8ff12da1 | 1295 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1296 | return ret; |
1297 | } | |
1298 | ||
1299 | /** | |
1300 | * @brief This function frees the command buffer. | |
1301 | * | |
69f9032d | 1302 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1303 | * @return 0 or -1 |
1304 | */ | |
69f9032d | 1305 | int lbs_free_cmd_buffer(struct lbs_private *priv) |
876c9d3a | 1306 | { |
ddac4526 | 1307 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1308 | unsigned int i; |
876c9d3a | 1309 | |
8ff12da1 | 1310 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1311 | |
1312 | /* need to check if cmd array is allocated or not */ | |
aa21c004 | 1313 | if (priv->cmd_array == NULL) { |
8ff12da1 | 1314 | lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n"); |
876c9d3a MT |
1315 | goto done; |
1316 | } | |
1317 | ||
ddac4526 | 1318 | cmdarray = priv->cmd_array; |
876c9d3a MT |
1319 | |
1320 | /* Release shared memory buffers */ | |
ddac4526 DW |
1321 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1322 | if (cmdarray[i].cmdbuf) { | |
1323 | kfree(cmdarray[i].cmdbuf); | |
1324 | cmdarray[i].cmdbuf = NULL; | |
876c9d3a MT |
1325 | } |
1326 | } | |
1327 | ||
1328 | /* Release cmd_ctrl_node */ | |
aa21c004 DW |
1329 | if (priv->cmd_array) { |
1330 | kfree(priv->cmd_array); | |
1331 | priv->cmd_array = NULL; | |
876c9d3a MT |
1332 | } |
1333 | ||
1334 | done: | |
8ff12da1 | 1335 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1336 | return 0; |
1337 | } | |
1338 | ||
1339 | /** | |
1340 | * @brief This function gets a free command node if available in | |
1341 | * command free queue. | |
1342 | * | |
69f9032d | 1343 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1344 | * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL |
1345 | */ | |
2fd6cfe3 | 1346 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv) |
876c9d3a MT |
1347 | { |
1348 | struct cmd_ctrl_node *tempnode; | |
876c9d3a MT |
1349 | unsigned long flags; |
1350 | ||
8ff12da1 HS |
1351 | lbs_deb_enter(LBS_DEB_HOST); |
1352 | ||
aa21c004 | 1353 | if (!priv) |
876c9d3a MT |
1354 | return NULL; |
1355 | ||
aa21c004 | 1356 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1357 | |
aa21c004 DW |
1358 | if (!list_empty(&priv->cmdfreeq)) { |
1359 | tempnode = list_first_entry(&priv->cmdfreeq, | |
abe3ed14 LZ |
1360 | struct cmd_ctrl_node, list); |
1361 | list_del(&tempnode->list); | |
876c9d3a | 1362 | } else { |
8ff12da1 | 1363 | lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n"); |
876c9d3a MT |
1364 | tempnode = NULL; |
1365 | } | |
1366 | ||
aa21c004 | 1367 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 1368 | |
8ff12da1 | 1369 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1370 | return tempnode; |
1371 | } | |
1372 | ||
876c9d3a MT |
1373 | /** |
1374 | * @brief This function executes next command in command | |
877d0310 | 1375 | * pending queue. It will put firmware back to PS mode |
876c9d3a MT |
1376 | * if applicable. |
1377 | * | |
69f9032d | 1378 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1379 | * @return 0 or -1 |
1380 | */ | |
69f9032d | 1381 | int lbs_execute_next_command(struct lbs_private *priv) |
876c9d3a | 1382 | { |
876c9d3a | 1383 | struct cmd_ctrl_node *cmdnode = NULL; |
ddac4526 | 1384 | struct cmd_header *cmd; |
876c9d3a MT |
1385 | unsigned long flags; |
1386 | int ret = 0; | |
1387 | ||
1afc09ab HS |
1388 | /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the |
1389 | * only caller to us is lbs_thread() and we get even when a | |
1390 | * data packet is received */ | |
8ff12da1 | 1391 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1392 | |
aa21c004 | 1393 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1394 | |
aa21c004 | 1395 | if (priv->cur_cmd) { |
8ff12da1 | 1396 | lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); |
aa21c004 | 1397 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1398 | ret = -1; |
1399 | goto done; | |
1400 | } | |
1401 | ||
aa21c004 DW |
1402 | if (!list_empty(&priv->cmdpendingq)) { |
1403 | cmdnode = list_first_entry(&priv->cmdpendingq, | |
abe3ed14 | 1404 | struct cmd_ctrl_node, list); |
876c9d3a MT |
1405 | } |
1406 | ||
aa21c004 | 1407 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1408 | |
1409 | if (cmdnode) { | |
ddac4526 | 1410 | cmd = cmdnode->cmdbuf; |
876c9d3a | 1411 | |
ddac4526 | 1412 | if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) { |
aa21c004 DW |
1413 | if ((priv->psstate == PS_STATE_SLEEP) || |
1414 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1415 | lbs_deb_host( |
1416 | "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n", | |
ddac4526 | 1417 | le16_to_cpu(cmd->command), |
aa21c004 | 1418 | priv->psstate); |
876c9d3a MT |
1419 | ret = -1; |
1420 | goto done; | |
1421 | } | |
8ff12da1 | 1422 | lbs_deb_host("EXEC_NEXT_CMD: OK to send command " |
ddac4526 DW |
1423 | "0x%04x in psstate %d\n", |
1424 | le16_to_cpu(cmd->command), priv->psstate); | |
aa21c004 | 1425 | } else if (priv->psstate != PS_STATE_FULL_POWER) { |
876c9d3a MT |
1426 | /* |
1427 | * 1. Non-PS command: | |
1428 | * Queue it. set needtowakeup to TRUE if current state | |
10078321 | 1429 | * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS. |
876c9d3a MT |
1430 | * 2. PS command but not Exit_PS: |
1431 | * Ignore it. | |
1432 | * 3. PS command Exit_PS: | |
1433 | * Set needtowakeup to TRUE if current state is SLEEP, | |
1434 | * otherwise send this command down to firmware | |
1435 | * immediately. | |
1436 | */ | |
ddac4526 | 1437 | if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) { |
876c9d3a MT |
1438 | /* Prepare to send Exit PS, |
1439 | * this non PS command will be sent later */ | |
aa21c004 DW |
1440 | if ((priv->psstate == PS_STATE_SLEEP) |
1441 | || (priv->psstate == PS_STATE_PRE_SLEEP) | |
876c9d3a MT |
1442 | ) { |
1443 | /* w/ new scheme, it will not reach here. | |
1444 | since it is blocked in main_thread. */ | |
aa21c004 | 1445 | priv->needtowakeup = 1; |
876c9d3a | 1446 | } else |
10078321 | 1447 | lbs_ps_wakeup(priv, 0); |
876c9d3a MT |
1448 | |
1449 | ret = 0; | |
1450 | goto done; | |
1451 | } else { | |
1452 | /* | |
1453 | * PS command. Ignore it if it is not Exit_PS. | |
1454 | * otherwise send it down immediately. | |
1455 | */ | |
38bfab1a | 1456 | struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1]; |
876c9d3a | 1457 | |
8ff12da1 HS |
1458 | lbs_deb_host( |
1459 | "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n", | |
876c9d3a MT |
1460 | psm->action); |
1461 | if (psm->action != | |
0aef64d7 | 1462 | cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
8ff12da1 HS |
1463 | lbs_deb_host( |
1464 | "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); | |
abe3ed14 | 1465 | list_del(&cmdnode->list); |
183aeac1 DW |
1466 | spin_lock_irqsave(&priv->driver_lock, flags); |
1467 | lbs_complete_command(priv, cmdnode, 0); | |
1468 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a MT |
1469 | |
1470 | ret = 0; | |
1471 | goto done; | |
1472 | } | |
1473 | ||
aa21c004 DW |
1474 | if ((priv->psstate == PS_STATE_SLEEP) || |
1475 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1476 | lbs_deb_host( |
1477 | "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); | |
abe3ed14 | 1478 | list_del(&cmdnode->list); |
183aeac1 DW |
1479 | spin_lock_irqsave(&priv->driver_lock, flags); |
1480 | lbs_complete_command(priv, cmdnode, 0); | |
1481 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
aa21c004 | 1482 | priv->needtowakeup = 1; |
876c9d3a MT |
1483 | |
1484 | ret = 0; | |
1485 | goto done; | |
1486 | } | |
1487 | ||
8ff12da1 HS |
1488 | lbs_deb_host( |
1489 | "EXEC_NEXT_CMD: sending EXIT_PS\n"); | |
876c9d3a MT |
1490 | } |
1491 | } | |
abe3ed14 | 1492 | list_del(&cmdnode->list); |
8ff12da1 | 1493 | lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", |
ddac4526 | 1494 | le16_to_cpu(cmd->command)); |
d9896ee1 | 1495 | lbs_submit_command(priv, cmdnode); |
876c9d3a MT |
1496 | } else { |
1497 | /* | |
1498 | * check if in power save mode, if yes, put the device back | |
1499 | * to PS mode | |
1500 | */ | |
e86dc1ca KD |
1501 | #ifdef TODO |
1502 | /* | |
1503 | * This was the old code for libertas+wext. Someone that | |
1504 | * understands this beast should re-code it in a sane way. | |
1505 | * | |
1506 | * I actually don't understand why this is related to WPA | |
1507 | * and to connection status, shouldn't powering should be | |
1508 | * independ of such things? | |
1509 | */ | |
aa21c004 DW |
1510 | if ((priv->psmode != LBS802_11POWERMODECAM) && |
1511 | (priv->psstate == PS_STATE_FULL_POWER) && | |
1512 | ((priv->connect_status == LBS_CONNECTED) || | |
602114ae | 1513 | lbs_mesh_connected(priv))) { |
aa21c004 DW |
1514 | if (priv->secinfo.WPAenabled || |
1515 | priv->secinfo.WPA2enabled) { | |
876c9d3a | 1516 | /* check for valid WPA group keys */ |
aa21c004 DW |
1517 | if (priv->wpa_mcast_key.len || |
1518 | priv->wpa_unicast_key.len) { | |
8ff12da1 | 1519 | lbs_deb_host( |
876c9d3a MT |
1520 | "EXEC_NEXT_CMD: WPA enabled and GTK_SET" |
1521 | " go back to PS_SLEEP"); | |
10078321 | 1522 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1523 | } |
1524 | } else { | |
8ff12da1 HS |
1525 | lbs_deb_host( |
1526 | "EXEC_NEXT_CMD: cmdpendingq empty, " | |
1527 | "go back to PS_SLEEP"); | |
10078321 | 1528 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1529 | } |
1530 | } | |
e86dc1ca | 1531 | #endif |
876c9d3a MT |
1532 | } |
1533 | ||
1534 | ret = 0; | |
1535 | done: | |
8ff12da1 | 1536 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
1537 | return ret; |
1538 | } | |
1539 | ||
f539f2ef | 1540 | static void lbs_send_confirmsleep(struct lbs_private *priv) |
876c9d3a MT |
1541 | { |
1542 | unsigned long flags; | |
f539f2ef | 1543 | int ret; |
876c9d3a | 1544 | |
8ff12da1 | 1545 | lbs_deb_enter(LBS_DEB_HOST); |
f539f2ef HS |
1546 | lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep, |
1547 | sizeof(confirm_sleep)); | |
876c9d3a | 1548 | |
f539f2ef HS |
1549 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep, |
1550 | sizeof(confirm_sleep)); | |
876c9d3a | 1551 | if (ret) { |
f539f2ef | 1552 | lbs_pr_alert("confirm_sleep failed\n"); |
7919b89c | 1553 | goto out; |
876c9d3a | 1554 | } |
7919b89c HS |
1555 | |
1556 | spin_lock_irqsave(&priv->driver_lock, flags); | |
1557 | ||
a01f5450 HS |
1558 | /* We don't get a response on the sleep-confirmation */ |
1559 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
1560 | ||
66fceb69 AK |
1561 | if (priv->is_host_sleep_configured) { |
1562 | priv->is_host_sleep_activated = 1; | |
1563 | wake_up_interruptible(&priv->host_sleep_q); | |
1564 | } | |
1565 | ||
7919b89c | 1566 | /* If nothing to do, go back to sleep (?) */ |
e64c026d | 1567 | if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx]) |
7919b89c HS |
1568 | priv->psstate = PS_STATE_SLEEP; |
1569 | ||
1570 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
1571 | ||
1572 | out: | |
f539f2ef | 1573 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1574 | } |
1575 | ||
69f9032d | 1576 | void lbs_ps_sleep(struct lbs_private *priv, int wait_option) |
876c9d3a | 1577 | { |
8ff12da1 | 1578 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1579 | |
1580 | /* | |
1581 | * PS is currently supported only in Infrastructure mode | |
1582 | * Remove this check if it is to be supported in IBSS mode also | |
1583 | */ | |
1584 | ||
10078321 | 1585 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1586 | CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL); |
876c9d3a | 1587 | |
8ff12da1 | 1588 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1589 | } |
1590 | ||
1591 | /** | |
8ff12da1 | 1592 | * @brief This function sends Exit_PS command to firmware. |
876c9d3a | 1593 | * |
69f9032d | 1594 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1595 | * @param wait_option wait response or not |
1596 | * @return n/a | |
1597 | */ | |
69f9032d | 1598 | void lbs_ps_wakeup(struct lbs_private *priv, int wait_option) |
876c9d3a | 1599 | { |
981f187b | 1600 | __le32 Localpsmode; |
876c9d3a | 1601 | |
8ff12da1 | 1602 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1603 | |
10078321 | 1604 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
876c9d3a | 1605 | |
10078321 | 1606 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1607 | CMD_SUBCMD_EXIT_PS, |
876c9d3a MT |
1608 | wait_option, 0, &Localpsmode); |
1609 | ||
8ff12da1 | 1610 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1611 | } |
1612 | ||
1613 | /** | |
1614 | * @brief This function checks condition and prepares to | |
1615 | * send sleep confirm command to firmware if ok. | |
1616 | * | |
69f9032d | 1617 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1618 | * @param psmode Power Saving mode |
1619 | * @return n/a | |
1620 | */ | |
d4ff0ef6 | 1621 | void lbs_ps_confirm_sleep(struct lbs_private *priv) |
876c9d3a MT |
1622 | { |
1623 | unsigned long flags =0; | |
d4ff0ef6 | 1624 | int allowed = 1; |
876c9d3a | 1625 | |
8ff12da1 | 1626 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1627 | |
a01f5450 | 1628 | spin_lock_irqsave(&priv->driver_lock, flags); |
634b8f49 | 1629 | if (priv->dnld_sent) { |
876c9d3a | 1630 | allowed = 0; |
23d36eec | 1631 | lbs_deb_host("dnld_sent was set\n"); |
876c9d3a MT |
1632 | } |
1633 | ||
7919b89c | 1634 | /* In-progress command? */ |
aa21c004 | 1635 | if (priv->cur_cmd) { |
876c9d3a | 1636 | allowed = 0; |
23d36eec | 1637 | lbs_deb_host("cur_cmd was set\n"); |
876c9d3a | 1638 | } |
7919b89c HS |
1639 | |
1640 | /* Pending events or command responses? */ | |
e64c026d | 1641 | if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) { |
876c9d3a | 1642 | allowed = 0; |
7919b89c | 1643 | lbs_deb_host("pending events or command responses\n"); |
876c9d3a | 1644 | } |
aa21c004 | 1645 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1646 | |
1647 | if (allowed) { | |
10078321 | 1648 | lbs_deb_host("sending lbs_ps_confirm_sleep\n"); |
f539f2ef | 1649 | lbs_send_confirmsleep(priv); |
876c9d3a | 1650 | } else { |
8ff12da1 | 1651 | lbs_deb_host("sleep confirm has been delayed\n"); |
876c9d3a MT |
1652 | } |
1653 | ||
8ff12da1 | 1654 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a | 1655 | } |
675787e2 HS |
1656 | |
1657 | ||
0112c9e9 AN |
1658 | /** |
1659 | * @brief Configures the transmission power control functionality. | |
1660 | * | |
1661 | * @param priv A pointer to struct lbs_private structure | |
1662 | * @param enable Transmission power control enable | |
1663 | * @param p0 Power level when link quality is good (dBm). | |
1664 | * @param p1 Power level when link quality is fair (dBm). | |
1665 | * @param p2 Power level when link quality is poor (dBm). | |
1666 | * @param usesnr Use Signal to Noise Ratio in TPC | |
1667 | * | |
1668 | * @return 0 on success | |
1669 | */ | |
1670 | int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1, | |
1671 | int8_t p2, int usesnr) | |
1672 | { | |
1673 | struct cmd_ds_802_11_tpc_cfg cmd; | |
1674 | int ret; | |
1675 | ||
1676 | memset(&cmd, 0, sizeof(cmd)); | |
1677 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1678 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1679 | cmd.enable = !!enable; | |
3ed6e080 | 1680 | cmd.usesnr = !!usesnr; |
0112c9e9 AN |
1681 | cmd.P0 = p0; |
1682 | cmd.P1 = p1; | |
1683 | cmd.P2 = p2; | |
1684 | ||
1685 | ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd); | |
1686 | ||
1687 | return ret; | |
1688 | } | |
1689 | ||
1690 | /** | |
1691 | * @brief Configures the power adaptation settings. | |
1692 | * | |
1693 | * @param priv A pointer to struct lbs_private structure | |
1694 | * @param enable Power adaptation enable | |
1695 | * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm). | |
1696 | * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm). | |
1697 | * @param p2 Power level for 48 and 54 Mbps (dBm). | |
1698 | * | |
1699 | * @return 0 on Success | |
1700 | */ | |
1701 | ||
1702 | int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0, | |
1703 | int8_t p1, int8_t p2) | |
1704 | { | |
1705 | struct cmd_ds_802_11_pa_cfg cmd; | |
1706 | int ret; | |
1707 | ||
1708 | memset(&cmd, 0, sizeof(cmd)); | |
1709 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1710 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1711 | cmd.enable = !!enable; | |
1712 | cmd.P0 = p0; | |
1713 | cmd.P1 = p1; | |
1714 | cmd.P2 = p2; | |
1715 | ||
1716 | ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd); | |
1717 | ||
1718 | return ret; | |
1719 | } | |
1720 | ||
1721 | ||
6d898b19 | 1722 | struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, |
8db4a2b9 HS |
1723 | uint16_t command, struct cmd_header *in_cmd, int in_cmd_size, |
1724 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
1725 | unsigned long callback_arg) | |
675787e2 | 1726 | { |
675787e2 | 1727 | struct cmd_ctrl_node *cmdnode; |
675787e2 HS |
1728 | |
1729 | lbs_deb_enter(LBS_DEB_HOST); | |
675787e2 | 1730 | |
aa21c004 | 1731 | if (priv->surpriseremoved) { |
675787e2 | 1732 | lbs_deb_host("PREP_CMD: card removed\n"); |
3399ea5f | 1733 | cmdnode = ERR_PTR(-ENOENT); |
675787e2 HS |
1734 | goto done; |
1735 | } | |
1736 | ||
63f275df AK |
1737 | if (!lbs_is_cmd_allowed(priv)) { |
1738 | cmdnode = ERR_PTR(-EBUSY); | |
1739 | goto done; | |
1740 | } | |
1741 | ||
675787e2 | 1742 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
675787e2 HS |
1743 | if (cmdnode == NULL) { |
1744 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); | |
1745 | ||
1746 | /* Wake up main thread to execute next command */ | |
1747 | wake_up_interruptible(&priv->waitq); | |
3399ea5f | 1748 | cmdnode = ERR_PTR(-ENOBUFS); |
675787e2 HS |
1749 | goto done; |
1750 | } | |
1751 | ||
448a51ae | 1752 | cmdnode->callback = callback; |
1309b55b | 1753 | cmdnode->callback_arg = callback_arg; |
675787e2 | 1754 | |
7ad994de | 1755 | /* Copy the incoming command to the buffer */ |
ddac4526 | 1756 | memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size); |
7ad994de | 1757 | |
675787e2 | 1758 | /* Set sequence number, clean result, move to buffer */ |
aa21c004 | 1759 | priv->seqnum++; |
ddac4526 DW |
1760 | cmdnode->cmdbuf->command = cpu_to_le16(command); |
1761 | cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size); | |
1762 | cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum); | |
1763 | cmdnode->cmdbuf->result = 0; | |
675787e2 HS |
1764 | |
1765 | lbs_deb_host("PREP_CMD: command 0x%04x\n", command); | |
1766 | ||
675787e2 | 1767 | cmdnode->cmdwaitqwoken = 0; |
681ffbb7 | 1768 | lbs_queue_cmd(priv, cmdnode); |
675787e2 HS |
1769 | wake_up_interruptible(&priv->waitq); |
1770 | ||
3399ea5f DW |
1771 | done: |
1772 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode); | |
1773 | return cmdnode; | |
1774 | } | |
1775 | ||
8db4a2b9 HS |
1776 | void lbs_cmd_async(struct lbs_private *priv, uint16_t command, |
1777 | struct cmd_header *in_cmd, int in_cmd_size) | |
1778 | { | |
1779 | lbs_deb_enter(LBS_DEB_CMD); | |
1780 | __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
1781 | lbs_cmd_async_callback, 0); | |
1782 | lbs_deb_leave(LBS_DEB_CMD); | |
1783 | } | |
1784 | ||
3399ea5f DW |
1785 | int __lbs_cmd(struct lbs_private *priv, uint16_t command, |
1786 | struct cmd_header *in_cmd, int in_cmd_size, | |
1787 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
1788 | unsigned long callback_arg) | |
1789 | { | |
1790 | struct cmd_ctrl_node *cmdnode; | |
1791 | unsigned long flags; | |
1792 | int ret = 0; | |
1793 | ||
1794 | lbs_deb_enter(LBS_DEB_HOST); | |
1795 | ||
1796 | cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
1797 | callback, callback_arg); | |
1798 | if (IS_ERR(cmdnode)) { | |
1799 | ret = PTR_ERR(cmdnode); | |
1800 | goto done; | |
1801 | } | |
1802 | ||
675787e2 HS |
1803 | might_sleep(); |
1804 | wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken); | |
1805 | ||
aa21c004 | 1806 | spin_lock_irqsave(&priv->driver_lock, flags); |
ae125bf8 DW |
1807 | ret = cmdnode->result; |
1808 | if (ret) | |
1809 | lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n", | |
1810 | command, ret); | |
3399ea5f | 1811 | |
ad12d0f4 | 1812 | __lbs_cleanup_and_insert_cmd(priv, cmdnode); |
aa21c004 | 1813 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
675787e2 HS |
1814 | |
1815 | done: | |
1816 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); | |
1817 | return ret; | |
1818 | } | |
14e865ba | 1819 | EXPORT_SYMBOL_GPL(__lbs_cmd); |