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>
7 #include <linux/kfifo.h>
17 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
21 * @brief Simple callback that copies response back into command
23 * @param priv A pointer to struct lbs_private structure
24 * @param extra A pointer to the original command structure for which
25 * 'resp' is a response
26 * @param resp A pointer to the command response
28 * @return 0 on success, error on failure
30 int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
31 struct cmd_header *resp)
33 struct cmd_header *buf = (void *)extra;
36 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
37 memcpy(buf, resp, copy_len);
40 EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
43 * @brief Simple callback that ignores the result. Use this if
44 * you just want to send a command to the hardware, but don't
45 * care for the result.
48 * @param extra ignored
51 * @return 0 for success
53 static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
54 struct cmd_header *resp)
61 * @brief Checks whether a command is allowed in Power Save mode
63 * @param command the command ID
64 * @return 1 if allowed, 0 if not allowed
66 static u8 is_command_allowed_in_ps(u16 cmd)
78 * @brief Updates the hardware details like MAC address and regulatory region
80 * @param priv A pointer to struct lbs_private structure
82 * @return 0 on success, error on failure
84 int lbs_update_hw_spec(struct lbs_private *priv)
86 struct cmd_ds_get_hw_spec cmd;
91 lbs_deb_enter(LBS_DEB_CMD);
93 memset(&cmd, 0, sizeof(cmd));
94 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
95 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
96 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
100 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
102 /* The firmware release is in an interesting format: the patch
103 * level is in the most significant nibble ... so fix that: */
104 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
105 priv->fwrelease = (priv->fwrelease << 8) |
106 (priv->fwrelease >> 24 & 0xff);
108 /* Some firmware capabilities:
109 * CF card firmware 5.0.16p0: cap 0x00000303
110 * USB dongle firmware 5.110.17p2: cap 0x00000303
112 printk("libertas: %s, fw %u.%u.%up%u, cap 0x%08x\n",
113 print_mac(mac, cmd.permanentaddr),
114 priv->fwrelease >> 24 & 0xff,
115 priv->fwrelease >> 16 & 0xff,
116 priv->fwrelease >> 8 & 0xff,
117 priv->fwrelease & 0xff,
119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
120 cmd.hwifversion, cmd.version);
122 /* Clamp region code to 8-bit since FW spec indicates that it should
123 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
124 * returns non-zero high 8 bits here.
126 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
128 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
129 /* use the region code to search for the index */
130 if (priv->regioncode == lbs_region_code_to_index[i])
134 /* if it's unidentified region code, use the default (USA) */
135 if (i >= MRVDRV_MAX_REGION_CODE) {
136 priv->regioncode = 0x10;
137 lbs_pr_info("unidentified region code; using the default (USA)\n");
140 if (priv->current_addr[0] == 0xff)
141 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
143 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
145 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
147 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
152 if (lbs_set_universaltable(priv, 0)) {
158 lbs_deb_leave(LBS_DEB_CMD);
162 int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
164 struct cmd_ds_host_sleep cmd_config;
167 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
168 cmd_config.criteria = cpu_to_le32(criteria);
169 cmd_config.gpio = priv->wol_gpio;
170 cmd_config.gap = priv->wol_gap;
172 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
174 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
175 priv->wol_criteria = criteria;
177 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
182 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
184 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
187 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
189 lbs_deb_enter(LBS_DEB_CMD);
191 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
192 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
194 psm->action = cpu_to_le16(cmd_action);
195 psm->multipledtim = 0;
196 switch (cmd_action) {
197 case CMD_SUBCMD_ENTER_PS:
198 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
200 psm->locallisteninterval = 0;
201 psm->nullpktinterval = 0;
203 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
206 case CMD_SUBCMD_EXIT_PS:
207 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
210 case CMD_SUBCMD_SLEEP_CONFIRMED:
211 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
218 lbs_deb_leave(LBS_DEB_CMD);
222 int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
223 uint16_t cmd_action, uint16_t *timeout)
225 struct cmd_ds_802_11_inactivity_timeout cmd;
228 lbs_deb_enter(LBS_DEB_CMD);
230 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
231 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
233 cmd.action = cpu_to_le16(cmd_action);
235 if (cmd_action == CMD_ACT_SET)
236 cmd.timeout = cpu_to_le16(*timeout);
240 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
243 *timeout = le16_to_cpu(cmd.timeout);
245 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
249 int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
250 struct sleep_params *sp)
252 struct cmd_ds_802_11_sleep_params cmd;
255 lbs_deb_enter(LBS_DEB_CMD);
257 if (cmd_action == CMD_ACT_GET) {
258 memset(&cmd, 0, sizeof(cmd));
260 cmd.error = cpu_to_le16(sp->sp_error);
261 cmd.offset = cpu_to_le16(sp->sp_offset);
262 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
263 cmd.calcontrol = sp->sp_calcontrol;
264 cmd.externalsleepclk = sp->sp_extsleepclk;
265 cmd.reserved = cpu_to_le16(sp->sp_reserved);
267 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
268 cmd.action = cpu_to_le16(cmd_action);
270 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
273 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
274 "calcontrol 0x%x extsleepclk 0x%x\n",
275 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
276 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
277 cmd.externalsleepclk);
279 sp->sp_error = le16_to_cpu(cmd.error);
280 sp->sp_offset = le16_to_cpu(cmd.offset);
281 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
282 sp->sp_calcontrol = cmd.calcontrol;
283 sp->sp_extsleepclk = cmd.externalsleepclk;
284 sp->sp_reserved = le16_to_cpu(cmd.reserved);
287 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
291 int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
292 struct assoc_request *assoc)
294 struct cmd_ds_802_11_set_wep cmd;
297 lbs_deb_enter(LBS_DEB_CMD);
299 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
300 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
302 cmd.action = cpu_to_le16(cmd_action);
304 if (cmd_action == CMD_ACT_ADD) {
307 /* default tx key index */
308 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
309 CMD_WEP_KEY_INDEX_MASK);
311 /* Copy key types and material to host command structure */
312 for (i = 0; i < 4; i++) {
313 struct enc_key *pkey = &assoc->wep_keys[i];
317 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
318 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
319 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
321 case KEY_LEN_WEP_104:
322 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
323 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
324 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
329 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
336 } else if (cmd_action == CMD_ACT_REMOVE) {
337 /* ACT_REMOVE clears _all_ WEP keys */
339 /* default tx key index */
340 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
341 CMD_WEP_KEY_INDEX_MASK);
342 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
345 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
347 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
351 int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
354 struct cmd_ds_802_11_enable_rsn cmd;
357 lbs_deb_enter(LBS_DEB_CMD);
359 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
360 cmd.action = cpu_to_le16(cmd_action);
362 if (cmd_action == CMD_ACT_SET) {
364 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
366 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
367 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
370 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
371 if (!ret && cmd_action == CMD_ACT_GET)
372 *enable = le16_to_cpu(cmd.enable);
374 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
378 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
381 lbs_deb_enter(LBS_DEB_CMD);
383 if (key->flags & KEY_INFO_WPA_ENABLED)
384 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
385 if (key->flags & KEY_INFO_WPA_UNICAST)
386 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
387 if (key->flags & KEY_INFO_WPA_MCAST)
388 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
390 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
391 keyparam->keytypeid = cpu_to_le16(key->type);
392 keyparam->keylen = cpu_to_le16(key->len);
393 memcpy(keyparam->key, key->key, key->len);
395 /* Length field doesn't include the {type,length} header */
396 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
397 lbs_deb_leave(LBS_DEB_CMD);
400 int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
401 struct assoc_request *assoc)
403 struct cmd_ds_802_11_key_material cmd;
407 lbs_deb_enter(LBS_DEB_CMD);
409 cmd.action = cpu_to_le16(cmd_action);
410 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
412 if (cmd_action == CMD_ACT_GET) {
413 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
415 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
417 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
418 set_one_wpa_key(&cmd.keyParamSet[index],
419 &assoc->wpa_unicast_key);
423 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
424 set_one_wpa_key(&cmd.keyParamSet[index],
425 &assoc->wpa_mcast_key);
429 /* The common header and as many keys as we included */
430 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
431 keyParamSet[index]));
433 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
434 /* Copy the returned key to driver private data */
435 if (!ret && cmd_action == CMD_ACT_GET) {
436 void *buf_ptr = cmd.keyParamSet;
437 void *resp_end = &(&cmd)[1];
439 while (buf_ptr < resp_end) {
440 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
442 uint16_t param_set_len = le16_to_cpu(keyparam->length);
443 uint16_t key_len = le16_to_cpu(keyparam->keylen);
444 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
445 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
448 end = (void *)keyparam + sizeof(keyparam->type)
449 + sizeof(keyparam->length) + param_set_len;
451 /* Make sure we don't access past the end of the IEs */
455 if (key_flags & KEY_INFO_WPA_UNICAST)
456 key = &priv->wpa_unicast_key;
457 else if (key_flags & KEY_INFO_WPA_MCAST)
458 key = &priv->wpa_mcast_key;
462 /* Copy returned key into driver */
463 memset(key, 0, sizeof(struct enc_key));
464 if (key_len > sizeof(key->key))
466 key->type = key_type;
467 key->flags = key_flags;
469 memcpy(key->key, keyparam->key, key->len);
475 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
479 static int lbs_cmd_802_11_reset(struct cmd_ds_command *cmd, int cmd_action)
481 struct cmd_ds_802_11_reset *reset = &cmd->params.reset;
483 lbs_deb_enter(LBS_DEB_CMD);
485 cmd->command = cpu_to_le16(CMD_802_11_RESET);
486 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_reset) + S_DS_GEN);
487 reset->action = cpu_to_le16(cmd_action);
489 lbs_deb_leave(LBS_DEB_CMD);
493 static int lbs_cmd_802_11_snmp_mib(struct lbs_private *priv,
494 struct cmd_ds_command *cmd,
496 int cmd_oid, void *pdata_buf)
498 struct cmd_ds_802_11_snmp_mib *pSNMPMIB = &cmd->params.smib;
501 lbs_deb_enter(LBS_DEB_CMD);
503 lbs_deb_cmd("SNMP_CMD: cmd_oid = 0x%x\n", cmd_oid);
505 cmd->command = cpu_to_le16(CMD_802_11_SNMP_MIB);
506 cmd->size = cpu_to_le16(sizeof(*pSNMPMIB) + S_DS_GEN);
509 case OID_802_11_INFRASTRUCTURE_MODE:
511 u8 mode = (u8) (size_t) pdata_buf;
512 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
513 pSNMPMIB->oid = cpu_to_le16((u16) DESIRED_BSSTYPE_I);
514 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u8));
515 if (mode == IW_MODE_ADHOC) {
516 ucTemp = SNMP_MIB_VALUE_ADHOC;
518 /* Infra and Auto modes */
519 ucTemp = SNMP_MIB_VALUE_INFRA;
522 memmove(pSNMPMIB->value, &ucTemp, sizeof(u8));
527 case OID_802_11D_ENABLE:
531 pSNMPMIB->oid = cpu_to_le16((u16) DOT11D_I);
533 if (cmd_action == CMD_ACT_SET) {
534 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
535 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
536 ulTemp = *(u32 *)pdata_buf;
537 *((__le16 *)(pSNMPMIB->value)) =
538 cpu_to_le16((u16) ulTemp);
543 case OID_802_11_FRAGMENTATION_THRESHOLD:
547 pSNMPMIB->oid = cpu_to_le16((u16) FRAGTHRESH_I);
549 if (cmd_action == CMD_ACT_GET) {
550 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
551 } else if (cmd_action == CMD_ACT_SET) {
552 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
553 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
554 ulTemp = *((u32 *) pdata_buf);
555 *((__le16 *)(pSNMPMIB->value)) =
556 cpu_to_le16((u16) ulTemp);
563 case OID_802_11_RTS_THRESHOLD:
567 pSNMPMIB->oid = cpu_to_le16(RTSTHRESH_I);
569 if (cmd_action == CMD_ACT_GET) {
570 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
571 } else if (cmd_action == CMD_ACT_SET) {
572 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
573 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
574 ulTemp = *((u32 *)pdata_buf);
575 *(__le16 *)(pSNMPMIB->value) =
576 cpu_to_le16((u16) ulTemp);
581 case OID_802_11_TX_RETRYCOUNT:
582 pSNMPMIB->oid = cpu_to_le16((u16) SHORT_RETRYLIM_I);
584 if (cmd_action == CMD_ACT_GET) {
585 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_GET);
586 } else if (cmd_action == CMD_ACT_SET) {
587 pSNMPMIB->querytype = cpu_to_le16(CMD_ACT_SET);
588 pSNMPMIB->bufsize = cpu_to_le16(sizeof(u16));
589 *((__le16 *)(pSNMPMIB->value)) =
590 cpu_to_le16((u16) priv->txretrycount);
599 "SNMP_CMD: command=0x%x, size=0x%x, seqnum=0x%x, result=0x%x\n",
600 le16_to_cpu(cmd->command), le16_to_cpu(cmd->size),
601 le16_to_cpu(cmd->seqnum), le16_to_cpu(cmd->result));
604 "SNMP_CMD: action 0x%x, oid 0x%x, oidsize 0x%x, value 0x%x\n",
605 le16_to_cpu(pSNMPMIB->querytype), le16_to_cpu(pSNMPMIB->oid),
606 le16_to_cpu(pSNMPMIB->bufsize),
607 le16_to_cpu(*(__le16 *) pSNMPMIB->value));
609 lbs_deb_leave(LBS_DEB_CMD);
613 static int lbs_cmd_802_11_rf_tx_power(struct cmd_ds_command *cmd,
614 u16 cmd_action, void *pdata_buf)
617 struct cmd_ds_802_11_rf_tx_power *prtp = &cmd->params.txp;
619 lbs_deb_enter(LBS_DEB_CMD);
622 cpu_to_le16((sizeof(struct cmd_ds_802_11_rf_tx_power)) + S_DS_GEN);
623 cmd->command = cpu_to_le16(CMD_802_11_RF_TX_POWER);
624 prtp->action = cpu_to_le16(cmd_action);
626 lbs_deb_cmd("RF_TX_POWER_CMD: size:%d cmd:0x%x Act:%d\n",
627 le16_to_cpu(cmd->size), le16_to_cpu(cmd->command),
628 le16_to_cpu(prtp->action));
630 switch (cmd_action) {
631 case CMD_ACT_TX_POWER_OPT_GET:
632 prtp->action = cpu_to_le16(CMD_ACT_GET);
633 prtp->currentlevel = 0;
636 case CMD_ACT_TX_POWER_OPT_SET_HIGH:
637 prtp->action = cpu_to_le16(CMD_ACT_SET);
638 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_HIGH);
641 case CMD_ACT_TX_POWER_OPT_SET_MID:
642 prtp->action = cpu_to_le16(CMD_ACT_SET);
643 prtp->currentlevel = cpu_to_le16(CMD_ACT_TX_POWER_INDEX_MID);
646 case CMD_ACT_TX_POWER_OPT_SET_LOW:
647 prtp->action = cpu_to_le16(CMD_ACT_SET);
648 prtp->currentlevel = cpu_to_le16(*((u16 *) pdata_buf));
652 lbs_deb_leave(LBS_DEB_CMD);
656 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
657 u16 cmd_action, void *pdata_buf)
659 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
661 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
663 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
666 monitor->action = cpu_to_le16(cmd_action);
667 if (cmd_action == CMD_ACT_SET) {
669 cpu_to_le16((u16) (*(u32 *) pdata_buf));
675 static int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
676 struct cmd_ds_command *cmd,
679 struct cmd_ds_802_11_rate_adapt_rateset
680 *rateadapt = &cmd->params.rateset;
682 lbs_deb_enter(LBS_DEB_CMD);
684 cpu_to_le16(sizeof(struct cmd_ds_802_11_rate_adapt_rateset)
686 cmd->command = cpu_to_le16(CMD_802_11_RATE_ADAPT_RATESET);
688 rateadapt->action = cpu_to_le16(cmd_action);
689 rateadapt->enablehwauto = cpu_to_le16(priv->enablehwauto);
690 rateadapt->bitmap = cpu_to_le16(priv->ratebitmap);
692 lbs_deb_leave(LBS_DEB_CMD);
697 * @brief Get the current data rate
699 * @param priv A pointer to struct lbs_private structure
701 * @return The data rate on success, error on failure
703 int lbs_get_data_rate(struct lbs_private *priv)
705 struct cmd_ds_802_11_data_rate cmd;
708 lbs_deb_enter(LBS_DEB_CMD);
710 memset(&cmd, 0, sizeof(cmd));
711 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
712 cmd.action = cpu_to_le16(CMD_ACT_GET_TX_RATE);
714 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
718 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
720 ret = (int) lbs_fw_index_to_data_rate(cmd.rates[0]);
721 lbs_deb_cmd("DATA_RATE: current rate 0x%02x\n", ret);
724 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
729 * @brief Set the data rate
731 * @param priv A pointer to struct lbs_private structure
732 * @param rate The desired data rate, or 0 to clear a locked rate
734 * @return 0 on success, error on failure
736 int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
738 struct cmd_ds_802_11_data_rate cmd;
741 lbs_deb_enter(LBS_DEB_CMD);
743 memset(&cmd, 0, sizeof(cmd));
744 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
747 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
748 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
749 if (cmd.rates[0] == 0) {
750 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
755 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
757 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
758 lbs_deb_cmd("DATA_RATE: setting auto\n");
761 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
765 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
767 /* FIXME: get actual rates FW can do if this command actually returns
768 * all data rates supported.
770 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
771 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
774 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
778 static int lbs_cmd_mac_multicast_adr(struct lbs_private *priv,
779 struct cmd_ds_command *cmd,
782 struct cmd_ds_mac_multicast_adr *pMCastAdr = &cmd->params.madr;
784 lbs_deb_enter(LBS_DEB_CMD);
785 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_mac_multicast_adr) +
787 cmd->command = cpu_to_le16(CMD_MAC_MULTICAST_ADR);
789 lbs_deb_cmd("MULTICAST_ADR: setting %d addresses\n", pMCastAdr->nr_of_adrs);
790 pMCastAdr->action = cpu_to_le16(cmd_action);
791 pMCastAdr->nr_of_adrs =
792 cpu_to_le16((u16) priv->nr_of_multicastmacaddr);
793 memcpy(pMCastAdr->maclist, priv->multicastlist,
794 priv->nr_of_multicastmacaddr * ETH_ALEN);
796 lbs_deb_leave(LBS_DEB_CMD);
801 * @brief Get the radio channel
803 * @param priv A pointer to struct lbs_private structure
805 * @return The channel on success, error on failure
807 int lbs_get_channel(struct lbs_private *priv)
809 struct cmd_ds_802_11_rf_channel cmd;
812 lbs_deb_enter(LBS_DEB_CMD);
814 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
815 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
817 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
821 ret = le16_to_cpu(cmd.channel);
822 lbs_deb_cmd("current radio channel is %d\n", ret);
825 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
829 int lbs_update_channel(struct lbs_private *priv)
833 /* the channel in f/w could be out of sync; get the current channel */
834 lbs_deb_enter(LBS_DEB_ASSOC);
836 ret = lbs_get_channel(priv);
838 priv->curbssparams.channel = ret;
841 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
846 * @brief Set the radio channel
848 * @param priv A pointer to struct lbs_private structure
849 * @param channel The desired channel, or 0 to clear a locked channel
851 * @return 0 on success, error on failure
853 int lbs_set_channel(struct lbs_private *priv, u8 channel)
855 struct cmd_ds_802_11_rf_channel cmd;
856 u8 old_channel = priv->curbssparams.channel;
859 lbs_deb_enter(LBS_DEB_CMD);
861 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
862 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
863 cmd.channel = cpu_to_le16(channel);
865 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
869 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
870 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
871 priv->curbssparams.channel);
874 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
878 static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
879 struct cmd_ds_command *cmd)
882 lbs_deb_enter(LBS_DEB_CMD);
883 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
884 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
885 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
887 /* reset Beacon SNR/NF/RSSI values */
888 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
889 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
890 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
891 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
892 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
893 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
895 lbs_deb_leave(LBS_DEB_CMD);
899 static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
900 u8 cmd_action, void *pdata_buf)
902 struct lbs_offset_value *offval;
904 lbs_deb_enter(LBS_DEB_CMD);
906 offval = (struct lbs_offset_value *)pdata_buf;
908 switch (le16_to_cpu(cmdptr->command)) {
909 case CMD_MAC_REG_ACCESS:
911 struct cmd_ds_mac_reg_access *macreg;
914 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
917 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
920 macreg->action = cpu_to_le16(cmd_action);
921 macreg->offset = cpu_to_le16((u16) offval->offset);
922 macreg->value = cpu_to_le32(offval->value);
927 case CMD_BBP_REG_ACCESS:
929 struct cmd_ds_bbp_reg_access *bbpreg;
933 (struct cmd_ds_bbp_reg_access)
936 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
939 bbpreg->action = cpu_to_le16(cmd_action);
940 bbpreg->offset = cpu_to_le16((u16) offval->offset);
941 bbpreg->value = (u8) offval->value;
946 case CMD_RF_REG_ACCESS:
948 struct cmd_ds_rf_reg_access *rfreg;
952 (struct cmd_ds_rf_reg_access) +
955 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
958 rfreg->action = cpu_to_le16(cmd_action);
959 rfreg->offset = cpu_to_le16((u16) offval->offset);
960 rfreg->value = (u8) offval->value;
969 lbs_deb_leave(LBS_DEB_CMD);
973 static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
974 u16 cmd_action, void *pdata_buf)
976 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
977 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
979 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
980 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
982 bt_access->action = cpu_to_le16(cmd_action);
984 switch (cmd_action) {
985 case CMD_ACT_BT_ACCESS_ADD:
986 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
987 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
989 case CMD_ACT_BT_ACCESS_DEL:
990 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
991 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
993 case CMD_ACT_BT_ACCESS_LIST:
994 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
996 case CMD_ACT_BT_ACCESS_RESET:
998 case CMD_ACT_BT_ACCESS_SET_INVERT:
999 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1001 case CMD_ACT_BT_ACCESS_GET_INVERT:
1006 lbs_deb_leave(LBS_DEB_CMD);
1010 static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
1011 u16 cmd_action, void *pdata_buf)
1013 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
1014 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
1016 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
1017 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
1021 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1023 memset(fwt_access, 0, sizeof(*fwt_access));
1025 fwt_access->action = cpu_to_le16(cmd_action);
1027 lbs_deb_leave(LBS_DEB_CMD);
1031 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1032 struct cmd_ds_mesh_access *cmd)
1036 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
1038 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
1039 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
1040 cmd->hdr.result = 0;
1042 cmd->action = cpu_to_le16(cmd_action);
1044 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
1046 lbs_deb_leave(LBS_DEB_CMD);
1050 int lbs_mesh_config(struct lbs_private *priv, uint16_t enable, uint16_t chan)
1052 struct cmd_ds_mesh_config cmd;
1054 memset(&cmd, 0, sizeof(cmd));
1055 cmd.action = cpu_to_le16(enable);
1056 cmd.channel = cpu_to_le16(chan);
1057 cmd.type = cpu_to_le16(priv->mesh_tlv);
1058 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1061 cmd.length = cpu_to_le16(priv->mesh_ssid_len);
1062 memcpy(cmd.data, priv->mesh_ssid, priv->mesh_ssid_len);
1064 lbs_deb_cmd("mesh config enable %d TLV %x channel %d SSID %s\n",
1065 enable, priv->mesh_tlv, chan,
1066 escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
1067 return lbs_cmd_with_response(priv, CMD_MESH_CONFIG, &cmd);
1070 static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1071 struct cmd_ds_command *cmd,
1074 struct cmd_ds_802_11_beacon_control
1075 *bcn_ctrl = &cmd->params.bcn_ctrl;
1077 lbs_deb_enter(LBS_DEB_CMD);
1079 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1081 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1083 bcn_ctrl->action = cpu_to_le16(cmd_action);
1084 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1085 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
1087 lbs_deb_leave(LBS_DEB_CMD);
1091 static void lbs_queue_cmd(struct lbs_private *priv,
1092 struct cmd_ctrl_node *cmdnode)
1094 unsigned long flags;
1097 lbs_deb_enter(LBS_DEB_HOST);
1100 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
1103 if (!cmdnode->cmdbuf->size) {
1104 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1107 cmdnode->result = 0;
1109 /* Exit_PS command needs to be queued in the header always. */
1110 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
1111 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
1113 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1114 if (priv->psstate != PS_STATE_FULL_POWER)
1119 spin_lock_irqsave(&priv->driver_lock, flags);
1122 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
1124 list_add(&cmdnode->list, &priv->cmdpendingq);
1126 spin_unlock_irqrestore(&priv->driver_lock, flags);
1128 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
1129 le16_to_cpu(cmdnode->cmdbuf->command));
1132 lbs_deb_leave(LBS_DEB_HOST);
1135 static void lbs_submit_command(struct lbs_private *priv,
1136 struct cmd_ctrl_node *cmdnode)
1138 unsigned long flags;
1139 struct cmd_header *cmd;
1145 lbs_deb_enter(LBS_DEB_HOST);
1147 cmd = cmdnode->cmdbuf;
1149 spin_lock_irqsave(&priv->driver_lock, flags);
1150 priv->cur_cmd = cmdnode;
1151 priv->cur_cmd_retcode = 0;
1152 spin_unlock_irqrestore(&priv->driver_lock, flags);
1154 cmdsize = le16_to_cpu(cmd->size);
1155 command = le16_to_cpu(cmd->command);
1157 /* These commands take longer */
1158 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
1159 command == CMD_802_11_AUTHENTICATE)
1162 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1163 command, le16_to_cpu(cmd->seqnum), cmdsize);
1164 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
1166 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
1169 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
1170 /* Let the timer kick in and retry, and potentially reset
1171 the whole thing if the condition persists */
1175 /* Setup the timer after transmit command */
1176 mod_timer(&priv->command_timer, jiffies + timeo);
1178 lbs_deb_leave(LBS_DEB_HOST);
1182 * This function inserts command node to cmdfreeq
1183 * after cleans it. Requires priv->driver_lock held.
1185 static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1186 struct cmd_ctrl_node *cmdnode)
1188 lbs_deb_enter(LBS_DEB_HOST);
1193 cmdnode->callback = NULL;
1194 cmdnode->callback_arg = 0;
1196 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1198 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1200 lbs_deb_leave(LBS_DEB_HOST);
1203 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1204 struct cmd_ctrl_node *ptempcmd)
1206 unsigned long flags;
1208 spin_lock_irqsave(&priv->driver_lock, flags);
1209 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
1210 spin_unlock_irqrestore(&priv->driver_lock, flags);
1213 void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1216 if (cmd == priv->cur_cmd)
1217 priv->cur_cmd_retcode = result;
1219 cmd->result = result;
1220 cmd->cmdwaitqwoken = 1;
1221 wake_up_interruptible(&cmd->cmdwait_q);
1223 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
1224 __lbs_cleanup_and_insert_cmd(priv, cmd);
1225 priv->cur_cmd = NULL;
1228 int lbs_set_radio_control(struct lbs_private *priv)
1231 struct cmd_ds_802_11_radio_control cmd;
1233 lbs_deb_enter(LBS_DEB_CMD);
1235 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1236 cmd.action = cpu_to_le16(CMD_ACT_SET);
1238 switch (priv->preamble) {
1239 case CMD_TYPE_SHORT_PREAMBLE:
1240 cmd.control = cpu_to_le16(SET_SHORT_PREAMBLE);
1243 case CMD_TYPE_LONG_PREAMBLE:
1244 cmd.control = cpu_to_le16(SET_LONG_PREAMBLE);
1247 case CMD_TYPE_AUTO_PREAMBLE:
1249 cmd.control = cpu_to_le16(SET_AUTO_PREAMBLE);
1254 cmd.control |= cpu_to_le16(TURN_ON_RF);
1256 cmd.control &= cpu_to_le16(~TURN_ON_RF);
1258 lbs_deb_cmd("RADIO_SET: radio %d, preamble %d\n", priv->radioon,
1261 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
1263 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1267 void lbs_set_mac_control(struct lbs_private *priv)
1269 struct cmd_ds_mac_control cmd;
1271 lbs_deb_enter(LBS_DEB_CMD);
1273 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1274 cmd.action = cpu_to_le16(priv->mac_control);
1277 lbs_cmd_async(priv, CMD_MAC_CONTROL,
1278 &cmd.hdr, sizeof(cmd));
1280 lbs_deb_leave(LBS_DEB_CMD);
1284 * @brief This function prepare the command before send to firmware.
1286 * @param priv A pointer to struct lbs_private structure
1287 * @param cmd_no command number
1288 * @param cmd_action command action: GET or SET
1289 * @param wait_option wait option: wait response or not
1290 * @param cmd_oid cmd oid: treated as sub command
1291 * @param pdata_buf A pointer to informaion buffer
1294 int lbs_prepare_and_send_command(struct lbs_private *priv,
1297 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1300 struct cmd_ctrl_node *cmdnode;
1301 struct cmd_ds_command *cmdptr;
1302 unsigned long flags;
1304 lbs_deb_enter(LBS_DEB_HOST);
1307 lbs_deb_host("PREP_CMD: priv is NULL\n");
1312 if (priv->surpriseremoved) {
1313 lbs_deb_host("PREP_CMD: card removed\n");
1318 cmdnode = lbs_get_cmd_ctrl_node(priv);
1320 if (cmdnode == NULL) {
1321 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1323 /* Wake up main thread to execute next command */
1324 wake_up_interruptible(&priv->waitq);
1329 cmdnode->callback = NULL;
1330 cmdnode->callback_arg = (unsigned long)pdata_buf;
1332 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
1334 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1336 /* Set sequence number, command and INT option */
1338 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
1340 cmdptr->command = cpu_to_le16(cmd_no);
1344 case CMD_802_11_PS_MODE:
1345 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
1348 case CMD_802_11_ASSOCIATE:
1349 case CMD_802_11_REASSOCIATE:
1350 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
1353 case CMD_802_11_DEAUTHENTICATE:
1354 ret = lbs_cmd_80211_deauthenticate(priv, cmdptr);
1357 case CMD_802_11_AD_HOC_START:
1358 ret = lbs_cmd_80211_ad_hoc_start(priv, cmdptr, pdata_buf);
1361 case CMD_802_11_RESET:
1362 ret = lbs_cmd_802_11_reset(cmdptr, cmd_action);
1365 case CMD_802_11_AUTHENTICATE:
1366 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
1369 case CMD_802_11_SNMP_MIB:
1370 ret = lbs_cmd_802_11_snmp_mib(priv, cmdptr,
1371 cmd_action, cmd_oid, pdata_buf);
1374 case CMD_MAC_REG_ACCESS:
1375 case CMD_BBP_REG_ACCESS:
1376 case CMD_RF_REG_ACCESS:
1377 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
1380 case CMD_802_11_RF_TX_POWER:
1381 ret = lbs_cmd_802_11_rf_tx_power(cmdptr,
1382 cmd_action, pdata_buf);
1385 case CMD_802_11_RATE_ADAPT_RATESET:
1386 ret = lbs_cmd_802_11_rate_adapt_rateset(priv,
1387 cmdptr, cmd_action);
1390 case CMD_MAC_MULTICAST_ADR:
1391 ret = lbs_cmd_mac_multicast_adr(priv, cmdptr, cmd_action);
1394 case CMD_802_11_MONITOR_MODE:
1395 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
1396 cmd_action, pdata_buf);
1399 case CMD_802_11_AD_HOC_JOIN:
1400 ret = lbs_cmd_80211_ad_hoc_join(priv, cmdptr, pdata_buf);
1403 case CMD_802_11_RSSI:
1404 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
1407 case CMD_802_11_AD_HOC_STOP:
1408 ret = lbs_cmd_80211_ad_hoc_stop(cmdptr);
1411 case CMD_802_11_SET_AFC:
1412 case CMD_802_11_GET_AFC:
1414 cmdptr->command = cpu_to_le16(cmd_no);
1415 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1418 memmove(&cmdptr->params.afc,
1419 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1424 case CMD_802_11D_DOMAIN_INFO:
1425 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
1426 cmd_no, cmd_action);
1429 case CMD_802_11_TPC_CFG:
1430 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1432 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1435 memmove(&cmdptr->params.tpccfg,
1436 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1440 case CMD_802_11_LED_GPIO_CTRL:
1442 struct mrvlietypes_ledgpio *gpio =
1443 (struct mrvlietypes_ledgpio*)
1444 cmdptr->params.ledgpio.data;
1446 memmove(&cmdptr->params.ledgpio,
1448 sizeof(struct cmd_ds_802_11_led_ctrl));
1451 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1453 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1455 cpu_to_le16(le16_to_cpu(gpio->header.len)
1457 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1458 gpio->header.len = gpio->header.len;
1465 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
1468 case CMD_FWT_ACCESS:
1469 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
1473 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1474 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1478 case CMD_802_11_BEACON_CTRL:
1479 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1482 lbs_deb_host("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1487 /* return error, since the command preparation failed */
1489 lbs_deb_host("PREP_CMD: command preparation failed\n");
1490 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1495 cmdnode->cmdwaitqwoken = 0;
1497 lbs_queue_cmd(priv, cmdnode);
1498 wake_up_interruptible(&priv->waitq);
1500 if (wait_option & CMD_OPTION_WAITFORRSP) {
1501 lbs_deb_host("PREP_CMD: wait for response\n");
1503 wait_event_interruptible(cmdnode->cmdwait_q,
1504 cmdnode->cmdwaitqwoken);
1507 spin_lock_irqsave(&priv->driver_lock, flags);
1508 if (priv->cur_cmd_retcode) {
1509 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1510 priv->cur_cmd_retcode);
1511 priv->cur_cmd_retcode = 0;
1514 spin_unlock_irqrestore(&priv->driver_lock, flags);
1517 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1522 * @brief This function allocates the command buffer and link
1523 * it to command free queue.
1525 * @param priv A pointer to struct lbs_private structure
1528 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1533 struct cmd_ctrl_node *cmdarray;
1535 lbs_deb_enter(LBS_DEB_HOST);
1537 /* Allocate and initialize the command array */
1538 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1539 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
1540 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1544 priv->cmd_array = cmdarray;
1546 /* Allocate and initialize each command buffer in the command array */
1547 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1548 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1549 if (!cmdarray[i].cmdbuf) {
1550 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1556 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1557 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1558 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
1563 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1568 * @brief This function frees the command buffer.
1570 * @param priv A pointer to struct lbs_private structure
1573 int lbs_free_cmd_buffer(struct lbs_private *priv)
1575 struct cmd_ctrl_node *cmdarray;
1578 lbs_deb_enter(LBS_DEB_HOST);
1580 /* need to check if cmd array is allocated or not */
1581 if (priv->cmd_array == NULL) {
1582 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1586 cmdarray = priv->cmd_array;
1588 /* Release shared memory buffers */
1589 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1590 if (cmdarray[i].cmdbuf) {
1591 kfree(cmdarray[i].cmdbuf);
1592 cmdarray[i].cmdbuf = NULL;
1596 /* Release cmd_ctrl_node */
1597 if (priv->cmd_array) {
1598 kfree(priv->cmd_array);
1599 priv->cmd_array = NULL;
1603 lbs_deb_leave(LBS_DEB_HOST);
1608 * @brief This function gets a free command node if available in
1609 * command free queue.
1611 * @param priv A pointer to struct lbs_private structure
1612 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1614 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
1616 struct cmd_ctrl_node *tempnode;
1617 unsigned long flags;
1619 lbs_deb_enter(LBS_DEB_HOST);
1624 spin_lock_irqsave(&priv->driver_lock, flags);
1626 if (!list_empty(&priv->cmdfreeq)) {
1627 tempnode = list_first_entry(&priv->cmdfreeq,
1628 struct cmd_ctrl_node, list);
1629 list_del(&tempnode->list);
1631 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1635 spin_unlock_irqrestore(&priv->driver_lock, flags);
1637 lbs_deb_leave(LBS_DEB_HOST);
1642 * @brief This function executes next command in command
1643 * pending queue. It will put fimware back to PS mode
1646 * @param priv A pointer to struct lbs_private structure
1649 int lbs_execute_next_command(struct lbs_private *priv)
1651 struct cmd_ctrl_node *cmdnode = NULL;
1652 struct cmd_header *cmd;
1653 unsigned long flags;
1656 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1657 * only caller to us is lbs_thread() and we get even when a
1658 * data packet is received */
1659 lbs_deb_enter(LBS_DEB_THREAD);
1661 spin_lock_irqsave(&priv->driver_lock, flags);
1663 if (priv->cur_cmd) {
1664 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1665 spin_unlock_irqrestore(&priv->driver_lock, flags);
1670 if (!list_empty(&priv->cmdpendingq)) {
1671 cmdnode = list_first_entry(&priv->cmdpendingq,
1672 struct cmd_ctrl_node, list);
1675 spin_unlock_irqrestore(&priv->driver_lock, flags);
1678 cmd = cmdnode->cmdbuf;
1680 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
1681 if ((priv->psstate == PS_STATE_SLEEP) ||
1682 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1684 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1685 le16_to_cpu(cmd->command),
1690 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1691 "0x%04x in psstate %d\n",
1692 le16_to_cpu(cmd->command), priv->psstate);
1693 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1695 * 1. Non-PS command:
1696 * Queue it. set needtowakeup to TRUE if current state
1697 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1698 * 2. PS command but not Exit_PS:
1700 * 3. PS command Exit_PS:
1701 * Set needtowakeup to TRUE if current state is SLEEP,
1702 * otherwise send this command down to firmware
1705 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
1706 /* Prepare to send Exit PS,
1707 * this non PS command will be sent later */
1708 if ((priv->psstate == PS_STATE_SLEEP)
1709 || (priv->psstate == PS_STATE_PRE_SLEEP)
1711 /* w/ new scheme, it will not reach here.
1712 since it is blocked in main_thread. */
1713 priv->needtowakeup = 1;
1715 lbs_ps_wakeup(priv, 0);
1721 * PS command. Ignore it if it is not Exit_PS.
1722 * otherwise send it down immediately.
1724 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
1727 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1730 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1732 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1733 list_del(&cmdnode->list);
1734 spin_lock_irqsave(&priv->driver_lock, flags);
1735 lbs_complete_command(priv, cmdnode, 0);
1736 spin_unlock_irqrestore(&priv->driver_lock, flags);
1742 if ((priv->psstate == PS_STATE_SLEEP) ||
1743 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1745 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1746 list_del(&cmdnode->list);
1747 spin_lock_irqsave(&priv->driver_lock, flags);
1748 lbs_complete_command(priv, cmdnode, 0);
1749 spin_unlock_irqrestore(&priv->driver_lock, flags);
1750 priv->needtowakeup = 1;
1757 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1760 list_del(&cmdnode->list);
1761 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1762 le16_to_cpu(cmd->command));
1763 lbs_submit_command(priv, cmdnode);
1766 * check if in power save mode, if yes, put the device back
1769 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1770 (priv->psstate == PS_STATE_FULL_POWER) &&
1771 ((priv->connect_status == LBS_CONNECTED) ||
1772 (priv->mesh_connect_status == LBS_CONNECTED))) {
1773 if (priv->secinfo.WPAenabled ||
1774 priv->secinfo.WPA2enabled) {
1775 /* check for valid WPA group keys */
1776 if (priv->wpa_mcast_key.len ||
1777 priv->wpa_unicast_key.len) {
1779 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1780 " go back to PS_SLEEP");
1781 lbs_ps_sleep(priv, 0);
1785 "EXEC_NEXT_CMD: cmdpendingq empty, "
1786 "go back to PS_SLEEP");
1787 lbs_ps_sleep(priv, 0);
1794 lbs_deb_leave(LBS_DEB_THREAD);
1798 void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
1800 union iwreq_data iwrq;
1803 lbs_deb_enter(LBS_DEB_WEXT);
1805 memset(&iwrq, 0, sizeof(union iwreq_data));
1806 memset(buf, 0, sizeof(buf));
1808 snprintf(buf, sizeof(buf) - 1, "%s", str);
1810 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1812 /* Send Event to upper layer */
1813 lbs_deb_wext("event indication string %s\n", (char *)buf);
1814 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1815 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
1817 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1819 lbs_deb_leave(LBS_DEB_WEXT);
1822 static void lbs_send_confirmsleep(struct lbs_private *priv)
1824 unsigned long flags;
1827 lbs_deb_enter(LBS_DEB_HOST);
1828 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1829 sizeof(confirm_sleep));
1831 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1832 sizeof(confirm_sleep));
1834 lbs_pr_alert("confirm_sleep failed\n");
1838 spin_lock_irqsave(&priv->driver_lock, flags);
1840 /* If nothing to do, go back to sleep (?) */
1841 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1842 priv->psstate = PS_STATE_SLEEP;
1844 spin_unlock_irqrestore(&priv->driver_lock, flags);
1847 lbs_deb_leave(LBS_DEB_HOST);
1850 void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
1852 lbs_deb_enter(LBS_DEB_HOST);
1855 * PS is currently supported only in Infrastructure mode
1856 * Remove this check if it is to be supported in IBSS mode also
1859 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1860 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1862 lbs_deb_leave(LBS_DEB_HOST);
1866 * @brief This function sends Exit_PS command to firmware.
1868 * @param priv A pointer to struct lbs_private structure
1869 * @param wait_option wait response or not
1872 void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
1876 lbs_deb_enter(LBS_DEB_HOST);
1878 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
1880 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1882 wait_option, 0, &Localpsmode);
1884 lbs_deb_leave(LBS_DEB_HOST);
1888 * @brief This function checks condition and prepares to
1889 * send sleep confirm command to firmware if ok.
1891 * @param priv A pointer to struct lbs_private structure
1892 * @param psmode Power Saving mode
1895 void lbs_ps_confirm_sleep(struct lbs_private *priv)
1897 unsigned long flags =0;
1900 lbs_deb_enter(LBS_DEB_HOST);
1902 if (priv->dnld_sent) {
1904 lbs_deb_host("dnld_sent was set\n");
1907 spin_lock_irqsave(&priv->driver_lock, flags);
1908 /* In-progress command? */
1909 if (priv->cur_cmd) {
1911 lbs_deb_host("cur_cmd was set\n");
1914 /* Pending events or command responses? */
1915 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
1917 lbs_deb_host("pending events or command responses\n");
1919 spin_unlock_irqrestore(&priv->driver_lock, flags);
1922 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1923 lbs_send_confirmsleep(priv);
1925 lbs_deb_host("sleep confirm has been delayed\n");
1928 lbs_deb_leave(LBS_DEB_HOST);
1932 static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1933 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1934 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1935 unsigned long callback_arg)
1937 struct cmd_ctrl_node *cmdnode;
1939 lbs_deb_enter(LBS_DEB_HOST);
1941 if (priv->surpriseremoved) {
1942 lbs_deb_host("PREP_CMD: card removed\n");
1943 cmdnode = ERR_PTR(-ENOENT);
1947 cmdnode = lbs_get_cmd_ctrl_node(priv);
1948 if (cmdnode == NULL) {
1949 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1951 /* Wake up main thread to execute next command */
1952 wake_up_interruptible(&priv->waitq);
1953 cmdnode = ERR_PTR(-ENOBUFS);
1957 cmdnode->callback = callback;
1958 cmdnode->callback_arg = callback_arg;
1960 /* Copy the incoming command to the buffer */
1961 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
1963 /* Set sequence number, clean result, move to buffer */
1965 cmdnode->cmdbuf->command = cpu_to_le16(command);
1966 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1967 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1968 cmdnode->cmdbuf->result = 0;
1970 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1972 cmdnode->cmdwaitqwoken = 0;
1973 lbs_queue_cmd(priv, cmdnode);
1974 wake_up_interruptible(&priv->waitq);
1977 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1981 void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1982 struct cmd_header *in_cmd, int in_cmd_size)
1984 lbs_deb_enter(LBS_DEB_CMD);
1985 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1986 lbs_cmd_async_callback, 0);
1987 lbs_deb_leave(LBS_DEB_CMD);
1990 int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1991 struct cmd_header *in_cmd, int in_cmd_size,
1992 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1993 unsigned long callback_arg)
1995 struct cmd_ctrl_node *cmdnode;
1996 unsigned long flags;
1999 lbs_deb_enter(LBS_DEB_HOST);
2001 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2002 callback, callback_arg);
2003 if (IS_ERR(cmdnode)) {
2004 ret = PTR_ERR(cmdnode);
2009 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2011 spin_lock_irqsave(&priv->driver_lock, flags);
2012 ret = cmdnode->result;
2014 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2017 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
2018 spin_unlock_irqrestore(&priv->driver_lock, flags);
2021 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2024 EXPORT_SYMBOL_GPL(__lbs_cmd);