blob: 8542d85f36afded911f7a687a7d7a99d2a2d293f [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>
Javier Cardonaedaea5c2008-05-17 00:55:10 -07007#include <net/ieee80211.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
David Woodhouse506e9022007-12-12 20:06:06 -0500162int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500163{
164 struct cmd_ds_host_sleep cmd_config;
165 int ret;
166
David Woodhouse9fae8992007-12-15 03:46:44 -0500167 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500168 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500169 cmd_config.gpio = priv->wol_gpio;
170 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500171
David Woodhouse689442d2007-12-12 16:00:42 -0500172 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500173 if (!ret) {
174 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
175 priv->wol_criteria = criteria;
176 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500177 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500178 }
David Woodhouse506e9022007-12-12 20:06:06 -0500179
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500180 return ret;
181}
182EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
183
Holger Schurige98a88d2008-03-19 14:25:58 +0100184static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200185 u16 cmd_action)
186{
187 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200188
Holger Schurig9012b282007-05-25 11:27:16 -0400189 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200190
Dan Williams0aef64d2007-08-02 11:31:18 -0400191 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400192 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
193 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200194 psm->action = cpu_to_le16(cmd_action);
195 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400196 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400197 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400198 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200199
Holger Schurig252cf0d12007-08-02 13:09:34 -0400200 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400201 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200202 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400203 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200204 break;
205
Dan Williams0aef64d2007-08-02 11:31:18 -0400206 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400207 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200208 break;
209
Dan Williams0aef64d2007-08-02 11:31:18 -0400210 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400211 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200212 break;
213
214 default:
215 break;
216 }
217
Holger Schurig9012b282007-05-25 11:27:16 -0400218 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200219 return 0;
220}
221
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500222int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
223 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200224{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500225 struct cmd_ds_802_11_inactivity_timeout cmd;
226 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200227
Holger Schurig8ff12da2007-08-02 11:54:31 -0400228 lbs_deb_enter(LBS_DEB_CMD);
229
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500230 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
231 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200232
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500233 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500235 if (cmd_action == CMD_ACT_SET)
236 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200237 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500238 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200239
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500240 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
241
242 if (!ret)
243 *timeout = le16_to_cpu(cmd.timeout);
244
245 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200246 return 0;
247}
248
David Woodhouse3fbe1042007-12-17 23:48:31 -0500249int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
250 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500252 struct cmd_ds_802_11_sleep_params cmd;
253 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200254
Holger Schurig9012b282007-05-25 11:27:16 -0400255 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256
Dan Williams0aef64d2007-08-02 11:31:18 -0400257 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500258 memset(&cmd, 0, sizeof(cmd));
259 } else {
260 cmd.error = cpu_to_le16(sp->sp_error);
261 cmd.offset = cpu_to_le16(sp->sp_offset);
262 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
263 cmd.calcontrol = sp->sp_calcontrol;
264 cmd.externalsleepclk = sp->sp_extsleepclk;
265 cmd.reserved = cpu_to_le16(sp->sp_reserved);
266 }
267 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
268 cmd.action = cpu_to_le16(cmd_action);
269
270 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
271
272 if (!ret) {
273 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
274 "calcontrol 0x%x extsleepclk 0x%x\n",
275 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
276 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
277 cmd.externalsleepclk);
278
279 sp->sp_error = le16_to_cpu(cmd.error);
280 sp->sp_offset = le16_to_cpu(cmd.offset);
281 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
282 sp->sp_calcontrol = cmd.calcontrol;
283 sp->sp_extsleepclk = cmd.externalsleepclk;
284 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200285 }
286
David Woodhouse3fbe1042007-12-17 23:48:31 -0500287 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288 return 0;
289}
290
David Woodhousef70dd452007-12-18 00:18:05 -0500291int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
292 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200293{
David Woodhousef70dd452007-12-18 00:18:05 -0500294 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200295 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200296
Holger Schurig9012b282007-05-25 11:27:16 -0400297 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200298
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200299 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500300 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
301 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200302
David Woodhousef70dd452007-12-18 00:18:05 -0500303 cmd.action = cpu_to_le16(cmd_action);
304
305 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200306 int i;
307
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200308 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500309 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
310 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200311
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200312 /* Copy key types and material to host command structure */
313 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500314 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200315
316 switch (pkey->len) {
317 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500318 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
319 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400320 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200321 break;
322 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500323 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
324 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400325 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200326 break;
327 case 0:
328 break;
329 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400330 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500331 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200332 ret = -1;
333 goto done;
334 break;
335 }
336 }
David Woodhousef70dd452007-12-18 00:18:05 -0500337 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200339
340 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500341 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
342 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000343 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 }
345
David Woodhousef70dd452007-12-18 00:18:05 -0500346 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347done:
Holger Schurig9012b282007-05-25 11:27:16 -0400348 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200349 return ret;
350}
351
David Woodhouse4f59abf2007-12-18 00:47:17 -0500352int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
353 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200354{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500355 struct cmd_ds_802_11_enable_rsn cmd;
356 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400357
358 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200359
David Woodhouse4f59abf2007-12-18 00:47:17 -0500360 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
361 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400362
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200363 if (cmd_action == CMD_ACT_GET)
364 cmd.enable = 0;
365 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400366 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500367 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400368 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500369 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400370 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371 }
372
David Woodhouse4f59abf2007-12-18 00:47:17 -0500373 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
374 if (!ret && cmd_action == CMD_ACT_GET)
375 *enable = le16_to_cpu(cmd.enable);
376
377 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
378 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379}
380
David Woodhouse9e1228d2008-03-03 12:15:39 +0100381static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
382 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200383{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400384 lbs_deb_enter(LBS_DEB_CMD);
385
David Woodhouse9e1228d2008-03-03 12:15:39 +0100386 if (key->flags & KEY_INFO_WPA_ENABLED)
387 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
388 if (key->flags & KEY_INFO_WPA_UNICAST)
389 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
390 if (key->flags & KEY_INFO_WPA_MCAST)
391 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200392
David Woodhouse9e1228d2008-03-03 12:15:39 +0100393 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
394 keyparam->keytypeid = cpu_to_le16(key->type);
395 keyparam->keylen = cpu_to_le16(key->len);
396 memcpy(keyparam->key, key->key, key->len);
397
398 /* Length field doesn't include the {type,length} header */
399 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400400 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200401}
402
David Woodhouse9e1228d2008-03-03 12:15:39 +0100403int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
404 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200405{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100406 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200407 int ret = 0;
408 int index = 0;
409
Holger Schurig9012b282007-05-25 11:27:16 -0400410 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411
David Woodhouse9e1228d2008-03-03 12:15:39 +0100412 cmd.action = cpu_to_le16(cmd_action);
413 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200414
Dan Williams0aef64d2007-08-02 11:31:18 -0400415 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100416 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
417 } else {
418 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
419
420 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
421 set_one_wpa_key(&cmd.keyParamSet[index],
422 &assoc->wpa_unicast_key);
423 index++;
424 }
425
426 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
427 set_one_wpa_key(&cmd.keyParamSet[index],
428 &assoc->wpa_mcast_key);
429 index++;
430 }
431
432 /* The common header and as many keys as we included */
433 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
434 keyParamSet[index]));
435 }
436 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
437 /* Copy the returned key to driver private data */
438 if (!ret && cmd_action == CMD_ACT_GET) {
439 void *buf_ptr = cmd.keyParamSet;
440 void *resp_end = &(&cmd)[1];
441
442 while (buf_ptr < resp_end) {
443 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
444 struct enc_key *key;
445 uint16_t param_set_len = le16_to_cpu(keyparam->length);
446 uint16_t key_len = le16_to_cpu(keyparam->keylen);
447 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
448 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
449 void *end;
450
451 end = (void *)keyparam + sizeof(keyparam->type)
452 + sizeof(keyparam->length) + param_set_len;
453
454 /* Make sure we don't access past the end of the IEs */
455 if (end > resp_end)
456 break;
457
458 if (key_flags & KEY_INFO_WPA_UNICAST)
459 key = &priv->wpa_unicast_key;
460 else if (key_flags & KEY_INFO_WPA_MCAST)
461 key = &priv->wpa_mcast_key;
462 else
463 break;
464
465 /* Copy returned key into driver */
466 memset(key, 0, sizeof(struct enc_key));
467 if (key_len > sizeof(key->key))
468 break;
469 key->type = key_type;
470 key->flags = key_flags;
471 key->len = key_len;
472 memcpy(key->key, keyparam->key, key->len);
473
474 buf_ptr = end + 1;
475 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200476 }
477
Holger Schurig9012b282007-05-25 11:27:16 -0400478 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200479 return ret;
480}
481
Dan Williams39fcf7a2008-09-10 12:49:00 -0400482/**
483 * @brief Set an SNMP MIB value
484 *
485 * @param priv A pointer to struct lbs_private structure
486 * @param oid The OID to set in the firmware
487 * @param val Value to set the OID to
488 *
489 * @return 0 on success, error on failure
490 */
491int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200492{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400493 struct cmd_ds_802_11_snmp_mib cmd;
494 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200495
Holger Schurig9012b282007-05-25 11:27:16 -0400496 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200497
Dan Williams39fcf7a2008-09-10 12:49:00 -0400498 memset(&cmd, 0, sizeof (cmd));
499 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
500 cmd.action = cpu_to_le16(CMD_ACT_SET);
501 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200502
Dan Williams39fcf7a2008-09-10 12:49:00 -0400503 switch (oid) {
504 case SNMP_MIB_OID_BSS_TYPE:
505 cmd.bufsize = cpu_to_le16(sizeof(u8));
506 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200507 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400508 case SNMP_MIB_OID_11D_ENABLE:
509 case SNMP_MIB_OID_FRAG_THRESHOLD:
510 case SNMP_MIB_OID_RTS_THRESHOLD:
511 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
512 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
513 cmd.bufsize = cpu_to_le16(sizeof(u16));
514 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200515 break;
516 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400517 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
518 ret = -EINVAL;
519 goto out;
520 }
521
522 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
523 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
524
525 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
526
527out:
528 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
529 return ret;
530}
531
532/**
533 * @brief Get an SNMP MIB value
534 *
535 * @param priv A pointer to struct lbs_private structure
536 * @param oid The OID to retrieve from the firmware
537 * @param out_val Location for the returned value
538 *
539 * @return 0 on success, error on failure
540 */
541int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
542{
543 struct cmd_ds_802_11_snmp_mib cmd;
544 int ret;
545
546 lbs_deb_enter(LBS_DEB_CMD);
547
548 memset(&cmd, 0, sizeof (cmd));
549 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
550 cmd.action = cpu_to_le16(CMD_ACT_GET);
551 cmd.oid = cpu_to_le16(oid);
552
553 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
554 if (ret)
555 goto out;
556
557 switch (le16_to_cpu(cmd.bufsize)) {
558 case sizeof(u8):
559 if (oid == SNMP_MIB_OID_BSS_TYPE) {
560 if (cmd.value[0] == 2)
561 *out_val = IW_MODE_ADHOC;
562 else
563 *out_val = IW_MODE_INFRA;
564 } else
565 *out_val = cmd.value[0];
566 break;
567 case sizeof(u16):
568 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
569 break;
570 default:
571 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
572 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200573 break;
574 }
575
Dan Williams39fcf7a2008-09-10 12:49:00 -0400576out:
577 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
578 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200579}
580
Dan Williams87c8c722008-08-19 15:15:35 -0400581/**
582 * @brief Get the min, max, and current TX power
583 *
584 * @param priv A pointer to struct lbs_private structure
585 * @param curlevel Current power level in dBm
586 * @param minlevel Minimum supported power level in dBm (optional)
587 * @param maxlevel Maximum supported power level in dBm (optional)
588 *
589 * @return 0 on success, error on failure
590 */
591int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
592 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200593{
Dan Williams87c8c722008-08-19 15:15:35 -0400594 struct cmd_ds_802_11_rf_tx_power cmd;
595 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200596
Holger Schurig9012b282007-05-25 11:27:16 -0400597 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200598
Dan Williams87c8c722008-08-19 15:15:35 -0400599 memset(&cmd, 0, sizeof(cmd));
600 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
601 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200602
Dan Williams87c8c722008-08-19 15:15:35 -0400603 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
604 if (ret == 0) {
605 *curlevel = le16_to_cpu(cmd.curlevel);
606 if (minlevel)
607 *minlevel = le16_to_cpu(cmd.minlevel);
608 if (maxlevel)
609 *maxlevel = le16_to_cpu(cmd.maxlevel);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200610 }
Holger Schurig9012b282007-05-25 11:27:16 -0400611
612 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400613 return ret;
614}
615
616/**
617 * @brief Set the TX power
618 *
619 * @param priv A pointer to struct lbs_private structure
620 * @param dbm The desired power level in dBm
621 *
622 * @return 0 on success, error on failure
623 */
624int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
625{
626 struct cmd_ds_802_11_rf_tx_power cmd;
627 int ret;
628
629 lbs_deb_enter(LBS_DEB_CMD);
630
631 memset(&cmd, 0, sizeof(cmd));
632 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
633 cmd.action = cpu_to_le16(CMD_ACT_SET);
634 cmd.curlevel = cpu_to_le16(dbm);
635
636 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
637
638 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
639
640 lbs_deb_leave(LBS_DEB_CMD);
641 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642}
643
Holger Schurige98a88d2008-03-19 14:25:58 +0100644static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -0400645 u16 cmd_action, void *pdata_buf)
646{
647 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
648
649 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
650 cmd->size =
651 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
652 S_DS_GEN);
653
654 monitor->action = cpu_to_le16(cmd_action);
655 if (cmd_action == CMD_ACT_SET) {
656 monitor->mode =
657 cpu_to_le16((u16) (*(u32 *) pdata_buf));
658 }
659
660 return 0;
661}
662
Javier Cardona85319f92008-05-24 10:59:49 +0100663static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200664{
Javier Cardona85319f92008-05-24 10:59:49 +0100665/* Bit Rate
666* 15:13 Reserved
667* 12 54 Mbps
668* 11 48 Mbps
669* 10 36 Mbps
670* 9 24 Mbps
671* 8 18 Mbps
672* 7 12 Mbps
673* 6 9 Mbps
674* 5 6 Mbps
675* 4 Reserved
676* 3 11 Mbps
677* 2 5.5 Mbps
678* 1 2 Mbps
679* 0 1 Mbps
680**/
681
682 uint16_t ratemask;
683 int i = lbs_data_rate_to_fw_index(rate);
684 if (lower_rates_ok)
685 ratemask = (0x1fef >> (12 - i));
686 else
687 ratemask = (1 << i);
688 return cpu_to_le16(ratemask);
689}
690
691int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
692 uint16_t cmd_action)
693{
694 struct cmd_ds_802_11_rate_adapt_rateset cmd;
695 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696
Holger Schurig8ff12da2007-08-02 11:54:31 -0400697 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200698
Javier Cardona85319f92008-05-24 10:59:49 +0100699 if (!priv->cur_rate && !priv->enablehwauto)
700 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200701
Javier Cardona85319f92008-05-24 10:59:49 +0100702 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
703
704 cmd.action = cpu_to_le16(cmd_action);
705 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
706 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
707 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
708 if (!ret && cmd_action == CMD_ACT_GET) {
709 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
710 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
711 }
712
713 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
714 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200715}
Javier Cardona85319f92008-05-24 10:59:49 +0100716EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200717
Dan Williams8e3c91b2007-12-11 15:50:59 -0500718/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500719 * @brief Set the data rate
720 *
721 * @param priv A pointer to struct lbs_private structure
722 * @param rate The desired data rate, or 0 to clear a locked rate
723 *
724 * @return 0 on success, error on failure
725 */
726int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
727{
728 struct cmd_ds_802_11_data_rate cmd;
729 int ret = 0;
730
731 lbs_deb_enter(LBS_DEB_CMD);
732
733 memset(&cmd, 0, sizeof(cmd));
734 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
735
736 if (rate > 0) {
737 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
738 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
739 if (cmd.rates[0] == 0) {
740 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
741 " 0x%02X\n", rate);
742 ret = 0;
743 goto out;
744 }
745 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
746 } else {
747 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400748 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749 }
750
David Woodhouse689442d2007-12-12 16:00:42 -0500751 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500752 if (ret)
753 goto out;
754
755 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
756
757 /* FIXME: get actual rates FW can do if this command actually returns
758 * all data rates supported.
759 */
760 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
761 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
762
763out:
764 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
765 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200766}
767
Dan Williams2dd4b262007-12-11 16:54:15 -0500768/**
769 * @brief Get the radio channel
770 *
771 * @param priv A pointer to struct lbs_private structure
772 *
773 * @return The channel on success, error on failure
774 */
775int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200776{
Dan Williams2dd4b262007-12-11 16:54:15 -0500777 struct cmd_ds_802_11_rf_channel cmd;
778 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200779
Holger Schurig8ff12da2007-08-02 11:54:31 -0400780 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200782 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500783 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
784 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200785
David Woodhouse689442d2007-12-12 16:00:42 -0500786 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500787 if (ret)
788 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200789
Dan Williamscb182a62007-12-11 17:35:51 -0500790 ret = le16_to_cpu(cmd.channel);
791 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500792
793out:
794 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
795 return ret;
796}
797
Holger Schurig73ab1f22008-04-02 16:52:19 +0200798int lbs_update_channel(struct lbs_private *priv)
799{
800 int ret;
801
802 /* the channel in f/w could be out of sync; get the current channel */
803 lbs_deb_enter(LBS_DEB_ASSOC);
804
805 ret = lbs_get_channel(priv);
806 if (ret > 0) {
807 priv->curbssparams.channel = ret;
808 ret = 0;
809 }
810 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
811 return ret;
812}
813
Dan Williams2dd4b262007-12-11 16:54:15 -0500814/**
815 * @brief Set the radio channel
816 *
817 * @param priv A pointer to struct lbs_private structure
818 * @param channel The desired channel, or 0 to clear a locked channel
819 *
820 * @return 0 on success, error on failure
821 */
822int lbs_set_channel(struct lbs_private *priv, u8 channel)
823{
824 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530825#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500826 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530827#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500828 int ret = 0;
829
830 lbs_deb_enter(LBS_DEB_CMD);
831
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200832 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500833 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
834 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
835 cmd.channel = cpu_to_le16(channel);
836
David Woodhouse689442d2007-12-12 16:00:42 -0500837 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500838 if (ret)
839 goto out;
840
Dan Williamscb182a62007-12-11 17:35:51 -0500841 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
842 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
843 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500844
845out:
846 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
847 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200848}
849
Holger Schurig69f90322007-11-23 15:43:44 +0100850static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200851 struct cmd_ds_command *cmd)
852{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200853
Holger Schurig8ff12da2007-08-02 11:54:31 -0400854 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400855 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400856 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400857 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200858
859 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000860 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
861 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
862 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
863 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
864 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
865 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200866
Holger Schurig8ff12da2007-08-02 11:54:31 -0400867 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200868 return 0;
869}
870
Holger Schurige98a88d2008-03-19 14:25:58 +0100871static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200872 u8 cmd_action, void *pdata_buf)
873{
Holger Schurig10078322007-11-15 18:05:47 -0500874 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200875
Holger Schurig9012b282007-05-25 11:27:16 -0400876 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200877
Holger Schurig10078322007-11-15 18:05:47 -0500878 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200879
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000880 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400881 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200882 {
883 struct cmd_ds_mac_reg_access *macreg;
884
885 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400886 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
887 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200888 macreg =
889 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
890 macreg;
891
892 macreg->action = cpu_to_le16(cmd_action);
893 macreg->offset = cpu_to_le16((u16) offval->offset);
894 macreg->value = cpu_to_le32(offval->value);
895
896 break;
897 }
898
Dan Williams0aef64d2007-08-02 11:31:18 -0400899 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 {
901 struct cmd_ds_bbp_reg_access *bbpreg;
902
903 cmdptr->size =
904 cpu_to_le16(sizeof
905 (struct cmd_ds_bbp_reg_access)
906 + S_DS_GEN);
907 bbpreg =
908 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
909 bbpreg;
910
911 bbpreg->action = cpu_to_le16(cmd_action);
912 bbpreg->offset = cpu_to_le16((u16) offval->offset);
913 bbpreg->value = (u8) offval->value;
914
915 break;
916 }
917
Dan Williams0aef64d2007-08-02 11:31:18 -0400918 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200919 {
920 struct cmd_ds_rf_reg_access *rfreg;
921
922 cmdptr->size =
923 cpu_to_le16(sizeof
924 (struct cmd_ds_rf_reg_access) +
925 S_DS_GEN);
926 rfreg =
927 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
928 rfreg;
929
930 rfreg->action = cpu_to_le16(cmd_action);
931 rfreg->offset = cpu_to_le16((u16) offval->offset);
932 rfreg->value = (u8) offval->value;
933
934 break;
935 }
936
937 default:
938 break;
939 }
940
Holger Schurig9012b282007-05-25 11:27:16 -0400941 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200942 return 0;
943}
944
Holger Schurige98a88d2008-03-19 14:25:58 +0100945static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200946 u16 cmd_action, void *pdata_buf)
947{
948 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400949 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200950
Dan Williams0aef64d2007-08-02 11:31:18 -0400951 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400952 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200953 cmd->result = 0;
954 bt_access->action = cpu_to_le16(cmd_action);
955
956 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400957 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200958 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400959 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200960 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400961 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200962 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400963 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200964 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400965 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200966 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
967 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400968 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200969 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400970 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400971 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
972 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400973 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -0400974 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200975 default:
976 break;
977 }
Holger Schurig8ff12da2007-08-02 11:54:31 -0400978 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200979 return 0;
980}
981
Holger Schurige98a88d2008-03-19 14:25:58 +0100982static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200983 u16 cmd_action, void *pdata_buf)
984{
985 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400986 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200987
Dan Williams0aef64d2007-08-02 11:31:18 -0400988 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400989 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 cmd->result = 0;
991
992 if (pdata_buf)
993 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
994 else
995 memset(fwt_access, 0, sizeof(*fwt_access));
996
997 fwt_access->action = cpu_to_le16(cmd_action);
998
Holger Schurig8ff12da2007-08-02 11:54:31 -0400999 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001000 return 0;
1001}
1002
David Woodhouse301eacb2007-12-11 15:23:59 -05001003int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1004 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001005{
David Woodhouse301eacb2007-12-11 15:23:59 -05001006 int ret;
1007
Holger Schurig8ff12da2007-08-02 11:54:31 -04001008 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001009
David Woodhouse301eacb2007-12-11 15:23:59 -05001010 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001011 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001012 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001013
David Woodhouse301eacb2007-12-11 15:23:59 -05001014 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001015
David Woodhouse689442d2007-12-12 16:00:42 -05001016 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001017
Holger Schurig8ff12da2007-08-02 11:54:31 -04001018 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001019 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001020}
1021
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001022static int __lbs_mesh_config_send(struct lbs_private *priv,
1023 struct cmd_ds_mesh_config *cmd,
1024 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001025{
1026 int ret;
1027
1028 lbs_deb_enter(LBS_DEB_CMD);
1029
1030 cmd->hdr.command = cpu_to_le16(CMD_MESH_CONFIG);
1031 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1032 cmd->hdr.result = 0;
1033
1034 cmd->type = cpu_to_le16(type);
1035 cmd->action = cpu_to_le16(action);
1036
1037 ret = lbs_cmd_with_response(priv, CMD_MESH_CONFIG, cmd);
1038
1039 lbs_deb_leave(LBS_DEB_CMD);
1040 return ret;
1041}
1042
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001043int lbs_mesh_config_send(struct lbs_private *priv,
1044 struct cmd_ds_mesh_config *cmd,
1045 uint16_t action, uint16_t type)
1046{
1047 int ret;
1048
1049 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1050 return -EOPNOTSUPP;
1051
1052 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1053 return ret;
1054}
1055
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001056/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1057 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1058 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1059 * lbs_mesh_config_send.
1060 */
1061int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001062{
1063 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001064 struct mrvl_meshie *ie;
David Woodhouse23a397a2007-12-11 18:56:42 -05001065
1066 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001067 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001068 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001069
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001070 switch (action) {
1071 case CMD_ACT_MESH_CONFIG_START:
1072 ie->hdr.id = MFIE_TYPE_GENERIC;
1073 ie->val.oui[0] = 0x00;
1074 ie->val.oui[1] = 0x50;
1075 ie->val.oui[2] = 0x43;
1076 ie->val.type = MARVELL_MESH_IE_TYPE;
1077 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1078 ie->val.version = MARVELL_MESH_IE_VERSION;
1079 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1080 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1081 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1082 ie->val.mesh_id_len = priv->mesh_ssid_len;
1083 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
1084 ie->hdr.len = sizeof(struct mrvl_meshie_val) -
1085 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1086 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1087 break;
1088 case CMD_ACT_MESH_CONFIG_STOP:
1089 break;
1090 default:
1091 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001092 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001093 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1094 action, priv->mesh_tlv, chan,
David Woodhouse06113c12007-12-11 22:52:03 -05001095 escape_essid(priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001096
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001097 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001098}
1099
Brajesh Dave96287ac2007-11-20 17:44:28 -05001100static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1101 struct cmd_ds_command *cmd,
1102 u16 cmd_action)
1103{
1104 struct cmd_ds_802_11_beacon_control
1105 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001106
1107 lbs_deb_enter(LBS_DEB_CMD);
1108 cmd->size =
1109 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1110 + S_DS_GEN);
1111 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1112
1113 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001114 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1115 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001116
1117 lbs_deb_leave(LBS_DEB_CMD);
1118 return 0;
1119}
1120
David Woodhouse681ffbb2007-12-15 20:04:54 -05001121static void lbs_queue_cmd(struct lbs_private *priv,
1122 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001123{
1124 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001125 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001126
Holger Schurig8ff12da2007-08-02 11:54:31 -04001127 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001128
David Woodhousec4ab4122007-12-15 00:41:51 -05001129 if (!cmdnode) {
1130 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001131 goto done;
1132 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001133 if (!cmdnode->cmdbuf->size) {
1134 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1135 goto done;
1136 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001137 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001138
1139 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001140 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001141 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001142
Dan Williams0aef64d2007-08-02 11:31:18 -04001143 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001144 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001145 addtail = 0;
1146 }
1147 }
1148
David Woodhouseaa21c002007-12-08 20:04:36 +00001149 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001150
David Woodhouseac472462007-12-08 00:35:00 +00001151 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001152 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001153 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001154 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001155
David Woodhouseaa21c002007-12-08 20:04:36 +00001156 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001157
Holger Schurig8ff12da2007-08-02 11:54:31 -04001158 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001159 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001160
1161done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001162 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001163}
1164
David Woodhouse18c52e72007-12-17 16:03:58 -05001165static void lbs_submit_command(struct lbs_private *priv,
1166 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001167{
1168 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001169 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001170 uint16_t cmdsize;
1171 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001172 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001173 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001174
Holger Schurig8ff12da2007-08-02 11:54:31 -04001175 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001176
Dan Williamsddac4522007-12-11 13:49:39 -05001177 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001178
David Woodhouseaa21c002007-12-08 20:04:36 +00001179 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001180 priv->cur_cmd = cmdnode;
1181 priv->cur_cmd_retcode = 0;
1182 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001183
Dan Williamsddac4522007-12-11 13:49:39 -05001184 cmdsize = le16_to_cpu(cmd->size);
1185 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001186
David Woodhouse18c52e72007-12-17 16:03:58 -05001187 /* These commands take longer */
1188 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE ||
1189 command == CMD_802_11_AUTHENTICATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001190 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001191
Holger Schurige5225b32008-03-26 10:04:44 +01001192 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1193 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001194 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001195
Dan Williamsddac4522007-12-11 13:49:39 -05001196 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001197
David Woodhoused9896ee2007-12-15 00:09:25 -05001198 if (ret) {
1199 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001200 /* Let the timer kick in and retry, and potentially reset
1201 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001202 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001203 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001204
1205 /* Setup the timer after transmit command */
David Woodhouse18c52e72007-12-17 16:03:58 -05001206 mod_timer(&priv->command_timer, jiffies + timeo);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001207
David Woodhouse18c52e72007-12-17 16:03:58 -05001208 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209}
1210
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001211/**
1212 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001213 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001214 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001215static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001216 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001217{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001218 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001219
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001220 if (!cmdnode)
1221 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001222
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001223 cmdnode->callback = NULL;
1224 cmdnode->callback_arg = 0;
1225
1226 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1227
1228 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1229 out:
1230 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001231}
1232
Holger Schurig69f90322007-11-23 15:43:44 +01001233static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1234 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001235{
1236 unsigned long flags;
1237
David Woodhouseaa21c002007-12-08 20:04:36 +00001238 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001239 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001240 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001241}
1242
David Woodhouse183aeac2007-12-15 01:52:54 -05001243void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1244 int result)
1245{
1246 if (cmd == priv->cur_cmd)
1247 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001248
David Woodhouseae125bf2007-12-15 04:22:52 -05001249 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001250 cmd->cmdwaitqwoken = 1;
1251 wake_up_interruptible(&cmd->cmdwait_q);
1252
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001253 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001254 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001255 priv->cur_cmd = NULL;
1256}
1257
Dan Williamsd5db2df2008-08-21 17:51:07 -04001258int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001259{
David Woodhousea7c45892007-12-17 22:43:48 -05001260 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001261 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001262
Holger Schurig9012b282007-05-25 11:27:16 -04001263 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001264
David Woodhousea7c45892007-12-17 22:43:48 -05001265 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1266 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001267
Dan Williamsd5db2df2008-08-21 17:51:07 -04001268 /* Only v8 and below support setting the preamble */
1269 if (priv->fwrelease < 0x09000000) {
1270 switch (preamble) {
1271 case RADIO_PREAMBLE_SHORT:
1272 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1273 goto out;
1274 /* Fall through */
1275 case RADIO_PREAMBLE_AUTO:
1276 case RADIO_PREAMBLE_LONG:
1277 cmd.control = cpu_to_le16(preamble);
1278 break;
1279 default:
1280 goto out;
1281 }
David Woodhousea7c45892007-12-17 22:43:48 -05001282 }
1283
Dan Williamsd5db2df2008-08-21 17:51:07 -04001284 if (radio_on)
1285 cmd.control |= cpu_to_le16(0x1);
1286 else {
1287 cmd.control &= cpu_to_le16(~0x1);
1288 priv->txpower_cur = 0;
1289 }
David Woodhousea7c45892007-12-17 22:43:48 -05001290
Dan Williamsd5db2df2008-08-21 17:51:07 -04001291 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1292 radio_on ? "ON" : "OFF", preamble);
1293
1294 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001295
1296 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001297
Dan Williamsd5db2df2008-08-21 17:51:07 -04001298out:
Holger Schurig9012b282007-05-25 11:27:16 -04001299 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300 return ret;
1301}
1302
Holger Schurigc97329e2008-03-18 11:20:21 +01001303void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001304{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001305 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001306
Holger Schurig9012b282007-05-25 11:27:16 -04001307 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308
Holger Schurig835d3ac2008-03-12 16:05:40 +01001309 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001310 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001311 cmd.reserved = 0;
1312
David Woodhouse75bf45a2008-05-20 13:32:45 +01001313 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001314
Holger Schurigc97329e2008-03-18 11:20:21 +01001315 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001316}
1317
1318/**
1319 * @brief This function prepare the command before send to firmware.
1320 *
Holger Schurig69f90322007-11-23 15:43:44 +01001321 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001322 * @param cmd_no command number
1323 * @param cmd_action command action: GET or SET
1324 * @param wait_option wait option: wait response or not
1325 * @param cmd_oid cmd oid: treated as sub command
1326 * @param pdata_buf A pointer to informaion buffer
1327 * @return 0 or -1
1328 */
Holger Schurig69f90322007-11-23 15:43:44 +01001329int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001330 u16 cmd_no,
1331 u16 cmd_action,
1332 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1333{
1334 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001335 struct cmd_ctrl_node *cmdnode;
1336 struct cmd_ds_command *cmdptr;
1337 unsigned long flags;
1338
Holger Schurig8ff12da2007-08-02 11:54:31 -04001339 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001340
David Woodhouseaa21c002007-12-08 20:04:36 +00001341 if (!priv) {
1342 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001343 ret = -1;
1344 goto done;
1345 }
1346
David Woodhouseaa21c002007-12-08 20:04:36 +00001347 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001348 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349 ret = -1;
1350 goto done;
1351 }
1352
Holger Schurig0d61d042007-12-05 17:58:06 +01001353 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001354
1355 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001356 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357
1358 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001359 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001360 ret = -1;
1361 goto done;
1362 }
1363
Holger Schurige98a88d2008-03-19 14:25:58 +01001364 cmdnode->callback = NULL;
1365 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001366
Dan Williamsddac4522007-12-11 13:49:39 -05001367 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001368
Holger Schurig8ff12da2007-08-02 11:54:31 -04001369 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001370
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001371 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001372 priv->seqnum++;
1373 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001374
David Woodhouse981f1872007-05-25 23:36:54 -04001375 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376 cmdptr->result = 0;
1377
1378 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001379 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001380 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381 break;
1382
Dan Williams0aef64d2007-08-02 11:31:18 -04001383 case CMD_802_11_ASSOCIATE:
1384 case CMD_802_11_REASSOCIATE:
Holger Schurig10078322007-11-15 18:05:47 -05001385 ret = lbs_cmd_80211_associate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001386 break;
1387
Dan Williams0aef64d2007-08-02 11:31:18 -04001388 case CMD_802_11_AUTHENTICATE:
Holger Schurig10078322007-11-15 18:05:47 -05001389 ret = lbs_cmd_80211_authenticate(priv, cmdptr, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390 break;
1391
Dan Williams0aef64d2007-08-02 11:31:18 -04001392 case CMD_MAC_REG_ACCESS:
1393 case CMD_BBP_REG_ACCESS:
1394 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001395 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001396 break;
1397
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001398 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001399 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001400 cmd_action, pdata_buf);
1401 break;
1402
Dan Williams0aef64d2007-08-02 11:31:18 -04001403 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001404 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001405 break;
1406
Dan Williams0aef64d2007-08-02 11:31:18 -04001407 case CMD_802_11_SET_AFC:
1408 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409
1410 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001411 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1412 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001413
1414 memmove(&cmdptr->params.afc,
1415 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1416
1417 ret = 0;
1418 goto done;
1419
Dan Williams0aef64d2007-08-02 11:31:18 -04001420 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001421 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422 cmd_no, cmd_action);
1423 break;
1424
Dan Williams0aef64d2007-08-02 11:31:18 -04001425 case CMD_802_11_TPC_CFG:
1426 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001427 cmdptr->size =
1428 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1429 S_DS_GEN);
1430
1431 memmove(&cmdptr->params.tpccfg,
1432 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1433
1434 ret = 0;
1435 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001436 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437 {
1438 struct mrvlietypes_ledgpio *gpio =
1439 (struct mrvlietypes_ledgpio*)
1440 cmdptr->params.ledgpio.data;
1441
1442 memmove(&cmdptr->params.ledgpio,
1443 pdata_buf,
1444 sizeof(struct cmd_ds_802_11_led_ctrl));
1445
1446 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001447 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001448
1449#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1450 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001451 cpu_to_le16(le16_to_cpu(gpio->header.len)
1452 + S_DS_GEN
1453 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1454 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001455
1456 ret = 0;
1457 break;
1458 }
David Woodhouse5844d122007-12-18 02:01:37 -05001459
Dan Williams0aef64d2007-08-02 11:31:18 -04001460 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001461 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001462 break;
1463
Dan Williams0aef64d2007-08-02 11:31:18 -04001464 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001465 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001466 break;
1467
Dan Williams0aef64d2007-08-02 11:31:18 -04001468 case CMD_GET_TSF:
1469 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001470 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1471 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472 ret = 0;
1473 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001474 case CMD_802_11_BEACON_CTRL:
1475 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1476 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001477 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001478 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001479 ret = -1;
1480 break;
1481 }
1482
1483 /* return error, since the command preparation failed */
1484 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001485 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001486 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487 ret = -1;
1488 goto done;
1489 }
1490
1491 cmdnode->cmdwaitqwoken = 0;
1492
David Woodhouse681ffbb2007-12-15 20:04:54 -05001493 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001494 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001495
Dan Williams0aef64d2007-08-02 11:31:18 -04001496 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001497 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 might_sleep();
1499 wait_event_interruptible(cmdnode->cmdwait_q,
1500 cmdnode->cmdwaitqwoken);
1501 }
1502
David Woodhouseaa21c002007-12-08 20:04:36 +00001503 spin_lock_irqsave(&priv->driver_lock, flags);
1504 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001505 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001506 priv->cur_cmd_retcode);
1507 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001508 ret = -1;
1509 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001510 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511
1512done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001513 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001514 return ret;
1515}
1516
1517/**
1518 * @brief This function allocates the command buffer and link
1519 * it to command free queue.
1520 *
Holger Schurig69f90322007-11-23 15:43:44 +01001521 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001522 * @return 0 or -1
1523 */
Holger Schurig69f90322007-11-23 15:43:44 +01001524int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001525{
1526 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001527 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001528 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001529 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001530
Holger Schurig8ff12da2007-08-02 11:54:31 -04001531 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001532
Dan Williamsddac4522007-12-11 13:49:39 -05001533 /* Allocate and initialize the command array */
1534 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1535 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001536 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001537 ret = -1;
1538 goto done;
1539 }
Dan Williamsddac4522007-12-11 13:49:39 -05001540 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001541
Dan Williamsddac4522007-12-11 13:49:39 -05001542 /* Allocate and initialize each command buffer in the command array */
1543 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1544 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1545 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001546 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001547 ret = -1;
1548 goto done;
1549 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001550 }
1551
Dan Williamsddac4522007-12-11 13:49:39 -05001552 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1553 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1554 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001555 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001556 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001557
1558done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001559 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 return ret;
1561}
1562
1563/**
1564 * @brief This function frees the command buffer.
1565 *
Holger Schurig69f90322007-11-23 15:43:44 +01001566 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001567 * @return 0 or -1
1568 */
Holger Schurig69f90322007-11-23 15:43:44 +01001569int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001570{
Dan Williamsddac4522007-12-11 13:49:39 -05001571 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001572 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573
Holger Schurig8ff12da2007-08-02 11:54:31 -04001574 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001575
1576 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001577 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001578 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 goto done;
1580 }
1581
Dan Williamsddac4522007-12-11 13:49:39 -05001582 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001583
1584 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001585 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1586 if (cmdarray[i].cmdbuf) {
1587 kfree(cmdarray[i].cmdbuf);
1588 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001589 }
1590 }
1591
1592 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001593 if (priv->cmd_array) {
1594 kfree(priv->cmd_array);
1595 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001596 }
1597
1598done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001599 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001600 return 0;
1601}
1602
1603/**
1604 * @brief This function gets a free command node if available in
1605 * command free queue.
1606 *
Holger Schurig69f90322007-11-23 15:43:44 +01001607 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001608 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1609 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001610static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611{
1612 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001613 unsigned long flags;
1614
Holger Schurig8ff12da2007-08-02 11:54:31 -04001615 lbs_deb_enter(LBS_DEB_HOST);
1616
David Woodhouseaa21c002007-12-08 20:04:36 +00001617 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001618 return NULL;
1619
David Woodhouseaa21c002007-12-08 20:04:36 +00001620 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621
David Woodhouseaa21c002007-12-08 20:04:36 +00001622 if (!list_empty(&priv->cmdfreeq)) {
1623 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001624 struct cmd_ctrl_node, list);
1625 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001626 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001627 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001628 tempnode = NULL;
1629 }
1630
David Woodhouseaa21c002007-12-08 20:04:36 +00001631 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001632
Holger Schurig8ff12da2007-08-02 11:54:31 -04001633 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001634 return tempnode;
1635}
1636
1637/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001638 * @brief This function executes next command in command
1639 * pending queue. It will put fimware back to PS mode
1640 * if applicable.
1641 *
Holger Schurig69f90322007-11-23 15:43:44 +01001642 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001643 * @return 0 or -1
1644 */
Holger Schurig69f90322007-11-23 15:43:44 +01001645int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001646{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001647 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001648 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001649 unsigned long flags;
1650 int ret = 0;
1651
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001652 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1653 * only caller to us is lbs_thread() and we get even when a
1654 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001655 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001656
David Woodhouseaa21c002007-12-08 20:04:36 +00001657 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658
David Woodhouseaa21c002007-12-08 20:04:36 +00001659 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001660 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001661 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001662 ret = -1;
1663 goto done;
1664 }
1665
David Woodhouseaa21c002007-12-08 20:04:36 +00001666 if (!list_empty(&priv->cmdpendingq)) {
1667 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001668 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001669 }
1670
David Woodhouseaa21c002007-12-08 20:04:36 +00001671 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672
1673 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001674 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675
Dan Williamsddac4522007-12-11 13:49:39 -05001676 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001677 if ((priv->psstate == PS_STATE_SLEEP) ||
1678 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001679 lbs_deb_host(
1680 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001681 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001682 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001683 ret = -1;
1684 goto done;
1685 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001686 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001687 "0x%04x in psstate %d\n",
1688 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001689 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001690 /*
1691 * 1. Non-PS command:
1692 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001693 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694 * 2. PS command but not Exit_PS:
1695 * Ignore it.
1696 * 3. PS command Exit_PS:
1697 * Set needtowakeup to TRUE if current state is SLEEP,
1698 * otherwise send this command down to firmware
1699 * immediately.
1700 */
Dan Williamsddac4522007-12-11 13:49:39 -05001701 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001702 /* Prepare to send Exit PS,
1703 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001704 if ((priv->psstate == PS_STATE_SLEEP)
1705 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001706 ) {
1707 /* w/ new scheme, it will not reach here.
1708 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001709 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001710 } else
Holger Schurig10078322007-11-15 18:05:47 -05001711 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001712
1713 ret = 0;
1714 goto done;
1715 } else {
1716 /*
1717 * PS command. Ignore it if it is not Exit_PS.
1718 * otherwise send it down immediately.
1719 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001720 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001721
Holger Schurig8ff12da2007-08-02 11:54:31 -04001722 lbs_deb_host(
1723 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001724 psm->action);
1725 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001726 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001727 lbs_deb_host(
1728 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001729 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001730 spin_lock_irqsave(&priv->driver_lock, flags);
1731 lbs_complete_command(priv, cmdnode, 0);
1732 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001733
1734 ret = 0;
1735 goto done;
1736 }
1737
David Woodhouseaa21c002007-12-08 20:04:36 +00001738 if ((priv->psstate == PS_STATE_SLEEP) ||
1739 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001740 lbs_deb_host(
1741 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\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);
David Woodhouseaa21c002007-12-08 20:04:36 +00001746 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001747
1748 ret = 0;
1749 goto done;
1750 }
1751
Holger Schurig8ff12da2007-08-02 11:54:31 -04001752 lbs_deb_host(
1753 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001754 }
1755 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001756 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001757 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001758 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001759 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001760 } else {
1761 /*
1762 * check if in power save mode, if yes, put the device back
1763 * to PS mode
1764 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001765 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1766 (priv->psstate == PS_STATE_FULL_POWER) &&
1767 ((priv->connect_status == LBS_CONNECTED) ||
1768 (priv->mesh_connect_status == LBS_CONNECTED))) {
1769 if (priv->secinfo.WPAenabled ||
1770 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001771 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001772 if (priv->wpa_mcast_key.len ||
1773 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001774 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001775 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1776 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001777 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001778 }
1779 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001780 lbs_deb_host(
1781 "EXEC_NEXT_CMD: cmdpendingq empty, "
1782 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001783 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001784 }
1785 }
1786 }
1787
1788 ret = 0;
1789done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001790 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001791 return ret;
1792}
1793
Holger Schurig69f90322007-11-23 15:43:44 +01001794void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001795{
1796 union iwreq_data iwrq;
1797 u8 buf[50];
1798
Holger Schurig8ff12da2007-08-02 11:54:31 -04001799 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001800
1801 memset(&iwrq, 0, sizeof(union iwreq_data));
1802 memset(buf, 0, sizeof(buf));
1803
1804 snprintf(buf, sizeof(buf) - 1, "%s", str);
1805
1806 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1807
1808 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001809 lbs_deb_wext("event indication string %s\n", (char *)buf);
1810 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1811 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001812
Holger Schurig634b8f42007-05-25 13:05:16 -04001813 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001814
Holger Schurig8ff12da2007-08-02 11:54:31 -04001815 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816}
1817
Holger Schurigf539f2e2008-03-26 13:22:11 +01001818static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001819{
1820 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001821 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001822
Holger Schurig8ff12da2007-08-02 11:54:31 -04001823 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001824 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1825 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001826
Holger Schurigf539f2e2008-03-26 13:22:11 +01001827 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1828 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001829 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001830 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001831 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832 }
Holger Schurig7919b892008-04-01 14:50:43 +02001833
1834 spin_lock_irqsave(&priv->driver_lock, flags);
1835
Holger Schuriga01f5452008-06-04 11:10:40 +02001836 /* We don't get a response on the sleep-confirmation */
1837 priv->dnld_sent = DNLD_RES_RECEIVED;
1838
Holger Schurig7919b892008-04-01 14:50:43 +02001839 /* If nothing to do, go back to sleep (?) */
1840 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1841 priv->psstate = PS_STATE_SLEEP;
1842
1843 spin_unlock_irqrestore(&priv->driver_lock, flags);
1844
1845out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001846 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001847}
1848
Holger Schurig69f90322007-11-23 15:43:44 +01001849void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001850{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001851 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001852
1853 /*
1854 * PS is currently supported only in Infrastructure mode
1855 * Remove this check if it is to be supported in IBSS mode also
1856 */
1857
Holger Schurig10078322007-11-15 18:05:47 -05001858 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001859 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001860
Holger Schurig8ff12da2007-08-02 11:54:31 -04001861 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001862}
1863
1864/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001865 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001866 *
Holger Schurig69f90322007-11-23 15:43:44 +01001867 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001868 * @param wait_option wait response or not
1869 * @return n/a
1870 */
Holger Schurig69f90322007-11-23 15:43:44 +01001871void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001872{
David Woodhouse981f1872007-05-25 23:36:54 -04001873 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001874
Holger Schurig8ff12da2007-08-02 11:54:31 -04001875 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001876
Holger Schurig10078322007-11-15 18:05:47 -05001877 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001878
Holger Schurig10078322007-11-15 18:05:47 -05001879 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001880 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001881 wait_option, 0, &Localpsmode);
1882
Holger Schurig8ff12da2007-08-02 11:54:31 -04001883 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001884}
1885
1886/**
1887 * @brief This function checks condition and prepares to
1888 * send sleep confirm command to firmware if ok.
1889 *
Holger Schurig69f90322007-11-23 15:43:44 +01001890 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001891 * @param psmode Power Saving mode
1892 * @return n/a
1893 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001894void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001895{
1896 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001897 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898
Holger Schurig8ff12da2007-08-02 11:54:31 -04001899 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001900
Holger Schuriga01f5452008-06-04 11:10:40 +02001901 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001902 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001903 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001904 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001905 }
1906
Holger Schurig7919b892008-04-01 14:50:43 +02001907 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001908 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001909 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001910 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001911 }
Holger Schurig7919b892008-04-01 14:50:43 +02001912
1913 /* Pending events or command responses? */
1914 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001915 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001916 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001917 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001918 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001919
1920 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001921 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001922 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001924 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001925 }
1926
Holger Schurig8ff12da2007-08-02 11:54:31 -04001927 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001928}
Holger Schurig675787e2007-12-05 17:58:11 +01001929
1930
Anna Neal0112c9e2008-09-11 11:17:25 -07001931/**
1932 * @brief Configures the transmission power control functionality.
1933 *
1934 * @param priv A pointer to struct lbs_private structure
1935 * @param enable Transmission power control enable
1936 * @param p0 Power level when link quality is good (dBm).
1937 * @param p1 Power level when link quality is fair (dBm).
1938 * @param p2 Power level when link quality is poor (dBm).
1939 * @param usesnr Use Signal to Noise Ratio in TPC
1940 *
1941 * @return 0 on success
1942 */
1943int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1944 int8_t p2, int usesnr)
1945{
1946 struct cmd_ds_802_11_tpc_cfg cmd;
1947 int ret;
1948
1949 memset(&cmd, 0, sizeof(cmd));
1950 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1951 cmd.action = cpu_to_le16(CMD_ACT_SET);
1952 cmd.enable = !!enable;
Anna Neal3ed6e082008-09-26 11:34:35 -04001953 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001954 cmd.P0 = p0;
1955 cmd.P1 = p1;
1956 cmd.P2 = p2;
1957
1958 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1959
1960 return ret;
1961}
1962
1963/**
1964 * @brief Configures the power adaptation settings.
1965 *
1966 * @param priv A pointer to struct lbs_private structure
1967 * @param enable Power adaptation enable
1968 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
1969 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
1970 * @param p2 Power level for 48 and 54 Mbps (dBm).
1971 *
1972 * @return 0 on Success
1973 */
1974
1975int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
1976 int8_t p1, int8_t p2)
1977{
1978 struct cmd_ds_802_11_pa_cfg cmd;
1979 int ret;
1980
1981 memset(&cmd, 0, sizeof(cmd));
1982 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1983 cmd.action = cpu_to_le16(CMD_ACT_SET);
1984 cmd.enable = !!enable;
1985 cmd.P0 = p0;
1986 cmd.P1 = p1;
1987 cmd.P2 = p2;
1988
1989 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
1990
1991 return ret;
1992}
1993
1994
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001995static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
1996 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
1997 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
1998 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01001999{
Holger Schurig675787e2007-12-05 17:58:11 +01002000 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002001
2002 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002003
David Woodhouseaa21c002007-12-08 20:04:36 +00002004 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002005 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002006 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002007 goto done;
2008 }
2009
2010 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002011 if (cmdnode == NULL) {
2012 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2013
2014 /* Wake up main thread to execute next command */
2015 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002016 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002017 goto done;
2018 }
2019
David Woodhouse448a51a2007-12-08 00:59:54 +00002020 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002021 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002022
Dan Williams7ad994d2007-12-11 12:33:30 -05002023 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002024 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002025
Holger Schurig675787e2007-12-05 17:58:11 +01002026 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002027 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002028 cmdnode->cmdbuf->command = cpu_to_le16(command);
2029 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2030 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2031 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002032
2033 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2034
Holger Schurig675787e2007-12-05 17:58:11 +01002035 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002036 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002037 wake_up_interruptible(&priv->waitq);
2038
David Woodhouse3399ea52007-12-15 03:09:33 -05002039 done:
2040 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2041 return cmdnode;
2042}
2043
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002044void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2045 struct cmd_header *in_cmd, int in_cmd_size)
2046{
2047 lbs_deb_enter(LBS_DEB_CMD);
2048 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2049 lbs_cmd_async_callback, 0);
2050 lbs_deb_leave(LBS_DEB_CMD);
2051}
2052
David Woodhouse3399ea52007-12-15 03:09:33 -05002053int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2054 struct cmd_header *in_cmd, int in_cmd_size,
2055 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2056 unsigned long callback_arg)
2057{
2058 struct cmd_ctrl_node *cmdnode;
2059 unsigned long flags;
2060 int ret = 0;
2061
2062 lbs_deb_enter(LBS_DEB_HOST);
2063
2064 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2065 callback, callback_arg);
2066 if (IS_ERR(cmdnode)) {
2067 ret = PTR_ERR(cmdnode);
2068 goto done;
2069 }
2070
Holger Schurig675787e2007-12-05 17:58:11 +01002071 might_sleep();
2072 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2073
David Woodhouseaa21c002007-12-08 20:04:36 +00002074 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002075 ret = cmdnode->result;
2076 if (ret)
2077 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2078 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002079
David Woodhousead12d0f2007-12-15 02:06:16 -05002080 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002081 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002082
2083done:
2084 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2085 return ret;
2086}
Dan Williams14e865b2007-12-10 15:11:23 -05002087EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002088
2089