blob: 8c3605cdc64c090de61dd4fdd98e3cb23b9c4d6a [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
6#include <net/iw_handler.h>
John W. Linville7e272fc2008-09-24 18:13:14 -04007#include <net/lib80211.h>
Holger Schurig7919b892008-04-01 14:50:43 +02008#include <linux/kfifo.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02009#include "host.h"
10#include "hostcmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020011#include "decl.h"
12#include "defs.h"
13#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020014#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020015#include "wext.h"
Dan Williams6e66f032007-12-11 12:42:16 -050016#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020017
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050018static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010019
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020020
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010022 * @brief Simple callback that copies response back into command
23 *
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
28 *
29 * @return 0 on success, error on failure
30 */
31int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
32 struct cmd_header *resp)
33{
34 struct cmd_header *buf = (void *)extra;
35 uint16_t copy_len;
36
37 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
38 memcpy(buf, resp, copy_len);
39 return 0;
40}
41EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
42
43/**
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.
47 *
48 * @param priv ignored
49 * @param extra ignored
50 * @param resp ignored
51 *
52 * @return 0 for success
53 */
54static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
55 struct cmd_header *resp)
56{
57 return 0;
58}
59
60
61/**
Dan Williams852e1f22007-12-10 15:24:47 -050062 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020063 *
64 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050065 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020066 */
Dan Williams852e1f22007-12-10 15:24:47 -050067static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020068{
Dan Williams852e1f22007-12-10 15:24:47 -050069 switch (cmd) {
70 case CMD_802_11_RSSI:
71 return 1;
72 default:
73 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020074 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 return 0;
76}
77
Dan Williams6e66f032007-12-11 12:42:16 -050078/**
79 * @brief Updates the hardware details like MAC address and regulatory region
80 *
81 * @param priv A pointer to struct lbs_private structure
82 *
83 * @return 0 on success, error on failure
84 */
85int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020086{
Dan Williams6e66f032007-12-11 12:42:16 -050087 struct cmd_ds_get_hw_spec cmd;
88 int ret = -1;
89 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020090
Holger Schurig9012b282007-05-25 11:27:16 -040091 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020092
Dan Williams6e66f032007-12-11 12:42:16 -050093 memset(&cmd, 0, sizeof(cmd));
94 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
95 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050096 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050097 if (ret)
98 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020099
Dan Williams6e66f032007-12-11 12:42:16 -0500100 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500101
Holger Schurigdac10a92008-01-16 15:55:22 +0100102 /* The firmware release is in an interesting format: the patch
103 * level is in the most significant nibble ... so fix that: */
104 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
105 priv->fwrelease = (priv->fwrelease << 8) |
106 (priv->fwrelease >> 24 & 0xff);
107
108 /* Some firmware capabilities:
109 * CF card firmware 5.0.16p0: cap 0x00000303
110 * USB dongle firmware 5.110.17p2: cap 0x00000303
111 */
Johannes Berge1749612008-10-27 15:59:26 -0700112 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
113 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100114 priv->fwrelease >> 24 & 0xff,
115 priv->fwrelease >> 16 & 0xff,
116 priv->fwrelease >> 8 & 0xff,
117 priv->fwrelease & 0xff,
118 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500119 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
120 cmd.hwifversion, cmd.version);
121
122 /* Clamp region code to 8-bit since FW spec indicates that it should
123 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
124 * returns non-zero high 8 bits here.
125 */
126 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
127
128 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
129 /* use the region code to search for the index */
130 if (priv->regioncode == lbs_region_code_to_index[i])
131 break;
132 }
133
134 /* if it's unidentified region code, use the default (USA) */
135 if (i >= MRVDRV_MAX_REGION_CODE) {
136 priv->regioncode = 0x10;
137 lbs_pr_info("unidentified region code; using the default (USA)\n");
138 }
139
140 if (priv->current_addr[0] == 0xff)
141 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
142
143 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
144 if (priv->mesh_dev)
145 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
146
147 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
148 ret = -1;
149 goto out;
150 }
151
152 if (lbs_set_universaltable(priv, 0)) {
153 ret = -1;
154 goto out;
155 }
156
157out:
Holger Schurig9012b282007-05-25 11:27:16 -0400158 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500159 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200160}
161
Anna Neal582c1b52008-10-20 16:46:56 -0700162int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
163 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500164{
165 struct cmd_ds_host_sleep cmd_config;
166 int ret;
167
David Woodhouse9fae8992007-12-15 03:46:44 -0500168 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500169 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500170 cmd_config.gpio = priv->wol_gpio;
171 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500172
Anna Neal582c1b52008-10-20 16:46:56 -0700173 if (p_wol_config != NULL)
174 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
175 sizeof(struct wol_config));
176 else
177 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
178
David Woodhouse689442d2007-12-12 16:00:42 -0500179 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500180 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700181 if (criteria) {
182 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
183 priv->wol_criteria = criteria;
184 } else
185 memcpy((uint8_t *) p_wol_config,
186 (uint8_t *)&cmd_config.wol_conf,
187 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500188 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500189 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500190 }
David Woodhouse506e9022007-12-12 20:06:06 -0500191
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500192 return ret;
193}
194EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
195
Holger Schurige98a88d2008-03-19 14:25:58 +0100196static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200197 u16 cmd_action)
198{
199 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200200
Holger Schurig9012b282007-05-25 11:27:16 -0400201 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202
Dan Williams0aef64d2007-08-02 11:31:18 -0400203 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400204 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
205 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200206 psm->action = cpu_to_le16(cmd_action);
207 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400208 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400209 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400210 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200211
Holger Schurig252cf0d2007-08-02 13:09:34 -0400212 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400213 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200214 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400215 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200216 break;
217
Dan Williams0aef64d2007-08-02 11:31:18 -0400218 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400219 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220 break;
221
Dan Williams0aef64d2007-08-02 11:31:18 -0400222 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400223 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224 break;
225
226 default:
227 break;
228 }
229
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231 return 0;
232}
233
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500234int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
235 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500237 struct cmd_ds_802_11_inactivity_timeout cmd;
238 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
Holger Schurig8ff12da2007-08-02 11:54:31 -0400240 lbs_deb_enter(LBS_DEB_CMD);
241
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500242 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
243 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500245 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500247 if (cmd_action == CMD_ACT_SET)
248 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200249 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500250 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500252 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
253
254 if (!ret)
255 *timeout = le16_to_cpu(cmd.timeout);
256
257 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200258 return 0;
259}
260
David Woodhouse3fbe1042007-12-17 23:48:31 -0500261int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
262 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200263{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500264 struct cmd_ds_802_11_sleep_params cmd;
265 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266
Holger Schurig9012b282007-05-25 11:27:16 -0400267 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200268
Dan Williams0aef64d2007-08-02 11:31:18 -0400269 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500270 memset(&cmd, 0, sizeof(cmd));
271 } else {
272 cmd.error = cpu_to_le16(sp->sp_error);
273 cmd.offset = cpu_to_le16(sp->sp_offset);
274 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
275 cmd.calcontrol = sp->sp_calcontrol;
276 cmd.externalsleepclk = sp->sp_extsleepclk;
277 cmd.reserved = cpu_to_le16(sp->sp_reserved);
278 }
279 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
280 cmd.action = cpu_to_le16(cmd_action);
281
282 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
283
284 if (!ret) {
285 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
286 "calcontrol 0x%x extsleepclk 0x%x\n",
287 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
288 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
289 cmd.externalsleepclk);
290
291 sp->sp_error = le16_to_cpu(cmd.error);
292 sp->sp_offset = le16_to_cpu(cmd.offset);
293 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
294 sp->sp_calcontrol = cmd.calcontrol;
295 sp->sp_extsleepclk = cmd.externalsleepclk;
296 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200297 }
298
David Woodhouse3fbe1042007-12-17 23:48:31 -0500299 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200300 return 0;
301}
302
David Woodhousef70dd452007-12-18 00:18:05 -0500303int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
304 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200305{
David Woodhousef70dd452007-12-18 00:18:05 -0500306 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200307 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308
Holger Schurig9012b282007-05-25 11:27:16 -0400309 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200310
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200311 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500312 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
313 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200314
David Woodhousef70dd452007-12-18 00:18:05 -0500315 cmd.action = cpu_to_le16(cmd_action);
316
317 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200318 int i;
319
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500321 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
322 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200323
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200324 /* Copy key types and material to host command structure */
325 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500326 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327
328 switch (pkey->len) {
329 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500330 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
331 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400332 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200333 break;
334 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500335 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
336 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400337 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 break;
339 case 0:
340 break;
341 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400342 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500343 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 ret = -1;
345 goto done;
346 break;
347 }
348 }
David Woodhousef70dd452007-12-18 00:18:05 -0500349 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200350 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200351
352 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500353 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
354 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000355 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200356 }
357
David Woodhousef70dd452007-12-18 00:18:05 -0500358 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359done:
Holger Schurig9012b282007-05-25 11:27:16 -0400360 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200361 return ret;
362}
363
David Woodhouse4f59abf2007-12-18 00:47:17 -0500364int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
365 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200366{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500367 struct cmd_ds_802_11_enable_rsn cmd;
368 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400369
370 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
David Woodhouse4f59abf2007-12-18 00:47:17 -0500372 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
373 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400374
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200375 if (cmd_action == CMD_ACT_GET)
376 cmd.enable = 0;
377 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400378 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500379 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400380 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500381 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400382 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383 }
384
David Woodhouse4f59abf2007-12-18 00:47:17 -0500385 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
386 if (!ret && cmd_action == CMD_ACT_GET)
387 *enable = le16_to_cpu(cmd.enable);
388
389 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
390 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391}
392
David Woodhouse9e1228d2008-03-03 12:15:39 +0100393static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
394 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200395{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400396 lbs_deb_enter(LBS_DEB_CMD);
397
David Woodhouse9e1228d2008-03-03 12:15:39 +0100398 if (key->flags & KEY_INFO_WPA_ENABLED)
399 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
400 if (key->flags & KEY_INFO_WPA_UNICAST)
401 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
402 if (key->flags & KEY_INFO_WPA_MCAST)
403 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200404
David Woodhouse9e1228d2008-03-03 12:15:39 +0100405 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
406 keyparam->keytypeid = cpu_to_le16(key->type);
407 keyparam->keylen = cpu_to_le16(key->len);
408 memcpy(keyparam->key, key->key, key->len);
409
410 /* Length field doesn't include the {type,length} header */
411 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400412 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200413}
414
David Woodhouse9e1228d2008-03-03 12:15:39 +0100415int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
416 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200417{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100418 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200419 int ret = 0;
420 int index = 0;
421
Holger Schurig9012b282007-05-25 11:27:16 -0400422 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200423
David Woodhouse9e1228d2008-03-03 12:15:39 +0100424 cmd.action = cpu_to_le16(cmd_action);
425 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200426
Dan Williams0aef64d2007-08-02 11:31:18 -0400427 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100428 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
429 } else {
430 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
431
432 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
433 set_one_wpa_key(&cmd.keyParamSet[index],
434 &assoc->wpa_unicast_key);
435 index++;
436 }
437
438 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
439 set_one_wpa_key(&cmd.keyParamSet[index],
440 &assoc->wpa_mcast_key);
441 index++;
442 }
443
444 /* The common header and as many keys as we included */
445 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
446 keyParamSet[index]));
447 }
448 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
449 /* Copy the returned key to driver private data */
450 if (!ret && cmd_action == CMD_ACT_GET) {
451 void *buf_ptr = cmd.keyParamSet;
452 void *resp_end = &(&cmd)[1];
453
454 while (buf_ptr < resp_end) {
455 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
456 struct enc_key *key;
457 uint16_t param_set_len = le16_to_cpu(keyparam->length);
458 uint16_t key_len = le16_to_cpu(keyparam->keylen);
459 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
460 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
461 void *end;
462
463 end = (void *)keyparam + sizeof(keyparam->type)
464 + sizeof(keyparam->length) + param_set_len;
465
466 /* Make sure we don't access past the end of the IEs */
467 if (end > resp_end)
468 break;
469
470 if (key_flags & KEY_INFO_WPA_UNICAST)
471 key = &priv->wpa_unicast_key;
472 else if (key_flags & KEY_INFO_WPA_MCAST)
473 key = &priv->wpa_mcast_key;
474 else
475 break;
476
477 /* Copy returned key into driver */
478 memset(key, 0, sizeof(struct enc_key));
479 if (key_len > sizeof(key->key))
480 break;
481 key->type = key_type;
482 key->flags = key_flags;
483 key->len = key_len;
484 memcpy(key->key, keyparam->key, key->len);
485
486 buf_ptr = end + 1;
487 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200488 }
489
Holger Schurig9012b282007-05-25 11:27:16 -0400490 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200491 return ret;
492}
493
Dan Williams39fcf7a2008-09-10 12:49:00 -0400494/**
495 * @brief Set an SNMP MIB value
496 *
497 * @param priv A pointer to struct lbs_private structure
498 * @param oid The OID to set in the firmware
499 * @param val Value to set the OID to
500 *
501 * @return 0 on success, error on failure
502 */
503int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200504{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400505 struct cmd_ds_802_11_snmp_mib cmd;
506 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507
Holger Schurig9012b282007-05-25 11:27:16 -0400508 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200509
Dan Williams39fcf7a2008-09-10 12:49:00 -0400510 memset(&cmd, 0, sizeof (cmd));
511 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
512 cmd.action = cpu_to_le16(CMD_ACT_SET);
513 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200514
Dan Williams39fcf7a2008-09-10 12:49:00 -0400515 switch (oid) {
516 case SNMP_MIB_OID_BSS_TYPE:
517 cmd.bufsize = cpu_to_le16(sizeof(u8));
518 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200519 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400520 case SNMP_MIB_OID_11D_ENABLE:
521 case SNMP_MIB_OID_FRAG_THRESHOLD:
522 case SNMP_MIB_OID_RTS_THRESHOLD:
523 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
524 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
525 cmd.bufsize = cpu_to_le16(sizeof(u16));
526 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527 break;
528 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400529 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
530 ret = -EINVAL;
531 goto out;
532 }
533
534 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
535 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
536
537 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
538
539out:
540 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
541 return ret;
542}
543
544/**
545 * @brief Get an SNMP MIB value
546 *
547 * @param priv A pointer to struct lbs_private structure
548 * @param oid The OID to retrieve from the firmware
549 * @param out_val Location for the returned value
550 *
551 * @return 0 on success, error on failure
552 */
553int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
554{
555 struct cmd_ds_802_11_snmp_mib cmd;
556 int ret;
557
558 lbs_deb_enter(LBS_DEB_CMD);
559
560 memset(&cmd, 0, sizeof (cmd));
561 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
562 cmd.action = cpu_to_le16(CMD_ACT_GET);
563 cmd.oid = cpu_to_le16(oid);
564
565 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
566 if (ret)
567 goto out;
568
569 switch (le16_to_cpu(cmd.bufsize)) {
570 case sizeof(u8):
571 if (oid == SNMP_MIB_OID_BSS_TYPE) {
572 if (cmd.value[0] == 2)
573 *out_val = IW_MODE_ADHOC;
574 else
575 *out_val = IW_MODE_INFRA;
576 } else
577 *out_val = cmd.value[0];
578 break;
579 case sizeof(u16):
580 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
581 break;
582 default:
583 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
584 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200585 break;
586 }
587
Dan Williams39fcf7a2008-09-10 12:49:00 -0400588out:
589 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
590 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200591}
592
Dan Williams87c8c722008-08-19 15:15:35 -0400593/**
594 * @brief Get the min, max, and current TX power
595 *
596 * @param priv A pointer to struct lbs_private structure
597 * @param curlevel Current power level in dBm
598 * @param minlevel Minimum supported power level in dBm (optional)
599 * @param maxlevel Maximum supported power level in dBm (optional)
600 *
601 * @return 0 on success, error on failure
602 */
603int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
604 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200605{
Dan Williams87c8c722008-08-19 15:15:35 -0400606 struct cmd_ds_802_11_rf_tx_power cmd;
607 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200608
Holger Schurig9012b282007-05-25 11:27:16 -0400609 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610
Dan Williams87c8c722008-08-19 15:15:35 -0400611 memset(&cmd, 0, sizeof(cmd));
612 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
613 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200614
Dan Williams87c8c722008-08-19 15:15:35 -0400615 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
616 if (ret == 0) {
617 *curlevel = le16_to_cpu(cmd.curlevel);
618 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100619 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400620 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100621 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200622 }
Holger Schurig9012b282007-05-25 11:27:16 -0400623
624 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400625 return ret;
626}
627
628/**
629 * @brief Set the TX power
630 *
631 * @param priv A pointer to struct lbs_private structure
632 * @param dbm The desired power level in dBm
633 *
634 * @return 0 on success, error on failure
635 */
636int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
637{
638 struct cmd_ds_802_11_rf_tx_power cmd;
639 int ret;
640
641 lbs_deb_enter(LBS_DEB_CMD);
642
643 memset(&cmd, 0, sizeof(cmd));
644 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
645 cmd.action = cpu_to_le16(CMD_ACT_SET);
646 cmd.curlevel = cpu_to_le16(dbm);
647
648 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
649
650 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
651
652 lbs_deb_leave(LBS_DEB_CMD);
653 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200654}
655
Holger Schurige98a88d2008-03-19 14:25:58 +0100656static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -0400657 u16 cmd_action, void *pdata_buf)
658{
659 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
660
661 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
662 cmd->size =
663 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
664 S_DS_GEN);
665
666 monitor->action = cpu_to_le16(cmd_action);
667 if (cmd_action == CMD_ACT_SET) {
668 monitor->mode =
669 cpu_to_le16((u16) (*(u32 *) pdata_buf));
670 }
671
672 return 0;
673}
674
Javier Cardona85319f92008-05-24 10:59:49 +0100675static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200676{
Javier Cardona85319f92008-05-24 10:59:49 +0100677/* Bit Rate
678* 15:13 Reserved
679* 12 54 Mbps
680* 11 48 Mbps
681* 10 36 Mbps
682* 9 24 Mbps
683* 8 18 Mbps
684* 7 12 Mbps
685* 6 9 Mbps
686* 5 6 Mbps
687* 4 Reserved
688* 3 11 Mbps
689* 2 5.5 Mbps
690* 1 2 Mbps
691* 0 1 Mbps
692**/
693
694 uint16_t ratemask;
695 int i = lbs_data_rate_to_fw_index(rate);
696 if (lower_rates_ok)
697 ratemask = (0x1fef >> (12 - i));
698 else
699 ratemask = (1 << i);
700 return cpu_to_le16(ratemask);
701}
702
703int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
704 uint16_t cmd_action)
705{
706 struct cmd_ds_802_11_rate_adapt_rateset cmd;
707 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200708
Holger Schurig8ff12da2007-08-02 11:54:31 -0400709 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200710
Javier Cardona85319f92008-05-24 10:59:49 +0100711 if (!priv->cur_rate && !priv->enablehwauto)
712 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200713
Javier Cardona85319f92008-05-24 10:59:49 +0100714 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
715
716 cmd.action = cpu_to_le16(cmd_action);
717 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
718 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
719 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
720 if (!ret && cmd_action == CMD_ACT_GET) {
721 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
722 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
723 }
724
725 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
726 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200727}
Javier Cardona85319f92008-05-24 10:59:49 +0100728EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200729
Dan Williams8e3c91b2007-12-11 15:50:59 -0500730/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500731 * @brief Set the data rate
732 *
733 * @param priv A pointer to struct lbs_private structure
734 * @param rate The desired data rate, or 0 to clear a locked rate
735 *
736 * @return 0 on success, error on failure
737 */
738int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
739{
740 struct cmd_ds_802_11_data_rate cmd;
741 int ret = 0;
742
743 lbs_deb_enter(LBS_DEB_CMD);
744
745 memset(&cmd, 0, sizeof(cmd));
746 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
747
748 if (rate > 0) {
749 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
750 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
751 if (cmd.rates[0] == 0) {
752 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
753 " 0x%02X\n", rate);
754 ret = 0;
755 goto out;
756 }
757 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
758 } else {
759 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400760 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200761 }
762
David Woodhouse689442d2007-12-12 16:00:42 -0500763 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500764 if (ret)
765 goto out;
766
767 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
768
769 /* FIXME: get actual rates FW can do if this command actually returns
770 * all data rates supported.
771 */
772 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
773 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
774
775out:
776 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
777 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200778}
779
Dan Williams2dd4b262007-12-11 16:54:15 -0500780/**
781 * @brief Get the radio channel
782 *
783 * @param priv A pointer to struct lbs_private structure
784 *
785 * @return The channel on success, error on failure
786 */
787int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200788{
Dan Williams2dd4b262007-12-11 16:54:15 -0500789 struct cmd_ds_802_11_rf_channel cmd;
790 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200791
Holger Schurig8ff12da2007-08-02 11:54:31 -0400792 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200793
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200794 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500795 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
796 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200797
David Woodhouse689442d2007-12-12 16:00:42 -0500798 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500799 if (ret)
800 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200801
Dan Williamscb182a62007-12-11 17:35:51 -0500802 ret = le16_to_cpu(cmd.channel);
803 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500804
805out:
806 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
807 return ret;
808}
809
Holger Schurig73ab1f22008-04-02 16:52:19 +0200810int lbs_update_channel(struct lbs_private *priv)
811{
812 int ret;
813
814 /* the channel in f/w could be out of sync; get the current channel */
815 lbs_deb_enter(LBS_DEB_ASSOC);
816
817 ret = lbs_get_channel(priv);
818 if (ret > 0) {
819 priv->curbssparams.channel = ret;
820 ret = 0;
821 }
822 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
823 return ret;
824}
825
Dan Williams2dd4b262007-12-11 16:54:15 -0500826/**
827 * @brief Set the radio channel
828 *
829 * @param priv A pointer to struct lbs_private structure
830 * @param channel The desired channel, or 0 to clear a locked channel
831 *
832 * @return 0 on success, error on failure
833 */
834int lbs_set_channel(struct lbs_private *priv, u8 channel)
835{
836 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530837#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500838 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530839#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500840 int ret = 0;
841
842 lbs_deb_enter(LBS_DEB_CMD);
843
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200844 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500845 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
846 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
847 cmd.channel = cpu_to_le16(channel);
848
David Woodhouse689442d2007-12-12 16:00:42 -0500849 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500850 if (ret)
851 goto out;
852
Dan Williamscb182a62007-12-11 17:35:51 -0500853 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
854 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
855 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500856
857out:
858 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
859 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200860}
861
Holger Schurig69f90322007-11-23 15:43:44 +0100862static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200863 struct cmd_ds_command *cmd)
864{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200865
Holger Schurig8ff12da2007-08-02 11:54:31 -0400866 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400867 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400868 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400869 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200870
871 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000872 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
873 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
874 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
875 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
876 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
877 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200878
Holger Schurig8ff12da2007-08-02 11:54:31 -0400879 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880 return 0;
881}
882
Holger Schurige98a88d2008-03-19 14:25:58 +0100883static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200884 u8 cmd_action, void *pdata_buf)
885{
Holger Schurig10078322007-11-15 18:05:47 -0500886 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200887
Holger Schurig9012b282007-05-25 11:27:16 -0400888 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200889
Holger Schurig10078322007-11-15 18:05:47 -0500890 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200891
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000892 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400893 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200894 {
895 struct cmd_ds_mac_reg_access *macreg;
896
897 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400898 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
899 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 macreg =
901 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
902 macreg;
903
904 macreg->action = cpu_to_le16(cmd_action);
905 macreg->offset = cpu_to_le16((u16) offval->offset);
906 macreg->value = cpu_to_le32(offval->value);
907
908 break;
909 }
910
Dan Williams0aef64d2007-08-02 11:31:18 -0400911 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200912 {
913 struct cmd_ds_bbp_reg_access *bbpreg;
914
915 cmdptr->size =
916 cpu_to_le16(sizeof
917 (struct cmd_ds_bbp_reg_access)
918 + S_DS_GEN);
919 bbpreg =
920 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
921 bbpreg;
922
923 bbpreg->action = cpu_to_le16(cmd_action);
924 bbpreg->offset = cpu_to_le16((u16) offval->offset);
925 bbpreg->value = (u8) offval->value;
926
927 break;
928 }
929
Dan Williams0aef64d2007-08-02 11:31:18 -0400930 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200931 {
932 struct cmd_ds_rf_reg_access *rfreg;
933
934 cmdptr->size =
935 cpu_to_le16(sizeof
936 (struct cmd_ds_rf_reg_access) +
937 S_DS_GEN);
938 rfreg =
939 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
940 rfreg;
941
942 rfreg->action = cpu_to_le16(cmd_action);
943 rfreg->offset = cpu_to_le16((u16) offval->offset);
944 rfreg->value = (u8) offval->value;
945
946 break;
947 }
948
949 default:
950 break;
951 }
952
Holger Schurig9012b282007-05-25 11:27:16 -0400953 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200954 return 0;
955}
956
Holger Schurige98a88d2008-03-19 14:25:58 +0100957static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958 u16 cmd_action, void *pdata_buf)
959{
960 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400961 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200962
Dan Williams0aef64d2007-08-02 11:31:18 -0400963 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400964 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200965 cmd->result = 0;
966 bt_access->action = cpu_to_le16(cmd_action);
967
968 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400969 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200970 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400971 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200972 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400973 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400975 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200976 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400977 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
979 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400980 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200981 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400982 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400983 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
984 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400985 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400986 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987 default:
988 break;
989 }
Holger Schurig8ff12da2007-08-02 11:54:31 -0400990 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200991 return 0;
992}
993
Holger Schurige98a88d2008-03-19 14:25:58 +0100994static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200995 u16 cmd_action, void *pdata_buf)
996{
997 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400998 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200999
Dan Williams0aef64d2007-08-02 11:31:18 -04001000 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001001 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001002 cmd->result = 0;
1003
1004 if (pdata_buf)
1005 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1006 else
1007 memset(fwt_access, 0, sizeof(*fwt_access));
1008
1009 fwt_access->action = cpu_to_le16(cmd_action);
1010
Holger Schurig8ff12da2007-08-02 11:54:31 -04001011 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001012 return 0;
1013}
1014
David Woodhouse301eacb2007-12-11 15:23:59 -05001015int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1016 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017{
David Woodhouse301eacb2007-12-11 15:23:59 -05001018 int ret;
1019
Holger Schurig8ff12da2007-08-02 11:54:31 -04001020 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001021
David Woodhouse301eacb2007-12-11 15:23:59 -05001022 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001023 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001024 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001025
David Woodhouse301eacb2007-12-11 15:23:59 -05001026 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001027
David Woodhouse689442d2007-12-12 16:00:42 -05001028 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001029
Holger Schurig8ff12da2007-08-02 11:54:31 -04001030 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001031 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032}
1033
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001034static int __lbs_mesh_config_send(struct lbs_private *priv,
1035 struct cmd_ds_mesh_config *cmd,
1036 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001037{
1038 int ret;
1039
1040 lbs_deb_enter(LBS_DEB_CMD);
1041
1042 cmd->hdr.command = cpu_to_le16(CMD_MESH_CONFIG);
1043 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1044 cmd->hdr.result = 0;
1045
1046 cmd->type = cpu_to_le16(type);
1047 cmd->action = cpu_to_le16(action);
1048
1049 ret = lbs_cmd_with_response(priv, CMD_MESH_CONFIG, cmd);
1050
1051 lbs_deb_leave(LBS_DEB_CMD);
1052 return ret;
1053}
1054
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001055int lbs_mesh_config_send(struct lbs_private *priv,
1056 struct cmd_ds_mesh_config *cmd,
1057 uint16_t action, uint16_t type)
1058{
1059 int ret;
1060
1061 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1062 return -EOPNOTSUPP;
1063
1064 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1065 return ret;
1066}
1067
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001068/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1069 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1070 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1071 * lbs_mesh_config_send.
1072 */
1073int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001074{
1075 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001076 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -04001077 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -05001078
1079 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001080 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001081 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001082
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001083 switch (action) {
1084 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +01001085 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001086 ie->val.oui[0] = 0x00;
1087 ie->val.oui[1] = 0x50;
1088 ie->val.oui[2] = 0x43;
1089 ie->val.type = MARVELL_MESH_IE_TYPE;
1090 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1091 ie->val.version = MARVELL_MESH_IE_VERSION;
1092 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1093 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1094 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1095 ie->val.mesh_id_len = priv->mesh_ssid_len;
1096 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +01001097 ie->len = sizeof(struct mrvl_meshie_val) -
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001098 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1099 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1100 break;
1101 case CMD_ACT_MESH_CONFIG_STOP:
1102 break;
1103 default:
1104 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001105 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001106 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1107 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -04001108 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001109
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001110 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001111}
1112
Brajesh Dave96287ac2007-11-20 17:44:28 -05001113static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1114 struct cmd_ds_command *cmd,
1115 u16 cmd_action)
1116{
1117 struct cmd_ds_802_11_beacon_control
1118 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001119
1120 lbs_deb_enter(LBS_DEB_CMD);
1121 cmd->size =
1122 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1123 + S_DS_GEN);
1124 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1125
1126 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001127 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1128 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001129
1130 lbs_deb_leave(LBS_DEB_CMD);
1131 return 0;
1132}
1133
David Woodhouse681ffbb2007-12-15 20:04:54 -05001134static void lbs_queue_cmd(struct lbs_private *priv,
1135 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001136{
1137 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001138 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001139
Holger Schurig8ff12da2007-08-02 11:54:31 -04001140 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001141
David Woodhousec4ab4122007-12-15 00:41:51 -05001142 if (!cmdnode) {
1143 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001144 goto done;
1145 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001146 if (!cmdnode->cmdbuf->size) {
1147 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1148 goto done;
1149 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001150 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001151
1152 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001153 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001154 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001155
Dan Williams0aef64d2007-08-02 11:31:18 -04001156 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001157 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001158 addtail = 0;
1159 }
1160 }
1161
David Woodhouseaa21c002007-12-08 20:04:36 +00001162 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163
David Woodhouseac472462007-12-08 00:35:00 +00001164 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001165 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001166 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001167 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168
David Woodhouseaa21c002007-12-08 20:04:36 +00001169 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170
Holger Schurig8ff12da2007-08-02 11:54:31 -04001171 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001172 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001173
1174done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001175 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176}
1177
David Woodhouse18c52e72007-12-17 16:03:58 -05001178static void lbs_submit_command(struct lbs_private *priv,
1179 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180{
1181 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001182 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001183 uint16_t cmdsize;
1184 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001185 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001186 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187
Holger Schurig8ff12da2007-08-02 11:54:31 -04001188 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001189
Dan Williamsddac4522007-12-11 13:49:39 -05001190 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001191
David Woodhouseaa21c002007-12-08 20:04:36 +00001192 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001193 priv->cur_cmd = cmdnode;
1194 priv->cur_cmd_retcode = 0;
1195 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001196
Dan Williamsddac4522007-12-11 13:49:39 -05001197 cmdsize = le16_to_cpu(cmd->size);
1198 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199
David Woodhouse18c52e72007-12-17 16:03:58 -05001200 /* These commands take longer */
1201 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
1202 command == CMD_802_11_AUTHENTICATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001203 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001204
Holger Schurige5225b32008-03-26 10:04:44 +01001205 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1206 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001207 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001208
Dan Williamsddac4522007-12-11 13:49:39 -05001209 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001210
David Woodhoused9896ee2007-12-15 00:09:25 -05001211 if (ret) {
1212 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001213 /* Let the timer kick in and retry, and potentially reset
1214 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001215 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001216 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217
1218 /* Setup the timer after transmit command */
David Woodhouse18c52e72007-12-17 16:03:58 -05001219 mod_timer(&priv->command_timer, jiffies + timeo);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001220
David Woodhouse18c52e72007-12-17 16:03:58 -05001221 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001222}
1223
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001224/**
1225 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001226 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001227 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001228static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001229 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001230{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001231 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001232
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001233 if (!cmdnode)
1234 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001235
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001236 cmdnode->callback = NULL;
1237 cmdnode->callback_arg = 0;
1238
1239 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1240
1241 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1242 out:
1243 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001244}
1245
Holger Schurig69f90322007-11-23 15:43:44 +01001246static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1247 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248{
1249 unsigned long flags;
1250
David Woodhouseaa21c002007-12-08 20:04:36 +00001251 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001252 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001253 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001254}
1255
David Woodhouse183aeac2007-12-15 01:52:54 -05001256void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1257 int result)
1258{
1259 if (cmd == priv->cur_cmd)
1260 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001261
David Woodhouseae125bf2007-12-15 04:22:52 -05001262 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001263 cmd->cmdwaitqwoken = 1;
1264 wake_up_interruptible(&cmd->cmdwait_q);
1265
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001266 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001267 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001268 priv->cur_cmd = NULL;
1269}
1270
Dan Williamsd5db2df2008-08-21 17:51:07 -04001271int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272{
David Woodhousea7c45892007-12-17 22:43:48 -05001273 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001274 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001275
Holger Schurig9012b282007-05-25 11:27:16 -04001276 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001277
David Woodhousea7c45892007-12-17 22:43:48 -05001278 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1279 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001280
Dan Williamsd5db2df2008-08-21 17:51:07 -04001281 /* Only v8 and below support setting the preamble */
1282 if (priv->fwrelease < 0x09000000) {
1283 switch (preamble) {
1284 case RADIO_PREAMBLE_SHORT:
1285 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1286 goto out;
1287 /* Fall through */
1288 case RADIO_PREAMBLE_AUTO:
1289 case RADIO_PREAMBLE_LONG:
1290 cmd.control = cpu_to_le16(preamble);
1291 break;
1292 default:
1293 goto out;
1294 }
David Woodhousea7c45892007-12-17 22:43:48 -05001295 }
1296
Dan Williamsd5db2df2008-08-21 17:51:07 -04001297 if (radio_on)
1298 cmd.control |= cpu_to_le16(0x1);
1299 else {
1300 cmd.control &= cpu_to_le16(~0x1);
1301 priv->txpower_cur = 0;
1302 }
David Woodhousea7c45892007-12-17 22:43:48 -05001303
Dan Williamsd5db2df2008-08-21 17:51:07 -04001304 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1305 radio_on ? "ON" : "OFF", preamble);
1306
1307 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001308
1309 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001310
Dan Williamsd5db2df2008-08-21 17:51:07 -04001311out:
Holger Schurig9012b282007-05-25 11:27:16 -04001312 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001313 return ret;
1314}
1315
Holger Schurigc97329e2008-03-18 11:20:21 +01001316void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001317{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001318 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001319
Holger Schurig9012b282007-05-25 11:27:16 -04001320 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001321
Holger Schurig835d3ac2008-03-12 16:05:40 +01001322 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001323 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001324 cmd.reserved = 0;
1325
David Woodhouse75bf45a2008-05-20 13:32:45 +01001326 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001327
Holger Schurigc97329e2008-03-18 11:20:21 +01001328 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001329}
1330
1331/**
1332 * @brief This function prepare the command before send to firmware.
1333 *
Holger Schurig69f90322007-11-23 15:43:44 +01001334 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 * @param cmd_no command number
1336 * @param cmd_action command action: GET or SET
1337 * @param wait_option wait option: wait response or not
1338 * @param cmd_oid cmd oid: treated as sub command
1339 * @param pdata_buf A pointer to informaion buffer
1340 * @return 0 or -1
1341 */
Holger Schurig69f90322007-11-23 15:43:44 +01001342int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001343 u16 cmd_no,
1344 u16 cmd_action,
1345 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1346{
1347 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001348 struct cmd_ctrl_node *cmdnode;
1349 struct cmd_ds_command *cmdptr;
1350 unsigned long flags;
1351
Holger Schurig8ff12da2007-08-02 11:54:31 -04001352 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001353
David Woodhouseaa21c002007-12-08 20:04:36 +00001354 if (!priv) {
1355 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001356 ret = -1;
1357 goto done;
1358 }
1359
David Woodhouseaa21c002007-12-08 20:04:36 +00001360 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001361 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001362 ret = -1;
1363 goto done;
1364 }
1365
Holger Schurig0d61d042007-12-05 17:58:06 +01001366 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001367
1368 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001369 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370
1371 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001372 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001373 ret = -1;
1374 goto done;
1375 }
1376
Holger Schurige98a88d2008-03-19 14:25:58 +01001377 cmdnode->callback = NULL;
1378 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001379
Dan Williamsddac4522007-12-11 13:49:39 -05001380 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381
Holger Schurig8ff12da2007-08-02 11:54:31 -04001382 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001383
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001385 priv->seqnum++;
1386 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001387
David Woodhouse981f1872007-05-25 23:36:54 -04001388 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001389 cmdptr->result = 0;
1390
1391 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001392 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001393 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001394 break;
1395
Dan Williams0aef64d2007-08-02 11:31:18 -04001396 case CMD_802_11_ASSOCIATE:
1397 case CMD_802_11_REASSOCIATE:
Holger Schurig10078322007-11-15 18:05:47 -05001398 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001399 break;
1400
Dan Williams0aef64d2007-08-02 11:31:18 -04001401 case CMD_802_11_AUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001402 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001403 break;
1404
Dan Williams0aef64d2007-08-02 11:31:18 -04001405 case CMD_MAC_REG_ACCESS:
1406 case CMD_BBP_REG_ACCESS:
1407 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001408 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409 break;
1410
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001411 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001412 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bbc2007-08-02 13:16:55 -04001413 cmd_action, pdata_buf);
1414 break;
1415
Dan Williams0aef64d2007-08-02 11:31:18 -04001416 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001417 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001418 break;
1419
Dan Williams0aef64d2007-08-02 11:31:18 -04001420 case CMD_802_11_SET_AFC:
1421 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422
1423 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001424 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1425 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001426
1427 memmove(&cmdptr->params.afc,
1428 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1429
1430 ret = 0;
1431 goto done;
1432
Dan Williams0aef64d2007-08-02 11:31:18 -04001433 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001434 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001435 cmd_no, cmd_action);
1436 break;
1437
Dan Williams0aef64d2007-08-02 11:31:18 -04001438 case CMD_802_11_TPC_CFG:
1439 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001440 cmdptr->size =
1441 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1442 S_DS_GEN);
1443
1444 memmove(&cmdptr->params.tpccfg,
1445 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1446
1447 ret = 0;
1448 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001449 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001450 {
1451 struct mrvlietypes_ledgpio *gpio =
1452 (struct mrvlietypes_ledgpio*)
1453 cmdptr->params.ledgpio.data;
1454
1455 memmove(&cmdptr->params.ledgpio,
1456 pdata_buf,
1457 sizeof(struct cmd_ds_802_11_led_ctrl));
1458
1459 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001460 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001461
1462#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1463 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001464 cpu_to_le16(le16_to_cpu(gpio->header.len)
1465 + S_DS_GEN
1466 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1467 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001468
1469 ret = 0;
1470 break;
1471 }
David Woodhouse5844d122007-12-18 02:01:37 -05001472
Dan Williams0aef64d2007-08-02 11:31:18 -04001473 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001474 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001475 break;
1476
Dan Williams0aef64d2007-08-02 11:31:18 -04001477 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001478 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 break;
1480
Dan Williams0aef64d2007-08-02 11:31:18 -04001481 case CMD_GET_TSF:
1482 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001483 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1484 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001485 ret = 0;
1486 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001487 case CMD_802_11_BEACON_CTRL:
1488 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1489 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001490 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001491 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001492 ret = -1;
1493 break;
1494 }
1495
1496 /* return error, since the command preparation failed */
1497 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001498 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001499 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001500 ret = -1;
1501 goto done;
1502 }
1503
1504 cmdnode->cmdwaitqwoken = 0;
1505
David Woodhouse681ffbb2007-12-15 20:04:54 -05001506 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001507 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508
Dan Williams0aef64d2007-08-02 11:31:18 -04001509 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001510 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511 might_sleep();
1512 wait_event_interruptible(cmdnode->cmdwait_q,
1513 cmdnode->cmdwaitqwoken);
1514 }
1515
David Woodhouseaa21c002007-12-08 20:04:36 +00001516 spin_lock_irqsave(&priv->driver_lock, flags);
1517 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001518 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001519 priv->cur_cmd_retcode);
1520 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001521 ret = -1;
1522 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001523 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001524
1525done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001526 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527 return ret;
1528}
1529
1530/**
1531 * @brief This function allocates the command buffer and link
1532 * it to command free queue.
1533 *
Holger Schurig69f90322007-11-23 15:43:44 +01001534 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001535 * @return 0 or -1
1536 */
Holger Schurig69f90322007-11-23 15:43:44 +01001537int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001538{
1539 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001540 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001542 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001543
Holger Schurig8ff12da2007-08-02 11:54:31 -04001544 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001545
Dan Williamsddac4522007-12-11 13:49:39 -05001546 /* Allocate and initialize the command array */
1547 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1548 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001549 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001550 ret = -1;
1551 goto done;
1552 }
Dan Williamsddac4522007-12-11 13:49:39 -05001553 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554
Dan Williamsddac4522007-12-11 13:49:39 -05001555 /* Allocate and initialize each command buffer in the command array */
1556 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1557 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1558 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001559 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 ret = -1;
1561 goto done;
1562 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001563 }
1564
Dan Williamsddac4522007-12-11 13:49:39 -05001565 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1566 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1567 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001568 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001569 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001570
1571done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001572 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573 return ret;
1574}
1575
1576/**
1577 * @brief This function frees the command buffer.
1578 *
Holger Schurig69f90322007-11-23 15:43:44 +01001579 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001580 * @return 0 or -1
1581 */
Holger Schurig69f90322007-11-23 15:43:44 +01001582int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583{
Dan Williamsddac4522007-12-11 13:49:39 -05001584 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001585 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001586
Holger Schurig8ff12da2007-08-02 11:54:31 -04001587 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001588
1589 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001590 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001591 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001592 goto done;
1593 }
1594
Dan Williamsddac4522007-12-11 13:49:39 -05001595 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001596
1597 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001598 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1599 if (cmdarray[i].cmdbuf) {
1600 kfree(cmdarray[i].cmdbuf);
1601 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001602 }
1603 }
1604
1605 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001606 if (priv->cmd_array) {
1607 kfree(priv->cmd_array);
1608 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001609 }
1610
1611done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001612 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613 return 0;
1614}
1615
1616/**
1617 * @brief This function gets a free command node if available in
1618 * command free queue.
1619 *
Holger Schurig69f90322007-11-23 15:43:44 +01001620 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1622 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001623static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001624{
1625 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001626 unsigned long flags;
1627
Holger Schurig8ff12da2007-08-02 11:54:31 -04001628 lbs_deb_enter(LBS_DEB_HOST);
1629
David Woodhouseaa21c002007-12-08 20:04:36 +00001630 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001631 return NULL;
1632
David Woodhouseaa21c002007-12-08 20:04:36 +00001633 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634
David Woodhouseaa21c002007-12-08 20:04:36 +00001635 if (!list_empty(&priv->cmdfreeq)) {
1636 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001637 struct cmd_ctrl_node, list);
1638 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001639 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001640 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001641 tempnode = NULL;
1642 }
1643
David Woodhouseaa21c002007-12-08 20:04:36 +00001644 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645
Holger Schurig8ff12da2007-08-02 11:54:31 -04001646 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 return tempnode;
1648}
1649
1650/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001651 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001652 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653 * if applicable.
1654 *
Holger Schurig69f90322007-11-23 15:43:44 +01001655 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656 * @return 0 or -1
1657 */
Holger Schurig69f90322007-11-23 15:43:44 +01001658int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001659{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001661 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662 unsigned long flags;
1663 int ret = 0;
1664
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001665 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1666 * only caller to us is lbs_thread() and we get even when a
1667 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001668 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669
David Woodhouseaa21c002007-12-08 20:04:36 +00001670 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001671
David Woodhouseaa21c002007-12-08 20:04:36 +00001672 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001673 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001674 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675 ret = -1;
1676 goto done;
1677 }
1678
David Woodhouseaa21c002007-12-08 20:04:36 +00001679 if (!list_empty(&priv->cmdpendingq)) {
1680 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001681 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001682 }
1683
David Woodhouseaa21c002007-12-08 20:04:36 +00001684 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001685
1686 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001687 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001688
Dan Williamsddac4522007-12-11 13:49:39 -05001689 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001690 if ((priv->psstate == PS_STATE_SLEEP) ||
1691 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001692 lbs_deb_host(
1693 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001694 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001695 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001696 ret = -1;
1697 goto done;
1698 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001699 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001700 "0x%04x in psstate %d\n",
1701 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001702 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001703 /*
1704 * 1. Non-PS command:
1705 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001706 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001707 * 2. PS command but not Exit_PS:
1708 * Ignore it.
1709 * 3. PS command Exit_PS:
1710 * Set needtowakeup to TRUE if current state is SLEEP,
1711 * otherwise send this command down to firmware
1712 * immediately.
1713 */
Dan Williamsddac4522007-12-11 13:49:39 -05001714 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 /* Prepare to send Exit PS,
1716 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001717 if ((priv->psstate == PS_STATE_SLEEP)
1718 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001719 ) {
1720 /* w/ new scheme, it will not reach here.
1721 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001722 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001723 } else
Holger Schurig10078322007-11-15 18:05:47 -05001724 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001725
1726 ret = 0;
1727 goto done;
1728 } else {
1729 /*
1730 * PS command. Ignore it if it is not Exit_PS.
1731 * otherwise send it down immediately.
1732 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001733 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001734
Holger Schurig8ff12da2007-08-02 11:54:31 -04001735 lbs_deb_host(
1736 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001737 psm->action);
1738 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001739 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001740 lbs_deb_host(
1741 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001742 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001743 spin_lock_irqsave(&priv->driver_lock, flags);
1744 lbs_complete_command(priv, cmdnode, 0);
1745 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001746
1747 ret = 0;
1748 goto done;
1749 }
1750
David Woodhouseaa21c002007-12-08 20:04:36 +00001751 if ((priv->psstate == PS_STATE_SLEEP) ||
1752 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001753 lbs_deb_host(
1754 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001755 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001756 spin_lock_irqsave(&priv->driver_lock, flags);
1757 lbs_complete_command(priv, cmdnode, 0);
1758 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001759 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001760
1761 ret = 0;
1762 goto done;
1763 }
1764
Holger Schurig8ff12da2007-08-02 11:54:31 -04001765 lbs_deb_host(
1766 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001767 }
1768 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001769 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001770 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001771 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001772 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001773 } else {
1774 /*
1775 * check if in power save mode, if yes, put the device back
1776 * to PS mode
1777 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001778 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1779 (priv->psstate == PS_STATE_FULL_POWER) &&
1780 ((priv->connect_status == LBS_CONNECTED) ||
1781 (priv->mesh_connect_status == LBS_CONNECTED))) {
1782 if (priv->secinfo.WPAenabled ||
1783 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001784 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001785 if (priv->wpa_mcast_key.len ||
1786 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001787 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001788 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1789 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001790 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 }
1792 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001793 lbs_deb_host(
1794 "EXEC_NEXT_CMD: cmdpendingq empty, "
1795 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001796 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001797 }
1798 }
1799 }
1800
1801 ret = 0;
1802done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001803 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001804 return ret;
1805}
1806
Holger Schurig69f90322007-11-23 15:43:44 +01001807void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001808{
1809 union iwreq_data iwrq;
1810 u8 buf[50];
1811
Holger Schurig8ff12da2007-08-02 11:54:31 -04001812 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001813
1814 memset(&iwrq, 0, sizeof(union iwreq_data));
1815 memset(buf, 0, sizeof(buf));
1816
1817 snprintf(buf, sizeof(buf) - 1, "%s", str);
1818
1819 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1820
1821 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001822 lbs_deb_wext("event indication string %s\n", (char *)buf);
1823 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1824 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001825
Holger Schurig634b8f42007-05-25 13:05:16 -04001826 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827
Holger Schurig8ff12da2007-08-02 11:54:31 -04001828 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829}
1830
Holger Schurigf539f2e2008-03-26 13:22:11 +01001831static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832{
1833 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001834 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001835
Holger Schurig8ff12da2007-08-02 11:54:31 -04001836 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001837 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1838 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001839
Holger Schurigf539f2e2008-03-26 13:22:11 +01001840 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1841 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001842 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001843 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001844 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001845 }
Holger Schurig7919b892008-04-01 14:50:43 +02001846
1847 spin_lock_irqsave(&priv->driver_lock, flags);
1848
Holger Schuriga01f5452008-06-04 11:10:40 +02001849 /* We don't get a response on the sleep-confirmation */
1850 priv->dnld_sent = DNLD_RES_RECEIVED;
1851
Holger Schurig7919b892008-04-01 14:50:43 +02001852 /* If nothing to do, go back to sleep (?) */
1853 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1854 priv->psstate = PS_STATE_SLEEP;
1855
1856 spin_unlock_irqrestore(&priv->driver_lock, flags);
1857
1858out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001859 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001860}
1861
Holger Schurig69f90322007-11-23 15:43:44 +01001862void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001863{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001864 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001865
1866 /*
1867 * PS is currently supported only in Infrastructure mode
1868 * Remove this check if it is to be supported in IBSS mode also
1869 */
1870
Holger Schurig10078322007-11-15 18:05:47 -05001871 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001872 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001873
Holger Schurig8ff12da2007-08-02 11:54:31 -04001874 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001875}
1876
1877/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001878 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001879 *
Holger Schurig69f90322007-11-23 15:43:44 +01001880 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881 * @param wait_option wait response or not
1882 * @return n/a
1883 */
Holger Schurig69f90322007-11-23 15:43:44 +01001884void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001885{
David Woodhouse981f1872007-05-25 23:36:54 -04001886 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001887
Holger Schurig8ff12da2007-08-02 11:54:31 -04001888 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001889
Holger Schurig10078322007-11-15 18:05:47 -05001890 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891
Holger Schurig10078322007-11-15 18:05:47 -05001892 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001893 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894 wait_option, 0, &Localpsmode);
1895
Holger Schurig8ff12da2007-08-02 11:54:31 -04001896 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001897}
1898
1899/**
1900 * @brief This function checks condition and prepares to
1901 * send sleep confirm command to firmware if ok.
1902 *
Holger Schurig69f90322007-11-23 15:43:44 +01001903 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904 * @param psmode Power Saving mode
1905 * @return n/a
1906 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001907void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908{
1909 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001910 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911
Holger Schurig8ff12da2007-08-02 11:54:31 -04001912 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001913
Holger Schuriga01f5452008-06-04 11:10:40 +02001914 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001915 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001917 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001918 }
1919
Holger Schurig7919b892008-04-01 14:50:43 +02001920 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001921 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001922 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001923 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001924 }
Holger Schurig7919b892008-04-01 14:50:43 +02001925
1926 /* Pending events or command responses? */
1927 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001928 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001929 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001930 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001931 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001932
1933 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001934 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001935 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001936 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001937 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001938 }
1939
Holger Schurig8ff12da2007-08-02 11:54:31 -04001940 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941}
Holger Schurig675787e2007-12-05 17:58:11 +01001942
1943
Anna Neal0112c9e2008-09-11 11:17:25 -07001944/**
1945 * @brief Configures the transmission power control functionality.
1946 *
1947 * @param priv A pointer to struct lbs_private structure
1948 * @param enable Transmission power control enable
1949 * @param p0 Power level when link quality is good (dBm).
1950 * @param p1 Power level when link quality is fair (dBm).
1951 * @param p2 Power level when link quality is poor (dBm).
1952 * @param usesnr Use Signal to Noise Ratio in TPC
1953 *
1954 * @return 0 on success
1955 */
1956int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1957 int8_t p2, int usesnr)
1958{
1959 struct cmd_ds_802_11_tpc_cfg cmd;
1960 int ret;
1961
1962 memset(&cmd, 0, sizeof(cmd));
1963 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1964 cmd.action = cpu_to_le16(CMD_ACT_SET);
1965 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001966 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001967 cmd.P0 = p0;
1968 cmd.P1 = p1;
1969 cmd.P2 = p2;
1970
1971 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1972
1973 return ret;
1974}
1975
1976/**
1977 * @brief Configures the power adaptation settings.
1978 *
1979 * @param priv A pointer to struct lbs_private structure
1980 * @param enable Power adaptation enable
1981 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1982 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1983 * @param p2 Power level for 48 and 54 Mbps (dBm).
1984 *
1985 * @return 0 on Success
1986 */
1987
1988int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1989 int8_t p1, int8_t p2)
1990{
1991 struct cmd_ds_802_11_pa_cfg cmd;
1992 int ret;
1993
1994 memset(&cmd, 0, sizeof(cmd));
1995 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1996 cmd.action = cpu_to_le16(CMD_ACT_SET);
1997 cmd.enable = !!enable;
1998 cmd.P0 = p0;
1999 cmd.P1 = p1;
2000 cmd.P2 = p2;
2001
2002 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2003
2004 return ret;
2005}
2006
2007
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002008static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
2009 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
2010 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2011 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01002012{
Holger Schurig675787e2007-12-05 17:58:11 +01002013 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002014
2015 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002016
David Woodhouseaa21c002007-12-08 20:04:36 +00002017 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002018 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002019 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002020 goto done;
2021 }
2022
2023 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002024 if (cmdnode == NULL) {
2025 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2026
2027 /* Wake up main thread to execute next command */
2028 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002029 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002030 goto done;
2031 }
2032
David Woodhouse448a51a2007-12-08 00:59:54 +00002033 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002034 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002035
Dan Williams7ad994d2007-12-11 12:33:30 -05002036 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002037 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002038
Holger Schurig675787e2007-12-05 17:58:11 +01002039 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002040 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002041 cmdnode->cmdbuf->command = cpu_to_le16(command);
2042 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2043 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2044 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002045
2046 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2047
Holger Schurig675787e2007-12-05 17:58:11 +01002048 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002049 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002050 wake_up_interruptible(&priv->waitq);
2051
David Woodhouse3399ea52007-12-15 03:09:33 -05002052 done:
2053 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2054 return cmdnode;
2055}
2056
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002057void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2058 struct cmd_header *in_cmd, int in_cmd_size)
2059{
2060 lbs_deb_enter(LBS_DEB_CMD);
2061 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2062 lbs_cmd_async_callback, 0);
2063 lbs_deb_leave(LBS_DEB_CMD);
2064}
2065
David Woodhouse3399ea52007-12-15 03:09:33 -05002066int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2067 struct cmd_header *in_cmd, int in_cmd_size,
2068 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2069 unsigned long callback_arg)
2070{
2071 struct cmd_ctrl_node *cmdnode;
2072 unsigned long flags;
2073 int ret = 0;
2074
2075 lbs_deb_enter(LBS_DEB_HOST);
2076
2077 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2078 callback, callback_arg);
2079 if (IS_ERR(cmdnode)) {
2080 ret = PTR_ERR(cmdnode);
2081 goto done;
2082 }
2083
Holger Schurig675787e2007-12-05 17:58:11 +01002084 might_sleep();
2085 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2086
David Woodhouseaa21c002007-12-08 20:04:36 +00002087 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002088 ret = cmdnode->result;
2089 if (ret)
2090 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2091 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002092
David Woodhousead12d0f2007-12-15 02:06:16 -05002093 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002094 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002095
2096done:
2097 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2098 return ret;
2099}
Dan Williams14e865b2007-12-10 15:11:23 -05002100EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002101
2102