xref: /openbmc/linux/drivers/net/wireless/ti/wl18xx/cmd.c (revision e3d786a3)
1 /*
2  * This file is part of wl18xx
3  *
4  * Copyright (C) 2011 Texas Instruments Inc.
5  *
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.
9  *
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.
14  *
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
19  *
20  */
21 
22 #include "../wlcore/cmd.h"
23 #include "../wlcore/debug.h"
24 #include "../wlcore/hw_ops.h"
25 
26 #include "cmd.h"
27 
28 int wl18xx_cmd_channel_switch(struct wl1271 *wl,
29 			      struct wl12xx_vif *wlvif,
30 			      struct ieee80211_channel_switch *ch_switch)
31 {
32 	struct wl18xx_cmd_channel_switch *cmd;
33 	u32 supported_rates;
34 	int ret;
35 
36 	wl1271_debug(DEBUG_ACX, "cmd channel switch (count=%d)",
37 		     ch_switch->count);
38 
39 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
40 	if (!cmd) {
41 		ret = -ENOMEM;
42 		goto out;
43 	}
44 
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;
49 
50 	switch (ch_switch->chandef.chan->band) {
51 	case NL80211_BAND_2GHZ:
52 		cmd->band = WLCORE_BAND_2_4GHZ;
53 		break;
54 	case NL80211_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;
62 	}
63 
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;
74 
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;
79 	}
80 
81 out_free:
82 	kfree(cmd);
83 out:
84 	return ret;
85 }
86 
87 int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
88 {
89 	struct wl18xx_cmd_smart_config_start *cmd;
90 	int ret = 0;
91 
92 	wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
93 		     group_bitmap);
94 
95 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
96 	if (!cmd) {
97 		ret = -ENOMEM;
98 		goto out;
99 	}
100 
101 	cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
102 
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;
107 	}
108 
109 out_free:
110 	kfree(cmd);
111 out:
112 	return ret;
113 }
114 
115 int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
116 {
117 	struct wl1271_cmd_header *cmd;
118 	int ret = 0;
119 
120 	wl1271_debug(DEBUG_CMD, "cmd smart config stop");
121 
122 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
123 	if (!cmd) {
124 		ret = -ENOMEM;
125 		goto out;
126 	}
127 
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;
132 	}
133 
134 out_free:
135 	kfree(cmd);
136 out:
137 	return ret;
138 }
139 
140 int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
141 					  u8 key_len, u8 *key)
142 {
143 	struct wl18xx_cmd_smart_config_set_group_key *cmd;
144 	int ret = 0;
145 
146 	wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
147 		     group_id);
148 
149 	if (key_len != sizeof(cmd->key)) {
150 		wl1271_error("invalid group key size: %d", key_len);
151 		return -E2BIG;
152 	}
153 
154 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
155 	if (!cmd) {
156 		ret = -ENOMEM;
157 		goto out;
158 	}
159 
160 	cmd->group_id = cpu_to_le32(group_id);
161 	memcpy(cmd->key, key, key_len);
162 
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;
168 	}
169 
170 out_free:
171 	kfree(cmd);
172 out:
173 	return ret;
174 }
175 
176 int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
177 {
178 	struct wlcore_cmd_cac_start *cmd;
179 	int ret = 0;
180 
181 	wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
182 		     wlvif->channel, start ? "start" : "stop");
183 
184 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
185 	if (!cmd)
186 		return -ENOMEM;
187 
188 	cmd->role_id = wlvif->role_id;
189 	cmd->channel = wlvif->channel;
190 	if (wlvif->band == NL80211_BAND_5GHZ)
191 		cmd->band = WLCORE_BAND_5GHZ;
192 	cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
193 
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;
200 	}
201 
202 out_free:
203 	kfree(cmd);
204 	return ret;
205 }
206 
207 int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
208 {
209 	struct wl18xx_cmd_dfs_radar_debug *cmd;
210 	int ret = 0;
211 
212 	wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
213 		     channel);
214 
215 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
216 	if (!cmd)
217 		return -ENOMEM;
218 
219 	cmd->channel = channel;
220 
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;
226 	}
227 
228 out_free:
229 	kfree(cmd);
230 	return ret;
231 }
232 
233 int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
234 {
235 	struct wl18xx_cmd_dfs_master_restart *cmd;
236 	int ret = 0;
237 
238 	wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
239 		     wlvif->role_id);
240 
241 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
242 	if (!cmd)
243 		return -ENOMEM;
244 
245 	cmd->role_id = wlvif->role_id;
246 
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;
252 	}
253 out_free:
254 	kfree(cmd);
255 	return ret;
256 }
257