2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <net/iw_handler.h>
15 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode);
16 struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
17 void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
18 struct cmd_ctrl_node *ptempnode,
19 u16 wait_option, void *pdata_buf);
23 * @brief Checks whether a command is allowed in Power Save mode
25 * @param command the command ID
26 * @return 1 if allowed, 0 if not allowed
28 static u8 is_command_allowed_in_ps(u16 cmd)
39 static int lbs_cmd_hw_spec(struct lbs_private *priv, struct cmd_ds_command *cmd)
41 struct cmd_ds_get_hw_spec *hwspec = &cmd->params.hwspec;
43 lbs_deb_enter(LBS_DEB_CMD);
45 cmd->command = cpu_to_le16(CMD_GET_HW_SPEC);
46 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_get_hw_spec) + S_DS_GEN);
47 memcpy(hwspec->permanentaddr, priv->current_addr, ETH_ALEN);
49 lbs_deb_leave(LBS_DEB_CMD);
53 static int lbs_cmd_802_11_ps_mode(struct lbs_private *priv,
54 struct cmd_ds_command *cmd,
57 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
59 lbs_deb_enter(LBS_DEB_CMD);
61 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
62 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
64 psm->action = cpu_to_le16(cmd_action);
65 psm->multipledtim = 0;
67 case CMD_SUBCMD_ENTER_PS:
68 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
70 psm->locallisteninterval = 0;
71 psm->nullpktinterval = 0;
73 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
76 case CMD_SUBCMD_EXIT_PS:
77 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
80 case CMD_SUBCMD_SLEEP_CONFIRMED:
81 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
88 lbs_deb_leave(LBS_DEB_CMD);
92 static int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
93 struct cmd_ds_command *cmd,
94 u16 cmd_action, void *pdata_buf)
96 u16 *timeout = pdata_buf;
98 lbs_deb_enter(LBS_DEB_CMD);
100 cmd->command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
102 cpu_to_le16(sizeof(struct cmd_ds_802_11_inactivity_timeout)
105 cmd->params.inactivity_timeout.action = cpu_to_le16(cmd_action);
108 cmd->params.inactivity_timeout.timeout = cpu_to_le16(*timeout);
110 cmd->params.inactivity_timeout.timeout = 0;
112 lbs_deb_leave(LBS_DEB_CMD);
116 static int lbs_cmd_802_11_sleep_params(struct lbs_private *priv,
117 struct cmd_ds_command *cmd,
120 struct cmd_ds_802_11_sleep_params *sp = &cmd->params.sleep_params;
122 lbs_deb_enter(LBS_DEB_CMD);
124 cmd->size = cpu_to_le16((sizeof(struct cmd_ds_802_11_sleep_params)) +
126 cmd->command = cpu_to_le16(CMD_802_11_SLEEP_PARAMS);
128 if (cmd_action == CMD_ACT_GET) {
129 memset(&priv->sp, 0, sizeof(struct sleep_params));
130 memset(sp, 0, sizeof(struct cmd_ds_802_11_sleep_params));
131 sp->action = cpu_to_le16(cmd_action);
132 } else if (cmd_action == CMD_ACT_SET) {
133 sp->action = cpu_to_le16(cmd_action);
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);
142 lbs_deb_leave(LBS_DEB_CMD);
146 static int lbs_cmd_802_11_set_wep(struct lbs_private *priv,
147 struct cmd_ds_command *cmd,
151 struct cmd_ds_802_11_set_wep *wep = &cmd->params.wep;
153 struct assoc_request * assoc_req = pdata_buf;
155 lbs_deb_enter(LBS_DEB_CMD);
157 cmd->command = cpu_to_le16(CMD_802_11_SET_WEP);
158 cmd->size = cpu_to_le16(sizeof(*wep) + S_DS_GEN);
160 if (cmd_act == CMD_ACT_ADD) {
164 lbs_deb_cmd("Invalid association request!");
169 wep->action = cpu_to_le16(CMD_ACT_ADD);
171 /* default tx key index */
172 wep->keyindex = cpu_to_le16((u16)(assoc_req->wep_tx_keyidx &
173 (u32)CMD_WEP_KEY_INDEX_MASK));
175 /* Copy key types and material to host command structure */
176 for (i = 0; i < 4; i++) {
177 struct enc_key * pkey = &assoc_req->wep_keys[i];
181 wep->keytype[i] = CMD_TYPE_WEP_40_BIT;
182 memmove(&wep->keymaterial[i], pkey->key,
184 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
186 case KEY_LEN_WEP_104:
187 wep->keytype[i] = CMD_TYPE_WEP_104_BIT;
188 memmove(&wep->keymaterial[i], pkey->key,
190 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
195 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
202 } else if (cmd_act == CMD_ACT_REMOVE) {
203 /* ACT_REMOVE clears _all_ WEP keys */
204 wep->action = cpu_to_le16(CMD_ACT_REMOVE);
206 /* default tx key index */
207 wep->keyindex = cpu_to_le16((u16)(priv->wep_tx_keyidx &
208 (u32)CMD_WEP_KEY_INDEX_MASK));
209 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
215 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
219 static int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv,
220 struct cmd_ds_command *cmd,
224 struct cmd_ds_802_11_enable_rsn *penableRSN = &cmd->params.enbrsn;
225 u32 * enable = pdata_buf;
227 lbs_deb_enter(LBS_DEB_CMD);
229 cmd->command = cpu_to_le16(CMD_802_11_ENABLE_RSN);
230 cmd->size = cpu_to_le16(sizeof(*penableRSN) + S_DS_GEN);
231 penableRSN->action = cpu_to_le16(cmd_action);
233 if (cmd_action == CMD_ACT_SET) {
235 penableRSN->enable = cpu_to_le16(CMD_ENABLE_RSN);
237 penableRSN->enable = cpu_to_le16(CMD_DISABLE_RSN);
238 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
241 lbs_deb_leave(LBS_DEB_CMD);
246 static ssize_t lbs_tlv_size(const u8 *tlv, u16 size)
249 struct mrvlietypesheader *tlv_h;
252 tlv_h = (struct mrvlietypesheader *) tlv;
255 length = le16_to_cpu(tlv_h->len) +
256 sizeof(struct mrvlietypesheader);
264 static void lbs_cmd_802_11_subscribe_event(struct lbs_private *priv,
265 struct cmd_ds_command *cmd, u16 cmd_action,
268 struct cmd_ds_802_11_subscribe_event *events =
269 (struct cmd_ds_802_11_subscribe_event *) pdata_buf;
271 /* pdata_buf points to a struct cmd_ds_802_11_subscribe_event and room
272 * for various Marvell TLVs */
274 lbs_deb_enter(LBS_DEB_CMD);
276 cmd->size = cpu_to_le16(sizeof(*events)
277 - sizeof(events->tlv)
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;
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);
289 lbs_deb_leave(LBS_DEB_CMD);
292 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet * pkeyparamset,
293 struct enc_key * pkey)
295 lbs_deb_enter(LBS_DEB_CMD);
297 if (pkey->flags & KEY_INFO_WPA_ENABLED) {
298 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
300 if (pkey->flags & KEY_INFO_WPA_UNICAST) {
301 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
303 if (pkey->flags & KEY_INFO_WPA_MCAST) {
304 pkeyparamset->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
307 pkeyparamset->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
308 pkeyparamset->keytypeid = cpu_to_le16(pkey->type);
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));
315 lbs_deb_leave(LBS_DEB_CMD);
318 static int lbs_cmd_802_11_key_material(struct lbs_private *priv,
319 struct cmd_ds_command *cmd,
321 u32 cmd_oid, void *pdata_buf)
323 struct cmd_ds_802_11_key_material *pkeymaterial =
324 &cmd->params.keymaterial;
325 struct assoc_request * assoc_req = pdata_buf;
329 lbs_deb_enter(LBS_DEB_CMD);
331 cmd->command = cpu_to_le16(CMD_802_11_KEY_MATERIAL);
332 pkeymaterial->action = cpu_to_le16(cmd_action);
334 if (cmd_action == CMD_ACT_GET) {
335 cmd->size = cpu_to_le16(S_DS_GEN + sizeof (pkeymaterial->action));
340 memset(&pkeymaterial->keyParamSet, 0, sizeof(pkeymaterial->keyParamSet));
342 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags)) {
343 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
344 &assoc_req->wpa_unicast_key);
348 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags)) {
349 set_one_wpa_key(&pkeymaterial->keyParamSet[index],
350 &assoc_req->wpa_mcast_key);
354 cmd->size = cpu_to_le16( S_DS_GEN
355 + sizeof (pkeymaterial->action)
356 + (index * sizeof(struct MrvlIEtype_keyParamSet)));
361 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
365 static int lbs_cmd_802_11_reset(struct lbs_private *priv,
366 struct cmd_ds_command *cmd, int cmd_action)
368 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
370 lbs_deb_enter(LBS_DEB_CMD);
372 cmd->command = cpu_to_le16(CMD_802_11_RESET);
373 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
374 reset->action = cpu_to_le16(cmd_action);
376 lbs_deb_leave(LBS_DEB_CMD);
380 static int lbs_cmd_802_11_get_log(struct lbs_private *priv,
381 struct cmd_ds_command *cmd)
383 lbs_deb_enter(LBS_DEB_CMD);
384 cmd->command = cpu_to_le16(CMD_802_11_GET_LOG);
386 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_log) + S_DS_GEN);
388 lbs_deb_leave(LBS_DEB_CMD);
392 static int lbs_cmd_802_11_get_stat(struct lbs_private *priv,
393 struct cmd_ds_command *cmd)
395 lbs_deb_enter(LBS_DEB_CMD);
396 cmd->command = cpu_to_le16(CMD_802_11_GET_STAT);
398 cpu_to_le16(sizeof(struct cmd_ds_802_11_get_stat) + S_DS_GEN);
400 lbs_deb_leave(LBS_DEB_CMD);
404 static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
405 struct cmd_ds_command *cmd,
407 int cmd_oid, void *pdata_buf)
409 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
412 lbs_deb_enter(LBS_DEB_CMD);
414 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
416 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
417 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
420 case OID_802_11_INFRASTRUCTURE_MODE:
422 u8 mode = (u8) (size_t) pdata_buf;
423 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
424 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
425 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
426 if (mode == IW_MODE_ADHOC) {
427 ucTemp = SNMP_MIB_VALUE_ADHOC;
429 /* Infra and Auto modes */
430 ucTemp = SNMP_MIB_VALUE_INFRA;
433 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
438 case OID_802_11D_ENABLE:
442 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
444 if (cmd_action == CMD_ACT_SET) {
445 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
446 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
447 ulTemp = *(u32 *)pdata_buf;
448 *((__le16 *)(pSNMPMIB->value)) =
449 cpu_to_le16((u16) ulTemp);
454 case OID_802_11_FRAGMENTATION_THRESHOLD:
458 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
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);
464 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
465 ulTemp = *((u32 *) pdata_buf);
466 *((__le16 *)(pSNMPMIB->value)) =
467 cpu_to_le16((u16) ulTemp);
474 case OID_802_11_RTS_THRESHOLD:
478 pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
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);
484 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
485 ulTemp = *((u32 *)pdata_buf);
486 *(__le16 *)(pSNMPMIB->value) =
487 cpu_to_le16((u16) ulTemp);
492 case OID_802_11_TX_RETRYCOUNT:
493 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
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);
499 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
500 *((__le16 *)(pSNMPMIB->value)) =
501 cpu_to_le16((u16) priv->txretrycount);
510 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
511 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
512 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
515 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
516 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
517 le16_to_cpu(pSNMPMIB->bufsize),
518 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
520 lbs_deb_leave(LBS_DEB_CMD);
524 static int lbs_cmd_802_11_radio_control(struct lbs_private *priv,
525 struct cmd_ds_command *cmd,
528 struct cmd_ds_802_11_radio_control *pradiocontrol = &cmd->params.radio;
530 lbs_deb_enter(LBS_DEB_CMD);
533 cpu_to_le16((sizeof(struct cmd_ds_802_11_radio_control)) +
535 cmd->command = cpu_to_le16(CMD_802_11_RADIO_CONTROL);
537 pradiocontrol->action = cpu_to_le16(cmd_action);
539 switch (priv->preamble) {
540 case CMD_TYPE_SHORT_PREAMBLE:
541 pradiocontrol->control = cpu_to_le16(SET_SHORT_PREAMBLE);
544 case CMD_TYPE_LONG_PREAMBLE:
545 pradiocontrol->control = cpu_to_le16(SET_LONG_PREAMBLE);
548 case CMD_TYPE_AUTO_PREAMBLE:
550 pradiocontrol->control = cpu_to_le16(SET_AUTO_PREAMBLE);
555 pradiocontrol->control |= cpu_to_le16(TURN_ON_RF);
557 pradiocontrol->control &= cpu_to_le16(~TURN_ON_RF);
559 lbs_deb_leave(LBS_DEB_CMD);
563 static int lbs_cmd_802_11_rf_tx_power(struct lbs_private *priv,
564 struct cmd_ds_command *cmd,
565 u16 cmd_action, void *pdata_buf)
568 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
570 lbs_deb_enter(LBS_DEB_CMD);
573 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
574 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
575 prtp->action = cpu_to_le16(cmd_action);
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));
581 switch (cmd_action) {
582 case CMD_ACT_TX_POWER_OPT_GET:
583 prtp->action = cpu_to_le16(CMD_ACT_GET);
584 prtp->currentlevel = 0;
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);
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);
597 case CMD_ACT_TX_POWER_OPT_SET_LOW:
598 prtp->action = cpu_to_le16(CMD_ACT_SET);
599 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
603 lbs_deb_leave(LBS_DEB_CMD);
607 static int lbs_cmd_802_11_monitor_mode(struct lbs_private *priv,
608 struct cmd_ds_command *cmd,
609 u16 cmd_action, void *pdata_buf)
611 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
613 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
615 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
618 monitor->action = cpu_to_le16(cmd_action);
619 if (cmd_action == CMD_ACT_SET) {
621 cpu_to_le16((u16) (*(u32 *) pdata_buf));
627 static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
628 struct cmd_ds_command *cmd,
631 struct cmd_ds_802_11_rate_adapt_rateset
632 *rateadapt = &cmd->params.rateset;
634 lbs_deb_enter(LBS_DEB_CMD);
636 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
638 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
640 rateadapt->action = cpu_to_le16(cmd_action);
641 rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
642 rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
644 lbs_deb_leave(LBS_DEB_CMD);
648 static int lbs_cmd_802_11_data_rate(struct lbs_private *priv,
649 struct cmd_ds_command *cmd,
652 struct cmd_ds_802_11_data_rate *pdatarate = &cmd->params.drate;
654 lbs_deb_enter(LBS_DEB_CMD);
656 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_data_rate) +
658 cmd->command = cpu_to_le16(CMD_802_11_DATA_RATE);
659 memset(pdatarate, 0, sizeof(struct cmd_ds_802_11_data_rate));
660 pdatarate->action = cpu_to_le16(cmd_action);
662 if (cmd_action == CMD_ACT_SET_TX_FIX_RATE) {
663 pdatarate->rates[0] = lbs_data_rate_to_fw_index(priv->cur_rate);
664 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n",
666 } else if (cmd_action == CMD_ACT_SET_TX_AUTO) {
667 lbs_deb_cmd("DATA_RATE: setting auto\n");
670 lbs_deb_leave(LBS_DEB_CMD);
674 static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
675 struct cmd_ds_command *cmd,
678 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
680 lbs_deb_enter(LBS_DEB_CMD);
681 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
683 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
685 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
686 pMCastAdr->action = cpu_to_le16(cmd_action);
687 pMCastAdr->nr_of_adrs =
688 cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
689 memcpy(pMCastAdr->maclist, priv->multicastlist,
690 priv->nr_of_multicastmacaddr * ETH_ALEN);
692 lbs_deb_leave(LBS_DEB_CMD);
696 static int lbs_cmd_802_11_rf_channel(struct lbs_private *priv,
697 struct cmd_ds_command *cmd,
698 int option, void *pdata_buf)
700 struct cmd_ds_802_11_rf_channel *rfchan = &cmd->params.rfchannel;
702 lbs_deb_enter(LBS_DEB_CMD);
703 cmd->command = cpu_to_le16(CMD_802_11_RF_CHANNEL);
704 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rf_channel) +
707 if (option == CMD_OPT_802_11_RF_CHANNEL_SET) {
708 rfchan->currentchannel = cpu_to_le16(*((u16 *) pdata_buf));
711 rfchan->action = cpu_to_le16(option);
713 lbs_deb_leave(LBS_DEB_CMD);
717 static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
718 struct cmd_ds_command *cmd)
721 lbs_deb_enter(LBS_DEB_CMD);
722 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
723 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
724 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
726 /* reset Beacon SNR/NF/RSSI values */
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;
734 lbs_deb_leave(LBS_DEB_CMD);
738 static int lbs_cmd_reg_access(struct lbs_private *priv,
739 struct cmd_ds_command *cmdptr,
740 u8 cmd_action, void *pdata_buf)
742 struct lbs_offset_value *offval;
744 lbs_deb_enter(LBS_DEB_CMD);
746 offval = (struct lbs_offset_value *)pdata_buf;
748 switch (le16_to_cpu(cmdptr->command)) {
749 case CMD_MAC_REG_ACCESS:
751 struct cmd_ds_mac_reg_access *macreg;
754 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
757 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
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);
767 case CMD_BBP_REG_ACCESS:
769 struct cmd_ds_bbp_reg_access *bbpreg;
773 (struct cmd_ds_bbp_reg_access)
776 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
779 bbpreg->action = cpu_to_le16(cmd_action);
780 bbpreg->offset = cpu_to_le16((u16) offval->offset);
781 bbpreg->value = (u8) offval->value;
786 case CMD_RF_REG_ACCESS:
788 struct cmd_ds_rf_reg_access *rfreg;
792 (struct cmd_ds_rf_reg_access) +
795 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
798 rfreg->action = cpu_to_le16(cmd_action);
799 rfreg->offset = cpu_to_le16((u16) offval->offset);
800 rfreg->value = (u8) offval->value;
809 lbs_deb_leave(LBS_DEB_CMD);
813 static int lbs_cmd_802_11_mac_address(struct lbs_private *priv,
814 struct cmd_ds_command *cmd,
818 lbs_deb_enter(LBS_DEB_CMD);
819 cmd->command = cpu_to_le16(CMD_802_11_MAC_ADDRESS);
820 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_mac_address) +
824 cmd->params.macadd.action = cpu_to_le16(cmd_action);
826 if (cmd_action == CMD_ACT_SET) {
827 memcpy(cmd->params.macadd.macadd,
828 priv->current_addr, ETH_ALEN);
829 lbs_deb_hex(LBS_DEB_CMD, "SET_CMD: MAC addr", priv->current_addr, 6);
832 lbs_deb_leave(LBS_DEB_CMD);
836 static int lbs_cmd_802_11_eeprom_access(struct lbs_private *priv,
837 struct cmd_ds_command *cmd,
838 int cmd_action, void *pdata_buf)
840 struct lbs_ioctl_regrdwr *ea = pdata_buf;
842 lbs_deb_enter(LBS_DEB_CMD);
844 cmd->command = cpu_to_le16(CMD_802_11_EEPROM_ACCESS);
845 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_eeprom_access) +
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;
854 lbs_deb_leave(LBS_DEB_CMD);
858 static int lbs_cmd_bt_access(struct lbs_private *priv,
859 struct cmd_ds_command *cmd,
860 u16 cmd_action, void *pdata_buf)
862 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
863 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
865 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
866 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
868 bt_access->action = cpu_to_le16(cmd_action);
870 switch (cmd_action) {
871 case CMD_ACT_BT_ACCESS_ADD:
872 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
873 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
875 case CMD_ACT_BT_ACCESS_DEL:
876 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
877 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
879 case CMD_ACT_BT_ACCESS_LIST:
880 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
882 case CMD_ACT_BT_ACCESS_RESET:
884 case CMD_ACT_BT_ACCESS_SET_INVERT:
885 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
887 case CMD_ACT_BT_ACCESS_GET_INVERT:
892 lbs_deb_leave(LBS_DEB_CMD);
896 static int lbs_cmd_fwt_access(struct lbs_private *priv,
897 struct cmd_ds_command *cmd,
898 u16 cmd_action, void *pdata_buf)
900 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
901 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
903 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
904 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
908 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
910 memset(fwt_access, 0, sizeof(*fwt_access));
912 fwt_access->action = cpu_to_le16(cmd_action);
914 lbs_deb_leave(LBS_DEB_CMD);
918 static int lbs_cmd_mesh_access(struct lbs_private *priv,
919 struct cmd_ds_command *cmd,
920 u16 cmd_action, void *pdata_buf)
922 struct cmd_ds_mesh_access *mesh_access = &cmd->params.mesh;
923 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
925 cmd->command = cpu_to_le16(CMD_MESH_ACCESS);
926 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mesh_access) + S_DS_GEN);
930 memcpy(mesh_access, pdata_buf, sizeof(*mesh_access));
932 memset(mesh_access, 0, sizeof(*mesh_access));
934 mesh_access->action = cpu_to_le16(cmd_action);
936 lbs_deb_leave(LBS_DEB_CMD);
940 static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
941 struct cmd_ds_command *cmd,
944 struct cmd_ds_802_11_beacon_control
945 *bcn_ctrl = &cmd->params.bcn_ctrl;
947 lbs_deb_enter(LBS_DEB_CMD);
949 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
951 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
953 bcn_ctrl->action = cpu_to_le16(cmd_action);
954 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
955 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
957 lbs_deb_leave(LBS_DEB_CMD);
962 * Note: NEVER use lbs_queue_cmd() with addtail==0 other than for
963 * the command timer, because it does not account for queued commands.
965 void lbs_queue_cmd(struct lbs_private *priv,
966 struct cmd_ctrl_node *cmdnode,
970 struct cmd_ds_command *cmdptr;
972 lbs_deb_enter(LBS_DEB_HOST);
975 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
979 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
981 lbs_deb_host("QUEUE_CMD: cmdptr is NULL\n");
985 /* Exit_PS command needs to be queued in the header always. */
986 if (le16_to_cpu(cmdptr->command) == CMD_802_11_PS_MODE) {
987 struct cmd_ds_802_11_ps_mode *psm = &cmdptr->params.psmode;
988 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
989 if (priv->psstate != PS_STATE_FULL_POWER)
994 spin_lock_irqsave(&priv->driver_lock, flags);
997 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
999 list_add(&cmdnode->list, &priv->cmdpendingq);
1001 spin_unlock_irqrestore(&priv->driver_lock, flags);
1003 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
1004 le16_to_cpu(((struct cmd_ds_gen*)cmdnode->bufvirtualaddr)->command));
1007 lbs_deb_leave(LBS_DEB_HOST);
1011 * TODO: Fix the issue when DownloadcommandToStation is being called the
1012 * second time when the command times out. All the cmdptr->xxx are in little
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
1017 static int DownloadcommandToStation(struct lbs_private *priv,
1018 struct cmd_ctrl_node *cmdnode)
1020 unsigned long flags;
1021 struct cmd_ds_command *cmdptr;
1026 lbs_deb_enter(LBS_DEB_HOST);
1028 if (!priv || !cmdnode) {
1029 lbs_deb_host("DNLD_CMD: priv or cmdmode is NULL\n");
1033 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1035 spin_lock_irqsave(&priv->driver_lock, flags);
1036 if (!cmdptr || !cmdptr->size) {
1037 lbs_deb_host("DNLD_CMD: cmdptr is NULL or zero\n");
1038 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
1039 spin_unlock_irqrestore(&priv->driver_lock, flags);
1043 priv->cur_cmd = cmdnode;
1044 priv->cur_cmd_retcode = 0;
1045 spin_unlock_irqrestore(&priv->driver_lock, flags);
1047 cmdsize = le16_to_cpu(cmdptr->size);
1048 command = le16_to_cpu(cmdptr->command);
1050 lbs_deb_host("DNLD_CMD: command 0x%04x, size %d, jiffies %lu\n",
1051 command, cmdsize, jiffies);
1052 lbs_deb_hex(LBS_DEB_HOST, "DNLD_CMD", cmdnode->bufvirtualaddr, cmdsize);
1054 cmdnode->cmdwaitqwoken = 0;
1056 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmdptr, cmdsize);
1059 lbs_deb_host("DNLD_CMD: hw_host_to_card failed\n");
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);
1068 lbs_deb_cmd("DNLD_CMD: sent command 0x%04x, jiffies %lu\n", command, jiffies);
1070 /* Setup the timer after transmit command */
1071 if (command == CMD_802_11_SCAN || command == CMD_802_11_AUTHENTICATE
1072 || command == CMD_802_11_ASSOCIATE)
1073 mod_timer(&priv->command_timer, jiffies + (10*HZ));
1075 mod_timer(&priv->command_timer, jiffies + (5*HZ));
1080 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1084 static int lbs_cmd_mac_control(struct lbs_private *priv,
1085 struct cmd_ds_command *cmd)
1087 struct cmd_ds_mac_control *mac = &cmd->params.macctrl;
1089 lbs_deb_enter(LBS_DEB_CMD);
1091 cmd->command = cpu_to_le16(CMD_MAC_CONTROL);
1092 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_control) + S_DS_GEN);
1093 mac->action = cpu_to_le16(priv->currentpacketfilter);
1095 lbs_deb_cmd("MAC_CONTROL: action 0x%x, size %d\n",
1096 le16_to_cpu(mac->action), le16_to_cpu(cmd->size));
1098 lbs_deb_leave(LBS_DEB_CMD);
1103 * This function inserts command node to cmdfreeq
1104 * after cleans it. Requires priv->driver_lock held.
1106 void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1107 struct cmd_ctrl_node *ptempcmd)
1113 cleanup_cmdnode(ptempcmd);
1114 list_add_tail(&ptempcmd->list, &priv->cmdfreeq);
1117 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1118 struct cmd_ctrl_node *ptempcmd)
1120 unsigned long flags;
1122 spin_lock_irqsave(&priv->driver_lock, flags);
1123 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
1124 spin_unlock_irqrestore(&priv->driver_lock, flags);
1127 int lbs_set_radio_control(struct lbs_private *priv)
1131 lbs_deb_enter(LBS_DEB_CMD);
1133 ret = lbs_prepare_and_send_command(priv,
1134 CMD_802_11_RADIO_CONTROL,
1136 CMD_OPTION_WAITFORRSP, 0, NULL);
1138 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n",
1139 priv->radioon, priv->preamble);
1141 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1145 int lbs_set_mac_packet_filter(struct lbs_private *priv)
1149 lbs_deb_enter(LBS_DEB_CMD);
1151 /* Send MAC control command to station */
1152 ret = lbs_prepare_and_send_command(priv,
1153 CMD_MAC_CONTROL, 0, 0, 0, NULL);
1155 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1160 * @brief This function prepare the command before send to firmware.
1162 * @param priv A pointer to struct lbs_private structure
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
1170 int lbs_prepare_and_send_command(struct lbs_private *priv,
1173 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1176 struct cmd_ctrl_node *cmdnode;
1177 struct cmd_ds_command *cmdptr;
1178 unsigned long flags;
1180 lbs_deb_enter(LBS_DEB_HOST);
1183 lbs_deb_host("PREP_CMD: priv is NULL\n");
1188 if (priv->surpriseremoved) {
1189 lbs_deb_host("PREP_CMD: card removed\n");
1194 cmdnode = lbs_get_cmd_ctrl_node(priv);
1196 if (cmdnode == NULL) {
1197 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1199 /* Wake up main thread to execute next command */
1200 wake_up_interruptible(&priv->waitq);
1205 lbs_set_cmd_ctrl_node(priv, cmdnode, wait_option, pdata_buf);
1207 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1209 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1212 lbs_deb_host("PREP_CMD: cmdptr is NULL\n");
1213 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1218 /* Set sequence number, command and INT option */
1220 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
1222 cmdptr->command = cpu_to_le16(cmd_no);
1226 case CMD_GET_HW_SPEC:
1227 ret = lbs_cmd_hw_spec(priv, cmdptr);
1229 case CMD_802_11_PS_MODE:
1230 ret = lbs_cmd_802_11_ps_mode(priv, cmdptr, cmd_action);
1233 case CMD_802_11_SCAN:
1234 ret = lbs_cmd_80211_scan(priv, cmdptr, pdata_buf);
1237 case CMD_MAC_CONTROL:
1238 ret = lbs_cmd_mac_control(priv, cmdptr);
1241 case CMD_802_11_ASSOCIATE:
1242 case CMD_802_11_REASSOCIATE:
1243 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
1246 case CMD_802_11_DEAUTHENTICATE:
1247 ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
1250 case CMD_802_11_SET_WEP:
1251 ret = lbs_cmd_802_11_set_wep(priv, cmdptr, cmd_action, pdata_buf);
1254 case CMD_802_11_AD_HOC_START:
1255 ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1260 case CMD_802_11_RESET:
1261 ret = lbs_cmd_802_11_reset(priv, cmdptr, cmd_action);
1264 case CMD_802_11_GET_LOG:
1265 ret = lbs_cmd_802_11_get_log(priv, cmdptr);
1268 case CMD_802_11_AUTHENTICATE:
1269 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1272 case CMD_802_11_GET_STAT:
1273 ret = lbs_cmd_802_11_get_stat(priv, cmdptr);
1276 case CMD_802_11_SNMP_MIB:
1277 ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
1278 cmd_action, cmd_oid, pdata_buf);
1281 case CMD_MAC_REG_ACCESS:
1282 case CMD_BBP_REG_ACCESS:
1283 case CMD_RF_REG_ACCESS:
1284 ret = lbs_cmd_reg_access(priv, cmdptr, cmd_action, pdata_buf);
1287 case CMD_802_11_RF_CHANNEL:
1288 ret = lbs_cmd_802_11_rf_channel(priv, cmdptr,
1289 cmd_action, pdata_buf);
1292 case CMD_802_11_RF_TX_POWER:
1293 ret = lbs_cmd_802_11_rf_tx_power(priv, cmdptr,
1294 cmd_action, pdata_buf);
1297 case CMD_802_11_RADIO_CONTROL:
1298 ret = lbs_cmd_802_11_radio_control(priv, cmdptr, cmd_action);
1301 case CMD_802_11_DATA_RATE:
1302 ret = lbs_cmd_802_11_data_rate(priv, cmdptr, cmd_action);
1304 case CMD_802_11_RATE_ADAPT_RATESET:
1305 ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
1306 cmdptr, cmd_action);
1309 case CMD_MAC_MULTICAST_ADR:
1310 ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1313 case CMD_802_11_MONITOR_MODE:
1314 ret = lbs_cmd_802_11_monitor_mode(priv, cmdptr,
1315 cmd_action, pdata_buf);
1318 case CMD_802_11_AD_HOC_JOIN:
1319 ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1322 case CMD_802_11_RSSI:
1323 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
1326 case CMD_802_11_AD_HOC_STOP:
1327 ret = lbs_cmd_80211_ad_hoc_stop(priv, cmdptr);
1330 case CMD_802_11_ENABLE_RSN:
1331 ret = lbs_cmd_802_11_enable_rsn(priv, cmdptr, cmd_action,
1335 case CMD_802_11_KEY_MATERIAL:
1336 ret = lbs_cmd_802_11_key_material(priv, cmdptr, cmd_action,
1337 cmd_oid, pdata_buf);
1340 case CMD_802_11_PAIRWISE_TSC:
1342 case CMD_802_11_GROUP_TSC:
1345 case CMD_802_11_MAC_ADDRESS:
1346 ret = lbs_cmd_802_11_mac_address(priv, cmdptr, cmd_action);
1349 case CMD_802_11_EEPROM_ACCESS:
1350 ret = lbs_cmd_802_11_eeprom_access(priv, cmdptr,
1351 cmd_action, pdata_buf);
1354 case CMD_802_11_SET_AFC:
1355 case CMD_802_11_GET_AFC:
1357 cmdptr->command = cpu_to_le16(cmd_no);
1358 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1361 memmove(&cmdptr->params.afc,
1362 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1367 case CMD_802_11D_DOMAIN_INFO:
1368 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
1369 cmd_no, cmd_action);
1372 case CMD_802_11_SLEEP_PARAMS:
1373 ret = lbs_cmd_802_11_sleep_params(priv, cmdptr, cmd_action);
1375 case CMD_802_11_INACTIVITY_TIMEOUT:
1376 ret = lbs_cmd_802_11_inactivity_timeout(priv, cmdptr,
1377 cmd_action, pdata_buf);
1378 lbs_set_cmd_ctrl_node(priv, cmdnode, 0, pdata_buf);
1381 case CMD_802_11_TPC_CFG:
1382 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1384 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1387 memmove(&cmdptr->params.tpccfg,
1388 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1392 case CMD_802_11_LED_GPIO_CTRL:
1394 struct mrvlietypes_ledgpio *gpio =
1395 (struct mrvlietypes_ledgpio*)
1396 cmdptr->params.ledgpio.data;
1398 memmove(&cmdptr->params.ledgpio,
1400 sizeof(struct cmd_ds_802_11_led_ctrl));
1403 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1405 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1407 cpu_to_le16(le16_to_cpu(gpio->header.len)
1409 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1410 gpio->header.len = gpio->header.len;
1415 case CMD_802_11_SUBSCRIBE_EVENT:
1416 lbs_cmd_802_11_subscribe_event(priv, cmdptr,
1417 cmd_action, pdata_buf);
1419 case CMD_802_11_PWR_CFG:
1420 cmdptr->command = cpu_to_le16(CMD_802_11_PWR_CFG);
1422 cpu_to_le16(sizeof(struct cmd_ds_802_11_pwr_cfg) +
1424 memmove(&cmdptr->params.pwrcfg, pdata_buf,
1425 sizeof(struct cmd_ds_802_11_pwr_cfg));
1430 ret = lbs_cmd_bt_access(priv, cmdptr, cmd_action, pdata_buf);
1433 case CMD_FWT_ACCESS:
1434 ret = lbs_cmd_fwt_access(priv, cmdptr, cmd_action, pdata_buf);
1437 case CMD_MESH_ACCESS:
1438 ret = lbs_cmd_mesh_access(priv, cmdptr, cmd_action, pdata_buf);
1442 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1443 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1447 case CMD_802_11_BEACON_CTRL:
1448 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1451 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1456 /* return error, since the command preparation failed */
1458 lbs_deb_host("PREP_CMD: command preparation failed\n");
1459 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1464 cmdnode->cmdwaitqwoken = 0;
1466 lbs_queue_cmd(priv, cmdnode, 1);
1467 wake_up_interruptible(&priv->waitq);
1469 if (wait_option & CMD_OPTION_WAITFORRSP) {
1470 lbs_deb_host("PREP_CMD: wait for response\n");
1472 wait_event_interruptible(cmdnode->cmdwait_q,
1473 cmdnode->cmdwaitqwoken);
1476 spin_lock_irqsave(&priv->driver_lock, flags);
1477 if (priv->cur_cmd_retcode) {
1478 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1479 priv->cur_cmd_retcode);
1480 priv->cur_cmd_retcode = 0;
1483 spin_unlock_irqrestore(&priv->driver_lock, flags);
1486 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1489 EXPORT_SYMBOL_GPL(lbs_prepare_and_send_command);
1492 * @brief This function allocates the command buffer and link
1493 * it to command free queue.
1495 * @param priv A pointer to struct lbs_private structure
1498 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1503 struct cmd_ctrl_node *tempcmd_array;
1504 u8 *ptempvirtualaddr;
1506 lbs_deb_enter(LBS_DEB_HOST);
1508 /* Allocate and initialize cmdCtrlNode */
1509 ulbufsize = sizeof(struct cmd_ctrl_node) * MRVDRV_NUM_OF_CMD_BUFFER;
1511 if (!(tempcmd_array = kzalloc(ulbufsize, GFP_KERNEL))) {
1512 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1516 priv->cmd_array = tempcmd_array;
1518 /* Allocate and initialize command buffers */
1519 ulbufsize = MRVDRV_SIZE_OF_CMD_BUFFER;
1520 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1521 if (!(ptempvirtualaddr = kzalloc(ulbufsize, GFP_KERNEL))) {
1522 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1527 /* Update command buffer virtual */
1528 tempcmd_array[i].bufvirtualaddr = ptempvirtualaddr;
1531 for (i = 0; i < MRVDRV_NUM_OF_CMD_BUFFER; i++) {
1532 init_waitqueue_head(&tempcmd_array[i].cmdwait_q);
1533 lbs_cleanup_and_insert_cmd(priv, &tempcmd_array[i]);
1539 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1544 * @brief This function frees the command buffer.
1546 * @param priv A pointer to struct lbs_private structure
1549 int lbs_free_cmd_buffer(struct lbs_private *priv)
1551 u32 ulbufsize; /* Someone needs to die for this. Slowly and painfully */
1553 struct cmd_ctrl_node *tempcmd_array;
1555 lbs_deb_enter(LBS_DEB_HOST);
1557 /* need to check if cmd array is allocated or not */
1558 if (priv->cmd_array == NULL) {
1559 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1563 tempcmd_array = priv->cmd_array;
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) {
1569 kfree(tempcmd_array[i].bufvirtualaddr);
1570 tempcmd_array[i].bufvirtualaddr = NULL;
1574 /* Release cmd_ctrl_node */
1575 if (priv->cmd_array) {
1576 kfree(priv->cmd_array);
1577 priv->cmd_array = NULL;
1581 lbs_deb_leave(LBS_DEB_HOST);
1586 * @brief This function gets a free command node if available in
1587 * command free queue.
1589 * @param priv A pointer to struct lbs_private structure
1590 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1592 struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
1594 struct cmd_ctrl_node *tempnode;
1595 unsigned long flags;
1597 lbs_deb_enter(LBS_DEB_HOST);
1602 spin_lock_irqsave(&priv->driver_lock, flags);
1604 if (!list_empty(&priv->cmdfreeq)) {
1605 tempnode = list_first_entry(&priv->cmdfreeq,
1606 struct cmd_ctrl_node, list);
1607 list_del(&tempnode->list);
1609 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1613 spin_unlock_irqrestore(&priv->driver_lock, flags);
1616 cleanup_cmdnode(tempnode);
1618 lbs_deb_leave(LBS_DEB_HOST);
1623 * @brief This function cleans command node.
1625 * @param ptempnode A pointer to cmdCtrlNode structure
1628 static void cleanup_cmdnode(struct cmd_ctrl_node *ptempnode)
1630 lbs_deb_enter(LBS_DEB_HOST);
1634 ptempnode->cmdwaitqwoken = 1;
1635 wake_up_interruptible(&ptempnode->cmdwait_q);
1636 ptempnode->wait_option = 0;
1637 ptempnode->pdata_buf = NULL;
1638 ptempnode->callback = NULL;
1639 ptempnode->callback_arg = 0;
1641 if (ptempnode->bufvirtualaddr != NULL)
1642 memset(ptempnode->bufvirtualaddr, 0, MRVDRV_SIZE_OF_CMD_BUFFER);
1644 lbs_deb_leave(LBS_DEB_HOST);
1648 * @brief This function initializes the command node.
1650 * @param priv A pointer to struct lbs_private structure
1651 * @param ptempnode A pointer to cmd_ctrl_node structure
1652 * @param wait_option wait option: wait response or not
1653 * @param pdata_buf A pointer to informaion buffer
1656 void lbs_set_cmd_ctrl_node(struct lbs_private *priv,
1657 struct cmd_ctrl_node *ptempnode,
1658 u16 wait_option, void *pdata_buf)
1660 lbs_deb_enter(LBS_DEB_HOST);
1665 ptempnode->wait_option = wait_option;
1666 ptempnode->pdata_buf = pdata_buf;
1667 ptempnode->callback = NULL;
1668 ptempnode->callback_arg = 0;
1670 lbs_deb_leave(LBS_DEB_HOST);
1674 * @brief This function executes next command in command
1675 * pending queue. It will put fimware back to PS mode
1678 * @param priv A pointer to struct lbs_private structure
1681 int lbs_execute_next_command(struct lbs_private *priv)
1683 struct cmd_ctrl_node *cmdnode = NULL;
1684 struct cmd_ds_command *cmdptr;
1685 unsigned long flags;
1688 // Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1689 // only caller to us is lbs_thread() and we get even when a
1690 // data packet is received
1691 lbs_deb_enter(LBS_DEB_THREAD);
1693 spin_lock_irqsave(&priv->driver_lock, flags);
1695 if (priv->cur_cmd) {
1696 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1697 spin_unlock_irqrestore(&priv->driver_lock, flags);
1702 if (!list_empty(&priv->cmdpendingq)) {
1703 cmdnode = list_first_entry(&priv->cmdpendingq,
1704 struct cmd_ctrl_node, list);
1707 spin_unlock_irqrestore(&priv->driver_lock, flags);
1710 cmdptr = (struct cmd_ds_command *)cmdnode->bufvirtualaddr;
1712 if (is_command_allowed_in_ps(le16_to_cpu(cmdptr->command))) {
1713 if ((priv->psstate == PS_STATE_SLEEP) ||
1714 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1716 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1717 le16_to_cpu(cmdptr->command),
1722 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1723 "0x%04x in psstate %d\n",
1724 le16_to_cpu(cmdptr->command),
1726 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1728 * 1. Non-PS command:
1729 * Queue it. set needtowakeup to TRUE if current state
1730 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1731 * 2. PS command but not Exit_PS:
1733 * 3. PS command Exit_PS:
1734 * Set needtowakeup to TRUE if current state is SLEEP,
1735 * otherwise send this command down to firmware
1738 if (cmdptr->command !=
1739 cpu_to_le16(CMD_802_11_PS_MODE)) {
1740 /* Prepare to send Exit PS,
1741 * this non PS command will be sent later */
1742 if ((priv->psstate == PS_STATE_SLEEP)
1743 || (priv->psstate == PS_STATE_PRE_SLEEP)
1745 /* w/ new scheme, it will not reach here.
1746 since it is blocked in main_thread. */
1747 priv->needtowakeup = 1;
1749 lbs_ps_wakeup(priv, 0);
1755 * PS command. Ignore it if it is not Exit_PS.
1756 * otherwise send it down immediately.
1758 struct cmd_ds_802_11_ps_mode *psm =
1759 &cmdptr->params.psmode;
1762 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1765 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1767 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1768 list_del(&cmdnode->list);
1769 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1775 if ((priv->psstate == PS_STATE_SLEEP) ||
1776 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1778 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1779 list_del(&cmdnode->list);
1780 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1781 priv->needtowakeup = 1;
1788 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1791 list_del(&cmdnode->list);
1792 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1793 le16_to_cpu(cmdptr->command));
1794 DownloadcommandToStation(priv, cmdnode);
1797 * check if in power save mode, if yes, put the device back
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) {
1806 /* check for valid WPA group keys */
1807 if (priv->wpa_mcast_key.len ||
1808 priv->wpa_unicast_key.len) {
1810 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1811 " go back to PS_SLEEP");
1812 lbs_ps_sleep(priv, 0);
1816 "EXEC_NEXT_CMD: cmdpendingq empty, "
1817 "go back to PS_SLEEP");
1818 lbs_ps_sleep(priv, 0);
1825 lbs_deb_leave(LBS_DEB_THREAD);
1829 void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
1831 union iwreq_data iwrq;
1834 lbs_deb_enter(LBS_DEB_WEXT);
1836 memset(&iwrq, 0, sizeof(union iwreq_data));
1837 memset(buf, 0, sizeof(buf));
1839 snprintf(buf, sizeof(buf) - 1, "%s", str);
1841 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1843 /* Send Event to upper layer */
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);
1848 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1850 lbs_deb_leave(LBS_DEB_WEXT);
1853 static int sendconfirmsleep(struct lbs_private *priv, u8 *cmdptr, u16 size)
1855 unsigned long flags;
1858 lbs_deb_enter(LBS_DEB_HOST);
1860 lbs_deb_host("SEND_SLEEPC_CMD: before download, cmd size %d\n",
1863 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm command", cmdptr, size);
1865 ret = priv->hw_host_to_card(priv, MVMS_CMD, cmdptr, size);
1866 priv->dnld_sent = DNLD_RES_RECEIVED;
1868 spin_lock_irqsave(&priv->driver_lock, flags);
1869 if (priv->intcounter || priv->currenttxskb)
1870 lbs_deb_host("SEND_SLEEPC_CMD: intcounter %d, currenttxskb %p\n",
1871 priv->intcounter, priv->currenttxskb);
1872 spin_unlock_irqrestore(&priv->driver_lock, flags);
1876 "SEND_SLEEPC_CMD: Host to Card failed for Confirm Sleep\n");
1878 spin_lock_irqsave(&priv->driver_lock, flags);
1879 if (!priv->intcounter) {
1880 priv->psstate = PS_STATE_SLEEP;
1882 lbs_deb_host("SEND_SLEEPC_CMD: after sent, intcounter %d\n",
1885 spin_unlock_irqrestore(&priv->driver_lock, flags);
1887 lbs_deb_host("SEND_SLEEPC_CMD: sent confirm sleep\n");
1890 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1894 void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
1896 lbs_deb_enter(LBS_DEB_HOST);
1899 * PS is currently supported only in Infrastructure mode
1900 * Remove this check if it is to be supported in IBSS mode also
1903 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1904 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1906 lbs_deb_leave(LBS_DEB_HOST);
1910 * @brief This function sends Exit_PS command to firmware.
1912 * @param priv A pointer to struct lbs_private structure
1913 * @param wait_option wait response or not
1916 void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
1920 lbs_deb_enter(LBS_DEB_HOST);
1922 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
1924 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1926 wait_option, 0, &Localpsmode);
1928 lbs_deb_leave(LBS_DEB_HOST);
1932 * @brief This function checks condition and prepares to
1933 * send sleep confirm command to firmware if ok.
1935 * @param priv A pointer to struct lbs_private structure
1936 * @param psmode Power Saving mode
1939 void lbs_ps_confirm_sleep(struct lbs_private *priv, u16 psmode)
1941 unsigned long flags =0;
1944 lbs_deb_enter(LBS_DEB_HOST);
1946 if (priv->dnld_sent) {
1948 lbs_deb_host("dnld_sent was set");
1951 spin_lock_irqsave(&priv->driver_lock, flags);
1952 if (priv->cur_cmd) {
1954 lbs_deb_host("cur_cmd was set");
1956 if (priv->intcounter > 0) {
1958 lbs_deb_host("intcounter %d", priv->intcounter);
1960 spin_unlock_irqrestore(&priv->driver_lock, flags);
1963 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1964 sendconfirmsleep(priv, (u8 *) & priv->lbs_ps_confirm_sleep,
1965 sizeof(struct PS_CMD_ConfirmSleep));
1967 lbs_deb_host("sleep confirm has been delayed\n");
1970 lbs_deb_leave(LBS_DEB_HOST);
1975 * @brief Simple way to call firmware functions
1977 * @param priv A pointer to struct lbs_private structure
1978 * @param psmode one of the many CMD_802_11_xxxx
1979 * @param cmd pointer to the parameters structure for above command
1980 * (this should not include the command, size, sequence
1981 * and result fields from struct cmd_ds_gen)
1982 * @param cmd_size size structure pointed to by cmd
1983 * @param rsp pointer to an area where the result should be placed
1984 * @param rsp_size pointer to the size of the rsp area. If the firmware
1985 * returns fewer bytes, then this *rsp_size will be
1986 * changed to the actual size.
1987 * @return -1 in case of a higher level error, otherwise
1988 * the result code from the firmware
1991 int __lbs_cmd(struct lbs_private *priv, uint16_t command, void *cmd, int cmd_size,
1992 int (*callback)(struct lbs_private *, unsigned long, struct cmd_ds_command *),
1993 unsigned long callback_arg)
1995 struct cmd_ctrl_node *cmdnode;
1996 struct cmd_ds_gen *cmdptr;
1997 unsigned long flags;
2000 lbs_deb_enter(LBS_DEB_HOST);
2003 lbs_deb_host("PREP_CMD: priv is NULL\n");
2008 if (priv->surpriseremoved) {
2009 lbs_deb_host("PREP_CMD: card removed\n");
2014 cmdnode = lbs_get_cmd_ctrl_node(priv);
2016 if (cmdnode == NULL) {
2017 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2019 /* Wake up main thread to execute next command */
2020 wake_up_interruptible(&priv->waitq);
2025 cmdptr = (struct cmd_ds_gen *)cmdnode->bufvirtualaddr;
2026 cmdnode->wait_option = CMD_OPTION_WAITFORRSP;
2027 cmdnode->callback = callback;
2028 cmdnode->callback_arg = callback_arg;
2030 /* Set sequence number, clean result, move to buffer */
2032 cmdptr->command = cpu_to_le16(command);
2033 cmdptr->size = cpu_to_le16(cmd_size + S_DS_GEN);
2034 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
2036 memcpy(cmdptr->cmdresp, cmd, cmd_size);
2038 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2040 /* here was the big old switch() statement, which is now obsolete,
2041 * because the caller of lbs_cmd() sets up all of *cmd for us. */
2043 cmdnode->cmdwaitqwoken = 0;
2044 lbs_queue_cmd(priv, cmdnode, 1);
2045 wake_up_interruptible(&priv->waitq);
2048 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2050 spin_lock_irqsave(&priv->driver_lock, flags);
2051 if (priv->cur_cmd_retcode) {
2052 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
2053 priv->cur_cmd_retcode);
2054 priv->cur_cmd_retcode = 0;
2057 spin_unlock_irqrestore(&priv->driver_lock, flags);
2060 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2063 EXPORT_SYMBOL_GPL(__lbs_cmd);