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