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