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>
9 #include <linux/sched.h>
19 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
);
22 * @brief Simple callback that copies response back into command
24 * @param priv A pointer to struct lbs_private structure
25 * @param extra A pointer to the original command structure for which
26 * 'resp' is a response
27 * @param resp A pointer to the command response
29 * @return 0 on success, error on failure
31 int lbs_cmd_copyback(struct lbs_private
*priv
, unsigned long extra
,
32 struct cmd_header
*resp
)
34 struct cmd_header
*buf
= (void *)extra
;
37 copy_len
= min(le16_to_cpu(buf
->size
), le16_to_cpu(resp
->size
));
38 memcpy(buf
, resp
, copy_len
);
41 EXPORT_SYMBOL_GPL(lbs_cmd_copyback
);
44 * @brief Simple callback that ignores the result. Use this if
45 * you just want to send a command to the hardware, but don't
46 * care for the result.
49 * @param extra ignored
52 * @return 0 for success
54 static int lbs_cmd_async_callback(struct lbs_private
*priv
, unsigned long extra
,
55 struct cmd_header
*resp
)
62 * @brief Checks whether a command is allowed in Power Save mode
64 * @param command the command ID
65 * @return 1 if allowed, 0 if not allowed
67 static u8
is_command_allowed_in_ps(u16 cmd
)
79 * @brief This function checks if the command is allowed.
81 * @param priv A pointer to lbs_private structure
82 * @return allowed or not allowed.
85 static int lbs_is_cmd_allowed(struct lbs_private
*priv
)
89 lbs_deb_enter(LBS_DEB_CMD
);
91 if (!priv
->is_auto_deep_sleep_enabled
) {
92 if (priv
->is_deep_sleep
) {
93 lbs_deb_cmd("command not allowed in deep sleep\n");
98 lbs_deb_leave(LBS_DEB_CMD
);
103 * @brief Updates the hardware details like MAC address and regulatory region
105 * @param priv A pointer to struct lbs_private structure
107 * @return 0 on success, error on failure
109 int lbs_update_hw_spec(struct lbs_private
*priv
)
111 struct cmd_ds_get_hw_spec cmd
;
115 lbs_deb_enter(LBS_DEB_CMD
);
117 memset(&cmd
, 0, sizeof(cmd
));
118 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
119 memcpy(cmd
.permanentaddr
, priv
->current_addr
, ETH_ALEN
);
120 ret
= lbs_cmd_with_response(priv
, CMD_GET_HW_SPEC
, &cmd
);
124 priv
->fwcapinfo
= le32_to_cpu(cmd
.fwcapinfo
);
126 /* The firmware release is in an interesting format: the patch
127 * level is in the most significant nibble ... so fix that: */
128 priv
->fwrelease
= le32_to_cpu(cmd
.fwrelease
);
129 priv
->fwrelease
= (priv
->fwrelease
<< 8) |
130 (priv
->fwrelease
>> 24 & 0xff);
132 /* Some firmware capabilities:
133 * CF card firmware 5.0.16p0: cap 0x00000303
134 * USB dongle firmware 5.110.17p2: cap 0x00000303
136 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
138 priv
->fwrelease
>> 24 & 0xff,
139 priv
->fwrelease
>> 16 & 0xff,
140 priv
->fwrelease
>> 8 & 0xff,
141 priv
->fwrelease
& 0xff,
143 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
144 cmd
.hwifversion
, cmd
.version
);
146 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
147 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
148 /* 5.110.22 have mesh command with 0xa3 command id */
149 /* 10.0.0.p0 FW brings in mesh config command with different id */
150 /* Check FW version MSB and initialize mesh_fw_ver */
151 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V5
)
152 priv
->mesh_fw_ver
= MESH_FW_OLD
;
153 else if ((MRVL_FW_MAJOR_REV(priv
->fwrelease
) >= MRVL_FW_V10
) &&
154 (priv
->fwcapinfo
& MESH_CAPINFO_ENABLE_MASK
))
155 priv
->mesh_fw_ver
= MESH_FW_NEW
;
157 priv
->mesh_fw_ver
= MESH_NONE
;
159 /* Clamp region code to 8-bit since FW spec indicates that it should
160 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
161 * returns non-zero high 8 bits here.
163 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
164 * need to check for this problem and handle it properly.
166 if (MRVL_FW_MAJOR_REV(priv
->fwrelease
) == MRVL_FW_V4
)
167 priv
->regioncode
= (le16_to_cpu(cmd
.regioncode
) >> 8) & 0xFF;
169 priv
->regioncode
= le16_to_cpu(cmd
.regioncode
) & 0xFF;
171 for (i
= 0; i
< MRVDRV_MAX_REGION_CODE
; i
++) {
172 /* use the region code to search for the index */
173 if (priv
->regioncode
== lbs_region_code_to_index
[i
])
177 /* if it's unidentified region code, use the default (USA) */
178 if (i
>= MRVDRV_MAX_REGION_CODE
) {
179 priv
->regioncode
= 0x10;
180 lbs_pr_info("unidentified region code; using the default (USA)\n");
183 if (priv
->current_addr
[0] == 0xff)
184 memmove(priv
->current_addr
, cmd
.permanentaddr
, ETH_ALEN
);
186 memcpy(priv
->dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
188 memcpy(priv
->mesh_dev
->dev_addr
, priv
->current_addr
, ETH_ALEN
);
190 if (lbs_set_regiontable(priv
, priv
->regioncode
, 0)) {
195 if (lbs_set_universaltable(priv
, 0)) {
201 lbs_deb_leave(LBS_DEB_CMD
);
205 int lbs_host_sleep_cfg(struct lbs_private
*priv
, uint32_t criteria
,
206 struct wol_config
*p_wol_config
)
208 struct cmd_ds_host_sleep cmd_config
;
211 cmd_config
.hdr
.size
= cpu_to_le16(sizeof(cmd_config
));
212 cmd_config
.criteria
= cpu_to_le32(criteria
);
213 cmd_config
.gpio
= priv
->wol_gpio
;
214 cmd_config
.gap
= priv
->wol_gap
;
216 if (p_wol_config
!= NULL
)
217 memcpy((uint8_t *)&cmd_config
.wol_conf
, (uint8_t *)p_wol_config
,
218 sizeof(struct wol_config
));
220 cmd_config
.wol_conf
.action
= CMD_ACT_ACTION_NONE
;
222 ret
= lbs_cmd_with_response(priv
, CMD_802_11_HOST_SLEEP_CFG
, &cmd_config
);
225 lbs_deb_cmd("Set WOL criteria to %x\n", criteria
);
226 priv
->wol_criteria
= criteria
;
228 memcpy((uint8_t *) p_wol_config
,
229 (uint8_t *)&cmd_config
.wol_conf
,
230 sizeof(struct wol_config
));
232 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret
);
237 EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg
);
239 static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command
*cmd
,
242 struct cmd_ds_802_11_ps_mode
*psm
= &cmd
->params
.psmode
;
244 lbs_deb_enter(LBS_DEB_CMD
);
246 cmd
->command
= cpu_to_le16(CMD_802_11_PS_MODE
);
247 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode
) +
249 psm
->action
= cpu_to_le16(cmd_action
);
250 psm
->multipledtim
= 0;
251 switch (cmd_action
) {
252 case CMD_SUBCMD_ENTER_PS
:
253 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
255 psm
->locallisteninterval
= 0;
256 psm
->nullpktinterval
= 0;
258 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM
);
261 case CMD_SUBCMD_EXIT_PS
:
262 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
265 case CMD_SUBCMD_SLEEP_CONFIRMED
:
266 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
273 lbs_deb_leave(LBS_DEB_CMD
);
277 int lbs_cmd_802_11_inactivity_timeout(struct lbs_private
*priv
,
278 uint16_t cmd_action
, uint16_t *timeout
)
280 struct cmd_ds_802_11_inactivity_timeout cmd
;
283 lbs_deb_enter(LBS_DEB_CMD
);
285 cmd
.hdr
.command
= cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT
);
286 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
288 cmd
.action
= cpu_to_le16(cmd_action
);
290 if (cmd_action
== CMD_ACT_SET
)
291 cmd
.timeout
= cpu_to_le16(*timeout
);
295 ret
= lbs_cmd_with_response(priv
, CMD_802_11_INACTIVITY_TIMEOUT
, &cmd
);
298 *timeout
= le16_to_cpu(cmd
.timeout
);
300 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
304 int lbs_cmd_802_11_sleep_params(struct lbs_private
*priv
, uint16_t cmd_action
,
305 struct sleep_params
*sp
)
307 struct cmd_ds_802_11_sleep_params cmd
;
310 lbs_deb_enter(LBS_DEB_CMD
);
312 if (cmd_action
== CMD_ACT_GET
) {
313 memset(&cmd
, 0, sizeof(cmd
));
315 cmd
.error
= cpu_to_le16(sp
->sp_error
);
316 cmd
.offset
= cpu_to_le16(sp
->sp_offset
);
317 cmd
.stabletime
= cpu_to_le16(sp
->sp_stabletime
);
318 cmd
.calcontrol
= sp
->sp_calcontrol
;
319 cmd
.externalsleepclk
= sp
->sp_extsleepclk
;
320 cmd
.reserved
= cpu_to_le16(sp
->sp_reserved
);
322 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
323 cmd
.action
= cpu_to_le16(cmd_action
);
325 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SLEEP_PARAMS
, &cmd
);
328 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
329 "calcontrol 0x%x extsleepclk 0x%x\n",
330 le16_to_cpu(cmd
.error
), le16_to_cpu(cmd
.offset
),
331 le16_to_cpu(cmd
.stabletime
), cmd
.calcontrol
,
332 cmd
.externalsleepclk
);
334 sp
->sp_error
= le16_to_cpu(cmd
.error
);
335 sp
->sp_offset
= le16_to_cpu(cmd
.offset
);
336 sp
->sp_stabletime
= le16_to_cpu(cmd
.stabletime
);
337 sp
->sp_calcontrol
= cmd
.calcontrol
;
338 sp
->sp_extsleepclk
= cmd
.externalsleepclk
;
339 sp
->sp_reserved
= le16_to_cpu(cmd
.reserved
);
342 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
346 static int lbs_wait_for_ds_awake(struct lbs_private
*priv
)
350 lbs_deb_enter(LBS_DEB_CMD
);
352 if (priv
->is_deep_sleep
) {
353 if (!wait_event_interruptible_timeout(priv
->ds_awake_q
,
354 !priv
->is_deep_sleep
, (10 * HZ
))) {
355 lbs_pr_err("ds_awake_q: timer expired\n");
360 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
364 int lbs_set_deep_sleep(struct lbs_private
*priv
, int deep_sleep
)
368 lbs_deb_enter(LBS_DEB_CMD
);
371 if (priv
->is_deep_sleep
!= 1) {
372 lbs_deb_cmd("deep sleep: sleep\n");
373 BUG_ON(!priv
->enter_deep_sleep
);
374 ret
= priv
->enter_deep_sleep(priv
);
376 netif_stop_queue(priv
->dev
);
377 netif_carrier_off(priv
->dev
);
380 lbs_pr_err("deep sleep: already enabled\n");
383 if (priv
->is_deep_sleep
) {
384 lbs_deb_cmd("deep sleep: wakeup\n");
385 BUG_ON(!priv
->exit_deep_sleep
);
386 ret
= priv
->exit_deep_sleep(priv
);
388 ret
= lbs_wait_for_ds_awake(priv
);
390 lbs_pr_err("deep sleep: wakeup"
396 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
400 int lbs_cmd_802_11_set_wep(struct lbs_private
*priv
, uint16_t cmd_action
,
401 struct assoc_request
*assoc
)
403 struct cmd_ds_802_11_set_wep cmd
;
406 lbs_deb_enter(LBS_DEB_CMD
);
408 memset(&cmd
, 0, sizeof(cmd
));
409 cmd
.hdr
.command
= cpu_to_le16(CMD_802_11_SET_WEP
);
410 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
412 cmd
.action
= cpu_to_le16(cmd_action
);
414 if (cmd_action
== CMD_ACT_ADD
) {
417 /* default tx key index */
418 cmd
.keyindex
= cpu_to_le16(assoc
->wep_tx_keyidx
&
419 CMD_WEP_KEY_INDEX_MASK
);
421 /* Copy key types and material to host command structure */
422 for (i
= 0; i
< 4; i
++) {
423 struct enc_key
*pkey
= &assoc
->wep_keys
[i
];
427 cmd
.keytype
[i
] = CMD_TYPE_WEP_40_BIT
;
428 memmove(cmd
.keymaterial
[i
], pkey
->key
, pkey
->len
);
429 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i
);
431 case KEY_LEN_WEP_104
:
432 cmd
.keytype
[i
] = CMD_TYPE_WEP_104_BIT
;
433 memmove(cmd
.keymaterial
[i
], pkey
->key
, pkey
->len
);
434 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i
);
439 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
446 } else if (cmd_action
== CMD_ACT_REMOVE
) {
447 /* ACT_REMOVE clears _all_ WEP keys */
449 /* default tx key index */
450 cmd
.keyindex
= cpu_to_le16(priv
->wep_tx_keyidx
&
451 CMD_WEP_KEY_INDEX_MASK
);
452 lbs_deb_cmd("SET_WEP: remove key %d\n", priv
->wep_tx_keyidx
);
455 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SET_WEP
, &cmd
);
457 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
461 int lbs_cmd_802_11_enable_rsn(struct lbs_private
*priv
, uint16_t cmd_action
,
464 struct cmd_ds_802_11_enable_rsn cmd
;
467 lbs_deb_enter(LBS_DEB_CMD
);
469 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
470 cmd
.action
= cpu_to_le16(cmd_action
);
472 if (cmd_action
== CMD_ACT_GET
)
476 cmd
.enable
= cpu_to_le16(CMD_ENABLE_RSN
);
478 cmd
.enable
= cpu_to_le16(CMD_DISABLE_RSN
);
479 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable
);
482 ret
= lbs_cmd_with_response(priv
, CMD_802_11_ENABLE_RSN
, &cmd
);
483 if (!ret
&& cmd_action
== CMD_ACT_GET
)
484 *enable
= le16_to_cpu(cmd
.enable
);
486 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
490 static void set_one_wpa_key(struct MrvlIEtype_keyParamSet
*keyparam
,
493 lbs_deb_enter(LBS_DEB_CMD
);
495 if (key
->flags
& KEY_INFO_WPA_ENABLED
)
496 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_ENABLED
);
497 if (key
->flags
& KEY_INFO_WPA_UNICAST
)
498 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_UNICAST
);
499 if (key
->flags
& KEY_INFO_WPA_MCAST
)
500 keyparam
->keyinfo
|= cpu_to_le16(KEY_INFO_WPA_MCAST
);
502 keyparam
->type
= cpu_to_le16(TLV_TYPE_KEY_MATERIAL
);
503 keyparam
->keytypeid
= cpu_to_le16(key
->type
);
504 keyparam
->keylen
= cpu_to_le16(key
->len
);
505 memcpy(keyparam
->key
, key
->key
, key
->len
);
507 /* Length field doesn't include the {type,length} header */
508 keyparam
->length
= cpu_to_le16(sizeof(*keyparam
) - 4);
509 lbs_deb_leave(LBS_DEB_CMD
);
512 int lbs_cmd_802_11_key_material(struct lbs_private
*priv
, uint16_t cmd_action
,
513 struct assoc_request
*assoc
)
515 struct cmd_ds_802_11_key_material cmd
;
519 lbs_deb_enter(LBS_DEB_CMD
);
521 cmd
.action
= cpu_to_le16(cmd_action
);
522 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
524 if (cmd_action
== CMD_ACT_GET
) {
525 cmd
.hdr
.size
= cpu_to_le16(S_DS_GEN
+ 2);
527 memset(cmd
.keyParamSet
, 0, sizeof(cmd
.keyParamSet
));
529 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY
, &assoc
->flags
)) {
530 set_one_wpa_key(&cmd
.keyParamSet
[index
],
531 &assoc
->wpa_unicast_key
);
535 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY
, &assoc
->flags
)) {
536 set_one_wpa_key(&cmd
.keyParamSet
[index
],
537 &assoc
->wpa_mcast_key
);
541 /* The common header and as many keys as we included */
542 cmd
.hdr
.size
= cpu_to_le16(offsetof(typeof(cmd
),
543 keyParamSet
[index
]));
545 ret
= lbs_cmd_with_response(priv
, CMD_802_11_KEY_MATERIAL
, &cmd
);
546 /* Copy the returned key to driver private data */
547 if (!ret
&& cmd_action
== CMD_ACT_GET
) {
548 void *buf_ptr
= cmd
.keyParamSet
;
549 void *resp_end
= &(&cmd
)[1];
551 while (buf_ptr
< resp_end
) {
552 struct MrvlIEtype_keyParamSet
*keyparam
= buf_ptr
;
554 uint16_t param_set_len
= le16_to_cpu(keyparam
->length
);
555 uint16_t key_len
= le16_to_cpu(keyparam
->keylen
);
556 uint16_t key_flags
= le16_to_cpu(keyparam
->keyinfo
);
557 uint16_t key_type
= le16_to_cpu(keyparam
->keytypeid
);
560 end
= (void *)keyparam
+ sizeof(keyparam
->type
)
561 + sizeof(keyparam
->length
) + param_set_len
;
563 /* Make sure we don't access past the end of the IEs */
567 if (key_flags
& KEY_INFO_WPA_UNICAST
)
568 key
= &priv
->wpa_unicast_key
;
569 else if (key_flags
& KEY_INFO_WPA_MCAST
)
570 key
= &priv
->wpa_mcast_key
;
574 /* Copy returned key into driver */
575 memset(key
, 0, sizeof(struct enc_key
));
576 if (key_len
> sizeof(key
->key
))
578 key
->type
= key_type
;
579 key
->flags
= key_flags
;
581 memcpy(key
->key
, keyparam
->key
, key
->len
);
587 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
592 * @brief Set an SNMP MIB value
594 * @param priv A pointer to struct lbs_private structure
595 * @param oid The OID to set in the firmware
596 * @param val Value to set the OID to
598 * @return 0 on success, error on failure
600 int lbs_set_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16 val
)
602 struct cmd_ds_802_11_snmp_mib cmd
;
605 lbs_deb_enter(LBS_DEB_CMD
);
607 memset(&cmd
, 0, sizeof (cmd
));
608 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
609 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
610 cmd
.oid
= cpu_to_le16((u16
) oid
);
613 case SNMP_MIB_OID_BSS_TYPE
:
614 cmd
.bufsize
= cpu_to_le16(sizeof(u8
));
615 cmd
.value
[0] = (val
== IW_MODE_ADHOC
) ? 2 : 1;
617 case SNMP_MIB_OID_11D_ENABLE
:
618 case SNMP_MIB_OID_FRAG_THRESHOLD
:
619 case SNMP_MIB_OID_RTS_THRESHOLD
:
620 case SNMP_MIB_OID_SHORT_RETRY_LIMIT
:
621 case SNMP_MIB_OID_LONG_RETRY_LIMIT
:
622 cmd
.bufsize
= cpu_to_le16(sizeof(u16
));
623 *((__le16
*)(&cmd
.value
)) = cpu_to_le16(val
);
626 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid
);
631 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
632 le16_to_cpu(cmd
.oid
), le16_to_cpu(cmd
.bufsize
), val
);
634 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
637 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
642 * @brief Get an SNMP MIB value
644 * @param priv A pointer to struct lbs_private structure
645 * @param oid The OID to retrieve from the firmware
646 * @param out_val Location for the returned value
648 * @return 0 on success, error on failure
650 int lbs_get_snmp_mib(struct lbs_private
*priv
, u32 oid
, u16
*out_val
)
652 struct cmd_ds_802_11_snmp_mib cmd
;
655 lbs_deb_enter(LBS_DEB_CMD
);
657 memset(&cmd
, 0, sizeof (cmd
));
658 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
659 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
660 cmd
.oid
= cpu_to_le16(oid
);
662 ret
= lbs_cmd_with_response(priv
, CMD_802_11_SNMP_MIB
, &cmd
);
666 switch (le16_to_cpu(cmd
.bufsize
)) {
668 if (oid
== SNMP_MIB_OID_BSS_TYPE
) {
669 if (cmd
.value
[0] == 2)
670 *out_val
= IW_MODE_ADHOC
;
672 *out_val
= IW_MODE_INFRA
;
674 *out_val
= cmd
.value
[0];
677 *out_val
= le16_to_cpu(*((__le16
*)(&cmd
.value
)));
680 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
681 oid
, le16_to_cpu(cmd
.bufsize
));
686 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
691 * @brief Get the min, max, and current TX power
693 * @param priv A pointer to struct lbs_private structure
694 * @param curlevel Current power level in dBm
695 * @param minlevel Minimum supported power level in dBm (optional)
696 * @param maxlevel Maximum supported power level in dBm (optional)
698 * @return 0 on success, error on failure
700 int lbs_get_tx_power(struct lbs_private
*priv
, s16
*curlevel
, s16
*minlevel
,
703 struct cmd_ds_802_11_rf_tx_power cmd
;
706 lbs_deb_enter(LBS_DEB_CMD
);
708 memset(&cmd
, 0, sizeof(cmd
));
709 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
710 cmd
.action
= cpu_to_le16(CMD_ACT_GET
);
712 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
714 *curlevel
= le16_to_cpu(cmd
.curlevel
);
716 *minlevel
= cmd
.minlevel
;
718 *maxlevel
= cmd
.maxlevel
;
721 lbs_deb_leave(LBS_DEB_CMD
);
726 * @brief Set the TX power
728 * @param priv A pointer to struct lbs_private structure
729 * @param dbm The desired power level in dBm
731 * @return 0 on success, error on failure
733 int lbs_set_tx_power(struct lbs_private
*priv
, s16 dbm
)
735 struct cmd_ds_802_11_rf_tx_power cmd
;
738 lbs_deb_enter(LBS_DEB_CMD
);
740 memset(&cmd
, 0, sizeof(cmd
));
741 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
742 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
743 cmd
.curlevel
= cpu_to_le16(dbm
);
745 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm
);
747 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_TX_POWER
, &cmd
);
749 lbs_deb_leave(LBS_DEB_CMD
);
753 static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command
*cmd
,
754 u16 cmd_action
, void *pdata_buf
)
756 struct cmd_ds_802_11_monitor_mode
*monitor
= &cmd
->params
.monitor
;
758 cmd
->command
= cpu_to_le16(CMD_802_11_MONITOR_MODE
);
760 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode
) +
763 monitor
->action
= cpu_to_le16(cmd_action
);
764 if (cmd_action
== CMD_ACT_SET
) {
766 cpu_to_le16((u16
) (*(u32
*) pdata_buf
));
772 static __le16
lbs_rate_to_fw_bitmap(int rate
, int lower_rates_ok
)
792 int i
= lbs_data_rate_to_fw_index(rate
);
794 ratemask
= (0x1fef >> (12 - i
));
797 return cpu_to_le16(ratemask
);
800 int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private
*priv
,
803 struct cmd_ds_802_11_rate_adapt_rateset cmd
;
806 lbs_deb_enter(LBS_DEB_CMD
);
808 if (!priv
->cur_rate
&& !priv
->enablehwauto
)
811 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
813 cmd
.action
= cpu_to_le16(cmd_action
);
814 cmd
.enablehwauto
= cpu_to_le16(priv
->enablehwauto
);
815 cmd
.bitmap
= lbs_rate_to_fw_bitmap(priv
->cur_rate
, priv
->enablehwauto
);
816 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RATE_ADAPT_RATESET
, &cmd
);
817 if (!ret
&& cmd_action
== CMD_ACT_GET
) {
818 priv
->ratebitmap
= le16_to_cpu(cmd
.bitmap
);
819 priv
->enablehwauto
= le16_to_cpu(cmd
.enablehwauto
);
822 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
825 EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset
);
828 * @brief Set the data rate
830 * @param priv A pointer to struct lbs_private structure
831 * @param rate The desired data rate, or 0 to clear a locked rate
833 * @return 0 on success, error on failure
835 int lbs_set_data_rate(struct lbs_private
*priv
, u8 rate
)
837 struct cmd_ds_802_11_data_rate cmd
;
840 lbs_deb_enter(LBS_DEB_CMD
);
842 memset(&cmd
, 0, sizeof(cmd
));
843 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
846 cmd
.action
= cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE
);
847 cmd
.rates
[0] = lbs_data_rate_to_fw_index(rate
);
848 if (cmd
.rates
[0] == 0) {
849 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
854 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd
.rates
[0]);
856 cmd
.action
= cpu_to_le16(CMD_ACT_SET_TX_AUTO
);
857 lbs_deb_cmd("DATA_RATE: setting auto\n");
860 ret
= lbs_cmd_with_response(priv
, CMD_802_11_DATA_RATE
, &cmd
);
864 lbs_deb_hex(LBS_DEB_CMD
, "DATA_RATE_RESP", (u8
*) &cmd
, sizeof (cmd
));
866 /* FIXME: get actual rates FW can do if this command actually returns
867 * all data rates supported.
869 priv
->cur_rate
= lbs_fw_index_to_data_rate(cmd
.rates
[0]);
870 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv
->cur_rate
);
873 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
878 * @brief Get the radio channel
880 * @param priv A pointer to struct lbs_private structure
882 * @return The channel on success, error on failure
884 int lbs_get_channel(struct lbs_private
*priv
)
886 struct cmd_ds_802_11_rf_channel cmd
;
889 lbs_deb_enter(LBS_DEB_CMD
);
891 memset(&cmd
, 0, sizeof(cmd
));
892 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
893 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET
);
895 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
899 ret
= le16_to_cpu(cmd
.channel
);
900 lbs_deb_cmd("current radio channel is %d\n", ret
);
903 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
907 int lbs_update_channel(struct lbs_private
*priv
)
911 /* the channel in f/w could be out of sync; get the current channel */
912 lbs_deb_enter(LBS_DEB_ASSOC
);
914 ret
= lbs_get_channel(priv
);
916 priv
->curbssparams
.channel
= ret
;
919 lbs_deb_leave_args(LBS_DEB_ASSOC
, "ret %d", ret
);
924 * @brief Set the radio channel
926 * @param priv A pointer to struct lbs_private structure
927 * @param channel The desired channel, or 0 to clear a locked channel
929 * @return 0 on success, error on failure
931 int lbs_set_channel(struct lbs_private
*priv
, u8 channel
)
933 struct cmd_ds_802_11_rf_channel cmd
;
935 u8 old_channel
= priv
->curbssparams
.channel
;
939 lbs_deb_enter(LBS_DEB_CMD
);
941 memset(&cmd
, 0, sizeof(cmd
));
942 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
943 cmd
.action
= cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET
);
944 cmd
.channel
= cpu_to_le16(channel
);
946 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RF_CHANNEL
, &cmd
);
950 priv
->curbssparams
.channel
= (uint8_t) le16_to_cpu(cmd
.channel
);
951 lbs_deb_cmd("channel switch from %d to %d\n", old_channel
,
952 priv
->curbssparams
.channel
);
955 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
959 static int lbs_cmd_802_11_rssi(struct lbs_private
*priv
,
960 struct cmd_ds_command
*cmd
)
963 lbs_deb_enter(LBS_DEB_CMD
);
964 cmd
->command
= cpu_to_le16(CMD_802_11_RSSI
);
965 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi
) + S_DS_GEN
);
966 cmd
->params
.rssi
.N
= cpu_to_le16(DEFAULT_BCN_AVG_FACTOR
);
968 /* reset Beacon SNR/NF/RSSI values */
969 priv
->SNR
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
970 priv
->SNR
[TYPE_BEACON
][TYPE_AVG
] = 0;
971 priv
->NF
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
972 priv
->NF
[TYPE_BEACON
][TYPE_AVG
] = 0;
973 priv
->RSSI
[TYPE_BEACON
][TYPE_NOAVG
] = 0;
974 priv
->RSSI
[TYPE_BEACON
][TYPE_AVG
] = 0;
976 lbs_deb_leave(LBS_DEB_CMD
);
980 static int lbs_cmd_reg_access(struct cmd_ds_command
*cmdptr
,
981 u8 cmd_action
, void *pdata_buf
)
983 struct lbs_offset_value
*offval
;
985 lbs_deb_enter(LBS_DEB_CMD
);
987 offval
= (struct lbs_offset_value
*)pdata_buf
;
989 switch (le16_to_cpu(cmdptr
->command
)) {
990 case CMD_MAC_REG_ACCESS
:
992 struct cmd_ds_mac_reg_access
*macreg
;
995 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access
)
998 (struct cmd_ds_mac_reg_access
*)&cmdptr
->params
.
1001 macreg
->action
= cpu_to_le16(cmd_action
);
1002 macreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
1003 macreg
->value
= cpu_to_le32(offval
->value
);
1008 case CMD_BBP_REG_ACCESS
:
1010 struct cmd_ds_bbp_reg_access
*bbpreg
;
1014 (struct cmd_ds_bbp_reg_access
)
1017 (struct cmd_ds_bbp_reg_access
*)&cmdptr
->params
.
1020 bbpreg
->action
= cpu_to_le16(cmd_action
);
1021 bbpreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
1022 bbpreg
->value
= (u8
) offval
->value
;
1027 case CMD_RF_REG_ACCESS
:
1029 struct cmd_ds_rf_reg_access
*rfreg
;
1033 (struct cmd_ds_rf_reg_access
) +
1036 (struct cmd_ds_rf_reg_access
*)&cmdptr
->params
.
1039 rfreg
->action
= cpu_to_le16(cmd_action
);
1040 rfreg
->offset
= cpu_to_le16((u16
) offval
->offset
);
1041 rfreg
->value
= (u8
) offval
->value
;
1050 lbs_deb_leave(LBS_DEB_CMD
);
1054 static int lbs_cmd_bt_access(struct cmd_ds_command
*cmd
,
1055 u16 cmd_action
, void *pdata_buf
)
1057 struct cmd_ds_bt_access
*bt_access
= &cmd
->params
.bt
;
1058 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
1060 cmd
->command
= cpu_to_le16(CMD_BT_ACCESS
);
1061 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_bt_access
) + S_DS_GEN
);
1063 bt_access
->action
= cpu_to_le16(cmd_action
);
1065 switch (cmd_action
) {
1066 case CMD_ACT_BT_ACCESS_ADD
:
1067 memcpy(bt_access
->addr1
, pdata_buf
, 2 * ETH_ALEN
);
1068 lbs_deb_hex(LBS_DEB_MESH
, "BT_ADD: blinded MAC addr", bt_access
->addr1
, 6);
1070 case CMD_ACT_BT_ACCESS_DEL
:
1071 memcpy(bt_access
->addr1
, pdata_buf
, 1 * ETH_ALEN
);
1072 lbs_deb_hex(LBS_DEB_MESH
, "BT_DEL: blinded MAC addr", bt_access
->addr1
, 6);
1074 case CMD_ACT_BT_ACCESS_LIST
:
1075 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
1077 case CMD_ACT_BT_ACCESS_RESET
:
1079 case CMD_ACT_BT_ACCESS_SET_INVERT
:
1080 bt_access
->id
= cpu_to_le32(*(u32
*) pdata_buf
);
1082 case CMD_ACT_BT_ACCESS_GET_INVERT
:
1087 lbs_deb_leave(LBS_DEB_CMD
);
1091 static int lbs_cmd_fwt_access(struct cmd_ds_command
*cmd
,
1092 u16 cmd_action
, void *pdata_buf
)
1094 struct cmd_ds_fwt_access
*fwt_access
= &cmd
->params
.fwt
;
1095 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
1097 cmd
->command
= cpu_to_le16(CMD_FWT_ACCESS
);
1098 cmd
->size
= cpu_to_le16(sizeof(struct cmd_ds_fwt_access
) + S_DS_GEN
);
1102 memcpy(fwt_access
, pdata_buf
, sizeof(*fwt_access
));
1104 memset(fwt_access
, 0, sizeof(*fwt_access
));
1106 fwt_access
->action
= cpu_to_le16(cmd_action
);
1108 lbs_deb_leave(LBS_DEB_CMD
);
1112 int lbs_mesh_access(struct lbs_private
*priv
, uint16_t cmd_action
,
1113 struct cmd_ds_mesh_access
*cmd
)
1117 lbs_deb_enter_args(LBS_DEB_CMD
, "action %d", cmd_action
);
1119 cmd
->hdr
.command
= cpu_to_le16(CMD_MESH_ACCESS
);
1120 cmd
->hdr
.size
= cpu_to_le16(sizeof(*cmd
));
1121 cmd
->hdr
.result
= 0;
1123 cmd
->action
= cpu_to_le16(cmd_action
);
1125 ret
= lbs_cmd_with_response(priv
, CMD_MESH_ACCESS
, cmd
);
1127 lbs_deb_leave(LBS_DEB_CMD
);
1131 static int __lbs_mesh_config_send(struct lbs_private
*priv
,
1132 struct cmd_ds_mesh_config
*cmd
,
1133 uint16_t action
, uint16_t type
)
1136 u16 command
= CMD_MESH_CONFIG_OLD
;
1138 lbs_deb_enter(LBS_DEB_CMD
);
1141 * Command id is 0xac for v10 FW along with mesh interface
1142 * id in bits 14-13-12.
1144 if (priv
->mesh_fw_ver
== MESH_FW_NEW
)
1145 command
= CMD_MESH_CONFIG
|
1146 (MESH_IFACE_ID
<< MESH_IFACE_BIT_OFFSET
);
1148 cmd
->hdr
.command
= cpu_to_le16(command
);
1149 cmd
->hdr
.size
= cpu_to_le16(sizeof(struct cmd_ds_mesh_config
));
1150 cmd
->hdr
.result
= 0;
1152 cmd
->type
= cpu_to_le16(type
);
1153 cmd
->action
= cpu_to_le16(action
);
1155 ret
= lbs_cmd_with_response(priv
, command
, cmd
);
1157 lbs_deb_leave(LBS_DEB_CMD
);
1161 int lbs_mesh_config_send(struct lbs_private
*priv
,
1162 struct cmd_ds_mesh_config
*cmd
,
1163 uint16_t action
, uint16_t type
)
1167 if (!(priv
->fwcapinfo
& FW_CAPINFO_PERSISTENT_CONFIG
))
1170 ret
= __lbs_mesh_config_send(priv
, cmd
, action
, type
);
1174 /* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1175 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1176 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1177 * lbs_mesh_config_send.
1179 int lbs_mesh_config(struct lbs_private
*priv
, uint16_t action
, uint16_t chan
)
1181 struct cmd_ds_mesh_config cmd
;
1182 struct mrvl_meshie
*ie
;
1183 DECLARE_SSID_BUF(ssid
);
1185 memset(&cmd
, 0, sizeof(cmd
));
1186 cmd
.channel
= cpu_to_le16(chan
);
1187 ie
= (struct mrvl_meshie
*)cmd
.data
;
1190 case CMD_ACT_MESH_CONFIG_START
:
1191 ie
->id
= WLAN_EID_GENERIC
;
1192 ie
->val
.oui
[0] = 0x00;
1193 ie
->val
.oui
[1] = 0x50;
1194 ie
->val
.oui
[2] = 0x43;
1195 ie
->val
.type
= MARVELL_MESH_IE_TYPE
;
1196 ie
->val
.subtype
= MARVELL_MESH_IE_SUBTYPE
;
1197 ie
->val
.version
= MARVELL_MESH_IE_VERSION
;
1198 ie
->val
.active_protocol_id
= MARVELL_MESH_PROTO_ID_HWMP
;
1199 ie
->val
.active_metric_id
= MARVELL_MESH_METRIC_ID
;
1200 ie
->val
.mesh_capability
= MARVELL_MESH_CAPABILITY
;
1201 ie
->val
.mesh_id_len
= priv
->mesh_ssid_len
;
1202 memcpy(ie
->val
.mesh_id
, priv
->mesh_ssid
, priv
->mesh_ssid_len
);
1203 ie
->len
= sizeof(struct mrvl_meshie_val
) -
1204 IW_ESSID_MAX_SIZE
+ priv
->mesh_ssid_len
;
1205 cmd
.length
= cpu_to_le16(sizeof(struct mrvl_meshie_val
));
1207 case CMD_ACT_MESH_CONFIG_STOP
:
1212 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1213 action
, priv
->mesh_tlv
, chan
,
1214 print_ssid(ssid
, priv
->mesh_ssid
, priv
->mesh_ssid_len
));
1216 return __lbs_mesh_config_send(priv
, &cmd
, action
, priv
->mesh_tlv
);
1219 static int lbs_cmd_bcn_ctrl(struct lbs_private
* priv
,
1220 struct cmd_ds_command
*cmd
,
1223 struct cmd_ds_802_11_beacon_control
1224 *bcn_ctrl
= &cmd
->params
.bcn_ctrl
;
1226 lbs_deb_enter(LBS_DEB_CMD
);
1228 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control
)
1230 cmd
->command
= cpu_to_le16(CMD_802_11_BEACON_CTRL
);
1232 bcn_ctrl
->action
= cpu_to_le16(cmd_action
);
1233 bcn_ctrl
->beacon_enable
= cpu_to_le16(priv
->beacon_enable
);
1234 bcn_ctrl
->beacon_period
= cpu_to_le16(priv
->beacon_period
);
1236 lbs_deb_leave(LBS_DEB_CMD
);
1240 static void lbs_queue_cmd(struct lbs_private
*priv
,
1241 struct cmd_ctrl_node
*cmdnode
)
1243 unsigned long flags
;
1246 lbs_deb_enter(LBS_DEB_HOST
);
1249 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
1252 if (!cmdnode
->cmdbuf
->size
) {
1253 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1256 cmdnode
->result
= 0;
1258 /* Exit_PS command needs to be queued in the header always. */
1259 if (le16_to_cpu(cmdnode
->cmdbuf
->command
) == CMD_802_11_PS_MODE
) {
1260 struct cmd_ds_802_11_ps_mode
*psm
= (void *) &cmdnode
->cmdbuf
[1];
1262 if (psm
->action
== cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
1263 if (priv
->psstate
!= PS_STATE_FULL_POWER
)
1268 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1271 list_add_tail(&cmdnode
->list
, &priv
->cmdpendingq
);
1273 list_add(&cmdnode
->list
, &priv
->cmdpendingq
);
1275 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1277 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
1278 le16_to_cpu(cmdnode
->cmdbuf
->command
));
1281 lbs_deb_leave(LBS_DEB_HOST
);
1284 static void lbs_submit_command(struct lbs_private
*priv
,
1285 struct cmd_ctrl_node
*cmdnode
)
1287 unsigned long flags
;
1288 struct cmd_header
*cmd
;
1294 lbs_deb_enter(LBS_DEB_HOST
);
1296 cmd
= cmdnode
->cmdbuf
;
1298 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1299 priv
->cur_cmd
= cmdnode
;
1300 priv
->cur_cmd_retcode
= 0;
1301 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1303 cmdsize
= le16_to_cpu(cmd
->size
);
1304 command
= le16_to_cpu(cmd
->command
);
1306 /* These commands take longer */
1307 if (command
== CMD_802_11_SCAN
|| command
== CMD_802_11_ASSOCIATE
)
1310 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1311 command
, le16_to_cpu(cmd
->seqnum
), cmdsize
);
1312 lbs_deb_hex(LBS_DEB_CMD
, "DNLD_CMD", (void *) cmdnode
->cmdbuf
, cmdsize
);
1314 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) cmd
, cmdsize
);
1317 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret
);
1318 /* Let the timer kick in and retry, and potentially reset
1319 the whole thing if the condition persists */
1323 if (command
== CMD_802_11_DEEP_SLEEP
) {
1324 if (priv
->is_auto_deep_sleep_enabled
) {
1325 priv
->wakeup_dev_required
= 1;
1326 priv
->dnld_sent
= 0;
1328 priv
->is_deep_sleep
= 1;
1329 lbs_complete_command(priv
, cmdnode
, 0);
1331 /* Setup the timer after transmit command */
1332 mod_timer(&priv
->command_timer
, jiffies
+ timeo
);
1335 lbs_deb_leave(LBS_DEB_HOST
);
1339 * This function inserts command node to cmdfreeq
1340 * after cleans it. Requires priv->driver_lock held.
1342 static void __lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
1343 struct cmd_ctrl_node
*cmdnode
)
1345 lbs_deb_enter(LBS_DEB_HOST
);
1350 cmdnode
->callback
= NULL
;
1351 cmdnode
->callback_arg
= 0;
1353 memset(cmdnode
->cmdbuf
, 0, LBS_CMD_BUFFER_SIZE
);
1355 list_add_tail(&cmdnode
->list
, &priv
->cmdfreeq
);
1357 lbs_deb_leave(LBS_DEB_HOST
);
1360 static void lbs_cleanup_and_insert_cmd(struct lbs_private
*priv
,
1361 struct cmd_ctrl_node
*ptempcmd
)
1363 unsigned long flags
;
1365 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1366 __lbs_cleanup_and_insert_cmd(priv
, ptempcmd
);
1367 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1370 void lbs_complete_command(struct lbs_private
*priv
, struct cmd_ctrl_node
*cmd
,
1373 if (cmd
== priv
->cur_cmd
)
1374 priv
->cur_cmd_retcode
= result
;
1376 cmd
->result
= result
;
1377 cmd
->cmdwaitqwoken
= 1;
1378 wake_up_interruptible(&cmd
->cmdwait_q
);
1380 if (!cmd
->callback
|| cmd
->callback
== lbs_cmd_async_callback
)
1381 __lbs_cleanup_and_insert_cmd(priv
, cmd
);
1382 priv
->cur_cmd
= NULL
;
1385 int lbs_set_radio(struct lbs_private
*priv
, u8 preamble
, u8 radio_on
)
1387 struct cmd_ds_802_11_radio_control cmd
;
1390 lbs_deb_enter(LBS_DEB_CMD
);
1392 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1393 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
1395 /* Only v8 and below support setting the preamble */
1396 if (priv
->fwrelease
< 0x09000000) {
1398 case RADIO_PREAMBLE_SHORT
:
1399 if (!(priv
->capability
& WLAN_CAPABILITY_SHORT_PREAMBLE
))
1402 case RADIO_PREAMBLE_AUTO
:
1403 case RADIO_PREAMBLE_LONG
:
1404 cmd
.control
= cpu_to_le16(preamble
);
1412 cmd
.control
|= cpu_to_le16(0x1);
1414 cmd
.control
&= cpu_to_le16(~0x1);
1415 priv
->txpower_cur
= 0;
1418 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1419 radio_on
? "ON" : "OFF", preamble
);
1421 priv
->radio_on
= radio_on
;
1423 ret
= lbs_cmd_with_response(priv
, CMD_802_11_RADIO_CONTROL
, &cmd
);
1426 lbs_deb_leave_args(LBS_DEB_CMD
, "ret %d", ret
);
1430 void lbs_set_mac_control(struct lbs_private
*priv
)
1432 struct cmd_ds_mac_control cmd
;
1434 lbs_deb_enter(LBS_DEB_CMD
);
1436 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
1437 cmd
.action
= cpu_to_le16(priv
->mac_control
);
1440 lbs_cmd_async(priv
, CMD_MAC_CONTROL
, &cmd
.hdr
, sizeof(cmd
));
1442 lbs_deb_leave(LBS_DEB_CMD
);
1446 * @brief This function prepare the command before send to firmware.
1448 * @param priv A pointer to struct lbs_private structure
1449 * @param cmd_no command number
1450 * @param cmd_action command action: GET or SET
1451 * @param wait_option wait option: wait response or not
1452 * @param cmd_oid cmd oid: treated as sub command
1453 * @param pdata_buf A pointer to informaion buffer
1456 int lbs_prepare_and_send_command(struct lbs_private
*priv
,
1459 u16 wait_option
, u32 cmd_oid
, void *pdata_buf
)
1462 struct cmd_ctrl_node
*cmdnode
;
1463 struct cmd_ds_command
*cmdptr
;
1464 unsigned long flags
;
1466 lbs_deb_enter(LBS_DEB_HOST
);
1469 lbs_deb_host("PREP_CMD: priv is NULL\n");
1474 if (priv
->surpriseremoved
) {
1475 lbs_deb_host("PREP_CMD: card removed\n");
1480 if (!lbs_is_cmd_allowed(priv
)) {
1485 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
1487 if (cmdnode
== NULL
) {
1488 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
1490 /* Wake up main thread to execute next command */
1491 wake_up_interruptible(&priv
->waitq
);
1496 cmdnode
->callback
= NULL
;
1497 cmdnode
->callback_arg
= (unsigned long)pdata_buf
;
1499 cmdptr
= (struct cmd_ds_command
*)cmdnode
->cmdbuf
;
1501 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no
);
1503 /* Set sequence number, command and INT option */
1505 cmdptr
->seqnum
= cpu_to_le16(priv
->seqnum
);
1507 cmdptr
->command
= cpu_to_le16(cmd_no
);
1511 case CMD_802_11_PS_MODE
:
1512 ret
= lbs_cmd_802_11_ps_mode(cmdptr
, cmd_action
);
1515 case CMD_MAC_REG_ACCESS
:
1516 case CMD_BBP_REG_ACCESS
:
1517 case CMD_RF_REG_ACCESS
:
1518 ret
= lbs_cmd_reg_access(cmdptr
, cmd_action
, pdata_buf
);
1521 case CMD_802_11_MONITOR_MODE
:
1522 ret
= lbs_cmd_802_11_monitor_mode(cmdptr
,
1523 cmd_action
, pdata_buf
);
1526 case CMD_802_11_RSSI
:
1527 ret
= lbs_cmd_802_11_rssi(priv
, cmdptr
);
1530 case CMD_802_11_SET_AFC
:
1531 case CMD_802_11_GET_AFC
:
1533 cmdptr
->command
= cpu_to_le16(cmd_no
);
1534 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_802_11_afc
) +
1537 memmove(&cmdptr
->params
.afc
,
1538 pdata_buf
, sizeof(struct cmd_ds_802_11_afc
));
1543 case CMD_802_11D_DOMAIN_INFO
:
1544 ret
= lbs_cmd_802_11d_domain_info(priv
, cmdptr
,
1545 cmd_no
, cmd_action
);
1548 case CMD_802_11_TPC_CFG
:
1549 cmdptr
->command
= cpu_to_le16(CMD_802_11_TPC_CFG
);
1551 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg
) +
1554 memmove(&cmdptr
->params
.tpccfg
,
1555 pdata_buf
, sizeof(struct cmd_ds_802_11_tpc_cfg
));
1559 case CMD_802_11_LED_GPIO_CTRL
:
1561 struct mrvl_ie_ledgpio
*gpio
=
1562 (struct mrvl_ie_ledgpio
*)
1563 cmdptr
->params
.ledgpio
.data
;
1565 memmove(&cmdptr
->params
.ledgpio
,
1567 sizeof(struct cmd_ds_802_11_led_ctrl
));
1570 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL
);
1572 #define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1574 cpu_to_le16(le16_to_cpu(gpio
->header
.len
)
1576 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN
);
1577 gpio
->header
.len
= gpio
->header
.len
;
1584 ret
= lbs_cmd_bt_access(cmdptr
, cmd_action
, pdata_buf
);
1587 case CMD_FWT_ACCESS
:
1588 ret
= lbs_cmd_fwt_access(cmdptr
, cmd_action
, pdata_buf
);
1592 cmdptr
->command
= cpu_to_le16(CMD_GET_TSF
);
1593 cmdptr
->size
= cpu_to_le16(sizeof(struct cmd_ds_get_tsf
) +
1597 case CMD_802_11_BEACON_CTRL
:
1598 ret
= lbs_cmd_bcn_ctrl(priv
, cmdptr
, cmd_action
);
1600 case CMD_802_11_DEEP_SLEEP
:
1601 cmdptr
->command
= cpu_to_le16(CMD_802_11_DEEP_SLEEP
);
1602 cmdptr
->size
= cpu_to_le16(S_DS_GEN
);
1605 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no
);
1610 /* return error, since the command preparation failed */
1612 lbs_deb_host("PREP_CMD: command preparation failed\n");
1613 lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
1618 cmdnode
->cmdwaitqwoken
= 0;
1620 lbs_queue_cmd(priv
, cmdnode
);
1621 wake_up_interruptible(&priv
->waitq
);
1623 if (wait_option
& CMD_OPTION_WAITFORRSP
) {
1624 lbs_deb_host("PREP_CMD: wait for response\n");
1626 wait_event_interruptible(cmdnode
->cmdwait_q
,
1627 cmdnode
->cmdwaitqwoken
);
1630 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1631 if (priv
->cur_cmd_retcode
) {
1632 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
1633 priv
->cur_cmd_retcode
);
1634 priv
->cur_cmd_retcode
= 0;
1637 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1640 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1645 * @brief This function allocates the command buffer and link
1646 * it to command free queue.
1648 * @param priv A pointer to struct lbs_private structure
1651 int lbs_allocate_cmd_buffer(struct lbs_private
*priv
)
1656 struct cmd_ctrl_node
*cmdarray
;
1658 lbs_deb_enter(LBS_DEB_HOST
);
1660 /* Allocate and initialize the command array */
1661 bufsize
= sizeof(struct cmd_ctrl_node
) * LBS_NUM_CMD_BUFFERS
;
1662 if (!(cmdarray
= kzalloc(bufsize
, GFP_KERNEL
))) {
1663 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
1667 priv
->cmd_array
= cmdarray
;
1669 /* Allocate and initialize each command buffer in the command array */
1670 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1671 cmdarray
[i
].cmdbuf
= kzalloc(LBS_CMD_BUFFER_SIZE
, GFP_KERNEL
);
1672 if (!cmdarray
[i
].cmdbuf
) {
1673 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
1679 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1680 init_waitqueue_head(&cmdarray
[i
].cmdwait_q
);
1681 lbs_cleanup_and_insert_cmd(priv
, &cmdarray
[i
]);
1686 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
1691 * @brief This function frees the command buffer.
1693 * @param priv A pointer to struct lbs_private structure
1696 int lbs_free_cmd_buffer(struct lbs_private
*priv
)
1698 struct cmd_ctrl_node
*cmdarray
;
1701 lbs_deb_enter(LBS_DEB_HOST
);
1703 /* need to check if cmd array is allocated or not */
1704 if (priv
->cmd_array
== NULL
) {
1705 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
1709 cmdarray
= priv
->cmd_array
;
1711 /* Release shared memory buffers */
1712 for (i
= 0; i
< LBS_NUM_CMD_BUFFERS
; i
++) {
1713 if (cmdarray
[i
].cmdbuf
) {
1714 kfree(cmdarray
[i
].cmdbuf
);
1715 cmdarray
[i
].cmdbuf
= NULL
;
1719 /* Release cmd_ctrl_node */
1720 if (priv
->cmd_array
) {
1721 kfree(priv
->cmd_array
);
1722 priv
->cmd_array
= NULL
;
1726 lbs_deb_leave(LBS_DEB_HOST
);
1731 * @brief This function gets a free command node if available in
1732 * command free queue.
1734 * @param priv A pointer to struct lbs_private structure
1735 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1737 static struct cmd_ctrl_node
*lbs_get_cmd_ctrl_node(struct lbs_private
*priv
)
1739 struct cmd_ctrl_node
*tempnode
;
1740 unsigned long flags
;
1742 lbs_deb_enter(LBS_DEB_HOST
);
1747 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1749 if (!list_empty(&priv
->cmdfreeq
)) {
1750 tempnode
= list_first_entry(&priv
->cmdfreeq
,
1751 struct cmd_ctrl_node
, list
);
1752 list_del(&tempnode
->list
);
1754 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
1758 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1760 lbs_deb_leave(LBS_DEB_HOST
);
1765 * @brief This function executes next command in command
1766 * pending queue. It will put firmware back to PS mode
1769 * @param priv A pointer to struct lbs_private structure
1772 int lbs_execute_next_command(struct lbs_private
*priv
)
1774 struct cmd_ctrl_node
*cmdnode
= NULL
;
1775 struct cmd_header
*cmd
;
1776 unsigned long flags
;
1779 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1780 * only caller to us is lbs_thread() and we get even when a
1781 * data packet is received */
1782 lbs_deb_enter(LBS_DEB_THREAD
);
1784 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1786 if (priv
->cur_cmd
) {
1787 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
1788 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1793 if (!list_empty(&priv
->cmdpendingq
)) {
1794 cmdnode
= list_first_entry(&priv
->cmdpendingq
,
1795 struct cmd_ctrl_node
, list
);
1798 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1801 cmd
= cmdnode
->cmdbuf
;
1803 if (is_command_allowed_in_ps(le16_to_cpu(cmd
->command
))) {
1804 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1805 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1807 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
1808 le16_to_cpu(cmd
->command
),
1813 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
1814 "0x%04x in psstate %d\n",
1815 le16_to_cpu(cmd
->command
), priv
->psstate
);
1816 } else if (priv
->psstate
!= PS_STATE_FULL_POWER
) {
1818 * 1. Non-PS command:
1819 * Queue it. set needtowakeup to TRUE if current state
1820 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
1821 * 2. PS command but not Exit_PS:
1823 * 3. PS command Exit_PS:
1824 * Set needtowakeup to TRUE if current state is SLEEP,
1825 * otherwise send this command down to firmware
1828 if (cmd
->command
!= cpu_to_le16(CMD_802_11_PS_MODE
)) {
1829 /* Prepare to send Exit PS,
1830 * this non PS command will be sent later */
1831 if ((priv
->psstate
== PS_STATE_SLEEP
)
1832 || (priv
->psstate
== PS_STATE_PRE_SLEEP
)
1834 /* w/ new scheme, it will not reach here.
1835 since it is blocked in main_thread. */
1836 priv
->needtowakeup
= 1;
1838 lbs_ps_wakeup(priv
, 0);
1844 * PS command. Ignore it if it is not Exit_PS.
1845 * otherwise send it down immediately.
1847 struct cmd_ds_802_11_ps_mode
*psm
= (void *)&cmd
[1];
1850 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
1853 cpu_to_le16(CMD_SUBCMD_EXIT_PS
)) {
1855 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
1856 list_del(&cmdnode
->list
);
1857 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1858 lbs_complete_command(priv
, cmdnode
, 0);
1859 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1865 if ((priv
->psstate
== PS_STATE_SLEEP
) ||
1866 (priv
->psstate
== PS_STATE_PRE_SLEEP
)) {
1868 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
1869 list_del(&cmdnode
->list
);
1870 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1871 lbs_complete_command(priv
, cmdnode
, 0);
1872 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1873 priv
->needtowakeup
= 1;
1880 "EXEC_NEXT_CMD: sending EXIT_PS\n");
1883 list_del(&cmdnode
->list
);
1884 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
1885 le16_to_cpu(cmd
->command
));
1886 lbs_submit_command(priv
, cmdnode
);
1889 * check if in power save mode, if yes, put the device back
1892 if ((priv
->psmode
!= LBS802_11POWERMODECAM
) &&
1893 (priv
->psstate
== PS_STATE_FULL_POWER
) &&
1894 ((priv
->connect_status
== LBS_CONNECTED
) ||
1895 (priv
->mesh_connect_status
== LBS_CONNECTED
))) {
1896 if (priv
->secinfo
.WPAenabled
||
1897 priv
->secinfo
.WPA2enabled
) {
1898 /* check for valid WPA group keys */
1899 if (priv
->wpa_mcast_key
.len
||
1900 priv
->wpa_unicast_key
.len
) {
1902 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1903 " go back to PS_SLEEP");
1904 lbs_ps_sleep(priv
, 0);
1908 "EXEC_NEXT_CMD: cmdpendingq empty, "
1909 "go back to PS_SLEEP");
1910 lbs_ps_sleep(priv
, 0);
1917 lbs_deb_leave(LBS_DEB_THREAD
);
1921 void lbs_send_iwevcustom_event(struct lbs_private
*priv
, s8
*str
)
1923 union iwreq_data iwrq
;
1926 lbs_deb_enter(LBS_DEB_WEXT
);
1928 memset(&iwrq
, 0, sizeof(union iwreq_data
));
1929 memset(buf
, 0, sizeof(buf
));
1931 snprintf(buf
, sizeof(buf
) - 1, "%s", str
);
1933 iwrq
.data
.length
= strlen(buf
) + 1 + IW_EV_LCP_LEN
;
1935 /* Send Event to upper layer */
1936 lbs_deb_wext("event indication string %s\n", (char *)buf
);
1937 lbs_deb_wext("event indication length %d\n", iwrq
.data
.length
);
1938 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str
);
1940 wireless_send_event(priv
->dev
, IWEVCUSTOM
, &iwrq
, buf
);
1942 lbs_deb_leave(LBS_DEB_WEXT
);
1945 static void lbs_send_confirmsleep(struct lbs_private
*priv
)
1947 unsigned long flags
;
1950 lbs_deb_enter(LBS_DEB_HOST
);
1951 lbs_deb_hex(LBS_DEB_HOST
, "sleep confirm", (u8
*) &confirm_sleep
,
1952 sizeof(confirm_sleep
));
1954 ret
= priv
->hw_host_to_card(priv
, MVMS_CMD
, (u8
*) &confirm_sleep
,
1955 sizeof(confirm_sleep
));
1957 lbs_pr_alert("confirm_sleep failed\n");
1961 spin_lock_irqsave(&priv
->driver_lock
, flags
);
1963 /* We don't get a response on the sleep-confirmation */
1964 priv
->dnld_sent
= DNLD_RES_RECEIVED
;
1966 /* If nothing to do, go back to sleep (?) */
1967 if (!__kfifo_len(priv
->event_fifo
) && !priv
->resp_len
[priv
->resp_idx
])
1968 priv
->psstate
= PS_STATE_SLEEP
;
1970 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
1973 lbs_deb_leave(LBS_DEB_HOST
);
1976 void lbs_ps_sleep(struct lbs_private
*priv
, int wait_option
)
1978 lbs_deb_enter(LBS_DEB_HOST
);
1981 * PS is currently supported only in Infrastructure mode
1982 * Remove this check if it is to be supported in IBSS mode also
1985 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
1986 CMD_SUBCMD_ENTER_PS
, wait_option
, 0, NULL
);
1988 lbs_deb_leave(LBS_DEB_HOST
);
1992 * @brief This function sends Exit_PS command to firmware.
1994 * @param priv A pointer to struct lbs_private structure
1995 * @param wait_option wait response or not
1998 void lbs_ps_wakeup(struct lbs_private
*priv
, int wait_option
)
2002 lbs_deb_enter(LBS_DEB_HOST
);
2004 Localpsmode
= cpu_to_le32(LBS802_11POWERMODECAM
);
2006 lbs_prepare_and_send_command(priv
, CMD_802_11_PS_MODE
,
2008 wait_option
, 0, &Localpsmode
);
2010 lbs_deb_leave(LBS_DEB_HOST
);
2014 * @brief This function checks condition and prepares to
2015 * send sleep confirm command to firmware if ok.
2017 * @param priv A pointer to struct lbs_private structure
2018 * @param psmode Power Saving mode
2021 void lbs_ps_confirm_sleep(struct lbs_private
*priv
)
2023 unsigned long flags
=0;
2026 lbs_deb_enter(LBS_DEB_HOST
);
2028 spin_lock_irqsave(&priv
->driver_lock
, flags
);
2029 if (priv
->dnld_sent
) {
2031 lbs_deb_host("dnld_sent was set\n");
2034 /* In-progress command? */
2035 if (priv
->cur_cmd
) {
2037 lbs_deb_host("cur_cmd was set\n");
2040 /* Pending events or command responses? */
2041 if (__kfifo_len(priv
->event_fifo
) || priv
->resp_len
[priv
->resp_idx
]) {
2043 lbs_deb_host("pending events or command responses\n");
2045 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
2048 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
2049 lbs_send_confirmsleep(priv
);
2051 lbs_deb_host("sleep confirm has been delayed\n");
2054 lbs_deb_leave(LBS_DEB_HOST
);
2059 * @brief Configures the transmission power control functionality.
2061 * @param priv A pointer to struct lbs_private structure
2062 * @param enable Transmission power control enable
2063 * @param p0 Power level when link quality is good (dBm).
2064 * @param p1 Power level when link quality is fair (dBm).
2065 * @param p2 Power level when link quality is poor (dBm).
2066 * @param usesnr Use Signal to Noise Ratio in TPC
2068 * @return 0 on success
2070 int lbs_set_tpc_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
, int8_t p1
,
2071 int8_t p2
, int usesnr
)
2073 struct cmd_ds_802_11_tpc_cfg cmd
;
2076 memset(&cmd
, 0, sizeof(cmd
));
2077 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
2078 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
2079 cmd
.enable
= !!enable
;
2080 cmd
.usesnr
= !!usesnr
;
2085 ret
= lbs_cmd_with_response(priv
, CMD_802_11_TPC_CFG
, &cmd
);
2091 * @brief Configures the power adaptation settings.
2093 * @param priv A pointer to struct lbs_private structure
2094 * @param enable Power adaptation enable
2095 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2096 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2097 * @param p2 Power level for 48 and 54 Mbps (dBm).
2099 * @return 0 on Success
2102 int lbs_set_power_adapt_cfg(struct lbs_private
*priv
, int enable
, int8_t p0
,
2103 int8_t p1
, int8_t p2
)
2105 struct cmd_ds_802_11_pa_cfg cmd
;
2108 memset(&cmd
, 0, sizeof(cmd
));
2109 cmd
.hdr
.size
= cpu_to_le16(sizeof(cmd
));
2110 cmd
.action
= cpu_to_le16(CMD_ACT_SET
);
2111 cmd
.enable
= !!enable
;
2116 ret
= lbs_cmd_with_response(priv
, CMD_802_11_PA_CFG
, &cmd
);
2122 static struct cmd_ctrl_node
*__lbs_cmd_async(struct lbs_private
*priv
,
2123 uint16_t command
, struct cmd_header
*in_cmd
, int in_cmd_size
,
2124 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
2125 unsigned long callback_arg
)
2127 struct cmd_ctrl_node
*cmdnode
;
2129 lbs_deb_enter(LBS_DEB_HOST
);
2131 if (priv
->surpriseremoved
) {
2132 lbs_deb_host("PREP_CMD: card removed\n");
2133 cmdnode
= ERR_PTR(-ENOENT
);
2137 if (!lbs_is_cmd_allowed(priv
)) {
2138 cmdnode
= ERR_PTR(-EBUSY
);
2142 cmdnode
= lbs_get_cmd_ctrl_node(priv
);
2143 if (cmdnode
== NULL
) {
2144 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2146 /* Wake up main thread to execute next command */
2147 wake_up_interruptible(&priv
->waitq
);
2148 cmdnode
= ERR_PTR(-ENOBUFS
);
2152 cmdnode
->callback
= callback
;
2153 cmdnode
->callback_arg
= callback_arg
;
2155 /* Copy the incoming command to the buffer */
2156 memcpy(cmdnode
->cmdbuf
, in_cmd
, in_cmd_size
);
2158 /* Set sequence number, clean result, move to buffer */
2160 cmdnode
->cmdbuf
->command
= cpu_to_le16(command
);
2161 cmdnode
->cmdbuf
->size
= cpu_to_le16(in_cmd_size
);
2162 cmdnode
->cmdbuf
->seqnum
= cpu_to_le16(priv
->seqnum
);
2163 cmdnode
->cmdbuf
->result
= 0;
2165 lbs_deb_host("PREP_CMD: command 0x%04x\n", command
);
2167 cmdnode
->cmdwaitqwoken
= 0;
2168 lbs_queue_cmd(priv
, cmdnode
);
2169 wake_up_interruptible(&priv
->waitq
);
2172 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %p", cmdnode
);
2176 void lbs_cmd_async(struct lbs_private
*priv
, uint16_t command
,
2177 struct cmd_header
*in_cmd
, int in_cmd_size
)
2179 lbs_deb_enter(LBS_DEB_CMD
);
2180 __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
2181 lbs_cmd_async_callback
, 0);
2182 lbs_deb_leave(LBS_DEB_CMD
);
2185 int __lbs_cmd(struct lbs_private
*priv
, uint16_t command
,
2186 struct cmd_header
*in_cmd
, int in_cmd_size
,
2187 int (*callback
)(struct lbs_private
*, unsigned long, struct cmd_header
*),
2188 unsigned long callback_arg
)
2190 struct cmd_ctrl_node
*cmdnode
;
2191 unsigned long flags
;
2194 lbs_deb_enter(LBS_DEB_HOST
);
2196 cmdnode
= __lbs_cmd_async(priv
, command
, in_cmd
, in_cmd_size
,
2197 callback
, callback_arg
);
2198 if (IS_ERR(cmdnode
)) {
2199 ret
= PTR_ERR(cmdnode
);
2204 wait_event_interruptible(cmdnode
->cmdwait_q
, cmdnode
->cmdwaitqwoken
);
2206 spin_lock_irqsave(&priv
->driver_lock
, flags
);
2207 ret
= cmdnode
->result
;
2209 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2212 __lbs_cleanup_and_insert_cmd(priv
, cmdnode
);
2213 spin_unlock_irqrestore(&priv
->driver_lock
, flags
);
2216 lbs_deb_leave_args(LBS_DEB_HOST
, "ret %d", ret
);
2219 EXPORT_SYMBOL_GPL(__lbs_cmd
);