Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | #include "cmd.h" |
| 2 | |
| 3 | #include <linux/module.h> |
| 4 | #include <linux/crc7.h> |
| 5 | #include <linux/spi/spi.h> |
| 6 | |
| 7 | #include "wl12xx.h" |
| 8 | #include "wl12xx_80211.h" |
| 9 | #include "reg.h" |
| 10 | #include "spi.h" |
| 11 | #include "ps.h" |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 12 | #include "acx.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 13 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 14 | /** |
| 15 | * send command to firmware |
| 16 | * |
| 17 | * @wl: wl struct |
| 18 | * @id: command id |
| 19 | * @buf: buffer containing the command, must work with dma |
| 20 | * @len: length of the buffer |
| 21 | */ |
| 22 | int wl12xx_cmd_send(struct wl12xx *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 23 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 24 | struct wl12xx_cmd_header *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 25 | unsigned long timeout; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 26 | u32 intr; |
| 27 | int ret = 0; |
| 28 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 29 | cmd = buf; |
| 30 | cmd->id = id; |
| 31 | cmd->status = 0; |
| 32 | |
| 33 | WARN_ON(len % 4 != 0); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 34 | |
| 35 | wl12xx_ps_elp_wakeup(wl); |
| 36 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 37 | wl12xx_spi_mem_write(wl, wl->cmd_box_addr, buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 38 | |
| 39 | wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
| 40 | |
| 41 | timeout = jiffies + msecs_to_jiffies(WL12XX_COMMAND_TIMEOUT); |
| 42 | |
| 43 | intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
| 44 | while (!(intr & wl->chip.intr_cmd_complete)) { |
| 45 | if (time_after(jiffies, timeout)) { |
| 46 | wl12xx_error("command complete timeout"); |
| 47 | ret = -ETIMEDOUT; |
| 48 | goto out; |
| 49 | } |
| 50 | |
| 51 | msleep(1); |
| 52 | |
| 53 | intr = wl12xx_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
| 54 | } |
| 55 | |
| 56 | wl12xx_reg_write32(wl, ACX_REG_INTERRUPT_ACK, |
| 57 | wl->chip.intr_cmd_complete); |
| 58 | |
| 59 | out: |
| 60 | wl12xx_ps_elp_sleep(wl); |
| 61 | |
| 62 | return ret; |
| 63 | } |
| 64 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 65 | /** |
| 66 | * send test command to firmware |
| 67 | * |
| 68 | * @wl: wl struct |
| 69 | * @buf: buffer containing the command, without headers, no dma requirements |
| 70 | * @len: length of the buffer |
| 71 | * @answer: is answer needed |
| 72 | * |
| 73 | * FIXME: cmd_test users need to be converted to the new interface |
| 74 | */ |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 75 | int wl12xx_cmd_test(struct wl12xx *wl, void *buf, size_t buf_len, u8 answer) |
| 76 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 77 | struct wl12xx_command *cmd; |
| 78 | size_t cmd_len; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 79 | int ret; |
| 80 | |
| 81 | wl12xx_debug(DEBUG_CMD, "cmd test"); |
| 82 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 83 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 84 | if (!cmd) { |
| 85 | ret = -ENOMEM; |
| 86 | goto out; |
| 87 | } |
| 88 | |
| 89 | memcpy(cmd->parameters, buf, buf_len); |
| 90 | |
| 91 | /* FIXME: ugly */ |
| 92 | cmd_len = sizeof(struct wl12xx_cmd_header) + buf_len; |
| 93 | |
| 94 | ret = wl12xx_cmd_send(wl, CMD_TEST, cmd, cmd_len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 95 | if (ret < 0) { |
| 96 | wl12xx_warning("TEST command failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 97 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | if (answer) { |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 101 | /* |
| 102 | * The test command got in, we can read the answer. |
| 103 | * The answer would be a wl12xx_command, where the |
| 104 | * parameter array contains the actual answer. |
| 105 | */ |
| 106 | |
| 107 | wl12xx_ps_elp_wakeup(wl); |
| 108 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 109 | wl12xx_spi_mem_read(wl, wl->cmd_box_addr, cmd, cmd_len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 110 | |
| 111 | wl12xx_ps_elp_sleep(wl); |
| 112 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 113 | if (cmd->header.status != CMD_STATUS_SUCCESS) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 114 | wl12xx_error("TEST command answer error: %d", |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 115 | cmd->header.status); |
| 116 | memcpy(buf, cmd->parameters, buf_len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 117 | } |
| 118 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 119 | out: |
| 120 | kfree(cmd); |
| 121 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 122 | } |
| 123 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 124 | /** |
| 125 | * read acx from firmware |
| 126 | * |
| 127 | * @wl: wl struct |
| 128 | * @id: acx id |
| 129 | * @buf: buffer for the response, including all headers, must work with dma |
| 130 | * @len: lenght of buf |
| 131 | */ |
| 132 | int wl12xx_cmd_interrogate(struct wl12xx *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 133 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 134 | struct acx_header *acx = buf; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 135 | int ret; |
| 136 | |
| 137 | wl12xx_debug(DEBUG_CMD, "cmd interrogate"); |
| 138 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 139 | acx->id = id; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 140 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 141 | /* payload length, does not include any headers */ |
| 142 | acx->len = len - sizeof(*acx); |
| 143 | |
| 144 | ret = wl12xx_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 145 | if (ret < 0) { |
| 146 | wl12xx_error("INTERROGATE command failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 147 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | wl12xx_ps_elp_wakeup(wl); |
| 151 | |
| 152 | /* the interrogate command got in, we can read the answer */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 153 | wl12xx_spi_mem_read(wl, wl->cmd_box_addr, buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 154 | |
| 155 | wl12xx_ps_elp_sleep(wl); |
| 156 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 157 | acx = buf; |
| 158 | if (acx->cmd.status != CMD_STATUS_SUCCESS) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 159 | wl12xx_error("INTERROGATE command error: %d", |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 160 | acx->cmd.status); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 161 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 162 | out: |
| 163 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 164 | } |
| 165 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 166 | /** |
| 167 | * write acx value to firmware |
| 168 | * |
| 169 | * @wl: wl struct |
| 170 | * @id: acx id |
| 171 | * @buf: buffer containing acx, including all headers, must work with dma |
| 172 | * @len: length of buf |
| 173 | */ |
| 174 | int wl12xx_cmd_configure(struct wl12xx *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 175 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 176 | struct acx_header *acx = buf; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 177 | int ret; |
| 178 | |
| 179 | wl12xx_debug(DEBUG_CMD, "cmd configure"); |
| 180 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 181 | acx->id = id; |
| 182 | |
| 183 | /* payload length, does not include any headers */ |
| 184 | acx->len = len - sizeof(*acx); |
| 185 | |
| 186 | ret = wl12xx_cmd_send(wl, CMD_CONFIGURE, acx, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 187 | if (ret < 0) { |
| 188 | wl12xx_warning("CONFIGURE command NOK"); |
| 189 | return ret; |
| 190 | } |
| 191 | |
| 192 | return 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | int wl12xx_cmd_vbm(struct wl12xx *wl, u8 identity, |
| 196 | void *bitmap, u16 bitmap_len, u8 bitmap_control) |
| 197 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 198 | struct wl12xx_cmd_vbm_update *vbm; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 199 | int ret; |
| 200 | |
| 201 | wl12xx_debug(DEBUG_CMD, "cmd vbm"); |
| 202 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 203 | vbm = kzalloc(sizeof(*vbm), GFP_KERNEL); |
| 204 | if (!vbm) { |
| 205 | ret = -ENOMEM; |
| 206 | goto out; |
| 207 | } |
| 208 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 209 | /* Count and period will be filled by the target */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 210 | vbm->tim.bitmap_ctrl = bitmap_control; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 211 | if (bitmap_len > PARTIAL_VBM_MAX) { |
| 212 | wl12xx_warning("cmd vbm len is %d B, truncating to %d", |
| 213 | bitmap_len, PARTIAL_VBM_MAX); |
| 214 | bitmap_len = PARTIAL_VBM_MAX; |
| 215 | } |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 216 | memcpy(vbm->tim.pvb_field, bitmap, bitmap_len); |
| 217 | vbm->tim.identity = identity; |
| 218 | vbm->tim.length = bitmap_len + 3; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 219 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 220 | vbm->len = cpu_to_le16(bitmap_len + 5); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 221 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 222 | ret = wl12xx_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 223 | if (ret < 0) { |
| 224 | wl12xx_error("VBM command failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 225 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 226 | } |
| 227 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 228 | out: |
| 229 | kfree(vbm); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 230 | return 0; |
| 231 | } |
| 232 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 233 | int wl12xx_cmd_data_path(struct wl12xx *wl, u8 channel, bool enable) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 234 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 235 | struct cmd_enabledisable_path *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 236 | int ret; |
| 237 | u16 cmd_rx, cmd_tx; |
| 238 | |
| 239 | wl12xx_debug(DEBUG_CMD, "cmd data path"); |
| 240 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 241 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 242 | if (!cmd) { |
| 243 | ret = -ENOMEM; |
| 244 | goto out; |
| 245 | } |
| 246 | |
| 247 | cmd->channel = channel; |
| 248 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 249 | if (enable) { |
| 250 | cmd_rx = CMD_ENABLE_RX; |
| 251 | cmd_tx = CMD_ENABLE_TX; |
| 252 | } else { |
| 253 | cmd_rx = CMD_DISABLE_RX; |
| 254 | cmd_tx = CMD_DISABLE_TX; |
| 255 | } |
| 256 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 257 | ret = wl12xx_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 258 | if (ret < 0) { |
| 259 | wl12xx_error("rx %s cmd for channel %d failed", |
| 260 | enable ? "start" : "stop", channel); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 261 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | wl12xx_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
| 265 | enable ? "start" : "stop", channel); |
| 266 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 267 | ret = wl12xx_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 268 | if (ret < 0) { |
| 269 | wl12xx_error("tx %s cmd for channel %d failed", |
| 270 | enable ? "start" : "stop", channel); |
| 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | wl12xx_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
| 275 | enable ? "start" : "stop", channel); |
| 276 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 277 | out: |
| 278 | kfree(cmd); |
| 279 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | int wl12xx_cmd_join(struct wl12xx *wl, u8 bss_type, u8 dtim_interval, |
| 283 | u16 beacon_interval, u8 wait) |
| 284 | { |
| 285 | unsigned long timeout; |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 286 | struct cmd_join *join; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 287 | int ret, i; |
| 288 | u8 *bssid; |
| 289 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 290 | join = kzalloc(sizeof(*join), GFP_KERNEL); |
| 291 | if (!join) { |
| 292 | ret = -ENOMEM; |
| 293 | goto out; |
| 294 | } |
| 295 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 296 | /* FIXME: this should be in main.c */ |
| 297 | ret = wl12xx_acx_frame_rates(wl, DEFAULT_HW_GEN_TX_RATE, |
| 298 | DEFAULT_HW_GEN_MODULATION_TYPE, |
| 299 | wl->tx_mgmt_frm_rate, |
| 300 | wl->tx_mgmt_frm_mod); |
| 301 | if (ret < 0) |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 302 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 303 | |
| 304 | wl12xx_debug(DEBUG_CMD, "cmd join"); |
| 305 | |
| 306 | /* Reverse order BSSID */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 307 | bssid = (u8 *) &join->bssid_lsb; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 308 | for (i = 0; i < ETH_ALEN; i++) |
| 309 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; |
| 310 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 311 | join->rx_config_options = wl->rx_config; |
| 312 | join->rx_filter_options = wl->rx_filter; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 313 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 314 | join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 315 | RATE_MASK_5_5MBPS | RATE_MASK_11MBPS; |
| 316 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 317 | join->beacon_interval = beacon_interval; |
| 318 | join->dtim_interval = dtim_interval; |
| 319 | join->bss_type = bss_type; |
| 320 | join->channel = wl->channel; |
| 321 | join->ctrl = JOIN_CMD_CTRL_TX_FLUSH; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 322 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 323 | ret = wl12xx_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 324 | if (ret < 0) { |
| 325 | wl12xx_error("failed to initiate cmd join"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 326 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | timeout = msecs_to_jiffies(JOIN_TIMEOUT); |
| 330 | |
| 331 | /* |
| 332 | * ugly hack: we should wait for JOIN_EVENT_COMPLETE_ID but to |
| 333 | * simplify locking we just sleep instead, for now |
| 334 | */ |
| 335 | if (wait) |
| 336 | msleep(10); |
| 337 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 338 | out: |
| 339 | kfree(join); |
| 340 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | int wl12xx_cmd_ps_mode(struct wl12xx *wl, u8 ps_mode) |
| 344 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 345 | struct wl12xx_cmd_ps_params *ps_params = NULL; |
| 346 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 347 | |
| 348 | /* FIXME: this should be in ps.c */ |
Luciano Coelho | 9f483dc | 2009-06-12 14:15:46 +0300 | [diff] [blame] | 349 | ret = wl12xx_acx_wake_up_conditions(wl, WAKE_UP_EVENT_DTIM_BITMAP, |
| 350 | wl->listen_int); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 351 | if (ret < 0) { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 352 | wl12xx_error("couldn't set wake up conditions"); |
| 353 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | wl12xx_debug(DEBUG_CMD, "cmd set ps mode"); |
| 357 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 358 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 359 | if (!ps_params) { |
| 360 | ret = -ENOMEM; |
| 361 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 362 | } |
| 363 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 364 | ps_params->ps_mode = ps_mode; |
| 365 | ps_params->send_null_data = 1; |
| 366 | ps_params->retries = 5; |
| 367 | ps_params->hang_over_period = 128; |
| 368 | ps_params->null_data_rate = 1; /* 1 Mbps */ |
| 369 | |
| 370 | ret = wl12xx_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
| 371 | sizeof(*ps_params)); |
| 372 | if (ret < 0) { |
| 373 | wl12xx_error("cmd set_ps_mode failed"); |
| 374 | goto out; |
| 375 | } |
| 376 | |
| 377 | out: |
| 378 | kfree(ps_params); |
| 379 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 380 | } |
| 381 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 382 | int wl12xx_cmd_read_memory(struct wl12xx *wl, u32 addr, void *answer, |
| 383 | size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 384 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 385 | struct cmd_read_write_memory *cmd; |
| 386 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 387 | |
| 388 | wl12xx_debug(DEBUG_CMD, "cmd read memory"); |
| 389 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 390 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 391 | if (!cmd) { |
| 392 | ret = -ENOMEM; |
| 393 | goto out; |
| 394 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 395 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 396 | WARN_ON(len > MAX_READ_SIZE); |
| 397 | len = min_t(size_t, len, MAX_READ_SIZE); |
| 398 | |
| 399 | cmd->addr = addr; |
| 400 | cmd->size = len; |
| 401 | |
| 402 | ret = wl12xx_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 403 | if (ret < 0) { |
| 404 | wl12xx_error("read memory command failed: %d", ret); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 405 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | /* the read command got in, we can now read the answer */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 409 | wl12xx_spi_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 410 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 411 | if (cmd->header.status != CMD_STATUS_SUCCESS) |
| 412 | wl12xx_error("error in read command result: %d", |
| 413 | cmd->header.status); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 414 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 415 | memcpy(answer, cmd->value, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 416 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 417 | out: |
| 418 | kfree(cmd); |
| 419 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | int wl12xx_cmd_template_set(struct wl12xx *wl, u16 cmd_id, |
| 423 | void *buf, size_t buf_len) |
| 424 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 425 | struct wl12xx_cmd_packet_template *cmd; |
| 426 | size_t cmd_len; |
| 427 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 428 | |
| 429 | wl12xx_debug(DEBUG_CMD, "cmd template %d", cmd_id); |
| 430 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 431 | WARN_ON(buf_len > WL12XX_MAX_TEMPLATE_SIZE); |
| 432 | buf_len = min_t(size_t, buf_len, WL12XX_MAX_TEMPLATE_SIZE); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 433 | cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 434 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 435 | cmd = kzalloc(cmd_len, GFP_KERNEL); |
| 436 | if (!cmd) { |
| 437 | ret = -ENOMEM; |
| 438 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 439 | } |
| 440 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 441 | cmd->size = cpu_to_le16(buf_len); |
| 442 | |
| 443 | if (buf) |
| 444 | memcpy(cmd->data, buf, buf_len); |
| 445 | |
| 446 | ret = wl12xx_cmd_send(wl, cmd_id, cmd, cmd_len); |
| 447 | if (ret < 0) { |
| 448 | wl12xx_warning("cmd set_template failed: %d", ret); |
| 449 | goto out; |
| 450 | } |
| 451 | |
| 452 | out: |
| 453 | kfree(cmd); |
| 454 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 455 | } |