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 <net/lib80211.h>
8 #include <linux/kfifo.h>
18 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 This function checks if the command is allowed.
80 * @param priv A pointer to lbs_private structure
81 * @return allowed or not allowed.
84 static int lbs_is_cmd_allowed(struct lbs_private *priv)
88 lbs_deb_enter(LBS_DEB_CMD);
90 if (!priv->is_auto_deep_sleep_enabled) {
91 if (priv->is_deep_sleep) {
92 lbs_deb_cmd("command not allowed in deep sleep\n");
97 lbs_deb_leave(LBS_DEB_CMD);
102 * @brief Updates the hardware details like MAC address and regulatory region
104 * @param priv A pointer to struct lbs_private structure
106 * @return 0 on success, error on failure
108 int lbs_update_hw_spec(struct lbs_private *priv)
110 struct cmd_ds_get_hw_spec cmd;
114 lbs_deb_enter(LBS_DEB_CMD);
116 memset(&cmd, 0, sizeof(cmd));
117 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
118 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
119 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
123 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
125 /* The firmware release is in an interesting format: the patch
126 * level is in the most significant nibble ... so fix that: */
127 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
128 priv->fwrelease = (priv->fwrelease << 8) |
129 (priv->fwrelease >> 24 & 0xff);
131 /* Some firmware capabilities:
132 * CF card firmware 5.0.16p0: cap 0x00000303
133 * USB dongle firmware 5.110.17p2: cap 0x00000303
135 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
137 priv->fwrelease >> 24 & 0xff,
138 priv->fwrelease >> 16 & 0xff,
139 priv->fwrelease >> 8 & 0xff,
140 priv->fwrelease & 0xff,
142 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
143 cmd.hwifversion, cmd.version);
145 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
146 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
147 /* 5.110.22 have mesh command with 0xa3 command id */
148 /* 10.0.0.p0 FW brings in mesh config command with different id */
149 /* Check FW version MSB and initialize mesh_fw_ver */
150 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
151 priv->mesh_fw_ver = MESH_FW_OLD;
152 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
153 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
154 priv->mesh_fw_ver = MESH_FW_NEW;
156 priv->mesh_fw_ver = MESH_NONE;
158 /* Clamp region code to 8-bit since FW spec indicates that it should
159 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
160 * returns non-zero high 8 bits here.
162 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
163 * need to check for this problem and handle it properly.
165 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
166 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
168 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
170 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
171 /* use the region code to search for the index */
172 if (priv->regioncode == lbs_region_code_to_index[i])
176 /* if it's unidentified region code, use the default (USA) */
177 if (i >= MRVDRV_MAX_REGION_CODE) {
178 priv->regioncode = 0x10;
179 lbs_pr_info("unidentified region code; using the default (USA)\n");
182 if (priv->current_addr[0] == 0xff)
183 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
185 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
187 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
189 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
195 lbs_deb_leave(LBS_DEB_CMD);
199 int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
200 struct wol_config *p_wol_config)
202 struct cmd_ds_host_sleep cmd_config;
205 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
206 cmd_config.criteria = cpu_to_le32(criteria);
207 cmd_config.gpio = priv->wol_gpio;
208 cmd_config.gap = priv->wol_gap;
210 if (p_wol_config != NULL)
211 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
212 sizeof(struct wol_config));
214 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
216 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
219 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
220 priv->wol_criteria = criteria;
222 memcpy((uint8_t *) p_wol_config,
223 (uint8_t *)&cmd_config.wol_conf,
224 sizeof(struct wol_config));
226 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
231 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
233 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
236 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
238 lbs_deb_enter(LBS_DEB_CMD);
240 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
241 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
243 psm->action = cpu_to_le16(cmd_action);
244 psm->multipledtim = 0;
245 switch (cmd_action) {
246 case CMD_SUBCMD_ENTER_PS:
247 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
249 psm->locallisteninterval = 0;
250 psm->nullpktinterval = 0;
252 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
255 case CMD_SUBCMD_EXIT_PS:
256 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
259 case CMD_SUBCMD_SLEEP_CONFIRMED:
260 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
267 lbs_deb_leave(LBS_DEB_CMD);
271 int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
272 struct sleep_params *sp)
274 struct cmd_ds_802_11_sleep_params cmd;
277 lbs_deb_enter(LBS_DEB_CMD);
279 if (cmd_action == CMD_ACT_GET) {
280 memset(&cmd, 0, sizeof(cmd));
282 cmd.error = cpu_to_le16(sp->sp_error);
283 cmd.offset = cpu_to_le16(sp->sp_offset);
284 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
285 cmd.calcontrol = sp->sp_calcontrol;
286 cmd.externalsleepclk = sp->sp_extsleepclk;
287 cmd.reserved = cpu_to_le16(sp->sp_reserved);
289 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
290 cmd.action = cpu_to_le16(cmd_action);
292 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
295 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
296 "calcontrol 0x%x extsleepclk 0x%x\n",
297 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
298 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
299 cmd.externalsleepclk);
301 sp->sp_error = le16_to_cpu(cmd.error);
302 sp->sp_offset = le16_to_cpu(cmd.offset);
303 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
304 sp->sp_calcontrol = cmd.calcontrol;
305 sp->sp_extsleepclk = cmd.externalsleepclk;
306 sp->sp_reserved = le16_to_cpu(cmd.reserved);
309 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
313 static int lbs_wait_for_ds_awake(struct lbs_private *priv)
317 lbs_deb_enter(LBS_DEB_CMD);
319 if (priv->is_deep_sleep) {
320 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
321 !priv->is_deep_sleep, (10 * HZ))) {
322 lbs_pr_err("ds_awake_q: timer expired\n");
327 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
331 int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
335 lbs_deb_enter(LBS_DEB_CMD);
338 if (priv->is_deep_sleep != 1) {
339 lbs_deb_cmd("deep sleep: sleep\n");
340 BUG_ON(!priv->enter_deep_sleep);
341 ret = priv->enter_deep_sleep(priv);
343 netif_stop_queue(priv->dev);
344 netif_carrier_off(priv->dev);
347 lbs_pr_err("deep sleep: already enabled\n");
350 if (priv->is_deep_sleep) {
351 lbs_deb_cmd("deep sleep: wakeup\n");
352 BUG_ON(!priv->exit_deep_sleep);
353 ret = priv->exit_deep_sleep(priv);
355 ret = lbs_wait_for_ds_awake(priv);
357 lbs_pr_err("deep sleep: wakeup"
363 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
367 int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
368 struct assoc_request *assoc)
370 struct cmd_ds_802_11_set_wep cmd;
373 lbs_deb_enter(LBS_DEB_CMD);
375 memset(&cmd, 0, sizeof(cmd));
376 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
377 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
379 cmd.action = cpu_to_le16(cmd_action);
381 if (cmd_action == CMD_ACT_ADD) {
384 /* default tx key index */
385 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
386 CMD_WEP_KEY_INDEX_MASK);
388 /* Copy key types and material to host command structure */
389 for (i = 0; i < 4; i++) {
390 struct enc_key *pkey = &assoc->wep_keys[i];
394 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
395 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
396 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
398 case KEY_LEN_WEP_104:
399 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
400 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
401 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
406 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
413 } else if (cmd_action == CMD_ACT_REMOVE) {
414 /* ACT_REMOVE clears _all_ WEP keys */
416 /* default tx key index */
417 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
418 CMD_WEP_KEY_INDEX_MASK);
419 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
422 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
424 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
428 int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
431 struct cmd_ds_802_11_enable_rsn cmd;
434 lbs_deb_enter(LBS_DEB_CMD);
436 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
437 cmd.action = cpu_to_le16(cmd_action);
439 if (cmd_action == CMD_ACT_GET)
443 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
445 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
446 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
449 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
450 if (!ret && cmd_action == CMD_ACT_GET)
451 *enable = le16_to_cpu(cmd.enable);
453 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
457 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
460 lbs_deb_enter(LBS_DEB_CMD);
462 if (key->flags & KEY_INFO_WPA_ENABLED)
463 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
464 if (key->flags & KEY_INFO_WPA_UNICAST)
465 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
466 if (key->flags & KEY_INFO_WPA_MCAST)
467 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
469 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
470 keyparam->keytypeid = cpu_to_le16(key->type);
471 keyparam->keylen = cpu_to_le16(key->len);
472 memcpy(keyparam->key, key->key, key->len);
474 /* Length field doesn't include the {type,length} header */
475 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
476 lbs_deb_leave(LBS_DEB_CMD);
479 int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
480 struct assoc_request *assoc)
482 struct cmd_ds_802_11_key_material cmd;
486 lbs_deb_enter(LBS_DEB_CMD);
488 cmd.action = cpu_to_le16(cmd_action);
489 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
491 if (cmd_action == CMD_ACT_GET) {
492 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
494 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
496 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
497 set_one_wpa_key(&cmd.keyParamSet[index],
498 &assoc->wpa_unicast_key);
502 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
503 set_one_wpa_key(&cmd.keyParamSet[index],
504 &assoc->wpa_mcast_key);
508 /* The common header and as many keys as we included */
509 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
510 keyParamSet[index]));
512 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
513 /* Copy the returned key to driver private data */
514 if (!ret && cmd_action == CMD_ACT_GET) {
515 void *buf_ptr = cmd.keyParamSet;
516 void *resp_end = &(&cmd)[1];
518 while (buf_ptr < resp_end) {
519 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
521 uint16_t param_set_len = le16_to_cpu(keyparam->length);
522 uint16_t key_len = le16_to_cpu(keyparam->keylen);
523 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
524 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
527 end = (void *)keyparam + sizeof(keyparam->type)
528 + sizeof(keyparam->length) + param_set_len;
530 /* Make sure we don't access past the end of the IEs */
534 if (key_flags & KEY_INFO_WPA_UNICAST)
535 key = &priv->wpa_unicast_key;
536 else if (key_flags & KEY_INFO_WPA_MCAST)
537 key = &priv->wpa_mcast_key;
541 /* Copy returned key into driver */
542 memset(key, 0, sizeof(struct enc_key));
543 if (key_len > sizeof(key->key))
545 key->type = key_type;
546 key->flags = key_flags;
548 memcpy(key->key, keyparam->key, key->len);
554 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
559 * @brief Set an SNMP MIB value
561 * @param priv A pointer to struct lbs_private structure
562 * @param oid The OID to set in the firmware
563 * @param val Value to set the OID to
565 * @return 0 on success, error on failure
567 int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
569 struct cmd_ds_802_11_snmp_mib cmd;
572 lbs_deb_enter(LBS_DEB_CMD);
574 memset(&cmd, 0, sizeof (cmd));
575 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
576 cmd.action = cpu_to_le16(CMD_ACT_SET);
577 cmd.oid = cpu_to_le16((u16) oid);
580 case SNMP_MIB_OID_BSS_TYPE:
581 cmd.bufsize = cpu_to_le16(sizeof(u8));
582 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
584 case SNMP_MIB_OID_11D_ENABLE:
585 case SNMP_MIB_OID_FRAG_THRESHOLD:
586 case SNMP_MIB_OID_RTS_THRESHOLD:
587 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
588 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
589 cmd.bufsize = cpu_to_le16(sizeof(u16));
590 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
593 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
598 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
599 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
601 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
604 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
609 * @brief Get an SNMP MIB value
611 * @param priv A pointer to struct lbs_private structure
612 * @param oid The OID to retrieve from the firmware
613 * @param out_val Location for the returned value
615 * @return 0 on success, error on failure
617 int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
619 struct cmd_ds_802_11_snmp_mib cmd;
622 lbs_deb_enter(LBS_DEB_CMD);
624 memset(&cmd, 0, sizeof (cmd));
625 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
626 cmd.action = cpu_to_le16(CMD_ACT_GET);
627 cmd.oid = cpu_to_le16(oid);
629 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
633 switch (le16_to_cpu(cmd.bufsize)) {
635 if (oid == SNMP_MIB_OID_BSS_TYPE) {
636 if (cmd.value[0] == 2)
637 *out_val = IW_MODE_ADHOC;
639 *out_val = IW_MODE_INFRA;
641 *out_val = cmd.value[0];
644 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
647 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
648 oid, le16_to_cpu(cmd.bufsize));
653 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
658 * @brief Get the min, max, and current TX power
660 * @param priv A pointer to struct lbs_private structure
661 * @param curlevel Current power level in dBm
662 * @param minlevel Minimum supported power level in dBm (optional)
663 * @param maxlevel Maximum supported power level in dBm (optional)
665 * @return 0 on success, error on failure
667 int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
670 struct cmd_ds_802_11_rf_tx_power cmd;
673 lbs_deb_enter(LBS_DEB_CMD);
675 memset(&cmd, 0, sizeof(cmd));
676 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
677 cmd.action = cpu_to_le16(CMD_ACT_GET);
679 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
681 *curlevel = le16_to_cpu(cmd.curlevel);
683 *minlevel = cmd.minlevel;
685 *maxlevel = cmd.maxlevel;
688 lbs_deb_leave(LBS_DEB_CMD);
693 * @brief Set the TX power
695 * @param priv A pointer to struct lbs_private structure
696 * @param dbm The desired power level in dBm
698 * @return 0 on success, error on failure
700 int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
702 struct cmd_ds_802_11_rf_tx_power cmd;
705 lbs_deb_enter(LBS_DEB_CMD);
707 memset(&cmd, 0, sizeof(cmd));
708 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
709 cmd.action = cpu_to_le16(CMD_ACT_SET);
710 cmd.curlevel = cpu_to_le16(dbm);
712 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
714 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
716 lbs_deb_leave(LBS_DEB_CMD);
720 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
721 u16 cmd_action, void *pdata_buf)
723 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
725 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
727 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
730 monitor->action = cpu_to_le16(cmd_action);
731 if (cmd_action == CMD_ACT_SET) {
733 cpu_to_le16((u16) (*(u32 *) pdata_buf));
739 static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
759 int i = lbs_data_rate_to_fw_index(rate);
761 ratemask = (0x1fef >> (12 - i));
764 return cpu_to_le16(ratemask);
767 int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
770 struct cmd_ds_802_11_rate_adapt_rateset cmd;
773 lbs_deb_enter(LBS_DEB_CMD);
775 if (!priv->cur_rate && !priv->enablehwauto)
778 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
780 cmd.action = cpu_to_le16(cmd_action);
781 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
782 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
783 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
784 if (!ret && cmd_action == CMD_ACT_GET) {
785 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
786 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
789 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
792 EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
795 * @brief Set the data rate
797 * @param priv A pointer to struct lbs_private structure
798 * @param rate The desired data rate, or 0 to clear a locked rate
800 * @return 0 on success, error on failure
802 int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
804 struct cmd_ds_802_11_data_rate cmd;
807 lbs_deb_enter(LBS_DEB_CMD);
809 memset(&cmd, 0, sizeof(cmd));
810 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
813 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
814 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
815 if (cmd.rates[0] == 0) {
816 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
821 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
823 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
824 lbs_deb_cmd("DATA_RATE: setting auto\n");
827 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
831 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
833 /* FIXME: get actual rates FW can do if this command actually returns
834 * all data rates supported.
836 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
837 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
840 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
845 * @brief Get the radio channel
847 * @param priv A pointer to struct lbs_private structure
849 * @return The channel on success, error on failure
851 static int lbs_get_channel(struct lbs_private *priv)
853 struct cmd_ds_802_11_rf_channel cmd;
856 lbs_deb_enter(LBS_DEB_CMD);
858 memset(&cmd, 0, sizeof(cmd));
859 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
860 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
862 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
866 ret = le16_to_cpu(cmd.channel);
867 lbs_deb_cmd("current radio channel is %d\n", ret);
870 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
874 int lbs_update_channel(struct lbs_private *priv)
878 /* the channel in f/w could be out of sync; get the current channel */
879 lbs_deb_enter(LBS_DEB_ASSOC);
881 ret = lbs_get_channel(priv);
886 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
891 * @brief Set the radio channel
893 * @param priv A pointer to struct lbs_private structure
894 * @param channel The desired channel, or 0 to clear a locked channel
896 * @return 0 on success, error on failure
898 int lbs_set_channel(struct lbs_private *priv, u8 channel)
900 struct cmd_ds_802_11_rf_channel cmd;
902 u8 old_channel = priv->channel;
906 lbs_deb_enter(LBS_DEB_CMD);
908 memset(&cmd, 0, sizeof(cmd));
909 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
910 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
911 cmd.channel = cpu_to_le16(channel);
913 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
917 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
918 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
922 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
926 static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
927 struct cmd_ds_command *cmd)
930 lbs_deb_enter(LBS_DEB_CMD);
931 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
932 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
933 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
935 /* reset Beacon SNR/NF/RSSI values */
936 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
937 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
938 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
939 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
940 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
941 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
943 lbs_deb_leave(LBS_DEB_CMD);
947 static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
948 u8 cmd_action, void *pdata_buf)
950 struct lbs_offset_value *offval;
952 lbs_deb_enter(LBS_DEB_CMD);
954 offval = (struct lbs_offset_value *)pdata_buf;
956 switch (le16_to_cpu(cmdptr->command)) {
957 case CMD_MAC_REG_ACCESS:
959 struct cmd_ds_mac_reg_access *macreg;
962 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
965 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
968 macreg->action = cpu_to_le16(cmd_action);
969 macreg->offset = cpu_to_le16((u16) offval->offset);
970 macreg->value = cpu_to_le32(offval->value);
975 case CMD_BBP_REG_ACCESS:
977 struct cmd_ds_bbp_reg_access *bbpreg;
981 (struct cmd_ds_bbp_reg_access)
984 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
987 bbpreg->action = cpu_to_le16(cmd_action);
988 bbpreg->offset = cpu_to_le16((u16) offval->offset);
989 bbpreg->value = (u8) offval->value;
994 case CMD_RF_REG_ACCESS:
996 struct cmd_ds_rf_reg_access *rfreg;
1000 (struct cmd_ds_rf_reg_access) +
1003 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
1006 rfreg->action = cpu_to_le16(cmd_action);
1007 rfreg->offset = cpu_to_le16((u16) offval->offset);
1008 rfreg->value = (u8) offval->value;
1017 lbs_deb_leave(LBS_DEB_CMD);
1021 static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
1022 u16 cmd_action, void *pdata_buf)
1024 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
1025 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
1027 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
1028 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
1030 bt_access->action = cpu_to_le16(cmd_action);
1032 switch (cmd_action) {
1033 case CMD_ACT_BT_ACCESS_ADD:
1034 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
1035 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
1037 case CMD_ACT_BT_ACCESS_DEL:
1038 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
1039 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
1041 case CMD_ACT_BT_ACCESS_LIST:
1042 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1044 case CMD_ACT_BT_ACCESS_RESET:
1046 case CMD_ACT_BT_ACCESS_SET_INVERT:
1047 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1049 case CMD_ACT_BT_ACCESS_GET_INVERT:
1054 lbs_deb_leave(LBS_DEB_CMD);
1058 static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
1059 u16 cmd_action, void *pdata_buf)
1061 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
1062 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
1064 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
1065 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
1069 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1071 memset(fwt_access, 0, sizeof(*fwt_access));
1073 fwt_access->action = cpu_to_le16(cmd_action);
1075 lbs_deb_leave(LBS_DEB_CMD);
1079 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1080 struct cmd_ds_mesh_access *cmd)
1084 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
1086 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
1087 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
1088 cmd->hdr.result = 0;
1090 cmd->action = cpu_to_le16(cmd_action);
1092 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
1094 lbs_deb_leave(LBS_DEB_CMD);
1098 static int __lbs_mesh_config_send(struct lbs_private *priv,
1099 struct cmd_ds_mesh_config *cmd,
1100 uint16_t action, uint16_t type)
1103 u16 command = CMD_MESH_CONFIG_OLD;
1105 lbs_deb_enter(LBS_DEB_CMD);
1108 * Command id is 0xac for v10 FW along with mesh interface
1109 * id in bits 14-13-12.
1111 if (priv->mesh_fw_ver == MESH_FW_NEW)
1112 command = CMD_MESH_CONFIG |
1113 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1115 cmd->hdr.command = cpu_to_le16(command);
1116 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1117 cmd->hdr.result = 0;
1119 cmd->type = cpu_to_le16(type);
1120 cmd->action = cpu_to_le16(action);
1122 ret = lbs_cmd_with_response(priv, command, cmd);
1124 lbs_deb_leave(LBS_DEB_CMD);
1128 int lbs_mesh_config_send(struct lbs_private *priv,
1129 struct cmd_ds_mesh_config *cmd,
1130 uint16_t action, uint16_t type)
1134 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1137 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1141 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1142 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1143 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1144 * lbs_mesh_config_send.
1146 int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
1148 struct cmd_ds_mesh_config cmd;
1149 struct mrvl_meshie *ie;
1150 DECLARE_SSID_BUF(ssid);
1152 memset(&cmd, 0, sizeof(cmd));
1153 cmd.channel = cpu_to_le16(chan);
1154 ie = (struct mrvl_meshie *)cmd.data;
1157 case CMD_ACT_MESH_CONFIG_START:
1158 ie->id = WLAN_EID_GENERIC;
1159 ie->val.oui[0] = 0x00;
1160 ie->val.oui[1] = 0x50;
1161 ie->val.oui[2] = 0x43;
1162 ie->val.type = MARVELL_MESH_IE_TYPE;
1163 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1164 ie->val.version = MARVELL_MESH_IE_VERSION;
1165 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1166 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1167 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1168 ie->val.mesh_id_len = priv->mesh_ssid_len;
1169 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
1170 ie->len = sizeof(struct mrvl_meshie_val) -
1171 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
1172 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1174 case CMD_ACT_MESH_CONFIG_STOP:
1179 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1180 action, priv->mesh_tlv, chan,
1181 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
1183 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
1186 static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1187 struct cmd_ds_command *cmd,
1190 struct cmd_ds_802_11_beacon_control
1191 *bcn_ctrl = &cmd->params.bcn_ctrl;
1193 lbs_deb_enter(LBS_DEB_CMD);
1195 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1197 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1199 bcn_ctrl->action = cpu_to_le16(cmd_action);
1200 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1201 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
1203 lbs_deb_leave(LBS_DEB_CMD);
1207 static void lbs_queue_cmd(struct lbs_private *priv,
1208 struct cmd_ctrl_node *cmdnode)
1210 unsigned long flags;
1213 lbs_deb_enter(LBS_DEB_HOST);
1216 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
1219 if (!cmdnode->cmdbuf->size) {
1220 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1223 cmdnode->result = 0;
1225 /* Exit_PS command needs to be queued in the header always. */
1226 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
1227 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
1229 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1230 if (priv->psstate != PS_STATE_FULL_POWER)
1235 spin_lock_irqsave(&priv->driver_lock, flags);
1238 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
1240 list_add(&cmdnode->list, &priv->cmdpendingq);
1242 spin_unlock_irqrestore(&priv->driver_lock, flags);
1244 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
1245 le16_to_cpu(cmdnode->cmdbuf->command));
1248 lbs_deb_leave(LBS_DEB_HOST);
1251 static void lbs_submit_command(struct lbs_private *priv,
1252 struct cmd_ctrl_node *cmdnode)
1254 unsigned long flags;
1255 struct cmd_header *cmd;
1261 lbs_deb_enter(LBS_DEB_HOST);
1263 cmd = cmdnode->cmdbuf;
1265 spin_lock_irqsave(&priv->driver_lock, flags);
1266 priv->cur_cmd = cmdnode;
1267 priv->cur_cmd_retcode = 0;
1268 spin_unlock_irqrestore(&priv->driver_lock, flags);
1270 cmdsize = le16_to_cpu(cmd->size);
1271 command = le16_to_cpu(cmd->command);
1273 /* These commands take longer */
1274 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
1277 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1278 command, le16_to_cpu(cmd->seqnum), cmdsize);
1279 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
1281 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
1284 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
1285 /* Let the timer kick in and retry, and potentially reset
1286 the whole thing if the condition persists */
1290 if (command == CMD_802_11_DEEP_SLEEP) {
1291 if (priv->is_auto_deep_sleep_enabled) {
1292 priv->wakeup_dev_required = 1;
1293 priv->dnld_sent = 0;
1295 priv->is_deep_sleep = 1;
1296 lbs_complete_command(priv, cmdnode, 0);
1298 /* Setup the timer after transmit command */
1299 mod_timer(&priv->command_timer, jiffies + timeo);
1302 lbs_deb_leave(LBS_DEB_HOST);
1306 * This function inserts command node to cmdfreeq
1307 * after cleans it. Requires priv->driver_lock held.
1309 static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1310 struct cmd_ctrl_node *cmdnode)
1312 lbs_deb_enter(LBS_DEB_HOST);
1317 cmdnode->callback = NULL;
1318 cmdnode->callback_arg = 0;
1320 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1322 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1324 lbs_deb_leave(LBS_DEB_HOST);
1327 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1328 struct cmd_ctrl_node *ptempcmd)
1330 unsigned long flags;
1332 spin_lock_irqsave(&priv->driver_lock, flags);
1333 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
1334 spin_unlock_irqrestore(&priv->driver_lock, flags);
1337 void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1340 if (cmd == priv->cur_cmd)
1341 priv->cur_cmd_retcode = result;
1343 cmd->result = result;
1344 cmd->cmdwaitqwoken = 1;
1345 wake_up_interruptible(&cmd->cmdwait_q);
1347 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
1348 __lbs_cleanup_and_insert_cmd(priv, cmd);
1349 priv->cur_cmd = NULL;
1352 int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
1354 struct cmd_ds_802_11_radio_control cmd;
1357 lbs_deb_enter(LBS_DEB_CMD);
1359 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1360 cmd.action = cpu_to_le16(CMD_ACT_SET);
1362 /* Only v8 and below support setting the preamble */
1363 if (priv->fwrelease < 0x09000000) {
1365 case RADIO_PREAMBLE_SHORT:
1366 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1369 case RADIO_PREAMBLE_AUTO:
1370 case RADIO_PREAMBLE_LONG:
1371 cmd.control = cpu_to_le16(preamble);
1379 cmd.control |= cpu_to_le16(0x1);
1381 cmd.control &= cpu_to_le16(~0x1);
1382 priv->txpower_cur = 0;
1385 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1386 radio_on ? "ON" : "OFF", preamble);
1388 priv->radio_on = radio_on;
1390 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
1393 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1397 void lbs_set_mac_control(struct lbs_private *priv)
1399 struct cmd_ds_mac_control cmd;
1401 lbs_deb_enter(LBS_DEB_CMD);
1403 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1404 cmd.action = cpu_to_le16(priv->mac_control);
1407 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
1409 lbs_deb_leave(LBS_DEB_CMD);
1413 * @brief This function prepare the command before send to firmware.
1415 * @param priv A pointer to struct lbs_private structure
1416 * @param cmd_no command number
1417 * @param cmd_action command action: GET or SET
1418 * @param wait_option wait option: wait response or not
1419 * @param cmd_oid cmd oid: treated as sub command
1420 * @param pdata_buf A pointer to informaion buffer
1423 int lbs_prepare_and_send_command(struct lbs_private *priv,
1426 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1429 struct cmd_ctrl_node *cmdnode;
1430 struct cmd_ds_command *cmdptr;
1431 unsigned long flags;
1433 lbs_deb_enter(LBS_DEB_HOST);
1436 lbs_deb_host("PREP_CMD: priv is NULL\n");
1441 if (priv->surpriseremoved) {
1442 lbs_deb_host("PREP_CMD: card removed\n");
1447 if (!lbs_is_cmd_allowed(priv)) {
1452 cmdnode = lbs_get_cmd_ctrl_node(priv);
1454 if (cmdnode == NULL) {
1455 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1457 /* Wake up main thread to execute next command */
1458 wake_up_interruptible(&priv->waitq);
1463 cmdnode->callback = NULL;
1464 cmdnode->callback_arg = (unsigned long)pdata_buf;
1466 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
1468 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1470 /* Set sequence number, command and INT option */
1472 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
1474 cmdptr->command = cpu_to_le16(cmd_no);
1478 case CMD_802_11_PS_MODE:
1479 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
1482 case CMD_MAC_REG_ACCESS:
1483 case CMD_BBP_REG_ACCESS:
1484 case CMD_RF_REG_ACCESS:
1485 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
1488 case CMD_802_11_MONITOR_MODE:
1489 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
1490 cmd_action, pdata_buf);
1493 case CMD_802_11_RSSI:
1494 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
1497 case CMD_802_11_SET_AFC:
1498 case CMD_802_11_GET_AFC:
1500 cmdptr->command = cpu_to_le16(cmd_no);
1501 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1504 memmove(&cmdptr->params.afc,
1505 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1510 case CMD_802_11_TPC_CFG:
1511 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1513 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1516 memmove(&cmdptr->params.tpccfg,
1517 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1521 case CMD_802_11_LED_GPIO_CTRL:
1523 struct mrvl_ie_ledgpio *gpio =
1524 (struct mrvl_ie_ledgpio*)
1525 cmdptr->params.ledgpio.data;
1527 memmove(&cmdptr->params.ledgpio,
1529 sizeof(struct cmd_ds_802_11_led_ctrl));
1532 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
1534 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1536 cpu_to_le16(le16_to_cpu(gpio->header.len)
1538 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1539 gpio->header.len = gpio->header.len;
1546 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
1549 case CMD_FWT_ACCESS:
1550 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
1554 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
1555 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1559 case CMD_802_11_BEACON_CTRL:
1560 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1562 case CMD_802_11_DEEP_SLEEP:
1563 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
1564 cmdptr->size = cpu_to_le16(S_DS_GEN);
1567 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1572 /* return error, since the command preparation failed */
1574 lbs_deb_host("PREP_CMD: command preparation failed\n");
1575 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1580 cmdnode->cmdwaitqwoken = 0;
1582 lbs_queue_cmd(priv, cmdnode);
1583 wake_up_interruptible(&priv->waitq);
1585 if (wait_option & CMD_OPTION_WAITFORRSP) {
1586 lbs_deb_host("PREP_CMD: wait for response\n");
1588 wait_event_interruptible(cmdnode->cmdwait_q,
1589 cmdnode->cmdwaitqwoken);
1592 spin_lock_irqsave(&priv->driver_lock, flags);
1593 if (priv->cur_cmd_retcode) {
1594 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1595 priv->cur_cmd_retcode);
1596 priv->cur_cmd_retcode = 0;
1599 spin_unlock_irqrestore(&priv->driver_lock, flags);
1602 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1607 * @brief This function allocates the command buffer and link
1608 * it to command free queue.
1610 * @param priv A pointer to struct lbs_private structure
1613 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1618 struct cmd_ctrl_node *cmdarray;
1620 lbs_deb_enter(LBS_DEB_HOST);
1622 /* Allocate and initialize the command array */
1623 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1624 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
1625 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1629 priv->cmd_array = cmdarray;
1631 /* Allocate and initialize each command buffer in the command array */
1632 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1633 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1634 if (!cmdarray[i].cmdbuf) {
1635 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1641 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1642 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1643 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
1648 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1653 * @brief This function frees the command buffer.
1655 * @param priv A pointer to struct lbs_private structure
1658 int lbs_free_cmd_buffer(struct lbs_private *priv)
1660 struct cmd_ctrl_node *cmdarray;
1663 lbs_deb_enter(LBS_DEB_HOST);
1665 /* need to check if cmd array is allocated or not */
1666 if (priv->cmd_array == NULL) {
1667 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1671 cmdarray = priv->cmd_array;
1673 /* Release shared memory buffers */
1674 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1675 if (cmdarray[i].cmdbuf) {
1676 kfree(cmdarray[i].cmdbuf);
1677 cmdarray[i].cmdbuf = NULL;
1681 /* Release cmd_ctrl_node */
1682 if (priv->cmd_array) {
1683 kfree(priv->cmd_array);
1684 priv->cmd_array = NULL;
1688 lbs_deb_leave(LBS_DEB_HOST);
1693 * @brief This function gets a free command node if available in
1694 * command free queue.
1696 * @param priv A pointer to struct lbs_private structure
1697 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1699 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
1701 struct cmd_ctrl_node *tempnode;
1702 unsigned long flags;
1704 lbs_deb_enter(LBS_DEB_HOST);
1709 spin_lock_irqsave(&priv->driver_lock, flags);
1711 if (!list_empty(&priv->cmdfreeq)) {
1712 tempnode = list_first_entry(&priv->cmdfreeq,
1713 struct cmd_ctrl_node, list);
1714 list_del(&tempnode->list);
1716 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1720 spin_unlock_irqrestore(&priv->driver_lock, flags);
1722 lbs_deb_leave(LBS_DEB_HOST);
1727 * @brief This function executes next command in command
1728 * pending queue. It will put firmware back to PS mode
1731 * @param priv A pointer to struct lbs_private structure
1734 int lbs_execute_next_command(struct lbs_private *priv)
1736 struct cmd_ctrl_node *cmdnode = NULL;
1737 struct cmd_header *cmd;
1738 unsigned long flags;
1741 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1742 * only caller to us is lbs_thread() and we get even when a
1743 * data packet is received */
1744 lbs_deb_enter(LBS_DEB_THREAD);
1746 spin_lock_irqsave(&priv->driver_lock, flags);
1748 if (priv->cur_cmd) {
1749 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1750 spin_unlock_irqrestore(&priv->driver_lock, flags);
1755 if (!list_empty(&priv->cmdpendingq)) {
1756 cmdnode = list_first_entry(&priv->cmdpendingq,
1757 struct cmd_ctrl_node, list);
1760 spin_unlock_irqrestore(&priv->driver_lock, flags);
1763 cmd = cmdnode->cmdbuf;
1765 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
1766 if ((priv->psstate == PS_STATE_SLEEP) ||
1767 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1769 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1770 le16_to_cpu(cmd->command),
1775 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1776 "0x%04x in psstate %d\n",
1777 le16_to_cpu(cmd->command), priv->psstate);
1778 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1780 * 1. Non-PS command:
1781 * Queue it. set needtowakeup to TRUE if current state
1782 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1783 * 2. PS command but not Exit_PS:
1785 * 3. PS command Exit_PS:
1786 * Set needtowakeup to TRUE if current state is SLEEP,
1787 * otherwise send this command down to firmware
1790 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
1791 /* Prepare to send Exit PS,
1792 * this non PS command will be sent later */
1793 if ((priv->psstate == PS_STATE_SLEEP)
1794 || (priv->psstate == PS_STATE_PRE_SLEEP)
1796 /* w/ new scheme, it will not reach here.
1797 since it is blocked in main_thread. */
1798 priv->needtowakeup = 1;
1800 lbs_ps_wakeup(priv, 0);
1806 * PS command. Ignore it if it is not Exit_PS.
1807 * otherwise send it down immediately.
1809 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
1812 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1815 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1817 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1818 list_del(&cmdnode->list);
1819 spin_lock_irqsave(&priv->driver_lock, flags);
1820 lbs_complete_command(priv, cmdnode, 0);
1821 spin_unlock_irqrestore(&priv->driver_lock, flags);
1827 if ((priv->psstate == PS_STATE_SLEEP) ||
1828 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1830 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1831 list_del(&cmdnode->list);
1832 spin_lock_irqsave(&priv->driver_lock, flags);
1833 lbs_complete_command(priv, cmdnode, 0);
1834 spin_unlock_irqrestore(&priv->driver_lock, flags);
1835 priv->needtowakeup = 1;
1842 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1845 list_del(&cmdnode->list);
1846 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1847 le16_to_cpu(cmd->command));
1848 lbs_submit_command(priv, cmdnode);
1851 * check if in power save mode, if yes, put the device back
1854 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1855 (priv->psstate == PS_STATE_FULL_POWER) &&
1856 ((priv->connect_status == LBS_CONNECTED) ||
1857 (priv->mesh_connect_status == LBS_CONNECTED))) {
1858 if (priv->secinfo.WPAenabled ||
1859 priv->secinfo.WPA2enabled) {
1860 /* check for valid WPA group keys */
1861 if (priv->wpa_mcast_key.len ||
1862 priv->wpa_unicast_key.len) {
1864 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1865 " go back to PS_SLEEP");
1866 lbs_ps_sleep(priv, 0);
1870 "EXEC_NEXT_CMD: cmdpendingq empty, "
1871 "go back to PS_SLEEP");
1872 lbs_ps_sleep(priv, 0);
1879 lbs_deb_leave(LBS_DEB_THREAD);
1883 void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
1885 union iwreq_data iwrq;
1888 lbs_deb_enter(LBS_DEB_WEXT);
1890 memset(&iwrq, 0, sizeof(union iwreq_data));
1891 memset(buf, 0, sizeof(buf));
1893 snprintf(buf, sizeof(buf) - 1, "%s", str);
1895 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1897 /* Send Event to upper layer */
1898 lbs_deb_wext("event indication string %s\n", (char *)buf);
1899 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1900 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
1902 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
1904 lbs_deb_leave(LBS_DEB_WEXT);
1907 static void lbs_send_confirmsleep(struct lbs_private *priv)
1909 unsigned long flags;
1912 lbs_deb_enter(LBS_DEB_HOST);
1913 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1914 sizeof(confirm_sleep));
1916 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1917 sizeof(confirm_sleep));
1919 lbs_pr_alert("confirm_sleep failed\n");
1923 spin_lock_irqsave(&priv->driver_lock, flags);
1925 /* We don't get a response on the sleep-confirmation */
1926 priv->dnld_sent = DNLD_RES_RECEIVED;
1928 /* If nothing to do, go back to sleep (?) */
1929 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1930 priv->psstate = PS_STATE_SLEEP;
1932 spin_unlock_irqrestore(&priv->driver_lock, flags);
1935 lbs_deb_leave(LBS_DEB_HOST);
1938 void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
1940 lbs_deb_enter(LBS_DEB_HOST);
1943 * PS is currently supported only in Infrastructure mode
1944 * Remove this check if it is to be supported in IBSS mode also
1947 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1948 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1950 lbs_deb_leave(LBS_DEB_HOST);
1954 * @brief This function sends Exit_PS command to firmware.
1956 * @param priv A pointer to struct lbs_private structure
1957 * @param wait_option wait response or not
1960 void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
1964 lbs_deb_enter(LBS_DEB_HOST);
1966 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
1968 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1970 wait_option, 0, &Localpsmode);
1972 lbs_deb_leave(LBS_DEB_HOST);
1976 * @brief This function checks condition and prepares to
1977 * send sleep confirm command to firmware if ok.
1979 * @param priv A pointer to struct lbs_private structure
1980 * @param psmode Power Saving mode
1983 void lbs_ps_confirm_sleep(struct lbs_private *priv)
1985 unsigned long flags =0;
1988 lbs_deb_enter(LBS_DEB_HOST);
1990 spin_lock_irqsave(&priv->driver_lock, flags);
1991 if (priv->dnld_sent) {
1993 lbs_deb_host("dnld_sent was set\n");
1996 /* In-progress command? */
1997 if (priv->cur_cmd) {
1999 lbs_deb_host("cur_cmd was set\n");
2002 /* Pending events or command responses? */
2003 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
2005 lbs_deb_host("pending events or command responses\n");
2007 spin_unlock_irqrestore(&priv->driver_lock, flags);
2010 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
2011 lbs_send_confirmsleep(priv);
2013 lbs_deb_host("sleep confirm has been delayed\n");
2016 lbs_deb_leave(LBS_DEB_HOST);
2021 * @brief Configures the transmission power control functionality.
2023 * @param priv A pointer to struct lbs_private structure
2024 * @param enable Transmission power control enable
2025 * @param p0 Power level when link quality is good (dBm).
2026 * @param p1 Power level when link quality is fair (dBm).
2027 * @param p2 Power level when link quality is poor (dBm).
2028 * @param usesnr Use Signal to Noise Ratio in TPC
2030 * @return 0 on success
2032 int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
2033 int8_t p2, int usesnr)
2035 struct cmd_ds_802_11_tpc_cfg cmd;
2038 memset(&cmd, 0, sizeof(cmd));
2039 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2040 cmd.action = cpu_to_le16(CMD_ACT_SET);
2041 cmd.enable = !!enable;
2042 cmd.usesnr = !!usesnr;
2047 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
2053 * @brief Configures the power adaptation settings.
2055 * @param priv A pointer to struct lbs_private structure
2056 * @param enable Power adaptation enable
2057 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2058 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2059 * @param p2 Power level for 48 and 54 Mbps (dBm).
2061 * @return 0 on Success
2064 int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
2065 int8_t p1, int8_t p2)
2067 struct cmd_ds_802_11_pa_cfg cmd;
2070 memset(&cmd, 0, sizeof(cmd));
2071 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2072 cmd.action = cpu_to_le16(CMD_ACT_SET);
2073 cmd.enable = !!enable;
2078 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2084 struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
2085 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
2086 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2087 unsigned long callback_arg)
2089 struct cmd_ctrl_node *cmdnode;
2091 lbs_deb_enter(LBS_DEB_HOST);
2093 if (priv->surpriseremoved) {
2094 lbs_deb_host("PREP_CMD: card removed\n");
2095 cmdnode = ERR_PTR(-ENOENT);
2099 if (!lbs_is_cmd_allowed(priv)) {
2100 cmdnode = ERR_PTR(-EBUSY);
2104 cmdnode = lbs_get_cmd_ctrl_node(priv);
2105 if (cmdnode == NULL) {
2106 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2108 /* Wake up main thread to execute next command */
2109 wake_up_interruptible(&priv->waitq);
2110 cmdnode = ERR_PTR(-ENOBUFS);
2114 cmdnode->callback = callback;
2115 cmdnode->callback_arg = callback_arg;
2117 /* Copy the incoming command to the buffer */
2118 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
2120 /* Set sequence number, clean result, move to buffer */
2122 cmdnode->cmdbuf->command = cpu_to_le16(command);
2123 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2124 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2125 cmdnode->cmdbuf->result = 0;
2127 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2129 cmdnode->cmdwaitqwoken = 0;
2130 lbs_queue_cmd(priv, cmdnode);
2131 wake_up_interruptible(&priv->waitq);
2134 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2138 void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2139 struct cmd_header *in_cmd, int in_cmd_size)
2141 lbs_deb_enter(LBS_DEB_CMD);
2142 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2143 lbs_cmd_async_callback, 0);
2144 lbs_deb_leave(LBS_DEB_CMD);
2147 int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2148 struct cmd_header *in_cmd, int in_cmd_size,
2149 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2150 unsigned long callback_arg)
2152 struct cmd_ctrl_node *cmdnode;
2153 unsigned long flags;
2156 lbs_deb_enter(LBS_DEB_HOST);
2158 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2159 callback, callback_arg);
2160 if (IS_ERR(cmdnode)) {
2161 ret = PTR_ERR(cmdnode);
2166 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2168 spin_lock_irqsave(&priv->driver_lock, flags);
2169 ret = cmdnode->result;
2171 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2174 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
2175 spin_unlock_irqrestore(&priv->driver_lock, flags);
2178 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2181 EXPORT_SYMBOL_GPL(__lbs_cmd);