]>
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 | ||
6 | #include <net/iw_handler.h> | |
7e272fcf | 7 | #include <net/lib80211.h> |
7919b89c | 8 | #include <linux/kfifo.h> |
d43c36dc | 9 | #include <linux/sched.h> |
876c9d3a MT |
10 | #include "host.h" |
11 | #include "hostcmd.h" | |
876c9d3a MT |
12 | #include "decl.h" |
13 | #include "defs.h" | |
14 | #include "dev.h" | |
697900ac | 15 | #include "assoc.h" |
876c9d3a | 16 | #include "wext.h" |
6e66f03f | 17 | #include "cmd.h" |
876c9d3a | 18 | |
2fd6cfe3 | 19 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv); |
0d61d042 | 20 | |
876c9d3a | 21 | |
8db4a2b9 HS |
22 | /** |
23 | * @brief Simple callback that copies response back into command | |
24 | * | |
25 | * @param priv A pointer to struct lbs_private structure | |
26 | * @param extra A pointer to the original command structure for which | |
27 | * 'resp' is a response | |
28 | * @param resp A pointer to the command response | |
29 | * | |
30 | * @return 0 on success, error on failure | |
31 | */ | |
32 | int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra, | |
33 | struct cmd_header *resp) | |
34 | { | |
35 | struct cmd_header *buf = (void *)extra; | |
36 | uint16_t copy_len; | |
37 | ||
38 | copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size)); | |
39 | memcpy(buf, resp, copy_len); | |
40 | return 0; | |
41 | } | |
42 | EXPORT_SYMBOL_GPL(lbs_cmd_copyback); | |
43 | ||
44 | /** | |
45 | * @brief Simple callback that ignores the result. Use this if | |
46 | * you just want to send a command to the hardware, but don't | |
47 | * care for the result. | |
48 | * | |
49 | * @param priv ignored | |
50 | * @param extra ignored | |
51 | * @param resp ignored | |
52 | * | |
53 | * @return 0 for success | |
54 | */ | |
55 | static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra, | |
56 | struct cmd_header *resp) | |
57 | { | |
58 | return 0; | |
59 | } | |
60 | ||
61 | ||
876c9d3a | 62 | /** |
852e1f2a | 63 | * @brief Checks whether a command is allowed in Power Save mode |
876c9d3a MT |
64 | * |
65 | * @param command the command ID | |
852e1f2a | 66 | * @return 1 if allowed, 0 if not allowed |
876c9d3a | 67 | */ |
852e1f2a | 68 | static u8 is_command_allowed_in_ps(u16 cmd) |
876c9d3a | 69 | { |
852e1f2a DW |
70 | switch (cmd) { |
71 | case CMD_802_11_RSSI: | |
72 | return 1; | |
73 | default: | |
74 | break; | |
876c9d3a | 75 | } |
876c9d3a MT |
76 | return 0; |
77 | } | |
78 | ||
6e66f03f DW |
79 | /** |
80 | * @brief Updates the hardware details like MAC address and regulatory region | |
81 | * | |
82 | * @param priv A pointer to struct lbs_private structure | |
83 | * | |
84 | * @return 0 on success, error on failure | |
85 | */ | |
86 | int lbs_update_hw_spec(struct lbs_private *priv) | |
876c9d3a | 87 | { |
6e66f03f DW |
88 | struct cmd_ds_get_hw_spec cmd; |
89 | int ret = -1; | |
90 | u32 i; | |
876c9d3a | 91 | |
9012b28a | 92 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 93 | |
6e66f03f DW |
94 | memset(&cmd, 0, sizeof(cmd)); |
95 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
96 | memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN); | |
689442dc | 97 | ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd); |
6e66f03f DW |
98 | if (ret) |
99 | goto out; | |
100 | ||
101 | priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo); | |
6e66f03f | 102 | |
dac10a9f HS |
103 | /* The firmware release is in an interesting format: the patch |
104 | * level is in the most significant nibble ... so fix that: */ | |
105 | priv->fwrelease = le32_to_cpu(cmd.fwrelease); | |
106 | priv->fwrelease = (priv->fwrelease << 8) | | |
107 | (priv->fwrelease >> 24 & 0xff); | |
108 | ||
109 | /* Some firmware capabilities: | |
110 | * CF card firmware 5.0.16p0: cap 0x00000303 | |
111 | * USB dongle firmware 5.110.17p2: cap 0x00000303 | |
112 | */ | |
e174961c JB |
113 | lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n", |
114 | cmd.permanentaddr, | |
dac10a9f HS |
115 | priv->fwrelease >> 24 & 0xff, |
116 | priv->fwrelease >> 16 & 0xff, | |
117 | priv->fwrelease >> 8 & 0xff, | |
118 | priv->fwrelease & 0xff, | |
119 | priv->fwcapinfo); | |
6e66f03f DW |
120 | lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n", |
121 | cmd.hwifversion, cmd.version); | |
122 | ||
684d6b36 BZ |
123 | /* Determine mesh_fw_ver from fwrelease and fwcapinfo */ |
124 | /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */ | |
125 | /* 5.110.22 have mesh command with 0xa3 command id */ | |
126 | /* 10.0.0.p0 FW brings in mesh config command with different id */ | |
127 | /* Check FW version MSB and initialize mesh_fw_ver */ | |
128 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) | |
129 | priv->mesh_fw_ver = MESH_FW_OLD; | |
130 | else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) && | |
131 | (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) | |
132 | priv->mesh_fw_ver = MESH_FW_NEW; | |
133 | else | |
134 | priv->mesh_fw_ver = MESH_NONE; | |
135 | ||
6e66f03f DW |
136 | /* Clamp region code to 8-bit since FW spec indicates that it should |
137 | * only ever be 8-bit, even though the field size is 16-bit. Some firmware | |
138 | * returns non-zero high 8 bits here. | |
15483996 MV |
139 | * |
140 | * Firmware version 4.0.102 used in CF8381 has region code shifted. We | |
141 | * need to check for this problem and handle it properly. | |
6e66f03f | 142 | */ |
15483996 MV |
143 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4) |
144 | priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF; | |
145 | else | |
146 | priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF; | |
6e66f03f DW |
147 | |
148 | for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) { | |
149 | /* use the region code to search for the index */ | |
150 | if (priv->regioncode == lbs_region_code_to_index[i]) | |
151 | break; | |
152 | } | |
153 | ||
154 | /* if it's unidentified region code, use the default (USA) */ | |
155 | if (i >= MRVDRV_MAX_REGION_CODE) { | |
156 | priv->regioncode = 0x10; | |
157 | lbs_pr_info("unidentified region code; using the default (USA)\n"); | |
158 | } | |
159 | ||
160 | if (priv->current_addr[0] == 0xff) | |
161 | memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN); | |
876c9d3a | 162 | |
6e66f03f DW |
163 | memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN); |
164 | if (priv->mesh_dev) | |
165 | memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN); | |
166 | ||
167 | if (lbs_set_regiontable(priv, priv->regioncode, 0)) { | |
168 | ret = -1; | |
169 | goto out; | |
170 | } | |
171 | ||
172 | if (lbs_set_universaltable(priv, 0)) { | |
173 | ret = -1; | |
174 | goto out; | |
175 | } | |
176 | ||
177 | out: | |
9012b28a | 178 | lbs_deb_leave(LBS_DEB_CMD); |
6e66f03f | 179 | return ret; |
876c9d3a MT |
180 | } |
181 | ||
582c1b53 AN |
182 | int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria, |
183 | struct wol_config *p_wol_config) | |
6ce4fd2a DW |
184 | { |
185 | struct cmd_ds_host_sleep cmd_config; | |
186 | int ret; | |
187 | ||
9fae899c | 188 | cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config)); |
6ce4fd2a | 189 | cmd_config.criteria = cpu_to_le32(criteria); |
506e9025 DW |
190 | cmd_config.gpio = priv->wol_gpio; |
191 | cmd_config.gap = priv->wol_gap; | |
6ce4fd2a | 192 | |
582c1b53 AN |
193 | if (p_wol_config != NULL) |
194 | memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config, | |
195 | sizeof(struct wol_config)); | |
196 | else | |
197 | cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE; | |
198 | ||
689442dc | 199 | ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config); |
506e9025 | 200 | if (!ret) { |
582c1b53 AN |
201 | if (criteria) { |
202 | lbs_deb_cmd("Set WOL criteria to %x\n", criteria); | |
203 | priv->wol_criteria = criteria; | |
204 | } else | |
205 | memcpy((uint8_t *) p_wol_config, | |
206 | (uint8_t *)&cmd_config.wol_conf, | |
207 | sizeof(struct wol_config)); | |
506e9025 | 208 | } else { |
6ce4fd2a | 209 | lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret); |
6ce4fd2a | 210 | } |
506e9025 | 211 | |
6ce4fd2a DW |
212 | return ret; |
213 | } | |
214 | EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg); | |
215 | ||
e98a88dd | 216 | static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd, |
876c9d3a MT |
217 | u16 cmd_action) |
218 | { | |
219 | struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode; | |
876c9d3a | 220 | |
9012b28a | 221 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 222 | |
0aef64d7 | 223 | cmd->command = cpu_to_le16(CMD_802_11_PS_MODE); |
981f187b DW |
224 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) + |
225 | S_DS_GEN); | |
876c9d3a MT |
226 | psm->action = cpu_to_le16(cmd_action); |
227 | psm->multipledtim = 0; | |
981f187b | 228 | switch (cmd_action) { |
0aef64d7 | 229 | case CMD_SUBCMD_ENTER_PS: |
9012b28a | 230 | lbs_deb_cmd("PS command:" "SubCode- Enter PS\n"); |
876c9d3a | 231 | |
252cf0d1 | 232 | psm->locallisteninterval = 0; |
97605c3e | 233 | psm->nullpktinterval = 0; |
876c9d3a | 234 | psm->multipledtim = |
56c4656e | 235 | cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM); |
876c9d3a MT |
236 | break; |
237 | ||
0aef64d7 | 238 | case CMD_SUBCMD_EXIT_PS: |
9012b28a | 239 | lbs_deb_cmd("PS command:" "SubCode- Exit PS\n"); |
876c9d3a MT |
240 | break; |
241 | ||
0aef64d7 | 242 | case CMD_SUBCMD_SLEEP_CONFIRMED: |
9012b28a | 243 | lbs_deb_cmd("PS command: SubCode- sleep confirm\n"); |
876c9d3a MT |
244 | break; |
245 | ||
246 | default: | |
247 | break; | |
248 | } | |
249 | ||
9012b28a | 250 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
251 | return 0; |
252 | } | |
253 | ||
6e5cc4fb DW |
254 | int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv, |
255 | uint16_t cmd_action, uint16_t *timeout) | |
876c9d3a | 256 | { |
6e5cc4fb DW |
257 | struct cmd_ds_802_11_inactivity_timeout cmd; |
258 | int ret; | |
876c9d3a | 259 | |
8ff12da1 HS |
260 | lbs_deb_enter(LBS_DEB_CMD); |
261 | ||
6e5cc4fb DW |
262 | cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT); |
263 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
876c9d3a | 264 | |
6e5cc4fb | 265 | cmd.action = cpu_to_le16(cmd_action); |
876c9d3a | 266 | |
6e5cc4fb DW |
267 | if (cmd_action == CMD_ACT_SET) |
268 | cmd.timeout = cpu_to_le16(*timeout); | |
876c9d3a | 269 | else |
6e5cc4fb | 270 | cmd.timeout = 0; |
876c9d3a | 271 | |
6e5cc4fb DW |
272 | ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd); |
273 | ||
274 | if (!ret) | |
275 | *timeout = le16_to_cpu(cmd.timeout); | |
276 | ||
277 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
876c9d3a MT |
278 | return 0; |
279 | } | |
280 | ||
3fbe104c DW |
281 | int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action, |
282 | struct sleep_params *sp) | |
876c9d3a | 283 | { |
3fbe104c DW |
284 | struct cmd_ds_802_11_sleep_params cmd; |
285 | int ret; | |
876c9d3a | 286 | |
9012b28a | 287 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 288 | |
0aef64d7 | 289 | if (cmd_action == CMD_ACT_GET) { |
3fbe104c DW |
290 | memset(&cmd, 0, sizeof(cmd)); |
291 | } else { | |
292 | cmd.error = cpu_to_le16(sp->sp_error); | |
293 | cmd.offset = cpu_to_le16(sp->sp_offset); | |
294 | cmd.stabletime = cpu_to_le16(sp->sp_stabletime); | |
295 | cmd.calcontrol = sp->sp_calcontrol; | |
296 | cmd.externalsleepclk = sp->sp_extsleepclk; | |
297 | cmd.reserved = cpu_to_le16(sp->sp_reserved); | |
876c9d3a | 298 | } |
3fbe104c DW |
299 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
300 | cmd.action = cpu_to_le16(cmd_action); | |
876c9d3a | 301 | |
3fbe104c DW |
302 | ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd); |
303 | ||
304 | if (!ret) { | |
305 | lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, " | |
306 | "calcontrol 0x%x extsleepclk 0x%x\n", | |
307 | le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset), | |
308 | le16_to_cpu(cmd.stabletime), cmd.calcontrol, | |
309 | cmd.externalsleepclk); | |
310 | ||
311 | sp->sp_error = le16_to_cpu(cmd.error); | |
312 | sp->sp_offset = le16_to_cpu(cmd.offset); | |
313 | sp->sp_stabletime = le16_to_cpu(cmd.stabletime); | |
314 | sp->sp_calcontrol = cmd.calcontrol; | |
315 | sp->sp_extsleepclk = cmd.externalsleepclk; | |
316 | sp->sp_reserved = le16_to_cpu(cmd.reserved); | |
317 | } | |
318 | ||
319 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
876c9d3a MT |
320 | return 0; |
321 | } | |
322 | ||
f70dd451 DW |
323 | int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action, |
324 | struct assoc_request *assoc) | |
876c9d3a | 325 | { |
f70dd451 | 326 | struct cmd_ds_802_11_set_wep cmd; |
876c9d3a | 327 | int ret = 0; |
876c9d3a | 328 | |
9012b28a | 329 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 330 | |
8d0c7fad | 331 | memset(&cmd, 0, sizeof(cmd)); |
f70dd451 DW |
332 | cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP); |
333 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
876c9d3a | 334 | |
f70dd451 | 335 | cmd.action = cpu_to_le16(cmd_action); |
876c9d3a | 336 | |
f70dd451 DW |
337 | if (cmd_action == CMD_ACT_ADD) { |
338 | int i; | |
876c9d3a MT |
339 | |
340 | /* default tx key index */ | |
f70dd451 DW |
341 | cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx & |
342 | CMD_WEP_KEY_INDEX_MASK); | |
876c9d3a | 343 | |
876c9d3a MT |
344 | /* Copy key types and material to host command structure */ |
345 | for (i = 0; i < 4; i++) { | |
f70dd451 | 346 | struct enc_key *pkey = &assoc->wep_keys[i]; |
876c9d3a MT |
347 | |
348 | switch (pkey->len) { | |
349 | case KEY_LEN_WEP_40: | |
f70dd451 DW |
350 | cmd.keytype[i] = CMD_TYPE_WEP_40_BIT; |
351 | memmove(cmd.keymaterial[i], pkey->key, pkey->len); | |
8ff12da1 | 352 | lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i); |
876c9d3a MT |
353 | break; |
354 | case KEY_LEN_WEP_104: | |
f70dd451 DW |
355 | cmd.keytype[i] = CMD_TYPE_WEP_104_BIT; |
356 | memmove(cmd.keymaterial[i], pkey->key, pkey->len); | |
8ff12da1 | 357 | lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i); |
876c9d3a MT |
358 | break; |
359 | case 0: | |
360 | break; | |
361 | default: | |
8ff12da1 | 362 | lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n", |
f70dd451 | 363 | i, pkey->len); |
876c9d3a MT |
364 | ret = -1; |
365 | goto done; | |
366 | break; | |
367 | } | |
368 | } | |
f70dd451 | 369 | } else if (cmd_action == CMD_ACT_REMOVE) { |
876c9d3a | 370 | /* ACT_REMOVE clears _all_ WEP keys */ |
876c9d3a MT |
371 | |
372 | /* default tx key index */ | |
f70dd451 DW |
373 | cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx & |
374 | CMD_WEP_KEY_INDEX_MASK); | |
aa21c004 | 375 | lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx); |
876c9d3a MT |
376 | } |
377 | ||
f70dd451 | 378 | ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd); |
876c9d3a | 379 | done: |
9012b28a | 380 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
381 | return ret; |
382 | } | |
383 | ||
4f59abf1 DW |
384 | int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action, |
385 | uint16_t *enable) | |
876c9d3a | 386 | { |
4f59abf1 DW |
387 | struct cmd_ds_802_11_enable_rsn cmd; |
388 | int ret; | |
90a42210 DW |
389 | |
390 | lbs_deb_enter(LBS_DEB_CMD); | |
876c9d3a | 391 | |
4f59abf1 DW |
392 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
393 | cmd.action = cpu_to_le16(cmd_action); | |
18c96c34 | 394 | |
8d0c7fad HS |
395 | if (cmd_action == CMD_ACT_GET) |
396 | cmd.enable = 0; | |
397 | else { | |
18c96c34 | 398 | if (*enable) |
4f59abf1 | 399 | cmd.enable = cpu_to_le16(CMD_ENABLE_RSN); |
18c96c34 | 400 | else |
4f59abf1 | 401 | cmd.enable = cpu_to_le16(CMD_DISABLE_RSN); |
8ff12da1 | 402 | lbs_deb_cmd("ENABLE_RSN: %d\n", *enable); |
876c9d3a MT |
403 | } |
404 | ||
4f59abf1 DW |
405 | ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd); |
406 | if (!ret && cmd_action == CMD_ACT_GET) | |
407 | *enable = le16_to_cpu(cmd.enable); | |
408 | ||
409 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
410 | return ret; | |
876c9d3a MT |
411 | } |
412 | ||
9e1228d0 DW |
413 | static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam, |
414 | struct enc_key *key) | |
876c9d3a | 415 | { |
8ff12da1 HS |
416 | lbs_deb_enter(LBS_DEB_CMD); |
417 | ||
9e1228d0 DW |
418 | if (key->flags & KEY_INFO_WPA_ENABLED) |
419 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED); | |
420 | if (key->flags & KEY_INFO_WPA_UNICAST) | |
421 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST); | |
422 | if (key->flags & KEY_INFO_WPA_MCAST) | |
423 | keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST); | |
876c9d3a | 424 | |
9e1228d0 DW |
425 | keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL); |
426 | keyparam->keytypeid = cpu_to_le16(key->type); | |
427 | keyparam->keylen = cpu_to_le16(key->len); | |
428 | memcpy(keyparam->key, key->key, key->len); | |
429 | ||
430 | /* Length field doesn't include the {type,length} header */ | |
431 | keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4); | |
8ff12da1 | 432 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
433 | } |
434 | ||
9e1228d0 DW |
435 | int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action, |
436 | struct assoc_request *assoc) | |
876c9d3a | 437 | { |
9e1228d0 | 438 | struct cmd_ds_802_11_key_material cmd; |
876c9d3a MT |
439 | int ret = 0; |
440 | int index = 0; | |
441 | ||
9012b28a | 442 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 443 | |
9e1228d0 DW |
444 | cmd.action = cpu_to_le16(cmd_action); |
445 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
876c9d3a | 446 | |
0aef64d7 | 447 | if (cmd_action == CMD_ACT_GET) { |
9e1228d0 DW |
448 | cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2); |
449 | } else { | |
450 | memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet)); | |
876c9d3a | 451 | |
9e1228d0 DW |
452 | if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) { |
453 | set_one_wpa_key(&cmd.keyParamSet[index], | |
454 | &assoc->wpa_unicast_key); | |
455 | index++; | |
456 | } | |
876c9d3a | 457 | |
9e1228d0 DW |
458 | if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) { |
459 | set_one_wpa_key(&cmd.keyParamSet[index], | |
460 | &assoc->wpa_mcast_key); | |
461 | index++; | |
462 | } | |
876c9d3a | 463 | |
9e1228d0 DW |
464 | /* The common header and as many keys as we included */ |
465 | cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd), | |
466 | keyParamSet[index])); | |
876c9d3a | 467 | } |
9e1228d0 DW |
468 | ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd); |
469 | /* Copy the returned key to driver private data */ | |
470 | if (!ret && cmd_action == CMD_ACT_GET) { | |
471 | void *buf_ptr = cmd.keyParamSet; | |
472 | void *resp_end = &(&cmd)[1]; | |
473 | ||
474 | while (buf_ptr < resp_end) { | |
475 | struct MrvlIEtype_keyParamSet *keyparam = buf_ptr; | |
476 | struct enc_key *key; | |
477 | uint16_t param_set_len = le16_to_cpu(keyparam->length); | |
478 | uint16_t key_len = le16_to_cpu(keyparam->keylen); | |
479 | uint16_t key_flags = le16_to_cpu(keyparam->keyinfo); | |
480 | uint16_t key_type = le16_to_cpu(keyparam->keytypeid); | |
481 | void *end; | |
482 | ||
483 | end = (void *)keyparam + sizeof(keyparam->type) | |
484 | + sizeof(keyparam->length) + param_set_len; | |
485 | ||
486 | /* Make sure we don't access past the end of the IEs */ | |
487 | if (end > resp_end) | |
488 | break; | |
876c9d3a | 489 | |
9e1228d0 DW |
490 | if (key_flags & KEY_INFO_WPA_UNICAST) |
491 | key = &priv->wpa_unicast_key; | |
492 | else if (key_flags & KEY_INFO_WPA_MCAST) | |
493 | key = &priv->wpa_mcast_key; | |
494 | else | |
495 | break; | |
876c9d3a | 496 | |
9e1228d0 DW |
497 | /* Copy returned key into driver */ |
498 | memset(key, 0, sizeof(struct enc_key)); | |
499 | if (key_len > sizeof(key->key)) | |
500 | break; | |
501 | key->type = key_type; | |
502 | key->flags = key_flags; | |
503 | key->len = key_len; | |
504 | memcpy(key->key, keyparam->key, key->len); | |
505 | ||
506 | buf_ptr = end + 1; | |
507 | } | |
508 | } | |
876c9d3a | 509 | |
9012b28a | 510 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
511 | return ret; |
512 | } | |
513 | ||
39fcf7a3 DW |
514 | /** |
515 | * @brief Set an SNMP MIB value | |
516 | * | |
517 | * @param priv A pointer to struct lbs_private structure | |
518 | * @param oid The OID to set in the firmware | |
519 | * @param val Value to set the OID to | |
520 | * | |
521 | * @return 0 on success, error on failure | |
522 | */ | |
523 | int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val) | |
876c9d3a | 524 | { |
39fcf7a3 DW |
525 | struct cmd_ds_802_11_snmp_mib cmd; |
526 | int ret; | |
876c9d3a | 527 | |
9012b28a | 528 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 529 | |
39fcf7a3 DW |
530 | memset(&cmd, 0, sizeof (cmd)); |
531 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
532 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
533 | cmd.oid = cpu_to_le16((u16) oid); | |
876c9d3a | 534 | |
39fcf7a3 DW |
535 | switch (oid) { |
536 | case SNMP_MIB_OID_BSS_TYPE: | |
537 | cmd.bufsize = cpu_to_le16(sizeof(u8)); | |
538 | cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1; | |
539 | break; | |
540 | case SNMP_MIB_OID_11D_ENABLE: | |
541 | case SNMP_MIB_OID_FRAG_THRESHOLD: | |
542 | case SNMP_MIB_OID_RTS_THRESHOLD: | |
543 | case SNMP_MIB_OID_SHORT_RETRY_LIMIT: | |
544 | case SNMP_MIB_OID_LONG_RETRY_LIMIT: | |
545 | cmd.bufsize = cpu_to_le16(sizeof(u16)); | |
546 | *((__le16 *)(&cmd.value)) = cpu_to_le16(val); | |
876c9d3a | 547 | break; |
39fcf7a3 DW |
548 | default: |
549 | lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid); | |
550 | ret = -EINVAL; | |
551 | goto out; | |
876c9d3a MT |
552 | } |
553 | ||
39fcf7a3 DW |
554 | lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n", |
555 | le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val); | |
876c9d3a | 556 | |
39fcf7a3 | 557 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
876c9d3a | 558 | |
39fcf7a3 DW |
559 | out: |
560 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
561 | return ret; | |
562 | } | |
876c9d3a | 563 | |
39fcf7a3 DW |
564 | /** |
565 | * @brief Get an SNMP MIB value | |
566 | * | |
567 | * @param priv A pointer to struct lbs_private structure | |
568 | * @param oid The OID to retrieve from the firmware | |
569 | * @param out_val Location for the returned value | |
570 | * | |
571 | * @return 0 on success, error on failure | |
572 | */ | |
573 | int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val) | |
574 | { | |
575 | struct cmd_ds_802_11_snmp_mib cmd; | |
576 | int ret; | |
876c9d3a | 577 | |
39fcf7a3 | 578 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 579 | |
39fcf7a3 DW |
580 | memset(&cmd, 0, sizeof (cmd)); |
581 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
582 | cmd.action = cpu_to_le16(CMD_ACT_GET); | |
583 | cmd.oid = cpu_to_le16(oid); | |
876c9d3a | 584 | |
39fcf7a3 DW |
585 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
586 | if (ret) | |
587 | goto out; | |
876c9d3a | 588 | |
39fcf7a3 DW |
589 | switch (le16_to_cpu(cmd.bufsize)) { |
590 | case sizeof(u8): | |
591 | if (oid == SNMP_MIB_OID_BSS_TYPE) { | |
592 | if (cmd.value[0] == 2) | |
593 | *out_val = IW_MODE_ADHOC; | |
594 | else | |
595 | *out_val = IW_MODE_INFRA; | |
596 | } else | |
597 | *out_val = cmd.value[0]; | |
598 | break; | |
599 | case sizeof(u16): | |
600 | *out_val = le16_to_cpu(*((__le16 *)(&cmd.value))); | |
876c9d3a MT |
601 | break; |
602 | default: | |
39fcf7a3 DW |
603 | lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n", |
604 | oid, le16_to_cpu(cmd.bufsize)); | |
876c9d3a MT |
605 | break; |
606 | } | |
607 | ||
39fcf7a3 DW |
608 | out: |
609 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
610 | return ret; | |
876c9d3a MT |
611 | } |
612 | ||
87c8c72d DW |
613 | /** |
614 | * @brief Get the min, max, and current TX power | |
615 | * | |
616 | * @param priv A pointer to struct lbs_private structure | |
617 | * @param curlevel Current power level in dBm | |
618 | * @param minlevel Minimum supported power level in dBm (optional) | |
619 | * @param maxlevel Maximum supported power level in dBm (optional) | |
620 | * | |
621 | * @return 0 on success, error on failure | |
622 | */ | |
623 | int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel, | |
624 | s16 *maxlevel) | |
876c9d3a | 625 | { |
87c8c72d DW |
626 | struct cmd_ds_802_11_rf_tx_power cmd; |
627 | int ret; | |
876c9d3a | 628 | |
9012b28a | 629 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 630 | |
87c8c72d DW |
631 | memset(&cmd, 0, sizeof(cmd)); |
632 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
633 | cmd.action = cpu_to_le16(CMD_ACT_GET); | |
634 | ||
635 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); | |
636 | if (ret == 0) { | |
637 | *curlevel = le16_to_cpu(cmd.curlevel); | |
638 | if (minlevel) | |
87bf24f3 | 639 | *minlevel = cmd.minlevel; |
87c8c72d | 640 | if (maxlevel) |
87bf24f3 | 641 | *maxlevel = cmd.maxlevel; |
87c8c72d | 642 | } |
876c9d3a | 643 | |
87c8c72d DW |
644 | lbs_deb_leave(LBS_DEB_CMD); |
645 | return ret; | |
646 | } | |
876c9d3a | 647 | |
87c8c72d DW |
648 | /** |
649 | * @brief Set the TX power | |
650 | * | |
651 | * @param priv A pointer to struct lbs_private structure | |
652 | * @param dbm The desired power level in dBm | |
653 | * | |
654 | * @return 0 on success, error on failure | |
655 | */ | |
656 | int lbs_set_tx_power(struct lbs_private *priv, s16 dbm) | |
657 | { | |
658 | struct cmd_ds_802_11_rf_tx_power cmd; | |
659 | int ret; | |
876c9d3a | 660 | |
87c8c72d | 661 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 662 | |
87c8c72d DW |
663 | memset(&cmd, 0, sizeof(cmd)); |
664 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
665 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
666 | cmd.curlevel = cpu_to_le16(dbm); | |
876c9d3a | 667 | |
87c8c72d DW |
668 | lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm); |
669 | ||
670 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); | |
9012b28a HS |
671 | |
672 | lbs_deb_leave(LBS_DEB_CMD); | |
87c8c72d | 673 | return ret; |
876c9d3a MT |
674 | } |
675 | ||
e98a88dd | 676 | static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd, |
965f8bbc LCC |
677 | u16 cmd_action, void *pdata_buf) |
678 | { | |
679 | struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor; | |
680 | ||
681 | cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE); | |
682 | cmd->size = | |
683 | cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) + | |
684 | S_DS_GEN); | |
685 | ||
686 | monitor->action = cpu_to_le16(cmd_action); | |
687 | if (cmd_action == CMD_ACT_SET) { | |
688 | monitor->mode = | |
689 | cpu_to_le16((u16) (*(u32 *) pdata_buf)); | |
690 | } | |
691 | ||
692 | return 0; | |
693 | } | |
694 | ||
85319f93 | 695 | static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok) |
876c9d3a | 696 | { |
85319f93 JC |
697 | /* Bit Rate |
698 | * 15:13 Reserved | |
699 | * 12 54 Mbps | |
700 | * 11 48 Mbps | |
701 | * 10 36 Mbps | |
702 | * 9 24 Mbps | |
703 | * 8 18 Mbps | |
704 | * 7 12 Mbps | |
705 | * 6 9 Mbps | |
706 | * 5 6 Mbps | |
707 | * 4 Reserved | |
708 | * 3 11 Mbps | |
709 | * 2 5.5 Mbps | |
710 | * 1 2 Mbps | |
711 | * 0 1 Mbps | |
712 | **/ | |
713 | ||
714 | uint16_t ratemask; | |
715 | int i = lbs_data_rate_to_fw_index(rate); | |
716 | if (lower_rates_ok) | |
717 | ratemask = (0x1fef >> (12 - i)); | |
718 | else | |
719 | ratemask = (1 << i); | |
720 | return cpu_to_le16(ratemask); | |
721 | } | |
722 | ||
723 | int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv, | |
724 | uint16_t cmd_action) | |
725 | { | |
726 | struct cmd_ds_802_11_rate_adapt_rateset cmd; | |
727 | int ret; | |
876c9d3a | 728 | |
8ff12da1 | 729 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 730 | |
85319f93 JC |
731 | if (!priv->cur_rate && !priv->enablehwauto) |
732 | return -EINVAL; | |
876c9d3a | 733 | |
85319f93 JC |
734 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
735 | ||
736 | cmd.action = cpu_to_le16(cmd_action); | |
737 | cmd.enablehwauto = cpu_to_le16(priv->enablehwauto); | |
738 | cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto); | |
739 | ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd); | |
740 | if (!ret && cmd_action == CMD_ACT_GET) { | |
741 | priv->ratebitmap = le16_to_cpu(cmd.bitmap); | |
742 | priv->enablehwauto = le16_to_cpu(cmd.enablehwauto); | |
743 | } | |
744 | ||
745 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
746 | return ret; | |
876c9d3a | 747 | } |
85319f93 | 748 | EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset); |
876c9d3a | 749 | |
8e3c91bb DW |
750 | /** |
751 | * @brief Set the data rate | |
752 | * | |
753 | * @param priv A pointer to struct lbs_private structure | |
754 | * @param rate The desired data rate, or 0 to clear a locked rate | |
755 | * | |
756 | * @return 0 on success, error on failure | |
757 | */ | |
758 | int lbs_set_data_rate(struct lbs_private *priv, u8 rate) | |
759 | { | |
760 | struct cmd_ds_802_11_data_rate cmd; | |
761 | int ret = 0; | |
762 | ||
763 | lbs_deb_enter(LBS_DEB_CMD); | |
764 | ||
765 | memset(&cmd, 0, sizeof(cmd)); | |
766 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
767 | ||
768 | if (rate > 0) { | |
769 | cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE); | |
770 | cmd.rates[0] = lbs_data_rate_to_fw_index(rate); | |
771 | if (cmd.rates[0] == 0) { | |
772 | lbs_deb_cmd("DATA_RATE: invalid requested rate of" | |
773 | " 0x%02X\n", rate); | |
774 | ret = 0; | |
775 | goto out; | |
776 | } | |
777 | lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]); | |
778 | } else { | |
779 | cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO); | |
8ff12da1 | 780 | lbs_deb_cmd("DATA_RATE: setting auto\n"); |
876c9d3a MT |
781 | } |
782 | ||
689442dc | 783 | ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd); |
8e3c91bb DW |
784 | if (ret) |
785 | goto out; | |
786 | ||
787 | lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd)); | |
788 | ||
789 | /* FIXME: get actual rates FW can do if this command actually returns | |
790 | * all data rates supported. | |
791 | */ | |
792 | priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]); | |
793 | lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate); | |
794 | ||
795 | out: | |
796 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
797 | return ret; | |
876c9d3a MT |
798 | } |
799 | ||
2dd4b262 DW |
800 | /** |
801 | * @brief Get the radio channel | |
802 | * | |
803 | * @param priv A pointer to struct lbs_private structure | |
804 | * | |
805 | * @return The channel on success, error on failure | |
806 | */ | |
807 | int lbs_get_channel(struct lbs_private *priv) | |
876c9d3a | 808 | { |
2dd4b262 DW |
809 | struct cmd_ds_802_11_rf_channel cmd; |
810 | int ret = 0; | |
876c9d3a | 811 | |
8ff12da1 | 812 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 813 | |
8d0c7fad | 814 | memset(&cmd, 0, sizeof(cmd)); |
2dd4b262 DW |
815 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
816 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET); | |
876c9d3a | 817 | |
689442dc | 818 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
2dd4b262 DW |
819 | if (ret) |
820 | goto out; | |
876c9d3a | 821 | |
cb182a60 DW |
822 | ret = le16_to_cpu(cmd.channel); |
823 | lbs_deb_cmd("current radio channel is %d\n", ret); | |
2dd4b262 DW |
824 | |
825 | out: | |
826 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
827 | return ret; | |
828 | } | |
829 | ||
73ab1f25 HS |
830 | int lbs_update_channel(struct lbs_private *priv) |
831 | { | |
832 | int ret; | |
833 | ||
834 | /* the channel in f/w could be out of sync; get the current channel */ | |
835 | lbs_deb_enter(LBS_DEB_ASSOC); | |
836 | ||
837 | ret = lbs_get_channel(priv); | |
838 | if (ret > 0) { | |
839 | priv->curbssparams.channel = ret; | |
840 | ret = 0; | |
841 | } | |
842 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); | |
843 | return ret; | |
844 | } | |
845 | ||
2dd4b262 DW |
846 | /** |
847 | * @brief Set the radio channel | |
848 | * | |
849 | * @param priv A pointer to struct lbs_private structure | |
850 | * @param channel The desired channel, or 0 to clear a locked channel | |
851 | * | |
852 | * @return 0 on success, error on failure | |
853 | */ | |
854 | int lbs_set_channel(struct lbs_private *priv, u8 channel) | |
855 | { | |
856 | struct cmd_ds_802_11_rf_channel cmd; | |
96d46d5d | 857 | #ifdef DEBUG |
2dd4b262 | 858 | u8 old_channel = priv->curbssparams.channel; |
96d46d5d | 859 | #endif |
2dd4b262 DW |
860 | int ret = 0; |
861 | ||
862 | lbs_deb_enter(LBS_DEB_CMD); | |
863 | ||
8d0c7fad | 864 | memset(&cmd, 0, sizeof(cmd)); |
2dd4b262 DW |
865 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
866 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET); | |
867 | cmd.channel = cpu_to_le16(channel); | |
868 | ||
689442dc | 869 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
2dd4b262 DW |
870 | if (ret) |
871 | goto out; | |
872 | ||
cb182a60 DW |
873 | priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel); |
874 | lbs_deb_cmd("channel switch from %d to %d\n", old_channel, | |
875 | priv->curbssparams.channel); | |
2dd4b262 DW |
876 | |
877 | out: | |
878 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); | |
879 | return ret; | |
876c9d3a MT |
880 | } |
881 | ||
69f9032d | 882 | static int lbs_cmd_802_11_rssi(struct lbs_private *priv, |
876c9d3a MT |
883 | struct cmd_ds_command *cmd) |
884 | { | |
876c9d3a | 885 | |
8ff12da1 | 886 | lbs_deb_enter(LBS_DEB_CMD); |
0aef64d7 | 887 | cmd->command = cpu_to_le16(CMD_802_11_RSSI); |
981f187b | 888 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN); |
a783f1ee | 889 | cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR); |
876c9d3a MT |
890 | |
891 | /* reset Beacon SNR/NF/RSSI values */ | |
aa21c004 DW |
892 | priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0; |
893 | priv->SNR[TYPE_BEACON][TYPE_AVG] = 0; | |
894 | priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0; | |
895 | priv->NF[TYPE_BEACON][TYPE_AVG] = 0; | |
896 | priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0; | |
897 | priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0; | |
876c9d3a | 898 | |
8ff12da1 | 899 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
900 | return 0; |
901 | } | |
902 | ||
e98a88dd | 903 | static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr, |
876c9d3a MT |
904 | u8 cmd_action, void *pdata_buf) |
905 | { | |
10078321 | 906 | struct lbs_offset_value *offval; |
876c9d3a | 907 | |
9012b28a | 908 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 909 | |
10078321 | 910 | offval = (struct lbs_offset_value *)pdata_buf; |
876c9d3a | 911 | |
c2df2efe | 912 | switch (le16_to_cpu(cmdptr->command)) { |
0aef64d7 | 913 | case CMD_MAC_REG_ACCESS: |
876c9d3a MT |
914 | { |
915 | struct cmd_ds_mac_reg_access *macreg; | |
916 | ||
917 | cmdptr->size = | |
981f187b DW |
918 | cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access) |
919 | + S_DS_GEN); | |
876c9d3a MT |
920 | macreg = |
921 | (struct cmd_ds_mac_reg_access *)&cmdptr->params. | |
922 | macreg; | |
923 | ||
924 | macreg->action = cpu_to_le16(cmd_action); | |
925 | macreg->offset = cpu_to_le16((u16) offval->offset); | |
926 | macreg->value = cpu_to_le32(offval->value); | |
927 | ||
928 | break; | |
929 | } | |
930 | ||
0aef64d7 | 931 | case CMD_BBP_REG_ACCESS: |
876c9d3a MT |
932 | { |
933 | struct cmd_ds_bbp_reg_access *bbpreg; | |
934 | ||
935 | cmdptr->size = | |
936 | cpu_to_le16(sizeof | |
937 | (struct cmd_ds_bbp_reg_access) | |
938 | + S_DS_GEN); | |
939 | bbpreg = | |
940 | (struct cmd_ds_bbp_reg_access *)&cmdptr->params. | |
941 | bbpreg; | |
942 | ||
943 | bbpreg->action = cpu_to_le16(cmd_action); | |
944 | bbpreg->offset = cpu_to_le16((u16) offval->offset); | |
945 | bbpreg->value = (u8) offval->value; | |
946 | ||
947 | break; | |
948 | } | |
949 | ||
0aef64d7 | 950 | case CMD_RF_REG_ACCESS: |
876c9d3a MT |
951 | { |
952 | struct cmd_ds_rf_reg_access *rfreg; | |
953 | ||
954 | cmdptr->size = | |
955 | cpu_to_le16(sizeof | |
956 | (struct cmd_ds_rf_reg_access) + | |
957 | S_DS_GEN); | |
958 | rfreg = | |
959 | (struct cmd_ds_rf_reg_access *)&cmdptr->params. | |
960 | rfreg; | |
961 | ||
962 | rfreg->action = cpu_to_le16(cmd_action); | |
963 | rfreg->offset = cpu_to_le16((u16) offval->offset); | |
964 | rfreg->value = (u8) offval->value; | |
965 | ||
966 | break; | |
967 | } | |
968 | ||
969 | default: | |
970 | break; | |
971 | } | |
972 | ||
9012b28a | 973 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
974 | return 0; |
975 | } | |
976 | ||
e98a88dd | 977 | static int lbs_cmd_bt_access(struct cmd_ds_command *cmd, |
876c9d3a MT |
978 | u16 cmd_action, void *pdata_buf) |
979 | { | |
980 | struct cmd_ds_bt_access *bt_access = &cmd->params.bt; | |
8ff12da1 | 981 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 982 | |
0aef64d7 | 983 | cmd->command = cpu_to_le16(CMD_BT_ACCESS); |
981f187b | 984 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN); |
876c9d3a MT |
985 | cmd->result = 0; |
986 | bt_access->action = cpu_to_le16(cmd_action); | |
987 | ||
988 | switch (cmd_action) { | |
0aef64d7 | 989 | case CMD_ACT_BT_ACCESS_ADD: |
876c9d3a | 990 | memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN); |
ece56191 | 991 | lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6); |
876c9d3a | 992 | break; |
0aef64d7 | 993 | case CMD_ACT_BT_ACCESS_DEL: |
876c9d3a | 994 | memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN); |
ece56191 | 995 | lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6); |
876c9d3a | 996 | break; |
0aef64d7 | 997 | case CMD_ACT_BT_ACCESS_LIST: |
876c9d3a MT |
998 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
999 | break; | |
0aef64d7 | 1000 | case CMD_ACT_BT_ACCESS_RESET: |
876c9d3a | 1001 | break; |
0aef64d7 | 1002 | case CMD_ACT_BT_ACCESS_SET_INVERT: |
90e8eafc LCC |
1003 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
1004 | break; | |
0aef64d7 | 1005 | case CMD_ACT_BT_ACCESS_GET_INVERT: |
90e8eafc | 1006 | break; |
876c9d3a MT |
1007 | default: |
1008 | break; | |
1009 | } | |
8ff12da1 | 1010 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1011 | return 0; |
1012 | } | |
1013 | ||
e98a88dd | 1014 | static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd, |
876c9d3a MT |
1015 | u16 cmd_action, void *pdata_buf) |
1016 | { | |
1017 | struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt; | |
8ff12da1 | 1018 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 1019 | |
0aef64d7 | 1020 | cmd->command = cpu_to_le16(CMD_FWT_ACCESS); |
981f187b | 1021 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN); |
876c9d3a MT |
1022 | cmd->result = 0; |
1023 | ||
1024 | if (pdata_buf) | |
1025 | memcpy(fwt_access, pdata_buf, sizeof(*fwt_access)); | |
1026 | else | |
1027 | memset(fwt_access, 0, sizeof(*fwt_access)); | |
1028 | ||
1029 | fwt_access->action = cpu_to_le16(cmd_action); | |
1030 | ||
8ff12da1 | 1031 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1032 | return 0; |
1033 | } | |
1034 | ||
301eacbf DW |
1035 | int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action, |
1036 | struct cmd_ds_mesh_access *cmd) | |
876c9d3a | 1037 | { |
301eacbf DW |
1038 | int ret; |
1039 | ||
8ff12da1 | 1040 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
876c9d3a | 1041 | |
301eacbf | 1042 | cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS); |
9fae899c | 1043 | cmd->hdr.size = cpu_to_le16(sizeof(*cmd)); |
301eacbf | 1044 | cmd->hdr.result = 0; |
876c9d3a | 1045 | |
301eacbf | 1046 | cmd->action = cpu_to_le16(cmd_action); |
876c9d3a | 1047 | |
689442dc | 1048 | ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd); |
876c9d3a | 1049 | |
8ff12da1 | 1050 | lbs_deb_leave(LBS_DEB_CMD); |
301eacbf | 1051 | return ret; |
876c9d3a MT |
1052 | } |
1053 | ||
1556c0f2 BC |
1054 | static int __lbs_mesh_config_send(struct lbs_private *priv, |
1055 | struct cmd_ds_mesh_config *cmd, | |
1056 | uint16_t action, uint16_t type) | |
edaea5ce JC |
1057 | { |
1058 | int ret; | |
684d6b36 | 1059 | u16 command = CMD_MESH_CONFIG_OLD; |
edaea5ce JC |
1060 | |
1061 | lbs_deb_enter(LBS_DEB_CMD); | |
1062 | ||
684d6b36 BZ |
1063 | /* |
1064 | * Command id is 0xac for v10 FW along with mesh interface | |
1065 | * id in bits 14-13-12. | |
1066 | */ | |
1067 | if (priv->mesh_fw_ver == MESH_FW_NEW) | |
1068 | command = CMD_MESH_CONFIG | | |
1069 | (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET); | |
1070 | ||
1071 | cmd->hdr.command = cpu_to_le16(command); | |
edaea5ce JC |
1072 | cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config)); |
1073 | cmd->hdr.result = 0; | |
1074 | ||
1075 | cmd->type = cpu_to_le16(type); | |
1076 | cmd->action = cpu_to_le16(action); | |
1077 | ||
684d6b36 | 1078 | ret = lbs_cmd_with_response(priv, command, cmd); |
edaea5ce JC |
1079 | |
1080 | lbs_deb_leave(LBS_DEB_CMD); | |
1081 | return ret; | |
1082 | } | |
1083 | ||
1556c0f2 BC |
1084 | int lbs_mesh_config_send(struct lbs_private *priv, |
1085 | struct cmd_ds_mesh_config *cmd, | |
1086 | uint16_t action, uint16_t type) | |
1087 | { | |
1088 | int ret; | |
1089 | ||
1090 | if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG)) | |
1091 | return -EOPNOTSUPP; | |
1092 | ||
1093 | ret = __lbs_mesh_config_send(priv, cmd, action, type); | |
1094 | return ret; | |
1095 | } | |
1096 | ||
edaea5ce JC |
1097 | /* This function is the CMD_MESH_CONFIG legacy function. It only handles the |
1098 | * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG | |
1099 | * are all handled by preparing a struct cmd_ds_mesh_config and passing it to | |
1100 | * lbs_mesh_config_send. | |
1101 | */ | |
1102 | int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan) | |
23a397ac DW |
1103 | { |
1104 | struct cmd_ds_mesh_config cmd; | |
edaea5ce | 1105 | struct mrvl_meshie *ie; |
9387b7ca | 1106 | DECLARE_SSID_BUF(ssid); |
23a397ac DW |
1107 | |
1108 | memset(&cmd, 0, sizeof(cmd)); | |
86062134 | 1109 | cmd.channel = cpu_to_le16(chan); |
edaea5ce JC |
1110 | ie = (struct mrvl_meshie *)cmd.data; |
1111 | ||
1112 | switch (action) { | |
1113 | case CMD_ACT_MESH_CONFIG_START: | |
2c706002 | 1114 | ie->id = WLAN_EID_GENERIC; |
edaea5ce JC |
1115 | ie->val.oui[0] = 0x00; |
1116 | ie->val.oui[1] = 0x50; | |
1117 | ie->val.oui[2] = 0x43; | |
1118 | ie->val.type = MARVELL_MESH_IE_TYPE; | |
1119 | ie->val.subtype = MARVELL_MESH_IE_SUBTYPE; | |
1120 | ie->val.version = MARVELL_MESH_IE_VERSION; | |
1121 | ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP; | |
1122 | ie->val.active_metric_id = MARVELL_MESH_METRIC_ID; | |
1123 | ie->val.mesh_capability = MARVELL_MESH_CAPABILITY; | |
1124 | ie->val.mesh_id_len = priv->mesh_ssid_len; | |
1125 | memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len); | |
2c706002 | 1126 | ie->len = sizeof(struct mrvl_meshie_val) - |
edaea5ce JC |
1127 | IW_ESSID_MAX_SIZE + priv->mesh_ssid_len; |
1128 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val)); | |
1129 | break; | |
1130 | case CMD_ACT_MESH_CONFIG_STOP: | |
1131 | break; | |
1132 | default: | |
1133 | return -1; | |
23a397ac | 1134 | } |
edaea5ce JC |
1135 | lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n", |
1136 | action, priv->mesh_tlv, chan, | |
9387b7ca | 1137 | print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len)); |
edaea5ce | 1138 | |
1556c0f2 | 1139 | return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv); |
23a397ac DW |
1140 | } |
1141 | ||
96287ac4 BD |
1142 | static int lbs_cmd_bcn_ctrl(struct lbs_private * priv, |
1143 | struct cmd_ds_command *cmd, | |
1144 | u16 cmd_action) | |
1145 | { | |
1146 | struct cmd_ds_802_11_beacon_control | |
1147 | *bcn_ctrl = &cmd->params.bcn_ctrl; | |
96287ac4 BD |
1148 | |
1149 | lbs_deb_enter(LBS_DEB_CMD); | |
1150 | cmd->size = | |
1151 | cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control) | |
1152 | + S_DS_GEN); | |
1153 | cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL); | |
1154 | ||
1155 | bcn_ctrl->action = cpu_to_le16(cmd_action); | |
aa21c004 DW |
1156 | bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable); |
1157 | bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period); | |
96287ac4 BD |
1158 | |
1159 | lbs_deb_leave(LBS_DEB_CMD); | |
1160 | return 0; | |
1161 | } | |
1162 | ||
681ffbb7 DW |
1163 | static void lbs_queue_cmd(struct lbs_private *priv, |
1164 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
1165 | { |
1166 | unsigned long flags; | |
681ffbb7 | 1167 | int addtail = 1; |
876c9d3a | 1168 | |
8ff12da1 | 1169 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1170 | |
c4ab4127 DW |
1171 | if (!cmdnode) { |
1172 | lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n"); | |
876c9d3a MT |
1173 | goto done; |
1174 | } | |
d9896ee1 DW |
1175 | if (!cmdnode->cmdbuf->size) { |
1176 | lbs_deb_host("DNLD_CMD: cmd size is zero\n"); | |
1177 | goto done; | |
1178 | } | |
ae125bf8 | 1179 | cmdnode->result = 0; |
876c9d3a MT |
1180 | |
1181 | /* Exit_PS command needs to be queued in the header always. */ | |
ddac4526 | 1182 | if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) { |
38bfab1a | 1183 | struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1]; |
ddac4526 | 1184 | |
0aef64d7 | 1185 | if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
aa21c004 | 1186 | if (priv->psstate != PS_STATE_FULL_POWER) |
876c9d3a MT |
1187 | addtail = 0; |
1188 | } | |
1189 | } | |
1190 | ||
aa21c004 | 1191 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1192 | |
ac47246e | 1193 | if (addtail) |
aa21c004 | 1194 | list_add_tail(&cmdnode->list, &priv->cmdpendingq); |
ac47246e | 1195 | else |
aa21c004 | 1196 | list_add(&cmdnode->list, &priv->cmdpendingq); |
876c9d3a | 1197 | |
aa21c004 | 1198 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 1199 | |
8ff12da1 | 1200 | lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n", |
c4ab4127 | 1201 | le16_to_cpu(cmdnode->cmdbuf->command)); |
876c9d3a MT |
1202 | |
1203 | done: | |
8ff12da1 | 1204 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1205 | } |
1206 | ||
18c52e7c DW |
1207 | static void lbs_submit_command(struct lbs_private *priv, |
1208 | struct cmd_ctrl_node *cmdnode) | |
876c9d3a MT |
1209 | { |
1210 | unsigned long flags; | |
ddac4526 | 1211 | struct cmd_header *cmd; |
18c52e7c DW |
1212 | uint16_t cmdsize; |
1213 | uint16_t command; | |
57962f0b | 1214 | int timeo = 3 * HZ; |
18c52e7c | 1215 | int ret; |
876c9d3a | 1216 | |
8ff12da1 | 1217 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1218 | |
ddac4526 | 1219 | cmd = cmdnode->cmdbuf; |
876c9d3a | 1220 | |
aa21c004 | 1221 | spin_lock_irqsave(&priv->driver_lock, flags); |
aa21c004 DW |
1222 | priv->cur_cmd = cmdnode; |
1223 | priv->cur_cmd_retcode = 0; | |
1224 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a | 1225 | |
ddac4526 DW |
1226 | cmdsize = le16_to_cpu(cmd->size); |
1227 | command = le16_to_cpu(cmd->command); | |
876c9d3a | 1228 | |
18c52e7c | 1229 | /* These commands take longer */ |
be0d76e4 | 1230 | if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE) |
57962f0b | 1231 | timeo = 5 * HZ; |
18c52e7c | 1232 | |
e5225b39 HS |
1233 | lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n", |
1234 | command, le16_to_cpu(cmd->seqnum), cmdsize); | |
1afc09ab | 1235 | lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize); |
8ff12da1 | 1236 | |
ddac4526 | 1237 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize); |
18c52e7c | 1238 | |
d9896ee1 DW |
1239 | if (ret) { |
1240 | lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret); | |
18c52e7c DW |
1241 | /* Let the timer kick in and retry, and potentially reset |
1242 | the whole thing if the condition persists */ | |
57962f0b | 1243 | timeo = HZ/4; |
1afc09ab | 1244 | } |
876c9d3a MT |
1245 | |
1246 | /* Setup the timer after transmit command */ | |
18c52e7c | 1247 | mod_timer(&priv->command_timer, jiffies + timeo); |
876c9d3a | 1248 | |
18c52e7c | 1249 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1250 | } |
1251 | ||
876c9d3a MT |
1252 | /** |
1253 | * This function inserts command node to cmdfreeq | |
aa21c004 | 1254 | * after cleans it. Requires priv->driver_lock held. |
876c9d3a | 1255 | */ |
183aeac1 | 1256 | static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
5ba2f8a0 | 1257 | struct cmd_ctrl_node *cmdnode) |
876c9d3a | 1258 | { |
5ba2f8a0 DW |
1259 | lbs_deb_enter(LBS_DEB_HOST); |
1260 | ||
1261 | if (!cmdnode) | |
1262 | goto out; | |
1263 | ||
5ba2f8a0 DW |
1264 | cmdnode->callback = NULL; |
1265 | cmdnode->callback_arg = 0; | |
876c9d3a | 1266 | |
5ba2f8a0 | 1267 | memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE); |
876c9d3a | 1268 | |
5ba2f8a0 DW |
1269 | list_add_tail(&cmdnode->list, &priv->cmdfreeq); |
1270 | out: | |
1271 | lbs_deb_leave(LBS_DEB_HOST); | |
876c9d3a MT |
1272 | } |
1273 | ||
69f9032d HS |
1274 | static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
1275 | struct cmd_ctrl_node *ptempcmd) | |
876c9d3a MT |
1276 | { |
1277 | unsigned long flags; | |
1278 | ||
aa21c004 | 1279 | spin_lock_irqsave(&priv->driver_lock, flags); |
10078321 | 1280 | __lbs_cleanup_and_insert_cmd(priv, ptempcmd); |
aa21c004 | 1281 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1282 | } |
1283 | ||
183aeac1 DW |
1284 | void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd, |
1285 | int result) | |
1286 | { | |
1287 | if (cmd == priv->cur_cmd) | |
1288 | priv->cur_cmd_retcode = result; | |
5ba2f8a0 | 1289 | |
ae125bf8 | 1290 | cmd->result = result; |
5ba2f8a0 DW |
1291 | cmd->cmdwaitqwoken = 1; |
1292 | wake_up_interruptible(&cmd->cmdwait_q); | |
1293 | ||
8db4a2b9 | 1294 | if (!cmd->callback || cmd->callback == lbs_cmd_async_callback) |
ad12d0f4 | 1295 | __lbs_cleanup_and_insert_cmd(priv, cmd); |
183aeac1 DW |
1296 | priv->cur_cmd = NULL; |
1297 | } | |
1298 | ||
d5db2dfa | 1299 | int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on) |
876c9d3a | 1300 | { |
a7c45890 | 1301 | struct cmd_ds_802_11_radio_control cmd; |
d5db2dfa | 1302 | int ret = -EINVAL; |
876c9d3a | 1303 | |
9012b28a | 1304 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1305 | |
a7c45890 DW |
1306 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
1307 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1308 | ||
d5db2dfa DW |
1309 | /* Only v8 and below support setting the preamble */ |
1310 | if (priv->fwrelease < 0x09000000) { | |
1311 | switch (preamble) { | |
1312 | case RADIO_PREAMBLE_SHORT: | |
1313 | if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) | |
1314 | goto out; | |
1315 | /* Fall through */ | |
1316 | case RADIO_PREAMBLE_AUTO: | |
1317 | case RADIO_PREAMBLE_LONG: | |
1318 | cmd.control = cpu_to_le16(preamble); | |
1319 | break; | |
1320 | default: | |
1321 | goto out; | |
1322 | } | |
1323 | } | |
a7c45890 | 1324 | |
d5db2dfa DW |
1325 | if (radio_on) |
1326 | cmd.control |= cpu_to_le16(0x1); | |
1327 | else { | |
1328 | cmd.control &= cpu_to_le16(~0x1); | |
1329 | priv->txpower_cur = 0; | |
a7c45890 | 1330 | } |
876c9d3a | 1331 | |
d5db2dfa DW |
1332 | lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n", |
1333 | radio_on ? "ON" : "OFF", preamble); | |
a7c45890 | 1334 | |
d5db2dfa | 1335 | priv->radio_on = radio_on; |
a7c45890 DW |
1336 | |
1337 | ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd); | |
876c9d3a | 1338 | |
d5db2dfa | 1339 | out: |
9012b28a | 1340 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
876c9d3a MT |
1341 | return ret; |
1342 | } | |
1343 | ||
c97329e2 | 1344 | void lbs_set_mac_control(struct lbs_private *priv) |
876c9d3a | 1345 | { |
835d3ac5 | 1346 | struct cmd_ds_mac_control cmd; |
876c9d3a | 1347 | |
9012b28a | 1348 | lbs_deb_enter(LBS_DEB_CMD); |
876c9d3a | 1349 | |
835d3ac5 | 1350 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
d9e9778c | 1351 | cmd.action = cpu_to_le16(priv->mac_control); |
835d3ac5 HS |
1352 | cmd.reserved = 0; |
1353 | ||
75bf45a7 | 1354 | lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd)); |
876c9d3a | 1355 | |
c97329e2 | 1356 | lbs_deb_leave(LBS_DEB_CMD); |
876c9d3a MT |
1357 | } |
1358 | ||
1359 | /** | |
1360 | * @brief This function prepare the command before send to firmware. | |
1361 | * | |
69f9032d | 1362 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1363 | * @param cmd_no command number |
1364 | * @param cmd_action command action: GET or SET | |
1365 | * @param wait_option wait option: wait response or not | |
1366 | * @param cmd_oid cmd oid: treated as sub command | |
1367 | * @param pdata_buf A pointer to informaion buffer | |
1368 | * @return 0 or -1 | |
1369 | */ | |
69f9032d | 1370 | int lbs_prepare_and_send_command(struct lbs_private *priv, |
876c9d3a MT |
1371 | u16 cmd_no, |
1372 | u16 cmd_action, | |
1373 | u16 wait_option, u32 cmd_oid, void *pdata_buf) | |
1374 | { | |
1375 | int ret = 0; | |
876c9d3a MT |
1376 | struct cmd_ctrl_node *cmdnode; |
1377 | struct cmd_ds_command *cmdptr; | |
1378 | unsigned long flags; | |
1379 | ||
8ff12da1 | 1380 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1381 | |
aa21c004 DW |
1382 | if (!priv) { |
1383 | lbs_deb_host("PREP_CMD: priv is NULL\n"); | |
876c9d3a MT |
1384 | ret = -1; |
1385 | goto done; | |
1386 | } | |
1387 | ||
aa21c004 | 1388 | if (priv->surpriseremoved) { |
8ff12da1 | 1389 | lbs_deb_host("PREP_CMD: card removed\n"); |
876c9d3a MT |
1390 | ret = -1; |
1391 | goto done; | |
1392 | } | |
1393 | ||
0d61d042 | 1394 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
876c9d3a MT |
1395 | |
1396 | if (cmdnode == NULL) { | |
8ff12da1 | 1397 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
876c9d3a MT |
1398 | |
1399 | /* Wake up main thread to execute next command */ | |
fe336150 | 1400 | wake_up_interruptible(&priv->waitq); |
876c9d3a MT |
1401 | ret = -1; |
1402 | goto done; | |
1403 | } | |
1404 | ||
e98a88dd HS |
1405 | cmdnode->callback = NULL; |
1406 | cmdnode->callback_arg = (unsigned long)pdata_buf; | |
876c9d3a | 1407 | |
ddac4526 | 1408 | cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf; |
876c9d3a | 1409 | |
8ff12da1 | 1410 | lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no); |
876c9d3a | 1411 | |
876c9d3a | 1412 | /* Set sequence number, command and INT option */ |
aa21c004 DW |
1413 | priv->seqnum++; |
1414 | cmdptr->seqnum = cpu_to_le16(priv->seqnum); | |
876c9d3a | 1415 | |
981f187b | 1416 | cmdptr->command = cpu_to_le16(cmd_no); |
876c9d3a MT |
1417 | cmdptr->result = 0; |
1418 | ||
1419 | switch (cmd_no) { | |
0aef64d7 | 1420 | case CMD_802_11_PS_MODE: |
e98a88dd | 1421 | ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action); |
876c9d3a MT |
1422 | break; |
1423 | ||
0aef64d7 DW |
1424 | case CMD_MAC_REG_ACCESS: |
1425 | case CMD_BBP_REG_ACCESS: | |
1426 | case CMD_RF_REG_ACCESS: | |
e98a88dd | 1427 | ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1428 | break; |
1429 | ||
965f8bbc | 1430 | case CMD_802_11_MONITOR_MODE: |
e98a88dd | 1431 | ret = lbs_cmd_802_11_monitor_mode(cmdptr, |
965f8bbc LCC |
1432 | cmd_action, pdata_buf); |
1433 | break; | |
1434 | ||
0aef64d7 | 1435 | case CMD_802_11_RSSI: |
10078321 | 1436 | ret = lbs_cmd_802_11_rssi(priv, cmdptr); |
876c9d3a MT |
1437 | break; |
1438 | ||
0aef64d7 DW |
1439 | case CMD_802_11_SET_AFC: |
1440 | case CMD_802_11_GET_AFC: | |
876c9d3a MT |
1441 | |
1442 | cmdptr->command = cpu_to_le16(cmd_no); | |
981f187b DW |
1443 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) + |
1444 | S_DS_GEN); | |
876c9d3a MT |
1445 | |
1446 | memmove(&cmdptr->params.afc, | |
1447 | pdata_buf, sizeof(struct cmd_ds_802_11_afc)); | |
1448 | ||
1449 | ret = 0; | |
1450 | goto done; | |
1451 | ||
0aef64d7 | 1452 | case CMD_802_11D_DOMAIN_INFO: |
10078321 | 1453 | ret = lbs_cmd_802_11d_domain_info(priv, cmdptr, |
876c9d3a MT |
1454 | cmd_no, cmd_action); |
1455 | break; | |
1456 | ||
0aef64d7 DW |
1457 | case CMD_802_11_TPC_CFG: |
1458 | cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG); | |
876c9d3a MT |
1459 | cmdptr->size = |
1460 | cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) + | |
1461 | S_DS_GEN); | |
1462 | ||
1463 | memmove(&cmdptr->params.tpccfg, | |
1464 | pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg)); | |
1465 | ||
1466 | ret = 0; | |
1467 | break; | |
0aef64d7 | 1468 | case CMD_802_11_LED_GPIO_CTRL: |
876c9d3a | 1469 | { |
75b6a61a DW |
1470 | struct mrvl_ie_ledgpio *gpio = |
1471 | (struct mrvl_ie_ledgpio*) | |
876c9d3a MT |
1472 | cmdptr->params.ledgpio.data; |
1473 | ||
1474 | memmove(&cmdptr->params.ledgpio, | |
1475 | pdata_buf, | |
1476 | sizeof(struct cmd_ds_802_11_led_ctrl)); | |
1477 | ||
1478 | cmdptr->command = | |
0aef64d7 | 1479 | cpu_to_le16(CMD_802_11_LED_GPIO_CTRL); |
876c9d3a MT |
1480 | |
1481 | #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8 | |
1482 | cmdptr->size = | |
c2df2efe HS |
1483 | cpu_to_le16(le16_to_cpu(gpio->header.len) |
1484 | + S_DS_GEN | |
1485 | + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN); | |
1486 | gpio->header.len = gpio->header.len; | |
876c9d3a MT |
1487 | |
1488 | ret = 0; | |
1489 | break; | |
1490 | } | |
5844d12e | 1491 | |
0aef64d7 | 1492 | case CMD_BT_ACCESS: |
e98a88dd | 1493 | ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1494 | break; |
1495 | ||
0aef64d7 | 1496 | case CMD_FWT_ACCESS: |
e98a88dd | 1497 | ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf); |
876c9d3a MT |
1498 | break; |
1499 | ||
0aef64d7 DW |
1500 | case CMD_GET_TSF: |
1501 | cmdptr->command = cpu_to_le16(CMD_GET_TSF); | |
981f187b DW |
1502 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) + |
1503 | S_DS_GEN); | |
876c9d3a MT |
1504 | ret = 0; |
1505 | break; | |
96287ac4 BD |
1506 | case CMD_802_11_BEACON_CTRL: |
1507 | ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action); | |
1508 | break; | |
876c9d3a | 1509 | default: |
e37fc6e1 | 1510 | lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no); |
876c9d3a MT |
1511 | ret = -1; |
1512 | break; | |
1513 | } | |
1514 | ||
1515 | /* return error, since the command preparation failed */ | |
1516 | if (ret != 0) { | |
8ff12da1 | 1517 | lbs_deb_host("PREP_CMD: command preparation failed\n"); |
10078321 | 1518 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
876c9d3a MT |
1519 | ret = -1; |
1520 | goto done; | |
1521 | } | |
1522 | ||
1523 | cmdnode->cmdwaitqwoken = 0; | |
1524 | ||
681ffbb7 | 1525 | lbs_queue_cmd(priv, cmdnode); |
fe336150 | 1526 | wake_up_interruptible(&priv->waitq); |
876c9d3a | 1527 | |
0aef64d7 | 1528 | if (wait_option & CMD_OPTION_WAITFORRSP) { |
8ff12da1 | 1529 | lbs_deb_host("PREP_CMD: wait for response\n"); |
876c9d3a MT |
1530 | might_sleep(); |
1531 | wait_event_interruptible(cmdnode->cmdwait_q, | |
1532 | cmdnode->cmdwaitqwoken); | |
1533 | } | |
1534 | ||
aa21c004 DW |
1535 | spin_lock_irqsave(&priv->driver_lock, flags); |
1536 | if (priv->cur_cmd_retcode) { | |
8ff12da1 | 1537 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", |
aa21c004 DW |
1538 | priv->cur_cmd_retcode); |
1539 | priv->cur_cmd_retcode = 0; | |
876c9d3a MT |
1540 | ret = -1; |
1541 | } | |
aa21c004 | 1542 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1543 | |
1544 | done: | |
8ff12da1 | 1545 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1546 | return ret; |
1547 | } | |
1548 | ||
1549 | /** | |
1550 | * @brief This function allocates the command buffer and link | |
1551 | * it to command free queue. | |
1552 | * | |
69f9032d | 1553 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1554 | * @return 0 or -1 |
1555 | */ | |
69f9032d | 1556 | int lbs_allocate_cmd_buffer(struct lbs_private *priv) |
876c9d3a MT |
1557 | { |
1558 | int ret = 0; | |
ddac4526 | 1559 | u32 bufsize; |
876c9d3a | 1560 | u32 i; |
ddac4526 | 1561 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1562 | |
8ff12da1 | 1563 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1564 | |
ddac4526 DW |
1565 | /* Allocate and initialize the command array */ |
1566 | bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS; | |
1567 | if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) { | |
8ff12da1 | 1568 | lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n"); |
876c9d3a MT |
1569 | ret = -1; |
1570 | goto done; | |
1571 | } | |
ddac4526 | 1572 | priv->cmd_array = cmdarray; |
876c9d3a | 1573 | |
ddac4526 DW |
1574 | /* Allocate and initialize each command buffer in the command array */ |
1575 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { | |
1576 | cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL); | |
1577 | if (!cmdarray[i].cmdbuf) { | |
8ff12da1 | 1578 | lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); |
876c9d3a MT |
1579 | ret = -1; |
1580 | goto done; | |
1581 | } | |
876c9d3a MT |
1582 | } |
1583 | ||
ddac4526 DW |
1584 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1585 | init_waitqueue_head(&cmdarray[i].cmdwait_q); | |
1586 | lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]); | |
876c9d3a | 1587 | } |
876c9d3a | 1588 | ret = 0; |
9012b28a HS |
1589 | |
1590 | done: | |
8ff12da1 | 1591 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
876c9d3a MT |
1592 | return ret; |
1593 | } | |
1594 | ||
1595 | /** | |
1596 | * @brief This function frees the command buffer. | |
1597 | * | |
69f9032d | 1598 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1599 | * @return 0 or -1 |
1600 | */ | |
69f9032d | 1601 | int lbs_free_cmd_buffer(struct lbs_private *priv) |
876c9d3a | 1602 | { |
ddac4526 | 1603 | struct cmd_ctrl_node *cmdarray; |
876c9d3a | 1604 | unsigned int i; |
876c9d3a | 1605 | |
8ff12da1 | 1606 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1607 | |
1608 | /* need to check if cmd array is allocated or not */ | |
aa21c004 | 1609 | if (priv->cmd_array == NULL) { |
8ff12da1 | 1610 | lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n"); |
876c9d3a MT |
1611 | goto done; |
1612 | } | |
1613 | ||
ddac4526 | 1614 | cmdarray = priv->cmd_array; |
876c9d3a MT |
1615 | |
1616 | /* Release shared memory buffers */ | |
ddac4526 DW |
1617 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
1618 | if (cmdarray[i].cmdbuf) { | |
1619 | kfree(cmdarray[i].cmdbuf); | |
1620 | cmdarray[i].cmdbuf = NULL; | |
876c9d3a MT |
1621 | } |
1622 | } | |
1623 | ||
1624 | /* Release cmd_ctrl_node */ | |
aa21c004 DW |
1625 | if (priv->cmd_array) { |
1626 | kfree(priv->cmd_array); | |
1627 | priv->cmd_array = NULL; | |
876c9d3a MT |
1628 | } |
1629 | ||
1630 | done: | |
8ff12da1 | 1631 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1632 | return 0; |
1633 | } | |
1634 | ||
1635 | /** | |
1636 | * @brief This function gets a free command node if available in | |
1637 | * command free queue. | |
1638 | * | |
69f9032d | 1639 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1640 | * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL |
1641 | */ | |
2fd6cfe3 | 1642 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv) |
876c9d3a MT |
1643 | { |
1644 | struct cmd_ctrl_node *tempnode; | |
876c9d3a MT |
1645 | unsigned long flags; |
1646 | ||
8ff12da1 HS |
1647 | lbs_deb_enter(LBS_DEB_HOST); |
1648 | ||
aa21c004 | 1649 | if (!priv) |
876c9d3a MT |
1650 | return NULL; |
1651 | ||
aa21c004 | 1652 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1653 | |
aa21c004 DW |
1654 | if (!list_empty(&priv->cmdfreeq)) { |
1655 | tempnode = list_first_entry(&priv->cmdfreeq, | |
abe3ed14 LZ |
1656 | struct cmd_ctrl_node, list); |
1657 | list_del(&tempnode->list); | |
876c9d3a | 1658 | } else { |
8ff12da1 | 1659 | lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n"); |
876c9d3a MT |
1660 | tempnode = NULL; |
1661 | } | |
1662 | ||
aa21c004 | 1663 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a | 1664 | |
8ff12da1 | 1665 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1666 | return tempnode; |
1667 | } | |
1668 | ||
876c9d3a MT |
1669 | /** |
1670 | * @brief This function executes next command in command | |
877d0310 | 1671 | * pending queue. It will put firmware back to PS mode |
876c9d3a MT |
1672 | * if applicable. |
1673 | * | |
69f9032d | 1674 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1675 | * @return 0 or -1 |
1676 | */ | |
69f9032d | 1677 | int lbs_execute_next_command(struct lbs_private *priv) |
876c9d3a | 1678 | { |
876c9d3a | 1679 | struct cmd_ctrl_node *cmdnode = NULL; |
ddac4526 | 1680 | struct cmd_header *cmd; |
876c9d3a MT |
1681 | unsigned long flags; |
1682 | int ret = 0; | |
1683 | ||
1afc09ab HS |
1684 | /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the |
1685 | * only caller to us is lbs_thread() and we get even when a | |
1686 | * data packet is received */ | |
8ff12da1 | 1687 | lbs_deb_enter(LBS_DEB_THREAD); |
876c9d3a | 1688 | |
aa21c004 | 1689 | spin_lock_irqsave(&priv->driver_lock, flags); |
876c9d3a | 1690 | |
aa21c004 | 1691 | if (priv->cur_cmd) { |
8ff12da1 | 1692 | lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); |
aa21c004 | 1693 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1694 | ret = -1; |
1695 | goto done; | |
1696 | } | |
1697 | ||
aa21c004 DW |
1698 | if (!list_empty(&priv->cmdpendingq)) { |
1699 | cmdnode = list_first_entry(&priv->cmdpendingq, | |
abe3ed14 | 1700 | struct cmd_ctrl_node, list); |
876c9d3a MT |
1701 | } |
1702 | ||
aa21c004 | 1703 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1704 | |
1705 | if (cmdnode) { | |
ddac4526 | 1706 | cmd = cmdnode->cmdbuf; |
876c9d3a | 1707 | |
ddac4526 | 1708 | if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) { |
aa21c004 DW |
1709 | if ((priv->psstate == PS_STATE_SLEEP) || |
1710 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1711 | lbs_deb_host( |
1712 | "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n", | |
ddac4526 | 1713 | le16_to_cpu(cmd->command), |
aa21c004 | 1714 | priv->psstate); |
876c9d3a MT |
1715 | ret = -1; |
1716 | goto done; | |
1717 | } | |
8ff12da1 | 1718 | lbs_deb_host("EXEC_NEXT_CMD: OK to send command " |
ddac4526 DW |
1719 | "0x%04x in psstate %d\n", |
1720 | le16_to_cpu(cmd->command), priv->psstate); | |
aa21c004 | 1721 | } else if (priv->psstate != PS_STATE_FULL_POWER) { |
876c9d3a MT |
1722 | /* |
1723 | * 1. Non-PS command: | |
1724 | * Queue it. set needtowakeup to TRUE if current state | |
10078321 | 1725 | * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS. |
876c9d3a MT |
1726 | * 2. PS command but not Exit_PS: |
1727 | * Ignore it. | |
1728 | * 3. PS command Exit_PS: | |
1729 | * Set needtowakeup to TRUE if current state is SLEEP, | |
1730 | * otherwise send this command down to firmware | |
1731 | * immediately. | |
1732 | */ | |
ddac4526 | 1733 | if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) { |
876c9d3a MT |
1734 | /* Prepare to send Exit PS, |
1735 | * this non PS command will be sent later */ | |
aa21c004 DW |
1736 | if ((priv->psstate == PS_STATE_SLEEP) |
1737 | || (priv->psstate == PS_STATE_PRE_SLEEP) | |
876c9d3a MT |
1738 | ) { |
1739 | /* w/ new scheme, it will not reach here. | |
1740 | since it is blocked in main_thread. */ | |
aa21c004 | 1741 | priv->needtowakeup = 1; |
876c9d3a | 1742 | } else |
10078321 | 1743 | lbs_ps_wakeup(priv, 0); |
876c9d3a MT |
1744 | |
1745 | ret = 0; | |
1746 | goto done; | |
1747 | } else { | |
1748 | /* | |
1749 | * PS command. Ignore it if it is not Exit_PS. | |
1750 | * otherwise send it down immediately. | |
1751 | */ | |
38bfab1a | 1752 | struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1]; |
876c9d3a | 1753 | |
8ff12da1 HS |
1754 | lbs_deb_host( |
1755 | "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n", | |
876c9d3a MT |
1756 | psm->action); |
1757 | if (psm->action != | |
0aef64d7 | 1758 | cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
8ff12da1 HS |
1759 | lbs_deb_host( |
1760 | "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); | |
abe3ed14 | 1761 | list_del(&cmdnode->list); |
183aeac1 DW |
1762 | spin_lock_irqsave(&priv->driver_lock, flags); |
1763 | lbs_complete_command(priv, cmdnode, 0); | |
1764 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
876c9d3a MT |
1765 | |
1766 | ret = 0; | |
1767 | goto done; | |
1768 | } | |
1769 | ||
aa21c004 DW |
1770 | if ((priv->psstate == PS_STATE_SLEEP) || |
1771 | (priv->psstate == PS_STATE_PRE_SLEEP)) { | |
8ff12da1 HS |
1772 | lbs_deb_host( |
1773 | "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); | |
abe3ed14 | 1774 | list_del(&cmdnode->list); |
183aeac1 DW |
1775 | spin_lock_irqsave(&priv->driver_lock, flags); |
1776 | lbs_complete_command(priv, cmdnode, 0); | |
1777 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
aa21c004 | 1778 | priv->needtowakeup = 1; |
876c9d3a MT |
1779 | |
1780 | ret = 0; | |
1781 | goto done; | |
1782 | } | |
1783 | ||
8ff12da1 HS |
1784 | lbs_deb_host( |
1785 | "EXEC_NEXT_CMD: sending EXIT_PS\n"); | |
876c9d3a MT |
1786 | } |
1787 | } | |
abe3ed14 | 1788 | list_del(&cmdnode->list); |
8ff12da1 | 1789 | lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", |
ddac4526 | 1790 | le16_to_cpu(cmd->command)); |
d9896ee1 | 1791 | lbs_submit_command(priv, cmdnode); |
876c9d3a MT |
1792 | } else { |
1793 | /* | |
1794 | * check if in power save mode, if yes, put the device back | |
1795 | * to PS mode | |
1796 | */ | |
aa21c004 DW |
1797 | if ((priv->psmode != LBS802_11POWERMODECAM) && |
1798 | (priv->psstate == PS_STATE_FULL_POWER) && | |
1799 | ((priv->connect_status == LBS_CONNECTED) || | |
1800 | (priv->mesh_connect_status == LBS_CONNECTED))) { | |
1801 | if (priv->secinfo.WPAenabled || | |
1802 | priv->secinfo.WPA2enabled) { | |
876c9d3a | 1803 | /* check for valid WPA group keys */ |
aa21c004 DW |
1804 | if (priv->wpa_mcast_key.len || |
1805 | priv->wpa_unicast_key.len) { | |
8ff12da1 | 1806 | lbs_deb_host( |
876c9d3a MT |
1807 | "EXEC_NEXT_CMD: WPA enabled and GTK_SET" |
1808 | " go back to PS_SLEEP"); | |
10078321 | 1809 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1810 | } |
1811 | } else { | |
8ff12da1 HS |
1812 | lbs_deb_host( |
1813 | "EXEC_NEXT_CMD: cmdpendingq empty, " | |
1814 | "go back to PS_SLEEP"); | |
10078321 | 1815 | lbs_ps_sleep(priv, 0); |
876c9d3a MT |
1816 | } |
1817 | } | |
1818 | } | |
1819 | ||
1820 | ret = 0; | |
1821 | done: | |
8ff12da1 | 1822 | lbs_deb_leave(LBS_DEB_THREAD); |
876c9d3a MT |
1823 | return ret; |
1824 | } | |
1825 | ||
69f9032d | 1826 | void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str) |
876c9d3a MT |
1827 | { |
1828 | union iwreq_data iwrq; | |
1829 | u8 buf[50]; | |
1830 | ||
8ff12da1 | 1831 | lbs_deb_enter(LBS_DEB_WEXT); |
876c9d3a MT |
1832 | |
1833 | memset(&iwrq, 0, sizeof(union iwreq_data)); | |
1834 | memset(buf, 0, sizeof(buf)); | |
1835 | ||
1836 | snprintf(buf, sizeof(buf) - 1, "%s", str); | |
1837 | ||
1838 | iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN; | |
1839 | ||
1840 | /* Send Event to upper layer */ | |
8ff12da1 HS |
1841 | lbs_deb_wext("event indication string %s\n", (char *)buf); |
1842 | lbs_deb_wext("event indication length %d\n", iwrq.data.length); | |
1843 | lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str); | |
876c9d3a | 1844 | |
634b8f49 | 1845 | wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf); |
876c9d3a | 1846 | |
8ff12da1 | 1847 | lbs_deb_leave(LBS_DEB_WEXT); |
876c9d3a MT |
1848 | } |
1849 | ||
f539f2ef | 1850 | static void lbs_send_confirmsleep(struct lbs_private *priv) |
876c9d3a MT |
1851 | { |
1852 | unsigned long flags; | |
f539f2ef | 1853 | int ret; |
876c9d3a | 1854 | |
8ff12da1 | 1855 | lbs_deb_enter(LBS_DEB_HOST); |
f539f2ef HS |
1856 | lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep, |
1857 | sizeof(confirm_sleep)); | |
876c9d3a | 1858 | |
f539f2ef HS |
1859 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep, |
1860 | sizeof(confirm_sleep)); | |
876c9d3a | 1861 | if (ret) { |
f539f2ef | 1862 | lbs_pr_alert("confirm_sleep failed\n"); |
7919b89c | 1863 | goto out; |
876c9d3a | 1864 | } |
7919b89c HS |
1865 | |
1866 | spin_lock_irqsave(&priv->driver_lock, flags); | |
1867 | ||
a01f5450 HS |
1868 | /* We don't get a response on the sleep-confirmation */ |
1869 | priv->dnld_sent = DNLD_RES_RECEIVED; | |
1870 | ||
7919b89c HS |
1871 | /* If nothing to do, go back to sleep (?) */ |
1872 | if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx]) | |
1873 | priv->psstate = PS_STATE_SLEEP; | |
1874 | ||
1875 | spin_unlock_irqrestore(&priv->driver_lock, flags); | |
1876 | ||
1877 | out: | |
f539f2ef | 1878 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1879 | } |
1880 | ||
69f9032d | 1881 | void lbs_ps_sleep(struct lbs_private *priv, int wait_option) |
876c9d3a | 1882 | { |
8ff12da1 | 1883 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a MT |
1884 | |
1885 | /* | |
1886 | * PS is currently supported only in Infrastructure mode | |
1887 | * Remove this check if it is to be supported in IBSS mode also | |
1888 | */ | |
1889 | ||
10078321 | 1890 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1891 | CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL); |
876c9d3a | 1892 | |
8ff12da1 | 1893 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1894 | } |
1895 | ||
1896 | /** | |
8ff12da1 | 1897 | * @brief This function sends Exit_PS command to firmware. |
876c9d3a | 1898 | * |
69f9032d | 1899 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1900 | * @param wait_option wait response or not |
1901 | * @return n/a | |
1902 | */ | |
69f9032d | 1903 | void lbs_ps_wakeup(struct lbs_private *priv, int wait_option) |
876c9d3a | 1904 | { |
981f187b | 1905 | __le32 Localpsmode; |
876c9d3a | 1906 | |
8ff12da1 | 1907 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1908 | |
10078321 | 1909 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
876c9d3a | 1910 | |
10078321 | 1911 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
0aef64d7 | 1912 | CMD_SUBCMD_EXIT_PS, |
876c9d3a MT |
1913 | wait_option, 0, &Localpsmode); |
1914 | ||
8ff12da1 | 1915 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a MT |
1916 | } |
1917 | ||
1918 | /** | |
1919 | * @brief This function checks condition and prepares to | |
1920 | * send sleep confirm command to firmware if ok. | |
1921 | * | |
69f9032d | 1922 | * @param priv A pointer to struct lbs_private structure |
876c9d3a MT |
1923 | * @param psmode Power Saving mode |
1924 | * @return n/a | |
1925 | */ | |
d4ff0ef6 | 1926 | void lbs_ps_confirm_sleep(struct lbs_private *priv) |
876c9d3a MT |
1927 | { |
1928 | unsigned long flags =0; | |
d4ff0ef6 | 1929 | int allowed = 1; |
876c9d3a | 1930 | |
8ff12da1 | 1931 | lbs_deb_enter(LBS_DEB_HOST); |
876c9d3a | 1932 | |
a01f5450 | 1933 | spin_lock_irqsave(&priv->driver_lock, flags); |
634b8f49 | 1934 | if (priv->dnld_sent) { |
876c9d3a | 1935 | allowed = 0; |
23d36eec | 1936 | lbs_deb_host("dnld_sent was set\n"); |
876c9d3a MT |
1937 | } |
1938 | ||
7919b89c | 1939 | /* In-progress command? */ |
aa21c004 | 1940 | if (priv->cur_cmd) { |
876c9d3a | 1941 | allowed = 0; |
23d36eec | 1942 | lbs_deb_host("cur_cmd was set\n"); |
876c9d3a | 1943 | } |
7919b89c HS |
1944 | |
1945 | /* Pending events or command responses? */ | |
1946 | if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) { | |
876c9d3a | 1947 | allowed = 0; |
7919b89c | 1948 | lbs_deb_host("pending events or command responses\n"); |
876c9d3a | 1949 | } |
aa21c004 | 1950 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
876c9d3a MT |
1951 | |
1952 | if (allowed) { | |
10078321 | 1953 | lbs_deb_host("sending lbs_ps_confirm_sleep\n"); |
f539f2ef | 1954 | lbs_send_confirmsleep(priv); |
876c9d3a | 1955 | } else { |
8ff12da1 | 1956 | lbs_deb_host("sleep confirm has been delayed\n"); |
876c9d3a MT |
1957 | } |
1958 | ||
8ff12da1 | 1959 | lbs_deb_leave(LBS_DEB_HOST); |
876c9d3a | 1960 | } |
675787e2 HS |
1961 | |
1962 | ||
0112c9e9 AN |
1963 | /** |
1964 | * @brief Configures the transmission power control functionality. | |
1965 | * | |
1966 | * @param priv A pointer to struct lbs_private structure | |
1967 | * @param enable Transmission power control enable | |
1968 | * @param p0 Power level when link quality is good (dBm). | |
1969 | * @param p1 Power level when link quality is fair (dBm). | |
1970 | * @param p2 Power level when link quality is poor (dBm). | |
1971 | * @param usesnr Use Signal to Noise Ratio in TPC | |
1972 | * | |
1973 | * @return 0 on success | |
1974 | */ | |
1975 | int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1, | |
1976 | int8_t p2, int usesnr) | |
1977 | { | |
1978 | struct cmd_ds_802_11_tpc_cfg cmd; | |
1979 | int ret; | |
1980 | ||
1981 | memset(&cmd, 0, sizeof(cmd)); | |
1982 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
1983 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
1984 | cmd.enable = !!enable; | |
3ed6e080 | 1985 | cmd.usesnr = !!usesnr; |
0112c9e9 AN |
1986 | cmd.P0 = p0; |
1987 | cmd.P1 = p1; | |
1988 | cmd.P2 = p2; | |
1989 | ||
1990 | ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd); | |
1991 | ||
1992 | return ret; | |
1993 | } | |
1994 | ||
1995 | /** | |
1996 | * @brief Configures the power adaptation settings. | |
1997 | * | |
1998 | * @param priv A pointer to struct lbs_private structure | |
1999 | * @param enable Power adaptation enable | |
2000 | * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm). | |
2001 | * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm). | |
2002 | * @param p2 Power level for 48 and 54 Mbps (dBm). | |
2003 | * | |
2004 | * @return 0 on Success | |
2005 | */ | |
2006 | ||
2007 | int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0, | |
2008 | int8_t p1, int8_t p2) | |
2009 | { | |
2010 | struct cmd_ds_802_11_pa_cfg cmd; | |
2011 | int ret; | |
2012 | ||
2013 | memset(&cmd, 0, sizeof(cmd)); | |
2014 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); | |
2015 | cmd.action = cpu_to_le16(CMD_ACT_SET); | |
2016 | cmd.enable = !!enable; | |
2017 | cmd.P0 = p0; | |
2018 | cmd.P1 = p1; | |
2019 | cmd.P2 = p2; | |
2020 | ||
2021 | ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd); | |
2022 | ||
2023 | return ret; | |
2024 | } | |
2025 | ||
2026 | ||
8db4a2b9 HS |
2027 | static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, |
2028 | uint16_t command, struct cmd_header *in_cmd, int in_cmd_size, | |
2029 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
2030 | unsigned long callback_arg) | |
675787e2 | 2031 | { |
675787e2 | 2032 | struct cmd_ctrl_node *cmdnode; |
675787e2 HS |
2033 | |
2034 | lbs_deb_enter(LBS_DEB_HOST); | |
675787e2 | 2035 | |
aa21c004 | 2036 | if (priv->surpriseremoved) { |
675787e2 | 2037 | lbs_deb_host("PREP_CMD: card removed\n"); |
3399ea5f | 2038 | cmdnode = ERR_PTR(-ENOENT); |
675787e2 HS |
2039 | goto done; |
2040 | } | |
2041 | ||
2042 | cmdnode = lbs_get_cmd_ctrl_node(priv); | |
675787e2 HS |
2043 | if (cmdnode == NULL) { |
2044 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); | |
2045 | ||
2046 | /* Wake up main thread to execute next command */ | |
2047 | wake_up_interruptible(&priv->waitq); | |
3399ea5f | 2048 | cmdnode = ERR_PTR(-ENOBUFS); |
675787e2 HS |
2049 | goto done; |
2050 | } | |
2051 | ||
448a51ae | 2052 | cmdnode->callback = callback; |
1309b55b | 2053 | cmdnode->callback_arg = callback_arg; |
675787e2 | 2054 | |
7ad994de | 2055 | /* Copy the incoming command to the buffer */ |
ddac4526 | 2056 | memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size); |
7ad994de | 2057 | |
675787e2 | 2058 | /* Set sequence number, clean result, move to buffer */ |
aa21c004 | 2059 | priv->seqnum++; |
ddac4526 DW |
2060 | cmdnode->cmdbuf->command = cpu_to_le16(command); |
2061 | cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size); | |
2062 | cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum); | |
2063 | cmdnode->cmdbuf->result = 0; | |
675787e2 HS |
2064 | |
2065 | lbs_deb_host("PREP_CMD: command 0x%04x\n", command); | |
2066 | ||
675787e2 | 2067 | cmdnode->cmdwaitqwoken = 0; |
681ffbb7 | 2068 | lbs_queue_cmd(priv, cmdnode); |
675787e2 HS |
2069 | wake_up_interruptible(&priv->waitq); |
2070 | ||
3399ea5f DW |
2071 | done: |
2072 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode); | |
2073 | return cmdnode; | |
2074 | } | |
2075 | ||
8db4a2b9 HS |
2076 | void lbs_cmd_async(struct lbs_private *priv, uint16_t command, |
2077 | struct cmd_header *in_cmd, int in_cmd_size) | |
2078 | { | |
2079 | lbs_deb_enter(LBS_DEB_CMD); | |
2080 | __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
2081 | lbs_cmd_async_callback, 0); | |
2082 | lbs_deb_leave(LBS_DEB_CMD); | |
2083 | } | |
2084 | ||
3399ea5f DW |
2085 | int __lbs_cmd(struct lbs_private *priv, uint16_t command, |
2086 | struct cmd_header *in_cmd, int in_cmd_size, | |
2087 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), | |
2088 | unsigned long callback_arg) | |
2089 | { | |
2090 | struct cmd_ctrl_node *cmdnode; | |
2091 | unsigned long flags; | |
2092 | int ret = 0; | |
2093 | ||
2094 | lbs_deb_enter(LBS_DEB_HOST); | |
2095 | ||
2096 | cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, | |
2097 | callback, callback_arg); | |
2098 | if (IS_ERR(cmdnode)) { | |
2099 | ret = PTR_ERR(cmdnode); | |
2100 | goto done; | |
2101 | } | |
2102 | ||
675787e2 HS |
2103 | might_sleep(); |
2104 | wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken); | |
2105 | ||
aa21c004 | 2106 | spin_lock_irqsave(&priv->driver_lock, flags); |
ae125bf8 DW |
2107 | ret = cmdnode->result; |
2108 | if (ret) | |
2109 | lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n", | |
2110 | command, ret); | |
3399ea5f | 2111 | |
ad12d0f4 | 2112 | __lbs_cleanup_and_insert_cmd(priv, cmdnode); |
aa21c004 | 2113 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
675787e2 HS |
2114 | |
2115 | done: | |
2116 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); | |
2117 | return ret; | |
2118 | } | |
14e865ba | 2119 | EXPORT_SYMBOL_GPL(__lbs_cmd); |
675787e2 HS |
2120 | |
2121 |