libertas: add simple copyback command callback
[deliverable/linux.git] / drivers / net / wireless / libertas / cmd.c
CommitLineData
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>
7#include "host.h"
8#include "hostcmd.h"
876c9d3a
MT
9#include "decl.h"
10#include "defs.h"
11#include "dev.h"
12#include "join.h"
13#include "wext.h"
14
15static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
0d61d042
HS
16struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
17void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
18 struct cmd_ctrl_node *ptempnode,
19 u16 wait_option, void *pdata_buf);
20
876c9d3a 21
876c9d3a 22/**
852e1f2a 23 * @brief Checks whether a command is allowed in Power Save mode
876c9d3a
MT
24 *
25 * @param command the command ID
852e1f2a 26 * @return 1 if allowed, 0 if not allowed
876c9d3a 27 */
852e1f2a 28static u8 is_command_allowed_in_ps(u16 cmd)
876c9d3a 29{
852e1f2a
DW
30 switch (cmd) {
31 case CMD_802_11_RSSI:
32 return 1;
33 default:
34 break;
876c9d3a 35 }
876c9d3a
MT
36 return 0;
37}
38
69f9032d 39static int lbs_cmd_hw_spec(struct lbs_private *priv, struct cmd_ds_command *cmd)
876c9d3a
MT
40{
41 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
42
9012b28a 43 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 44
0aef64d7 45 cmd->command = cpu_to_le16(CMD_GET_HW_SPEC);
981f187b 46 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
aa21c004 47 memcpy(hwspec->permanentaddr, priv->current_addr, ETH_ALEN);
876c9d3a 48
9012b28a 49 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
50 return 0;
51}
52
69f9032d 53static int lbs_cmd_802_11_ps_mode(struct lbs_private *priv,
876c9d3a
MT
54 struct cmd_ds_command *cmd,
55 u16 cmd_action)
56{
57 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
876c9d3a 58
9012b28a 59 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 60
0aef64d7 61 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
981f187b
DW
62 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
63 S_DS_GEN);
876c9d3a
MT
64 psm->action = cpu_to_le16(cmd_action);
65 psm->multipledtim = 0;
981f187b 66 switch (cmd_action) {
0aef64d7 67 case CMD_SUBCMD_ENTER_PS:
9012b28a 68 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
876c9d3a 69
252cf0d1 70 psm->locallisteninterval = 0;
97605c3e 71 psm->nullpktinterval = 0;
876c9d3a 72 psm->multipledtim =
56c4656e 73 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
876c9d3a
MT
74 break;
75
0aef64d7 76 case CMD_SUBCMD_EXIT_PS:
9012b28a 77 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
876c9d3a
MT
78 break;
79
0aef64d7 80 case CMD_SUBCMD_SLEEP_CONFIRMED:
9012b28a 81 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
876c9d3a
MT
82 break;
83
84 default:
85 break;
86 }
87
9012b28a 88 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
89 return 0;
90}
91
69f9032d 92static int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
876c9d3a
MT
93 struct cmd_ds_command *cmd,
94 u16 cmd_action, void *pdata_buf)
95{
96 u16 *timeout = pdata_buf;
97
8ff12da1
HS
98 lbs_deb_enter(LBS_DEB_CMD);
99
0aef64d7 100 cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
876c9d3a
MT
101 cmd->size =
102 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
103 + S_DS_GEN);
104
105 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
106
107 if (cmd_action)
981f187b 108 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
876c9d3a
MT
109 else
110 cmd->params.inactivity_timeout.timeout = 0;
111
8ff12da1 112 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
113 return 0;
114}
115
69f9032d 116static int lbs_cmd_802_11_sleep_params(struct lbs_private *priv,
876c9d3a
MT
117 struct cmd_ds_command *cmd,
118 u16 cmd_action)
119{
876c9d3a
MT
120 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
121
9012b28a 122 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 123
981f187b
DW
124 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
125 S_DS_GEN);
0aef64d7 126 cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
876c9d3a 127
0aef64d7 128 if (cmd_action == CMD_ACT_GET) {
aa21c004 129 memset(&priv->sp, 0, sizeof(struct sleep_params));
876c9d3a
MT
130 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
131 sp->action = cpu_to_le16(cmd_action);
0aef64d7 132 } else if (cmd_action == CMD_ACT_SET) {
876c9d3a 133 sp->action = cpu_to_le16(cmd_action);
aa21c004
DW
134 sp->error = cpu_to_le16(priv->sp.sp_error);
135 sp->offset = cpu_to_le16(priv->sp.sp_offset);
136 sp->stabletime = cpu_to_le16(priv->sp.sp_stabletime);
137 sp->calcontrol = (u8) priv->sp.sp_calcontrol;
138 sp->externalsleepclk = (u8) priv->sp.sp_extsleepclk;
139 sp->reserved = cpu_to_le16(priv->sp.sp_reserved);
876c9d3a
MT
140 }
141
9012b28a 142 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
143 return 0;
144}
145
69f9032d 146static int lbs_cmd_802_11_set_wep(struct lbs_private *priv,
876c9d3a
MT
147 struct cmd_ds_command *cmd,
148 u32 cmd_act,
149 void * pdata_buf)
150{
151 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
876c9d3a
MT
152 int ret = 0;
153 struct assoc_request * assoc_req = pdata_buf;
154
9012b28a 155 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 156
0aef64d7 157 cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
981f187b 158 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
876c9d3a 159
0aef64d7 160 if (cmd_act == CMD_ACT_ADD) {
876c9d3a
MT
161 int i;
162
163 if (!assoc_req) {
9012b28a 164 lbs_deb_cmd("Invalid association request!");
876c9d3a
MT
165 ret = -1;
166 goto done;
167 }
168
0aef64d7 169 wep->action = cpu_to_le16(CMD_ACT_ADD);
876c9d3a
MT
170
171 /* default tx key index */
981f187b 172 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
0aef64d7 173 (u32)CMD_WEP_KEY_INDEX_MASK));
876c9d3a 174
876c9d3a
MT
175 /* Copy key types and material to host command structure */
176 for (i = 0; i < 4; i++) {
1443b653 177 struct enc_key * pkey = &assoc_req->wep_keys[i];
876c9d3a
MT
178
179 switch (pkey->len) {
180 case KEY_LEN_WEP_40:
6470a89d 181 wep->keytype[i] = CMD_TYPE_WEP_40_BIT;
876c9d3a
MT
182 memmove(&wep->keymaterial[i], pkey->key,
183 pkey->len);
8ff12da1 184 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
876c9d3a
MT
185 break;
186 case KEY_LEN_WEP_104:
6470a89d 187 wep->keytype[i] = CMD_TYPE_WEP_104_BIT;
876c9d3a
MT
188 memmove(&wep->keymaterial[i], pkey->key,
189 pkey->len);
8ff12da1 190 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
876c9d3a
MT
191 break;
192 case 0:
193 break;
194 default:
8ff12da1 195 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
876c9d3a
MT
196 i, pkey->len);
197 ret = -1;
198 goto done;
199 break;
200 }
201 }
0aef64d7 202 } else if (cmd_act == CMD_ACT_REMOVE) {
876c9d3a 203 /* ACT_REMOVE clears _all_ WEP keys */
0aef64d7 204 wep->action = cpu_to_le16(CMD_ACT_REMOVE);
876c9d3a
MT
205
206 /* default tx key index */
aa21c004 207 wep->keyindex = cpu_to_le16((u16)(priv->wep_tx_keyidx &
0aef64d7 208 (u32)CMD_WEP_KEY_INDEX_MASK));
aa21c004 209 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
876c9d3a
MT
210 }
211
212 ret = 0;
213
214done:
9012b28a 215 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
216 return ret;
217}
218
69f9032d 219static int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv,
876c9d3a 220 struct cmd_ds_command *cmd,
90a42210
DW
221 u16 cmd_action,
222 void * pdata_buf)
876c9d3a
MT
223{
224 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
18c96c34 225 u32 * enable = pdata_buf;
90a42210
DW
226
227 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 228
0aef64d7 229 cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
981f187b 230 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
876c9d3a 231 penableRSN->action = cpu_to_le16(cmd_action);
18c96c34 232
0aef64d7 233 if (cmd_action == CMD_ACT_SET) {
18c96c34 234 if (*enable)
0aef64d7 235 penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
18c96c34 236 else
0aef64d7 237 penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
8ff12da1 238 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
876c9d3a
MT
239 }
240
90a42210 241 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
242 return 0;
243}
244
245
3a188649
HS
246static ssize_t lbs_tlv_size(const u8 *tlv, u16 size)
247{
248 ssize_t pos = 0;
249 struct mrvlietypesheader *tlv_h;
250 while (pos < size) {
251 u16 length;
252 tlv_h = (struct mrvlietypesheader *) tlv;
253 if (tlv_h->len == 0)
254 return pos;
255 length = le16_to_cpu(tlv_h->len) +
256 sizeof(struct mrvlietypesheader);
257 pos += length;
258 tlv += length;
259 }
260 return pos;
261}
262
263
264static void lbs_cmd_802_11_subscribe_event(struct lbs_private *priv,
265 struct cmd_ds_command *cmd, u16 cmd_action,
266 void *pdata_buf)
267{
268 struct cmd_ds_802_11_subscribe_event *events =
269 (struct cmd_ds_802_11_subscribe_event *) pdata_buf;
270
271 /* pdata_buf points to a struct cmd_ds_802_11_subscribe_event and room
272 * for various Marvell TLVs */
273
274 lbs_deb_enter(LBS_DEB_CMD);
275
276 cmd->size = cpu_to_le16(sizeof(*events)
277 - sizeof(events->tlv)
278 + S_DS_GEN);
279 cmd->params.subscribe_event.action = cpu_to_le16(cmd_action);
280 if (cmd_action == CMD_ACT_GET) {
281 cmd->params.subscribe_event.events = 0;
282 } else {
283 ssize_t sz = lbs_tlv_size(events->tlv, sizeof(events->tlv));
284 cmd->size = cpu_to_le16(le16_to_cpu(cmd->size) + sz);
285 cmd->params.subscribe_event.events = events->events;
286 memcpy(cmd->params.subscribe_event.tlv, events->tlv, sz);
287 }
288
289 lbs_deb_leave(LBS_DEB_CMD);
290}
291
876c9d3a 292static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
1443b653 293 struct enc_key * pkey)
876c9d3a 294{
8ff12da1
HS
295 lbs_deb_enter(LBS_DEB_CMD);
296
876c9d3a 297 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
90a42210 298 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
876c9d3a 299 }
876c9d3a
MT
300 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
301 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
90a42210
DW
302 }
303 if (pkey->flags & KEY_INFO_WPA_MCAST) {
876c9d3a
MT
304 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
305 }
306
307 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
1443b653 308 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
876c9d3a
MT
309 pkeyparamset->keylen = cpu_to_le16(pkey->len);
310 memcpy(pkeyparamset->key, pkey->key, pkey->len);
311 pkeyparamset->length = cpu_to_le16( sizeof(pkeyparamset->keytypeid)
312 + sizeof(pkeyparamset->keyinfo)
313 + sizeof(pkeyparamset->keylen)
314 + sizeof(pkeyparamset->key));
8ff12da1 315 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
316}
317
69f9032d 318static int lbs_cmd_802_11_key_material(struct lbs_private *priv,
876c9d3a
MT
319 struct cmd_ds_command *cmd,
320 u16 cmd_action,
321 u32 cmd_oid, void *pdata_buf)
322{
876c9d3a
MT
323 struct cmd_ds_802_11_key_material *pkeymaterial =
324 &cmd->params.keymaterial;
90a42210 325 struct assoc_request * assoc_req = pdata_buf;
876c9d3a
MT
326 int ret = 0;
327 int index = 0;
328
9012b28a 329 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 330
0aef64d7 331 cmd->command = cpu_to_le16(CMD_802_11_KEY_MATERIAL);
876c9d3a
MT
332 pkeymaterial->action = cpu_to_le16(cmd_action);
333
0aef64d7 334 if (cmd_action == CMD_ACT_GET) {
90a42210 335 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
876c9d3a
MT
336 ret = 0;
337 goto done;
338 }
339
340 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
341
90a42210 342 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
876c9d3a 343 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
90a42210 344 &assoc_req->wpa_unicast_key);
876c9d3a
MT
345 index++;
346 }
347
90a42210 348 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
876c9d3a 349 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
90a42210 350 &assoc_req->wpa_mcast_key);
876c9d3a
MT
351 index++;
352 }
353
354 cmd->size = cpu_to_le16( S_DS_GEN
90a42210
DW
355 + sizeof (pkeymaterial->action)
356 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
876c9d3a
MT
357
358 ret = 0;
359
360done:
9012b28a 361 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
362 return ret;
363}
364
69f9032d 365static int lbs_cmd_802_11_reset(struct lbs_private *priv,
876c9d3a
MT
366 struct cmd_ds_command *cmd, int cmd_action)
367{
368 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
369
8ff12da1
HS
370 lbs_deb_enter(LBS_DEB_CMD);
371
0aef64d7 372 cmd->command = cpu_to_le16(CMD_802_11_RESET);
876c9d3a
MT
373 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
374 reset->action = cpu_to_le16(cmd_action);
375
8ff12da1 376 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
377 return 0;
378}
379
69f9032d 380static int lbs_cmd_802_11_get_log(struct lbs_private *priv,
876c9d3a
MT
381 struct cmd_ds_command *cmd)
382{
8ff12da1 383 lbs_deb_enter(LBS_DEB_CMD);
0aef64d7 384 cmd->command = cpu_to_le16(CMD_802_11_GET_LOG);
876c9d3a
MT
385 cmd->size =
386 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
387
8ff12da1 388 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
389 return 0;
390}
391
69f9032d 392static int lbs_cmd_802_11_get_stat(struct lbs_private *priv,
876c9d3a
MT
393 struct cmd_ds_command *cmd)
394{
8ff12da1 395 lbs_deb_enter(LBS_DEB_CMD);
0aef64d7 396 cmd->command = cpu_to_le16(CMD_802_11_GET_STAT);
876c9d3a 397 cmd->size =
981f187b 398 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
876c9d3a 399
8ff12da1 400 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
401 return 0;
402}
403
69f9032d 404static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
876c9d3a
MT
405 struct cmd_ds_command *cmd,
406 int cmd_action,
407 int cmd_oid, void *pdata_buf)
408{
409 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
876c9d3a
MT
410 u8 ucTemp;
411
9012b28a 412 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 413
9012b28a 414 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
876c9d3a 415
0aef64d7 416 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
981f187b 417 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
876c9d3a
MT
418
419 switch (cmd_oid) {
420 case OID_802_11_INFRASTRUCTURE_MODE:
421 {
0dc5a290 422 u8 mode = (u8) (size_t) pdata_buf;
0aef64d7
DW
423 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
424 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
c2df2efe 425 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
0dc5a290 426 if (mode == IW_MODE_ADHOC) {
876c9d3a 427 ucTemp = SNMP_MIB_VALUE_ADHOC;
0dc5a290
DW
428 } else {
429 /* Infra and Auto modes */
430 ucTemp = SNMP_MIB_VALUE_INFRA;
431 }
876c9d3a
MT
432
433 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
434
435 break;
436 }
437
438 case OID_802_11D_ENABLE:
439 {
440 u32 ulTemp;
441
0aef64d7 442 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
876c9d3a 443
0aef64d7 444 if (cmd_action == CMD_ACT_SET) {
c2df2efe
HS
445 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
446 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
876c9d3a 447 ulTemp = *(u32 *)pdata_buf;
981f187b 448 *((__le16 *)(pSNMPMIB->value)) =
876c9d3a
MT
449 cpu_to_le16((u16) ulTemp);
450 }
451 break;
452 }
453
454 case OID_802_11_FRAGMENTATION_THRESHOLD:
455 {
456 u32 ulTemp;
457
0aef64d7 458 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
876c9d3a 459
0aef64d7
DW
460 if (cmd_action == CMD_ACT_GET) {
461 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
462 } else if (cmd_action == CMD_ACT_SET) {
463 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
981f187b 464 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
876c9d3a 465 ulTemp = *((u32 *) pdata_buf);
981f187b 466 *((__le16 *)(pSNMPMIB->value)) =
876c9d3a
MT
467 cpu_to_le16((u16) ulTemp);
468
469 }
470
471 break;
472 }
473
474 case OID_802_11_RTS_THRESHOLD:
475 {
476
477 u32 ulTemp;
c2df2efe 478 pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
876c9d3a 479
0aef64d7
DW
480 if (cmd_action == CMD_ACT_GET) {
481 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
482 } else if (cmd_action == CMD_ACT_SET) {
483 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
981f187b
DW
484 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
485 ulTemp = *((u32 *)pdata_buf);
486 *(__le16 *)(pSNMPMIB->value) =
876c9d3a
MT
487 cpu_to_le16((u16) ulTemp);
488
489 }
490 break;
491 }
492 case OID_802_11_TX_RETRYCOUNT:
0aef64d7 493 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
876c9d3a 494
0aef64d7
DW
495 if (cmd_action == CMD_ACT_GET) {
496 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
497 } else if (cmd_action == CMD_ACT_SET) {
498 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
876c9d3a 499 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
981f187b 500 *((__le16 *)(pSNMPMIB->value)) =
aa21c004 501 cpu_to_le16((u16) priv->txretrycount);
876c9d3a
MT
502 }
503
504 break;
505 default:
506 break;
507 }
508
9012b28a 509 lbs_deb_cmd(
876c9d3a 510 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
981f187b
DW
511 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
512 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
876c9d3a 513
9012b28a 514 lbs_deb_cmd(
8ff12da1 515 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
981f187b
DW
516 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
517 le16_to_cpu(pSNMPMIB->bufsize),
518 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
876c9d3a 519
9012b28a 520 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
521 return 0;
522}
523
69f9032d 524static int lbs_cmd_802_11_radio_control(struct lbs_private *priv,
876c9d3a
MT
525 struct cmd_ds_command *cmd,
526 int cmd_action)
527{
981f187b 528 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
876c9d3a 529
9012b28a 530 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
531
532 cmd->size =
533 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
534 S_DS_GEN);
0aef64d7 535 cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
876c9d3a
MT
536
537 pradiocontrol->action = cpu_to_le16(cmd_action);
538
aa21c004 539 switch (priv->preamble) {
0aef64d7 540 case CMD_TYPE_SHORT_PREAMBLE:
876c9d3a
MT
541 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
542 break;
543
0aef64d7 544 case CMD_TYPE_LONG_PREAMBLE:
876c9d3a
MT
545 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
546 break;
547
0aef64d7 548 case CMD_TYPE_AUTO_PREAMBLE:
876c9d3a
MT
549 default:
550 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
551 break;
552 }
553
aa21c004 554 if (priv->radioon)
876c9d3a
MT
555 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
556 else
557 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
558
9012b28a 559 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
560 return 0;
561}
562
69f9032d 563static int lbs_cmd_802_11_rf_tx_power(struct lbs_private *priv,
876c9d3a
MT
564 struct cmd_ds_command *cmd,
565 u16 cmd_action, void *pdata_buf)
566{
567
568 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
569
9012b28a 570 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
571
572 cmd->size =
981f187b 573 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
0aef64d7 574 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
981f187b 575 prtp->action = cpu_to_le16(cmd_action);
876c9d3a 576
981f187b
DW
577 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
578 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
579 le16_to_cpu(prtp->action));
876c9d3a
MT
580
581 switch (cmd_action) {
0aef64d7
DW
582 case CMD_ACT_TX_POWER_OPT_GET:
583 prtp->action = cpu_to_le16(CMD_ACT_GET);
876c9d3a
MT
584 prtp->currentlevel = 0;
585 break;
586
0aef64d7
DW
587 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
588 prtp->action = cpu_to_le16(CMD_ACT_SET);
589 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
876c9d3a
MT
590 break;
591
0aef64d7
DW
592 case CMD_ACT_TX_POWER_OPT_SET_MID:
593 prtp->action = cpu_to_le16(CMD_ACT_SET);
594 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
876c9d3a
MT
595 break;
596
0aef64d7
DW
597 case CMD_ACT_TX_POWER_OPT_SET_LOW:
598 prtp->action = cpu_to_le16(CMD_ACT_SET);
876c9d3a
MT
599 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
600 break;
601 }
9012b28a
HS
602
603 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
604 return 0;
605}
606
69f9032d 607static int lbs_cmd_802_11_monitor_mode(struct lbs_private *priv,
965f8bbc
LCC
608 struct cmd_ds_command *cmd,
609 u16 cmd_action, void *pdata_buf)
610{
611 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
612
613 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
614 cmd->size =
615 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
616 S_DS_GEN);
617
618 monitor->action = cpu_to_le16(cmd_action);
619 if (cmd_action == CMD_ACT_SET) {
620 monitor->mode =
621 cpu_to_le16((u16) (*(u32 *) pdata_buf));
622 }
623
624 return 0;
625}
626
69f9032d 627static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
876c9d3a
MT
628 struct cmd_ds_command *cmd,
629 u16 cmd_action)
630{
631 struct cmd_ds_802_11_rate_adapt_rateset
632 *rateadapt = &cmd->params.rateset;
876c9d3a 633
8ff12da1 634 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a
MT
635 cmd->size =
636 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
637 + S_DS_GEN);
0aef64d7 638 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
876c9d3a 639
981f187b 640 rateadapt->action = cpu_to_le16(cmd_action);
aa21c004
DW
641 rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
642 rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
876c9d3a 643
9012b28a 644 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
645 return 0;
646}
647
69f9032d 648static int lbs_cmd_802_11_data_rate(struct lbs_private *priv,
876c9d3a
MT
649 struct cmd_ds_command *cmd,
650 u16 cmd_action)
651{
652 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
876c9d3a 653
9012b28a 654 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 655
981f187b 656 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
876c9d3a 657 S_DS_GEN);
0aef64d7 658 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
876c9d3a 659 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
876c9d3a
MT
660 pdatarate->action = cpu_to_le16(cmd_action);
661
ffcae953 662 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
aa21c004 663 pdatarate->rates[0] = lbs_data_rate_to_fw_index(priv->cur_rate);
8ff12da1 664 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
aa21c004 665 priv->cur_rate);
ffcae953 666 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
8ff12da1 667 lbs_deb_cmd("DATA_RATE: setting auto\n");
876c9d3a
MT
668 }
669
9012b28a 670 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
671 return 0;
672}
673
69f9032d 674static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
876c9d3a
MT
675 struct cmd_ds_command *cmd,
676 u16 cmd_action)
677{
678 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
876c9d3a 679
8ff12da1 680 lbs_deb_enter(LBS_DEB_CMD);
981f187b 681 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
876c9d3a 682 S_DS_GEN);
0aef64d7 683 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
876c9d3a 684
8ff12da1 685 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
876c9d3a
MT
686 pMCastAdr->action = cpu_to_le16(cmd_action);
687 pMCastAdr->nr_of_adrs =
aa21c004
DW
688 cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
689 memcpy(pMCastAdr->maclist, priv->multicastlist,
690 priv->nr_of_multicastmacaddr * ETH_ALEN);
876c9d3a 691
8ff12da1 692 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
693 return 0;
694}
695
69f9032d 696static int lbs_cmd_802_11_rf_channel(struct lbs_private *priv,
876c9d3a
MT
697 struct cmd_ds_command *cmd,
698 int option, void *pdata_buf)
699{
700 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
701
8ff12da1 702 lbs_deb_enter(LBS_DEB_CMD);
0aef64d7 703 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
981f187b
DW
704 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
705 S_DS_GEN);
876c9d3a 706
0aef64d7 707 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
876c9d3a
MT
708 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
709 }
710
711 rfchan->action = cpu_to_le16(option);
712
8ff12da1 713 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
714 return 0;
715}
716
69f9032d 717static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
876c9d3a
MT
718 struct cmd_ds_command *cmd)
719{
876c9d3a 720
8ff12da1 721 lbs_deb_enter(LBS_DEB_CMD);
0aef64d7 722 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
981f187b 723 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
a783f1ee 724 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
876c9d3a
MT
725
726 /* reset Beacon SNR/NF/RSSI values */
aa21c004
DW
727 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
728 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
729 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
730 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
731 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
732 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
876c9d3a 733
8ff12da1 734 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
735 return 0;
736}
737
69f9032d 738static int lbs_cmd_reg_access(struct lbs_private *priv,
876c9d3a
MT
739 struct cmd_ds_command *cmdptr,
740 u8 cmd_action, void *pdata_buf)
741{
10078321 742 struct lbs_offset_value *offval;
876c9d3a 743
9012b28a 744 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 745
10078321 746 offval = (struct lbs_offset_value *)pdata_buf;
876c9d3a 747
c2df2efe 748 switch (le16_to_cpu(cmdptr->command)) {
0aef64d7 749 case CMD_MAC_REG_ACCESS:
876c9d3a
MT
750 {
751 struct cmd_ds_mac_reg_access *macreg;
752
753 cmdptr->size =
981f187b
DW
754 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
755 + S_DS_GEN);
876c9d3a
MT
756 macreg =
757 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
758 macreg;
759
760 macreg->action = cpu_to_le16(cmd_action);
761 macreg->offset = cpu_to_le16((u16) offval->offset);
762 macreg->value = cpu_to_le32(offval->value);
763
764 break;
765 }
766
0aef64d7 767 case CMD_BBP_REG_ACCESS:
876c9d3a
MT
768 {
769 struct cmd_ds_bbp_reg_access *bbpreg;
770
771 cmdptr->size =
772 cpu_to_le16(sizeof
773 (struct cmd_ds_bbp_reg_access)
774 + S_DS_GEN);
775 bbpreg =
776 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
777 bbpreg;
778
779 bbpreg->action = cpu_to_le16(cmd_action);
780 bbpreg->offset = cpu_to_le16((u16) offval->offset);
781 bbpreg->value = (u8) offval->value;
782
783 break;
784 }
785
0aef64d7 786 case CMD_RF_REG_ACCESS:
876c9d3a
MT
787 {
788 struct cmd_ds_rf_reg_access *rfreg;
789
790 cmdptr->size =
791 cpu_to_le16(sizeof
792 (struct cmd_ds_rf_reg_access) +
793 S_DS_GEN);
794 rfreg =
795 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
796 rfreg;
797
798 rfreg->action = cpu_to_le16(cmd_action);
799 rfreg->offset = cpu_to_le16((u16) offval->offset);
800 rfreg->value = (u8) offval->value;
801
802 break;
803 }
804
805 default:
806 break;
807 }
808
9012b28a 809 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
810 return 0;
811}
812
69f9032d 813static int lbs_cmd_802_11_mac_address(struct lbs_private *priv,
876c9d3a
MT
814 struct cmd_ds_command *cmd,
815 u16 cmd_action)
816{
876c9d3a 817
8ff12da1 818 lbs_deb_enter(LBS_DEB_CMD);
0aef64d7 819 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
981f187b 820 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
876c9d3a
MT
821 S_DS_GEN);
822 cmd->result = 0;
823
824 cmd->params.macadd.action = cpu_to_le16(cmd_action);
825
0aef64d7 826 if (cmd_action == CMD_ACT_SET) {
876c9d3a 827 memcpy(cmd->params.macadd.macadd,
aa21c004
DW
828 priv->current_addr, ETH_ALEN);
829 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", priv->current_addr, 6);
876c9d3a
MT
830 }
831
8ff12da1 832 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
833 return 0;
834}
835
69f9032d 836static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv,
876c9d3a
MT
837 struct cmd_ds_command *cmd,
838 int cmd_action, void *pdata_buf)
839{
10078321 840 struct lbs_ioctl_regrdwr *ea = pdata_buf;
876c9d3a 841
9012b28a 842 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 843
0aef64d7 844 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
981f187b
DW
845 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
846 S_DS_GEN);
876c9d3a
MT
847 cmd->result = 0;
848
849 cmd->params.rdeeprom.action = cpu_to_le16(ea->action);
850 cmd->params.rdeeprom.offset = cpu_to_le16(ea->offset);
851 cmd->params.rdeeprom.bytecount = cpu_to_le16(ea->NOB);
852 cmd->params.rdeeprom.value = 0;
853
8ff12da1 854 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
855 return 0;
856}
857
69f9032d 858static int lbs_cmd_bt_access(struct lbs_private *priv,
876c9d3a
MT
859 struct cmd_ds_command *cmd,
860 u16 cmd_action, void *pdata_buf)
861{
862 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
8ff12da1 863 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
876c9d3a 864
0aef64d7 865 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
981f187b 866 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
876c9d3a
MT
867 cmd->result = 0;
868 bt_access->action = cpu_to_le16(cmd_action);
869
870 switch (cmd_action) {
0aef64d7 871 case CMD_ACT_BT_ACCESS_ADD:
876c9d3a 872 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
ece56191 873 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
876c9d3a 874 break;
0aef64d7 875 case CMD_ACT_BT_ACCESS_DEL:
876c9d3a 876 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
ece56191 877 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
876c9d3a 878 break;
0aef64d7 879 case CMD_ACT_BT_ACCESS_LIST:
876c9d3a
MT
880 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
881 break;
0aef64d7 882 case CMD_ACT_BT_ACCESS_RESET:
876c9d3a 883 break;
0aef64d7 884 case CMD_ACT_BT_ACCESS_SET_INVERT:
90e8eafc
LCC
885 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
886 break;
0aef64d7 887 case CMD_ACT_BT_ACCESS_GET_INVERT:
90e8eafc 888 break;
876c9d3a
MT
889 default:
890 break;
891 }
8ff12da1 892 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
893 return 0;
894}
895
69f9032d 896static int lbs_cmd_fwt_access(struct lbs_private *priv,
876c9d3a
MT
897 struct cmd_ds_command *cmd,
898 u16 cmd_action, void *pdata_buf)
899{
900 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
8ff12da1 901 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
876c9d3a 902
0aef64d7 903 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
981f187b 904 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
876c9d3a
MT
905 cmd->result = 0;
906
907 if (pdata_buf)
908 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
909 else
910 memset(fwt_access, 0, sizeof(*fwt_access));
911
912 fwt_access->action = cpu_to_le16(cmd_action);
913
8ff12da1 914 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
915 return 0;
916}
917
69f9032d 918static int lbs_cmd_mesh_access(struct lbs_private *priv,
876c9d3a
MT
919 struct cmd_ds_command *cmd,
920 u16 cmd_action, void *pdata_buf)
921{
922 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
8ff12da1 923 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
876c9d3a 924
0aef64d7 925 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
981f187b 926 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
876c9d3a
MT
927 cmd->result = 0;
928
929 if (pdata_buf)
930 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
931 else
932 memset(mesh_access, 0, sizeof(*mesh_access));
933
934 mesh_access->action = cpu_to_le16(cmd_action);
935
8ff12da1 936 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
937 return 0;
938}
939
96287ac4
BD
940static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
941 struct cmd_ds_command *cmd,
942 u16 cmd_action)
943{
944 struct cmd_ds_802_11_beacon_control
945 *bcn_ctrl = &cmd->params.bcn_ctrl;
96287ac4
BD
946
947 lbs_deb_enter(LBS_DEB_CMD);
948 cmd->size =
949 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
950 + S_DS_GEN);
951 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
952
953 bcn_ctrl->action = cpu_to_le16(cmd_action);
aa21c004
DW
954 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
955 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
96287ac4
BD
956
957 lbs_deb_leave(LBS_DEB_CMD);
958 return 0;
959}
960
29f5f2a1 961/*
10078321 962 * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
29f5f2a1
MT
963 * the command timer, because it does not account for queued commands.
964 */
aa21c004 965void lbs_queue_cmd(struct lbs_private *priv,
69f9032d
HS
966 struct cmd_ctrl_node *cmdnode,
967 u8 addtail)
876c9d3a
MT
968{
969 unsigned long flags;
970 struct cmd_ds_command *cmdptr;
971
8ff12da1 972 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
973
974 if (!cmdnode) {
8ff12da1 975 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
876c9d3a
MT
976 goto done;
977 }
978
979 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
980 if (!cmdptr) {
8ff12da1 981 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
876c9d3a
MT
982 goto done;
983 }
984
985 /* Exit_PS command needs to be queued in the header always. */
c2df2efe 986 if (le16_to_cpu(cmdptr->command) == CMD_802_11_PS_MODE) {
876c9d3a 987 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
0aef64d7 988 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
aa21c004 989 if (priv->psstate != PS_STATE_FULL_POWER)
876c9d3a
MT
990 addtail = 0;
991 }
992 }
993
aa21c004 994 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 995
ac47246e 996 if (addtail)
aa21c004 997 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
ac47246e 998 else
aa21c004 999 list_add(&cmdnode->list, &priv->cmdpendingq);
876c9d3a 1000
aa21c004 1001 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 1002
8ff12da1 1003 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
981f187b 1004 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
876c9d3a
MT
1005
1006done:
8ff12da1 1007 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1008}
1009
1010/*
1011 * TODO: Fix the issue when DownloadcommandToStation is being called the
8ff12da1 1012 * second time when the command times out. All the cmdptr->xxx are in little
876c9d3a
MT
1013 * endian and therefore all the comparissions will fail.
1014 * For now - we are not performing the endian conversion the second time - but
1015 * for PS and DEEP_SLEEP we need to worry
1016 */
69f9032d 1017static int DownloadcommandToStation(struct lbs_private *priv,
876c9d3a
MT
1018 struct cmd_ctrl_node *cmdnode)
1019{
1020 unsigned long flags;
1021 struct cmd_ds_command *cmdptr;
b031ac10 1022 int ret = -1;
876c9d3a
MT
1023 u16 cmdsize;
1024 u16 command;
1025
8ff12da1 1026 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1027
aa21c004
DW
1028 if (!priv || !cmdnode) {
1029 lbs_deb_host("DNLD_CMD: priv or cmdmode is NULL\n");
876c9d3a
MT
1030 goto done;
1031 }
1032
1033 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1034
aa21c004 1035 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 1036 if (!cmdptr || !cmdptr->size) {
8ff12da1 1037 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
10078321 1038 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
aa21c004 1039 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1040 goto done;
1041 }
1042
aa21c004
DW
1043 priv->cur_cmd = cmdnode;
1044 priv->cur_cmd_retcode = 0;
1045 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 1046
c2df2efe
HS
1047 cmdsize = le16_to_cpu(cmdptr->size);
1048 command = le16_to_cpu(cmdptr->command);
876c9d3a 1049
8ff12da1 1050 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
c2df2efe 1051 command, cmdsize, jiffies);
8ff12da1
HS
1052 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
1053
876c9d3a 1054 cmdnode->cmdwaitqwoken = 0;
876c9d3a 1055
208fdd2f 1056 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
876c9d3a
MT
1057
1058 if (ret != 0) {
8ff12da1 1059 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
aa21c004
DW
1060 spin_lock_irqsave(&priv->driver_lock, flags);
1061 priv->cur_cmd_retcode = ret;
1062 __lbs_cleanup_and_insert_cmd(priv, priv->cur_cmd);
1063 priv->cur_cmd = NULL;
1064 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1065 goto done;
1066 }
1067
8ff12da1 1068 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
876c9d3a
MT
1069
1070 /* Setup the timer after transmit command */
0aef64d7
DW
1071 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1072 || command == CMD_802_11_ASSOCIATE)
aa21c004 1073 mod_timer(&priv->command_timer, jiffies + (10*HZ));
876c9d3a 1074 else
aa21c004 1075 mod_timer(&priv->command_timer, jiffies + (5*HZ));
876c9d3a
MT
1076
1077 ret = 0;
1078
9012b28a 1079done:
8ff12da1 1080 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
876c9d3a
MT
1081 return ret;
1082}
1083
69f9032d 1084static int lbs_cmd_mac_control(struct lbs_private *priv,
876c9d3a
MT
1085 struct cmd_ds_command *cmd)
1086{
1087 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1088
9012b28a 1089 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1090
0aef64d7 1091 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
981f187b 1092 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
aa21c004 1093 mac->action = cpu_to_le16(priv->currentpacketfilter);
876c9d3a 1094
8ff12da1 1095 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
981f187b 1096 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
876c9d3a 1097
9012b28a 1098 lbs_deb_leave(LBS_DEB_CMD);
876c9d3a
MT
1099 return 0;
1100}
1101
1102/**
1103 * This function inserts command node to cmdfreeq
aa21c004 1104 * after cleans it. Requires priv->driver_lock held.
876c9d3a 1105 */
69f9032d
HS
1106void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1107 struct cmd_ctrl_node *ptempcmd)
876c9d3a 1108{
876c9d3a
MT
1109
1110 if (!ptempcmd)
8ff12da1 1111 return;
876c9d3a
MT
1112
1113 cleanup_cmdnode(ptempcmd);
aa21c004 1114 list_add_tail(&ptempcmd->list, &priv->cmdfreeq);
876c9d3a
MT
1115}
1116
69f9032d
HS
1117static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1118 struct cmd_ctrl_node *ptempcmd)
876c9d3a
MT
1119{
1120 unsigned long flags;
1121
aa21c004 1122 spin_lock_irqsave(&priv->driver_lock, flags);
10078321 1123 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
aa21c004 1124 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1125}
1126
69f9032d 1127int lbs_set_radio_control(struct lbs_private *priv)
876c9d3a
MT
1128{
1129 int ret = 0;
1130
9012b28a 1131 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1132
10078321 1133 ret = lbs_prepare_and_send_command(priv,
0aef64d7
DW
1134 CMD_802_11_RADIO_CONTROL,
1135 CMD_ACT_SET,
1136 CMD_OPTION_WAITFORRSP, 0, NULL);
876c9d3a 1137
8ff12da1 1138 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
aa21c004 1139 priv->radioon, priv->preamble);
876c9d3a 1140
9012b28a 1141 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1142 return ret;
1143}
1144
69f9032d 1145int lbs_set_mac_packet_filter(struct lbs_private *priv)
876c9d3a
MT
1146{
1147 int ret = 0;
1148
9012b28a 1149 lbs_deb_enter(LBS_DEB_CMD);
876c9d3a 1150
876c9d3a 1151 /* Send MAC control command to station */
10078321 1152 ret = lbs_prepare_and_send_command(priv,
0aef64d7 1153 CMD_MAC_CONTROL, 0, 0, 0, NULL);
876c9d3a 1154
9012b28a 1155 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
876c9d3a
MT
1156 return ret;
1157}
1158
1159/**
1160 * @brief This function prepare the command before send to firmware.
1161 *
69f9032d 1162 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1163 * @param cmd_no command number
1164 * @param cmd_action command action: GET or SET
1165 * @param wait_option wait option: wait response or not
1166 * @param cmd_oid cmd oid: treated as sub command
1167 * @param pdata_buf A pointer to informaion buffer
1168 * @return 0 or -1
1169 */
69f9032d 1170int lbs_prepare_and_send_command(struct lbs_private *priv,
876c9d3a
MT
1171 u16 cmd_no,
1172 u16 cmd_action,
1173 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1174{
1175 int ret = 0;
876c9d3a
MT
1176 struct cmd_ctrl_node *cmdnode;
1177 struct cmd_ds_command *cmdptr;
1178 unsigned long flags;
1179
8ff12da1 1180 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1181
aa21c004
DW
1182 if (!priv) {
1183 lbs_deb_host("PREP_CMD: priv is NULL\n");
876c9d3a
MT
1184 ret = -1;
1185 goto done;
1186 }
1187
aa21c004 1188 if (priv->surpriseremoved) {
8ff12da1 1189 lbs_deb_host("PREP_CMD: card removed\n");
876c9d3a
MT
1190 ret = -1;
1191 goto done;
1192 }
1193
0d61d042 1194 cmdnode = lbs_get_cmd_ctrl_node(priv);
876c9d3a
MT
1195
1196 if (cmdnode == NULL) {
8ff12da1 1197 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
876c9d3a
MT
1198
1199 /* Wake up main thread to execute next command */
fe336150 1200 wake_up_interruptible(&priv->waitq);
876c9d3a
MT
1201 ret = -1;
1202 goto done;
1203 }
1204
f5ece8fc 1205 lbs_set_cmd_ctrl_node(priv, cmdnode, wait_option, pdata_buf);
876c9d3a
MT
1206
1207 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1208
8ff12da1 1209 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
876c9d3a
MT
1210
1211 if (!cmdptr) {
8ff12da1 1212 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
10078321 1213 lbs_cleanup_and_insert_cmd(priv, cmdnode);
876c9d3a
MT
1214 ret = -1;
1215 goto done;
1216 }
1217
1218 /* Set sequence number, command and INT option */
aa21c004
DW
1219 priv->seqnum++;
1220 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
876c9d3a 1221
981f187b 1222 cmdptr->command = cpu_to_le16(cmd_no);
876c9d3a
MT
1223 cmdptr->result = 0;
1224
1225 switch (cmd_no) {
0aef64d7 1226 case CMD_GET_HW_SPEC:
10078321 1227 ret = lbs_cmd_hw_spec(priv, cmdptr);
876c9d3a 1228 break;
0aef64d7 1229 case CMD_802_11_PS_MODE:
10078321 1230 ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
876c9d3a
MT
1231 break;
1232
0aef64d7 1233 case CMD_802_11_SCAN:
10078321 1234 ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
876c9d3a
MT
1235 break;
1236
0aef64d7 1237 case CMD_MAC_CONTROL:
10078321 1238 ret = lbs_cmd_mac_control(priv, cmdptr);
876c9d3a
MT
1239 break;
1240
0aef64d7
DW
1241 case CMD_802_11_ASSOCIATE:
1242 case CMD_802_11_REASSOCIATE:
10078321 1243 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
876c9d3a
MT
1244 break;
1245
0aef64d7 1246 case CMD_802_11_DEAUTHENTICATE:
10078321 1247 ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
876c9d3a
MT
1248 break;
1249
0aef64d7 1250 case CMD_802_11_SET_WEP:
10078321 1251 ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
876c9d3a
MT
1252 break;
1253
0aef64d7 1254 case CMD_802_11_AD_HOC_START:
10078321 1255 ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
876c9d3a 1256 break;
0aef64d7 1257 case CMD_CODE_DNLD:
876c9d3a
MT
1258 break;
1259
0aef64d7 1260 case CMD_802_11_RESET:
10078321 1261 ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
876c9d3a
MT
1262 break;
1263
0aef64d7 1264 case CMD_802_11_GET_LOG:
10078321 1265 ret = lbs_cmd_802_11_get_log(priv, cmdptr);
876c9d3a
MT
1266 break;
1267
0aef64d7 1268 case CMD_802_11_AUTHENTICATE:
10078321 1269 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
876c9d3a
MT
1270 break;
1271
0aef64d7 1272 case CMD_802_11_GET_STAT:
10078321 1273 ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
876c9d3a
MT
1274 break;
1275
0aef64d7 1276 case CMD_802_11_SNMP_MIB:
10078321 1277 ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
876c9d3a
MT
1278 cmd_action, cmd_oid, pdata_buf);
1279 break;
1280
0aef64d7
DW
1281 case CMD_MAC_REG_ACCESS:
1282 case CMD_BBP_REG_ACCESS:
1283 case CMD_RF_REG_ACCESS:
10078321 1284 ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
876c9d3a
MT
1285 break;
1286
0aef64d7 1287 case CMD_802_11_RF_CHANNEL:
10078321 1288 ret = lbs_cmd_802_11_rf_channel(priv, cmdptr,
876c9d3a
MT
1289 cmd_action, pdata_buf);
1290 break;
1291
0aef64d7 1292 case CMD_802_11_RF_TX_POWER:
10078321 1293 ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
876c9d3a
MT
1294 cmd_action, pdata_buf);
1295 break;
1296
0aef64d7 1297 case CMD_802_11_RADIO_CONTROL:
10078321 1298 ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
876c9d3a
MT
1299 break;
1300
0aef64d7 1301 case CMD_802_11_DATA_RATE:
10078321 1302 ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
876c9d3a 1303 break;
0aef64d7 1304 case CMD_802_11_RATE_ADAPT_RATESET:
10078321 1305 ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
876c9d3a
MT
1306 cmdptr, cmd_action);
1307 break;
1308
0aef64d7 1309 case CMD_MAC_MULTICAST_ADR:
10078321 1310 ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
876c9d3a
MT
1311 break;
1312
965f8bbc 1313 case CMD_802_11_MONITOR_MODE:
10078321 1314 ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
965f8bbc
LCC
1315 cmd_action, pdata_buf);
1316 break;
1317
0aef64d7 1318 case CMD_802_11_AD_HOC_JOIN:
10078321 1319 ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
876c9d3a
MT
1320 break;
1321
0aef64d7 1322 case CMD_802_11_RSSI:
10078321 1323 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
876c9d3a
MT
1324 break;
1325
0aef64d7 1326 case CMD_802_11_AD_HOC_STOP:
10078321 1327 ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
876c9d3a
MT
1328 break;
1329
0aef64d7 1330 case CMD_802_11_ENABLE_RSN:
10078321 1331 ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
90a42210 1332 pdata_buf);
876c9d3a
MT
1333 break;
1334
0aef64d7 1335 case CMD_802_11_KEY_MATERIAL:
10078321 1336 ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
90a42210 1337 cmd_oid, pdata_buf);
876c9d3a
MT
1338 break;
1339
0aef64d7 1340 case CMD_802_11_PAIRWISE_TSC:
876c9d3a 1341 break;
0aef64d7 1342 case CMD_802_11_GROUP_TSC:
876c9d3a
MT
1343 break;
1344
0aef64d7 1345 case CMD_802_11_MAC_ADDRESS:
10078321 1346 ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
876c9d3a
MT
1347 break;
1348
0aef64d7 1349 case CMD_802_11_EEPROM_ACCESS:
10078321 1350 ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
876c9d3a
MT
1351 cmd_action, pdata_buf);
1352 break;
1353
0aef64d7
DW
1354 case CMD_802_11_SET_AFC:
1355 case CMD_802_11_GET_AFC:
876c9d3a
MT
1356
1357 cmdptr->command = cpu_to_le16(cmd_no);
981f187b
DW
1358 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1359 S_DS_GEN);
876c9d3a
MT
1360
1361 memmove(&cmdptr->params.afc,
1362 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1363
1364 ret = 0;
1365 goto done;
1366
0aef64d7 1367 case CMD_802_11D_DOMAIN_INFO:
10078321 1368 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
876c9d3a
MT
1369 cmd_no, cmd_action);
1370 break;
1371
0aef64d7 1372 case CMD_802_11_SLEEP_PARAMS:
10078321 1373 ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
876c9d3a 1374 break;
0aef64d7 1375 case CMD_802_11_INACTIVITY_TIMEOUT:
10078321 1376 ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
876c9d3a 1377 cmd_action, pdata_buf);
f5ece8fc 1378 lbs_set_cmd_ctrl_node(priv, cmdnode, 0, pdata_buf);
876c9d3a
MT
1379 break;
1380
0aef64d7
DW
1381 case CMD_802_11_TPC_CFG:
1382 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
876c9d3a
MT
1383 cmdptr->size =
1384 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1385 S_DS_GEN);
1386
1387 memmove(&cmdptr->params.tpccfg,
1388 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1389
1390 ret = 0;
1391 break;
0aef64d7 1392 case CMD_802_11_LED_GPIO_CTRL:
876c9d3a
MT
1393 {
1394 struct mrvlietypes_ledgpio *gpio =
1395 (struct mrvlietypes_ledgpio*)
1396 cmdptr->params.ledgpio.data;
1397
1398 memmove(&cmdptr->params.ledgpio,
1399 pdata_buf,
1400 sizeof(struct cmd_ds_802_11_led_ctrl));
1401
1402 cmdptr->command =
0aef64d7 1403 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
876c9d3a
MT
1404
1405#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1406 cmdptr->size =
c2df2efe
HS
1407 cpu_to_le16(le16_to_cpu(gpio->header.len)
1408 + S_DS_GEN
1409 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1410 gpio->header.len = gpio->header.len;
876c9d3a
MT
1411
1412 ret = 0;
1413 break;
1414 }
3a188649
HS
1415 case CMD_802_11_SUBSCRIBE_EVENT:
1416 lbs_cmd_802_11_subscribe_event(priv, cmdptr,
1417 cmd_action, pdata_buf);
1418 break;
0aef64d7
DW
1419 case CMD_802_11_PWR_CFG:
1420 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
876c9d3a
MT
1421 cmdptr->size =
1422 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1423 S_DS_GEN);
1424 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1425 sizeof(struct cmd_ds_802_11_pwr_cfg));
1426
1427 ret = 0;
1428 break;
0aef64d7 1429 case CMD_BT_ACCESS:
10078321 1430 ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
876c9d3a
MT
1431 break;
1432
0aef64d7 1433 case CMD_FWT_ACCESS:
10078321 1434 ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
876c9d3a
MT
1435 break;
1436
0aef64d7 1437 case CMD_MESH_ACCESS:
10078321 1438 ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
876c9d3a
MT
1439 break;
1440
0aef64d7
DW
1441 case CMD_GET_TSF:
1442 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
981f187b
DW
1443 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1444 S_DS_GEN);
876c9d3a
MT
1445 ret = 0;
1446 break;
96287ac4
BD
1447 case CMD_802_11_BEACON_CTRL:
1448 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1449 break;
876c9d3a 1450 default:
8ff12da1 1451 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
876c9d3a
MT
1452 ret = -1;
1453 break;
1454 }
1455
1456 /* return error, since the command preparation failed */
1457 if (ret != 0) {
8ff12da1 1458 lbs_deb_host("PREP_CMD: command preparation failed\n");
10078321 1459 lbs_cleanup_and_insert_cmd(priv, cmdnode);
876c9d3a
MT
1460 ret = -1;
1461 goto done;
1462 }
1463
1464 cmdnode->cmdwaitqwoken = 0;
1465
aa21c004 1466 lbs_queue_cmd(priv, cmdnode, 1);
fe336150 1467 wake_up_interruptible(&priv->waitq);
876c9d3a 1468
0aef64d7 1469 if (wait_option & CMD_OPTION_WAITFORRSP) {
8ff12da1 1470 lbs_deb_host("PREP_CMD: wait for response\n");
876c9d3a
MT
1471 might_sleep();
1472 wait_event_interruptible(cmdnode->cmdwait_q,
1473 cmdnode->cmdwaitqwoken);
1474 }
1475
aa21c004
DW
1476 spin_lock_irqsave(&priv->driver_lock, flags);
1477 if (priv->cur_cmd_retcode) {
8ff12da1 1478 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
aa21c004
DW
1479 priv->cur_cmd_retcode);
1480 priv->cur_cmd_retcode = 0;
876c9d3a
MT
1481 ret = -1;
1482 }
aa21c004 1483 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1484
1485done:
8ff12da1 1486 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
876c9d3a
MT
1487 return ret;
1488}
10078321 1489EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
876c9d3a
MT
1490
1491/**
1492 * @brief This function allocates the command buffer and link
1493 * it to command free queue.
1494 *
69f9032d 1495 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1496 * @return 0 or -1
1497 */
69f9032d 1498int lbs_allocate_cmd_buffer(struct lbs_private *priv)
876c9d3a
MT
1499{
1500 int ret = 0;
1501 u32 ulbufsize;
1502 u32 i;
1503 struct cmd_ctrl_node *tempcmd_array;
1504 u8 *ptempvirtualaddr;
876c9d3a 1505
8ff12da1 1506 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
1507
1508 /* Allocate and initialize cmdCtrlNode */
1509 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1510
fb3dddf2 1511 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
8ff12da1 1512 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
876c9d3a
MT
1513 ret = -1;
1514 goto done;
1515 }
aa21c004 1516 priv->cmd_array = tempcmd_array;
876c9d3a
MT
1517
1518 /* Allocate and initialize command buffers */
1519 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1520 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
fb3dddf2 1521 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
8ff12da1 1522 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
876c9d3a
MT
1523 ret = -1;
1524 goto done;
1525 }
1526
876c9d3a
MT
1527 /* Update command buffer virtual */
1528 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1529 }
1530
1531 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1532 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
10078321 1533 lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
876c9d3a
MT
1534 }
1535
1536 ret = 0;
9012b28a
HS
1537
1538done:
8ff12da1 1539 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
876c9d3a
MT
1540 return ret;
1541}
1542
1543/**
1544 * @brief This function frees the command buffer.
1545 *
69f9032d 1546 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1547 * @return 0 or -1
1548 */
69f9032d 1549int lbs_free_cmd_buffer(struct lbs_private *priv)
876c9d3a 1550{
981f187b 1551 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
876c9d3a
MT
1552 unsigned int i;
1553 struct cmd_ctrl_node *tempcmd_array;
876c9d3a 1554
8ff12da1 1555 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
1556
1557 /* need to check if cmd array is allocated or not */
aa21c004 1558 if (priv->cmd_array == NULL) {
8ff12da1 1559 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
876c9d3a
MT
1560 goto done;
1561 }
1562
aa21c004 1563 tempcmd_array = priv->cmd_array;
876c9d3a
MT
1564
1565 /* Release shared memory buffers */
1566 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1567 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1568 if (tempcmd_array[i].bufvirtualaddr) {
876c9d3a
MT
1569 kfree(tempcmd_array[i].bufvirtualaddr);
1570 tempcmd_array[i].bufvirtualaddr = NULL;
1571 }
1572 }
1573
1574 /* Release cmd_ctrl_node */
aa21c004
DW
1575 if (priv->cmd_array) {
1576 kfree(priv->cmd_array);
1577 priv->cmd_array = NULL;
876c9d3a
MT
1578 }
1579
1580done:
8ff12da1 1581 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1582 return 0;
1583}
1584
1585/**
1586 * @brief This function gets a free command node if available in
1587 * command free queue.
1588 *
69f9032d 1589 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1590 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1591 */
0d61d042 1592struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
876c9d3a
MT
1593{
1594 struct cmd_ctrl_node *tempnode;
876c9d3a
MT
1595 unsigned long flags;
1596
8ff12da1
HS
1597 lbs_deb_enter(LBS_DEB_HOST);
1598
aa21c004 1599 if (!priv)
876c9d3a
MT
1600 return NULL;
1601
aa21c004 1602 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 1603
aa21c004
DW
1604 if (!list_empty(&priv->cmdfreeq)) {
1605 tempnode = list_first_entry(&priv->cmdfreeq,
abe3ed14
LZ
1606 struct cmd_ctrl_node, list);
1607 list_del(&tempnode->list);
876c9d3a 1608 } else {
8ff12da1 1609 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
876c9d3a
MT
1610 tempnode = NULL;
1611 }
1612
aa21c004 1613 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 1614
8ff12da1 1615 if (tempnode)
876c9d3a 1616 cleanup_cmdnode(tempnode);
876c9d3a 1617
8ff12da1 1618 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1619 return tempnode;
1620}
1621
1622/**
1623 * @brief This function cleans command node.
1624 *
1625 * @param ptempnode A pointer to cmdCtrlNode structure
1626 * @return n/a
1627 */
1628static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1629{
8ff12da1
HS
1630 lbs_deb_enter(LBS_DEB_HOST);
1631
876c9d3a
MT
1632 if (!ptempnode)
1633 return;
1634 ptempnode->cmdwaitqwoken = 1;
1635 wake_up_interruptible(&ptempnode->cmdwait_q);
876c9d3a
MT
1636 ptempnode->wait_option = 0;
1637 ptempnode->pdata_buf = NULL;
1723047d 1638 ptempnode->callback = NULL;
1309b55b 1639 ptempnode->callback_arg = 0;
876c9d3a
MT
1640
1641 if (ptempnode->bufvirtualaddr != NULL)
1642 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
8ff12da1
HS
1643
1644 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1645}
1646
1647/**
1648 * @brief This function initializes the command node.
1649 *
69f9032d 1650 * @param priv A pointer to struct lbs_private structure
876c9d3a 1651 * @param ptempnode A pointer to cmd_ctrl_node structure
876c9d3a
MT
1652 * @param wait_option wait option: wait response or not
1653 * @param pdata_buf A pointer to informaion buffer
1654 * @return 0 or -1
1655 */
69f9032d 1656void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
876c9d3a 1657 struct cmd_ctrl_node *ptempnode,
f5ece8fc 1658 u16 wait_option, void *pdata_buf)
876c9d3a 1659{
8ff12da1 1660 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
1661
1662 if (!ptempnode)
1663 return;
1664
876c9d3a
MT
1665 ptempnode->wait_option = wait_option;
1666 ptempnode->pdata_buf = pdata_buf;
1723047d 1667 ptempnode->callback = NULL;
1309b55b 1668 ptempnode->callback_arg = 0;
876c9d3a 1669
8ff12da1 1670 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1671}
1672
1673/**
1674 * @brief This function executes next command in command
1675 * pending queue. It will put fimware back to PS mode
1676 * if applicable.
1677 *
69f9032d 1678 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1679 * @return 0 or -1
1680 */
69f9032d 1681int lbs_execute_next_command(struct lbs_private *priv)
876c9d3a 1682{
876c9d3a
MT
1683 struct cmd_ctrl_node *cmdnode = NULL;
1684 struct cmd_ds_command *cmdptr;
1685 unsigned long flags;
1686 int ret = 0;
1687
8ff12da1 1688 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
10078321 1689 // only caller to us is lbs_thread() and we get even when a
8ff12da1
HS
1690 // data packet is received
1691 lbs_deb_enter(LBS_DEB_THREAD);
876c9d3a 1692
aa21c004 1693 spin_lock_irqsave(&priv->driver_lock, flags);
876c9d3a 1694
aa21c004 1695 if (priv->cur_cmd) {
8ff12da1 1696 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
aa21c004 1697 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1698 ret = -1;
1699 goto done;
1700 }
1701
aa21c004
DW
1702 if (!list_empty(&priv->cmdpendingq)) {
1703 cmdnode = list_first_entry(&priv->cmdpendingq,
abe3ed14 1704 struct cmd_ctrl_node, list);
876c9d3a
MT
1705 }
1706
aa21c004 1707 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1708
1709 if (cmdnode) {
876c9d3a
MT
1710 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1711
852e1f2a 1712 if (is_command_allowed_in_ps(le16_to_cpu(cmdptr->command))) {
aa21c004
DW
1713 if ((priv->psstate == PS_STATE_SLEEP) ||
1714 (priv->psstate == PS_STATE_PRE_SLEEP)) {
8ff12da1
HS
1715 lbs_deb_host(
1716 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
981f187b 1717 le16_to_cpu(cmdptr->command),
aa21c004 1718 priv->psstate);
876c9d3a
MT
1719 ret = -1;
1720 goto done;
1721 }
8ff12da1
HS
1722 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1723 "0x%04x in psstate %d\n",
981f187b 1724 le16_to_cpu(cmdptr->command),
aa21c004
DW
1725 priv->psstate);
1726 } else if (priv->psstate != PS_STATE_FULL_POWER) {
876c9d3a
MT
1727 /*
1728 * 1. Non-PS command:
1729 * Queue it. set needtowakeup to TRUE if current state
10078321 1730 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
876c9d3a
MT
1731 * 2. PS command but not Exit_PS:
1732 * Ignore it.
1733 * 3. PS command Exit_PS:
1734 * Set needtowakeup to TRUE if current state is SLEEP,
1735 * otherwise send this command down to firmware
1736 * immediately.
1737 */
1738 if (cmdptr->command !=
0aef64d7 1739 cpu_to_le16(CMD_802_11_PS_MODE)) {
876c9d3a
MT
1740 /* Prepare to send Exit PS,
1741 * this non PS command will be sent later */
aa21c004
DW
1742 if ((priv->psstate == PS_STATE_SLEEP)
1743 || (priv->psstate == PS_STATE_PRE_SLEEP)
876c9d3a
MT
1744 ) {
1745 /* w/ new scheme, it will not reach here.
1746 since it is blocked in main_thread. */
aa21c004 1747 priv->needtowakeup = 1;
876c9d3a 1748 } else
10078321 1749 lbs_ps_wakeup(priv, 0);
876c9d3a
MT
1750
1751 ret = 0;
1752 goto done;
1753 } else {
1754 /*
1755 * PS command. Ignore it if it is not Exit_PS.
1756 * otherwise send it down immediately.
1757 */
1758 struct cmd_ds_802_11_ps_mode *psm =
1759 &cmdptr->params.psmode;
1760
8ff12da1
HS
1761 lbs_deb_host(
1762 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
876c9d3a
MT
1763 psm->action);
1764 if (psm->action !=
0aef64d7 1765 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
8ff12da1
HS
1766 lbs_deb_host(
1767 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
abe3ed14 1768 list_del(&cmdnode->list);
10078321 1769 lbs_cleanup_and_insert_cmd(priv, cmdnode);
876c9d3a
MT
1770
1771 ret = 0;
1772 goto done;
1773 }
1774
aa21c004
DW
1775 if ((priv->psstate == PS_STATE_SLEEP) ||
1776 (priv->psstate == PS_STATE_PRE_SLEEP)) {
8ff12da1
HS
1777 lbs_deb_host(
1778 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
abe3ed14 1779 list_del(&cmdnode->list);
10078321 1780 lbs_cleanup_and_insert_cmd(priv, cmdnode);
aa21c004 1781 priv->needtowakeup = 1;
876c9d3a
MT
1782
1783 ret = 0;
1784 goto done;
1785 }
1786
8ff12da1
HS
1787 lbs_deb_host(
1788 "EXEC_NEXT_CMD: sending EXIT_PS\n");
876c9d3a
MT
1789 }
1790 }
abe3ed14 1791 list_del(&cmdnode->list);
8ff12da1 1792 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
981f187b 1793 le16_to_cpu(cmdptr->command));
876c9d3a
MT
1794 DownloadcommandToStation(priv, cmdnode);
1795 } else {
1796 /*
1797 * check if in power save mode, if yes, put the device back
1798 * to PS mode
1799 */
aa21c004
DW
1800 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1801 (priv->psstate == PS_STATE_FULL_POWER) &&
1802 ((priv->connect_status == LBS_CONNECTED) ||
1803 (priv->mesh_connect_status == LBS_CONNECTED))) {
1804 if (priv->secinfo.WPAenabled ||
1805 priv->secinfo.WPA2enabled) {
876c9d3a 1806 /* check for valid WPA group keys */
aa21c004
DW
1807 if (priv->wpa_mcast_key.len ||
1808 priv->wpa_unicast_key.len) {
8ff12da1 1809 lbs_deb_host(
876c9d3a
MT
1810 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1811 " go back to PS_SLEEP");
10078321 1812 lbs_ps_sleep(priv, 0);
876c9d3a
MT
1813 }
1814 } else {
8ff12da1
HS
1815 lbs_deb_host(
1816 "EXEC_NEXT_CMD: cmdpendingq empty, "
1817 "go back to PS_SLEEP");
10078321 1818 lbs_ps_sleep(priv, 0);
876c9d3a
MT
1819 }
1820 }
1821 }
1822
1823 ret = 0;
1824done:
8ff12da1 1825 lbs_deb_leave(LBS_DEB_THREAD);
876c9d3a
MT
1826 return ret;
1827}
1828
69f9032d 1829void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
876c9d3a
MT
1830{
1831 union iwreq_data iwrq;
1832 u8 buf[50];
1833
8ff12da1 1834 lbs_deb_enter(LBS_DEB_WEXT);
876c9d3a
MT
1835
1836 memset(&iwrq, 0, sizeof(union iwreq_data));
1837 memset(buf, 0, sizeof(buf));
1838
1839 snprintf(buf, sizeof(buf) - 1, "%s", str);
1840
1841 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1842
1843 /* Send Event to upper layer */
8ff12da1
HS
1844 lbs_deb_wext("event indication string %s\n", (char *)buf);
1845 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1846 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
876c9d3a 1847
634b8f49 1848 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
876c9d3a 1849
8ff12da1 1850 lbs_deb_leave(LBS_DEB_WEXT);
876c9d3a
MT
1851}
1852
69f9032d 1853static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
876c9d3a
MT
1854{
1855 unsigned long flags;
876c9d3a
MT
1856 int ret = 0;
1857
8ff12da1 1858 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1859
8ff12da1 1860 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
876c9d3a
MT
1861 size);
1862
8ff12da1 1863 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
876c9d3a 1864
208fdd2f 1865 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
634b8f49 1866 priv->dnld_sent = DNLD_RES_RECEIVED;
876c9d3a 1867
aa21c004
DW
1868 spin_lock_irqsave(&priv->driver_lock, flags);
1869 if (priv->intcounter || priv->currenttxskb)
8ff12da1 1870 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
aa21c004
DW
1871 priv->intcounter, priv->currenttxskb);
1872 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1873
1874 if (ret) {
1875 lbs_pr_alert(
1876 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1877 } else {
aa21c004
DW
1878 spin_lock_irqsave(&priv->driver_lock, flags);
1879 if (!priv->intcounter) {
1880 priv->psstate = PS_STATE_SLEEP;
876c9d3a 1881 } else {
8ff12da1 1882 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
aa21c004 1883 priv->intcounter);
876c9d3a 1884 }
aa21c004 1885 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a 1886
8ff12da1 1887 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
876c9d3a
MT
1888 }
1889
8ff12da1 1890 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
876c9d3a
MT
1891 return ret;
1892}
1893
69f9032d 1894void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
876c9d3a 1895{
8ff12da1 1896 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a
MT
1897
1898 /*
1899 * PS is currently supported only in Infrastructure mode
1900 * Remove this check if it is to be supported in IBSS mode also
1901 */
1902
10078321 1903 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
0aef64d7 1904 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
876c9d3a 1905
8ff12da1 1906 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1907}
1908
1909/**
8ff12da1 1910 * @brief This function sends Exit_PS command to firmware.
876c9d3a 1911 *
69f9032d 1912 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1913 * @param wait_option wait response or not
1914 * @return n/a
1915 */
69f9032d 1916void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
876c9d3a 1917{
981f187b 1918 __le32 Localpsmode;
876c9d3a 1919
8ff12da1 1920 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1921
10078321 1922 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
876c9d3a 1923
10078321 1924 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
0aef64d7 1925 CMD_SUBCMD_EXIT_PS,
876c9d3a
MT
1926 wait_option, 0, &Localpsmode);
1927
8ff12da1 1928 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a
MT
1929}
1930
1931/**
1932 * @brief This function checks condition and prepares to
1933 * send sleep confirm command to firmware if ok.
1934 *
69f9032d 1935 * @param priv A pointer to struct lbs_private structure
876c9d3a
MT
1936 * @param psmode Power Saving mode
1937 * @return n/a
1938 */
69f9032d 1939void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
876c9d3a
MT
1940{
1941 unsigned long flags =0;
876c9d3a
MT
1942 u8 allowed = 1;
1943
8ff12da1 1944 lbs_deb_enter(LBS_DEB_HOST);
876c9d3a 1945
634b8f49 1946 if (priv->dnld_sent) {
876c9d3a 1947 allowed = 0;
8ff12da1 1948 lbs_deb_host("dnld_sent was set");
876c9d3a
MT
1949 }
1950
aa21c004
DW
1951 spin_lock_irqsave(&priv->driver_lock, flags);
1952 if (priv->cur_cmd) {
876c9d3a 1953 allowed = 0;
8ff12da1 1954 lbs_deb_host("cur_cmd was set");
876c9d3a 1955 }
aa21c004 1956 if (priv->intcounter > 0) {
876c9d3a 1957 allowed = 0;
aa21c004 1958 lbs_deb_host("intcounter %d", priv->intcounter);
876c9d3a 1959 }
aa21c004 1960 spin_unlock_irqrestore(&priv->driver_lock, flags);
876c9d3a
MT
1961
1962 if (allowed) {
10078321 1963 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
aa21c004 1964 sendconfirmsleep(priv, (u8 *) & priv->lbs_ps_confirm_sleep,
876c9d3a
MT
1965 sizeof(struct PS_CMD_ConfirmSleep));
1966 } else {
8ff12da1 1967 lbs_deb_host("sleep confirm has been delayed\n");
876c9d3a
MT
1968 }
1969
8ff12da1 1970 lbs_deb_leave(LBS_DEB_HOST);
876c9d3a 1971}
675787e2
HS
1972
1973
a8bdcd71
DW
1974/**
1975 * @brief Simple callback that copies response back into command
1976 *
1977 * @param priv A pointer to struct lbs_private structure
1978 * @param extra A pointer to the original command structure for which
1979 * 'resp' is a response
1980 * @param resp A pointer to the command response
1981 *
1982 * @return 0 on success, error on failure
1983 */
1984int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
1985 struct cmd_header *resp)
1986{
1987 struct cmd_header *buf = (void *)extra;
1988 uint16_t copy_len;
1989
1990 lbs_deb_enter(LBS_DEB_CMD);
1991
1992 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
1993 lbs_deb_cmd("Copying back %u bytes; command response was %u bytes, "
1994 "copy back buffer was %u bytes", copy_len, resp->size,
1995 buf->size);
1996 memcpy(buf, resp, copy_len);
1997
1998 lbs_deb_leave(LBS_DEB_CMD);
1999 return 0;
2000}
2001
675787e2
HS
2002/**
2003 * @brief Simple way to call firmware functions
2004 *
2005 * @param priv A pointer to struct lbs_private structure
2006 * @param psmode one of the many CMD_802_11_xxxx
2007 * @param cmd pointer to the parameters structure for above command
2008 * (this should not include the command, size, sequence
2009 * and result fields from struct cmd_ds_gen)
2010 * @param cmd_size size structure pointed to by cmd
2011 * @param rsp pointer to an area where the result should be placed
2012 * @param rsp_size pointer to the size of the rsp area. If the firmware
2013 * returns fewer bytes, then this *rsp_size will be
2014 * changed to the actual size.
2015 * @return -1 in case of a higher level error, otherwise
2016 * the result code from the firmware
2017 */
7ad994de
DW
2018int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2019 struct cmd_header *in_cmd, int in_cmd_size,
2020 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
14e865ba 2021 unsigned long callback_arg)
675787e2 2022{
675787e2 2023 struct cmd_ctrl_node *cmdnode;
7ad994de 2024 struct cmd_header *send_cmd;
675787e2
HS
2025 unsigned long flags;
2026 int ret = 0;
2027
2028 lbs_deb_enter(LBS_DEB_HOST);
675787e2 2029
aa21c004
DW
2030 if (!priv) {
2031 lbs_deb_host("PREP_CMD: priv is NULL\n");
675787e2
HS
2032 ret = -1;
2033 goto done;
2034 }
2035
aa21c004 2036 if (priv->surpriseremoved) {
675787e2
HS
2037 lbs_deb_host("PREP_CMD: card removed\n");
2038 ret = -1;
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);
2048 ret = -1;
2049 goto done;
2050 }
2051
7ad994de 2052 send_cmd = (struct cmd_header *) cmdnode->bufvirtualaddr;
675787e2 2053 cmdnode->wait_option = CMD_OPTION_WAITFORRSP;
448a51ae 2054 cmdnode->callback = callback;
1309b55b 2055 cmdnode->callback_arg = callback_arg;
675787e2 2056
7ad994de
DW
2057 /* Copy the incoming command to the buffer */
2058 memcpy(send_cmd, in_cmd, in_cmd_size);
2059
675787e2 2060 /* Set sequence number, clean result, move to buffer */
aa21c004 2061 priv->seqnum++;
7ad994de
DW
2062 send_cmd->command = cpu_to_le16(command);
2063 send_cmd->size = cpu_to_le16(in_cmd_size);
2064 send_cmd->seqnum = cpu_to_le16(priv->seqnum);
2065 send_cmd->result = 0;
675787e2
HS
2066
2067 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2068
2069 /* here was the big old switch() statement, which is now obsolete,
2070 * because the caller of lbs_cmd() sets up all of *cmd for us. */
2071
2072 cmdnode->cmdwaitqwoken = 0;
aa21c004 2073 lbs_queue_cmd(priv, cmdnode, 1);
675787e2
HS
2074 wake_up_interruptible(&priv->waitq);
2075
2076 might_sleep();
2077 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2078
aa21c004
DW
2079 spin_lock_irqsave(&priv->driver_lock, flags);
2080 if (priv->cur_cmd_retcode) {
675787e2 2081 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
aa21c004
DW
2082 priv->cur_cmd_retcode);
2083 priv->cur_cmd_retcode = 0;
675787e2
HS
2084 ret = -1;
2085 }
aa21c004 2086 spin_unlock_irqrestore(&priv->driver_lock, flags);
675787e2
HS
2087
2088done:
2089 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2090 return ret;
2091}
14e865ba 2092EXPORT_SYMBOL_GPL(__lbs_cmd);
675787e2
HS
2093
2094
This page took 0.431792 seconds and 5 git commands to generate.