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