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