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