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