Kalle Valo | 9bc6772 | 2010-10-10 11:28:32 +0300 | [diff] [blame] | 1 | #include "cmd.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 2 | |
| 3 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/slab.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 5 | #include <linux/crc7.h> |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 6 | |
Kalle Valo | 1367411 | 2009-06-12 14:17:25 +0300 | [diff] [blame] | 7 | #include "wl1251.h" |
Kalle Valo | 9bc6772 | 2010-10-10 11:28:32 +0300 | [diff] [blame] | 8 | #include "reg.h" |
| 9 | #include "io.h" |
| 10 | #include "ps.h" |
| 11 | #include "acx.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 12 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 13 | /** |
| 14 | * send command to firmware |
| 15 | * |
| 16 | * @wl: wl struct |
| 17 | * @id: command id |
| 18 | * @buf: buffer containing the command, must work with dma |
| 19 | * @len: length of the buffer |
| 20 | */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 21 | int wl1251_cmd_send(struct wl1251 *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 22 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 23 | struct wl1251_cmd_header *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 24 | unsigned long timeout; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 25 | u32 intr; |
| 26 | int ret = 0; |
| 27 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 28 | cmd = buf; |
| 29 | cmd->id = id; |
| 30 | cmd->status = 0; |
| 31 | |
| 32 | WARN_ON(len % 4 != 0); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 33 | |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 34 | wl1251_mem_write(wl, wl->cmd_box_addr, buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 35 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 36 | wl1251_reg_write32(wl, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_CMD); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 37 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 38 | timeout = jiffies + msecs_to_jiffies(WL1251_COMMAND_TIMEOUT); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 39 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 40 | intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Kalle Valo | 0e71bb0 | 2009-08-07 13:33:57 +0300 | [diff] [blame] | 41 | while (!(intr & WL1251_ACX_INTR_CMD_COMPLETE)) { |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 42 | if (time_after(jiffies, timeout)) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 43 | wl1251_error("command complete timeout"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 44 | ret = -ETIMEDOUT; |
| 45 | goto out; |
| 46 | } |
| 47 | |
| 48 | msleep(1); |
| 49 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 50 | intr = wl1251_reg_read32(wl, ACX_REG_INTERRUPT_NO_CLEAR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 51 | } |
| 52 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 53 | wl1251_reg_write32(wl, ACX_REG_INTERRUPT_ACK, |
Kalle Valo | 0e71bb0 | 2009-08-07 13:33:57 +0300 | [diff] [blame] | 54 | WL1251_ACX_INTR_CMD_COMPLETE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 55 | |
| 56 | out: |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 57 | return ret; |
| 58 | } |
| 59 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 60 | /** |
| 61 | * send test command to firmware |
| 62 | * |
| 63 | * @wl: wl struct |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 64 | * @buf: buffer containing the command, with all headers, must work with dma |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 65 | * @len: length of the buffer |
| 66 | * @answer: is answer needed |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 67 | */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 68 | int wl1251_cmd_test(struct wl1251 *wl, void *buf, size_t buf_len, u8 answer) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 69 | { |
| 70 | int ret; |
| 71 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 72 | wl1251_debug(DEBUG_CMD, "cmd test"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 73 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 74 | ret = wl1251_cmd_send(wl, CMD_TEST, buf, buf_len); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 75 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 76 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 77 | wl1251_warning("TEST command failed"); |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 78 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | if (answer) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 82 | struct wl1251_command *cmd_answer; |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 83 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 84 | /* |
| 85 | * The test command got in, we can read the answer. |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 86 | * The answer would be a wl1251_command, where the |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 87 | * parameter array contains the actual answer. |
| 88 | */ |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 89 | wl1251_mem_read(wl, wl->cmd_box_addr, buf, buf_len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 90 | |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 91 | cmd_answer = buf; |
| 92 | |
| 93 | if (cmd_answer->header.status != CMD_STATUS_SUCCESS) |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 94 | wl1251_error("TEST command answer error: %d", |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 95 | cmd_answer->header.status); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 96 | } |
| 97 | |
Ari Kauppi | 6021b28 | 2009-06-12 14:16:13 +0300 | [diff] [blame] | 98 | return 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 99 | } |
| 100 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 101 | /** |
| 102 | * read acx from firmware |
| 103 | * |
| 104 | * @wl: wl struct |
| 105 | * @id: acx id |
| 106 | * @buf: buffer for the response, including all headers, must work with dma |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 107 | * @len: length of buf |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 108 | */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 109 | int wl1251_cmd_interrogate(struct wl1251 *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 110 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 111 | struct acx_header *acx = buf; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 112 | int ret; |
| 113 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 114 | wl1251_debug(DEBUG_CMD, "cmd interrogate"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 115 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 116 | acx->id = id; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 117 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 118 | /* payload length, does not include any headers */ |
| 119 | acx->len = len - sizeof(*acx); |
| 120 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 121 | ret = wl1251_cmd_send(wl, CMD_INTERROGATE, acx, sizeof(*acx)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 122 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 123 | wl1251_error("INTERROGATE command failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 124 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 125 | } |
| 126 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 127 | /* the interrogate command got in, we can read the answer */ |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 128 | wl1251_mem_read(wl, wl->cmd_box_addr, buf, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 129 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 130 | acx = buf; |
| 131 | if (acx->cmd.status != CMD_STATUS_SUCCESS) |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 132 | wl1251_error("INTERROGATE command error: %d", |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 133 | acx->cmd.status); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 134 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 135 | out: |
| 136 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 137 | } |
| 138 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 139 | /** |
| 140 | * write acx value to firmware |
| 141 | * |
| 142 | * @wl: wl struct |
| 143 | * @id: acx id |
| 144 | * @buf: buffer containing acx, including all headers, must work with dma |
| 145 | * @len: length of buf |
| 146 | */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 147 | int wl1251_cmd_configure(struct wl1251 *wl, u16 id, void *buf, size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 148 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 149 | struct acx_header *acx = buf; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 150 | int ret; |
| 151 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 152 | wl1251_debug(DEBUG_CMD, "cmd configure"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 153 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 154 | acx->id = id; |
| 155 | |
| 156 | /* payload length, does not include any headers */ |
| 157 | acx->len = len - sizeof(*acx); |
| 158 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 159 | ret = wl1251_cmd_send(wl, CMD_CONFIGURE, acx, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 160 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 161 | wl1251_warning("CONFIGURE command NOK"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 162 | return ret; |
| 163 | } |
| 164 | |
| 165 | return 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 166 | } |
| 167 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 168 | int wl1251_cmd_vbm(struct wl1251 *wl, u8 identity, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 169 | void *bitmap, u16 bitmap_len, u8 bitmap_control) |
| 170 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 171 | struct wl1251_cmd_vbm_update *vbm; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 172 | int ret; |
| 173 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 174 | wl1251_debug(DEBUG_CMD, "cmd vbm"); |
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 | vbm = kzalloc(sizeof(*vbm), GFP_KERNEL); |
| 177 | if (!vbm) { |
| 178 | ret = -ENOMEM; |
| 179 | goto out; |
| 180 | } |
| 181 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 182 | /* Count and period will be filled by the target */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 183 | vbm->tim.bitmap_ctrl = bitmap_control; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 184 | if (bitmap_len > PARTIAL_VBM_MAX) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 185 | wl1251_warning("cmd vbm len is %d B, truncating to %d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 186 | bitmap_len, PARTIAL_VBM_MAX); |
| 187 | bitmap_len = PARTIAL_VBM_MAX; |
| 188 | } |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 189 | memcpy(vbm->tim.pvb_field, bitmap, bitmap_len); |
| 190 | vbm->tim.identity = identity; |
| 191 | vbm->tim.length = bitmap_len + 3; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 192 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 193 | vbm->len = cpu_to_le16(bitmap_len + 5); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 194 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 195 | ret = wl1251_cmd_send(wl, CMD_VBM, vbm, sizeof(*vbm)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 196 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 197 | wl1251_error("VBM command failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 198 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 199 | } |
| 200 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 201 | out: |
| 202 | kfree(vbm); |
Julia Lawall | 9f19fa6 | 2010-08-16 18:25:21 +0200 | [diff] [blame] | 203 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 204 | } |
| 205 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 206 | int wl1251_cmd_data_path(struct wl1251 *wl, u8 channel, bool enable) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 207 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 208 | struct cmd_enabledisable_path *cmd; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 209 | int ret; |
| 210 | u16 cmd_rx, cmd_tx; |
| 211 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 212 | wl1251_debug(DEBUG_CMD, "cmd data path"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 213 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 214 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 215 | if (!cmd) { |
| 216 | ret = -ENOMEM; |
| 217 | goto out; |
| 218 | } |
| 219 | |
| 220 | cmd->channel = channel; |
| 221 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 222 | if (enable) { |
| 223 | cmd_rx = CMD_ENABLE_RX; |
| 224 | cmd_tx = CMD_ENABLE_TX; |
| 225 | } else { |
| 226 | cmd_rx = CMD_DISABLE_RX; |
| 227 | cmd_tx = CMD_DISABLE_TX; |
| 228 | } |
| 229 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 230 | ret = wl1251_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 231 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 232 | wl1251_error("rx %s cmd for channel %d failed", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 233 | enable ? "start" : "stop", channel); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 234 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 235 | } |
| 236 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 237 | wl1251_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 238 | enable ? "start" : "stop", channel); |
| 239 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 240 | ret = wl1251_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 241 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 242 | wl1251_error("tx %s cmd for channel %d failed", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 243 | enable ? "start" : "stop", channel); |
Julia Lawall | 059c438 | 2011-08-08 13:18:03 +0200 | [diff] [blame] | 244 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 245 | } |
| 246 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 247 | wl1251_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 248 | enable ? "start" : "stop", channel); |
| 249 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 250 | out: |
| 251 | kfree(cmd); |
| 252 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 253 | } |
| 254 | |
Kalle Valo | c88f875 | 2009-08-07 13:34:34 +0300 | [diff] [blame] | 255 | int wl1251_cmd_join(struct wl1251 *wl, u8 bss_type, u8 channel, |
| 256 | u16 beacon_interval, u8 dtim_interval) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 257 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 258 | struct cmd_join *join; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 259 | int ret, i; |
| 260 | u8 *bssid; |
| 261 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 262 | join = kzalloc(sizeof(*join), GFP_KERNEL); |
| 263 | if (!join) { |
| 264 | ret = -ENOMEM; |
| 265 | goto out; |
| 266 | } |
| 267 | |
Kalle Valo | c88f875 | 2009-08-07 13:34:34 +0300 | [diff] [blame] | 268 | wl1251_debug(DEBUG_CMD, "cmd join%s ch %d %d/%d", |
Kalle Valo | e2fd461 | 2009-08-07 13:34:12 +0300 | [diff] [blame] | 269 | bss_type == BSS_TYPE_IBSS ? " ibss" : "", |
Kalle Valo | c88f875 | 2009-08-07 13:34:34 +0300 | [diff] [blame] | 270 | channel, beacon_interval, dtim_interval); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 271 | |
| 272 | /* Reverse order BSSID */ |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 273 | bssid = (u8 *) &join->bssid_lsb; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 274 | for (i = 0; i < ETH_ALEN; i++) |
| 275 | bssid[i] = wl->bssid[ETH_ALEN - i - 1]; |
| 276 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 277 | join->rx_config_options = wl->rx_config; |
| 278 | join->rx_filter_options = wl->rx_filter; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 279 | |
Kalle Valo | f26b32e | 2009-08-07 13:35:33 +0300 | [diff] [blame] | 280 | /* |
| 281 | * FIXME: disable temporarily all filters because after commit |
| 282 | * 9cef8737 "mac80211: fix managed mode BSSID handling" broke |
| 283 | * association. The filter logic needs to be implemented properly |
| 284 | * and once that is done, this hack can be removed. |
| 285 | */ |
| 286 | join->rx_config_options = 0; |
| 287 | join->rx_filter_options = WL1251_DEFAULT_RX_FILTER; |
| 288 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 289 | join->basic_rate_set = RATE_MASK_1MBPS | RATE_MASK_2MBPS | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 290 | RATE_MASK_5_5MBPS | RATE_MASK_11MBPS; |
| 291 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 292 | join->beacon_interval = beacon_interval; |
| 293 | join->dtim_interval = dtim_interval; |
| 294 | join->bss_type = bss_type; |
Kalle Valo | c88f875 | 2009-08-07 13:34:34 +0300 | [diff] [blame] | 295 | join->channel = channel; |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 296 | join->ctrl = JOIN_CMD_CTRL_TX_FLUSH; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 297 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 298 | ret = wl1251_cmd_send(wl, CMD_START_JOIN, join, sizeof(*join)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 299 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 300 | wl1251_error("failed to initiate cmd join"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 301 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 302 | } |
| 303 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 304 | out: |
| 305 | kfree(join); |
| 306 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 307 | } |
| 308 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 309 | int wl1251_cmd_ps_mode(struct wl1251 *wl, u8 ps_mode) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 310 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 311 | struct wl1251_cmd_ps_params *ps_params = NULL; |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 312 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 313 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 314 | wl1251_debug(DEBUG_CMD, "cmd set ps mode"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 315 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 316 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 317 | if (!ps_params) { |
| 318 | ret = -ENOMEM; |
| 319 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 320 | } |
| 321 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 322 | ps_params->ps_mode = ps_mode; |
| 323 | ps_params->send_null_data = 1; |
| 324 | ps_params->retries = 5; |
| 325 | ps_params->hang_over_period = 128; |
| 326 | ps_params->null_data_rate = 1; /* 1 Mbps */ |
| 327 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 328 | ret = wl1251_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 329 | sizeof(*ps_params)); |
| 330 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 331 | wl1251_error("cmd set_ps_mode failed"); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 332 | goto out; |
| 333 | } |
| 334 | |
| 335 | out: |
| 336 | kfree(ps_params); |
| 337 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 338 | } |
| 339 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 340 | int wl1251_cmd_read_memory(struct wl1251 *wl, u32 addr, void *answer, |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 341 | size_t len) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 342 | { |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 343 | struct cmd_read_write_memory *cmd; |
| 344 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 345 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 346 | wl1251_debug(DEBUG_CMD, "cmd read memory"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 347 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 348 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 349 | if (!cmd) { |
| 350 | ret = -ENOMEM; |
| 351 | goto out; |
| 352 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 353 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 354 | WARN_ON(len > MAX_READ_SIZE); |
| 355 | len = min_t(size_t, len, MAX_READ_SIZE); |
| 356 | |
| 357 | cmd->addr = addr; |
| 358 | cmd->size = len; |
| 359 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 360 | ret = wl1251_cmd_send(wl, CMD_READ_MEMORY, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 361 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 362 | wl1251_error("read memory command failed: %d", ret); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 363 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /* the read command got in, we can now read the answer */ |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 367 | wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 368 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 369 | if (cmd->header.status != CMD_STATUS_SUCCESS) |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 370 | wl1251_error("error in read command result: %d", |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 371 | cmd->header.status); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 372 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 373 | memcpy(answer, cmd->value, len); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 374 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 375 | out: |
| 376 | kfree(cmd); |
| 377 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 378 | } |
| 379 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 380 | int wl1251_cmd_template_set(struct wl1251 *wl, u16 cmd_id, |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 381 | void *buf, size_t buf_len) |
| 382 | { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 383 | struct wl1251_cmd_packet_template *cmd; |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 384 | size_t cmd_len; |
| 385 | int ret = 0; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 386 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 387 | wl1251_debug(DEBUG_CMD, "cmd template %d", cmd_id); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 388 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 389 | WARN_ON(buf_len > WL1251_MAX_TEMPLATE_SIZE); |
| 390 | buf_len = min_t(size_t, buf_len, WL1251_MAX_TEMPLATE_SIZE); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 391 | cmd_len = ALIGN(sizeof(*cmd) + buf_len, 4); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 392 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 393 | cmd = kzalloc(cmd_len, GFP_KERNEL); |
| 394 | if (!cmd) { |
| 395 | ret = -ENOMEM; |
| 396 | goto out; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 397 | } |
| 398 | |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 399 | cmd->size = cpu_to_le16(buf_len); |
| 400 | |
| 401 | if (buf) |
| 402 | memcpy(cmd->data, buf, buf_len); |
| 403 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 404 | ret = wl1251_cmd_send(wl, cmd_id, cmd, cmd_len); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 405 | if (ret < 0) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 406 | wl1251_warning("cmd set_template failed: %d", ret); |
Kalle Valo | ff25839 | 2009-06-12 14:14:19 +0300 | [diff] [blame] | 407 | goto out; |
| 408 | } |
| 409 | |
| 410 | out: |
| 411 | kfree(cmd); |
| 412 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 413 | } |
Kalle Valo | 3a98c30 | 2010-01-05 20:16:51 +0200 | [diff] [blame] | 414 | |
| 415 | int wl1251_cmd_scan(struct wl1251 *wl, u8 *ssid, size_t ssid_len, |
Kalle Valo | dc52f0a | 2010-01-05 20:17:03 +0200 | [diff] [blame] | 416 | struct ieee80211_channel *channels[], |
Kalle Valo | 3a98c30 | 2010-01-05 20:16:51 +0200 | [diff] [blame] | 417 | unsigned int n_channels, unsigned int n_probes) |
| 418 | { |
| 419 | struct wl1251_cmd_scan *cmd; |
| 420 | int i, ret = 0; |
| 421 | |
| 422 | wl1251_debug(DEBUG_CMD, "cmd scan"); |
| 423 | |
| 424 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 425 | if (!cmd) |
| 426 | return -ENOMEM; |
| 427 | |
| 428 | cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD); |
| 429 | cmd->params.rx_filter_options = cpu_to_le32(CFG_RX_PRSP_EN | |
| 430 | CFG_RX_MGMT_EN | |
| 431 | CFG_RX_BCN_EN); |
| 432 | cmd->params.scan_options = 0; |
| 433 | cmd->params.num_channels = n_channels; |
| 434 | cmd->params.num_probe_requests = n_probes; |
| 435 | cmd->params.tx_rate = cpu_to_le16(1 << 1); /* 2 Mbps */ |
| 436 | cmd->params.tid_trigger = 0; |
| 437 | |
| 438 | for (i = 0; i < n_channels; i++) { |
| 439 | cmd->channels[i].min_duration = |
| 440 | cpu_to_le32(WL1251_SCAN_MIN_DURATION); |
| 441 | cmd->channels[i].max_duration = |
| 442 | cpu_to_le32(WL1251_SCAN_MAX_DURATION); |
| 443 | memset(&cmd->channels[i].bssid_lsb, 0xff, 4); |
| 444 | memset(&cmd->channels[i].bssid_msb, 0xff, 2); |
| 445 | cmd->channels[i].early_termination = 0; |
| 446 | cmd->channels[i].tx_power_att = 0; |
Kalle Valo | dc52f0a | 2010-01-05 20:17:03 +0200 | [diff] [blame] | 447 | cmd->channels[i].channel = channels[i]->hw_value; |
Kalle Valo | 3a98c30 | 2010-01-05 20:16:51 +0200 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | cmd->params.ssid_len = ssid_len; |
| 451 | if (ssid) |
| 452 | memcpy(cmd->params.ssid, ssid, ssid_len); |
| 453 | |
| 454 | ret = wl1251_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd)); |
| 455 | if (ret < 0) { |
| 456 | wl1251_error("cmd scan failed: %d", ret); |
| 457 | goto out; |
| 458 | } |
| 459 | |
| 460 | wl1251_mem_read(wl, wl->cmd_box_addr, cmd, sizeof(*cmd)); |
| 461 | |
| 462 | if (cmd->header.status != CMD_STATUS_SUCCESS) { |
| 463 | wl1251_error("cmd scan status wasn't success: %d", |
| 464 | cmd->header.status); |
| 465 | ret = -EIO; |
| 466 | goto out; |
| 467 | } |
| 468 | |
| 469 | out: |
| 470 | kfree(cmd); |
| 471 | return ret; |
| 472 | } |
| 473 | |
| 474 | int wl1251_cmd_trigger_scan_to(struct wl1251 *wl, u32 timeout) |
| 475 | { |
| 476 | struct wl1251_cmd_trigger_scan_to *cmd; |
| 477 | int ret; |
| 478 | |
| 479 | wl1251_debug(DEBUG_CMD, "cmd trigger scan to"); |
| 480 | |
| 481 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 482 | if (!cmd) |
| 483 | return -ENOMEM; |
| 484 | |
| 485 | cmd->timeout = timeout; |
| 486 | |
Yuri Kululin | fe0dbcc | 2010-08-13 13:46:12 +0400 | [diff] [blame] | 487 | ret = wl1251_cmd_send(wl, CMD_TRIGGER_SCAN_TO, cmd, sizeof(*cmd)); |
Kalle Valo | 3a98c30 | 2010-01-05 20:16:51 +0200 | [diff] [blame] | 488 | if (ret < 0) { |
| 489 | wl1251_error("cmd trigger scan to failed: %d", ret); |
| 490 | goto out; |
| 491 | } |
| 492 | |
| 493 | out: |
| 494 | kfree(cmd); |
| 495 | return ret; |
| 496 | } |