2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
6 #include <linux/kfifo.h>
7 #include <linux/sched.h>
8 #include <linux/slab.h>
9 #include <linux/if_arp.h>
15 #define CAL_NF(nf) ((s32)(-(s32)(nf)))
16 #define CAL_RSSI(snr, nf) ((s32)((s32)(snr) + CAL_NF(nf)))
19 * lbs_cmd_copyback - Simple callback that copies response back into command
21 * @priv: A pointer to &struct lbs_private structure
22 * @extra: A pointer to the original command structure for which
23 * 'resp' is a response
24 * @resp: A pointer to the command response
26 * returns: 0 on success, error on failure
28 int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
29 struct cmd_header *resp)
31 struct cmd_header *buf = (void *)extra;
34 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
35 memcpy(buf, resp, copy_len);
38 EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
41 * lbs_cmd_async_callback - Simple callback that ignores the result.
42 * Use this if you just want to send a command to the hardware, but don't
43 * care for the result.
49 * returns: 0 for success
51 static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
52 struct cmd_header *resp)
59 * is_command_allowed_in_ps - tests if a command is allowed in Power Save mode
61 * @cmd: the command ID
63 * returns: 1 if allowed, 0 if not allowed
65 static u8 is_command_allowed_in_ps(u16 cmd)
70 case CMD_802_11_HOST_SLEEP_CFG:
79 * lbs_update_hw_spec - Updates the hardware details like MAC address
80 * and regulatory region
82 * @priv: A pointer to &struct lbs_private structure
84 * returns: 0 on success, error on failure
86 int lbs_update_hw_spec(struct lbs_private *priv)
88 struct cmd_ds_get_hw_spec cmd;
92 lbs_deb_enter(LBS_DEB_CMD);
94 memset(&cmd, 0, sizeof(cmd));
95 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
96 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
97 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
101 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
103 /* The firmware release is in an interesting format: the patch
104 * level is in the most significant nibble ... so fix that: */
105 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
106 priv->fwrelease = (priv->fwrelease << 8) |
107 (priv->fwrelease >> 24 & 0xff);
109 /* Some firmware capabilities:
110 * CF card firmware 5.0.16p0: cap 0x00000303
111 * USB dongle firmware 5.110.17p2: cap 0x00000303
113 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
115 priv->fwrelease >> 24 & 0xff,
116 priv->fwrelease >> 16 & 0xff,
117 priv->fwrelease >> 8 & 0xff,
118 priv->fwrelease & 0xff,
120 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
121 cmd.hwifversion, cmd.version);
123 /* Clamp region code to 8-bit since FW spec indicates that it should
124 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
125 * returns non-zero high 8 bits here.
127 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
128 * need to check for this problem and handle it properly.
130 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
131 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
133 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
135 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
136 /* use the region code to search for the index */
137 if (priv->regioncode == lbs_region_code_to_index[i])
141 /* if it's unidentified region code, use the default (USA) */
142 if (i >= MRVDRV_MAX_REGION_CODE) {
143 priv->regioncode = 0x10;
144 lbs_pr_info("unidentified region code; using the default (USA)\n");
147 if (priv->current_addr[0] == 0xff)
148 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
150 if (!priv->copied_hwaddr) {
151 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
153 memcpy(priv->mesh_dev->dev_addr,
154 priv->current_addr, ETH_ALEN);
155 priv->copied_hwaddr = 1;
159 lbs_deb_leave(LBS_DEB_CMD);
163 static int lbs_ret_host_sleep_cfg(struct lbs_private *priv, unsigned long dummy,
164 struct cmd_header *resp)
166 lbs_deb_enter(LBS_DEB_CMD);
167 if (priv->is_host_sleep_activated) {
168 priv->is_host_sleep_configured = 0;
169 if (priv->psstate == PS_STATE_FULL_POWER) {
170 priv->is_host_sleep_activated = 0;
171 wake_up_interruptible(&priv->host_sleep_q);
174 priv->is_host_sleep_configured = 1;
176 lbs_deb_leave(LBS_DEB_CMD);
180 int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
181 struct wol_config *p_wol_config)
183 struct cmd_ds_host_sleep cmd_config;
187 * Certain firmware versions do not support EHS_REMOVE_WAKEUP command
188 * and the card will return a failure. Since we need to be
189 * able to reset the mask, in those cases we set a 0 mask instead.
191 if (criteria == EHS_REMOVE_WAKEUP && !priv->ehs_remove_supported)
194 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
195 cmd_config.criteria = cpu_to_le32(criteria);
196 cmd_config.gpio = priv->wol_gpio;
197 cmd_config.gap = priv->wol_gap;
199 if (p_wol_config != NULL)
200 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
201 sizeof(struct wol_config));
203 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
205 ret = __lbs_cmd(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config.hdr,
206 le16_to_cpu(cmd_config.hdr.size),
207 lbs_ret_host_sleep_cfg, 0);
210 memcpy((uint8_t *) p_wol_config,
211 (uint8_t *)&cmd_config.wol_conf,
212 sizeof(struct wol_config));
214 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
219 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
222 * lbs_set_ps_mode - Sets the Power Save mode
224 * @priv: A pointer to &struct lbs_private structure
225 * @cmd_action: The Power Save operation (PS_MODE_ACTION_ENTER_PS or
226 * PS_MODE_ACTION_EXIT_PS)
227 * @block: Whether to block on a response or not
229 * returns: 0 on success, error on failure
231 int lbs_set_ps_mode(struct lbs_private *priv, u16 cmd_action, bool block)
233 struct cmd_ds_802_11_ps_mode cmd;
236 lbs_deb_enter(LBS_DEB_CMD);
238 memset(&cmd, 0, sizeof(cmd));
239 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
240 cmd.action = cpu_to_le16(cmd_action);
242 if (cmd_action == PS_MODE_ACTION_ENTER_PS) {
243 lbs_deb_cmd("PS_MODE: action ENTER_PS\n");
244 cmd.multipledtim = cpu_to_le16(1); /* Default DTIM multiple */
245 } else if (cmd_action == PS_MODE_ACTION_EXIT_PS) {
246 lbs_deb_cmd("PS_MODE: action EXIT_PS\n");
248 /* We don't handle CONFIRM_SLEEP here because it needs to
249 * be fastpathed to the firmware.
251 lbs_deb_cmd("PS_MODE: unknown action 0x%X\n", cmd_action);
257 ret = lbs_cmd_with_response(priv, CMD_802_11_PS_MODE, &cmd);
259 lbs_cmd_async(priv, CMD_802_11_PS_MODE, &cmd.hdr, sizeof (cmd));
262 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
266 int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
267 struct sleep_params *sp)
269 struct cmd_ds_802_11_sleep_params cmd;
272 lbs_deb_enter(LBS_DEB_CMD);
274 if (cmd_action == CMD_ACT_GET) {
275 memset(&cmd, 0, sizeof(cmd));
277 cmd.error = cpu_to_le16(sp->sp_error);
278 cmd.offset = cpu_to_le16(sp->sp_offset);
279 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
280 cmd.calcontrol = sp->sp_calcontrol;
281 cmd.externalsleepclk = sp->sp_extsleepclk;
282 cmd.reserved = cpu_to_le16(sp->sp_reserved);
284 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
285 cmd.action = cpu_to_le16(cmd_action);
287 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
290 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
291 "calcontrol 0x%x extsleepclk 0x%x\n",
292 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
293 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
294 cmd.externalsleepclk);
296 sp->sp_error = le16_to_cpu(cmd.error);
297 sp->sp_offset = le16_to_cpu(cmd.offset);
298 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
299 sp->sp_calcontrol = cmd.calcontrol;
300 sp->sp_extsleepclk = cmd.externalsleepclk;
301 sp->sp_reserved = le16_to_cpu(cmd.reserved);
304 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
308 static int lbs_wait_for_ds_awake(struct lbs_private *priv)
312 lbs_deb_enter(LBS_DEB_CMD);
314 if (priv->is_deep_sleep) {
315 if (!wait_event_interruptible_timeout(priv->ds_awake_q,
316 !priv->is_deep_sleep, (10 * HZ))) {
317 lbs_pr_err("ds_awake_q: timer expired\n");
322 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
326 int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep)
330 lbs_deb_enter(LBS_DEB_CMD);
333 if (priv->is_deep_sleep != 1) {
334 lbs_deb_cmd("deep sleep: sleep\n");
335 BUG_ON(!priv->enter_deep_sleep);
336 ret = priv->enter_deep_sleep(priv);
338 netif_stop_queue(priv->dev);
339 netif_carrier_off(priv->dev);
342 lbs_pr_err("deep sleep: already enabled\n");
345 if (priv->is_deep_sleep) {
346 lbs_deb_cmd("deep sleep: wakeup\n");
347 BUG_ON(!priv->exit_deep_sleep);
348 ret = priv->exit_deep_sleep(priv);
350 ret = lbs_wait_for_ds_awake(priv);
352 lbs_pr_err("deep sleep: wakeup"
358 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
362 static int lbs_ret_host_sleep_activate(struct lbs_private *priv,
364 struct cmd_header *cmd)
366 lbs_deb_enter(LBS_DEB_FW);
367 priv->is_host_sleep_activated = 1;
368 wake_up_interruptible(&priv->host_sleep_q);
369 lbs_deb_leave(LBS_DEB_FW);
373 int lbs_set_host_sleep(struct lbs_private *priv, int host_sleep)
375 struct cmd_header cmd;
377 uint32_t criteria = EHS_REMOVE_WAKEUP;
379 lbs_deb_enter(LBS_DEB_CMD);
382 if (priv->is_host_sleep_activated != 1) {
383 memset(&cmd, 0, sizeof(cmd));
384 ret = lbs_host_sleep_cfg(priv, priv->wol_criteria,
385 (struct wol_config *)NULL);
387 lbs_pr_info("Host sleep configuration failed: "
391 if (priv->psstate == PS_STATE_FULL_POWER) {
392 ret = __lbs_cmd(priv,
393 CMD_802_11_HOST_SLEEP_ACTIVATE,
396 lbs_ret_host_sleep_activate, 0);
398 lbs_pr_info("HOST_SLEEP_ACTIVATE "
399 "failed: %d\n", ret);
402 if (!wait_event_interruptible_timeout(
404 priv->is_host_sleep_activated,
406 lbs_pr_err("host_sleep_q: timer expired\n");
410 lbs_pr_err("host sleep: already enabled\n");
413 if (priv->is_host_sleep_activated)
414 ret = lbs_host_sleep_cfg(priv, criteria,
415 (struct wol_config *)NULL);
422 * lbs_set_snmp_mib - Set an SNMP MIB value
424 * @priv: A pointer to &struct lbs_private structure
425 * @oid: The OID to set in the firmware
426 * @val: Value to set the OID to
428 * returns: 0 on success, error on failure
430 int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
432 struct cmd_ds_802_11_snmp_mib cmd;
435 lbs_deb_enter(LBS_DEB_CMD);
437 memset(&cmd, 0, sizeof (cmd));
438 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
439 cmd.action = cpu_to_le16(CMD_ACT_SET);
440 cmd.oid = cpu_to_le16((u16) oid);
443 case SNMP_MIB_OID_BSS_TYPE:
444 cmd.bufsize = cpu_to_le16(sizeof(u8));
447 case SNMP_MIB_OID_11D_ENABLE:
448 case SNMP_MIB_OID_FRAG_THRESHOLD:
449 case SNMP_MIB_OID_RTS_THRESHOLD:
450 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
451 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
452 cmd.bufsize = cpu_to_le16(sizeof(u16));
453 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
456 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
461 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
462 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
464 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
467 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
472 * lbs_get_snmp_mib - Get an SNMP MIB value
474 * @priv: A pointer to &struct lbs_private structure
475 * @oid: The OID to retrieve from the firmware
476 * @out_val: Location for the returned value
478 * returns: 0 on success, error on failure
480 int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
482 struct cmd_ds_802_11_snmp_mib cmd;
485 lbs_deb_enter(LBS_DEB_CMD);
487 memset(&cmd, 0, sizeof (cmd));
488 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
489 cmd.action = cpu_to_le16(CMD_ACT_GET);
490 cmd.oid = cpu_to_le16(oid);
492 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
496 switch (le16_to_cpu(cmd.bufsize)) {
498 *out_val = cmd.value[0];
501 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
504 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
505 oid, le16_to_cpu(cmd.bufsize));
510 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
515 * lbs_get_tx_power - Get the min, max, and current TX power
517 * @priv: A pointer to &struct lbs_private structure
518 * @curlevel: Current power level in dBm
519 * @minlevel: Minimum supported power level in dBm (optional)
520 * @maxlevel: Maximum supported power level in dBm (optional)
522 * returns: 0 on success, error on failure
524 int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
527 struct cmd_ds_802_11_rf_tx_power cmd;
530 lbs_deb_enter(LBS_DEB_CMD);
532 memset(&cmd, 0, sizeof(cmd));
533 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
534 cmd.action = cpu_to_le16(CMD_ACT_GET);
536 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
538 *curlevel = le16_to_cpu(cmd.curlevel);
540 *minlevel = cmd.minlevel;
542 *maxlevel = cmd.maxlevel;
545 lbs_deb_leave(LBS_DEB_CMD);
550 * lbs_set_tx_power - Set the TX power
552 * @priv: A pointer to &struct lbs_private structure
553 * @dbm: The desired power level in dBm
555 * returns: 0 on success, error on failure
557 int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
559 struct cmd_ds_802_11_rf_tx_power 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_ACT_SET);
567 cmd.curlevel = cpu_to_le16(dbm);
569 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
571 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
573 lbs_deb_leave(LBS_DEB_CMD);
578 * lbs_set_monitor_mode - Enable or disable monitor mode
579 * (only implemented on OLPC usb8388 FW)
581 * @priv: A pointer to &struct lbs_private structure
582 * @enable: 1 to enable monitor mode, 0 to disable
584 * returns: 0 on success, error on failure
586 int lbs_set_monitor_mode(struct lbs_private *priv, int enable)
588 struct cmd_ds_802_11_monitor_mode cmd;
591 memset(&cmd, 0, sizeof(cmd));
592 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
593 cmd.action = cpu_to_le16(CMD_ACT_SET);
595 cmd.mode = cpu_to_le16(0x1);
597 lbs_deb_cmd("SET_MONITOR_MODE: %d\n", enable);
599 ret = lbs_cmd_with_response(priv, CMD_802_11_MONITOR_MODE, &cmd);
601 priv->dev->type = enable ? ARPHRD_IEEE80211_RADIOTAP :
605 lbs_deb_leave(LBS_DEB_CMD);
610 * lbs_get_channel - Get the radio channel
612 * @priv: A pointer to &struct lbs_private structure
614 * returns: The channel on success, error on failure
616 static int lbs_get_channel(struct lbs_private *priv)
618 struct cmd_ds_802_11_rf_channel cmd;
621 lbs_deb_enter(LBS_DEB_CMD);
623 memset(&cmd, 0, sizeof(cmd));
624 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
625 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
627 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
631 ret = le16_to_cpu(cmd.channel);
632 lbs_deb_cmd("current radio channel is %d\n", ret);
635 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
639 int lbs_update_channel(struct lbs_private *priv)
643 /* the channel in f/w could be out of sync; get the current channel */
644 lbs_deb_enter(LBS_DEB_ASSOC);
646 ret = lbs_get_channel(priv);
651 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
656 * lbs_set_channel - Set the radio channel
658 * @priv: A pointer to &struct lbs_private structure
659 * @channel: The desired channel, or 0 to clear a locked channel
661 * returns: 0 on success, error on failure
663 int lbs_set_channel(struct lbs_private *priv, u8 channel)
665 struct cmd_ds_802_11_rf_channel cmd;
667 u8 old_channel = priv->channel;
671 lbs_deb_enter(LBS_DEB_CMD);
673 memset(&cmd, 0, sizeof(cmd));
674 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
675 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
676 cmd.channel = cpu_to_le16(channel);
678 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
682 priv->channel = (uint8_t) le16_to_cpu(cmd.channel);
683 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
687 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
692 * lbs_get_rssi - Get current RSSI and noise floor
694 * @priv: A pointer to &struct lbs_private structure
695 * @rssi: On successful return, signal level in mBm
696 * @nf: On successful return, Noise floor
698 * returns: The channel on success, error on failure
700 int lbs_get_rssi(struct lbs_private *priv, s8 *rssi, s8 *nf)
702 struct cmd_ds_802_11_rssi cmd;
705 lbs_deb_enter(LBS_DEB_CMD);
707 BUG_ON(rssi == NULL);
710 memset(&cmd, 0, sizeof(cmd));
711 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
712 /* Average SNR over last 8 beacons */
713 cmd.n_or_snr = cpu_to_le16(8);
715 ret = lbs_cmd_with_response(priv, CMD_802_11_RSSI, &cmd);
717 *nf = CAL_NF(le16_to_cpu(cmd.nf));
718 *rssi = CAL_RSSI(le16_to_cpu(cmd.n_or_snr), le16_to_cpu(cmd.nf));
721 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
726 * lbs_set_11d_domain_info - Send regulatory and 802.11d domain information
729 * @priv: pointer to &struct lbs_private
730 * @request: cfg80211 regulatory request structure
731 * @bands: the device's supported bands and channels
733 * returns: 0 on success, error code on failure
735 int lbs_set_11d_domain_info(struct lbs_private *priv,
736 struct regulatory_request *request,
737 struct ieee80211_supported_band **bands)
739 struct cmd_ds_802_11d_domain_info cmd;
740 struct mrvl_ie_domain_param_set *domain = &cmd.domain;
741 struct ieee80211_country_ie_triplet *t;
742 enum ieee80211_band band;
743 struct ieee80211_channel *ch;
745 u8 num_parsed_chan = 0;
746 u8 first_channel = 0, next_chan = 0, max_pwr = 0;
751 lbs_deb_enter(LBS_DEB_11D);
753 memset(&cmd, 0, sizeof(cmd));
754 cmd.action = cpu_to_le16(CMD_ACT_SET);
756 lbs_deb_11d("Setting country code '%c%c'\n",
757 request->alpha2[0], request->alpha2[1]);
759 domain->header.type = cpu_to_le16(TLV_TYPE_DOMAIN);
761 /* Set country code */
762 domain->country_code[0] = request->alpha2[0];
763 domain->country_code[1] = request->alpha2[1];
764 domain->country_code[2] = ' ';
766 /* Now set up the channel triplets; firmware is somewhat picky here
767 * and doesn't validate channel numbers and spans; hence it would
768 * interpret a triplet of (36, 4, 20) as channels 36, 37, 38, 39. Since
769 * the last 3 aren't valid channels, the driver is responsible for
770 * splitting that up into 4 triplet pairs of (36, 1, 20) + (40, 1, 20)
774 (band < IEEE80211_NUM_BANDS) && (num_triplet < MAX_11D_TRIPLETS);
781 (i < bands[band]->n_channels) && (num_triplet < MAX_11D_TRIPLETS);
783 ch = &bands[band]->channels[i];
784 if (ch->flags & IEEE80211_CHAN_DISABLED)
789 next_chan = first_channel = (u32) ch->hw_value;
790 max_pwr = ch->max_power;
795 if ((ch->hw_value == next_chan + 1) &&
796 (ch->max_power == max_pwr)) {
797 /* Consolidate adjacent channels */
801 /* Add this triplet */
802 lbs_deb_11d("11D triplet (%d, %d, %d)\n",
803 first_channel, num_parsed_chan,
805 t = &domain->triplet[num_triplet];
806 t->chans.first_channel = first_channel;
807 t->chans.num_channels = num_parsed_chan;
808 t->chans.max_power = max_pwr;
815 /* Add last triplet */
816 lbs_deb_11d("11D triplet (%d, %d, %d)\n", first_channel,
817 num_parsed_chan, max_pwr);
818 t = &domain->triplet[num_triplet];
819 t->chans.first_channel = first_channel;
820 t->chans.num_channels = num_parsed_chan;
821 t->chans.max_power = max_pwr;
826 lbs_deb_11d("# triplets %d\n", num_triplet);
828 /* Set command header sizes */
829 triplet_size = num_triplet * sizeof(struct ieee80211_country_ie_triplet);
830 domain->header.len = cpu_to_le16(sizeof(domain->country_code) +
833 lbs_deb_hex(LBS_DEB_11D, "802.11D domain param set",
834 (u8 *) &cmd.domain.country_code,
835 le16_to_cpu(domain->header.len));
837 cmd.hdr.size = cpu_to_le16(sizeof(cmd.hdr) +
839 sizeof(cmd.domain.header) +
840 sizeof(cmd.domain.country_code) +
843 ret = lbs_cmd_with_response(priv, CMD_802_11D_DOMAIN_INFO, &cmd);
845 lbs_deb_leave_args(LBS_DEB_11D, "ret %d", ret);
850 * lbs_get_reg - Read a MAC, Baseband, or RF register
852 * @priv: pointer to &struct lbs_private
853 * @reg: register command, one of CMD_MAC_REG_ACCESS,
854 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
855 * @offset: byte offset of the register to get
856 * @value: on success, the value of the register at 'offset'
858 * returns: 0 on success, error code on failure
860 int lbs_get_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 *value)
862 struct cmd_ds_reg_access cmd;
865 lbs_deb_enter(LBS_DEB_CMD);
867 BUG_ON(value == NULL);
869 memset(&cmd, 0, sizeof(cmd));
870 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
871 cmd.action = cpu_to_le16(CMD_ACT_GET);
873 if (reg != CMD_MAC_REG_ACCESS &&
874 reg != CMD_BBP_REG_ACCESS &&
875 reg != CMD_RF_REG_ACCESS) {
880 ret = lbs_cmd_with_response(priv, reg, &cmd);
882 if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
883 *value = cmd.value.bbp_rf;
884 else if (reg == CMD_MAC_REG_ACCESS)
885 *value = le32_to_cpu(cmd.value.mac);
889 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
894 * lbs_set_reg - Write a MAC, Baseband, or RF register
896 * @priv: pointer to &struct lbs_private
897 * @reg: register command, one of CMD_MAC_REG_ACCESS,
898 * CMD_BBP_REG_ACCESS, or CMD_RF_REG_ACCESS
899 * @offset: byte offset of the register to set
900 * @value: the value to write to the register at 'offset'
902 * returns: 0 on success, error code on failure
904 int lbs_set_reg(struct lbs_private *priv, u16 reg, u16 offset, u32 value)
906 struct cmd_ds_reg_access cmd;
909 lbs_deb_enter(LBS_DEB_CMD);
911 memset(&cmd, 0, sizeof(cmd));
912 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
913 cmd.action = cpu_to_le16(CMD_ACT_SET);
915 if (reg == CMD_BBP_REG_ACCESS || reg == CMD_RF_REG_ACCESS)
916 cmd.value.bbp_rf = (u8) (value & 0xFF);
917 else if (reg == CMD_MAC_REG_ACCESS)
918 cmd.value.mac = cpu_to_le32(value);
924 ret = lbs_cmd_with_response(priv, reg, &cmd);
927 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
931 static void lbs_queue_cmd(struct lbs_private *priv,
932 struct cmd_ctrl_node *cmdnode)
937 lbs_deb_enter(LBS_DEB_HOST);
940 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
943 if (!cmdnode->cmdbuf->size) {
944 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
949 /* Exit_PS command needs to be queued in the header always. */
950 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
951 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf;
953 if (psm->action == cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
954 if (priv->psstate != PS_STATE_FULL_POWER)
959 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_WAKEUP_CONFIRM)
962 spin_lock_irqsave(&priv->driver_lock, flags);
965 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
967 list_add(&cmdnode->list, &priv->cmdpendingq);
969 spin_unlock_irqrestore(&priv->driver_lock, flags);
971 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
972 le16_to_cpu(cmdnode->cmdbuf->command));
975 lbs_deb_leave(LBS_DEB_HOST);
978 static void lbs_submit_command(struct lbs_private *priv,
979 struct cmd_ctrl_node *cmdnode)
982 struct cmd_header *cmd;
988 lbs_deb_enter(LBS_DEB_HOST);
990 cmd = cmdnode->cmdbuf;
992 spin_lock_irqsave(&priv->driver_lock, flags);
993 priv->cur_cmd = cmdnode;
994 spin_unlock_irqrestore(&priv->driver_lock, flags);
996 cmdsize = le16_to_cpu(cmd->size);
997 command = le16_to_cpu(cmd->command);
999 /* These commands take longer */
1000 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
1003 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1004 command, le16_to_cpu(cmd->seqnum), cmdsize);
1005 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
1007 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
1010 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
1011 /* Let the timer kick in and retry, and potentially reset
1012 the whole thing if the condition persists */
1016 if (command == CMD_802_11_DEEP_SLEEP) {
1017 if (priv->is_auto_deep_sleep_enabled) {
1018 priv->wakeup_dev_required = 1;
1019 priv->dnld_sent = 0;
1021 priv->is_deep_sleep = 1;
1022 lbs_complete_command(priv, cmdnode, 0);
1024 /* Setup the timer after transmit command */
1025 mod_timer(&priv->command_timer, jiffies + timeo);
1028 lbs_deb_leave(LBS_DEB_HOST);
1032 * This function inserts command node to cmdfreeq
1033 * after cleans it. Requires priv->driver_lock held.
1035 static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1036 struct cmd_ctrl_node *cmdnode)
1038 lbs_deb_enter(LBS_DEB_HOST);
1043 cmdnode->callback = NULL;
1044 cmdnode->callback_arg = 0;
1046 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1048 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1050 lbs_deb_leave(LBS_DEB_HOST);
1053 static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1054 struct cmd_ctrl_node *ptempcmd)
1056 unsigned long flags;
1058 spin_lock_irqsave(&priv->driver_lock, flags);
1059 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
1060 spin_unlock_irqrestore(&priv->driver_lock, flags);
1063 void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1066 cmd->result = result;
1067 cmd->cmdwaitqwoken = 1;
1068 wake_up_interruptible(&cmd->cmdwait_q);
1070 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
1071 __lbs_cleanup_and_insert_cmd(priv, cmd);
1072 priv->cur_cmd = NULL;
1075 int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
1077 struct cmd_ds_802_11_radio_control cmd;
1080 lbs_deb_enter(LBS_DEB_CMD);
1082 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1083 cmd.action = cpu_to_le16(CMD_ACT_SET);
1085 /* Only v8 and below support setting the preamble */
1086 if (priv->fwrelease < 0x09000000) {
1088 case RADIO_PREAMBLE_SHORT:
1089 case RADIO_PREAMBLE_AUTO:
1090 case RADIO_PREAMBLE_LONG:
1091 cmd.control = cpu_to_le16(preamble);
1099 cmd.control |= cpu_to_le16(0x1);
1101 cmd.control &= cpu_to_le16(~0x1);
1102 priv->txpower_cur = 0;
1105 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1106 radio_on ? "ON" : "OFF", preamble);
1108 priv->radio_on = radio_on;
1110 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
1113 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
1117 void lbs_set_mac_control(struct lbs_private *priv)
1119 struct cmd_ds_mac_control cmd;
1121 lbs_deb_enter(LBS_DEB_CMD);
1123 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1124 cmd.action = cpu_to_le16(priv->mac_control);
1127 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
1129 lbs_deb_leave(LBS_DEB_CMD);
1133 * lbs_allocate_cmd_buffer - allocates the command buffer and links
1134 * it to command free queue
1136 * @priv: A pointer to &struct lbs_private structure
1138 * returns: 0 for success or -1 on error
1140 int lbs_allocate_cmd_buffer(struct lbs_private *priv)
1145 struct cmd_ctrl_node *cmdarray;
1147 lbs_deb_enter(LBS_DEB_HOST);
1149 /* Allocate and initialize the command array */
1150 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1151 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
1152 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1156 priv->cmd_array = cmdarray;
1158 /* Allocate and initialize each command buffer in the command array */
1159 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1160 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1161 if (!cmdarray[i].cmdbuf) {
1162 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1168 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1169 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1170 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
1175 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1180 * lbs_free_cmd_buffer - free the command buffer
1182 * @priv: A pointer to &struct lbs_private structure
1184 * returns: 0 for success
1186 int lbs_free_cmd_buffer(struct lbs_private *priv)
1188 struct cmd_ctrl_node *cmdarray;
1191 lbs_deb_enter(LBS_DEB_HOST);
1193 /* need to check if cmd array is allocated or not */
1194 if (priv->cmd_array == NULL) {
1195 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1199 cmdarray = priv->cmd_array;
1201 /* Release shared memory buffers */
1202 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1203 if (cmdarray[i].cmdbuf) {
1204 kfree(cmdarray[i].cmdbuf);
1205 cmdarray[i].cmdbuf = NULL;
1209 /* Release cmd_ctrl_node */
1210 if (priv->cmd_array) {
1211 kfree(priv->cmd_array);
1212 priv->cmd_array = NULL;
1216 lbs_deb_leave(LBS_DEB_HOST);
1221 * lbs_get_free_cmd_node - gets a free command node if available in
1222 * command free queue
1224 * @priv: A pointer to &struct lbs_private structure
1226 * returns: A pointer to &cmd_ctrl_node structure on success
1229 static struct cmd_ctrl_node *lbs_get_free_cmd_node(struct lbs_private *priv)
1231 struct cmd_ctrl_node *tempnode;
1232 unsigned long flags;
1234 lbs_deb_enter(LBS_DEB_HOST);
1239 spin_lock_irqsave(&priv->driver_lock, flags);
1241 if (!list_empty(&priv->cmdfreeq)) {
1242 tempnode = list_first_entry(&priv->cmdfreeq,
1243 struct cmd_ctrl_node, list);
1244 list_del(&tempnode->list);
1246 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1250 spin_unlock_irqrestore(&priv->driver_lock, flags);
1252 lbs_deb_leave(LBS_DEB_HOST);
1257 * lbs_execute_next_command - execute next command in command
1258 * pending queue. Will put firmware back to PS mode if applicable.
1260 * @priv: A pointer to &struct lbs_private structure
1262 * returns: 0 on success or -1 on error
1264 int lbs_execute_next_command(struct lbs_private *priv)
1266 struct cmd_ctrl_node *cmdnode = NULL;
1267 struct cmd_header *cmd;
1268 unsigned long flags;
1271 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1272 * only caller to us is lbs_thread() and we get even when a
1273 * data packet is received */
1274 lbs_deb_enter(LBS_DEB_THREAD);
1276 spin_lock_irqsave(&priv->driver_lock, flags);
1278 if (priv->cur_cmd) {
1279 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1280 spin_unlock_irqrestore(&priv->driver_lock, flags);
1285 if (!list_empty(&priv->cmdpendingq)) {
1286 cmdnode = list_first_entry(&priv->cmdpendingq,
1287 struct cmd_ctrl_node, list);
1290 spin_unlock_irqrestore(&priv->driver_lock, flags);
1293 cmd = cmdnode->cmdbuf;
1295 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
1296 if ((priv->psstate == PS_STATE_SLEEP) ||
1297 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1299 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1300 le16_to_cpu(cmd->command),
1305 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1306 "0x%04x in psstate %d\n",
1307 le16_to_cpu(cmd->command), priv->psstate);
1308 } else if (priv->psstate != PS_STATE_FULL_POWER) {
1310 * 1. Non-PS command:
1311 * Queue it. set needtowakeup to TRUE if current state
1312 * is SLEEP, otherwise call send EXIT_PS.
1313 * 2. PS command but not EXIT_PS:
1315 * 3. PS command EXIT_PS:
1316 * Set needtowakeup to TRUE if current state is SLEEP,
1317 * otherwise send this command down to firmware
1320 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
1321 /* Prepare to send Exit PS,
1322 * this non PS command will be sent later */
1323 if ((priv->psstate == PS_STATE_SLEEP)
1324 || (priv->psstate == PS_STATE_PRE_SLEEP)
1326 /* w/ new scheme, it will not reach here.
1327 since it is blocked in main_thread. */
1328 priv->needtowakeup = 1;
1330 lbs_set_ps_mode(priv,
1331 PS_MODE_ACTION_EXIT_PS,
1339 * PS command. Ignore it if it is not Exit_PS.
1340 * otherwise send it down immediately.
1342 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
1345 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1348 cpu_to_le16(PS_MODE_ACTION_EXIT_PS)) {
1350 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1351 list_del(&cmdnode->list);
1352 spin_lock_irqsave(&priv->driver_lock, flags);
1353 lbs_complete_command(priv, cmdnode, 0);
1354 spin_unlock_irqrestore(&priv->driver_lock, flags);
1360 if ((priv->psstate == PS_STATE_SLEEP) ||
1361 (priv->psstate == PS_STATE_PRE_SLEEP)) {
1363 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1364 list_del(&cmdnode->list);
1365 spin_lock_irqsave(&priv->driver_lock, flags);
1366 lbs_complete_command(priv, cmdnode, 0);
1367 spin_unlock_irqrestore(&priv->driver_lock, flags);
1368 priv->needtowakeup = 1;
1375 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1378 list_del(&cmdnode->list);
1379 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1380 le16_to_cpu(cmd->command));
1381 lbs_submit_command(priv, cmdnode);
1384 * check if in power save mode, if yes, put the device back
1389 * This was the old code for libertas+wext. Someone that
1390 * understands this beast should re-code it in a sane way.
1392 * I actually don't understand why this is related to WPA
1393 * and to connection status, shouldn't powering should be
1394 * independ of such things?
1396 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1397 (priv->psstate == PS_STATE_FULL_POWER) &&
1398 ((priv->connect_status == LBS_CONNECTED) ||
1399 lbs_mesh_connected(priv))) {
1400 if (priv->secinfo.WPAenabled ||
1401 priv->secinfo.WPA2enabled) {
1402 /* check for valid WPA group keys */
1403 if (priv->wpa_mcast_key.len ||
1404 priv->wpa_unicast_key.len) {
1406 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1407 " go back to PS_SLEEP");
1408 lbs_set_ps_mode(priv,
1409 PS_MODE_ACTION_ENTER_PS,
1414 "EXEC_NEXT_CMD: cmdpendingq empty, "
1415 "go back to PS_SLEEP");
1416 lbs_set_ps_mode(priv, PS_MODE_ACTION_ENTER_PS,
1425 lbs_deb_leave(LBS_DEB_THREAD);
1429 static void lbs_send_confirmsleep(struct lbs_private *priv)
1431 unsigned long flags;
1434 lbs_deb_enter(LBS_DEB_HOST);
1435 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1436 sizeof(confirm_sleep));
1438 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1439 sizeof(confirm_sleep));
1441 lbs_pr_alert("confirm_sleep failed\n");
1445 spin_lock_irqsave(&priv->driver_lock, flags);
1447 /* We don't get a response on the sleep-confirmation */
1448 priv->dnld_sent = DNLD_RES_RECEIVED;
1450 if (priv->is_host_sleep_configured) {
1451 priv->is_host_sleep_activated = 1;
1452 wake_up_interruptible(&priv->host_sleep_q);
1455 /* If nothing to do, go back to sleep (?) */
1456 if (!kfifo_len(&priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1457 priv->psstate = PS_STATE_SLEEP;
1459 spin_unlock_irqrestore(&priv->driver_lock, flags);
1462 lbs_deb_leave(LBS_DEB_HOST);
1466 * lbs_ps_confirm_sleep - checks condition and prepares to
1467 * send sleep confirm command to firmware if ok
1469 * @priv: A pointer to &struct lbs_private structure
1473 void lbs_ps_confirm_sleep(struct lbs_private *priv)
1475 unsigned long flags =0;
1478 lbs_deb_enter(LBS_DEB_HOST);
1480 spin_lock_irqsave(&priv->driver_lock, flags);
1481 if (priv->dnld_sent) {
1483 lbs_deb_host("dnld_sent was set\n");
1486 /* In-progress command? */
1487 if (priv->cur_cmd) {
1489 lbs_deb_host("cur_cmd was set\n");
1492 /* Pending events or command responses? */
1493 if (kfifo_len(&priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
1495 lbs_deb_host("pending events or command responses\n");
1497 spin_unlock_irqrestore(&priv->driver_lock, flags);
1500 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
1501 lbs_send_confirmsleep(priv);
1503 lbs_deb_host("sleep confirm has been delayed\n");
1506 lbs_deb_leave(LBS_DEB_HOST);
1511 * lbs_set_tpc_cfg - Configures the transmission power control functionality
1513 * @priv: A pointer to &struct lbs_private structure
1514 * @enable: Transmission power control enable
1515 * @p0: Power level when link quality is good (dBm).
1516 * @p1: Power level when link quality is fair (dBm).
1517 * @p2: Power level when link quality is poor (dBm).
1518 * @usesnr: Use Signal to Noise Ratio in TPC
1520 * returns: 0 on success
1522 int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1523 int8_t p2, int usesnr)
1525 struct cmd_ds_802_11_tpc_cfg cmd;
1528 memset(&cmd, 0, sizeof(cmd));
1529 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1530 cmd.action = cpu_to_le16(CMD_ACT_SET);
1531 cmd.enable = !!enable;
1532 cmd.usesnr = !!usesnr;
1537 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1543 * lbs_set_power_adapt_cfg - Configures the power adaptation settings
1545 * @priv: A pointer to &struct lbs_private structure
1546 * @enable: Power adaptation enable
1547 * @p0: Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1548 * @p1: Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1549 * @p2: Power level for 48 and 54 Mbps (dBm).
1551 * returns: 0 on Success
1554 int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1555 int8_t p1, int8_t p2)
1557 struct cmd_ds_802_11_pa_cfg cmd;
1560 memset(&cmd, 0, sizeof(cmd));
1561 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1562 cmd.action = cpu_to_le16(CMD_ACT_SET);
1563 cmd.enable = !!enable;
1568 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1574 struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1575 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1576 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1577 unsigned long callback_arg)
1579 struct cmd_ctrl_node *cmdnode;
1581 lbs_deb_enter(LBS_DEB_HOST);
1583 if (priv->surpriseremoved) {
1584 lbs_deb_host("PREP_CMD: card removed\n");
1585 cmdnode = ERR_PTR(-ENOENT);
1589 /* No commands are allowed in Deep Sleep until we toggle the GPIO
1590 * to wake up the card and it has signaled that it's ready.
1592 if (!priv->is_auto_deep_sleep_enabled) {
1593 if (priv->is_deep_sleep) {
1594 lbs_deb_cmd("command not allowed in deep sleep\n");
1595 cmdnode = ERR_PTR(-EBUSY);
1600 cmdnode = lbs_get_free_cmd_node(priv);
1601 if (cmdnode == NULL) {
1602 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1604 /* Wake up main thread to execute next command */
1605 wake_up_interruptible(&priv->waitq);
1606 cmdnode = ERR_PTR(-ENOBUFS);
1610 cmdnode->callback = callback;
1611 cmdnode->callback_arg = callback_arg;
1613 /* Copy the incoming command to the buffer */
1614 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
1616 /* Set sequence number, clean result, move to buffer */
1618 cmdnode->cmdbuf->command = cpu_to_le16(command);
1619 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
1620 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
1621 cmdnode->cmdbuf->result = 0;
1623 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
1625 cmdnode->cmdwaitqwoken = 0;
1626 lbs_queue_cmd(priv, cmdnode);
1627 wake_up_interruptible(&priv->waitq);
1630 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
1634 void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
1635 struct cmd_header *in_cmd, int in_cmd_size)
1637 lbs_deb_enter(LBS_DEB_CMD);
1638 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1639 lbs_cmd_async_callback, 0);
1640 lbs_deb_leave(LBS_DEB_CMD);
1643 int __lbs_cmd(struct lbs_private *priv, uint16_t command,
1644 struct cmd_header *in_cmd, int in_cmd_size,
1645 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1646 unsigned long callback_arg)
1648 struct cmd_ctrl_node *cmdnode;
1649 unsigned long flags;
1652 lbs_deb_enter(LBS_DEB_HOST);
1654 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
1655 callback, callback_arg);
1656 if (IS_ERR(cmdnode)) {
1657 ret = PTR_ERR(cmdnode);
1662 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
1664 spin_lock_irqsave(&priv->driver_lock, flags);
1665 ret = cmdnode->result;
1667 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
1670 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
1671 spin_unlock_irqrestore(&priv->driver_lock, flags);
1674 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
1677 EXPORT_SYMBOL_GPL(__lbs_cmd);