Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
Luciano Coelho | 2f826f5 | 2010-03-26 12:53:21 +0200 | [diff] [blame] | 4 | * Copyright (C) 2009-2010 Nokia Corporation |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
| 25 | #include <linux/platform_device.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 26 | #include <linux/spi/spi.h> |
| 27 | #include <linux/etherdevice.h> |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 28 | #include <linux/ieee80211.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 29 | #include <linux/slab.h> |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 30 | |
Luciano Coelho | c31be25 | 2011-11-21 19:25:24 +0200 | [diff] [blame] | 31 | #include "wlcore.h" |
Luciano Coelho | 0f4e312 | 2011-10-07 11:02:42 +0300 | [diff] [blame] | 32 | #include "debug.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 33 | #include "io.h" |
| 34 | #include "acx.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 35 | #include "wl12xx_80211.h" |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 36 | #include "cmd.h" |
| 37 | #include "event.h" |
Tony Lindgren | afeeecc | 2018-06-19 02:43:35 -0700 | [diff] [blame] | 38 | #include "ps.h" |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 39 | #include "tx.h" |
Luciano Coelho | 60462b4 | 2012-05-10 12:14:14 +0300 | [diff] [blame] | 40 | #include "hw_ops.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 41 | |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 42 | #define WL1271_CMD_FAST_POLL_COUNT 50 |
Yoni Divinsky | c45ee4f | 2012-06-27 21:35:47 +0300 | [diff] [blame] | 43 | #define WL1271_WAIT_EVENT_FAST_POLL_COUNT 20 |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * send command to firmware |
| 47 | * |
| 48 | * @wl: wl struct |
| 49 | * @id: command id |
| 50 | * @buf: buffer containing the command, must work with dma |
| 51 | * @len: length of the buffer |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 52 | * return the cmd status code on success. |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 53 | */ |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 54 | static int __wlcore_cmd_send(struct wl1271 *wl, u16 id, void *buf, |
| 55 | size_t len, size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 56 | { |
| 57 | struct wl1271_cmd_header *cmd; |
| 58 | unsigned long timeout; |
| 59 | u32 intr; |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 60 | int ret; |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 61 | u16 status; |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 62 | u16 poll_count = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 63 | |
Arik Nemtsov | 1ede950 | 2014-02-10 13:47:31 +0200 | [diff] [blame] | 64 | if (unlikely(wl->state == WLCORE_STATE_RESTARTING && |
| 65 | id != CMD_STOP_FWLOGGER)) |
Ido Yariv | 4cc5338 | 2012-07-24 19:18:49 +0300 | [diff] [blame] | 66 | return -EIO; |
| 67 | |
Luciano Coelho | f5b8f47 | 2014-11-10 09:25:17 +0200 | [diff] [blame] | 68 | if (WARN_ON_ONCE(len < sizeof(*cmd))) |
| 69 | return -EIO; |
| 70 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 71 | cmd = buf; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 72 | cmd->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 73 | cmd->status = 0; |
| 74 | |
| 75 | WARN_ON(len % 4 != 0); |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 76 | WARN_ON(test_bit(WL1271_FLAG_IN_ELP, &wl->flags)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 77 | |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 78 | ret = wlcore_write(wl, wl->cmd_box_addr, buf, len, false); |
| 79 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 80 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 81 | |
Luciano Coelho | f16ff75 | 2012-04-11 10:15:46 +0300 | [diff] [blame] | 82 | /* |
| 83 | * TODO: we just need this because one bit is in a different |
| 84 | * place. Is there any better way? |
| 85 | */ |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 86 | ret = wl->ops->trigger_cmd(wl, wl->cmd_box_addr, buf, len); |
| 87 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 88 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 89 | |
| 90 | timeout = jiffies + msecs_to_jiffies(WL1271_COMMAND_TIMEOUT); |
| 91 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 92 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); |
| 93 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 94 | return ret; |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 95 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 96 | while (!(intr & WL1271_ACX_INTR_CMD_COMPLETE)) { |
| 97 | if (time_after(jiffies, timeout)) { |
| 98 | wl1271_error("command complete timeout"); |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 99 | return -ETIMEDOUT; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 100 | } |
| 101 | |
Saravanan Dhanabal | bc0f03e | 2010-03-26 12:53:33 +0200 | [diff] [blame] | 102 | poll_count++; |
Juuso Oikarinen | 16092b5 | 2010-04-28 09:49:59 +0300 | [diff] [blame] | 103 | if (poll_count < WL1271_CMD_FAST_POLL_COUNT) |
| 104 | udelay(10); |
| 105 | else |
| 106 | msleep(1); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 107 | |
Ido Yariv | 6134323 | 2012-06-18 15:50:21 +0300 | [diff] [blame] | 108 | ret = wlcore_read_reg(wl, REG_INTERRUPT_NO_CLEAR, &intr); |
| 109 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 110 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 111 | } |
| 112 | |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 113 | /* read back the status code of the command */ |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 114 | if (res_len == 0) |
| 115 | res_len = sizeof(struct wl1271_cmd_header); |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 116 | |
| 117 | ret = wlcore_read(wl, wl->cmd_box_addr, cmd, res_len, false); |
| 118 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 119 | return ret; |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 120 | |
Juuso Oikarinen | ad150e9 | 2009-11-02 20:22:12 +0200 | [diff] [blame] | 121 | status = le16_to_cpu(cmd->status); |
Juuso Oikarinen | 3b775b4 | 2009-11-02 20:22:10 +0200 | [diff] [blame] | 122 | |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 123 | ret = wlcore_write_reg(wl, REG_INTERRUPT_ACK, |
| 124 | WL1271_ACX_INTR_CMD_COMPLETE); |
| 125 | if (ret < 0) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 126 | return ret; |
| 127 | |
| 128 | return status; |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * send command to fw and return cmd status on success |
| 133 | * valid_rets contains a bitmap of allowed error codes |
| 134 | */ |
Luciano Coelho | d351f5f | 2014-11-10 09:25:57 +0200 | [diff] [blame] | 135 | static int wlcore_cmd_send_failsafe(struct wl1271 *wl, u16 id, void *buf, |
| 136 | size_t len, size_t res_len, |
| 137 | unsigned long valid_rets) |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 138 | { |
| 139 | int ret = __wlcore_cmd_send(wl, id, buf, len, res_len); |
| 140 | |
| 141 | if (ret < 0) |
Ido Yariv | b0f0ad3 | 2012-06-20 00:48:23 +0300 | [diff] [blame] | 142 | goto fail; |
| 143 | |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 144 | /* success is always a valid status */ |
| 145 | valid_rets |= BIT(CMD_STATUS_SUCCESS); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 146 | |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 147 | if (ret >= MAX_COMMAND_STATUS || |
| 148 | !test_bit(ret, &valid_rets)) { |
| 149 | wl1271_error("command execute failure %d", ret); |
| 150 | ret = -EIO; |
| 151 | goto fail; |
| 152 | } |
| 153 | return ret; |
Arik Nemtsov | f482b76 | 2011-04-18 14:15:23 +0300 | [diff] [blame] | 154 | fail: |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 155 | wl12xx_queue_recovery_work(wl); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 156 | return ret; |
| 157 | } |
| 158 | |
Luciano Coelho | 99d84c1 | 2010-03-26 12:53:20 +0200 | [diff] [blame] | 159 | /* |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 160 | * wrapper for wlcore_cmd_send that accept only CMD_STATUS_SUCCESS |
| 161 | * return 0 on success. |
| 162 | */ |
| 163 | int wl1271_cmd_send(struct wl1271 *wl, u16 id, void *buf, size_t len, |
| 164 | size_t res_len) |
| 165 | { |
| 166 | int ret = wlcore_cmd_send_failsafe(wl, id, buf, len, res_len, 0); |
| 167 | |
| 168 | if (ret < 0) |
| 169 | return ret; |
| 170 | return 0; |
| 171 | } |
Luciano Coelho | d351f5f | 2014-11-10 09:25:57 +0200 | [diff] [blame] | 172 | EXPORT_SYMBOL_GPL(wl1271_cmd_send); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 173 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 174 | /* |
| 175 | * Poll the mailbox event field until any of the bits in the mask is set or a |
| 176 | * timeout occurs (WL1271_EVENT_TIMEOUT in msecs) |
| 177 | */ |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 178 | int wlcore_cmd_wait_for_event_or_timeout(struct wl1271 *wl, |
| 179 | u32 mask, bool *timeout) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 180 | { |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 181 | u32 *events_vector; |
| 182 | u32 event; |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 183 | unsigned long timeout_time; |
Yoni Divinsky | c45ee4f | 2012-06-27 21:35:47 +0300 | [diff] [blame] | 184 | u16 poll_count = 0; |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 185 | int ret = 0; |
| 186 | |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 187 | *timeout = false; |
| 188 | |
Dan Carpenter | 0230dfe | 2012-04-17 09:28:47 +0300 | [diff] [blame] | 189 | events_vector = kmalloc(sizeof(*events_vector), GFP_KERNEL | GFP_DMA); |
| 190 | if (!events_vector) |
| 191 | return -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 192 | |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 193 | timeout_time = jiffies + msecs_to_jiffies(WL1271_EVENT_TIMEOUT); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 194 | |
Tony Lindgren | afeeecc | 2018-06-19 02:43:35 -0700 | [diff] [blame] | 195 | ret = wl1271_ps_elp_wakeup(wl); |
| 196 | if (ret < 0) |
| 197 | return ret; |
| 198 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 199 | do { |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 200 | if (time_after(jiffies, timeout_time)) { |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 201 | wl1271_debug(DEBUG_CMD, "timeout waiting for event %d", |
| 202 | (int)mask); |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 203 | *timeout = true; |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 204 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 205 | } |
| 206 | |
Yoni Divinsky | c45ee4f | 2012-06-27 21:35:47 +0300 | [diff] [blame] | 207 | poll_count++; |
| 208 | if (poll_count < WL1271_WAIT_EVENT_FAST_POLL_COUNT) |
| 209 | usleep_range(50, 51); |
| 210 | else |
| 211 | usleep_range(1000, 5000); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 212 | |
| 213 | /* read from both event fields */ |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 214 | ret = wlcore_read(wl, wl->mbox_ptr[0], events_vector, |
| 215 | sizeof(*events_vector), false); |
| 216 | if (ret < 0) |
| 217 | goto out; |
| 218 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 219 | event = *events_vector & mask; |
Ido Yariv | 045b9b5 | 2012-06-18 12:31:16 +0300 | [diff] [blame] | 220 | |
| 221 | ret = wlcore_read(wl, wl->mbox_ptr[1], events_vector, |
| 222 | sizeof(*events_vector), false); |
| 223 | if (ret < 0) |
| 224 | goto out; |
| 225 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 226 | event |= *events_vector & mask; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 227 | } while (!event); |
| 228 | |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 229 | out: |
Tony Lindgren | afeeecc | 2018-06-19 02:43:35 -0700 | [diff] [blame] | 230 | wl1271_ps_elp_sleep(wl); |
Mircea Gherzan | 690142e | 2012-03-17 18:41:53 +0100 | [diff] [blame] | 231 | kfree(events_vector); |
| 232 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 233 | } |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 234 | EXPORT_SYMBOL_GPL(wlcore_cmd_wait_for_event_or_timeout); |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 235 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 236 | int wl12xx_cmd_role_enable(struct wl1271 *wl, u8 *addr, u8 role_type, |
| 237 | u8 *role_id) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 238 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 239 | struct wl12xx_cmd_role_enable *cmd; |
| 240 | int ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 241 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 242 | wl1271_debug(DEBUG_CMD, "cmd role enable"); |
| 243 | |
| 244 | if (WARN_ON(*role_id != WL12XX_INVALID_ROLE_ID)) |
| 245 | return -EBUSY; |
| 246 | |
| 247 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 248 | if (!cmd) { |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 249 | ret = -ENOMEM; |
| 250 | goto out; |
| 251 | } |
| 252 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 253 | /* get role id */ |
| 254 | cmd->role_id = find_first_zero_bit(wl->roles_map, WL12XX_MAX_ROLES); |
| 255 | if (cmd->role_id >= WL12XX_MAX_ROLES) { |
| 256 | ret = -EBUSY; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 257 | goto out_free; |
| 258 | } |
| 259 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 260 | memcpy(cmd->mac_address, addr, ETH_ALEN); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 261 | cmd->role_type = role_type; |
| 262 | |
| 263 | ret = wl1271_cmd_send(wl, CMD_ROLE_ENABLE, cmd, sizeof(*cmd), 0); |
| 264 | if (ret < 0) { |
| 265 | wl1271_error("failed to initiate cmd role enable"); |
| 266 | goto out_free; |
| 267 | } |
| 268 | |
| 269 | __set_bit(cmd->role_id, wl->roles_map); |
| 270 | *role_id = cmd->role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 271 | |
| 272 | out_free: |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 273 | kfree(cmd); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 274 | |
| 275 | out: |
| 276 | return ret; |
| 277 | } |
| 278 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 279 | int wl12xx_cmd_role_disable(struct wl1271 *wl, u8 *role_id) |
| 280 | { |
| 281 | struct wl12xx_cmd_role_disable *cmd; |
| 282 | int ret; |
| 283 | |
| 284 | wl1271_debug(DEBUG_CMD, "cmd role disable"); |
| 285 | |
| 286 | if (WARN_ON(*role_id == WL12XX_INVALID_ROLE_ID)) |
| 287 | return -ENOENT; |
| 288 | |
| 289 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 290 | if (!cmd) { |
| 291 | ret = -ENOMEM; |
| 292 | goto out; |
| 293 | } |
| 294 | cmd->role_id = *role_id; |
| 295 | |
| 296 | ret = wl1271_cmd_send(wl, CMD_ROLE_DISABLE, cmd, sizeof(*cmd), 0); |
| 297 | if (ret < 0) { |
| 298 | wl1271_error("failed to initiate cmd role disable"); |
| 299 | goto out_free; |
| 300 | } |
| 301 | |
| 302 | __clear_bit(*role_id, wl->roles_map); |
| 303 | *role_id = WL12XX_INVALID_ROLE_ID; |
| 304 | |
| 305 | out_free: |
| 306 | kfree(cmd); |
| 307 | |
| 308 | out: |
| 309 | return ret; |
| 310 | } |
| 311 | |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 312 | static int wlcore_get_new_session_id(struct wl1271 *wl, u8 hlid) |
| 313 | { |
| 314 | if (wl->session_ids[hlid] >= SESSION_COUNTER_MAX) |
| 315 | wl->session_ids[hlid] = 0; |
| 316 | |
| 317 | wl->session_ids[hlid]++; |
| 318 | |
| 319 | return wl->session_ids[hlid]; |
| 320 | } |
| 321 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 322 | int wl12xx_allocate_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 323 | { |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 324 | unsigned long flags; |
Eliad Peller | da08fdf | 2014-02-10 13:47:22 +0200 | [diff] [blame] | 325 | u8 link = find_first_zero_bit(wl->links_map, wl->num_links); |
| 326 | if (link >= wl->num_links) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 327 | return -EBUSY; |
| 328 | |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 329 | wl->session_ids[link] = wlcore_get_new_session_id(wl, link); |
| 330 | |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 331 | /* these bits are used by op_tx */ |
| 332 | spin_lock_irqsave(&wl->wl_lock, flags); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 333 | __set_bit(link, wl->links_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 334 | __set_bit(link, wlvif->links_map); |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 335 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Arik Nemtsov | b50a62b | 2012-11-27 08:44:56 +0200 | [diff] [blame] | 336 | |
Eliad Peller | 75fb4df | 2014-02-10 13:47:21 +0200 | [diff] [blame] | 337 | /* |
| 338 | * take the last "freed packets" value from the current FW status. |
| 339 | * on recovery, we might not have fw_status yet, and |
| 340 | * tx_lnk_free_pkts will be NULL. check for it. |
| 341 | */ |
| 342 | if (wl->fw_status->counters.tx_lnk_free_pkts) |
| 343 | wl->links[link].prev_freed_pkts = |
| 344 | wl->fw_status->counters.tx_lnk_free_pkts[link]; |
Arik Nemtsov | 1e0708a | 2012-11-27 08:44:57 +0200 | [diff] [blame] | 345 | wl->links[link].wlvif = wlvif; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 346 | |
| 347 | /* |
| 348 | * Take saved value for total freed packets from wlvif, in case this is |
| 349 | * recovery/resume |
| 350 | */ |
| 351 | if (wlvif->bss_type != BSS_TYPE_AP_BSS) |
| 352 | wl->links[link].total_freed_pkts = wlvif->total_freed_pkts; |
| 353 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 354 | *hlid = link; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 355 | |
| 356 | wl->active_link_count++; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 360 | void wl12xx_free_link(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 *hlid) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 361 | { |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 362 | unsigned long flags; |
| 363 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 364 | if (*hlid == WL12XX_INVALID_LINK_ID) |
| 365 | return; |
| 366 | |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 367 | /* these bits are used by op_tx */ |
| 368 | spin_lock_irqsave(&wl->wl_lock, flags); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 369 | __clear_bit(*hlid, wl->links_map); |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 370 | __clear_bit(*hlid, wlvif->links_map); |
Arik Nemtsov | 0b0e32b | 2012-02-28 00:41:29 +0200 | [diff] [blame] | 371 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
Arik Nemtsov | 6246ca0 | 2012-02-28 00:41:30 +0200 | [diff] [blame] | 372 | |
Arik Nemtsov | 6c4c453 | 2012-11-27 08:44:54 +0200 | [diff] [blame] | 373 | wl->links[*hlid].allocated_pkts = 0; |
| 374 | wl->links[*hlid].prev_freed_pkts = 0; |
| 375 | wl->links[*hlid].ba_bitmap = 0; |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 376 | eth_zero_addr(wl->links[*hlid].addr); |
Arik Nemtsov | 6c4c453 | 2012-11-27 08:44:54 +0200 | [diff] [blame] | 377 | |
Arik Nemtsov | 6246ca0 | 2012-02-28 00:41:30 +0200 | [diff] [blame] | 378 | /* |
| 379 | * At this point op_tx() will not add more packets to the queues. We |
| 380 | * can purge them. |
| 381 | */ |
| 382 | wl1271_tx_reset_link_queues(wl, *hlid); |
Arik Nemtsov | 1e0708a | 2012-11-27 08:44:57 +0200 | [diff] [blame] | 383 | wl->links[*hlid].wlvif = NULL; |
Arik Nemtsov | 6246ca0 | 2012-02-28 00:41:30 +0200 | [diff] [blame] | 384 | |
Eliad Peller | 50d26aa | 2014-07-11 03:01:26 +0300 | [diff] [blame] | 385 | if (wlvif->bss_type == BSS_TYPE_AP_BSS && |
| 386 | *hlid == wlvif->ap.bcast_hlid) { |
Eliad Peller | 30a0035 | 2014-07-11 03:01:27 +0300 | [diff] [blame] | 387 | u32 sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 388 | /* |
| 389 | * save the total freed packets in the wlvif, in case this is |
| 390 | * recovery or suspend |
| 391 | */ |
| 392 | wlvif->total_freed_pkts = wl->links[*hlid].total_freed_pkts; |
| 393 | |
| 394 | /* |
| 395 | * increment the initial seq number on recovery to account for |
| 396 | * transmitted packets that we haven't yet got in the FW status |
| 397 | */ |
Eliad Peller | 30a0035 | 2014-07-11 03:01:27 +0300 | [diff] [blame] | 398 | if (wlvif->encryption_type == KEY_GEM) |
| 399 | sqn_padding = WL1271_TX_SQN_POST_RECOVERY_PADDING_GEM; |
| 400 | |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 401 | if (test_bit(WL1271_FLAG_RECOVERY_IN_PROGRESS, &wl->flags)) |
Eliad Peller | 30a0035 | 2014-07-11 03:01:27 +0300 | [diff] [blame] | 402 | wlvif->total_freed_pkts += sqn_padding; |
Arik Nemtsov | 93d5d10 | 2013-03-12 17:19:38 +0200 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | wl->links[*hlid].total_freed_pkts = 0; |
| 406 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 407 | *hlid = WL12XX_INVALID_LINK_ID; |
Arik Nemtsov | 9a10096 | 2012-11-28 11:42:42 +0200 | [diff] [blame] | 408 | wl->active_link_count--; |
| 409 | WARN_ON_ONCE(wl->active_link_count < 0); |
Arik Nemtsov | 712e9bf | 2011-08-14 13:17:20 +0300 | [diff] [blame] | 410 | } |
| 411 | |
Eliad Peller | 750e9d1 | 2014-12-29 08:24:07 +0200 | [diff] [blame] | 412 | u8 wlcore_get_native_channel_type(u8 nl_channel_type) |
Arik Nemtsov | a6298db | 2012-05-10 12:13:31 +0300 | [diff] [blame] | 413 | { |
| 414 | switch (nl_channel_type) { |
| 415 | case NL80211_CHAN_NO_HT: |
| 416 | return WLCORE_CHAN_NO_HT; |
| 417 | case NL80211_CHAN_HT20: |
| 418 | return WLCORE_CHAN_HT20; |
| 419 | case NL80211_CHAN_HT40MINUS: |
| 420 | return WLCORE_CHAN_HT40MINUS; |
| 421 | case NL80211_CHAN_HT40PLUS: |
| 422 | return WLCORE_CHAN_HT40PLUS; |
| 423 | default: |
| 424 | WARN_ON(1); |
| 425 | return WLCORE_CHAN_NO_HT; |
| 426 | } |
| 427 | } |
Eliad Peller | 750e9d1 | 2014-12-29 08:24:07 +0200 | [diff] [blame] | 428 | EXPORT_SYMBOL_GPL(wlcore_get_native_channel_type); |
Arik Nemtsov | a6298db | 2012-05-10 12:13:31 +0300 | [diff] [blame] | 429 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 430 | static int wl12xx_cmd_role_start_dev(struct wl1271 *wl, |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 431 | struct wl12xx_vif *wlvif, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 432 | enum nl80211_band band, |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 433 | int channel) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 434 | { |
| 435 | struct wl12xx_cmd_role_start *cmd; |
| 436 | int ret; |
| 437 | |
| 438 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 439 | if (!cmd) { |
| 440 | ret = -ENOMEM; |
| 441 | goto out; |
| 442 | } |
| 443 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 444 | wl1271_debug(DEBUG_CMD, "cmd role start dev %d", wlvif->dev_role_id); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 445 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 446 | cmd->role_id = wlvif->dev_role_id; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 447 | if (band == NL80211_BAND_5GHZ) |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 448 | cmd->band = WLCORE_BAND_5GHZ; |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 449 | cmd->channel = channel; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 450 | |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 451 | if (wlvif->dev_hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 452 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 453 | if (ret) |
| 454 | goto out_free; |
| 455 | } |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 456 | cmd->device.hlid = wlvif->dev_hlid; |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 457 | cmd->device.session = wl->session_ids[wlvif->dev_hlid]; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 458 | |
| 459 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d", |
| 460 | cmd->role_id, cmd->device.hlid, cmd->device.session); |
| 461 | |
| 462 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 463 | if (ret < 0) { |
| 464 | wl1271_error("failed to initiate cmd role enable"); |
| 465 | goto err_hlid; |
| 466 | } |
| 467 | |
| 468 | goto out_free; |
| 469 | |
| 470 | err_hlid: |
| 471 | /* clear links on error */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 472 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 473 | |
| 474 | out_free: |
| 475 | kfree(cmd); |
| 476 | |
| 477 | out: |
| 478 | return ret; |
| 479 | } |
| 480 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 481 | static int wl12xx_cmd_role_stop_dev(struct wl1271 *wl, |
| 482 | struct wl12xx_vif *wlvif) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 483 | { |
| 484 | struct wl12xx_cmd_role_stop *cmd; |
| 485 | int ret; |
| 486 | |
Eliad Peller | afaf8bd | 2011-10-05 11:55:57 +0200 | [diff] [blame] | 487 | if (WARN_ON(wlvif->dev_hlid == WL12XX_INVALID_LINK_ID)) |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 488 | return -EINVAL; |
| 489 | |
| 490 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 491 | if (!cmd) { |
| 492 | ret = -ENOMEM; |
| 493 | goto out; |
| 494 | } |
| 495 | |
| 496 | wl1271_debug(DEBUG_CMD, "cmd role stop dev"); |
| 497 | |
Eliad Peller | 7edebf5 | 2011-10-05 11:55:52 +0200 | [diff] [blame] | 498 | cmd->role_id = wlvif->dev_role_id; |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 499 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
| 500 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); |
| 501 | |
| 502 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 503 | if (ret < 0) { |
| 504 | wl1271_error("failed to initiate cmd role stop"); |
| 505 | goto out_free; |
| 506 | } |
| 507 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 508 | wl12xx_free_link(wl, wlvif, &wlvif->dev_hlid); |
Eliad Peller | 04e8079 | 2011-08-14 13:17:09 +0300 | [diff] [blame] | 509 | |
| 510 | out_free: |
| 511 | kfree(cmd); |
| 512 | |
| 513 | out: |
| 514 | return ret; |
| 515 | } |
| 516 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 517 | int wl12xx_cmd_role_start_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 518 | { |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 519 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 520 | struct wl12xx_cmd_role_start *cmd; |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 521 | u32 supported_rates; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 522 | int ret; |
| 523 | |
| 524 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 525 | if (!cmd) { |
| 526 | ret = -ENOMEM; |
| 527 | goto out; |
| 528 | } |
| 529 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 530 | wl1271_debug(DEBUG_CMD, "cmd role start sta %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 531 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 532 | cmd->role_id = wlvif->role_id; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 533 | if (wlvif->band == NL80211_BAND_5GHZ) |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 534 | cmd->band = WLCORE_BAND_5GHZ; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 535 | cmd->channel = wlvif->channel; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 536 | cmd->sta.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 537 | cmd->sta.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 538 | cmd->sta.ssid_type = WL12XX_SSID_TYPE_ANY; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 539 | cmd->sta.ssid_len = wlvif->ssid_len; |
| 540 | memcpy(cmd->sta.ssid, wlvif->ssid, wlvif->ssid_len); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 541 | memcpy(cmd->sta.bssid, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 542 | |
| 543 | supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | |
| 544 | wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); |
| 545 | if (wlvif->p2p) |
| 546 | supported_rates &= ~CONF_TX_CCK_RATES; |
| 547 | |
| 548 | cmd->sta.local_rates = cpu_to_le32(supported_rates); |
| 549 | |
Arik Nemtsov | a6298db | 2012-05-10 12:13:31 +0300 | [diff] [blame] | 550 | cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 551 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 552 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 553 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 554 | if (ret) |
| 555 | goto out_free; |
| 556 | } |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 557 | cmd->sta.hlid = wlvif->sta.hlid; |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 558 | cmd->sta.session = wl->session_ids[wlvif->sta.hlid]; |
Eliad Peller | dc62a3d | 2012-11-20 13:20:11 +0200 | [diff] [blame] | 559 | /* |
Luciano Coelho | 9c3a8d9 | 2013-02-07 11:35:33 +0200 | [diff] [blame] | 560 | * We don't have the correct remote rates in this stage. The |
| 561 | * rates will be reconfigured later, after association, if the |
| 562 | * firmware supports ACX_PEER_CAP. Otherwise, there's nothing |
| 563 | * we can do, so use all supported_rates here. |
Eliad Peller | dc62a3d | 2012-11-20 13:20:11 +0200 | [diff] [blame] | 564 | */ |
Luciano Coelho | 9c3a8d9 | 2013-02-07 11:35:33 +0200 | [diff] [blame] | 565 | cmd->sta.remote_rates = cpu_to_le32(supported_rates); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 566 | |
| 567 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " |
| 568 | "basic_rate_set: 0x%x, remote_rates: 0x%x", |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 569 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 570 | wlvif->basic_rate_set, wlvif->rate_set); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 571 | |
| 572 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 573 | if (ret < 0) { |
| 574 | wl1271_error("failed to initiate cmd role start sta"); |
| 575 | goto err_hlid; |
| 576 | } |
| 577 | |
Arik Nemtsov | 5f9b677 | 2012-11-26 18:05:41 +0200 | [diff] [blame] | 578 | wlvif->sta.role_chan_type = wlvif->channel_type; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 579 | goto out_free; |
| 580 | |
| 581 | err_hlid: |
| 582 | /* clear links on error. */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 583 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 584 | |
| 585 | out_free: |
| 586 | kfree(cmd); |
| 587 | |
| 588 | out: |
| 589 | return ret; |
| 590 | } |
| 591 | |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 592 | /* use this function to stop ibss as well */ |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 593 | int wl12xx_cmd_role_stop_sta(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 594 | { |
| 595 | struct wl12xx_cmd_role_stop *cmd; |
| 596 | int ret; |
| 597 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 598 | if (WARN_ON(wlvif->sta.hlid == WL12XX_INVALID_LINK_ID)) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 599 | return -EINVAL; |
| 600 | |
| 601 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 602 | if (!cmd) { |
| 603 | ret = -ENOMEM; |
| 604 | goto out; |
| 605 | } |
| 606 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 607 | wl1271_debug(DEBUG_CMD, "cmd role stop sta %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 608 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 609 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 610 | cmd->disc_type = DISCONNECT_IMMEDIATE; |
| 611 | cmd->reason = cpu_to_le16(WLAN_REASON_UNSPECIFIED); |
| 612 | |
| 613 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 614 | if (ret < 0) { |
| 615 | wl1271_error("failed to initiate cmd role stop sta"); |
| 616 | goto out_free; |
| 617 | } |
| 618 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 619 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 620 | |
| 621 | out_free: |
| 622 | kfree(cmd); |
| 623 | |
| 624 | out: |
| 625 | return ret; |
| 626 | } |
| 627 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 628 | int wl12xx_cmd_role_start_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 629 | { |
| 630 | struct wl12xx_cmd_role_start *cmd; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 631 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
| 632 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Luciano Coelho | 60462b4 | 2012-05-10 12:14:14 +0300 | [diff] [blame] | 633 | u32 supported_rates; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 634 | int ret; |
| 635 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 636 | wl1271_debug(DEBUG_CMD, "cmd role start ap %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 637 | |
Maital Hahn | c0174ee | 2016-06-28 13:41:35 +0300 | [diff] [blame] | 638 | /* If MESH --> ssid_len is always 0 */ |
| 639 | if (!ieee80211_vif_is_mesh(vif)) { |
| 640 | /* trying to use hidden SSID with an old hostapd version */ |
| 641 | if (wlvif->ssid_len == 0 && !bss_conf->hidden_ssid) { |
| 642 | wl1271_error("got a null SSID from beacon/bss"); |
| 643 | ret = -EINVAL; |
| 644 | goto out; |
| 645 | } |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 649 | if (!cmd) { |
| 650 | ret = -ENOMEM; |
| 651 | goto out; |
| 652 | } |
| 653 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 654 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 655 | if (ret < 0) |
| 656 | goto out_free; |
| 657 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 658 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 659 | if (ret < 0) |
| 660 | goto out_free_global; |
| 661 | |
Arik Nemtsov | 0e752df | 2013-03-12 17:19:44 +0200 | [diff] [blame] | 662 | /* use the previous security seq, if this is a recovery/resume */ |
| 663 | wl->links[wlvif->ap.bcast_hlid].total_freed_pkts = |
| 664 | wlvif->total_freed_pkts; |
| 665 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 666 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 667 | cmd->ap.aging_period = cpu_to_le16(wl->conf.tx.ap_aging_period); |
| 668 | cmd->ap.bss_index = WL1271_AP_BSS_INDEX; |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 669 | cmd->ap.global_hlid = wlvif->ap.global_hlid; |
| 670 | cmd->ap.broadcast_hlid = wlvif->ap.bcast_hlid; |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 671 | cmd->ap.global_session_id = wl->session_ids[wlvif->ap.global_hlid]; |
| 672 | cmd->ap.bcast_session_id = wl->session_ids[wlvif->ap.bcast_hlid]; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 673 | cmd->ap.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 674 | cmd->ap.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 675 | cmd->ap.dtim_interval = bss_conf->dtim_period; |
| 676 | cmd->ap.beacon_expiry = WL1271_AP_DEF_BEACON_EXP; |
Eliad Peller | 8332f0f | 2012-01-31 11:57:19 +0200 | [diff] [blame] | 677 | /* FIXME: Change when adding DFS */ |
| 678 | cmd->ap.reset_tsf = 1; /* By default reset AP TSF */ |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 679 | cmd->ap.wmm = wlvif->wmm_enabled; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 680 | cmd->channel = wlvif->channel; |
Arik Nemtsov | a6298db | 2012-05-10 12:13:31 +0300 | [diff] [blame] | 681 | cmd->channel_type = wlcore_get_native_channel_type(wlvif->channel_type); |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 682 | |
| 683 | if (!bss_conf->hidden_ssid) { |
| 684 | /* take the SSID from the beacon for backward compatibility */ |
| 685 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_PUBLIC; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 686 | cmd->ap.ssid_len = wlvif->ssid_len; |
| 687 | memcpy(cmd->ap.ssid, wlvif->ssid, wlvif->ssid_len); |
Arik Nemtsov | 68eaaf6 | 2011-09-03 20:22:03 +0300 | [diff] [blame] | 688 | } else { |
| 689 | cmd->ap.ssid_type = WL12XX_SSID_TYPE_HIDDEN; |
| 690 | cmd->ap.ssid_len = bss_conf->ssid_len; |
| 691 | memcpy(cmd->ap.ssid, bss_conf->ssid, bss_conf->ssid_len); |
| 692 | } |
| 693 | |
Eliad Peller | 42ec1f8 | 2012-11-20 13:20:08 +0200 | [diff] [blame] | 694 | supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | |
Luciano Coelho | 60462b4 | 2012-05-10 12:14:14 +0300 | [diff] [blame] | 695 | wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif); |
Eliad Peller | 873d2a4 | 2012-11-26 18:05:46 +0200 | [diff] [blame] | 696 | if (wlvif->p2p) |
| 697 | supported_rates &= ~CONF_TX_CCK_RATES; |
Luciano Coelho | 60462b4 | 2012-05-10 12:14:14 +0300 | [diff] [blame] | 698 | |
| 699 | wl1271_debug(DEBUG_CMD, "cmd role start ap with supported_rates 0x%08x", |
| 700 | supported_rates); |
| 701 | |
| 702 | cmd->ap.local_rates = cpu_to_le32(supported_rates); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 703 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 704 | switch (wlvif->band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 705 | case NL80211_BAND_2GHZ: |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 706 | cmd->band = WLCORE_BAND_2_4GHZ; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 707 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 708 | case NL80211_BAND_5GHZ: |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 709 | cmd->band = WLCORE_BAND_5GHZ; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 710 | break; |
| 711 | default: |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 712 | wl1271_warning("ap start - unknown band: %d", (int)wlvif->band); |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 713 | cmd->band = WLCORE_BAND_2_4GHZ; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 714 | break; |
| 715 | } |
| 716 | |
| 717 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 718 | if (ret < 0) { |
| 719 | wl1271_error("failed to initiate cmd role start ap"); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 720 | goto out_free_bcast; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 721 | } |
| 722 | |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 723 | goto out_free; |
| 724 | |
| 725 | out_free_bcast: |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 726 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 727 | |
| 728 | out_free_global: |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 729 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 730 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 731 | out_free: |
| 732 | kfree(cmd); |
| 733 | |
| 734 | out: |
| 735 | return ret; |
| 736 | } |
| 737 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 738 | int wl12xx_cmd_role_stop_ap(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 739 | { |
| 740 | struct wl12xx_cmd_role_stop *cmd; |
| 741 | int ret; |
| 742 | |
| 743 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 744 | if (!cmd) { |
| 745 | ret = -ENOMEM; |
| 746 | goto out; |
| 747 | } |
| 748 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 749 | wl1271_debug(DEBUG_CMD, "cmd role stop ap %d", wlvif->role_id); |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 750 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 751 | cmd->role_id = wlvif->role_id; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 752 | |
| 753 | ret = wl1271_cmd_send(wl, CMD_ROLE_STOP, cmd, sizeof(*cmd), 0); |
| 754 | if (ret < 0) { |
| 755 | wl1271_error("failed to initiate cmd role stop ap"); |
| 756 | goto out_free; |
| 757 | } |
| 758 | |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 759 | wl12xx_free_link(wl, wlvif, &wlvif->ap.bcast_hlid); |
| 760 | wl12xx_free_link(wl, wlvif, &wlvif->ap.global_hlid); |
Arik Nemtsov | e51ae9b | 2011-08-14 13:17:21 +0300 | [diff] [blame] | 761 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 762 | out_free: |
| 763 | kfree(cmd); |
| 764 | |
| 765 | out: |
| 766 | return ret; |
| 767 | } |
| 768 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 769 | int wl12xx_cmd_role_start_ibss(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 770 | { |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 771 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 772 | struct wl12xx_cmd_role_start *cmd; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 773 | struct ieee80211_bss_conf *bss_conf = &vif->bss_conf; |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 774 | int ret; |
| 775 | |
| 776 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 777 | if (!cmd) { |
| 778 | ret = -ENOMEM; |
| 779 | goto out; |
| 780 | } |
| 781 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 782 | wl1271_debug(DEBUG_CMD, "cmd role start ibss %d", wlvif->role_id); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 783 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 784 | cmd->role_id = wlvif->role_id; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 785 | if (wlvif->band == NL80211_BAND_5GHZ) |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 786 | cmd->band = WLCORE_BAND_5GHZ; |
Eliad Peller | 61f845f | 2011-10-10 10:13:10 +0200 | [diff] [blame] | 787 | cmd->channel = wlvif->channel; |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 788 | cmd->ibss.basic_rate_set = cpu_to_le32(wlvif->basic_rate_set); |
Eliad Peller | 6a89979 | 2011-10-05 11:55:58 +0200 | [diff] [blame] | 789 | cmd->ibss.beacon_interval = cpu_to_le16(wlvif->beacon_int); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 790 | cmd->ibss.dtim_interval = bss_conf->dtim_period; |
| 791 | cmd->ibss.ssid_type = WL12XX_SSID_TYPE_ANY; |
Eliad Peller | 1fe9f16 | 2011-10-05 11:55:48 +0200 | [diff] [blame] | 792 | cmd->ibss.ssid_len = wlvif->ssid_len; |
| 793 | memcpy(cmd->ibss.ssid, wlvif->ssid, wlvif->ssid_len); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 794 | memcpy(cmd->ibss.bssid, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 795 | cmd->sta.local_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 796 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 797 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) { |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 798 | ret = wl12xx_allocate_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 799 | if (ret) |
| 800 | goto out_free; |
| 801 | } |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 802 | cmd->ibss.hlid = wlvif->sta.hlid; |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 803 | cmd->ibss.remote_rates = cpu_to_le32(wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 804 | |
| 805 | wl1271_debug(DEBUG_CMD, "role start: roleid=%d, hlid=%d, session=%d " |
| 806 | "basic_rate_set: 0x%x, remote_rates: 0x%x", |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 807 | wlvif->role_id, cmd->sta.hlid, cmd->sta.session, |
Eliad Peller | 30d0c8f | 2011-10-05 11:55:42 +0200 | [diff] [blame] | 808 | wlvif->basic_rate_set, wlvif->rate_set); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 809 | |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 810 | wl1271_debug(DEBUG_CMD, "vif->bss_conf.bssid = %pM", |
| 811 | vif->bss_conf.bssid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 812 | |
| 813 | ret = wl1271_cmd_send(wl, CMD_ROLE_START, cmd, sizeof(*cmd), 0); |
| 814 | if (ret < 0) { |
| 815 | wl1271_error("failed to initiate cmd role enable"); |
| 816 | goto err_hlid; |
| 817 | } |
| 818 | |
| 819 | goto out_free; |
| 820 | |
| 821 | err_hlid: |
| 822 | /* clear links on error. */ |
Eliad Peller | c7ffb90 | 2011-10-05 11:56:05 +0200 | [diff] [blame] | 823 | wl12xx_free_link(wl, wlvif, &wlvif->sta.hlid); |
Eliad Peller | 31cd3ae | 2011-08-14 13:17:25 +0300 | [diff] [blame] | 824 | |
| 825 | out_free: |
| 826 | kfree(cmd); |
| 827 | |
| 828 | out: |
| 829 | return ret; |
| 830 | } |
| 831 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 832 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 833 | /** |
| 834 | * send test command to firmware |
| 835 | * |
| 836 | * @wl: wl struct |
| 837 | * @buf: buffer containing the command, with all headers, must work with dma |
| 838 | * @len: length of the buffer |
| 839 | * @answer: is answer needed |
| 840 | */ |
| 841 | int wl1271_cmd_test(struct wl1271 *wl, void *buf, size_t buf_len, u8 answer) |
| 842 | { |
| 843 | int ret; |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 844 | size_t res_len = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 845 | |
| 846 | wl1271_debug(DEBUG_CMD, "cmd test"); |
| 847 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 848 | if (answer) |
| 849 | res_len = buf_len; |
| 850 | |
| 851 | ret = wl1271_cmd_send(wl, CMD_TEST, buf, buf_len, res_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 852 | |
| 853 | if (ret < 0) { |
| 854 | wl1271_warning("TEST command failed"); |
| 855 | return ret; |
| 856 | } |
| 857 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 858 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 859 | } |
Luciano Coelho | 9d68d1e | 2011-12-02 00:47:45 +0200 | [diff] [blame] | 860 | EXPORT_SYMBOL_GPL(wl1271_cmd_test); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 861 | |
| 862 | /** |
| 863 | * read acx from firmware |
| 864 | * |
| 865 | * @wl: wl struct |
| 866 | * @id: acx id |
| 867 | * @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] | 868 | * @len: length of buf |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 869 | */ |
Igal Chernobelsky | 4b67414 | 2013-09-09 12:24:35 +0300 | [diff] [blame] | 870 | int wl1271_cmd_interrogate(struct wl1271 *wl, u16 id, void *buf, |
| 871 | size_t cmd_len, size_t res_len) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 872 | { |
| 873 | struct acx_header *acx = buf; |
| 874 | int ret; |
| 875 | |
| 876 | wl1271_debug(DEBUG_CMD, "cmd interrogate"); |
| 877 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 878 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 879 | |
Igal Chernobelsky | 4b67414 | 2013-09-09 12:24:35 +0300 | [diff] [blame] | 880 | /* response payload length, does not include any headers */ |
| 881 | acx->len = cpu_to_le16(res_len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 882 | |
Igal Chernobelsky | 4b67414 | 2013-09-09 12:24:35 +0300 | [diff] [blame] | 883 | ret = wl1271_cmd_send(wl, CMD_INTERROGATE, acx, cmd_len, res_len); |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 884 | if (ret < 0) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 885 | wl1271_error("INTERROGATE command failed"); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 886 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 887 | return ret; |
| 888 | } |
| 889 | |
| 890 | /** |
| 891 | * write acx value to firmware |
| 892 | * |
| 893 | * @wl: wl struct |
| 894 | * @id: acx id |
| 895 | * @buf: buffer containing acx, including all headers, must work with dma |
| 896 | * @len: length of buf |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 897 | * @valid_rets: bitmap of valid cmd status codes (i.e. return values). |
| 898 | * return the cmd status on success. |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 899 | */ |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 900 | int wlcore_cmd_configure_failsafe(struct wl1271 *wl, u16 id, void *buf, |
| 901 | size_t len, unsigned long valid_rets) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 902 | { |
| 903 | struct acx_header *acx = buf; |
| 904 | int ret; |
| 905 | |
Eliad Peller | c91d060 | 2011-08-25 18:10:57 +0300 | [diff] [blame] | 906 | wl1271_debug(DEBUG_CMD, "cmd configure (%d)", id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 907 | |
Luciano Coelho | f5b8f47 | 2014-11-10 09:25:17 +0200 | [diff] [blame] | 908 | if (WARN_ON_ONCE(len < sizeof(*acx))) |
| 909 | return -EIO; |
| 910 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 911 | acx->id = cpu_to_le16(id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 912 | |
| 913 | /* payload length, does not include any headers */ |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 914 | acx->len = cpu_to_le16(len - sizeof(*acx)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 915 | |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 916 | ret = wlcore_cmd_send_failsafe(wl, CMD_CONFIGURE, acx, len, 0, |
| 917 | valid_rets); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 918 | if (ret < 0) { |
| 919 | wl1271_warning("CONFIGURE command NOK"); |
| 920 | return ret; |
| 921 | } |
| 922 | |
Eliad Peller | ea50843 | 2012-11-27 08:44:45 +0200 | [diff] [blame] | 923 | return ret; |
| 924 | } |
| 925 | |
| 926 | /* |
| 927 | * wrapper for wlcore_cmd_configure that accepts only success status. |
| 928 | * return 0 on success |
| 929 | */ |
| 930 | int wl1271_cmd_configure(struct wl1271 *wl, u16 id, void *buf, size_t len) |
| 931 | { |
| 932 | int ret = wlcore_cmd_configure_failsafe(wl, id, buf, len, 0); |
| 933 | |
| 934 | if (ret < 0) |
| 935 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 936 | return 0; |
| 937 | } |
Luciano Coelho | 9d68d1e | 2011-12-02 00:47:45 +0200 | [diff] [blame] | 938 | EXPORT_SYMBOL_GPL(wl1271_cmd_configure); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 939 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 940 | int wl1271_cmd_data_path(struct wl1271 *wl, bool enable) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 941 | { |
| 942 | struct cmd_enabledisable_path *cmd; |
| 943 | int ret; |
| 944 | u16 cmd_rx, cmd_tx; |
| 945 | |
| 946 | wl1271_debug(DEBUG_CMD, "cmd data path"); |
| 947 | |
| 948 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 949 | if (!cmd) { |
| 950 | ret = -ENOMEM; |
| 951 | goto out; |
| 952 | } |
| 953 | |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 954 | /* the channel here is only used for calibration, so hardcoded to 1 */ |
| 955 | cmd->channel = 1; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 956 | |
| 957 | if (enable) { |
| 958 | cmd_rx = CMD_ENABLE_RX; |
| 959 | cmd_tx = CMD_ENABLE_TX; |
| 960 | } else { |
| 961 | cmd_rx = CMD_DISABLE_RX; |
| 962 | cmd_tx = CMD_DISABLE_TX; |
| 963 | } |
| 964 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 965 | ret = wl1271_cmd_send(wl, cmd_rx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 966 | if (ret < 0) { |
| 967 | wl1271_error("rx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 968 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 969 | goto out; |
| 970 | } |
| 971 | |
| 972 | wl1271_debug(DEBUG_BOOT, "rx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 973 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 974 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 975 | ret = wl1271_cmd_send(wl, cmd_tx, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 976 | if (ret < 0) { |
| 977 | wl1271_error("tx %s cmd for channel %d failed", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 978 | enable ? "start" : "stop", cmd->channel); |
Juuso Oikarinen | 1b00f2b | 2010-03-26 12:53:17 +0200 | [diff] [blame] | 979 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | wl1271_debug(DEBUG_BOOT, "tx %s cmd channel %d", |
Luciano Coelho | 9421089 | 2009-12-11 15:40:55 +0200 | [diff] [blame] | 983 | enable ? "start" : "stop", cmd->channel); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 984 | |
| 985 | out: |
| 986 | kfree(cmd); |
| 987 | return ret; |
| 988 | } |
Luciano Coelho | c331b34 | 2012-05-10 12:13:49 +0300 | [diff] [blame] | 989 | EXPORT_SYMBOL_GPL(wl1271_cmd_data_path); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 990 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 991 | int wl1271_cmd_ps_mode(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 992 | u8 ps_mode, u16 auto_ps_timeout) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 993 | { |
| 994 | struct wl1271_cmd_ps_params *ps_params = NULL; |
| 995 | int ret = 0; |
| 996 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 997 | wl1271_debug(DEBUG_CMD, "cmd set ps mode"); |
| 998 | |
| 999 | ps_params = kzalloc(sizeof(*ps_params), GFP_KERNEL); |
| 1000 | if (!ps_params) { |
| 1001 | ret = -ENOMEM; |
| 1002 | goto out; |
| 1003 | } |
| 1004 | |
Eliad Peller | 0603d89 | 2011-10-05 11:55:51 +0200 | [diff] [blame] | 1005 | ps_params->role_id = wlvif->role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1006 | ps_params->ps_mode = ps_mode; |
Eyal Shapira | f1d63a5 | 2012-01-31 11:57:21 +0200 | [diff] [blame] | 1007 | ps_params->auto_ps_timeout = auto_ps_timeout; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1008 | |
| 1009 | ret = wl1271_cmd_send(wl, CMD_SET_PS_MODE, ps_params, |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1010 | sizeof(*ps_params), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1011 | if (ret < 0) { |
| 1012 | wl1271_error("cmd set_ps_mode failed"); |
| 1013 | goto out; |
| 1014 | } |
| 1015 | |
| 1016 | out: |
| 1017 | kfree(ps_params); |
| 1018 | return ret; |
| 1019 | } |
| 1020 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1021 | int wl1271_cmd_template_set(struct wl1271 *wl, u8 role_id, |
| 1022 | u16 template_id, void *buf, size_t buf_len, |
| 1023 | int index, u32 rates) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1024 | { |
| 1025 | struct wl1271_cmd_template_set *cmd; |
| 1026 | int ret = 0; |
| 1027 | |
Eliad Peller | c059beb | 2012-01-31 11:57:17 +0200 | [diff] [blame] | 1028 | wl1271_debug(DEBUG_CMD, "cmd template_set %d (role %d)", |
| 1029 | template_id, role_id); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1030 | |
| 1031 | WARN_ON(buf_len > WL1271_CMD_TEMPL_MAX_SIZE); |
| 1032 | buf_len = min_t(size_t, buf_len, WL1271_CMD_TEMPL_MAX_SIZE); |
| 1033 | |
| 1034 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1035 | if (!cmd) { |
| 1036 | ret = -ENOMEM; |
| 1037 | goto out; |
| 1038 | } |
| 1039 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1040 | /* during initialization wlvif is NULL */ |
| 1041 | cmd->role_id = role_id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1042 | cmd->len = cpu_to_le16(buf_len); |
| 1043 | cmd->template_type = template_id; |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 1044 | cmd->enabled_rates = cpu_to_le32(rates); |
Arik Nemtsov | 1e05a81 | 2010-10-16 17:44:51 +0200 | [diff] [blame] | 1045 | cmd->short_retry_limit = wl->conf.tx.tmpl_short_retry_limit; |
| 1046 | cmd->long_retry_limit = wl->conf.tx.tmpl_long_retry_limit; |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1047 | cmd->index = index; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1048 | |
| 1049 | if (buf) |
| 1050 | memcpy(cmd->template_data, buf, buf_len); |
| 1051 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1052 | ret = wl1271_cmd_send(wl, CMD_SET_TEMPLATE, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1053 | if (ret < 0) { |
| 1054 | wl1271_warning("cmd set_template failed: %d", ret); |
| 1055 | goto out_free; |
| 1056 | } |
| 1057 | |
| 1058 | out_free: |
| 1059 | kfree(cmd); |
| 1060 | |
| 1061 | out: |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1065 | int wl12xx_cmd_build_null_data(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1066 | { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1067 | struct sk_buff *skb = NULL; |
| 1068 | int size; |
| 1069 | void *ptr; |
| 1070 | int ret = -ENOMEM; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1071 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1072 | |
Eliad Peller | 536129c | 2011-10-05 11:55:45 +0200 | [diff] [blame] | 1073 | if (wlvif->bss_type == BSS_TYPE_IBSS) { |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1074 | size = sizeof(struct wl12xx_null_data_template); |
| 1075 | ptr = NULL; |
| 1076 | } else { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1077 | skb = ieee80211_nullfunc_get(wl->hw, |
| 1078 | wl12xx_wlvif_to_vif(wlvif)); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1079 | if (!skb) |
| 1080 | goto out; |
| 1081 | size = skb->len; |
| 1082 | ptr = skb->data; |
| 1083 | } |
| 1084 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1085 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1086 | CMD_TEMPL_NULL_DATA, ptr, size, 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1087 | wlvif->basic_rate); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1088 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1089 | out: |
| 1090 | dev_kfree_skb(skb); |
Juuso Oikarinen | a0cb7be | 2010-03-18 12:26:44 +0200 | [diff] [blame] | 1091 | if (ret) |
| 1092 | wl1271_warning("cmd buld null data failed %d", ret); |
| 1093 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1094 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1095 | |
| 1096 | } |
| 1097 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1098 | int wl12xx_cmd_build_klv_null_data(struct wl1271 *wl, |
| 1099 | struct wl12xx_vif *wlvif) |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1100 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1101 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1102 | struct sk_buff *skb = NULL; |
| 1103 | int ret = -ENOMEM; |
| 1104 | |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1105 | skb = ieee80211_nullfunc_get(wl->hw, vif); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1106 | if (!skb) |
| 1107 | goto out; |
| 1108 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1109 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_KLV, |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1110 | skb->data, skb->len, |
Eliad Peller | 001e39a | 2012-08-16 13:52:47 +0300 | [diff] [blame] | 1111 | wlvif->sta.klv_template_id, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1112 | wlvif->basic_rate); |
Juuso Oikarinen | bfb24c9 | 2010-03-26 12:53:31 +0200 | [diff] [blame] | 1113 | |
| 1114 | out: |
| 1115 | dev_kfree_skb(skb); |
| 1116 | if (ret) |
| 1117 | wl1271_warning("cmd build klv null data failed %d", ret); |
| 1118 | |
| 1119 | return ret; |
| 1120 | |
| 1121 | } |
| 1122 | |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1123 | int wl1271_cmd_build_ps_poll(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1124 | u16 aid) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1125 | { |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1126 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1127 | struct sk_buff *skb; |
| 1128 | int ret = 0; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1129 | |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1130 | skb = ieee80211_pspoll_get(wl->hw, vif); |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1131 | if (!skb) |
| 1132 | goto out; |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 1133 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1134 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1135 | CMD_TEMPL_PS_POLL, skb->data, |
Eliad Peller | 87fbcb0 | 2011-10-05 11:55:41 +0200 | [diff] [blame] | 1136 | skb->len, 0, wlvif->basic_rate_set); |
Juuso Oikarinen | c3fea19 | 2009-10-08 21:56:22 +0300 | [diff] [blame] | 1137 | |
Kalle Valo | 899e6e6 | 2010-03-18 12:26:34 +0200 | [diff] [blame] | 1138 | out: |
| 1139 | dev_kfree_skb(skb); |
| 1140 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1141 | } |
| 1142 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1143 | int wl12xx_cmd_build_probe_req(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1144 | u8 role_id, u8 band, |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1145 | const u8 *ssid, size_t ssid_len, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 1146 | const u8 *ie0, size_t ie0_len, const u8 *ie1, |
| 1147 | size_t ie1_len, bool sched_scan) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1148 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1149 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1150 | struct sk_buff *skb; |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1151 | int ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1152 | u32 rate; |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 1153 | u16 template_id_2_4 = wl->scan_templ_id_2_4; |
| 1154 | u16 template_id_5 = wl->scan_templ_id_5; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1155 | |
Victor Goldenshtein | 0fe7208 | 2013-09-17 18:41:24 +0300 | [diff] [blame] | 1156 | wl1271_debug(DEBUG_SCAN, "build probe request band %d", band); |
| 1157 | |
Johannes Berg | a344d67 | 2014-06-12 22:24:31 +0200 | [diff] [blame] | 1158 | skb = ieee80211_probereq_get(wl->hw, vif->addr, ssid, ssid_len, |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 1159 | ie0_len + ie1_len); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1160 | if (!skb) { |
| 1161 | ret = -ENOMEM; |
| 1162 | goto out; |
| 1163 | } |
David Spinadel | 633e271 | 2014-02-06 16:15:23 +0200 | [diff] [blame] | 1164 | if (ie0_len) |
| 1165 | memcpy(skb_put(skb, ie0_len), ie0, ie0_len); |
| 1166 | if (ie1_len) |
| 1167 | memcpy(skb_put(skb, ie1_len), ie1, ie1_len); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1168 | |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 1169 | if (sched_scan && |
Yoni Divinsky | 3df74f4 | 2012-06-27 13:01:44 +0300 | [diff] [blame] | 1170 | (wl->quirks & WLCORE_QUIRK_DUAL_PROBE_TMPL)) { |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 1171 | template_id_2_4 = wl->sched_scan_templ_id_2_4; |
| 1172 | template_id_5 = wl->sched_scan_templ_id_5; |
Yoni Divinsky | 3df74f4 | 2012-06-27 13:01:44 +0300 | [diff] [blame] | 1173 | } |
| 1174 | |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1175 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[band]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1176 | if (band == NL80211_BAND_2GHZ) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1177 | ret = wl1271_cmd_template_set(wl, role_id, |
Yoni Divinsky | 3df74f4 | 2012-06-27 13:01:44 +0300 | [diff] [blame] | 1178 | template_id_2_4, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1179 | skb->data, skb->len, 0, rate); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1180 | else |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1181 | ret = wl1271_cmd_template_set(wl, role_id, |
Yoni Divinsky | 3df74f4 | 2012-06-27 13:01:44 +0300 | [diff] [blame] | 1182 | template_id_5, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1183 | skb->data, skb->len, 0, rate); |
Kalle Valo | 818e306 | 2010-03-18 12:26:35 +0200 | [diff] [blame] | 1184 | |
| 1185 | out: |
| 1186 | dev_kfree_skb(skb); |
Teemu Paasikivi | abb0b3b | 2009-10-13 12:47:50 +0300 | [diff] [blame] | 1187 | return ret; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1188 | } |
Eliad Peller | 78e2806 | 2012-11-22 18:06:15 +0200 | [diff] [blame] | 1189 | EXPORT_SYMBOL_GPL(wl12xx_cmd_build_probe_req); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1190 | |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1191 | struct sk_buff *wl1271_cmd_build_ap_probe_req(struct wl1271 *wl, |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1192 | struct wl12xx_vif *wlvif, |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1193 | struct sk_buff *skb) |
| 1194 | { |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1195 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1196 | int ret; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1197 | u32 rate; |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1198 | |
| 1199 | if (!skb) |
Eliad Peller | 8358750 | 2011-10-10 10:12:53 +0200 | [diff] [blame] | 1200 | skb = ieee80211_ap_probereq_get(wl->hw, vif); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1201 | if (!skb) |
| 1202 | goto out; |
| 1203 | |
Victor Goldenshtein | 0fe7208 | 2013-09-17 18:41:24 +0300 | [diff] [blame] | 1204 | wl1271_debug(DEBUG_SCAN, "set ap probe request template"); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1205 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1206 | rate = wl1271_tx_min_rate_get(wl, wlvif->bitrate_masks[wlvif->band]); |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1207 | if (wlvif->band == NL80211_BAND_2GHZ) |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1208 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1209 | CMD_TEMPL_CFG_PROBE_REQ_2_4, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1210 | skb->data, skb->len, 0, rate); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1211 | else |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1212 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1213 | CMD_TEMPL_CFG_PROBE_REQ_5, |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1214 | skb->data, skb->len, 0, rate); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 1215 | |
| 1216 | if (ret < 0) |
| 1217 | wl1271_error("Unable to set ap probe request template."); |
| 1218 | |
| 1219 | out: |
| 1220 | return skb; |
| 1221 | } |
| 1222 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1223 | int wl1271_cmd_build_arp_rsp(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1224 | { |
Arik Nemtsov | 2c0133a | 2012-05-18 07:46:36 +0300 | [diff] [blame] | 1225 | int ret, extra = 0; |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1226 | u16 fc; |
Eliad Peller | 6e8cd33 | 2011-10-10 10:13:13 +0200 | [diff] [blame] | 1227 | struct ieee80211_vif *vif = wl12xx_wlvif_to_vif(wlvif); |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1228 | struct sk_buff *skb; |
| 1229 | struct wl12xx_arp_rsp_template *tmpl; |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1230 | struct ieee80211_hdr_3addr *hdr; |
| 1231 | struct arphdr *arp_hdr; |
| 1232 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1233 | skb = dev_alloc_skb(sizeof(*hdr) + sizeof(__le16) + sizeof(*tmpl) + |
| 1234 | WL1271_EXTRA_SPACE_MAX); |
| 1235 | if (!skb) { |
| 1236 | wl1271_error("failed to allocate buffer for arp rsp template"); |
| 1237 | return -ENOMEM; |
| 1238 | } |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1239 | |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1240 | skb_reserve(skb, sizeof(*hdr) + WL1271_EXTRA_SPACE_MAX); |
| 1241 | |
| 1242 | tmpl = (struct wl12xx_arp_rsp_template *)skb_put(skb, sizeof(*tmpl)); |
Jesper Juhl | 161f17b | 2012-05-03 10:25:51 +0300 | [diff] [blame] | 1243 | memset(tmpl, 0, sizeof(*tmpl)); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1244 | |
| 1245 | /* llc layer */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1246 | memcpy(tmpl->llc_hdr, rfc1042_header, sizeof(rfc1042_header)); |
| 1247 | tmpl->llc_type = cpu_to_be16(ETH_P_ARP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1248 | |
| 1249 | /* arp header */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1250 | arp_hdr = &tmpl->arp_hdr; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 1251 | arp_hdr->ar_hrd = cpu_to_be16(ARPHRD_ETHER); |
| 1252 | arp_hdr->ar_pro = cpu_to_be16(ETH_P_IP); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1253 | arp_hdr->ar_hln = ETH_ALEN; |
| 1254 | arp_hdr->ar_pln = 4; |
Eliad Peller | 6177eae | 2010-12-22 12:38:52 +0100 | [diff] [blame] | 1255 | arp_hdr->ar_op = cpu_to_be16(ARPOP_REPLY); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1256 | |
| 1257 | /* arp payload */ |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1258 | memcpy(tmpl->sender_hw, vif->addr, ETH_ALEN); |
| 1259 | tmpl->sender_ip = wlvif->ip_addr; |
| 1260 | |
| 1261 | /* encryption space */ |
| 1262 | switch (wlvif->encryption_type) { |
| 1263 | case KEY_TKIP: |
Arik Nemtsov | 2c0133a | 2012-05-18 07:46:36 +0300 | [diff] [blame] | 1264 | if (wl->quirks & WLCORE_QUIRK_TKIP_HEADER_SPACE) |
| 1265 | extra = WL1271_EXTRA_SPACE_TKIP; |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1266 | break; |
| 1267 | case KEY_AES: |
| 1268 | extra = WL1271_EXTRA_SPACE_AES; |
| 1269 | break; |
| 1270 | case KEY_NONE: |
| 1271 | case KEY_WEP: |
| 1272 | case KEY_GEM: |
| 1273 | extra = 0; |
| 1274 | break; |
| 1275 | default: |
| 1276 | wl1271_warning("Unknown encryption type: %d", |
| 1277 | wlvif->encryption_type); |
| 1278 | ret = -EINVAL; |
| 1279 | goto out; |
| 1280 | } |
| 1281 | |
| 1282 | if (extra) { |
| 1283 | u8 *space = skb_push(skb, extra); |
| 1284 | memset(space, 0, extra); |
| 1285 | } |
| 1286 | |
| 1287 | /* QoS header - BE */ |
| 1288 | if (wlvif->sta.qos) |
| 1289 | memset(skb_push(skb, sizeof(__le16)), 0, sizeof(__le16)); |
| 1290 | |
| 1291 | /* mac80211 header */ |
| 1292 | hdr = (struct ieee80211_hdr_3addr *)skb_push(skb, sizeof(*hdr)); |
Jesper Juhl | 161f17b | 2012-05-03 10:25:51 +0300 | [diff] [blame] | 1293 | memset(hdr, 0, sizeof(*hdr)); |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1294 | fc = IEEE80211_FTYPE_DATA | IEEE80211_FCTL_TODS; |
| 1295 | if (wlvif->sta.qos) |
| 1296 | fc |= IEEE80211_STYPE_QOS_DATA; |
| 1297 | else |
| 1298 | fc |= IEEE80211_STYPE_DATA; |
| 1299 | if (wlvif->encryption_type != KEY_NONE) |
| 1300 | fc |= IEEE80211_FCTL_PROTECTED; |
| 1301 | |
| 1302 | hdr->frame_control = cpu_to_le16(fc); |
| 1303 | memcpy(hdr->addr1, vif->bss_conf.bssid, ETH_ALEN); |
| 1304 | memcpy(hdr->addr2, vif->addr, ETH_ALEN); |
Joe Perches | 93803b3 | 2015-03-02 19:54:49 -0800 | [diff] [blame] | 1305 | eth_broadcast_addr(hdr->addr3); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1306 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1307 | ret = wl1271_cmd_template_set(wl, wlvif->role_id, CMD_TEMPL_ARP_RSP, |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1308 | skb->data, skb->len, 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1309 | wlvif->basic_rate); |
Eliad Peller | 5ec8a44 | 2012-02-02 12:22:09 +0200 | [diff] [blame] | 1310 | out: |
| 1311 | dev_kfree_skb(skb); |
Eliad Peller | c531277 | 2010-12-09 11:31:27 +0200 | [diff] [blame] | 1312 | return ret; |
| 1313 | } |
| 1314 | |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 1315 | int wl1271_build_qos_null_data(struct wl1271 *wl, struct ieee80211_vif *vif) |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1316 | { |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1317 | struct wl12xx_vif *wlvif = wl12xx_vif_to_data(vif); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1318 | struct ieee80211_qos_hdr template; |
| 1319 | |
| 1320 | memset(&template, 0, sizeof(template)); |
| 1321 | |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 1322 | memcpy(template.addr1, vif->bss_conf.bssid, ETH_ALEN); |
Eliad Peller | 784f694 | 2011-10-05 11:55:39 +0200 | [diff] [blame] | 1323 | memcpy(template.addr2, vif->addr, ETH_ALEN); |
Eliad Peller | cdf0949 | 2011-10-05 11:55:44 +0200 | [diff] [blame] | 1324 | memcpy(template.addr3, vif->bss_conf.bssid, ETH_ALEN); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1325 | |
| 1326 | template.frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA | |
| 1327 | IEEE80211_STYPE_QOS_NULLFUNC | |
| 1328 | IEEE80211_FCTL_TODS); |
| 1329 | |
| 1330 | /* FIXME: not sure what priority to use here */ |
| 1331 | template.qos_ctrl = cpu_to_le16(0); |
| 1332 | |
Eliad Peller | cdaac62 | 2012-01-31 11:57:16 +0200 | [diff] [blame] | 1333 | return wl1271_cmd_template_set(wl, wlvif->role_id, |
| 1334 | CMD_TEMPL_QOS_NULL_DATA, &template, |
Juuso Oikarinen | 606c148 | 2010-04-01 11:38:21 +0300 | [diff] [blame] | 1335 | sizeof(template), 0, |
Eliad Peller | d2d66c5 | 2011-10-05 11:55:43 +0200 | [diff] [blame] | 1336 | wlvif->basic_rate); |
Kalle Valo | 023e082 | 2010-03-18 12:26:36 +0200 | [diff] [blame] | 1337 | } |
| 1338 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1339 | int wl12xx_cmd_set_default_wep_key(struct wl1271 *wl, u8 id, u8 hlid) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1340 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1341 | struct wl1271_cmd_set_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1342 | int ret = 0; |
| 1343 | |
| 1344 | wl1271_debug(DEBUG_CMD, "cmd set_default_wep_key %d", id); |
| 1345 | |
| 1346 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1347 | if (!cmd) { |
| 1348 | ret = -ENOMEM; |
| 1349 | goto out; |
| 1350 | } |
| 1351 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1352 | cmd->hlid = hlid; |
| 1353 | cmd->key_id = id; |
| 1354 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1355 | cmd->key_action = cpu_to_le16(KEY_SET_ID); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1356 | cmd->key_type = KEY_WEP; |
| 1357 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1358 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1359 | if (ret < 0) { |
| 1360 | wl1271_warning("cmd set_default_wep_key failed: %d", ret); |
| 1361 | goto out; |
| 1362 | } |
| 1363 | |
| 1364 | out: |
| 1365 | kfree(cmd); |
| 1366 | |
| 1367 | return ret; |
| 1368 | } |
| 1369 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1370 | int wl1271_cmd_set_sta_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1371 | u16 action, u8 id, u8 key_type, |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 1372 | u8 key_size, const u8 *key, const u8 *addr, |
| 1373 | u32 tx_seq_32, u16 tx_seq_16) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1374 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1375 | struct wl1271_cmd_set_keys *cmd; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1376 | int ret = 0; |
| 1377 | |
Eliad Peller | b42f068 | 2011-08-14 13:17:24 +0300 | [diff] [blame] | 1378 | /* hlid might have already been deleted */ |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1379 | if (wlvif->sta.hlid == WL12XX_INVALID_LINK_ID) |
Eliad Peller | b42f068 | 2011-08-14 13:17:24 +0300 | [diff] [blame] | 1380 | return 0; |
| 1381 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1382 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1383 | if (!cmd) { |
| 1384 | ret = -ENOMEM; |
| 1385 | goto out; |
| 1386 | } |
| 1387 | |
Eliad Peller | 154da67 | 2011-10-05 11:55:53 +0200 | [diff] [blame] | 1388 | cmd->hlid = wlvif->sta.hlid; |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1389 | |
| 1390 | if (key_type == KEY_WEP) |
| 1391 | cmd->lid_key_type = WEP_DEFAULT_LID_TYPE; |
| 1392 | else if (is_broadcast_ether_addr(addr)) |
| 1393 | cmd->lid_key_type = BROADCAST_LID_TYPE; |
| 1394 | else |
| 1395 | cmd->lid_key_type = UNICAST_LID_TYPE; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1396 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1397 | cmd->key_action = cpu_to_le16(action); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1398 | cmd->key_size = key_size; |
| 1399 | cmd->key_type = key_type; |
| 1400 | |
Luciano Coelho | d0f63b2 | 2009-10-15 10:33:29 +0300 | [diff] [blame] | 1401 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 1402 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
Juuso Oikarinen | ac4e4ce | 2009-10-08 21:56:19 +0300 | [diff] [blame] | 1403 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1404 | cmd->key_id = id; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1405 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1406 | if (key_type == KEY_TKIP) { |
| 1407 | /* |
| 1408 | * We get the key in the following form: |
| 1409 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 1410 | * but the target is expecting: |
| 1411 | * TKIP - RX MIC - TX MIC |
| 1412 | */ |
| 1413 | memcpy(cmd->key, key, 16); |
| 1414 | memcpy(cmd->key + 16, key + 24, 8); |
| 1415 | memcpy(cmd->key + 24, key + 16, 8); |
| 1416 | |
| 1417 | } else { |
| 1418 | memcpy(cmd->key, key, key_size); |
| 1419 | } |
| 1420 | |
| 1421 | wl1271_dump(DEBUG_CRYPT, "TARGET KEY: ", cmd, sizeof(*cmd)); |
| 1422 | |
Juuso Oikarinen | fa867e7 | 2009-11-02 20:22:13 +0200 | [diff] [blame] | 1423 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1424 | if (ret < 0) { |
| 1425 | wl1271_warning("could not set keys"); |
Juuso Oikarinen | 152ee6e | 2010-02-18 13:25:42 +0200 | [diff] [blame] | 1426 | goto out; |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | out: |
| 1430 | kfree(cmd); |
| 1431 | |
| 1432 | return ret; |
| 1433 | } |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1434 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1435 | /* |
| 1436 | * TODO: merge with sta/ibss into 1 set_key function. |
| 1437 | * note there are slight diffs |
| 1438 | */ |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1439 | int wl1271_cmd_set_ap_key(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1440 | u16 action, u8 id, u8 key_type, |
| 1441 | u8 key_size, const u8 *key, u8 hlid, u32 tx_seq_32, |
| 1442 | u16 tx_seq_16) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1443 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1444 | struct wl1271_cmd_set_keys *cmd; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1445 | int ret = 0; |
| 1446 | u8 lid_type; |
| 1447 | |
| 1448 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1449 | if (!cmd) |
| 1450 | return -ENOMEM; |
| 1451 | |
Eliad Peller | a8ab39a | 2011-10-05 11:55:54 +0200 | [diff] [blame] | 1452 | if (hlid == wlvif->ap.bcast_hlid) { |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1453 | if (key_type == KEY_WEP) |
| 1454 | lid_type = WEP_DEFAULT_LID_TYPE; |
| 1455 | else |
| 1456 | lid_type = BROADCAST_LID_TYPE; |
| 1457 | } else { |
| 1458 | lid_type = UNICAST_LID_TYPE; |
| 1459 | } |
| 1460 | |
| 1461 | wl1271_debug(DEBUG_CRYPT, "ap key action: %d id: %d lid: %d type: %d" |
| 1462 | " hlid: %d", (int)action, (int)id, (int)lid_type, |
| 1463 | (int)key_type, (int)hlid); |
| 1464 | |
| 1465 | cmd->lid_key_type = lid_type; |
| 1466 | cmd->hlid = hlid; |
| 1467 | cmd->key_action = cpu_to_le16(action); |
| 1468 | cmd->key_size = key_size; |
| 1469 | cmd->key_type = key_type; |
| 1470 | cmd->key_id = id; |
| 1471 | cmd->ac_seq_num16[0] = cpu_to_le16(tx_seq_16); |
| 1472 | cmd->ac_seq_num32[0] = cpu_to_le32(tx_seq_32); |
| 1473 | |
| 1474 | if (key_type == KEY_TKIP) { |
| 1475 | /* |
| 1476 | * We get the key in the following form: |
| 1477 | * TKIP (16 bytes) - TX MIC (8 bytes) - RX MIC (8 bytes) |
| 1478 | * but the target is expecting: |
| 1479 | * TKIP - RX MIC - TX MIC |
| 1480 | */ |
| 1481 | memcpy(cmd->key, key, 16); |
| 1482 | memcpy(cmd->key + 16, key + 24, 8); |
| 1483 | memcpy(cmd->key + 24, key + 16, 8); |
| 1484 | } else { |
| 1485 | memcpy(cmd->key, key, key_size); |
| 1486 | } |
| 1487 | |
| 1488 | wl1271_dump(DEBUG_CRYPT, "TARGET AP KEY: ", cmd, sizeof(*cmd)); |
| 1489 | |
| 1490 | ret = wl1271_cmd_send(wl, CMD_SET_KEYS, cmd, sizeof(*cmd), 0); |
| 1491 | if (ret < 0) { |
| 1492 | wl1271_warning("could not set ap keys"); |
| 1493 | goto out; |
| 1494 | } |
| 1495 | |
| 1496 | out: |
| 1497 | kfree(cmd); |
| 1498 | return ret; |
| 1499 | } |
| 1500 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 1501 | int wl12xx_cmd_set_peer_state(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1502 | u8 hlid) |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1503 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1504 | struct wl12xx_cmd_set_peer_state *cmd; |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1505 | int ret = 0; |
| 1506 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 1507 | wl1271_debug(DEBUG_CMD, "cmd set peer state (hlid=%d)", hlid); |
Luciano Coelho | 25a7dc6 | 2009-10-12 15:08:42 +0300 | [diff] [blame] | 1508 | |
| 1509 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1510 | if (!cmd) { |
| 1511 | ret = -ENOMEM; |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
Eliad Peller | b67476e | 2011-08-14 13:17:23 +0300 | [diff] [blame] | 1515 | cmd->hlid = hlid; |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1516 | cmd->state = WL1271_CMD_STA_STATE_CONNECTED; |
| 1517 | |
Eliad Peller | d50529c | 2012-11-22 18:06:20 +0200 | [diff] [blame] | 1518 | /* wmm param is valid only for station role */ |
| 1519 | if (wlvif->bss_type == BSS_TYPE_STA_BSS) |
| 1520 | cmd->wmm = wlvif->wmm_enabled; |
| 1521 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1522 | ret = wl1271_cmd_send(wl, CMD_SET_PEER_STATE, cmd, sizeof(*cmd), 0); |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1523 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1524 | wl1271_error("failed to send set peer state command"); |
Juuso Oikarinen | be86cbe | 2010-05-27 12:53:01 +0300 | [diff] [blame] | 1525 | goto out_free; |
| 1526 | } |
| 1527 | |
| 1528 | out_free: |
| 1529 | kfree(cmd); |
| 1530 | |
| 1531 | out: |
| 1532 | return ret; |
| 1533 | } |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1534 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1535 | int wl12xx_cmd_add_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1536 | struct ieee80211_sta *sta, u8 hlid) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1537 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1538 | struct wl12xx_cmd_add_peer *cmd; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1539 | int i, ret; |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1540 | u32 sta_rates; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1541 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1542 | wl1271_debug(DEBUG_CMD, "cmd add peer %d", (int)hlid); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1543 | |
| 1544 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1545 | if (!cmd) { |
| 1546 | ret = -ENOMEM; |
| 1547 | goto out; |
| 1548 | } |
| 1549 | |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1550 | memcpy(cmd->addr, sta->addr, ETH_ALEN); |
| 1551 | cmd->bss_index = WL1271_AP_BSS_INDEX; |
| 1552 | cmd->aid = sta->aid; |
| 1553 | cmd->hlid = hlid; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1554 | cmd->sp_len = sta->max_sp; |
Arik Nemtsov | b4d38db | 2011-06-27 23:58:46 +0300 | [diff] [blame] | 1555 | cmd->wmm = sta->wme ? 1 : 0; |
Eliad Peller | 978cd3a | 2012-11-22 18:06:21 +0200 | [diff] [blame] | 1556 | cmd->session_id = wl->session_ids[hlid]; |
Eliad Peller | 028e724 | 2014-02-10 13:47:25 +0200 | [diff] [blame] | 1557 | cmd->role_id = wlvif->role_id; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1558 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1559 | for (i = 0; i < NUM_ACCESS_CATEGORIES_COPY; i++) |
| 1560 | if (sta->wme && (sta->uapsd_queues & BIT(i))) |
Yoni Divinsky | 2e42c20 | 2012-05-08 14:02:11 +0300 | [diff] [blame] | 1561 | cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = |
| 1562 | WL1271_PSD_UPSD_TRIGGER; |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1563 | else |
Yoni Divinsky | 2e42c20 | 2012-05-08 14:02:11 +0300 | [diff] [blame] | 1564 | cmd->psd_type[NUM_ACCESS_CATEGORIES_COPY-1-i] = |
| 1565 | WL1271_PSD_LEGACY; |
| 1566 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1567 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1568 | sta_rates = sta->supp_rates[wlvif->band]; |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1569 | if (sta->ht_cap.ht_supported) |
Arik Nemtsov | b3a47ee | 2012-05-10 12:13:33 +0300 | [diff] [blame] | 1570 | sta_rates |= |
| 1571 | (sta->ht_cap.mcs.rx_mask[0] << HW_HT_RATES_OFFSET) | |
| 1572 | (sta->ht_cap.mcs.rx_mask[1] << HW_MIMO_RATES_OFFSET); |
Arik Nemtsov | 99d5ad7 | 2011-08-14 13:17:28 +0300 | [diff] [blame] | 1573 | |
| 1574 | cmd->supported_rates = |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 1575 | cpu_to_le32(wl1271_tx_enabled_rates_get(wl, sta_rates, |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1576 | wlvif->band)); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1577 | |
Guy Mishol | 535633a | 2016-06-19 17:08:58 +0300 | [diff] [blame] | 1578 | if (!cmd->supported_rates) { |
| 1579 | wl1271_debug(DEBUG_CMD, |
| 1580 | "peer has no supported rates yet, configuring basic rates: 0x%x", |
| 1581 | wlvif->basic_rate_set); |
| 1582 | cmd->supported_rates = cpu_to_le32(wlvif->basic_rate_set); |
| 1583 | } |
| 1584 | |
Eliad Peller | 1ec23f7 | 2011-08-25 14:26:54 +0300 | [diff] [blame] | 1585 | wl1271_debug(DEBUG_CMD, "new peer rates=0x%x queues=0x%x", |
| 1586 | cmd->supported_rates, sta->uapsd_queues); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1587 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1588 | ret = wl1271_cmd_send(wl, CMD_ADD_PEER, cmd, sizeof(*cmd), 0); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1589 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1590 | wl1271_error("failed to initiate cmd add peer"); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1591 | goto out_free; |
| 1592 | } |
| 1593 | |
| 1594 | out_free: |
| 1595 | kfree(cmd); |
| 1596 | |
| 1597 | out: |
| 1598 | return ret; |
| 1599 | } |
| 1600 | |
Eliad Peller | 028e724 | 2014-02-10 13:47:25 +0200 | [diff] [blame] | 1601 | int wl12xx_cmd_remove_peer(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 1602 | u8 hlid) |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1603 | { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1604 | struct wl12xx_cmd_remove_peer *cmd; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1605 | int ret; |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 1606 | bool timeout = false; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1607 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1608 | wl1271_debug(DEBUG_CMD, "cmd remove peer %d", (int)hlid); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1609 | |
| 1610 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1611 | if (!cmd) { |
| 1612 | ret = -ENOMEM; |
| 1613 | goto out; |
| 1614 | } |
| 1615 | |
| 1616 | cmd->hlid = hlid; |
| 1617 | /* We never send a deauth, mac80211 is in charge of this */ |
| 1618 | cmd->reason_opcode = 0; |
| 1619 | cmd->send_deauth_flag = 0; |
Eliad Peller | 028e724 | 2014-02-10 13:47:25 +0200 | [diff] [blame] | 1620 | cmd->role_id = wlvif->role_id; |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1621 | |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1622 | ret = wl1271_cmd_send(wl, CMD_REMOVE_PEER, cmd, sizeof(*cmd), 0); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1623 | if (ret < 0) { |
Eliad Peller | c690ec8 | 2011-08-14 13:17:07 +0300 | [diff] [blame] | 1624 | wl1271_error("failed to initiate cmd remove peer"); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1625 | goto out_free; |
| 1626 | } |
| 1627 | |
Eliad Peller | c50a282 | 2012-11-22 18:06:19 +0200 | [diff] [blame] | 1628 | ret = wl->ops->wait_for_event(wl, |
| 1629 | WLCORE_EVENT_PEER_REMOVE_COMPLETE, |
| 1630 | &timeout); |
| 1631 | |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 1632 | /* |
| 1633 | * We are ok with a timeout here. The event is sometimes not sent |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 1634 | * due to a firmware bug. In case of another error (like SDIO timeout) |
| 1635 | * queue a recovery. |
Arik Nemtsov | 05285cf | 2010-11-12 17:15:03 +0200 | [diff] [blame] | 1636 | */ |
Eyal Shapira | 6c15c1a | 2012-06-26 10:41:16 +0300 | [diff] [blame] | 1637 | if (ret) |
| 1638 | wl12xx_queue_recovery_work(wl); |
Arik Nemtsov | 98bdaab | 2010-10-16 18:08:58 +0200 | [diff] [blame] | 1639 | |
| 1640 | out_free: |
| 1641 | kfree(cmd); |
| 1642 | |
| 1643 | out: |
| 1644 | return ret; |
| 1645 | } |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1646 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1647 | static int wlcore_get_reg_conf_ch_idx(enum nl80211_band band, u16 ch) |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1648 | { |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1649 | /* |
| 1650 | * map the given band/channel to the respective predefined |
| 1651 | * bit expected by the fw |
| 1652 | */ |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1653 | switch (band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1654 | case NL80211_BAND_2GHZ: |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1655 | /* channels 1..14 are mapped to 0..13 */ |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1656 | if (ch >= 1 && ch <= 14) |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1657 | return ch - 1; |
| 1658 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1659 | case NL80211_BAND_5GHZ: |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1660 | switch (ch) { |
| 1661 | case 8 ... 16: |
| 1662 | /* channels 8,12,16 are mapped to 18,19,20 */ |
| 1663 | return 18 + (ch-8)/4; |
| 1664 | case 34 ... 48: |
| 1665 | /* channels 34,36..48 are mapped to 21..28 */ |
| 1666 | return 21 + (ch-34)/2; |
| 1667 | case 52 ... 64: |
| 1668 | /* channels 52,56..64 are mapped to 29..32 */ |
| 1669 | return 29 + (ch-52)/4; |
| 1670 | case 100 ... 140: |
| 1671 | /* channels 100,104..140 are mapped to 33..43 */ |
| 1672 | return 33 + (ch-100)/4; |
| 1673 | case 149 ... 165: |
| 1674 | /* channels 149,153..165 are mapped to 44..48 */ |
| 1675 | return 44 + (ch-149)/4; |
| 1676 | default: |
| 1677 | break; |
| 1678 | } |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1679 | break; |
| 1680 | default: |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1681 | break; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1682 | } |
| 1683 | |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1684 | wl1271_error("%s: unknown band/channel: %d/%d", __func__, band, ch); |
| 1685 | return -1; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1686 | } |
| 1687 | |
| 1688 | void wlcore_set_pending_regdomain_ch(struct wl1271 *wl, u16 channel, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1689 | enum nl80211_band band) |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1690 | { |
| 1691 | int ch_bit_idx = 0; |
| 1692 | |
| 1693 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) |
| 1694 | return; |
| 1695 | |
| 1696 | ch_bit_idx = wlcore_get_reg_conf_ch_idx(band, channel); |
| 1697 | |
Eliad Peller | 49540d1 | 2013-09-17 18:41:27 +0300 | [diff] [blame] | 1698 | if (ch_bit_idx >= 0 && ch_bit_idx <= WL1271_MAX_CHANNELS) |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1699 | set_bit(ch_bit_idx, (long *)wl->reg_ch_conf_pending); |
| 1700 | } |
| 1701 | |
| 1702 | int wlcore_cmd_regdomain_config_locked(struct wl1271 *wl) |
| 1703 | { |
| 1704 | struct wl12xx_cmd_regdomain_dfs_config *cmd = NULL; |
| 1705 | int ret = 0, i, b, ch_bit_idx; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1706 | u32 tmp_ch_bitmap[2]; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1707 | struct wiphy *wiphy = wl->hw->wiphy; |
| 1708 | struct ieee80211_supported_band *band; |
| 1709 | bool timeout = false; |
| 1710 | |
| 1711 | if (!(wl->quirks & WLCORE_QUIRK_REGDOMAIN_CONF)) |
| 1712 | return 0; |
| 1713 | |
| 1714 | wl1271_debug(DEBUG_CMD, "cmd reg domain config"); |
| 1715 | |
| 1716 | memset(tmp_ch_bitmap, 0, sizeof(tmp_ch_bitmap)); |
| 1717 | |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1718 | for (b = NL80211_BAND_2GHZ; b <= NL80211_BAND_5GHZ; b++) { |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1719 | band = wiphy->bands[b]; |
| 1720 | for (i = 0; i < band->n_channels; i++) { |
Eliad Peller | 4ce9fad | 2014-12-29 08:24:11 +0200 | [diff] [blame] | 1721 | struct ieee80211_channel *channel = &band->channels[i]; |
| 1722 | u16 ch = channel->hw_value; |
| 1723 | u32 flags = channel->flags; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1724 | |
Eliad Peller | 4ce9fad | 2014-12-29 08:24:11 +0200 | [diff] [blame] | 1725 | if (flags & (IEEE80211_CHAN_DISABLED | |
| 1726 | IEEE80211_CHAN_NO_IR)) |
| 1727 | continue; |
| 1728 | |
| 1729 | if ((flags & IEEE80211_CHAN_RADAR) && |
| 1730 | channel->dfs_state != NL80211_DFS_AVAILABLE) |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1731 | continue; |
| 1732 | |
| 1733 | ch_bit_idx = wlcore_get_reg_conf_ch_idx(b, ch); |
| 1734 | if (ch_bit_idx < 0) |
| 1735 | continue; |
| 1736 | |
| 1737 | set_bit(ch_bit_idx, (long *)tmp_ch_bitmap); |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | tmp_ch_bitmap[0] |= wl->reg_ch_conf_pending[0]; |
| 1742 | tmp_ch_bitmap[1] |= wl->reg_ch_conf_pending[1]; |
| 1743 | |
| 1744 | if (!memcmp(tmp_ch_bitmap, wl->reg_ch_conf_last, sizeof(tmp_ch_bitmap))) |
| 1745 | goto out; |
| 1746 | |
| 1747 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1748 | if (!cmd) { |
| 1749 | ret = -ENOMEM; |
| 1750 | goto out; |
| 1751 | } |
| 1752 | |
| 1753 | cmd->ch_bit_map1 = cpu_to_le32(tmp_ch_bitmap[0]); |
| 1754 | cmd->ch_bit_map2 = cpu_to_le32(tmp_ch_bitmap[1]); |
Guy Mishol | 1cd91b2 | 2014-12-29 08:24:12 +0200 | [diff] [blame] | 1755 | cmd->dfs_region = wl->dfs_region; |
Victor Goldenshtein | 6b70e7e | 2012-11-25 18:26:59 +0200 | [diff] [blame] | 1756 | |
| 1757 | wl1271_debug(DEBUG_CMD, |
| 1758 | "cmd reg domain bitmap1: 0x%08x, bitmap2: 0x%08x", |
| 1759 | cmd->ch_bit_map1, cmd->ch_bit_map2); |
| 1760 | |
| 1761 | ret = wl1271_cmd_send(wl, CMD_DFS_CHANNEL_CONFIG, cmd, sizeof(*cmd), 0); |
| 1762 | if (ret < 0) { |
| 1763 | wl1271_error("failed to send reg domain dfs config"); |
| 1764 | goto out; |
| 1765 | } |
| 1766 | |
| 1767 | ret = wl->ops->wait_for_event(wl, |
| 1768 | WLCORE_EVENT_DFS_CONFIG_COMPLETE, |
| 1769 | &timeout); |
| 1770 | if (ret < 0 || timeout) { |
| 1771 | wl1271_error("reg domain conf %serror", |
| 1772 | timeout ? "completion " : ""); |
| 1773 | ret = timeout ? -ETIMEDOUT : ret; |
| 1774 | goto out; |
| 1775 | } |
| 1776 | |
| 1777 | memcpy(wl->reg_ch_conf_last, tmp_ch_bitmap, sizeof(tmp_ch_bitmap)); |
| 1778 | memset(wl->reg_ch_conf_pending, 0, sizeof(wl->reg_ch_conf_pending)); |
| 1779 | |
| 1780 | out: |
| 1781 | kfree(cmd); |
| 1782 | return ret; |
| 1783 | } |
| 1784 | |
Ido Yariv | 95dac04f | 2011-06-06 14:57:06 +0300 | [diff] [blame] | 1785 | int wl12xx_cmd_config_fwlog(struct wl1271 *wl) |
| 1786 | { |
| 1787 | struct wl12xx_cmd_config_fwlog *cmd; |
| 1788 | int ret = 0; |
| 1789 | |
| 1790 | wl1271_debug(DEBUG_CMD, "cmd config firmware logger"); |
| 1791 | |
| 1792 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1793 | if (!cmd) { |
| 1794 | ret = -ENOMEM; |
| 1795 | goto out; |
| 1796 | } |
| 1797 | |
| 1798 | cmd->logger_mode = wl->conf.fwlog.mode; |
| 1799 | cmd->log_severity = wl->conf.fwlog.severity; |
| 1800 | cmd->timestamp = wl->conf.fwlog.timestamp; |
| 1801 | cmd->output = wl->conf.fwlog.output; |
| 1802 | cmd->threshold = wl->conf.fwlog.threshold; |
| 1803 | |
| 1804 | ret = wl1271_cmd_send(wl, CMD_CONFIG_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1805 | if (ret < 0) { |
| 1806 | wl1271_error("failed to send config firmware logger command"); |
| 1807 | goto out_free; |
| 1808 | } |
| 1809 | |
| 1810 | out_free: |
| 1811 | kfree(cmd); |
| 1812 | |
| 1813 | out: |
| 1814 | return ret; |
| 1815 | } |
| 1816 | |
| 1817 | int wl12xx_cmd_start_fwlog(struct wl1271 *wl) |
| 1818 | { |
| 1819 | struct wl12xx_cmd_start_fwlog *cmd; |
| 1820 | int ret = 0; |
| 1821 | |
| 1822 | wl1271_debug(DEBUG_CMD, "cmd start firmware logger"); |
| 1823 | |
| 1824 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1825 | if (!cmd) { |
| 1826 | ret = -ENOMEM; |
| 1827 | goto out; |
| 1828 | } |
| 1829 | |
| 1830 | ret = wl1271_cmd_send(wl, CMD_START_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1831 | if (ret < 0) { |
| 1832 | wl1271_error("failed to send start firmware logger command"); |
| 1833 | goto out_free; |
| 1834 | } |
| 1835 | |
| 1836 | out_free: |
| 1837 | kfree(cmd); |
| 1838 | |
| 1839 | out: |
| 1840 | return ret; |
| 1841 | } |
| 1842 | |
| 1843 | int wl12xx_cmd_stop_fwlog(struct wl1271 *wl) |
| 1844 | { |
| 1845 | struct wl12xx_cmd_stop_fwlog *cmd; |
| 1846 | int ret = 0; |
| 1847 | |
| 1848 | wl1271_debug(DEBUG_CMD, "cmd stop firmware logger"); |
| 1849 | |
| 1850 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1851 | if (!cmd) { |
| 1852 | ret = -ENOMEM; |
| 1853 | goto out; |
| 1854 | } |
| 1855 | |
| 1856 | ret = wl1271_cmd_send(wl, CMD_STOP_FWLOGGER, cmd, sizeof(*cmd), 0); |
| 1857 | if (ret < 0) { |
| 1858 | wl1271_error("failed to send stop firmware logger command"); |
| 1859 | goto out_free; |
| 1860 | } |
| 1861 | |
| 1862 | out_free: |
| 1863 | kfree(cmd); |
| 1864 | |
| 1865 | out: |
| 1866 | return ret; |
| 1867 | } |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1868 | |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1869 | static int wl12xx_cmd_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1870 | u8 role_id, enum nl80211_band band, u8 channel) |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1871 | { |
| 1872 | struct wl12xx_cmd_roc *cmd; |
| 1873 | int ret = 0; |
| 1874 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 1875 | wl1271_debug(DEBUG_CMD, "cmd roc %d (%d)", channel, role_id); |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1876 | |
| 1877 | if (WARN_ON(role_id == WL12XX_INVALID_ROLE_ID)) |
| 1878 | return -EINVAL; |
| 1879 | |
| 1880 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1881 | if (!cmd) { |
| 1882 | ret = -ENOMEM; |
| 1883 | goto out; |
| 1884 | } |
| 1885 | |
| 1886 | cmd->role_id = role_id; |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 1887 | cmd->channel = channel; |
| 1888 | switch (band) { |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1889 | case NL80211_BAND_2GHZ: |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 1890 | cmd->band = WLCORE_BAND_2_4GHZ; |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1891 | break; |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1892 | case NL80211_BAND_5GHZ: |
Luciano Coelho | 0078213 | 2011-11-29 13:38:37 +0200 | [diff] [blame] | 1893 | cmd->band = WLCORE_BAND_5GHZ; |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1894 | break; |
| 1895 | default: |
Eliad Peller | 1b92f15 | 2011-10-10 10:13:09 +0200 | [diff] [blame] | 1896 | wl1271_error("roc - unknown band: %d", (int)wlvif->band); |
Eliad Peller | a7cba38 | 2011-08-14 13:17:16 +0300 | [diff] [blame] | 1897 | ret = -EINVAL; |
| 1898 | goto out_free; |
| 1899 | } |
| 1900 | |
| 1901 | |
| 1902 | ret = wl1271_cmd_send(wl, CMD_REMAIN_ON_CHANNEL, cmd, sizeof(*cmd), 0); |
| 1903 | if (ret < 0) { |
| 1904 | wl1271_error("failed to send ROC command"); |
| 1905 | goto out_free; |
| 1906 | } |
| 1907 | |
| 1908 | out_free: |
| 1909 | kfree(cmd); |
| 1910 | |
| 1911 | out: |
| 1912 | return ret; |
| 1913 | } |
| 1914 | |
| 1915 | static int wl12xx_cmd_croc(struct wl1271 *wl, u8 role_id) |
| 1916 | { |
| 1917 | struct wl12xx_cmd_croc *cmd; |
| 1918 | int ret = 0; |
| 1919 | |
| 1920 | wl1271_debug(DEBUG_CMD, "cmd croc (%d)", role_id); |
| 1921 | |
| 1922 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1923 | if (!cmd) { |
| 1924 | ret = -ENOMEM; |
| 1925 | goto out; |
| 1926 | } |
| 1927 | cmd->role_id = role_id; |
| 1928 | |
| 1929 | ret = wl1271_cmd_send(wl, CMD_CANCEL_REMAIN_ON_CHANNEL, cmd, |
| 1930 | sizeof(*cmd), 0); |
| 1931 | if (ret < 0) { |
| 1932 | wl1271_error("failed to send ROC command"); |
| 1933 | goto out_free; |
| 1934 | } |
| 1935 | |
| 1936 | out_free: |
| 1937 | kfree(cmd); |
| 1938 | |
| 1939 | out: |
| 1940 | return ret; |
| 1941 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1942 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 1943 | int wl12xx_roc(struct wl1271 *wl, struct wl12xx_vif *wlvif, u8 role_id, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 1944 | enum nl80211_band band, u8 channel) |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1945 | { |
| 1946 | int ret = 0; |
| 1947 | |
| 1948 | if (WARN_ON(test_bit(role_id, wl->roc_map))) |
| 1949 | return 0; |
| 1950 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 1951 | ret = wl12xx_cmd_roc(wl, wlvif, role_id, band, channel); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1952 | if (ret < 0) |
| 1953 | goto out; |
| 1954 | |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1955 | __set_bit(role_id, wl->roc_map); |
| 1956 | out: |
| 1957 | return ret; |
| 1958 | } |
| 1959 | |
| 1960 | int wl12xx_croc(struct wl1271 *wl, u8 role_id) |
| 1961 | { |
| 1962 | int ret = 0; |
| 1963 | |
| 1964 | if (WARN_ON(!test_bit(role_id, wl->roc_map))) |
| 1965 | return 0; |
| 1966 | |
| 1967 | ret = wl12xx_cmd_croc(wl, role_id); |
| 1968 | if (ret < 0) |
| 1969 | goto out; |
| 1970 | |
| 1971 | __clear_bit(role_id, wl->roc_map); |
Arik Nemtsov | 55df5af | 2012-03-03 22:18:00 +0200 | [diff] [blame] | 1972 | |
| 1973 | /* |
| 1974 | * Rearm the tx watchdog when removing the last ROC. This prevents |
| 1975 | * recoveries due to just finished ROCs - when Tx hasn't yet had |
| 1976 | * a chance to get out. |
| 1977 | */ |
| 1978 | if (find_first_bit(wl->roc_map, WL12XX_MAX_ROLES) >= WL12XX_MAX_ROLES) |
| 1979 | wl12xx_rearm_tx_watchdog_locked(wl); |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 1980 | out: |
| 1981 | return ret; |
| 1982 | } |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1983 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 1984 | int wl12xx_cmd_stop_channel_switch(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1985 | { |
| 1986 | struct wl12xx_cmd_stop_channel_switch *cmd; |
| 1987 | int ret; |
| 1988 | |
| 1989 | wl1271_debug(DEBUG_ACX, "cmd stop channel switch"); |
| 1990 | |
| 1991 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 1992 | if (!cmd) { |
| 1993 | ret = -ENOMEM; |
| 1994 | goto out; |
| 1995 | } |
| 1996 | |
Eliad Peller | fcab189 | 2012-11-22 18:06:18 +0200 | [diff] [blame] | 1997 | cmd->role_id = wlvif->role_id; |
| 1998 | |
Shahar Levi | 6d158ff | 2011-09-08 13:01:33 +0300 | [diff] [blame] | 1999 | ret = wl1271_cmd_send(wl, CMD_STOP_CHANNEL_SWICTH, cmd, sizeof(*cmd), 0); |
| 2000 | if (ret < 0) { |
| 2001 | wl1271_error("failed to stop channel switch command"); |
| 2002 | goto out_free; |
| 2003 | } |
| 2004 | |
| 2005 | out_free: |
| 2006 | kfree(cmd); |
| 2007 | |
| 2008 | out: |
| 2009 | return ret; |
| 2010 | } |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2011 | |
| 2012 | /* start dev role and roc on its channel */ |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 2013 | int wl12xx_start_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
Johannes Berg | 57fbcce | 2016-04-12 15:56:15 +0200 | [diff] [blame] | 2014 | enum nl80211_band band, int channel) |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2015 | { |
| 2016 | int ret; |
| 2017 | |
| 2018 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2019 | wlvif->bss_type == BSS_TYPE_IBSS))) |
| 2020 | return -EINVAL; |
| 2021 | |
Eliad Peller | 7845af3 | 2015-07-30 22:38:22 +0300 | [diff] [blame] | 2022 | /* the dev role is already started for p2p mgmt interfaces */ |
| 2023 | if (!wlcore_is_p2p_mgmt(wlvif)) { |
| 2024 | ret = wl12xx_cmd_role_enable(wl, |
| 2025 | wl12xx_wlvif_to_vif(wlvif)->addr, |
| 2026 | WL1271_ROLE_DEVICE, |
| 2027 | &wlvif->dev_role_id); |
| 2028 | if (ret < 0) |
| 2029 | goto out; |
| 2030 | } |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2031 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 2032 | ret = wl12xx_cmd_role_start_dev(wl, wlvif, band, channel); |
Eliad Peller | 889300f | 2012-07-26 17:17:06 +0300 | [diff] [blame] | 2033 | if (ret < 0) |
| 2034 | goto out_disable; |
| 2035 | |
Eliad Peller | dabf37d | 2012-11-20 13:20:03 +0200 | [diff] [blame] | 2036 | ret = wl12xx_roc(wl, wlvif, wlvif->dev_role_id, band, channel); |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2037 | if (ret < 0) |
| 2038 | goto out_stop; |
| 2039 | |
| 2040 | return 0; |
| 2041 | |
| 2042 | out_stop: |
| 2043 | wl12xx_cmd_role_stop_dev(wl, wlvif); |
Eliad Peller | 889300f | 2012-07-26 17:17:06 +0300 | [diff] [blame] | 2044 | out_disable: |
Eliad Peller | 7845af3 | 2015-07-30 22:38:22 +0300 | [diff] [blame] | 2045 | if (!wlcore_is_p2p_mgmt(wlvif)) |
| 2046 | wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2047 | out: |
| 2048 | return ret; |
| 2049 | } |
| 2050 | |
| 2051 | /* croc dev hlid, and stop the role */ |
| 2052 | int wl12xx_stop_dev(struct wl1271 *wl, struct wl12xx_vif *wlvif) |
| 2053 | { |
| 2054 | int ret; |
| 2055 | |
| 2056 | if (WARN_ON(!(wlvif->bss_type == BSS_TYPE_STA_BSS || |
| 2057 | wlvif->bss_type == BSS_TYPE_IBSS))) |
| 2058 | return -EINVAL; |
| 2059 | |
Eliad Peller | 8aefffe | 2011-12-18 20:25:42 +0200 | [diff] [blame] | 2060 | /* flush all pending packets */ |
Ido Yariv | eb96f84 | 2012-06-18 13:21:55 +0300 | [diff] [blame] | 2061 | ret = wlcore_tx_work_locked(wl); |
| 2062 | if (ret < 0) |
| 2063 | goto out; |
Eliad Peller | 8aefffe | 2011-12-18 20:25:42 +0200 | [diff] [blame] | 2064 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2065 | if (test_bit(wlvif->dev_role_id, wl->roc_map)) { |
| 2066 | ret = wl12xx_croc(wl, wlvif->dev_role_id); |
| 2067 | if (ret < 0) |
| 2068 | goto out; |
| 2069 | } |
| 2070 | |
| 2071 | ret = wl12xx_cmd_role_stop_dev(wl, wlvif); |
| 2072 | if (ret < 0) |
| 2073 | goto out; |
Eliad Peller | 889300f | 2012-07-26 17:17:06 +0300 | [diff] [blame] | 2074 | |
Eliad Peller | 7845af3 | 2015-07-30 22:38:22 +0300 | [diff] [blame] | 2075 | if (!wlcore_is_p2p_mgmt(wlvif)) { |
| 2076 | ret = wl12xx_cmd_role_disable(wl, &wlvif->dev_role_id); |
| 2077 | if (ret < 0) |
| 2078 | goto out; |
| 2079 | } |
Eliad Peller | 889300f | 2012-07-26 17:17:06 +0300 | [diff] [blame] | 2080 | |
Eliad Peller | 679a673 | 2011-10-11 11:55:44 +0200 | [diff] [blame] | 2081 | out: |
| 2082 | return ret; |
| 2083 | } |
Eliad Peller | c32e35f | 2015-07-30 22:38:21 +0300 | [diff] [blame] | 2084 | |
| 2085 | int wlcore_cmd_generic_cfg(struct wl1271 *wl, struct wl12xx_vif *wlvif, |
| 2086 | u8 feature, u8 enable, u8 value) |
| 2087 | { |
| 2088 | struct wlcore_cmd_generic_cfg *cmd; |
| 2089 | int ret; |
| 2090 | |
| 2091 | wl1271_debug(DEBUG_CMD, |
| 2092 | "cmd generic cfg (role %d feature %d enable %d value %d)", |
| 2093 | wlvif->role_id, feature, enable, value); |
| 2094 | |
| 2095 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 2096 | if (!cmd) |
| 2097 | return -ENOMEM; |
| 2098 | |
| 2099 | cmd->role_id = wlvif->role_id; |
| 2100 | cmd->feature = feature; |
| 2101 | cmd->enable = enable; |
| 2102 | cmd->value = value; |
| 2103 | |
| 2104 | ret = wl1271_cmd_send(wl, CMD_GENERIC_CFG, cmd, sizeof(*cmd), 0); |
| 2105 | if (ret < 0) { |
| 2106 | wl1271_error("failed to send generic cfg command"); |
| 2107 | goto out_free; |
| 2108 | } |
| 2109 | out_free: |
| 2110 | kfree(cmd); |
| 2111 | return ret; |
| 2112 | } |
| 2113 | EXPORT_SYMBOL_GPL(wlcore_cmd_generic_cfg); |