blob: 0a324dcd264cccf65821b41ee1dee4802aa6ab18 [file] [log] [blame]
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001/**
2 * This file contains the handling of command.
3 * It prepares command and sends it to firmware when it is ready.
4 */
5
6#include <net/iw_handler.h>
John W. Linville7e272fc2008-09-24 18:13:14 -04007#include <net/lib80211.h>
Holger Schurig7919b892008-04-01 14:50:43 +02008#include <linux/kfifo.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +04009#include <linux/sched.h>
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020010#include "host.h"
11#include "hostcmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020012#include "decl.h"
13#include "defs.h"
14#include "dev.h"
Holger Schurig697900a2008-04-02 16:27:10 +020015#include "assoc.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020016#include "wext.h"
Dan Williams6e66f032007-12-11 12:42:16 -050017#include "cmd.h"
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020018
David Woodhouse2fd6cfe2007-12-11 17:44:10 -050019static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv);
Holger Schurig0d61d042007-12-05 17:58:06 +010020
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020021
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020022/**
Holger Schurig8db4a2b2008-03-19 10:11:00 +010023 * @brief Simple callback that copies response back into command
24 *
25 * @param priv A pointer to struct lbs_private structure
26 * @param extra A pointer to the original command structure for which
27 * 'resp' is a response
28 * @param resp A pointer to the command response
29 *
30 * @return 0 on success, error on failure
31 */
32int lbs_cmd_copyback(struct lbs_private *priv, unsigned long extra,
33 struct cmd_header *resp)
34{
35 struct cmd_header *buf = (void *)extra;
36 uint16_t copy_len;
37
38 copy_len = min(le16_to_cpu(buf->size), le16_to_cpu(resp->size));
39 memcpy(buf, resp, copy_len);
40 return 0;
41}
42EXPORT_SYMBOL_GPL(lbs_cmd_copyback);
43
44/**
45 * @brief Simple callback that ignores the result. Use this if
46 * you just want to send a command to the hardware, but don't
47 * care for the result.
48 *
49 * @param priv ignored
50 * @param extra ignored
51 * @param resp ignored
52 *
53 * @return 0 for success
54 */
55static int lbs_cmd_async_callback(struct lbs_private *priv, unsigned long extra,
56 struct cmd_header *resp)
57{
58 return 0;
59}
60
61
62/**
Dan Williams852e1f22007-12-10 15:24:47 -050063 * @brief Checks whether a command is allowed in Power Save mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020064 *
65 * @param command the command ID
Dan Williams852e1f22007-12-10 15:24:47 -050066 * @return 1 if allowed, 0 if not allowed
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020067 */
Dan Williams852e1f22007-12-10 15:24:47 -050068static u8 is_command_allowed_in_ps(u16 cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020069{
Dan Williams852e1f22007-12-10 15:24:47 -050070 switch (cmd) {
71 case CMD_802_11_RSSI:
72 return 1;
73 default:
74 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020075 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020076 return 0;
77}
78
Dan Williams6e66f032007-12-11 12:42:16 -050079/**
80 * @brief Updates the hardware details like MAC address and regulatory region
81 *
82 * @param priv A pointer to struct lbs_private structure
83 *
84 * @return 0 on success, error on failure
85 */
86int lbs_update_hw_spec(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020087{
Dan Williams6e66f032007-12-11 12:42:16 -050088 struct cmd_ds_get_hw_spec cmd;
89 int ret = -1;
90 u32 i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020091
Holger Schurig9012b282007-05-25 11:27:16 -040092 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -020093
Dan Williams6e66f032007-12-11 12:42:16 -050094 memset(&cmd, 0, sizeof(cmd));
95 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
96 memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN);
David Woodhouse689442d2007-12-12 16:00:42 -050097 ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd);
Dan Williams6e66f032007-12-11 12:42:16 -050098 if (ret)
99 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200100
Dan Williams6e66f032007-12-11 12:42:16 -0500101 priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500102
Holger Schurigdac10a92008-01-16 15:55:22 +0100103 /* The firmware release is in an interesting format: the patch
104 * level is in the most significant nibble ... so fix that: */
105 priv->fwrelease = le32_to_cpu(cmd.fwrelease);
106 priv->fwrelease = (priv->fwrelease << 8) |
107 (priv->fwrelease >> 24 & 0xff);
108
109 /* Some firmware capabilities:
110 * CF card firmware 5.0.16p0: cap 0x00000303
111 * USB dongle firmware 5.110.17p2: cap 0x00000303
112 */
Johannes Berge1749612008-10-27 15:59:26 -0700113 lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n",
114 cmd.permanentaddr,
Holger Schurigdac10a92008-01-16 15:55:22 +0100115 priv->fwrelease >> 24 & 0xff,
116 priv->fwrelease >> 16 & 0xff,
117 priv->fwrelease >> 8 & 0xff,
118 priv->fwrelease & 0xff,
119 priv->fwcapinfo);
Dan Williams6e66f032007-12-11 12:42:16 -0500120 lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n",
121 cmd.hwifversion, cmd.version);
122
Bing Zhao684d6b32009-03-25 09:51:16 -0700123 /* Determine mesh_fw_ver from fwrelease and fwcapinfo */
124 /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */
125 /* 5.110.22 have mesh command with 0xa3 command id */
126 /* 10.0.0.p0 FW brings in mesh config command with different id */
127 /* Check FW version MSB and initialize mesh_fw_ver */
128 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5)
129 priv->mesh_fw_ver = MESH_FW_OLD;
130 else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) &&
131 (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK))
132 priv->mesh_fw_ver = MESH_FW_NEW;
133 else
134 priv->mesh_fw_ver = MESH_NONE;
135
Dan Williams6e66f032007-12-11 12:42:16 -0500136 /* Clamp region code to 8-bit since FW spec indicates that it should
137 * only ever be 8-bit, even though the field size is 16-bit. Some firmware
138 * returns non-zero high 8 bits here.
Marek Vasut15483992009-07-16 19:19:53 +0200139 *
140 * Firmware version 4.0.102 used in CF8381 has region code shifted. We
141 * need to check for this problem and handle it properly.
Dan Williams6e66f032007-12-11 12:42:16 -0500142 */
Marek Vasut15483992009-07-16 19:19:53 +0200143 if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4)
144 priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF;
145 else
146 priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF;
Dan Williams6e66f032007-12-11 12:42:16 -0500147
148 for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) {
149 /* use the region code to search for the index */
150 if (priv->regioncode == lbs_region_code_to_index[i])
151 break;
152 }
153
154 /* if it's unidentified region code, use the default (USA) */
155 if (i >= MRVDRV_MAX_REGION_CODE) {
156 priv->regioncode = 0x10;
157 lbs_pr_info("unidentified region code; using the default (USA)\n");
158 }
159
160 if (priv->current_addr[0] == 0xff)
161 memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN);
162
163 memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN);
164 if (priv->mesh_dev)
165 memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN);
166
167 if (lbs_set_regiontable(priv, priv->regioncode, 0)) {
168 ret = -1;
169 goto out;
170 }
171
172 if (lbs_set_universaltable(priv, 0)) {
173 ret = -1;
174 goto out;
175 }
176
177out:
Holger Schurig9012b282007-05-25 11:27:16 -0400178 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams6e66f032007-12-11 12:42:16 -0500179 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200180}
181
Anna Neal582c1b52008-10-20 16:46:56 -0700182int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria,
183 struct wol_config *p_wol_config)
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500184{
185 struct cmd_ds_host_sleep cmd_config;
186 int ret;
187
David Woodhouse9fae8992007-12-15 03:46:44 -0500188 cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config));
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500189 cmd_config.criteria = cpu_to_le32(criteria);
David Woodhouse506e9022007-12-12 20:06:06 -0500190 cmd_config.gpio = priv->wol_gpio;
191 cmd_config.gap = priv->wol_gap;
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500192
Anna Neal582c1b52008-10-20 16:46:56 -0700193 if (p_wol_config != NULL)
194 memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config,
195 sizeof(struct wol_config));
196 else
197 cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE;
198
David Woodhouse689442d2007-12-12 16:00:42 -0500199 ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config);
David Woodhouse506e9022007-12-12 20:06:06 -0500200 if (!ret) {
Anna Neal582c1b52008-10-20 16:46:56 -0700201 if (criteria) {
202 lbs_deb_cmd("Set WOL criteria to %x\n", criteria);
203 priv->wol_criteria = criteria;
204 } else
205 memcpy((uint8_t *) p_wol_config,
206 (uint8_t *)&cmd_config.wol_conf,
207 sizeof(struct wol_config));
David Woodhouse506e9022007-12-12 20:06:06 -0500208 } else {
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500209 lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret);
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500210 }
David Woodhouse506e9022007-12-12 20:06:06 -0500211
David Woodhouse6ce4fd22007-12-12 15:19:29 -0500212 return ret;
213}
214EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg);
215
Holger Schurige98a88d2008-03-19 14:25:58 +0100216static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200217 u16 cmd_action)
218{
219 struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200220
Holger Schurig9012b282007-05-25 11:27:16 -0400221 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200222
Dan Williams0aef64d2007-08-02 11:31:18 -0400223 cmd->command = cpu_to_le16(CMD_802_11_PS_MODE);
David Woodhouse981f1872007-05-25 23:36:54 -0400224 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) +
225 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200226 psm->action = cpu_to_le16(cmd_action);
227 psm->multipledtim = 0;
David Woodhouse981f1872007-05-25 23:36:54 -0400228 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400229 case CMD_SUBCMD_ENTER_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400230 lbs_deb_cmd("PS command:" "SubCode- Enter PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200231
Holger Schurig252cf0d2007-08-02 13:09:34 -0400232 psm->locallisteninterval = 0;
Holger Schurig97605c32007-08-02 13:09:15 -0400233 psm->nullpktinterval = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200234 psm->multipledtim =
Holger Schurig56c46562007-08-02 13:09:49 -0400235 cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200236 break;
237
Dan Williams0aef64d2007-08-02 11:31:18 -0400238 case CMD_SUBCMD_EXIT_PS:
Holger Schurig9012b282007-05-25 11:27:16 -0400239 lbs_deb_cmd("PS command:" "SubCode- Exit PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200240 break;
241
Dan Williams0aef64d2007-08-02 11:31:18 -0400242 case CMD_SUBCMD_SLEEP_CONFIRMED:
Holger Schurig9012b282007-05-25 11:27:16 -0400243 lbs_deb_cmd("PS command: SubCode- sleep confirm\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200244 break;
245
246 default:
247 break;
248 }
249
Holger Schurig9012b282007-05-25 11:27:16 -0400250 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200251 return 0;
252}
253
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500254int lbs_cmd_802_11_inactivity_timeout(struct lbs_private *priv,
255 uint16_t cmd_action, uint16_t *timeout)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200256{
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500257 struct cmd_ds_802_11_inactivity_timeout cmd;
258 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200259
Holger Schurig8ff12da2007-08-02 11:54:31 -0400260 lbs_deb_enter(LBS_DEB_CMD);
261
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500262 cmd.hdr.command = cpu_to_le16(CMD_802_11_INACTIVITY_TIMEOUT);
263 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200264
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500265 cmd.action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200266
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500267 if (cmd_action == CMD_ACT_SET)
268 cmd.timeout = cpu_to_le16(*timeout);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200269 else
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500270 cmd.timeout = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200271
David Woodhouse6e5cc4f2007-12-17 23:04:37 -0500272 ret = lbs_cmd_with_response(priv, CMD_802_11_INACTIVITY_TIMEOUT, &cmd);
273
274 if (!ret)
275 *timeout = le16_to_cpu(cmd.timeout);
276
277 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200278 return 0;
279}
280
David Woodhouse3fbe1042007-12-17 23:48:31 -0500281int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action,
282 struct sleep_params *sp)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200283{
David Woodhouse3fbe1042007-12-17 23:48:31 -0500284 struct cmd_ds_802_11_sleep_params cmd;
285 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200286
Holger Schurig9012b282007-05-25 11:27:16 -0400287 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200288
Dan Williams0aef64d2007-08-02 11:31:18 -0400289 if (cmd_action == CMD_ACT_GET) {
David Woodhouse3fbe1042007-12-17 23:48:31 -0500290 memset(&cmd, 0, sizeof(cmd));
291 } else {
292 cmd.error = cpu_to_le16(sp->sp_error);
293 cmd.offset = cpu_to_le16(sp->sp_offset);
294 cmd.stabletime = cpu_to_le16(sp->sp_stabletime);
295 cmd.calcontrol = sp->sp_calcontrol;
296 cmd.externalsleepclk = sp->sp_extsleepclk;
297 cmd.reserved = cpu_to_le16(sp->sp_reserved);
298 }
299 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
300 cmd.action = cpu_to_le16(cmd_action);
301
302 ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd);
303
304 if (!ret) {
305 lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, "
306 "calcontrol 0x%x extsleepclk 0x%x\n",
307 le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset),
308 le16_to_cpu(cmd.stabletime), cmd.calcontrol,
309 cmd.externalsleepclk);
310
311 sp->sp_error = le16_to_cpu(cmd.error);
312 sp->sp_offset = le16_to_cpu(cmd.offset);
313 sp->sp_stabletime = le16_to_cpu(cmd.stabletime);
314 sp->sp_calcontrol = cmd.calcontrol;
315 sp->sp_extsleepclk = cmd.externalsleepclk;
316 sp->sp_reserved = le16_to_cpu(cmd.reserved);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200317 }
318
David Woodhouse3fbe1042007-12-17 23:48:31 -0500319 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200320 return 0;
321}
322
David Woodhousef70dd452007-12-18 00:18:05 -0500323int lbs_cmd_802_11_set_wep(struct lbs_private *priv, uint16_t cmd_action,
324 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200325{
David Woodhousef70dd452007-12-18 00:18:05 -0500326 struct cmd_ds_802_11_set_wep cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200327 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200328
Holger Schurig9012b282007-05-25 11:27:16 -0400329 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200330
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200331 memset(&cmd, 0, sizeof(cmd));
David Woodhousef70dd452007-12-18 00:18:05 -0500332 cmd.hdr.command = cpu_to_le16(CMD_802_11_SET_WEP);
333 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200334
David Woodhousef70dd452007-12-18 00:18:05 -0500335 cmd.action = cpu_to_le16(cmd_action);
336
337 if (cmd_action == CMD_ACT_ADD) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200338 int i;
339
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200340 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500341 cmd.keyindex = cpu_to_le16(assoc->wep_tx_keyidx &
342 CMD_WEP_KEY_INDEX_MASK);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200343
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200344 /* Copy key types and material to host command structure */
345 for (i = 0; i < 4; i++) {
David Woodhousef70dd452007-12-18 00:18:05 -0500346 struct enc_key *pkey = &assoc->wep_keys[i];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200347
348 switch (pkey->len) {
349 case KEY_LEN_WEP_40:
David Woodhousef70dd452007-12-18 00:18:05 -0500350 cmd.keytype[i] = CMD_TYPE_WEP_40_BIT;
351 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400352 lbs_deb_cmd("SET_WEP: add key %d (40 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200353 break;
354 case KEY_LEN_WEP_104:
David Woodhousef70dd452007-12-18 00:18:05 -0500355 cmd.keytype[i] = CMD_TYPE_WEP_104_BIT;
356 memmove(cmd.keymaterial[i], pkey->key, pkey->len);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400357 lbs_deb_cmd("SET_WEP: add key %d (104 bit)\n", i);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200358 break;
359 case 0:
360 break;
361 default:
Holger Schurig8ff12da2007-08-02 11:54:31 -0400362 lbs_deb_cmd("SET_WEP: invalid key %d, length %d\n",
David Woodhousef70dd452007-12-18 00:18:05 -0500363 i, pkey->len);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200364 ret = -1;
365 goto done;
366 break;
367 }
368 }
David Woodhousef70dd452007-12-18 00:18:05 -0500369 } else if (cmd_action == CMD_ACT_REMOVE) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200370 /* ACT_REMOVE clears _all_ WEP keys */
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200371
372 /* default tx key index */
David Woodhousef70dd452007-12-18 00:18:05 -0500373 cmd.keyindex = cpu_to_le16(priv->wep_tx_keyidx &
374 CMD_WEP_KEY_INDEX_MASK);
David Woodhouseaa21c002007-12-08 20:04:36 +0000375 lbs_deb_cmd("SET_WEP: remove key %d\n", priv->wep_tx_keyidx);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200376 }
377
David Woodhousef70dd452007-12-18 00:18:05 -0500378 ret = lbs_cmd_with_response(priv, CMD_802_11_SET_WEP, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200379done:
Holger Schurig9012b282007-05-25 11:27:16 -0400380 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200381 return ret;
382}
383
David Woodhouse4f59abf2007-12-18 00:47:17 -0500384int lbs_cmd_802_11_enable_rsn(struct lbs_private *priv, uint16_t cmd_action,
385 uint16_t *enable)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200386{
David Woodhouse4f59abf2007-12-18 00:47:17 -0500387 struct cmd_ds_802_11_enable_rsn cmd;
388 int ret;
Dan Williams90a42212007-05-25 23:01:24 -0400389
390 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200391
David Woodhouse4f59abf2007-12-18 00:47:17 -0500392 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
393 cmd.action = cpu_to_le16(cmd_action);
Dan Williams18c96c342007-06-18 12:01:12 -0400394
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200395 if (cmd_action == CMD_ACT_GET)
396 cmd.enable = 0;
397 else {
Dan Williams18c96c342007-06-18 12:01:12 -0400398 if (*enable)
David Woodhouse4f59abf2007-12-18 00:47:17 -0500399 cmd.enable = cpu_to_le16(CMD_ENABLE_RSN);
Dan Williams18c96c342007-06-18 12:01:12 -0400400 else
David Woodhouse4f59abf2007-12-18 00:47:17 -0500401 cmd.enable = cpu_to_le16(CMD_DISABLE_RSN);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400402 lbs_deb_cmd("ENABLE_RSN: %d\n", *enable);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200403 }
404
David Woodhouse4f59abf2007-12-18 00:47:17 -0500405 ret = lbs_cmd_with_response(priv, CMD_802_11_ENABLE_RSN, &cmd);
406 if (!ret && cmd_action == CMD_ACT_GET)
407 *enable = le16_to_cpu(cmd.enable);
408
409 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
410 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200411}
412
David Woodhouse9e1228d2008-03-03 12:15:39 +0100413static void set_one_wpa_key(struct MrvlIEtype_keyParamSet *keyparam,
414 struct enc_key *key)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200415{
Holger Schurig8ff12da2007-08-02 11:54:31 -0400416 lbs_deb_enter(LBS_DEB_CMD);
417
David Woodhouse9e1228d2008-03-03 12:15:39 +0100418 if (key->flags & KEY_INFO_WPA_ENABLED)
419 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_ENABLED);
420 if (key->flags & KEY_INFO_WPA_UNICAST)
421 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_UNICAST);
422 if (key->flags & KEY_INFO_WPA_MCAST)
423 keyparam->keyinfo |= cpu_to_le16(KEY_INFO_WPA_MCAST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200424
David Woodhouse9e1228d2008-03-03 12:15:39 +0100425 keyparam->type = cpu_to_le16(TLV_TYPE_KEY_MATERIAL);
426 keyparam->keytypeid = cpu_to_le16(key->type);
427 keyparam->keylen = cpu_to_le16(key->len);
428 memcpy(keyparam->key, key->key, key->len);
429
430 /* Length field doesn't include the {type,length} header */
431 keyparam->length = cpu_to_le16(sizeof(*keyparam) - 4);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400432 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200433}
434
David Woodhouse9e1228d2008-03-03 12:15:39 +0100435int lbs_cmd_802_11_key_material(struct lbs_private *priv, uint16_t cmd_action,
436 struct assoc_request *assoc)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200437{
David Woodhouse9e1228d2008-03-03 12:15:39 +0100438 struct cmd_ds_802_11_key_material cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200439 int ret = 0;
440 int index = 0;
441
Holger Schurig9012b282007-05-25 11:27:16 -0400442 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200443
David Woodhouse9e1228d2008-03-03 12:15:39 +0100444 cmd.action = cpu_to_le16(cmd_action);
445 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200446
Dan Williams0aef64d2007-08-02 11:31:18 -0400447 if (cmd_action == CMD_ACT_GET) {
David Woodhouse9e1228d2008-03-03 12:15:39 +0100448 cmd.hdr.size = cpu_to_le16(S_DS_GEN + 2);
449 } else {
450 memset(cmd.keyParamSet, 0, sizeof(cmd.keyParamSet));
451
452 if (test_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc->flags)) {
453 set_one_wpa_key(&cmd.keyParamSet[index],
454 &assoc->wpa_unicast_key);
455 index++;
456 }
457
458 if (test_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc->flags)) {
459 set_one_wpa_key(&cmd.keyParamSet[index],
460 &assoc->wpa_mcast_key);
461 index++;
462 }
463
464 /* The common header and as many keys as we included */
465 cmd.hdr.size = cpu_to_le16(offsetof(typeof(cmd),
466 keyParamSet[index]));
467 }
468 ret = lbs_cmd_with_response(priv, CMD_802_11_KEY_MATERIAL, &cmd);
469 /* Copy the returned key to driver private data */
470 if (!ret && cmd_action == CMD_ACT_GET) {
471 void *buf_ptr = cmd.keyParamSet;
472 void *resp_end = &(&cmd)[1];
473
474 while (buf_ptr < resp_end) {
475 struct MrvlIEtype_keyParamSet *keyparam = buf_ptr;
476 struct enc_key *key;
477 uint16_t param_set_len = le16_to_cpu(keyparam->length);
478 uint16_t key_len = le16_to_cpu(keyparam->keylen);
479 uint16_t key_flags = le16_to_cpu(keyparam->keyinfo);
480 uint16_t key_type = le16_to_cpu(keyparam->keytypeid);
481 void *end;
482
483 end = (void *)keyparam + sizeof(keyparam->type)
484 + sizeof(keyparam->length) + param_set_len;
485
486 /* Make sure we don't access past the end of the IEs */
487 if (end > resp_end)
488 break;
489
490 if (key_flags & KEY_INFO_WPA_UNICAST)
491 key = &priv->wpa_unicast_key;
492 else if (key_flags & KEY_INFO_WPA_MCAST)
493 key = &priv->wpa_mcast_key;
494 else
495 break;
496
497 /* Copy returned key into driver */
498 memset(key, 0, sizeof(struct enc_key));
499 if (key_len > sizeof(key->key))
500 break;
501 key->type = key_type;
502 key->flags = key_flags;
503 key->len = key_len;
504 memcpy(key->key, keyparam->key, key->len);
505
506 buf_ptr = end + 1;
507 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200508 }
509
Holger Schurig9012b282007-05-25 11:27:16 -0400510 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200511 return ret;
512}
513
Dan Williams39fcf7a2008-09-10 12:49:00 -0400514/**
515 * @brief Set an SNMP MIB value
516 *
517 * @param priv A pointer to struct lbs_private structure
518 * @param oid The OID to set in the firmware
519 * @param val Value to set the OID to
520 *
521 * @return 0 on success, error on failure
522 */
523int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200524{
Dan Williams39fcf7a2008-09-10 12:49:00 -0400525 struct cmd_ds_802_11_snmp_mib cmd;
526 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200527
Holger Schurig9012b282007-05-25 11:27:16 -0400528 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200529
Dan Williams39fcf7a2008-09-10 12:49:00 -0400530 memset(&cmd, 0, sizeof (cmd));
531 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
532 cmd.action = cpu_to_le16(CMD_ACT_SET);
533 cmd.oid = cpu_to_le16((u16) oid);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200534
Dan Williams39fcf7a2008-09-10 12:49:00 -0400535 switch (oid) {
536 case SNMP_MIB_OID_BSS_TYPE:
537 cmd.bufsize = cpu_to_le16(sizeof(u8));
538 cmd.value[0] = (val == IW_MODE_ADHOC) ? 2 : 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200539 break;
Dan Williams39fcf7a2008-09-10 12:49:00 -0400540 case SNMP_MIB_OID_11D_ENABLE:
541 case SNMP_MIB_OID_FRAG_THRESHOLD:
542 case SNMP_MIB_OID_RTS_THRESHOLD:
543 case SNMP_MIB_OID_SHORT_RETRY_LIMIT:
544 case SNMP_MIB_OID_LONG_RETRY_LIMIT:
545 cmd.bufsize = cpu_to_le16(sizeof(u16));
546 *((__le16 *)(&cmd.value)) = cpu_to_le16(val);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200547 break;
548 default:
Dan Williams39fcf7a2008-09-10 12:49:00 -0400549 lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid);
550 ret = -EINVAL;
551 goto out;
552 }
553
554 lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n",
555 le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val);
556
557 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
558
559out:
560 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
561 return ret;
562}
563
564/**
565 * @brief Get an SNMP MIB value
566 *
567 * @param priv A pointer to struct lbs_private structure
568 * @param oid The OID to retrieve from the firmware
569 * @param out_val Location for the returned value
570 *
571 * @return 0 on success, error on failure
572 */
573int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val)
574{
575 struct cmd_ds_802_11_snmp_mib cmd;
576 int ret;
577
578 lbs_deb_enter(LBS_DEB_CMD);
579
580 memset(&cmd, 0, sizeof (cmd));
581 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
582 cmd.action = cpu_to_le16(CMD_ACT_GET);
583 cmd.oid = cpu_to_le16(oid);
584
585 ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd);
586 if (ret)
587 goto out;
588
589 switch (le16_to_cpu(cmd.bufsize)) {
590 case sizeof(u8):
591 if (oid == SNMP_MIB_OID_BSS_TYPE) {
592 if (cmd.value[0] == 2)
593 *out_val = IW_MODE_ADHOC;
594 else
595 *out_val = IW_MODE_INFRA;
596 } else
597 *out_val = cmd.value[0];
598 break;
599 case sizeof(u16):
600 *out_val = le16_to_cpu(*((__le16 *)(&cmd.value)));
601 break;
602 default:
603 lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n",
604 oid, le16_to_cpu(cmd.bufsize));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200605 break;
606 }
607
Dan Williams39fcf7a2008-09-10 12:49:00 -0400608out:
609 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
610 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200611}
612
Dan Williams87c8c722008-08-19 15:15:35 -0400613/**
614 * @brief Get the min, max, and current TX power
615 *
616 * @param priv A pointer to struct lbs_private structure
617 * @param curlevel Current power level in dBm
618 * @param minlevel Minimum supported power level in dBm (optional)
619 * @param maxlevel Maximum supported power level in dBm (optional)
620 *
621 * @return 0 on success, error on failure
622 */
623int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel,
624 s16 *maxlevel)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200625{
Dan Williams87c8c722008-08-19 15:15:35 -0400626 struct cmd_ds_802_11_rf_tx_power cmd;
627 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200628
Holger Schurig9012b282007-05-25 11:27:16 -0400629 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200630
Dan Williams87c8c722008-08-19 15:15:35 -0400631 memset(&cmd, 0, sizeof(cmd));
632 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
633 cmd.action = cpu_to_le16(CMD_ACT_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200634
Dan Williams87c8c722008-08-19 15:15:35 -0400635 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
636 if (ret == 0) {
637 *curlevel = le16_to_cpu(cmd.curlevel);
638 if (minlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100639 *minlevel = cmd.minlevel;
Dan Williams87c8c722008-08-19 15:15:35 -0400640 if (maxlevel)
Holger Schurig87bf24f2008-10-29 10:35:02 +0100641 *maxlevel = cmd.maxlevel;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200642 }
Holger Schurig9012b282007-05-25 11:27:16 -0400643
644 lbs_deb_leave(LBS_DEB_CMD);
Dan Williams87c8c722008-08-19 15:15:35 -0400645 return ret;
646}
647
648/**
649 * @brief Set the TX power
650 *
651 * @param priv A pointer to struct lbs_private structure
652 * @param dbm The desired power level in dBm
653 *
654 * @return 0 on success, error on failure
655 */
656int lbs_set_tx_power(struct lbs_private *priv, s16 dbm)
657{
658 struct cmd_ds_802_11_rf_tx_power cmd;
659 int ret;
660
661 lbs_deb_enter(LBS_DEB_CMD);
662
663 memset(&cmd, 0, sizeof(cmd));
664 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
665 cmd.action = cpu_to_le16(CMD_ACT_SET);
666 cmd.curlevel = cpu_to_le16(dbm);
667
668 lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm);
669
670 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd);
671
672 lbs_deb_leave(LBS_DEB_CMD);
673 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200674}
675
Holger Schurige98a88d2008-03-19 14:25:58 +0100676static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -0400677 u16 cmd_action, void *pdata_buf)
678{
679 struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor;
680
681 cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE);
682 cmd->size =
683 cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) +
684 S_DS_GEN);
685
686 monitor->action = cpu_to_le16(cmd_action);
687 if (cmd_action == CMD_ACT_SET) {
688 monitor->mode =
689 cpu_to_le16((u16) (*(u32 *) pdata_buf));
690 }
691
692 return 0;
693}
694
Javier Cardona85319f92008-05-24 10:59:49 +0100695static __le16 lbs_rate_to_fw_bitmap(int rate, int lower_rates_ok)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200696{
Javier Cardona85319f92008-05-24 10:59:49 +0100697/* Bit Rate
698* 15:13 Reserved
699* 12 54 Mbps
700* 11 48 Mbps
701* 10 36 Mbps
702* 9 24 Mbps
703* 8 18 Mbps
704* 7 12 Mbps
705* 6 9 Mbps
706* 5 6 Mbps
707* 4 Reserved
708* 3 11 Mbps
709* 2 5.5 Mbps
710* 1 2 Mbps
711* 0 1 Mbps
712**/
713
714 uint16_t ratemask;
715 int i = lbs_data_rate_to_fw_index(rate);
716 if (lower_rates_ok)
717 ratemask = (0x1fef >> (12 - i));
718 else
719 ratemask = (1 << i);
720 return cpu_to_le16(ratemask);
721}
722
723int lbs_cmd_802_11_rate_adapt_rateset(struct lbs_private *priv,
724 uint16_t cmd_action)
725{
726 struct cmd_ds_802_11_rate_adapt_rateset cmd;
727 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200728
Holger Schurig8ff12da2007-08-02 11:54:31 -0400729 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200730
Javier Cardona85319f92008-05-24 10:59:49 +0100731 if (!priv->cur_rate && !priv->enablehwauto)
732 return -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200733
Javier Cardona85319f92008-05-24 10:59:49 +0100734 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
735
736 cmd.action = cpu_to_le16(cmd_action);
737 cmd.enablehwauto = cpu_to_le16(priv->enablehwauto);
738 cmd.bitmap = lbs_rate_to_fw_bitmap(priv->cur_rate, priv->enablehwauto);
739 ret = lbs_cmd_with_response(priv, CMD_802_11_RATE_ADAPT_RATESET, &cmd);
740 if (!ret && cmd_action == CMD_ACT_GET) {
741 priv->ratebitmap = le16_to_cpu(cmd.bitmap);
742 priv->enablehwauto = le16_to_cpu(cmd.enablehwauto);
743 }
744
745 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
746 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200747}
Javier Cardona85319f92008-05-24 10:59:49 +0100748EXPORT_SYMBOL_GPL(lbs_cmd_802_11_rate_adapt_rateset);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200749
Dan Williams8e3c91b2007-12-11 15:50:59 -0500750/**
Dan Williams8e3c91b2007-12-11 15:50:59 -0500751 * @brief Set the data rate
752 *
753 * @param priv A pointer to struct lbs_private structure
754 * @param rate The desired data rate, or 0 to clear a locked rate
755 *
756 * @return 0 on success, error on failure
757 */
758int lbs_set_data_rate(struct lbs_private *priv, u8 rate)
759{
760 struct cmd_ds_802_11_data_rate cmd;
761 int ret = 0;
762
763 lbs_deb_enter(LBS_DEB_CMD);
764
765 memset(&cmd, 0, sizeof(cmd));
766 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
767
768 if (rate > 0) {
769 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_FIX_RATE);
770 cmd.rates[0] = lbs_data_rate_to_fw_index(rate);
771 if (cmd.rates[0] == 0) {
772 lbs_deb_cmd("DATA_RATE: invalid requested rate of"
773 " 0x%02X\n", rate);
774 ret = 0;
775 goto out;
776 }
777 lbs_deb_cmd("DATA_RATE: set fixed 0x%02X\n", cmd.rates[0]);
778 } else {
779 cmd.action = cpu_to_le16(CMD_ACT_SET_TX_AUTO);
Holger Schurig8ff12da2007-08-02 11:54:31 -0400780 lbs_deb_cmd("DATA_RATE: setting auto\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200781 }
782
David Woodhouse689442d2007-12-12 16:00:42 -0500783 ret = lbs_cmd_with_response(priv, CMD_802_11_DATA_RATE, &cmd);
Dan Williams8e3c91b2007-12-11 15:50:59 -0500784 if (ret)
785 goto out;
786
787 lbs_deb_hex(LBS_DEB_CMD, "DATA_RATE_RESP", (u8 *) &cmd, sizeof (cmd));
788
789 /* FIXME: get actual rates FW can do if this command actually returns
790 * all data rates supported.
791 */
792 priv->cur_rate = lbs_fw_index_to_data_rate(cmd.rates[0]);
793 lbs_deb_cmd("DATA_RATE: current rate is 0x%02x\n", priv->cur_rate);
794
795out:
796 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
797 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200798}
799
Dan Williams2dd4b262007-12-11 16:54:15 -0500800/**
801 * @brief Get the radio channel
802 *
803 * @param priv A pointer to struct lbs_private structure
804 *
805 * @return The channel on success, error on failure
806 */
807int lbs_get_channel(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200808{
Dan Williams2dd4b262007-12-11 16:54:15 -0500809 struct cmd_ds_802_11_rf_channel cmd;
810 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200811
Holger Schurig8ff12da2007-08-02 11:54:31 -0400812 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200813
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200814 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500815 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
816 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200817
David Woodhouse689442d2007-12-12 16:00:42 -0500818 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500819 if (ret)
820 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200821
Dan Williamscb182a62007-12-11 17:35:51 -0500822 ret = le16_to_cpu(cmd.channel);
823 lbs_deb_cmd("current radio channel is %d\n", ret);
Dan Williams2dd4b262007-12-11 16:54:15 -0500824
825out:
826 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
827 return ret;
828}
829
Holger Schurig73ab1f22008-04-02 16:52:19 +0200830int lbs_update_channel(struct lbs_private *priv)
831{
832 int ret;
833
834 /* the channel in f/w could be out of sync; get the current channel */
835 lbs_deb_enter(LBS_DEB_ASSOC);
836
837 ret = lbs_get_channel(priv);
838 if (ret > 0) {
839 priv->curbssparams.channel = ret;
840 ret = 0;
841 }
842 lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret);
843 return ret;
844}
845
Dan Williams2dd4b262007-12-11 16:54:15 -0500846/**
847 * @brief Set the radio channel
848 *
849 * @param priv A pointer to struct lbs_private structure
850 * @param channel The desired channel, or 0 to clear a locked channel
851 *
852 * @return 0 on success, error on failure
853 */
854int lbs_set_channel(struct lbs_private *priv, u8 channel)
855{
856 struct cmd_ds_802_11_rf_channel cmd;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530857#ifdef DEBUG
Dan Williams2dd4b262007-12-11 16:54:15 -0500858 u8 old_channel = priv->curbssparams.channel;
Manish Katiyar96d46d52008-10-13 16:22:42 +0530859#endif
Dan Williams2dd4b262007-12-11 16:54:15 -0500860 int ret = 0;
861
862 lbs_deb_enter(LBS_DEB_CMD);
863
Holger Schurig8d0c7fa2008-04-09 10:23:31 +0200864 memset(&cmd, 0, sizeof(cmd));
Dan Williams2dd4b262007-12-11 16:54:15 -0500865 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
866 cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET);
867 cmd.channel = cpu_to_le16(channel);
868
David Woodhouse689442d2007-12-12 16:00:42 -0500869 ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd);
Dan Williams2dd4b262007-12-11 16:54:15 -0500870 if (ret)
871 goto out;
872
Dan Williamscb182a62007-12-11 17:35:51 -0500873 priv->curbssparams.channel = (uint8_t) le16_to_cpu(cmd.channel);
874 lbs_deb_cmd("channel switch from %d to %d\n", old_channel,
875 priv->curbssparams.channel);
Dan Williams2dd4b262007-12-11 16:54:15 -0500876
877out:
878 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
879 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200880}
881
Holger Schurig69f90322007-11-23 15:43:44 +0100882static int lbs_cmd_802_11_rssi(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200883 struct cmd_ds_command *cmd)
884{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200885
Holger Schurig8ff12da2007-08-02 11:54:31 -0400886 lbs_deb_enter(LBS_DEB_CMD);
Dan Williams0aef64d2007-08-02 11:31:18 -0400887 cmd->command = cpu_to_le16(CMD_802_11_RSSI);
David Woodhouse981f1872007-05-25 23:36:54 -0400888 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_rssi) + S_DS_GEN);
Holger Schuriga783f1e2007-08-02 13:08:24 -0400889 cmd->params.rssi.N = cpu_to_le16(DEFAULT_BCN_AVG_FACTOR);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200890
891 /* reset Beacon SNR/NF/RSSI values */
David Woodhouseaa21c002007-12-08 20:04:36 +0000892 priv->SNR[TYPE_BEACON][TYPE_NOAVG] = 0;
893 priv->SNR[TYPE_BEACON][TYPE_AVG] = 0;
894 priv->NF[TYPE_BEACON][TYPE_NOAVG] = 0;
895 priv->NF[TYPE_BEACON][TYPE_AVG] = 0;
896 priv->RSSI[TYPE_BEACON][TYPE_NOAVG] = 0;
897 priv->RSSI[TYPE_BEACON][TYPE_AVG] = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200898
Holger Schurig8ff12da2007-08-02 11:54:31 -0400899 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200900 return 0;
901}
902
Holger Schurige98a88d2008-03-19 14:25:58 +0100903static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200904 u8 cmd_action, void *pdata_buf)
905{
Holger Schurig10078322007-11-15 18:05:47 -0500906 struct lbs_offset_value *offval;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200907
Holger Schurig9012b282007-05-25 11:27:16 -0400908 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200909
Holger Schurig10078322007-11-15 18:05:47 -0500910 offval = (struct lbs_offset_value *)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200911
Holger Schurigc2df2ef2007-12-07 15:30:44 +0000912 switch (le16_to_cpu(cmdptr->command)) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400913 case CMD_MAC_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200914 {
915 struct cmd_ds_mac_reg_access *macreg;
916
917 cmdptr->size =
David Woodhouse981f1872007-05-25 23:36:54 -0400918 cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access)
919 + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200920 macreg =
921 (struct cmd_ds_mac_reg_access *)&cmdptr->params.
922 macreg;
923
924 macreg->action = cpu_to_le16(cmd_action);
925 macreg->offset = cpu_to_le16((u16) offval->offset);
926 macreg->value = cpu_to_le32(offval->value);
927
928 break;
929 }
930
Dan Williams0aef64d2007-08-02 11:31:18 -0400931 case CMD_BBP_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200932 {
933 struct cmd_ds_bbp_reg_access *bbpreg;
934
935 cmdptr->size =
936 cpu_to_le16(sizeof
937 (struct cmd_ds_bbp_reg_access)
938 + S_DS_GEN);
939 bbpreg =
940 (struct cmd_ds_bbp_reg_access *)&cmdptr->params.
941 bbpreg;
942
943 bbpreg->action = cpu_to_le16(cmd_action);
944 bbpreg->offset = cpu_to_le16((u16) offval->offset);
945 bbpreg->value = (u8) offval->value;
946
947 break;
948 }
949
Dan Williams0aef64d2007-08-02 11:31:18 -0400950 case CMD_RF_REG_ACCESS:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200951 {
952 struct cmd_ds_rf_reg_access *rfreg;
953
954 cmdptr->size =
955 cpu_to_le16(sizeof
956 (struct cmd_ds_rf_reg_access) +
957 S_DS_GEN);
958 rfreg =
959 (struct cmd_ds_rf_reg_access *)&cmdptr->params.
960 rfreg;
961
962 rfreg->action = cpu_to_le16(cmd_action);
963 rfreg->offset = cpu_to_le16((u16) offval->offset);
964 rfreg->value = (u8) offval->value;
965
966 break;
967 }
968
969 default:
970 break;
971 }
972
Holger Schurig9012b282007-05-25 11:27:16 -0400973 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200974 return 0;
975}
976
Holger Schurige98a88d2008-03-19 14:25:58 +0100977static int lbs_cmd_bt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200978 u16 cmd_action, void *pdata_buf)
979{
980 struct cmd_ds_bt_access *bt_access = &cmd->params.bt;
Holger Schurig8ff12da2007-08-02 11:54:31 -0400981 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200982
Dan Williams0aef64d2007-08-02 11:31:18 -0400983 cmd->command = cpu_to_le16(CMD_BT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -0400984 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200985 cmd->result = 0;
986 bt_access->action = cpu_to_le16(cmd_action);
987
988 switch (cmd_action) {
Dan Williams0aef64d2007-08-02 11:31:18 -0400989 case CMD_ACT_BT_ACCESS_ADD:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200990 memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400991 lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200992 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400993 case CMD_ACT_BT_ACCESS_DEL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200994 memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN);
Holger Schurigece56192007-08-02 11:53:06 -0400995 lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200996 break;
Dan Williams0aef64d2007-08-02 11:31:18 -0400997 case CMD_ACT_BT_ACCESS_LIST:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -0200998 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
999 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001000 case CMD_ACT_BT_ACCESS_RESET:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001001 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001002 case CMD_ACT_BT_ACCESS_SET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001003 bt_access->id = cpu_to_le32(*(u32 *) pdata_buf);
1004 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001005 case CMD_ACT_BT_ACCESS_GET_INVERT:
Luis Carlos Cobo90e8eaf2007-05-25 13:53:26 -04001006 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001007 default:
1008 break;
1009 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001010 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001011 return 0;
1012}
1013
Holger Schurige98a88d2008-03-19 14:25:58 +01001014static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001015 u16 cmd_action, void *pdata_buf)
1016{
1017 struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt;
Holger Schurig8ff12da2007-08-02 11:54:31 -04001018 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001019
Dan Williams0aef64d2007-08-02 11:31:18 -04001020 cmd->command = cpu_to_le16(CMD_FWT_ACCESS);
David Woodhouse981f1872007-05-25 23:36:54 -04001021 cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001022 cmd->result = 0;
1023
1024 if (pdata_buf)
1025 memcpy(fwt_access, pdata_buf, sizeof(*fwt_access));
1026 else
1027 memset(fwt_access, 0, sizeof(*fwt_access));
1028
1029 fwt_access->action = cpu_to_le16(cmd_action);
1030
Holger Schurig8ff12da2007-08-02 11:54:31 -04001031 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001032 return 0;
1033}
1034
David Woodhouse301eacb2007-12-11 15:23:59 -05001035int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action,
1036 struct cmd_ds_mesh_access *cmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001037{
David Woodhouse301eacb2007-12-11 15:23:59 -05001038 int ret;
1039
Holger Schurig8ff12da2007-08-02 11:54:31 -04001040 lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001041
David Woodhouse301eacb2007-12-11 15:23:59 -05001042 cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS);
David Woodhouse9fae8992007-12-15 03:46:44 -05001043 cmd->hdr.size = cpu_to_le16(sizeof(*cmd));
David Woodhouse301eacb2007-12-11 15:23:59 -05001044 cmd->hdr.result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001045
David Woodhouse301eacb2007-12-11 15:23:59 -05001046 cmd->action = cpu_to_le16(cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001047
David Woodhouse689442d2007-12-12 16:00:42 -05001048 ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001049
Holger Schurig8ff12da2007-08-02 11:54:31 -04001050 lbs_deb_leave(LBS_DEB_CMD);
David Woodhouse301eacb2007-12-11 15:23:59 -05001051 return ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001052}
1053
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001054static int __lbs_mesh_config_send(struct lbs_private *priv,
1055 struct cmd_ds_mesh_config *cmd,
1056 uint16_t action, uint16_t type)
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001057{
1058 int ret;
Bing Zhao684d6b32009-03-25 09:51:16 -07001059 u16 command = CMD_MESH_CONFIG_OLD;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001060
1061 lbs_deb_enter(LBS_DEB_CMD);
1062
Bing Zhao684d6b32009-03-25 09:51:16 -07001063 /*
1064 * Command id is 0xac for v10 FW along with mesh interface
1065 * id in bits 14-13-12.
1066 */
1067 if (priv->mesh_fw_ver == MESH_FW_NEW)
1068 command = CMD_MESH_CONFIG |
1069 (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET);
1070
1071 cmd->hdr.command = cpu_to_le16(command);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001072 cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config));
1073 cmd->hdr.result = 0;
1074
1075 cmd->type = cpu_to_le16(type);
1076 cmd->action = cpu_to_le16(action);
1077
Bing Zhao684d6b32009-03-25 09:51:16 -07001078 ret = lbs_cmd_with_response(priv, command, cmd);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001079
1080 lbs_deb_leave(LBS_DEB_CMD);
1081 return ret;
1082}
1083
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001084int lbs_mesh_config_send(struct lbs_private *priv,
1085 struct cmd_ds_mesh_config *cmd,
1086 uint16_t action, uint16_t type)
1087{
1088 int ret;
1089
1090 if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG))
1091 return -EOPNOTSUPP;
1092
1093 ret = __lbs_mesh_config_send(priv, cmd, action, type);
1094 return ret;
1095}
1096
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001097/* This function is the CMD_MESH_CONFIG legacy function. It only handles the
1098 * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG
1099 * are all handled by preparing a struct cmd_ds_mesh_config and passing it to
1100 * lbs_mesh_config_send.
1101 */
1102int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan)
David Woodhouse23a397a2007-12-11 18:56:42 -05001103{
1104 struct cmd_ds_mesh_config cmd;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001105 struct mrvl_meshie *ie;
John W. Linville9387b7c2008-09-30 20:59:05 -04001106 DECLARE_SSID_BUF(ssid);
David Woodhouse23a397a2007-12-11 18:56:42 -05001107
1108 memset(&cmd, 0, sizeof(cmd));
David Woodhouse86062132007-12-13 00:32:36 -05001109 cmd.channel = cpu_to_le16(chan);
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001110 ie = (struct mrvl_meshie *)cmd.data;
David Woodhouse7e226272007-12-14 22:53:41 -05001111
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001112 switch (action) {
1113 case CMD_ACT_MESH_CONFIG_START:
Johannes Berg2c7060022008-10-30 22:09:54 +01001114 ie->id = WLAN_EID_GENERIC;
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001115 ie->val.oui[0] = 0x00;
1116 ie->val.oui[1] = 0x50;
1117 ie->val.oui[2] = 0x43;
1118 ie->val.type = MARVELL_MESH_IE_TYPE;
1119 ie->val.subtype = MARVELL_MESH_IE_SUBTYPE;
1120 ie->val.version = MARVELL_MESH_IE_VERSION;
1121 ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP;
1122 ie->val.active_metric_id = MARVELL_MESH_METRIC_ID;
1123 ie->val.mesh_capability = MARVELL_MESH_CAPABILITY;
1124 ie->val.mesh_id_len = priv->mesh_ssid_len;
1125 memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len);
Johannes Berg2c7060022008-10-30 22:09:54 +01001126 ie->len = sizeof(struct mrvl_meshie_val) -
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001127 IW_ESSID_MAX_SIZE + priv->mesh_ssid_len;
1128 cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val));
1129 break;
1130 case CMD_ACT_MESH_CONFIG_STOP:
1131 break;
1132 default:
1133 return -1;
David Woodhouse23a397a2007-12-11 18:56:42 -05001134 }
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001135 lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n",
1136 action, priv->mesh_tlv, chan,
John W. Linville9387b7c2008-09-30 20:59:05 -04001137 print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len));
Javier Cardonaedaea5c2008-05-17 00:55:10 -07001138
Brian Cavagnolo1556c0f2008-07-21 11:02:46 -07001139 return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv);
David Woodhouse23a397a2007-12-11 18:56:42 -05001140}
1141
Brajesh Dave96287ac2007-11-20 17:44:28 -05001142static int lbs_cmd_bcn_ctrl(struct lbs_private * priv,
1143 struct cmd_ds_command *cmd,
1144 u16 cmd_action)
1145{
1146 struct cmd_ds_802_11_beacon_control
1147 *bcn_ctrl = &cmd->params.bcn_ctrl;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001148
1149 lbs_deb_enter(LBS_DEB_CMD);
1150 cmd->size =
1151 cpu_to_le16(sizeof(struct cmd_ds_802_11_beacon_control)
1152 + S_DS_GEN);
1153 cmd->command = cpu_to_le16(CMD_802_11_BEACON_CTRL);
1154
1155 bcn_ctrl->action = cpu_to_le16(cmd_action);
David Woodhouseaa21c002007-12-08 20:04:36 +00001156 bcn_ctrl->beacon_enable = cpu_to_le16(priv->beacon_enable);
1157 bcn_ctrl->beacon_period = cpu_to_le16(priv->beacon_period);
Brajesh Dave96287ac2007-11-20 17:44:28 -05001158
1159 lbs_deb_leave(LBS_DEB_CMD);
1160 return 0;
1161}
1162
David Woodhouse681ffbb2007-12-15 20:04:54 -05001163static void lbs_queue_cmd(struct lbs_private *priv,
1164 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001165{
1166 unsigned long flags;
David Woodhouse681ffbb2007-12-15 20:04:54 -05001167 int addtail = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001168
Holger Schurig8ff12da2007-08-02 11:54:31 -04001169 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001170
David Woodhousec4ab4122007-12-15 00:41:51 -05001171 if (!cmdnode) {
1172 lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001173 goto done;
1174 }
David Woodhoused9896ee2007-12-15 00:09:25 -05001175 if (!cmdnode->cmdbuf->size) {
1176 lbs_deb_host("DNLD_CMD: cmd size is zero\n");
1177 goto done;
1178 }
David Woodhouseae125bf2007-12-15 04:22:52 -05001179 cmdnode->result = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001180
1181 /* Exit_PS command needs to be queued in the header always. */
Dan Williamsddac4522007-12-11 13:49:39 -05001182 if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) {
David Woodhouse38bfab12007-12-16 23:26:54 -05001183 struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1];
Dan Williamsddac4522007-12-11 13:49:39 -05001184
Dan Williams0aef64d2007-08-02 11:31:18 -04001185 if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001186 if (priv->psstate != PS_STATE_FULL_POWER)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001187 addtail = 0;
1188 }
1189 }
1190
David Woodhouseaa21c002007-12-08 20:04:36 +00001191 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001192
David Woodhouseac472462007-12-08 00:35:00 +00001193 if (addtail)
David Woodhouseaa21c002007-12-08 20:04:36 +00001194 list_add_tail(&cmdnode->list, &priv->cmdpendingq);
David Woodhouseac472462007-12-08 00:35:00 +00001195 else
David Woodhouseaa21c002007-12-08 20:04:36 +00001196 list_add(&cmdnode->list, &priv->cmdpendingq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001197
David Woodhouseaa21c002007-12-08 20:04:36 +00001198 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001199
Holger Schurig8ff12da2007-08-02 11:54:31 -04001200 lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n",
David Woodhousec4ab4122007-12-15 00:41:51 -05001201 le16_to_cpu(cmdnode->cmdbuf->command));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001202
1203done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001204 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001205}
1206
David Woodhouse18c52e72007-12-17 16:03:58 -05001207static void lbs_submit_command(struct lbs_private *priv,
1208 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001209{
1210 unsigned long flags;
Dan Williamsddac4522007-12-11 13:49:39 -05001211 struct cmd_header *cmd;
David Woodhouse18c52e72007-12-17 16:03:58 -05001212 uint16_t cmdsize;
1213 uint16_t command;
Holger Schurig57962f02008-05-14 16:30:28 +02001214 int timeo = 3 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001215 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001216
Holger Schurig8ff12da2007-08-02 11:54:31 -04001217 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001218
Dan Williamsddac4522007-12-11 13:49:39 -05001219 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001220
David Woodhouseaa21c002007-12-08 20:04:36 +00001221 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001222 priv->cur_cmd = cmdnode;
1223 priv->cur_cmd_retcode = 0;
1224 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001225
Dan Williamsddac4522007-12-11 13:49:39 -05001226 cmdsize = le16_to_cpu(cmd->size);
1227 command = le16_to_cpu(cmd->command);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001228
David Woodhouse18c52e72007-12-17 16:03:58 -05001229 /* These commands take longer */
Dan Williamsbe0d76e2009-05-22 20:05:25 -04001230 if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE)
Holger Schurig57962f02008-05-14 16:30:28 +02001231 timeo = 5 * HZ;
David Woodhouse18c52e72007-12-17 16:03:58 -05001232
Holger Schurige5225b32008-03-26 10:04:44 +01001233 lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n",
1234 command, le16_to_cpu(cmd->seqnum), cmdsize);
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001235 lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001236
Dan Williamsddac4522007-12-11 13:49:39 -05001237 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize);
David Woodhouse18c52e72007-12-17 16:03:58 -05001238
David Woodhoused9896ee2007-12-15 00:09:25 -05001239 if (ret) {
1240 lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret);
David Woodhouse18c52e72007-12-17 16:03:58 -05001241 /* Let the timer kick in and retry, and potentially reset
1242 the whole thing if the condition persists */
Holger Schurig57962f02008-05-14 16:30:28 +02001243 timeo = HZ/4;
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001244 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001245
1246 /* Setup the timer after transmit command */
David Woodhouse18c52e72007-12-17 16:03:58 -05001247 mod_timer(&priv->command_timer, jiffies + timeo);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001248
David Woodhouse18c52e72007-12-17 16:03:58 -05001249 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001250}
1251
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001252/**
1253 * This function inserts command node to cmdfreeq
David Woodhouseaa21c002007-12-08 20:04:36 +00001254 * after cleans it. Requires priv->driver_lock held.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001255 */
David Woodhouse183aeac2007-12-15 01:52:54 -05001256static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001257 struct cmd_ctrl_node *cmdnode)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001258{
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001259 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001260
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001261 if (!cmdnode)
1262 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001263
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001264 cmdnode->callback = NULL;
1265 cmdnode->callback_arg = 0;
1266
1267 memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE);
1268
1269 list_add_tail(&cmdnode->list, &priv->cmdfreeq);
1270 out:
1271 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001272}
1273
Holger Schurig69f90322007-11-23 15:43:44 +01001274static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv,
1275 struct cmd_ctrl_node *ptempcmd)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001276{
1277 unsigned long flags;
1278
David Woodhouseaa21c002007-12-08 20:04:36 +00001279 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig10078322007-11-15 18:05:47 -05001280 __lbs_cleanup_and_insert_cmd(priv, ptempcmd);
David Woodhouseaa21c002007-12-08 20:04:36 +00001281 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001282}
1283
David Woodhouse183aeac2007-12-15 01:52:54 -05001284void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd,
1285 int result)
1286{
1287 if (cmd == priv->cur_cmd)
1288 priv->cur_cmd_retcode = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001289
David Woodhouseae125bf2007-12-15 04:22:52 -05001290 cmd->result = result;
David Woodhouse5ba2f8a2007-12-15 02:02:56 -05001291 cmd->cmdwaitqwoken = 1;
1292 wake_up_interruptible(&cmd->cmdwait_q);
1293
Holger Schurig8db4a2b2008-03-19 10:11:00 +01001294 if (!cmd->callback || cmd->callback == lbs_cmd_async_callback)
David Woodhousead12d0f2007-12-15 02:06:16 -05001295 __lbs_cleanup_and_insert_cmd(priv, cmd);
David Woodhouse183aeac2007-12-15 01:52:54 -05001296 priv->cur_cmd = NULL;
1297}
1298
Dan Williamsd5db2df2008-08-21 17:51:07 -04001299int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001300{
David Woodhousea7c45892007-12-17 22:43:48 -05001301 struct cmd_ds_802_11_radio_control cmd;
Dan Williamsd5db2df2008-08-21 17:51:07 -04001302 int ret = -EINVAL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001303
Holger Schurig9012b282007-05-25 11:27:16 -04001304 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001305
David Woodhousea7c45892007-12-17 22:43:48 -05001306 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
1307 cmd.action = cpu_to_le16(CMD_ACT_SET);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001308
Dan Williamsd5db2df2008-08-21 17:51:07 -04001309 /* Only v8 and below support setting the preamble */
1310 if (priv->fwrelease < 0x09000000) {
1311 switch (preamble) {
1312 case RADIO_PREAMBLE_SHORT:
1313 if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE))
1314 goto out;
1315 /* Fall through */
1316 case RADIO_PREAMBLE_AUTO:
1317 case RADIO_PREAMBLE_LONG:
1318 cmd.control = cpu_to_le16(preamble);
1319 break;
1320 default:
1321 goto out;
1322 }
David Woodhousea7c45892007-12-17 22:43:48 -05001323 }
1324
Dan Williamsd5db2df2008-08-21 17:51:07 -04001325 if (radio_on)
1326 cmd.control |= cpu_to_le16(0x1);
1327 else {
1328 cmd.control &= cpu_to_le16(~0x1);
1329 priv->txpower_cur = 0;
1330 }
David Woodhousea7c45892007-12-17 22:43:48 -05001331
Dan Williamsd5db2df2008-08-21 17:51:07 -04001332 lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n",
1333 radio_on ? "ON" : "OFF", preamble);
1334
1335 priv->radio_on = radio_on;
David Woodhousea7c45892007-12-17 22:43:48 -05001336
1337 ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001338
Dan Williamsd5db2df2008-08-21 17:51:07 -04001339out:
Holger Schurig9012b282007-05-25 11:27:16 -04001340 lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001341 return ret;
1342}
1343
Holger Schurigc97329e2008-03-18 11:20:21 +01001344void lbs_set_mac_control(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001345{
Holger Schurig835d3ac2008-03-12 16:05:40 +01001346 struct cmd_ds_mac_control cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001347
Holger Schurig9012b282007-05-25 11:27:16 -04001348 lbs_deb_enter(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001349
Holger Schurig835d3ac2008-03-12 16:05:40 +01001350 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
Holger Schurigd9e97782008-03-12 16:06:43 +01001351 cmd.action = cpu_to_le16(priv->mac_control);
Holger Schurig835d3ac2008-03-12 16:05:40 +01001352 cmd.reserved = 0;
1353
David Woodhouse75bf45a2008-05-20 13:32:45 +01001354 lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001355
Holger Schurigc97329e2008-03-18 11:20:21 +01001356 lbs_deb_leave(LBS_DEB_CMD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001357}
1358
1359/**
1360 * @brief This function prepare the command before send to firmware.
1361 *
Holger Schurig69f90322007-11-23 15:43:44 +01001362 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001363 * @param cmd_no command number
1364 * @param cmd_action command action: GET or SET
1365 * @param wait_option wait option: wait response or not
1366 * @param cmd_oid cmd oid: treated as sub command
1367 * @param pdata_buf A pointer to informaion buffer
1368 * @return 0 or -1
1369 */
Holger Schurig69f90322007-11-23 15:43:44 +01001370int lbs_prepare_and_send_command(struct lbs_private *priv,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001371 u16 cmd_no,
1372 u16 cmd_action,
1373 u16 wait_option, u32 cmd_oid, void *pdata_buf)
1374{
1375 int ret = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001376 struct cmd_ctrl_node *cmdnode;
1377 struct cmd_ds_command *cmdptr;
1378 unsigned long flags;
1379
Holger Schurig8ff12da2007-08-02 11:54:31 -04001380 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001381
David Woodhouseaa21c002007-12-08 20:04:36 +00001382 if (!priv) {
1383 lbs_deb_host("PREP_CMD: priv is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001384 ret = -1;
1385 goto done;
1386 }
1387
David Woodhouseaa21c002007-12-08 20:04:36 +00001388 if (priv->surpriseremoved) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001389 lbs_deb_host("PREP_CMD: card removed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001390 ret = -1;
1391 goto done;
1392 }
1393
Holger Schurig0d61d042007-12-05 17:58:06 +01001394 cmdnode = lbs_get_cmd_ctrl_node(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001395
1396 if (cmdnode == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001397 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001398
1399 /* Wake up main thread to execute next command */
Dan Williamsfe336152007-08-02 11:32:25 -04001400 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001401 ret = -1;
1402 goto done;
1403 }
1404
Holger Schurige98a88d2008-03-19 14:25:58 +01001405 cmdnode->callback = NULL;
1406 cmdnode->callback_arg = (unsigned long)pdata_buf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001407
Dan Williamsddac4522007-12-11 13:49:39 -05001408 cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001409
Holger Schurig8ff12da2007-08-02 11:54:31 -04001410 lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001411
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001412 /* Set sequence number, command and INT option */
David Woodhouseaa21c002007-12-08 20:04:36 +00001413 priv->seqnum++;
1414 cmdptr->seqnum = cpu_to_le16(priv->seqnum);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001415
David Woodhouse981f1872007-05-25 23:36:54 -04001416 cmdptr->command = cpu_to_le16(cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001417 cmdptr->result = 0;
1418
1419 switch (cmd_no) {
Dan Williams0aef64d2007-08-02 11:31:18 -04001420 case CMD_802_11_PS_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001421 ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001422 break;
1423
Dan Williams0aef64d2007-08-02 11:31:18 -04001424 case CMD_MAC_REG_ACCESS:
1425 case CMD_BBP_REG_ACCESS:
1426 case CMD_RF_REG_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001427 ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001428 break;
1429
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001430 case CMD_802_11_MONITOR_MODE:
Holger Schurige98a88d2008-03-19 14:25:58 +01001431 ret = lbs_cmd_802_11_monitor_mode(cmdptr,
Luis Carlos Cobo965f8bb2007-08-02 13:16:55 -04001432 cmd_action, pdata_buf);
1433 break;
1434
Dan Williams0aef64d2007-08-02 11:31:18 -04001435 case CMD_802_11_RSSI:
Holger Schurig10078322007-11-15 18:05:47 -05001436 ret = lbs_cmd_802_11_rssi(priv, cmdptr);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001437 break;
1438
Dan Williams0aef64d2007-08-02 11:31:18 -04001439 case CMD_802_11_SET_AFC:
1440 case CMD_802_11_GET_AFC:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001441
1442 cmdptr->command = cpu_to_le16(cmd_no);
David Woodhouse981f1872007-05-25 23:36:54 -04001443 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) +
1444 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001445
1446 memmove(&cmdptr->params.afc,
1447 pdata_buf, sizeof(struct cmd_ds_802_11_afc));
1448
1449 ret = 0;
1450 goto done;
1451
Dan Williams0aef64d2007-08-02 11:31:18 -04001452 case CMD_802_11D_DOMAIN_INFO:
Holger Schurig10078322007-11-15 18:05:47 -05001453 ret = lbs_cmd_802_11d_domain_info(priv, cmdptr,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001454 cmd_no, cmd_action);
1455 break;
1456
Dan Williams0aef64d2007-08-02 11:31:18 -04001457 case CMD_802_11_TPC_CFG:
1458 cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001459 cmdptr->size =
1460 cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) +
1461 S_DS_GEN);
1462
1463 memmove(&cmdptr->params.tpccfg,
1464 pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg));
1465
1466 ret = 0;
1467 break;
Dan Williams0aef64d2007-08-02 11:31:18 -04001468 case CMD_802_11_LED_GPIO_CTRL:
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001469 {
Dan Williams75b6a612009-05-22 20:03:09 -04001470 struct mrvl_ie_ledgpio *gpio =
1471 (struct mrvl_ie_ledgpio*)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001472 cmdptr->params.ledgpio.data;
1473
1474 memmove(&cmdptr->params.ledgpio,
1475 pdata_buf,
1476 sizeof(struct cmd_ds_802_11_led_ctrl));
1477
1478 cmdptr->command =
Dan Williams0aef64d2007-08-02 11:31:18 -04001479 cpu_to_le16(CMD_802_11_LED_GPIO_CTRL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001480
1481#define ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN 8
1482 cmdptr->size =
Holger Schurigc2df2ef2007-12-07 15:30:44 +00001483 cpu_to_le16(le16_to_cpu(gpio->header.len)
1484 + S_DS_GEN
1485 + ACTION_NUMLED_TLVTYPE_LEN_FIELDS_LEN);
1486 gpio->header.len = gpio->header.len;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001487
1488 ret = 0;
1489 break;
1490 }
David Woodhouse5844d122007-12-18 02:01:37 -05001491
Dan Williams0aef64d2007-08-02 11:31:18 -04001492 case CMD_BT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001493 ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001494 break;
1495
Dan Williams0aef64d2007-08-02 11:31:18 -04001496 case CMD_FWT_ACCESS:
Holger Schurige98a88d2008-03-19 14:25:58 +01001497 ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001498 break;
1499
Dan Williams0aef64d2007-08-02 11:31:18 -04001500 case CMD_GET_TSF:
1501 cmdptr->command = cpu_to_le16(CMD_GET_TSF);
David Woodhouse981f1872007-05-25 23:36:54 -04001502 cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_get_tsf) +
1503 S_DS_GEN);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001504 ret = 0;
1505 break;
Brajesh Dave96287ac2007-11-20 17:44:28 -05001506 case CMD_802_11_BEACON_CTRL:
1507 ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action);
1508 break;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001509 default:
David Woodhousee37fc6e2008-05-20 11:47:16 +01001510 lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001511 ret = -1;
1512 break;
1513 }
1514
1515 /* return error, since the command preparation failed */
1516 if (ret != 0) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001517 lbs_deb_host("PREP_CMD: command preparation failed\n");
Holger Schurig10078322007-11-15 18:05:47 -05001518 lbs_cleanup_and_insert_cmd(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001519 ret = -1;
1520 goto done;
1521 }
1522
1523 cmdnode->cmdwaitqwoken = 0;
1524
David Woodhouse681ffbb2007-12-15 20:04:54 -05001525 lbs_queue_cmd(priv, cmdnode);
Dan Williamsfe336152007-08-02 11:32:25 -04001526 wake_up_interruptible(&priv->waitq);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001527
Dan Williams0aef64d2007-08-02 11:31:18 -04001528 if (wait_option & CMD_OPTION_WAITFORRSP) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001529 lbs_deb_host("PREP_CMD: wait for response\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001530 might_sleep();
1531 wait_event_interruptible(cmdnode->cmdwait_q,
1532 cmdnode->cmdwaitqwoken);
1533 }
1534
David Woodhouseaa21c002007-12-08 20:04:36 +00001535 spin_lock_irqsave(&priv->driver_lock, flags);
1536 if (priv->cur_cmd_retcode) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001537 lbs_deb_host("PREP_CMD: command failed with return code %d\n",
David Woodhouseaa21c002007-12-08 20:04:36 +00001538 priv->cur_cmd_retcode);
1539 priv->cur_cmd_retcode = 0;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001540 ret = -1;
1541 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001542 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001543
1544done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001545 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001546 return ret;
1547}
1548
1549/**
1550 * @brief This function allocates the command buffer and link
1551 * it to command free queue.
1552 *
Holger Schurig69f90322007-11-23 15:43:44 +01001553 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001554 * @return 0 or -1
1555 */
Holger Schurig69f90322007-11-23 15:43:44 +01001556int lbs_allocate_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001557{
1558 int ret = 0;
Dan Williamsddac4522007-12-11 13:49:39 -05001559 u32 bufsize;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001560 u32 i;
Dan Williamsddac4522007-12-11 13:49:39 -05001561 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001562
Holger Schurig8ff12da2007-08-02 11:54:31 -04001563 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001564
Dan Williamsddac4522007-12-11 13:49:39 -05001565 /* Allocate and initialize the command array */
1566 bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS;
1567 if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001568 lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001569 ret = -1;
1570 goto done;
1571 }
Dan Williamsddac4522007-12-11 13:49:39 -05001572 priv->cmd_array = cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001573
Dan Williamsddac4522007-12-11 13:49:39 -05001574 /* Allocate and initialize each command buffer in the command array */
1575 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1576 cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL);
1577 if (!cmdarray[i].cmdbuf) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001578 lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001579 ret = -1;
1580 goto done;
1581 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001582 }
1583
Dan Williamsddac4522007-12-11 13:49:39 -05001584 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1585 init_waitqueue_head(&cmdarray[i].cmdwait_q);
1586 lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001587 }
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001588 ret = 0;
Holger Schurig9012b282007-05-25 11:27:16 -04001589
1590done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001591 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001592 return ret;
1593}
1594
1595/**
1596 * @brief This function frees the command buffer.
1597 *
Holger Schurig69f90322007-11-23 15:43:44 +01001598 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001599 * @return 0 or -1
1600 */
Holger Schurig69f90322007-11-23 15:43:44 +01001601int lbs_free_cmd_buffer(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001602{
Dan Williamsddac4522007-12-11 13:49:39 -05001603 struct cmd_ctrl_node *cmdarray;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001604 unsigned int i;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001605
Holger Schurig8ff12da2007-08-02 11:54:31 -04001606 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001607
1608 /* need to check if cmd array is allocated or not */
David Woodhouseaa21c002007-12-08 20:04:36 +00001609 if (priv->cmd_array == NULL) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001610 lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001611 goto done;
1612 }
1613
Dan Williamsddac4522007-12-11 13:49:39 -05001614 cmdarray = priv->cmd_array;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001615
1616 /* Release shared memory buffers */
Dan Williamsddac4522007-12-11 13:49:39 -05001617 for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) {
1618 if (cmdarray[i].cmdbuf) {
1619 kfree(cmdarray[i].cmdbuf);
1620 cmdarray[i].cmdbuf = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001621 }
1622 }
1623
1624 /* Release cmd_ctrl_node */
David Woodhouseaa21c002007-12-08 20:04:36 +00001625 if (priv->cmd_array) {
1626 kfree(priv->cmd_array);
1627 priv->cmd_array = NULL;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001628 }
1629
1630done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001631 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001632 return 0;
1633}
1634
1635/**
1636 * @brief This function gets a free command node if available in
1637 * command free queue.
1638 *
Holger Schurig69f90322007-11-23 15:43:44 +01001639 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001640 * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL
1641 */
David Woodhouse2fd6cfe2007-12-11 17:44:10 -05001642static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001643{
1644 struct cmd_ctrl_node *tempnode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001645 unsigned long flags;
1646
Holger Schurig8ff12da2007-08-02 11:54:31 -04001647 lbs_deb_enter(LBS_DEB_HOST);
1648
David Woodhouseaa21c002007-12-08 20:04:36 +00001649 if (!priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001650 return NULL;
1651
David Woodhouseaa21c002007-12-08 20:04:36 +00001652 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001653
David Woodhouseaa21c002007-12-08 20:04:36 +00001654 if (!list_empty(&priv->cmdfreeq)) {
1655 tempnode = list_first_entry(&priv->cmdfreeq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001656 struct cmd_ctrl_node, list);
1657 list_del(&tempnode->list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001658 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001659 lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001660 tempnode = NULL;
1661 }
1662
David Woodhouseaa21c002007-12-08 20:04:36 +00001663 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001664
Holger Schurig8ff12da2007-08-02 11:54:31 -04001665 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001666 return tempnode;
1667}
1668
1669/**
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001670 * @brief This function executes next command in command
Nick Andrew877d0312009-01-26 11:06:57 +01001671 * pending queue. It will put firmware back to PS mode
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001672 * if applicable.
1673 *
Holger Schurig69f90322007-11-23 15:43:44 +01001674 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001675 * @return 0 or -1
1676 */
Holger Schurig69f90322007-11-23 15:43:44 +01001677int lbs_execute_next_command(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001678{
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001679 struct cmd_ctrl_node *cmdnode = NULL;
Dan Williamsddac4522007-12-11 13:49:39 -05001680 struct cmd_header *cmd;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001681 unsigned long flags;
1682 int ret = 0;
1683
Holger Schurig1afc09ab2008-01-29 09:14:40 +01001684 /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the
1685 * only caller to us is lbs_thread() and we get even when a
1686 * data packet is received */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001687 lbs_deb_enter(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001688
David Woodhouseaa21c002007-12-08 20:04:36 +00001689 spin_lock_irqsave(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001690
David Woodhouseaa21c002007-12-08 20:04:36 +00001691 if (priv->cur_cmd) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001692 lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n");
David Woodhouseaa21c002007-12-08 20:04:36 +00001693 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001694 ret = -1;
1695 goto done;
1696 }
1697
David Woodhouseaa21c002007-12-08 20:04:36 +00001698 if (!list_empty(&priv->cmdpendingq)) {
1699 cmdnode = list_first_entry(&priv->cmdpendingq,
Li Zefanabe3ed12007-12-06 13:01:21 +01001700 struct cmd_ctrl_node, list);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001701 }
1702
David Woodhouseaa21c002007-12-08 20:04:36 +00001703 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001704
1705 if (cmdnode) {
Dan Williamsddac4522007-12-11 13:49:39 -05001706 cmd = cmdnode->cmdbuf;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001707
Dan Williamsddac4522007-12-11 13:49:39 -05001708 if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) {
David Woodhouseaa21c002007-12-08 20:04:36 +00001709 if ((priv->psstate == PS_STATE_SLEEP) ||
1710 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001711 lbs_deb_host(
1712 "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001713 le16_to_cpu(cmd->command),
David Woodhouseaa21c002007-12-08 20:04:36 +00001714 priv->psstate);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001715 ret = -1;
1716 goto done;
1717 }
Holger Schurig8ff12da2007-08-02 11:54:31 -04001718 lbs_deb_host("EXEC_NEXT_CMD: OK to send command "
Dan Williamsddac4522007-12-11 13:49:39 -05001719 "0x%04x in psstate %d\n",
1720 le16_to_cpu(cmd->command), priv->psstate);
David Woodhouseaa21c002007-12-08 20:04:36 +00001721 } else if (priv->psstate != PS_STATE_FULL_POWER) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001722 /*
1723 * 1. Non-PS command:
1724 * Queue it. set needtowakeup to TRUE if current state
Holger Schurig10078322007-11-15 18:05:47 -05001725 * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001726 * 2. PS command but not Exit_PS:
1727 * Ignore it.
1728 * 3. PS command Exit_PS:
1729 * Set needtowakeup to TRUE if current state is SLEEP,
1730 * otherwise send this command down to firmware
1731 * immediately.
1732 */
Dan Williamsddac4522007-12-11 13:49:39 -05001733 if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001734 /* Prepare to send Exit PS,
1735 * this non PS command will be sent later */
David Woodhouseaa21c002007-12-08 20:04:36 +00001736 if ((priv->psstate == PS_STATE_SLEEP)
1737 || (priv->psstate == PS_STATE_PRE_SLEEP)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001738 ) {
1739 /* w/ new scheme, it will not reach here.
1740 since it is blocked in main_thread. */
David Woodhouseaa21c002007-12-08 20:04:36 +00001741 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001742 } else
Holger Schurig10078322007-11-15 18:05:47 -05001743 lbs_ps_wakeup(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001744
1745 ret = 0;
1746 goto done;
1747 } else {
1748 /*
1749 * PS command. Ignore it if it is not Exit_PS.
1750 * otherwise send it down immediately.
1751 */
David Woodhouse38bfab12007-12-16 23:26:54 -05001752 struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1];
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001753
Holger Schurig8ff12da2007-08-02 11:54:31 -04001754 lbs_deb_host(
1755 "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n",
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001756 psm->action);
1757 if (psm->action !=
Dan Williams0aef64d2007-08-02 11:31:18 -04001758 cpu_to_le16(CMD_SUBCMD_EXIT_PS)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001759 lbs_deb_host(
1760 "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001761 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001762 spin_lock_irqsave(&priv->driver_lock, flags);
1763 lbs_complete_command(priv, cmdnode, 0);
1764 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001765
1766 ret = 0;
1767 goto done;
1768 }
1769
David Woodhouseaa21c002007-12-08 20:04:36 +00001770 if ((priv->psstate == PS_STATE_SLEEP) ||
1771 (priv->psstate == PS_STATE_PRE_SLEEP)) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001772 lbs_deb_host(
1773 "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n");
Li Zefanabe3ed12007-12-06 13:01:21 +01001774 list_del(&cmdnode->list);
David Woodhouse183aeac2007-12-15 01:52:54 -05001775 spin_lock_irqsave(&priv->driver_lock, flags);
1776 lbs_complete_command(priv, cmdnode, 0);
1777 spin_unlock_irqrestore(&priv->driver_lock, flags);
David Woodhouseaa21c002007-12-08 20:04:36 +00001778 priv->needtowakeup = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001779
1780 ret = 0;
1781 goto done;
1782 }
1783
Holger Schurig8ff12da2007-08-02 11:54:31 -04001784 lbs_deb_host(
1785 "EXEC_NEXT_CMD: sending EXIT_PS\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001786 }
1787 }
Li Zefanabe3ed12007-12-06 13:01:21 +01001788 list_del(&cmdnode->list);
Holger Schurig8ff12da2007-08-02 11:54:31 -04001789 lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n",
Dan Williamsddac4522007-12-11 13:49:39 -05001790 le16_to_cpu(cmd->command));
David Woodhoused9896ee2007-12-15 00:09:25 -05001791 lbs_submit_command(priv, cmdnode);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001792 } else {
1793 /*
1794 * check if in power save mode, if yes, put the device back
1795 * to PS mode
1796 */
David Woodhouseaa21c002007-12-08 20:04:36 +00001797 if ((priv->psmode != LBS802_11POWERMODECAM) &&
1798 (priv->psstate == PS_STATE_FULL_POWER) &&
1799 ((priv->connect_status == LBS_CONNECTED) ||
1800 (priv->mesh_connect_status == LBS_CONNECTED))) {
1801 if (priv->secinfo.WPAenabled ||
1802 priv->secinfo.WPA2enabled) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001803 /* check for valid WPA group keys */
David Woodhouseaa21c002007-12-08 20:04:36 +00001804 if (priv->wpa_mcast_key.len ||
1805 priv->wpa_unicast_key.len) {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001806 lbs_deb_host(
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001807 "EXEC_NEXT_CMD: WPA enabled and GTK_SET"
1808 " go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001809 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001810 }
1811 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001812 lbs_deb_host(
1813 "EXEC_NEXT_CMD: cmdpendingq empty, "
1814 "go back to PS_SLEEP");
Holger Schurig10078322007-11-15 18:05:47 -05001815 lbs_ps_sleep(priv, 0);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001816 }
1817 }
1818 }
1819
1820 ret = 0;
1821done:
Holger Schurig8ff12da2007-08-02 11:54:31 -04001822 lbs_deb_leave(LBS_DEB_THREAD);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001823 return ret;
1824}
1825
Holger Schurig69f90322007-11-23 15:43:44 +01001826void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001827{
1828 union iwreq_data iwrq;
1829 u8 buf[50];
1830
Holger Schurig8ff12da2007-08-02 11:54:31 -04001831 lbs_deb_enter(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001832
1833 memset(&iwrq, 0, sizeof(union iwreq_data));
1834 memset(buf, 0, sizeof(buf));
1835
1836 snprintf(buf, sizeof(buf) - 1, "%s", str);
1837
1838 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
1839
1840 /* Send Event to upper layer */
Holger Schurig8ff12da2007-08-02 11:54:31 -04001841 lbs_deb_wext("event indication string %s\n", (char *)buf);
1842 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
1843 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001844
Holger Schurig634b8f42007-05-25 13:05:16 -04001845 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001846
Holger Schurig8ff12da2007-08-02 11:54:31 -04001847 lbs_deb_leave(LBS_DEB_WEXT);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001848}
1849
Holger Schurigf539f2e2008-03-26 13:22:11 +01001850static void lbs_send_confirmsleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001851{
1852 unsigned long flags;
Holger Schurigf539f2e2008-03-26 13:22:11 +01001853 int ret;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001854
Holger Schurig8ff12da2007-08-02 11:54:31 -04001855 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurigf539f2e2008-03-26 13:22:11 +01001856 lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep,
1857 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001858
Holger Schurigf539f2e2008-03-26 13:22:11 +01001859 ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep,
1860 sizeof(confirm_sleep));
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001861 if (ret) {
Holger Schurigf539f2e2008-03-26 13:22:11 +01001862 lbs_pr_alert("confirm_sleep failed\n");
Holger Schurig7919b892008-04-01 14:50:43 +02001863 goto out;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001864 }
Holger Schurig7919b892008-04-01 14:50:43 +02001865
1866 spin_lock_irqsave(&priv->driver_lock, flags);
1867
Holger Schuriga01f5452008-06-04 11:10:40 +02001868 /* We don't get a response on the sleep-confirmation */
1869 priv->dnld_sent = DNLD_RES_RECEIVED;
1870
Holger Schurig7919b892008-04-01 14:50:43 +02001871 /* If nothing to do, go back to sleep (?) */
1872 if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx])
1873 priv->psstate = PS_STATE_SLEEP;
1874
1875 spin_unlock_irqrestore(&priv->driver_lock, flags);
1876
1877out:
Holger Schurigf539f2e2008-03-26 13:22:11 +01001878 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001879}
1880
Holger Schurig69f90322007-11-23 15:43:44 +01001881void lbs_ps_sleep(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001882{
Holger Schurig8ff12da2007-08-02 11:54:31 -04001883 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001884
1885 /*
1886 * PS is currently supported only in Infrastructure mode
1887 * Remove this check if it is to be supported in IBSS mode also
1888 */
1889
Holger Schurig10078322007-11-15 18:05:47 -05001890 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001891 CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001892
Holger Schurig8ff12da2007-08-02 11:54:31 -04001893 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001894}
1895
1896/**
Holger Schurig8ff12da2007-08-02 11:54:31 -04001897 * @brief This function sends Exit_PS command to firmware.
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001898 *
Holger Schurig69f90322007-11-23 15:43:44 +01001899 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001900 * @param wait_option wait response or not
1901 * @return n/a
1902 */
Holger Schurig69f90322007-11-23 15:43:44 +01001903void lbs_ps_wakeup(struct lbs_private *priv, int wait_option)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001904{
David Woodhouse981f1872007-05-25 23:36:54 -04001905 __le32 Localpsmode;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001906
Holger Schurig8ff12da2007-08-02 11:54:31 -04001907 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001908
Holger Schurig10078322007-11-15 18:05:47 -05001909 Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001910
Holger Schurig10078322007-11-15 18:05:47 -05001911 lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE,
Dan Williams0aef64d2007-08-02 11:31:18 -04001912 CMD_SUBCMD_EXIT_PS,
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001913 wait_option, 0, &Localpsmode);
1914
Holger Schurig8ff12da2007-08-02 11:54:31 -04001915 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001916}
1917
1918/**
1919 * @brief This function checks condition and prepares to
1920 * send sleep confirm command to firmware if ok.
1921 *
Holger Schurig69f90322007-11-23 15:43:44 +01001922 * @param priv A pointer to struct lbs_private structure
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001923 * @param psmode Power Saving mode
1924 * @return n/a
1925 */
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001926void lbs_ps_confirm_sleep(struct lbs_private *priv)
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001927{
1928 unsigned long flags =0;
Holger Schurigd4ff0ef2008-03-19 14:25:18 +01001929 int allowed = 1;
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001930
Holger Schurig8ff12da2007-08-02 11:54:31 -04001931 lbs_deb_enter(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001932
Holger Schuriga01f5452008-06-04 11:10:40 +02001933 spin_lock_irqsave(&priv->driver_lock, flags);
Holger Schurig634b8f42007-05-25 13:05:16 -04001934 if (priv->dnld_sent) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001935 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001936 lbs_deb_host("dnld_sent was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001937 }
1938
Holger Schurig7919b892008-04-01 14:50:43 +02001939 /* In-progress command? */
David Woodhouseaa21c002007-12-08 20:04:36 +00001940 if (priv->cur_cmd) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001941 allowed = 0;
David Woodhouse23d36ee2007-12-12 00:14:21 -05001942 lbs_deb_host("cur_cmd was set\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001943 }
Holger Schurig7919b892008-04-01 14:50:43 +02001944
1945 /* Pending events or command responses? */
1946 if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) {
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001947 allowed = 0;
Holger Schurig7919b892008-04-01 14:50:43 +02001948 lbs_deb_host("pending events or command responses\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001949 }
David Woodhouseaa21c002007-12-08 20:04:36 +00001950 spin_unlock_irqrestore(&priv->driver_lock, flags);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001951
1952 if (allowed) {
Holger Schurig10078322007-11-15 18:05:47 -05001953 lbs_deb_host("sending lbs_ps_confirm_sleep\n");
Holger Schurigf539f2e2008-03-26 13:22:11 +01001954 lbs_send_confirmsleep(priv);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001955 } else {
Holger Schurig8ff12da2007-08-02 11:54:31 -04001956 lbs_deb_host("sleep confirm has been delayed\n");
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001957 }
1958
Holger Schurig8ff12da2007-08-02 11:54:31 -04001959 lbs_deb_leave(LBS_DEB_HOST);
Marcelo Tosatti876c9d32007-02-10 12:25:27 -02001960}
Holger Schurig675787e2007-12-05 17:58:11 +01001961
1962
Anna Neal0112c9e2008-09-11 11:17:25 -07001963/**
1964 * @brief Configures the transmission power control functionality.
1965 *
1966 * @param priv A pointer to struct lbs_private structure
1967 * @param enable Transmission power control enable
1968 * @param p0 Power level when link quality is good (dBm).
1969 * @param p1 Power level when link quality is fair (dBm).
1970 * @param p2 Power level when link quality is poor (dBm).
1971 * @param usesnr Use Signal to Noise Ratio in TPC
1972 *
1973 * @return 0 on success
1974 */
1975int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1,
1976 int8_t p2, int usesnr)
1977{
1978 struct cmd_ds_802_11_tpc_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;
Anna Neal3ed6e082008-09-26 11:34:35 -04001985 cmd.usesnr = !!usesnr;
Anna Neal0112c9e2008-09-11 11:17:25 -07001986 cmd.P0 = p0;
1987 cmd.P1 = p1;
1988 cmd.P2 = p2;
1989
1990 ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd);
1991
1992 return ret;
1993}
1994
1995/**
1996 * @brief Configures the power adaptation settings.
1997 *
1998 * @param priv A pointer to struct lbs_private structure
1999 * @param enable Power adaptation enable
2000 * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm).
2001 * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm).
2002 * @param p2 Power level for 48 and 54 Mbps (dBm).
2003 *
2004 * @return 0 on Success
2005 */
2006
2007int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0,
2008 int8_t p1, int8_t p2)
2009{
2010 struct cmd_ds_802_11_pa_cfg cmd;
2011 int ret;
2012
2013 memset(&cmd, 0, sizeof(cmd));
2014 cmd.hdr.size = cpu_to_le16(sizeof(cmd));
2015 cmd.action = cpu_to_le16(CMD_ACT_SET);
2016 cmd.enable = !!enable;
2017 cmd.P0 = p0;
2018 cmd.P1 = p1;
2019 cmd.P2 = p2;
2020
2021 ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd);
2022
2023 return ret;
2024}
2025
2026
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002027static struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv,
2028 uint16_t command, struct cmd_header *in_cmd, int in_cmd_size,
2029 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2030 unsigned long callback_arg)
Holger Schurig675787e2007-12-05 17:58:11 +01002031{
Holger Schurig675787e2007-12-05 17:58:11 +01002032 struct cmd_ctrl_node *cmdnode;
Holger Schurig675787e2007-12-05 17:58:11 +01002033
2034 lbs_deb_enter(LBS_DEB_HOST);
Holger Schurig675787e2007-12-05 17:58:11 +01002035
David Woodhouseaa21c002007-12-08 20:04:36 +00002036 if (priv->surpriseremoved) {
Holger Schurig675787e2007-12-05 17:58:11 +01002037 lbs_deb_host("PREP_CMD: card removed\n");
David Woodhouse3399ea52007-12-15 03:09:33 -05002038 cmdnode = ERR_PTR(-ENOENT);
Holger Schurig675787e2007-12-05 17:58:11 +01002039 goto done;
2040 }
2041
2042 cmdnode = lbs_get_cmd_ctrl_node(priv);
Holger Schurig675787e2007-12-05 17:58:11 +01002043 if (cmdnode == NULL) {
2044 lbs_deb_host("PREP_CMD: cmdnode is NULL\n");
2045
2046 /* Wake up main thread to execute next command */
2047 wake_up_interruptible(&priv->waitq);
David Woodhouse3399ea52007-12-15 03:09:33 -05002048 cmdnode = ERR_PTR(-ENOBUFS);
Holger Schurig675787e2007-12-05 17:58:11 +01002049 goto done;
2050 }
2051
David Woodhouse448a51a2007-12-08 00:59:54 +00002052 cmdnode->callback = callback;
David Woodhouse1309b552007-12-10 13:36:10 -05002053 cmdnode->callback_arg = callback_arg;
Holger Schurig675787e2007-12-05 17:58:11 +01002054
Dan Williams7ad994d2007-12-11 12:33:30 -05002055 /* Copy the incoming command to the buffer */
Dan Williamsddac4522007-12-11 13:49:39 -05002056 memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size);
Dan Williams7ad994d2007-12-11 12:33:30 -05002057
Holger Schurig675787e2007-12-05 17:58:11 +01002058 /* Set sequence number, clean result, move to buffer */
David Woodhouseaa21c002007-12-08 20:04:36 +00002059 priv->seqnum++;
Dan Williamsddac4522007-12-11 13:49:39 -05002060 cmdnode->cmdbuf->command = cpu_to_le16(command);
2061 cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size);
2062 cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum);
2063 cmdnode->cmdbuf->result = 0;
Holger Schurig675787e2007-12-05 17:58:11 +01002064
2065 lbs_deb_host("PREP_CMD: command 0x%04x\n", command);
2066
Holger Schurig675787e2007-12-05 17:58:11 +01002067 cmdnode->cmdwaitqwoken = 0;
David Woodhouse681ffbb2007-12-15 20:04:54 -05002068 lbs_queue_cmd(priv, cmdnode);
Holger Schurig675787e2007-12-05 17:58:11 +01002069 wake_up_interruptible(&priv->waitq);
2070
David Woodhouse3399ea52007-12-15 03:09:33 -05002071 done:
2072 lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode);
2073 return cmdnode;
2074}
2075
Holger Schurig8db4a2b2008-03-19 10:11:00 +01002076void lbs_cmd_async(struct lbs_private *priv, uint16_t command,
2077 struct cmd_header *in_cmd, int in_cmd_size)
2078{
2079 lbs_deb_enter(LBS_DEB_CMD);
2080 __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2081 lbs_cmd_async_callback, 0);
2082 lbs_deb_leave(LBS_DEB_CMD);
2083}
2084
David Woodhouse3399ea52007-12-15 03:09:33 -05002085int __lbs_cmd(struct lbs_private *priv, uint16_t command,
2086 struct cmd_header *in_cmd, int in_cmd_size,
2087 int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *),
2088 unsigned long callback_arg)
2089{
2090 struct cmd_ctrl_node *cmdnode;
2091 unsigned long flags;
2092 int ret = 0;
2093
2094 lbs_deb_enter(LBS_DEB_HOST);
2095
2096 cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size,
2097 callback, callback_arg);
2098 if (IS_ERR(cmdnode)) {
2099 ret = PTR_ERR(cmdnode);
2100 goto done;
2101 }
2102
Holger Schurig675787e2007-12-05 17:58:11 +01002103 might_sleep();
2104 wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken);
2105
David Woodhouseaa21c002007-12-08 20:04:36 +00002106 spin_lock_irqsave(&priv->driver_lock, flags);
David Woodhouseae125bf2007-12-15 04:22:52 -05002107 ret = cmdnode->result;
2108 if (ret)
2109 lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n",
2110 command, ret);
David Woodhouse3399ea52007-12-15 03:09:33 -05002111
David Woodhousead12d0f2007-12-15 02:06:16 -05002112 __lbs_cleanup_and_insert_cmd(priv, cmdnode);
David Woodhouseaa21c002007-12-08 20:04:36 +00002113 spin_unlock_irqrestore(&priv->driver_lock, flags);
Holger Schurig675787e2007-12-05 17:58:11 +01002114
2115done:
2116 lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret);
2117 return ret;
2118}
Dan Williams14e865b2007-12-10 15:11:23 -05002119EXPORT_SYMBOL_GPL(__lbs_cmd);
Holger Schurig675787e2007-12-05 17:58:11 +01002120
2121