Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / net / wireless / ti / wl18xx / cmd.c
bloba8d176ddc73c3c8e6a6f5f7adab2ec9ea7e1c924
1 /*
2 * This file is part of wl18xx
4 * Copyright (C) 2011 Texas Instruments Inc.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18 * 02110-1301 USA
22 #include "../wlcore/cmd.h"
23 #include "../wlcore/debug.h"
24 #include "../wlcore/hw_ops.h"
26 #include "cmd.h"
28 int wl18xx_cmd_channel_switch(struct wl1271 *wl,
29 struct wl12xx_vif *wlvif,
30 struct ieee80211_channel_switch *ch_switch)
32 struct wl18xx_cmd_channel_switch *cmd;
33 u32 supported_rates;
34 int ret;
36 wl1271_debug(DEBUG_ACX, "cmd channel switch (count=%d)",
37 ch_switch->count);
39 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
40 if (!cmd) {
41 ret = -ENOMEM;
42 goto out;
45 cmd->role_id = wlvif->role_id;
46 cmd->channel = ch_switch->chandef.chan->hw_value;
47 cmd->switch_time = ch_switch->count;
48 cmd->stop_tx = ch_switch->block_tx;
50 switch (ch_switch->chandef.chan->band) {
51 case IEEE80211_BAND_2GHZ:
52 cmd->band = WLCORE_BAND_2_4GHZ;
53 break;
54 case IEEE80211_BAND_5GHZ:
55 cmd->band = WLCORE_BAND_5GHZ;
56 break;
57 default:
58 wl1271_error("invalid channel switch band: %d",
59 ch_switch->chandef.chan->band);
60 ret = -EINVAL;
61 goto out_free;
64 supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
65 if (wlvif->bss_type == BSS_TYPE_STA_BSS)
66 supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
67 else
68 supported_rates |=
69 wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
70 if (wlvif->p2p)
71 supported_rates &= ~CONF_TX_CCK_RATES;
72 cmd->local_supported_rates = cpu_to_le32(supported_rates);
73 cmd->channel_type = wlvif->channel_type;
75 ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
76 if (ret < 0) {
77 wl1271_error("failed to send channel switch command");
78 goto out_free;
81 out_free:
82 kfree(cmd);
83 out:
84 return ret;
87 int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
89 struct wl18xx_cmd_smart_config_start *cmd;
90 int ret = 0;
92 wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
93 group_bitmap);
95 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
96 if (!cmd) {
97 ret = -ENOMEM;
98 goto out;
101 cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
103 ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
104 if (ret < 0) {
105 wl1271_error("failed to send smart config start command");
106 goto out_free;
109 out_free:
110 kfree(cmd);
111 out:
112 return ret;
115 int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
117 struct wl1271_cmd_header *cmd;
118 int ret = 0;
120 wl1271_debug(DEBUG_CMD, "cmd smart config stop");
122 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
123 if (!cmd) {
124 ret = -ENOMEM;
125 goto out;
128 ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
129 if (ret < 0) {
130 wl1271_error("failed to send smart config stop command");
131 goto out_free;
134 out_free:
135 kfree(cmd);
136 out:
137 return ret;
140 int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
141 u8 key_len, u8 *key)
143 struct wl18xx_cmd_smart_config_set_group_key *cmd;
144 int ret = 0;
146 wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
147 group_id);
149 if (key_len != sizeof(cmd->key)) {
150 wl1271_error("invalid group key size: %d", key_len);
151 return -E2BIG;
154 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
155 if (!cmd) {
156 ret = -ENOMEM;
157 goto out;
160 cmd->group_id = cpu_to_le32(group_id);
161 memcpy(cmd->key, key, key_len);
163 ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
164 sizeof(*cmd), 0);
165 if (ret < 0) {
166 wl1271_error("failed to send smart config set group key cmd");
167 goto out_free;
170 out_free:
171 kfree(cmd);
172 out:
173 return ret;
176 int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
178 struct wlcore_cmd_cac_start *cmd;
179 int ret = 0;
181 wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
182 wlvif->channel, start ? "start" : "stop");
184 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
185 if (!cmd)
186 return -ENOMEM;
188 cmd->role_id = wlvif->role_id;
189 cmd->channel = wlvif->channel;
190 if (wlvif->band == IEEE80211_BAND_5GHZ)
191 cmd->band = WLCORE_BAND_5GHZ;
192 cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
194 ret = wl1271_cmd_send(wl,
195 start ? CMD_CAC_START : CMD_CAC_STOP,
196 cmd, sizeof(*cmd), 0);
197 if (ret < 0) {
198 wl1271_error("failed to send cac command");
199 goto out_free;
202 out_free:
203 kfree(cmd);
204 return ret;
207 int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
209 struct wl18xx_cmd_dfs_radar_debug *cmd;
210 int ret = 0;
212 wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
213 channel);
215 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
216 if (!cmd)
217 return -ENOMEM;
219 cmd->channel = channel;
221 ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG,
222 cmd, sizeof(*cmd), 0);
223 if (ret < 0) {
224 wl1271_error("failed to send radar detection debug command");
225 goto out_free;
228 out_free:
229 kfree(cmd);
230 return ret;
233 int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
235 struct wl18xx_cmd_dfs_master_restart *cmd;
236 int ret = 0;
238 wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
239 wlvif->role_id);
241 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
242 if (!cmd)
243 return -ENOMEM;
245 cmd->role_id = wlvif->role_id;
247 ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART,
248 cmd, sizeof(*cmd), 0);
249 if (ret < 0) {
250 wl1271_error("failed to send dfs master restart command");
251 goto out_free;
253 out_free:
254 kfree(cmd);
255 return ret;