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