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) +
242 sizeof(struct cmd_header));
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);
368 * @brief Set an SNMP MIB value
370 * @param priv A pointer to struct lbs_private structure
371 * @param oid The OID to set in the firmware
372 * @param val Value to set the OID to
374 * @return 0 on success, error on failure
376 int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
378 struct cmd_ds_802_11_snmp_mib cmd;
381 lbs_deb_enter(LBS_DEB_CMD);
383 memset(&cmd, 0, sizeof (cmd));
384 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
385 cmd.action = cpu_to_le16(CMD_ACT_SET);
386 cmd.oid = cpu_to_le16((u16) oid);
389 case SNMP_MIB_OID_BSS_TYPE:
390 cmd.bufsize = cpu_to_le16(sizeof(u8));
391 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
393 case SNMP_MIB_OID_11D_ENABLE:
394 case SNMP_MIB_OID_FRAG_THRESHOLD:
395 case SNMP_MIB_OID_RTS_THRESHOLD:
396 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
397 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
398 cmd.bufsize = cpu_to_le16(sizeof(u16));
399 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
402 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
407 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
408 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
410 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
413 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
418 * @brief Get an SNMP MIB value
420 * @param priv A pointer to struct lbs_private structure
421 * @param oid The OID to retrieve from the firmware
422 * @param out_val Location for the returned value
424 * @return 0 on success, error on failure
426 int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
428 struct cmd_ds_802_11_snmp_mib cmd;
431 lbs_deb_enter(LBS_DEB_CMD);
433 memset(&cmd, 0, sizeof (cmd));
434 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
435 cmd.action = cpu_to_le16(CMD_ACT_GET);
436 cmd.oid = cpu_to_le16(oid);
438 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
442 switch (le16_to_cpu(cmd.bufsize)) {
444 if (oid == SNMP_MIB_OID_BSS_TYPE) {
445 if (cmd.value[0] == 2)
446 *out_val = IW_MODE_ADHOC;
448 *out_val = IW_MODE_INFRA;
450 *out_val = cmd.value[0];
453 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
456 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
457 oid, le16_to_cpu(cmd.bufsize));
462 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
467 * @brief Get the min, max, and current TX power
469 * @param priv A pointer to struct lbs_private structure
470 * @param curlevel Current power level in dBm
471 * @param minlevel Minimum supported power level in dBm (optional)
472 * @param maxlevel Maximum supported power level in dBm (optional)
474 * @return 0 on success, error on failure
476 int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
479 struct cmd_ds_802_11_rf_tx_power cmd;
482 lbs_deb_enter(LBS_DEB_CMD);
484 memset(&cmd, 0, sizeof(cmd));
485 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
486 cmd.action = cpu_to_le16(CMD_ACT_GET);
488 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
490 *curlevel = le16_to_cpu(cmd.curlevel);
492 *minlevel = cmd.minlevel;
494 *maxlevel = cmd.maxlevel;
497 lbs_deb_leave(LBS_DEB_CMD);
502 * @brief Set the TX power
504 * @param priv A pointer to struct lbs_private structure
505 * @param dbm The desired power level in dBm
507 * @return 0 on success, error on failure
509 int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
511 struct cmd_ds_802_11_rf_tx_power cmd;
514 lbs_deb_enter(LBS_DEB_CMD);
516 memset(&cmd, 0, sizeof(cmd));
517 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
518 cmd.action = cpu_to_le16(CMD_ACT_SET);
519 cmd.curlevel = cpu_to_le16(dbm);
521 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
523 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
525 lbs_deb_leave(LBS_DEB_CMD);
529 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
530 u16 cmd_action, void *pdata_buf)
532 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
534 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
536 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
537 sizeof(struct cmd_header));
539 monitor->action = cpu_to_le16(cmd_action);
540 if (cmd_action == CMD_ACT_SET) {
542 cpu_to_le16((u16) (*(u32 *) pdata_buf));
549 * @brief Get the radio channel
551 * @param priv A pointer to struct lbs_private structure
553 * @return The channel on success, error on failure
555 static int lbs_get_channel(struct lbs_private *priv)
557 struct cmd_ds_802_11_rf_channel cmd;
560 lbs_deb_enter(LBS_DEB_CMD);
562 memset(&cmd, 0, sizeof(cmd));
563 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
564 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
566 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
570 ret = le16_to_cpu(cmd.channel);
571 lbs_deb_cmd("current radio channel is %d\n", ret);
574 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
578 int lbs_update_channel(struct lbs_private *priv)
582 /* the channel in f/w could be out of sync; get the current channel */
583 lbs_deb_enter(LBS_DEB_ASSOC);
585 ret = lbs_get_channel(priv);
590 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
595 * @brief Set the radio channel
597 * @param priv A pointer to struct lbs_private structure
598 * @param channel The desired channel, or 0 to clear a locked channel
600 * @return 0 on success, error on failure
602 int lbs_set_channel(struct lbs_private *priv, u8 channel)
604 struct cmd_ds_802_11_rf_channel cmd;
606 u8 old_channel = priv->channel;
610 lbs_deb_enter(LBS_DEB_CMD);
612 memset(&cmd, 0, sizeof(cmd));
613 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
614 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
615 cmd.channel = cpu_to_le16(channel);
617 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
621 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
622 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
626 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
630 static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
631 u8 cmd_action, void *pdata_buf)
633 struct lbs_offset_value *offval;
635 lbs_deb_enter(LBS_DEB_CMD);
637 offval = (struct lbs_offset_value *)pdata_buf;
639 switch (le16_to_cpu(cmdptr->command)) {
640 case CMD_MAC_REG_ACCESS:
642 struct cmd_ds_mac_reg_access *macreg;
645 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
646 + sizeof(struct cmd_header));
648 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
651 macreg->action = cpu_to_le16(cmd_action);
652 macreg->offset = cpu_to_le16((u16) offval->offset);
653 macreg->value = cpu_to_le32(offval->value);
658 case CMD_BBP_REG_ACCESS:
660 struct cmd_ds_bbp_reg_access *bbpreg;
664 (struct cmd_ds_bbp_reg_access)
665 + sizeof(struct cmd_header));
667 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
670 bbpreg->action = cpu_to_le16(cmd_action);
671 bbpreg->offset = cpu_to_le16((u16) offval->offset);
672 bbpreg->value = (u8) offval->value;
677 case CMD_RF_REG_ACCESS:
679 struct cmd_ds_rf_reg_access *rfreg;
683 (struct cmd_ds_rf_reg_access) +
684 sizeof(struct cmd_header));
686 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
689 rfreg->action = cpu_to_le16(cmd_action);
690 rfreg->offset = cpu_to_le16((u16) offval->offset);
691 rfreg->value = (u8) offval->value;
700 lbs_deb_leave(LBS_DEB_CMD);
704 static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
705 u16 cmd_action, void *pdata_buf)
707 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
708 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
710 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
711 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
712 sizeof(struct cmd_header));
714 bt_access->action = cpu_to_le16(cmd_action);
716 switch (cmd_action) {
717 case CMD_ACT_BT_ACCESS_ADD:
718 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
719 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
721 case CMD_ACT_BT_ACCESS_DEL:
722 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
723 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
725 case CMD_ACT_BT_ACCESS_LIST:
726 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
728 case CMD_ACT_BT_ACCESS_RESET:
730 case CMD_ACT_BT_ACCESS_SET_INVERT:
731 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
733 case CMD_ACT_BT_ACCESS_GET_INVERT:
738 lbs_deb_leave(LBS_DEB_CMD);
742 static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
743 u16 cmd_action, void *pdata_buf)
745 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
746 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
748 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
749 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
750 sizeof(struct cmd_header));
754 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
756 memset(fwt_access, 0, sizeof(*fwt_access));
758 fwt_access->action = cpu_to_le16(cmd_action);
760 lbs_deb_leave(LBS_DEB_CMD);
764 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
765 struct cmd_ds_mesh_access *cmd)
769 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
771 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
772 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
775 cmd->action = cpu_to_le16(cmd_action);
777 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
779 lbs_deb_leave(LBS_DEB_CMD);
783 static int __lbs_mesh_config_send(struct lbs_private *priv,
784 struct cmd_ds_mesh_config *cmd,
785 uint16_t action, uint16_t type)
788 u16 command = CMD_MESH_CONFIG_OLD;
790 lbs_deb_enter(LBS_DEB_CMD);
793 * Command id is 0xac for v10 FW along with mesh interface
794 * id in bits 14-13-12.
796 if (priv->mesh_fw_ver == MESH_FW_NEW)
797 command = CMD_MESH_CONFIG |
798 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
800 cmd->hdr.command = cpu_to_le16(command);
801 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
804 cmd->type = cpu_to_le16(type);
805 cmd->action = cpu_to_le16(action);
807 ret = lbs_cmd_with_response(priv, command, cmd);
809 lbs_deb_leave(LBS_DEB_CMD);
813 int lbs_mesh_config_send(struct lbs_private *priv,
814 struct cmd_ds_mesh_config *cmd,
815 uint16_t action, uint16_t type)
819 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
822 ret = __lbs_mesh_config_send(priv, cmd, action, type);
826 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
827 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
828 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
829 * lbs_mesh_config_send.
831 int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
833 struct cmd_ds_mesh_config cmd;
834 struct mrvl_meshie *ie;
835 DECLARE_SSID_BUF(ssid);
837 memset(&cmd, 0, sizeof(cmd));
838 cmd.channel = cpu_to_le16(chan);
839 ie = (struct mrvl_meshie *)cmd.data;
842 case CMD_ACT_MESH_CONFIG_START:
843 ie->id = WLAN_EID_GENERIC;
844 ie->val.oui[0] = 0x00;
845 ie->val.oui[1] = 0x50;
846 ie->val.oui[2] = 0x43;
847 ie->val.type = MARVELL_MESH_IE_TYPE;
848 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
849 ie->val.version = MARVELL_MESH_IE_VERSION;
850 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
851 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
852 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
853 ie->val.mesh_id_len = priv->mesh_ssid_len;
854 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
855 ie->len = sizeof(struct mrvl_meshie_val) -
856 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
857 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
859 case CMD_ACT_MESH_CONFIG_STOP:
864 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
865 action, priv->mesh_tlv, chan,
866 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
868 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
871 static void lbs_queue_cmd(struct lbs_private *priv,
872 struct cmd_ctrl_node *cmdnode)
877 lbs_deb_enter(LBS_DEB_HOST);
880 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
883 if (!cmdnode->cmdbuf->size) {
884 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
889 /* Exit_PS command needs to be queued in the header always. */
890 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
891 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
893 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
894 if (priv->psstate != PS_STATE_FULL_POWER)
899 spin_lock_irqsave(&priv->driver_lock, flags);
902 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
904 list_add(&cmdnode->list, &priv->cmdpendingq);
906 spin_unlock_irqrestore(&priv->driver_lock, flags);
908 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
909 le16_to_cpu(cmdnode->cmdbuf->command));
912 lbs_deb_leave(LBS_DEB_HOST);
915 static void lbs_submit_command(struct lbs_private *priv,
916 struct cmd_ctrl_node *cmdnode)
919 struct cmd_header *cmd;
925 lbs_deb_enter(LBS_DEB_HOST);
927 cmd = cmdnode->cmdbuf;
929 spin_lock_irqsave(&priv->driver_lock, flags);
930 priv->cur_cmd = cmdnode;
931 priv->cur_cmd_retcode = 0;
932 spin_unlock_irqrestore(&priv->driver_lock, flags);
934 cmdsize = le16_to_cpu(cmd->size);
935 command = le16_to_cpu(cmd->command);
937 /* These commands take longer */
938 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
941 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
942 command, le16_to_cpu(cmd->seqnum), cmdsize);
943 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
945 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
948 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
949 /* Let the timer kick in and retry, and potentially reset
950 the whole thing if the condition persists */
954 if (command == CMD_802_11_DEEP_SLEEP) {
955 if (priv->is_auto_deep_sleep_enabled) {
956 priv->wakeup_dev_required = 1;
959 priv->is_deep_sleep = 1;
960 lbs_complete_command(priv, cmdnode, 0);
962 /* Setup the timer after transmit command */
963 mod_timer(&priv->command_timer, jiffies + timeo);
966 lbs_deb_leave(LBS_DEB_HOST);
970 * This function inserts command node to cmdfreeq
971 * after cleans it. Requires priv->driver_lock held.
973 static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
974 struct cmd_ctrl_node *cmdnode)
976 lbs_deb_enter(LBS_DEB_HOST);
981 cmdnode->callback = NULL;
982 cmdnode->callback_arg = 0;
984 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
986 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
988 lbs_deb_leave(LBS_DEB_HOST);
991 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
992 struct cmd_ctrl_node *ptempcmd)
996 spin_lock_irqsave(&priv->driver_lock, flags);
997 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
998 spin_unlock_irqrestore(&priv->driver_lock, flags);
1001 void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1004 if (cmd == priv->cur_cmd)
1005 priv->cur_cmd_retcode = result;
1007 cmd->result = result;
1008 cmd->cmdwaitqwoken = 1;
1009 wake_up_interruptible(&cmd->cmdwait_q);
1011 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
1012 __lbs_cleanup_and_insert_cmd(priv, cmd);
1013 priv->cur_cmd = NULL;
1016 int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
1018 struct cmd_ds_802_11_radio_control cmd;
1021 lbs_deb_enter(LBS_DEB_CMD);
1023 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1024 cmd.action = cpu_to_le16(CMD_ACT_SET);
1026 /* Only v8 and below support setting the preamble */
1027 if (priv->fwrelease < 0x09000000) {
1029 case RADIO_PREAMBLE_SHORT:
1030 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1033 case RADIO_PREAMBLE_AUTO:
1034 case RADIO_PREAMBLE_LONG:
1035 cmd.control = cpu_to_le16(preamble);
1043 cmd.control |= cpu_to_le16(0x1);
1045 cmd.control &= cpu_to_le16(~0x1);
1046 priv->txpower_cur = 0;
1049 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1050 radio_on ? "ON" : "OFF", preamble);
1052 priv->radio_on = radio_on;
1054 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
1057 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1061 void lbs_set_mac_control(struct lbs_private *priv)
1063 struct cmd_ds_mac_control cmd;
1065 lbs_deb_enter(LBS_DEB_CMD);
1067 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1068 cmd.action = cpu_to_le16(priv->mac_control);
1071 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
1073 lbs_deb_leave(LBS_DEB_CMD);
1077 * @brief This function prepare the command before send to firmware.
1079 * @param priv A pointer to struct lbs_private structure
1080 * @param cmd_no command number
1081 * @param cmd_action command action: GET or SET
1082 * @param wait_option wait option: wait response or not
1083 * @param cmd_oid cmd oid: treated as sub command
1084 * @param pdata_buf A pointer to informaion buffer
1087 int lbs_prepare_and_send_command(struct lbs_private *priv,
1090 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1093 struct cmd_ctrl_node *cmdnode;
1094 struct cmd_ds_command *cmdptr;
1095 unsigned long flags;
1097 lbs_deb_enter(LBS_DEB_HOST);
1100 lbs_deb_host("PREP_CMD: priv is NULL\n");
1105 if (priv->surpriseremoved) {
1106 lbs_deb_host("PREP_CMD: card removed\n");
1111 if (!lbs_is_cmd_allowed(priv)) {
1116 cmdnode = lbs_get_cmd_ctrl_node(priv);
1118 if (cmdnode == NULL) {
1119 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1121 /* Wake up main thread to execute next command */
1122 wake_up_interruptible(&priv->waitq);
1127 cmdnode->callback = NULL;
1128 cmdnode->callback_arg = (unsigned long)pdata_buf;
1130 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
1132 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1134 /* Set sequence number, command and INT option */
1136 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
1138 cmdptr->command = cpu_to_le16(cmd_no);
1142 case CMD_802_11_PS_MODE:
1143 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
1146 case CMD_MAC_REG_ACCESS:
1147 case CMD_BBP_REG_ACCESS:
1148 case CMD_RF_REG_ACCESS:
1149 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
1152 case CMD_802_11_MONITOR_MODE:
1153 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
1154 cmd_action, pdata_buf);
1157 case CMD_802_11_RSSI:
1158 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
1161 case CMD_802_11_SET_AFC:
1162 case CMD_802_11_GET_AFC:
1164 cmdptr->command = cpu_to_le16(cmd_no);
1165 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1166 sizeof(struct cmd_header));
1168 memmove(&cmdptr->params.afc,
1169 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1174 case CMD_802_11_TPC_CFG:
1175 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1177 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1178 sizeof(struct cmd_header));
1180 memmove(&cmdptr->params.tpccfg,
1181 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1187 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
1190 case CMD_FWT_ACCESS:
1191 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
1194 case CMD_802_11_BEACON_CTRL:
1195 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1197 case CMD_802_11_DEEP_SLEEP:
1198 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
1199 cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
1202 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1207 /* return error, since the command preparation failed */
1209 lbs_deb_host("PREP_CMD: command preparation failed\n");
1210 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1215 cmdnode->cmdwaitqwoken = 0;
1217 lbs_queue_cmd(priv, cmdnode);
1218 wake_up_interruptible(&priv->waitq);
1220 if (wait_option & CMD_OPTION_WAITFORRSP) {
1221 lbs_deb_host("PREP_CMD: wait for response\n");
1223 wait_event_interruptible(cmdnode->cmdwait_q,
1224 cmdnode->cmdwaitqwoken);
1227 spin_lock_irqsave(&priv->driver_lock, flags);
1228 if (priv->cur_cmd_retcode) {
1229 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1230 priv->cur_cmd_retcode);
1231 priv->cur_cmd_retcode = 0;
1234 spin_unlock_irqrestore(&priv->driver_lock, flags);
1237 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1242 * @brief This function allocates the command buffer and link
1243 * it to command free queue.
1245 * @param priv A pointer to struct lbs_private structure
1248 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1253 struct cmd_ctrl_node *cmdarray;
1255 lbs_deb_enter(LBS_DEB_HOST);
1257 /* Allocate and initialize the command array */
1258 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1259 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
1260 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1264 priv->cmd_array = cmdarray;
1266 /* Allocate and initialize each command buffer in the command array */
1267 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1268 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1269 if (!cmdarray[i].cmdbuf) {
1270 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1276 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1277 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1278 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
1283 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1288 * @brief This function frees the command buffer.
1290 * @param priv A pointer to struct lbs_private structure
1293 int lbs_free_cmd_buffer(struct lbs_private *priv)
1295 struct cmd_ctrl_node *cmdarray;
1298 lbs_deb_enter(LBS_DEB_HOST);
1300 /* need to check if cmd array is allocated or not */
1301 if (priv->cmd_array == NULL) {
1302 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1306 cmdarray = priv->cmd_array;
1308 /* Release shared memory buffers */
1309 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1310 if (cmdarray[i].cmdbuf) {
1311 kfree(cmdarray[i].cmdbuf);
1312 cmdarray[i].cmdbuf = NULL;
1316 /* Release cmd_ctrl_node */
1317 if (priv->cmd_array) {
1318 kfree(priv->cmd_array);
1319 priv->cmd_array = NULL;
1323 lbs_deb_leave(LBS_DEB_HOST);
1328 * @brief This function gets a free command node if available in
1329 * command free queue.
1331 * @param priv A pointer to struct lbs_private structure
1332 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1334 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
1336 struct cmd_ctrl_node *tempnode;
1337 unsigned long flags;
1339 lbs_deb_enter(LBS_DEB_HOST);
1344 spin_lock_irqsave(&priv->driver_lock, flags);
1346 if (!list_empty(&priv->cmdfreeq)) {
1347 tempnode = list_first_entry(&priv->cmdfreeq,
1348 struct cmd_ctrl_node, list);
1349 list_del(&tempnode->list);
1351 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1355 spin_unlock_irqrestore(&priv->driver_lock, flags);
1357 lbs_deb_leave(LBS_DEB_HOST);
1362 * @brief This function executes next command in command
1363 * pending queue. It will put firmware back to PS mode
1366 * @param priv A pointer to struct lbs_private structure
1369 int lbs_execute_next_command(struct lbs_private *priv)
1371 struct cmd_ctrl_node *cmdnode = NULL;
1372 struct cmd_header *cmd;
1373 unsigned long flags;
1376 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1377 * only caller to us is lbs_thread() and we get even when a
1378 * data packet is received */
1379 lbs_deb_enter(LBS_DEB_THREAD);
1381 spin_lock_irqsave(&priv->driver_lock, flags);
1383 if (priv->cur_cmd) {
1384 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1385 spin_unlock_irqrestore(&priv->driver_lock, flags);
1390 if (!list_empty(&priv->cmdpendingq)) {
1391 cmdnode = list_first_entry(&priv->cmdpendingq,
1392 struct cmd_ctrl_node, list);
1395 spin_unlock_irqrestore(&priv->driver_lock, flags);
1398 cmd = cmdnode->cmdbuf;
1400 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
1401 if ((priv->psstate == PS_STATE_SLEEP) ||
1402 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1404 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1405 le16_to_cpu(cmd->command),
1410 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1411 "0x%04x in psstate %d\n",
1412 le16_to_cpu(cmd->command), priv->psstate);
1413 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1415 * 1. Non-PS command:
1416 * Queue it. set needtowakeup to TRUE if current state
1417 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1418 * 2. PS command but not Exit_PS:
1420 * 3. PS command Exit_PS:
1421 * Set needtowakeup to TRUE if current state is SLEEP,
1422 * otherwise send this command down to firmware
1425 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
1426 /* Prepare to send Exit PS,
1427 * this non PS command will be sent later */
1428 if ((priv->psstate == PS_STATE_SLEEP)
1429 || (priv->psstate == PS_STATE_PRE_SLEEP)
1431 /* w/ new scheme, it will not reach here.
1432 since it is blocked in main_thread. */
1433 priv->needtowakeup = 1;
1435 lbs_ps_wakeup(priv, 0);
1441 * PS command. Ignore it if it is not Exit_PS.
1442 * otherwise send it down immediately.
1444 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
1447 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1450 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1452 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1453 list_del(&cmdnode->list);
1454 spin_lock_irqsave(&priv->driver_lock, flags);
1455 lbs_complete_command(priv, cmdnode, 0);
1456 spin_unlock_irqrestore(&priv->driver_lock, flags);
1462 if ((priv->psstate == PS_STATE_SLEEP) ||
1463 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1465 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1466 list_del(&cmdnode->list);
1467 spin_lock_irqsave(&priv->driver_lock, flags);
1468 lbs_complete_command(priv, cmdnode, 0);
1469 spin_unlock_irqrestore(&priv->driver_lock, flags);
1470 priv->needtowakeup = 1;
1477 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1480 list_del(&cmdnode->list);
1481 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1482 le16_to_cpu(cmd->command));
1483 lbs_submit_command(priv, cmdnode);
1486 * check if in power save mode, if yes, put the device back
1489 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1490 (priv->psstate == PS_STATE_FULL_POWER) &&
1491 ((priv->connect_status == LBS_CONNECTED) ||
1492 (priv->mesh_connect_status == LBS_CONNECTED))) {
1493 if (priv->secinfo.WPAenabled ||
1494 priv->secinfo.WPA2enabled) {
1495 /* check for valid WPA group keys */
1496 if (priv->wpa_mcast_key.len ||
1497 priv->wpa_unicast_key.len) {
1499 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1500 " go back to PS_SLEEP");
1501 lbs_ps_sleep(priv, 0);
1505 "EXEC_NEXT_CMD: cmdpendingq empty, "
1506 "go back to PS_SLEEP");
1507 lbs_ps_sleep(priv, 0);
1514 lbs_deb_leave(LBS_DEB_THREAD);
1518 static void lbs_send_confirmsleep(struct lbs_private *priv)
1520 unsigned long flags;
1523 lbs_deb_enter(LBS_DEB_HOST);
1524 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1525 sizeof(confirm_sleep));
1527 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1528 sizeof(confirm_sleep));
1530 lbs_pr_alert("confirm_sleep failed\n");
1534 spin_lock_irqsave(&priv->driver_lock, flags);
1536 /* We don't get a response on the sleep-confirmation */
1537 priv->dnld_sent = DNLD_RES_RECEIVED;
1539 /* If nothing to do, go back to sleep (?) */
1540 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1541 priv->psstate = PS_STATE_SLEEP;
1543 spin_unlock_irqrestore(&priv->driver_lock, flags);
1546 lbs_deb_leave(LBS_DEB_HOST);
1549 void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
1551 lbs_deb_enter(LBS_DEB_HOST);
1554 * PS is currently supported only in Infrastructure mode
1555 * Remove this check if it is to be supported in IBSS mode also
1558 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1559 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1561 lbs_deb_leave(LBS_DEB_HOST);
1565 * @brief This function sends Exit_PS command to firmware.
1567 * @param priv A pointer to struct lbs_private structure
1568 * @param wait_option wait response or not
1571 void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
1575 lbs_deb_enter(LBS_DEB_HOST);
1577 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
1579 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1581 wait_option, 0, &Localpsmode);
1583 lbs_deb_leave(LBS_DEB_HOST);
1587 * @brief This function checks condition and prepares to
1588 * send sleep confirm command to firmware if ok.
1590 * @param priv A pointer to struct lbs_private structure
1591 * @param psmode Power Saving mode
1594 void lbs_ps_confirm_sleep(struct lbs_private *priv)
1596 unsigned long flags =0;
1599 lbs_deb_enter(LBS_DEB_HOST);
1601 spin_lock_irqsave(&priv->driver_lock, flags);
1602 if (priv->dnld_sent) {
1604 lbs_deb_host("dnld_sent was set\n");
1607 /* In-progress command? */
1608 if (priv->cur_cmd) {
1610 lbs_deb_host("cur_cmd was set\n");
1613 /* Pending events or command responses? */
1614 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
1616 lbs_deb_host("pending events or command responses\n");
1618 spin_unlock_irqrestore(&priv->driver_lock, flags);
1621 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1622 lbs_send_confirmsleep(priv);
1624 lbs_deb_host("sleep confirm has been delayed\n");
1627 lbs_deb_leave(LBS_DEB_HOST);
1632 * @brief Configures the transmission power control functionality.
1634 * @param priv A pointer to struct lbs_private structure
1635 * @param enable Transmission power control enable
1636 * @param p0 Power level when link quality is good (dBm).
1637 * @param p1 Power level when link quality is fair (dBm).
1638 * @param p2 Power level when link quality is poor (dBm).
1639 * @param usesnr Use Signal to Noise Ratio in TPC
1641 * @return 0 on success
1643 int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1644 int8_t p2, int usesnr)
1646 struct cmd_ds_802_11_tpc_cfg cmd;
1649 memset(&cmd, 0, sizeof(cmd));
1650 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1651 cmd.action = cpu_to_le16(CMD_ACT_SET);
1652 cmd.enable = !!enable;
1653 cmd.usesnr = !!usesnr;
1658 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1664 * @brief Configures the power adaptation settings.
1666 * @param priv A pointer to struct lbs_private structure
1667 * @param enable Power adaptation enable
1668 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1669 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1670 * @param p2 Power level for 48 and 54 Mbps (dBm).
1672 * @return 0 on Success
1675 int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1676 int8_t p1, int8_t p2)
1678 struct cmd_ds_802_11_pa_cfg cmd;
1681 memset(&cmd, 0, sizeof(cmd));
1682 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1683 cmd.action = cpu_to_le16(CMD_ACT_SET);
1684 cmd.enable = !!enable;
1689 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1695 struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1696 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1697 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1698 unsigned long callback_arg)
1700 struct cmd_ctrl_node *cmdnode;
1702 lbs_deb_enter(LBS_DEB_HOST);
1704 if (priv->surpriseremoved) {
1705 lbs_deb_host("PREP_CMD: card removed\n");
1706 cmdnode = ERR_PTR(-ENOENT);
1710 if (!lbs_is_cmd_allowed(priv)) {
1711 cmdnode = ERR_PTR(-EBUSY);
1715 cmdnode = lbs_get_cmd_ctrl_node(priv);
1716 if (cmdnode == NULL) {
1717 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1719 /* Wake up main thread to execute next command */
1720 wake_up_interruptible(&priv->waitq);
1721 cmdnode = ERR_PTR(-ENOBUFS);
1725 cmdnode->callback = callback;
1726 cmdnode->callback_arg = callback_arg;
1728 /* Copy the incoming command to the buffer */
1729 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
1731 /* Set sequence number, clean result, move to buffer */
1733 cmdnode->cmdbuf->command = cpu_to_le16(command);
1734 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1735 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1736 cmdnode->cmdbuf->result = 0;
1738 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1740 cmdnode->cmdwaitqwoken = 0;
1741 lbs_queue_cmd(priv, cmdnode);
1742 wake_up_interruptible(&priv->waitq);
1745 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1749 void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1750 struct cmd_header *in_cmd, int in_cmd_size)
1752 lbs_deb_enter(LBS_DEB_CMD);
1753 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1754 lbs_cmd_async_callback, 0);
1755 lbs_deb_leave(LBS_DEB_CMD);
1758 int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1759 struct cmd_header *in_cmd, int in_cmd_size,
1760 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1761 unsigned long callback_arg)
1763 struct cmd_ctrl_node *cmdnode;
1764 unsigned long flags;
1767 lbs_deb_enter(LBS_DEB_HOST);
1769 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1770 callback, callback_arg);
1771 if (IS_ERR(cmdnode)) {
1772 ret = PTR_ERR(cmdnode);
1777 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1779 spin_lock_irqsave(&priv->driver_lock, flags);
1780 ret = cmdnode->result;
1782 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1785 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
1786 spin_unlock_irqrestore(&priv->driver_lock, flags);
1789 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1792 EXPORT_SYMBOL_GPL(__lbs_cmd);