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