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