Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | /** |
| 2 | * This file contains the handling of command. |
| 3 | * It prepares command and sends it to firmware when it is ready. |
| 4 | */ |
| 5 | |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 6 | #include <net/lib80211.h> |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 7 | #include <linux/kfifo.h> |
Holger Schurig | e93156e | 2009-10-22 15:30:58 +0200 | [diff] [blame] | 8 | #include <linux/sched.h> |
| 9 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 10 | #include "host.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 11 | #include "decl.h" |
| 12 | #include "defs.h" |
| 13 | #include "dev.h" |
Holger Schurig | 697900a | 2008-04-02 16:27:10 +0200 | [diff] [blame] | 14 | #include "assoc.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 15 | #include "wext.h" |
Holger Schurig | 2d46502 | 2009-10-22 15:30:48 +0200 | [diff] [blame] | 16 | #include "scan.h" |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 17 | #include "cmd.h" |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 18 | |
Holger Schurig | e93156e | 2009-10-22 15:30:58 +0200 | [diff] [blame] | 19 | |
David Woodhouse | 2fd6cfe | 2007-12-11 17:44:10 -0500 | [diff] [blame] | 20 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv); |
Holger Schurig | 0d61d04 | 2007-12-05 17:58:06 +0100 | [diff] [blame] | 21 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 22 | /** |
Holger Schurig | 8db4a2b | 2008-03-19 10:11:00 +0100 | [diff] [blame] | 23 | * @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 | */ |
| 32 | int 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 | } |
| 42 | EXPORT_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 | */ |
| 55 | static 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 Williams | 852e1f2 | 2007-12-10 15:24:47 -0500 | [diff] [blame] | 63 | * @brief Checks whether a command is allowed in Power Save mode |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 64 | * |
| 65 | * @param command the command ID |
Dan Williams | 852e1f2 | 2007-12-10 15:24:47 -0500 | [diff] [blame] | 66 | * @return 1 if allowed, 0 if not allowed |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 67 | */ |
Dan Williams | 852e1f2 | 2007-12-10 15:24:47 -0500 | [diff] [blame] | 68 | static u8 is_command_allowed_in_ps(u16 cmd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 69 | { |
Dan Williams | 852e1f2 | 2007-12-10 15:24:47 -0500 | [diff] [blame] | 70 | switch (cmd) { |
| 71 | case CMD_802_11_RSSI: |
| 72 | return 1; |
| 73 | default: |
| 74 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 75 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 76 | return 0; |
| 77 | } |
| 78 | |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 79 | /** |
Amitkumar Karwar | 63f275d | 2009-10-06 19:20:28 -0700 | [diff] [blame] | 80 | * @brief This function checks if the command is allowed. |
| 81 | * |
| 82 | * @param priv A pointer to lbs_private structure |
| 83 | * @return allowed or not allowed. |
| 84 | */ |
| 85 | |
| 86 | static int lbs_is_cmd_allowed(struct lbs_private *priv) |
| 87 | { |
| 88 | int ret = 1; |
| 89 | |
| 90 | lbs_deb_enter(LBS_DEB_CMD); |
| 91 | |
| 92 | if (!priv->is_auto_deep_sleep_enabled) { |
| 93 | if (priv->is_deep_sleep) { |
| 94 | lbs_deb_cmd("command not allowed in deep sleep\n"); |
| 95 | ret = 0; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | lbs_deb_leave(LBS_DEB_CMD); |
| 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | /** |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 104 | * @brief Updates the hardware details like MAC address and regulatory region |
| 105 | * |
| 106 | * @param priv A pointer to struct lbs_private structure |
| 107 | * |
| 108 | * @return 0 on success, error on failure |
| 109 | */ |
| 110 | int lbs_update_hw_spec(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 111 | { |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 112 | struct cmd_ds_get_hw_spec cmd; |
| 113 | int ret = -1; |
| 114 | u32 i; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 115 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 116 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 117 | |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 118 | memset(&cmd, 0, sizeof(cmd)); |
| 119 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 120 | memcpy(cmd.permanentaddr, priv->current_addr, ETH_ALEN); |
David Woodhouse | 689442d | 2007-12-12 16:00:42 -0500 | [diff] [blame] | 121 | ret = lbs_cmd_with_response(priv, CMD_GET_HW_SPEC, &cmd); |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 122 | if (ret) |
| 123 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 124 | |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 125 | priv->fwcapinfo = le32_to_cpu(cmd.fwcapinfo); |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 126 | |
Holger Schurig | dac10a9 | 2008-01-16 15:55:22 +0100 | [diff] [blame] | 127 | /* The firmware release is in an interesting format: the patch |
| 128 | * level is in the most significant nibble ... so fix that: */ |
| 129 | priv->fwrelease = le32_to_cpu(cmd.fwrelease); |
| 130 | priv->fwrelease = (priv->fwrelease << 8) | |
| 131 | (priv->fwrelease >> 24 & 0xff); |
| 132 | |
| 133 | /* Some firmware capabilities: |
| 134 | * CF card firmware 5.0.16p0: cap 0x00000303 |
| 135 | * USB dongle firmware 5.110.17p2: cap 0x00000303 |
| 136 | */ |
Johannes Berg | e174961 | 2008-10-27 15:59:26 -0700 | [diff] [blame] | 137 | lbs_pr_info("%pM, fw %u.%u.%up%u, cap 0x%08x\n", |
| 138 | cmd.permanentaddr, |
Holger Schurig | dac10a9 | 2008-01-16 15:55:22 +0100 | [diff] [blame] | 139 | priv->fwrelease >> 24 & 0xff, |
| 140 | priv->fwrelease >> 16 & 0xff, |
| 141 | priv->fwrelease >> 8 & 0xff, |
| 142 | priv->fwrelease & 0xff, |
| 143 | priv->fwcapinfo); |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 144 | lbs_deb_cmd("GET_HW_SPEC: hardware interface 0x%x, hardware spec 0x%04x\n", |
| 145 | cmd.hwifversion, cmd.version); |
| 146 | |
Bing Zhao | 684d6b3 | 2009-03-25 09:51:16 -0700 | [diff] [blame] | 147 | /* Determine mesh_fw_ver from fwrelease and fwcapinfo */ |
| 148 | /* 5.0.16p0 9.0.0.p0 is known to NOT support any mesh */ |
| 149 | /* 5.110.22 have mesh command with 0xa3 command id */ |
| 150 | /* 10.0.0.p0 FW brings in mesh config command with different id */ |
| 151 | /* Check FW version MSB and initialize mesh_fw_ver */ |
| 152 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V5) |
| 153 | priv->mesh_fw_ver = MESH_FW_OLD; |
| 154 | else if ((MRVL_FW_MAJOR_REV(priv->fwrelease) >= MRVL_FW_V10) && |
| 155 | (priv->fwcapinfo & MESH_CAPINFO_ENABLE_MASK)) |
| 156 | priv->mesh_fw_ver = MESH_FW_NEW; |
| 157 | else |
| 158 | priv->mesh_fw_ver = MESH_NONE; |
| 159 | |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 160 | /* Clamp region code to 8-bit since FW spec indicates that it should |
| 161 | * only ever be 8-bit, even though the field size is 16-bit. Some firmware |
| 162 | * returns non-zero high 8 bits here. |
Marek Vasut | 1548399 | 2009-07-16 19:19:53 +0200 | [diff] [blame] | 163 | * |
| 164 | * Firmware version 4.0.102 used in CF8381 has region code shifted. We |
| 165 | * need to check for this problem and handle it properly. |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 166 | */ |
Marek Vasut | 1548399 | 2009-07-16 19:19:53 +0200 | [diff] [blame] | 167 | if (MRVL_FW_MAJOR_REV(priv->fwrelease) == MRVL_FW_V4) |
| 168 | priv->regioncode = (le16_to_cpu(cmd.regioncode) >> 8) & 0xFF; |
| 169 | else |
| 170 | priv->regioncode = le16_to_cpu(cmd.regioncode) & 0xFF; |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 171 | |
| 172 | for (i = 0; i < MRVDRV_MAX_REGION_CODE; i++) { |
| 173 | /* use the region code to search for the index */ |
| 174 | if (priv->regioncode == lbs_region_code_to_index[i]) |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | /* if it's unidentified region code, use the default (USA) */ |
| 179 | if (i >= MRVDRV_MAX_REGION_CODE) { |
| 180 | priv->regioncode = 0x10; |
| 181 | lbs_pr_info("unidentified region code; using the default (USA)\n"); |
| 182 | } |
| 183 | |
| 184 | if (priv->current_addr[0] == 0xff) |
| 185 | memmove(priv->current_addr, cmd.permanentaddr, ETH_ALEN); |
| 186 | |
| 187 | memcpy(priv->dev->dev_addr, priv->current_addr, ETH_ALEN); |
| 188 | if (priv->mesh_dev) |
| 189 | memcpy(priv->mesh_dev->dev_addr, priv->current_addr, ETH_ALEN); |
| 190 | |
| 191 | if (lbs_set_regiontable(priv, priv->regioncode, 0)) { |
| 192 | ret = -1; |
| 193 | goto out; |
| 194 | } |
| 195 | |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 196 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 197 | lbs_deb_leave(LBS_DEB_CMD); |
Dan Williams | 6e66f03 | 2007-12-11 12:42:16 -0500 | [diff] [blame] | 198 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 199 | } |
| 200 | |
Anna Neal | 582c1b5 | 2008-10-20 16:46:56 -0700 | [diff] [blame] | 201 | int lbs_host_sleep_cfg(struct lbs_private *priv, uint32_t criteria, |
| 202 | struct wol_config *p_wol_config) |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 203 | { |
| 204 | struct cmd_ds_host_sleep cmd_config; |
| 205 | int ret; |
| 206 | |
David Woodhouse | 9fae899 | 2007-12-15 03:46:44 -0500 | [diff] [blame] | 207 | cmd_config.hdr.size = cpu_to_le16(sizeof(cmd_config)); |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 208 | cmd_config.criteria = cpu_to_le32(criteria); |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 209 | cmd_config.gpio = priv->wol_gpio; |
| 210 | cmd_config.gap = priv->wol_gap; |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 211 | |
Anna Neal | 582c1b5 | 2008-10-20 16:46:56 -0700 | [diff] [blame] | 212 | if (p_wol_config != NULL) |
| 213 | memcpy((uint8_t *)&cmd_config.wol_conf, (uint8_t *)p_wol_config, |
| 214 | sizeof(struct wol_config)); |
| 215 | else |
| 216 | cmd_config.wol_conf.action = CMD_ACT_ACTION_NONE; |
| 217 | |
David Woodhouse | 689442d | 2007-12-12 16:00:42 -0500 | [diff] [blame] | 218 | ret = lbs_cmd_with_response(priv, CMD_802_11_HOST_SLEEP_CFG, &cmd_config); |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 219 | if (!ret) { |
Anna Neal | 582c1b5 | 2008-10-20 16:46:56 -0700 | [diff] [blame] | 220 | if (criteria) { |
| 221 | lbs_deb_cmd("Set WOL criteria to %x\n", criteria); |
| 222 | priv->wol_criteria = criteria; |
| 223 | } else |
| 224 | memcpy((uint8_t *) p_wol_config, |
| 225 | (uint8_t *)&cmd_config.wol_conf, |
| 226 | sizeof(struct wol_config)); |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 227 | } else { |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 228 | lbs_pr_info("HOST_SLEEP_CFG failed %d\n", ret); |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 229 | } |
David Woodhouse | 506e902 | 2007-12-12 20:06:06 -0500 | [diff] [blame] | 230 | |
David Woodhouse | 6ce4fd2 | 2007-12-12 15:19:29 -0500 | [diff] [blame] | 231 | return ret; |
| 232 | } |
| 233 | EXPORT_SYMBOL_GPL(lbs_host_sleep_cfg); |
| 234 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 235 | static int lbs_cmd_802_11_ps_mode(struct cmd_ds_command *cmd, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 236 | u16 cmd_action) |
| 237 | { |
| 238 | struct cmd_ds_802_11_ps_mode *psm = &cmd->params.psmode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 239 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 240 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 241 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 242 | cmd->command = cpu_to_le16(CMD_802_11_PS_MODE); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 243 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_ps_mode) + |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 244 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 245 | psm->action = cpu_to_le16(cmd_action); |
| 246 | psm->multipledtim = 0; |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 247 | switch (cmd_action) { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 248 | case CMD_SUBCMD_ENTER_PS: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 249 | lbs_deb_cmd("PS command:" "SubCode- Enter PS\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 250 | |
Holger Schurig | 252cf0d | 2007-08-02 13:09:34 -0400 | [diff] [blame] | 251 | psm->locallisteninterval = 0; |
Holger Schurig | 97605c3 | 2007-08-02 13:09:15 -0400 | [diff] [blame] | 252 | psm->nullpktinterval = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 253 | psm->multipledtim = |
Holger Schurig | 56c4656 | 2007-08-02 13:09:49 -0400 | [diff] [blame] | 254 | cpu_to_le16(MRVDRV_DEFAULT_MULTIPLE_DTIM); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 255 | break; |
| 256 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 257 | case CMD_SUBCMD_EXIT_PS: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 258 | lbs_deb_cmd("PS command:" "SubCode- Exit PS\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 259 | break; |
| 260 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 261 | case CMD_SUBCMD_SLEEP_CONFIRMED: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 262 | lbs_deb_cmd("PS command: SubCode- sleep confirm\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 263 | break; |
| 264 | |
| 265 | default: |
| 266 | break; |
| 267 | } |
| 268 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 269 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 270 | return 0; |
| 271 | } |
| 272 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 273 | int lbs_cmd_802_11_sleep_params(struct lbs_private *priv, uint16_t cmd_action, |
| 274 | struct sleep_params *sp) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 275 | { |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 276 | struct cmd_ds_802_11_sleep_params cmd; |
| 277 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 278 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 279 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 280 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 281 | if (cmd_action == CMD_ACT_GET) { |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 282 | memset(&cmd, 0, sizeof(cmd)); |
| 283 | } else { |
| 284 | cmd.error = cpu_to_le16(sp->sp_error); |
| 285 | cmd.offset = cpu_to_le16(sp->sp_offset); |
| 286 | cmd.stabletime = cpu_to_le16(sp->sp_stabletime); |
| 287 | cmd.calcontrol = sp->sp_calcontrol; |
| 288 | cmd.externalsleepclk = sp->sp_extsleepclk; |
| 289 | cmd.reserved = cpu_to_le16(sp->sp_reserved); |
| 290 | } |
| 291 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 292 | cmd.action = cpu_to_le16(cmd_action); |
| 293 | |
| 294 | ret = lbs_cmd_with_response(priv, CMD_802_11_SLEEP_PARAMS, &cmd); |
| 295 | |
| 296 | if (!ret) { |
| 297 | lbs_deb_cmd("error 0x%x, offset 0x%x, stabletime 0x%x, " |
| 298 | "calcontrol 0x%x extsleepclk 0x%x\n", |
| 299 | le16_to_cpu(cmd.error), le16_to_cpu(cmd.offset), |
| 300 | le16_to_cpu(cmd.stabletime), cmd.calcontrol, |
| 301 | cmd.externalsleepclk); |
| 302 | |
| 303 | sp->sp_error = le16_to_cpu(cmd.error); |
| 304 | sp->sp_offset = le16_to_cpu(cmd.offset); |
| 305 | sp->sp_stabletime = le16_to_cpu(cmd.stabletime); |
| 306 | sp->sp_calcontrol = cmd.calcontrol; |
| 307 | sp->sp_extsleepclk = cmd.externalsleepclk; |
| 308 | sp->sp_reserved = le16_to_cpu(cmd.reserved); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 309 | } |
| 310 | |
David Woodhouse | 3fbe104 | 2007-12-17 23:48:31 -0500 | [diff] [blame] | 311 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 312 | return 0; |
| 313 | } |
| 314 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 315 | static int lbs_wait_for_ds_awake(struct lbs_private *priv) |
| 316 | { |
| 317 | int ret = 0; |
| 318 | |
| 319 | lbs_deb_enter(LBS_DEB_CMD); |
| 320 | |
| 321 | if (priv->is_deep_sleep) { |
| 322 | if (!wait_event_interruptible_timeout(priv->ds_awake_q, |
| 323 | !priv->is_deep_sleep, (10 * HZ))) { |
| 324 | lbs_pr_err("ds_awake_q: timer expired\n"); |
| 325 | ret = -1; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | int lbs_set_deep_sleep(struct lbs_private *priv, int deep_sleep) |
| 334 | { |
| 335 | int ret = 0; |
| 336 | |
| 337 | lbs_deb_enter(LBS_DEB_CMD); |
| 338 | |
| 339 | if (deep_sleep) { |
| 340 | if (priv->is_deep_sleep != 1) { |
| 341 | lbs_deb_cmd("deep sleep: sleep\n"); |
| 342 | BUG_ON(!priv->enter_deep_sleep); |
| 343 | ret = priv->enter_deep_sleep(priv); |
| 344 | if (!ret) { |
| 345 | netif_stop_queue(priv->dev); |
| 346 | netif_carrier_off(priv->dev); |
| 347 | } |
| 348 | } else { |
| 349 | lbs_pr_err("deep sleep: already enabled\n"); |
| 350 | } |
| 351 | } else { |
| 352 | if (priv->is_deep_sleep) { |
| 353 | lbs_deb_cmd("deep sleep: wakeup\n"); |
| 354 | BUG_ON(!priv->exit_deep_sleep); |
| 355 | ret = priv->exit_deep_sleep(priv); |
| 356 | if (!ret) { |
| 357 | ret = lbs_wait_for_ds_awake(priv); |
| 358 | if (ret) |
| 359 | lbs_pr_err("deep sleep: wakeup" |
| 360 | "failed\n"); |
| 361 | } |
| 362 | } |
| 363 | } |
| 364 | |
| 365 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 366 | return ret; |
| 367 | } |
| 368 | |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 369 | /** |
| 370 | * @brief Set an SNMP MIB value |
| 371 | * |
| 372 | * @param priv A pointer to struct lbs_private structure |
| 373 | * @param oid The OID to set in the firmware |
| 374 | * @param val Value to set the OID to |
| 375 | * |
| 376 | * @return 0 on success, error on failure |
| 377 | */ |
| 378 | int lbs_set_snmp_mib(struct lbs_private *priv, u32 oid, u16 val) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 379 | { |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 380 | struct cmd_ds_802_11_snmp_mib cmd; |
| 381 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 382 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 383 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 384 | |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 385 | memset(&cmd, 0, sizeof (cmd)); |
| 386 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 387 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 388 | cmd.oid = cpu_to_le16((u16) oid); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 389 | |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 390 | switch (oid) { |
| 391 | case SNMP_MIB_OID_BSS_TYPE: |
| 392 | cmd.bufsize = cpu_to_le16(sizeof(u8)); |
Holger Schurig | fef0640 | 2009-10-22 15:30:59 +0200 | [diff] [blame^] | 393 | cmd.value[0] = val; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 394 | break; |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 395 | case SNMP_MIB_OID_11D_ENABLE: |
| 396 | case SNMP_MIB_OID_FRAG_THRESHOLD: |
| 397 | case SNMP_MIB_OID_RTS_THRESHOLD: |
| 398 | case SNMP_MIB_OID_SHORT_RETRY_LIMIT: |
| 399 | case SNMP_MIB_OID_LONG_RETRY_LIMIT: |
| 400 | cmd.bufsize = cpu_to_le16(sizeof(u16)); |
| 401 | *((__le16 *)(&cmd.value)) = cpu_to_le16(val); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 402 | break; |
| 403 | default: |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 404 | lbs_deb_cmd("SNMP_CMD: (set) unhandled OID 0x%x\n", oid); |
| 405 | ret = -EINVAL; |
| 406 | goto out; |
| 407 | } |
| 408 | |
| 409 | lbs_deb_cmd("SNMP_CMD: (set) oid 0x%x, oid size 0x%x, value 0x%x\n", |
| 410 | le16_to_cpu(cmd.oid), le16_to_cpu(cmd.bufsize), val); |
| 411 | |
| 412 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
| 413 | |
| 414 | out: |
| 415 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * @brief Get an SNMP MIB value |
| 421 | * |
| 422 | * @param priv A pointer to struct lbs_private structure |
| 423 | * @param oid The OID to retrieve from the firmware |
| 424 | * @param out_val Location for the returned value |
| 425 | * |
| 426 | * @return 0 on success, error on failure |
| 427 | */ |
| 428 | int lbs_get_snmp_mib(struct lbs_private *priv, u32 oid, u16 *out_val) |
| 429 | { |
| 430 | struct cmd_ds_802_11_snmp_mib cmd; |
| 431 | int ret; |
| 432 | |
| 433 | lbs_deb_enter(LBS_DEB_CMD); |
| 434 | |
| 435 | memset(&cmd, 0, sizeof (cmd)); |
| 436 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 437 | cmd.action = cpu_to_le16(CMD_ACT_GET); |
| 438 | cmd.oid = cpu_to_le16(oid); |
| 439 | |
| 440 | ret = lbs_cmd_with_response(priv, CMD_802_11_SNMP_MIB, &cmd); |
| 441 | if (ret) |
| 442 | goto out; |
| 443 | |
| 444 | switch (le16_to_cpu(cmd.bufsize)) { |
| 445 | case sizeof(u8): |
Holger Schurig | fef0640 | 2009-10-22 15:30:59 +0200 | [diff] [blame^] | 446 | *out_val = cmd.value[0]; |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 447 | break; |
| 448 | case sizeof(u16): |
| 449 | *out_val = le16_to_cpu(*((__le16 *)(&cmd.value))); |
| 450 | break; |
| 451 | default: |
| 452 | lbs_deb_cmd("SNMP_CMD: (get) unhandled OID 0x%x size %d\n", |
| 453 | oid, le16_to_cpu(cmd.bufsize)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | |
Dan Williams | 39fcf7a | 2008-09-10 12:49:00 -0400 | [diff] [blame] | 457 | out: |
| 458 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 459 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 460 | } |
| 461 | |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 462 | /** |
| 463 | * @brief Get the min, max, and current TX power |
| 464 | * |
| 465 | * @param priv A pointer to struct lbs_private structure |
| 466 | * @param curlevel Current power level in dBm |
| 467 | * @param minlevel Minimum supported power level in dBm (optional) |
| 468 | * @param maxlevel Maximum supported power level in dBm (optional) |
| 469 | * |
| 470 | * @return 0 on success, error on failure |
| 471 | */ |
| 472 | int lbs_get_tx_power(struct lbs_private *priv, s16 *curlevel, s16 *minlevel, |
| 473 | s16 *maxlevel) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 474 | { |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 475 | struct cmd_ds_802_11_rf_tx_power cmd; |
| 476 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 477 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 478 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 479 | |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 480 | memset(&cmd, 0, sizeof(cmd)); |
| 481 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 482 | cmd.action = cpu_to_le16(CMD_ACT_GET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 483 | |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 484 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); |
| 485 | if (ret == 0) { |
| 486 | *curlevel = le16_to_cpu(cmd.curlevel); |
| 487 | if (minlevel) |
Holger Schurig | 87bf24f | 2008-10-29 10:35:02 +0100 | [diff] [blame] | 488 | *minlevel = cmd.minlevel; |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 489 | if (maxlevel) |
Holger Schurig | 87bf24f | 2008-10-29 10:35:02 +0100 | [diff] [blame] | 490 | *maxlevel = cmd.maxlevel; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 491 | } |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 492 | |
| 493 | lbs_deb_leave(LBS_DEB_CMD); |
Dan Williams | 87c8c72 | 2008-08-19 15:15:35 -0400 | [diff] [blame] | 494 | return ret; |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * @brief Set the TX power |
| 499 | * |
| 500 | * @param priv A pointer to struct lbs_private structure |
| 501 | * @param dbm The desired power level in dBm |
| 502 | * |
| 503 | * @return 0 on success, error on failure |
| 504 | */ |
| 505 | int lbs_set_tx_power(struct lbs_private *priv, s16 dbm) |
| 506 | { |
| 507 | struct cmd_ds_802_11_rf_tx_power cmd; |
| 508 | int ret; |
| 509 | |
| 510 | lbs_deb_enter(LBS_DEB_CMD); |
| 511 | |
| 512 | memset(&cmd, 0, sizeof(cmd)); |
| 513 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 514 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 515 | cmd.curlevel = cpu_to_le16(dbm); |
| 516 | |
| 517 | lbs_deb_cmd("SET_RF_TX_POWER: %d dBm\n", dbm); |
| 518 | |
| 519 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_TX_POWER, &cmd); |
| 520 | |
| 521 | lbs_deb_leave(LBS_DEB_CMD); |
| 522 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 523 | } |
| 524 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 525 | static int lbs_cmd_802_11_monitor_mode(struct cmd_ds_command *cmd, |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 526 | u16 cmd_action, void *pdata_buf) |
| 527 | { |
| 528 | struct cmd_ds_802_11_monitor_mode *monitor = &cmd->params.monitor; |
| 529 | |
| 530 | cmd->command = cpu_to_le16(CMD_802_11_MONITOR_MODE); |
| 531 | cmd->size = |
| 532 | cpu_to_le16(sizeof(struct cmd_ds_802_11_monitor_mode) + |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 533 | sizeof(struct cmd_header)); |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 534 | |
| 535 | monitor->action = cpu_to_le16(cmd_action); |
| 536 | if (cmd_action == CMD_ACT_SET) { |
| 537 | monitor->mode = |
| 538 | cpu_to_le16((u16) (*(u32 *) pdata_buf)); |
| 539 | } |
| 540 | |
| 541 | return 0; |
| 542 | } |
| 543 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 544 | /** |
| 545 | * @brief Get the radio channel |
| 546 | * |
| 547 | * @param priv A pointer to struct lbs_private structure |
| 548 | * |
| 549 | * @return The channel on success, error on failure |
| 550 | */ |
Holger Schurig | a3cbfb0 | 2009-10-16 17:33:56 +0200 | [diff] [blame] | 551 | static int lbs_get_channel(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 552 | { |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 553 | struct cmd_ds_802_11_rf_channel cmd; |
| 554 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 555 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 556 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 557 | |
Holger Schurig | 8d0c7fa | 2008-04-09 10:23:31 +0200 | [diff] [blame] | 558 | memset(&cmd, 0, sizeof(cmd)); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 559 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 560 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_GET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 561 | |
David Woodhouse | 689442d | 2007-12-12 16:00:42 -0500 | [diff] [blame] | 562 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 563 | if (ret) |
| 564 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 565 | |
Dan Williams | cb182a6 | 2007-12-11 17:35:51 -0500 | [diff] [blame] | 566 | ret = le16_to_cpu(cmd.channel); |
| 567 | lbs_deb_cmd("current radio channel is %d\n", ret); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 568 | |
| 569 | out: |
| 570 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 571 | return ret; |
| 572 | } |
| 573 | |
Holger Schurig | 73ab1f2 | 2008-04-02 16:52:19 +0200 | [diff] [blame] | 574 | int lbs_update_channel(struct lbs_private *priv) |
| 575 | { |
| 576 | int ret; |
| 577 | |
| 578 | /* the channel in f/w could be out of sync; get the current channel */ |
| 579 | lbs_deb_enter(LBS_DEB_ASSOC); |
| 580 | |
| 581 | ret = lbs_get_channel(priv); |
| 582 | if (ret > 0) { |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 583 | priv->channel = ret; |
Holger Schurig | 73ab1f2 | 2008-04-02 16:52:19 +0200 | [diff] [blame] | 584 | ret = 0; |
| 585 | } |
| 586 | lbs_deb_leave_args(LBS_DEB_ASSOC, "ret %d", ret); |
| 587 | return ret; |
| 588 | } |
| 589 | |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 590 | /** |
| 591 | * @brief Set the radio channel |
| 592 | * |
| 593 | * @param priv A pointer to struct lbs_private structure |
| 594 | * @param channel The desired channel, or 0 to clear a locked channel |
| 595 | * |
| 596 | * @return 0 on success, error on failure |
| 597 | */ |
| 598 | int lbs_set_channel(struct lbs_private *priv, u8 channel) |
| 599 | { |
| 600 | struct cmd_ds_802_11_rf_channel cmd; |
Manish Katiyar | 96d46d5 | 2008-10-13 16:22:42 +0530 | [diff] [blame] | 601 | #ifdef DEBUG |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 602 | u8 old_channel = priv->channel; |
Manish Katiyar | 96d46d5 | 2008-10-13 16:22:42 +0530 | [diff] [blame] | 603 | #endif |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 604 | int ret = 0; |
| 605 | |
| 606 | lbs_deb_enter(LBS_DEB_CMD); |
| 607 | |
Holger Schurig | 8d0c7fa | 2008-04-09 10:23:31 +0200 | [diff] [blame] | 608 | memset(&cmd, 0, sizeof(cmd)); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 609 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 610 | cmd.action = cpu_to_le16(CMD_OPT_802_11_RF_CHANNEL_SET); |
| 611 | cmd.channel = cpu_to_le16(channel); |
| 612 | |
David Woodhouse | 689442d | 2007-12-12 16:00:42 -0500 | [diff] [blame] | 613 | ret = lbs_cmd_with_response(priv, CMD_802_11_RF_CHANNEL, &cmd); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 614 | if (ret) |
| 615 | goto out; |
| 616 | |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 617 | priv->channel = (uint8_t) le16_to_cpu(cmd.channel); |
Dan Williams | cb182a6 | 2007-12-11 17:35:51 -0500 | [diff] [blame] | 618 | lbs_deb_cmd("channel switch from %d to %d\n", old_channel, |
Holger Schurig | c14951f | 2009-10-22 15:30:50 +0200 | [diff] [blame] | 619 | priv->channel); |
Dan Williams | 2dd4b26 | 2007-12-11 16:54:15 -0500 | [diff] [blame] | 620 | |
| 621 | out: |
| 622 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
| 623 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 624 | } |
| 625 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 626 | static int lbs_cmd_reg_access(struct cmd_ds_command *cmdptr, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 627 | u8 cmd_action, void *pdata_buf) |
| 628 | { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 629 | struct lbs_offset_value *offval; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 630 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 631 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 632 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 633 | offval = (struct lbs_offset_value *)pdata_buf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 634 | |
Holger Schurig | c2df2ef | 2007-12-07 15:30:44 +0000 | [diff] [blame] | 635 | switch (le16_to_cpu(cmdptr->command)) { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 636 | case CMD_MAC_REG_ACCESS: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 637 | { |
| 638 | struct cmd_ds_mac_reg_access *macreg; |
| 639 | |
| 640 | cmdptr->size = |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 641 | cpu_to_le16(sizeof (struct cmd_ds_mac_reg_access) |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 642 | + sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 643 | macreg = |
| 644 | (struct cmd_ds_mac_reg_access *)&cmdptr->params. |
| 645 | macreg; |
| 646 | |
| 647 | macreg->action = cpu_to_le16(cmd_action); |
| 648 | macreg->offset = cpu_to_le16((u16) offval->offset); |
| 649 | macreg->value = cpu_to_le32(offval->value); |
| 650 | |
| 651 | break; |
| 652 | } |
| 653 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 654 | case CMD_BBP_REG_ACCESS: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 655 | { |
| 656 | struct cmd_ds_bbp_reg_access *bbpreg; |
| 657 | |
| 658 | cmdptr->size = |
| 659 | cpu_to_le16(sizeof |
| 660 | (struct cmd_ds_bbp_reg_access) |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 661 | + sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 662 | bbpreg = |
| 663 | (struct cmd_ds_bbp_reg_access *)&cmdptr->params. |
| 664 | bbpreg; |
| 665 | |
| 666 | bbpreg->action = cpu_to_le16(cmd_action); |
| 667 | bbpreg->offset = cpu_to_le16((u16) offval->offset); |
| 668 | bbpreg->value = (u8) offval->value; |
| 669 | |
| 670 | break; |
| 671 | } |
| 672 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 673 | case CMD_RF_REG_ACCESS: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 674 | { |
| 675 | struct cmd_ds_rf_reg_access *rfreg; |
| 676 | |
| 677 | cmdptr->size = |
| 678 | cpu_to_le16(sizeof |
| 679 | (struct cmd_ds_rf_reg_access) + |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 680 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 681 | rfreg = |
| 682 | (struct cmd_ds_rf_reg_access *)&cmdptr->params. |
| 683 | rfreg; |
| 684 | |
| 685 | rfreg->action = cpu_to_le16(cmd_action); |
| 686 | rfreg->offset = cpu_to_le16((u16) offval->offset); |
| 687 | rfreg->value = (u8) offval->value; |
| 688 | |
| 689 | break; |
| 690 | } |
| 691 | |
| 692 | default: |
| 693 | break; |
| 694 | } |
| 695 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 696 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 697 | return 0; |
| 698 | } |
| 699 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 700 | static int lbs_cmd_bt_access(struct cmd_ds_command *cmd, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 701 | u16 cmd_action, void *pdata_buf) |
| 702 | { |
| 703 | struct cmd_ds_bt_access *bt_access = &cmd->params.bt; |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 704 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 705 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 706 | cmd->command = cpu_to_le16(CMD_BT_ACCESS); |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 707 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_bt_access) + |
| 708 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 709 | cmd->result = 0; |
| 710 | bt_access->action = cpu_to_le16(cmd_action); |
| 711 | |
| 712 | switch (cmd_action) { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 713 | case CMD_ACT_BT_ACCESS_ADD: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 714 | memcpy(bt_access->addr1, pdata_buf, 2 * ETH_ALEN); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 715 | lbs_deb_hex(LBS_DEB_MESH, "BT_ADD: blinded MAC addr", bt_access->addr1, 6); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 716 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 717 | case CMD_ACT_BT_ACCESS_DEL: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 718 | memcpy(bt_access->addr1, pdata_buf, 1 * ETH_ALEN); |
Holger Schurig | ece5619 | 2007-08-02 11:53:06 -0400 | [diff] [blame] | 719 | lbs_deb_hex(LBS_DEB_MESH, "BT_DEL: blinded MAC addr", bt_access->addr1, 6); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 720 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 721 | case CMD_ACT_BT_ACCESS_LIST: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 722 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
| 723 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 724 | case CMD_ACT_BT_ACCESS_RESET: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 725 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 726 | case CMD_ACT_BT_ACCESS_SET_INVERT: |
Luis Carlos Cobo | 90e8eaf | 2007-05-25 13:53:26 -0400 | [diff] [blame] | 727 | bt_access->id = cpu_to_le32(*(u32 *) pdata_buf); |
| 728 | break; |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 729 | case CMD_ACT_BT_ACCESS_GET_INVERT: |
Luis Carlos Cobo | 90e8eaf | 2007-05-25 13:53:26 -0400 | [diff] [blame] | 730 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 731 | default: |
| 732 | break; |
| 733 | } |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 734 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 735 | return 0; |
| 736 | } |
| 737 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 738 | static int lbs_cmd_fwt_access(struct cmd_ds_command *cmd, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 739 | u16 cmd_action, void *pdata_buf) |
| 740 | { |
| 741 | struct cmd_ds_fwt_access *fwt_access = &cmd->params.fwt; |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 742 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 743 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 744 | cmd->command = cpu_to_le16(CMD_FWT_ACCESS); |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 745 | cmd->size = cpu_to_le16(sizeof(struct cmd_ds_fwt_access) + |
| 746 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 747 | cmd->result = 0; |
| 748 | |
| 749 | if (pdata_buf) |
| 750 | memcpy(fwt_access, pdata_buf, sizeof(*fwt_access)); |
| 751 | else |
| 752 | memset(fwt_access, 0, sizeof(*fwt_access)); |
| 753 | |
| 754 | fwt_access->action = cpu_to_le16(cmd_action); |
| 755 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 756 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 757 | return 0; |
| 758 | } |
| 759 | |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 760 | int lbs_mesh_access(struct lbs_private *priv, uint16_t cmd_action, |
| 761 | struct cmd_ds_mesh_access *cmd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 762 | { |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 763 | int ret; |
| 764 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 765 | lbs_deb_enter_args(LBS_DEB_CMD, "action %d", cmd_action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 766 | |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 767 | cmd->hdr.command = cpu_to_le16(CMD_MESH_ACCESS); |
David Woodhouse | 9fae899 | 2007-12-15 03:46:44 -0500 | [diff] [blame] | 768 | cmd->hdr.size = cpu_to_le16(sizeof(*cmd)); |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 769 | cmd->hdr.result = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 770 | |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 771 | cmd->action = cpu_to_le16(cmd_action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 772 | |
David Woodhouse | 689442d | 2007-12-12 16:00:42 -0500 | [diff] [blame] | 773 | ret = lbs_cmd_with_response(priv, CMD_MESH_ACCESS, cmd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 774 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 775 | lbs_deb_leave(LBS_DEB_CMD); |
David Woodhouse | 301eacb | 2007-12-11 15:23:59 -0500 | [diff] [blame] | 776 | return ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 777 | } |
| 778 | |
Brian Cavagnolo | 1556c0f | 2008-07-21 11:02:46 -0700 | [diff] [blame] | 779 | static int __lbs_mesh_config_send(struct lbs_private *priv, |
| 780 | struct cmd_ds_mesh_config *cmd, |
| 781 | uint16_t action, uint16_t type) |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 782 | { |
| 783 | int ret; |
Bing Zhao | 684d6b3 | 2009-03-25 09:51:16 -0700 | [diff] [blame] | 784 | u16 command = CMD_MESH_CONFIG_OLD; |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 785 | |
| 786 | lbs_deb_enter(LBS_DEB_CMD); |
| 787 | |
Bing Zhao | 684d6b3 | 2009-03-25 09:51:16 -0700 | [diff] [blame] | 788 | /* |
| 789 | * Command id is 0xac for v10 FW along with mesh interface |
| 790 | * id in bits 14-13-12. |
| 791 | */ |
| 792 | if (priv->mesh_fw_ver == MESH_FW_NEW) |
| 793 | command = CMD_MESH_CONFIG | |
| 794 | (MESH_IFACE_ID << MESH_IFACE_BIT_OFFSET); |
| 795 | |
| 796 | cmd->hdr.command = cpu_to_le16(command); |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 797 | cmd->hdr.size = cpu_to_le16(sizeof(struct cmd_ds_mesh_config)); |
| 798 | cmd->hdr.result = 0; |
| 799 | |
| 800 | cmd->type = cpu_to_le16(type); |
| 801 | cmd->action = cpu_to_le16(action); |
| 802 | |
Bing Zhao | 684d6b3 | 2009-03-25 09:51:16 -0700 | [diff] [blame] | 803 | ret = lbs_cmd_with_response(priv, command, cmd); |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 804 | |
| 805 | lbs_deb_leave(LBS_DEB_CMD); |
| 806 | return ret; |
| 807 | } |
| 808 | |
Brian Cavagnolo | 1556c0f | 2008-07-21 11:02:46 -0700 | [diff] [blame] | 809 | int lbs_mesh_config_send(struct lbs_private *priv, |
| 810 | struct cmd_ds_mesh_config *cmd, |
| 811 | uint16_t action, uint16_t type) |
| 812 | { |
| 813 | int ret; |
| 814 | |
| 815 | if (!(priv->fwcapinfo & FW_CAPINFO_PERSISTENT_CONFIG)) |
| 816 | return -EOPNOTSUPP; |
| 817 | |
| 818 | ret = __lbs_mesh_config_send(priv, cmd, action, type); |
| 819 | return ret; |
| 820 | } |
| 821 | |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 822 | /* This function is the CMD_MESH_CONFIG legacy function. It only handles the |
| 823 | * START and STOP actions. The extended actions supported by CMD_MESH_CONFIG |
| 824 | * are all handled by preparing a struct cmd_ds_mesh_config and passing it to |
| 825 | * lbs_mesh_config_send. |
| 826 | */ |
| 827 | int lbs_mesh_config(struct lbs_private *priv, uint16_t action, uint16_t chan) |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 828 | { |
| 829 | struct cmd_ds_mesh_config cmd; |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 830 | struct mrvl_meshie *ie; |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 831 | DECLARE_SSID_BUF(ssid); |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 832 | |
| 833 | memset(&cmd, 0, sizeof(cmd)); |
David Woodhouse | 8606213 | 2007-12-13 00:32:36 -0500 | [diff] [blame] | 834 | cmd.channel = cpu_to_le16(chan); |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 835 | ie = (struct mrvl_meshie *)cmd.data; |
David Woodhouse | 7e22627 | 2007-12-14 22:53:41 -0500 | [diff] [blame] | 836 | |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 837 | switch (action) { |
| 838 | case CMD_ACT_MESH_CONFIG_START: |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 839 | ie->id = WLAN_EID_GENERIC; |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 840 | ie->val.oui[0] = 0x00; |
| 841 | ie->val.oui[1] = 0x50; |
| 842 | ie->val.oui[2] = 0x43; |
| 843 | ie->val.type = MARVELL_MESH_IE_TYPE; |
| 844 | ie->val.subtype = MARVELL_MESH_IE_SUBTYPE; |
| 845 | ie->val.version = MARVELL_MESH_IE_VERSION; |
| 846 | ie->val.active_protocol_id = MARVELL_MESH_PROTO_ID_HWMP; |
| 847 | ie->val.active_metric_id = MARVELL_MESH_METRIC_ID; |
| 848 | ie->val.mesh_capability = MARVELL_MESH_CAPABILITY; |
| 849 | ie->val.mesh_id_len = priv->mesh_ssid_len; |
| 850 | memcpy(ie->val.mesh_id, priv->mesh_ssid, priv->mesh_ssid_len); |
Johannes Berg | 2c706002 | 2008-10-30 22:09:54 +0100 | [diff] [blame] | 851 | ie->len = sizeof(struct mrvl_meshie_val) - |
Holger Schurig | 243e84e | 2009-10-22 15:30:47 +0200 | [diff] [blame] | 852 | IEEE80211_MAX_SSID_LEN + priv->mesh_ssid_len; |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 853 | cmd.length = cpu_to_le16(sizeof(struct mrvl_meshie_val)); |
| 854 | break; |
| 855 | case CMD_ACT_MESH_CONFIG_STOP: |
| 856 | break; |
| 857 | default: |
| 858 | return -1; |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 859 | } |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 860 | lbs_deb_cmd("mesh config action %d type %x channel %d SSID %s\n", |
| 861 | action, priv->mesh_tlv, chan, |
John W. Linville | 9387b7c | 2008-09-30 20:59:05 -0400 | [diff] [blame] | 862 | print_ssid(ssid, priv->mesh_ssid, priv->mesh_ssid_len)); |
Javier Cardona | edaea5c | 2008-05-17 00:55:10 -0700 | [diff] [blame] | 863 | |
Brian Cavagnolo | 1556c0f | 2008-07-21 11:02:46 -0700 | [diff] [blame] | 864 | return __lbs_mesh_config_send(priv, &cmd, action, priv->mesh_tlv); |
David Woodhouse | 23a397a | 2007-12-11 18:56:42 -0500 | [diff] [blame] | 865 | } |
| 866 | |
David Woodhouse | 681ffbb | 2007-12-15 20:04:54 -0500 | [diff] [blame] | 867 | static void lbs_queue_cmd(struct lbs_private *priv, |
| 868 | struct cmd_ctrl_node *cmdnode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 869 | { |
| 870 | unsigned long flags; |
David Woodhouse | 681ffbb | 2007-12-15 20:04:54 -0500 | [diff] [blame] | 871 | int addtail = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 872 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 873 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 874 | |
David Woodhouse | c4ab412 | 2007-12-15 00:41:51 -0500 | [diff] [blame] | 875 | if (!cmdnode) { |
| 876 | lbs_deb_host("QUEUE_CMD: cmdnode is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 877 | goto done; |
| 878 | } |
David Woodhouse | d9896ee | 2007-12-15 00:09:25 -0500 | [diff] [blame] | 879 | if (!cmdnode->cmdbuf->size) { |
| 880 | lbs_deb_host("DNLD_CMD: cmd size is zero\n"); |
| 881 | goto done; |
| 882 | } |
David Woodhouse | ae125bf | 2007-12-15 04:22:52 -0500 | [diff] [blame] | 883 | cmdnode->result = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 884 | |
| 885 | /* Exit_PS command needs to be queued in the header always. */ |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 886 | if (le16_to_cpu(cmdnode->cmdbuf->command) == CMD_802_11_PS_MODE) { |
David Woodhouse | 38bfab1 | 2007-12-16 23:26:54 -0500 | [diff] [blame] | 887 | struct cmd_ds_802_11_ps_mode *psm = (void *) &cmdnode->cmdbuf[1]; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 888 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 889 | if (psm->action == cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 890 | if (priv->psstate != PS_STATE_FULL_POWER) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 891 | addtail = 0; |
| 892 | } |
| 893 | } |
| 894 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 895 | spin_lock_irqsave(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 896 | |
David Woodhouse | ac47246 | 2007-12-08 00:35:00 +0000 | [diff] [blame] | 897 | if (addtail) |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 898 | list_add_tail(&cmdnode->list, &priv->cmdpendingq); |
David Woodhouse | ac47246 | 2007-12-08 00:35:00 +0000 | [diff] [blame] | 899 | else |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 900 | list_add(&cmdnode->list, &priv->cmdpendingq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 901 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 902 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 903 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 904 | lbs_deb_host("QUEUE_CMD: inserted command 0x%04x into cmdpendingq\n", |
David Woodhouse | c4ab412 | 2007-12-15 00:41:51 -0500 | [diff] [blame] | 905 | le16_to_cpu(cmdnode->cmdbuf->command)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 906 | |
| 907 | done: |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 908 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 909 | } |
| 910 | |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 911 | static void lbs_submit_command(struct lbs_private *priv, |
| 912 | struct cmd_ctrl_node *cmdnode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 913 | { |
| 914 | unsigned long flags; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 915 | struct cmd_header *cmd; |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 916 | uint16_t cmdsize; |
| 917 | uint16_t command; |
Holger Schurig | 57962f0 | 2008-05-14 16:30:28 +0200 | [diff] [blame] | 918 | int timeo = 3 * HZ; |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 919 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 920 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 921 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 922 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 923 | cmd = cmdnode->cmdbuf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 924 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 925 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 926 | priv->cur_cmd = cmdnode; |
| 927 | priv->cur_cmd_retcode = 0; |
| 928 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 929 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 930 | cmdsize = le16_to_cpu(cmd->size); |
| 931 | command = le16_to_cpu(cmd->command); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 932 | |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 933 | /* These commands take longer */ |
Dan Williams | be0d76e | 2009-05-22 20:05:25 -0400 | [diff] [blame] | 934 | if (command == CMD_802_11_SCAN || command == CMD_802_11_ASSOCIATE) |
Holger Schurig | 57962f0 | 2008-05-14 16:30:28 +0200 | [diff] [blame] | 935 | timeo = 5 * HZ; |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 936 | |
Holger Schurig | e5225b3 | 2008-03-26 10:04:44 +0100 | [diff] [blame] | 937 | lbs_deb_cmd("DNLD_CMD: command 0x%04x, seq %d, size %d\n", |
| 938 | command, le16_to_cpu(cmd->seqnum), cmdsize); |
Holger Schurig | 1afc09ab | 2008-01-29 09:14:40 +0100 | [diff] [blame] | 939 | lbs_deb_hex(LBS_DEB_CMD, "DNLD_CMD", (void *) cmdnode->cmdbuf, cmdsize); |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 940 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 941 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) cmd, cmdsize); |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 942 | |
David Woodhouse | d9896ee | 2007-12-15 00:09:25 -0500 | [diff] [blame] | 943 | if (ret) { |
| 944 | lbs_pr_info("DNLD_CMD: hw_host_to_card failed: %d\n", ret); |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 945 | /* Let the timer kick in and retry, and potentially reset |
| 946 | the whole thing if the condition persists */ |
Holger Schurig | 57962f0 | 2008-05-14 16:30:28 +0200 | [diff] [blame] | 947 | timeo = HZ/4; |
Holger Schurig | 1afc09ab | 2008-01-29 09:14:40 +0100 | [diff] [blame] | 948 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 949 | |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 950 | if (command == CMD_802_11_DEEP_SLEEP) { |
| 951 | if (priv->is_auto_deep_sleep_enabled) { |
| 952 | priv->wakeup_dev_required = 1; |
| 953 | priv->dnld_sent = 0; |
| 954 | } |
| 955 | priv->is_deep_sleep = 1; |
| 956 | lbs_complete_command(priv, cmdnode, 0); |
| 957 | } else { |
| 958 | /* Setup the timer after transmit command */ |
| 959 | mod_timer(&priv->command_timer, jiffies + timeo); |
| 960 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 961 | |
David Woodhouse | 18c52e7 | 2007-12-17 16:03:58 -0500 | [diff] [blame] | 962 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 963 | } |
| 964 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 965 | /** |
| 966 | * This function inserts command node to cmdfreeq |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 967 | * after cleans it. Requires priv->driver_lock held. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 968 | */ |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 969 | static void __lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 970 | struct cmd_ctrl_node *cmdnode) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 971 | { |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 972 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 973 | |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 974 | if (!cmdnode) |
| 975 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 976 | |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 977 | cmdnode->callback = NULL; |
| 978 | cmdnode->callback_arg = 0; |
| 979 | |
| 980 | memset(cmdnode->cmdbuf, 0, LBS_CMD_BUFFER_SIZE); |
| 981 | |
| 982 | list_add_tail(&cmdnode->list, &priv->cmdfreeq); |
| 983 | out: |
| 984 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 985 | } |
| 986 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 987 | static void lbs_cleanup_and_insert_cmd(struct lbs_private *priv, |
| 988 | struct cmd_ctrl_node *ptempcmd) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 989 | { |
| 990 | unsigned long flags; |
| 991 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 992 | spin_lock_irqsave(&priv->driver_lock, flags); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 993 | __lbs_cleanup_and_insert_cmd(priv, ptempcmd); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 994 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 995 | } |
| 996 | |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 997 | void lbs_complete_command(struct lbs_private *priv, struct cmd_ctrl_node *cmd, |
| 998 | int result) |
| 999 | { |
| 1000 | if (cmd == priv->cur_cmd) |
| 1001 | priv->cur_cmd_retcode = result; |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 1002 | |
David Woodhouse | ae125bf | 2007-12-15 04:22:52 -0500 | [diff] [blame] | 1003 | cmd->result = result; |
David Woodhouse | 5ba2f8a | 2007-12-15 02:02:56 -0500 | [diff] [blame] | 1004 | cmd->cmdwaitqwoken = 1; |
| 1005 | wake_up_interruptible(&cmd->cmdwait_q); |
| 1006 | |
Holger Schurig | 8db4a2b | 2008-03-19 10:11:00 +0100 | [diff] [blame] | 1007 | if (!cmd->callback || cmd->callback == lbs_cmd_async_callback) |
David Woodhouse | ad12d0f | 2007-12-15 02:06:16 -0500 | [diff] [blame] | 1008 | __lbs_cleanup_and_insert_cmd(priv, cmd); |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 1009 | priv->cur_cmd = NULL; |
| 1010 | } |
| 1011 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1012 | int lbs_set_radio(struct lbs_private *priv, u8 preamble, u8 radio_on) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1013 | { |
David Woodhouse | a7c4589 | 2007-12-17 22:43:48 -0500 | [diff] [blame] | 1014 | struct cmd_ds_802_11_radio_control cmd; |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1015 | int ret = -EINVAL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1016 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1017 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1018 | |
David Woodhouse | a7c4589 | 2007-12-17 22:43:48 -0500 | [diff] [blame] | 1019 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 1020 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1021 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1022 | /* Only v8 and below support setting the preamble */ |
| 1023 | if (priv->fwrelease < 0x09000000) { |
| 1024 | switch (preamble) { |
| 1025 | case RADIO_PREAMBLE_SHORT: |
| 1026 | if (!(priv->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)) |
| 1027 | goto out; |
| 1028 | /* Fall through */ |
| 1029 | case RADIO_PREAMBLE_AUTO: |
| 1030 | case RADIO_PREAMBLE_LONG: |
| 1031 | cmd.control = cpu_to_le16(preamble); |
| 1032 | break; |
| 1033 | default: |
| 1034 | goto out; |
| 1035 | } |
David Woodhouse | a7c4589 | 2007-12-17 22:43:48 -0500 | [diff] [blame] | 1036 | } |
| 1037 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1038 | if (radio_on) |
| 1039 | cmd.control |= cpu_to_le16(0x1); |
| 1040 | else { |
| 1041 | cmd.control &= cpu_to_le16(~0x1); |
| 1042 | priv->txpower_cur = 0; |
| 1043 | } |
David Woodhouse | a7c4589 | 2007-12-17 22:43:48 -0500 | [diff] [blame] | 1044 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1045 | lbs_deb_cmd("RADIO_CONTROL: radio %s, preamble %d\n", |
| 1046 | radio_on ? "ON" : "OFF", preamble); |
| 1047 | |
| 1048 | priv->radio_on = radio_on; |
David Woodhouse | a7c4589 | 2007-12-17 22:43:48 -0500 | [diff] [blame] | 1049 | |
| 1050 | ret = lbs_cmd_with_response(priv, CMD_802_11_RADIO_CONTROL, &cmd); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1051 | |
Dan Williams | d5db2df | 2008-08-21 17:51:07 -0400 | [diff] [blame] | 1052 | out: |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1053 | lbs_deb_leave_args(LBS_DEB_CMD, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1054 | return ret; |
| 1055 | } |
| 1056 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 1057 | void lbs_set_mac_control(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1058 | { |
Holger Schurig | 835d3ac | 2008-03-12 16:05:40 +0100 | [diff] [blame] | 1059 | struct cmd_ds_mac_control cmd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1060 | |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1061 | lbs_deb_enter(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1062 | |
Holger Schurig | 835d3ac | 2008-03-12 16:05:40 +0100 | [diff] [blame] | 1063 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
Holger Schurig | d9e9778 | 2008-03-12 16:06:43 +0100 | [diff] [blame] | 1064 | cmd.action = cpu_to_le16(priv->mac_control); |
Holger Schurig | 835d3ac | 2008-03-12 16:05:40 +0100 | [diff] [blame] | 1065 | cmd.reserved = 0; |
| 1066 | |
David Woodhouse | 75bf45a | 2008-05-20 13:32:45 +0100 | [diff] [blame] | 1067 | lbs_cmd_async(priv, CMD_MAC_CONTROL, &cmd.hdr, sizeof(cmd)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1068 | |
Holger Schurig | c97329e | 2008-03-18 11:20:21 +0100 | [diff] [blame] | 1069 | lbs_deb_leave(LBS_DEB_CMD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1070 | } |
| 1071 | |
| 1072 | /** |
| 1073 | * @brief This function prepare the command before send to firmware. |
| 1074 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1075 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1076 | * @param cmd_no command number |
| 1077 | * @param cmd_action command action: GET or SET |
| 1078 | * @param wait_option wait option: wait response or not |
| 1079 | * @param cmd_oid cmd oid: treated as sub command |
| 1080 | * @param pdata_buf A pointer to informaion buffer |
| 1081 | * @return 0 or -1 |
| 1082 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1083 | int lbs_prepare_and_send_command(struct lbs_private *priv, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1084 | u16 cmd_no, |
| 1085 | u16 cmd_action, |
| 1086 | u16 wait_option, u32 cmd_oid, void *pdata_buf) |
| 1087 | { |
| 1088 | int ret = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1089 | struct cmd_ctrl_node *cmdnode; |
| 1090 | struct cmd_ds_command *cmdptr; |
| 1091 | unsigned long flags; |
| 1092 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1093 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1094 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1095 | if (!priv) { |
| 1096 | lbs_deb_host("PREP_CMD: priv is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1097 | ret = -1; |
| 1098 | goto done; |
| 1099 | } |
| 1100 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1101 | if (priv->surpriseremoved) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1102 | lbs_deb_host("PREP_CMD: card removed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1103 | ret = -1; |
| 1104 | goto done; |
| 1105 | } |
| 1106 | |
Amitkumar Karwar | 63f275d | 2009-10-06 19:20:28 -0700 | [diff] [blame] | 1107 | if (!lbs_is_cmd_allowed(priv)) { |
| 1108 | ret = -EBUSY; |
| 1109 | goto done; |
| 1110 | } |
| 1111 | |
Holger Schurig | 0d61d04 | 2007-12-05 17:58:06 +0100 | [diff] [blame] | 1112 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1113 | |
| 1114 | if (cmdnode == NULL) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1115 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1116 | |
| 1117 | /* Wake up main thread to execute next command */ |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1118 | wake_up_interruptible(&priv->waitq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1119 | ret = -1; |
| 1120 | goto done; |
| 1121 | } |
| 1122 | |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1123 | cmdnode->callback = NULL; |
| 1124 | cmdnode->callback_arg = (unsigned long)pdata_buf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1125 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1126 | cmdptr = (struct cmd_ds_command *)cmdnode->cmdbuf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1127 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1128 | lbs_deb_host("PREP_CMD: command 0x%04x\n", cmd_no); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1129 | |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1130 | /* Set sequence number, command and INT option */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1131 | priv->seqnum++; |
| 1132 | cmdptr->seqnum = cpu_to_le16(priv->seqnum); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1133 | |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1134 | cmdptr->command = cpu_to_le16(cmd_no); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1135 | cmdptr->result = 0; |
| 1136 | |
| 1137 | switch (cmd_no) { |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1138 | case CMD_802_11_PS_MODE: |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1139 | ret = lbs_cmd_802_11_ps_mode(cmdptr, cmd_action); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1140 | break; |
| 1141 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1142 | case CMD_MAC_REG_ACCESS: |
| 1143 | case CMD_BBP_REG_ACCESS: |
| 1144 | case CMD_RF_REG_ACCESS: |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1145 | ret = lbs_cmd_reg_access(cmdptr, cmd_action, pdata_buf); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1146 | break; |
| 1147 | |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 1148 | case CMD_802_11_MONITOR_MODE: |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1149 | ret = lbs_cmd_802_11_monitor_mode(cmdptr, |
Luis Carlos Cobo | 965f8bbc | 2007-08-02 13:16:55 -0400 | [diff] [blame] | 1150 | cmd_action, pdata_buf); |
| 1151 | break; |
| 1152 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1153 | case CMD_802_11_RSSI: |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1154 | ret = lbs_cmd_802_11_rssi(priv, cmdptr); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1155 | break; |
| 1156 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1157 | case CMD_802_11_SET_AFC: |
| 1158 | case CMD_802_11_GET_AFC: |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1159 | |
| 1160 | cmdptr->command = cpu_to_le16(cmd_no); |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1161 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_ds_802_11_afc) + |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 1162 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1163 | |
| 1164 | memmove(&cmdptr->params.afc, |
| 1165 | pdata_buf, sizeof(struct cmd_ds_802_11_afc)); |
| 1166 | |
| 1167 | ret = 0; |
| 1168 | goto done; |
| 1169 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1170 | case CMD_802_11_TPC_CFG: |
| 1171 | cmdptr->command = cpu_to_le16(CMD_802_11_TPC_CFG); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1172 | cmdptr->size = |
| 1173 | cpu_to_le16(sizeof(struct cmd_ds_802_11_tpc_cfg) + |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 1174 | sizeof(struct cmd_header)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1175 | |
| 1176 | memmove(&cmdptr->params.tpccfg, |
| 1177 | pdata_buf, sizeof(struct cmd_ds_802_11_tpc_cfg)); |
| 1178 | |
| 1179 | ret = 0; |
| 1180 | break; |
David Woodhouse | 5844d12 | 2007-12-18 02:01:37 -0500 | [diff] [blame] | 1181 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1182 | case CMD_BT_ACCESS: |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1183 | ret = lbs_cmd_bt_access(cmdptr, cmd_action, pdata_buf); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1184 | break; |
| 1185 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1186 | case CMD_FWT_ACCESS: |
Holger Schurig | e98a88d | 2008-03-19 14:25:58 +0100 | [diff] [blame] | 1187 | ret = lbs_cmd_fwt_access(cmdptr, cmd_action, pdata_buf); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1188 | break; |
| 1189 | |
Brajesh Dave | 96287ac | 2007-11-20 17:44:28 -0500 | [diff] [blame] | 1190 | case CMD_802_11_BEACON_CTRL: |
| 1191 | ret = lbs_cmd_bcn_ctrl(priv, cmdptr, cmd_action); |
| 1192 | break; |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 1193 | case CMD_802_11_DEEP_SLEEP: |
| 1194 | cmdptr->command = cpu_to_le16(CMD_802_11_DEEP_SLEEP); |
Holger Schurig | 8ec97cc | 2009-10-22 15:30:55 +0200 | [diff] [blame] | 1195 | cmdptr->size = cpu_to_le16(sizeof(struct cmd_header)); |
Amitkumar Karwar | 4912545 | 2009-09-30 20:04:38 -0700 | [diff] [blame] | 1196 | break; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1197 | default: |
David Woodhouse | e37fc6e | 2008-05-20 11:47:16 +0100 | [diff] [blame] | 1198 | lbs_pr_err("PREP_CMD: unknown command 0x%04x\n", cmd_no); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1199 | ret = -1; |
| 1200 | break; |
| 1201 | } |
| 1202 | |
| 1203 | /* return error, since the command preparation failed */ |
| 1204 | if (ret != 0) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1205 | lbs_deb_host("PREP_CMD: command preparation failed\n"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1206 | lbs_cleanup_and_insert_cmd(priv, cmdnode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1207 | ret = -1; |
| 1208 | goto done; |
| 1209 | } |
| 1210 | |
| 1211 | cmdnode->cmdwaitqwoken = 0; |
| 1212 | |
David Woodhouse | 681ffbb | 2007-12-15 20:04:54 -0500 | [diff] [blame] | 1213 | lbs_queue_cmd(priv, cmdnode); |
Dan Williams | fe33615 | 2007-08-02 11:32:25 -0400 | [diff] [blame] | 1214 | wake_up_interruptible(&priv->waitq); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1215 | |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1216 | if (wait_option & CMD_OPTION_WAITFORRSP) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1217 | lbs_deb_host("PREP_CMD: wait for response\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1218 | might_sleep(); |
| 1219 | wait_event_interruptible(cmdnode->cmdwait_q, |
| 1220 | cmdnode->cmdwaitqwoken); |
| 1221 | } |
| 1222 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1223 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 1224 | if (priv->cur_cmd_retcode) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1225 | lbs_deb_host("PREP_CMD: command failed with return code %d\n", |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1226 | priv->cur_cmd_retcode); |
| 1227 | priv->cur_cmd_retcode = 0; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1228 | ret = -1; |
| 1229 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1230 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1231 | |
| 1232 | done: |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1233 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1234 | return ret; |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * @brief This function allocates the command buffer and link |
| 1239 | * it to command free queue. |
| 1240 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1241 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1242 | * @return 0 or -1 |
| 1243 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1244 | int lbs_allocate_cmd_buffer(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1245 | { |
| 1246 | int ret = 0; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1247 | u32 bufsize; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1248 | u32 i; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1249 | struct cmd_ctrl_node *cmdarray; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1250 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1251 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1252 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1253 | /* Allocate and initialize the command array */ |
| 1254 | bufsize = sizeof(struct cmd_ctrl_node) * LBS_NUM_CMD_BUFFERS; |
| 1255 | if (!(cmdarray = kzalloc(bufsize, GFP_KERNEL))) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1256 | lbs_deb_host("ALLOC_CMD_BUF: tempcmd_array is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1257 | ret = -1; |
| 1258 | goto done; |
| 1259 | } |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1260 | priv->cmd_array = cmdarray; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1261 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1262 | /* Allocate and initialize each command buffer in the command array */ |
| 1263 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
| 1264 | cmdarray[i].cmdbuf = kzalloc(LBS_CMD_BUFFER_SIZE, GFP_KERNEL); |
| 1265 | if (!cmdarray[i].cmdbuf) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1266 | lbs_deb_host("ALLOC_CMD_BUF: ptempvirtualaddr is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1267 | ret = -1; |
| 1268 | goto done; |
| 1269 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1270 | } |
| 1271 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1272 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
| 1273 | init_waitqueue_head(&cmdarray[i].cmdwait_q); |
| 1274 | lbs_cleanup_and_insert_cmd(priv, &cmdarray[i]); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1275 | } |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1276 | ret = 0; |
Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 1277 | |
| 1278 | done: |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1279 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | /** |
| 1284 | * @brief This function frees the command buffer. |
| 1285 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1286 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1287 | * @return 0 or -1 |
| 1288 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1289 | int lbs_free_cmd_buffer(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1290 | { |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1291 | struct cmd_ctrl_node *cmdarray; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1292 | unsigned int i; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1293 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1294 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1295 | |
| 1296 | /* need to check if cmd array is allocated or not */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1297 | if (priv->cmd_array == NULL) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1298 | lbs_deb_host("FREE_CMD_BUF: cmd_array is NULL\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1299 | goto done; |
| 1300 | } |
| 1301 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1302 | cmdarray = priv->cmd_array; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1303 | |
| 1304 | /* Release shared memory buffers */ |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1305 | for (i = 0; i < LBS_NUM_CMD_BUFFERS; i++) { |
| 1306 | if (cmdarray[i].cmdbuf) { |
| 1307 | kfree(cmdarray[i].cmdbuf); |
| 1308 | cmdarray[i].cmdbuf = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | /* Release cmd_ctrl_node */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1313 | if (priv->cmd_array) { |
| 1314 | kfree(priv->cmd_array); |
| 1315 | priv->cmd_array = NULL; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1316 | } |
| 1317 | |
| 1318 | done: |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1319 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | |
| 1323 | /** |
| 1324 | * @brief This function gets a free command node if available in |
| 1325 | * command free queue. |
| 1326 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1327 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1328 | * @return cmd_ctrl_node A pointer to cmd_ctrl_node structure or NULL |
| 1329 | */ |
David Woodhouse | 2fd6cfe | 2007-12-11 17:44:10 -0500 | [diff] [blame] | 1330 | static struct cmd_ctrl_node *lbs_get_cmd_ctrl_node(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1331 | { |
| 1332 | struct cmd_ctrl_node *tempnode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1333 | unsigned long flags; |
| 1334 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1335 | lbs_deb_enter(LBS_DEB_HOST); |
| 1336 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1337 | if (!priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1338 | return NULL; |
| 1339 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1340 | spin_lock_irqsave(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1341 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1342 | if (!list_empty(&priv->cmdfreeq)) { |
| 1343 | tempnode = list_first_entry(&priv->cmdfreeq, |
Li Zefan | abe3ed1 | 2007-12-06 13:01:21 +0100 | [diff] [blame] | 1344 | struct cmd_ctrl_node, list); |
| 1345 | list_del(&tempnode->list); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1346 | } else { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1347 | lbs_deb_host("GET_CMD_NODE: cmd_ctrl_node is not available\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1348 | tempnode = NULL; |
| 1349 | } |
| 1350 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1351 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1352 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1353 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1354 | return tempnode; |
| 1355 | } |
| 1356 | |
| 1357 | /** |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1358 | * @brief This function executes next command in command |
Nick Andrew | 877d031 | 2009-01-26 11:06:57 +0100 | [diff] [blame] | 1359 | * pending queue. It will put firmware back to PS mode |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1360 | * if applicable. |
| 1361 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1362 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1363 | * @return 0 or -1 |
| 1364 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1365 | int lbs_execute_next_command(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1366 | { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1367 | struct cmd_ctrl_node *cmdnode = NULL; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1368 | struct cmd_header *cmd; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1369 | unsigned long flags; |
| 1370 | int ret = 0; |
| 1371 | |
Holger Schurig | 1afc09ab | 2008-01-29 09:14:40 +0100 | [diff] [blame] | 1372 | /* Debug group is LBS_DEB_THREAD and not LBS_DEB_HOST, because the |
| 1373 | * only caller to us is lbs_thread() and we get even when a |
| 1374 | * data packet is received */ |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1375 | lbs_deb_enter(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1376 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1377 | spin_lock_irqsave(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1378 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1379 | if (priv->cur_cmd) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1380 | lbs_pr_alert( "EXEC_NEXT_CMD: already processing command!\n"); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1381 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1382 | ret = -1; |
| 1383 | goto done; |
| 1384 | } |
| 1385 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1386 | if (!list_empty(&priv->cmdpendingq)) { |
| 1387 | cmdnode = list_first_entry(&priv->cmdpendingq, |
Li Zefan | abe3ed1 | 2007-12-06 13:01:21 +0100 | [diff] [blame] | 1388 | struct cmd_ctrl_node, list); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1389 | } |
| 1390 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1391 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1392 | |
| 1393 | if (cmdnode) { |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1394 | cmd = cmdnode->cmdbuf; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1395 | |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1396 | if (is_command_allowed_in_ps(le16_to_cpu(cmd->command))) { |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1397 | if ((priv->psstate == PS_STATE_SLEEP) || |
| 1398 | (priv->psstate == PS_STATE_PRE_SLEEP)) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1399 | lbs_deb_host( |
| 1400 | "EXEC_NEXT_CMD: cannot send cmd 0x%04x in psstate %d\n", |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1401 | le16_to_cpu(cmd->command), |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1402 | priv->psstate); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1403 | ret = -1; |
| 1404 | goto done; |
| 1405 | } |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1406 | lbs_deb_host("EXEC_NEXT_CMD: OK to send command " |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1407 | "0x%04x in psstate %d\n", |
| 1408 | le16_to_cpu(cmd->command), priv->psstate); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1409 | } else if (priv->psstate != PS_STATE_FULL_POWER) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1410 | /* |
| 1411 | * 1. Non-PS command: |
| 1412 | * Queue it. set needtowakeup to TRUE if current state |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1413 | * is SLEEP, otherwise call lbs_ps_wakeup to send Exit_PS. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1414 | * 2. PS command but not Exit_PS: |
| 1415 | * Ignore it. |
| 1416 | * 3. PS command Exit_PS: |
| 1417 | * Set needtowakeup to TRUE if current state is SLEEP, |
| 1418 | * otherwise send this command down to firmware |
| 1419 | * immediately. |
| 1420 | */ |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1421 | if (cmd->command != cpu_to_le16(CMD_802_11_PS_MODE)) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1422 | /* Prepare to send Exit PS, |
| 1423 | * this non PS command will be sent later */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1424 | if ((priv->psstate == PS_STATE_SLEEP) |
| 1425 | || (priv->psstate == PS_STATE_PRE_SLEEP) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1426 | ) { |
| 1427 | /* w/ new scheme, it will not reach here. |
| 1428 | since it is blocked in main_thread. */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1429 | priv->needtowakeup = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1430 | } else |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1431 | lbs_ps_wakeup(priv, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1432 | |
| 1433 | ret = 0; |
| 1434 | goto done; |
| 1435 | } else { |
| 1436 | /* |
| 1437 | * PS command. Ignore it if it is not Exit_PS. |
| 1438 | * otherwise send it down immediately. |
| 1439 | */ |
David Woodhouse | 38bfab1 | 2007-12-16 23:26:54 -0500 | [diff] [blame] | 1440 | struct cmd_ds_802_11_ps_mode *psm = (void *)&cmd[1]; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1441 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1442 | lbs_deb_host( |
| 1443 | "EXEC_NEXT_CMD: PS cmd, action 0x%02x\n", |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1444 | psm->action); |
| 1445 | if (psm->action != |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1446 | cpu_to_le16(CMD_SUBCMD_EXIT_PS)) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1447 | lbs_deb_host( |
| 1448 | "EXEC_NEXT_CMD: ignore ENTER_PS cmd\n"); |
Li Zefan | abe3ed1 | 2007-12-06 13:01:21 +0100 | [diff] [blame] | 1449 | list_del(&cmdnode->list); |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 1450 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 1451 | lbs_complete_command(priv, cmdnode, 0); |
| 1452 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1453 | |
| 1454 | ret = 0; |
| 1455 | goto done; |
| 1456 | } |
| 1457 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1458 | if ((priv->psstate == PS_STATE_SLEEP) || |
| 1459 | (priv->psstate == PS_STATE_PRE_SLEEP)) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1460 | lbs_deb_host( |
| 1461 | "EXEC_NEXT_CMD: ignore EXIT_PS cmd in sleep\n"); |
Li Zefan | abe3ed1 | 2007-12-06 13:01:21 +0100 | [diff] [blame] | 1462 | list_del(&cmdnode->list); |
David Woodhouse | 183aeac | 2007-12-15 01:52:54 -0500 | [diff] [blame] | 1463 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 1464 | lbs_complete_command(priv, cmdnode, 0); |
| 1465 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1466 | priv->needtowakeup = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1467 | |
| 1468 | ret = 0; |
| 1469 | goto done; |
| 1470 | } |
| 1471 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1472 | lbs_deb_host( |
| 1473 | "EXEC_NEXT_CMD: sending EXIT_PS\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1474 | } |
| 1475 | } |
Li Zefan | abe3ed1 | 2007-12-06 13:01:21 +0100 | [diff] [blame] | 1476 | list_del(&cmdnode->list); |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1477 | lbs_deb_host("EXEC_NEXT_CMD: sending command 0x%04x\n", |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1478 | le16_to_cpu(cmd->command)); |
David Woodhouse | d9896ee | 2007-12-15 00:09:25 -0500 | [diff] [blame] | 1479 | lbs_submit_command(priv, cmdnode); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1480 | } else { |
| 1481 | /* |
| 1482 | * check if in power save mode, if yes, put the device back |
| 1483 | * to PS mode |
| 1484 | */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1485 | if ((priv->psmode != LBS802_11POWERMODECAM) && |
| 1486 | (priv->psstate == PS_STATE_FULL_POWER) && |
| 1487 | ((priv->connect_status == LBS_CONNECTED) || |
| 1488 | (priv->mesh_connect_status == LBS_CONNECTED))) { |
| 1489 | if (priv->secinfo.WPAenabled || |
| 1490 | priv->secinfo.WPA2enabled) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1491 | /* check for valid WPA group keys */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1492 | if (priv->wpa_mcast_key.len || |
| 1493 | priv->wpa_unicast_key.len) { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1494 | lbs_deb_host( |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1495 | "EXEC_NEXT_CMD: WPA enabled and GTK_SET" |
| 1496 | " go back to PS_SLEEP"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1497 | lbs_ps_sleep(priv, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1498 | } |
| 1499 | } else { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1500 | lbs_deb_host( |
| 1501 | "EXEC_NEXT_CMD: cmdpendingq empty, " |
| 1502 | "go back to PS_SLEEP"); |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1503 | lbs_ps_sleep(priv, 0); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1504 | } |
| 1505 | } |
| 1506 | } |
| 1507 | |
| 1508 | ret = 0; |
| 1509 | done: |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1510 | lbs_deb_leave(LBS_DEB_THREAD); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1511 | return ret; |
| 1512 | } |
| 1513 | |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1514 | static void lbs_send_confirmsleep(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1515 | { |
| 1516 | unsigned long flags; |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1517 | int ret; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1518 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1519 | lbs_deb_enter(LBS_DEB_HOST); |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1520 | lbs_deb_hex(LBS_DEB_HOST, "sleep confirm", (u8 *) &confirm_sleep, |
| 1521 | sizeof(confirm_sleep)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1522 | |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1523 | ret = priv->hw_host_to_card(priv, MVMS_CMD, (u8 *) &confirm_sleep, |
| 1524 | sizeof(confirm_sleep)); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1525 | if (ret) { |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1526 | lbs_pr_alert("confirm_sleep failed\n"); |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1527 | goto out; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1528 | } |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1529 | |
| 1530 | spin_lock_irqsave(&priv->driver_lock, flags); |
| 1531 | |
Holger Schurig | a01f545 | 2008-06-04 11:10:40 +0200 | [diff] [blame] | 1532 | /* We don't get a response on the sleep-confirmation */ |
| 1533 | priv->dnld_sent = DNLD_RES_RECEIVED; |
| 1534 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1535 | /* If nothing to do, go back to sleep (?) */ |
| 1536 | if (!__kfifo_len(priv->event_fifo) && !priv->resp_len[priv->resp_idx]) |
| 1537 | priv->psstate = PS_STATE_SLEEP; |
| 1538 | |
| 1539 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
| 1540 | |
| 1541 | out: |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1542 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1543 | } |
| 1544 | |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1545 | void lbs_ps_sleep(struct lbs_private *priv, int wait_option) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1546 | { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1547 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1548 | |
| 1549 | /* |
| 1550 | * PS is currently supported only in Infrastructure mode |
| 1551 | * Remove this check if it is to be supported in IBSS mode also |
| 1552 | */ |
| 1553 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1554 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1555 | CMD_SUBCMD_ENTER_PS, wait_option, 0, NULL); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1556 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1557 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1558 | } |
| 1559 | |
| 1560 | /** |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1561 | * @brief This function sends Exit_PS command to firmware. |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1562 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1563 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1564 | * @param wait_option wait response or not |
| 1565 | * @return n/a |
| 1566 | */ |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1567 | void lbs_ps_wakeup(struct lbs_private *priv, int wait_option) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1568 | { |
David Woodhouse | 981f187 | 2007-05-25 23:36:54 -0400 | [diff] [blame] | 1569 | __le32 Localpsmode; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1570 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1571 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1572 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1573 | Localpsmode = cpu_to_le32(LBS802_11POWERMODECAM); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1574 | |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1575 | lbs_prepare_and_send_command(priv, CMD_802_11_PS_MODE, |
Dan Williams | 0aef64d | 2007-08-02 11:31:18 -0400 | [diff] [blame] | 1576 | CMD_SUBCMD_EXIT_PS, |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1577 | wait_option, 0, &Localpsmode); |
| 1578 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1579 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | /** |
| 1583 | * @brief This function checks condition and prepares to |
| 1584 | * send sleep confirm command to firmware if ok. |
| 1585 | * |
Holger Schurig | 69f9032 | 2007-11-23 15:43:44 +0100 | [diff] [blame] | 1586 | * @param priv A pointer to struct lbs_private structure |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1587 | * @param psmode Power Saving mode |
| 1588 | * @return n/a |
| 1589 | */ |
Holger Schurig | d4ff0ef | 2008-03-19 14:25:18 +0100 | [diff] [blame] | 1590 | void lbs_ps_confirm_sleep(struct lbs_private *priv) |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1591 | { |
| 1592 | unsigned long flags =0; |
Holger Schurig | d4ff0ef | 2008-03-19 14:25:18 +0100 | [diff] [blame] | 1593 | int allowed = 1; |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1594 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1595 | lbs_deb_enter(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1596 | |
Holger Schurig | a01f545 | 2008-06-04 11:10:40 +0200 | [diff] [blame] | 1597 | spin_lock_irqsave(&priv->driver_lock, flags); |
Holger Schurig | 634b8f49 | 2007-05-25 13:05:16 -0400 | [diff] [blame] | 1598 | if (priv->dnld_sent) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1599 | allowed = 0; |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1600 | lbs_deb_host("dnld_sent was set\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1601 | } |
| 1602 | |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1603 | /* In-progress command? */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1604 | if (priv->cur_cmd) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1605 | allowed = 0; |
David Woodhouse | 23d36ee | 2007-12-12 00:14:21 -0500 | [diff] [blame] | 1606 | lbs_deb_host("cur_cmd was set\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1607 | } |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1608 | |
| 1609 | /* Pending events or command responses? */ |
| 1610 | if (__kfifo_len(priv->event_fifo) || priv->resp_len[priv->resp_idx]) { |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1611 | allowed = 0; |
Holger Schurig | 7919b89 | 2008-04-01 14:50:43 +0200 | [diff] [blame] | 1612 | lbs_deb_host("pending events or command responses\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1613 | } |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1614 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1615 | |
| 1616 | if (allowed) { |
Holger Schurig | 1007832 | 2007-11-15 18:05:47 -0500 | [diff] [blame] | 1617 | lbs_deb_host("sending lbs_ps_confirm_sleep\n"); |
Holger Schurig | f539f2e | 2008-03-26 13:22:11 +0100 | [diff] [blame] | 1618 | lbs_send_confirmsleep(priv); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1619 | } else { |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1620 | lbs_deb_host("sleep confirm has been delayed\n"); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1621 | } |
| 1622 | |
Holger Schurig | 8ff12da | 2007-08-02 11:54:31 -0400 | [diff] [blame] | 1623 | lbs_deb_leave(LBS_DEB_HOST); |
Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1624 | } |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1625 | |
| 1626 | |
Anna Neal | 0112c9e | 2008-09-11 11:17:25 -0700 | [diff] [blame] | 1627 | /** |
| 1628 | * @brief Configures the transmission power control functionality. |
| 1629 | * |
| 1630 | * @param priv A pointer to struct lbs_private structure |
| 1631 | * @param enable Transmission power control enable |
| 1632 | * @param p0 Power level when link quality is good (dBm). |
| 1633 | * @param p1 Power level when link quality is fair (dBm). |
| 1634 | * @param p2 Power level when link quality is poor (dBm). |
| 1635 | * @param usesnr Use Signal to Noise Ratio in TPC |
| 1636 | * |
| 1637 | * @return 0 on success |
| 1638 | */ |
| 1639 | int lbs_set_tpc_cfg(struct lbs_private *priv, int enable, int8_t p0, int8_t p1, |
| 1640 | int8_t p2, int usesnr) |
| 1641 | { |
| 1642 | struct cmd_ds_802_11_tpc_cfg cmd; |
| 1643 | int ret; |
| 1644 | |
| 1645 | memset(&cmd, 0, sizeof(cmd)); |
| 1646 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 1647 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 1648 | cmd.enable = !!enable; |
Anna Neal | 3ed6e08 | 2008-09-26 11:34:35 -0400 | [diff] [blame] | 1649 | cmd.usesnr = !!usesnr; |
Anna Neal | 0112c9e | 2008-09-11 11:17:25 -0700 | [diff] [blame] | 1650 | cmd.P0 = p0; |
| 1651 | cmd.P1 = p1; |
| 1652 | cmd.P2 = p2; |
| 1653 | |
| 1654 | ret = lbs_cmd_with_response(priv, CMD_802_11_TPC_CFG, &cmd); |
| 1655 | |
| 1656 | return ret; |
| 1657 | } |
| 1658 | |
| 1659 | /** |
| 1660 | * @brief Configures the power adaptation settings. |
| 1661 | * |
| 1662 | * @param priv A pointer to struct lbs_private structure |
| 1663 | * @param enable Power adaptation enable |
| 1664 | * @param p0 Power level for 1, 2, 5.5 and 11 Mbps (dBm). |
| 1665 | * @param p1 Power level for 6, 9, 12, 18, 22, 24 and 36 Mbps (dBm). |
| 1666 | * @param p2 Power level for 48 and 54 Mbps (dBm). |
| 1667 | * |
| 1668 | * @return 0 on Success |
| 1669 | */ |
| 1670 | |
| 1671 | int lbs_set_power_adapt_cfg(struct lbs_private *priv, int enable, int8_t p0, |
| 1672 | int8_t p1, int8_t p2) |
| 1673 | { |
| 1674 | struct cmd_ds_802_11_pa_cfg cmd; |
| 1675 | int ret; |
| 1676 | |
| 1677 | memset(&cmd, 0, sizeof(cmd)); |
| 1678 | cmd.hdr.size = cpu_to_le16(sizeof(cmd)); |
| 1679 | cmd.action = cpu_to_le16(CMD_ACT_SET); |
| 1680 | cmd.enable = !!enable; |
| 1681 | cmd.P0 = p0; |
| 1682 | cmd.P1 = p1; |
| 1683 | cmd.P2 = p2; |
| 1684 | |
| 1685 | ret = lbs_cmd_with_response(priv, CMD_802_11_PA_CFG , &cmd); |
| 1686 | |
| 1687 | return ret; |
| 1688 | } |
| 1689 | |
| 1690 | |
Holger Schurig | 6d898b1 | 2009-10-14 16:49:53 +0200 | [diff] [blame] | 1691 | struct cmd_ctrl_node *__lbs_cmd_async(struct lbs_private *priv, |
Holger Schurig | 8db4a2b | 2008-03-19 10:11:00 +0100 | [diff] [blame] | 1692 | uint16_t command, struct cmd_header *in_cmd, int in_cmd_size, |
| 1693 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), |
| 1694 | unsigned long callback_arg) |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1695 | { |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1696 | struct cmd_ctrl_node *cmdnode; |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1697 | |
| 1698 | lbs_deb_enter(LBS_DEB_HOST); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1699 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1700 | if (priv->surpriseremoved) { |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1701 | lbs_deb_host("PREP_CMD: card removed\n"); |
David Woodhouse | 3399ea5 | 2007-12-15 03:09:33 -0500 | [diff] [blame] | 1702 | cmdnode = ERR_PTR(-ENOENT); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1703 | goto done; |
| 1704 | } |
| 1705 | |
Amitkumar Karwar | 63f275d | 2009-10-06 19:20:28 -0700 | [diff] [blame] | 1706 | if (!lbs_is_cmd_allowed(priv)) { |
| 1707 | cmdnode = ERR_PTR(-EBUSY); |
| 1708 | goto done; |
| 1709 | } |
| 1710 | |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1711 | cmdnode = lbs_get_cmd_ctrl_node(priv); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1712 | if (cmdnode == NULL) { |
| 1713 | lbs_deb_host("PREP_CMD: cmdnode is NULL\n"); |
| 1714 | |
| 1715 | /* Wake up main thread to execute next command */ |
| 1716 | wake_up_interruptible(&priv->waitq); |
David Woodhouse | 3399ea5 | 2007-12-15 03:09:33 -0500 | [diff] [blame] | 1717 | cmdnode = ERR_PTR(-ENOBUFS); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1718 | goto done; |
| 1719 | } |
| 1720 | |
David Woodhouse | 448a51a | 2007-12-08 00:59:54 +0000 | [diff] [blame] | 1721 | cmdnode->callback = callback; |
David Woodhouse | 1309b55 | 2007-12-10 13:36:10 -0500 | [diff] [blame] | 1722 | cmdnode->callback_arg = callback_arg; |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1723 | |
Dan Williams | 7ad994d | 2007-12-11 12:33:30 -0500 | [diff] [blame] | 1724 | /* Copy the incoming command to the buffer */ |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1725 | memcpy(cmdnode->cmdbuf, in_cmd, in_cmd_size); |
Dan Williams | 7ad994d | 2007-12-11 12:33:30 -0500 | [diff] [blame] | 1726 | |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1727 | /* Set sequence number, clean result, move to buffer */ |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1728 | priv->seqnum++; |
Dan Williams | ddac452 | 2007-12-11 13:49:39 -0500 | [diff] [blame] | 1729 | cmdnode->cmdbuf->command = cpu_to_le16(command); |
| 1730 | cmdnode->cmdbuf->size = cpu_to_le16(in_cmd_size); |
| 1731 | cmdnode->cmdbuf->seqnum = cpu_to_le16(priv->seqnum); |
| 1732 | cmdnode->cmdbuf->result = 0; |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1733 | |
| 1734 | lbs_deb_host("PREP_CMD: command 0x%04x\n", command); |
| 1735 | |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1736 | cmdnode->cmdwaitqwoken = 0; |
David Woodhouse | 681ffbb | 2007-12-15 20:04:54 -0500 | [diff] [blame] | 1737 | lbs_queue_cmd(priv, cmdnode); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1738 | wake_up_interruptible(&priv->waitq); |
| 1739 | |
David Woodhouse | 3399ea5 | 2007-12-15 03:09:33 -0500 | [diff] [blame] | 1740 | done: |
| 1741 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %p", cmdnode); |
| 1742 | return cmdnode; |
| 1743 | } |
| 1744 | |
Holger Schurig | 8db4a2b | 2008-03-19 10:11:00 +0100 | [diff] [blame] | 1745 | void lbs_cmd_async(struct lbs_private *priv, uint16_t command, |
| 1746 | struct cmd_header *in_cmd, int in_cmd_size) |
| 1747 | { |
| 1748 | lbs_deb_enter(LBS_DEB_CMD); |
| 1749 | __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, |
| 1750 | lbs_cmd_async_callback, 0); |
| 1751 | lbs_deb_leave(LBS_DEB_CMD); |
| 1752 | } |
| 1753 | |
David Woodhouse | 3399ea5 | 2007-12-15 03:09:33 -0500 | [diff] [blame] | 1754 | int __lbs_cmd(struct lbs_private *priv, uint16_t command, |
| 1755 | struct cmd_header *in_cmd, int in_cmd_size, |
| 1756 | int (*callback)(struct lbs_private *, unsigned long, struct cmd_header *), |
| 1757 | unsigned long callback_arg) |
| 1758 | { |
| 1759 | struct cmd_ctrl_node *cmdnode; |
| 1760 | unsigned long flags; |
| 1761 | int ret = 0; |
| 1762 | |
| 1763 | lbs_deb_enter(LBS_DEB_HOST); |
| 1764 | |
| 1765 | cmdnode = __lbs_cmd_async(priv, command, in_cmd, in_cmd_size, |
| 1766 | callback, callback_arg); |
| 1767 | if (IS_ERR(cmdnode)) { |
| 1768 | ret = PTR_ERR(cmdnode); |
| 1769 | goto done; |
| 1770 | } |
| 1771 | |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1772 | might_sleep(); |
| 1773 | wait_event_interruptible(cmdnode->cmdwait_q, cmdnode->cmdwaitqwoken); |
| 1774 | |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1775 | spin_lock_irqsave(&priv->driver_lock, flags); |
David Woodhouse | ae125bf | 2007-12-15 04:22:52 -0500 | [diff] [blame] | 1776 | ret = cmdnode->result; |
| 1777 | if (ret) |
| 1778 | lbs_pr_info("PREP_CMD: command 0x%04x failed: %d\n", |
| 1779 | command, ret); |
David Woodhouse | 3399ea5 | 2007-12-15 03:09:33 -0500 | [diff] [blame] | 1780 | |
David Woodhouse | ad12d0f | 2007-12-15 02:06:16 -0500 | [diff] [blame] | 1781 | __lbs_cleanup_and_insert_cmd(priv, cmdnode); |
David Woodhouse | aa21c00 | 2007-12-08 20:04:36 +0000 | [diff] [blame] | 1782 | spin_unlock_irqrestore(&priv->driver_lock, flags); |
Holger Schurig | 675787e | 2007-12-05 17:58:11 +0100 | [diff] [blame] | 1783 | |
| 1784 | done: |
| 1785 | lbs_deb_leave_args(LBS_DEB_HOST, "ret %d", ret); |
| 1786 | return ret; |
| 1787 | } |
Dan Williams | 14e865b | 2007-12-10 15:11:23 -0500 | [diff] [blame] | 1788 | EXPORT_SYMBOL_GPL(__lbs_cmd); |