xref: /openbmc/linux/drivers/net/wireless/ti/wl18xx/cmd.c (revision 57fbcce37be7c1d2622b56587c10ade00e96afa3)
1fcab1890SEliad Peller /*
2fcab1890SEliad Peller  * This file is part of wl18xx
3fcab1890SEliad Peller  *
4fcab1890SEliad Peller  * Copyright (C) 2011 Texas Instruments Inc.
5fcab1890SEliad Peller  *
6fcab1890SEliad Peller  * This program is free software; you can redistribute it and/or
7fcab1890SEliad Peller  * modify it under the terms of the GNU General Public License
8fcab1890SEliad Peller  * version 2 as published by the Free Software Foundation.
9fcab1890SEliad Peller  *
10fcab1890SEliad Peller  * This program is distributed in the hope that it will be useful, but
11fcab1890SEliad Peller  * WITHOUT ANY WARRANTY; without even the implied warranty of
12fcab1890SEliad Peller  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13fcab1890SEliad Peller  * General Public License for more details.
14fcab1890SEliad Peller  *
15fcab1890SEliad Peller  * You should have received a copy of the GNU General Public License
16fcab1890SEliad Peller  * along with this program; if not, write to the Free Software
17fcab1890SEliad Peller  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18fcab1890SEliad Peller  * 02110-1301 USA
19fcab1890SEliad Peller  *
20fcab1890SEliad Peller  */
21fcab1890SEliad Peller 
22fcab1890SEliad Peller #include "../wlcore/cmd.h"
23fcab1890SEliad Peller #include "../wlcore/debug.h"
24fcab1890SEliad Peller #include "../wlcore/hw_ops.h"
25fcab1890SEliad Peller 
26fcab1890SEliad Peller #include "cmd.h"
27fcab1890SEliad Peller 
28fcab1890SEliad Peller int wl18xx_cmd_channel_switch(struct wl1271 *wl,
29fcab1890SEliad Peller 			      struct wl12xx_vif *wlvif,
30fcab1890SEliad Peller 			      struct ieee80211_channel_switch *ch_switch)
31fcab1890SEliad Peller {
32fcab1890SEliad Peller 	struct wl18xx_cmd_channel_switch *cmd;
33fcab1890SEliad Peller 	u32 supported_rates;
34fcab1890SEliad Peller 	int ret;
35fcab1890SEliad Peller 
36534719f4SEliad Peller 	wl1271_debug(DEBUG_ACX, "cmd channel switch (count=%d)",
37534719f4SEliad Peller 		     ch_switch->count);
38fcab1890SEliad Peller 
39fcab1890SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
40fcab1890SEliad Peller 	if (!cmd) {
41fcab1890SEliad Peller 		ret = -ENOMEM;
42fcab1890SEliad Peller 		goto out;
43fcab1890SEliad Peller 	}
44fcab1890SEliad Peller 
45fcab1890SEliad Peller 	cmd->role_id = wlvif->role_id;
4685220d71SJohannes Berg 	cmd->channel = ch_switch->chandef.chan->hw_value;
47fcab1890SEliad Peller 	cmd->switch_time = ch_switch->count;
48fcab1890SEliad Peller 	cmd->stop_tx = ch_switch->block_tx;
49fcab1890SEliad Peller 
5085220d71SJohannes Berg 	switch (ch_switch->chandef.chan->band) {
51*57fbcce3SJohannes Berg 	case NL80211_BAND_2GHZ:
52fcab1890SEliad Peller 		cmd->band = WLCORE_BAND_2_4GHZ;
53fcab1890SEliad Peller 		break;
54*57fbcce3SJohannes Berg 	case NL80211_BAND_5GHZ:
55fcab1890SEliad Peller 		cmd->band = WLCORE_BAND_5GHZ;
56fcab1890SEliad Peller 		break;
57fcab1890SEliad Peller 	default:
58fcab1890SEliad Peller 		wl1271_error("invalid channel switch band: %d",
5985220d71SJohannes Berg 			     ch_switch->chandef.chan->band);
60fcab1890SEliad Peller 		ret = -EINVAL;
61fcab1890SEliad Peller 		goto out_free;
62fcab1890SEliad Peller 	}
63fcab1890SEliad Peller 
64534719f4SEliad Peller 	supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES;
65534719f4SEliad Peller 	if (wlvif->bss_type == BSS_TYPE_STA_BSS)
66534719f4SEliad Peller 		supported_rates |= wlcore_hw_sta_get_ap_rate_mask(wl, wlvif);
67534719f4SEliad Peller 	else
68534719f4SEliad Peller 		supported_rates |=
69534719f4SEliad Peller 			wlcore_hw_ap_get_mimo_wide_rate_mask(wl, wlvif);
70fcab1890SEliad Peller 	if (wlvif->p2p)
71fcab1890SEliad Peller 		supported_rates &= ~CONF_TX_CCK_RATES;
72fcab1890SEliad Peller 	cmd->local_supported_rates = cpu_to_le32(supported_rates);
73fcab1890SEliad Peller 	cmd->channel_type = wlvif->channel_type;
74fcab1890SEliad Peller 
75fcab1890SEliad Peller 	ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0);
76fcab1890SEliad Peller 	if (ret < 0) {
77fcab1890SEliad Peller 		wl1271_error("failed to send channel switch command");
78fcab1890SEliad Peller 		goto out_free;
79fcab1890SEliad Peller 	}
80fcab1890SEliad Peller 
81fcab1890SEliad Peller out_free:
82fcab1890SEliad Peller 	kfree(cmd);
83fcab1890SEliad Peller out:
84fcab1890SEliad Peller 	return ret;
85fcab1890SEliad Peller }
86ccb1df94SEliad Peller 
87ccb1df94SEliad Peller int wl18xx_cmd_smart_config_start(struct wl1271 *wl, u32 group_bitmap)
88ccb1df94SEliad Peller {
89ccb1df94SEliad Peller 	struct wl18xx_cmd_smart_config_start *cmd;
90ccb1df94SEliad Peller 	int ret = 0;
91ccb1df94SEliad Peller 
92ccb1df94SEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd smart config start group_bitmap=0x%x",
93ccb1df94SEliad Peller 		     group_bitmap);
94ccb1df94SEliad Peller 
95ccb1df94SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
96ccb1df94SEliad Peller 	if (!cmd) {
97ccb1df94SEliad Peller 		ret = -ENOMEM;
98ccb1df94SEliad Peller 		goto out;
99ccb1df94SEliad Peller 	}
100ccb1df94SEliad Peller 
101ccb1df94SEliad Peller 	cmd->group_id_bitmask = cpu_to_le32(group_bitmap);
102ccb1df94SEliad Peller 
103ccb1df94SEliad Peller 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_START, cmd, sizeof(*cmd), 0);
104ccb1df94SEliad Peller 	if (ret < 0) {
105ccb1df94SEliad Peller 		wl1271_error("failed to send smart config start command");
106ccb1df94SEliad Peller 		goto out_free;
107ccb1df94SEliad Peller 	}
108ccb1df94SEliad Peller 
109ccb1df94SEliad Peller out_free:
110ccb1df94SEliad Peller 	kfree(cmd);
111ccb1df94SEliad Peller out:
112ccb1df94SEliad Peller 	return ret;
113ccb1df94SEliad Peller }
114ccb1df94SEliad Peller 
115ccb1df94SEliad Peller int wl18xx_cmd_smart_config_stop(struct wl1271 *wl)
116ccb1df94SEliad Peller {
117ccb1df94SEliad Peller 	struct wl1271_cmd_header *cmd;
118ccb1df94SEliad Peller 	int ret = 0;
119ccb1df94SEliad Peller 
120ccb1df94SEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd smart config stop");
121ccb1df94SEliad Peller 
122ccb1df94SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
123ccb1df94SEliad Peller 	if (!cmd) {
124ccb1df94SEliad Peller 		ret = -ENOMEM;
125ccb1df94SEliad Peller 		goto out;
126ccb1df94SEliad Peller 	}
127ccb1df94SEliad Peller 
128ccb1df94SEliad Peller 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_STOP, cmd, sizeof(*cmd), 0);
129ccb1df94SEliad Peller 	if (ret < 0) {
130ccb1df94SEliad Peller 		wl1271_error("failed to send smart config stop command");
131ccb1df94SEliad Peller 		goto out_free;
132ccb1df94SEliad Peller 	}
133ccb1df94SEliad Peller 
134ccb1df94SEliad Peller out_free:
135ccb1df94SEliad Peller 	kfree(cmd);
136ccb1df94SEliad Peller out:
137ccb1df94SEliad Peller 	return ret;
138ccb1df94SEliad Peller }
139ccb1df94SEliad Peller 
140ccb1df94SEliad Peller int wl18xx_cmd_smart_config_set_group_key(struct wl1271 *wl, u16 group_id,
141ccb1df94SEliad Peller 					  u8 key_len, u8 *key)
142ccb1df94SEliad Peller {
143ccb1df94SEliad Peller 	struct wl18xx_cmd_smart_config_set_group_key *cmd;
144ccb1df94SEliad Peller 	int ret = 0;
145ccb1df94SEliad Peller 
146ccb1df94SEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd smart config set group key id=0x%x",
147ccb1df94SEliad Peller 		     group_id);
148ccb1df94SEliad Peller 
149ccb1df94SEliad Peller 	if (key_len != sizeof(cmd->key)) {
150ccb1df94SEliad Peller 		wl1271_error("invalid group key size: %d", key_len);
151ccb1df94SEliad Peller 		return -E2BIG;
152ccb1df94SEliad Peller 	}
153ccb1df94SEliad Peller 
154ccb1df94SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
155ccb1df94SEliad Peller 	if (!cmd) {
156ccb1df94SEliad Peller 		ret = -ENOMEM;
157ccb1df94SEliad Peller 		goto out;
158ccb1df94SEliad Peller 	}
159ccb1df94SEliad Peller 
160ccb1df94SEliad Peller 	cmd->group_id = cpu_to_le32(group_id);
161ccb1df94SEliad Peller 	memcpy(cmd->key, key, key_len);
162ccb1df94SEliad Peller 
163ccb1df94SEliad Peller 	ret = wl1271_cmd_send(wl, CMD_SMART_CONFIG_SET_GROUP_KEY, cmd,
164ccb1df94SEliad Peller 			      sizeof(*cmd), 0);
165ccb1df94SEliad Peller 	if (ret < 0) {
166ccb1df94SEliad Peller 		wl1271_error("failed to send smart config set group key cmd");
167ccb1df94SEliad Peller 		goto out_free;
168ccb1df94SEliad Peller 	}
169ccb1df94SEliad Peller 
170ccb1df94SEliad Peller out_free:
171ccb1df94SEliad Peller 	kfree(cmd);
172ccb1df94SEliad Peller out:
173ccb1df94SEliad Peller 	return ret;
174ccb1df94SEliad Peller }
175750e9d15SEliad Peller 
176750e9d15SEliad Peller int wl18xx_cmd_set_cac(struct wl1271 *wl, struct wl12xx_vif *wlvif, bool start)
177750e9d15SEliad Peller {
178750e9d15SEliad Peller 	struct wlcore_cmd_cac_start *cmd;
179750e9d15SEliad Peller 	int ret = 0;
180750e9d15SEliad Peller 
181750e9d15SEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd cac (channel %d) %s",
182750e9d15SEliad Peller 		     wlvif->channel, start ? "start" : "stop");
183750e9d15SEliad Peller 
184750e9d15SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
185750e9d15SEliad Peller 	if (!cmd)
186750e9d15SEliad Peller 		return -ENOMEM;
187750e9d15SEliad Peller 
188750e9d15SEliad Peller 	cmd->role_id = wlvif->role_id;
189750e9d15SEliad Peller 	cmd->channel = wlvif->channel;
190*57fbcce3SJohannes Berg 	if (wlvif->band == NL80211_BAND_5GHZ)
191750e9d15SEliad Peller 		cmd->band = WLCORE_BAND_5GHZ;
192750e9d15SEliad Peller 	cmd->bandwidth = wlcore_get_native_channel_type(wlvif->channel_type);
193750e9d15SEliad Peller 
194750e9d15SEliad Peller 	ret = wl1271_cmd_send(wl,
195750e9d15SEliad Peller 			      start ? CMD_CAC_START : CMD_CAC_STOP,
196750e9d15SEliad Peller 			      cmd, sizeof(*cmd), 0);
197750e9d15SEliad Peller 	if (ret < 0) {
198750e9d15SEliad Peller 		wl1271_error("failed to send cac command");
199750e9d15SEliad Peller 		goto out_free;
200750e9d15SEliad Peller 	}
201750e9d15SEliad Peller 
202750e9d15SEliad Peller out_free:
203750e9d15SEliad Peller 	kfree(cmd);
204750e9d15SEliad Peller 	return ret;
205750e9d15SEliad Peller }
206e7d32324SEliad Peller 
207e7d32324SEliad Peller int wl18xx_cmd_radar_detection_debug(struct wl1271 *wl, u8 channel)
208e7d32324SEliad Peller {
209e7d32324SEliad Peller 	struct wl18xx_cmd_dfs_radar_debug *cmd;
210e7d32324SEliad Peller 	int ret = 0;
211e7d32324SEliad Peller 
212e7d32324SEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd radar detection debug (chan %d)",
213e7d32324SEliad Peller 		     channel);
214e7d32324SEliad Peller 
215e7d32324SEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
216e7d32324SEliad Peller 	if (!cmd)
217e7d32324SEliad Peller 		return -ENOMEM;
218e7d32324SEliad Peller 
219e7d32324SEliad Peller 	cmd->channel = channel;
220e7d32324SEliad Peller 
221e7d32324SEliad Peller 	ret = wl1271_cmd_send(wl, CMD_DFS_RADAR_DETECTION_DEBUG,
222e7d32324SEliad Peller 			      cmd, sizeof(*cmd), 0);
223e7d32324SEliad Peller 	if (ret < 0) {
224e7d32324SEliad Peller 		wl1271_error("failed to send radar detection debug command");
225e7d32324SEliad Peller 		goto out_free;
226e7d32324SEliad Peller 	}
227e7d32324SEliad Peller 
228e7d32324SEliad Peller out_free:
229e7d32324SEliad Peller 	kfree(cmd);
230e7d32324SEliad Peller 	return ret;
231e7d32324SEliad Peller }
232830513abSEliad Peller 
233830513abSEliad Peller int wl18xx_cmd_dfs_master_restart(struct wl1271 *wl, struct wl12xx_vif *wlvif)
234830513abSEliad Peller {
235830513abSEliad Peller 	struct wl18xx_cmd_dfs_master_restart *cmd;
236830513abSEliad Peller 	int ret = 0;
237830513abSEliad Peller 
238830513abSEliad Peller 	wl1271_debug(DEBUG_CMD, "cmd dfs master restart (role %d)",
239830513abSEliad Peller 		     wlvif->role_id);
240830513abSEliad Peller 
241830513abSEliad Peller 	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
242830513abSEliad Peller 	if (!cmd)
243830513abSEliad Peller 		return -ENOMEM;
244830513abSEliad Peller 
245830513abSEliad Peller 	cmd->role_id = wlvif->role_id;
246830513abSEliad Peller 
247830513abSEliad Peller 	ret = wl1271_cmd_send(wl, CMD_DFS_MASTER_RESTART,
248830513abSEliad Peller 			      cmd, sizeof(*cmd), 0);
249830513abSEliad Peller 	if (ret < 0) {
250830513abSEliad Peller 		wl1271_error("failed to send dfs master restart command");
251830513abSEliad Peller 		goto out_free;
252830513abSEliad Peller 	}
253830513abSEliad Peller out_free:
254830513abSEliad Peller 	kfree(cmd);
255830513abSEliad Peller 	return ret;
256830513abSEliad Peller }
257