2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <net/lib80211.h>
7 #include <linux/kfifo.h>
8 #include <linux/sched.h>
20 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
23 * @brief Simple callback that copies response back into command
25 * @param priv A pointer to struct lbs_private structure
26 * @param extra A pointer to the original command structure for which
27 * 'resp' is a response
28 * @param resp A pointer to the command response
30 * @return 0 on success, error on failure
32 int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
33 struct cmd_header *resp)
35 struct cmd_header *buf = (void *)extra;
38 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
39 memcpy(buf, resp, copy_len);
42 EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
45 * @brief Simple callback that ignores the result. Use this if
46 * you just want to send a command to the hardware, but don't
47 * care for the result.
50 * @param extra ignored
53 * @return 0 for success
55 static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
56 struct cmd_header *resp)
63 * @brief Checks whether a command is allowed in Power Save mode
65 * @param command the command ID
66 * @return 1 if allowed, 0 if not allowed
68 static u8 is_command_allowed_in_ps(u16 cmd)
80 * @brief This function checks if the command is allowed.
82 * @param priv A pointer to lbs_private structure
83 * @return allowed or not allowed.
86 static int lbs_is_cmd_allowed(struct lbs_private *priv)
90 lbs_deb_enter(LBS_DEB_CMD);
92 if (!priv->is_auto_deep_sleep_enabled) {
93 if (priv->is_deep_sleep) {
94 lbs_deb_cmd("command not allowed in deep sleep\n");
99 lbs_deb_leave(LBS_DEB_CMD);
104 * @brief Updates the hardware details like MAC address and regulatory region
106 * @param priv A pointer to struct lbs_private structure
108 * @return 0 on success, error on failure
110 int lbs_update_hw_spec(struct lbs_private *priv)
112 struct cmd_ds_get_hw_spec cmd;
116 lbs_deb_enter(LBS_DEB_CMD);
118 memset(&cmd, 0, sizeof(cmd));
119 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
120 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
121 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
125 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
127 /* The firmware release is in an interesting format: the patch
128 * level is in the most significant nibble ... so fix that: */
129 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
130 priv->fwrelease = (priv->fwrelease << 8) |
131 (priv->fwrelease >> 24 & 0xff);
133 /* Some firmware capabilities:
134 * CF card firmware 5.0.16p0: cap 0x00000303
135 * USB dongle firmware 5.110.17p2: cap 0x00000303
137 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
139 priv->fwrelease >> 24 & 0xff,
140 priv->fwrelease >> 16 & 0xff,
141 priv->fwrelease >> 8 & 0xff,
142 priv->fwrelease & 0xff,
144 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
145 cmd.hwifversion, cmd.version);
147 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
148 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
149 /* 5.110.22 have mesh command with 0xa3 command id */
150 /* 10.0.0.p0 FW brings in mesh config command with different id */
151 /* Check FW version MSB and initialize mesh_fw_ver */
152 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
153 priv->mesh_fw_ver = MESH_FW_OLD;
154 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
155 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
156 priv->mesh_fw_ver = MESH_FW_NEW;
158 priv->mesh_fw_ver = MESH_NONE;
160 /* Clamp region code to 8-bit since FW spec indicates that it should
161 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
162 * returns non-zero high 8 bits here.
164 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
165 * need to check for this problem and handle it properly.
167 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
168 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
170 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
172 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
173 /* use the region code to search for the index */
174 if (priv->regioncode == lbs_region_code_to_index[i])
178 /* if it's unidentified region code, use the default (USA) */
179 if (i >= MRVDRV_MAX_REGION_CODE) {
180 priv->regioncode = 0x10;
181 lbs_pr_info("unidentified region code; using the default (USA)\n");
184 if (priv->current_addr[0] == 0xff)
185 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
187 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
189 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
191 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
197 lbs_deb_leave(LBS_DEB_CMD);
201 int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
202 struct wol_config *p_wol_config)
204 struct cmd_ds_host_sleep cmd_config;
207 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
208 cmd_config.criteria = cpu_to_le32(criteria);
209 cmd_config.gpio = priv->wol_gpio;
210 cmd_config.gap = priv->wol_gap;
212 if (p_wol_config != NULL)
213 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
214 sizeof(struct wol_config));
216 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
218 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
221 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
222 priv->wol_criteria = criteria;
224 memcpy((uint8_t *) p_wol_config,
225 (uint8_t *)&cmd_config.wol_conf,
226 sizeof(struct wol_config));
228 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
233 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
235 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
238 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
240 lbs_deb_enter(LBS_DEB_CMD);
242 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
243 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
244 sizeof(struct cmd_header));
245 psm->action = cpu_to_le16(cmd_action);
246 psm->multipledtim = 0;
247 switch (cmd_action) {
248 case CMD_SUBCMD_ENTER_PS:
249 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
251 psm->locallisteninterval = 0;
252 psm->nullpktinterval = 0;
254 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
257 case CMD_SUBCMD_EXIT_PS:
258 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
261 case CMD_SUBCMD_SLEEP_CONFIRMED:
262 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
269 lbs_deb_leave(LBS_DEB_CMD);
273 int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
274 struct sleep_params *sp)
276 struct cmd_ds_802_11_sleep_params cmd;
279 lbs_deb_enter(LBS_DEB_CMD);
281 if (cmd_action == CMD_ACT_GET) {
282 memset(&cmd, 0, sizeof(cmd));
284 cmd.error = cpu_to_le16(sp->sp_error);
285 cmd.offset = cpu_to_le16(sp->sp_offset);
286 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
287 cmd.calcontrol = sp->sp_calcontrol;
288 cmd.externalsleepclk = sp->sp_extsleepclk;
289 cmd.reserved = cpu_to_le16(sp->sp_reserved);
291 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
292 cmd.action = cpu_to_le16(cmd_action);
294 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
297 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
298 "calcontrol 0x%x extsleepclk 0x%x\n",
299 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
300 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
301 cmd.externalsleepclk);
303 sp->sp_error = le16_to_cpu(cmd.error);
304 sp->sp_offset = le16_to_cpu(cmd.offset);
305 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
306 sp->sp_calcontrol = cmd.calcontrol;
307 sp->sp_extsleepclk = cmd.externalsleepclk;
308 sp->sp_reserved = le16_to_cpu(cmd.reserved);
311 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
315 static int lbs_wait_for_ds_awake(struct lbs_private *priv)
319 lbs_deb_enter(LBS_DEB_CMD);
321 if (priv->is_deep_sleep) {
322 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
323 !priv->is_deep_sleep, (10 * HZ))) {
324 lbs_pr_err("ds_awake_q: timer expired\n");
329 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
333 int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
337 lbs_deb_enter(LBS_DEB_CMD);
340 if (priv->is_deep_sleep != 1) {
341 lbs_deb_cmd("deep sleep: sleep\n");
342 BUG_ON(!priv->enter_deep_sleep);
343 ret = priv->enter_deep_sleep(priv);
345 netif_stop_queue(priv->dev);
346 netif_carrier_off(priv->dev);
349 lbs_pr_err("deep sleep: already enabled\n");
352 if (priv->is_deep_sleep) {
353 lbs_deb_cmd("deep sleep: wakeup\n");
354 BUG_ON(!priv->exit_deep_sleep);
355 ret = priv->exit_deep_sleep(priv);
357 ret = lbs_wait_for_ds_awake(priv);
359 lbs_pr_err("deep sleep: wakeup"
365 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
370 * @brief Set an SNMP MIB value
372 * @param priv A pointer to struct lbs_private structure
373 * @param oid The OID to set in the firmware
374 * @param val Value to set the OID to
376 * @return 0 on success, error on failure
378 int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
380 struct cmd_ds_802_11_snmp_mib cmd;
383 lbs_deb_enter(LBS_DEB_CMD);
385 memset(&cmd, 0, sizeof (cmd));
386 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
387 cmd.action = cpu_to_le16(CMD_ACT_SET);
388 cmd.oid = cpu_to_le16((u16) oid);
391 case SNMP_MIB_OID_BSS_TYPE:
392 cmd.bufsize = cpu_to_le16(sizeof(u8));
393 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
395 case SNMP_MIB_OID_11D_ENABLE:
396 case SNMP_MIB_OID_FRAG_THRESHOLD:
397 case SNMP_MIB_OID_RTS_THRESHOLD:
398 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
399 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
400 cmd.bufsize = cpu_to_le16(sizeof(u16));
401 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
404 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
409 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
410 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
412 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
415 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
420 * @brief Get an SNMP MIB value
422 * @param priv A pointer to struct lbs_private structure
423 * @param oid The OID to retrieve from the firmware
424 * @param out_val Location for the returned value
426 * @return 0 on success, error on failure
428 int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
430 struct cmd_ds_802_11_snmp_mib cmd;
433 lbs_deb_enter(LBS_DEB_CMD);
435 memset(&cmd, 0, sizeof (cmd));
436 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
437 cmd.action = cpu_to_le16(CMD_ACT_GET);
438 cmd.oid = cpu_to_le16(oid);
440 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
444 switch (le16_to_cpu(cmd.bufsize)) {
446 if (oid == SNMP_MIB_OID_BSS_TYPE) {
447 if (cmd.value[0] == 2)
448 *out_val = IW_MODE_ADHOC;
450 *out_val = IW_MODE_INFRA;
452 *out_val = cmd.value[0];
455 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
458 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
459 oid, le16_to_cpu(cmd.bufsize));
464 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
469 * @brief Get the min, max, and current TX power
471 * @param priv A pointer to struct lbs_private structure
472 * @param curlevel Current power level in dBm
473 * @param minlevel Minimum supported power level in dBm (optional)
474 * @param maxlevel Maximum supported power level in dBm (optional)
476 * @return 0 on success, error on failure
478 int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
481 struct cmd_ds_802_11_rf_tx_power cmd;
484 lbs_deb_enter(LBS_DEB_CMD);
486 memset(&cmd, 0, sizeof(cmd));
487 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
488 cmd.action = cpu_to_le16(CMD_ACT_GET);
490 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
492 *curlevel = le16_to_cpu(cmd.curlevel);
494 *minlevel = cmd.minlevel;
496 *maxlevel = cmd.maxlevel;
499 lbs_deb_leave(LBS_DEB_CMD);
504 * @brief Set the TX power
506 * @param priv A pointer to struct lbs_private structure
507 * @param dbm The desired power level in dBm
509 * @return 0 on success, error on failure
511 int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
513 struct cmd_ds_802_11_rf_tx_power cmd;
516 lbs_deb_enter(LBS_DEB_CMD);
518 memset(&cmd, 0, sizeof(cmd));
519 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
520 cmd.action = cpu_to_le16(CMD_ACT_SET);
521 cmd.curlevel = cpu_to_le16(dbm);
523 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
525 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
527 lbs_deb_leave(LBS_DEB_CMD);
531 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
532 u16 cmd_action, void *pdata_buf)
534 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
536 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
538 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
539 sizeof(struct cmd_header));
541 monitor->action = cpu_to_le16(cmd_action);
542 if (cmd_action == CMD_ACT_SET) {
544 cpu_to_le16((u16) (*(u32 *) pdata_buf));
551 * @brief Get the radio channel
553 * @param priv A pointer to struct lbs_private structure
555 * @return The channel on success, error on failure
557 static int lbs_get_channel(struct lbs_private *priv)
559 struct cmd_ds_802_11_rf_channel cmd;
562 lbs_deb_enter(LBS_DEB_CMD);
564 memset(&cmd, 0, sizeof(cmd));
565 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
566 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
568 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
572 ret = le16_to_cpu(cmd.channel);
573 lbs_deb_cmd("current radio channel is %d\n", ret);
576 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
580 int lbs_update_channel(struct lbs_private *priv)
584 /* the channel in f/w could be out of sync; get the current channel */
585 lbs_deb_enter(LBS_DEB_ASSOC);
587 ret = lbs_get_channel(priv);
592 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
597 * @brief Set the radio channel
599 * @param priv A pointer to struct lbs_private structure
600 * @param channel The desired channel, or 0 to clear a locked channel
602 * @return 0 on success, error on failure
604 int lbs_set_channel(struct lbs_private *priv, u8 channel)
606 struct cmd_ds_802_11_rf_channel cmd;
608 u8 old_channel = priv->channel;
612 lbs_deb_enter(LBS_DEB_CMD);
614 memset(&cmd, 0, sizeof(cmd));
615 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
616 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
617 cmd.channel = cpu_to_le16(channel);
619 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
623 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
624 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
628 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
632 static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
633 u8 cmd_action, void *pdata_buf)
635 struct lbs_offset_value *offval;
637 lbs_deb_enter(LBS_DEB_CMD);
639 offval = (struct lbs_offset_value *)pdata_buf;
641 switch (le16_to_cpu(cmdptr->command)) {
642 case CMD_MAC_REG_ACCESS:
644 struct cmd_ds_mac_reg_access *macreg;
647 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
648 + sizeof(struct cmd_header));
650 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
653 macreg->action = cpu_to_le16(cmd_action);
654 macreg->offset = cpu_to_le16((u16) offval->offset);
655 macreg->value = cpu_to_le32(offval->value);
660 case CMD_BBP_REG_ACCESS:
662 struct cmd_ds_bbp_reg_access *bbpreg;
666 (struct cmd_ds_bbp_reg_access)
667 + sizeof(struct cmd_header));
669 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
672 bbpreg->action = cpu_to_le16(cmd_action);
673 bbpreg->offset = cpu_to_le16((u16) offval->offset);
674 bbpreg->value = (u8) offval->value;
679 case CMD_RF_REG_ACCESS:
681 struct cmd_ds_rf_reg_access *rfreg;
685 (struct cmd_ds_rf_reg_access) +
686 sizeof(struct cmd_header));
688 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
691 rfreg->action = cpu_to_le16(cmd_action);
692 rfreg->offset = cpu_to_le16((u16) offval->offset);
693 rfreg->value = (u8) offval->value;
702 lbs_deb_leave(LBS_DEB_CMD);
706 static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
707 u16 cmd_action, void *pdata_buf)
709 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
710 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
712 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
713 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) +
714 sizeof(struct cmd_header));
716 bt_access->action = cpu_to_le16(cmd_action);
718 switch (cmd_action) {
719 case CMD_ACT_BT_ACCESS_ADD:
720 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
721 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
723 case CMD_ACT_BT_ACCESS_DEL:
724 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
725 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
727 case CMD_ACT_BT_ACCESS_LIST:
728 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
730 case CMD_ACT_BT_ACCESS_RESET:
732 case CMD_ACT_BT_ACCESS_SET_INVERT:
733 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
735 case CMD_ACT_BT_ACCESS_GET_INVERT:
740 lbs_deb_leave(LBS_DEB_CMD);
744 static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
745 u16 cmd_action, void *pdata_buf)
747 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
748 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
750 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
751 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) +
752 sizeof(struct cmd_header));
756 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
758 memset(fwt_access, 0, sizeof(*fwt_access));
760 fwt_access->action = cpu_to_le16(cmd_action);
762 lbs_deb_leave(LBS_DEB_CMD);
766 int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
767 struct cmd_ds_mesh_access *cmd)
771 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
773 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
774 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
777 cmd->action = cpu_to_le16(cmd_action);
779 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
781 lbs_deb_leave(LBS_DEB_CMD);
785 static int __lbs_mesh_config_send(struct lbs_private *priv,
786 struct cmd_ds_mesh_config *cmd,
787 uint16_t action, uint16_t type)
790 u16 command = CMD_MESH_CONFIG_OLD;
792 lbs_deb_enter(LBS_DEB_CMD);
795 * Command id is 0xac for v10 FW along with mesh interface
796 * id in bits 14-13-12.
798 if (priv->mesh_fw_ver == MESH_FW_NEW)
799 command = CMD_MESH_CONFIG |
800 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
802 cmd->hdr.command = cpu_to_le16(command);
803 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
806 cmd->type = cpu_to_le16(type);
807 cmd->action = cpu_to_le16(action);
809 ret = lbs_cmd_with_response(priv, command, cmd);
811 lbs_deb_leave(LBS_DEB_CMD);
815 int lbs_mesh_config_send(struct lbs_private *priv,
816 struct cmd_ds_mesh_config *cmd,
817 uint16_t action, uint16_t type)
821 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
824 ret = __lbs_mesh_config_send(priv, cmd, action, type);
828 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
829 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
830 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
831 * lbs_mesh_config_send.
833 int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
835 struct cmd_ds_mesh_config cmd;
836 struct mrvl_meshie *ie;
837 DECLARE_SSID_BUF(ssid);
839 memset(&cmd, 0, sizeof(cmd));
840 cmd.channel = cpu_to_le16(chan);
841 ie = (struct mrvl_meshie *)cmd.data;
844 case CMD_ACT_MESH_CONFIG_START:
845 ie->id = WLAN_EID_GENERIC;
846 ie->val.oui[0] = 0x00;
847 ie->val.oui[1] = 0x50;
848 ie->val.oui[2] = 0x43;
849 ie->val.type = MARVELL_MESH_IE_TYPE;
850 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
851 ie->val.version = MARVELL_MESH_IE_VERSION;
852 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
853 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
854 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
855 ie->val.mesh_id_len = priv->mesh_ssid_len;
856 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
857 ie->len = sizeof(struct mrvl_meshie_val) -
858 IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len;
859 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
861 case CMD_ACT_MESH_CONFIG_STOP:
866 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
867 action, priv->mesh_tlv, chan,
868 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
870 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
873 static void lbs_queue_cmd(struct lbs_private *priv,
874 struct cmd_ctrl_node *cmdnode)
879 lbs_deb_enter(LBS_DEB_HOST);
882 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
885 if (!cmdnode->cmdbuf->size) {
886 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
891 /* Exit_PS command needs to be queued in the header always. */
892 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
893 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
895 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
896 if (priv->psstate != PS_STATE_FULL_POWER)
901 spin_lock_irqsave(&priv->driver_lock, flags);
904 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
906 list_add(&cmdnode->list, &priv->cmdpendingq);
908 spin_unlock_irqrestore(&priv->driver_lock, flags);
910 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
911 le16_to_cpu(cmdnode->cmdbuf->command));
914 lbs_deb_leave(LBS_DEB_HOST);
917 static void lbs_submit_command(struct lbs_private *priv,
918 struct cmd_ctrl_node *cmdnode)
921 struct cmd_header *cmd;
927 lbs_deb_enter(LBS_DEB_HOST);
929 cmd = cmdnode->cmdbuf;
931 spin_lock_irqsave(&priv->driver_lock, flags);
932 priv->cur_cmd = cmdnode;
933 priv->cur_cmd_retcode = 0;
934 spin_unlock_irqrestore(&priv->driver_lock, flags);
936 cmdsize = le16_to_cpu(cmd->size);
937 command = le16_to_cpu(cmd->command);
939 /* These commands take longer */
940 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
943 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
944 command, le16_to_cpu(cmd->seqnum), cmdsize);
945 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
947 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
950 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
951 /* Let the timer kick in and retry, and potentially reset
952 the whole thing if the condition persists */
956 if (command == CMD_802_11_DEEP_SLEEP) {
957 if (priv->is_auto_deep_sleep_enabled) {
958 priv->wakeup_dev_required = 1;
961 priv->is_deep_sleep = 1;
962 lbs_complete_command(priv, cmdnode, 0);
964 /* Setup the timer after transmit command */
965 mod_timer(&priv->command_timer, jiffies + timeo);
968 lbs_deb_leave(LBS_DEB_HOST);
972 * This function inserts command node to cmdfreeq
973 * after cleans it. Requires priv->driver_lock held.
975 static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
976 struct cmd_ctrl_node *cmdnode)
978 lbs_deb_enter(LBS_DEB_HOST);
983 cmdnode->callback = NULL;
984 cmdnode->callback_arg = 0;
986 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
988 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
990 lbs_deb_leave(LBS_DEB_HOST);
993 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
994 struct cmd_ctrl_node *ptempcmd)
998 spin_lock_irqsave(&priv->driver_lock, flags);
999 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
1000 spin_unlock_irqrestore(&priv->driver_lock, flags);
1003 void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1006 if (cmd == priv->cur_cmd)
1007 priv->cur_cmd_retcode = result;
1009 cmd->result = result;
1010 cmd->cmdwaitqwoken = 1;
1011 wake_up_interruptible(&cmd->cmdwait_q);
1013 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
1014 __lbs_cleanup_and_insert_cmd(priv, cmd);
1015 priv->cur_cmd = NULL;
1018 int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
1020 struct cmd_ds_802_11_radio_control cmd;
1023 lbs_deb_enter(LBS_DEB_CMD);
1025 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1026 cmd.action = cpu_to_le16(CMD_ACT_SET);
1028 /* Only v8 and below support setting the preamble */
1029 if (priv->fwrelease < 0x09000000) {
1031 case RADIO_PREAMBLE_SHORT:
1032 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1035 case RADIO_PREAMBLE_AUTO:
1036 case RADIO_PREAMBLE_LONG:
1037 cmd.control = cpu_to_le16(preamble);
1045 cmd.control |= cpu_to_le16(0x1);
1047 cmd.control &= cpu_to_le16(~0x1);
1048 priv->txpower_cur = 0;
1051 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1052 radio_on ? "ON" : "OFF", preamble);
1054 priv->radio_on = radio_on;
1056 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
1059 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1063 void lbs_set_mac_control(struct lbs_private *priv)
1065 struct cmd_ds_mac_control cmd;
1067 lbs_deb_enter(LBS_DEB_CMD);
1069 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1070 cmd.action = cpu_to_le16(priv->mac_control);
1073 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
1075 lbs_deb_leave(LBS_DEB_CMD);
1079 * @brief This function prepare the command before send to firmware.
1081 * @param priv A pointer to struct lbs_private structure
1082 * @param cmd_no command number
1083 * @param cmd_action command action: GET or SET
1084 * @param wait_option wait option: wait response or not
1085 * @param cmd_oid cmd oid: treated as sub command
1086 * @param pdata_buf A pointer to informaion buffer
1089 int lbs_prepare_and_send_command(struct lbs_private *priv,
1092 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1095 struct cmd_ctrl_node *cmdnode;
1096 struct cmd_ds_command *cmdptr;
1097 unsigned long flags;
1099 lbs_deb_enter(LBS_DEB_HOST);
1102 lbs_deb_host("PREP_CMD: priv is NULL\n");
1107 if (priv->surpriseremoved) {
1108 lbs_deb_host("PREP_CMD: card removed\n");
1113 if (!lbs_is_cmd_allowed(priv)) {
1118 cmdnode = lbs_get_cmd_ctrl_node(priv);
1120 if (cmdnode == NULL) {
1121 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1123 /* Wake up main thread to execute next command */
1124 wake_up_interruptible(&priv->waitq);
1129 cmdnode->callback = NULL;
1130 cmdnode->callback_arg = (unsigned long)pdata_buf;
1132 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
1134 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
1136 /* Set sequence number, command and INT option */
1138 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
1140 cmdptr->command = cpu_to_le16(cmd_no);
1144 case CMD_802_11_PS_MODE:
1145 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
1148 case CMD_MAC_REG_ACCESS:
1149 case CMD_BBP_REG_ACCESS:
1150 case CMD_RF_REG_ACCESS:
1151 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
1154 case CMD_802_11_MONITOR_MODE:
1155 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
1156 cmd_action, pdata_buf);
1159 case CMD_802_11_RSSI:
1160 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
1163 case CMD_802_11_SET_AFC:
1164 case CMD_802_11_GET_AFC:
1166 cmdptr->command = cpu_to_le16(cmd_no);
1167 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1168 sizeof(struct cmd_header));
1170 memmove(&cmdptr->params.afc,
1171 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1176 case CMD_802_11_TPC_CFG:
1177 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
1179 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1180 sizeof(struct cmd_header));
1182 memmove(&cmdptr->params.tpccfg,
1183 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1189 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
1192 case CMD_FWT_ACCESS:
1193 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
1196 case CMD_802_11_BEACON_CTRL:
1197 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1199 case CMD_802_11_DEEP_SLEEP:
1200 cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP);
1201 cmdptr->size = cpu_to_le16(sizeof(struct cmd_header));
1204 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
1209 /* return error, since the command preparation failed */
1211 lbs_deb_host("PREP_CMD: command preparation failed\n");
1212 lbs_cleanup_and_insert_cmd(priv, cmdnode);
1217 cmdnode->cmdwaitqwoken = 0;
1219 lbs_queue_cmd(priv, cmdnode);
1220 wake_up_interruptible(&priv->waitq);
1222 if (wait_option & CMD_OPTION_WAITFORRSP) {
1223 lbs_deb_host("PREP_CMD: wait for response\n");
1225 wait_event_interruptible(cmdnode->cmdwait_q,
1226 cmdnode->cmdwaitqwoken);
1229 spin_lock_irqsave(&priv->driver_lock, flags);
1230 if (priv->cur_cmd_retcode) {
1231 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1232 priv->cur_cmd_retcode);
1233 priv->cur_cmd_retcode = 0;
1236 spin_unlock_irqrestore(&priv->driver_lock, flags);
1239 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1244 * @brief This function allocates the command buffer and link
1245 * it to command free queue.
1247 * @param priv A pointer to struct lbs_private structure
1250 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1255 struct cmd_ctrl_node *cmdarray;
1257 lbs_deb_enter(LBS_DEB_HOST);
1259 /* Allocate and initialize the command array */
1260 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1261 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
1262 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1266 priv->cmd_array = cmdarray;
1268 /* Allocate and initialize each command buffer in the command array */
1269 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1270 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1271 if (!cmdarray[i].cmdbuf) {
1272 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1278 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1279 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1280 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
1285 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1290 * @brief This function frees the command buffer.
1292 * @param priv A pointer to struct lbs_private structure
1295 int lbs_free_cmd_buffer(struct lbs_private *priv)
1297 struct cmd_ctrl_node *cmdarray;
1300 lbs_deb_enter(LBS_DEB_HOST);
1302 /* need to check if cmd array is allocated or not */
1303 if (priv->cmd_array == NULL) {
1304 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1308 cmdarray = priv->cmd_array;
1310 /* Release shared memory buffers */
1311 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1312 if (cmdarray[i].cmdbuf) {
1313 kfree(cmdarray[i].cmdbuf);
1314 cmdarray[i].cmdbuf = NULL;
1318 /* Release cmd_ctrl_node */
1319 if (priv->cmd_array) {
1320 kfree(priv->cmd_array);
1321 priv->cmd_array = NULL;
1325 lbs_deb_leave(LBS_DEB_HOST);
1330 * @brief This function gets a free command node if available in
1331 * command free queue.
1333 * @param priv A pointer to struct lbs_private structure
1334 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1336 static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
1338 struct cmd_ctrl_node *tempnode;
1339 unsigned long flags;
1341 lbs_deb_enter(LBS_DEB_HOST);
1346 spin_lock_irqsave(&priv->driver_lock, flags);
1348 if (!list_empty(&priv->cmdfreeq)) {
1349 tempnode = list_first_entry(&priv->cmdfreeq,
1350 struct cmd_ctrl_node, list);
1351 list_del(&tempnode->list);
1353 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1357 spin_unlock_irqrestore(&priv->driver_lock, flags);
1359 lbs_deb_leave(LBS_DEB_HOST);
1364 * @brief This function executes next command in command
1365 * pending queue. It will put firmware back to PS mode
1368 * @param priv A pointer to struct lbs_private structure
1371 int lbs_execute_next_command(struct lbs_private *priv)
1373 struct cmd_ctrl_node *cmdnode = NULL;
1374 struct cmd_header *cmd;
1375 unsigned long flags;
1378 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1379 * only caller to us is lbs_thread() and we get even when a
1380 * data packet is received */
1381 lbs_deb_enter(LBS_DEB_THREAD);
1383 spin_lock_irqsave(&priv->driver_lock, flags);
1385 if (priv->cur_cmd) {
1386 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1387 spin_unlock_irqrestore(&priv->driver_lock, flags);
1392 if (!list_empty(&priv->cmdpendingq)) {
1393 cmdnode = list_first_entry(&priv->cmdpendingq,
1394 struct cmd_ctrl_node, list);
1397 spin_unlock_irqrestore(&priv->driver_lock, flags);
1400 cmd = cmdnode->cmdbuf;
1402 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
1403 if ((priv->psstate == PS_STATE_SLEEP) ||
1404 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1406 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1407 le16_to_cpu(cmd->command),
1412 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1413 "0x%04x in psstate %d\n",
1414 le16_to_cpu(cmd->command), priv->psstate);
1415 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1417 * 1. Non-PS command:
1418 * Queue it. set needtowakeup to TRUE if current state
1419 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1420 * 2. PS command but not Exit_PS:
1422 * 3. PS command Exit_PS:
1423 * Set needtowakeup to TRUE if current state is SLEEP,
1424 * otherwise send this command down to firmware
1427 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
1428 /* Prepare to send Exit PS,
1429 * this non PS command will be sent later */
1430 if ((priv->psstate == PS_STATE_SLEEP)
1431 || (priv->psstate == PS_STATE_PRE_SLEEP)
1433 /* w/ new scheme, it will not reach here.
1434 since it is blocked in main_thread. */
1435 priv->needtowakeup = 1;
1437 lbs_ps_wakeup(priv, 0);
1443 * PS command. Ignore it if it is not Exit_PS.
1444 * otherwise send it down immediately.
1446 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
1449 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1452 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
1454 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1455 list_del(&cmdnode->list);
1456 spin_lock_irqsave(&priv->driver_lock, flags);
1457 lbs_complete_command(priv, cmdnode, 0);
1458 spin_unlock_irqrestore(&priv->driver_lock, flags);
1464 if ((priv->psstate == PS_STATE_SLEEP) ||
1465 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1467 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1468 list_del(&cmdnode->list);
1469 spin_lock_irqsave(&priv->driver_lock, flags);
1470 lbs_complete_command(priv, cmdnode, 0);
1471 spin_unlock_irqrestore(&priv->driver_lock, flags);
1472 priv->needtowakeup = 1;
1479 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1482 list_del(&cmdnode->list);
1483 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1484 le16_to_cpu(cmd->command));
1485 lbs_submit_command(priv, cmdnode);
1488 * check if in power save mode, if yes, put the device back
1491 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1492 (priv->psstate == PS_STATE_FULL_POWER) &&
1493 ((priv->connect_status == LBS_CONNECTED) ||
1494 (priv->mesh_connect_status == LBS_CONNECTED))) {
1495 if (priv->secinfo.WPAenabled ||
1496 priv->secinfo.WPA2enabled) {
1497 /* check for valid WPA group keys */
1498 if (priv->wpa_mcast_key.len ||
1499 priv->wpa_unicast_key.len) {
1501 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1502 " go back to PS_SLEEP");
1503 lbs_ps_sleep(priv, 0);
1507 "EXEC_NEXT_CMD: cmdpendingq empty, "
1508 "go back to PS_SLEEP");
1509 lbs_ps_sleep(priv, 0);
1516 lbs_deb_leave(LBS_DEB_THREAD);
1520 static void lbs_send_confirmsleep(struct lbs_private *priv)
1522 unsigned long flags;
1525 lbs_deb_enter(LBS_DEB_HOST);
1526 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1527 sizeof(confirm_sleep));
1529 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1530 sizeof(confirm_sleep));
1532 lbs_pr_alert("confirm_sleep failed\n");
1536 spin_lock_irqsave(&priv->driver_lock, flags);
1538 /* We don't get a response on the sleep-confirmation */
1539 priv->dnld_sent = DNLD_RES_RECEIVED;
1541 /* If nothing to do, go back to sleep (?) */
1542 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1543 priv->psstate = PS_STATE_SLEEP;
1545 spin_unlock_irqrestore(&priv->driver_lock, flags);
1548 lbs_deb_leave(LBS_DEB_HOST);
1551 void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
1553 lbs_deb_enter(LBS_DEB_HOST);
1556 * PS is currently supported only in Infrastructure mode
1557 * Remove this check if it is to be supported in IBSS mode also
1560 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1561 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
1563 lbs_deb_leave(LBS_DEB_HOST);
1567 * @brief This function sends Exit_PS command to firmware.
1569 * @param priv A pointer to struct lbs_private structure
1570 * @param wait_option wait response or not
1573 void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
1577 lbs_deb_enter(LBS_DEB_HOST);
1579 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
1581 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
1583 wait_option, 0, &Localpsmode);
1585 lbs_deb_leave(LBS_DEB_HOST);
1589 * @brief This function checks condition and prepares to
1590 * send sleep confirm command to firmware if ok.
1592 * @param priv A pointer to struct lbs_private structure
1593 * @param psmode Power Saving mode
1596 void lbs_ps_confirm_sleep(struct lbs_private *priv)
1598 unsigned long flags =0;
1601 lbs_deb_enter(LBS_DEB_HOST);
1603 spin_lock_irqsave(&priv->driver_lock, flags);
1604 if (priv->dnld_sent) {
1606 lbs_deb_host("dnld_sent was set\n");
1609 /* In-progress command? */
1610 if (priv->cur_cmd) {
1612 lbs_deb_host("cur_cmd was set\n");
1615 /* Pending events or command responses? */
1616 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
1618 lbs_deb_host("pending events or command responses\n");
1620 spin_unlock_irqrestore(&priv->driver_lock, flags);
1623 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1624 lbs_send_confirmsleep(priv);
1626 lbs_deb_host("sleep confirm has been delayed\n");
1629 lbs_deb_leave(LBS_DEB_HOST);
1634 * @brief Configures the transmission power control functionality.
1636 * @param priv A pointer to struct lbs_private structure
1637 * @param enable Transmission power control enable
1638 * @param p0 Power level when link quality is good (dBm).
1639 * @param p1 Power level when link quality is fair (dBm).
1640 * @param p2 Power level when link quality is poor (dBm).
1641 * @param usesnr Use Signal to Noise Ratio in TPC
1643 * @return 0 on success
1645 int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1646 int8_t p2, int usesnr)
1648 struct cmd_ds_802_11_tpc_cfg cmd;
1651 memset(&cmd, 0, sizeof(cmd));
1652 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1653 cmd.action = cpu_to_le16(CMD_ACT_SET);
1654 cmd.enable = !!enable;
1655 cmd.usesnr = !!usesnr;
1660 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1666 * @brief Configures the power adaptation settings.
1668 * @param priv A pointer to struct lbs_private structure
1669 * @param enable Power adaptation enable
1670 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1671 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1672 * @param p2 Power level for 48 and 54 Mbps (dBm).
1674 * @return 0 on Success
1677 int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1678 int8_t p1, int8_t p2)
1680 struct cmd_ds_802_11_pa_cfg cmd;
1683 memset(&cmd, 0, sizeof(cmd));
1684 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1685 cmd.action = cpu_to_le16(CMD_ACT_SET);
1686 cmd.enable = !!enable;
1691 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1697 struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1698 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1699 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1700 unsigned long callback_arg)
1702 struct cmd_ctrl_node *cmdnode;
1704 lbs_deb_enter(LBS_DEB_HOST);
1706 if (priv->surpriseremoved) {
1707 lbs_deb_host("PREP_CMD: card removed\n");
1708 cmdnode = ERR_PTR(-ENOENT);
1712 if (!lbs_is_cmd_allowed(priv)) {
1713 cmdnode = ERR_PTR(-EBUSY);
1717 cmdnode = lbs_get_cmd_ctrl_node(priv);
1718 if (cmdnode == NULL) {
1719 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1721 /* Wake up main thread to execute next command */
1722 wake_up_interruptible(&priv->waitq);
1723 cmdnode = ERR_PTR(-ENOBUFS);
1727 cmdnode->callback = callback;
1728 cmdnode->callback_arg = callback_arg;
1730 /* Copy the incoming command to the buffer */
1731 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
1733 /* Set sequence number, clean result, move to buffer */
1735 cmdnode->cmdbuf->command = cpu_to_le16(command);
1736 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1737 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1738 cmdnode->cmdbuf->result = 0;
1740 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1742 cmdnode->cmdwaitqwoken = 0;
1743 lbs_queue_cmd(priv, cmdnode);
1744 wake_up_interruptible(&priv->waitq);
1747 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1751 void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1752 struct cmd_header *in_cmd, int in_cmd_size)
1754 lbs_deb_enter(LBS_DEB_CMD);
1755 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1756 lbs_cmd_async_callback, 0);
1757 lbs_deb_leave(LBS_DEB_CMD);
1760 int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1761 struct cmd_header *in_cmd, int in_cmd_size,
1762 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1763 unsigned long callback_arg)
1765 struct cmd_ctrl_node *cmdnode;
1766 unsigned long flags;
1769 lbs_deb_enter(LBS_DEB_HOST);
1771 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1772 callback, callback_arg);
1773 if (IS_ERR(cmdnode)) {
1774 ret = PTR_ERR(cmdnode);
1779 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1781 spin_lock_irqsave(&priv->driver_lock, flags);
1782 ret = cmdnode->result;
1784 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1787 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
1788 spin_unlock_irqrestore(&priv->driver_lock, flags);
1791 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1794 EXPORT_SYMBOL_GPL(__lbs_cmd);